feat: 添加网元配置文件备份的FTP配置管理功能

This commit is contained in:
TsMask
2025-04-10 16:09:46 +08:00
parent c2ea573c6a
commit 6617cbcb0a
5 changed files with 187 additions and 45 deletions

View File

@@ -10,13 +10,11 @@ import (
"be.ems/lib/file"
"be.ems/lib/log"
"be.ems/lib/services"
"be.ems/src/framework/config"
"be.ems/src/framework/database/db"
"be.ems/src/framework/i18n"
"be.ems/src/framework/reqctx"
"be.ems/src/framework/resp"
"be.ems/src/framework/ssh"
"be.ems/src/framework/utils/crypto"
systemService "be.ems/src/modules/system/service"
"github.com/gin-gonic/gin"
)
@@ -161,23 +159,16 @@ func (m *SysJob) SetFTPConfig(c *gin.Context) {
}
// 获取配置
cfg := systemService.NewSysConfig.FindByKey("sys.exportTable")
cfg := systemService.NewSysConfig.FindByKey("neData.exportTableFTP")
if cfg.ConfigId > 0 {
// 加密body
appKey := config.Get("aes.appKey").(string)
byteData, err := json.Marshal(body)
if err != nil {
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
bodyEn, err := crypto.AESEncryptBase64(string(byteData), appKey)
if err != nil {
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
// 更新
cfg.ConfigValue = bodyEn
systemService.NewSysConfig.Update(cfg)
cfg.ConfigValue = string(byteData)
cfg.UpdateBy = reqctx.LoginUserToUserName(c)
systemService.NewSysConfig.UpdateEncryptValue(cfg)
}
c.JSON(200, resp.Ok(nil))
@@ -187,15 +178,8 @@ func (m *SysJob) SetFTPConfig(c *gin.Context) {
// GET /table/ftp
func (m *SysJob) GetFTPConfig(c *gin.Context) {
// 获取配置
cfg := systemService.NewSysConfig.FindByKey("sys.exportTable")
cfg := systemService.NewSysConfig.FindByKeyDecryptValue("neData.exportTableFTP")
if cfg.ConfigId > 0 {
// 解密body
appKey := config.Get("aes.appKey").(string)
bodyDe, err := crypto.AESDecryptBase64(cfg.ConfigValue, appKey)
if err != nil {
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
var body struct {
Password string `json:"password" `
Username string `json:"username" binding:"required"`
@@ -204,8 +188,7 @@ func (m *SysJob) GetFTPConfig(c *gin.Context) {
Enable bool `json:"enable"`
Dir string `json:"dir" binding:"required"`
}
err = json.Unmarshal([]byte(bodyDe), &body)
if err != nil {
if err := json.Unmarshal([]byte(cfg.ConfigValue), &body); err != nil {
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
@@ -246,17 +229,9 @@ func (m *SysJob) PutFTP(c *gin.Context) {
Enable bool `json:"enable"`
Dir string `json:"dir" binding:"required"`
}
cfg := systemService.NewSysConfig.FindByKey("sys.exportTable")
cfg := systemService.NewSysConfig.FindByKeyDecryptValue("neData.exportTableFTP")
if cfg.ConfigId > 0 {
// 解密body
appKey := config.Get("aes.appKey").(string)
bodyDe, err := crypto.AESDecryptBase64(cfg.ConfigValue, appKey)
if err != nil {
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
err = json.Unmarshal([]byte(bodyDe), &cfgData)
if err != nil {
if err := json.Unmarshal([]byte(cfg.ConfigValue), &cfgData); err != nil {
c.JSON(200, resp.ErrMsg(err.Error()))
return
}