diff --git a/CHANGELOG.md b/CHANGELOG.md
index 09de4f2..dc2c8be 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file.
## [v2.0.1] - 2024-09-01
### Added
+- Vlans and docker0 support [#47](https://github.com/aceberg/WatchYourLAN/issues/47). Thanks [thehijacker](https://github.com/thehijacker) for help with this issue!
- Remember `sort` field
- InfluxDB error handling
diff --git a/README.md b/README.md
index 1324937..290e206 100644
--- a/README.md
+++ b/README.md
@@ -73,9 +73,10 @@ Configuration can be done through config file, GUI or environment variables
### Scan settings
| Variable | Description | Default |
| -------- | ----------- | ------- |
-| IFACES | Interfaces to scan. Could be one or more, separated by space. Currently `docker0` is not supported, as `arp-scan` wouldn't work with it correctly | |
+| IFACES | Interfaces to scan. Could be one or more, separated by space. See [docs/VLAN_ARP_SCAN.md](https://github.com/aceberg/WatchYourLAN/blob/main/docs/VLAN_ARP_SCAN.md). | |
| TIMEOUT | Time between scans (seconds) | 120 |
-| ARP_ARGS | Arguments for `arp-scan`. See `man arp-scan` for more. Enable `debug` log level to see resulting command. (Example: `-r 1`) | |
+| ARP_ARGS | Arguments for `arp-scan`. Enable `debug` log level to see resulting command. (Example: `-r 1`). See [docs/VLAN_ARP_SCAN.md](https://github.com/aceberg/WatchYourLAN/blob/main/docs/VLAN_ARP_SCAN.md). | |
+| ARP_STRS ARP_STRS_JOINED | See [docs/VLAN_ARP_SCAN.md](https://github.com/aceberg/WatchYourLAN/blob/main/docs/VLAN_ARP_SCAN.md). | |
| LOG_LEVEL | Log level: `debug`, `info`, `warn` or `error` | info |
| TRIM_HIST | Remove history after (hours) | 48 |
| HIST_IN_DB | Store History in DB - if `false`, the History will be stored only in memory and will be lost on app restart. Though, it will keep the app DB smaller (and InfluxDB is recommended for long term History storage) | false |
@@ -168,7 +169,7 @@ Or use [docker-compose](docker-compose-local.yml)
Expand
-Moved to [docs/API.md](./docs/API.md)
+Moved to [docs/API.md](https://github.com/aceberg/WatchYourLAN/blob/main/docs/API.md)
## Thanks
diff --git a/docs/VLAN_ARP_SCAN.md b/docs/VLAN_ARP_SCAN.md
index ff33f4a..0c811f3 100644
--- a/docs/VLAN_ARP_SCAN.md
+++ b/docs/VLAN_ARP_SCAN.md
@@ -2,7 +2,7 @@
### 1. IFACES
-`IFACES` is a required variable for WYL to work. It can be set through GUI, config file or environment variables.
+`IFACES` is a required variable for WYL to work. It can be set through `GUI`, config file or environment variables.
`IFACES` is a list of network interfaces to scan, space separated. For example
```sh
IFACES: "enp4s0 wlxf4ec3892dd51"
@@ -14,7 +14,7 @@ arp-scan -glNx -I $ONE_IFACE
```
### 2. ARP_ARGS
-Setting `ARP_ARGS` is optional. It can be set through GUI, config file or environment variables.
+Setting `ARP_ARGS` is optional. It can be set through `GUI`, config file or environment variables.
`ARP_ARGS` is additional arguments for `arp-scan`, that will be applied for **every** one of `IFACES`. For example:
```sh
ARP_ARGS: "-r 1"
@@ -25,10 +25,10 @@ arp-scan -glNx -r 1 -I $ONE_IFACE
See `man arp-scan` for all arguments available.
-### 3. ARP_STRS
+### 3. ARP_STRS for VLANs, docker0 and other complicated scans
If `ARP_STRS` is set, it will initiate a completely separate from `IFACES` scan.
> [!WARNING]
-> `ARP_STRS` can be set only through GUI or config file. For environment (docker-compose) see `ARP_STRS_JOINED`.
+> `ARP_STRS` can be set only through `GUI` or config file. For environment (docker-compose) see `ARP_STRS_JOINED`.
`ARP_STRS` is a list of strings. `arp-scan` will run for each of them:
```sh
@@ -40,8 +40,27 @@ arp-scan -gNx 10.0.107.0/24 -Q 107 -I eth0
```
Where `-Q` is a `vlan` id. **Warning:** the last element of string (`eth0` in this example) will be set as `Interface` for found hosts, so it is recommended to put interface at the end.
+
+Setting `ARP_STRS` from config file:
+```yaml
+arp_strs:
+ - -gNx 172.17.0.1/24 -I docker0
+ - -glNx -I virbr0
+```
+From `GUI` put one string in `Arp Strings` input field, click `Save`, then another empty string will appear.
+
### 4. ARP_STRS_JOINED
`ARP_STRS_JOINED` is a way to set `ARP_STRS` from ENV. It's a list of strings, comma separated, without spaces before or after comma.
```sh
-ARP_STRS_JOINED: "-glNx -I enp1s0,-glNx -I enp1s0"
+ARP_STRS_JOINED: "-gNx 172.17.0.1/24 -I docker0,-gNx 10.0.107.0/24 -Q 107 -I eth0"
+```
+
+### 5. Examples
+vlan id 107
+```sh
+ARP_STRS_JOINED: "-gNx 10.0.107.0/24 -Q 107 -I eth0"
+```
+docker0
+```sh
+ARP_STRS_JOINED: "-gNx 172.17.0.1/24 -I docker0"
```
\ No newline at end of file
diff --git a/internal/web/functions.go b/internal/web/functions.go
index 87c116d..9f9b9e8 100644
--- a/internal/web/functions.go
+++ b/internal/web/functions.go
@@ -2,6 +2,7 @@ package web
import (
"net"
+ "slices"
"strconv"
"strings"
@@ -45,3 +46,13 @@ func getHostsByMAC(mac string, hosts []models.Host) (foundHosts []models.Host) {
return foundHosts
}
+
+func getAllIfaces(hosts []models.Host) (ifaces []string) {
+
+ for _, host := range hosts {
+ if !slices.Contains(ifaces, host.Iface) {
+ ifaces = append(ifaces, host.Iface)
+ }
+ }
+ return ifaces
+}
diff --git a/internal/web/index.go b/internal/web/index.go
index 020e0dc..473bed1 100644
--- a/internal/web/index.go
+++ b/internal/web/index.go
@@ -2,7 +2,6 @@ package web
import (
"net/http"
- "strings"
"github.com/gin-gonic/gin"
@@ -12,7 +11,7 @@ import (
func indexHandler(c *gin.Context) {
var guiData models.GuiData
guiData.Config = appConfig
- guiData.Themes = strings.Split(appConfig.Ifaces, " ")
+ guiData.Themes = getAllIfaces(allHosts)
c.HTML(http.StatusOK, "header.html", guiData)
c.HTML(http.StatusOK, "index.html", guiData)
diff --git a/internal/web/public/js/history.js b/internal/web/public/js/history.js
index 33216b2..8599705 100644
--- a/internal/web/public/js/history.js
+++ b/internal/web/public/js/history.js
@@ -26,13 +26,17 @@ async function loadHistory() {
for (let a of addrsArray) {
url = '/api/history/'+a.Mac;
hist = await (await fetch(url)).json();
- hist = sortHistByDate(hist);
- if (show > 0) {
- hist = hist.slice(0, show);
+ if (hist != null) {
+ hist = sortHistByDate(hist);
+
+ if (show > 0) {
+ hist = hist.slice(0, show);
+ }
+
+ td = getHistHTML(hist); // hist-html.js
}
-
- td = getHistHTML(hist); // hist-html.js
+
i = i + 1;
tr = `
diff --git a/internal/web/templates/config.html b/internal/web/templates/config.html
index 746b7d4..463804a 100644
--- a/internal/web/templates/config.html
+++ b/internal/web/templates/config.html
@@ -1,5 +1,5 @@
{{ define "config.html" }}
-
+
@@ -191,7 +191,8 @@
● 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)
+
● 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)
● Store History in DB - if off, the History will be stored only in memory and will be lost on app restart. Though, it will keep the app DB smaller and InfluxDB is recommended for long term History storage
● 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