2021-05-08 18:00:33 +08:00
|
|
|
|
package entity
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
2024-01-05 08:55:34 +08:00
|
|
|
|
"errors"
|
2022-08-02 21:44:01 +08:00
|
|
|
|
"mayfly-go/internal/common/utils"
|
2022-06-02 17:41:11 +08:00
|
|
|
|
"mayfly-go/pkg/model"
|
2021-05-08 18:00:33 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
type Machine struct {
|
|
|
|
|
|
model.Model
|
2022-10-26 20:49:29 +08:00
|
|
|
|
|
2023-12-05 23:03:51 +08:00
|
|
|
|
Code string `json:"code"`
|
2022-07-23 16:41:04 +08:00
|
|
|
|
Name string `json:"name"`
|
2023-12-05 23:03:51 +08:00
|
|
|
|
Ip string `json:"ip"` // IP地址
|
|
|
|
|
|
Port int `json:"port"` // 端口号
|
|
|
|
|
|
Username string `json:"username"` // 用户名
|
|
|
|
|
|
Password string `json:"password"` // 密码
|
|
|
|
|
|
AuthCertId int `json:"authCertId"` // 授权凭证id
|
2022-07-23 16:41:04 +08:00
|
|
|
|
Status int8 `json:"status"` // 状态 1:启用;2:停用
|
|
|
|
|
|
Remark string `json:"remark"` // 备注
|
2023-03-06 16:59:57 +08:00
|
|
|
|
SshTunnelMachineId int `json:"sshTunnelMachineId"` // ssh隧道机器id
|
2022-08-29 21:43:24 +08:00
|
|
|
|
EnableRecorder int8 `json:"enableRecorder"` // 是否启用终端回放记录
|
2021-05-08 18:00:33 +08:00
|
|
|
|
}
|
2022-04-27 10:59:02 +08:00
|
|
|
|
|
|
|
|
|
|
const (
|
2023-03-06 16:59:57 +08:00
|
|
|
|
MachineStatusEnable int8 = 1 // 启用状态
|
|
|
|
|
|
MachineStatusDisable int8 = -1 // 禁用状态
|
2022-04-27 10:59:02 +08:00
|
|
|
|
)
|
2022-08-02 21:44:01 +08:00
|
|
|
|
|
2024-01-05 08:55:34 +08:00
|
|
|
|
func (m *Machine) PwdEncrypt() error {
|
2022-08-02 21:44:01 +08:00
|
|
|
|
// 密码替换为加密后的密码
|
2024-01-05 08:55:34 +08:00
|
|
|
|
password, err := utils.PwdAesEncrypt(m.Password)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return errors.New("加密主机密码失败")
|
|
|
|
|
|
}
|
|
|
|
|
|
m.Password = password
|
|
|
|
|
|
return nil
|
2022-08-02 21:44:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-05 08:55:34 +08:00
|
|
|
|
func (m *Machine) PwdDecrypt() error {
|
2022-08-02 21:44:01 +08:00
|
|
|
|
// 密码替换为解密后的密码
|
2024-01-05 08:55:34 +08:00
|
|
|
|
password, err := utils.PwdAesDecrypt(m.Password)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return errors.New("解密主机密码失败")
|
|
|
|
|
|
}
|
|
|
|
|
|
m.Password = password
|
|
|
|
|
|
return nil
|
2022-08-02 21:44:01 +08:00
|
|
|
|
}
|
2022-11-18 17:52:30 +08:00
|
|
|
|
|
2023-03-06 16:59:57 +08:00
|
|
|
|
func (m *Machine) UseAuthCert() bool {
|
|
|
|
|
|
return m.AuthCertId > 0
|
2022-11-18 17:52:30 +08:00
|
|
|
|
}
|