Compare commits

..

2 Commits

Author SHA1 Message Date
tadic-luka 16da7f37c8
Merge f91615d4af into 4090592112 2025-11-04 21:53:14 +01:00
Luka Tadić f91615d4af feat: add web route for sending WOL package to given mac addr
adds a new route /device/send-wol/:mac-addr to send the magic WOL package
to the specified mac-addr.
Method is POST and is protected.

Useful for custom wake up scripts: example is sending HTTP request through iOS shortcut

Test plan:
calling the API with curl
```
$ curl -X POST   http://<jetkvm-ip>/send-wol/xx:xx:xx:xx:xx:xx
WOL sent to xx:xx:xx:xx:xx:xx
```

and observing the magic packet on my laptop/PC:
```
$ ncat -u -l 9 -k | xxd
00000000: ffff ffff ffff d050 9978 a620 d050 9978  .......P.x. .P.x
00000010: a620 d050 9978 a620 d050 9978 a620 d050  . .P.x. .P.x. .P
00000020: 9978 a620 d050 9978 a620 d050 9978 a620  .x. .P.x. .P.x.
00000030: d050 9978 a620 d050 9978 a620 d050 9978  .P.x. .P.x. .P.x
00000040: a620 d050 9978 a620 d050 9978 a620 d050  . .P.x. .P.x. .P
00000050: 9978 a620 d050 9978 a620 d050 9978 a620  .x. .P.x. .P.x.
```
2025-11-04 21:37:03 +01:00
1 changed files with 3 additions and 15 deletions

18
web.go
View File

@ -8,7 +8,6 @@ import (
"errors"
"fmt"
"io/fs"
"net"
"net/http"
"net/http/pprof"
"path/filepath"
@ -812,21 +811,10 @@ func handleSetup(c *gin.Context) {
}
func handleSendWOLMagicPacket(c *gin.Context) {
inputMacAddr := c.Param("mac-addr")
macAddr, err := net.ParseMAC(inputMacAddr)
macAddr := c.Param("mac-addr")
err := rpcSendWOLMagicPacket(macAddr)
if err != nil {
logger.Warn().Err(err).Str("sendWol", inputMacAddr).Msg("Invalid mac address provided")
c.String(http.StatusBadRequest, "Invalid mac address provided")
return
logger.Warn().Err(err).Str("sendWOL", macAddr).Msg("Failed to send WOL to macAddr")
}
macAddrString := macAddr.String()
err = rpcSendWOLMagicPacket(macAddrString)
if err != nil {
logger.Warn().Err(err).Str("sendWOL", macAddrString).Msg("Failed to send WOL magic packet")
c.String(http.StatusInternalServerError, "Failed to send WOL to %s: %v", macAddrString, err)
return
}
c.String(http.StatusOK, "WOL sent to %s ", macAddr)
}