2 LuCI - Lua Configuration Interface
4 Copyright 2010 Jo-Philipp Wich <xm@subsignal.org>
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
13 local sys = require "luci.sys"
14 local fs = require "nixio.fs"
16 m = SimpleForm("wol", translate("Wake on LAN"),
17 translate("Wake on LAN is a mechanism to remotely boot computers in the local network."))
19 m.submit = translate("Wake up host")
23 local has_ewk = fs.access("/usr/bin/etherwake")
24 local has_wol = fs.access("/usr/bin/wol")
27 s = m:section(SimpleSection)
29 if has_ewk and has_wol then
30 bin = s:option(ListValue, "binary", translate("WoL program"),
31 translate("Sometimes only one of the two tools works. If one fails, try the other one"))
33 bin:value("/usr/bin/etherwake", "Etherwake")
34 bin:value("/usr/bin/wol", "WoL")
38 iface = s:option(ListValue, "iface", translate("Network interface to use"),
39 translate("Specifies the interface the WoL packet is sent on"))
42 iface:depends("binary", "/usr/bin/etherwake")
45 iface:value("", translate("Broadcast on all interfaces"))
47 for _, e in ipairs(sys.net.devices()) do
48 if e ~= "lo" then iface:value(e) end
53 host = s:option(Value, "mac", translate("Host to wake up"),
54 translate("Choose the host to wake up or enter a custom MAC address to use"))
56 sys.net.mac_hints(function(mac, name)
57 host:value(mac, "%s (%s)" %{ mac, name })
61 function host.write(self, s, val)
62 local host = luci.http.formvalue("cbid.wol.1.mac")
63 if host and #host > 0 and host:match("^[a-fA-F0-9:]+$") then
65 local util = luci.http.formvalue("cbid.wol.1.binary") or (
66 has_ewk and "/usr/bin/etherwake" or "/usr/bin/wol"
69 if util == "/usr/bin/etherwake" then
70 local iface = luci.http.formvalue("cbid.wol.1.iface")
72 util, (iface ~= "" and " -i %q" % iface or ""), host
75 cmd = "%s -v %q" %{ util, host }
78 local msg = "<p><strong>%s</strong><br /><br /><code>%s<br /><br />" %{
79 translate("Starting WoL utility:"), cmd
82 local p = io.popen(cmd .. " 2>&1")
85 local l = p:read("*l")
87 if #l > 100 then l = l:sub(1, 100) .. "..." end
88 msg = msg .. l .. "<br />"
96 msg = msg .. "</code></p>"