Skip to content

Commit

Permalink
Release 1.0.4 (#62, #65)
Browse files Browse the repository at this point in the history
  • Loading branch information
aceberg committed Oct 12, 2023
1 parent 0acd987 commit 64a4b17
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 23 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
# Change Log
All notable changes to this project will be documented in this file.

## [v1.0.4] - 2023-10-12
### Added
- Configurable `timeout` for `arp-scan` [#65](https://github.com/aceberg/WatchYourLAN/issues/65)

## [v1.0.3] - 2023-10-08
### Fixed
- Github Action workflow for binary release
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Configuration can be done through config file or environment variables

| Variable | Description | Default |
| -------- | ----------- | ------- |
| ARP_TIMEOUT | Per host timeout for <b>arp-scan</b> (in milliseconds) | 500 |
| AUTH | Enable Session-Cookie authentication | false |
| AUTH_EXPIRE | Session expiration time. A number and suffix: **m, h, d** or **M**. | 7d |
| AUTH_USER | Username | "" |
Expand Down
7 changes: 6 additions & 1 deletion internal/conf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ func Get(path string) (config models.Conf, authConf auth.Conf) {
viper.SetDefault("COLOR", "light")
viper.SetDefault("IGNOREIP", "no")
viper.SetDefault("LOGLEVEL", "verbose")
viper.SetDefault("HISTORY_DAYS", "30")
viper.SetDefault("ARP_TIMEOUT", "500")

viper.SetDefault("AUTH_USER", "")
viper.SetDefault("AUTH_PASSWORD", "")
viper.SetDefault("AUTH_EXPIRE", "7d")
viper.SetDefault("HISTORY_DAYS", "30")

viper.SetConfigFile(path)
viper.SetConfigType("yaml")
Expand All @@ -44,6 +46,8 @@ func Get(path string) (config models.Conf, authConf auth.Conf) {
config.IgnoreIP = viper.Get("IGNOREIP").(string)
config.LogLevel = viper.Get("LOGLEVEL").(string)
config.HistDays = viper.Get("HISTORY_DAYS").(string)
config.ArpTimeout = viper.Get("ARP_TIMEOUT").(string)

authConf.Auth = viper.GetBool("AUTH")
authConf.User, _ = viper.Get("AUTH_USER").(string)
authConf.Password, _ = viper.Get("AUTH_PASSWORD").(string)
Expand Down Expand Up @@ -72,6 +76,7 @@ func Write(path string, config models.Conf, authConf auth.Conf) {
viper.Set("IGNOREIP", config.IgnoreIP)
viper.Set("LOGLEVEL", config.LogLevel)
viper.Set("HISTORY_DAYS", config.HistDays)
viper.Set("ARP_TIMEOUT", config.ArpTimeout)

viper.Set("auth", authConf.Auth)
viper.Set("auth_user", authConf.User)
Expand Down
29 changes: 15 additions & 14 deletions internal/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@ import (

// Conf - app config
type Conf struct {
Iface string
DbPath string
GuiIP string
GuiPort string
Timeout int
ShoutURL string
Theme string
Color string
IgnoreIP string
LogLevel string
NodePath string
Icon string
Auth bool
HistDays string
Iface string
DbPath string
GuiIP string
GuiPort string
Timeout int
ShoutURL string
Theme string
Color string
IgnoreIP string
LogLevel string
NodePath string
Icon string
Auth bool
HistDays string
ArpTimeout string
}

// Host - one host
Expand Down
8 changes: 4 additions & 4 deletions internal/scan/arpscan.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

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

// Scan all interfaces
func arpScan(allIfaces string, logLevel string) []models.Host {
func arpScan() []models.Host {
var text string
var foundHosts = []models.Host{}

perString := strings.Split(allIfaces, " ")
perString := strings.Split(appConfig.Iface, " ")

for _, iface := range perString {
text = scanIface(iface)
if logLevel != "short" {
if appConfig.LogLevel != "short" {
log.Println("INFO: scanning interface", iface)
log.Println("INFO: found IPs:", text)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/scan/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func Start(config models.Conf, quit chan bool) {
plusDate := lastDate.Add(time.Duration(appConfig.Timeout) * time.Second)

if nowDate.After(plusDate) {
structHosts = arpScan(appConfig.Iface, appConfig.LogLevel) // arpscan.go
structHosts = arpScan() // arpscan.go
dbHosts = db.Select(appConfig.DbPath)

toMap()
Expand Down
1 change: 1 addition & 0 deletions internal/web/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func saveConfigHandler(w http.ResponseWriter, r *http.Request) {
AppConfig.IgnoreIP = r.FormValue("ignoreip")
AppConfig.LogLevel = r.FormValue("loglevel")
AppConfig.HistDays = r.FormValue("history")
AppConfig.ArpTimeout = r.FormValue("arp_timeout")

timeout := r.FormValue("timeout")
AppConfig.Timeout, err = strconv.Atoi(timeout)
Expand Down
21 changes: 19 additions & 2 deletions internal/web/templates/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</tr>
<tr>
<td>Timeout (seconds)</td>
<td><input name="timeout" type="text" class="form-control" value="{{ .Config.Timeout }}"></td>
<td><input name="timeout" type="number" class="form-control" value="{{ .Config.Timeout }}"></td>
</tr>
<tr>
<td>Shoutrrr URL</td>
Expand Down Expand Up @@ -71,7 +71,23 @@
</tr>
<tr>
<td>Keep history (days)</td>
<td><input name="history" type="text" class="form-control" value="{{ .Config.HistDays }}"></td>
<td><input name="history" type="number" class="form-control" value="{{ .Config.HistDays }}"></td>
</tr>
<tr>
<td>Arp Timeout</td>
<td>
<select name="arp_timeout" class="form-select">
<option selected value="{{ .Config.ArpTimeout }}">{{ .Config.ArpTimeout }}</option>
<option value="100">100</option>
<option value="250">250</option>
<option value="500">500</option>
<option value="1000">1000</option>
<option value="1500">1500</option>
<option value="2000">2000</option>
<option value="3000">3000</option>
<option value="5000">5000</option>
</select>
</td>
</tr>
<tr>
<td><button type="submit" class="btn btn-primary">Save</button></td>
Expand All @@ -92,6 +108,7 @@
<p>● If you want to detect unknown hosts by MAC only, set <b>Ignore IP</b> to "yes"</p>
<p><b>Log Level</b> defines how much log output you want to see</p>
<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>
<p><b>Arp Timeout</b> per host timeout for <b>arp-scan</b> (in milliseconds). Default: 500</p>
</div>
<br>
<form action="/clear/" method="post">
Expand Down
2 changes: 1 addition & 1 deletion internal/web/templates/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION=1.0.3
VERSION=1.0.4

0 comments on commit 64a4b17

Please sign in to comment.