feat: 更新多个模块以支持新的数据结构和日志格式

This commit is contained in:
TsMask
2025-02-20 10:08:27 +08:00
parent 045a2b6b01
commit f3c33b31ac
272 changed files with 13246 additions and 15885 deletions

View File

@@ -7,9 +7,9 @@ import (
"be.ems/src/framework/i18n"
"be.ems/src/framework/logger"
"be.ems/src/framework/utils/ctx"
"be.ems/src/framework/utils/ssh"
"be.ems/src/framework/vo/result"
"be.ems/src/framework/reqctx"
"be.ems/src/framework/resp"
"be.ems/src/framework/ssh"
neService "be.ems/src/modules/network_element/service"
"github.com/gin-gonic/gin"
@@ -19,14 +19,14 @@ import (
//
// GET /ssh?hostId=1&cols=80&rows=40
func (s *WSController) SSH(c *gin.Context) {
language := ctx.AcceptLanguage(c)
language := reqctx.AcceptLanguage(c)
var query struct {
HostId string `form:"hostId" binding:"required"` // 连接主机ID
Cols int `form:"cols"` // 终端单行字符数
Rows int `form:"rows"` // 终端显示行数
HostId int64 `form:"hostId" binding:"required"` // 连接主机ID
Cols int `form:"cols"` // 终端单行字符数
Rows int `form:"rows"` // 终端显示行数
}
if err := c.ShouldBindQuery(&query); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
if query.Cols < 80 || query.Cols > 400 {
@@ -37,16 +37,16 @@ func (s *WSController) SSH(c *gin.Context) {
}
// 登录用户信息
loginUser, err := ctx.LoginUser(c)
loginUser, err := reqctx.LoginUser(c)
if err != nil {
c.JSON(401, result.CodeMsg(401, i18n.TKey(language, err.Error())))
c.JSON(401, resp.CodeMsg(401, i18n.TKey(language, err.Error())))
return
}
neHost := neService.NewNeHost.SelectById(query.HostId)
if neHost.HostID != query.HostId || neHost.HostType != "ssh" {
neHost := neService.NewNeHost.FindById(query.HostId)
if neHost.ID != query.HostId || neHost.HostType != "ssh" {
// 没有可访问主机信息数据!
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neHost.noData")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "neHost.noData")))
return
}
@@ -62,7 +62,7 @@ func (s *WSController) SSH(c *gin.Context) {
}
if clientErr != nil {
// 连接主机失败,请检查连接参数后重试
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neHost.errByHostInfo")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "neHost.errByHostInfo")))
return
}
defer client.Close()
@@ -71,7 +71,7 @@ func (s *WSController) SSH(c *gin.Context) {
clientSession, err := client.NewClientSession(query.Cols, query.Rows)
if err != nil {
// 连接主机失败,请检查连接参数后重试
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neHost.errByHostInfo")))
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "neHost.errByHostInfo")))
return
}
defer clientSession.Close()
@@ -83,7 +83,7 @@ func (s *WSController) SSH(c *gin.Context) {
}
defer wsConn.Close()
wsClient := s.wsService.ClientCreate(loginUser.UserID, nil, wsConn, clientSession)
wsClient := s.wsService.ClientCreate(loginUser.UserId, nil, wsConn, clientSession)
go s.wsService.ClientWriteListen(wsClient)
go s.wsService.ClientReadListen(wsClient, s.wsReceiveService.Shell)
@@ -96,8 +96,8 @@ func (s *WSController) SSH(c *gin.Context) {
outputByte := clientSession.Read()
if len(outputByte) > 0 {
outputStr := string(outputByte)
msgByte, _ := json.Marshal(result.Ok(map[string]any{
"requestId": fmt.Sprintf("ssh_%s_%d", neHost.HostID, ms.UnixMilli()),
msgByte, _ := json.Marshal(resp.Ok(map[string]any{
"requestId": fmt.Sprintf("ssh_%d_%d", neHost.ID, ms.UnixMilli()),
"data": outputStr,
}))
wsClient.MsgChan <- msgByte
@@ -111,7 +111,7 @@ func (s *WSController) SSH(c *gin.Context) {
}
case <-wsClient.StopChan: // 等待停止信号
s.wsService.ClientClose(wsClient.ID)
logger.Infof("ws Stop Client UID %s", wsClient.BindUid)
logger.Infof("ws Stop Client UID %d", wsClient.BindUid)
return
}
}