diff --git a/.gitignore b/.gitignore index b2f7365..e8e02e2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ # Ignore local data -data/ -hosts.db \ No newline at end of file +data/ \ No newline at end of file diff --git a/db-create.go b/db-create.go index 1975fde..7ee6a5c 100644 --- a/db-create.go +++ b/db-create.go @@ -21,16 +21,18 @@ func db_create(dbPath string) { "DATE" TEXT, "KNOWN" INTEGER DEFAULT 0 );` - db_exec(dbPath, sqlStatement) + db_query(dbPath, sqlStatement) } } -func db_exec (dbPath string, sqlStatement string) { +func db_query (dbPath string, sqlStatement string) (*sql.Rows) { db, _ := sql.Open("sqlite3", dbPath) defer db.Close() - _, err := db.Exec(sqlStatement) + res, err := db.Query(sqlStatement) if err != nil { log.Fatal(err) } + + return res } \ No newline at end of file diff --git a/db-search.go b/db-search.go new file mode 100644 index 0000000..68802cc --- /dev/null +++ b/db-search.go @@ -0,0 +1,15 @@ +package main + +import ( + // "os" + "fmt" + // "log" + // "database/sql" + // _ "github.com/mattn/go-sqlite3" +) + +func db_search(dbPath string) { + sqlStatement := `` + res := db_query(dbPath, sqlStatement) + fmt.Println(res) +} \ No newline at end of file diff --git a/index.go b/index.go index e33a726..b923733 100644 --- a/index.go +++ b/index.go @@ -14,9 +14,11 @@ func index (w http.ResponseWriter, r *http.Request) { tmpl.ExecuteTemplate(w, "index", FoundHosts) } -func webgui (hosts []Host) { +func webgui (config Conf, hosts []Host) { // fmt.Println(FoundHosts) FoundHosts = hosts + address := config.GuiIP + ":" + config.GuiPort + http.HandleFunc("/", index) - http.ListenAndServe(":8840", nil) + http.ListenAndServe(address, nil) } \ No newline at end of file diff --git a/main.go b/main.go index 947fd6a..1e52868 100644 --- a/main.go +++ b/main.go @@ -12,6 +12,7 @@ type Host struct { Hw string Date string Known uint16 + Now uint16 } type Conf struct { @@ -24,13 +25,13 @@ type Conf struct { func main() { newConfig := get_config("./data/config") - text := scan_iface(newConfig.Iface) - foundHosts := parse_output(text) + foundHosts := parse_output(scan_iface(newConfig.Iface)) fmt.Println(foundHosts) db_create(newConfig.DbPath) - fmt.Println("http://localhost:8840") - webgui(foundHosts) + fmt.Println(fmt.Sprintf("http://%s:%s", newConfig.GuiIP, newConfig.GuiPort)) + + webgui(newConfig, foundHosts) } \ No newline at end of file diff --git a/watchyourlan b/watchyourlan new file mode 100755 index 0000000..c3687d4 Binary files /dev/null and b/watchyourlan differ