From 4f66f6fdddd768421593b75878bfdb3dfe789e2f Mon Sep 17 00:00:00 2001 From: Paul Lecuq Date: Tue, 8 Feb 2022 15:32:10 +0100 Subject: [PATCH] skipping duplicates whitelist inserts --- src/models/cfg.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/models/cfg.go b/src/models/cfg.go index ab31568..abec549 100644 --- a/src/models/cfg.go +++ b/src/models/cfg.go @@ -25,6 +25,11 @@ func (wl Whitelist) Insert(cfg config.Config) (err error) { exists, _ := cfg.Db.Get(&w) if exists { existing, _ := GetWhitelists(cfg) + for _, j := range existing { + if j == wl.IP { + return fmt.Errorf("ip %s already in config", j) + } + } existing = append(existing, wl.IP) w.Value = strings.Join(existing, ",") cfg.Db.ID(w.ID).Update(&w)