add: gm http server auth key
This commit is contained in:
1 parent
bea91fbf73
commit
0cbaa27b74
4 files changed
+5
-27
No files matched your search
@@ -1,5 +1,8 @@
|
||||
http_port = 9001
|
||||
|
||||
[hk4e]
|
||||
gm_auth_key = "flswld" # gm认证密钥
|
||||
|
||||
[logger]
|
||||
level = "DEBUG"
|
||||
mode = "CONSOLE"
|
||||
|
||||
@@ -54,6 +54,7 @@ type Hk4e struct {
|
||||
DispatchUrl string `toml:"dispatch_url"` // 二级dispatch地址 将域名改为dispatch的外网地址
|
||||
ForwardRegionUrl string `toml:"forward_region_url"` // 转发的一级dispatch地址
|
||||
ForwardDispatchUrl string `toml:"forward_dispatch_url"` // 转发的二级dispatch地址
|
||||
GmAuthKey string `toml:"gm_auth_key"` // gm认证密钥
|
||||
}
|
||||
|
||||
// Hk4eRobot 原神机器人
|
||||
|
||||
@@ -2,7 +2,6 @@ package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"sync"
|
||||
@@ -69,30 +68,6 @@ func NewController(db *dao.Dao, discovery *rpc.DiscoveryClient, messageQueue *mq
|
||||
return r
|
||||
}
|
||||
|
||||
func (c *Controller) authorize() gin.HandlerFunc {
|
||||
return func(context *gin.Context) {
|
||||
addr := context.ClientIP()
|
||||
if addr == "" {
|
||||
addr = context.Request.RemoteAddr
|
||||
}
|
||||
ip := net.ParseIP(addr)
|
||||
ipv4 := ip.To4()
|
||||
if ip.IsLoopback() ||
|
||||
ipv4[0] == 10 ||
|
||||
ipv4[0] == 169 && ipv4[1] == 254 ||
|
||||
ipv4[0] == 172 && ipv4[1] >= 16 && ipv4[1] <= 31 ||
|
||||
ipv4[0] == 192 && ipv4[1] == 168 {
|
||||
context.Next()
|
||||
return
|
||||
}
|
||||
context.Abort()
|
||||
context.JSON(http.StatusOK, gin.H{
|
||||
"code": "10001",
|
||||
"msg": "没有访问权限",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Controller) registerRouter() {
|
||||
if config.GetConfig().Logger.Level == "DEBUG" {
|
||||
gin.SetMode(gin.DebugMode)
|
||||
@@ -186,7 +161,6 @@ func (c *Controller) registerRouter() {
|
||||
engine.StaticFS("/static", http.Dir("./static/geetest/static"))
|
||||
engine.StaticFS("/pictures", http.Dir("./static/geetest/pictures"))
|
||||
}
|
||||
engine.Use(c.authorize())
|
||||
engine.POST("/gate/token/verify", c.gateTokenVerify)
|
||||
port := config.GetConfig().HttpPort
|
||||
addr := ":" + strconv.Itoa(int(port))
|
||||
|
||||
@@ -71,7 +71,7 @@ func (c *Controller) syncGlobalGsOnlineMap() {
|
||||
|
||||
func (c *Controller) authorize() gin.HandlerFunc {
|
||||
return func(context *gin.Context) {
|
||||
if context.GetHeader("Auth") == "flswld" {
|
||||
if context.GetHeader("GmAuthKey") == config.GetConfig().Hk4e.GmAuthKey {
|
||||
// 验证通过
|
||||
context.Next()
|
||||
return
|
||||
|
||||
Reference in new issue
Block a user