update 2026-10-07 18:47:42

This commit is contained in:
action committed 2026-10-07 18:47:42 +08:00
1 parent 617f7ca2a6
commit bd061545ed
4832 files changed
+1693456

No files matched your search

@@ -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" ]
}
}
}
}