Last active
October 14, 2019 09:14
-
-
Save nikiink/48185245a8d649602f2c06fc0c497e3e to your computer and use it in GitHub Desktop.
OpenWrt LuCI Wol web interface
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
FILE: /usr/lib/lua/luci/controller/wolapp/wol.lua | |
USAGE: http://..../cgi-bin/luci/wolapp/wol?m=xx:xx:xx:xx:xx:xx | |
]]-- | |
module("luci.controller.wolapp.wol", package.seeall) | |
function index() | |
entry({"wolapp", "wol"}, call("action_wol"), "W-O-L", 10).dependent=false | |
end | |
function action_wol() | |
local fs = require "nixio.fs" | |
luci.http.prepare_content("text/plain") | |
local m = luci.http.formvalue("m") | |
local outfile = os.tmpname() | |
local errfile = os.tmpname() | |
local rv = os.execute("/usr/bin/wol %s >%s 2>%s" %{ m, outfile, errfile }) | |
local stdout = fs.readfile(outfile, 1024 * 512) or "" | |
local stderr = fs.readfile(errfile, 1024 * 512) or "" | |
fs.unlink(outfile) | |
fs.unlink(errfile) | |
luci.http.write("ADDRESS: %s \n" % {m}) | |
luci.http.write("%s\n%s\n" % {stdout, stderr}) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment