mirror of
https://github.com/fatedier/frp.git
synced 2025-04-23 01:31:26 +00:00
Merge bf52c89e2aeba9982a50581a661b825b140bea1a into 773169e0c44070facd652c4b8b3fe6e6ff4d78f3
This commit is contained in:
commit
6efbce92b2
@ -89,6 +89,8 @@ log.level = "info"
|
|||||||
log.maxDays = 3
|
log.maxDays = 3
|
||||||
# disable log colors when log.to is console, default is false
|
# disable log colors when log.to is console, default is false
|
||||||
log.disablePrintColor = false
|
log.disablePrintColor = false
|
||||||
|
# log the duration of each connection name has string 'ssh' or 'rdp'.
|
||||||
|
log.durationtypes = "ssh,rdp"
|
||||||
|
|
||||||
# DetailedErrorsToClient defines whether to send the specific error (with debug info) to frpc. By default, this value is true.
|
# DetailedErrorsToClient defines whether to send the specific error (with debug info) to frpc. By default, this value is true.
|
||||||
detailedErrorsToClient = true
|
detailedErrorsToClient = true
|
||||||
|
@ -70,6 +70,12 @@ log_max_days = 3
|
|||||||
# disable log colors when log_file is console, default is false
|
# disable log colors when log_file is console, default is false
|
||||||
disable_log_color = false
|
disable_log_color = false
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
# DetailedErrorsToClient defines whether to send the specific error (with debug info) to frpc. By default, this value is true.
|
# DetailedErrorsToClient defines whether to send the specific error (with debug info) to frpc. By default, this value is true.
|
||||||
detailed_errors_to_client = true
|
detailed_errors_to_client = true
|
||||||
|
|
||||||
|
@ -243,6 +243,7 @@ func RegisterServerConfigFlags(cmd *cobra.Command, c *v1.ServerConfig, opts ...R
|
|||||||
cmd.PersistentFlags().StringVarP(&c.Log.Level, "log_level", "", "info", "log level")
|
cmd.PersistentFlags().StringVarP(&c.Log.Level, "log_level", "", "info", "log level")
|
||||||
cmd.PersistentFlags().Int64VarP(&c.Log.MaxDays, "log_max_days", "", 3, "log max days")
|
cmd.PersistentFlags().Int64VarP(&c.Log.MaxDays, "log_max_days", "", 3, "log max days")
|
||||||
cmd.PersistentFlags().BoolVarP(&c.Log.DisablePrintColor, "disable_log_color", "", false, "disable log color in console")
|
cmd.PersistentFlags().BoolVarP(&c.Log.DisablePrintColor, "disable_log_color", "", false, "disable log color in console")
|
||||||
|
cmd.PersistentFlags().StringVarP(&c.Log.DurationTypes, "log_duration_types", "", "", "log duration types")
|
||||||
cmd.PersistentFlags().StringVarP(&c.Auth.Token, "token", "t", "", "auth token")
|
cmd.PersistentFlags().StringVarP(&c.Auth.Token, "token", "t", "", "auth token")
|
||||||
cmd.PersistentFlags().StringVarP(&c.SubDomainHost, "subdomain_host", "", "", "subdomain host")
|
cmd.PersistentFlags().StringVarP(&c.SubDomainHost, "subdomain_host", "", "", "subdomain host")
|
||||||
cmd.PersistentFlags().VarP(&PortsRangeSliceFlag{V: &c.AllowPorts}, "allow_ports", "", "allow ports")
|
cmd.PersistentFlags().VarP(&PortsRangeSliceFlag{V: &c.AllowPorts}, "allow_ports", "", "allow ports")
|
||||||
|
@ -133,6 +133,7 @@ func Convert_ServerCommonConf_To_v1(conf *ServerCommonConf) *v1.ServerConfig {
|
|||||||
out.Log.Level = conf.LogLevel
|
out.Log.Level = conf.LogLevel
|
||||||
out.Log.MaxDays = conf.LogMaxDays
|
out.Log.MaxDays = conf.LogMaxDays
|
||||||
out.Log.DisablePrintColor = conf.DisableLogColor
|
out.Log.DisablePrintColor = conf.DisableLogColor
|
||||||
|
out.Log.DurationTypes = conf.LogDurationTypes
|
||||||
|
|
||||||
out.DetailedErrorsToClient = lo.ToPtr(conf.DetailedErrorsToClient)
|
out.DetailedErrorsToClient = lo.ToPtr(conf.DetailedErrorsToClient)
|
||||||
out.SubDomainHost = conf.SubDomainHost
|
out.SubDomainHost = conf.SubDomainHost
|
||||||
|
@ -125,6 +125,11 @@ 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 `ini:"disable_log_color" json:"disable_log_color"`
|
DisableLogColor bool `ini:"disable_log_color" json:"disable_log_color"`
|
||||||
|
// LogDurationTypes specifies the types of connection names for which the
|
||||||
|
// duration will be logged. If set to 'ssh,rdp', it will log the duration
|
||||||
|
// of connections named 'ssh', 'ssh_1', 'sshname', 'rdp', 'rdp_test1', or
|
||||||
|
// 'web_my_rdp'. By default, this value is "".
|
||||||
|
LogDurationTypes string `ini:"log_duration_types" json:"log_duration_types"`
|
||||||
// DetailedErrorsToClient defines whether to send the specific error (with
|
// DetailedErrorsToClient defines whether to send the specific error (with
|
||||||
// debug info) to frpc. By default, this value is true.
|
// debug info) to frpc. By default, this value is true.
|
||||||
DetailedErrorsToClient bool `ini:"detailed_errors_to_client" json:"detailed_errors_to_client"`
|
DetailedErrorsToClient bool `ini:"detailed_errors_to_client" json:"detailed_errors_to_client"`
|
||||||
@ -210,6 +215,7 @@ func GetDefaultServerConf() ServerCommonConf {
|
|||||||
DashboardAddr: "0.0.0.0",
|
DashboardAddr: "0.0.0.0",
|
||||||
LogFile: "console",
|
LogFile: "console",
|
||||||
LogWay: "console",
|
LogWay: "console",
|
||||||
|
LogDurationTypes: "",
|
||||||
DetailedErrorsToClient: true,
|
DetailedErrorsToClient: true,
|
||||||
TCPMux: true,
|
TCPMux: true,
|
||||||
AllowPorts: make(map[int]struct{}),
|
AllowPorts: make(map[int]struct{}),
|
||||||
|
@ -110,12 +110,18 @@ type LogConfig struct {
|
|||||||
MaxDays int64 `json:"maxDays"`
|
MaxDays int64 `json:"maxDays"`
|
||||||
// DisablePrintColor disables log colors when log.to is "console".
|
// DisablePrintColor disables log colors when log.to is "console".
|
||||||
DisablePrintColor bool `json:"disablePrintColor,omitempty"`
|
DisablePrintColor bool `json:"disablePrintColor,omitempty"`
|
||||||
|
// DurationTypes specifies the types of connection names for which the
|
||||||
|
// duration will be logged. If set to 'ssh,rdp', it will log the duration
|
||||||
|
// of connections named 'ssh', 'ssh_1', 'sshname', 'rdp', 'rdp_test1', or
|
||||||
|
// 'web_my_rdp'. By default, this value is "".
|
||||||
|
DurationTypes string `json:"durationtypes,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *LogConfig) Complete() {
|
func (c *LogConfig) Complete() {
|
||||||
c.To = util.EmptyOr(c.To, "console")
|
c.To = util.EmptyOr(c.To, "console")
|
||||||
c.Level = util.EmptyOr(c.Level, "info")
|
c.Level = util.EmptyOr(c.Level, "info")
|
||||||
c.MaxDays = util.EmptyOr(c.MaxDays, 3)
|
c.MaxDays = util.EmptyOr(c.MaxDays, 3)
|
||||||
|
c.DurationTypes = util.EmptyOr(c.DurationTypes, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
type HTTPPluginOptions struct {
|
type HTTPPluginOptions struct {
|
||||||
|
@ -21,6 +21,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -62,6 +63,7 @@ type Proxy interface {
|
|||||||
|
|
||||||
type BaseProxy struct {
|
type BaseProxy struct {
|
||||||
name string
|
name string
|
||||||
|
logDuration bool
|
||||||
rc *controller.ResourceController
|
rc *controller.ResourceController
|
||||||
listeners []net.Listener
|
listeners []net.Listener
|
||||||
usedPortsNum int
|
usedPortsNum int
|
||||||
@ -258,6 +260,7 @@ func (pxy *BaseProxy) handleUserTCPConnection(userConn net.Conn) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
startime := time.Now().UnixNano() / 1000000 // time in microseconds
|
||||||
xl.Debugf("join connections, workConn(l[%s] r[%s]) userConn(l[%s] r[%s])", workConn.LocalAddr().String(),
|
xl.Debugf("join connections, workConn(l[%s] r[%s]) userConn(l[%s] r[%s])", workConn.LocalAddr().String(),
|
||||||
workConn.RemoteAddr().String(), userConn.LocalAddr().String(), userConn.RemoteAddr().String())
|
workConn.RemoteAddr().String(), userConn.LocalAddr().String(), userConn.RemoteAddr().String())
|
||||||
|
|
||||||
@ -268,7 +271,34 @@ func (pxy *BaseProxy) handleUserTCPConnection(userConn net.Conn) {
|
|||||||
metrics.Server.CloseConnection(name, proxyType)
|
metrics.Server.CloseConnection(name, proxyType)
|
||||||
metrics.Server.AddTrafficIn(name, proxyType, inCount)
|
metrics.Server.AddTrafficIn(name, proxyType, inCount)
|
||||||
metrics.Server.AddTrafficOut(name, proxyType, outCount)
|
metrics.Server.AddTrafficOut(name, proxyType, outCount)
|
||||||
xl.Debugf("join connections closed")
|
|
||||||
|
// Log the duration of connection.
|
||||||
|
if pxy.logDuration {
|
||||||
|
endtime := time.Now().UnixNano() / 1000000 // time in microseconds
|
||||||
|
connectionDuration := endtime - startime
|
||||||
|
xl.Debugf("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.Infof("connection closed, it remains [%d]ms, userConn(l[%s] r[%s])", connectionDuration,
|
||||||
|
userConn.LocalAddr().String(), userConn.RemoteAddr().String())
|
||||||
|
} else {
|
||||||
|
xl.Debugf("join connection closed, userConn(l[%s] r[%s])", userConn.LocalAddr().String(), userConn.RemoteAddr().String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check Duration should be loged or not. True: while connection name contain a string in logDurationTypes.
|
||||||
|
func IsTheTypeToLog(logDurationTypes string, name string, xl *xlog.Logger) bool {
|
||||||
|
if strings.Contains(logDurationTypes, "all") {
|
||||||
|
xl.Infof("The duration of each connection through this Proxy will be logged.")
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
thestrlist := strings.Split(logDurationTypes, ",")
|
||||||
|
for i := 0; i < len(thestrlist); i++ {
|
||||||
|
if (thestrlist[i] != "") && strings.Contains(name, thestrlist[i]) {
|
||||||
|
xl.Infof("The duration of each connection through this Proxy will be logged.")
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
type Options struct {
|
type Options struct {
|
||||||
@ -293,6 +323,7 @@ func NewProxy(ctx context.Context, options *Options) (pxy Proxy, err error) {
|
|||||||
|
|
||||||
basePxy := BaseProxy{
|
basePxy := BaseProxy{
|
||||||
name: configurer.GetBaseConfig().Name,
|
name: configurer.GetBaseConfig().Name,
|
||||||
|
logDuration: IsTheTypeToLog(options.ServerCfg.Log.DurationTypes, configurer.GetBaseConfig().Name, xl),
|
||||||
rc: options.ResourceController,
|
rc: options.ResourceController,
|
||||||
listeners: make([]net.Listener, 0),
|
listeners: make([]net.Listener, 0),
|
||||||
poolCount: options.PoolCount,
|
poolCount: options.PoolCount,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user