8000 Add wildcard support for exclude domain by xXxsomebodyoncetoldmexXx · Pull Request #62 · zema1/suo5 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add wildcard support for exclude domain #62

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion ctrl/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Suo5Config struct {

TestExit string `json:"-"`
ExcludeDomainMap map[string]bool `json:"-"`
ExcludeDomainWCMap map[string]bool `json:"-"`
Offset int `json:"-"`
Header http.Header `json:"-"`
OnRemoteConnected func(e *ConnectedEvent) `json:"-"`
Expand All @@ -43,8 +44,14 @@ func (s *Suo5Config) Parse() error {

func (s *Suo5Config) parseExcludeDomain() {
s.ExcludeDomainMap = make(map[string]bool)
s.ExcludeDomainWCMap = make(map[string]bool)
for _, domain := range s.ExcludeDomain {
s.ExcludeDomainMap[strings.ToLower(strings.TrimSpace(domain))] = true
domain = strings.ToLower(strings.TrimSpace(domain))
if domain[0] == '*' {
s.ExcludeDomainWCMap[domain[2:]] = true
} else {
s.ExcludeDomainMap[domain] = true
}
}
}

Expand Down
21 changes: 20 additions & 1 deletion ctrl/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"net"
"net/http"
"strconv"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -44,6 +45,24 @@
selector gosocks5.Selector
}

func IsExcludeDomain(m *socks5Handler, d string) bool {
// Default Exclude
if m.config.ExcludeDomainMap[d] {
return true
}

// WildCard Exclude
ntld := strings.Count(d, ".")
for ntld > 0 && !m.config.ExcludeDomainWCMap[d] {
d = strings.SplitN(d, ".", 2)[1]
ntld--
}
if ntld != 0 {

Check failure on line 60 in ctrl/handler.go

View workflow job for this annotation

GitHub Actions / golangci-lint

S1008: should use 'return ntld != 0' instead of 'if ntld != 0 { return true }; return false' (gosimple)
return true
}
return false
}

func (m *socks5Handler) Handle(conn net.Conn) error {
defer conn.Close()

Expand All @@ -54,7 +73,7 @@
return err
}

if m.config.ExcludeDomainMap[req.Addr.Host] {
if IsExcludeDomain(m, req.Addr.Host) {
log.Infof("drop connection to %s", req.Addr.Host)
return nil
}
Expand Down
Binary file added suo5
Binary file not shown.
Loading
0