提交 v1.3.0 beta

This commit is contained in:
dushixiang
2022-10-23 20:05:13 +08:00
parent 4ff4d37442
commit 112435199a
329 changed files with 18340 additions and 58458 deletions

View File

@ -4,10 +4,10 @@ import (
"errors"
"fmt"
"net"
"next-terminal/server/common/term"
"os"
"sync"
"next-terminal/server/term"
"next-terminal/server/utils"
"golang.org/x/crypto/ssh"
@ -90,7 +90,9 @@ func (g *Gateway) CloseSshTunnel(id string) {
}
if len(g.tunnels) == 0 {
_ = g.SshClient.Close()
if g.SshClient != nil {
_ = g.SshClient.Close()
}
g.Connected = false
g.Message = "暂未使用"
}

View File

@ -3,7 +3,6 @@ package gateway
import (
"sync"
"next-terminal/server/log"
"next-terminal/server/model"
)
@ -33,7 +32,6 @@ func (m *manager) Add(model *model.AccessGateway) *Gateway {
tunnels: make(map[string]*Tunnel),
}
m.gateways.Store(g.ID, g)
log.Infof("add Gateway: %s", g.ID)
return g
}
@ -43,7 +41,6 @@ func (m *manager) Del(id string) {
g.Close()
}
m.gateways.Delete(id)
log.Infof("del Gateway: %s", id)
}
var GlobalGatewayManager *manager

View File

@ -5,8 +5,6 @@ import (
"io"
"net"
"next-terminal/server/log"
"golang.org/x/crypto/ssh"
)
@ -22,34 +20,23 @@ type Tunnel struct {
}
func (r *Tunnel) Open(sshClient *ssh.Client) {
localAddr := fmt.Sprintf("%s:%d", r.localHost, r.localPort)
for {
log.Debugf("隧道 %v 等待客户端访问 %v", r.id, localAddr)
localConn, err := r.listener.Accept()
if err != nil {
log.Debugf("隧道 %v 接受连接失败 %v, 退出循环", r.id, err.Error())
log.Debug("-------------------------------------------------")
return
}
r.localConnections = append(r.localConnections, localConn)
log.Debugf("隧道 %v 新增本地连接 %v", r.id, localConn.RemoteAddr().String())
remoteAddr := fmt.Sprintf("%s:%d", r.remoteHost, r.remotePort)
log.Debugf("隧道 %v 连接远程地址 %v ...", r.id, remoteAddr)
remoteConn, err := sshClient.Dial("tcp", remoteAddr)
if err != nil {
log.Debugf("隧道 %v 连接远程地址 %v, 退出循环", r.id, err.Error())
log.Debug("-------------------------------------------------")
return
}
r.remoteConnections = append(r.remoteConnections, remoteConn)
log.Debugf("隧道 %v 连接远程主机成功", r.id)
go copyConn(localConn, remoteConn)
go copyConn(remoteConn, localConn)
log.Debugf("隧道 %v 开始转发数据 [%v]->[%v]", r.id, localAddr, remoteAddr)
log.Debug("~~~~~~~~~~~~~~~~~~~~分割线~~~~~~~~~~~~~~~~~~~~~~~~")
}
}
@ -63,7 +50,6 @@ func (r *Tunnel) Close() {
}
r.remoteConnections = nil
_ = r.listener.Close()
log.Debugf("隧道 %v 监听器关闭", r.id)
}
func copyConn(writer, reader net.Conn) {