summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-app-travelmate/luasrc/controller/travelmate.lua
diff options
context:
space:
mode:
authorDirk Brenken <dev@brenken.org>2018-07-28 19:02:35 +0200
committerDirk Brenken <dev@brenken.org>2018-07-28 19:02:35 +0200
commit11cd64e08e3b69371ed61459f5118c7a48a7f846 (patch)
tree1da5d68ace19dc8fda8061e12e428396b1fe8ff7 /applications/luci-app-travelmate/luasrc/controller/travelmate.lua
parent39cabc03611369d7cb421b5fcff90ce20d9d51c4 (diff)
luci-app-travelmate: sync with travelmate 1.2.1
* Runtime Information, Logview and Station Overview are now dynamically updated via XHR poll * New runtime information for "Faulty Stations" (Travelmate backend will no longer rename faulty uplinks) * Add a new "Restart" button to reset "Faulty Stations" information and trigger a Travelmate restart * In Stations overview the currently used uplink is emphasized in blue, faulty uplinks in red * Numerous cleanups (e.g. space=>tab indentation) and other small fixes Signed-off-by: Dirk Brenken <dev@brenken.org>
Diffstat (limited to 'applications/luci-app-travelmate/luasrc/controller/travelmate.lua')
-rw-r--r--applications/luci-app-travelmate/luasrc/controller/travelmate.lua49
1 files changed, 40 insertions, 9 deletions
diff --git a/applications/luci-app-travelmate/luasrc/controller/travelmate.lua b/applications/luci-app-travelmate/luasrc/controller/travelmate.lua
index 493a387c3e..00969ffe7d 100644
--- a/applications/luci-app-travelmate/luasrc/controller/travelmate.lua
+++ b/applications/luci-app-travelmate/luasrc/controller/travelmate.lua
@@ -3,9 +3,12 @@
module("luci.controller.travelmate", package.seeall)
-local util = require("luci.util")
-local i18n = require("luci.i18n")
-local templ = require("luci.template")
+local sys = require("luci.sys")
+local util = require("luci.util")
+local http = require("luci.http")
+local i18n = require("luci.i18n")
+local json = require("luci.jsonc")
+local uci = require("luci.model.uci").cursor()
function index()
if not nixio.fs.access("/etc/config/travelmate") then
@@ -14,13 +17,16 @@ function index()
entry({"admin", "services", "travelmate"}, firstchild(), _("Travelmate"), 40).dependent = false
entry({"admin", "services", "travelmate", "tab_from_cbi"}, cbi("travelmate/overview_tab", {hideresetbtn=true, hidesavebtn=true}), _("Overview"), 10).leaf = true
entry({"admin", "services", "travelmate", "stations"}, template("travelmate/stations"), _("Wireless Stations"), 20).leaf = true
- entry({"admin", "services", "travelmate", "logfile"}, call("logread"), _("View Logfile"), 30).leaf = true
+ entry({"admin", "services", "travelmate", "log"}, template("travelmate/logread"), _("View Logfile"), 30).leaf = true
entry({"admin", "services", "travelmate", "advanced"}, firstchild(), _("Advanced"), 100)
entry({"admin", "services", "travelmate", "advanced", "configuration"}, form("travelmate/configuration_tab"), _("Edit Travelmate Configuration"), 110).leaf = true
entry({"admin", "services", "travelmate", "advanced", "cfg_wireless"}, form("travelmate/cfg_wireless_tab"), _("Edit Wireless Configuration"), 120).leaf = true
entry({"admin", "services", "travelmate", "advanced", "cfg_network"}, form("travelmate/cfg_network_tab"), _("Edit Network Configuration"), 130).leaf = true
entry({"admin", "services", "travelmate", "advanced", "cfg_firewall"}, form("travelmate/cfg_firewall_tab"), _("Edit Firewall Configuration"), 140).leaf = true
+ entry({"admin", "services", "travelmate", "logread"}, call("logread"), nil).leaf = true
+ entry({"admin", "services", "travelmate", "status"}, call("status_update"), nil).leaf = true
+ entry({"admin", "services", "travelmate", "action"}, call("trm_action"), nil).leaf = true
entry({"admin", "services", "travelmate", "apqr"}, template("travelmate/ap_qr")).leaf = true
entry({"admin", "services", "travelmate", "wifiscan"}, template("travelmate/wifi_scan")).leaf = true
entry({"admin", "services", "travelmate", "wifiadd"}, form("travelmate/wifi_add", {hideresetbtn=true, hidesavebtn=true})).leaf = true
@@ -29,13 +35,38 @@ function index()
entry({"admin", "services", "travelmate", "wifiorder"}, form("travelmate/wifi_order", {hideresetbtn=true, hidesavebtn=true})).leaf = true
end
+function trm_action(name)
+ if name == "do_restart" then
+ luci.sys.call("/etc/init.d/travelmate restart >/dev/null 2>&1")
+ end
+ luci.http.prepare_content("text/plain")
+ luci.http.write("0")
+end
+
+function status_update()
+ local rt_file
+ local content
+
+ rt_file = uci:get("travelmate", "global", "trm_rtfile") or "/tmp/trm_runtime.json"
+
+ if nixio.fs.access(rt_file) then
+ content = json.parse(nixio.fs.readfile(rt_file) or "")
+ http.prepare_content("application/json")
+ http.write_json(content)
+ end
+end
+
function logread()
- local logfile = ""
+ local content
if nixio.fs.access("/var/log/messages") then
- logfile = util.trim(util.exec("grep -F 'travelmate-' /var/log/messages"))
- elseif nixio.fs.access("/sbin/logread") then
- logfile = util.trim(util.exec("logread -e 'travelmate-'"))
+ content = util.trim(util.exec("grep -F 'travelmate-' /var/log/messages"))
+ else
+ content = util.trim(util.exec("logread -e 'travelmate-'"))
+ end
+
+ if content == "" then
+ content = "No travelmate related logs yet!"
end
- templ.render("travelmate/logread", {title = i18n.translate("Travelmate Logfile"), content = logfile})
+ http.write(content)
end