security/routes/status.go

49 lines
1012 B
Go
Raw Permalink Normal View History

2024-03-21 20:20:24 +00:00
package routes
import (
"strings"
"git.matterlinux.xyz/matter/security/lib"
2024-08-13 19:40:44 +00:00
"git.matterlinux.xyz/matter/security/log"
2024-03-21 20:20:24 +00:00
"github.com/gofiber/fiber/v2"
_ "github.com/mattn/go-sqlite3"
)
2024-08-13 19:40:44 +00:00
func POST_Status(c *fiber.Ctx) error {
2024-08-13 19:25:36 +00:00
body := struct {
ID string `form:"id"`
Status string `form:"status"`
Message string `form:"message"`
}{}
err := c.BodyParser(&body)
if err != nil {
return lib.RenderError(c, 400)
}
user, err := lib.GetUser(c)
if err != nil {
2024-08-13 19:40:44 +00:00
log.Error("Failed to get the user: %s", err.Error())
2024-08-13 19:25:36 +00:00
return lib.RenderError(c, 500)
}
vuln, suc := lib.FindVuln(body.ID)
if !suc {
return lib.RenderError(c, 404)
}
vuln.Message = body.Message
vuln.Status = body.Status
if vuln.Author != user.Username && !strings.Contains(vuln.Author, ", "+user.Username) {
vuln.Author += ", " + user.Username
}
err = lib.UpdateVuln(vuln)
if err != nil {
2024-08-13 19:40:44 +00:00
log.Error("Failed to update the vuln: %s", err.Error())
2024-08-13 19:25:36 +00:00
return lib.RenderError(c, 500)
}
return c.Redirect("/manage")
2024-03-21 20:20:24 +00:00
}