summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-app-mwan3/luasrc/model
diff options
context:
space:
mode:
Diffstat (limited to 'applications/luci-app-mwan3/luasrc/model')
-rw-r--r--applications/luci-app-mwan3/luasrc/model/cbi/mwan/globalsconfig.lua8
-rw-r--r--applications/luci-app-mwan3/luasrc/model/cbi/mwan/interface.lua394
-rw-r--r--applications/luci-app-mwan3/luasrc/model/cbi/mwan/interfaceconfig.lua337
-rw-r--r--applications/luci-app-mwan3/luasrc/model/cbi/mwan/member.lua58
-rw-r--r--applications/luci-app-mwan3/luasrc/model/cbi/mwan/memberconfig.lua40
-rw-r--r--applications/luci-app-mwan3/luasrc/model/cbi/mwan/notify.lua7
-rw-r--r--applications/luci-app-mwan3/luasrc/model/cbi/mwan/policy.lua120
-rw-r--r--applications/luci-app-mwan3/luasrc/model/cbi/mwan/policyconfig.lua67
-rw-r--r--applications/luci-app-mwan3/luasrc/model/cbi/mwan/rule.lua182
-rw-r--r--applications/luci-app-mwan3/luasrc/model/cbi/mwan/ruleconfig.lua108
10 files changed, 496 insertions, 825 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..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")
-s = m:section(NamedSection, "globals", "globals", translate("Globals mwan3 options"))
+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 77198d5c39..166f077910 100644
--- a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/interface.lua
+++ b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/interface.lua
@@ -1,276 +1,208 @@
--- ------ extra functions ------ --
+dsp = require "luci.dispatcher"
-function interfaceCheck() -- find issues with too many interfaces, reliability and metric
- uci.cursor():foreach("mwan3", "interface",
- function (section)
- local interfaceName = section[".name"]
- interfaceNumber = interfaceNumber+1 -- count number of mwan interfaces configured
- -- create list of metrics for none and duplicate checking
- local metricValue = ut.trim(sys.exec("uci -p /var/state get network." .. interfaceName .. ".metric"))
- if metricValue == "" then
- errorFound = 1
- errorNoMetricList = errorNoMetricList .. interfaceName .. " "
- else
- metricList = metricList .. interfaceName .. " " .. metricValue .. "\n"
- end
- -- check if any interfaces have a higher reliability requirement than tracking IPs configured
- local trackingNumber = tonumber(ut.trim(sys.exec("echo $(uci -p /var/state get mwan3." .. interfaceName .. ".track_ip) | wc -w")))
- if trackingNumber > 0 then
- local reliabilityNumber = tonumber(ut.trim(sys.exec("uci -p /var/state get mwan3." .. interfaceName .. ".reliability")))
- if reliabilityNumber and reliabilityNumber > trackingNumber then
- errorFound = 1
- errorReliabilityList = errorReliabilityList .. interfaceName .. " "
- end
- end
- -- check if any interfaces are not properly configured in /etc/config/network or have no default route in main routing table
- if ut.trim(sys.exec("uci -p /var/state get network." .. interfaceName)) == "interface" then
- local interfaceDevice = ut.trim(sys.exec("uci -p /var/state get network." .. interfaceName .. ".ifname"))
- if interfaceDevice == "uci: Entry not found" or interfaceDevice == "" then
- errorFound = 1
- errorNetConfigList = errorNetConfigList .. interfaceName .. " "
- errorRouteList = errorRouteList .. interfaceName .. " "
- else
- local routeCheck = ut.trim(sys.exec("route -n | awk '{if ($8 == \"" .. interfaceDevice .. "\" && $1 == \"0.0.0.0\" && $3 == \"0.0.0.0\") print $1}'"))
- if routeCheck == "" then
- errorFound = 1
- errorRouteList = errorRouteList .. interfaceName .. " "
- end
- end
- else
- errorFound = 1
- errorNetConfigList = errorNetConfigList .. interfaceName .. " "
- errorRouteList = errorRouteList .. interfaceName .. " "
- end
- end
- )
- -- check if any interfaces have duplicate metrics
- local metricDuplicateNumbers = sys.exec("echo '" .. metricList .. "' | awk '{print $2}' | uniq -d")
- if metricDuplicateNumbers ~= "" then
- errorFound = 1
- local metricDuplicates = ""
- for line in metricDuplicateNumbers:gmatch("[^\r\n]+") do
- metricDuplicates = sys.exec("echo '" .. metricList .. "' | grep '" .. line .. "' | awk '{print $1}'")
- errorDuplicateMetricList = errorDuplicateMetricList .. metricDuplicates
- end
- errorDuplicateMetricList = sys.exec("echo '" .. errorDuplicateMetricList .. "' | tr '\n' ' '")
- end
-end
-function interfaceWarnings() -- display status and warning messages at the top of the page
+function interfaceWarnings(overview, count)
local warnings = ""
- if interfaceNumber <= 250 then
- warnings = "<strong>" .. translatef("There are currently %d of 250 supported interfaces configured", interfaceNumber) .. "</strong>"
+ if count <= 250 then
+ warnings = string.format("<strong>%s</strong></br>",
+ translatef("There are currently %d of 250 supported interfaces configured", count)
+ )
else
- warnings = "<font color=\"ff0000\"><strong>" .. translatef("WARNING: %d interfaces are configured exceeding the maximum of 250!", interfaceNumber) .. "</strong></font>"
+ warnings = string.format("<strong>%s</strong></br>",
+ translatef("WARNING: %d interfaces are configured exceeding the maximum of 250!", count)
+ )
end
- if errorReliabilityList ~= " " then
- warnings = warnings .. "<br /><br /><font color=\"ff0000\"><strong>" .. translate("WARNING: Some interfaces have a higher reliability requirement than there are tracking IP addresses!") .. "</strong></font>"
- end
- if errorRouteList ~= " " then
- warnings = warnings .. "<br /><br /><font color=\"ff0000\"><strong>" .. translate("WARNING: Some interfaces have no default route in the main routing table!") .. "</strong></font>"
- end
- if errorNetConfigList ~= " " then
- warnings = warnings .. "<br /><br /><font color=\"ff0000\"><strong>" .. translate("WARNING: Some interfaces are configured incorrectly or not at all in /etc/config/network!") .. "</strong></font>"
- end
- if errorNoMetricList ~= " " then
- warnings = warnings .. "<br /><br /><font color=\"ff0000\"><strong>" .. translate("WARNING: Some interfaces have no metric configured in /etc/config/network!") .. "</strong></font>"
- end
- if errorDuplicateMetricList ~= " " then
- warnings = warnings .. "<br /><br /><font color=\"ff0000\"><strong>" .. translate("WARNING: Some interfaces have duplicate metrics configured in /etc/config/network!") .. "</strong></font>"
+
+ for i, k in pairs(overview) do
+ if overview[i]["network"] == false then
+ warnings = warnings .. string.format("<strong>%s</strong></br>",
+ translatef("WARNING: Interface %s are not found in /etc/config/network", i)
+ )
+ end
+
+ if overview[i]["default_route"] == false then
+ warnings = warnings .. string.format("<strong>%s</strong></br>",
+ translatef("WARNING: Interface %s has no default route in the main routing table", i)
+ )
+ end
+
+ if overview[i]["reliability"] == false then
+ warnings = warnings .. string.format("<strong>%s</strong></br>",
+ translatef("WARNING: Interface %s has a higher reliability " ..
+ "requirement than tracking hosts (%d)", i, overview[i]["tracking"])
+ )
+ end
+
+ if overview[i]["duplicate_metric"] == true then
+ warnings = warnings .. string.format("<strong>%s</strong></br>",
+ translatef("WARNING: Interface %s has a duplicate metric %s configured", i, overview[i]["metric"])
+ )
+ end
end
+
return warnings
end
--- ------ interface configuration ------ --
-
-dsp = require "luci.dispatcher"
-sys = require "luci.sys"
-ut = require "luci.util"
+function configCheck()
+ local overview = {}
+ local count = 0
+ local duplicate_metric = {}
+ uci.cursor():foreach("mwan3", "interface",
+ function (section)
+ local uci = uci.cursor(nil, "/var/state")
+ local iface = section[".name"]
+ overview[iface] = {}
+ count = count + 1
+ local network = uci:get("network", iface)
+ overview[iface]["network"] = false
+ if network ~= nil then
+ overview[iface]["network"] = true
+
+ local device = uci:get("network", iface, "ifname")
+ if device ~= nil then
+ overview[iface]["device"] = device
+ end
-interfaceNumber = 0
-metricList = ""
-errorFound = 0
-errorDuplicateMetricList = " "
-errorNetConfigList = " "
-errorNoMetricList = " "
-errorReliabilityList = " "
-errorRouteList = " "
-interfaceCheck()
+ local metric = uci:get("network", iface, "metric")
+ if metric ~= nil then
+ overview[iface]["metric"] = metric
+ overview[iface]["duplicate_metric"] = false
+ for _, m in ipairs(duplicate_metric) do
+ if m == metric then
+ overview[iface]["duplicate_metric"] = true
+ end
+ end
+ table.insert(duplicate_metric, metric)
+ end
+ local dump = require("luci.util").ubus("network.interface.%s" % iface, "status", {})
+ overview[iface]["default_route"] = false
+ if dump then
+ local _, route
+ for _, route in ipairs(dump.route) do
+ if dump.route[_].target == "0.0.0.0" then
+ overview[iface]["default_route"] = true
+ end
+ end
+ end
+ end
-m5 = Map("mwan3", translate("MWAN Interface Configuration"),
- interfaceWarnings())
- m5:append(Template("mwan/config_css"))
+ local trackingNumber = uci:get("mwan3", iface, "track_ip")
+ overview[iface]["tracking"] = 0
+ if #trackingNumber > 0 then
+ overview[iface]["tracking"] = #trackingNumber
+ overview[iface]["reliability"] = false
+ local reliabilityNumber = tonumber(uci:get("mwan3", iface, "reliability"))
+ if reliabilityNumber and reliabilityNumber <= #trackingNumber then
+ overview[iface]["reliability"] = true
+ end
+ end
+ end
+ )
+ return overview, count
+end
+m5 = Map("mwan3", translate("MWAN - Interfaces"),
+ interfaceWarnings(configCheck()))
-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<br />" ..
"MWAN requires that all interfaces have a unique metric configured in /etc/config/network<br />" ..
"Names must match the interface name found in /etc/config/network (see advanced tab)<br />" ..
"Names may contain characters A-Z, a-z, 0-9, _ and no spaces<br />" ..
"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 "Yes"
- else
- return "No"
- end
- end
-
-track_ip = mwan_interface:option(DummyValue, "track_ip", translate("Tracking IP"))
- track_ip.rawhtml = true
- function track_ip.cfgvalue(self, s)
- tracked = self.map:get(s, "track_ip")
- if tracked then
- local ipList = ""
- for k,v in pairs(tracked) do
- ipList = ipList .. v .. "<br />"
- end
- return ipList
- else
- return "&#8212;"
- 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)
- if tracked then
- return self.map:get(s, "track_method") or "&#8212;"
- else
- return "&#8212;"
- 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 "&#8212;"
+ else
+ return "&#8212;"
end
+end
reliability = mwan_interface:option(DummyValue, "reliability", translate("Tracking reliability"))
- reliability.rawhtml = true
- function reliability.cfgvalue(self, s)
- if tracked then
- return self.map:get(s, "reliability") or "&#8212;"
- else
- return "&#8212;"
- end
- end
-
-count = mwan_interface:option(DummyValue, "count", translate("Ping count"))
- count.rawhtml = true
- function count.cfgvalue(self, s)
- if tracked then
- return self.map:get(s, "count") or "&#8212;"
- else
- return "&#8212;"
- end
- end
-
-timeout = mwan_interface:option(DummyValue, "timeout", translate("Ping timeout"))
- timeout.rawhtml = true
- function timeout.cfgvalue(self, s)
- if tracked then
- local timeoutValue = self.map:get(s, "timeout")
- if timeoutValue then
- return timeoutValue .. "s"
- else
- return "&#8212;"
- end
- else
- return "&#8212;"
- 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 "&#8212;"
+ else
+ return "&#8212;"
end
+end
interval = mwan_interface:option(DummyValue, "interval", translate("Ping interval"))
- interval.rawhtml = true
- function interval.cfgvalue(self, s)
- if tracked then
- local intervalValue = self.map:get(s, "interval")
- if intervalValue then
- return intervalValue .. "s"
- else
- return "&#8212;"
- 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 "&#8212;"
end
+ else
+ return "&#8212;"
end
+end
down = mwan_interface:option(DummyValue, "down", translate("Interface down"))
- down.rawhtml = true
- function down.cfgvalue(self, s)
- if tracked then
- return self.map:get(s, "down") or "&#8212;"
- else
- return "&#8212;"
- 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 "&#8212;"
+ else
+ return "&#8212;"
end
+end
up = mwan_interface:option(DummyValue, "up", translate("Interface up"))
- up.rawhtml = true
- function up.cfgvalue(self, s)
- if tracked then
- return self.map:get(s, "up") or "&#8212;"
- else
- return "&#8212;"
- 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 "&#8212;"
+ else
+ return "&#8212;"
end
+end
metric = mwan_interface:option(DummyValue, "metric", translate("Metric"))
- metric.rawhtml = true
- function metric.cfgvalue(self, s)
- local metricValue = sys.exec("uci -p /var/state get network." .. s .. ".metric")
- if metricValue ~= "" then
- return metricValue
- else
- return "&#8212;"
- end
- end
-
-errors = mwan_interface:option(DummyValue, "errors", translate("Errors"))
- errors.rawhtml = true
- function errors.cfgvalue(self, s)
- if errorFound == 1 then
- local mouseOver, lineBreak = "", ""
- if string.find(errorReliabilityList, " " .. s .. " ") then
- mouseOver = "Higher reliability requirement than there are tracking IP addresses"
- lineBreak = "&#10;&#10;"
- end
- if string.find(errorRouteList, " " .. s .. " ") then
- mouseOver = mouseOver .. lineBreak .. "No default route in the main routing table"
- lineBreak = "&#10;&#10;"
- end
- if string.find(errorNetConfigList, " " .. s .. " ") then
- mouseOver = mouseOver .. lineBreak .. "Configured incorrectly or not at all in /etc/config/network"
- lineBreak = "&#10;&#10;"
- end
- if string.find(errorNoMetricList, " " .. s .. " ") then
- mouseOver = mouseOver .. lineBreak .. "No metric configured in /etc/config/network"
- lineBreak = "&#10;&#10;"
- end
- if string.find(errorDuplicateMetricList, " " .. s .. " ") then
- mouseOver = mouseOver .. lineBreak .. "Duplicate metric configured in /etc/config/network"
- end
- if mouseOver == "" then
- return ""
- else
- return "<span title=\"" .. mouseOver .. "\"><img src=\"/luci-static/resources/cbi/reset.gif\" alt=\"error\"></img></span>"
- end
- 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 "&#8212;"
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 86e959771e..9f1db08be7 100644
--- a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/interfaceconfig.lua
+++ b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/interfaceconfig.lua
@@ -1,266 +1,179 @@
--- ------ extra functions ------ --
-
-function interfaceCheck()
- metricValue = ut.trim(sys.exec("uci -p /var/state get network." .. arg[1] .. ".metric"))
- if metricValue == "" then -- no metric
- errorNoMetric = 1
- else -- if metric exists create list of interface metrics to compare against for duplicates
- uci.cursor():foreach("mwan3", "interface",
- function (section)
- local metricValue = ut.trim(sys.exec("uci -p /var/state get network." .. section[".name"] .. ".metric"))
- metricList = metricList .. section[".name"] .. " " .. metricValue .. "\n"
- end
- )
- -- compare metric against list
- local metricDuplicateNumbers, metricDuplicates = sys.exec("echo '" .. metricList .. "' | awk '{print $2}' | uniq -d"), ""
- for line in metricDuplicateNumbers:gmatch("[^\r\n]+") do
- metricDuplicates = sys.exec("echo '" .. metricList .. "' | grep '" .. line .. "' | awk '{print $1}'")
- errorDuplicateMetricList = errorDuplicateMetricList .. metricDuplicates
- end
- if sys.exec("echo '" .. errorDuplicateMetricList .. "' | grep -w " .. arg[1]) ~= "" then
- errorDuplicateMetric = 1
- end
- end
- -- check if this interface has a higher reliability requirement than track IPs configured
- local trackingNumber = tonumber(ut.trim(sys.exec("echo $(uci -p /var/state get mwan3." .. arg[1] .. ".track_ip) | wc -w")))
- if trackingNumber > 0 then
- local reliabilityNumber = tonumber(ut.trim(sys.exec("uci -p /var/state get mwan3." .. arg[1] .. ".reliability")))
- if reliabilityNumber and reliabilityNumber > trackingNumber then
- errorReliability = 1
- end
- end
- -- check if any interfaces are not properly configured in /etc/config/network or have no default route in main routing table
- if ut.trim(sys.exec("uci -p /var/state get network." .. arg[1])) == "interface" then
- local interfaceDevice = ut.trim(sys.exec("uci -p /var/state get network." .. arg[1] .. ".ifname"))
- if interfaceDevice == "uci: Entry not found" or interfaceDevice == "" then
- errorNetConfig = 1
- errorRoute = 1
- else
- local routeCheck = ut.trim(sys.exec("route -n | awk '{if ($8 == \"" .. interfaceDevice .. "\" && $1 == \"0.0.0.0\" && $3 == \"0.0.0.0\") print $1}'"))
- if routeCheck == "" then
- errorRoute = 1
- end
- end
- else
- errorNetConfig = 1
- errorRoute = 1
- end
-end
-
-function interfaceWarnings() -- display warning messages at the top of the page
- local warns, lineBreak = "", ""
- if errorReliability == 1 then
- warns = "<font color=\"ff0000\"><strong>" .. translate("WARNING: This interface has a higher reliability requirement than there are tracking IP addresses!") .. "</strong></font>"
- lineBreak = "<br /><br />"
- end
- if errorRoute == 1 then
- warns = warns .. lineBreak .. "<font color=\"ff0000\"><strong>" .. translate("WARNING: This interface has no default route in the main routing table!") .. "</strong></font>"
- lineBreak = "<br /><br />"
- end
- if errorNetConfig == 1 then
- warns = warns .. lineBreak .. "<font color=\"ff0000\"><strong>" .. translate("WARNING: This interface is configured incorrectly or not at all in /etc/config/network!") .. "</strong></font>"
- lineBreak = "<br /><br />"
- end
- if errorNoMetric == 1 then
- warns = warns .. lineBreak .. "<font color=\"ff0000\"><strong>" .. translate("WARNING: This interface has no metric configured in /etc/config/network!") .. "</strong></font>"
- elseif errorDuplicateMetric == 1 then
- warns = warns .. lineBreak .. "<font color=\"ff0000\"><strong>" .. translate("WARNING: This and other interfaces have duplicate metrics configured in /etc/config/network!") .. "</strong></font>"
- end
- return warns
-end
-
--- ------ interface configuration ------ --
-
dsp = require "luci.dispatcher"
-sys = require "luci.sys"
-ut = require "luci.util"
arg[1] = arg[1] or ""
-metricValue = ""
-metricList = ""
-errorDuplicateMetricList = ""
-errorNoMetric = 0
-errorDuplicateMetric = 0
-errorRoute = 0
-errorNetConfig = 0
-errorReliability = 0
-interfaceCheck()
-
-m5 = Map("mwan3", translatef("MWAN Interface Configuration - %s", arg[1]),
- interfaceWarnings())
+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)
- if errorNoMetric == 0 then
- return metricValue
- else
- return "&#8212;"
- 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 "&#8212;"
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 b73ee57652..ebe1162c55 100644
--- a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/member.lua
+++ b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/member.lua
@@ -1,46 +1,40 @@
--- ------ member configuration ------ --
+dsp = require "luci.dispatcher"
-ds = require "luci.dispatcher"
+m5 = Map("mwan3", translate("MWAN - Members"))
-m5 = Map("mwan3", translate("MWAN Member Configuration"))
- 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<br />" ..
"Names may contain characters A-Z, a-z, 0-9, _ and no spaces<br />" ..
"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 = ds.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))
- 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 "&#8212;"
- end
+interface.rawhtml = true
+function interface.cfgvalue(self, s)
+ return self.map:get(s, "interface") or "&#8212;"
+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 220c4bddd6..ade357f819 100644
--- a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/memberconfig.lua
+++ b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/memberconfig.lua
@@ -1,47 +1,27 @@
--- ------ 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
-
+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"))
- 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)"
-
-
--- ------ currently configured interfaces ------ --
-
-mwan_interface = m5:section(TypedSection, "interface", translate("Currently Configured Interfaces"))
- mwan_interface.addremove = false
- mwan_interface.dynamic = false
- mwan_interface.sortable = false
- mwan_interface.template = "cbi/tblsection"
-
+weight.datatype = "range(1, 1000)"
return m5
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..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,12 +1,11 @@
--- ------ hotplug script configuration ------ --
-
local fs = require "nixio.fs"
local ut = require "luci.util"
script = "/etc/mwan3.user"
-m5 = SimpleForm("luci", nil)
-f = m5:section(SimpleSection, translate("MWAN Notification"),
+m5 = SimpleForm("luci", translate("MWAN - Notification"))
+
+f = m5:section(SimpleSection, nil,
translate("This section allows you to modify the content of \"/etc/mwan3.user\".<br />" ..
"The file is also preserved during sysupgrade.<br />" ..
"<br />" ..
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..6d2ce71300 100644
--- a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/policy.lua
+++ b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/policy.lua
@@ -1,94 +1,80 @@
--- ------ extra functions ------ --
+dsp = require "luci.dispatcher"
+
+
+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 "<font color=\"ff0000\"><strong>" .. translate("WARNING: Some policies have names exceeding the maximum of 15 characters!") .. "</strong></font>"
- 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("<strong>%s</strong></br>",
+ translatef("WARNING: Policie %s has exceeding the maximum name of 15 characters", i)
+ )
+ end
+ end
-m5 = Map("mwan3", translate("MWAN Policy Configuration"),
- policyWarn())
- m5:append(Template("mwan/config_css"))
+ return warnings
+end
+m5 = Map("mwan3", translate("MWAN - Policies"),
+ policyError(policyCheck()))
-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<br />" ..
"Member interfaces with lower metrics are used first. Interfaces with the same metric load-balance<br />" ..
"Load-balanced member interfaces distribute more traffic out those with higher weights<br />" ..
"Names may contain characters A-Z, a-z, 0-9, _ and no spaces. Names must be 15 characters or less<br />" ..
"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 = ds.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))
- 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 .. "<br />"
- end
- return memberList
- else
- return "&#8212;"
+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 .. "<br />"
end
+ return memberList
+ else
+ return "&#8212;"
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
- 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 "<span title=\"Name exceeds 15 characters\"><img src=\"/luci-static/resources/cbi/reset.gif\" alt=\"error\"></img></span>"
- 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 cdf6521a79..1f8da0f2dd 100644
--- a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/policyconfig.lua
+++ b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/policyconfig.lua
@@ -1,65 +1,26 @@
--- ------ 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 "<font color=\"ff0000\"><strong>" .. translatef("WARNING: This policy's name is %d characters exceeding the maximum of 15!", policyNameLength) .. "</strong></font>"
- 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
-
+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"))
- 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)"))
-
-
--- ------ currently configured members ------ --
-
-mwan_member = m5:section(TypedSection, "member", translate("Currently Configured Members"))
- mwan_member.addremove = false
- mwan_member.dynamic = false
- mwan_member.sortable = false
- mwan_member.template = "cbi/tblsection"
-
+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 586f174b28..5b19693e66 100644
--- a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/rule.lua
+++ b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/rule.lua
@@ -1,141 +1,99 @@
--- ------ extra functions ------ --
+dsp = require "luci.dispatcher"
+
-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 "<font color=\"ff0000\"><strong>" .. translate("WARNING: Some rules have a port configured with no or improper protocol specified! Please configure a specific protocol!") .. "</strong></font>"
- 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("<strong>%s</strong></br>",
+ 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()
-
-
-m5 = Map("mwan3", translate("MWAN Rule Configuration"),
- ruleWarn())
- m5:append(Template("mwan/config_css"))
+ return warnings
+end
+m5 = Map("mwan3", translate("MWAN - Rules"),
+ ruleWarn(ruleCheck())
+ )
-mwan_rule = m5:section(TypedSection, "rule", translate("Traffic Rules"),
- translate("Rules specify which traffic will use a particular MWAN policy based on IP address, port or protocol<br />" ..
- "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<br />" ..
- "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<br />" ..
+mwan_rule = m5:section(TypedSection, "rule", nil,
+ translate("Rules specify which traffic will use a particular MWAN policy<br />" ..
+ "Rules are based on IP address, port or protocol<br />" ..
+ "Rules are matched from top to bottom<br />" ..
+ "Rules below a matching rule are ignored<br />" ..
+ "Traffic not matching any rule is routed using the main routing table<br />" ..
+ "Traffic destined for known (other than default) networks is handled by the main routing table<br />" ..
+ "Traffic matching a rule, but all WAN interfaces for that policy are down will be blackholed<br />" ..
"Names may contain characters A-Z, a-z, 0-9, _ and no spaces<br />" ..
"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 "&#8212;"
- end
+src_ip.rawhtml = true
+function src_ip.cfgvalue(self, s)
+ return self.map:get(s, "src_ip") or "&#8212;"
+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 "&#8212;"
- end
+src_port.rawhtml = true
+function src_port.cfgvalue(self, s)
+ return self.map:get(s, "src_port") or "&#8212;"
+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 "&#8212;"
- end
+dest_ip.rawhtml = true
+function dest_ip.cfgvalue(self, s)
+ return self.map:get(s, "dest_ip") or "&#8212;"
+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 "&#8212;"
- end
+dest_port.rawhtml = true
+function dest_port.cfgvalue(self, s)
+ return self.map:get(s, "dest_port") or "&#8212;"
+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
-
-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 "&#8212;"
- 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 "&#8212;"
- 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 "&#8212;"
- 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 "<span title=\"" .. translate("No protocol specified") .. "\"><img src=\"/luci-static/resources/cbi/reset.gif\" alt=\"error\"></img></span>"
- end
- end
-
+use_policy.rawhtml = true
+function use_policy.cfgvalue(self, s)
+ return self.map:get(s, "use_policy") or "&#8212;"
+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 87c4691af4..712ada03ed 100644
--- a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/ruleconfig.lua
+++ b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/ruleconfig.lua
@@ -1,113 +1,59 @@
--- ------ 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 "<font color=\"ff0000\"><strong>" .. translate("WARNING: This rule is incorrectly configured with no or improper protocol specified! Please configure a specific protocol!") .. "</strong></font>"
- else
- return ""
- end
-end
-
-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
-
--- ------ 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", "")
- 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 contents of /etc/protocols for protocol descriptions"))
- 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)
+ 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")
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\")"))
-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)"))
-
-
--- ------ currently configured policies ------ --
-
-mwan_policy = m5:section(TypedSection, "policy", translate("Currently Configured Policies"))
- mwan_policy.addremove = false
- mwan_policy.dynamic = false
- mwan_policy.sortable = false
- mwan_policy.template = "cbi/tblsection"
-
+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