security/routes/status.go

49 lines
1012 B
Go

package routes
import (
"strings"
"git.matterlinux.xyz/matter/security/lib"
"git.matterlinux.xyz/matter/security/log"
"github.com/gofiber/fiber/v2"
_ "github.com/mattn/go-sqlite3"
)
func POST_Status(c *fiber.Ctx) error {
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 {
log.Error("Failed to get the user: %s", err.Error())
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 {
log.Error("Failed to update the vuln: %s", err.Error())
return lib.RenderError(c, 500)
}
return c.Redirect("/manage")
}