mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-10 18:05:48 +02:00
feat: 2FA authorization for web terminal
This commit is contained in:
parent
802d05f692
commit
3a22861640
15 changed files with 359 additions and 54 deletions
|
@ -5,6 +5,7 @@ import (
|
|||
"github.com/0xJacky/Nginx-UI/app"
|
||||
"github.com/0xJacky/Nginx-UI/internal/logger"
|
||||
"github.com/0xJacky/Nginx-UI/internal/user"
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/0xJacky/Nginx-UI/settings"
|
||||
"github.com/gin-contrib/static"
|
||||
"github.com/gin-gonic/gin"
|
||||
|
@ -74,6 +75,41 @@ func authRequired() gin.HandlerFunc {
|
|||
}
|
||||
}
|
||||
|
||||
func required2FA() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
u, ok := c.Get("user")
|
||||
if !ok {
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
cUser := u.(*model.Auth)
|
||||
if !cUser.EnabledOTP() {
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
ssid := c.GetHeader("X-Secure-Session-ID")
|
||||
if ssid == "" {
|
||||
ssid = c.Query("X-Secure-Session-ID")
|
||||
}
|
||||
if ssid == "" {
|
||||
c.AbortWithStatusJSON(http.StatusForbidden, gin.H{
|
||||
"message": "Secure Session ID is empty",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if user.VerifySecureSessionID(ssid, cUser.ID) {
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
|
||||
c.AbortWithStatusJSON(http.StatusForbidden, gin.H{
|
||||
"message": "Secure Session ID is invalid",
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
type serverFileSystemType struct {
|
||||
http.FileSystem
|
||||
}
|
||||
|
|
|
@ -69,7 +69,10 @@ func InitRouter() *gin.Engine {
|
|||
{
|
||||
analytic.InitWebSocketRouter(w)
|
||||
certificate.InitCertificateWebSocketRouter(w)
|
||||
terminal.InitRouter(w)
|
||||
o := w.Group("", required2FA())
|
||||
{
|
||||
terminal.InitRouter(o)
|
||||
}
|
||||
nginx.InitNginxLogRouter(w)
|
||||
upstream.InitRouter(w)
|
||||
system.InitWebSocketRouter(w)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue