123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281 |
- package legacy
- import (
- "strings"
- "gopkg.in/ini.v1"
- legacyauth "github.com/fatedier/frp/pkg/auth/legacy"
- )
- type HTTPPluginOptions struct {
- Name string `ini:"name"`
- Addr string `ini:"addr"`
- Path string `ini:"path"`
- Ops []string `ini:"ops"`
- TLSVerify bool `ini:"tlsVerify"`
- }
- type ServerCommonConf struct {
- legacyauth.ServerConfig `ini:",extends"`
-
-
- BindAddr string `ini:"bind_addr" json:"bind_addr"`
-
-
- BindPort int `ini:"bind_port" json:"bind_port"`
-
-
-
- KCPBindPort int `ini:"kcp_bind_port" json:"kcp_bind_port"`
-
-
-
- QUICBindPort int `ini:"quic_bind_port" json:"quic_bind_port"`
-
- QUICKeepalivePeriod int `ini:"quic_keepalive_period" json:"quic_keepalive_period"`
- QUICMaxIdleTimeout int `ini:"quic_max_idle_timeout" json:"quic_max_idle_timeout"`
- QUICMaxIncomingStreams int `ini:"quic_max_incoming_streams" json:"quic_max_incoming_streams"`
-
-
- ProxyBindAddr string `ini:"proxy_bind_addr" json:"proxy_bind_addr"`
-
-
-
- VhostHTTPPort int `ini:"vhost_http_port" json:"vhost_http_port"`
-
-
-
- VhostHTTPSPort int `ini:"vhost_https_port" json:"vhost_https_port"`
-
-
-
-
- TCPMuxHTTPConnectPort int `ini:"tcpmux_httpconnect_port" json:"tcpmux_httpconnect_port"`
-
- TCPMuxPassthrough bool `ini:"tcpmux_passthrough" json:"tcpmux_passthrough"`
-
-
- VhostHTTPTimeout int64 `ini:"vhost_http_timeout" json:"vhost_http_timeout"`
-
-
- DashboardAddr string `ini:"dashboard_addr" json:"dashboard_addr"`
-
-
-
- DashboardPort int `ini:"dashboard_port" json:"dashboard_port"`
-
-
-
- DashboardTLSCertFile string `ini:"dashboard_tls_cert_file" json:"dashboard_tls_cert_file"`
-
-
-
- DashboardTLSKeyFile string `ini:"dashboard_tls_key_file" json:"dashboard_tls_key_file"`
-
-
- DashboardTLSMode bool `ini:"dashboard_tls_mode" json:"dashboard_tls_mode"`
-
-
- DashboardUser string `ini:"dashboard_user" json:"dashboard_user"`
-
-
- DashboardPwd string `ini:"dashboard_pwd" json:"dashboard_pwd"`
-
-
- EnablePrometheus bool `ini:"enable_prometheus" json:"enable_prometheus"`
-
-
-
- AssetsDir string `ini:"assets_dir" json:"assets_dir"`
-
-
-
- LogFile string `ini:"log_file" json:"log_file"`
-
-
-
-
- LogWay string `ini:"log_way" json:"log_way"`
-
-
- LogLevel string `ini:"log_level" json:"log_level"`
-
-
-
- LogMaxDays int64 `ini:"log_max_days" json:"log_max_days"`
-
-
- DisableLogColor bool `ini:"disable_log_color" json:"disable_log_color"`
-
-
- DetailedErrorsToClient bool `ini:"detailed_errors_to_client" json:"detailed_errors_to_client"`
-
-
-
-
-
- SubDomainHost string `ini:"subdomain_host" json:"subdomain_host"`
-
-
-
- TCPMux bool `ini:"tcp_mux" json:"tcp_mux"`
-
-
- TCPMuxKeepaliveInterval int64 `ini:"tcp_mux_keepalive_interval" json:"tcp_mux_keepalive_interval"`
-
-
- TCPKeepAlive int64 `ini:"tcp_keepalive" json:"tcp_keepalive"`
-
-
-
- Custom404Page string `ini:"custom_404_page" json:"custom_404_page"`
-
-
-
- AllowPorts map[int]struct{} `ini:"-" json:"-"`
-
- AllowPortsStr string `ini:"-" json:"-"`
-
-
- MaxPoolCount int64 `ini:"max_pool_count" json:"max_pool_count"`
-
-
-
- MaxPortsPerClient int64 `ini:"max_ports_per_client" json:"max_ports_per_client"`
-
-
- TLSOnly bool `ini:"tls_only" json:"tls_only"`
-
-
-
-
- TLSCertFile string `ini:"tls_cert_file" json:"tls_cert_file"`
-
-
-
-
- TLSKeyFile string `ini:"tls_key_file" json:"tls_key_file"`
-
-
-
-
- TLSTrustedCaFile string `ini:"tls_trusted_ca_file" json:"tls_trusted_ca_file"`
-
-
-
- HeartbeatTimeout int64 `ini:"heartbeat_timeout" json:"heartbeat_timeout"`
-
-
- UserConnTimeout int64 `ini:"user_conn_timeout" json:"user_conn_timeout"`
-
- HTTPPlugins map[string]HTTPPluginOptions `ini:"-" json:"http_plugins"`
-
-
- UDPPacketSize int64 `ini:"udp_packet_size" json:"udp_packet_size"`
-
-
- PprofEnable bool `ini:"pprof_enable" json:"pprof_enable"`
-
- NatHoleAnalysisDataReserveHours int64 `ini:"nat_hole_analysis_data_reserve_hours" json:"nat_hole_analysis_data_reserve_hours"`
- }
- func GetDefaultServerConf() ServerCommonConf {
- return ServerCommonConf{
- ServerConfig: legacyauth.GetDefaultServerConf(),
- DashboardAddr: "0.0.0.0",
- LogFile: "console",
- LogWay: "console",
- DetailedErrorsToClient: true,
- TCPMux: true,
- AllowPorts: make(map[int]struct{}),
- HTTPPlugins: make(map[string]HTTPPluginOptions),
- }
- }
- func UnmarshalServerConfFromIni(source any) (ServerCommonConf, error) {
- f, err := ini.LoadSources(ini.LoadOptions{
- Insensitive: false,
- InsensitiveSections: false,
- InsensitiveKeys: false,
- IgnoreInlineComment: true,
- AllowBooleanKeys: true,
- }, source)
- if err != nil {
- return ServerCommonConf{}, err
- }
- s, err := f.GetSection("common")
- if err != nil {
- return ServerCommonConf{}, err
- }
- common := GetDefaultServerConf()
- err = s.MapTo(&common)
- if err != nil {
- return ServerCommonConf{}, err
- }
-
- allowPortStr := s.Key("allow_ports").String()
- if allowPortStr != "" {
- common.AllowPortsStr = allowPortStr
- }
-
- pluginOpts := make(map[string]HTTPPluginOptions)
- for _, section := range f.Sections() {
- name := section.Name()
- if !strings.HasPrefix(name, "plugin.") {
- continue
- }
- opt, err := loadHTTPPluginOpt(section)
- if err != nil {
- return ServerCommonConf{}, err
- }
- pluginOpts[opt.Name] = *opt
- }
- common.HTTPPlugins = pluginOpts
- return common, nil
- }
- func loadHTTPPluginOpt(section *ini.Section) (*HTTPPluginOptions, error) {
- name := strings.TrimSpace(strings.TrimPrefix(section.Name(), "plugin."))
- opt := &HTTPPluginOptions{}
- err := section.MapTo(opt)
- if err != nil {
- return nil, err
- }
- opt.Name = name
- return opt, nil
- }
|