update 2026-09-26 17:00:06

This commit is contained in:
action committed 2026-09-26 17:00:06 +08:00
1 parent 97ae9f68da
commit bcc9ceb04a
4756 files changed
+1670713

No files matched your search

@@ -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'
+142
View File
@@ -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" ]
}
}
}
}