-
Notifications
You must be signed in to change notification settings - Fork 4
/
args.go
81 lines (65 loc) · 2.78 KB
/
args.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
// Defines the command line parsing function and global variables
import (
"flag"
"fmt"
"os"
)
var gArgLogPath string
var gArgAuditPath string
var gArgAuditBoth bool
var gArgLogBoth bool
var gArgNoAuditBool bool
var gArgConfigPath string
var gArgPACPath string
var gArgRoutingConfigPath string
var gArgListen string
var gArgQuietBool bool
var gArgVerboseBool bool
var gArgHttpListen string
var gArgCustomHosts string
func cmdlineError(a ...interface{}) {
fmt.Fprintln(os.Stderr, a...)
os.Exit(1)
}
// parseArgs parses the command line arguments, performs some checks, and store them in the associated global variables
func parseArgs() {
flag.BoolVar(&gArgQuietBool, "q", false, "Quiet mode")
flag.BoolVar(&gArgVerboseBool, "v", false, "Verbose mode")
flag.StringVar(&gArgListen, "socks", "127.0.0.1:8851", "Address and port to listen on (format: local_addr:local_port)")
flag.StringVar(&gArgHttpListen, "http", "", "Address and port to listen on for HTTP CONNECT input (format: local_addr:local_port) (no http listener by default)")
flag.StringVar(&gArgAuditPath, "audit-file", "", "File to output audit traces. Output to STDOUT if empty")
flag.BoolVar(&gArgAuditBoth, "audit-both", false, "Output audit traces to both -audit-file and STDOUT.")
flag.StringVar(&gArgLogPath, "log-file", "", "File to output logs. Output to STDOUT if empty")
flag.BoolVar(&gArgLogBoth, "log-both", false, "Output logs to both -log-file and STDOUT.")
flag.StringVar(&gArgConfigPath, "c", "./bbs.json", "JSON configuration file path")
flag.BoolVar(&gArgNoAuditBool, "no-audit", false, "No audit traces mode")
flag.StringVar(&gArgCustomHosts, "custom-hosts", "", "File to define custom hosts IP (like /etc/hosts)")
if gPACcompiled {
flag.StringVar(&gArgRoutingConfigPath, "routes", "", "JSON routing configuration file path")
flag.StringVar(&gArgPACPath, "pac", "", "PAC script file path")
} else {
flag.StringVar(&gArgRoutingConfigPath, "routes", "./routes.json", "JSON routing configuration file path")
}
flag.Parse()
if gArgQuietBool && gArgVerboseBool {
cmdlineError("Arguments -q and -v cannot be used together")
}
if gArgAuditBoth && gArgAuditPath == "" {
cmdlineError("-audit-file must be defined if -audit-both is set")
}
if gArgLogBoth && gArgLogPath == "" {
cmdlineError("-log-file must be defined if -log-both is set")
}
if (gArgNoAuditBool && gArgAuditBoth) || (gArgNoAuditBool && gArgAuditPath != "") {
cmdlineError("Arguments -no-audit and -audit-file/-audit-both cannot be used together")
}
if gPACcompiled {
if (gArgPACPath != "") && (gArgRoutingConfigPath != "") {
cmdlineError("Arguments -pac and -routes cannot be used together")
}
if (gArgPACPath == "") && (gArgRoutingConfigPath == "") {
cmdlineError("At least one of -pac and -routes must be defined")
}
}
}