diff options
author | FChannel <> | 2022-06-16 17:05:28 -0700 |
---|---|---|
committer | FChannel <> | 2022-06-19 12:53:29 -0700 |
commit | 6237c9ac3213d2efed516c56881474dcaa508935 (patch) | |
tree | 9cc58d1a3d6f6ac33f7f0eec39d375d018578c97 | |
parent | bc096c388bb0beeee09fa866a55ea1fbb41b9cb6 (diff) |
javascript free reporting
-rw-r--r-- | main.go | 3 | ||||
-rw-r--r-- | route/routes/boardmgmt.go | 78 | ||||
-rw-r--r-- | views/css/themes/default.css | 11 | ||||
-rw-r--r-- | views/css/themes/gruvbox.css | 9 | ||||
-rw-r--r-- | views/partials/posts.html | 4 | ||||
-rw-r--r-- | views/report.html | 29 |
6 files changed, 113 insertions, 21 deletions
@@ -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 @@ <span class="subject"><b>{{ .Name }}</b></span> <span class="name"><b>{{ if .AttributedTo }} {{.AttributedTo }} {{ else }} Anonymous {{ end }}</b></span> <span class="tripcode"> {{ .TripCode }} </span> - <span class="timestamp" data-utc="{{.Published | timeToUnix}}">{{ .Published | timeToReadableLong }} <a id="{{ .Id }}-anchor" href="/{{ $board.Name }}/{{ shortURL $board.Actor.Outbox $opId }}">No.</a> <a id="{{ .Id }}-link" title="{{ .Id }}" {{ if eq .Type "Note" }} href="javascript:quote('{{ $board.Actor.Id }}', '{{ $opId }}', '{{ .Id }}')" {{ end }}>{{ shortURL $board.Actor.Outbox .Id }}</a> {{ if ne .Type "Tombstone" }}[<a href="javascript:report('{{ $board.Actor.Id }}', '{{ .Id }}')">Report</a>]{{ end }}</span> + <span class="timestamp" data-utc="{{.Published | timeToUnix}}">{{ .Published | timeToReadableLong }} <a id="{{ .Id }}-anchor" href="/{{ $board.Name }}/{{ shortURL $board.Actor.Outbox $opId }}">No.</a> <a id="{{ .Id }}-link" title="{{ .Id }}" {{ if eq .Type "Note" }} href="javascript:quote('{{ $board.Actor.Id }}', '{{ $opId }}', '{{ .Id }}')" {{ end }}>{{ shortURL $board.Actor.Outbox .Id }}</a> {{ if ne .Type "Tombstone" }}[<a href="/make-report?actor={{ $board.Actor.Id }}&post={{ .Id }}">Report</a>]{{ end }}</span> <p id="{{ .Id }}-content" style="white-space: pre-wrap; margin: 10px 30px 10px 30px;">{{ parseContent $board.Actor $opId .Content $thread .Id $page.PostType }}</p> {{ if .Replies }} {{ $replies := .Replies }} @@ -103,7 +103,7 @@ <span class="subject"><b>{{ .Name }}</b></span> <span class="name"><b>{{ if .AttributedTo }} {{.AttributedTo }} {{ else }} Anonymous {{ end }}</b></span> <span class="tripcode"> {{ .TripCode }} </span> - <span class="timestamp" data-utc="{{ .Published | timeToUnix }}">{{ .Published | timeToReadableLong }} <a id="{{ .Id }}-anchor" href="/{{ $board.Name }}/{{ shortURL $board.Actor.Outbox $opId }}#{{ shortURL $board.Actor.Outbox .Id }}">No. </a><a id="{{ .Id }}-link" title="{{ .Id }}" {{ if eq .Type "Note" }} href="javascript:quote('{{ $board.Actor.Id }}', '{{ $opId }}', '{{ .Id }}')" {{ end }}>{{ shortURL $board.Actor.Outbox .Id }}</a> {{ if ne .Type "Tombstone" }}[<a href="javascript:report('{{ $board.Actor.Id }}', '{{ .Id }}')">Report</a>]{{ end }}</span> + <span class="timestamp" data-utc="{{ .Published | timeToUnix }}">{{ .Published | timeToReadableLong }} <a id="{{ .Id }}-anchor" href="/{{ $board.Name }}/{{ shortURL $board.Actor.Outbox $opId }}#{{ shortURL $board.Actor.Outbox .Id }}">No. </a><a id="{{ .Id }}-link" title="{{ .Id }}" {{ if eq .Type "Note" }} href="javascript:quote('{{ $board.Actor.Id }}', '{{ $opId }}', '{{ .Id }}')" {{ end }}>{{ shortURL $board.Actor.Outbox .Id }}</a> {{ if ne .Type "Tombstone" }}[<a href="/make-report?actor={{ $board.Actor.Id }}&post={{ .Id }}">Report</a>]{{ end }}</span> {{ $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 }} + +<div style="height: 500px; width: 420px; margin: 0 auto; margin-top:75px;"> + <a href="{{ .page.Board.Actor.Id }}/{{ shortURL .page.Board.Actor.Outbox .page.Board.InReplyTo }}">[Back]</a> + <div id="report-box"> + <div id="report-header" style="text-align: center; display: inline-block; z-index: 0;">Report Post No. {{ shortURL .page.Board.Actor.Outbox .page.Board.InReplyTo }}</div> + <form id="report-post" action="/report" method="post"> + <label for="comment">Reason:</label><br> + <textarea id="report-comment" name="comment" rows="12" cols="54" style="width: 396px;" maxlength="100" oninput="sessionStorage.setItem('element-report-comment', document.getElementById('report-comment').value)"></textarea> + <br> + <input id="report-submit" type="submit" value="Report" style="float: right;"> + <input type="hidden" id="report-inReplyTo-box" name="id" value="{{ .page.Board.InReplyTo }}"> + <input type="hidden" id="sendTo" name="sendTo" value="{{ .page.Board.To }}"> + <input type="hidden" id="boardName" name="board" value="{{ .page.Board.Name }}"> + <input type="hidden" name="close" value="0"> + <input type="hidden" id="captchaCode" name="captchaCode" value="{{ .page.Board.CaptchaCode }}"> + <div style="width: 202px; margin: 0 auto; padding-top: 12px;"> + <label for="captcha">Captcha:</label><br> + <input style="display: inline-block;" type="text" id="captcha" name="captcha" autocomplete="off"><br> + </div> + <div style="width: 230px; margin: 0 auto;"> + <img src="{{ .page.Board.Captcha }}"> + </div> + </form> + </div> +</div> + +{{ template "partials/footer" .page }} +{{ template "partials/general_scripts" .page }} |