diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2014-12-03 15:17:05 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2015-01-08 16:26:20 +0100 |
commit | 1bb4822dca6113f73e3bc89e2acf15935e6f8e92 (patch) | |
tree | 35e16f100466e4e00657199b38bb3d87d52bf73f /applications/luci-app-wol/luasrc/model/cbi/wol.lua | |
parent | 9edd0e46c3f880727738ce8ca6ff1c8b85f99ef4 (diff) |
Rework LuCI build system
* Rename subdirectories to their repective OpenWrt package names
* Make each LuCI module its own standalone package
* Deploy a shared luci.mk which is used by each module Makefile
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
Diffstat (limited to 'applications/luci-app-wol/luasrc/model/cbi/wol.lua')
-rw-r--r-- | applications/luci-app-wol/luasrc/model/cbi/wol.lua | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/applications/luci-app-wol/luasrc/model/cbi/wol.lua b/applications/luci-app-wol/luasrc/model/cbi/wol.lua new file mode 100644 index 0000000000..ece9e4983a --- /dev/null +++ b/applications/luci-app-wol/luasrc/model/cbi/wol.lua @@ -0,0 +1,103 @@ +--[[ +LuCI - Lua Configuration Interface + +Copyright 2010 Jo-Philipp Wich <xm@subsignal.org> + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 +]]-- + +local sys = require "luci.sys" +local fs = require "nixio.fs" + +m = SimpleForm("wol", translate("Wake on LAN"), + translate("Wake on LAN is a mechanism to remotely boot computers in the local network.")) + +m.submit = translate("Wake up host") +m.reset = false + + +local has_ewk = fs.access("/usr/bin/etherwake") +local has_wol = fs.access("/usr/bin/wol") + + +s = m:section(SimpleSection) + +if has_ewk and has_wol then + bin = s:option(ListValue, "binary", translate("WoL program"), + translate("Sometimes only one of the two tools works. If one fails, try the other one")) + + bin:value("/usr/bin/etherwake", "Etherwake") + bin:value("/usr/bin/wol", "WoL") +end + +if has_ewk then + iface = s:option(ListValue, "iface", translate("Network interface to use"), + translate("Specifies the interface the WoL packet is sent on")) + + if has_wol then + iface:depends("binary", "/usr/bin/etherwake") + 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 +end + + +host = s:option(Value, "mac", translate("Host to wake up"), + translate("Choose the host to wake up or enter a custom MAC address to use")) + +sys.net.mac_hints(function(mac, name) + host:value(mac, "%s (%s)" %{ mac, name }) +end) + + +function host.write(self, s, val) + local host = luci.http.formvalue("cbid.wol.1.mac") + 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" + ) + + 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 |