Merge branch 'refs/heads/feat-cmd'

This commit is contained in:
junleea 2025-03-24 20:14:50 +08:00
commit 2d08dd7cec
4 changed files with 19 additions and 18 deletions

View File

@ -50,9 +50,9 @@ func FindShellByID(id, uid uint) []Shell {
func FindShellByAuthID(auth_id int) []Shell {
var shells []Shell
if proto.Config.SERVER_SQL_LOG {
DB.Debug().Exec("select * from shells where auth_id = ? order by created_at desc limit 100", auth_id).Scan(&shells)
DB.Debug().Where("auth_id = ?", auth_id).Order("created_at DESC").Limit(100).Find(&shells)
} else {
DB.Exec("select * from shells where auth_id = ? order by created_at desc limit 100", auth_id).Scan(&shells)
DB.Where("auth_id = ?", auth_id).Order("created_at DESC").Limit(100).Find(&shells)
}
return shells
}

View File

@ -10,21 +10,21 @@ type ShellHandler struct {
}
type CreateShellReq struct {
ShellName string `json:"shell_name"`
ShellContent string `json:"shell_content"`
Server string `json:"server"`
ShellName string `json:"shell_name" form:"shell_name" binding:"required"`
ShellContent string `json:"shell_content" form:"shell_content" binding:"required"`
Server string `json:"server" form:"server" binding:"required"`
}
type UpdateShellReq struct {
ID uint `json:"id"`
ShellName string `json:"shell_name"`
ShellContent string `json:"shell_content"`
Server string `json:"server"`
Status int `json:"status"`
ShellResult string `json:"shell_result"`
ID uint `json:"id" form:"id" binding:"required"`
ShellName string `json:"shell_name" form:"shell_name"`
ShellContent string `json:"shell_content" form:"shell_content"`
Server string `json:"server" form:"server"`
Status int `json:"status" form:"status"`
ShellResult string `json:"shell_result" form:"shell_result"`
}
type UpdateShellReqV2 struct {
Shells []UpdateShellReq `json:"shells"`
Shells []UpdateShellReq `json:"shells" form:"shells"`
}
type UpdateShellResp struct {
@ -45,7 +45,7 @@ func (s *ShellHandler) CreateShell(c *gin.Context) {
user_id, _ := c.Get("id")
uid := int(user_id.(float64))
var req CreateShellReq
if err := c.ShouldBindJSON(&req); err != nil {
if err := c.ShouldBind(&req); err != nil {
c.JSON(200, gin.H{"code": proto.ShellCreateFailed, "message": "参数错误", "data": err.Error()})
} else {
id := service.CreateShell(req.ShellName, req.ShellContent, req.Server, uid)
@ -68,10 +68,11 @@ func (s *ShellHandler) UpdateShell(c *gin.Context) {
var req UpdateShellReqV2
userId, _ := c.Get("id")
id := int(userId.(float64))
if err := c.ShouldBindJSON(&req); err != nil {
if err := c.ShouldBind(&req); err != nil {
c.JSON(200, gin.H{"code": proto.ShellUpdateFailed, "message": "参数错误", "data": err.Error()})
} else {
var resp []UpdateShellResp
//log.Println("UpdateShellReqData:", req.Shells)
for _, v := range req.Shells {
if service.UpdateShellByID(v.ID, uint(id), v.ShellName, v.ShellContent, v.Server, v.Status, v.ShellResult) {
resp = append(resp, UpdateShellResp{ID: v.ID, Status: v.Status})
@ -91,9 +92,10 @@ func (s *ShellHandler) ServerWillRun(c *gin.Context) {
userId, _ := c.Get("id")
id := int(userId.(float64))
var req ServerWillRunReq
if err := c.ShouldBindJSON(&req); err != nil {
if err := c.ShouldBind(&req); err != nil {
c.JSON(200, gin.H{"code": proto.ShellUpdateFailed, "message": "参数错误", "data": err.Error()})
} else {
//log.Printf("ServerWillRunReq:%s,id:%d", req.Server, id)
willRunShells, err2 := service.FindShellWillRunByServer(req.Server, id)
if err2 != nil {
c.JSON(200, gin.H{"code": proto.ShellUpdateFailed, "message": "获取失败", "data": err2.Error()})

View File

@ -149,7 +149,6 @@ func JWTAuthMiddleware() gin.HandlerFunc {
})
return
}
log.Printf("req super_id:%s", sId)
id, _ := strconv.Atoi(sId)
idFloat64 := float64(id)
//查看s_id类型

View File

@ -61,9 +61,9 @@ func ShellWillRunFromServer() {
return
}
//返回执行结果
url := "https://" + proto.Config.MASTER_SERVER_DOMAIN + "/shell/update"
url := "https://" + proto.Config.MASTER_SERVER_DOMAIN + "/shell/update?super_id=1"
var req proto.SyncUserShellResp
req.Token = worker.GetRedisSetMembers("super_permission_tokens?super_id=1")[0]
req.Token = worker.GetRedisSetMembers("super_permission_tokens")[0]
req.Shells = resp
resp_data, err := worker.SyncDataFromMasterShellReq3(url, req)
if err != nil {