修改ssh部署

pull/135/head
zhangchenhao 2025-05-23 17:04:27 +08:00
parent e5634d4992
commit bee46d943f
3 changed files with 49 additions and 28 deletions

2
.gitignore vendored
View File

@ -1 +1,3 @@
.DS_Store .DS_Store
/data/
/logs/

View File

@ -18,6 +18,7 @@ type SSHConfig struct {
PrivateKey string `json:"key"` // 可选 PrivateKey string `json:"key"` // 可选
Host string Host string
Port any Port any
Mode string `json:"mode"`
} }
type RemoteFile struct { type RemoteFile struct {
@ -59,7 +60,14 @@ func writeMultipleFilesViaSSH(config SSHConfig, files []RemoteFile, preCmd, post
default: default:
port = "22" port = "22"
} }
IPtype := public.CheckIPType(config.Host)
if IPtype == "IPv6" {
config.Host = "[" + config.Host + "]"
}
addr := fmt.Sprintf("%s:%s", config.Host, port) addr := fmt.Sprintf("%s:%s", config.Host, port)
if config.Mode == "" || config.Mode == "password" {
config.PrivateKey = ""
}
authMethods, err := buildAuthMethods(config.Password, config.PrivateKey) authMethods, err := buildAuthMethods(config.Password, config.PrivateKey)
if err != nil { if err != nil {

View File

@ -220,3 +220,14 @@ func ExecCommand(command string) (string, string, error) {
return stdout.String(), stderr.String(), err return stdout.String(), stderr.String(), err
} }
func CheckIPType(address string) string {
ip := net.ParseIP(address)
if ip == nil {
return "Invalid IP"
}
if ip.To4() != nil {
return "IPv4"
}
return "IPv6"
}