mirror of
https://github.com/caiwx86/small-packages.git
synced 2026-10-29 23:05:13 +08:00
update 2026-10-07 18:47:42
This commit is contained in:
1 parent
617f7ca2a6
commit
bd061545ed
4832 files changed
+1693456
No files matched your search
@@ -0,0 +1,45 @@
|
||||
#
|
||||
# Copyright 2019-2026 sirpdboy
|
||||
#
|
||||
# This is free software, licensed under the Apache License, Version 2.0 .
|
||||
#
|
||||
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=luci-app-taskplan
|
||||
PKG_VERSION:=3.0.0
|
||||
PKG_RELEASE:=20260303
|
||||
|
||||
|
||||
PKG_LICENSE:=GPL-2.0
|
||||
PKG_MAINTAINER:=sirpdboy
|
||||
|
||||
LUCI_PKGARCH:=all
|
||||
|
||||
define Package/luci-app-taskplan
|
||||
SECTION:=luci
|
||||
CATEGORY:=LuCI
|
||||
SUBMENU:=3. Applications
|
||||
TITLE:=LuCI Support for Task Plan
|
||||
PKGARCH:=all
|
||||
DEPENDS:=+rpcd +luci-base +bash
|
||||
endef
|
||||
|
||||
define Package/luci-app-taskplan/description
|
||||
Scheduled tasks and startup tasks management.
|
||||
Includes restart, shutdown, network restart, memory release,
|
||||
system cleaning, and custom scripts.
|
||||
endef
|
||||
|
||||
define Build/Compile
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)/conffiles
|
||||
/etc/config/taskplan
|
||||
endef
|
||||
|
||||
include $(TOPDIR)/feeds/luci/luci.mk
|
||||
|
||||
# call BuildPackage - OpenWrt buildroot signature
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
'use strict';
|
||||
'require view';
|
||||
'require ui';
|
||||
'require poll';
|
||||
'require fs';
|
||||
|
||||
return view.extend({
|
||||
load: function() {
|
||||
return fs.read('/etc/taskplan/taskplan.log').catch(function(err) {
|
||||
console.error('Failed to read log file:', err);
|
||||
return '';
|
||||
});
|
||||
},
|
||||
|
||||
handleClearLog: function() {
|
||||
var self = this;
|
||||
return fs.write('/etc/taskplan/taskplan.log', '').then(function() {
|
||||
ui.addNotification(null, E('p', {}, _('Log cleared')));
|
||||
self.updateLogDisplay();
|
||||
}).catch(function(err) {
|
||||
ui.addNotification(null, E('p', { 'class': 'alert-message' }, _('Failed to clear log: ') + err.message));
|
||||
});
|
||||
},
|
||||
|
||||
handleReverseLog: function() {
|
||||
this.reverse = !this.reverse;
|
||||
this.updateLogDisplay();
|
||||
},
|
||||
|
||||
handleDownloadLog: function() {
|
||||
var self = this;
|
||||
fs.read('/etc/taskplan/taskplan.log').then(function(content) {
|
||||
if (content) {
|
||||
var blob = new Blob([content], { type: 'text/plain' });
|
||||
var url = URL.createObjectURL(blob);
|
||||
var a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = 'taskplan.log';
|
||||
a.click();
|
||||
URL.revokeObjectURL(url);
|
||||
} else {
|
||||
ui.addNotification(null, E('p', {}, _('Log is empty')));
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
updateLogDisplay: function() {
|
||||
var self = this;
|
||||
fs.read('/etc/taskplan/taskplan.log').then(function(content) {
|
||||
var logArea = document.getElementById('log_content');
|
||||
if (logArea) {
|
||||
if (self.reverse) {
|
||||
logArea.value = content.split('\n').reverse().join('\n');
|
||||
} else {
|
||||
logArea.value = content;
|
||||
}
|
||||
// 如果不是反向模式,自动滚动到底部
|
||||
if (!self.reverse) {
|
||||
logArea.scrollTop = logArea.scrollHeight;
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
render: function(logContent) {
|
||||
this.reverse = false;
|
||||
|
||||
return E('div', { 'class': 'view' }, [
|
||||
E('div', { 'class': 'cbi-map' }, [
|
||||
// 标题
|
||||
E('h2', {}, _('Task Plan Log Viewer')),
|
||||
|
||||
E('div', { 'class': 'cbi-section', 'style': 'margin-bottom:10px;' }, [
|
||||
E('div', { 'class': 'cbi-section-actions' }, [
|
||||
E('button', {
|
||||
'class': 'btn cbi-button cbi-button-apply',
|
||||
'click': ui.createHandlerFn(this, 'handleClearLog')
|
||||
}, [ _('Clear Log') ]),
|
||||
' ',
|
||||
E('button', {
|
||||
'class': 'btn cbi-button cbi-button-edit',
|
||||
'click': ui.createHandlerFn(this, 'handleReverseLog')
|
||||
}, [ _('Reverse Order') ])
|
||||
])
|
||||
]),
|
||||
|
||||
// 日志显示区域
|
||||
E('div', { 'class': 'cbi-section' }, [
|
||||
E('textarea', {
|
||||
'id': 'log_content',
|
||||
'class': 'cbi-input-textarea',
|
||||
'style': 'width:100%; height:500px; font-family:monospace; font-size:12px; padding:10px; border-radius:4px;',
|
||||
'readonly': 'readonly',
|
||||
'wrap': 'off'
|
||||
}, logContent || '')
|
||||
])
|
||||
])
|
||||
]);
|
||||
},
|
||||
|
||||
handle: function(ev) {
|
||||
var self = this;
|
||||
|
||||
poll.add(function() {
|
||||
return fs.read('/etc/taskplan/taskplan.log').then(function(content) {
|
||||
var logArea = document.getElementById('log_content');
|
||||
if (logArea) {
|
||||
if (self.reverse) {
|
||||
logArea.value = content.split('\n').reverse().join('\n');
|
||||
} else {
|
||||
logArea.value = content;
|
||||
logArea.scrollTop = logArea.scrollHeight;
|
||||
}
|
||||
}
|
||||
});
|
||||
}, 5);
|
||||
|
||||
return this.render.apply(this, arguments);
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,110 @@
|
||||
'use strict';
|
||||
'require view';
|
||||
'require form';
|
||||
'require ui';
|
||||
'require uci';
|
||||
'require rpc';
|
||||
|
||||
var callExec = rpc.declare({
|
||||
object: 'luci',
|
||||
method: 'exec',
|
||||
params: ['command'],
|
||||
expect: { result: 0 }
|
||||
});
|
||||
|
||||
return view.extend({
|
||||
load: function() {
|
||||
return uci.load('taskplan');
|
||||
},
|
||||
|
||||
render: function(data) {
|
||||
var m = new form.Map('taskplan', _('Scheduled Tasks'),
|
||||
_('<b>The original [Timing Settings] includes scheduled task execution and startup task execution. Presets include over 10 functions, including restart, shutdown, network restart, memory release, system cleaning, network sharing, network shutdown, automatic detection of network disconnects and reconnection, MWAN3 load balancing detection of reconnection, and custom scripts</b></br>') +
|
||||
_('N1-N5 is continuous, N1, N3, N5 is discontinuous, */N represents every N hours or every N minutes.The week can only be 0~6, the hour can only be 0~23, the minute can only be 0~59, the unavailable time is 48 hours.'));
|
||||
|
||||
var s = m.section(form.TypedSection, 'global');
|
||||
s.anonymous = true;
|
||||
|
||||
var e = s.option(form.TextValue, 'customscript', _('Edit Custom Script'));
|
||||
e.description = _('Shell commands for [Customscript] task type');
|
||||
e.rows = 5;
|
||||
e.default = '#!/bin/bash\n# Add your commands here';
|
||||
e.optional = false;
|
||||
|
||||
e = s.option(form.TextValue, 'customscript2', _('Edit Custom Script2'));
|
||||
e.description = _('Shell commands for [Customscript2] task type');
|
||||
e.rows = 5;
|
||||
e.default = '#!/bin/bash\n# Add your commands here';
|
||||
e.optional = false;
|
||||
|
||||
var ss = m.section(form.TypedSection, 'stime', '');
|
||||
ss.addremove = true;
|
||||
ss.anonymous = true;
|
||||
ss.sortable = true;
|
||||
ss.template = 'cbi/tblsection';
|
||||
|
||||
var remarks = ss.option(form.Value, 'remarks', _('Remarks'));
|
||||
remarks.optional = false;
|
||||
|
||||
var enable = ss.option(form.Flag, 'enable', _('Enable'));
|
||||
enable.rmempty = false;
|
||||
enable.default = 1;
|
||||
|
||||
var stype = ss.option(form.ListValue, 'stype', _('Scheduled Type'));
|
||||
stype.value(1, _('Scheduled Reboot'));
|
||||
stype.value(2, _('Scheduled Poweroff'));
|
||||
stype.value(3, _('Scheduled ReNetwork'));
|
||||
stype.value(4, _('Scheduled RestartSamba'));
|
||||
stype.value(5, _('Scheduled Restartwan'));
|
||||
stype.value(6, _('Scheduled Closewan'));
|
||||
stype.value(7, _('Scheduled Clearmem'));
|
||||
stype.value(8, _('Scheduled Sysfree'));
|
||||
stype.value(9, _('Scheduled DisReconn'));
|
||||
stype.value(10, _('Scheduled DisRereboot'));
|
||||
stype.value(11, _('Scheduled Restartmwan3'));
|
||||
stype.value(13, _('Scheduled Wifiup'));
|
||||
stype.value(14, _('Scheduled Wifidown'));
|
||||
stype.value(12, _('Scheduled Customscript'));
|
||||
stype.value(15, _('Scheduled Customscript2'));
|
||||
stype.default = 1;
|
||||
|
||||
var month = ss.option(form.Value, 'month', _('Month(0~11)'));
|
||||
month.rmempty = false;
|
||||
month.default = '*';
|
||||
month.datatype = 'string';
|
||||
|
||||
var week = ss.option(form.Value, 'week', _('Week Day(0~6)'));
|
||||
week.rmempty = true;
|
||||
week.value('*', _('Everyday'));
|
||||
week.value('0', _('Sunday'));
|
||||
week.value('1', _('Monday'));
|
||||
week.value('2', _('Tuesday'));
|
||||
week.value('3', _('Wednesday'));
|
||||
week.value('4', _('Thursday'));
|
||||
week.value('5', _('Friday'));
|
||||
week.value('6', _('Saturday'));
|
||||
week.default = '*';
|
||||
week.datatype = 'string';
|
||||
|
||||
var hour = ss.option(form.Value, 'hour', _('Hour(0~23)'));
|
||||
hour.description = _('1-8 is the continuous time from 1-8 clock; 11,12,16 clock are discontinuous; */3 represents every 3 hours; * every hour.');
|
||||
hour.rmempty = false;
|
||||
hour.default = 0;
|
||||
hour.datatype = 'string';
|
||||
|
||||
var minute = ss.option(form.Value, 'minute', _('Minute(0~59)'));
|
||||
minute.description = _('1-30 is continuous 1-30 minutes; 7,8,9 minutes discontinuous ; */5 means every 5 minutes ; * every minutes.');
|
||||
minute.rmempty = false;
|
||||
minute.default = 0;
|
||||
minute.datatype = 'string';
|
||||
|
||||
m.apply_on_parse = true;
|
||||
m.on_after_apply = function() {
|
||||
return callExec('/etc/init.d/taskplan start').then(function() {
|
||||
ui.addNotification(null, E('p', {}, _('Tasks updated')));
|
||||
});
|
||||
};
|
||||
|
||||
return m.render();
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,87 @@
|
||||
'use strict';
|
||||
'require view';
|
||||
'require form';
|
||||
'require ui';
|
||||
'require uci';
|
||||
'require rpc';
|
||||
|
||||
var callExec = rpc.declare({
|
||||
object: 'luci',
|
||||
method: 'exec',
|
||||
params: ['command'],
|
||||
expect: { result: 0 }
|
||||
});
|
||||
|
||||
return view.extend({
|
||||
load: function() {
|
||||
return uci.load('taskplan');
|
||||
},
|
||||
|
||||
render: function(data) {
|
||||
var m = new form.Map('taskplan', _('Startup Tasks'),
|
||||
_('<b>The original [Timing Settings] includes scheduled task execution and startup task execution. Presets include over 10 functions, including restart, shutdown, network restart, memory release, system cleaning, network sharing, network shutdown, automatic detection of network disconnects and reconnection, MWAN3 load balancing detection of reconnection, and custom scripts</b></br>') +
|
||||
_('The task to be executed upon startup, with a startup delay time unit of seconds.'));
|
||||
|
||||
var s = m.section(form.TypedSection, 'global');
|
||||
s.anonymous = true;
|
||||
|
||||
var e = s.option(form.TextValue, 'customscript', _('Edit Custom Script'));
|
||||
e.description = _('Shell commands for Customscript task type');
|
||||
e.rows = 5;
|
||||
e.default = '#!/bin/sh\n# Add your commands here';
|
||||
e.optional = false;
|
||||
|
||||
e = s.option(form.TextValue, 'customscript2', _('Edit Custom Script2'));
|
||||
e.description = _('Shell commands for Customscript2 task type');
|
||||
e.rows = 5;
|
||||
e.default = '#!/bin/sh\n# Add your commands here';
|
||||
e.optional = false;
|
||||
|
||||
var ls = m.section(form.TypedSection, 'ltime', '');
|
||||
ls.addremove = true;
|
||||
ls.anonymous = true;
|
||||
ls.sortable = true;
|
||||
ls.template = 'cbi/tblsection';
|
||||
|
||||
var remarks = ls.option(form.Value, 'remarks', _('Remarks'));
|
||||
remarks.optional = false;
|
||||
|
||||
var enable = ls.option(form.Flag, 'enable', _('Enable'));
|
||||
enable.rmempty = false;
|
||||
enable.default = 1;
|
||||
|
||||
var stype = ls.option(form.ListValue, 'stype', _('Startup Type'));
|
||||
stype.description = _('Action to perform at system startup');
|
||||
stype.value(1, _('Scheduled Reboot'));
|
||||
stype.value(2, _('Scheduled Poweroff'));
|
||||
stype.value(3, _('Scheduled ReNetwork'));
|
||||
stype.value(4, _('Scheduled RestartSamba'));
|
||||
stype.value(5, _('Scheduled Restartwan'));
|
||||
stype.value(6, _('Scheduled Closewan'));
|
||||
stype.value(7, _('Scheduled Clearmem'));
|
||||
stype.value(8, _('Scheduled Sysfree'));
|
||||
stype.value(9, _('Scheduled DisReconn'));
|
||||
stype.value(10, _('Scheduled DisRereboot'));
|
||||
stype.value(11, _('Scheduled Restartmwan3'));
|
||||
stype.value(13, _('Scheduled Wifiup'));
|
||||
stype.value(14, _('Scheduled Wifidown'));
|
||||
stype.value(12, _('Scheduled Customscript'));
|
||||
stype.value(15, _('Scheduled Customscript2'));
|
||||
stype.default = 12;
|
||||
|
||||
var delay = ls.option(form.Value, 'delay', _('Delayed Start(seconds)'));
|
||||
delay.description = _('Seconds to wait after boot before execution');
|
||||
delay.datatype = 'uinteger';
|
||||
delay.default = 10;
|
||||
delay.optional = false;
|
||||
|
||||
m.apply_on_parse = true;
|
||||
m.on_after_apply = function() {
|
||||
return callExec('/etc/init.d/taskplan start').then(function() {
|
||||
ui.addNotification(null, E('p', {}, _('Tasks updated')));
|
||||
});
|
||||
};
|
||||
|
||||
return m.render();
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,309 @@
|
||||
# Translation file for taskplan.js
|
||||
# Copyright (C) 2022-2026 Sirpdboy <herboy2008@gmail.com>
|
||||
# Licensed to the public under the Apache License 2.0
|
||||
#
|
||||
|
||||
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: luci-app-taskplan\n"
|
||||
"Language: zh_Hans\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
|
||||
msgid "Control"
|
||||
msgstr "管控"
|
||||
|
||||
msgid "Task Plan"
|
||||
msgstr "任务设置"
|
||||
|
||||
msgid "Scheduled Tasks"
|
||||
msgstr "定时执行任务"
|
||||
|
||||
msgid "Startup Tasks"
|
||||
msgstr "开机启动任务"
|
||||
|
||||
msgid "<b>The original [Timing Settings] includes scheduled task execution and startup task execution. Presets include over 10 functions, including restart, shutdown, network restart, memory release, system cleaning, network sharing, network shutdown, automatic detection of network disconnects and reconnection, MWAN3 load balancing detection of reconnection, and custom scripts</b></br>"
|
||||
msgstr "<b>原【定时设置】包括定时任务执行和启动任务执行。预设了重启、关机、网络重启、释放内存、系统清理、网络共享、网络关闭、自动检测断网重连、MWAN3负载均衡检测重连、自定义脚本等10余种功能</b></br>"
|
||||
|
||||
msgid "N1-N5 is continuous, N1, N3, N5 is discontinuous, */N represents every N hours or every N minutes.The week can only be 0~6, the hour can only be 0~23, the minute can only be 0~59, the unavailable time is 48 hours."
|
||||
msgstr "N1-N5为连续,N1、N3、N5为不连续,*/N表示每N小时或每N分钟。星期只能0~6,小时只能0~23,分钟只能0~59,不可用时间为48小时。"
|
||||
|
||||
msgid "Edit Custom Script"
|
||||
msgstr "编辑自定义脚本"
|
||||
|
||||
msgid "Shell commands for [Customscript] task type"
|
||||
msgstr "【自定义脚本】任务类型的Shell命令"
|
||||
|
||||
msgid "Edit Custom Script2"
|
||||
msgstr "编辑自定义脚本2"
|
||||
|
||||
msgid "Shell commands for [Customscript2] task type"
|
||||
msgstr "【自定义脚本2】任务类型的Shell命令"
|
||||
|
||||
# scheduled.js - 任务列表
|
||||
msgid "Remarks"
|
||||
msgstr "备注"
|
||||
|
||||
msgid "Task description"
|
||||
msgstr "任务描述"
|
||||
|
||||
msgid "Enable"
|
||||
msgstr "启用"
|
||||
|
||||
msgid "Scheduled Type"
|
||||
msgstr "定时类型"
|
||||
|
||||
|
||||
# scheduled.js - 任务类型值
|
||||
msgid "Scheduled Reboot"
|
||||
msgstr "定时重启"
|
||||
|
||||
msgid "Scheduled Poweroff"
|
||||
msgstr "定时关机"
|
||||
|
||||
msgid "Scheduled ReNetwork"
|
||||
msgstr "定时重启网络"
|
||||
|
||||
msgid "Scheduled RestartSamba"
|
||||
msgstr "定时重启Samba"
|
||||
|
||||
msgid "Scheduled Restartwan"
|
||||
msgstr "定时重启WAN"
|
||||
|
||||
msgid "Scheduled Closewan"
|
||||
msgstr "定时关闭WAN"
|
||||
|
||||
msgid "Scheduled Clearmem"
|
||||
msgstr "定时清理内存"
|
||||
|
||||
msgid "Scheduled Sysfree"
|
||||
msgstr "定时系统清理"
|
||||
|
||||
msgid "Scheduled DisReconn"
|
||||
msgstr "定时断网重连"
|
||||
|
||||
msgid "Scheduled DisRereboot"
|
||||
msgstr "定时断网重启"
|
||||
|
||||
msgid "Scheduled Restartmwan3"
|
||||
msgstr "定时重启MWAN3"
|
||||
|
||||
msgid "Scheduled Wifiup"
|
||||
msgstr "定时开启WiFi"
|
||||
|
||||
msgid "Scheduled Wifidown"
|
||||
msgstr "定时关闭WiFi"
|
||||
|
||||
msgid "Scheduled Customscript"
|
||||
msgstr "定时 自定义脚本"
|
||||
|
||||
msgid "Scheduled Customscript2"
|
||||
msgstr "定时 自定义脚本2"
|
||||
|
||||
# scheduled.js - 时间设置
|
||||
msgid "Month(0~11)"
|
||||
msgstr "月份(0~11)"
|
||||
|
||||
msgid "Week Day(0~6)"
|
||||
msgstr "星期(0~6)"
|
||||
|
||||
msgid "Everyday"
|
||||
msgstr "每天"
|
||||
|
||||
msgid "Sunday"
|
||||
msgstr "星期日"
|
||||
|
||||
msgid "Monday"
|
||||
msgstr "星期一"
|
||||
|
||||
msgid "Tuesday"
|
||||
msgstr "星期二"
|
||||
|
||||
msgid "Wednesday"
|
||||
msgstr "星期三"
|
||||
|
||||
msgid "Thursday"
|
||||
msgstr "星期四"
|
||||
|
||||
msgid "Friday"
|
||||
msgstr "星期五"
|
||||
|
||||
msgid "Saturday"
|
||||
msgstr "星期六"
|
||||
|
||||
msgid "Hour(0~23)"
|
||||
msgstr "小时(0~23)"
|
||||
|
||||
msgid "1-8 is the continuous time from 1-8 clock; 11,12,16 clock are discontinuous; */3 represents every 3 hours; * every hour."
|
||||
msgstr "1-8是从1点到8点的连续时间;11、12、16点钟不连续;*/3表示每3小时一次;*每小时。"
|
||||
|
||||
msgid "Minute(0~59)"
|
||||
msgstr "分钟(0~59)"
|
||||
|
||||
msgid "1-30 is continuous 1-30 minutes; 7,8,9 minutes discontinuous ; */5 means every 5 minutes ; * every minutes."
|
||||
msgstr "1-30是连续的1-30分钟;7,8,9分钟不连续;*/5表示每5分钟一次;*每分钟。"
|
||||
|
||||
msgid "Tasks updated"
|
||||
msgstr "任务已更新"
|
||||
|
||||
# startup.js - 页面标题和说明
|
||||
msgid "Startup task"
|
||||
msgstr "启动任务"
|
||||
|
||||
msgid "The task to be executed upon startup, with a startup delay time unit of seconds."
|
||||
msgstr "在启动时执行的任务,启动延迟时间单位为秒。"
|
||||
|
||||
# startup.js - 任务类型
|
||||
msgid "Startup Type"
|
||||
msgstr "启动类型"
|
||||
|
||||
msgid "Action to perform at system startup"
|
||||
msgstr "系统启动时要执行的操作"
|
||||
|
||||
# startup.js - 延迟设置
|
||||
msgid "Delayed Start(seconds)"
|
||||
msgstr "延迟启动(秒)"
|
||||
|
||||
msgid "Seconds to wait after boot before execution"
|
||||
msgstr "启动后等待执行的秒数"
|
||||
|
||||
# startup.js - 提示
|
||||
msgid "⚠️ DANGEROUS - Will reboot system after boot"
|
||||
msgstr "⚠️ 危险 - 启动后会重启系统"
|
||||
|
||||
msgid "⚠️ DANGEROUS - Will shutdown system after boot"
|
||||
msgstr "⚠️ 危险 - 启动后会关闭系统"
|
||||
|
||||
msgid "⚠️ May disrupt connectivity"
|
||||
msgstr "⚠️ 可能会中断连接"
|
||||
|
||||
msgid "✓ Safe - Restart file sharing"
|
||||
msgstr "✓ 安全 - 重启文件共享"
|
||||
|
||||
msgid "✓ Safe - Restart WAN connection"
|
||||
msgstr "✓ 安全 - 重启WAN连接"
|
||||
|
||||
msgid "⚠️ Will disable internet - use with delay"
|
||||
msgstr "⚠️ 会禁用网络 - 请使用延迟"
|
||||
|
||||
msgid "✓ Safe - Clear memory cache"
|
||||
msgstr "✓ 安全 - 清理内存缓存"
|
||||
|
||||
msgid "⚠️ Will clean system and reboot - careful"
|
||||
msgstr "⚠️ 会清理系统并重启 - 小心使用"
|
||||
|
||||
msgid "✓ Safe - Check and reconnect internet"
|
||||
msgstr "✓ 安全 - 检查并重连网络"
|
||||
|
||||
msgid "⚠️ May reboot if no internet - use delay"
|
||||
msgstr "⚠️ 无网络时可能重启 - 请使用延迟"
|
||||
|
||||
msgid "✓ Safe - Restart MWAN3"
|
||||
msgstr "✓ 安全 - 重启MWAN3"
|
||||
|
||||
msgid "✓ Safe - Enable WiFi"
|
||||
msgstr "✓ 安全 - 开启WiFi"
|
||||
|
||||
msgid "✓ Safe - Disable WiFi"
|
||||
msgstr "✓ 安全 - 关闭WiFi"
|
||||
|
||||
msgid "✓ Recommended - Run custom script 1"
|
||||
msgstr "✓ 推荐 - 运行自定义脚本1"
|
||||
|
||||
msgid "✓ Recommended - Run custom script 2"
|
||||
msgstr "✓ 推荐 - 运行自定义脚本2"
|
||||
|
||||
# log.js - 页面标题和按钮
|
||||
|
||||
msgid "Log Viewer"
|
||||
msgstr "日志查看"
|
||||
|
||||
msgid "Task Plan Log Viewer"
|
||||
msgstr "任务设置日志查看"
|
||||
|
||||
msgid "Clear Log"
|
||||
msgstr "清空日志"
|
||||
|
||||
msgid "Reverse Order"
|
||||
msgstr "反向显示"
|
||||
|
||||
msgid "Download Log"
|
||||
msgstr "下载日志"
|
||||
|
||||
msgid "Execution Log"
|
||||
msgstr "执行日志"
|
||||
|
||||
msgid "Log cleared"
|
||||
msgstr "日志已清空"
|
||||
|
||||
msgid "Failed to clear log: "
|
||||
msgstr "清空日志失败:"
|
||||
|
||||
msgid "Log is empty"
|
||||
msgstr "日志为空"
|
||||
|
||||
# log.js - 状态卡片
|
||||
msgid "Service"
|
||||
msgstr "服务"
|
||||
|
||||
msgid "Running"
|
||||
msgstr "运行中"
|
||||
|
||||
msgid "Stopped"
|
||||
msgstr "已停止"
|
||||
|
||||
msgid "Scheduled"
|
||||
msgstr "定时任务"
|
||||
|
||||
msgid "Startup"
|
||||
msgstr "启动任务"
|
||||
|
||||
msgid "Cron"
|
||||
msgstr "定时条目"
|
||||
|
||||
msgid "Status"
|
||||
msgstr "状态"
|
||||
|
||||
msgid "Type"
|
||||
msgstr "类型"
|
||||
|
||||
msgid "Schedule"
|
||||
msgstr "调度时间"
|
||||
|
||||
msgid "Delay"
|
||||
msgstr "延迟"
|
||||
|
||||
msgid "No scheduled tasks"
|
||||
msgstr "没有定时任务"
|
||||
|
||||
msgid "No startup tasks"
|
||||
msgstr "没有启动任务"
|
||||
|
||||
# log.js - 任务状态指示
|
||||
msgid "● Enabled"
|
||||
msgstr "● 已启用"
|
||||
|
||||
msgid "○ Disabled"
|
||||
msgstr "○ 已禁用"
|
||||
|
||||
# 通用
|
||||
msgid "Unknown"
|
||||
msgstr "未知"
|
||||
|
||||
msgid "Error"
|
||||
msgstr "错误"
|
||||
|
||||
msgid "Success"
|
||||
msgstr "成功"
|
||||
|
||||
msgid "Failed"
|
||||
msgstr "失败"
|
||||
|
||||
msgid "Please wait..."
|
||||
msgstr "请稍候..."
|
||||
|
||||
msgid "Operation completed"
|
||||
msgstr "操作完成"
|
||||
|
||||
msgid "Operation failed"
|
||||
msgstr "操作失败"
|
||||
@@ -0,0 +1,33 @@
|
||||
|
||||
config global
|
||||
option enabled '0'
|
||||
option customscript '# Sh script rules'
|
||||
option customscript2 '# Sh script rules'
|
||||
|
||||
config stime
|
||||
option week '*'
|
||||
option stype '2'
|
||||
option month '*'
|
||||
option enable '0'
|
||||
option ttype '0'
|
||||
option delay '10'
|
||||
option remarks '每天22:30执行'
|
||||
option hour '22'
|
||||
option minute '30'
|
||||
config stime
|
||||
option week '*'
|
||||
option month '*'
|
||||
option stype '11'
|
||||
option ttype '1'
|
||||
option delay '20'
|
||||
option enable '0'
|
||||
option hour '*'
|
||||
option remarks '每月每天每过4分钟执行'
|
||||
option minute '*/4'
|
||||
|
||||
config ltime
|
||||
option remarks '开机启动延时30秒执行'
|
||||
option stype '11'
|
||||
option delay '30'
|
||||
option enable '0'
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
# copyright by sirpdboy
|
||||
# Converted for OpenWrt 25.10
|
||||
|
||||
START=99
|
||||
STOP=10
|
||||
TMP=/etc/taskplan
|
||||
LOG=$TMP/taskplan.log
|
||||
TT=/etc/taskplan/taskplanrun
|
||||
CR=/etc/crontabs/root
|
||||
|
||||
# 确保目录存在
|
||||
[ ! -d $TMP ] && mkdir -p $TMP 2>/dev/null
|
||||
[ ! -s $LOG ] && echo '' > $LOG
|
||||
|
||||
run_taskplan()
|
||||
{
|
||||
[ -n "$(uci -q get taskplan.@global[0].customscript)" ] && \
|
||||
uci -q get taskplan.@global[0].customscript > /etc/taskplan/taskplancustomscript && \
|
||||
sed -i 's/\r$//' /etc/taskplan/taskplancustomscript
|
||||
|
||||
[ -n "$(uci -q get taskplan.@global[0].customscript2)" ] && \
|
||||
uci -q get taskplan.@global[0].customscript2 > /etc/taskplan/taskplancustomscript2 && \
|
||||
sed -i 's/\r$//' /etc/taskplan/taskplancustomscript2
|
||||
|
||||
ssum=$(uci -q show taskplan | grep -c "stime\[[0-9]\]" || echo 0)
|
||||
lsum=$(uci -q show taskplan | grep -c "ltime\[[0-9]\]" || echo 0)
|
||||
|
||||
# 清空crontab中的taskplan条目
|
||||
sed -i '/taskplanhandler/d' $CR >/dev/null 2>&1
|
||||
|
||||
# 处理定时任务
|
||||
for i in $(seq 0 $((ssum-1)) 2>/dev/null); do
|
||||
enable=$(uci -q get taskplan.@stime[$i].enable)
|
||||
if [ "x$enable" = "x1" ]; then
|
||||
month=$(uci -q get taskplan.@stime[$i].month || echo "*")
|
||||
stype=$(uci -q get taskplan.@stime[$i].stype)
|
||||
week=$(uci -q get taskplan.@stime[$i].week || echo "*")
|
||||
minute=$(uci -q get taskplan.@stime[$i].minute || echo "0")
|
||||
hour=$(uci -q get taskplan.@stime[$i].hour || echo "*")
|
||||
|
||||
# 格式化时间
|
||||
[ "$hour" = "0" ] && hour="0"
|
||||
[ "$minute" = "0" ] && minute="0"
|
||||
|
||||
case "$stype" in
|
||||
1) cmd="$minute $hour * $month $week /usr/bin/taskplanhandler reboot Scheduled_task" ;;
|
||||
2) cmd="$minute $hour * $month $week /usr/bin/taskplanhandler poweroff Scheduled_task" ;;
|
||||
3) cmd="$minute $hour * $month $week /usr/bin/taskplanhandler network Scheduled_task" ;;
|
||||
4) cmd="$minute $hour * $month $week /usr/bin/taskplanhandler restartsamba Scheduled_task" ;;
|
||||
5) cmd="$minute $hour * $month $week /usr/bin/taskplanhandler restartwan Scheduled_task" ;;
|
||||
6) cmd="$minute $hour * $month $week /usr/bin/taskplanhandler closewan Scheduled_task" ;;
|
||||
7) cmd="$minute $hour * $month $week /usr/bin/taskplanhandler clearmem Scheduled_task" ;;
|
||||
8) cmd="$minute $hour * $month $week /usr/bin/taskplanhandler sysfree Scheduled_task" ;;
|
||||
9) cmd="$minute $hour * $month $week /usr/bin/taskplanhandler disreconn Scheduled_task" ;;
|
||||
10) cmd="$minute $hour * $month $week /usr/bin/taskplanhandler disrereboot Scheduled_task" ;;
|
||||
11) cmd="$minute $hour * $month $week /usr/bin/taskplanhandler restartmwan3 Scheduled_task" ;;
|
||||
12) cmd="$minute $hour * $month $week /usr/bin/taskplanhandler customscript Scheduled_task" ;;
|
||||
13) cmd="$minute $hour * $month $week /usr/bin/taskplanhandler upwifi Scheduled_task" ;;
|
||||
14) cmd="$minute $hour * $month $week /usr/bin/taskplanhandler downwifi Scheduled_task" ;;
|
||||
15) cmd="$minute $hour * $month $week /usr/bin/taskplanhandler customscript2 Scheduled_task" ;;
|
||||
16) cmd="$minute $hour * $month $week /usr/bin/taskplanhandler restartlan Scheduled_task" ;;
|
||||
esac
|
||||
echo "$cmd" >> $CR
|
||||
fi
|
||||
done
|
||||
|
||||
# 创建启动任务脚本
|
||||
echo "#!/bin/sh" > $TT
|
||||
chmod +x $TT
|
||||
|
||||
for i in $(seq 0 $((lsum-1)) 2>/dev/null); do
|
||||
enable=$(uci -q get taskplan.@ltime[$i].enable)
|
||||
if [ "x$enable" = "x1" ]; then
|
||||
stype=$(uci -q get taskplan.@ltime[$i].stype)
|
||||
delay=$(uci -q get taskplan.@ltime[$i].delay || echo 10)
|
||||
|
||||
case "$stype" in
|
||||
1) echo "(sleep $delay && /usr/bin/taskplanhandler reboot Startup_task) &" >>$TT ;;
|
||||
2) echo "(sleep $delay && /usr/bin/taskplanhandler poweroff Startup_task) &" >>$TT ;;
|
||||
3) echo "(sleep $delay && /usr/bin/taskplanhandler network Startup_task) &" >>$TT ;;
|
||||
4) echo "(sleep $delay && /usr/bin/taskplanhandler restartsamba Startup_task) &" >>$TT ;;
|
||||
5) echo "(sleep $delay && /usr/bin/taskplanhandler restartwan Startup_task) &" >>$TT ;;
|
||||
6) echo "(sleep $delay && /usr/bin/taskplanhandler closewan Startup_task) &" >>$TT ;;
|
||||
7) echo "(sleep $delay && /usr/bin/taskplanhandler clearmem Startup_task) &" >>$TT ;;
|
||||
8) echo "(sleep $delay && /usr/bin/taskplanhandler sysfree Startup_task) &" >>$TT ;;
|
||||
9) echo "(sleep $delay && /usr/bin/taskplanhandler disreconn Startup_task) &" >>$TT ;;
|
||||
10) echo "(sleep $delay && /usr/bin/taskplanhandler disrereboot Startup_task) &" >>$TT ;;
|
||||
11) echo "(sleep $delay && /usr/bin/taskplanhandler restartmwan3 Startup_task) &" >>$TT ;;
|
||||
12) echo "(sleep $delay && /usr/bin/taskplanhandler customscript Startup_task) &" >>$TT ;;
|
||||
13) echo "(sleep $delay && /usr/bin/taskplanhandler upwifi Startup_task) &" >>$TT ;;
|
||||
14) echo "(sleep $delay && /usr/bin/taskplanhandler downwifi Startup_task) &" >>$TT ;;
|
||||
15) echo "(sleep $delay && /usr/bin/taskplanhandler customscript2 Startup_task) &" >>$TT ;;
|
||||
16) echo "(sleep $delay && /usr/bin/taskplanhandler restartlan Startup_task) &" >>$TT ;;
|
||||
esac
|
||||
fi
|
||||
done
|
||||
|
||||
echo 'exit 0' >> $TT
|
||||
}
|
||||
|
||||
start()
|
||||
{
|
||||
del_cru
|
||||
run_taskplan
|
||||
/etc/init.d/cron reload
|
||||
echo "$(date): taskplan started" >> $LOG
|
||||
}
|
||||
|
||||
boot()
|
||||
{
|
||||
# 启动时执行
|
||||
del_cru
|
||||
run_taskplan
|
||||
/etc/init.d/cron reload
|
||||
|
||||
if [ -f $TT ] && [ -s $TT ]; then
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S'): Executing taskplanrun at boot" >> $LOG
|
||||
bash $TT >> $LOG 2>&1 &
|
||||
else
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S'): taskplanrun file not found or empty at boot" >> $LOG
|
||||
fi
|
||||
}
|
||||
|
||||
stop()
|
||||
{
|
||||
del_cru
|
||||
/etc/init.d/cron reload
|
||||
}
|
||||
|
||||
restart()
|
||||
{
|
||||
stop
|
||||
sleep 2
|
||||
start
|
||||
}
|
||||
del_cru()
|
||||
{
|
||||
sed -i '/taskplanhandler/d' $CR >/dev/null 2>&1 || true
|
||||
echo "#!/bin/sh" > $TT # 清空文件但保留基本结构
|
||||
chmod +x $TT
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
#!/bin/bash\n# Add your commands here
|
||||
@@ -0,0 +1 @@
|
||||
#!/bin/bash\n# Add your commands here
|
||||
@@ -0,0 +1,4 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo ""
|
||||
exit 0
|
||||
@@ -0,0 +1,15 @@
|
||||
#!/bin/sh
|
||||
if [ ! -f /etc/config/taskplan ]; then
|
||||
cat > /etc/config/taskplan << EOF
|
||||
config global 'global'
|
||||
option customscript ' '
|
||||
option customscript2 ' '
|
||||
|
||||
EOF
|
||||
fi
|
||||
mkdir -p /etc/taskplan
|
||||
touch /etc/taskplan/taskplan.log
|
||||
chmod +x /usr/libexec/rpcd/luci.taskplan /etc/init.d/taskplan /etc/taskplan/taskplanrun /usr/bin/taskplanhandler
|
||||
rm -rf /tmp/luci-modulecache /tmp/luci-indexcache*
|
||||
|
||||
exit 0
|
||||
@@ -0,0 +1,155 @@
|
||||
#!/bin/sh
|
||||
# author 2021 jjm2473
|
||||
# author 2020-2026 sirpdboy
|
||||
# Converted for OpenWrt 25.10
|
||||
|
||||
TMP_T=/var/taskplan/taskplan.tmp
|
||||
LOG=/etc/taskplan/taskplan.log
|
||||
|
||||
log(){
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') $*" >> $LOG
|
||||
}
|
||||
|
||||
limit_log() {
|
||||
local logf=$1
|
||||
[ ! -f "$logf" ] && return
|
||||
local sc=100
|
||||
[ -n "$2" ] && sc=$2
|
||||
local count=$(grep -c "" $logf 2>/dev/null || echo 0)
|
||||
if [ $count -gt $sc ]; then
|
||||
let count=count-$sc
|
||||
sed -i "1,$count d" $logf 2>/dev/null
|
||||
fi
|
||||
}
|
||||
|
||||
remwan3() {
|
||||
while true; do
|
||||
status=$(/usr/sbin/mwan3 status 2>/dev/null | grep -i error)
|
||||
if [ -z "$status" ]; then
|
||||
log "Mwan3 is OK"
|
||||
exit 0
|
||||
else
|
||||
log "mwan3 restarting ..."
|
||||
/usr/sbin/mwan3 restart
|
||||
fi
|
||||
sleep 60
|
||||
done
|
||||
}
|
||||
|
||||
disreconnwan() {
|
||||
i=0
|
||||
PingA=114.114.114.114
|
||||
PingB=223.5.5.5
|
||||
PingErr=1
|
||||
|
||||
while [ $i -lt 5 ]; do
|
||||
if ping -c 1 -W 3 $PingA >/dev/null 2>&1; then
|
||||
PingErr=0
|
||||
break
|
||||
elif ping -c 1 -W 3 $PingB >/dev/null 2>&1; then
|
||||
PingErr=0
|
||||
break
|
||||
else
|
||||
i=$((i + 1))
|
||||
sleep 10
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
trigger() {
|
||||
case "$1" in
|
||||
reboot)
|
||||
reboot
|
||||
;;
|
||||
poweroff)
|
||||
poweroff
|
||||
;;
|
||||
network)
|
||||
/etc/init.d/network restart
|
||||
;;
|
||||
clearmem)
|
||||
sync && echo 3 > /proc/sys/vm/drop_caches
|
||||
;;
|
||||
sysfree)
|
||||
cd /overlay
|
||||
rm -rf $(ls | egrep -v '(upper|.fs_state)') 2>/dev/null
|
||||
cd upper 2>/dev/null
|
||||
rm -rf $(ls | egrep -v '(etc)') 2>/dev/null
|
||||
cd etc 2>/dev/null
|
||||
rm -rf $(ls | egrep -v '(config|ssr|bench.log|shadow)') 2>/dev/null
|
||||
rm -rf /var/luci-modulecache 2>/dev/null
|
||||
rm -rf /var/luci-indexcache 2>/dev/null
|
||||
rm -rf /tmp/cache/* 2>/dev/null
|
||||
reboot
|
||||
;;
|
||||
restartsamba)
|
||||
/etc/init.d/ksmdb restart 2>/dev/null
|
||||
/etc/init.d/samba restart 2>/dev/null
|
||||
/etc/init.d/samba4 restart 2>/dev/null
|
||||
log "Samba restarted"
|
||||
;;
|
||||
restartlan)
|
||||
ifdown lan && ifup lan
|
||||
log "restart lan succeeded!"
|
||||
;;
|
||||
restartwan)
|
||||
ifup wan
|
||||
log "restart wan succeeded!"
|
||||
;;
|
||||
closewan)
|
||||
ifdown wan
|
||||
;;
|
||||
disreconn)
|
||||
disreconnwan
|
||||
if [ $PingErr = 1 ]; then
|
||||
ifup wan
|
||||
log "Redial succeeded!"
|
||||
fi
|
||||
;;
|
||||
disrereboot)
|
||||
disreconnwan
|
||||
if [ $PingErr = 1 ]; then
|
||||
log "Reboot succeeded!"
|
||||
reboot
|
||||
fi
|
||||
;;
|
||||
restartmwan3)
|
||||
[ -x /usr/sbin/mwan3 ] && remwan3
|
||||
;;
|
||||
customscript)
|
||||
if [ -s /etc/taskplan/taskplancustomscript ]; then
|
||||
bash /etc/taskplan/taskplancustomscript
|
||||
log "CustomScript succeeded!"
|
||||
else
|
||||
log "CustomScript run Error!"
|
||||
fi
|
||||
;;
|
||||
customscript2)
|
||||
if [ -s /etc/taskplan/taskplancustomscript2 ]; then
|
||||
bash /etc/taskplan/taskplancustomscript2
|
||||
log "CustomScript2 succeeded!"
|
||||
else
|
||||
log "CustomScript2 run Error!"
|
||||
fi
|
||||
;;
|
||||
upwifi)
|
||||
ifconfig wlan0 up 2>/dev/null
|
||||
uci set wireless.radio0.disabled=0 2>/dev/null
|
||||
uci set wireless.radio1.disabled=0 2>/dev/null
|
||||
uci commit wireless 2>/dev/null
|
||||
wifi up
|
||||
;;
|
||||
downwifi)
|
||||
ifconfig wlan0 down 2>/dev/null
|
||||
uci set wireless.radio0.disabled=1 2>/dev/null
|
||||
uci set wireless.radio1.disabled=1 2>/dev/null
|
||||
uci commit wireless 2>/dev/null
|
||||
wifi down
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
limit_log $LOG 500
|
||||
PingErr=0
|
||||
log "Scheduled operation $2: $1" && trigger $1
|
||||
|
||||
@@ -0,0 +1,205 @@
|
||||
#!/bin/sh
|
||||
# UBUS RPC module for Task Plan
|
||||
# Path: /usr/libexec/rpcd/luci.taskplan
|
||||
|
||||
. /usr/share/libubox/jshn.sh
|
||||
|
||||
LOG_FILE="/etc/taskplan/taskplan.log"
|
||||
CONFIG_FILE="/etc/config/taskplan"
|
||||
CRON_FILE="/etc/crontabs/root"
|
||||
|
||||
# 主函数 - 处理所有RPC调用
|
||||
main() {
|
||||
local method
|
||||
|
||||
# 读取输入
|
||||
json_load "$1"
|
||||
json_get_var method method
|
||||
|
||||
case "$method" in
|
||||
status)
|
||||
status
|
||||
;;
|
||||
list)
|
||||
list
|
||||
;;
|
||||
task_list)
|
||||
task_list
|
||||
;;
|
||||
start)
|
||||
start_service
|
||||
;;
|
||||
stop)
|
||||
stop_service
|
||||
;;
|
||||
restart)
|
||||
restart_service
|
||||
;;
|
||||
reload)
|
||||
reload_service
|
||||
;;
|
||||
*)
|
||||
json_init
|
||||
json_add_int "error" 1
|
||||
json_add_string "message" "Unknown method: $method"
|
||||
json_dump
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# 获取服务状态
|
||||
status() {
|
||||
local running=0
|
||||
local cron_tasks=0
|
||||
local log_content=""
|
||||
local scheduled=0
|
||||
local startup=0
|
||||
|
||||
# 检查进程是否运行
|
||||
if pidof taskplan >/dev/null 2>&1 || pgrep -f taskplan >/dev/null 2>&1; then
|
||||
running=1
|
||||
fi
|
||||
|
||||
# 统计cron任务
|
||||
if [ -f "$CRON_FILE" ]; then
|
||||
cron_tasks=$(grep -c "taskplanhandler" "$CRON_FILE" 2>/dev/null || echo 0)
|
||||
fi
|
||||
|
||||
# 统计配置
|
||||
if [ -f "$CONFIG_FILE" ]; then
|
||||
scheduled=$(grep -c "stime" "$CONFIG_FILE" 2>/dev/null || echo 0)
|
||||
startup=$(grep -c "ltime" "$CONFIG_FILE" 2>/dev/null || echo 0)
|
||||
fi
|
||||
|
||||
# 获取日志最后50行
|
||||
if [ -f "$LOG_FILE" ]; then
|
||||
log_content=$(tail -n 50 "$LOG_FILE" 2>/dev/null)
|
||||
fi
|
||||
|
||||
json_init
|
||||
json_add_int "running" $running
|
||||
json_add_int "cron_tasks" $cron_tasks
|
||||
json_add_int "scheduled_tasks" $scheduled
|
||||
json_add_int "startup_tasks" $startup
|
||||
json_add_string "log" "$log_content"
|
||||
json_dump
|
||||
}
|
||||
|
||||
# 获取配置统计
|
||||
list() {
|
||||
local ssum=0
|
||||
local lsum=0
|
||||
|
||||
if [ -f "$CONFIG_FILE" ]; then
|
||||
ssum=$(grep -c "stime" "$CONFIG_FILE" 2>/dev/null || echo 0)
|
||||
lsum=$(grep -c "ltime" "$CONFIG_FILE" 2>/dev/null || echo 0)
|
||||
fi
|
||||
|
||||
json_init
|
||||
json_add_int "scheduled" $ssum
|
||||
json_add_int "startup" $lsum
|
||||
json_dump
|
||||
}
|
||||
|
||||
# 获取任务列表
|
||||
task_list() {
|
||||
json_init
|
||||
json_add_array "tasks"
|
||||
|
||||
# 获取定时任务
|
||||
if [ -f "$CONFIG_FILE" ]; then
|
||||
local index=0
|
||||
while true; do
|
||||
local section=$(uci -q get taskplan.@stime[$index] 2>/dev/null)
|
||||
[ -z "$section" ] && break
|
||||
|
||||
local enable=$(uci -q get taskplan.@stime[$index].enable || echo 0)
|
||||
local remarks=$(uci -q get taskplan.@stime[$index].remarks || echo "")
|
||||
local stype=$(uci -q get taskplan.@stime[$index].stype || echo "")
|
||||
local month=$(uci -q get taskplan.@stime[$index].month || echo "*")
|
||||
local week=$(uci -q get taskplan.@stime[$index].week || echo "*")
|
||||
local hour=$(uci -q get taskplan.@stime[$index].hour || echo "*")
|
||||
local minute=$(uci -q get taskplan.@stime[$index].minute || echo "*")
|
||||
|
||||
json_add_object
|
||||
json_add_string "type" "scheduled"
|
||||
json_add_int "index" $index
|
||||
json_add_int "enable" $enable
|
||||
json_add_string "remarks" "$remarks"
|
||||
json_add_string "stype" "$stype"
|
||||
json_add_string "schedule" "$minute $hour $week $month"
|
||||
json_close_object
|
||||
|
||||
index=$((index + 1))
|
||||
done
|
||||
|
||||
# 获取启动任务
|
||||
local index=0
|
||||
while true; do
|
||||
local section=$(uci -q get taskplan.@ltime[$index] 2>/dev/null)
|
||||
[ -z "$section" ] && break
|
||||
|
||||
local enable=$(uci -q get taskplan.@ltime[$index].enable || echo 0)
|
||||
local remarks=$(uci -q get taskplan.@ltime[$index].remarks || echo "")
|
||||
local stype=$(uci -q get taskplan.@ltime[$index].stype || echo "")
|
||||
local delay=$(uci -q get taskplan.@ltime[$index].delay || echo "10")
|
||||
|
||||
json_add_object
|
||||
json_add_string "type" "startup"
|
||||
json_add_int "index" $index
|
||||
json_add_int "enable" $enable
|
||||
json_add_string "remarks" "$remarks"
|
||||
json_add_string "stype" "$stype"
|
||||
json_add_int "delay" $delay
|
||||
json_close_object
|
||||
|
||||
index=$((index + 1))
|
||||
done
|
||||
fi
|
||||
|
||||
json_close_array
|
||||
json_dump
|
||||
}
|
||||
|
||||
# 启动服务
|
||||
start_service() {
|
||||
/etc/init.d/taskplan start >/dev/null 2>&1
|
||||
local ret=$?
|
||||
json_init
|
||||
json_add_int "result" $ret
|
||||
[ $ret -eq 0 ] && json_add_string "message" "Service started"
|
||||
json_dump
|
||||
}
|
||||
|
||||
# 停止服务
|
||||
stop_service() {
|
||||
/etc/init.d/taskplan stop >/dev/null 2>&1
|
||||
local ret=$?
|
||||
json_init
|
||||
json_add_int "result" $ret
|
||||
[ $ret -eq 0 ] && json_add_string "message" "Service stopped"
|
||||
json_dump
|
||||
}
|
||||
|
||||
# 重启服务
|
||||
restart_service() {
|
||||
/etc/init.d/taskplan restart >/dev/null 2>&1
|
||||
local ret=$?
|
||||
json_init
|
||||
json_add_int "result" $ret
|
||||
[ $ret -eq 0 ] && json_add_string "message" "Service restarted"
|
||||
json_dump
|
||||
}
|
||||
|
||||
# 重新加载
|
||||
reload_service() {
|
||||
/etc/init.d/taskplan reload >/dev/null 2>&1
|
||||
local ret=$?
|
||||
json_init
|
||||
json_add_int "result" $ret
|
||||
[ $ret -eq 0 ] && json_add_string "message" "Service reloaded"
|
||||
json_dump
|
||||
}
|
||||
|
||||
# 执行主函数
|
||||
main "$@"
|
||||
@@ -0,0 +1,44 @@
|
||||
{
|
||||
"admin/control": {
|
||||
"title": "Control",
|
||||
"order": 44,
|
||||
"action": {
|
||||
"type": "firstchild"
|
||||
}
|
||||
},
|
||||
"admin/control/taskplan": {
|
||||
"title": "Task Plan",
|
||||
"order": 60,
|
||||
"action": {
|
||||
"type": "firstchild"
|
||||
},
|
||||
"depends": {
|
||||
"acl": [ "luci-app-taskplan" ],
|
||||
"uci": { "taskplan": true }
|
||||
}
|
||||
},
|
||||
"admin/control/taskplan/scheduled": {
|
||||
"title": "Scheduled Tasks",
|
||||
"order": 10,
|
||||
"action": {
|
||||
"type": "view",
|
||||
"path": "taskplan/scheduled"
|
||||
}
|
||||
},
|
||||
"admin/control/taskplan/startup": {
|
||||
"title": "Startup Tasks",
|
||||
"order": 20,
|
||||
"action": {
|
||||
"type": "view",
|
||||
"path": "taskplan/startup"
|
||||
}
|
||||
},
|
||||
"admin/control/taskplan/log": {
|
||||
"title": "Log Viewer",
|
||||
"order": 30,
|
||||
"action": {
|
||||
"type": "view",
|
||||
"path": "taskplan/log"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"luci-app-taskplan": {
|
||||
"description": "Grant access to Task Plan procedures",
|
||||
"read": {
|
||||
"ubus": {
|
||||
"luci.taskplan": [ "status", "list", "task_list" ]
|
||||
},
|
||||
"file": {
|
||||
"/etc/taskplan/taskplan.log": [ "read" ],
|
||||
"/etc/config/taskplan": [ "read" ],
|
||||
"/etc/taskplan/taskplan.log": [ "read" ],
|
||||
"/etc/taskplan/taskplancustomscript": [ "read" ],
|
||||
"/etc/taskplan/taskplancustomscript2": [ "read" ]
|
||||
}
|
||||
},
|
||||
"write": {
|
||||
"ubus": {
|
||||
"luci.taskplan": [ "start", "stop", "restart", "reload" ]
|
||||
},
|
||||
"file": {
|
||||
"/etc/config/taskplan": [ "write" ],
|
||||
"/etc/taskplan/taskplancustomscript": [ "write" ],
|
||||
"/etc/taskplan/taskplancustomscript2": [ "write" ]
|
||||
},
|
||||
"execute": {
|
||||
"/etc/init.d/taskplan": [ "start", "stop", "restart", "reload" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user