From a9398ada8fdbb4f99aacfcb6ccfd040f9511ba8f Mon Sep 17 00:00:00 2001 From: jcy <574209987@qq.com> Date: Wed, 13 Apr 2016 17:44:14 +0800 Subject: [PATCH] fix_cfg_bug --- src/frp/models/client/config.go | 62 ++++++++++++++++++++++++++++++--- src/frp/models/server/config.go | 49 ++++++++++++++++++++++++-- 2 files changed, 103 insertions(+), 8 deletions(-) diff --git a/src/frp/models/client/config.go b/src/frp/models/client/config.go index 3c09c751..cd3df326 100644 --- a/src/frp/models/client/config.go +++ b/src/frp/models/client/config.go @@ -47,11 +47,23 @@ func LoadConf(confFile string) (err error) { tmpStr, ok = conf.Get("common", "server_addr") if ok { ServerAddr = tmpStr + } else { + tmpStr, ok = conf.Get("common", "SERVER_ADDR") + + if ok { + ServerAddr = tmpStr + } } tmpStr, ok = conf.Get("common", "server_port") if ok { ServerPort, _ = strconv.ParseInt(tmpStr, 10, 64) + } else { + tmpStr, ok = conf.Get("common", "SERVER_PORT") + + if ok { + ServerPort, _ = strconv.ParseInt(tmpStr, 10, 64) + } } tmpStr, ok = conf.Get("common", "log_file") @@ -62,11 +74,28 @@ func LoadConf(confFile string) (err error) { } else { LogWay = "file" } + } else { + tmpStr, ok = conf.Get("common", "LOG_FILE") + + if ok { + LogFile = tmpStr + if LogFile == "console" { + LogWay = "console" + } else { + LogWay = "file" + } + } } tmpStr, ok = conf.Get("common", "log_level") if ok { LogLevel = tmpStr + } else { + tmpStr, ok = conf.Get("common", "LOG_LEVEL") + + if ok { + LogLevel = tmpStr + } } var authToken string @@ -74,7 +103,13 @@ func LoadConf(confFile string) (err error) { if ok { authToken = tmpStr } else { - return fmt.Errorf("auth_token not found") + tmpStr, ok = conf.Get("common", "AUTH_TOKEN") + + if ok { + authToken = tmpStr + } else { + return fmt.Errorf("auth_token not found") + } } // proxies @@ -90,8 +125,12 @@ func LoadConf(confFile string) (err error) { // local_ip proxyClient.LocalIp, ok = section["local_ip"] if !ok { - // use 127.0.0.1 as default - proxyClient.LocalIp = "127.0.0.1" + proxyClient.LocalIp, ok = section["LOCAL_IP"] + + if !ok { + // use 127.0.0.1 as default + proxyClient.LocalIp = "127.0.0.1" + } } // local_port @@ -102,7 +141,16 @@ func LoadConf(confFile string) (err error) { return fmt.Errorf("Parse ini file error: proxy [%s] local_port error", proxyClient.Name) } } else { - return fmt.Errorf("Parse ini file error: proxy [%s] local_port not found", proxyClient.Name) + portStr, ok := section["LOCAL_PORT"] + + if ok { + proxyClient.LocalPort, err = strconv.ParseInt(portStr, 10, 64) + if err != nil { + return fmt.Errorf("Parse ini file error: proxy [%s] local_port error", proxyClient.Name) + } + } else { + return fmt.Errorf("Parse ini file error: proxy [%s] local_port not found", proxyClient.Name) + } } // use_encryption @@ -110,8 +158,12 @@ func LoadConf(confFile string) (err error) { useEncryptionStr, ok := section["use_encryption"] if ok && useEncryptionStr == "true" { proxyClient.UseEncryption = true + } else { + useEncryptionStr, ok := section["USE_ENCRYPTION"] + if ok && useEncryptionStr == "true" { + proxyClient.UseEncryption = true + } } - ProxyClients[proxyClient.Name] = proxyClient } } diff --git a/src/frp/models/server/config.go b/src/frp/models/server/config.go index 23fd9699..5809dc3f 100644 --- a/src/frp/models/server/config.go +++ b/src/frp/models/server/config.go @@ -47,11 +47,23 @@ func LoadConf(confFile string) (err error) { tmpStr, ok = conf.Get("common", "bind_addr") if ok { BindAddr = tmpStr + } else { + tmpStr, ok = conf.Get("common", "BIND_ADDR") + + if ok { + BindAddr = tmpStr + } } tmpStr, ok = conf.Get("common", "bind_port") if ok { BindPort, _ = strconv.ParseInt(tmpStr, 10, 64) + } else { + tmpStr, ok = conf.Get("common", "BIND_PORT") + + if ok { + BindPort, _ = strconv.ParseInt(tmpStr, 10, 64) + } } tmpStr, ok = conf.Get("common", "log_file") @@ -62,11 +74,28 @@ func LoadConf(confFile string) (err error) { } else { LogWay = "file" } + } else { + tmpStr, ok = conf.Get("common", "LOG_FILE") + + if ok { + LogFile = tmpStr + if LogFile == "console" { + LogWay = "console" + } else { + LogWay = "file" + } + } } tmpStr, ok = conf.Get("common", "log_level") if ok { LogLevel = tmpStr + } else { + tmpStr, ok = conf.Get("common", "LOG_LEVEL") + + if ok { + LogLevel = tmpStr + } } // servers @@ -77,12 +106,18 @@ func LoadConf(confFile string) (err error) { proxyServer.AuthToken, ok = section["auth_token"] if !ok { - return fmt.Errorf("Parse ini file error: proxy [%s] no auth_token found", proxyServer.Name) + proxyServer.AuthToken, ok = section["AUTH_TOKEN"] + if !ok { + return fmt.Errorf("Parse ini file error: proxy [%s] no auth_token found", proxyServer.Name) + } } proxyServer.BindAddr, ok = section["bind_addr"] if !ok { - proxyServer.BindAddr = "0.0.0.0" + proxyServer.BindAddr, ok = section["BIND_ADDR"] + if !ok { + proxyServer.BindAddr = "0.0.0.0" + } } portStr, ok := section["listen_port"] @@ -92,7 +127,15 @@ func LoadConf(confFile string) (err error) { return fmt.Errorf("Parse ini file error: proxy [%s] listen_port error", proxyServer.Name) } } else { - return fmt.Errorf("Parse ini file error: proxy [%s] listen_port not found", proxyServer.Name) + portStr, ok := section["LISTEN_PORT"] + if ok { + proxyServer.ListenPort, err = strconv.ParseInt(portStr, 10, 64) + if err != nil { + return fmt.Errorf("Parse ini file error: proxy [%s] listen_port error", proxyServer.Name) + } + } else { + return fmt.Errorf("Parse ini file error: proxy [%s] listen_port not found", proxyServer.Name) + } } proxyServer.Init()