|
|
@@ -26,7 +26,7 @@ func genConfig() *userConfig {
|
|
|
make([]configBoard, 0, len(config.Boards)),
|
|
|
}
|
|
|
for k := range config.Admins { u.Admins = append(u.Admins, k) }
|
|
|
- for b := range config.Boards { u.Boards = append(u.Boards, config.Boards[b]) }
|
|
|
+ for b := range config.Boards { u.Boards = append(u.Boards, *config.Boards[b]) }
|
|
|
return u
|
|
|
}
|
|
|
|
|
|
@@ -34,10 +34,6 @@ func serveIndex(c echo.Context) error {
|
|
|
return c.File("server/templates/head.html")
|
|
|
}
|
|
|
|
|
|
-func serveLogin(c echo.Context) error {
|
|
|
- return c.File("server/templates/login.html")
|
|
|
-}
|
|
|
-
|
|
|
func serveInterface(address string) {
|
|
|
e := echo.New()
|
|
|
|
|
|
@@ -52,7 +48,13 @@ func serveInterface(address string) {
|
|
|
return c.Redirect(http.StatusTemporaryRedirect, "/login")
|
|
|
})
|
|
|
|
|
|
- e.GET("/login", serveLogin)
|
|
|
+ e.GET("/login", func(c echo.Context) error {
|
|
|
+ sess, _ := session.Get("session", c)
|
|
|
+ if auth, ok := sess.Values["authorised"]; ok && auth.(bool) {
|
|
|
+ return c.Redirect(http.StatusTemporaryRedirect, "/admin")
|
|
|
+ }
|
|
|
+ return c.File("server/templates/login.html")
|
|
|
+ })
|
|
|
g := e.Group("/admin")
|
|
|
|
|
|
g.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
|
|
|
@@ -60,10 +62,8 @@ func serveInterface(address string) {
|
|
|
sess, _ := session.Get("session", c)
|
|
|
auth, ok := sess.Values["authorised"]
|
|
|
if !ok || !auth.(bool) {
|
|
|
- fmt.Println("Not authorised")
|
|
|
return c.Redirect(http.StatusTemporaryRedirect, "/login")
|
|
|
}
|
|
|
- fmt.Println("Authorised")
|
|
|
return next(c)
|
|
|
}
|
|
|
})
|
|
|
@@ -104,7 +104,7 @@ func serveInterface(address string) {
|
|
|
fmt.Printf("Failed hash password %s\n", err)
|
|
|
return c.String(http.StatusNotAcceptable, "Failed to hash")
|
|
|
}
|
|
|
- config.Admins[name] = admin
|
|
|
+ config.Admins[name] = &admin
|
|
|
}
|
|
|
|
|
|
saveConfig()
|
|
|
@@ -120,7 +120,8 @@ func serveInterface(address string) {
|
|
|
if err != nil || (keysize != 128 && keysize != 192 && keysize != 256) {
|
|
|
return c.String(http.StatusNotAcceptable, "Invalid key size")
|
|
|
}
|
|
|
- key, err := hex.DecodeString(c.FormValue("key"))
|
|
|
+ keystr := strings.Trim(c.FormValue("key"), " ")
|
|
|
+ key, err := hex.DecodeString(keystr)
|
|
|
if err != nil {
|
|
|
return c.String(http.StatusNotAcceptable, "Key is not base 16")
|
|
|
}
|
|
|
@@ -141,7 +142,7 @@ func serveInterface(address string) {
|
|
|
_, err = rand.Read(key)
|
|
|
errCheck(err, "Failed generate random key")
|
|
|
}
|
|
|
- config.Boards[id] = configBoard{
|
|
|
+ config.Boards[id] = &configBoard{
|
|
|
id,
|
|
|
key,
|
|
|
hex.EncodeToString(key),
|
|
|
@@ -185,8 +186,10 @@ func serveInterface(address string) {
|
|
|
password := c.FormValue("password")
|
|
|
user, ok := config.Admins[username]
|
|
|
if !ok || !user.checkPassword(password) {
|
|
|
+ e.Logger.Printf("User %s failed to login\n", username)
|
|
|
return c.File("server/templates/login.html")
|
|
|
}
|
|
|
+ e.Logger.Printf("User %s successfully logged in\n", username)
|
|
|
sess, _ := session.Get("session", c)
|
|
|
sess.Options = &sessions.Options{
|
|
|
Path: "/",
|
|
|
@@ -208,6 +211,10 @@ func serveInterface(address string) {
|
|
|
return c.Redirect(http.StatusTemporaryRedirect, "/login")
|
|
|
})
|
|
|
|
|
|
+ g.GET("/logs", func(c echo.Context) error {
|
|
|
+ return c.JSON(http.StatusOK, &serverLogs)
|
|
|
+ })
|
|
|
+
|
|
|
//g.Use(middleware.BasicAuth()
|
|
|
g.GET("/config", func(c echo.Context) error {
|
|
|
return c.JSON(http.StatusOK, genConfig())
|