From 6237c9ac3213d2efed516c56881474dcaa508935 Mon Sep 17 00:00:00 2001 From: FChannel <> Date: Thu, 16 Jun 2022 17:05:28 -0700 Subject: javascript free reporting --- main.go | 3 +- route/routes/boardmgmt.go | 78 +++++++++++++++++++++++++++++++++++--------- views/css/themes/default.css | 11 +++++-- views/css/themes/gruvbox.css | 9 ++++- views/partials/posts.html | 4 +-- views/report.html | 29 ++++++++++++++++ 6 files changed, 113 insertions(+), 21 deletions(-) create mode 100644 views/report.html diff --git a/main.go b/main.go index b570102..e472762 100644 --- a/main.go +++ b/main.go @@ -84,7 +84,8 @@ func main() { app.Get("/poparchive", routes.BoardPopArchive) app.Get("/autosubscribe", routes.BoardAutoSubscribe) app.All("/blacklist", routes.BoardBlacklist) - app.All("/report", routes.BoardReport) + app.All("/report", routes.ReportPost) + app.Get("/make-report", routes.ReportGet) // Webfinger routes app.Get("/.well-known/webfinger", routes.Webfinger) diff --git a/route/routes/boardmgmt.go b/route/routes/boardmgmt.go index b1770f3..5f24cdd 100644 --- a/route/routes/boardmgmt.go +++ b/route/routes/boardmgmt.go @@ -6,9 +6,13 @@ import ( "os" "regexp" "strconv" + "strings" "github.com/FChannel0/FChannel-Server/activitypub" "github.com/FChannel0/FChannel-Server/config" + "github.com/FChannel0/FChannel-Server/route" + "github.com/FChannel0/FChannel-Server/webfinger" + "github.com/FChannel0/FChannel-Server/db" "github.com/FChannel0/FChannel-Server/post" "github.com/FChannel0/FChannel-Server/util" @@ -437,7 +441,7 @@ func BoardBlacklist(ctx *fiber.Ctx) error { return ctx.Redirect("/"+config.Key+"#regex", http.StatusSeeOther) } -func BoardReport(ctx *fiber.Ctx) error { +func ReportPost(ctx *fiber.Ctx) error { id := ctx.FormValue("id") board := ctx.FormValue("board") reason := ctx.FormValue("comment") @@ -450,20 +454,6 @@ func BoardReport(ctx *fiber.Ctx) error { } _, auth := util.GetPasswordFromSession(ctx) - var captcha = ctx.FormValue("captchaCode") + ":" + ctx.FormValue("captcha") - - if len(reason) > 100 { - return ctx.Status(403).Render("403", fiber.Map{ - "message": "Report comment limit 100 characters", - }) - } - - if ok, _ := post.CheckCaptcha(captcha); !ok && close != "1" { - return ctx.Status(403).Render("403", fiber.Map{ - "message": "Invalid captcha", - }) - } - var obj = activitypub.ObjectBase{Id: id} if close == "1" { @@ -506,6 +496,26 @@ func BoardReport(ctx *fiber.Ctx) error { return ctx.Redirect("/"+board+"/"+util.RemoteShort(obj.Id), http.StatusSeeOther) } + var captcha = ctx.FormValue("captchaCode") + ":" + ctx.FormValue("captcha") + + if len(reason) > 100 { + return ctx.Status(403).Render("403", fiber.Map{ + "message": "Report comment limit 100 characters", + }) + } + + if len(strings.TrimSpace(reason)) == 0 { + return ctx.Status(403).Render("403", fiber.Map{ + "message": "Report reason required", + }) + } + + if ok, _ := post.CheckCaptcha(captcha); !ok && close != "1" { + return ctx.Status(403).Render("403", fiber.Map{ + "message": "Invalid captcha", + }) + } + if err := db.CreateLocalReport(obj.Id, board, reason); err != nil { config.Log.Println(err) return ctx.Status(404).Render("404", fiber.Map{ @@ -515,3 +525,41 @@ func BoardReport(ctx *fiber.Ctx) error { return ctx.Redirect(id, http.StatusSeeOther) } + +func ReportGet(ctx *fiber.Ctx) error { + actor, _ := activitypub.GetActor(ctx.Query("actor")) + + var data route.PageData + data.Board.Actor = actor + data.Board.Name = actor.Name + data.Board.PrefName = actor.PreferredUsername + data.Board.Summary = actor.Summary + data.Board.InReplyTo = ctx.Query("post") + data.Board.To = actor.Outbox + data.Board.Restricted = actor.Restricted + + capt, err := util.GetRandomCaptcha() + + if err != nil { + return util.MakeError(err, "OutboxGet") + } + + data.Board.Captcha = config.Domain + "/" + capt + data.Board.CaptchaCode = post.GetCaptchaCode(data.Board.Captcha) + + data.Meta.Description = data.Board.Summary + data.Meta.Url = data.Board.Actor.Id + data.Meta.Title = data.Title + + data.Instance, err = activitypub.GetActorFromDB(config.Domain) + + data.Themes = &config.Themes + data.ThemeCookie = route.GetThemeCookie(ctx) + + data.Key = config.Key + data.Board.ModCred, _ = util.GetPasswordFromSession(ctx) + data.Board.Domain = config.Domain + data.Boards = webfinger.Boards + + return ctx.Render("report", fiber.Map{"page": data}, "layouts/main") +} diff --git a/views/css/themes/default.css b/views/css/themes/default.css index 488ba4f..3201975 100644 --- a/views/css/themes/default.css +++ b/views/css/themes/default.css @@ -24,12 +24,12 @@ h1, h2, h3, h4, h5, h6 { color: #af0a0f; } -.popup-box { +.popup-box, #report-box { border: 4px solid #d3caf0; background-color: #eff5ff; } -.nsfw .popup-box { +.nsfw .popup-box, .nsfw #report-box { border: 4px solid #f0e2d9; background-color: #f9f9e0; } @@ -160,6 +160,13 @@ a.reply { display: block; } +#report-box { + min-width: 300px; + width: min-content; + z-index: 9; + display: block; +} + /* TODO: rename */ .box2 { border: 4px solid #f0e2d9; diff --git a/views/css/themes/gruvbox.css b/views/css/themes/gruvbox.css index 788b2b6..a4474ce 100644 --- a/views/css/themes/gruvbox.css +++ b/views/css/themes/gruvbox.css @@ -20,7 +20,7 @@ body { font-size: 0.9em; } -.popup-box { +.popup-box, #report-box { border: 4px solid #928374; background-color: #3c3836; } @@ -141,6 +141,13 @@ input[type="text"] { display: block; } +#report-box { + min-width: 300px; + width: min-content; + z-index: 9; + display: block; +} + /* TODO: rename */ .box2 { border: 4px solid #928374; diff --git a/views/partials/posts.html b/views/partials/posts.html index d57a199..6fe2d2d 100644 --- a/views/partials/posts.html +++ b/views/partials/posts.html @@ -48,7 +48,7 @@ {{ .Name }} {{ if .AttributedTo }} {{.AttributedTo }} {{ else }} Anonymous {{ end }} {{ .TripCode }} - +
{{ parseContent $board.Actor $opId .Content $thread .Id $page.PostType }}
{{ if .Replies }} {{ $replies := .Replies }} @@ -103,7 +103,7 @@ {{ .Name }} {{ if .AttributedTo }} {{.AttributedTo }} {{ else }} Anonymous {{ end }} {{ .TripCode }} - + {{ $parentId := .Id }} {{ if .Replies.OrderedItems }} {{ range .Replies.OrderedItems }} diff --git a/views/report.html b/views/report.html new file mode 100644 index 0000000..d691349 --- /dev/null +++ b/views/report.html @@ -0,0 +1,29 @@ +{{ template "partials/top" .page }} + +