Implement control panel

This commit is contained in:
Pijus Kamandulis
2025-07-04 21:23:21 +03:00
parent ef247fc843
commit effe887b3b
3 changed files with 64 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
package web
import (
"net/http"
"pool-stats/database"
)
type ControlPanelPageData struct {
PageDataBase
Message string
}
func (ws *WebServer) ControlPanelHandler(w http.ResponseWriter, r *http.Request) {
username := ws.getUser(r)
if username == "" {
http.Error(w, "Unauthorized", http.StatusUnauthorized)
return
}
data := ControlPanelPageData{}
action := r.URL.Query().Get("action")
if action != "" {
data.Message = ws.executeAction(action)
}
ws.renderTemplate(w, r, "templates/cp.html", &data)
}
func (ws *WebServer) executeAction(action string) string {
switch action {
case "ClearDailyStats":
database.ClearDailyStats(ws.db)
return "Daily stats cleared successfully"
default:
return "Unknown action"
}
}