mirror of
https://github.com/komari-monitor/komari.git
synced 2026-11-24 09:05:49 +00:00
Relocate API routing, OAuth, and Nezha compatibility wiring into the web package to keep server startup focused on initialization concerns and improve code organization.
51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
package admin
|
|
|
|
import (
|
|
"github.com/komari-monitor/komari/web/api"
|
|
"github.com/komari-monitor/komari/database/accounts"
|
|
"github.com/komari-monitor/komari/database/auditlog"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func GetSessions(c *gin.Context) {
|
|
|
|
ss, err := accounts.GetAllSessions()
|
|
if err != nil {
|
|
api.RespondError(c, 500, "Failed to retrieve sessions: "+err.Error())
|
|
return
|
|
}
|
|
current, _ := c.Cookie("session_token")
|
|
c.JSON(200, gin.H{"status": "success", "current": current, "data": ss})
|
|
}
|
|
|
|
func DeleteSession(c *gin.Context) {
|
|
var req struct {
|
|
Session string `json:"session" binding:"required"`
|
|
}
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
api.RespondError(c, 400, "Invalid request: "+err.Error())
|
|
return
|
|
}
|
|
err := accounts.DeleteSession(req.Session)
|
|
if err != nil {
|
|
api.RespondError(c, 500, "Failed to delete session: "+err.Error())
|
|
return
|
|
}
|
|
uuid, _ := c.Get("uuid")
|
|
auditlog.Log(c.ClientIP(), uuid.(string), "delete session", "info")
|
|
api.RespondSuccess(c, nil)
|
|
}
|
|
|
|
func DeleteAllSession(c *gin.Context) {
|
|
|
|
err := accounts.DeleteAllSessions()
|
|
if err != nil {
|
|
api.RespondError(c, 500, "Failed to delete all sessions: "+err.Error())
|
|
return
|
|
}
|
|
uuid, _ := c.Get("uuid")
|
|
auditlog.Log(c.ClientIP(), uuid.(string), "delete all sessions", "warn")
|
|
api.RespondSuccess(c, nil)
|
|
}
|