diff --git a/README.md b/README.md index 1a97e7e..5f8a7a3 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,7 @@ Configuration can be done through config file, GUI or environment variables. Var | TZ | Set your timezone for correct time | | | HOST | Listen address | 0.0.0.0 | | PORT | Port for web GUI | 8840 | +| BASE_PATH | Optional web path prefix for UI and API (no trailing slash) | | | THEME | Any theme name from https://bootswatch.com in lowcase or [additional](https://github.com/aceberg/aceberg-bootswatch-fork) | sand | | COLOR | Background color: light or dark | dark | | NODEPATH | Path to local node modules | | @@ -138,6 +139,7 @@ Config file name is `config_v2.yaml`. Example: ```yaml arp_args: "" +base_path: "" color: dark host: 0.0.0.0 ifaces: enp4s0 diff --git a/backend/internal/api/config.go b/backend/internal/api/config.go index 9f1999c..d7aaecb 100644 --- a/backend/internal/api/config.go +++ b/backend/internal/api/config.go @@ -3,6 +3,7 @@ package api import ( "net/http" "strconv" + "strings" "github.com/gin-gonic/gin" @@ -20,6 +21,9 @@ func saveConfigHandler(c *gin.Context) { conf.AppConfig.NodePath = c.PostForm("node") conf.AppConfig.ShoutURL = c.PostForm("shout") + basePath := c.PostForm("basepath") + conf.AppConfig.BasePath = strings.TrimRight(basePath, "/") + conf.Write(conf.AppConfig) c.Redirect(http.StatusFound, c.Request.Referer()) diff --git a/backend/internal/api/routes.go b/backend/internal/api/routes.go index f27223a..b2205ce 100644 --- a/backend/internal/api/routes.go +++ b/backend/internal/api/routes.go @@ -8,7 +8,7 @@ import ( ) // Routes - start API routes -func Routes(router *gin.Engine) { +func Routes(router gin.IRouter) { r0 := router.Group("/api") { diff --git a/backend/internal/conf/read.go b/backend/internal/conf/read.go index 6f5d0ae..23d98a3 100644 --- a/backend/internal/conf/read.go +++ b/backend/internal/conf/read.go @@ -13,6 +13,7 @@ func read(path string) (config models.Conf) { viper.SetDefault("HOST", "0.0.0.0") viper.SetDefault("PORT", "8840") + viper.SetDefault("BASE_PATH", "") viper.SetDefault("THEME", "sand") viper.SetDefault("COLOR", "dark") viper.SetDefault("NODEPATH", "") @@ -40,6 +41,7 @@ func read(path string) (config models.Conf) { config.Host = viper.Get("HOST").(string) config.Port = viper.Get("PORT").(string) + config.BasePath = strings.Trim(viper.GetString("BASE_PATH"), "/") config.Theme = viper.Get("THEME").(string) config.Color = viper.Get("COLOR").(string) config.NodePath = viper.Get("NODEPATH").(string) diff --git a/backend/internal/conf/write.go b/backend/internal/conf/write.go index 201ecb9..d6acdb2 100644 --- a/backend/internal/conf/write.go +++ b/backend/internal/conf/write.go @@ -19,6 +19,7 @@ func Write(config models.Conf) { viper.Set("HOST", config.Host) viper.Set("PORT", config.Port) + viper.Set("BASE_PATH", "") // Can be set only with ENV viper.Set("THEME", config.Theme) viper.Set("COLOR", config.Color) viper.Set("NODEPATH", config.NodePath) diff --git a/backend/internal/models/models.go b/backend/internal/models/models.go index 7fcfd16..6e16901 100644 --- a/backend/internal/models/models.go +++ b/backend/internal/models/models.go @@ -4,6 +4,7 @@ package models type Conf struct { Host string Port string + BasePath string Theme string Color string DirPath string diff --git a/backend/internal/web/index.go b/backend/internal/web/index.go index cb4b4ff..7057c49 100644 --- a/backend/internal/web/index.go +++ b/backend/internal/web/index.go @@ -3,10 +3,19 @@ package web import ( "net/http" + "github.com/aceberg/WatchYourLAN/internal/conf" "github.com/gin-gonic/gin" ) func indexHandler(c *gin.Context) { + basePath := "" + if conf.AppConfig.BasePath != "" { + basePath = "/" + conf.AppConfig.BasePath + } - c.HTML(http.StatusOK, "index.html", true) + data := gin.H{ + "BasePath": basePath, + } + + c.HTML(http.StatusOK, "index.html", data) } diff --git a/backend/internal/web/public/assets/Config.js b/backend/internal/web/public/assets/Config.js index 894ad64..b683b28 100644 --- a/backend/internal/web/public/assets/Config.js +++ b/backend/internal/web/public/assets/Config.js @@ -1 +1 @@ -import{c as J,o as K,a as X,t,i as r,b,s as H,d as W,e as c,S as V,f as e,F as M,g as Z,h as tt,j as Q}from"./index.js";var et=t('
| Swagger API docs | /swagger/index.html |
| Local node-bootstrap URL | local themes and fonts (optional). If empty, the app will pull everything from cdn |
| 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. Enable debug log level to see resulting command. (Example: -r 1). See docs for more |
| Arp Strings | can setup scans for vlans, docker0 and etcetera. See docs for more |
| Trim History | remove history after (hours) |
| 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');function rt(){const[i,d]=J(""),[s,a]=J("");return K(async()=>{const l=await X();d(l),a("https://github.com/aceberg/WatchYourLAN/releases/tag/"+l)}),(()=>{var l=et(),n=l.firstChild,o=n.firstChild,p=o.nextSibling;return r(p,i),b(()=>H(p,"href",s())),l})()}var lt=t(" |