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"
}
}

View File

@@ -44,6 +44,7 @@ func NewWebServer(db *clover.DB, port int, adminPassword string) *WebServer {
func (ws *WebServer) Start() error {
http.HandleFunc("/", ws.IndexHandler)
http.HandleFunc("/cp", ws.ControlPanelHandler)
http.HandleFunc("/login", ws.LoginHandler)
http.HandleFunc("/logout", ws.LogoutHandler)
http.HandleFunc("/shares", ws.SharesHandler)