mirror of
https://github.com/hanzoai/simple-coredns-manager.git
synced 2026-10-30 19:55:29 +00:00
Full-featured web UI for managing CoreDNS Corefile and host files with diff preview, Docker-based reload, and master password authentication. Built for MWIT-LINK infrastructure DNS management. Co-authored-by: Hanzo Dev <[email protected]>
34 lines
793 B
Go
34 lines
793 B
Go
package auth
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/golang-jwt/jwt/v5"
|
|
"github.com/labstack/echo/v4"
|
|
)
|
|
|
|
func Middleware(secret []byte) echo.MiddlewareFunc {
|
|
return func(next echo.HandlerFunc) echo.HandlerFunc {
|
|
return func(c echo.Context) error {
|
|
cookie, err := c.Cookie(CookieName)
|
|
if err != nil || cookie.Value == "" {
|
|
return c.Redirect(http.StatusSeeOther, "/login")
|
|
}
|
|
|
|
token, err := jwt.Parse(cookie.Value, func(t *jwt.Token) (interface{}, error) {
|
|
if _, ok := t.Method.(*jwt.SigningMethodHMAC); !ok {
|
|
return nil, jwt.ErrSignatureInvalid
|
|
}
|
|
return secret, nil
|
|
})
|
|
if err != nil || !token.Valid {
|
|
ClearCookie(c.Response().Writer)
|
|
return c.Redirect(http.StatusSeeOther, "/login")
|
|
}
|
|
|
|
c.Set("authenticated", true)
|
|
return next(c)
|
|
}
|
|
}
|
|
}
|