Merge pull request #859 from feckert/realtime_wlan
[project/luci.git] / applications / luci-app-wifischedule / luasrc / controller / wifischedule / wifi_schedule.lua
1 -- Copyright (c) 2016, prpl Foundation
2 --
3 -- Permission to use, copy, modify, and/or distribute this software for any purpose with or without
4 -- fee is hereby granted, provided that the above copyright notice and this permission notice appear
5 -- in all copies.
6 --
7 -- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
8 -- INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE
9 -- FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
10 -- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
11 -- ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
12 --
13 -- Author: Nils Koenig <openwrt@newk.it>
14
15 module("luci.controller.wifischedule.wifi_schedule", package.seeall)
16
17 local fs = require "nixio.fs"
18 local sys = require "luci.sys"
19 local template = require "luci.template"
20 local i18n = require "luci.i18n"
21
22 function index()
23     if not nixio.fs.access("/etc/config/wifi_schedule") then
24         return
25     end
26     entry({"admin", "services", "wifi_schedule"}, firstchild(), _("Wifi Schedule"), 60).dependent=false
27     entry({"admin", "services", "wifi_schedule", "tab_from_cbi"}, cbi("wifischedule/wifi_schedule"), _("Schedule"), 1)
28     entry({"admin", "services", "wifi_schedule", "wifi_schedule"}, call("wifi_schedule_log"), _("View Logfile"), 2)
29     entry({"admin", "services", "wifi_schedule", "cronjob"}, call("view_crontab"), _("View Cron Jobs"), 3)
30 end
31
32 function wifi_schedule_log()
33     local logfile = fs.readfile("/tmp/log/wifi_schedule.log") or ""
34     template.render("wifischedule/file_viewer",
35         {title = i18n.translate("Wifi Schedule Logfile"), content = logfile})
36 end
37
38 function view_crontab()
39     local crontab = fs.readfile("/etc/crontabs/root") or ""
40     template.render("wifischedule/file_viewer",
41         {title = i18n.translate("Cron Jobs"), content = crontab})
42 end