Kaynağa Gözat

调试功能:token设置

zou.yingbin 4 yıl önce
ebeveyn
işleme
7feb4ae559

+ 2 - 0
controllers/other/logfilelist.go

@@ -37,6 +37,8 @@ git hash: {{.githash}}<br>
 oracle : {{.db}} <br>
 mysql  : {{.mysql}} <br>
 redis  : {{.redis}} <br>
+<br>
+<a href="{{.host}}/debug/token" title="仅当调试模式内网段才能成功设置" target="_blank">点击设置token</a>
 <h1>日志文件列表</h1>
 <p>------------------------</p>
 {{.data}}

+ 29 - 0
controllers/other/settoken.go

@@ -0,0 +1,29 @@
+/**
+* @Author: zou.yingbin
+* @Create  : 2021/10/27 10:22
+* @Modify  : 2021/10/27 10:22
+ */
+
+package other
+
+import (
+	"github.com/gin-gonic/gin"
+	"mtp2_if/rediscli"
+	"net/http"
+	"strings"
+)
+
+// SetToken 设置调试token
+func SetToken(c *gin.Context) {
+	host := c.Request.Host
+	if strings.Contains(host, `192.168.`) || strings.Contains(host, `localhost`) {
+		if cli := rediscli.GetRedisClient(); cli != nil {
+			_ = cli.HSet("\"monitor:online_loginid:778899:1\"", "Token", "778899_123456_1")
+			c.String(http.StatusOK, `设置成功!(仅当内网且调试模式下才可设置), token:778899_123456_1`)
+		} else {
+			c.String(http.StatusOK, "not connect redis")
+		}
+	} else {
+		c.String(http.StatusOK, "not support!")
+	}
+}

+ 1 - 0
routers/router.go

@@ -57,6 +57,7 @@ func InitRouter() *gin.Engine {
 		r.GET("/debug/log/view", other.LogView)
 		r.GET("/debug/download", other.DownloadFile)
 		r.GET("/debug/update", other.MakeUpdateScript)
+		r.GET("/debug/token", other.SetToken)
 	}
 	// 终端配置
 	r.GET("/cfg", cfg.QueryCfg)