From 5bd5f1bfda1befa9b912bc0ab0697bee64b100c2 Mon Sep 17 00:00:00 2001 From: CHIZI-0618 <2916997591@qq.com> Date: Sat, 14 May 2022 13:00:33 +0800 Subject: [PATCH] chore: remove Script mode residual code. --- config/config.go | 5 ----- constant/path.go | 18 ------------------ constant/rule.go | 3 --- hub/route/script.go | 16 ---------------- hub/route/server.go | 1 - tunnel/mode.go | 4 ---- tunnel/tunnel.go | 4 ---- 7 files changed, 51 deletions(-) delete mode 100644 hub/route/script.go diff --git a/config/config.go b/config/config.go index a11304f8..9a315577 100644 --- a/config/config.go +++ b/config/config.go @@ -543,7 +543,6 @@ func parseRules(cfg *RawConfig, proxies map[string]C.Proxy) ([]C.Rule, map[strin var rules []C.Rule rulesConfig := cfg.Rule - mode := cfg.Mode // parse rules for idx, line := range rulesConfig { @@ -555,10 +554,6 @@ func parseRules(cfg *RawConfig, proxies map[string]C.Proxy) ([]C.Rule, map[strin ruleName = strings.ToUpper(rule[0]) ) - if mode == T.Script && ruleName != "GEOSITE" { - continue - } - l := len(rule) if ruleName == "NOT" || ruleName == "OR" || ruleName == "AND" { diff --git a/constant/path.go b/constant/path.go index b49b2180..7ce4f4e0 100644 --- a/constant/path.go +++ b/constant/path.go @@ -29,7 +29,6 @@ var Path = func() *path { type path struct { homeDir string configFile string - scriptDir string } // SetHomeDir is used to set the configuration path @@ -123,23 +122,6 @@ func (p *path) GeoSite() string { return P.Join(p.homeDir, "GeoSite.dat") } -func (p *path) ScriptDir() string { - if len(p.scriptDir) != 0 { - return p.scriptDir - } - if dir, err := os.MkdirTemp("", Name+"-"); err == nil { - p.scriptDir = dir - } else { - p.scriptDir = P.Join(os.TempDir(), Name) - _ = os.MkdirAll(p.scriptDir, 0o644) - } - return p.scriptDir -} - -func (p *path) Script() string { - return P.Join(p.ScriptDir(), "clash_script.py") -} - func (p *path) GetAssetLocation(file string) string { return P.Join(p.homeDir, file) } diff --git a/constant/rule.go b/constant/rule.go index 1617979f..e41309f0 100644 --- a/constant/rule.go +++ b/constant/rule.go @@ -13,7 +13,6 @@ const ( DstPort Process ProcessPath - Script RuleSet Network Uid @@ -49,8 +48,6 @@ func (rt RuleType) String() string { return "Process" case ProcessPath: return "ProcessPath" - case Script: - return "Script" case MATCH: return "Match" case RuleSet: diff --git a/hub/route/script.go b/hub/route/script.go deleted file mode 100644 index fc1f791d..00000000 --- a/hub/route/script.go +++ /dev/null @@ -1,16 +0,0 @@ -package route - -import ( - "github.com/go-chi/chi/v5" - "net/http" -) - -func scriptRouter() http.Handler { - r := chi.NewRouter() - r.Get("/", getScript) - return r -} - -func getScript(writer http.ResponseWriter, request *http.Request) { - writer.WriteHeader(http.StatusMethodNotAllowed) -} diff --git a/hub/route/server.go b/hub/route/server.go index 9bb15ddd..ac12fed3 100644 --- a/hub/route/server.go +++ b/hub/route/server.go @@ -72,7 +72,6 @@ func Start(addr string, secret string) { r.Mount("/connections", connectionRouter()) r.Mount("/providers/proxies", proxyProviderRouter()) r.Mount("/providers/rules", ruleProviderRouter()) - r.Mount("/script", scriptRouter()) r.Mount("/cache", cacheRouter()) }) diff --git a/tunnel/mode.go b/tunnel/mode.go index 6e3561d8..a1697a32 100644 --- a/tunnel/mode.go +++ b/tunnel/mode.go @@ -12,14 +12,12 @@ type TunnelMode int var ModeMapping = map[string]TunnelMode{ Global.String(): Global, Rule.String(): Rule, - Script.String(): Script, Direct.String(): Direct, } const ( Global TunnelMode = iota Rule - Script Direct ) @@ -63,8 +61,6 @@ func (m TunnelMode) String() string { return "global" case Rule: return "rule" - case Script: - return "script" case Direct: return "direct" default: diff --git a/tunnel/tunnel.go b/tunnel/tunnel.go index 72102bf1..4cfc399b 100644 --- a/tunnel/tunnel.go +++ b/tunnel/tunnel.go @@ -291,8 +291,6 @@ func handleUDPConn(packet *inbound.PacketAdapter) { } else { log.Infoln("[UDP] %s --> %s match %s using %s", metadata.SourceDetail(), metadata.RemoteAddress(), rule.Payload(), rawPc.Chains().String()) } - case mode == Script: - log.Infoln("[UDP] %s --> %s using SCRIPT %s", metadata.SourceDetail(), metadata.RemoteAddress(), rawPc.Chains().String()) case mode == Global: log.Infoln("[UDP] %s --> %s using GLOBAL", metadata.SourceDetail(), metadata.RemoteAddress()) case mode == Direct: @@ -362,8 +360,6 @@ func handleTCPConn(connCtx C.ConnContext) { } else { log.Infoln("[TCP] %s --> %s match %s using %s", metadata.SourceDetail(), metadata.RemoteAddress(), rule.RuleType().String(), remoteConn.Chains().String()) } - case mode == Script: - log.Infoln("[TCP] %s --> %s using SCRIPT %s", metadata.SourceDetail(), metadata.RemoteAddress(), remoteConn.Chains().String()) case mode == Global: log.Infoln("[TCP] %s --> %s using GLOBAL", metadata.SourceDetail(), metadata.RemoteAddress()) case mode == Direct: