frpc: support --vhost-http-port,--vhost-https-port,--privilege-token command

This commit is contained in:
袁凡迪 2017-09-07 00:29:16 +08:00
parent c48a89731a
commit eea729aefe

View File

@ -32,17 +32,23 @@ import (
var usage string = `frps is the server of frp var usage string = `frps is the server of frp
Usage: Usage:
frps [-c config_file] [-L log_file] [--log-level=<log_level>] [--addr=<bind_addr>] frps [--disable-conf=<disable_conf>] [-c config_file] [-L log_file] [--log-level=<log_level>]
frps [--addr=<bind_addr>] [--vhost-https-port=<vhost_https_port>] [--vhost-http-port=<vhost_http_port>]
frps [--privilege-token=<privilege_token>]
frps -h | --help frps -h | --help
frps -v | --version frps -v | --version
Options: Options:
-c config_file set config file --disable-conf if true then use command line to config
-L log_file set output log file, including console -c config_file set config file
--log-level=<log_level> set log level: debug, info, warn, error -L log_file set output log file, including console
--addr=<bind_addr> listen addr for client, example: 0.0.0.0:7000 --log-level=<log_level> set log level: debug, info, warn, error
-h --help show this screen --addr=<bind_addr> listen addr for client, example: 0.0.0.0:7000
-v --version show version --vhost-http-port=<vhost_http_port> set vhost_http_port
--vhost-https-port=<vhost_https_port> set vhost_https_port
--privilege-token=<privilege_token> enable privilege_mode and set privilege_token
-h --help show this screen
-v --version show version
` `
func main() { func main() {
@ -51,19 +57,22 @@ func main() {
// the configures parsed from file will be replaced by those from command line if exist // the configures parsed from file will be replaced by those from command line if exist
args, err := docopt.Parse(usage, nil, true, version.Full(), false) args, err := docopt.Parse(usage, nil, true, version.Full(), false)
if args["-c"] != nil { if args["--disable-conf"] == nil || args["--disable-conf"].(string) != "true" {
confFile = args["-c"].(string) if args["-c"] != nil {
} confFile = args["-c"].(string)
}
conf, err := ini.LoadFile(confFile) conf, err := ini.LoadFile(confFile)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
os.Exit(1) os.Exit(1)
} }
config.ServerCommonCfg, err = config.LoadServerCommonConf(conf) config.ServerCommonCfg, err = config.LoadServerCommonConf(conf)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
os.Exit(1) os.Exit(1)
}
} else {
config.ServerCommonCfg = config.GetDefaultServerCommonConf()
} }
if args["-L"] != nil { if args["-L"] != nil {
@ -94,6 +103,29 @@ func main() {
config.ServerCommonCfg.BindPort = bindPort config.ServerCommonCfg.BindPort = bindPort
} }
if args["--vhost-http-port"] != nil {
vhostHttpPort, err := strconv.ParseInt(args["--vhost-http-port"].(string), 10, 64)
if err != nil || vhostHttpPort < 0 || vhostHttpPort > 65535 {
fmt.Println("--vhost_http_port error,allow range 0 - 65535")
os.Exit(1)
}
config.ServerCommonCfg.VhostHttpPort = vhostHttpPort
}
if args["--vhost-https-port"] != nil {
vhostHttpsPort, err := strconv.ParseInt(args["--vhost-https-port"].(string), 10, 64)
if err != nil || vhostHttpsPort < 0 || vhostHttpsPort > 65535 {
fmt.Println("--vhost_http_port error,allow range 0 - 65535")
os.Exit(1)
}
config.ServerCommonCfg.VhostHttpsPort = vhostHttpsPort
}
if args["--privilege-token"] != nil {
config.ServerCommonCfg.PrivilegeMode = true
config.ServerCommonCfg.PrivilegeToken = args["--privilege-token"].(string)
}
if args["-v"] != nil { if args["-v"] != nil {
if args["-v"].(bool) { if args["-v"].(bool) {
fmt.Println(version.Full()) fmt.Println(version.Full())