Implement control panel
This commit is contained in:
parent
ef247fc843
commit
effe887b3b
24
templates/cp.html
Normal file
24
templates/cp.html
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
{{ define "title" }}Control Panel{{ end }} {{ define "header" }}⚙️ Control
|
||||||
|
Panel{{ end }} {{ define "content" }}
|
||||||
|
|
||||||
|
<div>
|
||||||
|
{{ if .Message }}
|
||||||
|
<strong>Info:</strong> {{ .Message }} {{ end }}
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Action</th>
|
||||||
|
<th>Description</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td><a href="/cp?action=ClearDailyStats">Clear Daily Stats</a></td>
|
||||||
|
<td>Clear Daily Stats cache</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{ end }} {{ template "layout" . }}
|
39
web/controlPanelHandler.go
Normal file
39
web/controlPanelHandler.go
Normal 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"
|
||||||
|
}
|
||||||
|
}
|
@ -44,6 +44,7 @@ func NewWebServer(db *clover.DB, port int, adminPassword string) *WebServer {
|
|||||||
|
|
||||||
func (ws *WebServer) Start() error {
|
func (ws *WebServer) Start() error {
|
||||||
http.HandleFunc("/", ws.IndexHandler)
|
http.HandleFunc("/", ws.IndexHandler)
|
||||||
|
http.HandleFunc("/cp", ws.ControlPanelHandler)
|
||||||
http.HandleFunc("/login", ws.LoginHandler)
|
http.HandleFunc("/login", ws.LoginHandler)
|
||||||
http.HandleFunc("/logout", ws.LogoutHandler)
|
http.HandleFunc("/logout", ws.LogoutHandler)
|
||||||
http.HandleFunc("/shares", ws.SharesHandler)
|
http.HandleFunc("/shares", ws.SharesHandler)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user