From f8c67951196c248119dff3095f025beeb6bf6068 Mon Sep 17 00:00:00 2001 From: Guy Lewin Date: Mon, 10 Feb 2020 19:29:57 +0200 Subject: [PATCH] DetailedErrorsToClient - only send detailed error info if this is on --- models/config/server_common.go | 66 +++++++++++++++++++--------------- server/control.go | 6 +++- server/service.go | 12 +++++-- 3 files changed, 53 insertions(+), 31 deletions(-) diff --git a/models/config/server_common.go b/models/config/server_common.go index df6b7a10..d4faf8c3 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 "". @@ -143,34 +146,35 @@ 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, - 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, + HeartBeatTimeout: 90, + UserConnTimeout: 10, + Custom404Page: "", + HTTPPlugins: make(map[string]plugin.HTTPPluginOptions), } } @@ -314,6 +318,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..bb06ccf6 100644 --- a/server/control.go +++ b/server/control.go @@ -438,7 +438,11 @@ func (ctl *Control) manager() { ProxyName: m.ProxyName, } if err != nil { - resp.Error = err.Error() + if ctl.serverCfg.DetailedErrorsToClient { + resp.Error = err.Error() + } else { + resp.Error = fmt.Sprintf("new proxy [%s] error", m.ProxyName) + } xl.Warn("new proxy [%s] error: %v", m.ProxyName, err) } else { resp.RemoteAddr = remoteAddr diff --git a/server/service.go b/server/service.go index 122555af..dd29bbc8 100644 --- a/server/service.go +++ b/server/service.go @@ -320,9 +320,13 @@ func (svr *Service) HandleListener(l net.Listener) { // Otherwise send success message in control's work goroutine. if err != nil { xl.Warn("register control error: %v", err) + errStr := "register control error" + if svr.cfg.DetailedErrorsToClient { + errStr = err.Error() + } msg.WriteMsg(conn, &msg.LoginResp{ Version: version.Full(), - Error: err.Error(), + Error: errStr, }) conn.Close() } @@ -331,9 +335,13 @@ func (svr *Service) HandleListener(l net.Listener) { case *msg.NewVisitorConn: if err = svr.RegisterVisitorConn(conn, m); err != nil { xl.Warn("register visitor conn error: %v", err) + errStr := "register visitor conn error" + if svr.cfg.DetailedErrorsToClient { + errStr = err.Error() + } msg.WriteMsg(conn, &msg.NewVisitorConnResp{ ProxyName: m.ProxyName, - Error: err.Error(), + Error: errStr, }) conn.Close() } else {