Skip to content

Commit

Permalink
Merge pull request #2324 from fatedier/dev
Browse files Browse the repository at this point in the history
bump version v0.36.2
  • Loading branch information
fatedier authored Mar 22, 2021
2 parents 55da58e + 9a849a2 commit c5c79e4
Show file tree
Hide file tree
Showing 23 changed files with 99 additions and 74 deletions.
2 changes: 1 addition & 1 deletion Makefile.cross-compiles
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export PATH := $(GOPATH)/bin:$(PATH)
export GO111MODULE=on
LDFLAGS := -s -w

os-archs=darwin:amd64 darwin:arm64 freebsd:386 freebsd:amd64 linux:386 linux:amd64 linux:arm windows:386 windows:amd64 linux:mips64 linux:mips64le linux:mips:softfloat linux:mipsle:softfloat
os-archs=darwin:amd64 darwin:arm64 freebsd:386 freebsd:amd64 linux:386 linux:amd64 linux:arm linux:arm64 windows:386 windows:amd64 linux:mips64 linux:mips64le linux:mips:softfloat linux:mipsle:softfloat

all: build

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ This feature is suitable for a large number of short connections.

Load balancing is supported by `group`.

This feature is only available for types `tcp` and `http` now.
This feature is only available for types `tcp`, `http`, `tcpmux` now.

```ini
# frpc.ini
Expand Down Expand Up @@ -1006,7 +1006,7 @@ frpc will generate 8 proxies like `test_tcp_0`, `test_tcp_1`, ..., `test_tcp_7`.

frpc only forwards requests to local TCP or UDP ports by default.

Plugins are used for providing rich features. There are built-in plugins such as `unix_domain_socket`, `http_proxy`, `socks5`, `static_file` and you can see [example usage](#example-usage).
Plugins are used for providing rich features. There are built-in plugins such as `unix_domain_socket`, `http_proxy`, `socks5`, `static_file`, `http2https`, `https2http`, `https2https` and you can see [example usage](#example-usage).

Specify which plugin to use with the `plugin` parameter. Configuration parameters of plugin should be started with `plugin_`. `local_ip` and `local_port` are not used for plugin.

Expand Down
2 changes: 1 addition & 1 deletion assets/frpc/statik/statik.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/frps/static/index.html
Original file line number Diff line number Diff line change
@@ -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?b8b55d8156200869417b"></script><script type="text/javascript" src="vendor.js?3e078a9d741093b909de"></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>
2 changes: 1 addition & 1 deletion assets/frps/static/manifest.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion assets/frps/static/vendor.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/frps/statik/statik.go

Large diffs are not rendered by default.

18 changes: 7 additions & 11 deletions cmd/frpc/sub/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,10 @@ func parseClientCommonCfg(fileType int, source []byte) (cfg config.ClientCommonC
return
}

err = cfg.Check()
cfg.Complete()
err = cfg.Validate()
if err != nil {
err = fmt.Errorf("Parse config error: %v", err)
return
}
return
Expand All @@ -167,11 +169,6 @@ func parseClientCommonCfgFromCmd() (cfg config.ClientCommonConf, err error) {
cfg.LogLevel = logLevel
cfg.LogFile = logFile
cfg.LogMaxDays = int64(logMaxDays)
if logFile == "console" {
cfg.LogWay = "console"
} else {
cfg.LogWay = "file"
}
cfg.DisableLogColor = disableLogColor

// Only token authentication is supported in cmd mode
Expand All @@ -186,21 +183,20 @@ func runClient(cfgFilePath string) (err error) {
var content []byte
content, err = config.GetRenderedConfFromFile(cfgFilePath)
if err != nil {
return
return err
}

cfg, err := parseClientCommonCfg(CfgFileTypeIni, content)
if err != nil {
return
return err
}

pxyCfgs, visitorCfgs, err := config.LoadAllProxyConfsFromIni(cfg.User, content, cfg.Start)
if err != nil {
return
return err
}

err = startService(cfg, pxyCfgs, visitorCfgs, cfgFilePath)
return
return startService(cfg, pxyCfgs, visitorCfgs, cfgFilePath)
}

func startService(
Expand Down
20 changes: 10 additions & 10 deletions cmd/frps/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,13 @@ var rootCmd = &cobra.Command{
var cfg config.ServerCommonConf
var err error
if cfgFile != "" {
log.Info("frps uses config file: %s", cfgFile)
var content []byte
content, err = config.GetRenderedConfFromFile(cfgFile)
if err != nil {
return err
}
cfg, err = parseServerCommonCfg(CfgFileTypeIni, content)
} else {
log.Info("frps uses command line arguments for config")
cfg, err = parseServerCommonCfg(CfgFileTypeCmd, nil)
}
if err != nil {
Expand Down Expand Up @@ -144,9 +142,10 @@ func parseServerCommonCfg(fileType int, source []byte) (cfg config.ServerCommonC
if err != nil {
return
}

err = cfg.Check()
cfg.Complete()
err = cfg.Validate()
if err != nil {
err = fmt.Errorf("Parse config error: %v", err)
return
}
return
Expand Down Expand Up @@ -190,18 +189,19 @@ func parseServerCommonCfgFromCmd() (cfg config.ServerCommonConf, err error) {
}
}
cfg.MaxPortsPerClient = maxPortsPerClient

if logFile == "console" {
cfg.LogWay = "console"
} else {
cfg.LogWay = "file"
}
cfg.DisableLogColor = disableLogColor
return
}

func runServer(cfg config.ServerCommonConf) (err error) {
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)
if err != nil {
return err
Expand Down
20 changes: 16 additions & 4 deletions pkg/config/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
// recommended to use GetDefaultClientConf instead of creating this object
// directly, so that all unspecified fields have reasonable default values.
type ClientCommonConf struct {
auth.ClientConfig `ini:",extends" json:"inline"`
auth.ClientConfig `ini:",extends"`

// ServerAddr specifies the address of the server to connect to. By
// default, this value is "0.0.0.0".
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down
26 changes: 13 additions & 13 deletions pkg/config/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ type BaseProxyConf struct {
Metas map[string]string `ini:"-" json:"metas"`

// TODO: LocalSvrConf => LocalAppConf
LocalSvrConf `ini:",extends" json:"inline"`
HealthCheckConf `ini:",extends" json:"inline"`
LocalSvrConf `ini:",extends"`
HealthCheckConf `ini:",extends"`
}

type DomainConf struct {
Expand All @@ -155,8 +155,8 @@ type DomainConf struct {

// HTTP
type HTTPProxyConf struct {
BaseProxyConf `ini:",extends" json:"inline"`
DomainConf `ini:",extends" json:"inline"`
BaseProxyConf `ini:",extends"`
DomainConf `ini:",extends"`

Locations []string `ini:"locations" json:"locations"`
HTTPUser string `ini:"http_user" json:"http_user"`
Expand All @@ -167,50 +167,50 @@ type HTTPProxyConf struct {

// HTTPS
type HTTPSProxyConf struct {
BaseProxyConf `ini:",extends" json:"inline"`
DomainConf `ini:",extends" json:"inline"`
BaseProxyConf `ini:",extends"`
DomainConf `ini:",extends"`
}

// TCP
type TCPProxyConf struct {
BaseProxyConf `ini:",extends" json:"inline"`
BaseProxyConf `ini:",extends"`
RemotePort int `ini:"remote_port" json:"remote_port"`
}

// TCPMux
type TCPMuxProxyConf struct {
BaseProxyConf `ini:",extends" json:"inline"`
DomainConf `ini:",extends" json:"inline"`
BaseProxyConf `ini:",extends"`
DomainConf `ini:",extends"`

Multiplexer string `ini:"multiplexer"`
}

// STCP
type STCPProxyConf struct {
BaseProxyConf `ini:",extends" json:"inline"`
BaseProxyConf `ini:",extends"`

Role string `ini:"role" json:"role"`
Sk string `ini:"sk" json:"sk"`
}

// XTCP
type XTCPProxyConf struct {
BaseProxyConf `ini:",extends" json:"inline"`
BaseProxyConf `ini:",extends"`

Role string `ini:"role" json:"role"`
Sk string `ini:"sk" json:"sk"`
}

// UDP
type UDPProxyConf struct {
BaseProxyConf `ini:",extends" json:"inline"`
BaseProxyConf `ini:",extends"`

RemotePort int `ini:"remote_port" json:"remote_port"`
}

// SUDP
type SUDPProxyConf struct {
BaseProxyConf `ini:",extends" json:"inline"`
BaseProxyConf `ini:",extends"`

Role string `ini:"role" json:"role"`
Sk string `ini:"sk" json:"sk"`
Expand Down
32 changes: 24 additions & 8 deletions pkg/config/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
// recommended to use GetDefaultServerConf instead of creating this object
// directly, so that all unspecified fields have reasonable default values.
type ServerCommonConf struct {
auth.ServerConfig `ini:",extends" json:"inline"`
auth.ServerConfig `ini:",extends"`

// BindAddr specifies the address that the server binds to. By default,
// this value is "0.0.0.0".
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{}{}
Expand All @@ -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."))

Expand Down
7 changes: 4 additions & 3 deletions pkg/config/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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)
}
}
6 changes: 3 additions & 3 deletions pkg/config/visitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ type BaseVisitorConf struct {
}

type SUDPVisitorConf struct {
BaseVisitorConf `ini:",extends" json:"inline"`
BaseVisitorConf `ini:",extends"`
}

type STCPVisitorConf struct {
BaseVisitorConf `ini:",extends" json:"inline"`
BaseVisitorConf `ini:",extends"`
}

type XTCPVisitorConf struct {
BaseVisitorConf `ini:",extends" json:"inline"`
BaseVisitorConf `ini:",extends"`
}

// DefaultVisitorConf creates a empty VisitorConf object by visitorType.
Expand Down
Loading

0 comments on commit c5c79e4

Please sign in to comment.