From 8512402488e1a42ccd0946a728ff75d61df0152c Mon Sep 17 00:00:00 2001 From: Paul Lecuq Date: Tue, 22 Feb 2022 19:46:01 +0100 Subject: [PATCH] replace abusive keywords --- src/models/cfg.go | 26 +++++++++++++------------- src/routers/funcs.go | 24 ++++++++++++++---------- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/src/models/cfg.go b/src/models/cfg.go index c68c013..a581373 100644 --- a/src/models/cfg.go +++ b/src/models/cfg.go @@ -11,20 +11,20 @@ import ( //var ipv4_regex = `^(((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.|$)){4})/` var ipv4_cidr_regex = `^(((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.|)){4}\/([1-3])?([0-9])?$)` -// GetWhitelists ... -func GetWhitelists(cfg config.Config) (res []string, err error) { - var w = Cfg{Key: "whitelist"} +// GetTrustlists ... +func GetTrustlists(cfg config.Config) (res []string, err error) { + var w = Cfg{Key: "trustlist"} if exists, _ := cfg.Db.Get(&w); exists { res = strings.Split(w.Value, ",") } return } -func (wl Whitelist) InsertOrUpdate(cfg config.Config) (err error) { - var w = Cfg{Key: "whitelist"} +func (wl Trustlist) InsertOrUpdate(cfg config.Config) (err error) { + var w = Cfg{Key: "trustlist"} exists, _ := cfg.Db.Get(&w) if exists { - existing, _ := GetWhitelists(cfg) + existing, _ := GetTrustlists(cfg) for _, j := range existing { if j == wl.IP { return fmt.Errorf("ip %s already in config", j) @@ -34,15 +34,15 @@ func (wl Whitelist) InsertOrUpdate(cfg config.Config) (err error) { w.Value = strings.Join(existing, ",") cfg.Db.ID(w.ID).Update(&w) } - return fmt.Errorf("no whitelist updated") + return fmt.Errorf("no trustlist updated") } -func (wl Whitelist) Delete(cfg config.Config, ip string) (err error) { - var w = Cfg{Key: "whitelist"} +func (wl Trustlist) Delete(cfg config.Config, ip string) (err error) { + var w = Cfg{Key: "trustlist"} exists, _ := cfg.Db.Get(&w) var updated []string if exists { - existing, _ := GetWhitelists(cfg) + existing, _ := GetTrustlists(cfg) for _, sip := range existing { if sip != ip { updated = append(updated, sip) @@ -51,15 +51,15 @@ func (wl Whitelist) Delete(cfg config.Config, ip string) (err error) { w.Value = strings.Join(updated, ",") cfg.Db.ID(w.ID).Update(&w) } - return fmt.Errorf("no whitelist updated") + return fmt.Errorf("no trustlist updated") } -func (wl Whitelist) Verify() bool { +func (wl Trustlist) Verify() bool { reg := regexp.MustCompile(ipv4_cidr_regex) return reg.MatchString(wl.IP) } -type Whitelist struct { +type Trustlist struct { IP string `json:"ip"` } diff --git a/src/routers/funcs.go b/src/routers/funcs.go index dac7313..d668d3b 100644 --- a/src/routers/funcs.go +++ b/src/routers/funcs.go @@ -18,7 +18,7 @@ func RegisterRoutes(e *echo.Echo, ctx *context.Context, cfg *config.Config) { e.GET("/", func(c echo.Context) error { return c.HTML(http.StatusOK, ` -

Welcome to ipbl software (https://git.paulbsd.com/paulbsd/ipbl)

+

Welcome to ipbl software (https://git.paulbsd.com/paulbsd/ipbl)

`) }) @@ -72,21 +72,25 @@ func RegisterRoutes(e *echo.Echo, ctx *context.Context, cfg *config.Config) { } numinsert, numupdate, _, _ := models.InsertIPBulk(cfg, &ips) if numinsert > 0 { - msg = fmt.Sprintf("Inserted %d IP", numinsert) + msg = fmt.Sprintf("inserted %d IP", numinsert) log.Println(msg) } if numupdate > 0 { - msg = fmt.Sprintf("Updated %d IP", numupdate) + if len(msg) > 0 { + msg = fmt.Sprintf("%s, updated %d IP", msg, numupdate) + } else { + msg = fmt.Sprintf("updated %d IP", numupdate) + } log.Println(msg) } return Result(c, err, msg) }) - e.GET("/ips/whitelist", func(c echo.Context) (err error) { - whitelists, err := models.GetWhitelists(*cfg) - return Result(c, err, whitelists) + e.GET("/ips/trustlist", func(c echo.Context) (err error) { + trustlists, err := models.GetTrustlists(*cfg) + return Result(c, err, trustlists) }) - e.POST("/ips/whitelist", func(c echo.Context) (err error) { - var cidr models.Whitelist + e.POST("/ips/trustlist", func(c echo.Context) (err error) { + var cidr models.Trustlist err = c.Bind(&cidr) if err == nil && cidr.Verify() { err = cidr.InsertOrUpdate(*cfg) @@ -94,9 +98,9 @@ func RegisterRoutes(e *echo.Echo, ctx *context.Context, cfg *config.Config) { } return Result(c, err, nil) }) - e.DELETE("/ips/whitelist/:ip", func(c echo.Context) (err error) { + e.DELETE("/ips/trustlist/:ip", func(c echo.Context) (err error) { var ip = c.Param("ip") - var cidr models.Whitelist + var cidr models.Trustlist err = cidr.Delete(*cfg, ip) if err != nil { return c.JSON(http.StatusOK, "Deleted old CIDR")