SpoofDPI/util/config.go

83 lines
2.0 KiB
Go
Raw Permalink 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
Banner 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 = args.Port
c.DnsAddr = args.DnsAddr
c.DnsPort = args.DnsPort
c.Debug = args.Debug
c.EnableDoh = args.EnableDoh
c.Banner = args.Banner
2024-08-15 10:12:29 +00:00
c.SystemProxy = args.SystemProxy
c.Timeout = args.Timeout
c.AllowedPatterns = parseAllowedPattern(args.AllowedPattern)
c.WindowSize = args.WindowSize
}
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()
2024-08-25 09:17:25 +00:00
pterm.DefaultBasicText.Println("Press 'CTRL + c' to quit")
2023-05-07 05:57:37 +00:00
}
func PrintSimpleInfo() {
fmt.Println("")
fmt.Println("- ADDR : ", config.Addr)
fmt.Println("- PORT : ", config.Port)
fmt.Println("- DNS : ", config.DnsAddr)
fmt.Println("- DEBUG : ", config.Debug)
2023-05-07 05:57:37 +00:00
fmt.Println("")
fmt.Println("Press 'CTRL + c to quit'")
fmt.Println("")
2023-05-07 05:57:37 +00:00
}