added folders config in database
Some checks reported errors
continuous-integration/drone/push Build encountered an error
continuous-integration/drone/tag Build encountered an error

This commit is contained in:
Paul 2022-02-24 17:28:29 +01:00
parent ef228e3750
commit 29a5c5927b
2 changed files with 25 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package models
import (
"encoding/json"
"fmt"
"regexp"
"strings"
@ -59,10 +60,30 @@ func (wl Trustlist) Verify() bool {
return reg.MatchString(wl.IP)
}
// GetFolders ...
func GetFolders(cfg config.Config) (res []Folder, err error) {
var w = Cfg{Key: "folders"}
if exists, _ := cfg.Db.Get(&w); exists {
err = json.Unmarshal([]byte(w.Value), &res)
}
return
}
type Trustlist struct {
IP string `json:"ip"`
}
type Folder struct {
Path string `json:"path"`
Sets []Set `json:"sets"`
}
type Set struct {
Type string `json:"type"`
Filename string `json:"filename"`
Regex string `json:"regex"`
}
// Cfg is ipbl config
type Cfg struct {
ID int `xorm:"pk autoincr" json:"-"`

View File

@ -107,6 +107,10 @@ func RegisterRoutes(e *echo.Echo, ctx *context.Context, cfg *config.Config) {
}
return
})
e.GET("/ips/folders", func(c echo.Context) (err error) {
folders, err := models.GetFolders(*cfg)
return Result(c, err, folders)
})
e.Logger.Fatal(
e.Start(