🐶 Sync 2025-11-02 14:26:26
This commit is contained in:
33
luci-app-wolplus/luasrc/controller/wolplus.lua
Normal file
33
luci-app-wolplus/luasrc/controller/wolplus.lua
Normal file
@@ -0,0 +1,33 @@
|
||||
module("luci.controller.wolplus", package.seeall)
|
||||
local t, a
|
||||
local x = luci.model.uci.cursor()
|
||||
|
||||
function index()
|
||||
if not nixio.fs.access("/etc/config/wolplus") then return end
|
||||
entry({"admin", "services", "wolplus"}, cbi("wolplus"), _("Wake on LAN")).dependent = true
|
||||
entry( {"admin", "services", "wolplus", "awake"}, post("awake") ).leaf = true
|
||||
end
|
||||
|
||||
function awake(sections)
|
||||
lan = x:get("wolplus",sections,"maceth")
|
||||
mac = x:get("wolplus",sections,"macaddr")
|
||||
local e = {}
|
||||
cmd = "/usr/bin/etherwake -D -i " .. lan .. " -b " .. mac .. " 2>&1"
|
||||
local p = io.popen(cmd)
|
||||
local msg = ""
|
||||
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
|
||||
else
|
||||
break
|
||||
end
|
||||
end
|
||||
p:close()
|
||||
end
|
||||
e["data"] = msg
|
||||
luci.http.prepare_content("application/json")
|
||||
luci.http.write_json(e)
|
||||
end
|
||||
35
luci-app-wolplus/luasrc/model/cbi/wolplus.lua
Normal file
35
luci-app-wolplus/luasrc/model/cbi/wolplus.lua
Normal file
@@ -0,0 +1,35 @@
|
||||
local i = require "luci.sys"
|
||||
local t, e
|
||||
t = Map("wolplus", translate("Wake on LAN"), translate("Wake on LAN is a mechanism to remotely boot computers in the local network."))
|
||||
t.template = "wolplus/index"
|
||||
e = t:section(TypedSection, "macclient", translate("Host list"))
|
||||
e.template = "cbi/tblsection"
|
||||
e.anonymous = true
|
||||
e.addremove = true
|
||||
a = e:option(Value, "name", translate("Name"))
|
||||
a.optional = false
|
||||
nolimit_mac = e:option(Value, "macaddr", translate("Mac Address"))
|
||||
nolimit_mac.rmempty = false
|
||||
i.net.mac_hints(function(e, t) nolimit_mac:value(e, "%s (%s)" % {e, t}) end)
|
||||
nolimit_eth = e:option(Value, "maceth", translate("Network interface"))
|
||||
nolimit_eth.rmempty = false
|
||||
for t, e in ipairs(i.net.devices()) do if e ~= "lo" then nolimit_eth:value(e) end end
|
||||
btn = e:option(Button, "_awake",translate("Wake up host"))
|
||||
btn.inputtitle = translate("Wake up host")
|
||||
btn.inputstyle = "apply"
|
||||
btn.disabled = false
|
||||
btn.template = "wolplus/awake"
|
||||
function gen_uuid(format)
|
||||
local uuid = i.exec("echo -n $(cat /proc/sys/kernel/random/uuid)")
|
||||
if format == nil then
|
||||
uuid = string.gsub(uuid, "-", "")
|
||||
end
|
||||
return uuid
|
||||
end
|
||||
function e.create(e, t)
|
||||
local uuid = gen_uuid()
|
||||
t = uuid
|
||||
TypedSection.create(e, t)
|
||||
end
|
||||
|
||||
return t
|
||||
3
luci-app-wolplus/luasrc/view/wolplus/awake.htm
Normal file
3
luci-app-wolplus/luasrc/view/wolplus/awake.htm
Normal file
@@ -0,0 +1,3 @@
|
||||
<%+cbi/valueheader%>
|
||||
<input class="cbi-button cbi-input-<%=self.inputstyle or "button" %>" style="font-size: 100%;" type="button" onclick="onclick_awake(this.id)" <%=attr("name", section) .. attr("id", cbid) .. attr("value", self.inputtitle)%> />
|
||||
<%+cbi/valuefooter%>
|
||||
22
luci-app-wolplus/luasrc/view/wolplus/index.htm
Normal file
22
luci-app-wolplus/luasrc/view/wolplus/index.htm
Normal file
@@ -0,0 +1,22 @@
|
||||
<% include("cbi/map") %>
|
||||
<script type="text/javascript">
|
||||
function _id2section(id) {
|
||||
var x = id.split(".");
|
||||
return x[2];
|
||||
}
|
||||
function onclick_awake(id) {
|
||||
var section = _id2section(id);
|
||||
var btnXHR = new XHR();
|
||||
btnXHR.post('<%=url([[admin]], [[services]], [[wolplus]], [[awake]])%>/' + section, { token: '<%=token%>' },
|
||||
function(x, data) {
|
||||
if (x.responseText == "_uncommitted_") {
|
||||
txt="<%:Please [Save & Apply] changes first%>";
|
||||
alert( txt.replace(new RegExp("<%:&%>", "g"), "&") );
|
||||
} else {
|
||||
alert( JSON.parse(x.response).data );
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user