diff --git a/http/admin/handler.go b/http/admin/handler.go index 6555551..763e4b4 100644 --- a/http/admin/handler.go +++ b/http/admin/handler.go @@ -56,6 +56,7 @@ func AdminRouter(r chi.Router) { r.Post("/new_admin.sh", handleNewAdmin) r.Post("/del_admin.sh", handleDelAdmin) r.Get("/status.sh", serveStatus) + r.Post("/set_rules.sh", handleSetRules) } // Router sets up moderation functions diff --git a/http/admin/newboard.go b/http/admin/newboard.go index ef707bd..4a55f7a 100644 --- a/http/admin/newboard.go +++ b/http/admin/newboard.go @@ -24,7 +24,9 @@ func handleNewBoard(w http.ResponseWriter, r *http.Request) { } db := middle.GetDB(r) - var board = &resources.Board{} + var board = &resources.Board{ + Metadata: map[string]string{}, + } board.ShortName = r.FormValue("shortname") board.LongName = r.FormValue("longname") @@ -34,7 +36,7 @@ func handleNewBoard(w http.ResponseWriter, r *http.Request) { return } - if board.ShortName == "admin" || board.ShortName == "@" || board.ShortName == "mod"{ + if board.ShortName == "admin" || board.ShortName == "@" || board.ShortName == "mod" { errw.ErrorWriter(errors.New("No"), w, r) } diff --git a/http/admin/res/panel.html b/http/admin/res/panel.html index 4721d13..1bbd2f8 100644 --- a/http/admin/res/panel.html +++ b/http/admin/res/panel.html @@ -21,7 +21,7 @@

-
+ @@ -65,7 +65,7 @@

- +
@@ -117,7 +117,7 @@

- +
@@ -157,7 +157,7 @@

- +
@@ -184,5 +184,57 @@

+
+
+
+ + + + + + + + + + + + + + + + + + +
+ Action + + Set Board Rules + +
+ Board Name (Short) + + +
+ Rules + + +
+ + +
+ +
+

\ No newline at end of file diff --git a/http/admin/setboardrules.go b/http/admin/setboardrules.go new file mode 100644 index 0000000..31ab947 --- /dev/null +++ b/http/admin/setboardrules.go @@ -0,0 +1,42 @@ +package admin + +import ( + "github.com/tidwall/buntdb" + "go.rls.moe/nyx/http/errw" + "go.rls.moe/nyx/http/middle" + "go.rls.moe/nyx/resources" + "net/http" +) + +func handleSetRules(w http.ResponseWriter, r *http.Request) { + sess := middle.GetSession(r) + if !middle.IsAdminSession(sess) { + w.WriteHeader(http.StatusUnauthorized) + w.Write([]byte("Unauthorized")) + return + } + + err := r.ParseForm() + if err != nil { + errw.ErrorWriter(err, w, r) + return + } + db := middle.GetDB(r) + + boardName := r.FormValue("shortname") + rules := r.FormValue("rules") + + if err = db.Update(func(tx *buntdb.Tx) error { + board, err := resources.GetBoard(tx, r.Host, boardName) + if err != nil { + return err + } + board.Metadata["rules"] = rules + return resources.UpdateBoard(tx, r.Host, board) + }); err != nil { + errw.ErrorWriter(err, w, r) + return + } + + http.Redirect(w, r, "/admin/panel.html", http.StatusSeeOther) +} diff --git a/http/board/newthread.go b/http/board/newthread.go index 686b789..02031a8 100644 --- a/http/board/newthread.go +++ b/http/board/newthread.go @@ -34,6 +34,7 @@ func handleNewThread(w http.ResponseWriter, r *http.Request) { var mainReply = &resources.Reply{} thread.Board = chi.URLParam(r, "board") + thread.Metadata = map[string]string{} err = parseReply(r, mainReply) if err == trollThrottle { diff --git a/http/board/res/thread.tmpl.html b/http/board/res/thread.tmpl.html index 0599cf3..19c11da 100644 --- a/http/board/res/thread.tmpl.html +++ b/http/board/res/thread.tmpl.html @@ -103,6 +103,16 @@ + {{ if .Board.Metadata.rules }} + + + Rules + + + {{ renderText .Board.Metadata.rules }} + + + {{ end }}