diff --git a/.version b/.version
index 31f28ae..29b5c4f 100644
--- a/.version
+++ b/.version
@@ -1 +1 @@
-VERSION=0.8.2
\ No newline at end of file
+VERSION=0.8.3
\ No newline at end of file
diff --git a/internal/db/db-edit.go b/internal/db/db-edit.go
index 1756094..7480c10 100644
--- a/internal/db/db-edit.go
+++ b/internal/db/db-edit.go
@@ -57,3 +57,10 @@ func Update(path string, oneHost models.Host) {
//fmt.Println("Update statement:", sqlStatement)
dbExec(path, sqlStatement)
}
+
+// Delete - delete host from DB
+func Delete(path string, id uint16) {
+ sqlStatement := `DELETE FROM "now" WHERE ID='%d';`
+ sqlStatement = fmt.Sprintf(sqlStatement, id)
+ dbExec(path, sqlStatement)
+}
diff --git a/internal/web/host.go b/internal/web/host.go
new file mode 100644
index 0000000..3f825dc
--- /dev/null
+++ b/internal/web/host.go
@@ -0,0 +1,62 @@
+package web
+
+import (
+ "html/template"
+ "log"
+ "net"
+ "net/http"
+ "strconv"
+
+ "github.com/aceberg/WatchYourLAN/internal/check"
+ "github.com/aceberg/WatchYourLAN/internal/db"
+ "github.com/aceberg/WatchYourLAN/internal/models"
+)
+
+func delHandler(w http.ResponseWriter, r *http.Request) {
+
+ idStr := r.FormValue("id")
+ id, err := strconv.Atoi(idStr)
+ check.IfError(err)
+
+ log.Println("INFO: delete host ID =", id)
+
+ db.Delete(AppConfig.DbPath, uint16(id))
+
+ http.Redirect(w, r, "/home/", 302)
+}
+
+func hostHandler(w http.ResponseWriter, r *http.Request) {
+ var guiData models.GuiData
+ var host models.Host
+
+ guiData.Config = AppConfig
+ guiData.Icon = Icon
+
+ idStr := r.URL.Query().Get("id")
+
+ id, err := strconv.Atoi(idStr)
+ check.IfError(err)
+
+ id16 := uint16(id)
+
+ for _, oneHost := range AllHosts {
+ if id16 == oneHost.ID {
+ host = oneHost
+ break
+ }
+ }
+
+ guiData.Hosts = append(guiData.Hosts, host)
+
+ addr, err := net.LookupAddr(host.IP)
+ check.IfError(err)
+
+ guiData.Themes = addr
+
+ tmpl, err := template.ParseFS(TemplHTML, TemplPath+"host.html", TemplPath+"header.html", TemplPath+"footer.html")
+ check.IfError(err)
+ err = tmpl.ExecuteTemplate(w, "header", guiData)
+ check.IfError(err)
+ err = tmpl.ExecuteTemplate(w, "host", guiData)
+ check.IfError(err)
+}
diff --git a/internal/web/templates/host.html b/internal/web/templates/host.html
new file mode 100644
index 0000000..f642389
--- /dev/null
+++ b/internal/web/templates/host.html
@@ -0,0 +1,81 @@
+{{ define "host" }}
+
+
+
+
+
+
+ {{ range .Hosts }}
+
+ | ID |
+ {{ .ID }} |
+
+
+ | Name |
+ {{ .Name }} |
+
+
+ | IP |
+ {{ .IP }} |
+
+
+ | Mac |
+ {{ .Mac }} |
+
+
+ | Hw |
+ {{ .Hw }} |
+
+
+ | Date |
+ {{ .Date }} |
+
+
+ | Known |
+
+ {{ if eq .Known 1 }}
+ Yes
+ {{ else }}
+ No
+ {{ end }}
+ |
+
+
+ | Now |
+
+ {{ if eq .Now 1 }}
+ Online
+ {{ else }}
+ Offline
+ {{ end }}
+ |
+
+
+ |
+
+ |
+ |
+
+ {{ end }}
+
+
+
+
+
+ | Domain name |
+
+ {{ range .Themes }}
+ {{ . }}
+ {{ end }}
+ |
+
+
+
+
+
+
+
+{{ template "footer" }}
+{{ end }}
\ No newline at end of file
diff --git a/internal/web/templates/index.html b/internal/web/templates/index.html
index ca7e604..dd00ead 100644
--- a/internal/web/templates/index.html
+++ b/internal/web/templates/index.html
@@ -19,7 +19,7 @@
| {{ .Name }} |
{{ .IP }} |
- {{ .Mac }} |
+ {{ .Mac }} |
{{ .Hw }} |
{{ if eq .Known 1 }}
@@ -50,7 +50,7 @@
|
{{ .IP }} |
- {{ .Mac }} |
+ {{ .Mac }} |
{{ .Hw }} |
{{ .Date }} |
diff --git a/internal/web/templates/offline.html b/internal/web/templates/offline.html
index 4188acd..454d029 100644
--- a/internal/web/templates/offline.html
+++ b/internal/web/templates/offline.html
@@ -48,7 +48,7 @@
|
{{ .IP }} |
- {{ .Mac }} |
+ {{ .Mac }} |
{{ .Hw }} |
{{ .Date }} |
diff --git a/internal/web/webgui.go b/internal/web/webgui.go
index b3ada07..a2097b5 100644
--- a/internal/web/webgui.go
+++ b/internal/web/webgui.go
@@ -56,7 +56,9 @@ func Gui(configPath string) {
http.HandleFunc("/", indexHandler)
http.HandleFunc("/config/", configHandler)
+ http.HandleFunc("/del_host/", delHandler)
http.HandleFunc("/home/", homeHandler)
+ http.HandleFunc("/host/", hostHandler)
http.HandleFunc("/offline/", offlineHandler)
http.HandleFunc("/online/", onlineHandler)
http.HandleFunc("/save_config/", saveConfigHandler)
|