mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-31 14:08:06 +08:00
fix: 主机连接、数据库连接适配 IPv6 (#2832)
This commit is contained in:
parent
fbc34c2847
commit
8adca0efa2
@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/1Panel-dev/1Panel/backend/buserr"
|
"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
|
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)
|
connArgs := fmt.Sprintf("%s:%s@tcp(%s:%d)/?charset=utf8", conn.Username, conn.Password, conn.Address, conn.Port)
|
||||||
db, err := sql.Open("mysql", connArgs)
|
db, err := sql.Open("mysql", connArgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -26,6 +27,9 @@ type ConnInfo struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *ConnInfo) NewClient() (*ConnInfo, error) {
|
func (c *ConnInfo) NewClient() (*ConnInfo, error) {
|
||||||
|
if strings.Contains(c.Addr, ":") {
|
||||||
|
c.Addr = fmt.Sprintf("[%s]", c.Addr)
|
||||||
|
}
|
||||||
config := &gossh.ClientConfig{}
|
config := &gossh.ClientConfig{}
|
||||||
config.SetDefaults()
|
config.SetDefaults()
|
||||||
addr := fmt.Sprintf("%s:%d", c.Addr, c.Port)
|
addr := fmt.Sprintf("%s:%d", c.Addr, c.Port)
|
||||||
@ -45,7 +49,11 @@ func (c *ConnInfo) NewClient() (*ConnInfo, error) {
|
|||||||
config.Timeout = c.DialTimeOut
|
config.Timeout = c.DialTimeOut
|
||||||
|
|
||||||
config.HostKeyCallback = gossh.InsecureIgnoreHostKey()
|
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 {
|
if nil != err {
|
||||||
return c, err
|
return c, err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user