diff --git a/models/config/server_common.go b/models/config/server_common.go index 58a72528..20e92f9c 100644 --- a/models/config/server_common.go +++ b/models/config/server_common.go @@ -98,6 +98,9 @@ type ServerCommonConf struct { // DisableLogColor disables log colors when LogWay == "console" when set to // true. By default, this value is false. DisableLogColor bool `json:"disable_log_color"` + // DetailedErrorsToClient defines whether to send the specific error (with + // debug info) to frpc. By default, this value is true. + DetailedErrorsToClient bool `json:"detailed_errors_to_client"` // Token specifies the authorization token used to authenticate keys // received from clients. Clients must have a matching token to be // authorized to use the server. By default, this value is "". @@ -146,35 +149,36 @@ type ServerCommonConf struct { // defaults. func GetDefaultServerConf() ServerCommonConf { return ServerCommonConf{ - BindAddr: "0.0.0.0", - BindPort: 7000, - BindUdpPort: 0, - KcpBindPort: 0, - ProxyBindAddr: "0.0.0.0", - VhostHttpPort: 0, - VhostHttpsPort: 0, - VhostHttpTimeout: 60, - DashboardAddr: "0.0.0.0", - DashboardPort: 0, - DashboardUser: "admin", - DashboardPwd: "admin", - AssetsDir: "", - LogFile: "console", - LogWay: "console", - LogLevel: "info", - LogMaxDays: 3, - DisableLogColor: false, - Token: "", - SubDomainHost: "", - TcpMux: true, - AllowPorts: make(map[int]struct{}), - MaxPoolCount: 5, - MaxPortsPerClient: 0, - TlsOnly: false, - HeartBeatTimeout: 90, - UserConnTimeout: 10, - Custom404Page: "", - HTTPPlugins: make(map[string]plugin.HTTPPluginOptions), + BindAddr: "0.0.0.0", + BindPort: 7000, + BindUdpPort: 0, + KcpBindPort: 0, + ProxyBindAddr: "0.0.0.0", + VhostHttpPort: 0, + VhostHttpsPort: 0, + VhostHttpTimeout: 60, + DashboardAddr: "0.0.0.0", + DashboardPort: 0, + DashboardUser: "admin", + DashboardPwd: "admin", + AssetsDir: "", + LogFile: "console", + LogWay: "console", + LogLevel: "info", + LogMaxDays: 3, + DisableLogColor: false, + DetailedErrorsToClient: true, + Token: "", + SubDomainHost: "", + TcpMux: true, + AllowPorts: make(map[int]struct{}), + MaxPoolCount: 5, + MaxPortsPerClient: 0, + TlsOnly: false, + HeartBeatTimeout: 90, + UserConnTimeout: 10, + Custom404Page: "", + HTTPPlugins: make(map[string]plugin.HTTPPluginOptions), } } @@ -318,6 +322,12 @@ func UnmarshalServerConfFromIni(content string) (cfg ServerCommonConf, err error cfg.DisableLogColor = true } + if tmpStr, ok = conf.Get("common", "detailed_errors_to_client"); ok && tmpStr == "false" { + cfg.DetailedErrorsToClient = false + } else { + cfg.DetailedErrorsToClient = true + } + cfg.Token, _ = conf.Get("common", "token") if allowPortsStr, ok := conf.Get("common", "allow_ports"); ok { diff --git a/server/control.go b/server/control.go index e5e4901c..4b9227ab 100644 --- a/server/control.go +++ b/server/control.go @@ -31,6 +31,7 @@ import ( "github.com/fatedier/frp/server/controller" "github.com/fatedier/frp/server/proxy" "github.com/fatedier/frp/server/stats" + "github.com/fatedier/frp/utils/util" "github.com/fatedier/frp/utils/version" "github.com/fatedier/frp/utils/xlog" @@ -438,8 +439,8 @@ func (ctl *Control) manager() { ProxyName: m.ProxyName, } if err != nil { - resp.Error = err.Error() xl.Warn("new proxy [%s] error: %v", m.ProxyName, err) + resp.Error = util.GenerateResponseErrorString(fmt.Sprintf("new proxy [%s] error", m.ProxyName), err, ctl.serverCfg.DetailedErrorsToClient) } else { resp.RemoteAddr = remoteAddr xl.Info("new proxy [%s] success", m.ProxyName) diff --git a/server/service.go b/server/service.go index 314d59bd..1ad7e281 100644 --- a/server/service.go +++ b/server/service.go @@ -322,7 +322,7 @@ func (svr *Service) HandleListener(l net.Listener) { xl.Warn("register control error: %v", err) msg.WriteMsg(conn, &msg.LoginResp{ Version: version.Full(), - Error: err.Error(), + Error: util.GenerateResponseErrorString("register control error", err, svr.cfg.DetailedErrorsToClient), }) conn.Close() } @@ -333,7 +333,7 @@ func (svr *Service) HandleListener(l net.Listener) { xl.Warn("register visitor conn error: %v", err) msg.WriteMsg(conn, &msg.NewVisitorConnResp{ ProxyName: m.ProxyName, - Error: err.Error(), + Error: util.GenerateResponseErrorString("register visitor conn error", err, svr.cfg.DetailedErrorsToClient), }) conn.Close() } else { diff --git a/utils/util/util.go b/utils/util/util.go index 7ea4e83c..5b30d543 100644 --- a/utils/util/util.go +++ b/utils/util/util.go @@ -101,3 +101,11 @@ func ParseRangeNumbers(rangeStr string) (numbers []int64, err error) { } return } + +func GenerateResponseErrorString(summary string, err error, detailed bool) string { + if detailed { + return err.Error() + } else { + return summary + } +}