mirror of
https://github.com/fatedier/frp.git
synced 2025-07-27 07:35:07 +00:00
fix config parse logic (#2323)
This commit is contained in:
@@ -173,13 +173,21 @@ func GetDefaultClientConf() ClientCommonConf {
|
||||
}
|
||||
}
|
||||
|
||||
func (cfg *ClientCommonConf) Check() error {
|
||||
func (cfg *ClientCommonConf) Complete() {
|
||||
if cfg.LogFile == "console" {
|
||||
cfg.LogWay = "console"
|
||||
} else {
|
||||
cfg.LogWay = "file"
|
||||
}
|
||||
}
|
||||
|
||||
func (cfg *ClientCommonConf) Validate() error {
|
||||
if cfg.HeartbeatInterval <= 0 {
|
||||
return fmt.Errorf("Parse conf error: invalid heartbeat_interval")
|
||||
return fmt.Errorf("invalid heartbeat_interval")
|
||||
}
|
||||
|
||||
if cfg.HeartbeatTimeout < cfg.HeartbeatInterval {
|
||||
return fmt.Errorf("Parse conf error: invalid heartbeat_timeout, heartbeat_timeout is less than heartbeat_interval")
|
||||
return fmt.Errorf("invalid heartbeat_timeout, heartbeat_timeout is less than heartbeat_interval")
|
||||
}
|
||||
|
||||
if cfg.TLSEnable == false {
|
||||
@@ -196,6 +204,10 @@ func (cfg *ClientCommonConf) Check() error {
|
||||
}
|
||||
}
|
||||
|
||||
if cfg.Protocol != "tcp" && cfg.Protocol != "kcp" && cfg.Protocol != "websocket" {
|
||||
return fmt.Errorf("invalid protocol")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@@ -46,7 +46,7 @@ type ServerCommonConf struct {
|
||||
// this value is 0.
|
||||
KCPBindPort int `ini:"kcp_bind_port" 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".
|
||||
// may be the same as BindAddr.
|
||||
ProxyBindAddr string `ini:"proxy_bind_addr" json:"proxy_bind_addr"`
|
||||
// VhostHTTPPort specifies the port that the server listens for HTTP Vhost
|
||||
// requests. If this value is 0, the server will not listen for HTTP
|
||||
@@ -174,7 +174,7 @@ func GetDefaultServerConf() ServerCommonConf {
|
||||
BindPort: 7000,
|
||||
BindUDPPort: 0,
|
||||
KCPBindPort: 0,
|
||||
ProxyBindAddr: "0.0.0.0",
|
||||
ProxyBindAddr: "",
|
||||
VhostHTTPPort: 0,
|
||||
VhostHTTPSPort: 0,
|
||||
TCPMuxHTTPConnectPort: 0,
|
||||
@@ -208,10 +208,6 @@ func GetDefaultServerConf() ServerCommonConf {
|
||||
}
|
||||
}
|
||||
|
||||
func (cfg *ServerCommonConf) Check() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func UnmarshalServerConfFromIni(source interface{}) (ServerCommonConf, error) {
|
||||
|
||||
f, err := ini.LoadSources(ini.LoadOptions{
|
||||
@@ -242,7 +238,7 @@ func UnmarshalServerConfFromIni(source interface{}) (ServerCommonConf, error) {
|
||||
if allowPortStr != "" {
|
||||
allowPorts, err := util.ParseRangeNumbers(allowPortStr)
|
||||
if err != nil {
|
||||
return ServerCommonConf{}, fmt.Errorf("Parse conf error: allow_ports: %v", err)
|
||||
return ServerCommonConf{}, fmt.Errorf("invalid allow_ports: %v", err)
|
||||
}
|
||||
for _, port := range allowPorts {
|
||||
common.AllowPorts[int(port)] = struct{}{}
|
||||
@@ -269,6 +265,26 @@ func UnmarshalServerConfFromIni(source interface{}) (ServerCommonConf, error) {
|
||||
return common, nil
|
||||
}
|
||||
|
||||
func (cfg *ServerCommonConf) Complete() {
|
||||
if cfg.LogFile == "console" {
|
||||
cfg.LogWay = "console"
|
||||
} else {
|
||||
cfg.LogWay = "file"
|
||||
}
|
||||
|
||||
if cfg.ProxyBindAddr == "" {
|
||||
cfg.ProxyBindAddr = cfg.BindAddr
|
||||
}
|
||||
|
||||
if cfg.TLSTrustedCaFile != "" {
|
||||
cfg.TLSOnly = true
|
||||
}
|
||||
}
|
||||
|
||||
func (cfg *ServerCommonConf) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func loadHTTPPluginOpt(section *ini.Section) (*plugin.HTTPPluginOptions, error) {
|
||||
name := strings.TrimSpace(strings.TrimPrefix(section.Name(), "plugin."))
|
||||
|
||||
|
@@ -18,7 +18,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/fatedier/frp/pkg/auth"
|
||||
"github.com/fatedier/frp/pkg/plugin/server"
|
||||
plugin "github.com/fatedier/frp/pkg/plugin/server"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
@@ -133,7 +133,7 @@ func Test_LoadServerCommonConf(t *testing.T) {
|
||||
},
|
||||
MaxPoolCount: 59,
|
||||
MaxPortsPerClient: 9,
|
||||
TLSOnly: false,
|
||||
TLSOnly: true,
|
||||
TLSCertFile: "server.crt",
|
||||
TLSKeyFile: "server.key",
|
||||
TLSTrustedCaFile: "ca.crt",
|
||||
@@ -177,7 +177,7 @@ func Test_LoadServerCommonConf(t *testing.T) {
|
||||
BindAddr: "0.0.0.9",
|
||||
BindPort: 7009,
|
||||
BindUDPPort: 7008,
|
||||
ProxyBindAddr: "0.0.0.0",
|
||||
ProxyBindAddr: "0.0.0.9",
|
||||
VhostHTTPTimeout: 60,
|
||||
DashboardAddr: "0.0.0.0",
|
||||
DashboardUser: "admin",
|
||||
@@ -202,6 +202,7 @@ func Test_LoadServerCommonConf(t *testing.T) {
|
||||
for _, c := range testcases {
|
||||
actual, err := UnmarshalServerConfFromIni(c.source)
|
||||
assert.NoError(err)
|
||||
actual.Complete()
|
||||
assert.Equal(c.expected, actual)
|
||||
}
|
||||
}
|
||||
|
@@ -19,7 +19,7 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
var version string = "0.36.1"
|
||||
var version string = "0.36.2"
|
||||
|
||||
func Full() string {
|
||||
return version
|
||||
|
Reference in New Issue
Block a user