SpoofDPI/util/config.go

72 lines
1.7 KiB
Go
Raw Normal View History

2023-05-07 05:57:37 +00:00
package util
import (
"fmt"
"regexp"
"github.com/pterm/pterm"
2024-07-21 08:12:16 +00:00
"github.com/pterm/pterm/putils"
2023-05-07 05:57:37 +00:00
)
type Config struct {
Addr string
Port int
DnsAddr string
DnsPort int
EnableDoh bool
Debug bool
Silent bool
SystemProxy bool
Timeout int
WindowSize int
2024-08-15 10:12:29 +00:00
AllowedPatterns []*regexp.Regexp
2023-05-07 05:57:37 +00:00
}
var config *Config
func GetConfig() *Config {
2024-08-15 10:12:29 +00:00
if config == nil {
config = new(Config)
}
2023-05-07 05:57:37 +00:00
return config
}
func (c *Config) Load(args *Args) {
2024-08-15 10:12:29 +00:00
c.Addr = args.Addr
c.Port = int(args.Port)
2024-08-15 10:12:29 +00:00
c.DnsAddr = args.DnsAddr
c.DnsPort = int(args.DnsPort)
2024-08-15 10:12:29 +00:00
c.Debug = args.Debug
c.EnableDoh = args.EnableDoh
c.Silent = args.Silent
2024-08-15 10:12:29 +00:00
c.SystemProxy = args.SystemProxy
c.Timeout = int(args.Timeout)
2024-08-15 10:12:29 +00:00
c.AllowedPatterns = parseAllowedPattern(args.AllowedPattern)
c.WindowSize = int(args.WindowSize)
2024-08-15 10:12:29 +00:00
}
func parseAllowedPattern(patterns StringArray) []*regexp.Regexp {
2024-08-15 10:12:29 +00:00
var allowedPatterns []*regexp.Regexp
for _, pattern := range patterns {
2024-08-15 10:12:29 +00:00
allowedPatterns = append(allowedPatterns, regexp.MustCompile(pattern))
}
return allowedPatterns
2023-05-07 05:57:37 +00:00
}
func PrintColoredBanner() {
2024-07-22 04:49:18 +00:00
cyan := putils.LettersFromStringWithStyle("Spoof", pterm.NewStyle(pterm.FgCyan))
purple := putils.LettersFromStringWithStyle("DPI", pterm.NewStyle(pterm.FgLightMagenta))
2023-05-07 05:57:37 +00:00
pterm.DefaultBigText.WithLetters(cyan, purple).Render()
pterm.DefaultBulletList.WithItems([]pterm.BulletListItem{
{Level: 0, Text: "ADDR : " + fmt.Sprint(config.Addr)},
{Level: 0, Text: "PORT : " + fmt.Sprint(config.Port)},
{Level: 0, Text: "DNS : " + fmt.Sprint(config.DnsAddr)},
{Level: 0, Text: "DEBUG : " + fmt.Sprint(config.Debug)},
2023-05-07 05:57:37 +00:00
}).Render()
pterm.DefaultBasicText.Println("Press 'CTRL + c' to quit")
2023-05-07 05:57:37 +00:00
}