Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
31801dd707 | |||
991306c726 | |||
d07b1d4dba | |||
ed9d9474e3 | |||
c56ba425c7 |
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -26,3 +26,4 @@ config.toml
|
|||
miniwol
|
||||
|
||||
!example/**
|
||||
__debug_bin
|
||||
|
|
15
.vscode/launch.json
vendored
Normal file
15
.vscode/launch.json
vendored
Normal 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
17
LICENSE
|
@ -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.
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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, "/")
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -27,16 +27,12 @@
|
|||
<td>
|
||||
<div 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">
|
||||
<input type="number" name="Index" value="{{$i}}" hidden>
|
||||
<input type="submit" value="⏻" title="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">
|
||||
<input type="number" name="Index" value="{{$i}}" hidden>
|
||||
<input type="submit" value="🗑" title="Delete">
|
||||
</form>
|
||||
</div>
|
||||
</td>
|
||||
|
|
|
@ -14,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="⏻" title="Logout">
|
||||
</form>
|
||||
{{ end }}
|
||||
</nav>
|
||||
|
|
Loading…
Reference in New Issue
Block a user