mirror of
https://github.com/xvzc/SpoofDPI.git
synced 2024-12-22 14:26:31 +00:00
chore: refactor config
This commit is contained in:
parent
b46a67dd20
commit
7f27c1ad43
@ -28,7 +28,7 @@ func New(config *util.Config) *Proxy {
|
||||
port: *config.Port,
|
||||
timeout: *config.Timeout,
|
||||
windowSize: *config.WindowSize,
|
||||
allowedPattern: config.AllowedPattern,
|
||||
allowedPattern: config.AllowedPatterns,
|
||||
resolver: dns.NewResolver(config),
|
||||
}
|
||||
}
|
||||
|
12
util/args.go
12
util/args.go
@ -3,7 +3,6 @@ package util
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
type Args struct {
|
||||
@ -16,7 +15,7 @@ type Args struct {
|
||||
NoBanner *bool
|
||||
SystemProxy *bool
|
||||
Timeout *int
|
||||
AllowedPattern []*regexp.Regexp
|
||||
AllowedPattern *StringArray
|
||||
WindowSize *int
|
||||
Version *bool
|
||||
}
|
||||
@ -33,7 +32,7 @@ func (arr *StringArray) Set(value string) error {
|
||||
}
|
||||
|
||||
func ParseArgs() *Args {
|
||||
args := new(Args)
|
||||
args := new(Args)
|
||||
args.Addr = flag.String("addr", "127.0.0.1", "listen address")
|
||||
args.Port = flag.Int("port", 8080, "port")
|
||||
args.DnsAddr = flag.String("dns-addr", "8.8.8.8", "dns address")
|
||||
@ -50,18 +49,13 @@ fragmentation for the first data packet and the rest
|
||||
`)
|
||||
args.Version = flag.Bool("v", false, "print spoof-dpi's version; this may contain some other relevant information")
|
||||
|
||||
var allowedPattern StringArray
|
||||
flag.Var(
|
||||
&allowedPattern,
|
||||
args.AllowedPattern,
|
||||
"pattern",
|
||||
"bypass DPI only on packets matching this regex pattern; can be given multiple times",
|
||||
)
|
||||
|
||||
flag.Parse()
|
||||
|
||||
for _, pattern := range allowedPattern {
|
||||
args.AllowedPattern = append(args.AllowedPattern, regexp.MustCompile(pattern))
|
||||
}
|
||||
|
||||
return args
|
||||
}
|
||||
|
@ -9,40 +9,50 @@ import (
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Addr *string
|
||||
Port *int
|
||||
DnsAddr *string
|
||||
DnsPort *int
|
||||
EnableDoh *bool
|
||||
Debug *bool
|
||||
NoBanner *bool
|
||||
SystemProxy *bool
|
||||
Timeout *int
|
||||
WindowSize *int
|
||||
AllowedPattern []*regexp.Regexp
|
||||
Addr *string
|
||||
Port *int
|
||||
DnsAddr *string
|
||||
DnsPort *int
|
||||
EnableDoh *bool
|
||||
Debug *bool
|
||||
NoBanner *bool
|
||||
SystemProxy *bool
|
||||
Timeout *int
|
||||
WindowSize *int
|
||||
AllowedPatterns []*regexp.Regexp
|
||||
}
|
||||
|
||||
var config *Config
|
||||
|
||||
func GetConfig() *Config {
|
||||
if config == nil {
|
||||
config = new(Config)
|
||||
}
|
||||
if config == nil {
|
||||
config = new(Config)
|
||||
}
|
||||
return config
|
||||
}
|
||||
|
||||
func (c *Config) Load(args *Args) {
|
||||
c.Addr = args.Addr
|
||||
c.Port = args.Port
|
||||
c.DnsAddr = args.DnsAddr
|
||||
c.DnsPort = args.DnsPort
|
||||
c.Debug = args.Debug
|
||||
c.EnableDoh = args.EnableDoh
|
||||
c.NoBanner = args.NoBanner
|
||||
c.SystemProxy = args.SystemProxy
|
||||
c.Timeout = args.Timeout
|
||||
c.AllowedPattern = args.AllowedPattern
|
||||
c.WindowSize = args.WindowSize
|
||||
c.Addr = args.Addr
|
||||
c.Port = args.Port
|
||||
c.DnsAddr = args.DnsAddr
|
||||
c.DnsPort = args.DnsPort
|
||||
c.Debug = args.Debug
|
||||
c.EnableDoh = args.EnableDoh
|
||||
c.NoBanner = args.NoBanner
|
||||
c.SystemProxy = args.SystemProxy
|
||||
c.Timeout = args.Timeout
|
||||
c.AllowedPatterns = parseAllowedPattern(args.AllowedPattern)
|
||||
c.WindowSize = args.WindowSize
|
||||
}
|
||||
|
||||
func parseAllowedPattern(patterns *StringArray) []*regexp.Regexp {
|
||||
var allowedPatterns []*regexp.Regexp
|
||||
|
||||
for _, pattern := range *patterns {
|
||||
allowedPatterns = append(allowedPatterns, regexp.MustCompile(pattern))
|
||||
}
|
||||
|
||||
return allowedPatterns
|
||||
}
|
||||
|
||||
func PrintColoredBanner() {
|
||||
|
Loading…
Reference in New Issue
Block a user