From effe887b3b5952f862037661e7be7613fc8df075 Mon Sep 17 00:00:00 2001 From: Pijus Kamandulis Date: Fri, 4 Jul 2025 21:23:21 +0300 Subject: [PATCH] Implement control panel --- templates/cp.html | 24 +++++++++++++++++++++++ web/controlPanelHandler.go | 39 ++++++++++++++++++++++++++++++++++++++ web/server.go | 1 + 3 files changed, 64 insertions(+) create mode 100644 templates/cp.html create mode 100644 web/controlPanelHandler.go diff --git a/templates/cp.html b/templates/cp.html new file mode 100644 index 0000000..cfdc0c8 --- /dev/null +++ b/templates/cp.html @@ -0,0 +1,24 @@ +{{ define "title" }}Control Panel{{ end }} {{ define "header" }}⚙️ Control +Panel{{ end }} {{ define "content" }} + +
+ {{ if .Message }} + Info: {{ .Message }} {{ end }} + + + + + + + + + + + + + + +
ActionDescription
Clear Daily StatsClear Daily Stats cache
+
+ +{{ end }} {{ template "layout" . }} diff --git a/web/controlPanelHandler.go b/web/controlPanelHandler.go new file mode 100644 index 0000000..ef4d9f6 --- /dev/null +++ b/web/controlPanelHandler.go @@ -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" + } +} diff --git a/web/server.go b/web/server.go index 3c785de..507799f 100644 --- a/web/server.go +++ b/web/server.go @@ -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)