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),
|
||||
}
|
||||
}
|
||||
|
10
util/args.go
10
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
|
||||
}
|
||||
@ -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
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ type Config struct {
|
||||
SystemProxy *bool
|
||||
Timeout *int
|
||||
WindowSize *int
|
||||
AllowedPattern []*regexp.Regexp
|
||||
AllowedPatterns []*regexp.Regexp
|
||||
}
|
||||
|
||||
var config *Config
|
||||
@ -41,10 +41,20 @@ func (c *Config) Load(args *Args) {
|
||||
c.NoBanner = args.NoBanner
|
||||
c.SystemProxy = args.SystemProxy
|
||||
c.Timeout = args.Timeout
|
||||
c.AllowedPattern = args.AllowedPattern
|
||||
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() {
|
||||
cyan := putils.LettersFromStringWithStyle("Spoof", pterm.NewStyle(pterm.FgCyan))
|
||||
purple := putils.LettersFromStringWithStyle("DPI", pterm.NewStyle(pterm.FgLightMagenta))
|
||||
|
Loading…
Reference in New Issue
Block a user