Skip to content

Commit

Permalink
fix: auto_block proxy rule
Browse files Browse the repository at this point in the history
  • Loading branch information
nange committed Dec 8, 2023
1 parent e9725c8 commit 8c8c1b3
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 37 deletions.
2 changes: 1 addition & 1 deletion cmd/easyss/tray.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (st *SysTray) AddProxyRuleMenu() (*systray.MenuItem, *systray.MenuItem, *sy

autoBlock := proxyMenue.AddSubMenuItemCheckbox("自动+屏蔽广告跟踪", "自动判断请求是否走代理或者屏蔽", false)
if st.SS().ProxyRule() == easyss.ProxyRuleAutoBlock {
auto.Check()
autoBlock.Check()
}

reverseAuto := proxyMenue.AddSubMenuItemCheckbox("反向自动(国外访问国内)", "适用国外访问国内IP域名", false)
Expand Down
56 changes: 46 additions & 10 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,52 @@ import (
"github.com/nange/easyss/v2/util"
)

var Methods = map[string]struct{}{
type ProxyRule int

const (
ProxyRuleUnknown ProxyRule = iota
ProxyRuleAuto
ProxyRuleReverseAuto
ProxyRuleProxy
ProxyRuleDirect
ProxyRuleAutoBlock
)

var proxyRules = map[string]ProxyRule{
"auto": ProxyRuleAuto,
"reverse_auto": ProxyRuleReverseAuto,
"proxy": ProxyRuleProxy,
"direct": ProxyRuleDirect,
"auto_block": ProxyRuleAutoBlock,
}

func ParseProxyRuleFromString(rule string) ProxyRule {
if r, ok := proxyRules[rule]; ok {
return r
}

return ProxyRuleUnknown
}

func AllProxyRule() []string {
keys := make([]string, 0, len(proxyRules))
for k := range proxyRules {
keys = append(keys, k)
}
return keys
}

var methods = map[string]struct{}{
"aes-256-gcm": {},
"chacha20-poly1305": {},
}

var ProxyRules = map[string]struct{}{
"auto": {},
"auto_block": {},
"proxy": {},
"direct": {},
func AllMethod() []string {
keys := make([]string, 0, len(methods))
for k := range proxyRules {
keys = append(keys, k)
}
return keys
}

const (
Expand Down Expand Up @@ -134,8 +170,8 @@ func (c *Config) Validate() error {
}
}
if c.Method != "" {
if _, ok := Methods[c.Method]; !ok {
return fmt.Errorf("unsupported method:%s, supported methods:[aes-256-gcm, chacha20-poly1305]", c.Method)
if _, ok := methods[c.Method]; !ok {
return fmt.Errorf("unsupported method:%s, supported methods:%v", c.Method, AllMethod())
}
}
switch c.LogLevel {
Expand All @@ -144,8 +180,8 @@ func (c *Config) Validate() error {
return fmt.Errorf("unsupported log-level:%s, supported log-levels:[debug, info, warn, error]", c.LogLevel)
}
if c.ProxyRule != "" {
if _, ok := ProxyRules[c.ProxyRule]; !ok {
return fmt.Errorf("unsupported proxy rule:%s, supported rules:[auto, auto_block, proxy, direct]", c.ProxyRule)
if _, ok := proxyRules[c.ProxyRule]; !ok {
return fmt.Errorf("unsupported proxy rule:%s, supported rules:%v", c.ProxyRule, AllProxyRule())
}
}
if c.OutboundProto != OutboundProtoNative && c.OutboundProto != OutboundProtoHTTP &&
Expand Down
26 changes: 0 additions & 26 deletions easyss.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,32 +165,6 @@ func (gs *GeoSite) SimpleMatch(domain string, matchSub bool) bool {
return false
}

type ProxyRule int

const (
ProxyRuleUnknown ProxyRule = iota
ProxyRuleAuto
ProxyRuleReverseAuto
ProxyRuleProxy
ProxyRuleDirect
ProxyRuleAutoBlock
)

func ParseProxyRuleFromString(rule string) ProxyRule {
m := map[string]ProxyRule{
"auto": ProxyRuleAuto,
"reverse_auto": ProxyRuleReverseAuto,
"proxy": ProxyRuleProxy,
"direct": ProxyRuleDirect,
"auto_block": ProxyRuleAutoBlock,
}
if r, ok := m[rule]; ok {
return r
}

return ProxyRuleUnknown
}

type HostRule int

const (
Expand Down

0 comments on commit 8c8c1b3

Please sign in to comment.