36 lines
887 B
Go
36 lines
887 B
Go
package controller
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
|
|
"ezops/model"
|
|
"ezops/pkg/crypto"
|
|
)
|
|
|
|
// loadRDPCredential 解密并解析 Windows 服务器 RDP 凭据 // Logan.Li
|
|
func loadRDPCredential(crypt *crypto.SecretBox, server model.Server) (model.RDPSecretContent, error) {
|
|
var cred model.RDPSecretContent
|
|
if server.Password == "" {
|
|
return cred, errors.New("该 Windows 资产未关联 RDP 凭据")
|
|
}
|
|
plain := server.Password
|
|
if dec, err := crypt.Decrypt(server.Password); err == nil {
|
|
plain = dec
|
|
}
|
|
if err := json.Unmarshal([]byte(plain), &cred); err != nil {
|
|
cred.Username = server.Username
|
|
cred.Password = plain
|
|
}
|
|
if cred.Username == "" {
|
|
cred.Username = server.Username
|
|
}
|
|
if cred.Security == "" {
|
|
cred.Security = "nla"
|
|
}
|
|
if cred.Username == "" || cred.Password == "" {
|
|
return cred, errors.New("RDP 凭据缺少用户名或密码")
|
|
}
|
|
return cred, nil
|
|
}
|