Logs and comments
This commit is contained in:
parent
cc278e9e92
commit
7d93c1973a
6 changed files with 28 additions and 33 deletions
12
Makefile
12
Makefile
|
|
@ -1,8 +1,6 @@
|
||||||
DUSER=aceberg
|
DUSER=aceberg
|
||||||
DNAME=watchyourlan
|
DNAME=watchyourlan
|
||||||
|
|
||||||
VERSION=0.5
|
|
||||||
|
|
||||||
mod:
|
mod:
|
||||||
cd src && \
|
cd src && \
|
||||||
rm go.mod && \
|
rm go.mod && \
|
||||||
|
|
@ -18,7 +16,7 @@ go-build:
|
||||||
go build .
|
go build .
|
||||||
|
|
||||||
docker-build:
|
docker-build:
|
||||||
docker build -t $(DUSER)/$(DNAME):latest -t $(DUSER)/$(DNAME):$(VERSION) .
|
docker build -t $(DUSER)/$(DNAME) .
|
||||||
|
|
||||||
docker-run:
|
docker-run:
|
||||||
docker rm wyl || true
|
docker rm wyl || true
|
||||||
|
|
@ -27,14 +25,10 @@ docker-run:
|
||||||
-e "TZ=Asia/Novosibirsk" \
|
-e "TZ=Asia/Novosibirsk" \
|
||||||
--network="host" \
|
--network="host" \
|
||||||
-v ~/.dockerdata/wyl:/data \
|
-v ~/.dockerdata/wyl:/data \
|
||||||
$(DUSER)/$(DNAME):$(VERSION)
|
$(DUSER)/$(DNAME)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm src/$(DNAME) || true
|
rm src/$(DNAME) || true
|
||||||
docker rmi -f $(DUSER)/$(DNAME):latest $(DUSER)/$(DNAME):$(VERSION)
|
docker rmi -f $(DUSER)/$(DNAME)
|
||||||
|
|
||||||
dev: docker-build docker-run
|
dev: docker-build docker-run
|
||||||
|
|
||||||
docker-push:
|
|
||||||
docker push $(DUSER)/$(DNAME):latest
|
|
||||||
docker push $(DUSER)/$(DNAME):$(VERSION)
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
[](https://github.com/aceberg/WatchYourLAN/actions/workflows/docker-publish.yml)
|
[](https://github.com/aceberg/WatchYourLAN/actions/workflows/docker-publish.yml)
|
||||||

|

|
||||||
|
|
||||||
Lightweight local network IP scanner with web gui
|
Lightweight network IP scanner with web GUI
|
||||||
|
|
||||||
## Quick start
|
## Quick start
|
||||||
|
|
||||||
|
|
@ -45,7 +45,7 @@ Configuration can be done through config file or environment variables
|
||||||
## Config file
|
## Config file
|
||||||
|
|
||||||
Config file path is `/data/config`.
|
Config file path is `/data/config`.
|
||||||
All variables could be set there. Exmple:
|
All variables could be set there. Example:
|
||||||
```sh
|
```sh
|
||||||
IFACE="enp2s0 wg0"
|
IFACE="enp2s0 wg0"
|
||||||
DBPATH="/data/hosts.db"
|
DBPATH="/data/hosts.db"
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
// "fmt"
|
"log"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -45,7 +45,9 @@ func arp_scan() ([]Host) {
|
||||||
perString := strings.Split(AppConfig.Iface, " ")
|
perString := strings.Split(AppConfig.Iface, " ")
|
||||||
|
|
||||||
for _, iface := range perString {
|
for _, iface := range perString {
|
||||||
|
log.Println("INFO: scanning interface", iface)
|
||||||
text = scan_iface(iface)
|
text = scan_iface(iface)
|
||||||
|
log.Println("INFO: found IPs:", text)
|
||||||
foundHosts = append(foundHosts, parse_output(text)...)
|
foundHosts = append(foundHosts, parse_output(text)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,13 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"log"
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
func db_create() {
|
func db_create() {
|
||||||
if _, err := os.Stat(AppConfig.DbPath); err == nil {
|
if _, err := os.Stat(AppConfig.DbPath); err == nil {
|
||||||
fmt.Println("DB exists")
|
log.Println("INFO: DB exists")
|
||||||
} else {
|
} else {
|
||||||
sqlStatement := `CREATE TABLE "now" (
|
sqlStatement := `CREATE TABLE "now" (
|
||||||
"ID" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
|
"ID" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
|
||||||
|
|
@ -20,7 +21,7 @@ func db_create() {
|
||||||
"NOW" INTEGER DEFAULT 0
|
"NOW" INTEGER DEFAULT 0
|
||||||
);`
|
);`
|
||||||
db_exec(sqlStatement)
|
db_exec(sqlStatement)
|
||||||
fmt.Println("Table created!")
|
log.Println("INFO: Table created!")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,11 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
// "fmt"
|
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
func get_config(path string) (config Conf) {
|
func get_config(path string) (config Conf) {
|
||||||
viper.SetDefault("IFACE", "eth0")
|
viper.SetDefault("IFACE", "enp1s0")
|
||||||
viper.SetDefault("DBPATH", "/data/db.sqlite")
|
viper.SetDefault("DBPATH", "/data/db.sqlite")
|
||||||
viper.SetDefault("GUIIP", "localhost")
|
viper.SetDefault("GUIIP", "localhost")
|
||||||
viper.SetDefault("GUIPORT", "8840")
|
viper.SetDefault("GUIPORT", "8840")
|
||||||
|
|
@ -24,7 +23,5 @@ func get_config(path string) (config Conf) {
|
||||||
config.GuiPort = viper.Get("GUIPORT").(string)
|
config.GuiPort = viper.Get("GUIPORT").(string)
|
||||||
config.Timeout = viper.GetInt("TIMEOUT")
|
config.Timeout = viper.GetInt("TIMEOUT")
|
||||||
|
|
||||||
// fmt.Println(viper.Get("DBPATH"))
|
|
||||||
|
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
25
src/main.go
25
src/main.go
|
|
@ -1,7 +1,6 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
// "fmt"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -28,24 +27,26 @@ var AppConfig Conf
|
||||||
var AllHosts []Host
|
var AllHosts []Host
|
||||||
|
|
||||||
func scan_and_compare() {
|
func scan_and_compare() {
|
||||||
for {
|
var foundHosts []Host
|
||||||
foundHosts := arp_scan()
|
var dbHosts []Host
|
||||||
dbHosts := db_select()
|
for { // Endless
|
||||||
db_setnow()
|
foundHosts = arp_scan() // Scan interfaces
|
||||||
hosts_compare(foundHosts, dbHosts)
|
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()
|
AllHosts = db_select()
|
||||||
// fmt.Println("Refresh")
|
time.Sleep(time.Duration(AppConfig.Timeout) * time.Second) // Timeout
|
||||||
time.Sleep(time.Duration(AppConfig.Timeout) * time.Second)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
AllHosts = []Host{}
|
AllHosts = []Host{}
|
||||||
AppConfig = get_config("./data/config")
|
AppConfig = get_config("/data/config") // Get config from Defaults, Config file, Env
|
||||||
db_create()
|
|
||||||
|
db_create() // Check if DB exists. Create if not
|
||||||
|
|
||||||
go scan_and_compare()
|
go scan_and_compare()
|
||||||
|
|
||||||
webgui()
|
webgui() // Start web GUI
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue