diff --git a/backend/utils/mysql/client.go b/backend/utils/mysql/client.go index f52651bcb..b2ca2a35b 100644 --- a/backend/utils/mysql/client.go +++ b/backend/utils/mysql/client.go @@ -4,6 +4,7 @@ import ( "context" "database/sql" "fmt" + "strings" "time" "github.com/1Panel-dev/1Panel/backend/buserr" @@ -31,6 +32,9 @@ func NewMysqlClient(conn client.DBInfo) (MysqlClient, error) { return client.NewLocal(connArgs, conn.Address, conn.Password, conn.Database), nil } + if strings.Contains(conn.Address, ":") { + conn.Address = fmt.Sprintf("[%s]", conn.Address) + } connArgs := fmt.Sprintf("%s:%s@tcp(%s:%d)/?charset=utf8", conn.Username, conn.Password, conn.Address, conn.Port) db, err := sql.Open("mysql", connArgs) if err != nil { diff --git a/backend/utils/ssh/ssh.go b/backend/utils/ssh/ssh.go index bbe6d2377..f487182d4 100644 --- a/backend/utils/ssh/ssh.go +++ b/backend/utils/ssh/ssh.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "io" + "strings" "sync" "time" @@ -26,6 +27,9 @@ type ConnInfo struct { } func (c *ConnInfo) NewClient() (*ConnInfo, error) { + if strings.Contains(c.Addr, ":") { + c.Addr = fmt.Sprintf("[%s]", c.Addr) + } config := &gossh.ClientConfig{} config.SetDefaults() addr := fmt.Sprintf("%s:%d", c.Addr, c.Port) @@ -45,7 +49,11 @@ func (c *ConnInfo) NewClient() (*ConnInfo, error) { config.Timeout = c.DialTimeOut config.HostKeyCallback = gossh.InsecureIgnoreHostKey() - client, err := gossh.Dial("tcp", addr, config) + proto := "tcp" + if strings.Contains(c.Addr, ":") { + proto = "tcp6" + } + client, err := gossh.Dial(proto, addr, config) if nil != err { return c, err }