mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-10 18:05:48 +02:00
feat: add ip whitelist
This commit is contained in:
parent
7a9aa3a33b
commit
3b937ee0f4
17 changed files with 1026 additions and 927 deletions
25
router/ip.go
Normal file
25
router/ip.go
Normal file
|
@ -0,0 +1,25 @@
|
|||
package router
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/settings"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/samber/lo"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func ipWhiteList() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
clientIP := c.ClientIP()
|
||||
if len(settings.AuthSettings.IPWhiteList) == 0 || clientIP == "127.0.0.1" {
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
|
||||
if !lo.Contains(settings.AuthSettings.IPWhiteList, clientIP) {
|
||||
c.AbortWithStatus(http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
||||
c.Next()
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@ import (
|
|||
"encoding/base64"
|
||||
"github.com/0xJacky/Nginx-UI/app"
|
||||
"github.com/0xJacky/Nginx-UI/internal/logger"
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/0xJacky/Nginx-UI/internal/user"
|
||||
"github.com/0xJacky/Nginx-UI/settings"
|
||||
"github.com/gin-contrib/static"
|
||||
"github.com/gin-gonic/gin"
|
||||
|
@ -58,7 +58,7 @@ func authRequired() gin.HandlerFunc {
|
|||
}
|
||||
}
|
||||
|
||||
if model.CheckToken(token) < 1 {
|
||||
if user.CheckToken(token) < 1 {
|
||||
abortWithAuthFailure()
|
||||
return
|
||||
}
|
||||
|
|
|
@ -23,10 +23,9 @@ import (
|
|||
func InitRouter() *gin.Engine {
|
||||
r := gin.New()
|
||||
r.Use(gin.Logger())
|
||||
|
||||
r.Use(recovery())
|
||||
|
||||
r.Use(cacheJs())
|
||||
r.Use(ipWhiteList())
|
||||
|
||||
//r.Use(OperationSync())
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue