From c47dd30cf89a40cae11c1b402c3df8af3d9d67d5 Mon Sep 17 00:00:00 2001 From: berlin2123 <68841407+berlin2123@users.noreply.github.com> Date: Wed, 27 Apr 2022 16:59:27 +0800 Subject: [PATCH 01/23] Log duration of each connection Log duration of each connection, which may be used to indentify Brute_Force_Attack inside frps sever. --- server/proxy/proxy.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/server/proxy/proxy.go b/server/proxy/proxy.go index 43c2c74e..c7044b2f 100644 --- a/server/proxy/proxy.go +++ b/server/proxy/proxy.go @@ -287,6 +287,7 @@ func HandleUserTCPConnection(pxy Proxy, userConn net.Conn, serverCfg config.Serv if cfg.UseCompression { local = frpIo.WithCompression(local) } + startime := time.Now().UnixNano() / 1000000 // time in microseconds xl.Debug("join connections, workConn(l[%s] r[%s]) userConn(l[%s] r[%s])", workConn.LocalAddr().String(), workConn.RemoteAddr().String(), userConn.LocalAddr().String(), userConn.RemoteAddr().String()) @@ -297,7 +298,11 @@ func HandleUserTCPConnection(pxy Proxy, userConn net.Conn, serverCfg config.Serv metrics.Server.CloseConnection(name, proxyType) metrics.Server.AddTrafficIn(name, proxyType, inCount) metrics.Server.AddTrafficOut(name, proxyType, outCount) - xl.Debug("join connections closed") + endtime := time.Now().UnixNano() / 1000000 // time in microseconds + connection_duration := endtime - startime + //xl.Debug("join connections closed, it remains [%d]ms, workConn(l[%s] r[%s]) userConn(l[%s] r[%s])", connection_duration, + // workConn.LocalAddr().String(), workConn.RemoteAddr().String(), userConn.LocalAddr().String(), userConn.RemoteAddr().String() ) + xl.Info("connections closed, it remains [%d]ms, [%s]", connection_duration, userConn.RemoteAddr().String() ) } type Manager struct { From 39aabe6c748437833737285c90816a2de023b0b2 Mon Sep 17 00:00:00 2001 From: berlin2123 <68841407+berlin2123@users.noreply.github.com> Date: Wed, 27 Apr 2022 19:38:20 +0800 Subject: [PATCH 02/23] Update proxy.go Unit second is OK --- server/proxy/proxy.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/server/proxy/proxy.go b/server/proxy/proxy.go index c7044b2f..60c29d41 100644 --- a/server/proxy/proxy.go +++ b/server/proxy/proxy.go @@ -287,7 +287,7 @@ func HandleUserTCPConnection(pxy Proxy, userConn net.Conn, serverCfg config.Serv if cfg.UseCompression { local = frpIo.WithCompression(local) } - startime := time.Now().UnixNano() / 1000000 // time in microseconds + startime := time.Now().Unix() xl.Debug("join connections, workConn(l[%s] r[%s]) userConn(l[%s] r[%s])", workConn.LocalAddr().String(), workConn.RemoteAddr().String(), userConn.LocalAddr().String(), userConn.RemoteAddr().String()) @@ -298,11 +298,11 @@ func HandleUserTCPConnection(pxy Proxy, userConn net.Conn, serverCfg config.Serv metrics.Server.CloseConnection(name, proxyType) metrics.Server.AddTrafficIn(name, proxyType, inCount) metrics.Server.AddTrafficOut(name, proxyType, outCount) - endtime := time.Now().UnixNano() / 1000000 // time in microseconds + endtime := time.Now().Unix() connection_duration := endtime - startime - //xl.Debug("join connections closed, it remains [%d]ms, workConn(l[%s] r[%s]) userConn(l[%s] r[%s])", connection_duration, + //xl.Debug("join connections closed, it remains [%d]seconds, workConn(l[%s] r[%s]) userConn(l[%s] r[%s])", connection_duration, // workConn.LocalAddr().String(), workConn.RemoteAddr().String(), userConn.LocalAddr().String(), userConn.RemoteAddr().String() ) - xl.Info("connections closed, it remains [%d]ms, [%s]", connection_duration, userConn.RemoteAddr().String() ) + xl.Info("connections closed, it remains [%d]seconds, [%s]", connection_duration, userConn.RemoteAddr().String() ) } type Manager struct { From 3318f68b5c78483d6252dc0f8cf2f3c89af0f60f Mon Sep 17 00:00:00 2001 From: berlin2123 <68841407+berlin2123@users.noreply.github.com> Date: Sun, 29 May 2022 09:43:27 +0800 Subject: [PATCH 03/23] Update proxy.go --- server/proxy/proxy.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/server/proxy/proxy.go b/server/proxy/proxy.go index 60c29d41..5cdb673e 100644 --- a/server/proxy/proxy.go +++ b/server/proxy/proxy.go @@ -287,7 +287,7 @@ func HandleUserTCPConnection(pxy Proxy, userConn net.Conn, serverCfg config.Serv if cfg.UseCompression { local = frpIo.WithCompression(local) } - startime := time.Now().Unix() + startime := time.Now().UnixNano() / 1000000 // time in microseconds xl.Debug("join connections, workConn(l[%s] r[%s]) userConn(l[%s] r[%s])", workConn.LocalAddr().String(), workConn.RemoteAddr().String(), userConn.LocalAddr().String(), userConn.RemoteAddr().String()) @@ -298,11 +298,11 @@ func HandleUserTCPConnection(pxy Proxy, userConn net.Conn, serverCfg config.Serv metrics.Server.CloseConnection(name, proxyType) metrics.Server.AddTrafficIn(name, proxyType, inCount) metrics.Server.AddTrafficOut(name, proxyType, outCount) - endtime := time.Now().Unix() + endtime := time.Now().UnixNano() / 1000000 // time in microseconds connection_duration := endtime - startime - //xl.Debug("join connections closed, it remains [%d]seconds, workConn(l[%s] r[%s]) userConn(l[%s] r[%s])", connection_duration, + //xl.Debug("join connections closed, it remains [%d]ms, workConn(l[%s] r[%s]) userConn(l[%s] r[%s])", connection_duration, // workConn.LocalAddr().String(), workConn.RemoteAddr().String(), userConn.LocalAddr().String(), userConn.RemoteAddr().String() ) - xl.Info("connections closed, it remains [%d]seconds, [%s]", connection_duration, userConn.RemoteAddr().String() ) + xl.Info("connections closed, it remains [%d]ms, [%s]", connection_duration, userConn.RemoteAddr().String() ) } type Manager struct { From 2048d12db818214a8691fed596574c20294801da Mon Sep 17 00:00:00 2001 From: berlin2123 <68841407+berlin2123@users.noreply.github.com> Date: Thu, 9 Jun 2022 20:19:02 +0800 Subject: [PATCH 04/23] Update proxy.go --- server/proxy/proxy.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/proxy/proxy.go b/server/proxy/proxy.go index 5cdb673e..e84d195e 100644 --- a/server/proxy/proxy.go +++ b/server/proxy/proxy.go @@ -302,7 +302,7 @@ func HandleUserTCPConnection(pxy Proxy, userConn net.Conn, serverCfg config.Serv connection_duration := endtime - startime //xl.Debug("join connections closed, it remains [%d]ms, workConn(l[%s] r[%s]) userConn(l[%s] r[%s])", connection_duration, // workConn.LocalAddr().String(), workConn.RemoteAddr().String(), userConn.LocalAddr().String(), userConn.RemoteAddr().String() ) - xl.Info("connections closed, it remains [%d]ms, [%s]", connection_duration, userConn.RemoteAddr().String() ) + xl.Info("connections closed, it remains [%d]ms, r[%s]", connection_duration, userConn.RemoteAddr().String() ) } type Manager struct { From d1fe4bd314675c3d2618e0580388ba65916e2050 Mon Sep 17 00:00:00 2001 From: berlin2123 <68841407+berlin2123@users.noreply.github.com> Date: Thu, 9 Jun 2022 20:23:17 +0800 Subject: [PATCH 05/23] Update proxy.go --- server/proxy/proxy.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/proxy/proxy.go b/server/proxy/proxy.go index e84d195e..124aca50 100644 --- a/server/proxy/proxy.go +++ b/server/proxy/proxy.go @@ -300,9 +300,9 @@ func HandleUserTCPConnection(pxy Proxy, userConn net.Conn, serverCfg config.Serv metrics.Server.AddTrafficOut(name, proxyType, outCount) endtime := time.Now().UnixNano() / 1000000 // time in microseconds connection_duration := endtime - startime - //xl.Debug("join connections closed, it remains [%d]ms, workConn(l[%s] r[%s]) userConn(l[%s] r[%s])", connection_duration, - // workConn.LocalAddr().String(), workConn.RemoteAddr().String(), userConn.LocalAddr().String(), userConn.RemoteAddr().String() ) - xl.Info("connections closed, it remains [%d]ms, r[%s]", connection_duration, userConn.RemoteAddr().String() ) + xl.Debug("join connection closed, it remains [%d]ms, workConn(l[%s] r[%s]) userConn(l[%s] r[%s])", connection_duration, + workConn.LocalAddr().String(), workConn.RemoteAddr().String(), userConn.LocalAddr().String(), userConn.RemoteAddr().String() ) + xl.Info("connection closed, it remains [%d]ms, r[%s]", connection_duration, userConn.RemoteAddr().String() ) } type Manager struct { From 708149d90c8b34c143773dfc5e6a094091a144b6 Mon Sep 17 00:00:00 2001 From: berlin2123 <68841407+berlin2123@users.noreply.github.com> Date: Sun, 12 Jun 2022 16:05:58 +0800 Subject: [PATCH 06/23] Update frps_full.ini --- conf/frps_full.ini | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/conf/frps_full.ini b/conf/frps_full.ini index fecb8bf3..89ff8e72 100644 --- a/conf/frps_full.ini +++ b/conf/frps_full.ini @@ -54,6 +54,12 @@ log_level = info log_max_days = 3 +# log the duration of each connection for the connection type identified by its name +# examples, +# 'log_duration_types = ssh,rdp', it will log the duration for connection name has string 'ssh' or 'rdp'. +# 'log_duration_types = all', it will log the duration for all connections. +log_duration_types = ssh,rdp + # disable log colors when log_file is console, default is false disable_log_color = false From 7726d2902fa823dd2ba40badc851fbc111ca2be1 Mon Sep 17 00:00:00 2001 From: berlin2123 <68841407+berlin2123@users.noreply.github.com> Date: Sun, 12 Jun 2022 16:12:03 +0800 Subject: [PATCH 07/23] Log duration of each connection --- cmd/frps/root.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmd/frps/root.go b/cmd/frps/root.go index cdf92672..522a85b6 100644 --- a/cmd/frps/root.go +++ b/cmd/frps/root.go @@ -54,6 +54,7 @@ var ( logFile string logLevel string logMaxDays int64 + logDurationTypes string disableLogColor bool token string subDomainHost string @@ -84,6 +85,7 @@ 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().StringVarP(&logDurationTypes, "log_duration_types", "", "ssh,rdp", "log duration types") rootCmd.PersistentFlags().BoolVarP(&disableLogColor, "disable_log_color", "", false, "disable log color in console") rootCmd.PersistentFlags().StringVarP(&token, "token", "t", "", "auth token") @@ -170,6 +172,7 @@ func parseServerCommonCfgFromCmd() (cfg config.ServerCommonConf, err error) { cfg.LogFile = logFile cfg.LogLevel = logLevel cfg.LogMaxDays = logMaxDays + cfg.LogDurationTypes = logDurationTypes cfg.SubDomainHost = subDomainHost cfg.TLSOnly = tlsOnly From 632404176de7bbb64553110f76c88d4c6f191c51 Mon Sep 17 00:00:00 2001 From: berlin2123 <68841407+berlin2123@users.noreply.github.com> Date: Sun, 12 Jun 2022 16:29:58 +0800 Subject: [PATCH 08/23] Log duration of each connection --- pkg/config/server.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/config/server.go b/pkg/config/server.go index cf298f2e..57876cce 100644 --- a/pkg/config/server.go +++ b/pkg/config/server.go @@ -101,6 +101,11 @@ type ServerCommonConf struct { // before deletion. This is only used if LogWay == "file". By default, this // value is 0. LogMaxDays int64 `ini:"log_max_days" json:"log_max_days"` + // LogDurationTypes specifies the type of connection name, which will log + // the duration of those connections. if it is setting as 'ssh,rdp', it + // will log the duration of the name as 'ssh', 'ssh_1', 'sshname', 'rdp', + // 'rdp_test1' or 'web_my_rdp' . By default, this value is "ssh,rdp". + LogDurationTypes string `json:"log_duration_types"` // DisableLogColor disables log colors when LogWay == "console" when set to // true. By default, this value is false. DisableLogColor bool `ini:"disable_log_color" json:"disable_log_color"` @@ -199,6 +204,7 @@ func GetDefaultServerConf() ServerCommonConf { LogWay: "console", LogLevel: "info", LogMaxDays: 3, + LogDurationTypes: "ssh,rdp", DisableLogColor: false, DetailedErrorsToClient: true, SubDomainHost: "", From 105d3a453df949a2a99ab17853734896e25212b6 Mon Sep 17 00:00:00 2001 From: berlin2123 <68841407+berlin2123@users.noreply.github.com> Date: Sun, 12 Jun 2022 16:34:51 +0800 Subject: [PATCH 09/23] Update proxy.go --- server/proxy/proxy.go | 45 +++++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/server/proxy/proxy.go b/server/proxy/proxy.go index 124aca50..ee42e261 100644 --- a/server/proxy/proxy.go +++ b/server/proxy/proxy.go @@ -20,6 +20,7 @@ import ( "io" "net" "strconv" + "strings" "sync" "time" @@ -291,20 +292,40 @@ func HandleUserTCPConnection(pxy Proxy, userConn net.Conn, serverCfg config.Serv xl.Debug("join connections, workConn(l[%s] r[%s]) userConn(l[%s] r[%s])", workConn.LocalAddr().String(), workConn.RemoteAddr().String(), userConn.LocalAddr().String(), userConn.RemoteAddr().String()) - name := pxy.GetName() - proxyType := pxy.GetConf().GetBaseInfo().ProxyType - metrics.Server.OpenConnection(name, proxyType) - inCount, outCount := frpIo.Join(local, userConn) - metrics.Server.CloseConnection(name, proxyType) - metrics.Server.AddTrafficIn(name, proxyType, inCount) - metrics.Server.AddTrafficOut(name, proxyType, outCount) - endtime := time.Now().UnixNano() / 1000000 // time in microseconds - connection_duration := endtime - startime - xl.Debug("join connection closed, it remains [%d]ms, workConn(l[%s] r[%s]) userConn(l[%s] r[%s])", connection_duration, - workConn.LocalAddr().String(), workConn.RemoteAddr().String(), userConn.LocalAddr().String(), userConn.RemoteAddr().String() ) - xl.Info("connection closed, it remains [%d]ms, r[%s]", connection_duration, userConn.RemoteAddr().String() ) + name := pxy.GetName() + proxyType := pxy.GetConf().GetBaseInfo().ProxyType + metrics.Server.OpenConnection(name, proxyType) + inCount, outCount := frpIo.Join(local, userConn) + metrics.Server.CloseConnection(name, proxyType) + metrics.Server.AddTrafficIn(name, proxyType, inCount) + metrics.Server.AddTrafficOut(name, proxyType, outCount) + + if IsTheTypeToLog(serverCfg.LogDurationTypes, name) { + endtime := time.Now().UnixNano() / 1000000 // time in microseconds + connection_duration := endtime - startime + xl.Debug("join connection closed, it remains [%d]ms, workConn(l[%s] r[%s]) userConn(l[%s] r[%s])", connection_duration, + workConn.LocalAddr().String(), workConn.RemoteAddr().String(), userConn.LocalAddr().String(), userConn.RemoteAddr().String()) + xl.Info("connection closed, it remains [%d]ms, userConn(l[%s] r[%s])", connection_duration, + userConn.LocalAddr().String(), userConn.RemoteAddr().String()) + } else { + xl.Debug("join connection closed, userConn(l[%s] r[%s])", userConn.LocalAddr().String(), userConn.RemoteAddr().String()) + } } +func IsTheTypeToLog(LogDurationTypes string, name string) bool { + if strings.Contains(LogDurationTypes, "all") { + return true + } + thestrlist := strings.Split(LogDurationTypes, ",") + for i := 0; i < len(thestrlist); i++ { + if strings.Contains(name, thestrlist[i]) { + return true + } + } + return false +} + + type Manager struct { // proxies indexed by proxy name pxys map[string]Proxy From eccbeab2f5e1089667e5d0e1369c19fbc5b7f09f Mon Sep 17 00:00:00 2001 From: berlin2123 <68841407+berlin2123@users.noreply.github.com> Date: Sun, 12 Jun 2022 16:37:07 +0800 Subject: [PATCH 10/23] Update proxy.go --- server/proxy/proxy.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/server/proxy/proxy.go b/server/proxy/proxy.go index ee42e261..5d6132bb 100644 --- a/server/proxy/proxy.go +++ b/server/proxy/proxy.go @@ -292,13 +292,13 @@ func HandleUserTCPConnection(pxy Proxy, userConn net.Conn, serverCfg config.Serv xl.Debug("join connections, workConn(l[%s] r[%s]) userConn(l[%s] r[%s])", workConn.LocalAddr().String(), workConn.RemoteAddr().String(), userConn.LocalAddr().String(), userConn.RemoteAddr().String()) - name := pxy.GetName() - proxyType := pxy.GetConf().GetBaseInfo().ProxyType - metrics.Server.OpenConnection(name, proxyType) - inCount, outCount := frpIo.Join(local, userConn) - metrics.Server.CloseConnection(name, proxyType) - metrics.Server.AddTrafficIn(name, proxyType, inCount) - metrics.Server.AddTrafficOut(name, proxyType, outCount) + name := pxy.GetName() + proxyType := pxy.GetConf().GetBaseInfo().ProxyType + metrics.Server.OpenConnection(name, proxyType) + inCount, outCount := frpIo.Join(local, userConn) + metrics.Server.CloseConnection(name, proxyType) + metrics.Server.AddTrafficIn(name, proxyType, inCount) + metrics.Server.AddTrafficOut(name, proxyType, outCount) if IsTheTypeToLog(serverCfg.LogDurationTypes, name) { endtime := time.Now().UnixNano() / 1000000 // time in microseconds From a165076c21d0df0e537df0ad77dc555074923811 Mon Sep 17 00:00:00 2001 From: berlin2123 <68841407+berlin2123@users.noreply.github.com> Date: Sun, 12 Jun 2022 16:47:42 +0800 Subject: [PATCH 11/23] Update proxy.go --- server/proxy/proxy.go | 1 - 1 file changed, 1 deletion(-) diff --git a/server/proxy/proxy.go b/server/proxy/proxy.go index 5d6132bb..ca97d8ce 100644 --- a/server/proxy/proxy.go +++ b/server/proxy/proxy.go @@ -325,7 +325,6 @@ func IsTheTypeToLog(LogDurationTypes string, name string) bool { return false } - type Manager struct { // proxies indexed by proxy name pxys map[string]Proxy From 5ef77d8bccc0ca895909af8a16e65b399aae018c Mon Sep 17 00:00:00 2001 From: berlin2123 <68841407+berlin2123@users.noreply.github.com> Date: Sun, 12 Jun 2022 17:00:56 +0800 Subject: [PATCH 12/23] Update server_test.go --- pkg/config/server_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/config/server_test.go b/pkg/config/server_test.go index 8646ca62..bd96fe45 100644 --- a/pkg/config/server_test.go +++ b/pkg/config/server_test.go @@ -53,6 +53,7 @@ func Test_LoadServerCommonConf(t *testing.T) { log_way = file log_level = info9 log_max_days = 39 + log_duration_types = ssh,rdp disable_log_color = false detailed_errors_to_client authentication_method = token @@ -121,6 +122,7 @@ func Test_LoadServerCommonConf(t *testing.T) { LogWay: "file", LogLevel: "info9", LogMaxDays: 39, + LogDurationTypes: "ssh,rdp", DisableLogColor: false, DetailedErrorsToClient: true, HeartbeatTimeout: 99, From a04cf0f1cc33aff31ec18d38544863421d2759dc Mon Sep 17 00:00:00 2001 From: berlin2123 <68841407+berlin2123@users.noreply.github.com> Date: Sun, 12 Jun 2022 17:35:33 +0800 Subject: [PATCH 13/23] Update server.go --- pkg/config/server.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/config/server.go b/pkg/config/server.go index 57876cce..2b445bb3 100644 --- a/pkg/config/server.go +++ b/pkg/config/server.go @@ -105,7 +105,7 @@ type ServerCommonConf struct { // the duration of those connections. if it is setting as 'ssh,rdp', it // will log the duration of the name as 'ssh', 'ssh_1', 'sshname', 'rdp', // 'rdp_test1' or 'web_my_rdp' . By default, this value is "ssh,rdp". - LogDurationTypes string `json:"log_duration_types"` + LogDurationTypes string `ini:"log_duration_types" json:"log_duration_types"` // DisableLogColor disables log colors when LogWay == "console" when set to // true. By default, this value is false. DisableLogColor bool `ini:"disable_log_color" json:"disable_log_color"` From 330991ac9b540f83b17a5b660fac1a7d89dd8bf2 Mon Sep 17 00:00:00 2001 From: berlin2123 <68841407+berlin2123@users.noreply.github.com> Date: Wed, 22 Jun 2022 09:31:31 +0800 Subject: [PATCH 14/23] Update server_test.go --- pkg/config/server_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/config/server_test.go b/pkg/config/server_test.go index bd96fe45..2d2121bc 100644 --- a/pkg/config/server_test.go +++ b/pkg/config/server_test.go @@ -53,7 +53,7 @@ func Test_LoadServerCommonConf(t *testing.T) { log_way = file log_level = info9 log_max_days = 39 - log_duration_types = ssh,rdp + log_duration_types = ssh disable_log_color = false detailed_errors_to_client authentication_method = token @@ -122,7 +122,7 @@ func Test_LoadServerCommonConf(t *testing.T) { LogWay: "file", LogLevel: "info9", LogMaxDays: 39, - LogDurationTypes: "ssh,rdp", + LogDurationTypes: "ssh", DisableLogColor: false, DetailedErrorsToClient: true, HeartbeatTimeout: 99, From 24de683ed60122111d44b8ab67fb18f77022be71 Mon Sep 17 00:00:00 2001 From: berlin2123 <68841407+berlin2123@users.noreply.github.com> Date: Wed, 22 Jun 2022 09:35:58 +0800 Subject: [PATCH 15/23] Update server_test.go --- pkg/config/server_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/config/server_test.go b/pkg/config/server_test.go index 2d2121bc..bd96fe45 100644 --- a/pkg/config/server_test.go +++ b/pkg/config/server_test.go @@ -53,7 +53,7 @@ func Test_LoadServerCommonConf(t *testing.T) { log_way = file log_level = info9 log_max_days = 39 - log_duration_types = ssh + log_duration_types = ssh,rdp disable_log_color = false detailed_errors_to_client authentication_method = token @@ -122,7 +122,7 @@ func Test_LoadServerCommonConf(t *testing.T) { LogWay: "file", LogLevel: "info9", LogMaxDays: 39, - LogDurationTypes: "ssh", + LogDurationTypes: "ssh,rdp", DisableLogColor: false, DetailedErrorsToClient: true, HeartbeatTimeout: 99, From 77eaf7014f43a548eb4c1c6cc72c7bfa74df9702 Mon Sep 17 00:00:00 2001 From: berlin2123 <68841407+berlin2123@users.noreply.github.com> Date: Wed, 22 Jun 2022 09:42:07 +0800 Subject: [PATCH 16/23] Update server_test.go --- pkg/config/server_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/config/server_test.go b/pkg/config/server_test.go index bd96fe45..6da685e7 100644 --- a/pkg/config/server_test.go +++ b/pkg/config/server_test.go @@ -53,7 +53,7 @@ func Test_LoadServerCommonConf(t *testing.T) { log_way = file log_level = info9 log_max_days = 39 - log_duration_types = ssh,rdp + log_duration_types = ssh9,rdp9 disable_log_color = false detailed_errors_to_client authentication_method = token @@ -122,7 +122,7 @@ func Test_LoadServerCommonConf(t *testing.T) { LogWay: "file", LogLevel: "info9", LogMaxDays: 39, - LogDurationTypes: "ssh,rdp", + LogDurationTypes: "ssh9,rdp9", DisableLogColor: false, DetailedErrorsToClient: true, HeartbeatTimeout: 99, @@ -191,6 +191,7 @@ func Test_LoadServerCommonConf(t *testing.T) { LogWay: "console", LogLevel: "info", LogMaxDays: 3, + LogDurationTypes: "ssh,rdp", DetailedErrorsToClient: true, TCPMux: true, TCPMuxKeepaliveInterval: 60, From 47b4de091c5ebf18fcf9dba7fc4c44115be4ed24 Mon Sep 17 00:00:00 2001 From: berlin2123 <68841407+berlin2123@users.noreply.github.com> Date: Mon, 18 Jul 2022 16:47:13 +0800 Subject: [PATCH 17/23] Update root.go --- cmd/frps/root.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/frps/root.go b/cmd/frps/root.go index 522a85b6..56b65aba 100644 --- a/cmd/frps/root.go +++ b/cmd/frps/root.go @@ -54,7 +54,7 @@ var ( logFile string logLevel string logMaxDays int64 - logDurationTypes string + logDurationTypes string disableLogColor bool token string subDomainHost string From 5716df714005a152e789678867e0a5b1162d2988 Mon Sep 17 00:00:00 2001 From: berlin2123 <68841407+berlin2123@users.noreply.github.com> Date: Mon, 18 Jul 2022 16:59:35 +0800 Subject: [PATCH 18/23] Update root.go --- cmd/frps/root.go | 52 ++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/cmd/frps/root.go b/cmd/frps/root.go index 56b65aba..ee3ef5cf 100644 --- a/cmd/frps/root.go +++ b/cmd/frps/root.go @@ -37,32 +37,32 @@ var ( cfgFile string showVersion bool - bindAddr string - bindPort int - bindUDPPort int - kcpBindPort int - proxyBindAddr string - vhostHTTPPort int - vhostHTTPSPort int - vhostHTTPTimeout int64 - dashboardAddr string - dashboardPort int - dashboardUser string - dashboardPwd string - enablePrometheus bool - assetsDir string - logFile string - logLevel string - logMaxDays int64 - logDurationTypes string - disableLogColor bool - token string - subDomainHost string - tcpMux bool - allowPorts string - maxPoolCount int64 - maxPortsPerClient int64 - tlsOnly bool + bindAddr string + bindPort int + bindUDPPort int + kcpBindPort int + proxyBindAddr string + vhostHTTPPort int + vhostHTTPSPort int + vhostHTTPTimeout int64 + dashboardAddr string + dashboardPort int + dashboardUser string + dashboardPwd string + enablePrometheus bool + assetsDir string + logFile string + logLevel string + logMaxDays int64 + logDurationTypes string + disableLogColor bool + token string + subDomainHost string + tcpMux bool + allowPorts string + maxPoolCount int64 + maxPortsPerClient int64 + tlsOnly bool ) func init() { From 24d0192d559f28a67aede0f0d00ab6371b799f2e Mon Sep 17 00:00:00 2001 From: berlin2123 <68841407+berlin2123@users.noreply.github.com> Date: Thu, 13 Oct 2022 09:56:47 +0800 Subject: [PATCH 19/23] Update root.go --- cmd/frps/root.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/frps/root.go b/cmd/frps/root.go index caad6cd2..95825aa9 100644 --- a/cmd/frps/root.go +++ b/cmd/frps/root.go @@ -88,7 +88,7 @@ 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().StringVarP(&logDurationTypes, "log_duration_types", "", "ssh,rdp", "log duration types") + rootCmd.PersistentFlags().StringVarP(&logDurationTypes, "log_duration_types", "", "ssh,rdp", "log duration types") rootCmd.PersistentFlags().BoolVarP(&disableLogColor, "disable_log_color", "", false, "disable log color in console") rootCmd.PersistentFlags().StringVarP(&token, "token", "t", "", "auth token") From 8a1db433e91f186063fe89795a6eac6bbced9b33 Mon Sep 17 00:00:00 2001 From: berlin2123 <68841407+berlin2123@users.noreply.github.com> Date: Thu, 13 Oct 2022 09:59:47 +0800 Subject: [PATCH 20/23] Update root.go --- cmd/frps/root.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/frps/root.go b/cmd/frps/root.go index 95825aa9..02efb372 100644 --- a/cmd/frps/root.go +++ b/cmd/frps/root.go @@ -181,7 +181,7 @@ func parseServerCommonCfgFromCmd() (cfg config.ServerCommonConf, err error) { cfg.LogFile = logFile cfg.LogLevel = logLevel cfg.LogMaxDays = logMaxDays - cfg.LogDurationTypes = logDurationTypes + cfg.LogDurationTypes = logDurationTypes cfg.SubDomainHost = subDomainHost cfg.TLSOnly = tlsOnly From c2cbd3f3ef82a207d086596e9ca302d35d916c8c Mon Sep 17 00:00:00 2001 From: berlin2123 <68841407+berlin2123@users.noreply.github.com> Date: Thu, 13 Oct 2022 10:04:36 +0800 Subject: [PATCH 21/23] Update proxy.go --- server/proxy/proxy.go | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/server/proxy/proxy.go b/server/proxy/proxy.go index ca97d8ce..d7372e18 100644 --- a/server/proxy/proxy.go +++ b/server/proxy/proxy.go @@ -300,29 +300,29 @@ func HandleUserTCPConnection(pxy Proxy, userConn net.Conn, serverCfg config.Serv metrics.Server.AddTrafficIn(name, proxyType, inCount) metrics.Server.AddTrafficOut(name, proxyType, outCount) - if IsTheTypeToLog(serverCfg.LogDurationTypes, name) { - endtime := time.Now().UnixNano() / 1000000 // time in microseconds - connection_duration := endtime - startime - xl.Debug("join connection closed, it remains [%d]ms, workConn(l[%s] r[%s]) userConn(l[%s] r[%s])", connection_duration, - workConn.LocalAddr().String(), workConn.RemoteAddr().String(), userConn.LocalAddr().String(), userConn.RemoteAddr().String()) - xl.Info("connection closed, it remains [%d]ms, userConn(l[%s] r[%s])", connection_duration, - userConn.LocalAddr().String(), userConn.RemoteAddr().String()) - } else { - xl.Debug("join connection closed, userConn(l[%s] r[%s])", userConn.LocalAddr().String(), userConn.RemoteAddr().String()) - } + if IsTheTypeToLog(serverCfg.LogDurationTypes, name) { + endtime := time.Now().UnixNano() / 1000000 // time in microseconds + connectionDuration := endtime - startime + xl.Debug("join connection closed, it remains [%d]ms, workConn(l[%s] r[%s]) userConn(l[%s] r[%s])", connectionDuration, + workConn.LocalAddr().String(), workConn.RemoteAddr().String(), userConn.LocalAddr().String(), userConn.RemoteAddr().String()) + xl.Info("connection closed, it remains [%d]ms, userConn(l[%s] r[%s])", connectionDuration, + userConn.LocalAddr().String(), userConn.RemoteAddr().String()) + } else { + xl.Debug("join connection closed, userConn(l[%s] r[%s])", userConn.LocalAddr().String(), userConn.RemoteAddr().String()) + } } func IsTheTypeToLog(LogDurationTypes string, name string) bool { - if strings.Contains(LogDurationTypes, "all") { - return true - } - thestrlist := strings.Split(LogDurationTypes, ",") - for i := 0; i < len(thestrlist); i++ { - if strings.Contains(name, thestrlist[i]) { - return true - } - } - return false + if strings.Contains(LogDurationTypes, "all") { + return true + } + thestrlist := strings.Split(LogDurationTypes, ",") + for i := 0; i < len(thestrlist); i++ { + if strings.Contains(name, thestrlist[i]) { + return true + } + } + return false } type Manager struct { From 0f60ef3ecb7bec73857f0aaf22c572fe9162a792 Mon Sep 17 00:00:00 2001 From: berlin2123 <68841407+berlin2123@users.noreply.github.com> Date: Thu, 13 Oct 2022 10:06:56 +0800 Subject: [PATCH 22/23] Update server.go --- pkg/config/server.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/config/server.go b/pkg/config/server.go index 0f0f2e3f..675a2454 100644 --- a/pkg/config/server.go +++ b/pkg/config/server.go @@ -115,10 +115,10 @@ type ServerCommonConf struct { // value is 0. LogMaxDays int64 `ini:"log_max_days" json:"log_max_days"` // LogDurationTypes specifies the type of connection name, which will log - // the duration of those connections. if it is setting as 'ssh,rdp', it - // will log the duration of the name as 'ssh', 'ssh_1', 'sshname', 'rdp', - // 'rdp_test1' or 'web_my_rdp' . By default, this value is "ssh,rdp". - LogDurationTypes string `ini:"log_duration_types" json:"log_duration_types"` + // the duration of those connections. if it is setting as 'ssh,rdp', it + // will log the duration of the name as 'ssh', 'ssh_1', 'sshname', 'rdp', + // 'rdp_test1' or 'web_my_rdp' . By default, this value is "ssh,rdp". + LogDurationTypes string `ini:"log_duration_types" json:"log_duration_types"` // DisableLogColor disables log colors when LogWay == "console" when set to // true. By default, this value is false. DisableLogColor bool `ini:"disable_log_color" json:"disable_log_color"` From 8ed42b967d9732ef159fe59baf7295e9d52f22fc Mon Sep 17 00:00:00 2001 From: berlin2123 <68841407+berlin2123@users.noreply.github.com> Date: Thu, 13 Oct 2022 10:10:46 +0800 Subject: [PATCH 23/23] Update proxy.go --- server/proxy/proxy.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/server/proxy/proxy.go b/server/proxy/proxy.go index d7372e18..df00608c 100644 --- a/server/proxy/proxy.go +++ b/server/proxy/proxy.go @@ -306,17 +306,17 @@ func HandleUserTCPConnection(pxy Proxy, userConn net.Conn, serverCfg config.Serv xl.Debug("join connection closed, it remains [%d]ms, workConn(l[%s] r[%s]) userConn(l[%s] r[%s])", connectionDuration, workConn.LocalAddr().String(), workConn.RemoteAddr().String(), userConn.LocalAddr().String(), userConn.RemoteAddr().String()) xl.Info("connection closed, it remains [%d]ms, userConn(l[%s] r[%s])", connectionDuration, - userConn.LocalAddr().String(), userConn.RemoteAddr().String()) + userConn.LocalAddr().String(), userConn.RemoteAddr().String()) } else { xl.Debug("join connection closed, userConn(l[%s] r[%s])", userConn.LocalAddr().String(), userConn.RemoteAddr().String()) } } -func IsTheTypeToLog(LogDurationTypes string, name string) bool { - if strings.Contains(LogDurationTypes, "all") { +func IsTheTypeToLog(logDurationTypes string, name string) bool { + if strings.Contains(logDurationTypes, "all") { return true } - thestrlist := strings.Split(LogDurationTypes, ",") + thestrlist := strings.Split(logDurationTypes, ",") for i := 0; i < len(thestrlist); i++ { if strings.Contains(name, thestrlist[i]) { return true