mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-03-14 01:34:47 +08:00
fix: 主机密码回显解密 (#1540)
This commit is contained in:
parent
319afd2d51
commit
b61d8aaabc
@ -42,6 +42,8 @@ func (b *BaseApi) CreateHost(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
req.Password = passwordItem
|
req.Password = passwordItem
|
||||||
|
req.PrivateKey = ""
|
||||||
|
req.PassPhrase = ""
|
||||||
}
|
}
|
||||||
if req.AuthMode == "key" && len(req.PrivateKey) != 0 {
|
if req.AuthMode == "key" && len(req.PrivateKey) != 0 {
|
||||||
privateKey, err := base64.StdEncoding.DecodeString(req.PrivateKey)
|
privateKey, err := base64.StdEncoding.DecodeString(req.PrivateKey)
|
||||||
@ -55,6 +57,16 @@ func (b *BaseApi) CreateHost(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
req.Password = keyItem
|
req.Password = keyItem
|
||||||
|
|
||||||
|
if len(req.PassPhrase) != 0 {
|
||||||
|
pass, err := encrypt.StringEncrypt(req.PassPhrase)
|
||||||
|
if err != nil {
|
||||||
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
req.PassPhrase = pass
|
||||||
|
}
|
||||||
|
req.Password = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
host, err := hostService.Create(req)
|
host, err := hostService.Create(req)
|
||||||
@ -229,6 +241,15 @@ func (b *BaseApi) UpdateHost(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
req.PrivateKey = keyItem
|
req.PrivateKey = keyItem
|
||||||
|
|
||||||
|
if len(req.PassPhrase) != 0 {
|
||||||
|
pass, err := encrypt.StringEncrypt(req.PassPhrase)
|
||||||
|
if err != nil {
|
||||||
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
req.PassPhrase = pass
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
upMap := make(map[string]interface{})
|
upMap := make(map[string]interface{})
|
||||||
@ -239,10 +260,12 @@ func (b *BaseApi) UpdateHost(c *gin.Context) {
|
|||||||
upMap["user"] = req.User
|
upMap["user"] = req.User
|
||||||
upMap["auth_mode"] = req.AuthMode
|
upMap["auth_mode"] = req.AuthMode
|
||||||
upMap["remember_password"] = req.RememberPassword
|
upMap["remember_password"] = req.RememberPassword
|
||||||
if len(req.Password) != 0 {
|
if req.AuthMode == "password" {
|
||||||
upMap["password"] = req.Password
|
upMap["password"] = req.Password
|
||||||
}
|
upMap["private_key"] = ""
|
||||||
if len(req.PrivateKey) != 0 {
|
upMap["pass_phrase"] = ""
|
||||||
|
} else {
|
||||||
|
upMap["password"] = ""
|
||||||
upMap["private_key"] = req.PrivateKey
|
upMap["private_key"] = req.PrivateKey
|
||||||
upMap["pass_phrase"] = req.PassPhrase
|
upMap["pass_phrase"] = req.PassPhrase
|
||||||
}
|
}
|
||||||
|
@ -105,6 +105,10 @@ func (u *HostService) TestLocalConn(id uint) bool {
|
|||||||
connInfo.PrivateKey = []byte(host.PrivateKey)
|
connInfo.PrivateKey = []byte(host.PrivateKey)
|
||||||
}
|
}
|
||||||
if len(host.PassPhrase) != 0 {
|
if len(host.PassPhrase) != 0 {
|
||||||
|
host.PassPhrase, err = encrypt.StringDecrypt(host.PassPhrase)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
connInfo.PassPhrase = []byte(host.PassPhrase)
|
connInfo.PassPhrase = []byte(host.PassPhrase)
|
||||||
}
|
}
|
||||||
client, err := connInfo.NewClient()
|
client, err := connInfo.NewClient()
|
||||||
@ -133,6 +137,13 @@ func (u *HostService) GetHostInfo(id uint) (*model.Host, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(host.PassPhrase) != 0 {
|
||||||
|
host.PassPhrase, err = encrypt.StringDecrypt(host.PassPhrase)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
return &host, err
|
return &host, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,6 +164,25 @@ func (u *HostService) SearchWithPage(search dto.SearchHostWithPage) (int64, inte
|
|||||||
item.Password = ""
|
item.Password = ""
|
||||||
item.PrivateKey = ""
|
item.PrivateKey = ""
|
||||||
item.PassPhrase = ""
|
item.PassPhrase = ""
|
||||||
|
} else {
|
||||||
|
if len(host.Password) != 0 {
|
||||||
|
item.Password, err = encrypt.StringDecrypt(host.Password)
|
||||||
|
if err != nil {
|
||||||
|
return 0, nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(host.PrivateKey) != 0 {
|
||||||
|
item.PrivateKey, err = encrypt.StringDecrypt(host.PrivateKey)
|
||||||
|
if err != nil {
|
||||||
|
return 0, nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(host.PassPhrase) != 0 {
|
||||||
|
item.PassPhrase, err = encrypt.StringDecrypt(host.PassPhrase)
|
||||||
|
if err != nil {
|
||||||
|
return 0, nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
dtoHosts = append(dtoHosts, item)
|
dtoHosts = append(dtoHosts, item)
|
||||||
}
|
}
|
||||||
|
@ -460,6 +460,15 @@ var EncryptHostPassword = &gormigrate.Migration{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if len(host.PassPhrase) != 0 {
|
||||||
|
pass, err := encrypt.StringEncrypt(host.PassPhrase)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := tx.Model(&model.Host{}).Update("pass_phrase", pass).Error; err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user