From 16b4165e5102fc9b4766e1bd1204ca9cf23199aa Mon Sep 17 00:00:00 2001 From: FChannel <> Date: Thu, 22 Jul 2021 19:03:28 -0700 Subject: added banning media by saving hash in database --- outboxPost.go | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) (limited to 'outboxPost.go') diff --git a/outboxPost.go b/outboxPost.go index 356647e..a827e21 100644 --- a/outboxPost.go +++ b/outboxPost.go @@ -7,6 +7,7 @@ import _ "github.com/lib/pq" import "encoding/json" import "reflect" import "io/ioutil" +import "mime/multipart" import "os" import "regexp" import "strings" @@ -24,6 +25,8 @@ func ParseOutboxRequest(w http.ResponseWriter, r *http.Request, db *sql.DB) { r.ParseMultipartForm(5 << 20) if(BoardHasAuthType(db, actor.Name, "captcha") && CheckCaptcha(db, r.FormValue("captcha"))) { f, header, _ := r.FormFile("file") + defer f.Close() + if(header != nil) { if(header.Size > (7 << 20)){ w.WriteHeader(http.StatusRequestEntityTooLarge) @@ -31,6 +34,12 @@ func ParseOutboxRequest(w http.ResponseWriter, r *http.Request, db *sql.DB) { return } + if(IsMediaBanned(db, f)) { + fmt.Println("media banned") + http.Redirect(w, r, Domain, http.StatusSeeOther) + return + } + contentType, _ := GetFileContentType(f) if(!SupportedMIMEType(contentType)) { @@ -39,7 +48,7 @@ func ParseOutboxRequest(w http.ResponseWriter, r *http.Request, db *sql.DB) { return } } - + var nObj = CreateObject("Note") nObj = ObjectFromForm(r, db, nObj) @@ -339,7 +348,6 @@ func ObjectFromForm(r *http.Request, db *sql.DB, obj ObjectBase) ObjectBase { err := cmd.Run() CheckError(err, "error with removing exif data from image") - } obj.Preview = CreatePreviewObject(obj.Attachment[0]) @@ -617,3 +625,32 @@ func MakeActivityFollowingReq(w http.ResponseWriter, r *http.Request, activity A return false } + +func IsMediaBanned(db *sql.DB, f multipart.File) bool { + f.Seek(0, 0) + + fileBytes, _ := ioutil.ReadAll(f) + + hash := HashBytes(fileBytes) + + f.Seek(0, 0) + + query := `select hash from bannedmedia where hash=$1` + + rows, err := db.Query(query, hash) + + CheckError(err, "could not get hash from banned media in db") + + var h string + + defer rows.Close() + + rows.Next() + rows.Scan(&h) + + if h == hash { + return true + } + + return false +} -- cgit v1.2.3 From c5eff11c39d0a07f5cb7401835d04ba4df9edcbf Mon Sep 17 00:00:00 2001 From: FChannel <> Date: Thu, 22 Jul 2021 20:15:31 -0700 Subject: null reference --- outboxPost.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'outboxPost.go') diff --git a/outboxPost.go b/outboxPost.go index a827e21..b3a8baf 100644 --- a/outboxPost.go +++ b/outboxPost.go @@ -25,9 +25,9 @@ func ParseOutboxRequest(w http.ResponseWriter, r *http.Request, db *sql.DB) { r.ParseMultipartForm(5 << 20) if(BoardHasAuthType(db, actor.Name, "captcha") && CheckCaptcha(db, r.FormValue("captcha"))) { f, header, _ := r.FormFile("file") - defer f.Close() - + if(header != nil) { + defer f.Close() if(header.Size > (7 << 20)){ w.WriteHeader(http.StatusRequestEntityTooLarge) w.Write([]byte("7MB max file size")) -- cgit v1.2.3 From 8f7386f2906716d40099fb50f029d48796dd1bbd Mon Sep 17 00:00:00 2001 From: FChannel <> Date: Fri, 23 Jul 2021 22:45:44 -0700 Subject: added cross post support. could blow up if referencing a link that is not local to the database or cache. --- outboxPost.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'outboxPost.go') diff --git a/outboxPost.go b/outboxPost.go index b3a8baf..1d658ea 100644 --- a/outboxPost.go +++ b/outboxPost.go @@ -381,7 +381,7 @@ func ObjectFromForm(r *http.Request, db *sql.DB, obj ObjectBase) ObjectBase { } } - replyingTo := ParseCommentForReplies(r.FormValue("comment")) + replyingTo := ParseCommentForReplies(db, r.FormValue("comment"), originalPost.Id) for _, e := range replyingTo { -- cgit v1.2.3 From def81637bc3d9f7ff73fed2786dbaa7a78086799 Mon Sep 17 00:00:00 2001 From: FChannel <> Date: Sun, 25 Jul 2021 13:25:47 -0700 Subject: fixed auto follow logic as well as out of sync following --- outboxPost.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'outboxPost.go') diff --git a/outboxPost.go b/outboxPost.go index 1d658ea..88b9927 100644 --- a/outboxPost.go +++ b/outboxPost.go @@ -101,7 +101,7 @@ func ParseOutboxRequest(w http.ResponseWriter, r *http.Request, db *sql.DB) { var rActivity Activity if validActor && validLocalActor { rActivity = AcceptFollow(activity) - SetActorFollowingDB(db, rActivity) + rActivity = SetActorFollowingDB(db, rActivity) MakeActivityRequest(db, activity) } @@ -565,16 +565,26 @@ func ParseInboxRequest(w http.ResponseWriter, r *http.Request, db *sql.DB) { MakeActivityRequest(db, response) alreadyFollow := false + alreadyFollowing := false autoSub := GetActorAutoSubscribeDB(db, response.Actor.Id) following := GetActorFollowingDB(db, response.Actor.Id) for _, e := range following { - if e.Id == activity.Actor.Id { + if e.Id == response.Object.Id { alreadyFollow = true } } - if autoSub && !alreadyFollow { + actor := FingerActor(response.Object.Actor) + remoteActorFollowingCol := GetCollectionFromReq(actor.Following) + + for _, e := range remoteActorFollowingCol.Items { + if e.Id == response.Actor.Id { + alreadyFollowing = true + } + } + + if autoSub && !alreadyFollow && alreadyFollowing { followActivity := MakeFollowActivity(db, response.Actor.Id, response.Object.Actor) if FingerActor(response.Object.Actor).Id != "" { @@ -597,7 +607,6 @@ func ParseInboxRequest(w http.ResponseWriter, r *http.Request, db *sql.DB) { } break } - } func MakeActivityFollowingReq(w http.ResponseWriter, r *http.Request, activity Activity) bool { -- cgit v1.2.3 From 74b29610d09b05b3f563bb84e8ec65b534c2ee83 Mon Sep 17 00:00:00 2001 From: FChannel <> Date: Sun, 25 Jul 2021 13:49:05 -0700 Subject: added modification to media ban --- outboxPost.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'outboxPost.go') diff --git a/outboxPost.go b/outboxPost.go index 88b9927..6d23e23 100644 --- a/outboxPost.go +++ b/outboxPost.go @@ -637,8 +637,13 @@ func MakeActivityFollowingReq(w http.ResponseWriter, r *http.Request, activity A func IsMediaBanned(db *sql.DB, f multipart.File) bool { f.Seek(0, 0) - - fileBytes, _ := ioutil.ReadAll(f) + + fileBytes := make([]byte, 2048) + + _, err := f.Read(fileBytes) + if err != nil { + fmt.Println("error readin bytes for media ban") + } hash := HashBytes(fileBytes) -- cgit v1.2.3