1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063 |
- package config
- import (
- "fmt"
- "reflect"
- "strings"
- "github.com/fatedier/frp/pkg/consts"
- "github.com/fatedier/frp/pkg/msg"
- "gopkg.in/ini.v1"
- )
- var (
- proxyConfTypeMap = map[string]reflect.Type{
- consts.TCPProxy: reflect.TypeOf(TCPProxyConf{}),
- consts.TCPMuxProxy: reflect.TypeOf(TCPMuxProxyConf{}),
- consts.UDPProxy: reflect.TypeOf(UDPProxyConf{}),
- consts.HTTPProxy: reflect.TypeOf(HTTPProxyConf{}),
- consts.HTTPSProxy: reflect.TypeOf(HTTPSProxyConf{}),
- consts.STCPProxy: reflect.TypeOf(STCPProxyConf{}),
- consts.XTCPProxy: reflect.TypeOf(XTCPProxyConf{}),
- consts.SUDPProxy: reflect.TypeOf(SUDPProxyConf{}),
- }
- )
- func NewConfByType(proxyType string) ProxyConf {
- v, ok := proxyConfTypeMap[proxyType]
- if !ok {
- return nil
- }
- cfg := reflect.New(v).Interface().(ProxyConf)
- return cfg
- }
- type ProxyConf interface {
- GetBaseInfo() *BaseProxyConf
- UnmarshalFromMsg(*msg.NewProxy)
- UnmarshalFromIni(string, string, *ini.Section) error
- MarshalToMsg(*msg.NewProxy)
- CheckForCli() error
- CheckForSvr(ServerCommonConf) error
- Compare(ProxyConf) bool
- }
- type LocalSvrConf struct {
-
- LocalIP string `ini:"local_ip" json:"local_ip"`
-
- LocalPort int `ini:"local_port" json:"local_port"`
-
-
-
- Plugin string `ini:"plugin" json:"plugin"`
-
-
- PluginParams map[string]string `ini:"-"`
- }
- type HealthCheckConf struct {
-
-
-
-
-
-
-
-
-
-
- HealthCheckType string `ini:"health_check_type" json:"health_check_type"`
-
-
-
- HealthCheckTimeoutS int `ini:"health_check_timeout_s" json:"health_check_timeout_s"`
-
-
- HealthCheckMaxFailed int `ini:"health_check_max_failed" json:"health_check_max_failed"`
-
-
- HealthCheckIntervalS int `ini:"health_check_interval_s" json:"health_check_interval_s"`
-
-
- HealthCheckURL string `ini:"health_check_url" json:"health_check_url"`
-
-
- HealthCheckAddr string `ini:"-"`
- }
- type BaseProxyConf struct {
-
- ProxyName string `ini:"name" json:"name"`
-
-
-
- ProxyType string `ini:"type" json:"type"`
-
-
-
- UseEncryption bool `ini:"use_encryption" json:"use_encryption"`
-
-
- UseCompression bool `ini:"use_compression" json:"use_compression"`
-
-
-
- Group string `ini:"group" json:"group"`
-
-
- GroupKey string `ini:"group_key" json:"group_key"`
-
-
-
- ProxyProtocolVersion string `ini:"proxy_protocol_version" json:"proxy_protocol_version"`
-
-
- BandwidthLimit BandwidthQuantity `ini:"bandwidth_limit" json:"bandwidth_limit"`
-
- Metas map[string]string `ini:"-" json:"metas"`
- LocalSvrConf `ini:",extends"`
- HealthCheckConf `ini:",extends"`
- }
- type DomainConf struct {
- CustomDomains []string `ini:"custom_domains" json:"custom_domains"`
- SubDomain string `ini:"subdomain" json:"subdomain"`
- }
- type HTTPProxyConf struct {
- BaseProxyConf `ini:",extends"`
- DomainConf `ini:",extends"`
- Locations []string `ini:"locations" json:"locations"`
- HTTPUser string `ini:"http_user" json:"http_user"`
- HTTPPwd string `ini:"http_pwd" json:"http_pwd"`
- HostHeaderRewrite string `ini:"host_header_rewrite" json:"host_header_rewrite"`
- Headers map[string]string `ini:"-" json:"headers"`
- }
- type HTTPSProxyConf struct {
- BaseProxyConf `ini:",extends"`
- DomainConf `ini:",extends"`
- }
- type TCPProxyConf struct {
- BaseProxyConf `ini:",extends"`
- RemotePort int `ini:"remote_port" json:"remote_port"`
- }
- type TCPMuxProxyConf struct {
- BaseProxyConf `ini:",extends"`
- DomainConf `ini:",extends"`
- Multiplexer string `ini:"multiplexer"`
- }
- type STCPProxyConf struct {
- BaseProxyConf `ini:",extends"`
- Role string `ini:"role" json:"role"`
- Sk string `ini:"sk" json:"sk"`
- }
- type XTCPProxyConf struct {
- BaseProxyConf `ini:",extends"`
- Role string `ini:"role" json:"role"`
- Sk string `ini:"sk" json:"sk"`
- }
- type UDPProxyConf struct {
- BaseProxyConf `ini:",extends"`
- RemotePort int `ini:"remote_port" json:"remote_port"`
- }
- type SUDPProxyConf struct {
- BaseProxyConf `ini:",extends"`
- Role string `ini:"role" json:"role"`
- Sk string `ini:"sk" json:"sk"`
- }
- func DefaultProxyConf(proxyType string) ProxyConf {
- var conf ProxyConf
- switch proxyType {
- case consts.TCPProxy:
- conf = &TCPProxyConf{
- BaseProxyConf: defaultBaseProxyConf(proxyType),
- }
- case consts.TCPMuxProxy:
- conf = &TCPMuxProxyConf{
- BaseProxyConf: defaultBaseProxyConf(proxyType),
- }
- case consts.UDPProxy:
- conf = &UDPProxyConf{
- BaseProxyConf: defaultBaseProxyConf(proxyType),
- }
- case consts.HTTPProxy:
- conf = &HTTPProxyConf{
- BaseProxyConf: defaultBaseProxyConf(proxyType),
- }
- case consts.HTTPSProxy:
- conf = &HTTPSProxyConf{
- BaseProxyConf: defaultBaseProxyConf(proxyType),
- }
- case consts.STCPProxy:
- conf = &STCPProxyConf{
- BaseProxyConf: defaultBaseProxyConf(proxyType),
- Role: "server",
- }
- case consts.XTCPProxy:
- conf = &XTCPProxyConf{
- BaseProxyConf: defaultBaseProxyConf(proxyType),
- Role: "server",
- }
- case consts.SUDPProxy:
- conf = &SUDPProxyConf{
- BaseProxyConf: defaultBaseProxyConf(proxyType),
- Role: "server",
- }
- default:
- return nil
- }
- return conf
- }
- func NewProxyConfFromIni(prefix, name string, section *ini.Section) (ProxyConf, error) {
-
- proxyType := section.Key("type").String()
- if proxyType == "" {
- proxyType = consts.TCPProxy
- }
- conf := DefaultProxyConf(proxyType)
- if conf == nil {
- return nil, fmt.Errorf("proxy %s has invalid type [%s]", name, proxyType)
- }
- if err := conf.UnmarshalFromIni(prefix, name, section); err != nil {
- return nil, err
- }
- if err := conf.CheckForCli(); err != nil {
- return nil, err
- }
- return conf, nil
- }
- func NewProxyConfFromMsg(pMsg *msg.NewProxy, serverCfg ServerCommonConf) (ProxyConf, error) {
- if pMsg.ProxyType == "" {
- pMsg.ProxyType = consts.TCPProxy
- }
- conf := DefaultProxyConf(pMsg.ProxyType)
- if conf == nil {
- return nil, fmt.Errorf("proxy [%s] type [%s] error", pMsg.ProxyName, pMsg.ProxyType)
- }
- conf.UnmarshalFromMsg(pMsg)
- err := conf.CheckForSvr(serverCfg)
- if err != nil {
- return nil, err
- }
- return conf, nil
- }
- func defaultBaseProxyConf(proxyType string) BaseProxyConf {
- return BaseProxyConf{
- ProxyType: proxyType,
- LocalSvrConf: LocalSvrConf{
- LocalIP: "127.0.0.1",
- },
- }
- }
- func (cfg *BaseProxyConf) GetBaseInfo() *BaseProxyConf {
- return cfg
- }
- func (cfg *BaseProxyConf) compare(cmp *BaseProxyConf) bool {
- if cfg.ProxyName != cmp.ProxyName ||
- cfg.ProxyType != cmp.ProxyType ||
- cfg.UseEncryption != cmp.UseEncryption ||
- cfg.UseCompression != cmp.UseCompression ||
- cfg.Group != cmp.Group ||
- cfg.GroupKey != cmp.GroupKey ||
- cfg.ProxyProtocolVersion != cmp.ProxyProtocolVersion ||
- !cfg.BandwidthLimit.Equal(&cmp.BandwidthLimit) ||
- !reflect.DeepEqual(cfg.Metas, cmp.Metas) {
- return false
- }
- if !reflect.DeepEqual(cfg.LocalSvrConf, cmp.LocalSvrConf) {
- return false
- }
- if !reflect.DeepEqual(cfg.HealthCheckConf, cmp.HealthCheckConf) {
- return false
- }
- return true
- }
- func (cfg *BaseProxyConf) decorate(prefix string, name string, section *ini.Section) error {
-
- cfg.ProxyName = prefix + name
-
- cfg.Metas = GetMapWithoutPrefix(section.KeysHash(), "meta_")
-
- if bandwidth, err := section.GetKey("bandwidth_limit"); err == nil {
- cfg.BandwidthLimit, err = NewBandwidthQuantity(bandwidth.String())
- if err != nil {
- return err
- }
- }
-
- cfg.LocalSvrConf.PluginParams = GetMapByPrefix(section.KeysHash(), "plugin_")
-
- if cfg.HealthCheckType == "tcp" && cfg.Plugin == "" {
- cfg.HealthCheckAddr = cfg.LocalIP + fmt.Sprintf(":%d", cfg.LocalPort)
- }
- if cfg.HealthCheckType == "http" && cfg.Plugin == "" && cfg.HealthCheckURL != "" {
- s := fmt.Sprintf("http://%s:%d", cfg.LocalIP, cfg.LocalPort)
- if !strings.HasPrefix(cfg.HealthCheckURL, "/") {
- s += "/"
- }
- cfg.HealthCheckURL = s + cfg.HealthCheckURL
- }
- return nil
- }
- func (cfg *BaseProxyConf) marshalToMsg(pMsg *msg.NewProxy) {
- pMsg.ProxyName = cfg.ProxyName
- pMsg.ProxyType = cfg.ProxyType
- pMsg.UseEncryption = cfg.UseEncryption
- pMsg.UseCompression = cfg.UseCompression
- pMsg.Group = cfg.Group
- pMsg.GroupKey = cfg.GroupKey
- pMsg.Metas = cfg.Metas
- }
- func (cfg *BaseProxyConf) unmarshalFromMsg(pMsg *msg.NewProxy) {
- cfg.ProxyName = pMsg.ProxyName
- cfg.ProxyType = pMsg.ProxyType
- cfg.UseEncryption = pMsg.UseEncryption
- cfg.UseCompression = pMsg.UseCompression
- cfg.Group = pMsg.Group
- cfg.GroupKey = pMsg.GroupKey
- cfg.Metas = pMsg.Metas
- }
- func (cfg *BaseProxyConf) checkForCli() (err error) {
- if cfg.ProxyProtocolVersion != "" {
- if cfg.ProxyProtocolVersion != "v1" && cfg.ProxyProtocolVersion != "v2" {
- return fmt.Errorf("no support proxy protocol version: %s", cfg.ProxyProtocolVersion)
- }
- }
- if err = cfg.LocalSvrConf.checkForCli(); err != nil {
- return
- }
- if err = cfg.HealthCheckConf.checkForCli(); err != nil {
- return
- }
- return nil
- }
- func (cfg *BaseProxyConf) checkForSvr(conf ServerCommonConf) error {
- return nil
- }
- func (cfg *DomainConf) check() (err error) {
- if len(cfg.CustomDomains) == 0 && cfg.SubDomain == "" {
- err = fmt.Errorf("custom_domains and subdomain should set at least one of them")
- return
- }
- return
- }
- func (cfg *DomainConf) checkForCli() (err error) {
- if err = cfg.check(); err != nil {
- return
- }
- return
- }
- func (cfg *DomainConf) checkForSvr(serverCfg ServerCommonConf) (err error) {
- if err = cfg.check(); err != nil {
- return
- }
- for _, domain := range cfg.CustomDomains {
- if serverCfg.SubDomainHost != "" && len(strings.Split(serverCfg.SubDomainHost, ".")) < len(strings.Split(domain, ".")) {
- if strings.Contains(domain, serverCfg.SubDomainHost) {
- return fmt.Errorf("custom domain [%s] should not belong to subdomain_host [%s]", domain, serverCfg.SubDomainHost)
- }
- }
- }
- if cfg.SubDomain != "" {
- if serverCfg.SubDomainHost == "" {
- return fmt.Errorf("subdomain is not supported because this feature is not enabled in remote frps")
- }
- if strings.Contains(cfg.SubDomain, ".") || strings.Contains(cfg.SubDomain, "*") {
- return fmt.Errorf("'.' and '*' is not supported in subdomain")
- }
- }
- return nil
- }
- func (cfg *LocalSvrConf) checkForCli() (err error) {
- if cfg.Plugin == "" {
- if cfg.LocalIP == "" {
- err = fmt.Errorf("local ip or plugin is required")
- return
- }
- if cfg.LocalPort <= 0 {
- err = fmt.Errorf("error local_port")
- return
- }
- }
- return
- }
- func (cfg *HealthCheckConf) checkForCli() error {
- if cfg.HealthCheckType != "" && cfg.HealthCheckType != "tcp" && cfg.HealthCheckType != "http" {
- return fmt.Errorf("unsupport health check type")
- }
- if cfg.HealthCheckType != "" {
- if cfg.HealthCheckType == "http" && cfg.HealthCheckURL == "" {
- return fmt.Errorf("health_check_url is required for health check type 'http'")
- }
- }
- return nil
- }
- func preUnmarshalFromIni(cfg ProxyConf, prefix string, name string, section *ini.Section) error {
- err := section.MapTo(cfg)
- if err != nil {
- return err
- }
- err = cfg.GetBaseInfo().decorate(prefix, name, section)
- if err != nil {
- return err
- }
- return nil
- }
- func (cfg *TCPProxyConf) Compare(cmp ProxyConf) bool {
- cmpConf, ok := cmp.(*TCPProxyConf)
- if !ok {
- return false
- }
- if !cfg.BaseProxyConf.compare(&cmpConf.BaseProxyConf) {
- return false
- }
-
- if cfg.RemotePort != cmpConf.RemotePort {
- return false
- }
- return true
- }
- func (cfg *TCPProxyConf) UnmarshalFromMsg(pMsg *msg.NewProxy) {
- cfg.BaseProxyConf.unmarshalFromMsg(pMsg)
-
- cfg.RemotePort = pMsg.RemotePort
- }
- func (cfg *TCPProxyConf) UnmarshalFromIni(prefix string, name string, section *ini.Section) error {
- err := preUnmarshalFromIni(cfg, prefix, name, section)
- if err != nil {
- return err
- }
-
- return nil
- }
- func (cfg *TCPProxyConf) MarshalToMsg(pMsg *msg.NewProxy) {
- cfg.BaseProxyConf.marshalToMsg(pMsg)
-
- pMsg.RemotePort = cfg.RemotePort
- }
- func (cfg *TCPProxyConf) CheckForCli() (err error) {
- if err = cfg.BaseProxyConf.checkForCli(); err != nil {
- return
- }
-
- return
- }
- func (cfg *TCPProxyConf) CheckForSvr(serverCfg ServerCommonConf) error {
- return nil
- }
- func (cfg *TCPMuxProxyConf) Compare(cmp ProxyConf) bool {
- cmpConf, ok := cmp.(*TCPMuxProxyConf)
- if !ok {
- return false
- }
- if !cfg.BaseProxyConf.compare(&cmpConf.BaseProxyConf) {
- return false
- }
-
- if !reflect.DeepEqual(cfg.DomainConf, cmpConf.DomainConf) {
- return false
- }
- if cfg.Multiplexer != cmpConf.Multiplexer {
- return false
- }
- return true
- }
- func (cfg *TCPMuxProxyConf) UnmarshalFromIni(prefix string, name string, section *ini.Section) error {
- err := preUnmarshalFromIni(cfg, prefix, name, section)
- if err != nil {
- return err
- }
-
- return nil
- }
- func (cfg *TCPMuxProxyConf) UnmarshalFromMsg(pMsg *msg.NewProxy) {
- cfg.BaseProxyConf.unmarshalFromMsg(pMsg)
-
- cfg.CustomDomains = pMsg.CustomDomains
- cfg.SubDomain = pMsg.SubDomain
- cfg.Multiplexer = pMsg.Multiplexer
- }
- func (cfg *TCPMuxProxyConf) MarshalToMsg(pMsg *msg.NewProxy) {
- cfg.BaseProxyConf.marshalToMsg(pMsg)
-
- pMsg.CustomDomains = cfg.CustomDomains
- pMsg.SubDomain = cfg.SubDomain
- pMsg.Multiplexer = cfg.Multiplexer
- }
- func (cfg *TCPMuxProxyConf) CheckForCli() (err error) {
- if err = cfg.BaseProxyConf.checkForCli(); err != nil {
- return
- }
-
- if err = cfg.DomainConf.checkForCli(); err != nil {
- return
- }
- if cfg.Multiplexer != consts.HTTPConnectTCPMultiplexer {
- return fmt.Errorf("parse conf error: incorrect multiplexer [%s]", cfg.Multiplexer)
- }
- return
- }
- func (cfg *TCPMuxProxyConf) CheckForSvr(serverCfg ServerCommonConf) (err error) {
- if cfg.Multiplexer != consts.HTTPConnectTCPMultiplexer {
- return fmt.Errorf("proxy [%s] incorrect multiplexer [%s]", cfg.ProxyName, cfg.Multiplexer)
- }
- if cfg.Multiplexer == consts.HTTPConnectTCPMultiplexer && serverCfg.TCPMuxHTTPConnectPort == 0 {
- return fmt.Errorf("proxy [%s] type [tcpmux] with multiplexer [httpconnect] requires tcpmux_httpconnect_port configuration", cfg.ProxyName)
- }
- if err = cfg.DomainConf.checkForSvr(serverCfg); err != nil {
- err = fmt.Errorf("proxy [%s] domain conf check error: %v", cfg.ProxyName, err)
- return
- }
- return
- }
- func (cfg *UDPProxyConf) Compare(cmp ProxyConf) bool {
- cmpConf, ok := cmp.(*UDPProxyConf)
- if !ok {
- return false
- }
- if !cfg.BaseProxyConf.compare(&cmpConf.BaseProxyConf) {
- return false
- }
-
- if cfg.RemotePort != cmpConf.RemotePort {
- return false
- }
- return true
- }
- func (cfg *UDPProxyConf) UnmarshalFromIni(prefix string, name string, section *ini.Section) error {
- err := preUnmarshalFromIni(cfg, prefix, name, section)
- if err != nil {
- return err
- }
-
- return nil
- }
- func (cfg *UDPProxyConf) UnmarshalFromMsg(pMsg *msg.NewProxy) {
- cfg.BaseProxyConf.unmarshalFromMsg(pMsg)
-
- cfg.RemotePort = pMsg.RemotePort
- }
- func (cfg *UDPProxyConf) MarshalToMsg(pMsg *msg.NewProxy) {
- cfg.BaseProxyConf.marshalToMsg(pMsg)
-
- pMsg.RemotePort = cfg.RemotePort
- }
- func (cfg *UDPProxyConf) CheckForCli() (err error) {
- if err = cfg.BaseProxyConf.checkForCli(); err != nil {
- return
- }
-
- return
- }
- func (cfg *UDPProxyConf) CheckForSvr(serverCfg ServerCommonConf) error {
- return nil
- }
- func (cfg *HTTPProxyConf) Compare(cmp ProxyConf) bool {
- cmpConf, ok := cmp.(*HTTPProxyConf)
- if !ok {
- return false
- }
- if !cfg.BaseProxyConf.compare(&cmpConf.BaseProxyConf) {
- return false
- }
-
- if !reflect.DeepEqual(cfg.DomainConf, cmpConf.DomainConf) {
- return false
- }
- if !reflect.DeepEqual(cfg.Locations, cmpConf.Locations) ||
- cfg.HTTPUser != cmpConf.HTTPUser ||
- cfg.HTTPPwd != cmpConf.HTTPPwd ||
- cfg.HostHeaderRewrite != cmpConf.HostHeaderRewrite ||
- !reflect.DeepEqual(cfg.Headers, cmpConf.Headers) {
- return false
- }
- return true
- }
- func (cfg *HTTPProxyConf) UnmarshalFromIni(prefix string, name string, section *ini.Section) error {
- err := preUnmarshalFromIni(cfg, prefix, name, section)
- if err != nil {
- return err
- }
-
- cfg.Headers = GetMapWithoutPrefix(section.KeysHash(), "header_")
- return nil
- }
- func (cfg *HTTPProxyConf) UnmarshalFromMsg(pMsg *msg.NewProxy) {
- cfg.BaseProxyConf.unmarshalFromMsg(pMsg)
-
- cfg.CustomDomains = pMsg.CustomDomains
- cfg.SubDomain = pMsg.SubDomain
- cfg.Locations = pMsg.Locations
- cfg.HostHeaderRewrite = pMsg.HostHeaderRewrite
- cfg.HTTPUser = pMsg.HTTPUser
- cfg.HTTPPwd = pMsg.HTTPPwd
- cfg.Headers = pMsg.Headers
- }
- func (cfg *HTTPProxyConf) MarshalToMsg(pMsg *msg.NewProxy) {
- cfg.BaseProxyConf.marshalToMsg(pMsg)
-
- pMsg.CustomDomains = cfg.CustomDomains
- pMsg.SubDomain = cfg.SubDomain
- pMsg.Locations = cfg.Locations
- pMsg.HostHeaderRewrite = cfg.HostHeaderRewrite
- pMsg.HTTPUser = cfg.HTTPUser
- pMsg.HTTPPwd = cfg.HTTPPwd
- pMsg.Headers = cfg.Headers
- }
- func (cfg *HTTPProxyConf) CheckForCli() (err error) {
- if err = cfg.BaseProxyConf.checkForCli(); err != nil {
- return
- }
-
- if err = cfg.DomainConf.checkForCli(); err != nil {
- return
- }
- return
- }
- func (cfg *HTTPProxyConf) CheckForSvr(serverCfg ServerCommonConf) (err error) {
- if serverCfg.VhostHTTPPort == 0 {
- return fmt.Errorf("type [http] not support when vhost_http_port is not set")
- }
- if err = cfg.DomainConf.checkForSvr(serverCfg); err != nil {
- err = fmt.Errorf("proxy [%s] domain conf check error: %v", cfg.ProxyName, err)
- return
- }
- return
- }
- func (cfg *HTTPSProxyConf) Compare(cmp ProxyConf) bool {
- cmpConf, ok := cmp.(*HTTPSProxyConf)
- if !ok {
- return false
- }
- if !cfg.BaseProxyConf.compare(&cmpConf.BaseProxyConf) {
- return false
- }
-
- if !reflect.DeepEqual(cfg.DomainConf, cmpConf.DomainConf) {
- return false
- }
- return true
- }
- func (cfg *HTTPSProxyConf) UnmarshalFromIni(prefix string, name string, section *ini.Section) error {
- err := preUnmarshalFromIni(cfg, prefix, name, section)
- if err != nil {
- return err
- }
-
- return nil
- }
- func (cfg *HTTPSProxyConf) UnmarshalFromMsg(pMsg *msg.NewProxy) {
- cfg.BaseProxyConf.unmarshalFromMsg(pMsg)
-
- cfg.CustomDomains = pMsg.CustomDomains
- cfg.SubDomain = pMsg.SubDomain
- }
- func (cfg *HTTPSProxyConf) MarshalToMsg(pMsg *msg.NewProxy) {
- cfg.BaseProxyConf.marshalToMsg(pMsg)
-
- pMsg.CustomDomains = cfg.CustomDomains
- pMsg.SubDomain = cfg.SubDomain
- }
- func (cfg *HTTPSProxyConf) CheckForCli() (err error) {
- if err = cfg.BaseProxyConf.checkForCli(); err != nil {
- return
- }
-
- if err = cfg.DomainConf.checkForCli(); err != nil {
- return
- }
- return
- }
- func (cfg *HTTPSProxyConf) CheckForSvr(serverCfg ServerCommonConf) (err error) {
- if serverCfg.VhostHTTPSPort == 0 {
- return fmt.Errorf("type [https] not support when vhost_https_port is not set")
- }
- if err = cfg.DomainConf.checkForSvr(serverCfg); err != nil {
- err = fmt.Errorf("proxy [%s] domain conf check error: %v", cfg.ProxyName, err)
- return
- }
- return
- }
- func (cfg *SUDPProxyConf) Compare(cmp ProxyConf) bool {
- cmpConf, ok := cmp.(*SUDPProxyConf)
- if !ok {
- return false
- }
- if !cfg.BaseProxyConf.compare(&cmpConf.BaseProxyConf) {
- return false
- }
-
- if cfg.Role != cmpConf.Role ||
- cfg.Sk != cmpConf.Sk {
- return false
- }
- return true
- }
- func (cfg *SUDPProxyConf) UnmarshalFromIni(prefix string, name string, section *ini.Section) error {
- err := preUnmarshalFromIni(cfg, prefix, name, section)
- if err != nil {
- return err
- }
-
- return nil
- }
- func (cfg *SUDPProxyConf) UnmarshalFromMsg(pMsg *msg.NewProxy) {
- cfg.BaseProxyConf.unmarshalFromMsg(pMsg)
-
- cfg.Sk = pMsg.Sk
- }
- func (cfg *SUDPProxyConf) MarshalToMsg(pMsg *msg.NewProxy) {
- cfg.BaseProxyConf.marshalToMsg(pMsg)
-
- pMsg.Sk = cfg.Sk
- }
- func (cfg *SUDPProxyConf) CheckForCli() (err error) {
- if err := cfg.BaseProxyConf.checkForCli(); err != nil {
- return err
- }
-
- if cfg.Role != "server" {
- return fmt.Errorf("role should be 'server'")
- }
- return nil
- }
- func (cfg *SUDPProxyConf) CheckForSvr(serverCfg ServerCommonConf) error {
- return nil
- }
- func (cfg *STCPProxyConf) Compare(cmp ProxyConf) bool {
- cmpConf, ok := cmp.(*STCPProxyConf)
- if !ok {
- return false
- }
- if !cfg.BaseProxyConf.compare(&cmpConf.BaseProxyConf) {
- return false
- }
-
- if cfg.Role != cmpConf.Role ||
- cfg.Sk != cmpConf.Sk {
- return false
- }
- return true
- }
- func (cfg *STCPProxyConf) UnmarshalFromIni(prefix string, name string, section *ini.Section) error {
- err := preUnmarshalFromIni(cfg, prefix, name, section)
- if err != nil {
- return err
- }
-
- if cfg.Role == "" {
- cfg.Role = "server"
- }
- return nil
- }
- func (cfg *STCPProxyConf) UnmarshalFromMsg(pMsg *msg.NewProxy) {
- cfg.BaseProxyConf.unmarshalFromMsg(pMsg)
-
- cfg.Sk = pMsg.Sk
- }
- func (cfg *STCPProxyConf) MarshalToMsg(pMsg *msg.NewProxy) {
- cfg.BaseProxyConf.marshalToMsg(pMsg)
-
- pMsg.Sk = cfg.Sk
- }
- func (cfg *STCPProxyConf) CheckForCli() (err error) {
- if err = cfg.BaseProxyConf.checkForCli(); err != nil {
- return
- }
-
- if cfg.Role != "server" {
- return fmt.Errorf("role should be 'server'")
- }
- return
- }
- func (cfg *STCPProxyConf) CheckForSvr(serverCfg ServerCommonConf) error {
- return nil
- }
- func (cfg *XTCPProxyConf) Compare(cmp ProxyConf) bool {
- cmpConf, ok := cmp.(*XTCPProxyConf)
- if !ok {
- return false
- }
- if !cfg.BaseProxyConf.compare(&cmpConf.BaseProxyConf) {
- return false
- }
-
- if cfg.Role != cmpConf.Role ||
- cfg.Sk != cmpConf.Sk {
- return false
- }
- return true
- }
- func (cfg *XTCPProxyConf) UnmarshalFromIni(prefix string, name string, section *ini.Section) error {
- err := preUnmarshalFromIni(cfg, prefix, name, section)
- if err != nil {
- return err
- }
-
- if cfg.Role == "" {
- cfg.Role = "server"
- }
- return nil
- }
- func (cfg *XTCPProxyConf) UnmarshalFromMsg(pMsg *msg.NewProxy) {
- cfg.BaseProxyConf.unmarshalFromMsg(pMsg)
-
- cfg.Sk = pMsg.Sk
- }
- func (cfg *XTCPProxyConf) MarshalToMsg(pMsg *msg.NewProxy) {
- cfg.BaseProxyConf.marshalToMsg(pMsg)
-
- pMsg.Sk = cfg.Sk
- }
- func (cfg *XTCPProxyConf) CheckForCli() (err error) {
- if err = cfg.BaseProxyConf.checkForCli(); err != nil {
- return
- }
-
- if cfg.Role != "server" {
- return fmt.Errorf("role should be 'server'")
- }
- return
- }
- func (cfg *XTCPProxyConf) CheckForSvr(serverCfg ServerCommonConf) error {
- return nil
- }
|