Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ccfe8c9

Browse files
authored
Merge pull request #4392 from fatedier/dev
bump version
2 parents 243ca99 + 03c8d7b commit ccfe8c9

33 files changed

+272
-132
lines changed

.github/FUNDING.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# These are supported funding model platforms
22

33
github: [fatedier]
4-
custom: ["https://afdian.net/a/fatedier"]
4+
custom: ["https://afdian.com/a/fatedier"]

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ linters-settings:
8888
excludes:
8989
- G401
9090
- G402
91+
- G404
9192
- G501
9293

9394
issues:

Makefile.cross-compiles

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export PATH := $(PATH):`go env GOPATH`/bin
22
export GO111MODULE=on
33
LDFLAGS := -s -w
44

5-
os-archs=darwin:amd64 darwin:arm64 freebsd:amd64 linux:amd64 linux:arm:7 linux:arm:5 linux:arm64 windows:amd64 windows:arm64 linux:mips64 linux:mips64le linux:mips:softfloat linux:mipsle:softfloat linux:riscv64 android:arm64
5+
os-archs=darwin:amd64 darwin:arm64 freebsd:amd64 linux:amd64 linux:arm:7 linux:arm:5 linux:arm64 windows:amd64 windows:arm64 linux:mips64 linux:mips64le linux:mips:softfloat linux:mipsle:softfloat linux:riscv64 linux:loong64 android:arm64
66

77
all: build
88

README.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@
99

1010
<h3 align="center">Gold Sponsors</h3>
1111
<!--gold sponsors start-->
12-
<p align="center">
13-
<a href="https://lokal.so/?utm_campaign=github_repo&utm_medium=referral&utm_content=frp&utm_source=github" target="_blank">
14-
<img width="420px" src="https://raw.githubusercontent.com/fatedier/frp/dev/doc/pic/sponsor_lokal.png">
15-
</a>
16-
</p>
1712
<p align="center">
1813
<a href="https://workos.com/?utm_campaign=github_repo&utm_medium=referral&utm_content=frp&utm_source=github" target="_blank">
1914
<img width="420px" src="https://raw.githubusercontent.com/fatedier/frp/dev/doc/pic/sponsor_workos.png">

README_zh.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ frp 是一个专注于内网穿透的高性能的反向代理应用,支持 TCP
1111

1212
<h3 align="center">Gold Sponsors</h3>
1313
<!--gold sponsors start-->
14-
<p align="center">
15-
<a href="https://lokal.so/?utm_campaign=github_repo&utm_medium=referral&utm_content=frp&utm_source=github" target="_blank">
16-
<img width="420px" src="https://raw.githubusercontent.com/fatedier/frp/dev/doc/pic/sponsor_lokal.png">
17-
</a>
18-
</p>
1914
<p align="center">
2015
<a href="https://workos.com/?utm_campaign=github_repo&utm_medium=referral&utm_content=frp&utm_source=github" target="_blank">
2116
<img width="420px" src="https://raw.githubusercontent.com/fatedier/frp/dev/doc/pic/sponsor_workos.png">

Release.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
### Features
22

3-
* Added a new plugin "http2http" which allows forwarding HTTP requests to another HTTP server, supporting options like local address binding, host header rewrite, and custom request headers.
4-
* Added `enableHTTP2` option to control whether to enable HTTP/2 in plugin https2http and https2https, default is true.
3+
* Added a new plugin `tls2raw`: Enables TLS termination and forwarding of decrypted raw traffic to local service.
4+
* Added a default timeout of 30 seconds for the frpc subcommands to prevent commands from being stuck for a long time due to network issues.
55

6-
### Changes
6+
### Fixes
77

8-
* Plugin https2http & https2https: return 421 `Misdirected Request` if host not match sni.
8+
* Fixed the issue that when `loginFailExit = false`, the frpc stop command cannot be stopped correctly if the server is not successfully connected after startup.

client/proxy/proxy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ func (pxy *BaseProxy) HandleTCPWorkConnection(workConn net.Conn, m *msg.StartWor
192192
if pxy.proxyPlugin != nil {
193193
// if plugin is set, let plugin handle connection first
194194
xl.Debugf("handle by plugin: %s", pxy.proxyPlugin.Name())
195-
pxy.proxyPlugin.Handle(remote, workConn, &extraInfo)
195+
pxy.proxyPlugin.Handle(pxy.ctx, remote, workConn, &extraInfo)
196196
xl.Debugf("handle by plugin finished")
197197
return
198198
}

client/service.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,15 @@ func (svr *Service) Run(ctx context.Context) error {
169169
netpkg.SetDefaultDNSAddress(svr.common.DNSServer)
170170
}
171171

172+
if svr.webServer != nil {
173+
go func() {
174+
log.Infof("admin server listen on %s", svr.webServer.Address())
175+
if err := svr.webServer.Run(); err != nil {
176+
log.Warnf("admin server exit with error: %v", err)
177+
}
178+
}()
179+
}
180+
172181
// first login to frps
173182
svr.loopLoginUntilSuccess(10*time.Second, lo.FromPtr(svr.common.LoginFailExit))
174183
if svr.ctl == nil {
@@ -179,14 +188,6 @@ func (svr *Service) Run(ctx context.Context) error {
179188

180189
go svr.keepControllerWorking()
181190

182-
if svr.webServer != nil {
183-
go func() {
184-
log.Infof("admin server listen on %s", svr.webServer.Address())
185-
if err := svr.webServer.Run(); err != nil {
186-
log.Warnf("admin server exit with error: %v", err)
187-
}
188-
}()
189-
}
190191
<-svr.ctx.Done()
191192
svr.stop()
192193
return nil

cmd/frpc/sub/admin.go

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
package sub
1616

1717
import (
18+
"context"
1819
"fmt"
1920
"os"
2021
"strings"
22+
"time"
2123

2224
"github.com/rodaine/table"
2325
"github.com/spf13/cobra"
@@ -27,24 +29,24 @@ import (
2729
clientsdk "github.com/fatedier/frp/pkg/sdk/client"
2830
)
2931

30-
func init() {
31-
rootCmd.AddCommand(NewAdminCommand(
32-
"reload",
33-
"Hot-Reload frpc configuration",
34-
ReloadHandler,
35-
))
32+
var adminAPITimeout = 30 * time.Second
3633

37-
rootCmd.AddCommand(NewAdminCommand(
38-
"status",
39-
"Overview of all proxies status",
40-
StatusHandler,
41-
))
34+
func init() {
35+
commands := []struct {
36+
name string
37+
description string
38+
handler func(*v1.ClientCommonConfig) error
39+
}{
40+
{"reload", "Hot-Reload frpc configuration", ReloadHandler},
41+
{"status", "Overview of all proxies status", StatusHandler},
42+
{"stop", "Stop the running frpc", StopHandler},
43+
}
4244

43-
rootCmd.AddCommand(NewAdminCommand(
44-
"stop",
45-
"Stop the running frpc",
46-
StopHandler,
47-
))
45+
for _, cmdConfig := range commands {
46+
cmd := NewAdminCommand(cmdConfig.name, cmdConfig.description, cmdConfig.handler)
47+
cmd.Flags().DurationVar(&adminAPITimeout, "api-timeout", adminAPITimeout, "Timeout for admin API calls")
48+
rootCmd.AddCommand(cmd)
49+
}
4850
}
4951

5052
func NewAdminCommand(name, short string, handler func(*v1.ClientCommonConfig) error) *cobra.Command {
@@ -73,7 +75,9 @@ func NewAdminCommand(name, short string, handler func(*v1.ClientCommonConfig) er
7375
func ReloadHandler(clientCfg *v1.ClientCommonConfig) error {
7476
client := clientsdk.New(clientCfg.WebServer.Addr, clientCfg.WebServer.Port)
7577
client.SetAuth(clientCfg.WebServer.User, clientCfg.WebServer.Password)
76-
if err := client.Reload(strictConfigMode); err != nil {
78+
ctx, cancel := context.WithTimeout(context.Background(), adminAPITimeout)
79+
defer cancel()
80+
if err := client.Reload(ctx, strictConfigMode); err != nil {
7781
return err
7882
}
7983
fmt.Println("reload success")
@@ -83,7 +87,9 @@ func ReloadHandler(clientCfg *v1.ClientCommonConfig) error {
8387
func StatusHandler(clientCfg *v1.ClientCommonConfig) error {
8488
client := clientsdk.New(clientCfg.WebServer.Addr, clientCfg.WebServer.Port)
8589
client.SetAuth(clientCfg.WebServer.User, clientCfg.WebServer.Password)
86-
res, err := client.GetAllProxyStatus()
90+
ctx, cancel := context.WithTimeout(context.Background(), adminAPITimeout)
91+
defer cancel()
92+
res, err := client.GetAllProxyStatus(ctx)
8793
if err != nil {
8894
return err
8995
}
@@ -109,7 +115,9 @@ func StatusHandler(clientCfg *v1.ClientCommonConfig) error {
109115
func StopHandler(clientCfg *v1.ClientCommonConfig) error {
110116
client := clientsdk.New(clientCfg.WebServer.Addr, clientCfg.WebServer.Port)
111117
client.SetAuth(clientCfg.WebServer.User, clientCfg.WebServer.Password)
112-
if err := client.Stop(); err != nil {
118+
ctx, cancel := context.WithTimeout(context.Background(), adminAPITimeout)
119+
defer cancel()
120+
if err := client.Stop(ctx); err != nil {
113121
return err
114122
}
115123
fmt.Println("stop success")

conf/frpc_full_example.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,16 @@ localAddr = "127.0.0.1:80"
325325
hostHeaderRewrite = "127.0.0.1"
326326
requestHeaders.set.x-from-where = "frp"
327327

328+
[[proxies]]
329+
name = "plugin_tls2raw"
330+
type = "https"
331+
remotePort = 6008
332+
[proxies.plugin]
333+
type = "tls2raw"
334+
localAddr = "127.0.0.1:80"
335+
crtPath = "./server.crt"
336+
keyPath = "./server.key"
337+
328338
[[proxies]]
329339
name = "secret_tcp"
330340
# If the type is secret tcp, remotePort is useless

0 commit comments

Comments
 (0)