mirror of https://github.com/allinssl/allinssl
修改ssh部署
parent
e5634d4992
commit
bee46d943f
|
@ -1 +1,3 @@
|
|||
.DS_Store
|
||||
/data/
|
||||
/logs/
|
||||
|
|
|
@ -18,6 +18,7 @@ type SSHConfig struct {
|
|||
PrivateKey string `json:"key"` // 可选
|
||||
Host string
|
||||
Port any
|
||||
Mode string `json:"mode"`
|
||||
}
|
||||
|
||||
type RemoteFile struct {
|
||||
|
@ -59,7 +60,14 @@ func writeMultipleFilesViaSSH(config SSHConfig, files []RemoteFile, preCmd, post
|
|||
default:
|
||||
port = "22"
|
||||
}
|
||||
IPtype := public.CheckIPType(config.Host)
|
||||
if IPtype == "IPv6" {
|
||||
config.Host = "[" + config.Host + "]"
|
||||
}
|
||||
addr := fmt.Sprintf("%s:%s", config.Host, port)
|
||||
if config.Mode == "" || config.Mode == "password" {
|
||||
config.PrivateKey = ""
|
||||
}
|
||||
|
||||
authMethods, err := buildAuthMethods(config.Password, config.PrivateKey)
|
||||
if err != nil {
|
||||
|
|
|
@ -220,3 +220,14 @@ func ExecCommand(command string) (string, string, error) {
|
|||
|
||||
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"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue