luci-app-wifischedule: minor changes

* Formatting codes.
* Move to services sub menu.
* Update Simplified Chinese translation.
* And some other small changes.

Signed-off-by: Hsing-Wang Liao <kuoruan@gmail.com>
This commit is contained in:
Hsing-Wang Liao 2017-01-05 16:28:45 +08:00
parent a2dfd21c80
commit ddfe7c4374
6 changed files with 79 additions and 73 deletions

View file

@ -12,21 +12,31 @@
-- --
-- Author: Nils Koenig <openwrt@newk.it> -- Author: Nils Koenig <openwrt@newk.it>
module("luci.controller.wifischedule.wifi_schedule", package.seeall) module("luci.controller.wifischedule.wifi_schedule", package.seeall)
local fs = require "nixio.fs"
local sys = require "luci.sys"
local template = require "luci.template"
local i18n = require "luci.i18n"
function index() function index()
entry({"admin", "wifi_schedule"}, firstchild(), _("Wifi Schedule"), 60).dependent=false if not nixio.fs.access("/etc/config/wifi_schedule") then
entry({"admin", "wifi_schedule", "tab_from_cbi"}, cbi("wifischedule/wifi_schedule"), _("Schedule"), 1) return
entry({"admin", "wifi_schedule", "wifi_schedule"}, call("wifi_schedule_log"), _("View Logfile"), 2) end
entry({"admin", "wifi_schedule", "cronjob"}, call("view_crontab"), _("View Cron Jobs"), 3) entry({"admin", "services", "wifi_schedule"}, firstchild(), _("Wifi Schedule"), 60).dependent=false
entry({"admin", "services", "wifi_schedule", "tab_from_cbi"}, cbi("wifischedule/wifi_schedule"), _("Schedule"), 1)
entry({"admin", "services", "wifi_schedule", "wifi_schedule"}, call("wifi_schedule_log"), _("View Logfile"), 2)
entry({"admin", "services", "wifi_schedule", "cronjob"}, call("view_crontab"), _("View Cron Jobs"), 3)
end end
function wifi_schedule_log() function wifi_schedule_log()
local logfile = luci.sys.exec("cat /tmp/log/wifi_schedule.log") local logfile = fs.readfile("/tmp/log/wifi_schedule.log") or ""
luci.template.render("wifischedule/file_viewer", {title="Wifi Schedule Logfile", content=logfile}) template.render("wifischedule/file_viewer",
{title = i18n.translate("Wifi Schedule Logfile"), content = logfile})
end end
function view_crontab() function view_crontab()
local crontab = luci.sys.exec("cat /etc/crontabs/root") local crontab = fs.readfile("/etc/crontabs/root") or ""
luci.template.render("wifischedule/file_viewer", {title="Cron Jobs", content=crontab}) template.render("wifischedule/file_viewer",
{title = i18n.translate("Cron Jobs"), content = crontab})
end end

View file

@ -12,15 +12,11 @@
-- --
-- Author: Nils Koenig <openwrt@newk.it> -- Author: Nils Koenig <openwrt@newk.it>
function file_exists(name) local fs = require "nixio.fs"
local f=io.open(name,"r") local sys = require "luci.sys"
if f~=nil then io.close(f) return true else return false end
end
function time_validator(self, value, desc) function time_validator(self, value, desc)
if value ~= nil then if value ~= nil then
h_str, m_str = string.match(value, "^(%d%d?):(%d%d?)$") h_str, m_str = string.match(value, "^(%d%d?):(%d%d?)$")
h = tonumber(h_str) h = tonumber(h_str)
m = tonumber(m_str) m = tonumber(m_str)
@ -32,16 +28,16 @@ function time_validator(self, value, desc)
m <= 59) then m <= 59) then
return value return value
end end
end end
return nil, translate("The value '" .. desc .. "' is invalid") return nil, translatef("The value %s is invalid", desc)
end end
-- ------------------------------------------------------------------------------------------------- -- -------------------------------------------------------------------------------------------------
-- BEGIN Map -- BEGIN Map
m = Map("wifi_schedule", translate("Wifi Schedule"), translate("Defines a schedule when to turn on and off wifi.")) m = Map("wifi_schedule", translate("Wifi Schedule"), translate("Defines a schedule when to turn on and off wifi."))
function m.on_commit(self) function m.on_commit(self)
luci.sys.exec("/usr/bin/wifi_schedule.sh cron") sys.exec("/usr/bin/wifi_schedule.sh cron")
end end
-- END Map -- END Map
@ -54,13 +50,13 @@ global_section.anonymous = true
-- BEGIN Global Enable Checkbox -- BEGIN Global Enable Checkbox
global_enable = global_section:option(Flag, "enabled", translate("Enable Wifi Schedule")) global_enable = global_section:option(Flag, "enabled", translate("Enable Wifi Schedule"))
global_enable.optional=false; global_enable.optional = false
global_enable.rmempty = false; global_enable.rmempty = false
function global_enable.validate(self, value, global_section) function global_enable.validate(self, value, global_section)
if value == "1" then if value == "1" then
if ( file_exists("/sbin/wifi") and if ( fs.access("/sbin/wifi") and
file_exists("/usr/bin/wifi_schedule.sh") )then fs.access("/usr/bin/wifi_schedule.sh") )then
return value return value
else else
return nil, translate("Could not find required /usr/bin/wifi_schedule.sh or /sbin/wifi") return nil, translate("Could not find required /usr/bin/wifi_schedule.sh or /sbin/wifi")
@ -71,39 +67,38 @@ function global_enable.validate(self, value, global_section)
end end
-- END Global Enable Checkbox -- END Global Enable Checkbox
-- BEGIN Global Logging Checkbox -- BEGIN Global Logging Checkbox
global_logging = global_section:option(Flag, "logging", translate("Enable logging")) global_logging = global_section:option(Flag, "logging", translate("Enable logging"))
global_logging.optional=false; global_logging.optional = false
global_logging.rmempty = false; global_logging.rmempty = false
global_logging.default = 0 global_logging.default = 0
-- END Global Enable Checkbox -- END Global Enable Checkbox
-- BEGIN Global Activate WiFi Button -- BEGIN Global Activate WiFi Button
enable_wifi = global_section:option(Button, "enable_wifi", translate("Activate wifi")) enable_wifi = global_section:option(Button, "enable_wifi", translate("Activate wifi"))
function enable_wifi.write() function enable_wifi.write()
luci.sys.exec("/usr/bin/wifi_schedule.sh start manual") sys.exec("/usr/bin/wifi_schedule.sh start manual")
end end
-- END Global Activate Wifi Button -- END Global Activate Wifi Button
-- BEGIN Global Disable WiFi Gracefully Button -- BEGIN Global Disable WiFi Gracefully Button
disable_wifi_gracefully = global_section:option(Button, "disable_wifi_gracefully", translate("Disable wifi gracefully")) disable_wifi_gracefully = global_section:option(Button, "disable_wifi_gracefully", translate("Disable wifi gracefully"))
function disable_wifi_gracefully.write() function disable_wifi_gracefully.write()
luci.sys.exec("/usr/bin/wifi_schedule.sh stop manual") sys.exec("/usr/bin/wifi_schedule.sh stop manual")
end end
-- END Global Disable Wifi Gracefully Button -- END Global Disable Wifi Gracefully Button
-- BEGIN Disable WiFi Forced Button -- BEGIN Disable WiFi Forced Button
disable_wifi_forced = global_section:option(Button, "disable_wifi_forced", translate("Disabled wifi forced")) disable_wifi_forced = global_section:option(Button, "disable_wifi_forced", translate("Disabled wifi forced"))
function disable_wifi_forced.write() function disable_wifi_forced.write()
luci.sys.exec("/usr/bin/wifi_schedule.sh forcestop manual") sys.exec("/usr/bin/wifi_schedule.sh forcestop manual")
end end
-- END Global Disable WiFi Forced Button -- END Global Disable WiFi Forced Button
-- BEGIN Global Unload Modules Checkbox -- BEGIN Global Unload Modules Checkbox
global_unload_modules = global_section:option(Flag, "unload_modules", translate("Unload Modules (experimental; saves more power)")) global_unload_modules = global_section:option(Flag, "unload_modules", translate("Unload Modules (experimental; saves more power)"))
global_unload_modules.optional = false; global_unload_modules.optional = false
global_unload_modules.rmempty = false; global_unload_modules.rmempty = false
global_unload_modules.default = 0 global_unload_modules.default = 0
-- END Global Unload Modules Checkbox -- END Global Unload Modules Checkbox
@ -111,13 +106,13 @@ global_unload_modules.default = 0
-- BEGIN Modules -- BEGIN Modules
modules = global_section:option(TextValue, "modules", "") modules = global_section:option(TextValue, "modules", "")
modules:depends("unload_modules", global_unload_modules.enabled); modules:depends("unload_modules", global_unload_modules.enabled);
modules.wrap = "off" modules.wrap = "off"
modules.rows = 10 modules.rows = 10
function modules.cfgvalue(self, section) function modules.cfgvalue(self, section)
mod=uci.get("wifi_schedule", section, "modules") mod = uci.get("wifi_schedule", section, "modules")
if mod == nil then if mod == nil then
mod="" mod = ""
end end
return mod:gsub(" ", "\r\n") return mod:gsub(" ", "\r\n")
end end
@ -131,28 +126,27 @@ function modules.write(self, section, value)
end end
-- END Modules -- END Modules
-- BEGIN Determine Modules -- BEGIN Determine Modules
determine_modules = global_section:option(Button, "determine_modules", translate("Determine Modules Automatically")) determine_modules = global_section:option(Button, "determine_modules", translate("Determine Modules Automatically"))
determine_modules:depends("unload_modules", global_unload_modules.enabled); determine_modules:depends("unload_modules", global_unload_modules.enabled);
function determine_modules.write(self, section) function determine_modules.write(self, section)
output = luci.sys.exec("/usr/bin/wifi_schedule.sh getmodules") output = sys.exec("/usr/bin/wifi_schedule.sh getmodules")
modules:write(section, output) modules:write(section, output)
end end
-- END Determine Modules -- END Determine Modules
-- BEGIN Section -- BEGIN Section
d = m:section(TypedSection, "entry", translate("Schedule events")) d = m:section(TypedSection, "entry", translate("Schedule events"))
d.addremove = true d.addremove = true
--d.anonymous = true --d.anonymous = true
-- END Section -- END Section
-- BEGIN Enable Checkbox -- BEGIN Enable Checkbox
c = d:option(Flag, "enabled", translate("Enable")) c = d:option(Flag, "enabled", translate("Enable"))
c.optional=false; c.rmempty = false; c.optional = false
c.rmempty = false
-- END Enable Checkbox -- END Enable Checkbox
-- BEGIN Day(s) of Week -- BEGIN Day(s) of Week
dow = d:option(MultiValue, "daysofweek", translate("Day(s) of Week")) dow = d:option(MultiValue, "daysofweek", translate("Day(s) of Week"))
dow.optional = false dow.optional = false
@ -168,8 +162,8 @@ dow:value("Sunday", translate("Sunday"))
-- BEGIN Start Wifi Dropdown -- BEGIN Start Wifi Dropdown
starttime = d:option(Value, "starttime", translate("Start WiFi")) starttime = d:option(Value, "starttime", translate("Start WiFi"))
starttime.optional=false; starttime.optional = false
starttime.rmempty = false; starttime.rmempty = false
starttime:value("00:00") starttime:value("00:00")
starttime:value("01:00") starttime:value("01:00")
starttime:value("02:00") starttime:value("02:00")
@ -198,14 +192,12 @@ starttime:value("23:00")
function starttime.validate(self, value, d) function starttime.validate(self, value, d)
return time_validator(self, value, translate("Start Time")) return time_validator(self, value, translate("Start Time"))
end end
-- END Start Wifi Dropdown -- END Start Wifi Dropdown
-- BEGIN Stop Wifi Dropdown -- BEGIN Stop Wifi Dropdown
stoptime = d:option(Value, "stoptime", translate("Stop WiFi")) stoptime = d:option(Value, "stoptime", translate("Stop WiFi"))
stoptime.optional=false; stoptime.optional = false
stoptime.rmempty = false; stoptime.rmempty = false
stoptime:value("00:00") stoptime:value("00:00")
stoptime:value("01:00") stoptime:value("01:00")
stoptime:value("02:00") stoptime:value("02:00")
@ -236,15 +228,14 @@ function stoptime.validate(self, value, d)
end end
-- END Stop Wifi Dropdown -- END Stop Wifi Dropdown
-- BEGIN Force Wifi Stop Checkbox -- BEGIN Force Wifi Stop Checkbox
force_wifi = d:option(Flag, "forcewifidown", translate("Force disabling wifi even if stations associated")) force_wifi = d:option(Flag, "forcewifidown", translate("Force disabling wifi even if stations associated"))
force_wifi.default = false force_wifi.default = false
force_wifi.rmempty = false; force_wifi.rmempty = false
function force_wifi.validate(self, value, d) function force_wifi.validate(self, value, d)
if value == "0" then if value == "0" then
if file_exists("/usr/bin/iwinfo") then if fs.access("/usr/bin/iwinfo") then
return value return value
else else
return nil, translate("Could not find required programm /usr/bin/iwinfo") return nil, translate("Could not find required programm /usr/bin/iwinfo")
@ -255,5 +246,4 @@ function force_wifi.validate(self, value, d)
end end
-- END Force Wifi Checkbox -- END Force Wifi Checkbox
return m return m

View file

@ -15,7 +15,7 @@ Author: Nils Koenig <openwrt@newk.it>
-%> -%>
<%+header%> <%+header%>
<h2 name="title"><%=translate(title)%></h2> <h2 name="title"><%=title%></h2>
<div id="content_fileviewer"> <div id="content_fileviewer">
<textarea style="width: 100%" readonly="readonly" wrap="off" rows="<%=content:cmatch("\n")+1%>" id="content_id"><%=content:pcdata()%></textarea> <textarea style="width: 100%" readonly="readonly" wrap="off" rows="<%=content:cmatch("\n")+1%>" id="content_id"><%=content:pcdata()%></textarea>
</div> </div>

View file

@ -22,6 +22,9 @@ msgstr ""
msgid "Could not find required programm /usr/bin/iwinfo" msgid "Could not find required programm /usr/bin/iwinfo"
msgstr "必須のプログラム /usr/bin/iwinfo が見つかりませんでした。" msgstr "必須のプログラム /usr/bin/iwinfo が見つかりませんでした。"
msgid "Cron Jobs"
msgstr "Cronジョブ"
msgid "Day(s) of Week" msgid "Day(s) of Week"
msgstr "曜日" msgstr "曜日"
@ -82,7 +85,7 @@ msgstr "WiFiの停止"
msgid "Sunday" msgid "Sunday"
msgstr "日曜日" msgstr "日曜日"
msgid "The value '" msgid "The value %s is invalid"
msgstr "" msgstr ""
msgid "Thursday" msgid "Thursday"
@ -106,8 +109,5 @@ msgstr "水曜日"
msgid "Wifi Schedule" msgid "Wifi Schedule"
msgstr "WiFi スケジュール" msgstr "WiFi スケジュール"
#~ msgid "Cron Jobs" msgid "Wifi Schedule Logfile"
#~ msgstr "Cronジョブ" msgstr "WiFiスケジュール ログファイル"
#~ msgid "Wifi Schedule Logfile"
#~ msgstr "WiFiスケジュール ログファイル"

View file

@ -10,6 +10,9 @@ msgstr ""
msgid "Could not find required programm /usr/bin/iwinfo" msgid "Could not find required programm /usr/bin/iwinfo"
msgstr "" msgstr ""
msgid "Cron Jobs"
msgstr ""
msgid "Day(s) of Week" msgid "Day(s) of Week"
msgstr "" msgstr ""
@ -70,7 +73,7 @@ msgstr ""
msgid "Sunday" msgid "Sunday"
msgstr "" msgstr ""
msgid "The value '" msgid "The value %s is invalid"
msgstr "" msgstr ""
msgid "Thursday" msgid "Thursday"
@ -93,3 +96,6 @@ msgstr ""
msgid "Wifi Schedule" msgid "Wifi Schedule"
msgstr "" msgstr ""
msgid "Wifi Schedule Logfile"
msgstr ""

View file

@ -10,11 +10,14 @@ msgstr "无法找到必需的 /usr/bin/wifi_schedule.sh 或 /sbin/wifi"
msgid "Could not find required programm /usr/bin/iwinfo" msgid "Could not find required programm /usr/bin/iwinfo"
msgstr "无法找到必需程序:/usr/bin/iwinfo" msgstr "无法找到必需程序:/usr/bin/iwinfo"
msgid "Cron Jobs"
msgstr "计划任务"
msgid "Day(s) of Week" msgid "Day(s) of Week"
msgstr "星期" msgstr "星期"
msgid "Defines a schedule when to turn on and off wifi." msgid "Defines a schedule when to turn on and off wifi."
msgstr "定义打开和关闭 WiFi 的时间表" msgstr "定义自动打开和关闭 WiFi 的计划表"
msgid "Determine Modules Automatically" msgid "Determine Modules Automatically"
msgstr "自动确定模块" msgstr "自动确定模块"
@ -29,7 +32,7 @@ msgid "Enable"
msgstr "启用" msgstr "启用"
msgid "Enable Wifi Schedule" msgid "Enable Wifi Schedule"
msgstr "启用 WiFi 时间表" msgstr "启用 WiFi 计划"
msgid "Enable logging" msgid "Enable logging"
msgstr "启用日志" msgstr "启用日志"
@ -50,7 +53,7 @@ msgid "Saturday"
msgstr "星期六" msgstr "星期六"
msgid "Schedule" msgid "Schedule"
msgstr "时间表" msgstr "计划表"
msgid "Schedule events" msgid "Schedule events"
msgstr "计划事件" msgstr "计划事件"
@ -70,8 +73,8 @@ msgstr "关闭 WiFi"
msgid "Sunday" msgid "Sunday"
msgstr "星期日" msgstr "星期日"
msgid "The value '" msgid "The value %s is invalid"
msgstr "" msgstr "%s 的值无效"
msgid "Thursday" msgid "Thursday"
msgstr "星期四" msgstr "星期四"
@ -80,7 +83,7 @@ msgid "Tuesday"
msgstr "星期二" msgstr "星期二"
msgid "Unload Modules (experimental; saves more power)" msgid "Unload Modules (experimental; saves more power)"
msgstr "取消加载模块(实验性的,节省更多电量)" msgstr "载模块(实验性的,节省更多电量)"
msgid "View Cron Jobs" msgid "View Cron Jobs"
msgstr "查看计划任务" msgstr "查看计划任务"
@ -92,10 +95,7 @@ msgid "Wednesday"
msgstr "星期三" msgstr "星期三"
msgid "Wifi Schedule" msgid "Wifi Schedule"
msgstr "WiFi 时间表" msgstr "WiFi 计划"
#~ msgid "Cron Jobs" msgid "Wifi Schedule Logfile"
#~ msgstr "计划任务" msgstr "WiFi 计划日志文件"
#~ msgid "Wifi Schedule Logfile"
#~ msgstr "WiFi 时间表日志文件"