From 79866698f11d3d3504ddb6786e3980df70ad9774 Mon Sep 17 00:00:00 2001 From: aceberg <1502200+aceberg@users.noreply.github.com> Date: Mon, 26 Jun 2023 21:21:29 +0700 Subject: [PATCH] local node modules option --- Makefile | 3 +-- cmd/WatchYourLAN/main.go | 7 +++---- internal/models/models.go | 2 +- internal/web/config.go | 16 ---------------- internal/web/templates/config.html | 5 +---- internal/web/templates/header.html | 8 +++----- internal/web/webgui.go | 10 ++-------- 7 files changed, 11 insertions(+), 40 deletions(-) diff --git a/Makefile b/Makefile index 1c9efd1..6237689 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,6 @@ DNAME=watchyourlan IFACE=enp4s0 DBPATH=/data/hosts.db SHOUTRRR_URL=gotify://192.168.2.1:8083/AwQqpAae.rrl5Ob/?title=Unknown host detected&DisableTLS=yes -THEME=darkly mod: rm go.mod || true && \ @@ -16,7 +15,7 @@ run: cd cmd/WatchYourLAN/ && \ sudo \ env IFACE=$(IFACE) DBPATH=$(DBPATH) THEME=$(THEME) \ - go run . + go run . #-n http://192.168.2.3:8850 fmt: go fmt ./... diff --git a/cmd/WatchYourLAN/main.go b/cmd/WatchYourLAN/main.go index a07fa87..fd023e7 100644 --- a/cmd/WatchYourLAN/main.go +++ b/cmd/WatchYourLAN/main.go @@ -8,15 +8,14 @@ import ( ) const configPath = "/data/config" - -const bootPath = "" +const nodePath = "" func main() { confPtr := flag.String("c", configPath, "Path to config file") - bootPtr := flag.String("b", bootPath, "Path to local Bootswatch") + nodePtr := flag.String("n", nodePath, "Path to node modules") flag.Parse() check.Path(*confPtr) - web.Gui(*confPtr, *bootPtr) // Start web GUI + web.Gui(*confPtr, *nodePtr) // Start web GUI } diff --git a/internal/models/models.go b/internal/models/models.go index 1a2c485..b603365 100644 --- a/internal/models/models.go +++ b/internal/models/models.go @@ -24,7 +24,7 @@ type Conf struct { Color string IgnoreIP string LogLevel string - BootPath string + NodePath string Icon string } diff --git a/internal/web/config.go b/internal/web/config.go index 9138d76..829ba38 100644 --- a/internal/web/config.go +++ b/internal/web/config.go @@ -1,13 +1,10 @@ package web import ( - "io" "log" "net/http" "strconv" - "github.com/tidwall/gjson" - "github.com/aceberg/WatchYourLAN/internal/check" "github.com/aceberg/WatchYourLAN/internal/conf" "github.com/aceberg/WatchYourLAN/internal/db" @@ -27,19 +24,6 @@ func configHandler(w http.ResponseWriter, r *http.Request) { version := string(file) guiData.Version = version[8:] - url := "https://api.github.com/repos/aceberg/WatchYourLAN/releases/latest" - req, err := http.Get(url) - check.IfError(err) - - defer req.Body.Close() - - body, err := io.ReadAll(req.Body) - check.IfError(err) - - bodyStr := string(body) - release := gjson.Get(bodyStr, "tag_name") - guiData.Release = release.String() - guiData.Themes = []string{"cerulean", "cosmo", "cyborg", "darkly", "flatly", "journal", "litera", "lumen", "lux", "materia", "minty", "morph", "pulse", "quartz", "sandstone", "simplex", "sketchy", "slate", "solar", "spacelab", "superhero", "united", "vapor", "yeti", "zephyr"} execTemplate(w, "config", guiData) diff --git a/internal/web/templates/config.html b/internal/web/templates/config.html index ed52492..07c4f75 100644 --- a/internal/web/templates/config.html +++ b/internal/web/templates/config.html @@ -79,10 +79,7 @@
Current version: {{ .Version }}; Latest version: {{ .Release }}
- {{ if ne .Version .Release }} -Update available!
- {{ end }} +Current version: {{ .Version }}
● There can be one or more Interfaces, space separated
● After changing Host, Port or Path to DB you need to restart the app
diff --git a/internal/web/templates/header.html b/internal/web/templates/header.html index faa58f3..636abab 100644 --- a/internal/web/templates/header.html +++ b/internal/web/templates/header.html @@ -5,16 +5,14 @@ - {{ if eq .Config.BootPath "" }} + {{ if eq .Config.NodePath "" }} {{ else }} - - - - + + {{ end }} diff --git a/internal/web/webgui.go b/internal/web/webgui.go index 14d958f..b3f92aa 100644 --- a/internal/web/webgui.go +++ b/internal/web/webgui.go @@ -11,11 +11,11 @@ import ( ) // Gui - start web GUI -func Gui(configPath, bootPath string) { +func Gui(configPath, nodePath string) { ConfigPath = configPath AppConfig = conf.Get(ConfigPath) - AppConfig.BootPath = bootPath + AppConfig.NodePath = nodePath AppConfig.Icon = Icon address := AppConfig.GuiIP + ":" + AppConfig.GuiPort @@ -28,12 +28,6 @@ func Gui(configPath, bootPath string) { AllHosts = db.Select(AppConfig.DbPath) - if AppConfig.BootPath != "" { - fs := http.FileServer(http.Dir(AppConfig.BootPath)) - http.Handle("/css/", http.StripPrefix("/css", fs)) - // http.Handle("/css/", http.FileServer(http.Dir(AppConfig.BootPath))) - } - log.Println("=================================== ") log.Printf("Web GUI at http://%s", address) log.Println("=================================== ")