| 239 | } |
| 240 | |
| 241 | func (u *SettingService) SaveConnInfo(req dto.SSHConnData) error { |
| 242 | if req.AuthMode == "password" && len(req.Password) != 0 { |
| 243 | password, err := base64.StdEncoding.DecodeString(req.Password) |
| 244 | if err != nil { |
| 245 | return err |
| 246 | } |
| 247 | req.Password = string(password) |
| 248 | } |
| 249 | if req.AuthMode == "key" && len(req.PrivateKey) != 0 { |
| 250 | privateKey, err := base64.StdEncoding.DecodeString(req.PrivateKey) |
| 251 | if err != nil { |
| 252 | return err |
| 253 | } |
| 254 | req.PrivateKey = string(privateKey) |
| 255 | } |
| 256 | |
| 257 | var connInfo ssh.ConnInfo |
| 258 | _ = copier.Copy(&connInfo, &req) |
| 259 | connInfo.PrivateKey = []byte(req.PrivateKey) |
| 260 | if len(req.PassPhrase) != 0 { |
| 261 | connInfo.PassPhrase = []byte(req.PassPhrase) |
| 262 | } |
| 263 | client, err := ssh.NewClient(connInfo) |
| 264 | if err != nil { |
| 265 | return err |
| 266 | } |
| 267 | defer client.Close() |
| 268 | |
| 269 | var connItem model.LocalConnInfo |
| 270 | _ = copier.Copy(&connItem, &req) |
| 271 | localConn, _ := json.Marshal(&connItem) |
| 272 | connAfterEncrypt, _ := encrypt.StringEncrypt(string(localConn)) |
| 273 | _ = settingRepo.Update("LocalSSHConn", connAfterEncrypt) |
| 274 | return nil |
| 275 | } |
| 276 | |
| 277 | func (u *SettingService) SetDefaultIsConn(req dto.SSHDefaultConn) error { |
| 278 | if req.DefaultConn == constant.StatusDisable && req.WithReset { |