Handle id/alias mismatch, index

This commit is contained in:
adro 2022-02-17 13:54:52 +01:00
parent 84d396cfb6
commit 4b86aadae4
3 changed files with 10 additions and 8 deletions

View File

@ -22,7 +22,7 @@ func index(w http.ResponseWriter, r *http.Request) {
sCookie, err := r.Cookie("session")
if err == nil && isAuthenticated(sCookie.Value) == nil {
page.Title = "Miniwol"
contentBuffer.WriteString("TODO")
contentBuffer.WriteString("<a href='/device'>Device</a>")
} else {
page.Title = "Login"
err = loginTemplate.Execute(&contentBuffer, struct{}{})

View File

@ -5,14 +5,15 @@
<th>IP/Broadcast</th>
<th>Actions</th>
</tr>
{{range .}}
{{range $i, $d := .}}
<tr>
<td>{{.Alias}}</td>
<td>{{.MAC}}</td>
<td>{{.IP}}</td>
<td>{{$d.Alias}}</td>
<td>{{$d.MAC}}</td>
<td>{{$d.IP}}</td>
<td>
<form action="/wake" method="post">
<input type="text" name="alias" value="{{.Alias}}" hidden>
<input type="text" name="index" value="{{$i}}" hidden>
<input type="text" name="alias" value="{{$d.Alias}}" hidden>
<input type="submit" value="Wake">
</form>
</td>

View File

@ -1,6 +1,7 @@
package web
import (
"fmt"
"miniwol/config"
"miniwol/lib"
"net/http"
@ -12,8 +13,8 @@ func wake(w http.ResponseWriter, r *http.Request) {
return
}
for _, device := range config.Config.Device {
if r.FormValue("alias") == device.Alias {
for i, device := range config.Config.Device {
if r.FormValue("alias") == device.Alias && r.FormValue("index") == fmt.Sprint(i) {
if !strings.Contains(device.IP, ":") {
device.IP += ":9"
}