mirror of https://github.com/openwrt/luci.git
applications/luci-wol: handle command execution in write hook and use message facility to output info
parent
3cb299dc10
commit
34b3ae2a42
|
@ -23,51 +23,6 @@ m.reset = false
|
||||||
local has_ewk = fs.access("/usr/bin/etherwake")
|
local has_ewk = fs.access("/usr/bin/etherwake")
|
||||||
local has_wol = fs.access("/usr/bin/wol")
|
local has_wol = fs.access("/usr/bin/wol")
|
||||||
|
|
||||||
if luci.http.formvalue("cbi.submit") then
|
|
||||||
local host = luci.http.formvalue("cbid.wol.1.mac")
|
|
||||||
if host and #host > 0 then
|
|
||||||
local cmd
|
|
||||||
local util = luci.http.formvalue("cbid.wol.1.binary") or (
|
|
||||||
has_ewk and "/usr/bin/etherwake" or "/usr/bin/wol"
|
|
||||||
)
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
else
|
|
||||||
cmd = "%s -v %q" %{ util, host }
|
|
||||||
end
|
|
||||||
|
|
||||||
is = m:section(SimpleSection)
|
|
||||||
|
|
||||||
function is.render()
|
|
||||||
luci.http.write(
|
|
||||||
"<p><br /><strong>%s</strong><br /><br /><code>%s<br /><br />" %{
|
|
||||||
translate("Starting WoL utility:"), cmd
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
local p = io.popen(cmd .. " 2>&1")
|
|
||||||
if p then
|
|
||||||
while true do
|
|
||||||
local l = p:read("*l")
|
|
||||||
if l then
|
|
||||||
if #l > 100 then l = l:sub(1, 100) .. "..." end
|
|
||||||
luci.http.write(l .. "<br />")
|
|
||||||
else
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
p:close()
|
|
||||||
end
|
|
||||||
|
|
||||||
luci.http.write("</code><br /></p>")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
s = m:section(SimpleSection)
|
s = m:section(SimpleSection)
|
||||||
|
|
||||||
|
@ -120,5 +75,47 @@ for mac, ip in pairs(arp) do
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function host.write(self, s, val)
|
||||||
|
local host = luci.http.formvalue("cbid.wol.1.mac")
|
||||||
|
if host and #host > 0 then
|
||||||
|
local cmd
|
||||||
|
local util = luci.http.formvalue("cbid.wol.1.binary") or (
|
||||||
|
has_ewk and "/usr/bin/etherwake" or "/usr/bin/wol"
|
||||||
|
)
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
else
|
||||||
|
cmd = "%s -v %q" %{ util, host }
|
||||||
|
end
|
||||||
|
|
||||||
|
local msg = "<p><strong>%s</strong><br /><br /><code>%s<br /><br />" %{
|
||||||
|
translate("Starting WoL utility:"), cmd
|
||||||
|
}
|
||||||
|
|
||||||
|
local p = io.popen(cmd .. " 2>&1")
|
||||||
|
if p then
|
||||||
|
while true do
|
||||||
|
local l = p:read("*l")
|
||||||
|
if l then
|
||||||
|
if #l > 100 then l = l:sub(1, 100) .. "..." end
|
||||||
|
msg = msg .. l .. "<br />"
|
||||||
|
else
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
p:close()
|
||||||
|
end
|
||||||
|
|
||||||
|
msg = msg .. "</code></p>"
|
||||||
|
|
||||||
|
m.message = msg
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
return m
|
return m
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue