feat: 导出udm-auth未加密数据

This commit is contained in:
TsMask
2025-09-28 18:38:08 +08:00
parent d82f186bc0
commit 33bbe5cd2c
6 changed files with 85 additions and 0 deletions

View File

@@ -2,7 +2,9 @@ package controller
import (
"fmt"
"os"
"path/filepath"
"runtime"
"strings"
"time"
@@ -653,3 +655,77 @@ func (s *UDMAuthController) Import(c *gin.Context) {
}
c.JSON(200, resp.OkMsg(resultMsg))
}
// UDM鉴权用户导出解密数据
//
// GET /export-dec
//
// @Tags network_data/udm/auth
// @Accept json
// @Produce json
// @Param data body object true "Request Param"
// @Success 200 {object} object "Response Results"
// @Security TokenAuth
// @Summary UDM Authenticated User Export Decrypted Data
// @Description UDM Authenticated User Export Decrypted Data
// @Router /neData/udm/auth/export-dec [get]
func (s *UDMAuthController) ExportDec(c *gin.Context) {
// 查询结果,根据查询条件结果,单页最大值限制
neId := c.Query("neId")
if neId == "" {
c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_CHEACK, "bind err: neId is empty"))
return
}
// 网元主机的Telnet客户端
telnetClient, err := s.neInfoService.NeRunTelnetClient("UDM", neId, 1)
if err != nil {
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
defer telnetClient.Close()
// 发送MML
// 导出解密的ki和opc 需要执行 dec authdat:imsi=all
// 生成文件 /user/local/etc/udm/authdata.txt
cmd := "dec authdat:imsi=all"
data, err := telnet.ConvertToStr(telnetClient, cmd)
if err != nil {
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
// 命令ok时
if strings.Contains(data, "ok") {
// 网元主机的SSH客户端
sshClient, err := s.neInfoService.NeRunSSHClient("UDM", neId)
if err != nil {
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
defer sshClient.Close()
// 网元主机的SSH客户端进行文件传输
sftpClient, err := sshClient.NewClientSFTP()
if err != nil {
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
defer sftpClient.Close()
// 复制到本地
nePath := "/usr/local/etc/udm/authdata.txt"
localFilePath := filepath.Join("/tmp/omc/pull", filepath.Base(nePath))
if runtime.GOOS == "windows" {
localFilePath = fmt.Sprintf("C:%s", localFilePath)
}
if err = sftpClient.CopyFileRemoteToLocal(nePath, localFilePath); err != nil {
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
sshClient.RunCMD(fmt.Sprintf("sudo rm -rf %s", nePath))
defer os.Remove(localFilePath)
c.FileAttachment(localFilePath, filepath.Base(nePath))
return
}
c.JSON(200, resp.ErrMsg("unexpected result"))
}

View File

@@ -380,6 +380,11 @@ func Setup(router *gin.Engine) {
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.udmAuth", collectlogs.BUSINESS_TYPE_IMPORT)),
controller.NewUDMAuth.Import,
)
udmAuthGroup.GET("/export-dec",
middleware.AuthorizeUser(map[string][]string{"hasPerms": {"neData:udm-auth:export-dec"}}),
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.udmAuth", collectlogs.BUSINESS_TYPE_EXPORT)),
controller.NewUDMAuth.ExportDec,
)
}
// 网元UDM 签约用户信息