From 811685c269762780a1a88a15c7f0dd96e5727d9c Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Fri, 12 Jan 2018 09:17:16 +0100 Subject: luci-app-mwan3: remove old /etc/hotplug.d/16-mwancustombak" Remove old /etc/hotplug.d/15-mwancustombak file use instead /etc/mwan3.user from the mwan3 base package. The modification could be done undet "Networke | Load Balancer | Notify" Signed-off-by: Florian Eckert --- .../root/etc/hotplug.d/iface/16-mwancustombak | 38 ---------------------- 1 file changed, 38 deletions(-) delete mode 100755 applications/luci-app-mwan3/root/etc/hotplug.d/iface/16-mwancustombak diff --git a/applications/luci-app-mwan3/root/etc/hotplug.d/iface/16-mwancustombak b/applications/luci-app-mwan3/root/etc/hotplug.d/iface/16-mwancustombak deleted file mode 100755 index 6e2875e3de..0000000000 --- a/applications/luci-app-mwan3/root/etc/hotplug.d/iface/16-mwancustombak +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/sh - -# to enable this script uncomment the case loop at the bottom -# to report mwan status on interface hotplug ifup/ifdown events modify the lines in the send_alert function - -send_alert() -{ - # variable "$1" stores the MWAN status information - # insert your code here to send the contents of "$1" - echo "$1" -} - -gather_event_info() -{ - # create event information message - local EVENT_INFO="Interface [ "$INTERFACE" ($DEVICE) ] on router [ "$(uci -p /var/state get system.@system[0].hostname)" ] has triggered a hotplug [ "$ACTION" ] event on "$(date +"%a %b %d %Y %T %Z")"" - - # get current interface, policy and rule status - local CURRENT_STATUS="$(/usr/sbin/mwan3 status)" - - # get last 50 MWAN systemlog messages - local MWAN_LOG="$(echo -e "Last 50 MWAN systemlog entries. Newest entries sorted at the top:\n$(logread | grep mwan3 | tail -n 50 | sed 'x;1!H;$!d;x')")" - - # pass event info to send_alert function - send_alert "$(echo -e "$EVENT_INFO\n\n$CURRENT_STATUS\n\n$MWAN_LOG")" -} - -#case "$ACTION" in -# ifup) -# gather_event_info -# ;; -# -# ifdown) -# gather_event_info -# ;; -#esac - -exit 0 -- cgit v1.2.3 From 0b4942c396b44e1597c6c1592aef86d0a345a006 Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Fri, 12 Jan 2018 10:49:45 +0100 Subject: luci-app-mwan3: rename mwan3 status overview plugin Signed-off-by: Florian Eckert --- .../luasrc/view/admin_status/index/mwan.htm | 2 +- .../luasrc/view/mwan/openwrt_overview_status.htm | 80 ---------------------- .../luasrc/view/mwan/overview_status_interface.htm | 80 ++++++++++++++++++++++ 3 files changed, 81 insertions(+), 81 deletions(-) delete mode 100644 applications/luci-app-mwan3/luasrc/view/mwan/openwrt_overview_status.htm create mode 100644 applications/luci-app-mwan3/luasrc/view/mwan/overview_status_interface.htm diff --git a/applications/luci-app-mwan3/luasrc/view/admin_status/index/mwan.htm b/applications/luci-app-mwan3/luasrc/view/admin_status/index/mwan.htm index 53b997af90..d76db724bd 100644 --- a/applications/luci-app-mwan3/luasrc/view/admin_status/index/mwan.htm +++ b/applications/luci-app-mwan3/luasrc/view/admin_status/index/mwan.htm @@ -1 +1 @@ -<%+mwan/openwrt_overview_status%> +<%+mwan/overview_status_interface%> diff --git a/applications/luci-app-mwan3/luasrc/view/mwan/openwrt_overview_status.htm b/applications/luci-app-mwan3/luasrc/view/mwan/openwrt_overview_status.htm deleted file mode 100644 index 335c95c8fd..0000000000 --- a/applications/luci-app-mwan3/luasrc/view/mwan/openwrt_overview_status.htm +++ /dev/null @@ -1,80 +0,0 @@ - - -
- <%:MWAN Interface Live Status%> -
<%:Loading%><%:Collecting data...%>
-
- - 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 new file mode 100644 index 0000000000..335c95c8fd --- /dev/null +++ b/applications/luci-app-mwan3/luasrc/view/mwan/overview_status_interface.htm @@ -0,0 +1,80 @@ + + +
+ <%:MWAN Interface Live Status%> +
<%:Loading%><%:Collecting data...%>
+
+ + -- cgit v1.2.3 From 72bcd39b9fdcf9d1aad01894c8cc72bfb1d33cb7 Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Fri, 12 Jan 2018 10:50:58 +0100 Subject: luci-app-mwan3: unify header in configuration tab Signed-off-by: Florian Eckert --- applications/luci-app-mwan3/luasrc/model/cbi/mwan/globalsconfig.lua | 4 ++-- applications/luci-app-mwan3/luasrc/model/cbi/mwan/interface.lua | 4 ++-- applications/luci-app-mwan3/luasrc/model/cbi/mwan/member.lua | 4 ++-- applications/luci-app-mwan3/luasrc/model/cbi/mwan/notify.lua | 4 ++-- applications/luci-app-mwan3/luasrc/model/cbi/mwan/policy.lua | 4 ++-- applications/luci-app-mwan3/luasrc/model/cbi/mwan/rule.lua | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/globalsconfig.lua b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/globalsconfig.lua index 919ed46cd4..3e1a28325b 100644 --- a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/globalsconfig.lua +++ b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/globalsconfig.lua @@ -14,9 +14,9 @@ $Id$ local net = require "luci.model.network".init() -m = Map("mwan3") +m = Map("mwan3", translate("MWAN - Globals")) -s = m:section(NamedSection, "globals", "globals", translate("Globals mwan3 options")) +s = m:section(NamedSection, "globals", "globals", nil) n = s:option(ListValue, "local_source", translate("Local source interface"), translate("Use the IP address of this interface as source IP address for traffic initiated by the router itself")) diff --git a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/interface.lua b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/interface.lua index 77198d5c39..4f5dc75360 100644 --- a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/interface.lua +++ b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/interface.lua @@ -98,12 +98,12 @@ errorRouteList = " " interfaceCheck() -m5 = Map("mwan3", translate("MWAN Interface Configuration"), +m5 = Map("mwan3", translate("MWAN - Interfaces"), interfaceWarnings()) m5:append(Template("mwan/config_css")) -mwan_interface = m5:section(TypedSection, "interface", translate("Interfaces"), +mwan_interface = m5:section(TypedSection, "interface", nil, translate("MWAN supports up to 250 physical and/or logical interfaces
" .. "MWAN requires that all interfaces have a unique metric configured in /etc/config/network
" .. "Names must match the interface name found in /etc/config/network (see advanced tab)
" .. diff --git a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/member.lua b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/member.lua index b73ee57652..aa7daab1d2 100644 --- a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/member.lua +++ b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/member.lua @@ -3,11 +3,11 @@ ds = require "luci.dispatcher" -m5 = Map("mwan3", translate("MWAN Member Configuration")) +m5 = Map("mwan3", translate("MWAN - Members")) m5:append(Template("mwan/config_css")) -mwan_member = m5:section(TypedSection, "member", translate("Members"), +mwan_member = m5:section(TypedSection, "member", nil, translate("Members are profiles attaching a metric and weight to an MWAN interface
" .. "Names may contain characters A-Z, a-z, 0-9, _ and no spaces
" .. "Members may not share the same name as configured interfaces, policies or rules")) diff --git a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/notify.lua b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/notify.lua index 20e86fc027..14237e60f4 100644 --- a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/notify.lua +++ b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/notify.lua @@ -4,9 +4,9 @@ local fs = require "nixio.fs" local ut = require "luci.util" script = "/etc/mwan3.user" -m5 = SimpleForm("luci", nil) +m5 = SimpleForm("luci", translate("MWAN - Notification")) -f = m5:section(SimpleSection, translate("MWAN Notification"), +f = m5:section(SimpleSection, nil, translate("This section allows you to modify the content of \"/etc/mwan3.user\".
" .. "The file is also preserved during sysupgrade.
" .. "
" .. diff --git a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/policy.lua b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/policy.lua index 495b45e646..363ba91292 100644 --- a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/policy.lua +++ b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/policy.lua @@ -29,12 +29,12 @@ err_name_list = " " policyCheck() -m5 = Map("mwan3", translate("MWAN Policy Configuration"), +m5 = Map("mwan3", translate("MWAN - Policies"), policyWarn()) m5:append(Template("mwan/config_css")) -mwan_policy = m5:section(TypedSection, "policy", translate("Policies"), +mwan_policy = m5:section(TypedSection, "policy", nil, translate("Policies are profiles grouping one or more members controlling how MWAN distributes traffic
" .. "Member interfaces with lower metrics are used first. Interfaces with the same metric load-balance
" .. "Load-balanced member interfaces distribute more traffic out those with higher weights
" .. diff --git a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/rule.lua b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/rule.lua index 586f174b28..9134bbc6ac 100644 --- a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/rule.lua +++ b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/rule.lua @@ -33,12 +33,12 @@ error_protocol_list = " " ruleCheck() -m5 = Map("mwan3", translate("MWAN Rule Configuration"), +m5 = Map("mwan3", translate("MWAN - Rules"), ruleWarn()) m5:append(Template("mwan/config_css")) -mwan_rule = m5:section(TypedSection, "rule", translate("Traffic Rules"), +mwan_rule = m5:section(TypedSection, "rule", nil, translate("Rules specify which traffic will use a particular MWAN policy based on IP address, port or protocol
" .. "Rules are matched from top to bottom. Rules below a matching rule are ignored. Traffic not matching any rule is routed using the main routing table
" .. "Traffic destined for known (other than default) networks is handled by the main routing table. Traffic matching a rule, but all WAN interfaces for that policy are down will be blackholed
" .. -- cgit v1.2.3 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(-) diff --git a/applications/luci-app-mwan3/luasrc/controller/mwan3.lua b/applications/luci-app-mwan3/luasrc/controller/mwan3.lua index f429cc60ff..62e888c921 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 335c95c8fd..279f140bab 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...%>
-
-- cgit v1.2.3 From 8014e21d6d10da4ce4376ca6daed7acc53882282 Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Wed, 17 Jan 2018 15:30:15 +0100 Subject: luci-app-mwan3: update rule help text Signed-off-by: Florian Eckert --- applications/luci-app-mwan3/luasrc/model/cbi/mwan/rule.lua | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/rule.lua b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/rule.lua index bdabd38f34..151103f7bd 100644 --- a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/rule.lua +++ b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/rule.lua @@ -37,9 +37,13 @@ m5 = Map("mwan3", translate("MWAN - Rules"), ruleWarn()) mwan_rule = m5:section(TypedSection, "rule", nil, - translate("Rules specify which traffic will use a particular MWAN policy based on IP address, port or protocol
" .. - "Rules are matched from top to bottom. Rules below a matching rule are ignored. Traffic not matching any rule is routed using the main routing table
" .. - "Traffic destined for known (other than default) networks is handled by the main routing table. Traffic matching a rule, but all WAN interfaces for that policy are down will be blackholed
" .. + translate("Rules specify which traffic will use a particular MWAN policy
" .. + "Rules are based on IP address, port or protocol
" .. + "Rules are matched from top to bottom
" .. + "Rules below a matching rule are ignored
" .. + "Traffic not matching any rule is routed using the main routing table
" .. + "Traffic destined for known (other than default) networks is handled by the main routing table
" .. + "Traffic matching a rule, but all WAN interfaces for that policy are down will be blackholed
" .. "Names may contain characters A-Z, a-z, 0-9, _ and no spaces
" .. "Rules may not share the same name as configured interfaces, members or policies")) mwan_rule.addremove = true -- cgit v1.2.3 From de1afe2a90450d68e2e2c368fd888520e4ac3f7d Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Wed, 17 Jan 2018 15:22:57 +0100 Subject: luci-app-mwan3: remove some config parameter from rule overview table Signed-off-by: Florian Eckert --- .../luasrc/model/cbi/mwan/interface.lua | 4 +- .../luci-app-mwan3/luasrc/model/cbi/mwan/rule.lua | 44 ---------------------- 2 files changed, 2 insertions(+), 46 deletions(-) diff --git a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/interface.lua b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/interface.lua index 23a94a153d..01f18dae4a 100644 --- a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/interface.lua +++ b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/interface.lua @@ -130,9 +130,9 @@ enabled = mwan_interface:option(DummyValue, "enabled", translate("Enabled")) enabled.rawhtml = true function enabled.cfgvalue(self, s) if self.map:get(s, "enabled") == "1" then - return "Yes" + return translate("Yes") else - return "No" + return translate("No") end end diff --git a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/rule.lua b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/rule.lua index 151103f7bd..97f28bd325 100644 --- a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/rule.lua +++ b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/rule.lua @@ -90,54 +90,10 @@ proto = mwan_rule:option(DummyValue, "proto", translate("Protocol")) return self.map:get(s, "proto") or "all" end -sticky = mwan_rule:option(DummyValue, "sticky", translate("Sticky")) - sticky.rawhtml = true - function sticky.cfgvalue(self, s) - if self.map:get(s, "sticky") == "1" then - stickied = 1 - return translate("Yes") - else - stickied = nil - return translate("No") - end - end - -timeout = mwan_rule:option(DummyValue, "timeout", translate("Sticky timeout")) - timeout.rawhtml = true - function timeout.cfgvalue(self, s) - if stickied then - local timeoutValue = self.map:get(s, "timeout") - if timeoutValue then - return timeoutValue .. "s" - else - return "600s" - end - else - return "—" - end - end - -ipset = mwan_rule:option(DummyValue, "ipset", translate("IPset")) - ipset.rawhtml = true - function ipset.cfgvalue(self, s) - return self.map:get(s, "ipset") or "—" - end - use_policy = mwan_rule:option(DummyValue, "use_policy", translate("Policy assigned")) use_policy.rawhtml = true function use_policy.cfgvalue(self, s) return self.map:get(s, "use_policy") or "—" end -errors = mwan_rule:option(DummyValue, "errors", translate("Errors")) - errors.rawhtml = true - function errors.cfgvalue(self, s) - if not string.find(error_protocol_list, " " .. s .. " ") then - return "" - else - return "\"error\"" - end - end - - return m5 -- cgit v1.2.3 From aae3d298c2a74d2f17887555bf7398c3de339b62 Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Wed, 17 Jan 2018 16:05:25 +0100 Subject: luci-app-mwan3: refactoring warning compilation on the rule config pages Signed-off-by: Florian Eckert --- .../luci-app-mwan3/luasrc/model/cbi/mwan/rule.lua | 50 +++++++++++----------- .../luasrc/model/cbi/mwan/ruleconfig.lua | 40 +++-------------- 2 files changed, 32 insertions(+), 58 deletions(-) diff --git a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/rule.lua b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/rule.lua index 97f28bd325..d71cb2bc1f 100644 --- a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/rule.lua +++ b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/rule.lua @@ -1,40 +1,42 @@ --- ------ extra functions ------ -- +dsp = require "luci.dispatcher" +sys = require "luci.sys" +ut = require "luci.util" -function ruleCheck() -- determine if rules needs a proper protocol configured +function ruleCheck() + local rule_error = {} uci.cursor():foreach("mwan3", "rule", function (section) - local sourcePort = ut.trim(sys.exec("uci -p /var/state get mwan3." .. section[".name"] .. ".src_port")) - local destPort = ut.trim(sys.exec("uci -p /var/state get mwan3." .. section[".name"] .. ".dest_port")) - if sourcePort ~= "" or destPort ~= "" then -- ports configured - local protocol = ut.trim(sys.exec("uci -p /var/state get mwan3." .. section[".name"] .. ".proto")) - if protocol == "" or protocol == "all" then -- no or improper protocol - error_protocol_list = error_protocol_list .. section[".name"] .. " " + rule_error[section[".name"]] = false + local uci = uci.cursor(nil, "/var/state") + local sourcePort = uci:get("mwan3", section[".name"], "src_port") + local destPort = uci:get("mwan3", section[".name"], "dest_port") + if sourcePort ~= nil or destPort ~= nil then + local protocol = uci:get("mwan3", section[".name"], "proto") + if protocol == nil or protocol == "all" then + rule_error[section[".name"]] = true end end end ) + return rule_error end -function ruleWarn() -- display warning messages at the top of the page - if error_protocol_list ~= " " then - return "" .. translate("WARNING: Some rules have a port configured with no or improper protocol specified! Please configure a specific protocol!") .. "" - else - return "" +function ruleWarn(rule_error) + local warnings = "" + for i, k in pairs(rule_error) do + if rule_error[i] == true then + warnings = warnings .. string.format("%s
", + translatef("WARNING: Rule %s have a port configured with no or improper protocol specified!", i) + ) + end end -end - --- ------ rule configuration ------ -- - -dsp = require "luci.dispatcher" -sys = require "luci.sys" -ut = require "luci.util" - -error_protocol_list = " " -ruleCheck() + return warnings +end m5 = Map("mwan3", translate("MWAN - Rules"), - ruleWarn()) + ruleWarn(ruleCheck()) + ) mwan_rule = m5:section(TypedSection, "rule", nil, translate("Rules specify which traffic will use a particular MWAN policy
" .. diff --git a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/ruleconfig.lua b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/ruleconfig.lua index 812d46365f..4ff9f11673 100644 --- a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/ruleconfig.lua +++ b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/ruleconfig.lua @@ -1,23 +1,7 @@ --- ------ extra functions ------ -- - -function ruleCheck() -- determine if rule needs a protocol specified - local sourcePort = ut.trim(sys.exec("uci -p /var/state get mwan3." .. arg[1] .. ".src_port")) - local destPort = ut.trim(sys.exec("uci -p /var/state get mwan3." .. arg[1] .. ".dest_port")) - if sourcePort ~= "" or destPort ~= "" then -- ports configured - local protocol = ut.trim(sys.exec("uci -p /var/state get mwan3." .. arg[1] .. ".proto")) - if protocol == "" or protocol == "all" then -- no or improper protocol - error_protocol = 1 - end - end -end - -function ruleWarn() -- display warning message at the top of the page - if error_protocol == 1 then - return "" .. translate("WARNING: This rule is incorrectly configured with no or improper protocol specified! Please configure a specific protocol!") .. "" - else - return "" - end -end +dsp = require "luci.dispatcher" +sys = require "luci.sys" +ut = require "luci.util" +arg[1] = arg[1] or "" function cbiAddPolicy(field) uci.cursor():foreach("mwan3", "policy", @@ -34,20 +18,8 @@ function cbiAddProtocol(field) end end --- ------ rule configuration ------ -- - -dsp = require "luci.dispatcher" -sys = require "luci.sys" -ut = require "luci.util" -arg[1] = arg[1] or "" - -error_protocol = 0 -ruleCheck() - - -m5 = Map("mwan3", translatef("MWAN Rule Configuration - %s", arg[1]), - ruleWarn()) - m5.redirect = dsp.build_url("admin", "network", "mwan", "rule") +m5 = Map("mwan3", translatef("MWAN Rule Configuration - %s", arg[1])) +m5.redirect = dsp.build_url("admin", "network", "mwan", "rule") mwan_rule = m5:section(NamedSection, arg[1], "rule", "") -- cgit v1.2.3 From ed0d2ba6cfd24fac3eaa5e566cc2ac29cae1e444 Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Wed, 17 Jan 2018 16:27:09 +0100 Subject: luci-app-mwan3: refactoring ruleconfig page Signed-off-by: Florian Eckert --- .../luasrc/model/cbi/mwan/ruleconfig.lua | 34 +++++++--------------- 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/ruleconfig.lua b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/ruleconfig.lua index 4ff9f11673..756e089404 100644 --- a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/ruleconfig.lua +++ b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/ruleconfig.lua @@ -3,25 +3,9 @@ sys = require "luci.sys" ut = require "luci.util" arg[1] = arg[1] or "" -function cbiAddPolicy(field) - uci.cursor():foreach("mwan3", "policy", - function (section) - field:value(section[".name"]) - end - ) -end - -function cbiAddProtocol(field) - local protocols = ut.trim(sys.exec("cat /etc/protocols | grep ' # ' | awk '{print $1}' | grep -vw -e 'ip' -e 'tcp' -e 'udp' -e 'icmp' -e 'esp' | grep -v 'ipv6' | sort | tr '\n' ' '")) - for p in string.gmatch(protocols, "%S+") do - field:value(p) - end -end - m5 = Map("mwan3", translatef("MWAN Rule Configuration - %s", arg[1])) m5.redirect = dsp.build_url("admin", "network", "mwan", "rule") - mwan_rule = m5:section(NamedSection, arg[1], "rule", "") mwan_rule.addremove = false mwan_rule.dynamic = false @@ -42,16 +26,14 @@ dest_port = mwan_rule:option(Value, "dest_port", translate("Destination port"), translate("May be entered as a single or multiple port(s) (eg \"22\" or \"80,443\") or as a portrange (eg \"1024:2048\") without quotes")) proto = mwan_rule:option(Value, "proto", translate("Protocol"), - translate("View the contents of /etc/protocols for protocol descriptions")) + translate("View the content of /etc/protocols for protocol description")) proto.default = "all" proto.rmempty = false proto:value("all") - proto:value("ip") proto:value("tcp") proto:value("udp") proto:value("icmp") proto:value("esp") - cbiAddProtocol(proto) sticky = mwan_rule:option(ListValue, "sticky", translate("Sticky"), translate("Traffic from the same source IP address that previously matched this rule within the sticky timeout period will use the same WAN interface")) @@ -66,10 +48,14 @@ timeout = mwan_rule:option(Value, "timeout", translate("Sticky timeout"), ipset = mwan_rule:option(Value, "ipset", translate("IPset"), translate("Name of IPset rule. Requires IPset rule in /etc/dnsmasq.conf (eg \"ipset=/youtube.com/youtube\")")) -use_policy = mwan_rule:option(Value, "use_policy", translate("Policy assigned")) - cbiAddPolicy(use_policy) - use_policy:value("unreachable", translate("unreachable (reject)")) - use_policy:value("blackhole", translate("blackhole (drop)")) - use_policy:value("default", translate("default (use main routing table)")) +policy = mwan_rule:option(Value, "use_policy", translate("Policy assigned")) +m5.uci:foreach("mwan3", "policy", + function(s) + policy:value(s['.name'], s['.name']) + end +) +policy:value("unreachable", translate("unreachable (reject)")) +policy:value("blackhole", translate("blackhole (drop)")) +policy:value("default", translate("default (use main routing table)")) return m5 -- cgit v1.2.3 From b4350f21ff2f31b7dbcdbc5f034659ba580c059f Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Wed, 17 Jan 2018 17:01:42 +0100 Subject: luci-app-mwan3: refactoring warning compilation on the policy config pages Signed-off-by: Florian Eckert --- .../luasrc/model/cbi/mwan/policy.lua | 51 +++++++++------------- .../luasrc/model/cbi/mwan/policyconfig.lua | 46 ++++--------------- 2 files changed, 28 insertions(+), 69 deletions(-) diff --git a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/policy.lua b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/policy.lua index 6de5ae82bc..44585d75ef 100644 --- a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/policy.lua +++ b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/policy.lua @@ -1,36 +1,36 @@ --- ------ extra functions ------ -- +ds = require "luci.dispatcher" +sys = require "luci.sys" + +function policyCheck() + local policy_error = {} -function policyCheck() -- check to see if any policy names exceed the maximum of 15 characters uci.cursor():foreach("mwan3", "policy", function (section) + policy_error[section[".name"]] = false if string.len(section[".name"]) > 15 then - nameTooLong = 1 - err_name_list = err_name_list .. section[".name"] .. " " + policy_error[section[".name"]] = true end end ) -end -function policyWarn() -- display status and warning messages at the top of the page - if nameTooLong == 1 then - return "" .. translate("WARNING: Some policies have names exceeding the maximum of 15 characters!") .. "" - else - return "" - end + return policy_error end --- ------ policy configuration ------ -- - -ds = require "luci.dispatcher" -sys = require "luci.sys" - -nameTooLong = 0 -err_name_list = " " -policyCheck() +function policyError(policy_error) + local warnings = "" + for i, k in pairs(policy_error) do + if policy_error[i] == true then + warnings = warnings .. string.format("%s
", + translatef("WARNING: Policie %s has exceeding the maximum name of 15 characters", i) + ) + end + end + return warnings +end m5 = Map("mwan3", translate("MWAN - Policies"), - policyWarn()) + policyError(policyCheck())) mwan_policy = m5:section(TypedSection, "policy", nil, @@ -79,15 +79,4 @@ last_resort = mwan_policy:option(DummyValue, "last_resort", translate("Last reso end end -errors = mwan_policy:option(DummyValue, "errors", translate("Errors")) - errors.rawhtml = true - function errors.cfgvalue(self, s) - if not string.find(err_name_list, " " .. s .. " ") then - return "" - else - return "\"error\"" - end - end - - return m5 diff --git a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/policyconfig.lua b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/policyconfig.lua index b9ff321a1f..f29a06093a 100644 --- a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/policyconfig.lua +++ b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/policyconfig.lua @@ -1,49 +1,19 @@ --- ------ extra functions ------ -- - -function policyCheck() -- check to see if this policy's name exceed the maximum of 15 characters - policyNameLength = string.len(arg[1]) - if policyNameLength > 15 then - nameTooLong = 1 - end -end - -function policyWarn() -- display status and warning messages at the top of the page - if nameTooLong == 1 then - return "" .. translatef("WARNING: This policy's name is %d characters exceeding the maximum of 15!", policyNameLength) .. "" - else - return "" - end -end - -function cbiAddMember(field) - uci.cursor():foreach("mwan3", "member", - function (section) - field:value(section[".name"]) - end - ) -end - --- ------ policy configuration ------ -- - dsp = require "luci.dispatcher" arg[1] = arg[1] or "" -nameTooLong = 0 -policyCheck() - - -m5 = Map("mwan3", translatef("MWAN Policy Configuration - %s", arg[1]), - policyWarn()) - m5.redirect = dsp.build_url("admin", "network", "mwan", "policy") - +m5 = Map("mwan3", translatef("MWAN Policy Configuration - %s", arg[1])) +m5.redirect = dsp.build_url("admin", "network", "mwan", "policy") mwan_policy = m5:section(NamedSection, arg[1], "policy", "") mwan_policy.addremove = false mwan_policy.dynamic = false - -use_member = mwan_policy:option(DynamicList, "use_member", translate("Member used")) - cbiAddMember(use_member) +member = mwan_policy:option(DynamicList, "use_member", translate("Member used")) +m5.uci:foreach("mwan3", "member", + function(s) + member:value(s['.name'], s['.name']) + end +) last_resort = mwan_policy:option(ListValue, "last_resort", translate("Last resort"), translate("When all policy members are offline use this behavior for matched traffic")) -- cgit v1.2.3 From d369c80beccedf883b4cd47b4e3c1debc9f37e9a Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Wed, 17 Jan 2018 17:10:06 +0100 Subject: luci-app-mwan3: refactoring member config pages Signed-off-by: Florian Eckert --- .../luasrc/model/cbi/mwan/member.lua | 4 ---- .../luasrc/model/cbi/mwan/memberconfig.lua | 22 ++++++---------------- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/member.lua b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/member.lua index 67030cc8db..0865fccaf7 100644 --- a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/member.lua +++ b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/member.lua @@ -1,5 +1,3 @@ --- ------ member configuration ------ -- - ds = require "luci.dispatcher" @@ -21,7 +19,6 @@ mwan_member = m5:section(TypedSection, "member", nil, luci.http.redirect(ds.build_url("admin", "network", "mwan", "member", section)) end - interface = mwan_member:option(DummyValue, "interface", translate("Interface")) interface.rawhtml = true function interface.cfgvalue(self, s) @@ -40,5 +37,4 @@ weight = mwan_member:option(DummyValue, "weight", translate("Weight")) return self.map:get(s, "weight") or "1" end - return m5 diff --git a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/memberconfig.lua b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/memberconfig.lua index 8b606cdebd..1208905c39 100644 --- a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/memberconfig.lua +++ b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/memberconfig.lua @@ -1,30 +1,20 @@ --- ------ extra functions ------ -- - -function cbi_add_interface(field) - uci.cursor():foreach("mwan3", "interface", - function (section) - field:value(section[".name"]) - end - ) -end - --- ------ member configuration ------ -- - dsp = require "luci.dispatcher" arg[1] = arg[1] or "" m5 = Map("mwan3", translatef("MWAN Member Configuration - %s", arg[1])) - m5.redirect = dsp.build_url("admin", "network", "mwan", "member") - +m5.redirect = dsp.build_url("admin", "network", "mwan", "member") mwan_member = m5:section(NamedSection, arg[1], "member", "") mwan_member.addremove = false mwan_member.dynamic = false - interface = mwan_member:option(Value, "interface", translate("Interface")) - cbi_add_interface(interface) +m5.uci:foreach("mwan3", "interface", + function(s) + interface:value(s['.name'], s['.name']) + end +) metric = mwan_member:option(Value, "metric", translate("Metric"), translate("Acceptable values: 1-256. Defaults to 1 if not set")) -- cgit v1.2.3 From 831bd71eb387973a25277e3fa7391c6a4af83597 Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Thu, 18 Jan 2018 07:26:27 +0100 Subject: luci-app-mwan3: remove/unify lua require order Signed-off-by: Florian Eckert --- .../luci-app-mwan3/luasrc/model/cbi/mwan/globalsconfig.lua | 4 +++- applications/luci-app-mwan3/luasrc/model/cbi/mwan/interface.lua | 3 +-- .../luci-app-mwan3/luasrc/model/cbi/mwan/interfaceconfig.lua | 2 -- applications/luci-app-mwan3/luasrc/model/cbi/mwan/member.lua | 6 +++--- applications/luci-app-mwan3/luasrc/model/cbi/mwan/notify.lua | 3 +-- applications/luci-app-mwan3/luasrc/model/cbi/mwan/policy.lua | 8 ++++---- .../luci-app-mwan3/luasrc/model/cbi/mwan/policyconfig.lua | 1 + applications/luci-app-mwan3/luasrc/model/cbi/mwan/rule.lua | 3 +-- applications/luci-app-mwan3/luasrc/model/cbi/mwan/ruleconfig.lua | 3 +-- 9 files changed, 15 insertions(+), 18 deletions(-) diff --git a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/globalsconfig.lua b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/globalsconfig.lua index 3e1a28325b..b53d288d0d 100644 --- a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/globalsconfig.lua +++ b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/globalsconfig.lua @@ -14,12 +14,14 @@ $Id$ local net = require "luci.model.network".init() + m = Map("mwan3", translate("MWAN - Globals")) s = m:section(NamedSection, "globals", "globals", nil) n = s:option(ListValue, "local_source", translate("Local source interface"), - translate("Use the IP address of this interface as source IP address for traffic initiated by the router itself")) + translate("Use the IP address of this interface as source IP " .. + "address for traffic initiated by the router itself")) n:value("none") n.default = "none" for _, net in ipairs(net:get_networks()) do diff --git a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/interface.lua b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/interface.lua index 01f18dae4a..f80319327e 100644 --- a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/interface.lua +++ b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/interface.lua @@ -1,6 +1,5 @@ dsp = require "luci.dispatcher" -sys = require "luci.sys" -ut = require "luci.util" + function interfaceWarnings(overview, count) local warnings = "" diff --git a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/interfaceconfig.lua b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/interfaceconfig.lua index 07ccd2d59f..01b96da41a 100644 --- a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/interfaceconfig.lua +++ b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/interfaceconfig.lua @@ -1,6 +1,4 @@ dsp = require "luci.dispatcher" -sys = require "luci.sys" -ut = require "luci.util" arg[1] = arg[1] or "" diff --git a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/member.lua b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/member.lua index 0865fccaf7..63e511e53c 100644 --- a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/member.lua +++ b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/member.lua @@ -1,4 +1,4 @@ -ds = require "luci.dispatcher" +dsp = require "luci.dispatcher" m5 = Map("mwan3", translate("MWAN - Members")) @@ -12,11 +12,11 @@ mwan_member = m5:section(TypedSection, "member", nil, mwan_member.sectionhead = translate("Member") mwan_member.sortable = true mwan_member.template = "cbi/tblsection" - mwan_member.extedit = ds.build_url("admin", "network", "mwan", "member", "%s") + mwan_member.extedit = dsp.build_url("admin", "network", "mwan", "member", "%s") function mwan_member.create(self, section) TypedSection.create(self, section) m5.uci:save("mwan3") - luci.http.redirect(ds.build_url("admin", "network", "mwan", "member", section)) + luci.http.redirect(dsp.build_url("admin", "network", "mwan", "member", section)) end interface = mwan_member:option(DummyValue, "interface", translate("Interface")) diff --git a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/notify.lua b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/notify.lua index 14237e60f4..1019302ac9 100644 --- a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/notify.lua +++ b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/notify.lua @@ -1,9 +1,8 @@ --- ------ hotplug script configuration ------ -- - local fs = require "nixio.fs" local ut = require "luci.util" script = "/etc/mwan3.user" + m5 = SimpleForm("luci", translate("MWAN - Notification")) f = m5:section(SimpleSection, nil, diff --git a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/policy.lua b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/policy.lua index 44585d75ef..6340359fae 100644 --- a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/policy.lua +++ b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/policy.lua @@ -1,5 +1,5 @@ -ds = require "luci.dispatcher" -sys = require "luci.sys" +dsp = require "luci.dispatcher" + function policyCheck() local policy_error = {} @@ -44,11 +44,11 @@ mwan_policy = m5:section(TypedSection, "policy", nil, mwan_policy.sectionhead = translate("Policy") mwan_policy.sortable = true mwan_policy.template = "cbi/tblsection" - mwan_policy.extedit = ds.build_url("admin", "network", "mwan", "policy", "%s") + mwan_policy.extedit = dsp.build_url("admin", "network", "mwan", "policy", "%s") function mwan_policy.create(self, section) TypedSection.create(self, section) m5.uci:save("mwan3") - luci.http.redirect(ds.build_url("admin", "network", "mwan", "policy", section)) + luci.http.redirect(dsp.build_url("admin", "network", "mwan", "policy", section)) end diff --git a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/policyconfig.lua b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/policyconfig.lua index f29a06093a..29bb3dcd88 100644 --- a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/policyconfig.lua +++ b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/policyconfig.lua @@ -1,6 +1,7 @@ dsp = require "luci.dispatcher" arg[1] = arg[1] or "" + m5 = Map("mwan3", translatef("MWAN Policy Configuration - %s", arg[1])) m5.redirect = dsp.build_url("admin", "network", "mwan", "policy") diff --git a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/rule.lua b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/rule.lua index d71cb2bc1f..5c6329e339 100644 --- a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/rule.lua +++ b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/rule.lua @@ -1,6 +1,5 @@ dsp = require "luci.dispatcher" -sys = require "luci.sys" -ut = require "luci.util" + function ruleCheck() local rule_error = {} diff --git a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/ruleconfig.lua b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/ruleconfig.lua index 756e089404..e12639e33d 100644 --- a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/ruleconfig.lua +++ b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/ruleconfig.lua @@ -1,8 +1,7 @@ dsp = require "luci.dispatcher" -sys = require "luci.sys" -ut = require "luci.util" arg[1] = arg[1] or "" + m5 = Map("mwan3", translatef("MWAN Rule Configuration - %s", arg[1])) m5.redirect = dsp.build_url("admin", "network", "mwan", "rule") -- cgit v1.2.3 From 278b3f53dbf07e4e73cade28b9cb262f77c790cd Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Thu, 18 Jan 2018 07:41:41 +0100 Subject: luci-app-mwan3: fix unify luci code styling Signed-off-by: Florian Eckert --- .../luasrc/model/cbi/mwan/interface.lua | 140 ++++++------ .../luasrc/model/cbi/mwan/interfaceconfig.lua | 250 ++++++++++----------- .../luasrc/model/cbi/mwan/member.lua | 46 ++-- .../luasrc/model/cbi/mwan/memberconfig.lua | 8 +- .../luasrc/model/cbi/mwan/policy.lua | 64 +++--- .../luasrc/model/cbi/mwan/policyconfig.lua | 12 +- .../luci-app-mwan3/luasrc/model/cbi/mwan/rule.lua | 73 +++--- .../luasrc/model/cbi/mwan/ruleconfig.lua | 31 ++- 8 files changed, 308 insertions(+), 316 deletions(-) diff --git a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/interface.lua b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/interface.lua index f80319327e..166f077910 100644 --- a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/interface.lua +++ b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/interface.lua @@ -105,106 +105,104 @@ end m5 = Map("mwan3", translate("MWAN - Interfaces"), interfaceWarnings(configCheck())) - mwan_interface = m5:section(TypedSection, "interface", nil, translate("MWAN supports up to 250 physical and/or logical interfaces
" .. "MWAN requires that all interfaces have a unique metric configured in /etc/config/network
" .. "Names must match the interface name found in /etc/config/network (see advanced tab)
" .. "Names may contain characters A-Z, a-z, 0-9, _ and no spaces
" .. "Interfaces may not share the same name as configured members, policies or rules")) - mwan_interface.addremove = true - mwan_interface.dynamic = false - mwan_interface.sectionhead = translate("Interface") - mwan_interface.sortable = false - mwan_interface.template = "cbi/tblsection" - mwan_interface.extedit = dsp.build_url("admin", "network", "mwan", "interface", "%s") - function mwan_interface.create(self, section) - TypedSection.create(self, section) - m5.uci:save("mwan3") - luci.http.redirect(dsp.build_url("admin", "network", "mwan", "interface", section)) - end - +mwan_interface.addremove = true +mwan_interface.dynamic = false +mwan_interface.sectionhead = translate("Interface") +mwan_interface.sortable = false +mwan_interface.template = "cbi/tblsection" +mwan_interface.extedit = dsp.build_url("admin", "network", "mwan", "interface", "%s") +function mwan_interface.create(self, section) + TypedSection.create(self, section) + m5.uci:save("mwan3") + luci.http.redirect(dsp.build_url("admin", "network", "mwan", "interface", section)) +end enabled = mwan_interface:option(DummyValue, "enabled", translate("Enabled")) - enabled.rawhtml = true - function enabled.cfgvalue(self, s) - if self.map:get(s, "enabled") == "1" then - return translate("Yes") - else - return translate("No") - end +enabled.rawhtml = true +function enabled.cfgvalue(self, s) + if self.map:get(s, "enabled") == "1" then + return translate("Yes") + else + return translate("No") end +end track_method = mwan_interface:option(DummyValue, "track_method", translate("Tracking method")) - track_method.rawhtml = true - function track_method.cfgvalue(self, s) - local tracked = self.map:get(s, "track_ip") - if tracked then - return self.map:get(s, "track_method") or "—" - else - return "—" - end +track_method.rawhtml = true +function track_method.cfgvalue(self, s) + local tracked = self.map:get(s, "track_ip") + if tracked then + return self.map:get(s, "track_method") or "—" + else + return "—" end +end reliability = mwan_interface:option(DummyValue, "reliability", translate("Tracking reliability")) - reliability.rawhtml = true - function reliability.cfgvalue(self, s) - local tracked = self.map:get(s, "track_ip") - if tracked then - return self.map:get(s, "reliability") or "—" - else - return "—" - end +reliability.rawhtml = true +function reliability.cfgvalue(self, s) + local tracked = self.map:get(s, "track_ip") + if tracked then + return self.map:get(s, "reliability") or "—" + else + return "—" end +end interval = mwan_interface:option(DummyValue, "interval", translate("Ping interval")) - interval.rawhtml = true - function interval.cfgvalue(self, s) - local tracked = self.map:get(s, "track_ip") - if tracked then - local intervalValue = self.map:get(s, "interval") - if intervalValue then - return intervalValue .. "s" - else - return "—" - end +interval.rawhtml = true +function interval.cfgvalue(self, s) + local tracked = self.map:get(s, "track_ip") + if tracked then + local intervalValue = self.map:get(s, "interval") + if intervalValue then + return intervalValue .. "s" else return "—" end + else + return "—" end +end down = mwan_interface:option(DummyValue, "down", translate("Interface down")) - down.rawhtml = true - function down.cfgvalue(self, s) - local tracked = self.map:get(s, "track_ip") - if tracked then - return self.map:get(s, "down") or "—" - else - return "—" - end +down.rawhtml = true +function down.cfgvalue(self, s) + local tracked = self.map:get(s, "track_ip") + if tracked then + return self.map:get(s, "down") or "—" + else + return "—" end +end up = mwan_interface:option(DummyValue, "up", translate("Interface up")) - up.rawhtml = true - function up.cfgvalue(self, s) - local tracked = self.map:get(s, "track_ip") - if tracked then - return self.map:get(s, "up") or "—" - else - return "—" - end +up.rawhtml = true +function up.cfgvalue(self, s) + local tracked = self.map:get(s, "track_ip") + if tracked then + return self.map:get(s, "up") or "—" + else + return "—" end +end metric = mwan_interface:option(DummyValue, "metric", translate("Metric")) - metric.rawhtml = true - function metric.cfgvalue(self, s) - local uci = uci.cursor(nil, "/var/state") - local metric = uci:get("network", s, "metric") - if metric then - return metric - else - return "—" - end +metric.rawhtml = true +function metric.cfgvalue(self, s) + local uci = uci.cursor(nil, "/var/state") + local metric = uci:get("network", s, "metric") + if metric then + return metric + else + return "—" end +end return m5 diff --git a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/interfaceconfig.lua b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/interfaceconfig.lua index 01b96da41a..9f1db08be7 100644 --- a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/interfaceconfig.lua +++ b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/interfaceconfig.lua @@ -5,177 +5,175 @@ arg[1] = arg[1] or "" m5 = Map("mwan3", translatef("MWAN Interface Configuration - %s", arg[1])) m5.redirect = dsp.build_url("admin", "network", "mwan", "interface") - mwan_interface = m5:section(NamedSection, arg[1], "interface", "") - mwan_interface.addremove = false - mwan_interface.dynamic = false - +mwan_interface.addremove = false +mwan_interface.dynamic = false enabled = mwan_interface:option(ListValue, "enabled", translate("Enabled")) - enabled.default = "1" - enabled:value("1", translate("Yes")) - enabled:value("0", translate("No")) +enabled.default = "1" +enabled:value("1", translate("Yes")) +enabled:value("0", translate("No")) initial_state = mwan_interface:option(ListValue, "initial_state", translate("Initial state"), translate("Expect interface state on up event")) - initial_state.default = "online" - initial_state:value("online", translate("Online")) - initial_state:value("offline", translate("Offline")) +initial_state.default = "online" +initial_state:value("online", translate("Online")) +initial_state:value("offline", translate("Offline")) family = mwan_interface:option(ListValue, "family", translate("Internet Protocol")) - family.default = "ipv4" - family:value("ipv4", translate("IPv4")) - family:value("ipv6", translate("IPv6")) +family.default = "ipv4" +family:value("ipv4", translate("IPv4")) +family:value("ipv6", translate("IPv6")) track_ip = mwan_interface:option(DynamicList, "track_ip", translate("Tracking hostname or IP address"), translate("This hostname or IP address will be pinged to determine if the link is up or down. Leave blank to assume interface is always online")) - track_ip.datatype = "host" +track_ip.datatype = "host" track_method = mwan_interface:option(ListValue, "track_method", translate("Tracking method")) - track_method.default = "ping" - track_method:value("ping") - track_method:value("arping") - track_method:value("httping") +track_method.default = "ping" +track_method:value("ping") +track_method:value("arping") +track_method:value("httping") reliability = mwan_interface:option(Value, "reliability", translate("Tracking reliability"), translate("Acceptable values: 1-100. This many Tracking IP addresses must respond for the link to be deemed up")) - reliability.datatype = "range(1, 100)" - reliability.default = "1" +reliability.datatype = "range(1, 100)" +reliability.default = "1" count = mwan_interface:option(ListValue, "count", translate("Ping count")) - count.default = "1" - count:value("1") - count:value("2") - count:value("3") - count:value("4") - count:value("5") +count.default = "1" +count:value("1") +count:value("2") +count:value("3") +count:value("4") +count:value("5") size = mwan_interface:option(Value, "size", translate("Ping size")) - size.default = "56" - size:value("8") - size:value("24") - size:value("56") - size:value("120") - size:value("248") - size:value("504") - size:value("1016") - size:value("1472") - size:value("2040") - size.datatype = "range(1, 65507)" - size.rmempty = false - size.optional = false +size.default = "56" +size:value("8") +size:value("24") +size:value("56") +size:value("120") +size:value("248") +size:value("504") +size:value("1016") +size:value("1472") +size:value("2040") +size.datatype = "range(1, 65507)" +size.rmempty = false +size.optional = false timeout = mwan_interface:option(ListValue, "timeout", translate("Ping timeout")) - timeout.default = "2" - timeout:value("1", translatef("%d second", 1)) - timeout:value("2", translatef("%d seconds", 2)) - timeout:value("3", translatef("%d seconds", 3)) - timeout:value("4", translatef("%d seconds", 4)) - timeout:value("5", translatef("%d seconds", 5)) - timeout:value("6", translatef("%d seconds", 6)) - timeout:value("7", translatef("%d seconds", 7)) - timeout:value("8", translatef("%d seconds", 8)) - timeout:value("9", translatef("%d seconds", 9)) - timeout:value("10", translatef("%d seconds", 10)) +timeout.default = "2" +timeout:value("1", translatef("%d second", 1)) +timeout:value("2", translatef("%d seconds", 2)) +timeout:value("3", translatef("%d seconds", 3)) +timeout:value("4", translatef("%d seconds", 4)) +timeout:value("5", translatef("%d seconds", 5)) +timeout:value("6", translatef("%d seconds", 6)) +timeout:value("7", translatef("%d seconds", 7)) +timeout:value("8", translatef("%d seconds", 8)) +timeout:value("9", translatef("%d seconds", 9)) +timeout:value("10", translatef("%d seconds", 10)) interval = mwan_interface:option(ListValue, "interval", translate("Ping interval")) - interval.default = "5" - interval:value("1", translatef("%d second", 1)) - interval:value("3", translatef("%d seconds", 3)) - interval:value("5", translatef("%d seconds", 5)) - interval:value("10", translatef("%d seconds", 10)) - interval:value("20", translatef("%d seconds", 20)) - interval:value("30", translatef("%d seconds", 30)) - interval:value("60", translatef("%d minute", 1)) - interval:value("300", translatef("%d minutes", 5)) - interval:value("600", translatef("%d minutes", 10)) - interval:value("900", translatef("%d minutes", 15)) - interval:value("1800", translatef("%d minutes", 30)) - interval:value("3600", translatef("%d hour", 1)) +interval.default = "5" +interval:value("1", translatef("%d second", 1)) +interval:value("3", translatef("%d seconds", 3)) +interval:value("5", translatef("%d seconds", 5)) +interval:value("10", translatef("%d seconds", 10)) +interval:value("20", translatef("%d seconds", 20)) +interval:value("30", translatef("%d seconds", 30)) +interval:value("60", translatef("%d minute", 1)) +interval:value("300", translatef("%d minutes", 5)) +interval:value("600", translatef("%d minutes", 10)) +interval:value("900", translatef("%d minutes", 15)) +interval:value("1800", translatef("%d minutes", 30)) +interval:value("3600", translatef("%d hour", 1)) failure = mwan_interface:option(Value, "failure_interval", translate("Failure interval"), translate("Ping interval during failure detection")) - failure.default = "5" - failure:value("1", translatef("%d second", 1)) - failure:value("3", translatef("%d seconds", 3)) - failure:value("5", translatef("%d seconds", 5)) - failure:value("10", translatef("%d seconds", 10)) - failure:value("20", translatef("%d seconds", 20)) - failure:value("30", translatef("%d seconds", 30)) - failure:value("60", translatef("%d minute", 1)) - failure:value("300", translatef("%d minutes", 5)) - failure:value("600", translatef("%d minutes", 10)) - failure:value("900", translatef("%d minutes", 15)) - failure:value("1800", translatef("%d minutes", 30)) - failure:value("3600", translatef("%d hour", 1)) +failure.default = "5" +failure:value("1", translatef("%d second", 1)) +failure:value("3", translatef("%d seconds", 3)) +failure:value("5", translatef("%d seconds", 5)) +failure:value("10", translatef("%d seconds", 10)) +failure:value("20", translatef("%d seconds", 20)) +failure:value("30", translatef("%d seconds", 30)) +failure:value("60", translatef("%d minute", 1)) +failure:value("300", translatef("%d minutes", 5)) +failure:value("600", translatef("%d minutes", 10)) +failure:value("900", translatef("%d minutes", 15)) +failure:value("1800", translatef("%d minutes", 30)) +failure:value("3600", translatef("%d hour", 1)) keep_failure = mwan_interface:option(Flag, "keep_failure_interval", translate("Keep failure interval"), translate("Keep ping failure interval during failure state")) - keep_failure.default = keep_failure.disabled +keep_failure.default = keep_failure.disabled recovery = mwan_interface:option(Value, "recovery_interval", translate("Recovery interval"), translate("Ping interval during failure recovering")) - recovery.default = "5" - recovery:value("1", translatef("%d second", 1)) - recovery:value("3", translatef("%d seconds", 3)) - recovery:value("5", translatef("%d seconds", 5)) - recovery:value("10", translatef("%d seconds", 10)) - recovery:value("20", translatef("%d seconds", 20)) - recovery:value("30", translatef("%d seconds", 30)) - recovery:value("60", translatef("%d minute", 1)) - recovery:value("300", translatef("%d minutes", 5)) - recovery:value("600", translatef("%d minutes", 10)) - recovery:value("900", translatef("%d minutes", 15)) - recovery:value("1800", translatef("%d minutes", 30)) - recovery:value("3600", translatef("%d hour", 1)) +recovery.default = "5" +recovery:value("1", translatef("%d second", 1)) +recovery:value("3", translatef("%d seconds", 3)) +recovery:value("5", translatef("%d seconds", 5)) +recovery:value("10", translatef("%d seconds", 10)) +recovery:value("20", translatef("%d seconds", 20)) +recovery:value("30", translatef("%d seconds", 30)) +recovery:value("60", translatef("%d minute", 1)) +recovery:value("300", translatef("%d minutes", 5)) +recovery:value("600", translatef("%d minutes", 10)) +recovery:value("900", translatef("%d minutes", 15)) +recovery:value("1800", translatef("%d minutes", 30)) +recovery:value("3600", translatef("%d hour", 1)) down = mwan_interface:option(ListValue, "down", translate("Interface down"), translate("Interface will be deemed down after this many failed ping tests")) - down.default = "3" - down:value("1") - down:value("2") - down:value("3") - down:value("4") - down:value("5") - down:value("6") - down:value("7") - down:value("8") - down:value("9") - down:value("10") +down.default = "3" +down:value("1") +down:value("2") +down:value("3") +down:value("4") +down:value("5") +down:value("6") +down:value("7") +down:value("8") +down:value("9") +down:value("10") up = mwan_interface:option(ListValue, "up", translate("Interface up"), translate("Downed interface will be deemed up after this many successful ping tests")) - up.default = "3" - up:value("1") - up:value("2") - up:value("3") - up:value("4") - up:value("5") - up:value("6") - up:value("7") - up:value("8") - up:value("9") - up:value("10") +up.default = "3" +up:value("1") +up:value("2") +up:value("3") +up:value("4") +up:value("5") +up:value("6") +up:value("7") +up:value("8") +up:value("9") +up:value("10") flush = mwan_interface:option(ListValue, "flush_conntrack", translate("Flush conntrack table"), translate("Flush global firewall conntrack table on interface events")) - flush.default = "never" - flush:value("ifup", translate("ifup")) - flush:value("ifdown", translate("ifdown")) - flush:value("never", translate("never")) - flush:value("always", translate("always")) +flush.default = "never" +flush:value("ifup", translate("ifup")) +flush:value("ifdown", translate("ifdown")) +flush:value("never", translate("never")) +flush:value("always", translate("always")) metric = mwan_interface:option(DummyValue, "metric", translate("Metric"), translate("This displays the metric assigned to this interface in /etc/config/network")) - metric.rawhtml = true - function metric.cfgvalue(self, s) - local uci = uci.cursor(nil, "/var/state") - local metric = uci:get("network", arg[1], "metric") - if metric then - return metric - else - return "—" - end +metric.rawhtml = true +function metric.cfgvalue(self, s) + local uci = uci.cursor(nil, "/var/state") + local metric = uci:get("network", arg[1], "metric") + if metric then + return metric + else + return "—" end +end return m5 diff --git a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/member.lua b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/member.lua index 63e511e53c..ebe1162c55 100644 --- a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/member.lua +++ b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/member.lua @@ -7,34 +7,34 @@ mwan_member = m5:section(TypedSection, "member", nil, translate("Members are profiles attaching a metric and weight to an MWAN interface
" .. "Names may contain characters A-Z, a-z, 0-9, _ and no spaces
" .. "Members may not share the same name as configured interfaces, policies or rules")) - mwan_member.addremove = true - mwan_member.dynamic = false - mwan_member.sectionhead = translate("Member") - mwan_member.sortable = true - mwan_member.template = "cbi/tblsection" - mwan_member.extedit = dsp.build_url("admin", "network", "mwan", "member", "%s") - function mwan_member.create(self, section) - TypedSection.create(self, section) - m5.uci:save("mwan3") - luci.http.redirect(dsp.build_url("admin", "network", "mwan", "member", section)) - end +mwan_member.addremove = true +mwan_member.dynamic = false +mwan_member.sectionhead = translate("Member") +mwan_member.sortable = true +mwan_member.template = "cbi/tblsection" +mwan_member.extedit = dsp.build_url("admin", "network", "mwan", "member", "%s") +function mwan_member.create(self, section) + TypedSection.create(self, section) + m5.uci:save("mwan3") + luci.http.redirect(dsp.build_url("admin", "network", "mwan", "member", section)) +end interface = mwan_member:option(DummyValue, "interface", translate("Interface")) - interface.rawhtml = true - function interface.cfgvalue(self, s) - return self.map:get(s, "interface") or "—" - end +interface.rawhtml = true +function interface.cfgvalue(self, s) + return self.map:get(s, "interface") or "—" +end metric = mwan_member:option(DummyValue, "metric", translate("Metric")) - metric.rawhtml = true - function metric.cfgvalue(self, s) - return self.map:get(s, "metric") or "1" - end +metric.rawhtml = true +function metric.cfgvalue(self, s) + return self.map:get(s, "metric") or "1" +end weight = mwan_member:option(DummyValue, "weight", translate("Weight")) - weight.rawhtml = true - function weight.cfgvalue(self, s) - return self.map:get(s, "weight") or "1" - end +weight.rawhtml = true +function weight.cfgvalue(self, s) + return self.map:get(s, "weight") or "1" +end return m5 diff --git a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/memberconfig.lua b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/memberconfig.lua index 1208905c39..ade357f819 100644 --- a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/memberconfig.lua +++ b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/memberconfig.lua @@ -6,8 +6,8 @@ m5 = Map("mwan3", translatef("MWAN Member Configuration - %s", arg[1])) m5.redirect = dsp.build_url("admin", "network", "mwan", "member") mwan_member = m5:section(NamedSection, arg[1], "member", "") - mwan_member.addremove = false - mwan_member.dynamic = false +mwan_member.addremove = false +mwan_member.dynamic = false interface = mwan_member:option(Value, "interface", translate("Interface")) m5.uci:foreach("mwan3", "interface", @@ -18,10 +18,10 @@ m5.uci:foreach("mwan3", "interface", metric = mwan_member:option(Value, "metric", translate("Metric"), translate("Acceptable values: 1-256. Defaults to 1 if not set")) - metric.datatype = "range(1, 256)" +metric.datatype = "range(1, 256)" weight = mwan_member:option(Value, "weight", translate("Weight"), translate("Acceptable values: 1-1000. Defaults to 1 if not set")) - weight.datatype = "range(1, 1000)" +weight.datatype = "range(1, 1000)" return m5 diff --git a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/policy.lua b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/policy.lua index 6340359fae..6d2ce71300 100644 --- a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/policy.lua +++ b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/policy.lua @@ -32,51 +32,49 @@ end m5 = Map("mwan3", translate("MWAN - Policies"), policyError(policyCheck())) - mwan_policy = m5:section(TypedSection, "policy", nil, translate("Policies are profiles grouping one or more members controlling how MWAN distributes traffic
" .. "Member interfaces with lower metrics are used first. Interfaces with the same metric load-balance
" .. "Load-balanced member interfaces distribute more traffic out those with higher weights
" .. "Names may contain characters A-Z, a-z, 0-9, _ and no spaces. Names must be 15 characters or less
" .. "Policies may not share the same name as configured interfaces, members or rules")) - mwan_policy.addremove = true - mwan_policy.dynamic = false - mwan_policy.sectionhead = translate("Policy") - mwan_policy.sortable = true - mwan_policy.template = "cbi/tblsection" - mwan_policy.extedit = dsp.build_url("admin", "network", "mwan", "policy", "%s") - function mwan_policy.create(self, section) - TypedSection.create(self, section) - m5.uci:save("mwan3") - luci.http.redirect(dsp.build_url("admin", "network", "mwan", "policy", section)) - end - +mwan_policy.addremove = true +mwan_policy.dynamic = false +mwan_policy.sectionhead = translate("Policy") +mwan_policy.sortable = true +mwan_policy.template = "cbi/tblsection" +mwan_policy.extedit = dsp.build_url("admin", "network", "mwan", "policy", "%s") +function mwan_policy.create(self, section) + TypedSection.create(self, section) + m5.uci:save("mwan3") + luci.http.redirect(dsp.build_url("admin", "network", "mwan", "policy", section)) +end use_member = mwan_policy:option(DummyValue, "use_member", translate("Members assigned")) - use_member.rawhtml = true - function use_member.cfgvalue(self, s) - local memberConfig, memberList = self.map:get(s, "use_member"), "" - if memberConfig then - for k,v in pairs(memberConfig) do - memberList = memberList .. v .. "
" - end - return memberList - else - return "—" +use_member.rawhtml = true +function use_member.cfgvalue(self, s) + local memberConfig, memberList = self.map:get(s, "use_member"), "" + if memberConfig then + for k,v in pairs(memberConfig) do + memberList = memberList .. v .. "
" end + return memberList + else + return "—" end +end last_resort = mwan_policy:option(DummyValue, "last_resort", translate("Last resort")) - last_resort.rawhtml = true - function last_resort.cfgvalue(self, s) - local action = self.map:get(s, "last_resort") - if action == "blackhole" then - return translate("blackhole (drop)") - elseif action == "default" then - return translate("default (use main routing table)") - else - return translate("unreachable (reject)") - end +last_resort.rawhtml = true +function last_resort.cfgvalue(self, s) + local action = self.map:get(s, "last_resort") + if action == "blackhole" then + return translate("blackhole (drop)") + elseif action == "default" then + return translate("default (use main routing table)") + else + return translate("unreachable (reject)") end +end return m5 diff --git a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/policyconfig.lua b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/policyconfig.lua index 29bb3dcd88..1f8da0f2dd 100644 --- a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/policyconfig.lua +++ b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/policyconfig.lua @@ -6,8 +6,8 @@ m5 = Map("mwan3", translatef("MWAN Policy Configuration - %s", arg[1])) m5.redirect = dsp.build_url("admin", "network", "mwan", "policy") mwan_policy = m5:section(NamedSection, arg[1], "policy", "") - mwan_policy.addremove = false - mwan_policy.dynamic = false +mwan_policy.addremove = false +mwan_policy.dynamic = false member = mwan_policy:option(DynamicList, "use_member", translate("Member used")) m5.uci:foreach("mwan3", "member", @@ -18,9 +18,9 @@ m5.uci:foreach("mwan3", "member", last_resort = mwan_policy:option(ListValue, "last_resort", translate("Last resort"), translate("When all policy members are offline use this behavior for matched traffic")) - last_resort.default = "unreachable" - last_resort:value("unreachable", translate("unreachable (reject)")) - last_resort:value("blackhole", translate("blackhole (drop)")) - last_resort:value("default", translate("default (use main routing table)")) +last_resort.default = "unreachable" +last_resort:value("unreachable", translate("unreachable (reject)")) +last_resort:value("blackhole", translate("blackhole (drop)")) +last_resort:value("default", translate("default (use main routing table)")) return m5 diff --git a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/rule.lua b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/rule.lua index 5c6329e339..5b19693e66 100644 --- a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/rule.lua +++ b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/rule.lua @@ -47,54 +47,53 @@ mwan_rule = m5:section(TypedSection, "rule", nil, "Traffic matching a rule, but all WAN interfaces for that policy are down will be blackholed
" .. "Names may contain characters A-Z, a-z, 0-9, _ and no spaces
" .. "Rules may not share the same name as configured interfaces, members or policies")) - mwan_rule.addremove = true - mwan_rule.anonymous = false - mwan_rule.dynamic = false - mwan_rule.sectionhead = translate("Rule") - mwan_rule.sortable = true - mwan_rule.template = "cbi/tblsection" - mwan_rule.extedit = dsp.build_url("admin", "network", "mwan", "rule", "%s") - function mwan_rule.create(self, section) - TypedSection.create(self, section) - m5.uci:save("mwan3") - luci.http.redirect(dsp.build_url("admin", "network", "mwan", "rule", section)) - end - +mwan_rule.addremove = true +mwan_rule.anonymous = false +mwan_rule.dynamic = false +mwan_rule.sectionhead = translate("Rule") +mwan_rule.sortable = true +mwan_rule.template = "cbi/tblsection" +mwan_rule.extedit = dsp.build_url("admin", "network", "mwan", "rule", "%s") +function mwan_rule.create(self, section) + TypedSection.create(self, section) + m5.uci:save("mwan3") + luci.http.redirect(dsp.build_url("admin", "network", "mwan", "rule", section)) +end src_ip = mwan_rule:option(DummyValue, "src_ip", translate("Source address")) - src_ip.rawhtml = true - function src_ip.cfgvalue(self, s) - return self.map:get(s, "src_ip") or "—" - end +src_ip.rawhtml = true +function src_ip.cfgvalue(self, s) + return self.map:get(s, "src_ip") or "—" +end src_port = mwan_rule:option(DummyValue, "src_port", translate("Source port")) - src_port.rawhtml = true - function src_port.cfgvalue(self, s) - return self.map:get(s, "src_port") or "—" - end +src_port.rawhtml = true +function src_port.cfgvalue(self, s) + return self.map:get(s, "src_port") or "—" +end dest_ip = mwan_rule:option(DummyValue, "dest_ip", translate("Destination address")) - dest_ip.rawhtml = true - function dest_ip.cfgvalue(self, s) - return self.map:get(s, "dest_ip") or "—" - end +dest_ip.rawhtml = true +function dest_ip.cfgvalue(self, s) + return self.map:get(s, "dest_ip") or "—" +end dest_port = mwan_rule:option(DummyValue, "dest_port", translate("Destination port")) - dest_port.rawhtml = true - function dest_port.cfgvalue(self, s) - return self.map:get(s, "dest_port") or "—" - end +dest_port.rawhtml = true +function dest_port.cfgvalue(self, s) + return self.map:get(s, "dest_port") or "—" +end proto = mwan_rule:option(DummyValue, "proto", translate("Protocol")) - proto.rawhtml = true - function proto.cfgvalue(self, s) - return self.map:get(s, "proto") or "all" - end +proto.rawhtml = true +function proto.cfgvalue(self, s) + return self.map:get(s, "proto") or "all" +end use_policy = mwan_rule:option(DummyValue, "use_policy", translate("Policy assigned")) - use_policy.rawhtml = true - function use_policy.cfgvalue(self, s) - return self.map:get(s, "use_policy") or "—" - end +use_policy.rawhtml = true +function use_policy.cfgvalue(self, s) + return self.map:get(s, "use_policy") or "—" +end return m5 diff --git a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/ruleconfig.lua b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/ruleconfig.lua index e12639e33d..712ada03ed 100644 --- a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/ruleconfig.lua +++ b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/ruleconfig.lua @@ -6,43 +6,42 @@ m5 = Map("mwan3", translatef("MWAN Rule Configuration - %s", arg[1])) m5.redirect = dsp.build_url("admin", "network", "mwan", "rule") mwan_rule = m5:section(NamedSection, arg[1], "rule", "") - mwan_rule.addremove = false - mwan_rule.dynamic = false - +mwan_rule.addremove = false +mwan_rule.dynamic = false src_ip = mwan_rule:option(Value, "src_ip", translate("Source address"), translate("Supports CIDR notation (eg \"192.168.100.0/24\") without quotes")) - src_ip.datatype = ipaddr +src_ip.datatype = ipaddr src_port = mwan_rule:option(Value, "src_port", translate("Source port"), translate("May be entered as a single or multiple port(s) (eg \"22\" or \"80,443\") or as a portrange (eg \"1024:2048\") without quotes")) dest_ip = mwan_rule:option(Value, "dest_ip", translate("Destination address"), translate("Supports CIDR notation (eg \"192.168.100.0/24\") without quotes")) - dest_ip.datatype = ipaddr +dest_ip.datatype = ipaddr dest_port = mwan_rule:option(Value, "dest_port", translate("Destination port"), translate("May be entered as a single or multiple port(s) (eg \"22\" or \"80,443\") or as a portrange (eg \"1024:2048\") without quotes")) proto = mwan_rule:option(Value, "proto", translate("Protocol"), translate("View the content of /etc/protocols for protocol description")) - proto.default = "all" - proto.rmempty = false - proto:value("all") - proto:value("tcp") - proto:value("udp") - proto:value("icmp") - proto:value("esp") +proto.default = "all" +proto.rmempty = false +proto:value("all") +proto:value("tcp") +proto:value("udp") +proto:value("icmp") +proto:value("esp") sticky = mwan_rule:option(ListValue, "sticky", translate("Sticky"), translate("Traffic from the same source IP address that previously matched this rule within the sticky timeout period will use the same WAN interface")) - sticky.default = "0" - sticky:value("1", translate("Yes")) - sticky:value("0", translate("No")) +sticky.default = "0" +sticky:value("1", translate("Yes")) +sticky:value("0", translate("No")) timeout = mwan_rule:option(Value, "timeout", translate("Sticky timeout"), translate("Seconds. Acceptable values: 1-1000000. Defaults to 600 if not set")) - timeout.datatype = "range(1, 1000000)" +timeout.datatype = "range(1, 1000000)" ipset = mwan_rule:option(Value, "ipset", translate("IPset"), translate("Name of IPset rule. Requires IPset rule in /etc/dnsmasq.conf (eg \"ipset=/youtube.com/youtube\")")) -- cgit v1.2.3 From 5b92193978e037d646edf23559440f18bf66be2c Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Thu, 18 Jan 2018 13:11:03 +0100 Subject: luci-app-mwan3: refactoring diagnostics view and controller Signed-off-by: Florian Eckert --- .../luci-app-mwan3/luasrc/controller/mwan3.lua | 145 +++++++++++++-------- .../luasrc/view/mwan/status_diagnostics.htm | 105 +++++++-------- 2 files changed, 141 insertions(+), 109 deletions(-) diff --git a/applications/luci-app-mwan3/luasrc/controller/mwan3.lua b/applications/luci-app-mwan3/luasrc/controller/mwan3.lua index 5d4ddfbdaf..e7e8dc93c8 100644 --- a/applications/luci-app-mwan3/luasrc/controller/mwan3.lua +++ b/applications/luci-app-mwan3/luasrc/controller/mwan3.lua @@ -80,9 +80,10 @@ function detailedStatus() luci.http.write_json(mArray) end -function diagnosticsData(interface, tool, task) - function getInterfaceNumber() +function diagnosticsData(interface, task) + function getInterfaceNumber(interface) local number = 0 + local interfaceNumber uci.cursor():foreach("mwan3", "interface", function (section) number = number+1 @@ -91,71 +92,111 @@ function diagnosticsData(interface, tool, task) end end ) + return interfaceNumber end - local mArray = {} + function diag_command(cmd, addr) + if addr and addr:match("^[a-zA-Z0-9%-%.:_]+$") then + local util = io.popen(cmd % addr) + if util then + while true do + local ln = util:read("*l") + if not ln then break end + luci.http.write(ln) + luci.http.write("\n") + end + util:close() + end + return + end + end - local results = "" - local interfaceDevice = ut.trim(sys.exec("uci -q -p /var/state get network." .. interface .. ".ifname")) - if interfaceDevice ~= "" then - if tool == "ping" then - local gateway = ut.trim(sys.exec("route -n | awk '{if ($8 == \"" .. interfaceDevice .. "\" && $1 == \"0.0.0.0\" && $3 == \"0.0.0.0\") print $2}'")) - if gateway ~= "" then - if task == "gateway" then - local pingCommand = "ping -c 3 -W 2 -I " .. interfaceDevice .. " " .. gateway - results = pingCommand .. "\n\n" .. sys.exec(pingCommand) - else - local tracked = ut.trim(sys.exec("uci -q -p /var/state get mwan3." .. interface .. ".track_ip")) - if tracked ~= "" then - for z in tracked:gmatch("[^ ]+") do - local pingCommand = "ping -c 3 -W 2 -I " .. interfaceDevice .. " " .. z - results = results .. pingCommand .. "\n\n" .. sys.exec(pingCommand) .. "\n\n" - end - else - results = "No tracking IP addresses configured on " .. interface - end + function get_gateway(inteface) + local dump = require("luci.util").ubus("network.interface.%s" % interface, "status", {}) + local gateway + if dump then + local _, route + for _, route in ipairs(dump.route) do + if dump.route[_].target == "0.0.0.0" then + gateway = dump.route[_].nexthop end + end + end + return gateway + end + + local mArray = {} + local results = "" + local number = getInterfaceNumber(interface) + + local uci = uci.cursor(nil, "/var/state") + local device = uci:get("network", interface, "ifname") + + luci.http.prepare_content("text/plain") + if device ~= "" then + if task == "ping_gateway" then + local gateway = get_gateway(interface) + if gateway ~= nil then + diag_command("ping -c 5 -W 1 %q 2>&1", gateway) else - results = "No default gateway for " .. interface .. " found. Default route does not exist or is configured incorrectly" + luci.http.prepare_content("text/plain") + luci.http.write(string.format("No gateway for interface %s found.", interface)) end - elseif tool == "rulechk" then - getInterfaceNumber() - local rule1 = sys.exec(ip .. "rule | grep $(echo $((" .. interfaceNumber .. " + 1000)))") - local rule2 = sys.exec(ip .. "rule | grep $(echo $((" .. interfaceNumber .. " + 2000)))") - if rule1 ~= "" and rule2 ~= "" then - results = "All required interface IP rules found:\n\n" .. rule1 .. rule2 - elseif rule1 ~= "" or rule2 ~= "" then - results = "Missing 1 of the 2 required interface IP rules\n\n\nRules found:\n\n" .. rule1 .. rule2 + elseif task == "ping_trackips" then + local trackips = uci:get("mwan3", interface, "track_ip") + if #trackips > 0 then + for i in pairs(trackips) do + diag_command("ping -c 5 -W 1 %q 2>&1", trackips[i]) + end else - results = "Missing both of the required interface IP rules" + luci.http.write(string.format("No tracking Hosts for interface %s defined.", interface)) end - elseif tool == "routechk" then - getInterfaceNumber() - local routeTable = sys.exec(ip .. "route list table " .. interfaceNumber) - if routeTable ~= "" then - results = "Interface routing table " .. interfaceNumber .. " was found:\n\n" .. routeTable + elseif task == "check_rules" then + local number = getInterfaceNumber(interface) + local iif = 1000 + number + local fwmark = 2000 + number + local iif_rule = sys.exec(string.format("ip rule | grep %d", iif)) + local fwmark_rule = sys.exec(string.format("ip rule | grep %d", fwmark)) + if iif_rule ~= "" and fwmark_rule ~= "" then + luci.http.write(string.format("All required IP rules for interface %s found", interface)) + luci.http.write("\n") + luci.http.write(fwmark_rule) + luci.http.write(iif_rule) + elseif iif_rule == "" and fwmark_rule ~= "" then + luci.http.write(string.format("Only one IP rules for interface %s found", interface)) + luci.http.write("\n") + luci.http.write(fwmark_rule) + elseif iif_rule ~= "" and fwmark_rule == "" then + luci.http.write(string.format("Only one IP rules for interface %s found", interface)) + luci.http.write("\n") + luci.http.write(iif_rule) else - results = "Missing required interface routing table " .. interfaceNumber + luci.http.write(string.format("Missing both IP rules for interface %s", interface)) end - elseif tool == "hotplug" then - if task == "ifup" then - os.execute("/usr/sbin/mwan3 ifup " .. interface) - results = "Hotplug ifup sent to interface " .. interface .. "..." + elseif task == "check_routes" then + local number = getInterfaceNumber(interface) + local routeTable = sys.exec(string.format("ip route list table %s", number)) + if routeTable ~= "" then + luci.http.write(string.format("Routing table %s for interface %s found", number, interface)) + luci.http.write("\n") + luci.http.write(routeTable) else - os.execute("/usr/sbin/mwan3 ifdown " .. interface) - results = "Hotplug ifdown sent to interface " .. interface .. "..." + luci.http.write(string.format("Routing table %s for interface %s not found", number, interface)) end + elseif task == "hotplug_ifup" then + os.execute(string.format("/usr/sbin/mwan3 ifup %s", interface)) + luci.http.write(string.format("Hotplug ifup sent to interface %s", interface)) + elseif task == "hotplug_ifdown" then + os.execute(string.format("/usr/sbin/mwan3 ifdown %s", interface)) + luci.http.write(string.format("Hotplug ifdown sent to interface %s", interface)) + else + luci.http.write("Unknown task") end else - results = "Unable to perform diagnostic tests on " .. interface .. ". There is no physical or virtual device associated with this interface" - end - if results ~= "" then - results = ut.trim(results) - mArray.diagnostics = { results } + luci.http.write(string.format("Unable to perform diagnostic tests on %s.", interface)) + luci.http.write("\n") + luci.http.write("There is no physical or virtual device associated with this interface.") end - - luci.http.prepare_content("application/json") - luci.http.write_json(mArray) end function troubleshootingData() diff --git a/applications/luci-app-mwan3/luasrc/view/mwan/status_diagnostics.htm b/applications/luci-app-mwan3/luasrc/view/mwan/status_diagnostics.htm index f7a1ede2e4..7e1ef4106a 100644 --- a/applications/luci-app-mwan3/luasrc/view/mwan/status_diagnostics.htm +++ b/applications/luci-app-mwan3/luasrc/view/mwan/status_diagnostics.htm @@ -10,10 +10,11 @@ <% local uci = require "luci.model.uci" - interfaceNames = "" + local iface = {} + uci.cursor():foreach("mwan3", "interface", function (section) - interfaceNames = interfaceNames .. section[".name"] .. " " + table.insert(iface, section[".name"]) end ) %> @@ -22,74 +23,64 @@ -
-
- <%:MWAN Interface Diagnostics%> - -
- - - - - - -
-
+
+
+

<%:MWAN Status - Diagnostics%>

+ +
+
+ +
+ + +
+ +
+ + +
+ +
+ +
+
+
-
- - + <%+footer%> -- cgit v1.2.3 From 406564c7db61f5e80bc246554488d7b04566d4cb Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Thu, 18 Jan 2018 13:42:21 +0100 Subject: luci-app-mwan3: refactoring detail status view and controller Signed-off-by: Florian Eckert --- .../luci-app-mwan3/luasrc/controller/mwan3.lua | 15 +++++------ .../luasrc/view/mwan/status_detail.htm | 30 ++++++++-------------- 2 files changed, 16 insertions(+), 29 deletions(-) diff --git a/applications/luci-app-mwan3/luasrc/controller/mwan3.lua b/applications/luci-app-mwan3/luasrc/controller/mwan3.lua index e7e8dc93c8..69e72b7fdc 100644 --- a/applications/luci-app-mwan3/luasrc/controller/mwan3.lua +++ b/applications/luci-app-mwan3/luasrc/controller/mwan3.lua @@ -68,16 +68,13 @@ function mwan_Status() end function detailedStatus() - local mArray = {} - - -- detailed mwan status - local detailStatusInfo = ut.trim(sys.exec("/usr/sbin/mwan3 status")) - if detailStatusInfo ~= "" then - mArray.mwandetail = { detailStatusInfo } + local statusInfo = ut.trim(sys.exec("/usr/sbin/mwan3 status")) + luci.http.prepare_content("text/plain") + if statusInfo ~= "" then + luci.http.write(statusInfo) + else + luci.http.write("Unable to get status information") end - - luci.http.prepare_content("application/json") - luci.http.write_json(mArray) end function diagnosticsData(interface, task) diff --git a/applications/luci-app-mwan3/luasrc/view/mwan/status_detail.htm b/applications/luci-app-mwan3/luasrc/view/mwan/status_detail.htm index 0ff2824ed2..4cb65dd2b1 100644 --- a/applications/luci-app-mwan3/luasrc/view/mwan/status_detail.htm +++ b/applications/luci-app-mwan3/luasrc/view/mwan/status_detail.htm @@ -10,33 +10,23 @@ -
+
- <%:MWAN Detailed Status%> -
<%:Loading%><%:Collecting data...%>
+ <%:Collecting data...%> + + <%:Loading%> +
- - <%+footer%> -- cgit v1.2.3 From 24fe9b12792e687993b818687c17f0a4eaa1764a Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Thu, 18 Jan 2018 13:51:47 +0100 Subject: luci-app-mwan3: rename status tab names Signed-off-by: Florian Eckert --- applications/luci-app-mwan3/luasrc/view/mwan/status_detail.htm | 7 ++++--- .../luci-app-mwan3/luasrc/view/mwan/status_diagnostics.htm | 4 ++-- applications/luci-app-mwan3/luasrc/view/mwan/status_interface.htm | 6 +++--- .../luci-app-mwan3/luasrc/view/mwan/status_troubleshooting.htm | 4 ++-- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/applications/luci-app-mwan3/luasrc/view/mwan/status_detail.htm b/applications/luci-app-mwan3/luasrc/view/mwan/status_detail.htm index 4cb65dd2b1..708479cf84 100644 --- a/applications/luci-app-mwan3/luasrc/view/mwan/status_detail.htm +++ b/applications/luci-app-mwan3/luasrc/view/mwan/status_detail.htm @@ -1,8 +1,8 @@ <%+header%> @@ -20,7 +20,8 @@ ); //]]> -
+
+

<%:MWAN Status - Detail%>

<%:Collecting data...%> diff --git a/applications/luci-app-mwan3/luasrc/view/mwan/status_diagnostics.htm b/applications/luci-app-mwan3/luasrc/view/mwan/status_diagnostics.htm index 7e1ef4106a..d524e101eb 100644 --- a/applications/luci-app-mwan3/luasrc/view/mwan/status_diagnostics.htm +++ b/applications/luci-app-mwan3/luasrc/view/mwan/status_diagnostics.htm @@ -1,8 +1,8 @@ <%+header%> diff --git a/applications/luci-app-mwan3/luasrc/view/mwan/status_interface.htm b/applications/luci-app-mwan3/luasrc/view/mwan/status_interface.htm index e6cbb484cb..1c9123c709 100644 --- a/applications/luci-app-mwan3/luasrc/view/mwan/status_interface.htm +++ b/applications/luci-app-mwan3/luasrc/view/mwan/status_interface.htm @@ -1,8 +1,8 @@ <%+header%> @@ -58,7 +58,7 @@
- <%:MWAN Interface Live Status%> + <%:MWAN status - Interface Live Status%>
<%:Loading%><%:Collecting data...%>
diff --git a/applications/luci-app-mwan3/luasrc/view/mwan/status_troubleshooting.htm b/applications/luci-app-mwan3/luasrc/view/mwan/status_troubleshooting.htm index 483e289493..2ede35cef1 100644 --- a/applications/luci-app-mwan3/luasrc/view/mwan/status_troubleshooting.htm +++ b/applications/luci-app-mwan3/luasrc/view/mwan/status_troubleshooting.htm @@ -1,8 +1,8 @@ <%+header%> -- cgit v1.2.3 From 6a700eded1136d79ec8001415a88d324bebcc8f0 Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Thu, 18 Jan 2018 14:45:18 +0100 Subject: luci-app-mwan3: refactoring troubleshooting page Signed-off-by: Florian Eckert --- .../luci-app-mwan3/luasrc/controller/mwan3.lua | 182 ++++++++++----------- .../luasrc/view/mwan/status_troubleshooting.htm | 50 ++---- 2 files changed, 102 insertions(+), 130 deletions(-) diff --git a/applications/luci-app-mwan3/luasrc/controller/mwan3.lua b/applications/luci-app-mwan3/luasrc/controller/mwan3.lua index 69e72b7fdc..cf5708051f 100644 --- a/applications/luci-app-mwan3/luasrc/controller/mwan3.lua +++ b/applications/luci-app-mwan3/luasrc/controller/mwan3.lua @@ -198,104 +198,104 @@ end function troubleshootingData() local ver = require "luci.version" + local dash = "-------------------------------------------------" - local mArray = {} - - -- software versions - local wrtRelease = ut.trim(ver.distversion) - if wrtRelease ~= "" then - wrtRelease = "OpenWrt - " .. wrtRelease - else - wrtRelease = "OpenWrt - unknown" - end - local luciRelease = ut.trim(ver.luciversion) - if luciRelease ~= "" then - luciRelease = "\nLuCI - " .. luciRelease - else - luciRelease = "\nLuCI - unknown" - end - local mwanVersion = ut.trim(sys.exec("opkg info mwan3 | grep Version | awk '{print $2}'")) - if mwanVersion ~= "" then - mwanVersion = "\n\nmwan3 - " .. mwanVersion - else - mwanVersion = "\n\nmwan3 - unknown" - end - local mwanLuciVersion = ut.trim(sys.exec("opkg info luci-app-mwan3 | grep Version | awk '{print $2}'")) - if mwanLuciVersion ~= "" then - mwanLuciVersion = "\nmwan3-luci - " .. mwanLuciVersion - else - mwanLuciVersion = "\nmwan3-luci - unknown" - end - mArray.versions = { wrtRelease .. luciRelease .. mwanVersion .. mwanLuciVersion } - - -- mwan config - local mwanConfig = ut.trim(sys.exec("cat /etc/config/mwan3")) - if mwanConfig == "" then - mwanConfig = "No data found" - end - mArray.mwanconfig = { mwanConfig } - - -- network config - local networkConfig = ut.trim(sys.exec("cat /etc/config/network | sed -e 's/.*username.*/ USERNAME HIDDEN/' -e 's/.*password.*/ PASSWORD HIDDEN/'")) - if networkConfig == "" then - networkConfig = "No data found" - end - mArray.netconfig = { networkConfig } + luci.http.prepare_content("text/plain") - -- wireless config - local wirelessConfig = ut.trim(sys.exec("cat /etc/config/wireless | sed -e 's/.*username.*/ USERNAME HIDDEN/' -e 's/.*password.*/ PASSWORD HIDDEN/' -e 's/.*key.*/ KEY HIDDEN/'")) - if wirelessConfig == "" then - wirelessConfig = "No data found" - end - mArray.wificonfig = { wirelessConfig } - - -- ifconfig - local ifconfig = ut.trim(sys.exec("ifconfig")) - if ifconfig == "" then - ifconfig = "No data found" - end - mArray.ifconfig = { ifconfig } + luci.http.write("\n") + luci.http.write("\n") + luci.http.write("Software-Version") + luci.http.write("\n") + luci.http.write(dash) + luci.http.write("\n") + if ver.distversion then + luci.http.write(string.format("OpenWrt - %s", ver.distversion)) + luci.http.write("\n") + else + luci.http.write("OpenWrt - unknown") + luci.http.write("\n") + end - -- route -n - local routeShow = ut.trim(sys.exec("route -n")) - if routeShow == "" then - routeShow = "No data found" - end - mArray.routeshow = { routeShow } + if ver.luciversion then + luci.http.write(string.format("LuCI - %s", ver.luciversion)) + luci.http.write("\n") + else + luci.http.write("LuCI - unknown") + luci.http.write("\n") + end - -- ip rule show - local ipRuleShow = ut.trim(sys.exec(ip .. "rule show")) - if ipRuleShow == "" then - ipRuleShow = "No data found" - end - mArray.iprule = { ipRuleShow } + luci.http.write("\n") + luci.http.write("\n") + local output = ut.trim(sys.exec("ip a show")) + luci.http.write("Output of \"ip a show\"") + luci.http.write("\n") + luci.http.write(dash) + luci.http.write("\n") + if output ~= "" then + luci.http.write(output) + luci.http.write("\n") + else + luci.http.write("No data found") + luci.http.write("\n") + end - -- ip route list table 1-250 - local routeList, routeString = ut.trim(sys.exec(ip .. "rule | sed 's/://g' 2>/dev/null | awk '$1>=2001 && $1<=2250' | awk '{print $NF}'")), "" - if routeList ~= "" then - for line in routeList:gmatch("[^\r\n]+") do - routeString = routeString .. line .. "\n" .. sys.exec(ip .. "route list table " .. line) - end - routeString = ut.trim(routeString) - else - routeString = "No data found" - end - mArray.routelist = { routeString } + luci.http.write("\n") + luci.http.write("\n") + local output = ut.trim(sys.exec("ip route show")) + luci.http.write("Output of \"ip route show\"") + luci.http.write("\n") + luci.http.write(dash) + luci.http.write("\n") + if output ~= "" then + luci.http.write(output) + luci.http.write("\n") + else + luci.http.write("No data found") + luci.http.write("\n") + end - -- default firewall output policy - local firewallOut = ut.trim(sys.exec("uci -q -p /var/state get firewall.@defaults[0].output")) - if firewallOut == "" then - firewallOut = "No data found" - end - mArray.firewallout = { firewallOut } + luci.http.write("\n") + luci.http.write("\n") + local output = ut.trim(sys.exec("ip rule show")) + luci.http.write("Output of \"ip rule show\"") + luci.http.write("\n") + luci.http.write(dash) + luci.http.write("\n") + if output ~= "" then + luci.http.write(output) + luci.http.write("\n") + else + luci.http.write("No data found") + luci.http.write("\n") + end - -- iptables - local iptables = ut.trim(sys.exec("iptables -L -t mangle -v -n")) - if iptables == "" then - iptables = "No data found" + luci.http.write("\n") + luci.http.write("\n") + luci.http.write("Output of \"ip route list table 1-250\"") + luci.http.write("\n") + luci.http.write(dash) + luci.http.write("\n") + for i=1,250 do + local output = ut.trim(sys.exec(string.format("ip route list table %d", i))) + if output ~= "" then + luci.http.write(string.format("Table %s: ", i)) + luci.http.write(output) + luci.http.write("\n") end - mArray.iptables = { iptables } + end - luci.http.prepare_content("application/json") - luci.http.write_json(mArray) + luci.http.write("\n") + luci.http.write("\n") + local output = ut.trim(sys.exec("iptables -L -t mangle -v -n")) + luci.http.write("Output of \"iptables -L -t mangle -v -n\"") + luci.http.write("\n") + luci.http.write(dash) + luci.http.write("\n") + if output ~= "" then + luci.http.write(output) + luci.http.write("\n") + else + luci.http.write("No data found") + luci.http.write("\n") + end end diff --git a/applications/luci-app-mwan3/luasrc/view/mwan/status_troubleshooting.htm b/applications/luci-app-mwan3/luasrc/view/mwan/status_troubleshooting.htm index 2ede35cef1..348bf947fb 100644 --- a/applications/luci-app-mwan3/luasrc/view/mwan/status_troubleshooting.htm +++ b/applications/luci-app-mwan3/luasrc/view/mwan/status_troubleshooting.htm @@ -10,52 +10,24 @@ -
+
+

<%:MWAN Status - Troubleshooting%>

- <%:Troubleshooting Data%> -
<%:Loading%><%:Collecting data...%>
+ <%:Collecting data...%> + + <%:Loading%> +
- - <%+footer%> -- cgit v1.2.3