mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-11-03 10:53:56 +08:00
🌴 Sync 2026-03-05 23:51:42
This commit is contained in:
1 parent
97c049ed0a
commit
0acff03804
14253 files changed
+3893239
No files matched your search
@@ -0,0 +1,17 @@
|
||||
#
|
||||
# Copyright (C) 2021-2099 ykxVK8yL5L <https://github.com/ykxVK8yL5L>
|
||||
#
|
||||
# This is free software, licensed under the Apache License, Version 2.0 .
|
||||
#
|
||||
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
LUCI_TITLE:=luci-app-Taskschedule
|
||||
LUCI_DEPENDS:=
|
||||
|
||||
|
||||
include $(TOPDIR)/feeds/luci/luci.mk
|
||||
|
||||
|
||||
# call BuildPackage - OpenWrt buildroot signature
|
||||
@@ -0,0 +1,42 @@
|
||||
module("luci.controller.taskschedule", package.seeall)
|
||||
|
||||
function index()
|
||||
if not nixio.fs.access("/etc/config/taskschedule") then
|
||||
return
|
||||
end
|
||||
|
||||
entry({"admin", "services", "taskschedule"}, alias("admin", "services", "taskschedule", "home"),_("任务"), 10).dependent = true -- 任务列表
|
||||
entry({"admin", "services", "taskschedule","home"}, cbi("taskschedule/taskschedule"), _("任务"),30).leaf = true
|
||||
--entry({"admin", "services", "taskschedule", "log"}, cbi("taskschedule/log"),_("日志"), 30).leaf = true -- 日志页面
|
||||
entry({"admin", "services", "taskschedule", "log"}, call("show_log"),_("日志"), 30).leaf = true -- 日志页面
|
||||
end
|
||||
|
||||
|
||||
local function isempty(s)
|
||||
return s == nil or s == ''
|
||||
end
|
||||
|
||||
|
||||
|
||||
function show_log(name)
|
||||
if isempty(name) then
|
||||
command = "echo ''"
|
||||
else
|
||||
command = "/bin/cat /var/log/taskschedule-"..name..".txt"
|
||||
end
|
||||
|
||||
log = luci.sys.exec(command)
|
||||
luci.http.prepare_content("text/html")
|
||||
luci.template.render("taskschedule/log",{log=log})
|
||||
end
|
||||
|
||||
|
||||
function act_status()
|
||||
local e = {}
|
||||
e.running = luci.sys.call("/usr/bin/pgrep -f 'qemu-system-x86_64 -name synology' >/dev/null") == 0
|
||||
luci.http.prepare_content("application/json")
|
||||
luci.http.write_json(e)
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
require "luci.sys"
|
||||
require "luci.http"
|
||||
|
||||
local m, s, o
|
||||
m = Map("taskschedule", translate("General Settings"))
|
||||
|
||||
|
||||
-- g = m:section(TypedSection, "taskschedule", "taskschedule")
|
||||
-- g.anonymous = true
|
||||
-- log_path = g:option(Value, "log_dir", translate("日志目录路径"))
|
||||
-- log_path.rmempty = true
|
||||
-- log_path.placeholder = "日志目录路径"
|
||||
-- log_path.default = "/var/log/taskschedule/log/"
|
||||
|
||||
|
||||
s = m:section(TypedSection, "tasks", translate("任务列表")
|
||||
, translate("任务列表."))
|
||||
s.anonymous = true
|
||||
s.addremove = true
|
||||
s.template = "cbi/tblsection"
|
||||
|
||||
remark = s:option(Value, "remark", translate("备注"))
|
||||
remark.rmempty = true
|
||||
remark.placeholder = "备注"
|
||||
|
||||
exec = s:option(Button, "exec_task", translate("执行"))
|
||||
exec.inputstyle = "apply"
|
||||
exec.render = function(self, section, scope)
|
||||
sl = m.uci:get("taskschedule", section, "shell")
|
||||
if sl == nil then
|
||||
return
|
||||
end
|
||||
running_pid = luci.sys.exec("pgrep -f '"..sl.."'")
|
||||
if running_pid ==nil or running_pid == '' then
|
||||
self.title = '执行'
|
||||
self.inputstyle = "apply"
|
||||
else
|
||||
self.title = running_pid
|
||||
self.inputstyle = "remove"
|
||||
end
|
||||
Button.render(self, section, scope)
|
||||
end
|
||||
exec.write = function(self, section)
|
||||
ne = m.uci:get("taskschedule", section, "name")
|
||||
sl = m.uci:get("taskschedule", section, "shell")
|
||||
if sl == nil then
|
||||
return
|
||||
end
|
||||
-- ld = m.uci:get("taskschedule", "@taskschedule[0]","log_dir")
|
||||
log_file = "/var/log/taskschedule-"..ne
|
||||
running_pid = luci.sys.exec("pgrep -f '"..sl.."'")
|
||||
command = "echo 'hello'"
|
||||
if running_pid ==nil or running_pid == '' then
|
||||
command="nohup "..sl..">"..log_file..".txt 2>&1 &"
|
||||
else
|
||||
command="kill $(pgrep -f '"..sl.."')"
|
||||
end
|
||||
luci.sys.exec(command)
|
||||
end
|
||||
|
||||
|
||||
name = s:option(Value, "name", translate("名称【英文】"))
|
||||
name.rmempty = false
|
||||
name.placeholder = "任务名称[英文]"
|
||||
|
||||
|
||||
dm = s:option(Value, "shell", translate("命令"))
|
||||
dm.rmempty = false
|
||||
dm.placeholder = "shell命令"
|
||||
|
||||
|
||||
|
||||
show_log = s:option(Button, "show_log", translate("日志"))
|
||||
show_log.inputstyle = "apply"
|
||||
show_log.write = function(self, section)
|
||||
ne = m.uci:get("taskschedule", section, "name")
|
||||
--luci.http.redirect(luci.dispatcher.build_url("admin", "services", "taskschedule", "log",ne))
|
||||
luci.http.redirect(luci.dispatcher.build_url("admin/services/taskschedule/log/"..ne))
|
||||
end
|
||||
|
||||
del_log = s:option(Button, "del_log", translate("删除日志"))
|
||||
del_log.inputstyle = "apply"
|
||||
del_log.write = function(self, section)
|
||||
ne = m.uci:get("taskschedule", section, "name")
|
||||
log_file = "/var/log/taskschedule-"..ne
|
||||
command="rm -f "..log_file..".txt"
|
||||
luci.sys.exec(command)
|
||||
end
|
||||
|
||||
|
||||
|
||||
return m
|
||||
@@ -0,0 +1,3 @@
|
||||
<%+header%>
|
||||
<textarea id="logview" class="cbi-input-textarea" style="width: 100%" rows="30" readonly="readonly"><%=log%></textarea>
|
||||
<%+footer%>
|
||||
@@ -0,0 +1,2 @@
|
||||
config taskschedule
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"luci-app-taskschedule": {
|
||||
"description": "Grant UCI access for luci-app-taskschedule",
|
||||
"read": {
|
||||
"uci": [ "taskschedule" ]
|
||||
},
|
||||
"write": {
|
||||
"uci": [ "taskschedule" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user