Del host, name from DNS
This commit is contained in:
parent
2497cd12da
commit
b05ca57cbe
7 changed files with 156 additions and 4 deletions
2
.version
2
.version
|
|
@ -1 +1 @@
|
|||
VERSION=0.8.2
|
||||
VERSION=0.8.3
|
||||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
62
internal/web/host.go
Normal file
62
internal/web/host.go
Normal file
|
|
@ -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)
|
||||
}
|
||||
81
internal/web/templates/host.html
Normal file
81
internal/web/templates/host.html
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
{{ define "host" }}
|
||||
|
||||
<body>
|
||||
<div class="container mt-5">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<table class="table">
|
||||
{{ range .Hosts }}
|
||||
<tr>
|
||||
<td>ID</td>
|
||||
<td>{{ .ID }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Name</td>
|
||||
<td>{{ .Name }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>IP</td>
|
||||
<td><a href="http://{{ .IP }}" target="_blank">{{ .IP }}</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Mac</td>
|
||||
<td>{{ .Mac }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Hw</td>
|
||||
<td>{{ .Hw }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Date</td>
|
||||
<td>{{ .Date }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Known</td>
|
||||
<td>
|
||||
{{ if eq .Known 1 }}
|
||||
Yes
|
||||
{{ else }}
|
||||
No
|
||||
{{ end }}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Now</td>
|
||||
<td>
|
||||
{{ if eq .Now 1 }}
|
||||
Online
|
||||
{{ else }}
|
||||
Offline
|
||||
{{ end }}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<form action="/del_host/" method="post">
|
||||
<input name="id" type="hidden" class="form-control" value="{{ .ID }}"><button type="submit" class="btn btn-danger">Delete host</button>
|
||||
</form>
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
</table>
|
||||
</div>
|
||||
<div class="col">
|
||||
<table class="table">
|
||||
<tr>
|
||||
<td>Domain name</td>
|
||||
<td>
|
||||
{{ range .Themes }}
|
||||
{{ . }}
|
||||
{{ end }}
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
{{ template "footer" }}
|
||||
{{ end }}
|
||||
|
|
@ -19,7 +19,7 @@
|
|||
<tr>
|
||||
<td>{{ .Name }}</td>
|
||||
<td><a href="http://{{ .IP }}" target="_blank">{{ .IP }}</a></td>
|
||||
<td>{{ .Mac }}</td>
|
||||
<td><a href="/host?id={{ .ID }}">{{ .Mac }}</a></td>
|
||||
<td>{{ .Hw }}</td>
|
||||
<td>
|
||||
{{ if eq .Known 1 }}
|
||||
|
|
@ -50,7 +50,7 @@
|
|||
<input name="name" type="text" class="form-control text-dark" value="{{ .Name }}">
|
||||
</td>
|
||||
<td>{{ .IP }}</td>
|
||||
<td>{{ .Mac }}</td>
|
||||
<td><a href="/host?id={{ .ID }}">{{ .Mac }}</a></td>
|
||||
<td>{{ .Hw }}</td>
|
||||
<td>{{ .Date }}</td>
|
||||
<td>
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@
|
|||
<input name="name" type="text" class="form-control text-dark" value="{{ .Name }}">
|
||||
</td>
|
||||
<td><a href="http://{{ .IP }}" target="_blank">{{ .IP }}</a></td>
|
||||
<td>{{ .Mac }}</td>
|
||||
<td><a href="/host?id={{ .ID }}">{{ .Mac }}</a></td>
|
||||
<td>{{ .Hw }}</td>
|
||||
<td>{{ .Date }}</td>
|
||||
<td>
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue