Feature: add mode script

This commit is contained in:
yaling888
2021-10-15 14:11:14 +08:00
parent 862174d21b
commit c0e9d69163
28 changed files with 1918 additions and 356 deletions

View File

@ -22,6 +22,7 @@ var Path = func() *path {
type path struct {
homeDir string
configFile string
scriptDir string
}
// SetHomeDir is used to set the configuration path
@ -67,6 +68,23 @@ 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, 0644)
}
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)
}

View File

@ -1,5 +1,7 @@
package constant
import "net"
// Rule Type
const (
Domain RuleType = iota
@ -12,6 +14,7 @@ const (
SrcPort
DstPort
Process
Script
MATCH
)
@ -39,6 +42,8 @@ func (rt RuleType) String() string {
return "DstPort"
case Process:
return "Process"
case Script:
return "Script"
case MATCH:
return "Match"
default:
@ -54,3 +59,5 @@ type Rule interface {
ShouldResolveIP() bool
RuleExtra() *RuleExtra
}
var TunBroadcastAddr = net.IPv4(198, 18, 255, 255)