change config options

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

@ -8,17 +8,17 @@ import (
func loadConfig() *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.StringVar(&config.addr, "addr", ":9080", "proxy 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.StringVar(&config.dump, "dump", "", "dump filename")
flag.IntVar(&config.dumpLevel, "dump_level", 0, "dump level: 0 - header, 1 - header + body")
flag.StringVar(&config.mapperDir, "mapper_dir", "", "mapper files dirpath")
flag.StringVar(&config.certPath, "cert_path", "", "path of generate cert files")
flag.Var((*arrayValue)(&config.ignoreHosts), "ignore_hosts", "a list of ignore hosts")
flag.Var((*arrayValue)(&config.allowHosts), "allow_hosts", "a list of allow hosts")
flag.BoolVar(&config.Version, "version", false, "show version")
flag.StringVar(&config.Addr, "addr", ":9080", "proxy 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.Var((*arrayValue)(&config.IgnoreHosts), "ignore_hosts", "a list of ignore hosts")
flag.Var((*arrayValue)(&config.AllowHosts), "allow_hosts", "a list of allow hosts")
flag.StringVar(&config.CertPath, "cert_path", "", "path of generate cert files")
flag.IntVar(&config.Debug, "debug", 0, "debug mode: 1 - print debug log, 2 - show debug from")
flag.StringVar(&config.Dump, "dump", "", "dump filename")
flag.IntVar(&config.DumpLevel, "dump_level", 0, "dump level: 0 - header, 1 - header + body")
flag.StringVar(&config.MapperDir, "mapper_dir", "", "mapper files dirpath")
flag.Parse()
return config

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

Loading…
Cancel
Save