Logs and comments

This commit is contained in:
aceberg 2022-08-24 00:10:55 +07:00
parent cc278e9e92
commit 7d93c1973a
6 changed files with 28 additions and 33 deletions

View file

@ -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)
dev: docker-build docker-run

View file

@ -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"

View file

@ -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)...)
}

View file

@ -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!")
}
}

View file

@ -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
}

View file

@ -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
}