diff --git a/http/admin/handler.go b/http/admin/handler.go index f7ddb3b..b7bf3c9 100644 --- a/http/admin/handler.go +++ b/http/admin/handler.go @@ -2,6 +2,7 @@ package admin import ( "bytes" + "fmt" "github.com/GeertJohan/go.rice" "github.com/icza/session" "github.com/pressly/chi" @@ -11,6 +12,7 @@ import ( "go.rls.moe/nyx/resources" "html/template" "net/http" + "strconv" "time" ) @@ -43,7 +45,7 @@ func init() { // Router sets up the Administration Panel // It **must** be setup on the /admin/ basepath -func Router(r chi.Router) { +func AdminRouter(r chi.Router) { r.Get("/", serveLogin) r.Get("/index.html", serveLogin) r.Get("/panel.html", servePanel) @@ -52,6 +54,73 @@ func Router(r chi.Router) { r.Post("/logout.sh", handleLogout) } +// Router sets up moderation functions +// It **must** be setup on the /mod/ basepath +func ModRouter(r chi.Router) { + r.Post("/del_reply.sh", handleDelPost) +} + +func handleDelPost(w http.ResponseWriter, r *http.Request) { + sess := middle.GetSession(r) + if sess == nil { + w.WriteHeader(http.StatusUnauthorized) + w.Write([]byte("Unauthorized")) + return + } + if sess.CAttr("mode") != "admin" && sess.CAttr("mode") != "mod" { + w.WriteHeader(http.StatusUnauthorized) + w.Write([]byte("Unauthorized")) + return + } + + err := r.ParseForm() + if err != nil { + errw.ErrorWriter(err, w, r) + return + } + + rid, err := strconv.Atoi(r.FormValue("reply_id")) + if err != nil { + errw.ErrorWriter(err, w, r) + return + } + trid, err := strconv.Atoi(r.FormValue("thread_id")) + if err != nil { + errw.ErrorWriter(err, w, r) + return + } + board := r.FormValue("board") + + if sess.CAttr("mode") == "mod" && sess.CAttr("board") != board { + w.WriteHeader(http.StatusUnauthorized) + w.Write([]byte("Not on this board")) + return + } + + db := middle.GetDB(r) + + err = db.Update(func(tx *buntdb.Tx) error { + reply, err := resources.GetReply(tx, r.Host, board, trid, rid) + if err != nil { + return err + } + reply.Text = "[deleted]" + reply.Metadata["deleted"] = "yes" + err = resources.UpdateReply(tx, r.Host, board, reply) + if err != nil { + return err + } + return nil + }) + + if err != nil { + errw.ErrorWriter(err, w, r) + return + } + + http.Redirect(w, r, fmt.Sprintf("/%s/%d/thread.html", board, trid), http.StatusSeeOther) +} + func serveLogin(w http.ResponseWriter, r *http.Request) { dat := bytes.NewBuffer([]byte{}) err := loginTmpl.Execute(dat, middle.GetBaseCtx(r)) diff --git a/http/admin/newboard.go b/http/admin/newboard.go index ef981bc..58e7513 100644 --- a/http/admin/newboard.go +++ b/http/admin/newboard.go @@ -25,6 +25,7 @@ func handleNewBoard(w http.ResponseWriter, r *http.Request) { err := r.ParseForm() if err != nil { errw.ErrorWriter(err, w, r) + return } db := middle.GetDB(r) @@ -38,7 +39,7 @@ func handleNewBoard(w http.ResponseWriter, r *http.Request) { return } - if board.ShortName == "admin" && board.ShortName == "@" { + 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 048bdfe..1bf0804 100644 --- a/http/admin/res/panel.html +++ b/http/admin/res/panel.html @@ -31,27 +31,47 @@ -