Compare commits

...

7 Commits

Author SHA1 Message Date
31801dd707 Update LICENSE
Changed to 0-BSD so anyone can copy-paste fragments as they please.
2024-12-10 08:11:35 +00:00
991306c726 Added title for logout 2022-04-28 11:10:40 +02:00
d07b1d4dba Added an option to disable https-only 2022-04-28 11:08:11 +02:00
ed9d9474e3 Icons, identify device by index, launch.json 2022-02-23 14:02:46 +01:00
c56ba425c7 Session refresh, shorter default ttl
- Session cookies also no longer expire on the client
2022-02-23 13:34:52 +01:00
68845fc715 Small improvements
- Removed fake favicon in favor of 204
- Improved table actions (mobile)
2022-02-22 10:34:45 +01:00
e171a7fa09 Update 'README.md' 2022-02-21 20:12:08 +00:00
11 changed files with 70 additions and 44 deletions

1
.gitignore vendored
View File

@ -26,3 +26,4 @@ config.toml
miniwol
!example/**
__debug_bin

15
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}"
}
]
}

17
LICENSE
View File

@ -1,9 +1,14 @@
MIT License
BSD Zero Clause License
Copyright (c) <year> <copyright holders>
Copyright (c) 2024 adroslice
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.

View File

@ -6,7 +6,7 @@ Small web server to send Wake-on-LAN requests to its local network
- Binary includes everything except config
## Installation
Run `go install git.ulra.eu/adro/miniwol`, resulting in a binary `~/go/bin/miniwol`.
Run `go install git.ulra.eu/adro/miniwol@latest`, resulting in a binary `~/go/bin/miniwol`.
Move this binary to e.G. `/usr/bin/miniwol` to run it like any command.
Examples include a simple systemd service to have it start automatically.

View File

@ -14,10 +14,11 @@ type Device struct {
}
type config struct {
Server string
PassHash string
SessionTTL float64
Devices []Device
Server string
PassHash string
SessionTTL float64
StrictCookies bool
Devices []Device
}
var Config config
@ -26,8 +27,9 @@ var configPath string
func init() {
Config = config{
Server: ":8080",
SessionTTL: 1440,
Server: ":8080",
SessionTTL: 10,
StrictCookies: true,
}
// Locations to look for a config file for

View File

@ -1,6 +1,7 @@
Server = ":8080" # The address the webserver should bind to
PassHash = "$2a$10$I.26oCzkjZ8qwfhbmeYM3.kppBjxtPsxkeE1Y.ULjVvA1IBPcQP42" # "password"
SessionTTL = 60 # How many minutes sessions last for
SessionTTL = 10 # How many minutes sessions last for
StrictCookies = true # Whether to use the strict cookie policy (HTTPS Only)
[[Devices]]
Alias = "SomeDevice"

View File

@ -37,9 +37,12 @@ func checkAuth(token string) error {
func withAuth(handler echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
session, err := c.Cookie("session")
// Redirect to login if session expired/invalid
if err != nil || checkAuth(session.Value) != nil {
return c.Redirect(http.StatusSeeOther, "/")
}
// Refresh session
sessions[session.Value] = time.Now().Add(time.Second * time.Duration(config.Config.SessionTTL*60))
return handler(c)
}
}
@ -56,10 +59,9 @@ func auth(c echo.Context) error {
Name: "session",
Value: token,
Path: "/",
Secure: true,
Secure: config.Config.StrictCookies,
HttpOnly: true,
SameSite: http.SameSiteStrictMode,
Expires: sessions[token],
})
return c.Redirect(http.StatusSeeOther, "/")
}

View File

@ -3,6 +3,7 @@ package web
import (
"errors"
"net/http"
"strconv"
"strings"
"git.ulra.eu/adro/miniwol/config"
@ -27,13 +28,12 @@ func add(c echo.Context) error {
}
func wake(c echo.Context) error {
_device := config.Device{}
err := c.Bind(&_device)
index, err := strconv.Atoi(c.FormValue("Index"))
if err != nil {
return err
}
for _, device := range config.Config.Devices {
if device == _device {
for i, device := range config.Config.Devices {
if i == index {
if !strings.Contains(device.IP, ":") {
device.IP += ":9"
}
@ -49,13 +49,12 @@ func wake(c echo.Context) error {
}
func remove(c echo.Context) error {
_device := config.Device{}
err := c.Bind(&_device)
index, err := strconv.Atoi(c.FormValue("Index"))
if err != nil {
return err
}
for i, device := range config.Config.Devices {
if device == _device {
for i := range config.Config.Devices {
if i == index {
config.Config.Devices = append(config.Config.Devices[:i], config.Config.Devices[i+1:]...)
err := config.Save()
if err != nil {

View File

@ -24,19 +24,17 @@
<td>{{$d.Alias}}</td>
<td>{{$d.MAC}}</td>
<td>{{$d.IP}}</td>
<td class="actions">
<form action="/wake" method="post">
<input type="text" name="Alias" value="{{$d.Alias}}" hidden>
<input type="text" name="MAC" value="{{$d.MAC}}" hidden>
<input type="text" name="IP" value="{{$d.IP}}" hidden>
<input type="submit" value="Wake">
</form>
<form action="/remove" method="post">
<input type="text" name="Alias" value="{{$d.Alias}}" hidden>
<input type="text" name="MAC" value="{{$d.MAC}}" hidden>
<input type="text" name="IP" value="{{$d.IP}}" hidden>
<input type="submit" value="Remove">
</form>
<td>
<div class="actions">
<form action="/wake" method="post">
<input type="number" name="Index" value="{{$i}}" hidden>
<input type="submit" value="&#x23FB;" title="Wake">
</form>
<form action="/remove" method="post">
<input type="number" name="Index" value="{{$i}}" hidden>
<input type="submit" value="&#x1F5D1;" title="Delete">
</form>
</div>
</td>
</tr>
{{end}}
@ -63,10 +61,9 @@
}
.actions {
text-align: center;
}
.actions > form {
display: contents;
flex-flow: row wrap;
justify-content: center;
padding: 0;
gap: 0.5rem;
}
</style>

View File

@ -5,7 +5,6 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Small web server to send Wake-on-LAN requests to its local network">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="icon" href="data:,">
<link rel="stylesheet" href="/style.css">
<title>{{ .Title }} - miniwol</title>
</head>
@ -15,7 +14,7 @@
<div style="flex-grow: 1;"></div>
{{ if .Auth }}
<form action="/deauth" method="post">
<input type="submit" value="Logout">
<input type="submit" value="&#x23FB;" title="Logout">
</form>
{{ end }}
</nav>

View File

@ -28,6 +28,7 @@ func Run() error {
e.GET("/", index)
e.GET("/style.css", style)
e.GET("/favicon.ico", favicon)
e.POST("/auth", auth)
e.POST("/deauth", withAuth(deauth))
e.POST("/add", withAuth(add))
@ -76,3 +77,7 @@ func style(c echo.Context) error {
}
return c.Blob(200, "text/css", styleData)
}
func favicon(c echo.Context) error {
return c.NoContent(204)
}