From 7e1d876604a81951720d9e94111c0fea593d69f8 Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Wed, 5 Mar 2025 19:15:48 +0800 Subject: [PATCH 01/10] =?UTF-8?q?sql=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dao/shell.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dao/shell.go b/dao/shell.go index 362d3b0..e382be7 100644 --- a/dao/shell.go +++ b/dao/shell.go @@ -35,9 +35,9 @@ func FindShellByID(id, uid uint) []Shell { var result *gorm.DB if proto.Config.SERVER_SQL_LOG { - result = DB.Debug().Where("id = ? & auth_id = ?", id, uid).First(&shell) + result = DB.Debug().Where("id = ? and auth_id = ?", id, uid).First(&shell) } else { - result = DB.Where("id = ? & auth_id = ?", id, uid).First(&shell) + result = DB.Where("id = ? and auth_id = ?", id, uid).First(&shell) } var res []Shell res = append(res, shell) From 81652333967049547d9934e5b9a2205785c8c3cf Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Wed, 5 Mar 2025 19:21:42 +0800 Subject: [PATCH 02/10] =?UTF-8?q?sql=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dao/shell.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/dao/shell.go b/dao/shell.go index e382be7..23f962c 100644 --- a/dao/shell.go +++ b/dao/shell.go @@ -77,9 +77,24 @@ func UpdateShellByID(id, authId uint, shellName, shellContent string, status int func FindShellWillRunByServer(server string, uid uint) []Shell { var shells []Shell if proto.Config.SERVER_SQL_LOG { - DB.Debug().Exec("select * from shells where server = ? and auth_id = ? and status = 0 order by created_at desc limit 100", server, uid).Scan(&shells) + result := DB.Debug().Where("server = ? AND auth_id = ? AND status = 0", server, uid). + Order("created_at DESC"). + Limit(100). + Find(&shells) + if result.Error != nil { + // 若查询过程中出现错误,输出错误信息 + log.Printf("Failed to query shells: %v\n", result.Error) + } } else { - DB.Exec("select * from shells where server = ? and auth_id = ? and status = 0 order by created_at desc limit 100", server, uid).Scan(&shells) + //DB.Exec("select * from shells where server = ? and auth_id = ? and status = 0 order by created_at desc limit 100", server, uid).Scan(&shells) + result := DB.Where("server = ? AND auth_id = ? AND status = 0", server, uid). + Order("created_at DESC"). + Limit(100). + Find(&shells) + if result.Error != nil { + // 若查询过程中出现错误,输出错误信息 + log.Printf("Failed to query shells: %v\n", result.Error) + } } return shells } From 5bbb158a7d42169488c3fde9e7316ede2ba7b955 Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Wed, 5 Mar 2025 19:24:23 +0800 Subject: [PATCH 03/10] =?UTF-8?q?sql=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dao/shell.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dao/shell.go b/dao/shell.go index 23f962c..39d78ec 100644 --- a/dao/shell.go +++ b/dao/shell.go @@ -42,7 +42,7 @@ func FindShellByID(id, uid uint) []Shell { var res []Shell res = append(res, shell) if result.Error != nil { - log.Fatalf("FindShellByID failed: %v", result.Error) + log.Printf("FindShellByID failed: %v", result.Error) } return res } From e9fd3b346d341af722a8f4d65d28df4918c921c5 Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Wed, 5 Mar 2025 19:33:07 +0800 Subject: [PATCH 04/10] =?UTF-8?q?sql=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- service/shellService.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/service/shellService.go b/service/shellService.go index 2eb55f5..5e417f1 100644 --- a/service/shellService.go +++ b/service/shellService.go @@ -57,10 +57,13 @@ func ShellWillRunFromServer() { resp = append(resp, proto.UpdateShellReq{ID: v.ID, Server: v.Server, Status: 2, ShellResult: res}) } } + if len(resp) == 0 { + return + } //返回执行结果 url := "https://" + proto.Config.MASTER_SERVER_DOMAIN + "/shell/update" 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 resp_data, err := worker.SyncDataFromMasterShellReq3(url, req) if err != nil { @@ -78,7 +81,7 @@ func ShellWillRunFromServer() { func GetShellWillRunFromMaster(server string) ([]dao.Shell, error) { master := proto.Config.MASTER_SERVER_DOMAIN //发起请求获取待执行的shell - url := "https://" + master + "/shell/server_will_run_list" + url := "https://" + master + "/shell/server_will_run_list?super_id=1" var req proto.SyncUserShellReq req.Server = server req.Token = worker.GetRedisSetMembers("super_permission_tokens")[0] From a6954f8f9e3e236a394257ed1889780a3324babe Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Wed, 5 Mar 2025 19:35:13 +0800 Subject: [PATCH 05/10] =?UTF-8?q?=E8=B6=85=E7=BA=A7token?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 1 + 1 file changed, 1 insertion(+) diff --git a/main.go b/main.go index f5ca7b7..9dd4b07 100644 --- a/main.go +++ b/main.go @@ -152,6 +152,7 @@ func JWTAuthMiddleware() gin.HandlerFunc { if sId == "" { sId = "1" } + log.Printf("req super_id:%s", sId) id, _ := strconv.Atoi(sId) idFloat64 := float64(id) //查看s_id类型 From 0ebc447c32371da2104c6674bc63c27e501112bb Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Wed, 5 Mar 2025 19:40:55 +0800 Subject: [PATCH 06/10] =?UTF-8?q?=E8=B6=85=E7=BA=A7token?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/main.go b/main.go index 9dd4b07..2dc7e18 100644 --- a/main.go +++ b/main.go @@ -137,15 +137,15 @@ func JWTAuthMiddleware() gin.HandlerFunc { //查看token是否在超级token中 if worker.IsContainSet("super_permission_tokens", tokenString) { sId := c.Request.Header.Get("super_id") - if sId == "" { - c.AbortWithStatus(200) - c.JSON(200, gin.H{ - "message": "NOT_LOGIN", - "error": "super_id is empty", - "code": proto.TokenIsNull, - }) - return - } + //if sId == "" { + // c.AbortWithStatus(200) + // c.JSON(200, gin.H{ + // "message": "NOT_LOGIN", + // "error": "super_id is empty", + // "code": proto.TokenIsNull, + // }) + // return + //} if sId == "" { sId = c.Query("super_id") } From 2042c11b4043f25d3c1535fdf5354e47d4ca71c9 Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Wed, 5 Mar 2025 19:45:33 +0800 Subject: [PATCH 07/10] =?UTF-8?q?=E8=B6=85=E7=BA=A7token?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/main.go b/main.go index 2dc7e18..b99820f 100644 --- a/main.go +++ b/main.go @@ -137,20 +137,17 @@ func JWTAuthMiddleware() gin.HandlerFunc { //查看token是否在超级token中 if worker.IsContainSet("super_permission_tokens", tokenString) { sId := c.Request.Header.Get("super_id") - //if sId == "" { - // c.AbortWithStatus(200) - // c.JSON(200, gin.H{ - // "message": "NOT_LOGIN", - // "error": "super_id is empty", - // "code": proto.TokenIsNull, - // }) - // return - //} if sId == "" { sId = c.Query("super_id") } if sId == "" { - sId = "1" + c.AbortWithStatus(200) + c.JSON(200, gin.H{ + "message": "NOT_LOGIN", + "error": "super_id is empty", + "code": proto.TokenIsNull, + }) + return } log.Printf("req super_id:%s", sId) id, _ := strconv.Atoi(sId) From b75d6a62ef8829b61d580511ffa84a1b39d0c976 Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Wed, 5 Mar 2025 19:54:31 +0800 Subject: [PATCH 08/10] =?UTF-8?q?=E6=B5=8B=E8=AF=95shell=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/main.go b/main.go index b99820f..d3640ed 100644 --- a/main.go +++ b/main.go @@ -134,6 +134,11 @@ func JWTAuthMiddleware() gin.HandlerFunc { return } } + //测试 + if strings.Contains(c.Request.URL.Path, "/shell/") { + log.Printf("req token:%s ,path:%s", tokenString, c.Request.URL.Path) + } + //查看token是否在超级token中 if worker.IsContainSet("super_permission_tokens", tokenString) { sId := c.Request.Header.Get("super_id") From ccf1916e4e6359ba7b3267fdeb381bce5f185a9e Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Wed, 5 Mar 2025 19:56:20 +0800 Subject: [PATCH 09/10] =?UTF-8?q?=E6=B5=8B=E8=AF=95shell=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index d3640ed..e1efb5b 100644 --- a/main.go +++ b/main.go @@ -105,6 +105,10 @@ func JWTAuthMiddleware() gin.HandlerFunc { if tokenString == "" { tokenString = c.Query("token") } + //测试 + if strings.Contains(c.Request.URL.Path, "/shell/") { + log.Printf("req token:%s ,path:%s", tokenString, c.Request.URL.Path) + } //如果请求为login或register,则不需要验证token for k, _ := range proto.Url_map { @@ -134,10 +138,6 @@ func JWTAuthMiddleware() gin.HandlerFunc { return } } - //测试 - if strings.Contains(c.Request.URL.Path, "/shell/") { - log.Printf("req token:%s ,path:%s", tokenString, c.Request.URL.Path) - } //查看token是否在超级token中 if worker.IsContainSet("super_permission_tokens", tokenString) { From af83caeaa46abc686bca45707a9af477c5bb9580 Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Wed, 5 Mar 2025 19:59:40 +0800 Subject: [PATCH 10/10] =?UTF-8?q?header=E5=8A=A0token?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 5 ----- worker/req.go | 2 ++ 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index e1efb5b..c699a85 100644 --- a/main.go +++ b/main.go @@ -105,11 +105,6 @@ func JWTAuthMiddleware() gin.HandlerFunc { if tokenString == "" { tokenString = c.Query("token") } - //测试 - if strings.Contains(c.Request.URL.Path, "/shell/") { - log.Printf("req token:%s ,path:%s", tokenString, c.Request.URL.Path) - } - //如果请求为login或register,则不需要验证token for k, _ := range proto.Url_map { if strings.Contains(c.Request.URL.Path, k) { diff --git a/worker/req.go b/worker/req.go index 85b707e..56615cb 100644 --- a/worker/req.go +++ b/worker/req.go @@ -211,6 +211,7 @@ func SyncDataFromMasterShellReq2(url string, data proto.SyncUserShellReq) ([]dao return res, err } req.Header.Set("Content-Type", "application/json") + req.Header.Set("token", data.Token) //传输数据 if client == nil { client = &http.Client{} @@ -254,6 +255,7 @@ func SyncDataFromMasterShellReq3(url string, data proto.SyncUserShellResp) ([]pr return res, err } req.Header.Set("Content-Type", "application/json") + req.Header.Set("token", data.Token) //传输数据 if client == nil { client = &http.Client{}