diff --git a/cmd/frpc/main.go b/cmd/frpc/main.go index ba3d932..443c110 100644 --- a/cmd/frpc/main.go +++ b/cmd/frpc/main.go @@ -15,6 +15,9 @@ package main import ( + "math/rand" + "time" + _ "github.com/fatedier/frp/assets/frpc/statik" "github.com/fatedier/frp/cmd/frpc/sub" @@ -23,6 +26,7 @@ import ( func main() { crypto.DefaultSalt = "frp" + rand.Seed(time.Now().UnixNano()) sub.Execute() } diff --git a/cmd/frpc/sub/http.go b/cmd/frpc/sub/http.go index 08e915c..6e682e6 100644 --- a/cmd/frpc/sub/http.go +++ b/cmd/frpc/sub/http.go @@ -33,6 +33,7 @@ func init() { httpCmd.PersistentFlags().StringVarP(&logLevel, "log_level", "", "info", "log level") httpCmd.PersistentFlags().StringVarP(&logFile, "log_file", "", "console", "console or file path") httpCmd.PersistentFlags().IntVarP(&logMaxDays, "log_max_days", "", 3, "log file reversed days") + httpCmd.PersistentFlags().BoolVarP(&disableLogColor, "disable_log_color", "", false, "disable log color in console") httpCmd.PersistentFlags().StringVarP(&proxyName, "proxy_name", "n", "", "proxy name") httpCmd.PersistentFlags().StringVarP(&localIp, "local_ip", "i", "127.0.0.1", "local ip") diff --git a/cmd/frpc/sub/https.go b/cmd/frpc/sub/https.go index 5eb6a7d..6fc0615 100644 --- a/cmd/frpc/sub/https.go +++ b/cmd/frpc/sub/https.go @@ -33,6 +33,7 @@ func init() { httpsCmd.PersistentFlags().StringVarP(&logLevel, "log_level", "", "info", "log level") httpsCmd.PersistentFlags().StringVarP(&logFile, "log_file", "", "console", "console or file path") httpsCmd.PersistentFlags().IntVarP(&logMaxDays, "log_max_days", "", 3, "log file reversed days") + httpsCmd.PersistentFlags().BoolVarP(&disableLogColor, "disable_log_color", "", false, "disable log color in console") httpsCmd.PersistentFlags().StringVarP(&proxyName, "proxy_name", "n", "", "proxy name") httpsCmd.PersistentFlags().StringVarP(&localIp, "local_ip", "i", "127.0.0.1", "local ip") diff --git a/cmd/frpc/sub/root.go b/cmd/frpc/sub/root.go index 61d9b3d..157206f 100644 --- a/cmd/frpc/sub/root.go +++ b/cmd/frpc/sub/root.go @@ -43,13 +43,14 @@ var ( cfgFile string showVersion bool - serverAddr string - user string - protocol string - token string - logLevel string - logFile string - logMaxDays int + serverAddr string + user string + protocol string + token string + logLevel string + logFile string + logMaxDays int + disableLogColor bool proxyName string localIp string @@ -165,6 +166,7 @@ func parseClientCommonCfgFromCmd() (err error) { } else { g.GlbClientCfg.LogWay = "file" } + g.GlbClientCfg.DisableLogColor = disableLogColor return nil } @@ -191,7 +193,9 @@ func runClient(cfgFilePath string) (err error) { } func startService(pxyCfgs map[string]config.ProxyConf, visitorCfgs map[string]config.VisitorConf) (err error) { - log.InitLog(g.GlbClientCfg.LogWay, g.GlbClientCfg.LogFile, g.GlbClientCfg.LogLevel, g.GlbClientCfg.LogMaxDays) + log.InitLog(g.GlbClientCfg.LogWay, g.GlbClientCfg.LogFile, g.GlbClientCfg.LogLevel, + g.GlbClientCfg.LogMaxDays, g.GlbClientCfg.DisableLogColor) + if g.GlbClientCfg.DnsServer != "" { s := g.GlbClientCfg.DnsServer if !strings.Contains(s, ":") { diff --git a/cmd/frpc/sub/stcp.go b/cmd/frpc/sub/stcp.go index c91040e..610fd73 100644 --- a/cmd/frpc/sub/stcp.go +++ b/cmd/frpc/sub/stcp.go @@ -32,6 +32,7 @@ func init() { stcpCmd.PersistentFlags().StringVarP(&logLevel, "log_level", "", "info", "log level") stcpCmd.PersistentFlags().StringVarP(&logFile, "log_file", "", "console", "console or file path") stcpCmd.PersistentFlags().IntVarP(&logMaxDays, "log_max_days", "", 3, "log file reversed days") + stcpCmd.PersistentFlags().BoolVarP(&disableLogColor, "disable_log_color", "", false, "disable log color in console") stcpCmd.PersistentFlags().StringVarP(&proxyName, "proxy_name", "n", "", "proxy name") stcpCmd.PersistentFlags().StringVarP(&role, "role", "", "server", "role") diff --git a/cmd/frpc/sub/tcp.go b/cmd/frpc/sub/tcp.go index 154db15..76a2a3c 100644 --- a/cmd/frpc/sub/tcp.go +++ b/cmd/frpc/sub/tcp.go @@ -32,6 +32,7 @@ func init() { tcpCmd.PersistentFlags().StringVarP(&logLevel, "log_level", "", "info", "log level") tcpCmd.PersistentFlags().StringVarP(&logFile, "log_file", "", "console", "console or file path") tcpCmd.PersistentFlags().IntVarP(&logMaxDays, "log_max_days", "", 3, "log file reversed days") + tcpCmd.PersistentFlags().BoolVarP(&disableLogColor, "disable_log_color", "", false, "disable log color in console") tcpCmd.PersistentFlags().StringVarP(&proxyName, "proxy_name", "n", "", "proxy name") tcpCmd.PersistentFlags().StringVarP(&localIp, "local_ip", "i", "127.0.0.1", "local ip") diff --git a/cmd/frpc/sub/udp.go b/cmd/frpc/sub/udp.go index 3572e41..f2d9d48 100644 --- a/cmd/frpc/sub/udp.go +++ b/cmd/frpc/sub/udp.go @@ -32,6 +32,7 @@ func init() { udpCmd.PersistentFlags().StringVarP(&logLevel, "log_level", "", "info", "log level") udpCmd.PersistentFlags().StringVarP(&logFile, "log_file", "", "console", "console or file path") udpCmd.PersistentFlags().IntVarP(&logMaxDays, "log_max_days", "", 3, "log file reversed days") + udpCmd.PersistentFlags().BoolVarP(&disableLogColor, "disable_log_color", "", false, "disable log color in console") udpCmd.PersistentFlags().StringVarP(&proxyName, "proxy_name", "n", "", "proxy name") udpCmd.PersistentFlags().StringVarP(&localIp, "local_ip", "i", "127.0.0.1", "local ip") diff --git a/cmd/frpc/sub/xtcp.go b/cmd/frpc/sub/xtcp.go index c15ac5a..5ba944e 100644 --- a/cmd/frpc/sub/xtcp.go +++ b/cmd/frpc/sub/xtcp.go @@ -32,6 +32,7 @@ func init() { xtcpCmd.PersistentFlags().StringVarP(&logLevel, "log_level", "", "info", "log level") xtcpCmd.PersistentFlags().StringVarP(&logFile, "log_file", "", "console", "console or file path") xtcpCmd.PersistentFlags().IntVarP(&logMaxDays, "log_max_days", "", 3, "log file reversed days") + xtcpCmd.PersistentFlags().BoolVarP(&disableLogColor, "disable_log_color", "", false, "disable log color in console") xtcpCmd.PersistentFlags().StringVarP(&proxyName, "proxy_name", "n", "", "proxy name") xtcpCmd.PersistentFlags().StringVarP(&role, "role", "", "server", "role") diff --git a/cmd/frps/main.go b/cmd/frps/main.go index 4253aed..8264dd7 100644 --- a/cmd/frps/main.go +++ b/cmd/frps/main.go @@ -15,6 +15,9 @@ package main import ( + "math/rand" + "time" + "github.com/fatedier/golib/crypto" _ "github.com/fatedier/frp/assets/frps/statik" @@ -22,6 +25,7 @@ import ( func main() { crypto.DefaultSalt = "frp" + rand.Seed(time.Now().UnixNano()) Execute() } diff --git a/cmd/frps/root.go b/cmd/frps/root.go index 4dcd889..abad271 100644 --- a/cmd/frps/root.go +++ b/cmd/frps/root.go @@ -53,6 +53,7 @@ var ( logFile string logLevel string logMaxDays int64 + disableLogColor bool token string subDomainHost string tcpMux bool @@ -80,6 +81,8 @@ func init() { rootCmd.PersistentFlags().StringVarP(&logFile, "log_file", "", "console", "log file") rootCmd.PersistentFlags().StringVarP(&logLevel, "log_level", "", "info", "log level") rootCmd.PersistentFlags().Int64VarP(&logMaxDays, "log_max_days", "", 3, "log max days") + rootCmd.PersistentFlags().BoolVarP(&disableLogColor, "disable_log_color", "", false, "disable log color in console") + rootCmd.PersistentFlags().StringVarP(&token, "token", "t", "", "auth token") rootCmd.PersistentFlags().StringVarP(&subDomainHost, "subdomain_host", "", "", "subdomain host") rootCmd.PersistentFlags().StringVarP(&allowPorts, "allow_ports", "", "", "allow ports") @@ -191,12 +194,13 @@ func parseServerCommonCfgFromCmd() (err error) { } else { g.GlbServerCfg.LogWay = "file" } + g.GlbServerCfg.DisableLogColor = disableLogColor return } func runServer() (err error) { log.InitLog(g.GlbServerCfg.LogWay, g.GlbServerCfg.LogFile, g.GlbServerCfg.LogLevel, - g.GlbServerCfg.LogMaxDays) + g.GlbServerCfg.LogMaxDays, g.GlbServerCfg.DisableLogColor) svr, err := server.NewService() if err != nil { return err diff --git a/conf/frpc_full.ini b/conf/frpc_full.ini index c84e684..90f9e41 100644 --- a/conf/frpc_full.ini +++ b/conf/frpc_full.ini @@ -18,6 +18,9 @@ log_level = info log_max_days = 3 +# disable log colors when log_file is console, default is false +disable_log_color = false + # for authentication token = 12345678 diff --git a/conf/frps_full.ini b/conf/frps_full.ini index a8c0e63..ed507ce 100644 --- a/conf/frps_full.ini +++ b/conf/frps_full.ini @@ -43,6 +43,9 @@ log_level = info log_max_days = 3 +# disable log colors when log_file is console, default is false +disable_log_color = false + # auth token token = 12345678 diff --git a/models/config/client_common.go b/models/config/client_common.go index 1cd9ffc..7b9e0c5 100644 --- a/models/config/client_common.go +++ b/models/config/client_common.go @@ -32,6 +32,7 @@ type ClientCommonConf struct { LogWay string `json:"log_way"` LogLevel string `json:"log_level"` LogMaxDays int64 `json:"log_max_days"` + DisableLogColor bool `json:"disable_log_color"` Token string `json:"token"` AdminAddr string `json:"admin_addr"` AdminPort int `json:"admin_port"` @@ -58,6 +59,7 @@ func GetDefaultClientConf() *ClientCommonConf { LogWay: "console", LogLevel: "info", LogMaxDays: 3, + DisableLogColor: false, Token: "", AdminAddr: "127.0.0.1", AdminPort: 0, @@ -106,6 +108,10 @@ func UnmarshalClientConfFromIni(defaultCfg *ClientCommonConf, content string) (c cfg.ServerPort = int(v) } + if tmpStr, ok = conf.Get("common", "disable_log_color"); ok && tmpStr == "true" { + cfg.DisableLogColor = true + } + if tmpStr, ok = conf.Get("common", "http_proxy"); ok { cfg.HttpProxy = tmpStr } diff --git a/models/config/server_common.go b/models/config/server_common.go index 1e54bdd..8e54f24 100644 --- a/models/config/server_common.go +++ b/models/config/server_common.go @@ -58,18 +58,19 @@ type ServerCommonConf struct { DashboardAddr string `json:"dashboard_addr"` // if DashboardPort equals 0, dashboard is not available - DashboardPort int `json:"dashboard_port"` - DashboardUser string `json:"dashboard_user"` - DashboardPwd string `json:"dashboard_pwd"` - AssetsDir string `json:"asserts_dir"` - LogFile string `json:"log_file"` - LogWay string `json:"log_way"` // console or file - LogLevel string `json:"log_level"` - LogMaxDays int64 `json:"log_max_days"` - Token string `json:"token"` - SubDomainHost string `json:"subdomain_host"` - TcpMux bool `json:"tcp_mux"` - Custom404Page string `json:"custom_404_page"` + DashboardPort int `json:"dashboard_port"` + DashboardUser string `json:"dashboard_user"` + DashboardPwd string `json:"dashboard_pwd"` + AssetsDir string `json:"asserts_dir"` + LogFile string `json:"log_file"` + LogWay string `json:"log_way"` // console or file + LogLevel string `json:"log_level"` + LogMaxDays int64 `json:"log_max_days"` + DisableLogColor bool `json:"disable_log_color"` + Token string `json:"token"` + SubDomainHost string `json:"subdomain_host"` + TcpMux bool `json:"tcp_mux"` + Custom404Page string `json:"custom_404_page"` AllowPorts map[int]struct{} MaxPoolCount int64 `json:"max_pool_count"` @@ -97,6 +98,7 @@ func GetDefaultServerConf() *ServerCommonConf { LogWay: "console", LogLevel: "info", LogMaxDays: 3, + DisableLogColor: false, Token: "", SubDomainHost: "", TcpMux: true, @@ -244,6 +246,10 @@ func UnmarshalServerConfFromIni(defaultCfg *ServerCommonConf, content string) (c } } + if tmpStr, ok = conf.Get("common", "disable_log_color"); ok && tmpStr == "true" { + cfg.DisableLogColor = true + } + cfg.Token, _ = conf.Get("common", "token") if allowPortsStr, ok := conf.Get("common", "allow_ports"); ok { diff --git a/tests/ci/health/health_test.go b/tests/ci/health/health_test.go index 99ee22b..f19c375 100644 --- a/tests/ci/health/health_test.go +++ b/tests/ci/health/health_test.go @@ -67,6 +67,20 @@ custom_domains = test2.com health_check_type = http health_check_interval_s = 1 health_check_url = /health + +[http3] +type = http +local_port = 15005 +custom_domains = test.balancing.com +group = test-balancing +group_key = 123 + +[http4] +type = http +local_port = 15006 +custom_domains = test.balancing.com +group = test-balancing +group_key = 123 ` func TestHealthCheck(t *testing.T) { @@ -124,6 +138,22 @@ func TestHealthCheck(t *testing.T) { defer httpSvc2.Stop() } + httpSvc3 := mock.NewHttpServer(15005, func(w http.ResponseWriter, r *http.Request) { + w.Write([]byte("http3")) + }) + err = httpSvc3.Start() + if assert.NoError(err) { + defer httpSvc3.Stop() + } + + httpSvc4 := mock.NewHttpServer(15006, func(w http.ResponseWriter, r *http.Request) { + w.Write([]byte("http4")) + }) + err = httpSvc4.Start() + if assert.NoError(err) { + defer httpSvc4.Stop() + } + time.Sleep(200 * time.Millisecond) // ****** start frps and frpc ****** @@ -244,4 +274,20 @@ func TestHealthCheck(t *testing.T) { assert.NoError(err) assert.Equal(200, code) assert.Equal("http2", body) + + // ****** load balancing type http ****** + result = make([]string, 0) + + code, body, _, err = util.SendHttpMsg("GET", "http://127.0.0.1:14000/xxx", "test.balancing.com", nil, "") + assert.NoError(err) + assert.Equal(200, code) + result = append(result, body) + + code, body, _, err = util.SendHttpMsg("GET", "http://127.0.0.1:14000/xxx", "test.balancing.com", nil, "") + assert.NoError(err) + assert.Equal(200, code) + result = append(result, body) + + assert.Contains(result, "http3") + assert.Contains(result, "http4") } diff --git a/utils/log/log.go b/utils/log/log.go index c0ce7f1..1a9033b 100644 --- a/utils/log/log.go +++ b/utils/log/log.go @@ -29,16 +29,20 @@ func init() { Log.SetLogFuncCallDepth(Log.GetLogFuncCallDepth() + 1) } -func InitLog(logWay string, logFile string, logLevel string, maxdays int64) { - SetLogFile(logWay, logFile, maxdays) +func InitLog(logWay string, logFile string, logLevel string, maxdays int64, disableLogColor bool) { + SetLogFile(logWay, logFile, maxdays, disableLogColor) SetLogLevel(logLevel) } // SetLogFile to configure log params // logWay: file or console -func SetLogFile(logWay string, logFile string, maxdays int64) { +func SetLogFile(logWay string, logFile string, maxdays int64, disableLogColor bool) { if logWay == "console" { - Log.SetLogger("console", "") + params := "" + if disableLogColor { + params = fmt.Sprintf(`{"color": false}`) + } + Log.SetLogger("console", params) } else { params := fmt.Sprintf(`{"filename": "%s", "maxdays": %d}`, logFile, maxdays) Log.SetLogger("file", params) diff --git a/utils/version/version.go b/utils/version/version.go index a4cb6c0..7a73de8 100644 --- a/utils/version/version.go +++ b/utils/version/version.go @@ -19,7 +19,7 @@ import ( "strings" ) -var version string = "0.28.2" +var version string = "0.29.0" func Full() string { return version