diff --git a/internal/web/config.go b/internal/web/config.go index d24a85e..a539f0f 100644 --- a/internal/web/config.go +++ b/internal/web/config.go @@ -35,10 +35,20 @@ func saveConfigHandler(c *gin.Context) { appConfig.Theme = c.PostForm("theme") appConfig.Color = c.PostForm("color") appConfig.NodePath = c.PostForm("node") + appConfig.ShoutURL = c.PostForm("shout") + + conf.Write(appConfig) + + slog.Info("Writing new config to " + appConfig.ConfPath) + + c.Redirect(http.StatusFound, "/config") +} + +func saveSettingsHandler(c *gin.Context) { + appConfig.LogLevel = c.PostForm("log") appConfig.ArpArgs = c.PostForm("arpargs") appConfig.Ifaces = c.PostForm("ifaces") - appConfig.ShoutURL = c.PostForm("shout") appConfig.UseDB = c.PostForm("usedb") appConfig.PGConnect = c.PostForm("pgconnect") diff --git a/internal/web/routines-upd.go b/internal/web/routines-upd.go index 7a1c7d5..06eaed7 100644 --- a/internal/web/routines-upd.go +++ b/internal/web/routines-upd.go @@ -7,7 +7,7 @@ import ( ) func updateRoutines() { - slog.Debug("Restarting go routines") + slog.Debug("Restarting scan routine") close(quitScan) diff --git a/internal/web/templates/config.html b/internal/web/templates/config.html index 003468d..1355e6f 100644 --- a/internal/web/templates/config.html +++ b/internal/web/templates/config.html @@ -5,7 +5,7 @@
-
Config
+
Basic config
@@ -35,7 +35,7 @@ - + @@ -44,6 +44,46 @@ + + + + + +
Local node-bootstrap urlLocal node-bootstrap URL
+
+
+ +
+
Scan settings
+
+ + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - @@ -150,16 +163,20 @@ -
+
About (v{{ .Version }})

● After changing Host or Port the app must be restarted

-

Timeout (minutes) - how often watched ports are scanned

-

Trim History - how many port states are saved in memory and displayed on the History page

+

Shoutrrr URL provides notifications to Discord, Email, Gotify, Telegram and other services. Link to documentation

+

Interfaces - one or more, space separated

+

Timeout (seconds) - time between scans

+

Args for arp-scan - pass your own arguments to arp-scan. See man arp-scan for more. Enable debug log level to see resulting command. (Example: -r 1)

+

Trim History (hours) - remove history after

+

PG Connect URL - address to connect to PostgreSQL DB. (Example: postgres://username:password@192.168.0.1:5432/dbname?sslmode=disable). Full list of URL parameters here

● If you find this app useful, please, donate

-

● Commission you own app (Golang, HTML/JS). Contact and prices here

+

● Commission you own app (Golang, HTML/JS). Contact here

diff --git a/internal/web/trim-history.go b/internal/web/trim-history.go new file mode 100644 index 0000000..e1406e4 --- /dev/null +++ b/internal/web/trim-history.go @@ -0,0 +1,42 @@ +package web + +import ( + "log/slog" + "time" + + "github.com/aceberg/WatchYourLAN/internal/db" +) + +func trimHistoryRoutine() { + + for { + trimHistory() + + time.Sleep(time.Duration(1) * time.Hour) // Every hour + } +} + +func trimHistory() { + + hours := appConfig.TrimHist + + nowStr := time.Now().Format("2006-01-02 15:04:05") // This needed so all time is + now, _ := time.Parse("2006-01-02 15:04:05", nowStr) // in one format + nowMinus := now.Add(-time.Duration(hours) * time.Hour) + + history := db.Select("history") + + slog.Info("Removing all History before", "date", nowMinus.Format("2006-01-02 15:04:05")) + + n := 0 + for _, hist := range history { + date, _ := time.Parse("2006-01-02 15:04:05", hist.Date) + + if date.Before(nowMinus) { + n = n + 1 + db.Delete("history", hist.ID) + } + } + + slog.Info("Removed records from History", "n", n) +} diff --git a/internal/web/webgui.go b/internal/web/webgui.go index cbea95b..49107ce 100644 --- a/internal/web/webgui.go +++ b/internal/web/webgui.go @@ -25,7 +25,8 @@ func Gui(dirPath, nodePath string) { appConfig.NodePath = nodePath quitScan = make(chan bool) - updateRoutines() // routines-upd.go + updateRoutines() // routines-upd.go + go trimHistoryRoutine() // trim-history.go slog.Info("Config dir", "path", appConfig.DirPath) @@ -57,8 +58,9 @@ func Gui(dirPath, nodePath string) { router.GET("/host/:id", hostHandler) // host.go router.GET("/config/", configHandler) // config.go - router.POST("/config/", saveConfigHandler) // config.go - router.POST("/config_influx/", saveInfluxHandler) // config.go + router.POST("/config/", saveConfigHandler) // config.go + router.POST("/config_settings/", saveSettingsHandler) // config.go + router.POST("/config_influx/", saveInfluxHandler) // config.go err := router.Run(address) check.IfError(err)
Interfaces
Timeout (seconds)
Args for arp-scan
Trim History (hours)
Log level
Use DB
Log level
Interfaces
Timeout
Args for arp-scan
Trim History (hours)