chore: refactor config

This commit is contained in:
xvzc 2024-08-15 19:12:29 +09:00
parent b46a67dd20
commit 7f27c1ad43
3 changed files with 39 additions and 35 deletions

View File

@ -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),
}
}

View File

@ -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
}

View File

@ -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))