From d46dc93dce176e8e2c054a1454c097123a08b4af Mon Sep 17 00:00:00 2001 From: FChannel <> Date: Wed, 12 May 2021 23:06:40 -0700 Subject: admin tripcode --- OutboxPost.go | 4 +--- client.go | 5 ++--- main.go | 25 +++++++++++++++++++++---- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/OutboxPost.go b/OutboxPost.go index cb0f988..fd87506 100644 --- a/OutboxPost.go +++ b/OutboxPost.go @@ -364,8 +364,7 @@ func ObjectFromForm(r *http.Request, db *sql.DB, obj ObjectBase) ObjectBase { obj.Preview = CreatePreviewObject(obj.Attachment[0]) } - obj.AttributedTo = CreateNameTripCode(r.FormValue("name")) - obj.AttributedTo = EscapeString(obj.AttributedTo) + obj.AttributedTo = EscapeString(r.FormValue("name")) obj.Name = EscapeString(r.FormValue("subject")) obj.Content = EscapeString(r.FormValue("comment")) @@ -382,7 +381,6 @@ func ObjectFromForm(r *http.Request, db *sql.DB, obj ObjectBase) ObjectBase { activity.To = append(activity.To, originalPost.Id) } - if originalPost.Id != "" { if !IsActivityLocal(db, activity) { id := GetActorFromID(originalPost.Id).Id diff --git a/client.go b/client.go index d31ba07..1ef6250 100644 --- a/client.go +++ b/client.go @@ -77,7 +77,7 @@ func IndexGet(w http.ResponseWriter, r *http.Request, db *sql.DB) { t := template.Must(template.ParseFiles("./static/main.html", "./static/index.html")) actor := GetActorFromDB(db, Domain) - + var data PageData data.Title = "Welcome to " + actor.PreferredUsername data.Message = fmt.Sprintf("%s is a federated image board based on activitypub. The current version of the code running the server is still a work in progress, expect a bumpy ride for the time being. Get the server code here https://github.com/FChannel0", Domain) @@ -149,7 +149,7 @@ func CatalogGet(w http.ResponseWriter, r *http.Request, db *sql.DB, collection C t := template.Must(template.ParseFiles("./static/main.html", "./static/ncatalog.html", "./static/top.html")) actor := collection.Actor - + var returnData PageData returnData.Board.Name = actor.Name returnData.Board.PrefName = actor.PreferredUsername @@ -191,7 +191,6 @@ func PostGet(w http.ResponseWriter, r *http.Request, db *sql.DB){ inReplyTo := actor.Id + "/" + postId var returnData PageData - returnData.Board.Name = actor.Name returnData.Board.PrefName = actor.PreferredUsername returnData.Board.To = actor.Outbox diff --git a/main.go b/main.go index 43ea539..c5229dc 100644 --- a/main.go +++ b/main.go @@ -289,6 +289,12 @@ func main() { return } + if(r.FormValue("inReplyTo") == "" && file == nil) { + w.Write([]byte("Media is required for new posts")) + return + } + + if(r.FormValue("inReplyTo") == "" || file == nil) { if(r.FormValue("comment") == "" && r.FormValue("subject") == ""){ w.Write([]byte("Comment or Subject required")) @@ -331,7 +337,10 @@ func main() { for key, r0 := range r.Form { if(key == "captcha") { err := we.WriteField(key, r.FormValue("captchaCode") + ":" + r.FormValue("captcha")) - CheckError(err, "error with writing field") + CheckError(err, "error with writing captcha field") + }else if(key == "name") { + err := we.WriteField(key, CreateNameTripCode(r)) + CheckError(err, "error with writing name field") }else{ err := we.WriteField(key, r0[0]) CheckError(err, "error with writing field") @@ -931,11 +940,19 @@ func CreateTripCode(input string) string { return code[0] } -func CreateNameTripCode(input string) string { +func CreateNameTripCode(r *http.Request) string { + input := r.FormValue("name") re := regexp.MustCompile("#.+") chunck := re.FindString(input) - hash := CreateTripCode(chunck) - return re.ReplaceAllString(input, "!" + hash[42:50]) + ce := regexp.MustCompile(`(?i)#Admin`) + admin := ce.MatchString(chunck) + _, modcred := GetPasswordFromSession(r) + if(admin && modcred != "" ) { + return re.ReplaceAllString(input, "#Admin") + } else { + hash := CreateTripCode(chunck) + return re.ReplaceAllString(input, "!" + hash[42:50]) + } } func GetActorFromPath(db *sql.DB, location string, prefix string) Actor { -- cgit v1.2.3