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
data/
hosts.db
data/

View file

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

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

View file

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

BIN
watchyourlan Executable file

Binary file not shown.