Merge 9dc574d49a
into 0f1005ff61
This commit is contained in:
commit
c7d04ead48
@ -17,7 +17,11 @@ package client
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -211,6 +215,41 @@ func (ctl *Control) init() {
|
|||||||
ctl.closedCh = make(chan int)
|
ctl.closedCh = make(chan int)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ctl *Control) getDynamicServer() (err error) {
|
||||||
|
if config.ClientCommonCfg.ServerDynamic == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
serv := config.ClientCommonCfg.ServerDynamic
|
||||||
|
if strings.ToLower(serv[:4]) != "http" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := http.Get(serv + "?user=" + config.ClientCommonCfg.User)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := ioutil.ReadAll(res.Body)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
serv = string(data)
|
||||||
|
addr := strings.Split(serv, ":")
|
||||||
|
if len(addr) != 2 {
|
||||||
|
ctl.Error("dynamic server info error: %v", serv)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
serverPort, err := strconv.ParseInt(addr[1], 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
config.ClientCommonCfg.ServerAddr = addr[0]
|
||||||
|
config.ClientCommonCfg.ServerPort = serverPort
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// login send a login message to server and wait for a loginResp message.
|
// login send a login message to server and wait for a loginResp message.
|
||||||
func (ctl *Control) login() (err error) {
|
func (ctl *Control) login() (err error) {
|
||||||
if ctl.conn != nil {
|
if ctl.conn != nil {
|
||||||
@ -220,6 +259,11 @@ func (ctl *Control) login() (err error) {
|
|||||||
ctl.session.Close()
|
ctl.session.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
errDynamic := ctl.getDynamicServer()
|
||||||
|
if errDynamic != nil {
|
||||||
|
ctl.Error("Get dynamic server error: %s", errDynamic.Error())
|
||||||
|
}
|
||||||
|
|
||||||
conn, err := frpNet.ConnectServerByHttpProxy(config.ClientCommonCfg.HttpProxy, config.ClientCommonCfg.Protocol,
|
conn, err := frpNet.ConnectServerByHttpProxy(config.ClientCommonCfg.HttpProxy, config.ClientCommonCfg.Protocol,
|
||||||
fmt.Sprintf("%s:%d", config.ClientCommonCfg.ServerAddr, config.ClientCommonCfg.ServerPort))
|
fmt.Sprintf("%s:%d", config.ClientCommonCfg.ServerAddr, config.ClientCommonCfg.ServerPort))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -43,7 +43,7 @@ var (
|
|||||||
var usage string = `frpc is the client of frp
|
var usage string = `frpc is the client of frp
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
frpc [-c config_file] [-L log_file] [--log-level=<log_level>] [--server-addr=<server_addr>]
|
frpc [-c config_file] [-L log_file] [--log-level=<log_level>] [--user=<user_name>] [--server-addr=<server_addr>] [--server-dynamic=<http_url>]
|
||||||
frpc [-c config_file] --reload
|
frpc [-c config_file] --reload
|
||||||
frpc -h | --help
|
frpc -h | --help
|
||||||
frpc -v | --version
|
frpc -v | --version
|
||||||
@ -53,6 +53,7 @@ Options:
|
|||||||
-L log_file set output log file, including console
|
-L log_file set output log file, including console
|
||||||
--log-level=<log_level> set log level: debug, info, warn, error
|
--log-level=<log_level> set log level: debug, info, warn, error
|
||||||
--server-addr=<server_addr> addr which frps is listening for, example: 0.0.0.0:7000
|
--server-addr=<server_addr> addr which frps is listening for, example: 0.0.0.0:7000
|
||||||
|
--server-dynamic=<http_url> get frps addr from http_url, example: http://server.com/frp/
|
||||||
--reload reload configure file without program exit
|
--reload reload configure file without program exit
|
||||||
-h --help show this screen
|
-h --help show this screen
|
||||||
-v --version show version
|
-v --version show version
|
||||||
@ -134,6 +135,14 @@ func main() {
|
|||||||
config.ClientCommonCfg.LogLevel = args["--log-level"].(string)
|
config.ClientCommonCfg.LogLevel = args["--log-level"].(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if args["--user"] != nil {
|
||||||
|
config.ClientCommonCfg.User = args["--user"].(string)
|
||||||
|
}
|
||||||
|
|
||||||
|
if args["--server-dynamic"] != nil {
|
||||||
|
config.ClientCommonCfg.ServerDynamic = args["--server-dynamic"].(string)
|
||||||
|
}
|
||||||
|
|
||||||
if args["--server-addr"] != nil {
|
if args["--server-addr"] != nil {
|
||||||
addr := strings.Split(args["--server-addr"].(string), ":")
|
addr := strings.Split(args["--server-addr"].(string), ":")
|
||||||
if len(addr) != 2 {
|
if len(addr) != 2 {
|
||||||
|
@ -28,6 +28,7 @@ var ClientCommonCfg *ClientCommonConf
|
|||||||
// client common config
|
// client common config
|
||||||
type ClientCommonConf struct {
|
type ClientCommonConf struct {
|
||||||
ConfigFile string
|
ConfigFile string
|
||||||
|
ServerDynamic string
|
||||||
ServerAddr string
|
ServerAddr string
|
||||||
ServerPort int64
|
ServerPort int64
|
||||||
ServerUdpPort int64 // this is specified by login response message from frps
|
ServerUdpPort int64 // this is specified by login response message from frps
|
||||||
@ -54,6 +55,7 @@ type ClientCommonConf struct {
|
|||||||
func GetDeaultClientCommonConf() *ClientCommonConf {
|
func GetDeaultClientCommonConf() *ClientCommonConf {
|
||||||
return &ClientCommonConf{
|
return &ClientCommonConf{
|
||||||
ConfigFile: "./frpc.ini",
|
ConfigFile: "./frpc.ini",
|
||||||
|
ServerDynamic: "",
|
||||||
ServerAddr: "0.0.0.0",
|
ServerAddr: "0.0.0.0",
|
||||||
ServerPort: 7000,
|
ServerPort: 7000,
|
||||||
ServerUdpPort: 0,
|
ServerUdpPort: 0,
|
||||||
@ -86,9 +88,9 @@ func LoadClientCommonConf(conf ini.File) (cfg *ClientCommonConf, err error) {
|
|||||||
)
|
)
|
||||||
cfg = GetDeaultClientCommonConf()
|
cfg = GetDeaultClientCommonConf()
|
||||||
|
|
||||||
tmpStr, ok = conf.Get("common", "server_addr")
|
tmpStr, ok = conf.Get("common", "server_dynamic")
|
||||||
if ok {
|
if ok {
|
||||||
cfg.ServerAddr = tmpStr
|
cfg.ServerDynamic = tmpStr
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpStr, ok = conf.Get("common", "server_port")
|
tmpStr, ok = conf.Get("common", "server_port")
|
||||||
|
Loading…
Reference in New Issue
Block a user