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 {
|
2024-08-23 12:17:35 +00:00
|
|
|
Addr string
|
|
|
|
Port int
|
|
|
|
DnsAddr string
|
|
|
|
DnsPort int
|
2024-09-08 13:45:24 +00:00
|
|
|
DnsIPv4Only bool
|
2024-08-23 12:17:35 +00:00
|
|
|
EnableDoh bool
|
|
|
|
Debug bool
|
2024-09-08 13:43:09 +00:00
|
|
|
Silent bool
|
2024-08-23 12:17:35 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2024-08-15 06:19:45 +00:00
|
|
|
func (c *Config) Load(args *Args) {
|
2024-08-15 10:12:29 +00:00
|
|
|
c.Addr = args.Addr
|
2024-08-31 14:50:02 +00:00
|
|
|
c.Port = int(args.Port)
|
2024-08-15 10:12:29 +00:00
|
|
|
c.DnsAddr = args.DnsAddr
|
2024-08-31 14:50:02 +00:00
|
|
|
c.DnsPort = int(args.DnsPort)
|
2024-09-08 13:45:24 +00:00
|
|
|
c.DnsIPv4Only = args.DnsIPv4Only
|
2024-08-15 10:12:29 +00:00
|
|
|
c.Debug = args.Debug
|
|
|
|
c.EnableDoh = args.EnableDoh
|
2024-09-08 13:43:09 +00:00
|
|
|
c.Silent = args.Silent
|
2024-08-15 10:12:29 +00:00
|
|
|
c.SystemProxy = args.SystemProxy
|
2024-08-31 14:50:02 +00:00
|
|
|
c.Timeout = int(args.Timeout)
|
2024-08-15 10:12:29 +00:00
|
|
|
c.AllowedPatterns = parseAllowedPattern(args.AllowedPattern)
|
2024-08-31 14:50:02 +00:00
|
|
|
c.WindowSize = int(args.WindowSize)
|
2024-08-15 10:12:29 +00:00
|
|
|
}
|
|
|
|
|
2024-08-23 12:17:35 +00:00
|
|
|
func parseAllowedPattern(patterns StringArray) []*regexp.Regexp {
|
2024-08-15 10:12:29 +00:00
|
|
|
var allowedPatterns []*regexp.Regexp
|
|
|
|
|
2024-08-23 12:17:35 +00:00
|
|
|
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{
|
2024-08-23 12:17:35 +00:00
|
|
|
{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:09:58 +00:00
|
|
|
|
2024-08-31 14:50:02 +00:00
|
|
|
pterm.DefaultBasicText.Println("Press 'CTRL + c' to quit")
|
2023-05-07 05:57:37 +00:00
|
|
|
}
|