mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-11-04 15:13:56 +08:00
✨ Sync 2026-04-23 03:02:20
This commit is contained in:
1 parent
707fbd9449
commit
186f3f4b2d
16 files changed
+341
-336
No files matched your search
@@ -1,4 +1,5 @@
|
||||
# Copyright (C) 2025 Openwrt.org
|
||||
# Copyright (C) 2016 Openwrt.org
|
||||
# Copyright (C) 2025 LWB1978
|
||||
#
|
||||
# This is free software, licensed under the Apache License, Version 2.0 .
|
||||
#
|
||||
@@ -6,8 +7,8 @@
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
LUCI_TITLE:=LuCI support for Timewol
|
||||
PKG_VERSION:=20250407
|
||||
PKG_RELEASE:=4
|
||||
PKG_VERSION:=20260422
|
||||
PKG_RELEASE:=5
|
||||
|
||||
LUCI_DEPENDS:=+luci-base +etherwake
|
||||
LUCI_PKGARCH:=all
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
-- Copyright (C) 2025 LWB1978
|
||||
|
||||
module("luci.controller.timewol", package.seeall)
|
||||
|
||||
local http = require "luci.http"
|
||||
local uci = require "luci.model.uci".cursor()
|
||||
local sys = require "luci.sys"
|
||||
local json = require "luci.jsonc"
|
||||
local util = require "luci.util"
|
||||
|
||||
function index()
|
||||
if not nixio.fs.access("/etc/config/timewol") then return end
|
||||
|
||||
@@ -11,36 +19,42 @@ function index()
|
||||
page.acl_depends = { "luci-app-timewol" }
|
||||
|
||||
entry({"admin", "control", "timewol", "status"}, call("status")).leaf = true
|
||||
entry({"admin", "control", "timewol", "awake"}, call("awake")).leaf = true
|
||||
|
||||
entry({"admin", "control", "timewol", "wakeup"}, call("wakeup")).leaf = true
|
||||
end
|
||||
|
||||
local function http_write_json(content)
|
||||
http.prepare_content("application/json")
|
||||
http.write(json.stringify(content or {code = 1}))
|
||||
end
|
||||
|
||||
function status()
|
||||
local e = {}
|
||||
e.status = luci.sys.call("cat /etc/crontabs/root | grep -v '^[ \t]*#' | grep etherwake >/dev/null") == 0
|
||||
luci.http.prepare_content("application/json")
|
||||
luci.http.write_json(e)
|
||||
e.status = sys.call("grep -v '^[ \t]*#' /etc/crontabs/root | grep etherwake >/dev/null") == 0
|
||||
http_write_json(e)
|
||||
end
|
||||
|
||||
function awake(sections)
|
||||
lan = x:get("timewol",sections,"maceth")
|
||||
mac = x:get("timewol",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()
|
||||
function wakeup()
|
||||
uci:revert("timewol")
|
||||
local section = http.formvalue("section") or ""
|
||||
if section == "" then
|
||||
http_write_json({ success = false, msg = "Missing section" })
|
||||
return
|
||||
end
|
||||
e["data"] = msg
|
||||
luci.http.prepare_content("application/json")
|
||||
luci.http.write_json(e)
|
||||
local maceth = uci:get("timewol", section, "maceth") or ""
|
||||
local macaddr = uci:get("timewol", section, "macaddr") or ""
|
||||
if maceth == "" or macaddr == "" then
|
||||
http_write_json({ success = false, msg = "Missing MAC or interface" })
|
||||
return
|
||||
end
|
||||
local cmd = string.format(
|
||||
"/usr/bin/etherwake -D -i %s %s",
|
||||
util.shellquote(maceth),
|
||||
util.shellquote(macaddr)
|
||||
)
|
||||
if sys.call(cmd) ~= 0 then
|
||||
http_write_json({ success = false, msg = "Wake failed" })
|
||||
return
|
||||
end
|
||||
http_write_json({ success = true })
|
||||
end
|
||||
@@ -1,3 +1,5 @@
|
||||
-- Copyright (C) 2025 LWB1978
|
||||
|
||||
local sys = require "luci.sys"
|
||||
local m, s, o
|
||||
|
||||
@@ -31,6 +33,10 @@ o = s:option(Flag, "enable", translate("Enable"))
|
||||
o.default = 1
|
||||
o.rmempty = false
|
||||
|
||||
o = s:option(Value, "remark", translate("Remarks"))
|
||||
o.width = "auto"
|
||||
o.rmempty = false
|
||||
|
||||
-- Client MAC Address
|
||||
o = s:option(Value, "macaddr", translate("Client MAC"))
|
||||
o.rmempty = false
|
||||
@@ -48,13 +54,6 @@ for _, device in ipairs(sys.net.devices()) do
|
||||
end
|
||||
end
|
||||
|
||||
-- wake device
|
||||
local btn = s:option(Button, "_awake",translate("Wake Up Host"))
|
||||
btn.inputtitle = translate("Awake")
|
||||
btn.inputstyle = "apply"
|
||||
btn.disabled = false
|
||||
btn.template = "timewol/awake"
|
||||
|
||||
-- Function to validate cron field values
|
||||
local function validate_cron_field(option_name, value, min, max, default)
|
||||
if value == "" then
|
||||
@@ -88,6 +87,14 @@ for _, opt in ipairs(schedule_options) do
|
||||
end
|
||||
end
|
||||
|
||||
o = s:option(DummyValue, "_Wake")
|
||||
o.rawhtml = true
|
||||
o.cfgvalue = function(self, section)
|
||||
return string.format([[
|
||||
<input type="button" class="btn cbi-button cbi-button-apply" onclick="WakeUP('%s')" value="%s" />]],
|
||||
section, translate("Wake"))
|
||||
end
|
||||
|
||||
-- Apply the configuration changes
|
||||
m.apply_on_parse = true
|
||||
function m.on_apply(self)
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
<%+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%>
|
||||
@@ -1,11 +1,12 @@
|
||||
<%#
|
||||
Copyright 2016 Chen RuiWei <crwbak@gmail.com>
|
||||
Copyright (C) 2025 LWB1978
|
||||
Licensed to the public under the Apache License 2.0.
|
||||
-%>
|
||||
|
||||
<% include("cbi/map") %>
|
||||
<script type="text/javascript">//<![CDATA[
|
||||
XHR.poll(2, '<%=luci.dispatcher.build_url("admin", "control", "timewol", "status")%>', null,
|
||||
XHR.poll(5, '<%=luci.dispatcher.build_url("admin", "control", "timewol", "status")%>', null,
|
||||
function(x, result)
|
||||
{
|
||||
var status = document.getElementsByClassName('timewol_status')[0];
|
||||
@@ -14,23 +15,36 @@
|
||||
status.innerHTML = result.status?'<%=translate("RUNNING")%>':'<%=translate("NOT RUNNING")%>';
|
||||
}
|
||||
)
|
||||
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]], [[control]], [[timewol]], [[awake]])%>/' + section, { token: '<%=token%>' },
|
||||
function(x, data) {
|
||||
if (x.responseText == "_uncommitted_") {
|
||||
txt="<%:Please [Save & Apply] your changes first%>";
|
||||
alert( txt.replace(new RegExp("<%:&%>", "g"), "&") );
|
||||
} else {
|
||||
alert( JSON.parse(x.response).data );
|
||||
}
|
||||
|
||||
function WakeUP(section) {
|
||||
var input = document.querySelector("input[name='cbid.timewol." + section + ".remark']");
|
||||
var remark = input ? input.value.trim() : "";
|
||||
if (!confirm("<%:Are you sure you want to wake%> " + remark + " ?")) {
|
||||
return;
|
||||
}
|
||||
fetch('<%=luci.dispatcher.build_url("admin", "control", "timewol", "wakeup")%>?section='
|
||||
+ encodeURIComponent(section))
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (!data.success) {
|
||||
alert(data.msg || "Operation failed");
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
//]]>
|
||||
</script>
|
||||
|
||||
<style>
|
||||
|
||||
input[id*=".timewol."][id$=".minute"],
|
||||
input[id*=".timewol."][id$=".hour"],
|
||||
input[id*=".timewol."][id$=".day"],
|
||||
input[id*=".timewol."][id$=".month"],
|
||||
input[id*=".timewol."][id$=".weeks"] {
|
||||
width: 45px !important;
|
||||
min-width: unset !important;
|
||||
max-width: unset !important;
|
||||
text-align: center !important;
|
||||
}
|
||||
|
||||
</style>
|
||||
@@ -52,5 +52,11 @@ msgstr "星期"
|
||||
msgid "Invalid value for %s: %s. Must be between %d and %d or '*'"
|
||||
msgstr "%s: %s 的值无效. 必须在 %d 和 %d 之间,或为 '*'"
|
||||
|
||||
msgid "Awake"
|
||||
msgstr "立即唤醒"
|
||||
msgid "Remarks"
|
||||
msgstr "备注"
|
||||
|
||||
msgid "Wake"
|
||||
msgstr "唤醒"
|
||||
|
||||
msgid "Are you sure you want to wake"
|
||||
msgstr "你是否要唤醒"
|
||||
@@ -1,6 +1,8 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
#
|
||||
# Copyright (C) 2025 OpenWrt.org
|
||||
# Copyright (C) 2015 OpenWrt-dist
|
||||
# Copyright (C) 2016 fw867 <ffkykzs@gmail.com>
|
||||
# Copyright (C) 2025 LWB1978
|
||||
#
|
||||
# This is free software, licensed under the GNU General Public License v3.
|
||||
# See /LICENSE for more information.
|
||||
|
||||
Reference in new issue
Block a user