mirror of
https://github.com/komari-monitor/komari.git
synced 2025-11-13 18:36:10 +00:00
- 添加用户认证和权限控制 - 实现客户端管理功能,包括添加、编辑和删除客户端 - 支持客户端上传基础信息和监控报告 - 提供基本的自定义配置功能 - 实现数据库初始化和数据存储
31 lines
563 B
Go
31 lines
563 B
Go
package api
|
|
|
|
import (
|
|
"komari/database"
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func AdminAuthMiddleware() gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
|
|
session, err := c.Cookie("session_token")
|
|
if err != nil {
|
|
c.JSON(http.StatusUnauthorized, gin.H{"status": "error", "error": "Unauthorized"})
|
|
c.Abort()
|
|
return
|
|
}
|
|
|
|
// Komari is a single user system
|
|
_, err = database.GetSession(session)
|
|
if err != nil {
|
|
c.JSON(http.StatusUnauthorized, gin.H{"status": "error", "error": "Unauthorized."})
|
|
c.Abort()
|
|
return
|
|
}
|
|
|
|
c.Next()
|
|
}
|
|
}
|