55 lines
1.2 KiB
Go
55 lines
1.2 KiB
Go
package routes
|
|
|
|
import (
|
|
"git.matterlinux.xyz/matter/security/lib"
|
|
"git.matterlinux.xyz/matter/security/log"
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
func POST_New(c *fiber.Ctx) error {
|
|
body := struct {
|
|
Desc string `form:"desc"`
|
|
Source string `form:"source"`
|
|
Severity string `form:"severity"`
|
|
Package string `form:"package"`
|
|
Versions string `form:"versions"`
|
|
}{}
|
|
|
|
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)
|
|
}
|
|
|
|
if !lib.ValidSeverity(body.Severity) {
|
|
return lib.RenderError(c, 400)
|
|
}
|
|
|
|
v := lib.Vuln{
|
|
ID: lib.GetID(),
|
|
Desc: body.Desc,
|
|
Source: body.Source,
|
|
Severity: body.Severity,
|
|
Package: body.Package,
|
|
Versions: body.Versions,
|
|
Status: "Waiting for review",
|
|
Message: "This vulnerability is waiting for a review from the maintainers",
|
|
Author: user.Username,
|
|
Date: lib.GetFTime(),
|
|
Updated: lib.GetFTime(),
|
|
}
|
|
|
|
err = lib.AddVuln(v)
|
|
if err != nil {
|
|
log.Error("Failed to add vuln: %s", err.Error())
|
|
return lib.RenderError(c, 500)
|
|
}
|
|
|
|
return c.Redirect("/manage")
|
|
}
|