diff --git a/README_EN.md b/README_EN.md index c57e3cfb..695a58c6 100644 --- a/README_EN.md +++ b/README_EN.md @@ -18,7 +18,7 @@ The Rat Panel is an open source lightweight Linux server operation and maintenance management panel developed using Golang and Vue. -QQ group: [12370907](https://jq.qq.com/?_wv=1027&k=I1oJKSTH) | WeChat group:[Copy this link](https://work.weixin.qq.com/gm/d8ebf618553398d454e3378695c858b6) | Forum: [tom.moe](https://tom.moe) | Sponsor: [Open Collective](https://opencollective.com/tnb) +QQ group: [12370907](https://jq.qq.com/?_wv=1027&k=I1oJKSTH) | WeChat group: [Copy this link](https://work.weixin.qq.com/gm/d8ebf618553398d454e3378695c858b6) | Forum: [tom.moe](https://tom.moe) | Sponsor: [Open Collective](https://opencollective.com/tnb) ## Advantages diff --git a/internal/biz/ssh.go b/internal/biz/ssh.go index bfa4664d..e8d18bc1 100644 --- a/internal/biz/ssh.go +++ b/internal/biz/ssh.go @@ -1,6 +1,20 @@ package biz -import "github.com/TheTNB/panel/internal/http/request" +import ( + "time" + + "github.com/TheTNB/panel/internal/http/request" + "github.com/TheTNB/panel/pkg/ssh" +) + +type SSH struct { + ID uint `gorm:"primaryKey" json:"id"` + Host string `json:"host"` + Port uint `json:"port"` + Config ssh.ClientConfig `json:"config"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` +} type SSHRepo interface { GetInfo() (map[string]any, error) diff --git a/pkg/ssh/ssh.go b/pkg/ssh/ssh.go index 6cfda0dd..9282f740 100644 --- a/pkg/ssh/ssh.go +++ b/pkg/ssh/ssh.go @@ -1,7 +1,6 @@ package ssh import ( - "os" "time" "golang.org/x/crypto/ssh" @@ -19,7 +18,7 @@ type ClientConfig struct { HostAddr string User string Password string - KeyPath string + Key string Timeout time.Duration } @@ -33,13 +32,13 @@ func ClientConfigPassword(hostAddr, user, Password string) *ClientConfig { } } -func ClientConfigPublicKey(hostAddr, user, keyPath string) *ClientConfig { +func ClientConfigPublicKey(hostAddr, user, key string) *ClientConfig { return &ClientConfig{ Timeout: time.Second * 5, AuthMethod: PUBLICKEY, HostAddr: hostAddr, User: user, - KeyPath: keyPath, + Key: key, } } @@ -54,7 +53,7 @@ func NewSSHClient(conf *ClientConfig) (*ssh.Client, error) { case PASSWORD: config.Auth = []ssh.AuthMethod{ssh.Password(conf.Password)} case PUBLICKEY: - signer, err := getKey(conf.KeyPath) + signer, err := parseKey(conf.Key) if err != nil { return nil, err } @@ -68,11 +67,6 @@ func NewSSHClient(conf *ClientConfig) (*ssh.Client, error) { return c, nil } -func getKey(keyPath string) (ssh.Signer, error) { - key, err := os.ReadFile(keyPath) - if err != nil { - return nil, err - } - - return ssh.ParsePrivateKey(key) +func parseKey(key string) (ssh.Signer, error) { + return ssh.ParsePrivateKey([]byte(key)) }