applications/luci-wol: cope with host entries that have multiple MACs assigned
[project/luci.git] / applications / luci-wol / luasrc / model / cbi / wol.lua
index ac73919..ad3479b 100644 (file)
@@ -48,7 +48,7 @@ if has_ewk then
        end
 
        iface:value("", translate("Broadcast on all interfaces"))
-       
+
        for _, e in ipairs(sys.net.devices()) do
                if e ~= "lo" then iface:value(e) end
        end
@@ -72,7 +72,14 @@ end
 uci:foreach("dhcp", "host",
        function(s)
                if s.mac and s.ip then
-                       arp[s.mac:upper()] = { s.ip, s.name }
+                       if type(s.mac) == "table" then
+                               local m
+                               for _, m in ipairs(s.mac) do
+                                       arp[m:upper()] = { s.ip, s.name }
+                               end
+                       else
+                               arp[s.mac:upper()] = { s.ip, s.name }
+                       end
                end
        end)
 
@@ -86,7 +93,7 @@ end
 
 function host.write(self, s, val)
        local host = luci.http.formvalue("cbid.wol.1.mac")
-       if host and #host > 0 then
+       if host and #host > 0 and host:match("^[a-fA-F0-9:]+$") then
                local cmd
                local util = luci.http.formvalue("cbid.wol.1.binary") or (
                        has_ewk and "/usr/bin/etherwake" or "/usr/bin/wol"
@@ -127,4 +134,3 @@ end
 
 
 return m
-