From 6413dd0fa2b3a381d306069ad8d2dd766fe754ec Mon Sep 17 00:00:00 2001 From: FChannel <> Date: Sun, 30 May 2021 14:01:01 -0700 Subject: removed Header Referer for re routing since it does not work for all browsers ie IceCat --- README.md | 30 ++++++--------------------- main.go | 71 +++++++++++++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 59 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index 05ff96b..8da0dd6 100644 --- a/README.md +++ b/README.md @@ -74,36 +74,18 @@ Any contributions or suggestions are appreciated. Best way to give immediate fee `emailpass:password` +#### local testing + When testing on a local env when setting the `instance` value in the config file you have to append the port number to the local address eg. `instance:localhost:3000` with `instanceport` also being set to the same port. + + If you want to test federation between servers locally you have to use your local ip as the `instance` eg. `instance:192.168.0.2:3000` and `instance:192:168:0:3:3000` adding the port to localhost will not route correctly. + ### Managing the server To access the managment page to create new boards or subscribe to other boards, when you start the server the console will output the `Mod key` and `Admin Login` Use the `Mod key` by appending it to your servers url, `https://fchan.xyz/[Mod key]` once there you will be prompted for the `Admin Login` credentials. - You can manage each board by appending the `Mod key` to the desired board url: `https://fchan.xyz/g/[Mod Key]` + You can manage each board by appending the `Mod key` to the desired board url: `https://fchan.xyz/[Mod Key]/g` The `Mod key` is not static and is reset on server restart. -### Creating a new board - - `CreateNewBoardDB(db *sql.DB, actor Actor)` - - returns Actor. - -### Creating a new actor - - `CreateNewActor(board string, prefName string, summary string, authReq []string, restricted bool)` - - returns Actor - - - `board` is the abbreviated name such as `g` - - - `prefName` is the fully readable name such as `Technology` - - - `summary` is a summary of the board - - - `authReq` is an array string of required privileges to post on the board, default is: `[]string{"captcha","email","passphrase"}` - - - `restricted` is bool. `true` is blue board, `false` is red board - - ## Server Update Check the git repo for the latest commits. If there are commits you want to update to, pull and restart instance. diff --git a/main.go b/main.go index bd88c41..8405bc6 100644 --- a/main.go +++ b/main.go @@ -472,9 +472,14 @@ func main() { FollowingBoards = GetActorFollowingDB(db, Domain) - Boards = GetBoardCollection(db) + Boards = GetBoardCollection(db) + + var redirect string + if(actor.Name != "main") { + redirect = "/" + actor.Name + } - http.Redirect(w, r, r.Header.Get("Referer"), http.StatusSeeOther) + http.Redirect(w, r, "/" + *Key + "/" + redirect, http.StatusSeeOther) } else if manage && actor.Name != "" { t := template.Must(template.ParseFiles("./static/main.html", "./static/manage.html")) @@ -646,7 +651,7 @@ func main() { Boards = GetBoardCollection(db) } - http.Redirect(w, r, r.Header.Get("Referer"), http.StatusSeeOther) + http.Redirect(w, r, "/" + *Key, http.StatusSeeOther) }) http.HandleFunc("/verify", func(w http.ResponseWriter, r *http.Request){ @@ -707,8 +712,9 @@ func main() { http.HandleFunc("/delete", func(w http.ResponseWriter, r *http.Request){ id := r.URL.Query().Get("id") - board := r.URL.Query().Get("board") - actor := GetActorFromPath(db, id, "/") + board := r.URL.Query().Get("board") + col := GetCollectionFromID(id) + actor := col.OrderedItems[0].Actor _, auth := GetPasswordFromSession(r) if id == "" || auth == "" { @@ -723,29 +729,51 @@ func main() { return } + var OP string + if len(col.OrderedItems[0].InReplyTo) > 0 { + OP = col.OrderedItems[0].InReplyTo[0].Id + } + if !IsIDLocal(db, id) { CreateLocalDeleteDB(db, id, "post") - CloseLocalReportDB(db, id, board) - http.Redirect(w, r, r.Header.Get("Referer"), http.StatusSeeOther) + CloseLocalReportDB(db, id, actor.Id) + + if(board != "") { + http.Redirect(w, r, "/" + *Key + "/" + board , http.StatusSeeOther) + } else if(OP != ""){ + http.Redirect(w, r, OP, http.StatusSeeOther) + } else { + http.Redirect(w, r, actor.Id, http.StatusSeeOther) + } + return } var obj ObjectBase obj.Id = id - obj.Actor = &actor + obj.Actor = actor isOP := CheckIfObjectOP(db, obj.Id) if !isOP { DeleteObjectRequest(db, id) DeleteObject(db, obj.Id) - http.Redirect(w, r, r.Header.Get("Referer"), http.StatusSeeOther) + if(board != ""){ + http.Redirect(w, r, "/" + *Key + "/" + board , http.StatusSeeOther) + }else{ + http.Redirect(w, r, OP, http.StatusSeeOther) + } return + } else { DeleteObjectAndRepliesRequest(db, id) DeleteObjectAndReplies(db, obj.Id) - http.Redirect(w, r, r.Header.Get("Referer"), http.StatusSeeOther) + if(board != ""){ + http.Redirect(w, r, "/" + *Key + "/" + board , http.StatusSeeOther) + }else{ + http.Redirect(w, r, actor.Id, http.StatusSeeOther) + } return } @@ -756,7 +784,16 @@ func main() { http.HandleFunc("/deleteattach", func(w http.ResponseWriter, r *http.Request){ id := r.URL.Query().Get("id") + col := GetCollectionFromID(id) + actor := col.OrderedItems[0].Actor + var OP string + if (len(col.OrderedItems[0].InReplyTo) > 0 && col.OrderedItems[0].InReplyTo[0].Id != "") { + OP = col.OrderedItems[0].InReplyTo[0].Id + } else { + OP = id + } + _, auth := GetPasswordFromSession(r) if id == "" || auth == "" { @@ -765,8 +802,6 @@ func main() { return } - actor := GetActorFromPath(db, id, "/") - if !HasAuth(db, auth, actor.Id) { w.WriteHeader(http.StatusBadRequest) w.Write([]byte("")) @@ -775,13 +810,13 @@ func main() { if !IsIDLocal(db, id) { CreateLocalDeleteDB(db, id, "attachment") - http.Redirect(w, r, r.Header.Get("Referer"), http.StatusSeeOther) + http.Redirect(w, r, OP, http.StatusSeeOther) return } DeleteAttachmentFromFile(db, id) DeletePreviewFromFile(db, id) - http.Redirect(w, r, r.Header.Get("Referer"), http.StatusSeeOther) + http.Redirect(w, r, OP, http.StatusSeeOther) }) http.HandleFunc("/report", func(w http.ResponseWriter, r *http.Request){ @@ -818,13 +853,13 @@ func main() { if !IsIDLocal(db, id) { CloseLocalReportDB(db, id, board) - http.Redirect(w, r, r.Header.Get("Referer"), http.StatusSeeOther) + http.Redirect(w, r, "/" + *Key + "/" + board, http.StatusSeeOther) return } reported := DeleteReportActivity(db, id) if reported { - http.Redirect(w, r, r.Header.Get("Referer"), http.StatusSeeOther) + http.Redirect(w, r, "/" + *Key + "/" + board, http.StatusSeeOther) return } @@ -835,13 +870,13 @@ func main() { if !IsIDLocal(db, id) { CreateLocalReportDB(db, id, board, reason) - http.Redirect(w, r, r.Header.Get("Referer"), http.StatusSeeOther) + http.Redirect(w, r, "/" + board + "/" + remoteShort(id), http.StatusSeeOther) return } reported := ReportActivity(db, id, reason) if reported { - http.Redirect(w, r, r.Header.Get("Referer"), http.StatusSeeOther) + http.Redirect(w, r, id, http.StatusSeeOther) return } -- cgit v1.2.3