update: new logging functions
This commit is contained in:
@ -1,12 +1,12 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"log"
|
||||
"math"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"git.matterlinux.xyz/matter/security/lib"
|
||||
"git.matterlinux.xyz/matter/security/log"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
@ -21,7 +21,7 @@ func GetPage(c *fiber.Ctx) (int, int, int) {
|
||||
return page, page * PAGE_SIZE, (page * PAGE_SIZE) - PAGE_SIZE
|
||||
}
|
||||
|
||||
func GETDetails(c *fiber.Ctx) error {
|
||||
func GET_Details(c *fiber.Ctx) error {
|
||||
id := c.Params("id")
|
||||
if id == "" || !strings.HasPrefix(id, "MPSI-") {
|
||||
return lib.RenderError(c, 404)
|
||||
@ -32,19 +32,17 @@ func GETDetails(c *fiber.Ctx) error {
|
||||
return lib.RenderError(c, 404)
|
||||
}
|
||||
|
||||
return c.Render("details", fiber.Map{
|
||||
"v": v,
|
||||
})
|
||||
return c.Render("details", &v)
|
||||
}
|
||||
|
||||
func GETIndex(c *fiber.Ctx) error {
|
||||
func GET_Index(c *fiber.Ctx) error {
|
||||
cur, max, min := GetPage(c)
|
||||
search_qu := c.Query("q")
|
||||
search_in := c.Query("i")
|
||||
|
||||
vulns, err := lib.LoadVulns()
|
||||
if err != nil {
|
||||
log.Printf("Failed to load vulns: %s", err.Error())
|
||||
log.Error("Failed to load vulns: %s", err.Error())
|
||||
return lib.RenderError(c, 500)
|
||||
}
|
||||
|
||||
@ -74,7 +72,6 @@ func GETIndex(c *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
results = append(results, vulns[i])
|
||||
|
||||
}
|
||||
|
||||
pages := int64(math.Ceil(float64(len(results)) / float64(PAGE_SIZE)))
|
||||
|
@ -1,13 +1,12 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"git.matterlinux.xyz/matter/security/lib"
|
||||
"git.matterlinux.xyz/matter/security/log"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func POSTLogin(c *fiber.Ctx) error {
|
||||
func POST_Login(c *fiber.Ctx) error {
|
||||
body := struct {
|
||||
Username string `form:"username"`
|
||||
Password string `form:"password"`
|
||||
@ -20,7 +19,7 @@ func POSTLogin(c *fiber.Ctx) error {
|
||||
|
||||
users, err := lib.LoadUsers()
|
||||
if err != nil {
|
||||
log.Printf("Failed to load users: %s", err.Error())
|
||||
log.Error("Failed to load users: %s", err.Error())
|
||||
return lib.RenderError(c, 500)
|
||||
}
|
||||
|
||||
@ -34,7 +33,7 @@ func POSTLogin(c *fiber.Ctx) error {
|
||||
})
|
||||
err = lib.UpdateUser(u)
|
||||
if err != nil {
|
||||
log.Printf("Failed to update user: %s", err.Error())
|
||||
log.Error("Failed to update user: %s", err.Error())
|
||||
return lib.RenderError(c, 500)
|
||||
}
|
||||
return c.Redirect("/manage")
|
||||
@ -45,7 +44,7 @@ func POSTLogin(c *fiber.Ctx) error {
|
||||
return c.Render("login", fiber.Map{})
|
||||
}
|
||||
|
||||
func GETLogin(c *fiber.Ctx) error {
|
||||
func GET_Login(c *fiber.Ctx) error {
|
||||
if c.Cookies("auth") != "" {
|
||||
return c.Redirect("/manage")
|
||||
}
|
||||
|
@ -1,9 +1,8 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"git.matterlinux.xyz/matter/security/lib"
|
||||
"git.matterlinux.xyz/matter/security/log"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
@ -16,7 +15,7 @@ func MiddleAuth(c *fiber.Ctx) error {
|
||||
|
||||
users, err := lib.LoadUsers()
|
||||
if err != nil {
|
||||
log.Printf("Failed to load users: %s", err.Error())
|
||||
log.Error("Failed to load users: %s", err.Error())
|
||||
return lib.RenderError(c, 500)
|
||||
}
|
||||
|
||||
@ -34,21 +33,21 @@ func MiddleAuth(c *fiber.Ctx) error {
|
||||
return c.Redirect("/login")
|
||||
}
|
||||
|
||||
func GETManage(c *fiber.Ctx) error {
|
||||
func GET_Manage(c *fiber.Ctx) error {
|
||||
return c.Render("manage", fiber.Map{})
|
||||
}
|
||||
|
||||
func GETLogout(c *fiber.Ctx) error {
|
||||
func GET_Logout(c *fiber.Ctx) error {
|
||||
user, err := lib.GetUser(c)
|
||||
if err != nil {
|
||||
log.Printf("Failed to load user: %s", err.Error())
|
||||
log.Error("Failed to load user: %s", err.Error())
|
||||
return lib.RenderError(c, 500)
|
||||
}
|
||||
|
||||
user.Cookie = "notset"
|
||||
err = lib.UpdateUser(user)
|
||||
if err != nil {
|
||||
log.Printf("Failed to save users: %s", err.Error())
|
||||
log.Error("Failed to save users: %s", err.Error())
|
||||
return lib.RenderError(c, 500)
|
||||
}
|
||||
|
||||
|
@ -1,13 +1,12 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"git.matterlinux.xyz/matter/security/lib"
|
||||
"git.matterlinux.xyz/matter/security/log"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func POSTNew(c *fiber.Ctx) error {
|
||||
func POST_New(c *fiber.Ctx) error {
|
||||
body := struct {
|
||||
Desc string `form:"desc"`
|
||||
Source string `form:"source"`
|
||||
@ -23,7 +22,7 @@ func POSTNew(c *fiber.Ctx) error {
|
||||
|
||||
user, err := lib.GetUser(c)
|
||||
if err != nil {
|
||||
log.Printf("Failed to get the user: %s", err.Error())
|
||||
log.Error("Failed to get the user: %s", err.Error())
|
||||
return lib.RenderError(c, 500)
|
||||
}
|
||||
|
||||
@ -47,7 +46,7 @@ func POSTNew(c *fiber.Ctx) error {
|
||||
|
||||
err = lib.AddVuln(v)
|
||||
if err != nil {
|
||||
log.Printf("Failed to add vuln: %s", err.Error())
|
||||
log.Error("Failed to add vuln: %s", err.Error())
|
||||
return lib.RenderError(c, 500)
|
||||
}
|
||||
|
||||
|
@ -1,15 +1,15 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"git.matterlinux.xyz/matter/security/lib"
|
||||
"git.matterlinux.xyz/matter/security/log"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
func POSTStatus(c *fiber.Ctx) error {
|
||||
func POST_Status(c *fiber.Ctx) error {
|
||||
body := struct {
|
||||
ID string `form:"id"`
|
||||
Status string `form:"status"`
|
||||
@ -23,7 +23,7 @@ func POSTStatus(c *fiber.Ctx) error {
|
||||
|
||||
user, err := lib.GetUser(c)
|
||||
if err != nil {
|
||||
log.Printf("Failed to get the user: %s", err.Error())
|
||||
log.Error("Failed to get the user: %s", err.Error())
|
||||
return lib.RenderError(c, 500)
|
||||
}
|
||||
|
||||
@ -40,7 +40,7 @@ func POSTStatus(c *fiber.Ctx) error {
|
||||
|
||||
err = lib.UpdateVuln(vuln)
|
||||
if err != nil {
|
||||
log.Printf("Failed to update the vuln: %s", err.Error())
|
||||
log.Error("Failed to update the vuln: %s", err.Error())
|
||||
return lib.RenderError(c, 500)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user