From 504fdad14bcf6862d24037b3cb49f0ed4fd95220 Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Fri, 12 Jan 2018 16:12:02 +0100 Subject: luci-app-mwan3: use mwan3 ubus call for status information Signed-off-by: Florian Eckert --- .../luci-app-mwan3/luasrc/controller/mwan3.lua | 66 +++------------------- .../luasrc/view/mwan/overview_status_interface.htm | 48 ++++++++-------- .../luasrc/view/mwan/status_interface.htm | 47 ++++++--------- 3 files changed, 50 insertions(+), 111 deletions(-) (limited to 'applications/luci-app-mwan3') diff --git a/applications/luci-app-mwan3/luasrc/controller/mwan3.lua b/applications/luci-app-mwan3/luasrc/controller/mwan3.lua index f429cc60f..62e888c92 100644 --- a/applications/luci-app-mwan3/luasrc/controller/mwan3.lua +++ b/applications/luci-app-mwan3/luasrc/controller/mwan3.lua @@ -23,7 +23,7 @@ function index() entry({"admin", "status", "mwan", "troubleshooting"}, template("mwan/status_troubleshooting")) entry({"admin", "status", "mwan", "interface_status"}, - call("interfaceStatus")) + call("mwan_Status")) entry({"admin", "status", "mwan", "detailed_status"}, call("detailedStatus")) entry({"admin", "status", "mwan", "diagnostics_display"}, @@ -56,65 +56,15 @@ function index() _("Notification"), 50).leaf = true end -function getInterfaceStatus(ruleNumber, interfaceName) - if ut.trim(sys.exec("uci -q -p /var/state get mwan3." .. interfaceName .. ".enabled")) == "1" then - if ut.trim(sys.exec(ip .. "route list table " .. ruleNumber)) ~= "" then - if ut.trim(sys.exec("uci -q -p /var/state get mwan3." .. interfaceName .. ".track_ip")) ~= "" then - return "online" - else - return "notMonitored" - end - else - return "offline" - end - else - return "notEnabled" - end -end - -function getInterfaceName() - local ruleNumber, status = 0, "" - uci.cursor():foreach("mwan3", "interface", - function (section) - ruleNumber = ruleNumber+1 - status = status .. section[".name"] .. "[" .. getInterfaceStatus(ruleNumber, section[".name"]) .. "]" - end - ) - return status -end - -function interfaceStatus() - local ntm = require "luci.model.network".init() - - local mArray = {} - - -- overview status - local statusString = getInterfaceName() - if statusString ~= "" then - mArray.wans = {} - wansid = {} - - for wanName, interfaceState in string.gfind(statusString, "([^%[]+)%[([^%]]+)%]") do - local wanInterfaceName = ut.trim(sys.exec("uci -q -p /var/state get network." .. wanName .. ".ifname")) - if wanInterfaceName == "" then - wanInterfaceName = "X" - end - local wanDeviceLink = ntm:get_interface(wanInterfaceName) - wanDeviceLink = wanDeviceLink and wanDeviceLink:get_network() - wanDeviceLink = wanDeviceLink and wanDeviceLink:adminlink() or "#" - wansid[wanName] = #mArray.wans + 1 - mArray.wans[wansid[wanName]] = { name = wanName, link = wanDeviceLink, ifname = wanInterfaceName, status = interfaceState } - end - end - - -- overview status log - local mwanLog = ut.trim(sys.exec("logread | grep mwan3 | tail -n 50 | sed 'x;1!H;$!d;x' 2>/dev/null")) - if mwanLog ~= "" then - mArray.mwanlog = { mwanLog } - end +function mwan_Status() + local status = ut.ubus("mwan3", "status", {}) luci.http.prepare_content("application/json") - luci.http.write_json(mArray) + if status ~= nil then + luci.http.write_json(status) + else + luci.http.write_json({}) + end end function detailedStatus() diff --git a/applications/luci-app-mwan3/luasrc/view/mwan/overview_status_interface.htm b/applications/luci-app-mwan3/luasrc/view/mwan/overview_status_interface.htm index 335c95c8f..279f140ba 100644 --- a/applications/luci-app-mwan3/luasrc/view/mwan/overview_status_interface.htm +++ b/applications/luci-app-mwan3/luasrc/view/mwan/overview_status_interface.htm @@ -1,44 +1,46 @@ @@ -70,10 +61,6 @@ <%:MWAN Interface Live Status%>
<%:Loading%><%:Collecting data...%>
-
- <%:MWAN Interface Systemlog%> -
<%:Loading%><%:Collecting data...%>
-