From f91615d4aff42ae33f8e8c19122e4b29c0d71aec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luka=20Tadi=C4=87?= Date: Tue, 4 Nov 2025 21:28:01 +0100 Subject: [PATCH] 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:///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. ``` --- web.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/web.go b/web.go index 0fd968b8..9c7d41a4 100644 --- a/web.go +++ b/web.go @@ -184,6 +184,9 @@ func setupRouter() *gin.Engine { protected.PUT("/auth/password-local", handleUpdatePassword) protected.DELETE("/auth/local-password", handleDeletePassword) protected.POST("/storage/upload", handleUploadHttp) + + protected.POST("/device/send-wol/:mac-addr", handleSendWOLMagicPacket) + } // Catch-all route for SPA @@ -341,7 +344,6 @@ func handleWebRTCSignalWsMessages( l.Trace().Msg("sending ping frame") err := wsCon.Ping(runCtx) - if err != nil { l.Warn().Str("error", err.Error()).Msg("websocket ping error") cancelRun() @@ -807,3 +809,12 @@ func handleSetup(c *gin.Context) { c.JSON(http.StatusOK, gin.H{"message": "Device setup completed successfully"}) } + +func handleSendWOLMagicPacket(c *gin.Context) { + macAddr := c.Param("mac-addr") + err := rpcSendWOLMagicPacket(macAddr) + if err != nil { + logger.Warn().Err(err).Str("sendWOL", macAddr).Msg("Failed to send WOL to macAddr") + } + c.String(http.StatusOK, "WOL sent to %s ", macAddr) +}