|
|
@ -24,46 +24,120 @@ import (
|
|
|
|
"github.com/fatedier/frp/utils/util"
|
|
|
|
"github.com/fatedier/frp/utils/util"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// common config
|
|
|
|
// ServerCommonConf contains information for a server service. It is
|
|
|
|
|
|
|
|
// recommended to use GetDefaultServerConf instead of creating this object
|
|
|
|
|
|
|
|
// directly, so that all unspecified fields have reasonable default values.
|
|
|
|
type ServerCommonConf struct {
|
|
|
|
type ServerCommonConf struct {
|
|
|
|
BindAddr string `json:"bind_addr"`
|
|
|
|
// BindAddr specifies the address that the server binds to. By default,
|
|
|
|
BindPort int `json:"bind_port"`
|
|
|
|
// this value is "0.0.0.0".
|
|
|
|
BindUdpPort int `json:"bind_udp_port"`
|
|
|
|
BindAddr string `json:"bind_addr"`
|
|
|
|
KcpBindPort int `json:"kcp_bind_port"`
|
|
|
|
// BindPort specifies the port that the server listens on. By default, this
|
|
|
|
|
|
|
|
// value is 7000.
|
|
|
|
|
|
|
|
BindPort int `json:"bind_port"`
|
|
|
|
|
|
|
|
// BindUdpPort specifies the UDP port that the server listens on. If this
|
|
|
|
|
|
|
|
// value is 0, the server will not listen for UDP connections. By default,
|
|
|
|
|
|
|
|
// this value is 0
|
|
|
|
|
|
|
|
BindUdpPort int `json:"bind_udp_port"`
|
|
|
|
|
|
|
|
// BindKcpPort specifies the KCP port that the server listens on. If this
|
|
|
|
|
|
|
|
// value is 0, the server will not listen for KCP connections. By default,
|
|
|
|
|
|
|
|
// this value is 0.
|
|
|
|
|
|
|
|
KcpBindPort int `json:"kcp_bind_port"`
|
|
|
|
|
|
|
|
// ProxyBindAddr specifies the address that the proxy binds to. This value
|
|
|
|
|
|
|
|
// may be the same as BindAddr. By default, this value is "0.0.0.0".
|
|
|
|
ProxyBindAddr string `json:"proxy_bind_addr"`
|
|
|
|
ProxyBindAddr string `json:"proxy_bind_addr"`
|
|
|
|
|
|
|
|
|
|
|
|
// If VhostHttpPort equals 0, don't listen a public port for http protocol.
|
|
|
|
// VhostHttpPort specifies the port that the server listens for HTTP Vhost
|
|
|
|
|
|
|
|
// requests. If this value is 0, the server will not listen for HTTP
|
|
|
|
|
|
|
|
// requests. By default, this value is 0.
|
|
|
|
VhostHttpPort int `json:"vhost_http_port"`
|
|
|
|
VhostHttpPort int `json:"vhost_http_port"`
|
|
|
|
|
|
|
|
|
|
|
|
// if VhostHttpsPort equals 0, don't listen a public port for https protocol
|
|
|
|
// VhostHttpsPort specifies the port that the server listens for HTTPS
|
|
|
|
|
|
|
|
// Vhost requests. If this value is 0, the server will not listen for HTTPS
|
|
|
|
|
|
|
|
// requests. By default, this value is 0.
|
|
|
|
VhostHttpsPort int `json:"vhost_https_port"`
|
|
|
|
VhostHttpsPort int `json:"vhost_https_port"`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// VhostHttpTimeout specifies the response header timeout for the Vhost
|
|
|
|
|
|
|
|
// HTTP server, in seconds. By default, this value is 60.
|
|
|
|
VhostHttpTimeout int64 `json:"vhost_http_timeout"`
|
|
|
|
VhostHttpTimeout int64 `json:"vhost_http_timeout"`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// DashboardAddr specifies the address that the dashboard binds to. By
|
|
|
|
|
|
|
|
// default, this value is "0.0.0.0".
|
|
|
|
DashboardAddr string `json:"dashboard_addr"`
|
|
|
|
DashboardAddr string `json:"dashboard_addr"`
|
|
|
|
|
|
|
|
|
|
|
|
// if DashboardPort equals 0, dashboard is not available
|
|
|
|
// DashboardPort specifies the port that the dashboard listens on. If this
|
|
|
|
DashboardPort int `json:"dashboard_port"`
|
|
|
|
// value is 0, the dashboard will not be started. By default, this value is
|
|
|
|
DashboardUser string `json:"dashboard_user"`
|
|
|
|
// 0.
|
|
|
|
DashboardPwd string `json:"dashboard_pwd"`
|
|
|
|
DashboardPort int `json:"dashboard_port"`
|
|
|
|
AssetsDir string `json:"asserts_dir"`
|
|
|
|
// DashboardUser specifies the username that the dashboard will use for
|
|
|
|
LogFile string `json:"log_file"`
|
|
|
|
// login. By default, this value is "admin".
|
|
|
|
LogWay string `json:"log_way"` // console or file
|
|
|
|
DashboardUser string `json:"dashboard_user"`
|
|
|
|
LogLevel string `json:"log_level"`
|
|
|
|
// DashboardUser specifies the password that the dashboard will use for
|
|
|
|
LogMaxDays int64 `json:"log_max_days"`
|
|
|
|
// login. By default, this value is "admin".
|
|
|
|
DisableLogColor bool `json:"disable_log_color"`
|
|
|
|
DashboardPwd string `json:"dashboard_pwd"`
|
|
|
|
Token string `json:"token"`
|
|
|
|
// AssetsDir specifies the local directory that the dashboard will load
|
|
|
|
SubDomainHost string `json:"subdomain_host"`
|
|
|
|
// resources from. If this value is "", assets will be loaded from the
|
|
|
|
TcpMux bool `json:"tcp_mux"`
|
|
|
|
// bundled executable using statik. By default, this value is "".
|
|
|
|
Custom404Page string `json:"custom_404_page"`
|
|
|
|
AssetsDir string `json:"asserts_dir"`
|
|
|
|
|
|
|
|
// LogFile specifies a file where logs will be written to. This value will
|
|
|
|
AllowPorts map[int]struct{}
|
|
|
|
// only be used if LogWay is set appropriately. By default, this value is
|
|
|
|
MaxPoolCount int64 `json:"max_pool_count"`
|
|
|
|
// "console".
|
|
|
|
|
|
|
|
LogFile string `json:"log_file"`
|
|
|
|
|
|
|
|
// LogWay specifies the way logging is managed. Valid values are "console"
|
|
|
|
|
|
|
|
// or "file". If "console" is used, logs will be printed to stdout. If
|
|
|
|
|
|
|
|
// "file" is used, logs will be printed to LogFile. By default, this value
|
|
|
|
|
|
|
|
// is "console".
|
|
|
|
|
|
|
|
LogWay string `json:"log_way"`
|
|
|
|
|
|
|
|
// LogLevel specifies the minimum log level. Valid values are "trace",
|
|
|
|
|
|
|
|
// "debug", "info", "warn", and "error". By default, this value is "info".
|
|
|
|
|
|
|
|
LogLevel string `json:"log_level"`
|
|
|
|
|
|
|
|
// LogMaxDays specifies the maximum number of days to store log information
|
|
|
|
|
|
|
|
// before deletion. This is only used if LogWay == "file". By default, this
|
|
|
|
|
|
|
|
// value is 0.
|
|
|
|
|
|
|
|
LogMaxDays int64 `json:"log_max_days"`
|
|
|
|
|
|
|
|
// DisableLogColor disables log colors when LogWay == "console" when set to
|
|
|
|
|
|
|
|
// true. By default, this value is false.
|
|
|
|
|
|
|
|
DisableLogColor bool `json:"disable_log_color"`
|
|
|
|
|
|
|
|
// 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 "".
|
|
|
|
|
|
|
|
Token string `json:"token"`
|
|
|
|
|
|
|
|
// SubDomainHost specifies the domain that will be attached to sub-domains
|
|
|
|
|
|
|
|
// requested by the client when using Vhost proxying. For example, if this
|
|
|
|
|
|
|
|
// value is set to "frps.com" and the client requested the subdomain
|
|
|
|
|
|
|
|
// "test", the resulting URL would be "test.frps.com". By default, this
|
|
|
|
|
|
|
|
// value is "".
|
|
|
|
|
|
|
|
SubDomainHost string `json:"subdomain_host"`
|
|
|
|
|
|
|
|
// TcpMux toggles TCP stream multiplexing. This allows multiple requests
|
|
|
|
|
|
|
|
// from a client to share a single TCP connection. By default, this value
|
|
|
|
|
|
|
|
// is true.
|
|
|
|
|
|
|
|
TcpMux bool `json:"tcp_mux"`
|
|
|
|
|
|
|
|
// Custom404Page specifies a path to a custom 404 page to display. If this
|
|
|
|
|
|
|
|
// value is "", a default page will be displayed. By default, this value is
|
|
|
|
|
|
|
|
// "".
|
|
|
|
|
|
|
|
Custom404Page string `json:"custom_404_page"`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// AllowPorts specifies a set of ports that clients are able to proxy to.
|
|
|
|
|
|
|
|
// If the length of this value is 0, all ports are allowed. By default,
|
|
|
|
|
|
|
|
// this value is an empty set.
|
|
|
|
|
|
|
|
AllowPorts map[int]struct{}
|
|
|
|
|
|
|
|
// MaxPoolCount specifies the maximum pool size for each proxy. By default,
|
|
|
|
|
|
|
|
// this value is 5.
|
|
|
|
|
|
|
|
MaxPoolCount int64 `json:"max_pool_count"`
|
|
|
|
|
|
|
|
// MaxPortsPerClient specifies the maximum number of ports a single client
|
|
|
|
|
|
|
|
// may proxy to. If this value is 0, no limit will be applied. By default,
|
|
|
|
|
|
|
|
// this value is 0.
|
|
|
|
MaxPortsPerClient int64 `json:"max_ports_per_client"`
|
|
|
|
MaxPortsPerClient int64 `json:"max_ports_per_client"`
|
|
|
|
HeartBeatTimeout int64 `json:"heart_beat_timeout"`
|
|
|
|
// HeartBeatTimeout specifies the maximum time to wait for a heartbeat
|
|
|
|
UserConnTimeout int64 `json:"user_conn_timeout"`
|
|
|
|
// before terminating the connection. It is not recommended to change this
|
|
|
|
|
|
|
|
// value. By default, this value is 90.
|
|
|
|
|
|
|
|
HeartBeatTimeout int64 `json:"heart_beat_timeout"`
|
|
|
|
|
|
|
|
// UserConnTimeout specifies the maximum time to wait for a work
|
|
|
|
|
|
|
|
// connection. By default, this value is 10.
|
|
|
|
|
|
|
|
UserConnTimeout int64 `json:"user_conn_timeout"`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// GetDefaultServerConf returns a server configuration with reasonable
|
|
|
|
|
|
|
|
// defaults.
|
|
|
|
func GetDefaultServerConf() ServerCommonConf {
|
|
|
|
func GetDefaultServerConf() ServerCommonConf {
|
|
|
|
return ServerCommonConf{
|
|
|
|
return ServerCommonConf{
|
|
|
|
BindAddr: "0.0.0.0",
|
|
|
|
BindAddr: "0.0.0.0",
|
|
|
@ -96,6 +170,8 @@ func GetDefaultServerConf() ServerCommonConf {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// UnmarshalServerConfFromIni parses the contents of a server configuration ini
|
|
|
|
|
|
|
|
// file and returns the resulting server configuration.
|
|
|
|
func UnmarshalServerConfFromIni(content string) (cfg ServerCommonConf, err error) {
|
|
|
|
func UnmarshalServerConfFromIni(content string) (cfg ServerCommonConf, err error) {
|
|
|
|
cfg = GetDefaultServerConf()
|
|
|
|
cfg = GetDefaultServerConf()
|
|
|
|
|
|
|
|
|
|
|
|