Compare commits

..

No commits in common. "2d08dd7cec05d149f7f33c2b82fe9edf3b1c5380" and "6490779a2e013d0ef5ba8aa1c5e1607149dadf57" have entirely different histories.

4 changed files with 18 additions and 19 deletions

View File

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

View File

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

View File

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

View File

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