🐶 Sync 2025-11-02 14:26:26
This commit is contained in:
17
luci-app-wolplus/Makefile
Normal file
17
luci-app-wolplus/Makefile
Normal file
@@ -0,0 +1,17 @@
|
||||
# Copyright (C) 2016 Openwrt.org
|
||||
#
|
||||
# This is free software, licensed under the Apache License, Version 2.0 .
|
||||
#
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
LUCI_TITLE:=LuCI support for wolplus From sundaqiang
|
||||
LUCI_DEPENDS:=+etherwake
|
||||
LUCI_PKGARCH:=all
|
||||
PKG_VERSION:=1.0
|
||||
PKG_RELEASE:=20201225
|
||||
PKG_MAINTAINER:=sundaqiang
|
||||
|
||||
include $(TOPDIR)/feeds/luci/luci.mk
|
||||
|
||||
# call BuildPackage - OpenWrt buildroot signature
|
||||
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>
|
||||
|
||||
1
luci-app-wolplus/po/zh-cn
Symbolic link
1
luci-app-wolplus/po/zh-cn
Symbolic link
@@ -0,0 +1 @@
|
||||
zh_Hans
|
||||
23
luci-app-wolplus/po/zh_Hans/wolplus.po
Normal file
23
luci-app-wolplus/po/zh_Hans/wolplus.po
Normal file
@@ -0,0 +1,23 @@
|
||||
msgid "Wake on LAN"
|
||||
msgstr "网络唤醒"
|
||||
|
||||
msgid "Wake on LAN is a mechanism to remotely boot computers in the local network."
|
||||
msgstr "网络唤醒是一个远程启动本地网络内计算机的机制。"
|
||||
|
||||
msgid "Host list"
|
||||
msgstr "主机列表"
|
||||
|
||||
msgid "Name"
|
||||
msgstr "名称"
|
||||
|
||||
msgid "Mac Address"
|
||||
msgstr "客户端 MAC"
|
||||
|
||||
msgid "Network interface"
|
||||
msgstr "网络接口"
|
||||
|
||||
msgid "Wake up host"
|
||||
msgstr "唤醒主机"
|
||||
|
||||
msgid "Please [Save & Apply] changes first"
|
||||
msgstr "请先保存并应用设置"
|
||||
0
luci-app-wolplus/root/etc/config/wolplus
Normal file
0
luci-app-wolplus/root/etc/config/wolplus
Normal file
11
luci-app-wolplus/root/etc/uci-defaults/luci-app-wolplus
Normal file
11
luci-app-wolplus/root/etc/uci-defaults/luci-app-wolplus
Normal file
@@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
delete ucitrack.@wolplus[-1]
|
||||
add ucitrack wolplus
|
||||
set ucitrack.@wolplus[-1].init=wolplus
|
||||
commit ucitrack
|
||||
EOF
|
||||
|
||||
rm -f /tmp/luci-indexcache
|
||||
exit 0
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"luci-app-wolplus": {
|
||||
"description": "Grant UCI access for luci-app-wolplus",
|
||||
"read": {
|
||||
"uci": [ "wolplus" ]
|
||||
},
|
||||
"write": {
|
||||
"uci": [ "wolplus" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user