forked from sirpdboy/luci-app-autotimeset
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
137 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module("luci.controller.autopoweroff",package.seeall) | ||
function index() | ||
entry({"admin","system","autopoweroff"},cbi("autopoweroff"),_("Scheduled poweroff"),88) | ||
entry({"admin","system","autopoweroff"},cbi("autopoweroff"),_("Scheduled Setting"),88) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,46 @@ | ||
require("luci.sys") | ||
local o=require"luci.dispatcher" | ||
local e=require("luci.model.ipkg") | ||
local s=require"nixio.fs" | ||
local e=luci.model.uci.cursor() | ||
local m,s,e | ||
|
||
m=Map("autopoweroff",translate("Scheduled poweroff"),translate("Scheduled poweroff Setting")) | ||
m=Map("autopoweroff",translate("Scheduled Setting"),translate("Scheduled reboot poweroff Setting")) | ||
|
||
s=m:section(TypedSection,"login","") | ||
s.addremove=false | ||
s.anonymous=true | ||
|
||
enable=s:option(Flag,"enable",translate("Enable")) | ||
enable.rmempty = false | ||
enable.default=0 | ||
|
||
week=s:option(ListValue,"week",translate("Week Day")) | ||
week:value(7,translate("Everyday")) | ||
week:value(1,translate("Monday")) | ||
week:value(2,translate("Tuesday")) | ||
week:value(3,translate("Wednesday")) | ||
week:value(4,translate("Thursday")) | ||
week:value(5,translate("Friday")) | ||
week:value(6,translate("Saturday")) | ||
week:value(0,translate("Sunday")) | ||
week.default=0 | ||
|
||
hour=s:option(Value,"hour",translate("Hour")) | ||
hour.datatype = "range(0,23)" | ||
hour.rmempty = false | ||
|
||
pass=s:option(Value,"minute",translate("Minute")) | ||
pass.datatype = "range(0,59)" | ||
pass.rmempty = false | ||
|
||
e=s:option(Flag,"enable",translate("Enable")) | ||
e.rmempty = false | ||
e.default=0 | ||
|
||
e=s:option(ListValue,"stype",translate("Scheduled Type")) | ||
e:value(1,translate("Scheduled Reboot")) | ||
e:value(2,translate("Scheduled Poweroff")) | ||
e.default=1 | ||
|
||
e=s:option(ListValue,"week",translate("Week Day")) | ||
e:value(7,translate("Everyday")) | ||
e:value(1,translate("Monday")) | ||
e:value(2,translate("Tuesday")) | ||
e:value(3,translate("Wednesday")) | ||
e:value(4,translate("Thursday")) | ||
e:value(5,translate("Friday")) | ||
e:value(6,translate("Saturday")) | ||
e:value(0,translate("Sunday")) | ||
e.default=7 | ||
|
||
e=s:option(Value,"hour",translate("Hour")) | ||
e.datatype = "range(0,23)" | ||
e.rmempty = false | ||
|
||
e=s:option(Value,"minute",translate("Minute")) | ||
e.datatype = "range(0,59)" | ||
e.rmempty = false | ||
|
||
local e=luci.http.formvalue("cbi.apply") | ||
if e then | ||
luci.sys.call("/etc/init.d/autopoweroff restart >/dev/null") | ||
io.popen("/etc/init.d/autopoweroff restart") | ||
end | ||
|
||
return m |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,26 @@ | ||
msgid "Scheduled poweroff" | ||
msgstr "定时关机" | ||
msgid "Scheduled Setting" | ||
msgstr "定时设置" | ||
|
||
msgid "Scheduled reboot poweroff Setting" | ||
msgstr "定时重启关机二合一设置" | ||
|
||
msgid "Scheduled poweroff Setting" | ||
msgstr "定时关机设置" | ||
msgid "Scheduled Type" | ||
msgstr "定时类型" | ||
|
||
msgid "Scheduled Reboot" | ||
msgstr "定时重启" | ||
|
||
msgid "Scheduled Poweroff" | ||
msgstr "定时关机" | ||
|
||
msgid "Week Day" | ||
msgstr "指定星期" | ||
|
||
msgid "Everyday" | ||
msgstr "每天" | ||
|
||
msgid "Hour" | ||
msgstr "指定小时" | ||
|
||
msgid "Minute" | ||
msgstr "指定分钟" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
|
||
config login | ||
option minute '0' | ||
option minute '1' | ||
option hour '1' | ||
option week '1' | ||
option enable '0' | ||
|
||
option stype '1' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,96 @@ | ||
#!/bin/sh /etc/rc.common | ||
START=50 | ||
#copyright by sirpdboy | ||
|
||
START=95 | ||
STOP=10 | ||
|
||
run_poweroff() | ||
{ | ||
local enable | ||
config_get_bool enable $1 enable | ||
|
||
if [ $enable = 1 ]; then | ||
local minute | ||
local hour | ||
if [ $enable = 1 ] ; then | ||
config_get stype $1 stype | ||
config_get week $1 week | ||
config_get minute $1 minute | ||
config_get hour $1 hour | ||
if [ $minute = 0 ] ; then | ||
minute="00" | ||
[ "$minute" -eq 0 ] && minute="00" | ||
[ "$week" -eq 7 ] && week="*" | ||
|
||
if [ $stype = 1 ] ; then | ||
local cmd="$minute $hour * * $week sleep 5 && touch /etc/banner && reboot" | ||
if [ ! -f "/etc/crontabs/root" ] || [ $(cat /etc/crontabs/root | grep "$cmd" | wc -l) -eq 0 ]; then | ||
sed -i '/reboot/d' /etc/crontabs/root >/dev/null 2>&1 | ||
echo "$cmd" >> /etc/crontabs/root | ||
|
||
fi | ||
echo "Auto REBOOT has started.." | ||
|
||
fi | ||
if [ $week = 7 ] ; then | ||
week="*" | ||
if [ $stype = 2 ] ; then | ||
local cmd="$minute $hour * * $week sleep 5 && touch /etc/banner && poweroff" | ||
if [ ! -f "/etc/crontabs/root" ] || [ $(cat /etc/crontabs/root | grep "$cmd" | wc -l) -eq 0 ]; then | ||
sed -i '/poweroff/d' /etc/crontabs/root >/dev/null 2>&1 | ||
echo "$cmd" >> /etc/crontabs/root | ||
|
||
fi | ||
echo "Auto poweroff has started.." | ||
fi | ||
sed -i '/poweroff/d' /etc/crontabs/root >/dev/null 2>&1 | ||
/etc/init.d/cron restart | ||
echo "$minute $hour * * $week sleep 5 && touch /etc/banner && poweroff" >> /etc/crontabs/root | ||
echo "Auto poweroff has started." | ||
else | ||
sed -i '/poweroff/d' /etc/crontabs/root >/dev/null 2>&1 | ||
/etc/init.d/cron restart | ||
echo "Auto REBOOT has started." | ||
else | ||
del_cru | ||
fi | ||
} | ||
|
||
|
||
add_cru() | ||
{ | ||
local enable=$(uci get autopoweroff.@login[0].enable) | ||
if [ $enable = 1 ] ; then | ||
local stype=$(uci get autopoweroff.@login[0].stype) | ||
local week=$(uci get autopoweroff.@login[0].week) | ||
local minute=$(uci get autopoweroff.@login[0].minute) | ||
local hour=$(uci get autopoweroff.@login[0].hour) | ||
if [ $stype = 1 ] ; then | ||
local cmd="$minute $hour * * $week sleep 5 && touch /etc/banner && reboot" | ||
if [ ! -f "/etc/crontabs/root" ] || [ $(cat /etc/crontabs/root | grep "$cmd" | wc -l) -eq 0 ]; then | ||
sed -i '/reboot/d' /etc/crontabs/root >/dev/null 2>&1 | ||
echo "$cmd" >> /etc/crontabs/root | ||
|
||
fi | ||
echo "Auto REBOOT has started." | ||
fi | ||
if [ $stype = 2 ] ; then | ||
local cmd="$minute $hour * * $week sleep 5 && touch /etc/banner && poweroff" | ||
if [ ! -f "/etc/crontabs/root" ] || [ $(cat /etc/crontabs/root | grep "$cmd" | wc -l) -eq 0 ]; then | ||
sed -i '/poweroff/d' /etc/crontabs/root >/dev/null 2>&1 | ||
echo "$cmd" >> /etc/crontabs/root | ||
|
||
fi | ||
echo "Auto poweroff has started." | ||
fi | ||
else | ||
del_cru | ||
fi | ||
} | ||
|
||
start() | ||
{ | ||
{ | ||
config_load autopoweroff | ||
config_foreach run_poweroff login | ||
add_cru | ||
} | ||
|
||
stop() | ||
{ | ||
echo "Auto poweroff has stoped." | ||
del_cru | ||
echo "Auto poweroff has stop." | ||
} | ||
|
||
del_cru() | ||
{ | ||
if [ -f "/etc/crontabs/root" ] && [ $(cat /etc/crontabs/root | grep reboot | wc -l) -ne 0 ]; then | ||
sed -i '/reboot/d' /etc/crontabs/root >/dev/null 2>&1 | ||
fi | ||
if [ -f "/etc/crontabs/root" ] && [ $(cat /etc/crontabs/root | grep poweroff | wc -l) -ne 0 ]; then | ||
sed -i '/poweroff/d' /etc/crontabs/root >/dev/null 2>&1 | ||
fi | ||
} | ||
|