prox5/list_management.go

95 lines
2.3 KiB
Go
Raw Normal View History

2022-05-23 01:05:50 +00:00
package prox5
import (
"bufio"
2022-09-28 23:44:23 +00:00
"errors"
2021-10-25 09:57:38 +00:00
"io"
"os"
"strings"
)
2021-09-21 12:24:30 +00:00
// LoadProxyTXT loads proxies from a given seed file and feeds them to the mapBuilder to be later queued automatically for validation.
2022-07-25 07:14:26 +00:00
// Expects one of the following formats for each line:
2022-09-23 01:57:35 +00:00
// - 127.0.0.1:1080
// - 127.0.0.1:1080:user:pass
// - yeet.com:1080
// - yeet.com:1080:user:pass
// - [fe80::2ef0:5dff:fe7f:c299]:1080
// - [fe80::2ef0:5dff:fe7f:c299]:1080:user:pass
2022-10-16 10:53:04 +00:00
func (p5 *ProxyEngine) LoadProxyTXT(seedFile string) (count int) {
2021-10-25 10:32:59 +00:00
f, err := os.Open(seedFile)
if err != nil {
2022-09-22 23:45:15 +00:00
p5.dbgPrint(simpleString(err.Error()))
2021-10-25 10:32:59 +00:00
return 0
}
defer func() {
2021-10-25 10:32:59 +00:00
if err := f.Close(); err != nil {
2022-09-22 23:45:15 +00:00
p5.dbgPrint(simpleString(err.Error()))
2021-10-25 10:32:59 +00:00
}
}()
2021-10-25 10:32:59 +00:00
bs, err := io.ReadAll(f)
if err != nil {
2022-09-22 23:45:15 +00:00
p5.dbgPrint(simpleString(err.Error()))
2021-09-20 01:23:18 +00:00
return 0
}
2021-10-25 09:57:38 +00:00
sockstr := string(bs)
2022-09-22 23:45:15 +00:00
return p5.LoadMultiLineString(sockstr)
}
2022-07-25 07:14:26 +00:00
// LoadSingleProxy loads a SOCKS proxy into our map.
// Expects one of the following formats:
2022-09-23 01:57:35 +00:00
// - 127.0.0.1:1080
// - 127.0.0.1:1080:user:pass
// - yeet.com:1080
// - yeet.com:1080:user:pass
// - [fe80::2ef0:5dff:fe7f:c299]:1080
// - [fe80::2ef0:5dff:fe7f:c299]:1080:user:pass
2022-10-16 10:53:04 +00:00
func (p5 *ProxyEngine) LoadSingleProxy(sock string) bool {
2022-09-28 23:44:23 +00:00
var ok bool
2022-08-29 05:41:34 +00:00
if sock, ok = filter(sock); !ok {
2022-09-28 23:44:23 +00:00
return false
2021-10-25 04:15:06 +00:00
}
2022-09-28 23:44:23 +00:00
if err := p5.loadSingleProxy(sock); err != nil {
return false
}
return true
2021-10-25 04:15:06 +00:00
}
2022-10-16 10:53:04 +00:00
func (p5 *ProxyEngine) loadSingleProxy(sock string) error {
2023-01-31 09:21:29 +00:00
p, ok := p5.proxyMap.add(sock)
if !ok {
2022-09-28 23:44:23 +00:00
return errors.New("proxy already exists")
2021-10-25 10:32:59 +00:00
}
2023-01-31 09:21:29 +00:00
p5.Pending.add(p)
2022-09-28 23:44:23 +00:00
return nil
}
2022-07-25 07:14:26 +00:00
// LoadMultiLineString loads a multiine string object with proxy per line.
// Expects one of the following formats for each line:
2022-09-23 01:57:35 +00:00
// - 127.0.0.1:1080
// - 127.0.0.1:1080:user:pass
// - yeet.com:1080
// - yeet.com:1080:user:pass
// - [fe80::2ef0:5dff:fe7f:c299]:1080
// - [fe80::2ef0:5dff:fe7f:c299]:1080:user:pass
2022-10-16 10:53:04 +00:00
func (p5 *ProxyEngine) LoadMultiLineString(socks string) int {
var count int
scan := bufio.NewScanner(strings.NewReader(socks))
for scan.Scan() {
2022-09-23 22:57:46 +00:00
if err := p5.loadSingleProxy(scan.Text()); err != nil {
continue
2021-10-25 09:57:38 +00:00
}
2022-09-23 22:57:46 +00:00
count++
}
2021-09-20 01:23:18 +00:00
return count
}
2021-09-21 12:24:30 +00:00
// ClearSOCKSList clears the map of proxies that we have on record.
// Other operations (proxies that are still in buffered channels) will continue.
2022-10-16 10:53:04 +00:00
func (p5 *ProxyEngine) ClearSOCKSList() {
p5.proxyMap.clear()
}