fix: 修复网关选择器显示ID问题,添加SSH网关连接调试日志

This commit is contained in:
2026-04-23 14:47:30 +08:00
parent 65323216b5
commit 0bc0eabac0
3 changed files with 33 additions and 18 deletions
+12
View File
@@ -5,11 +5,21 @@ import (
"net"
"time"
"next-terminal/server/log"
"golang.org/x/crypto/ssh"
"golang.org/x/net/proxy"
)
func NewSshClient(ip string, port int, username, password, privateKey, passphrase string) (*ssh.Client, error) {
log.Debug("NewSshClient",
log.String("ip", ip),
log.Int("port", port),
log.String("username", username),
log.Bool("hasPassword", password != "" && password != "-"),
log.Bool("hasPrivateKey", privateKey != "" && privateKey != "-"),
log.Bool("hasPassphrase", passphrase != "" && passphrase != "-"))
var authMethod ssh.AuthMethod
if username == "-" || username == "" {
username = "root"
@@ -39,8 +49,10 @@ func NewSshClient(ip string, port int, username, password, privateKey, passphras
}
}
authMethod = ssh.PublicKeys(key)
log.Debug("NewSshClient using public key auth")
} else {
authMethod = ssh.Password(password)
log.Debug("NewSshClient using password auth")
}
config := &ssh.ClientConfig{
+21
View File
@@ -36,6 +36,17 @@ func (r gatewayService) GetGatewayById(accessGatewayId string) (g *gateway.Gatew
func (r gatewayService) loadSshGateway(m *model.SshGateway) (g *gateway.Gateway, err error) {
r.DisconnectById(m.ID)
log.Debug("loadSshGateway",
log.String("id", m.ID),
log.String("name", m.Name),
log.String("configMode", m.ConfigMode),
log.String("ip", m.IP),
log.Int("port", m.Port),
log.String("accountType", m.AccountType),
log.String("username", m.Username),
log.Bool("hasPassword", m.Password != ""),
log.Bool("hasPrivateKey", m.PrivateKey != ""))
// 根据配置模式获取连接信息
switch m.ConfigMode {
case "direct":
@@ -52,6 +63,10 @@ func (r gatewayService) loadSshGateway(m *model.SshGateway) (g *gateway.Gateway,
m.Password = credential.Password
m.PrivateKey = credential.PrivateKey
m.Passphrase = credential.Passphrase
log.Debug("loadSshGateway from credential",
log.String("username", m.Username),
log.Bool("hasPassword", m.Password != ""),
log.Bool("hasPrivateKey", m.PrivateKey != ""))
g = gateway.GlobalGatewayManager.AddFromSshGateway(m)
}
case "asset":
@@ -67,6 +82,12 @@ func (r gatewayService) loadSshGateway(m *model.SshGateway) (g *gateway.Gateway,
m.Password = asset.Password
m.PrivateKey = asset.PrivateKey
m.Passphrase = asset.Passphrase
log.Debug("loadSshGateway from asset",
log.String("ip", m.IP),
log.Int("port", m.Port),
log.String("username", m.Username),
log.Bool("hasPassword", m.Password != ""),
log.Bool("hasPrivateKey", m.PrivateKey != ""))
g = gateway.GlobalGatewayManager.AddFromSshGateway(m)
}
default:
-18
View File
@@ -333,12 +333,6 @@ const AssetsPost = function ({assetId, groupId, copy, onClose}: AssetsInfoProps)
showSearch
rules={[{required: true}]}
debounceTime={0}
convertValue={(value: any) => {
if (value && value !== '-') {
return { value, label: value };
}
return undefined;
}}
/>
);
} else if (gatewayType === 'agent') {
@@ -352,12 +346,6 @@ const AssetsPost = function ({assetId, groupId, copy, onClose}: AssetsInfoProps)
showSearch
rules={[{required: true}]}
debounceTime={0}
convertValue={(value: any) => {
if (value && value !== '-') {
return { value, label: value };
}
return undefined;
}}
/>
);
} else if (gatewayType === 'group') {
@@ -370,12 +358,6 @@ const AssetsPost = function ({assetId, groupId, copy, onClose}: AssetsInfoProps)
params={{gatewayType}}
showSearch
rules={[{required: true}]}
convertValue={(value: any) => {
if (value && value !== '-') {
return { value, label: value };
}
return undefined;
}}
/>
);
}