DB query
This commit is contained in:
parent
80225df1d1
commit
e736fd8372
6 changed files with 30 additions and 11 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -1,3 +1,2 @@
|
|||
# Ignore local data
|
||||
data/
|
||||
hosts.db
|
||||
data/
|
||||
|
|
@ -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
15
db-search.go
Normal 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)
|
||||
}
|
||||
6
index.go
6
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)
|
||||
}
|
||||
9
main.go
9
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)
|
||||
}
|
||||
BIN
watchyourlan
Executable file
BIN
watchyourlan
Executable file
Binary file not shown.
Loading…
Reference in a new issue