From 58ed6ecdfb87369f3c91dc9cfe96d8941e14f9f3 Mon Sep 17 00:00:00 2001 From: bouncepaw Date: Thu, 18 Feb 2021 19:50:37 +0500 Subject: [PATCH] Add /admin/shutdown --- main.go | 11 +++++++++++ user/user.go | 1 + 2 files changed, 12 insertions(+) diff --git a/main.go b/main.go index 00e5346..a19fd18 100644 --- a/main.go +++ b/main.go @@ -75,6 +75,14 @@ func handlerReindex(w http.ResponseWriter, rq *http.Request) { http.Redirect(w, rq, "/", http.StatusSeeOther) } +// Stop the wiki +func handlerAdminShutdown(w http.ResponseWriter, rq *http.Request) { + log.Println(rq.URL) + if user.CanProceed(rq, "admin/shutdown") { + log.Fatal("An admin commanded the wiki to shutdown") + } +} + // Update header links by reading the configured hypha, if there is any, or resorting to default values. func handlerUpdateHeaderLinks(w http.ResponseWriter, rq *http.Request) { log.Println(rq.URL) @@ -195,6 +203,9 @@ func main() { }) http.HandleFunc("/static/common.css", handlerStyle) http.HandleFunc("/static/icon/", handlerIcon) + if user.AuthUsed { + http.HandleFunc("/admin/shutdown", handlerAdminShutdown) + } http.HandleFunc("/", func(w http.ResponseWriter, rq *http.Request) { http.Redirect(w, rq, "/hypha/"+util.HomePage, http.StatusSeeOther) }) diff --git a/user/user.go b/user/user.go index efc0028..aa7a74c 100644 --- a/user/user.go +++ b/user/user.go @@ -26,6 +26,7 @@ var minimalRights = map[string]int{ "delete-ask": 3, "delete-confirm": 3, "reindex": 4, + "admin/shutdown": 4, } // Group — Right