Merge pull request #1644 from GuyLewin/feature/detailed-errors-to-client

DetailedErrorsToClient - only send detailed error info if this is on
This commit is contained in:
fatedier 2020-02-12 10:39:03 +08:00 committed by GitHub
commit 83d80857fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 32 deletions

View File

@ -98,6 +98,9 @@ type ServerCommonConf struct {
// DisableLogColor disables log colors when LogWay == "console" when set to // DisableLogColor disables log colors when LogWay == "console" when set to
// true. By default, this value is false. // true. By default, this value is false.
DisableLogColor bool `json:"disable_log_color"` 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 // Token specifies the authorization token used to authenticate keys
// received from clients. Clients must have a matching token to be // received from clients. Clients must have a matching token to be
// authorized to use the server. By default, this value is "". // authorized to use the server. By default, this value is "".
@ -146,35 +149,36 @@ type ServerCommonConf struct {
// defaults. // defaults.
func GetDefaultServerConf() ServerCommonConf { func GetDefaultServerConf() ServerCommonConf {
return ServerCommonConf{ return ServerCommonConf{
BindAddr: "0.0.0.0", BindAddr: "0.0.0.0",
BindPort: 7000, BindPort: 7000,
BindUdpPort: 0, BindUdpPort: 0,
KcpBindPort: 0, KcpBindPort: 0,
ProxyBindAddr: "0.0.0.0", ProxyBindAddr: "0.0.0.0",
VhostHttpPort: 0, VhostHttpPort: 0,
VhostHttpsPort: 0, VhostHttpsPort: 0,
VhostHttpTimeout: 60, VhostHttpTimeout: 60,
DashboardAddr: "0.0.0.0", DashboardAddr: "0.0.0.0",
DashboardPort: 0, DashboardPort: 0,
DashboardUser: "admin", DashboardUser: "admin",
DashboardPwd: "admin", DashboardPwd: "admin",
AssetsDir: "", AssetsDir: "",
LogFile: "console", LogFile: "console",
LogWay: "console", LogWay: "console",
LogLevel: "info", LogLevel: "info",
LogMaxDays: 3, LogMaxDays: 3,
DisableLogColor: false, DisableLogColor: false,
Token: "", DetailedErrorsToClient: true,
SubDomainHost: "", Token: "",
TcpMux: true, SubDomainHost: "",
AllowPorts: make(map[int]struct{}), TcpMux: true,
MaxPoolCount: 5, AllowPorts: make(map[int]struct{}),
MaxPortsPerClient: 0, MaxPoolCount: 5,
TlsOnly: false, MaxPortsPerClient: 0,
HeartBeatTimeout: 90, TlsOnly: false,
UserConnTimeout: 10, HeartBeatTimeout: 90,
Custom404Page: "", UserConnTimeout: 10,
HTTPPlugins: make(map[string]plugin.HTTPPluginOptions), Custom404Page: "",
HTTPPlugins: make(map[string]plugin.HTTPPluginOptions),
} }
} }
@ -318,6 +322,12 @@ func UnmarshalServerConfFromIni(content string) (cfg ServerCommonConf, err error
cfg.DisableLogColor = true 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") cfg.Token, _ = conf.Get("common", "token")
if allowPortsStr, ok := conf.Get("common", "allow_ports"); ok { if allowPortsStr, ok := conf.Get("common", "allow_ports"); ok {

View File

@ -31,6 +31,7 @@ import (
"github.com/fatedier/frp/server/controller" "github.com/fatedier/frp/server/controller"
"github.com/fatedier/frp/server/proxy" "github.com/fatedier/frp/server/proxy"
"github.com/fatedier/frp/server/stats" "github.com/fatedier/frp/server/stats"
"github.com/fatedier/frp/utils/util"
"github.com/fatedier/frp/utils/version" "github.com/fatedier/frp/utils/version"
"github.com/fatedier/frp/utils/xlog" "github.com/fatedier/frp/utils/xlog"
@ -438,8 +439,8 @@ func (ctl *Control) manager() {
ProxyName: m.ProxyName, ProxyName: m.ProxyName,
} }
if err != nil { if err != nil {
resp.Error = err.Error()
xl.Warn("new proxy [%s] error: %v", m.ProxyName, err) 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 { } else {
resp.RemoteAddr = remoteAddr resp.RemoteAddr = remoteAddr
xl.Info("new proxy [%s] success", m.ProxyName) xl.Info("new proxy [%s] success", m.ProxyName)

View File

@ -322,7 +322,7 @@ func (svr *Service) HandleListener(l net.Listener) {
xl.Warn("register control error: %v", err) xl.Warn("register control error: %v", err)
msg.WriteMsg(conn, &msg.LoginResp{ msg.WriteMsg(conn, &msg.LoginResp{
Version: version.Full(), Version: version.Full(),
Error: err.Error(), Error: util.GenerateResponseErrorString("register control error", err, svr.cfg.DetailedErrorsToClient),
}) })
conn.Close() conn.Close()
} }
@ -333,7 +333,7 @@ func (svr *Service) HandleListener(l net.Listener) {
xl.Warn("register visitor conn error: %v", err) xl.Warn("register visitor conn error: %v", err)
msg.WriteMsg(conn, &msg.NewVisitorConnResp{ msg.WriteMsg(conn, &msg.NewVisitorConnResp{
ProxyName: m.ProxyName, ProxyName: m.ProxyName,
Error: err.Error(), Error: util.GenerateResponseErrorString("register visitor conn error", err, svr.cfg.DetailedErrorsToClient),
}) })
conn.Close() conn.Close()
} else { } else {

View File

@ -101,3 +101,11 @@ func ParseRangeNumbers(rangeStr string) (numbers []int64, err error) {
} }
return return
} }
func GenerateResponseErrorString(summary string, err error, detailed bool) string {
if detailed {
return err.Error()
} else {
return summary
}
}