mirror of
https://gitee.com/IrisVega/frp.git
synced 2024-11-01 22:31:29 +08:00
fix config parse logic (#2323)
This commit is contained in:
parent
6b80861bd6
commit
9a849a29e9
File diff suppressed because one or more lines are too long
@ -1 +1 @@
|
|||||||
<!doctype html> <html lang=en> <head> <meta charset=utf-8> <title>frps dashboard</title> <link rel="shortcut icon" href="favicon.ico"></head> <body> <div id=app></div> <script type="text/javascript" src="manifest.js?9cdfcd28c7394b82e47d"></script><script type="text/javascript" src="vendor.js?6aeb7e29d75bc1975785"></script></body> </html>
|
<!doctype html> <html lang=en> <head> <meta charset=utf-8> <title>frps dashboard</title> <link rel="shortcut icon" href="favicon.ico"></head> <body> <div id=app></div> <script type="text/javascript" src="manifest.js?782d7b1b910e824ac986"></script><script type="text/javascript" src="vendor.js?7f899297af075fb3b085"></script></body> </html>
|
@ -1 +1 @@
|
|||||||
!function(e){function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}var r=window.webpackJsonp;window.webpackJsonp=function(t,c,u){for(var i,a,f,l=0,s=[];l<t.length;l++)a=t[l],o[a]&&s.push(o[a][0]),o[a]=0;for(i in c)Object.prototype.hasOwnProperty.call(c,i)&&(e[i]=c[i]);for(r&&r(t,c,u);s.length;)s.shift()();if(u)for(l=0;l<u.length;l++)f=n(n.s=u[l]);return f};var t={},o={1:0};n.e=function(e){function r(){i.onerror=i.onload=null,clearTimeout(a);var n=o[e];0!==n&&(n&&n[1](new Error("Loading chunk "+e+" failed.")),o[e]=void 0)}var t=o[e];if(0===t)return new Promise(function(e){e()});if(t)return t[2];var c=new Promise(function(n,r){t=o[e]=[n,r]});t[2]=c;var u=document.getElementsByTagName("head")[0],i=document.createElement("script");i.type="text/javascript",i.charset="utf-8",i.async=!0,i.timeout=12e4,n.nc&&i.setAttribute("nonce",n.nc),i.src=n.p+""+e+".js?"+{0:"6aeb7e29d75bc1975785"}[e];var a=setTimeout(r,12e4);return i.onerror=i.onload=r,u.appendChild(i),c},n.m=e,n.c=t,n.i=function(e){return e},n.d=function(e,r,t){n.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:t})},n.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(r,"a",r),r},n.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},n.p="",n.oe=function(e){throw console.error(e),e}}([]);
|
!function(e){function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}var r=window.webpackJsonp;window.webpackJsonp=function(t,u,c){for(var i,a,f,l=0,s=[];l<t.length;l++)a=t[l],o[a]&&s.push(o[a][0]),o[a]=0;for(i in u)Object.prototype.hasOwnProperty.call(u,i)&&(e[i]=u[i]);for(r&&r(t,u,c);s.length;)s.shift()();if(c)for(l=0;l<c.length;l++)f=n(n.s=c[l]);return f};var t={},o={1:0};n.e=function(e){function r(){i.onerror=i.onload=null,clearTimeout(a);var n=o[e];0!==n&&(n&&n[1](new Error("Loading chunk "+e+" failed.")),o[e]=void 0)}var t=o[e];if(0===t)return new Promise(function(e){e()});if(t)return t[2];var u=new Promise(function(n,r){t=o[e]=[n,r]});t[2]=u;var c=document.getElementsByTagName("head")[0],i=document.createElement("script");i.type="text/javascript",i.charset="utf-8",i.async=!0,i.timeout=12e4,n.nc&&i.setAttribute("nonce",n.nc),i.src=n.p+""+e+".js?"+{0:"7f899297af075fb3b085"}[e];var a=setTimeout(r,12e4);return i.onerror=i.onload=r,c.appendChild(i),u},n.m=e,n.c=t,n.i=function(e){return e},n.d=function(e,r,t){n.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:t})},n.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(r,"a",r),r},n.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},n.p="",n.oe=function(e){throw console.error(e),e}}([]);
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -138,13 +138,11 @@ func parseClientCommonCfg(fileType int, source []byte) (cfg config.ClientCommonC
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if cfg.LogFile == "console" {
|
|
||||||
cfg.LogWay = "console"
|
cfg.Complete()
|
||||||
} else {
|
err = cfg.Validate()
|
||||||
cfg.LogWay = "file"
|
|
||||||
}
|
|
||||||
err = cfg.Check()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
err = fmt.Errorf("Parse config error: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@ -185,21 +183,20 @@ func runClient(cfgFilePath string) (err error) {
|
|||||||
var content []byte
|
var content []byte
|
||||||
content, err = config.GetRenderedConfFromFile(cfgFilePath)
|
content, err = config.GetRenderedConfFromFile(cfgFilePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg, err := parseClientCommonCfg(CfgFileTypeIni, content)
|
cfg, err := parseClientCommonCfg(CfgFileTypeIni, content)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
pxyCfgs, visitorCfgs, err := config.LoadAllProxyConfsFromIni(cfg.User, content, cfg.Start)
|
pxyCfgs, visitorCfgs, err := config.LoadAllProxyConfsFromIni(cfg.User, content, cfg.Start)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = startService(cfg, pxyCfgs, visitorCfgs, cfgFilePath)
|
return startService(cfg, pxyCfgs, visitorCfgs, cfgFilePath)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func startService(
|
func startService(
|
||||||
|
@ -105,7 +105,6 @@ var rootCmd = &cobra.Command{
|
|||||||
var cfg config.ServerCommonConf
|
var cfg config.ServerCommonConf
|
||||||
var err error
|
var err error
|
||||||
if cfgFile != "" {
|
if cfgFile != "" {
|
||||||
log.Info("frps uses config file: %s", cfgFile)
|
|
||||||
var content []byte
|
var content []byte
|
||||||
content, err = config.GetRenderedConfFromFile(cfgFile)
|
content, err = config.GetRenderedConfFromFile(cfgFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -113,7 +112,6 @@ var rootCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
cfg, err = parseServerCommonCfg(CfgFileTypeIni, content)
|
cfg, err = parseServerCommonCfg(CfgFileTypeIni, content)
|
||||||
} else {
|
} else {
|
||||||
log.Info("frps uses command line arguments for config")
|
|
||||||
cfg, err = parseServerCommonCfg(CfgFileTypeCmd, nil)
|
cfg, err = parseServerCommonCfg(CfgFileTypeCmd, nil)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -144,13 +142,10 @@ func parseServerCommonCfg(fileType int, source []byte) (cfg config.ServerCommonC
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if cfg.LogFile == "console" {
|
cfg.Complete()
|
||||||
cfg.LogWay = "console"
|
err = cfg.Validate()
|
||||||
} else {
|
|
||||||
cfg.LogWay = "file"
|
|
||||||
}
|
|
||||||
err = cfg.Check()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
err = fmt.Errorf("Parse config error: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@ -200,6 +195,13 @@ func parseServerCommonCfgFromCmd() (cfg config.ServerCommonConf, err error) {
|
|||||||
|
|
||||||
func runServer(cfg config.ServerCommonConf) (err error) {
|
func runServer(cfg config.ServerCommonConf) (err error) {
|
||||||
log.InitLog(cfg.LogWay, cfg.LogFile, cfg.LogLevel, cfg.LogMaxDays, cfg.DisableLogColor)
|
log.InitLog(cfg.LogWay, cfg.LogFile, cfg.LogLevel, cfg.LogMaxDays, cfg.DisableLogColor)
|
||||||
|
|
||||||
|
if cfgFile != "" {
|
||||||
|
log.Info("frps uses config file: %s", cfgFile)
|
||||||
|
} else {
|
||||||
|
log.Info("frps uses command line arguments for config")
|
||||||
|
}
|
||||||
|
|
||||||
svr, err := server.NewService(cfg)
|
svr, err := server.NewService(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -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 {
|
if cfg.HeartbeatInterval <= 0 {
|
||||||
return fmt.Errorf("Parse conf error: invalid heartbeat_interval")
|
return fmt.Errorf("invalid heartbeat_interval")
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg.HeartbeatTimeout < cfg.HeartbeatInterval {
|
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 {
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ type ServerCommonConf struct {
|
|||||||
// this value is 0.
|
// this value is 0.
|
||||||
KCPBindPort int `ini:"kcp_bind_port" json:"kcp_bind_port"`
|
KCPBindPort int `ini:"kcp_bind_port" json:"kcp_bind_port"`
|
||||||
// ProxyBindAddr specifies the address that the proxy binds to. This value
|
// 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"`
|
ProxyBindAddr string `ini:"proxy_bind_addr" json:"proxy_bind_addr"`
|
||||||
// VhostHTTPPort specifies the port that the server listens for HTTP Vhost
|
// 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. If this value is 0, the server will not listen for HTTP
|
||||||
@ -174,7 +174,7 @@ func GetDefaultServerConf() ServerCommonConf {
|
|||||||
BindPort: 7000,
|
BindPort: 7000,
|
||||||
BindUDPPort: 0,
|
BindUDPPort: 0,
|
||||||
KCPBindPort: 0,
|
KCPBindPort: 0,
|
||||||
ProxyBindAddr: "0.0.0.0",
|
ProxyBindAddr: "",
|
||||||
VhostHTTPPort: 0,
|
VhostHTTPPort: 0,
|
||||||
VhostHTTPSPort: 0,
|
VhostHTTPSPort: 0,
|
||||||
TCPMuxHTTPConnectPort: 0,
|
TCPMuxHTTPConnectPort: 0,
|
||||||
@ -208,10 +208,6 @@ func GetDefaultServerConf() ServerCommonConf {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cfg *ServerCommonConf) Check() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func UnmarshalServerConfFromIni(source interface{}) (ServerCommonConf, error) {
|
func UnmarshalServerConfFromIni(source interface{}) (ServerCommonConf, error) {
|
||||||
|
|
||||||
f, err := ini.LoadSources(ini.LoadOptions{
|
f, err := ini.LoadSources(ini.LoadOptions{
|
||||||
@ -242,7 +238,7 @@ func UnmarshalServerConfFromIni(source interface{}) (ServerCommonConf, error) {
|
|||||||
if allowPortStr != "" {
|
if allowPortStr != "" {
|
||||||
allowPorts, err := util.ParseRangeNumbers(allowPortStr)
|
allowPorts, err := util.ParseRangeNumbers(allowPortStr)
|
||||||
if err != nil {
|
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 {
|
for _, port := range allowPorts {
|
||||||
common.AllowPorts[int(port)] = struct{}{}
|
common.AllowPorts[int(port)] = struct{}{}
|
||||||
@ -269,6 +265,26 @@ func UnmarshalServerConfFromIni(source interface{}) (ServerCommonConf, error) {
|
|||||||
return common, nil
|
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) {
|
func loadHTTPPluginOpt(section *ini.Section) (*plugin.HTTPPluginOptions, error) {
|
||||||
name := strings.TrimSpace(strings.TrimPrefix(section.Name(), "plugin."))
|
name := strings.TrimSpace(strings.TrimPrefix(section.Name(), "plugin."))
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/fatedier/frp/pkg/auth"
|
"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"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
@ -133,7 +133,7 @@ func Test_LoadServerCommonConf(t *testing.T) {
|
|||||||
},
|
},
|
||||||
MaxPoolCount: 59,
|
MaxPoolCount: 59,
|
||||||
MaxPortsPerClient: 9,
|
MaxPortsPerClient: 9,
|
||||||
TLSOnly: false,
|
TLSOnly: true,
|
||||||
TLSCertFile: "server.crt",
|
TLSCertFile: "server.crt",
|
||||||
TLSKeyFile: "server.key",
|
TLSKeyFile: "server.key",
|
||||||
TLSTrustedCaFile: "ca.crt",
|
TLSTrustedCaFile: "ca.crt",
|
||||||
@ -177,7 +177,7 @@ func Test_LoadServerCommonConf(t *testing.T) {
|
|||||||
BindAddr: "0.0.0.9",
|
BindAddr: "0.0.0.9",
|
||||||
BindPort: 7009,
|
BindPort: 7009,
|
||||||
BindUDPPort: 7008,
|
BindUDPPort: 7008,
|
||||||
ProxyBindAddr: "0.0.0.0",
|
ProxyBindAddr: "0.0.0.9",
|
||||||
VhostHTTPTimeout: 60,
|
VhostHTTPTimeout: 60,
|
||||||
DashboardAddr: "0.0.0.0",
|
DashboardAddr: "0.0.0.0",
|
||||||
DashboardUser: "admin",
|
DashboardUser: "admin",
|
||||||
@ -202,6 +202,7 @@ func Test_LoadServerCommonConf(t *testing.T) {
|
|||||||
for _, c := range testcases {
|
for _, c := range testcases {
|
||||||
actual, err := UnmarshalServerConfFromIni(c.source)
|
actual, err := UnmarshalServerConfFromIni(c.source)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
actual.Complete()
|
||||||
assert.Equal(c.expected, actual)
|
assert.Equal(c.expected, actual)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
var version string = "0.36.1"
|
var version string = "0.36.2"
|
||||||
|
|
||||||
func Full() string {
|
func Full() string {
|
||||||
return version
|
return version
|
||||||
|
@ -54,8 +54,8 @@ class HttpProxy extends BaseProxy {
|
|||||||
this.custom_domains = proxyStats.conf.custom_domains
|
this.custom_domains = proxyStats.conf.custom_domains
|
||||||
this.host_header_rewrite = proxyStats.conf.host_header_rewrite
|
this.host_header_rewrite = proxyStats.conf.host_header_rewrite
|
||||||
this.locations = proxyStats.conf.locations
|
this.locations = proxyStats.conf.locations
|
||||||
if (proxyStats.conf.sub_domain != "") {
|
if (proxyStats.conf.subdomain != "") {
|
||||||
this.subdomain = proxyStats.conf.sub_domain + "." + subdomain_host
|
this.subdomain = proxyStats.conf.subdomain + "." + subdomain_host
|
||||||
} else {
|
} else {
|
||||||
this.subdomain = ""
|
this.subdomain = ""
|
||||||
}
|
}
|
||||||
@ -75,8 +75,8 @@ class HttpsProxy extends BaseProxy {
|
|||||||
this.port = port
|
this.port = port
|
||||||
if (proxyStats.conf != null) {
|
if (proxyStats.conf != null) {
|
||||||
this.custom_domains = proxyStats.conf.custom_domains
|
this.custom_domains = proxyStats.conf.custom_domains
|
||||||
if (proxyStats.conf.sub_domain != "") {
|
if (proxyStats.conf.subdomain != "") {
|
||||||
this.subdomain = proxyStats.conf.sub_domain + "." + subdomain_host
|
this.subdomain = proxyStats.conf.subdomain + "." + subdomain_host
|
||||||
} else {
|
} else {
|
||||||
this.subdomain = ""
|
this.subdomain = ""
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user