Skip to content

Commit

Permalink
Ignore IP change Issue #25
Browse files Browse the repository at this point in the history
  • Loading branch information
aceberg committed Jan 2, 2023
1 parent 5243138 commit 2497cd1
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION=0.8.1
VERSION=0.8.2
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [v0.8.2] - 2023-01-02
### Added
- Option to ignore IP change [Issue #25](https://github.com/aceberg/WatchYourLAN/issues/25)


## [v0.8.1] - 2022-12-29
### Changed
- Full code refactoring
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Configuration can be done through config file or environment variables
| TIMEOUT | Time between scans (seconds) | 60 (1 minute) |
| SHOUTRRR_URL | Url to any notification service supported by [Shoutrrr](https://github.com/containrrr/shoutrrr) (gotify, email, telegram and others) | "" |
| THEME | Any theme name from https://bootswatch.com in lowcase | solar |
| IGNOREIP | If you want to detect unknown hosts by MAC only, set this wariable to "yes" | no |

## Config file

Expand Down
3 changes: 3 additions & 0 deletions internal/conf/get-config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func Get(path string) (config models.Conf) {
viper.SetDefault("TIMEOUT", "60")
viper.SetDefault("SHOUTRRR_URL", "")
viper.SetDefault("THEME", "solar")
viper.SetDefault("IGNOREIP", "no")

viper.SetConfigFile(path)
viper.SetConfigType("env")
Expand All @@ -31,6 +32,7 @@ func Get(path string) (config models.Conf) {
config.Timeout = viper.GetInt("TIMEOUT")
config.ShoutURL = viper.Get("SHOUTRRR_URL").(string)
config.Theme = viper.Get("THEME").(string)
config.IgnoreIP = viper.Get("IGNOREIP").(string)

return config
}
Expand All @@ -47,6 +49,7 @@ func Write(path string, config models.Conf) {
viper.Set("TIMEOUT", config.Timeout)
viper.Set("SHOUTRRR_URL", config.ShoutURL)
viper.Set("THEME", config.Theme)
viper.Set("IGNOREIP", config.IgnoreIP)

err := viper.WriteConfig()
check.IfError(err)
Expand Down
1 change: 1 addition & 0 deletions internal/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Conf struct {
Timeout int
ShoutURL string
Theme string
IgnoreIP string
}

// GuiData - all data sent to html page
Expand Down
9 changes: 5 additions & 4 deletions internal/scan/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import (
"github.com/aceberg/WatchYourLAN/internal/notify"
)

func hostInDB(path string, host models.Host, dbHosts []models.Host) bool { // Check if host is already in DB
func hostInDB(appConfig models.Conf, host models.Host, dbHosts []models.Host) bool { // Check if host is already in DB
for _, oneHost := range dbHosts {
if host.IP == oneHost.IP && host.Mac == oneHost.Mac && host.Hw == oneHost.Hw {
if host.Mac == oneHost.Mac && (appConfig.IgnoreIP == "yes" || host.IP == oneHost.IP) {
oneHost.IP = host.IP
oneHost.Date = host.Date
oneHost.Now = 1
db.Update(path, oneHost)
db.Update(appConfig.DbPath, oneHost)
return true
}
}
Expand All @@ -23,7 +24,7 @@ func hostInDB(path string, host models.Host, dbHosts []models.Host) bool { // Ch

func hostsCompare(appConfig models.Conf, foundHosts, dbHosts []models.Host) {
for _, oneHost := range foundHosts {
if !(hostInDB(appConfig.DbPath, oneHost, dbHosts)) {
if !(hostInDB(appConfig, oneHost, dbHosts)) {
oneHost.Now = 1 // Mark host online
msg := fmt.Sprintf("UNKNOWN HOST IP: '%s', MAC: '%s', Hw: '%s'", oneHost.IP, oneHost.Mac, oneHost.Hw)
log.Println("WARN:", msg)
Expand Down
1 change: 1 addition & 0 deletions internal/web/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func saveConfigHandler(w http.ResponseWriter, r *http.Request) {
AppConfig.GuiPort = r.FormValue("port")
AppConfig.ShoutURL = r.FormValue("shout")
AppConfig.Theme = r.FormValue("theme")
AppConfig.IgnoreIP = r.FormValue("ignoreip")

timeout := r.FormValue("timeout")
AppConfig.Timeout, err = strconv.Atoi(timeout)
Expand Down
4 changes: 4 additions & 0 deletions internal/web/templates/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
{{ end }}
</select></td>
</tr>
<tr>
<td>Ignore IP</td>
<td><input name="ignoreip" type="text" class="form-control" value="{{ .Config.IgnoreIP }}"></td>
</tr>
<tr>
<td><button type="submit" class="btn btn-primary">Save</button></td>
<td></td>
Expand Down

0 comments on commit 2497cd1

Please sign in to comment.