diff options
Diffstat (limited to 'route')
-rw-r--r-- | route/routes/actor.go | 21 | ||||
-rw-r--r-- | route/routes/boardmgmt.go | 42 | ||||
-rw-r--r-- | route/routes/news.go | 6 |
3 files changed, 52 insertions, 17 deletions
diff --git a/route/routes/actor.go b/route/routes/actor.go index a7711d3..2437567 100644 --- a/route/routes/actor.go +++ b/route/routes/actor.go @@ -2,7 +2,6 @@ package routes import ( "bytes" - "errors" "io" "io/ioutil" "mime/multipart" @@ -235,7 +234,7 @@ func ActorPost(ctx *fiber.Ctx) error { } if is, _ := util.IsPostBlacklist(ctx.FormValue("comment")); is { - errors.New("\n\nBlacklist post blocked\n\n") + config.Log.Println("Blacklist post blocked") return ctx.Redirect("/", 301) } @@ -274,12 +273,12 @@ func ActorPost(ctx *fiber.Ctx) error { fw, err := we.CreateFormFile("file", header.Filename) if err != nil { - errors.New("error with form file create") + return util.MakeError(err, "ActorPost") } _, err = io.Copy(fw, file) if err != nil { - errors.New("error with form file copy") + return util.MakeError(err, "ActorPost") } } @@ -291,24 +290,24 @@ func ActorPost(ctx *fiber.Ctx) error { if key == "captcha" { err := we.WriteField(key, ctx.FormValue("captchaCode")+":"+ctx.FormValue("captcha")) if err != nil { - errors.New("error with writing captcha field") + return util.MakeError(err, "ActorPost") } } else if key == "name" { name, tripcode, _ := post.CreateNameTripCode(ctx) err := we.WriteField(key, name) if err != nil { - errors.New("error with writing name field") + return util.MakeError(err, "ActorPost") } err = we.WriteField("tripcode", tripcode) if err != nil { - errors.New("error with writing tripcode field") + return util.MakeError(err, "ActorPost") } } else { err := we.WriteField(key, r0[0]) if err != nil { - errors.New("error with writing field") + return util.MakeError(err, "ActorPost") } } } @@ -316,7 +315,7 @@ func ActorPost(ctx *fiber.Ctx) error { if ctx.FormValue("inReplyTo") == "" && reply != "" { err := we.WriteField("inReplyTo", reply) if err != nil { - errors.New("error with writing inReplyTo field") + return util.MakeError(err, "ActorPost") } } @@ -327,7 +326,7 @@ func ActorPost(ctx *fiber.Ctx) error { req, err := http.NewRequest("POST", sendTo, &b) if err != nil { - errors.New("error with post form req") + return util.MakeError(err, "ActorPost") } req.Header.Set("Content-Type", we.FormDataContentType()) @@ -335,7 +334,7 @@ func ActorPost(ctx *fiber.Ctx) error { resp, err := util.RouteProxy(req) if err != nil { - errors.New("error with post form resp") + return util.MakeError(err, "ActorPost") } defer resp.Body.Close() diff --git a/route/routes/boardmgmt.go b/route/routes/boardmgmt.go index 0498c5b..5d6dd93 100644 --- a/route/routes/boardmgmt.go +++ b/route/routes/boardmgmt.go @@ -5,6 +5,7 @@ import ( "net/http" "os" "regexp" + "strconv" "github.com/FChannel0/FChannel-Server/activitypub" "github.com/FChannel0/FChannel-Server/config" @@ -351,9 +352,46 @@ func BoardAutoSubscribe(ctx *fiber.Ctx) error { return ctx.SendString("board auto subscribe") } -// TODO routes/BoardBlacklist func BoardBlacklist(ctx *fiber.Ctx) error { - return ctx.SendString("board blacklist") + actor, err := activitypub.GetActorFromDB(config.Domain) + + if err != nil { + return util.MakeError(err, "BoardBlacklist") + } + + if has := actor.HasValidation(ctx); !has { + return ctx.Status(404).Render("404", fiber.Map{}) + } + + if ctx.Method() == "GET" { + if id := ctx.Query("remove"); id != "" { + i, _ := strconv.Atoi(id) + if err := util.DeleteRegexBlacklist(i); err != nil { + return util.MakeError(err, "BoardBlacklist") + } + } + } else { + regex := ctx.FormValue("regex") + testCase := ctx.FormValue("testCase") + + if regex == "" { + return ctx.Redirect("/", http.StatusSeeOther) + } + + re := regexp.MustCompile(regex) + + if testCase == "" { + if err := util.WriteRegexBlacklist(regex); err != nil { + return util.MakeError(err, "BoardBlacklist") + } + } else if re.MatchString(testCase) { + if err := util.WriteRegexBlacklist(regex); err != nil { + return util.MakeError(err, "BoardBlacklist") + } + } + } + + return ctx.Redirect("/"+config.Key+"#regex", http.StatusSeeOther) } func BoardReport(ctx *fiber.Ctx) error { diff --git a/route/routes/news.go b/route/routes/news.go index 6917e4b..8e8047a 100644 --- a/route/routes/news.go +++ b/route/routes/news.go @@ -19,8 +19,7 @@ func NewsGet(ctx *fiber.Ctx) error { ts, err := strconv.Atoi(timestamp) if err != nil { - ctx.Status(http.StatusForbidden) - return ctx.Render("404", fiber.Map{}) + return ctx.Status(404).Render("404", fiber.Map{}) } actor, err := activitypub.GetActorFromDB(config.Domain) @@ -131,8 +130,7 @@ func NewsDelete(ctx *fiber.Ctx) error { tsint, err := strconv.Atoi(timestamp) if err != nil { - ctx.Status(http.StatusForbidden) - return ctx.Render("404", fiber.Map{}) + return ctx.Status(404).Render("404", fiber.Map{}) } if err := db.DeleteNewsItem(tsint); err != nil { |