change config options

addon-dailer
lqqyt2423 2 years ago
parent 29dd649d8e
commit 3ca08c33b1

@ -8,17 +8,17 @@ import (
func loadConfig() *Config { func loadConfig() *Config {
config := new(Config) config := new(Config)
flag.IntVar(&config.debug, "debug", 0, "debug mode: 1 - print debug log, 2 - show debug from") flag.BoolVar(&config.Version, "version", false, "show version")
flag.BoolVar(&config.version, "version", false, "show version") flag.StringVar(&config.Addr, "addr", ":9080", "proxy listen addr")
flag.StringVar(&config.addr, "addr", ":9080", "proxy listen addr") flag.StringVar(&config.WebAddr, "web_addr", ":9081", "web interface listen addr")
flag.StringVar(&config.webAddr, "web_addr", ":9081", "web interface listen addr") flag.BoolVar(&config.SslInsecure, "ssl_insecure", false, "not verify upstream server SSL/TLS certificates.")
flag.BoolVar(&config.sslInsecure, "ssl_insecure", false, "not verify upstream server SSL/TLS certificates.") flag.Var((*arrayValue)(&config.IgnoreHosts), "ignore_hosts", "a list of ignore hosts")
flag.StringVar(&config.dump, "dump", "", "dump filename") flag.Var((*arrayValue)(&config.AllowHosts), "allow_hosts", "a list of allow hosts")
flag.IntVar(&config.dumpLevel, "dump_level", 0, "dump level: 0 - header, 1 - header + body") flag.StringVar(&config.CertPath, "cert_path", "", "path of generate cert files")
flag.StringVar(&config.mapperDir, "mapper_dir", "", "mapper files dirpath") flag.IntVar(&config.Debug, "debug", 0, "debug mode: 1 - print debug log, 2 - show debug from")
flag.StringVar(&config.certPath, "cert_path", "", "path of generate cert files") flag.StringVar(&config.Dump, "dump", "", "dump filename")
flag.Var((*arrayValue)(&config.ignoreHosts), "ignore_hosts", "a list of ignore hosts") flag.IntVar(&config.DumpLevel, "dump_level", 0, "dump level: 0 - header, 1 - header + body")
flag.Var((*arrayValue)(&config.allowHosts), "allow_hosts", "a list of allow hosts") flag.StringVar(&config.MapperDir, "mapper_dir", "", "mapper files dirpath")
flag.Parse() flag.Parse()
return config return config

@ -13,33 +13,29 @@ import (
) )
type Config struct { type Config struct {
debug int Version bool // show version
version bool Addr string // proxy listen addr
certPath string WebAddr string // web interface listen addr
SslInsecure bool // not verify upstream server SSL/TLS certificates.
addr string IgnoreHosts []string // a list of ignore hosts
webAddr string AllowHosts []string // a list of allow hosts
sslInsecure bool CertPath string // path of generate cert files
Debug int // debug mode: 1 - print debug log, 2 - show debug from
dump string // dump filename Dump string // dump filename
dumpLevel int // dump level DumpLevel int // dump level: 0 - header, 1 - header + body
MapperDir string // mapper files dirpath
mapperDir string
ignoreHosts []string
allowHosts []string
} }
func main() { func main() {
config := loadConfig() config := loadConfig()
if config.debug > 0 { if config.Debug > 0 {
rawLog.SetFlags(rawLog.LstdFlags | rawLog.Lshortfile) rawLog.SetFlags(rawLog.LstdFlags | rawLog.Lshortfile)
log.SetLevel(log.DebugLevel) log.SetLevel(log.DebugLevel)
} else { } else {
log.SetLevel(log.InfoLevel) log.SetLevel(log.InfoLevel)
} }
if config.debug == 2 { if config.Debug == 2 {
log.SetReportCaller(true) log.SetReportCaller(true)
} }
log.SetOutput(os.Stdout) log.SetOutput(os.Stdout)
@ -48,11 +44,11 @@ func main() {
}) })
opts := &proxy.Options{ opts := &proxy.Options{
Debug: config.debug, Debug: config.Debug,
Addr: config.addr, Addr: config.Addr,
StreamLargeBodies: 1024 * 1024 * 5, StreamLargeBodies: 1024 * 1024 * 5,
SslInsecure: config.sslInsecure, SslInsecure: config.SslInsecure,
CaRootPath: config.certPath, CaRootPath: config.CertPath,
} }
p, err := proxy.NewProxy(opts) p, err := proxy.NewProxy(opts)
@ -60,34 +56,34 @@ func main() {
log.Fatal(err) log.Fatal(err)
} }
if config.version { if config.Version {
fmt.Println("go-mitmproxy: " + p.Version) fmt.Println("go-mitmproxy: " + p.Version)
os.Exit(0) os.Exit(0)
} }
log.Infof("go-mitmproxy version %v\n", p.Version) log.Infof("go-mitmproxy version %v\n", p.Version)
if len(config.ignoreHosts) > 0 { if len(config.IgnoreHosts) > 0 {
p.SetShouldInterceptRule(func(address string) bool { p.SetShouldInterceptRule(func(address string) bool {
return !matchHost(address, config.ignoreHosts) return !matchHost(address, config.IgnoreHosts)
}) })
} }
if len(config.allowHosts) > 0 { if len(config.AllowHosts) > 0 {
p.SetShouldInterceptRule(func(address string) bool { p.SetShouldInterceptRule(func(address string) bool {
return matchHost(address, config.allowHosts) return matchHost(address, config.AllowHosts)
}) })
} }
p.AddAddon(&proxy.LogAddon{}) p.AddAddon(&proxy.LogAddon{})
p.AddAddon(web.NewWebAddon(config.webAddr)) p.AddAddon(web.NewWebAddon(config.WebAddr))
if config.dump != "" { if config.Dump != "" {
dumper := addon.NewDumperWithFilename(config.dump, config.dumpLevel) dumper := addon.NewDumperWithFilename(config.Dump, config.DumpLevel)
p.AddAddon(dumper) p.AddAddon(dumper)
} }
if config.mapperDir != "" { if config.MapperDir != "" {
mapper := addon.NewMapper(config.mapperDir) mapper := addon.NewMapper(config.MapperDir)
p.AddAddon(mapper) p.AddAddon(mapper)
} }

Loading…
Cancel
Save