From e64fcce417311fe22e7f2afe07743fcbc1d7de9a Mon Sep 17 00:00:00 2001 From: kac- <6b6163@gmail.com> Date: Wed, 6 Jun 2018 18:25:55 +0200 Subject: [PATCH] cmd: frps: allow_ports option --- cmd/frps/root.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/cmd/frps/root.go b/cmd/frps/root.go index fb19f532..a874db44 100644 --- a/cmd/frps/root.go +++ b/cmd/frps/root.go @@ -25,6 +25,7 @@ import ( "github.com/fatedier/frp/models/config" "github.com/fatedier/frp/server" "github.com/fatedier/frp/utils/log" + "github.com/fatedier/frp/utils/util" "github.com/fatedier/frp/utils/version" ) @@ -84,6 +85,7 @@ func init() { rootCmd.PersistentFlags().StringVarP(&token, "token", "t", "", "auth token") rootCmd.PersistentFlags().Int64VarP(&authTimeout, "auth_timeout", "", 900, "auth timeout") rootCmd.PersistentFlags().StringVarP(&subDomainHost, "subdomain_host", "", "", "subdomain host") + rootCmd.PersistentFlags().StringVarP(&allowPorts, "allow_ports", "", "", "allow ports") rootCmd.PersistentFlags().Int64VarP(&maxPortsPerClient, "max_ports_per_client", "", 0, "max ports per client") } @@ -176,6 +178,18 @@ func parseServerCommonCfgFromCmd() (err error) { g.GlbServerCfg.Token = token g.GlbServerCfg.AuthTimeout = authTimeout g.GlbServerCfg.SubDomainHost = subDomainHost + if len(allowPorts) > 0 { + // e.g. 1000-2000,2001,2002,3000-4000 + ports, errRet := util.ParseRangeNumbers(allowPorts) + if errRet != nil { + err = fmt.Errorf("Parse conf error: allow_ports: %v", errRet) + return + } + + for _, port := range ports { + g.GlbServerCfg.AllowPorts[int(port)] = struct{}{} + } + } g.GlbServerCfg.MaxPortsPerClient = maxPortsPerClient return }