fix: Web 全局状态同步、字典文件错误提示、长驻插件连接可取消

- scan.go: Web API 构建 config/state 后同步到全局实例
- config_builder.go: 用户名/密码/URL 文件读取失败时输出错误日志
- reverseshell.go: 读命令设 1s 超时,超时后检查 ctx 实现可取消
- forwardshell.go: handleClient 接受 ctx,取消时关闭连接解除阻塞
- socks5proxy.go: handleClient 接受 ctx,取消时关闭连接解除 IO 阻塞
This commit is contained in:
ZacharyZcR
2026-04-27 21:45:16 +08:00
parent 653f11295a
commit 3d7cdcbe5f
5 changed files with 42 additions and 8 deletions
+14 -4
View File
@@ -118,24 +118,34 @@ func (p *Socks5ProxyPlugin) startSocks5Server(ctx context.Context, port int, sta
}
// 并发处理客户端连接
go p.handleClient(conn)
go p.handleClient(ctx, conn)
}
}
// handleClient 处理客户端连接
func (p *Socks5ProxyPlugin) handleClient(clientConn net.Conn) {
func (p *Socks5ProxyPlugin) handleClient(ctx context.Context, clientConn net.Conn) {
defer func() { _ = clientConn.Close() }()
// ctx 取消时关闭连接,解除阻塞的 IO
go func() {
<-ctx.Done()
_ = clientConn.Close()
}()
// SOCKS5握手阶段
if err := p.handleSocks5Handshake(clientConn); err != nil {
common.LogError(i18n.Tr("socks5_handshake_failed", err))
if ctx.Err() == nil {
common.LogError(i18n.Tr("socks5_handshake_failed", err))
}
return
}
// SOCKS5请求阶段
targetConn, _, err := p.handleSocks5Request(clientConn)
if err != nil {
common.LogError(i18n.Tr("socks5_request_failed", err))
if ctx.Err() == nil {
common.LogError(i18n.Tr("socks5_request_failed", err))
}
return
}
defer func() { _ = targetConn.Close() }()