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
|
|
|
|
EnableDoh bool
|
|
|
|
Debug bool
|
2024-08-25 09:09:58 +00:00
|
|
|
Banner 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
|
|
|
|
c.Port = args.Port
|
|
|
|
c.DnsAddr = args.DnsAddr
|
|
|
|
c.DnsPort = args.DnsPort
|
|
|
|
c.Debug = args.Debug
|
|
|
|
c.EnableDoh = args.EnableDoh
|
2024-08-25 09:09:58 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
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-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("")
|
2024-08-23 12:17:35 +00:00
|
|
|
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("")
|
2024-08-25 09:09:58 +00:00
|
|
|
fmt.Println("Press 'CTRL + c to quit'")
|
|
|
|
fmt.Println("")
|
2023-05-07 05:57:37 +00:00
|
|
|
}
|