luci-app-wol: add ability to send packet to broadcast address
authorHannu Nyman <hannu.nyman@iki.fi>
Fri, 27 Jan 2017 08:36:12 +0000 (10:36 +0200)
committerHannu Nyman <hannu.nyman@iki.fi>
Fri, 27 Jan 2017 08:37:54 +0000 (10:37 +0200)
Add the ability to send the WOL packet to the broadcast address,
if etherwake is used as the wol tool.

Modified from the original idea in #975

Signed-off-by: Hannu Nyman <hannu.nyman@iki.fi>
applications/luci-app-wol/luasrc/model/cbi/wol.lua

index e87cac3dc29961675c19ce723a4288f5436089b3..ec6a1be2a8a4b0a0e50f305a12afaa59c6006353 100644 (file)
@@ -48,6 +48,13 @@ sys.net.mac_hints(function(mac, name)
        host:value(mac, "%s (%s)" %{ mac, name })
 end)
 
+if has_ewk then
+       broadcast = s:option(Flag, "broadcast",
+               translate("Send to broadcast address"))
+       if has_wol then
+               broadcast:depends("binary", "/usr/bin/etherwake")
+       end
+end
 
 function host.write(self, s, val)
        local host = luci.http.formvalue("cbid.wol.1.mac")
@@ -59,8 +66,10 @@ function host.write(self, s, val)
 
                if util == "/usr/bin/etherwake" then
                        local iface = luci.http.formvalue("cbid.wol.1.iface")
-                       cmd = "%s -D%s %q" %{
-                               util, (iface ~= "" and " -i %q" % iface or ""), host
+                       local broadcast = luci.http.formvalue("cbid.wol.1.broadcast")
+                       cmd = "%s -D%s %s %q" %{
+                               util, (iface ~= "" and " -i %q" % iface or ""),
+                               (broadcast == "1" and " -b" or ""), host
                        }
                else
                        cmd = "%s -v %q" %{ util, host }