Skip to content

Commit 64a4b17

Browse files
committed
Release 1.0.4 (#62, #65)
1 parent 0acd987 commit 64a4b17

File tree

9 files changed

+52
-23
lines changed

9 files changed

+52
-23
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
# Change Log
33
All notable changes to this project will be documented in this file.
44

5+
## [v1.0.4] - 2023-10-12
6+
### Added
7+
- Configurable `timeout` for `arp-scan` [#65](https://github.com/aceberg/WatchYourLAN/issues/65)
8+
59
## [v1.0.3] - 2023-10-08
610
### Fixed
711
- Github Action workflow for binary release

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Configuration can be done through config file or environment variables
4141

4242
| Variable | Description | Default |
4343
| -------- | ----------- | ------- |
44+
| ARP_TIMEOUT | Per host timeout for <b>arp-scan</b> (in milliseconds) | 500 |
4445
| AUTH | Enable Session-Cookie authentication | false |
4546
| AUTH_EXPIRE | Session expiration time. A number and suffix: **m, h, d** or **M**. | 7d |
4647
| AUTH_USER | Username | "" |

internal/conf/config.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ func Get(path string) (config models.Conf, authConf auth.Conf) {
2121
viper.SetDefault("COLOR", "light")
2222
viper.SetDefault("IGNOREIP", "no")
2323
viper.SetDefault("LOGLEVEL", "verbose")
24+
viper.SetDefault("HISTORY_DAYS", "30")
25+
viper.SetDefault("ARP_TIMEOUT", "500")
26+
2427
viper.SetDefault("AUTH_USER", "")
2528
viper.SetDefault("AUTH_PASSWORD", "")
2629
viper.SetDefault("AUTH_EXPIRE", "7d")
27-
viper.SetDefault("HISTORY_DAYS", "30")
2830

2931
viper.SetConfigFile(path)
3032
viper.SetConfigType("yaml")
@@ -44,6 +46,8 @@ func Get(path string) (config models.Conf, authConf auth.Conf) {
4446
config.IgnoreIP = viper.Get("IGNOREIP").(string)
4547
config.LogLevel = viper.Get("LOGLEVEL").(string)
4648
config.HistDays = viper.Get("HISTORY_DAYS").(string)
49+
config.ArpTimeout = viper.Get("ARP_TIMEOUT").(string)
50+
4751
authConf.Auth = viper.GetBool("AUTH")
4852
authConf.User, _ = viper.Get("AUTH_USER").(string)
4953
authConf.Password, _ = viper.Get("AUTH_PASSWORD").(string)
@@ -72,6 +76,7 @@ func Write(path string, config models.Conf, authConf auth.Conf) {
7276
viper.Set("IGNOREIP", config.IgnoreIP)
7377
viper.Set("LOGLEVEL", config.LogLevel)
7478
viper.Set("HISTORY_DAYS", config.HistDays)
79+
viper.Set("ARP_TIMEOUT", config.ArpTimeout)
7580

7681
viper.Set("auth", authConf.Auth)
7782
viper.Set("auth_user", authConf.User)

internal/models/models.go

+15-14
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,21 @@ import (
66

77
// Conf - app config
88
type Conf struct {
9-
Iface string
10-
DbPath string
11-
GuiIP string
12-
GuiPort string
13-
Timeout int
14-
ShoutURL string
15-
Theme string
16-
Color string
17-
IgnoreIP string
18-
LogLevel string
19-
NodePath string
20-
Icon string
21-
Auth bool
22-
HistDays string
9+
Iface string
10+
DbPath string
11+
GuiIP string
12+
GuiPort string
13+
Timeout int
14+
ShoutURL string
15+
Theme string
16+
Color string
17+
IgnoreIP string
18+
LogLevel string
19+
NodePath string
20+
Icon string
21+
Auth bool
22+
HistDays string
23+
ArpTimeout string
2324
}
2425

2526
// Host - one host

internal/scan/arpscan.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
)
1111

1212
func scanIface(iface string) string {
13-
cmd, err := exec.Command("arp-scan", "-glNx", "-I", iface).Output()
13+
cmd, err := exec.Command("arp-scan", "-glNx", "-t", appConfig.ArpTimeout, "-I", iface).Output()
1414
if err != nil {
1515
return string("")
1616
}
@@ -40,15 +40,15 @@ func parseOutput(text string) []models.Host {
4040
}
4141

4242
// Scan all interfaces
43-
func arpScan(allIfaces string, logLevel string) []models.Host {
43+
func arpScan() []models.Host {
4444
var text string
4545
var foundHosts = []models.Host{}
4646

47-
perString := strings.Split(allIfaces, " ")
47+
perString := strings.Split(appConfig.Iface, " ")
4848

4949
for _, iface := range perString {
5050
text = scanIface(iface)
51-
if logLevel != "short" {
51+
if appConfig.LogLevel != "short" {
5252
log.Println("INFO: scanning interface", iface)
5353
log.Println("INFO: found IPs:", text)
5454
}

internal/scan/start.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func Start(config models.Conf, quit chan bool) {
2828
plusDate := lastDate.Add(time.Duration(appConfig.Timeout) * time.Second)
2929

3030
if nowDate.After(plusDate) {
31-
structHosts = arpScan(appConfig.Iface, appConfig.LogLevel) // arpscan.go
31+
structHosts = arpScan() // arpscan.go
3232
dbHosts = db.Select(appConfig.DbPath)
3333

3434
toMap()

internal/web/config.go

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ func saveConfigHandler(w http.ResponseWriter, r *http.Request) {
4242
AppConfig.IgnoreIP = r.FormValue("ignoreip")
4343
AppConfig.LogLevel = r.FormValue("loglevel")
4444
AppConfig.HistDays = r.FormValue("history")
45+
AppConfig.ArpTimeout = r.FormValue("arp_timeout")
4546

4647
timeout := r.FormValue("timeout")
4748
AppConfig.Timeout, err = strconv.Atoi(timeout)

internal/web/templates/config.html

+19-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
</tr>
2525
<tr>
2626
<td>Timeout (seconds)</td>
27-
<td><input name="timeout" type="text" class="form-control" value="{{ .Config.Timeout }}"></td>
27+
<td><input name="timeout" type="number" class="form-control" value="{{ .Config.Timeout }}"></td>
2828
</tr>
2929
<tr>
3030
<td>Shoutrrr URL</td>
@@ -71,7 +71,23 @@
7171
</tr>
7272
<tr>
7373
<td>Keep history (days)</td>
74-
<td><input name="history" type="text" class="form-control" value="{{ .Config.HistDays }}"></td>
74+
<td><input name="history" type="number" class="form-control" value="{{ .Config.HistDays }}"></td>
75+
</tr>
76+
<tr>
77+
<td>Arp Timeout</td>
78+
<td>
79+
<select name="arp_timeout" class="form-select">
80+
<option selected value="{{ .Config.ArpTimeout }}">{{ .Config.ArpTimeout }}</option>
81+
<option value="100">100</option>
82+
<option value="250">250</option>
83+
<option value="500">500</option>
84+
<option value="1000">1000</option>
85+
<option value="1500">1500</option>
86+
<option value="2000">2000</option>
87+
<option value="3000">3000</option>
88+
<option value="5000">5000</option>
89+
</select>
90+
</td>
7591
</tr>
7692
<tr>
7793
<td><button type="submit" class="btn btn-primary">Save</button></td>
@@ -92,6 +108,7 @@
92108
<p>● If you want to detect unknown hosts by MAC only, set <b>Ignore IP</b> to "yes"</p>
93109
<p><b>Log Level</b> defines how much log output you want to see</p>
94110
<p>● The <b>Clear table</b> button below will delete all records from table. If you want to delete a single host, click on its MAC and press <b>Delete host</b> button</p>
111+
<p><b>Arp Timeout</b> per host timeout for <b>arp-scan</b> (in milliseconds). Default: 500</p>
95112
</div>
96113
<br>
97114
<form action="/clear/" method="post">

internal/web/templates/version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION=1.0.3
1+
VERSION=1.0.4

0 commit comments

Comments
 (0)