diff --git a/src/arpscan.go b/src/arpscan.go index 0e07311..6b025ef 100644 --- a/src/arpscan.go +++ b/src/arpscan.go @@ -32,6 +32,7 @@ func parse_output(text string) ([]Host) { oneHost.Mac = p[1] oneHost.Hw = p[2] oneHost.Date = currentTime.Format("2006-01-02 15:04:05") + oneHost.Now = 1 foundHosts = append(foundHosts, oneHost) } } diff --git a/src/db-connect.go b/src/db-connect.go index f376aa3..9f8f158 100644 --- a/src/db-connect.go +++ b/src/db-connect.go @@ -1,7 +1,7 @@ package main import ( - "fmt" + //"fmt" "log" "database/sql" _ "github.com/mattn/go-sqlite3" @@ -31,7 +31,7 @@ func db_select(dbPath string) (dbHosts []Host) { dbHosts = []Host{} for res.Next() { var oneHost Host - err = res.Scan(&oneHost.Id, &oneHost.Name, &oneHost.Ip, &oneHost.Mac, &oneHost.Hw, &oneHost.Date, &oneHost.Known) + err = res.Scan(&oneHost.Id, &oneHost.Name, &oneHost.Ip, &oneHost.Mac, &oneHost.Hw, &oneHost.Date, &oneHost.Known, &oneHost.Now) if err != nil { log.Fatal(err) } @@ -39,6 +39,6 @@ func db_select(dbPath string) (dbHosts []Host) { dbHosts = append(dbHosts, oneHost) } - fmt.Println("Select all:", dbHosts) + //fmt.Println("Select all:", dbHosts) return dbHosts } \ No newline at end of file diff --git a/src/db-edit.go b/src/db-edit.go index 7a82fcd..ffdd3dc 100644 --- a/src/db-edit.go +++ b/src/db-edit.go @@ -16,7 +16,8 @@ func db_create(dbPath string) { "MAC" TEXT, "HW" TEXT, "DATE" TEXT, - "KNOWN" INTEGER DEFAULT 0 + "KNOWN" INTEGER DEFAULT 0, + "NOW" INTEGER DEFAULT 0 );` db_exec(dbPath, sqlStatement) fmt.Println("Table created!") @@ -24,8 +25,8 @@ func db_create(dbPath string) { } func db_insert(dbPath string, oneHost Host) { - sqlStatement := `INSERT INTO "now" (NAME, IP, MAC, HW, DATE, KNOWN) VALUES ('','%s','%s','%s','%s', '%d');` - sqlStatement = fmt.Sprintf(sqlStatement, oneHost.Ip, oneHost.Mac, oneHost.Hw, oneHost.Date, 1) - fmt.Println("Insert statement:", sqlStatement) + sqlStatement := `INSERT INTO "now" (NAME, IP, MAC, HW, DATE, KNOWN, NOW) VALUES ('%s','%s','%s','%s','%s','%d','%d');` + sqlStatement = fmt.Sprintf(sqlStatement, oneHost.Name, oneHost.Ip, oneHost.Mac, oneHost.Hw, oneHost.Date, oneHost.Known, oneHost.Now) + //fmt.Println("Insert statement:", sqlStatement) db_exec(dbPath, sqlStatement) } \ No newline at end of file diff --git a/src/main.go b/src/main.go index 23c1b39..c750f28 100644 --- a/src/main.go +++ b/src/main.go @@ -22,18 +22,26 @@ type Conf struct { GuiPort string } +var AppConfig Conf + func main() { - newConfig := get_config("./data/config") + AppConfig = get_config("./data/config") - foundHosts := parse_output(scan_iface(newConfig.Iface)) + foundHosts := parse_output(scan_iface(AppConfig.Iface)) - fmt.Println("Found hosts:", foundHosts) + //fmt.Println("Found hosts:", foundHosts) - db_create(newConfig.DbPath) - db_insert(newConfig.DbPath, foundHosts[0]) - db_select(newConfig.DbPath) + db_create(AppConfig.DbPath) + dbHosts := db_select(AppConfig.DbPath) - fmt.Println(fmt.Sprintf("http://%s:%s", newConfig.GuiIP, newConfig.GuiPort)) + //fmt.Println("DB hosts:", dbHosts) + + db_compare(foundHosts, dbHosts) + + dbHosts = db_select(AppConfig.DbPath) + allHosts := append(foundHosts,dbHosts...) + + fmt.Println(fmt.Sprintf("http://%s:%s", AppConfig.GuiIP, AppConfig.GuiPort)) - webgui(newConfig, foundHosts) + webgui(AppConfig, allHosts) } \ No newline at end of file diff --git a/src/templates/index.html b/src/templates/index.html index de52e2d..863e751 100644 --- a/src/templates/index.html +++ b/src/templates/index.html @@ -14,13 +14,15 @@