Projects STRLCPY prox5 Commits d61405b3
🤬
  • ■ ■ ■ ■ ■
    list_management.go
    skipped 1 lines
    2 2   
    3 3  import (
    4 4   "bufio"
    5  - "fmt"
    6 5   "io"
    7 6   "os"
    8  - "strconv"
    9 7   "strings"
    10 8   "time"
    11  - 
    12  - "github.com/miekg/dns"
    13  - ipa "inet.af/netaddr"
    14 9  )
    15 10   
    16 11  // throw shit proxies here, get map
    skipped 4 lines
    21 16   inChan = make(chan string, 100000)
    22 17  }
    23 18   
    24  -func checkV6(in string) (filtered string, ok bool) {
    25  - split := strings.Split(in, "]:")
    26  - if len(split) != 2 {
    27  - return in, false
    28  - }
    29  - 
    30  - combo, err := ipa.ParseIPPort(split[0] + "]:" + split[1])
    31  - if err != nil {
    32  - return in, false
    33  - }
    34  - 
    35  - if !strings.Contains(split[1], ":") {
    36  - return combo.String(), true
    37  - }
    38  - 
    39  - split6 := strings.Split(split[1], ":")
    40  - if len(split6) != 2 {
    41  - return in, false
    42  - }
    43  - 
    44  - return fmt.Sprintf("%s:%s@%s", split6[0], split6[1], combo.String()), true
    45  -}
    46  - 
    47  -func (pe *ProxyEngine) filter(in string) (filtered string, ok bool) { //nolint:cyclop
    48  - if !strings.Contains(in, ":") {
    49  - return in, false
    50  - }
    51  - split := strings.Split(in, ":")
    52  - 
    53  - if len(split) < 2 {
    54  - return in, false
    55  - }
    56  - 
    57  - if _, err := strconv.Atoi(split[1]); err != nil {
    58  - return in, false
    59  - }
    60  - 
    61  - switch len(split) {
    62  - case 2:
    63  - if _, ok := dns.IsDomainName(split[0]); ok {
    64  - return in, true
    65  - }
    66  - combo, err := ipa.ParseIPPort(in)
    67  - if err != nil {
    68  - return in, false
    69  - }
    70  - return combo.String(), true
    71  - case 4:
    72  - if _, ok := dns.IsDomainName(split[0]); ok {
    73  - return fmt.Sprintf("%s:%s@%s:%s", split[2], split[3], split[0], split[1]), true
    74  - }
    75  - combo, err := ipa.ParseIPPort(split[0] + ":" + split[1])
    76  - if err != nil {
    77  - return in, false
    78  - }
    79  - return fmt.Sprintf("%s:%s@%s", split[2], split[3], combo.String()), true
    80  - default:
    81  - if !strings.Contains(split[0], "[") || !strings.Contains(split[0], "]:") {
    82  - return in, false
    83  - }
    84  - }
    85  - return checkV6(in)
    86  -}
    87  - 
    88 19  // LoadProxyTXT loads proxies from a given seed file and feeds them to the mapBuilder to be later queued automatically for validation.
    89 20  // Expects one of the following formats for each line:
    90 21  // * 127.0.0.1:1080
    skipped 34 lines
    125 56  // * [fe80::2ef0:5dff:fe7f:c299]:1080
    126 57  // * [fe80::2ef0:5dff:fe7f:c299]:1080:user:pass
    127 58  func (pe *ProxyEngine) LoadSingleProxy(sock string) (ok bool) {
    128  - if sock, ok = pe.filter(sock); !ok {
     59 + if sock, ok = filter(sock); !ok {
    129 60   return
    130 61   }
    131 62   go pe.loadSingleProxy(sock)
    skipped 39 lines
  • ■ ■ ■ ■ ■ ■
    parse.go
     1 +package prox5
     2 + 
     3 +import (
     4 + "strconv"
     5 + "strings"
     6 + 
     7 + "github.com/miekg/dns"
     8 + ipa "inet.af/netaddr"
     9 + 
     10 + "git.tcp.direct/kayos/prox5/internal/pools"
     11 +)
     12 + 
     13 +func filterv6(in string) (filtered string, ok bool) {
     14 + split := strings.Split(in, "]:")
     15 + if len(split) < 2 {
     16 + 
     17 + return "", false
     18 + }
     19 + split2 := strings.Split(split[1], ":")
     20 + switch len(split2) {
     21 + case 0:
     22 + combo, err := ipa.ParseIPPort(buildProxyString("", "", split[0], split2[0], true))
     23 + if err == nil {
     24 + return combo.String(), true
     25 + }
     26 + case 1:
     27 + println("len(split2) == 1")
     28 + concat := buildProxyString("", "", split[0], split2[0], true)
     29 + combo, err := ipa.ParseIPPort(concat)
     30 + if err == nil {
     31 + return combo.String(), true
     32 + }
     33 + default:
     34 + println("len(split2) != 1")
     35 + _, err := ipa.ParseIPPort(buildProxyString("", "", split[0], split2[0], true))
     36 + if err == nil {
     37 + return buildProxyString(split2[1], split2[2], split[0], split2[0], true), true
     38 + }
     39 + }
     40 + return "", true
     41 +}
     42 + 
     43 +func isNumber(s string) bool {
     44 + _, err := strconv.Atoi(s)
     45 + return err == nil
     46 +}
     47 + 
     48 +func buildProxyString(username, password, address, port string, v6 bool) (result string) {
     49 + builder := pools.CopABuffer.Get().(*strings.Builder)
     50 + if username != "" && password != "" {
     51 + builder.WriteString(username)
     52 + builder.WriteString(":")
     53 + builder.WriteString(password)
     54 + builder.WriteString("@")
     55 + }
     56 + builder.WriteString(address)
     57 + if v6 {
     58 + builder.WriteString("]")
     59 + }
     60 + builder.WriteString(":")
     61 + builder.WriteString(port)
     62 + result = builder.String()
     63 + pools.DiscardBuffer(builder)
     64 + return
     65 +}
     66 + 
     67 +func filter(in string) (filtered string, ok bool) { //nolint:cyclop
     68 + if !strings.Contains(in, ":") {
     69 + return "", false
     70 + }
     71 + split := strings.Split(in, ":")
     72 + 
     73 + if len(split) < 2 {
     74 + return "", false
     75 + }
     76 + switch len(split) {
     77 + case 2:
     78 + _, isDomain := dns.IsDomainName(split[0])
     79 + if isDomain && isNumber(split[1]) {
     80 + return in, true
     81 + }
     82 + combo, err := ipa.ParseIPPort(in)
     83 + if err != nil {
     84 + return "", false
     85 + }
     86 + return combo.String(), true
     87 + case 4:
     88 + _, isDomain := dns.IsDomainName(split[0])
     89 + if isDomain && isNumber(split[1]) {
     90 + return buildProxyString(split[2], split[3], split[0], split[1], false), true
     91 + }
     92 + _, isDomain = dns.IsDomainName(split[2])
     93 + if isDomain && isNumber(split[3]) {
     94 + return buildProxyString(split[0], split[1], split[2], split[3], false), true
     95 + }
     96 + if _, err := ipa.ParseIPPort(split[2] + ":" + split[3]); err == nil {
     97 + return buildProxyString(split[0], split[1], split[2], split[3], false), true
     98 + }
     99 + if _, err := ipa.ParseIPPort(split[0] + ":" + split[1]); err == nil {
     100 + return buildProxyString(split[2], split[3], split[0], split[1], false), true
     101 + }
     102 + default:
     103 + if !strings.Contains(in, "[") || !strings.Contains(in, "]:") {
     104 + return "", false
     105 + }
     106 + }
     107 + return filterv6(in)
     108 +}
     109 + 
  • ■ ■ ■ ■ ■ ■
    parse_test.go
     1 +package prox5
     2 + 
     3 +import "testing"
     4 + 
     5 +func Test_filter(t *testing.T) {
     6 + type args struct {
     7 + in string
     8 + }
     9 + type test struct {
     10 + name string
     11 + args args
     12 + wantFiltered string
     13 + wantOk bool
     14 + }
     15 + var tests = []test{
     16 + {
     17 + name: "simple",
     18 + args: args{
     19 + in: "127.0.0.1:1080",
     20 + },
     21 + wantFiltered: "127.0.0.1:1080",
     22 + wantOk: true,
     23 + },
     24 + {
     25 + name: "withAuth",
     26 + args: args{
     27 + in: "127.0.0.1:1080:user:pass",
     28 + },
     29 + wantFiltered: "user:[email protected]:1080",
     30 + wantOk: true,
     31 + },
     32 + {
     33 + name: "simpleDomain",
     34 + args: args{
     35 + in: "yeet.com:1080",
     36 + },
     37 + wantFiltered: "yeet.com:1080",
     38 + wantOk: true,
     39 + },
     40 + {
     41 + name: "domainWithAuth",
     42 + args: args{
     43 + in: "yeet.com:1080:user:pass",
     44 + },
     45 + wantFiltered: "user:[email protected]:1080",
     46 + wantOk: true,
     47 + },
     48 + {
     49 + name: "ipv6",
     50 + args: args{
     51 + in: "[fe80::2ef0:5dff:fe7f:c299]:1080",
     52 + },
     53 + wantFiltered: "[fe80::2ef0:5dff:fe7f:c299]:1080",
     54 + wantOk: true,
     55 + },
     56 + {
     57 + name: "ipv6WithAuth",
     58 + args: args{
     59 + in: "[fe80::2ef0:5dff:fe7f:c299]:1080:user:pass",
     60 + },
     61 + wantFiltered: "user:pass@[fe80::2ef0:5dff:fe7f:c299]:1080",
     62 + wantOk: true,
     63 + },
     64 + {
     65 + name: "invalid",
     66 + args: args{
     67 + in: "yeet",
     68 + },
     69 + wantFiltered: "",
     70 + wantOk: false,
     71 + },
     72 + }
     73 + for _, tt := range tests {
     74 + t.Run(tt.name, func(t *testing.T) {
     75 + gotFiltered, gotOk := filter(tt.args.in)
     76 + if gotFiltered != tt.wantFiltered {
     77 + t.Errorf("filter() gotFiltered = %v, want %v", gotFiltered, tt.wantFiltered)
     78 + }
     79 + if gotOk != tt.wantOk {
     80 + t.Errorf("filter() gotOk = %v, want %v", gotOk, tt.wantOk)
     81 + }
     82 + })
     83 + }
     84 +}
     85 + 
Please wait...
Page is in error, reload to recover