This commit is contained in:
aceberg 2022-08-17 12:41:15 +07:00
parent 80225df1d1
commit e736fd8372
6 changed files with 30 additions and 11 deletions

3
.gitignore vendored
View file

@ -1,3 +1,2 @@
# Ignore local data # Ignore local data
data/ data/
hosts.db

View file

@ -21,16 +21,18 @@ func db_create(dbPath string) {
"DATE" TEXT, "DATE" TEXT,
"KNOWN" INTEGER DEFAULT 0 "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) db, _ := sql.Open("sqlite3", dbPath)
defer db.Close() defer db.Close()
_, err := db.Exec(sqlStatement) res, err := db.Query(sqlStatement)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
return res
} }

15
db-search.go Normal file
View file

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

View file

@ -14,9 +14,11 @@ func index (w http.ResponseWriter, r *http.Request) {
tmpl.ExecuteTemplate(w, "index", FoundHosts) tmpl.ExecuteTemplate(w, "index", FoundHosts)
} }
func webgui (hosts []Host) { func webgui (config Conf, hosts []Host) {
// fmt.Println(FoundHosts) // fmt.Println(FoundHosts)
FoundHosts = hosts FoundHosts = hosts
address := config.GuiIP + ":" + config.GuiPort
http.HandleFunc("/", index) http.HandleFunc("/", index)
http.ListenAndServe(":8840", nil) http.ListenAndServe(address, nil)
} }

View file

@ -12,6 +12,7 @@ type Host struct {
Hw string Hw string
Date string Date string
Known uint16 Known uint16
Now uint16
} }
type Conf struct { type Conf struct {
@ -24,13 +25,13 @@ type Conf struct {
func main() { func main() {
newConfig := get_config("./data/config") newConfig := get_config("./data/config")
text := scan_iface(newConfig.Iface) foundHosts := parse_output(scan_iface(newConfig.Iface))
foundHosts := parse_output(text)
fmt.Println(foundHosts) fmt.Println(foundHosts)
db_create(newConfig.DbPath) db_create(newConfig.DbPath)
fmt.Println("http://localhost:8840") fmt.Println(fmt.Sprintf("http://%s:%s", newConfig.GuiIP, newConfig.GuiPort))
webgui(foundHosts)
webgui(newConfig, foundHosts)
} }

BIN
watchyourlan Executable file

Binary file not shown.