diff --git a/Makefile b/Makefile index c757235..eeb77f5 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,6 @@ DUSER=aceberg DNAME=watchyourlan -VERSION=0.5 - mod: cd src && \ rm go.mod && \ @@ -18,7 +16,7 @@ go-build: go build . docker-build: - docker build -t $(DUSER)/$(DNAME):latest -t $(DUSER)/$(DNAME):$(VERSION) . + docker build -t $(DUSER)/$(DNAME) . docker-run: docker rm wyl || true @@ -27,14 +25,10 @@ docker-run: -e "TZ=Asia/Novosibirsk" \ --network="host" \ -v ~/.dockerdata/wyl:/data \ - $(DUSER)/$(DNAME):$(VERSION) + $(DUSER)/$(DNAME) clean: rm src/$(DNAME) || true - docker rmi -f $(DUSER)/$(DNAME):latest $(DUSER)/$(DNAME):$(VERSION) + docker rmi -f $(DUSER)/$(DNAME) -dev: docker-build docker-run - -docker-push: - docker push $(DUSER)/$(DNAME):latest - docker push $(DUSER)/$(DNAME):$(VERSION) \ No newline at end of file +dev: docker-build docker-run \ No newline at end of file diff --git a/README.md b/README.md index e4cc3bd..a48ecef 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![Docker](https://github.com/aceberg/WatchYourLAN/actions/workflows/docker-publish.yml/badge.svg)](https://github.com/aceberg/WatchYourLAN/actions/workflows/docker-publish.yml) ![Docker Image Size (latest semver)](https://img.shields.io/docker/image-size/aceberg/watchyourlan) -Lightweight local network IP scanner with web gui +Lightweight network IP scanner with web GUI ## Quick start @@ -45,7 +45,7 @@ Configuration can be done through config file or environment variables ## Config file Config file path is `/data/config`. -All variables could be set there. Exmple: +All variables could be set there. Example: ```sh IFACE="enp2s0 wg0" DBPATH="/data/hosts.db" diff --git a/src/arpscan.go b/src/arpscan.go index 9af3c45..f3c4fb7 100644 --- a/src/arpscan.go +++ b/src/arpscan.go @@ -1,7 +1,7 @@ package main import ( - // "fmt" + "log" "os/exec" "strings" "time" @@ -45,7 +45,9 @@ func arp_scan() ([]Host) { perString := strings.Split(AppConfig.Iface, " ") for _, iface := range perString { + log.Println("INFO: scanning interface", iface) text = scan_iface(iface) + log.Println("INFO: found IPs:", text) foundHosts = append(foundHosts, parse_output(text)...) } diff --git a/src/db-edit.go b/src/db-edit.go index 15f66f3..6708fdc 100644 --- a/src/db-edit.go +++ b/src/db-edit.go @@ -2,12 +2,13 @@ package main import ( "os" + "log" "fmt" ) func db_create() { if _, err := os.Stat(AppConfig.DbPath); err == nil { - fmt.Println("DB exists") + log.Println("INFO: DB exists") } else { sqlStatement := `CREATE TABLE "now" ( "ID" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE, @@ -20,7 +21,7 @@ func db_create() { "NOW" INTEGER DEFAULT 0 );` db_exec(sqlStatement) - fmt.Println("Table created!") + log.Println("INFO: Table created!") } } diff --git a/src/getconfig.go b/src/getconfig.go index 1eb9960..8756206 100644 --- a/src/getconfig.go +++ b/src/getconfig.go @@ -1,12 +1,11 @@ package main import ( - // "fmt" "github.com/spf13/viper" ) func get_config(path string) (config Conf) { - viper.SetDefault("IFACE", "eth0") + viper.SetDefault("IFACE", "enp1s0") viper.SetDefault("DBPATH", "/data/db.sqlite") viper.SetDefault("GUIIP", "localhost") viper.SetDefault("GUIPORT", "8840") @@ -24,7 +23,5 @@ func get_config(path string) (config Conf) { config.GuiPort = viper.Get("GUIPORT").(string) config.Timeout = viper.GetInt("TIMEOUT") - // fmt.Println(viper.Get("DBPATH")) - return config } \ No newline at end of file diff --git a/src/main.go b/src/main.go index c9fe77f..7f762bd 100644 --- a/src/main.go +++ b/src/main.go @@ -1,7 +1,6 @@ package main import ( - // "fmt" "time" ) @@ -28,24 +27,26 @@ var AppConfig Conf var AllHosts []Host func scan_and_compare() { - for { - foundHosts := arp_scan() - dbHosts := db_select() - db_setnow() - hosts_compare(foundHosts, dbHosts) - + var foundHosts []Host + var dbHosts []Host + for { // Endless + foundHosts = arp_scan() // Scan interfaces + dbHosts = db_select() // Select everything from DB + db_setnow() // Mark hosts in DB as offline + hosts_compare(foundHosts, dbHosts) // Compare hosts online and in DB + // and add them to DB AllHosts = db_select() - // fmt.Println("Refresh") - time.Sleep(time.Duration(AppConfig.Timeout) * time.Second) + time.Sleep(time.Duration(AppConfig.Timeout) * time.Second) // Timeout } } func main() { AllHosts = []Host{} - AppConfig = get_config("./data/config") - db_create() - - go scan_and_compare() + AppConfig = get_config("/data/config") // Get config from Defaults, Config file, Env - webgui() + db_create() // Check if DB exists. Create if not + + go scan_and_compare() + + webgui() // Start web GUI } \ No newline at end of file