config

package
v1.15.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 19, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultAppFile = "app.config"

Variables

This section is empty.

Functions

func Expiry added in v1.12.0

func Expiry(configPath string, del AutoDelete) (time.Duration, error)

Expiry returns the remaining duration, after which a config will expire. If a config has no expiry date, an `ErrNoDeadline` error is returned.

func UnmarshalAppConfFromIni added in v1.12.0

func UnmarshalAppConfFromIni(source any, dst *App) error

Types

type App added in v1.12.0

type App struct {
	Password string       `ini:"password,omitempty"`
	Defaults ClientCommon `ini:"defaults"`
}

func (*App) Save added in v1.12.0

func (conf *App) Save(path string) error

type AutoDelete added in v1.13.0

type AutoDelete struct {
	// DeleteMethod specifies what delete method to use to delete the config.
	// If "absolute" is specified, the expiry date is set in config. If "relative" is specified, the expiry date
	// is calculated by adding the days to the file modification time. If it's empty, the config has no expiry date.
	DeleteMethod string `ini:"frpmgr_delete_method,omitempty"`
	// DeleteAfterDays is the number of days a config will be kept, after which it may be stopped and deleted.
	DeleteAfterDays uint `ini:"frpmgr_delete_after_days,omitempty" relative:"true"`
	// DeleteAfterDate is the last date the config will be valid, after which it may be stopped and deleted.
	DeleteAfterDate time.Time `ini:"frpmgr_delete_after_date,omitempty" absolute:"true"`
}

func (AutoDelete) Complete added in v1.13.0

func (ad AutoDelete) Complete() AutoDelete

type BaseProxyConf

type BaseProxyConf struct {
	// Name is the name of this proxy.
	Name string `ini:"-"`
	// Type specifies the type of this. Valid values include tcp, udp,
	// xtcp, stcp, sudp, http, https, tcpmux. By default, this value is "tcp".
	Type string `ini:"type,omitempty"`

	// UseEncryption controls whether communication with the server will
	// be encrypted. Encryption is done using the tokens supplied in the server
	// and client configuration. By default, this value is false.
	UseEncryption bool `ini:"use_encryption,omitempty"`
	// UseCompression controls whether communication with the server
	// will be compressed. By default, this value is false.
	UseCompression bool `ini:"use_compression,omitempty"`
	// Group specifies which group the proxy is a part of. The server will use
	// this information to load balance proxies in the same group. If the value
	// is "", this will not be in a group. By default, this value is "".
	Group string `ini:"group,omitempty"`
	// GroupKey specifies a group key, which should be the same among proxies
	// of the same group. By default, this value is "".
	GroupKey string `ini:"group_key,omitempty"`

	// ProxyProtocolVersion specifies which protocol version to use. Valid
	// values include "v1", "v2", and "". If the value is "", a protocol
	// version will be automatically selected. By default, this value is "".
	ProxyProtocolVersion string `ini:"proxy_protocol_version,omitempty"`

	// BandwidthLimit limits the bandwidth.
	// 0 means no limit.
	BandwidthLimit     string `ini:"bandwidth_limit,omitempty"`
	BandwidthLimitMode string `ini:"bandwidth_limit_mode,omitempty"`

	// LocalIP specifies the IP address or host name.
	LocalIP string `ini:"local_ip,omitempty"`
	// LocalPort specifies the port.
	LocalPort string `ini:"local_port,omitempty"`

	// Plugin specifies what plugin should be used for ng. If this value
	// is set, the LocalIp and LocalPort values will be ignored. By default,
	// this value is "".
	Plugin string `ini:"plugin,omitempty"`
	// PluginParams specify parameters to be passed to the plugin, if one is
	// being used.
	PluginParams `ini:",extends"`
	// HealthCheckType specifies what protocol to use for health checking.
	HealthCheckType string `ini:"health_check_type,omitempty"` // tcp | http
	// Health checking parameters.
	HealthCheckConf `ini:",extends"`
	// Custom collects all the unparsed options.
	Custom map[string]string `ini:"-"`
	// Disabled defines whether to start the proxy.
	Disabled bool `ini:"-"`
}

BaseProxyConf provides configuration info that is common to all types.

type ClientAuth

type ClientAuth struct {
	AuthMethod               string `ini:"authentication_method,omitempty"`
	AuthenticateHeartBeats   bool   `ini:"authenticate_heartbeats,omitempty" token:"true" oidc:"true"`
	AuthenticateNewWorkConns bool   `ini:"authenticate_new_work_conns,omitempty" token:"true" oidc:"true"`
	Token                    string `ini:"token,omitempty" token:"true"`
	OIDCClientId             string `ini:"oidc_client_id,omitempty" oidc:"true"`
	OIDCClientSecret         string `ini:"oidc_client_secret,omitempty" oidc:"true"`
	OIDCAudience             string `ini:"oidc_audience,omitempty" oidc:"true"`
	OIDCScope                string `ini:"oidc_scope,omitempty" oidc:"true"`
	OIDCTokenEndpoint        string `ini:"oidc_token_endpoint_url,omitempty" oidc:"true"`
}

func (ClientAuth) Complete added in v1.13.0

func (ca ClientAuth) Complete() ClientAuth

type ClientCommon

type ClientCommon struct {
	ClientAuth              `ini:",extends"`
	ServerAddress           string   `ini:"server_addr,omitempty"`
	ServerPort              string   `ini:"server_port,omitempty"`
	NatHoleSTUNServer       string   `ini:"nat_hole_stun_server,omitempty"`
	DialServerTimeout       int64    `ini:"dial_server_timeout,omitempty"`
	DialServerKeepAlive     int64    `ini:"dial_server_keepalive,omitempty"`
	ConnectServerLocalIP    string   `ini:"connect_server_local_ip,omitempty"`
	HTTPProxy               string   `ini:"http_proxy,omitempty"`
	LogFile                 string   `ini:"log_file,omitempty"`
	LogLevel                string   `ini:"log_level,omitempty"`
	LogMaxDays              uint     `ini:"log_max_days,omitempty"`
	AdminAddr               string   `ini:"admin_addr,omitempty"`
	AdminPort               string   `ini:"admin_port,omitempty"`
	AdminUser               string   `ini:"admin_user,omitempty"`
	AdminPwd                string   `ini:"admin_pwd,omitempty"`
	AssetsDir               string   `ini:"assets_dir,omitempty"`
	PoolCount               uint     `ini:"pool_count,omitempty"`
	DNSServer               string   `ini:"dns_server,omitempty"`
	Protocol                string   `ini:"protocol,omitempty"`
	QUICKeepalivePeriod     int      `ini:"quic_keepalive_period,omitempty"`
	QUICMaxIdleTimeout      int      `ini:"quic_max_idle_timeout,omitempty"`
	QUICMaxIncomingStreams  int      `ini:"quic_max_incoming_streams,omitempty"`
	LoginFailExit           bool     `ini:"login_fail_exit"`
	User                    string   `ini:"user,omitempty"`
	HeartbeatInterval       int64    `ini:"heartbeat_interval,omitempty"`
	HeartbeatTimeout        int64    `ini:"heartbeat_timeout,omitempty"`
	TCPMux                  bool     `ini:"tcp_mux"`
	TCPMuxKeepaliveInterval int64    `ini:"tcp_mux_keepalive_interval,omitempty"`
	TLSEnable               bool     `ini:"tls_enable"`
	TLSCertFile             string   `ini:"tls_cert_file,omitempty"`
	TLSKeyFile              string   `ini:"tls_key_file,omitempty"`
	TLSTrustedCaFile        string   `ini:"tls_trusted_ca_file,omitempty"`
	TLSServerName           string   `ini:"tls_server_name,omitempty"`
	UDPPacketSize           int64    `ini:"udp_packet_size,omitempty"`
	Start                   []string `ini:"start,omitempty"`

	// ManualStart defines whether to start the config on system boot.
	ManualStart bool `ini:"frpmgr_manual_start,omitempty"`
	// SVCBEnable resolves the SVCB record of server address.
	// By enabling this feature, the server address and port
	// can be updated dynamically.
	//
	// WARNING: This is an experimental feature.
	// It may affect the stability of the service.
	SVCBEnable bool `ini:"frpmgr_svcb_enable,omitempty"`
	// AutoDelete is a mechanism for temporary use.
	// The config will be stopped and deleted at some point.
	AutoDelete `ini:",extends"`
	// Custom collects all the unparsed options.
	Custom map[string]string `ini:"-"`
}

type ClientConfig

type ClientConfig struct {
	ClientCommon
	Proxies []*Proxy
}

func NewDefaultClientConfig

func NewDefaultClientConfig() *ClientConfig

func UnmarshalClientConfFromIni

func UnmarshalClientConfFromIni(source interface{}) (*ClientConfig, error)

func (*ClientConfig) AddItem

func (conf *ClientConfig) AddItem(item interface{}) bool

func (*ClientConfig) AutoStart

func (conf *ClientConfig) AutoStart() bool

func (*ClientConfig) Complete

func (conf *ClientConfig) Complete(read bool)

func (*ClientConfig) Copy added in v1.9.0

func (conf *ClientConfig) Copy(all bool) Config

func (*ClientConfig) CountStart added in v1.7.1

func (conf *ClientConfig) CountStart() int

CountStart returns the number of enabled proxies.

func (*ClientConfig) DeleteItem

func (conf *ClientConfig) DeleteItem(index int)

func (*ClientConfig) Expiry added in v1.13.0

func (conf *ClientConfig) Expiry() bool

func (*ClientConfig) GetLogFile

func (conf *ClientConfig) GetLogFile() string

func (*ClientConfig) GetSTUNServer added in v1.14.0

func (conf *ClientConfig) GetSTUNServer() string

func (*ClientConfig) ItemAt

func (conf *ClientConfig) ItemAt(index int) interface{}

func (*ClientConfig) Items

func (conf *ClientConfig) Items() interface{}

func (*ClientConfig) Save

func (conf *ClientConfig) Save(path string) error

type Config

type Config interface {
	// Items returns all sections in this config. which must be a slice of pointer to struct.
	Items() interface{}
	// ItemAt returns the section in this config for the given index.
	ItemAt(index int) interface{}
	// DeleteItem deletes the section for the given index.
	DeleteItem(index int)
	// AddItem adds a section to this config.
	AddItem(item interface{}) bool
	// Save serializes this config and saves to the given path.
	Save(path string) error
	// Complete prunes and completes this config.
	// When "read" is true, the config should be completed for a file loaded from source.
	// Otherwise, it should be completed for file written to disk.
	Complete(read bool)
	// GetLogFile returns the log file path of this config.
	GetLogFile() string
	// AutoStart indicates whether this config should be started at boot.
	AutoStart() bool
	// Expiry indicates whether the config has an expiry date.
	Expiry() bool
	// GetSTUNServer returns the STUN server to help penetrate NAT hole.
	GetSTUNServer() string
	// Copy creates a new copy of this config.
	Copy(all bool) Config
}

Config is the interface that a config must implement to support management.

type HealthCheckConf

type HealthCheckConf struct {
	// HealthCheckTimeoutS specifies the number of seconds to wait for a health
	// check attempt to connect. If the timeout is reached, this counts as a
	// health check failure. By default, this value is 3.
	HealthCheckTimeoutS int `ini:"health_check_timeout_s,omitempty" tcp:"true" http:"true"`
	// HealthCheckMaxFailed specifies the number of allowed failures before the
	// is stopped. By default, this value is 1.
	HealthCheckMaxFailed int `ini:"health_check_max_failed,omitempty" tcp:"true" http:"true"`
	// HealthCheckIntervalS specifies the time in seconds between health
	// checks. By default, this value is 10.
	HealthCheckIntervalS int `ini:"health_check_interval_s,omitempty" tcp:"true" http:"true"`
	// HealthCheckURL specifies the address to send health checks to if the
	// health check type is "http".
	HealthCheckURL string `ini:"health_check_url,omitempty" http:"true"`
}

HealthCheckConf configures health checking. This can be useful for load balancing purposes to detect and remove proxies to failing services.

type PluginParams

type PluginParams struct {
	PluginLocalAddr         string `ini:"plugin_local_addr,omitempty" http2https:"true" https2https:"true" https2http:"true"`
	PluginCrtPath           string `ini:"plugin_crt_path,omitempty" https2https:"true" https2http:"true"`
	PluginKeyPath           string `ini:"plugin_key_path,omitempty" https2https:"true" https2http:"true"`
	PluginHostHeaderRewrite string `ini:"plugin_host_header_rewrite,omitempty" http2https:"true" https2https:"true" https2http:"true"`
	PluginHttpUser          string `ini:"plugin_http_user,omitempty" http_proxy:"true" static_file:"true"`
	PluginHttpPasswd        string `ini:"plugin_http_passwd,omitempty" http_proxy:"true" static_file:"true"`
	PluginUser              string `ini:"plugin_user,omitempty" socks5:"true"`
	PluginPasswd            string `ini:"plugin_passwd,omitempty" socks5:"true"`
	PluginLocalPath         string `ini:"plugin_local_path,omitempty" static_file:"true"`
	PluginStripPrefix       string `ini:"plugin_strip_prefix,omitempty" static_file:"true"`
	PluginUnixPath          string `ini:"plugin_unix_path,omitempty" unix_domain_socket:"true"`
}

type Proxy

type Proxy struct {
	BaseProxyConf     `ini:",extends"`
	RemotePort        string `ini:"remote_port,omitempty" tcp:"true" udp:"true"`
	Role              string `ini:"role,omitempty" stcp:"true" xtcp:"true" sudp:"true" visitor:"*"`
	SK                string `ini:"sk,omitempty" stcp:"true" xtcp:"true" sudp:"true" visitor:"*"`
	AllowUsers        string `ini:"allow_users,omitempty" stcp:"true" xtcp:"true" sudp:"true"`
	ServerUser        string `ini:"server_user,omitempty" visitor:"*"`
	ServerName        string `ini:"server_name,omitempty" visitor:"*"`
	BindAddr          string `ini:"bind_addr,omitempty" visitor:"*"`
	BindPort          string `ini:"bind_port,omitempty" visitor:"*"`
	CustomDomains     string `ini:"custom_domains,omitempty" http:"true" https:"true" tcpmux:"true"`
	SubDomain         string `ini:"subdomain,omitempty" http:"true" https:"true" tcpmux:"true"`
	Locations         string `ini:"locations,omitempty" http:"true"`
	HTTPUser          string `ini:"http_user,omitempty" http:"true" tcpmux:"true"`
	HTTPPwd           string `ini:"http_pwd,omitempty" http:"true" tcpmux:"true"`
	HostHeaderRewrite string `ini:"host_header_rewrite,omitempty" http:"true"`
	Multiplexer       string `ini:"multiplexer,omitempty" tcpmux:"true"`
	RouteByHTTPUser   string `ini:"route_by_http_user,omitempty" http:"true" tcpmux:"true"`
	// "kcp" or "quic"
	Protocol          string `ini:"protocol,omitempty" visitor:"xtcp"`
	KeepTunnelOpen    bool   `ini:"keep_tunnel_open,omitempty" visitor:"xtcp"`
	MaxRetriesAnHour  int    `ini:"max_retries_an_hour,omitempty" visitor:"xtcp"`
	MinRetryInterval  int    `ini:"min_retry_interval,omitempty" visitor:"xtcp"`
	FallbackTo        string `ini:"fallback_to,omitempty" visitor:"xtcp"`
	FallbackTimeoutMs int    `ini:"fallback_timeout_ms,omitempty" visitor:"xtcp"`
}

func NewDefaultProxyConfig added in v1.8.0

func NewDefaultProxyConfig(name string) *Proxy

func NewProxyFromIni added in v1.8.0

func NewProxyFromIni(name string, section *ini.Section) (*Proxy, error)

NewProxyFromIni creates a proxy object from ini section

func UnmarshalProxyFromIni added in v1.8.0

func UnmarshalProxyFromIni(source interface{}) (*Proxy, error)

UnmarshalProxyFromIni finds a single proxy section and unmarshals it from ini source.

func (*Proxy) Complete added in v1.14.0

func (p *Proxy) Complete()

Complete removes redundant parameters base on the proxy type.

func (*Proxy) GetAlias added in v1.7.1

func (p *Proxy) GetAlias() []string

GetAlias returns the alias of this proxy. It's usually equal to the proxy name, but proxies that start with "range:" differ from it.

func (*Proxy) IsVisitor added in v1.10.0

func (p *Proxy) IsVisitor() bool

IsVisitor returns a boolean indicating whether the proxy has a visitor role.

func (*Proxy) Marshal added in v1.7.1

func (p *Proxy) Marshal() ([]byte, error)

Marshal returns the encoded proxy.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL