2018-01-17 13:37:14 +00:00
|
|
|
dsp = require "luci.dispatcher"
|
2018-01-18 06:26:27 +00:00
|
|
|
|
2017-02-17 10:22:01 +00:00
|
|
|
|
2018-01-17 13:37:14 +00:00
|
|
|
function interfaceWarnings(overview, count)
|
2017-02-17 10:22:01 +00:00
|
|
|
local warnings = ""
|
2018-01-17 13:37:14 +00:00
|
|
|
if count <= 250 then
|
|
|
|
warnings = string.format("<strong>%s</strong></br>",
|
|
|
|
translatef("There are currently %d of 250 supported interfaces configured", count)
|
|
|
|
)
|
2017-02-17 10:22:01 +00:00
|
|
|
else
|
2018-01-17 13:37:14 +00:00
|
|
|
warnings = string.format("<strong>%s</strong></br>",
|
|
|
|
translatef("WARNING: %d interfaces are configured exceeding the maximum of 250!", count)
|
|
|
|
)
|
2017-02-17 10:22:01 +00:00
|
|
|
end
|
2018-01-17 13:37:14 +00:00
|
|
|
|
|
|
|
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
|
2017-02-17 10:22:01 +00:00
|
|
|
end
|
2018-01-17 13:37:14 +00:00
|
|
|
|
2017-02-17 10:22:01 +00:00
|
|
|
return warnings
|
|
|
|
end
|
|
|
|
|
2018-01-17 13:37:14 +00:00
|
|
|
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
|
2017-02-17 10:22:01 +00:00
|
|
|
|
2018-01-17 13:37:14 +00:00
|
|
|
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
|
2017-02-17 10:22:01 +00:00
|
|
|
|
2018-01-17 13:37:14 +00:00
|
|
|
local dump = require("luci.util").ubus("network.interface.%s" % iface, "status", {})
|
|
|
|
overview[iface]["default_route"] = false
|
2018-01-19 08:49:46 +00:00
|
|
|
if dump and dump.route then
|
2018-01-17 13:37:14 +00:00
|
|
|
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
|
2017-02-17 10:22:01 +00:00
|
|
|
|
2018-01-17 13:37:14 +00:00
|
|
|
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
|
2017-02-17 10:22:01 +00:00
|
|
|
|
2018-01-12 09:50:58 +00:00
|
|
|
m5 = Map("mwan3", translate("MWAN - Interfaces"),
|
2018-01-17 13:37:14 +00:00
|
|
|
interfaceWarnings(configCheck()))
|
2017-02-17 10:22:01 +00:00
|
|
|
|
2018-01-12 09:50:58 +00:00
|
|
|
mwan_interface = m5:section(TypedSection, "interface", nil,
|
2017-02-17 10:22:01 +00:00
|
|
|
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"))
|
2018-01-18 06:41:41 +00:00
|
|
|
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
|
2017-02-17 10:22:01 +00:00
|
|
|
|
|
|
|
enabled = mwan_interface:option(DummyValue, "enabled", translate("Enabled"))
|
2018-01-18 06:41:41 +00:00
|
|
|
enabled.rawhtml = true
|
|
|
|
function enabled.cfgvalue(self, s)
|
|
|
|
if self.map:get(s, "enabled") == "1" then
|
|
|
|
return translate("Yes")
|
|
|
|
else
|
|
|
|
return translate("No")
|
2017-02-17 10:22:01 +00:00
|
|
|
end
|
2018-01-18 06:41:41 +00:00
|
|
|
end
|
2017-02-17 10:22:01 +00:00
|
|
|
|
2017-08-14 16:49:41 +00:00
|
|
|
track_method = mwan_interface:option(DummyValue, "track_method", translate("Tracking method"))
|
2018-01-18 06:41:41 +00:00
|
|
|
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 "—"
|
2017-08-14 16:49:41 +00:00
|
|
|
end
|
2018-01-18 06:41:41 +00:00
|
|
|
end
|
2017-08-14 16:49:41 +00:00
|
|
|
|
2017-02-17 10:22:01 +00:00
|
|
|
reliability = mwan_interface:option(DummyValue, "reliability", translate("Tracking reliability"))
|
2018-01-18 06:41:41 +00:00
|
|
|
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 "—"
|
2017-02-17 10:22:01 +00:00
|
|
|
end
|
2018-01-18 06:41:41 +00:00
|
|
|
end
|
2017-02-17 10:22:01 +00:00
|
|
|
|
|
|
|
interval = mwan_interface:option(DummyValue, "interval", translate("Ping interval"))
|
2018-01-18 06:41:41 +00:00
|
|
|
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"
|
2017-02-17 10:22:01 +00:00
|
|
|
else
|
|
|
|
return "—"
|
|
|
|
end
|
2018-01-18 06:41:41 +00:00
|
|
|
else
|
|
|
|
return "—"
|
2017-02-17 10:22:01 +00:00
|
|
|
end
|
2018-01-18 06:41:41 +00:00
|
|
|
end
|
2017-02-17 10:22:01 +00:00
|
|
|
|
|
|
|
down = mwan_interface:option(DummyValue, "down", translate("Interface down"))
|
2018-01-18 06:41:41 +00:00
|
|
|
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 "—"
|
2017-02-17 10:22:01 +00:00
|
|
|
end
|
2018-01-18 06:41:41 +00:00
|
|
|
end
|
2017-02-17 10:22:01 +00:00
|
|
|
|
|
|
|
up = mwan_interface:option(DummyValue, "up", translate("Interface up"))
|
2018-01-18 06:41:41 +00:00
|
|
|
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 "—"
|
2017-02-17 10:22:01 +00:00
|
|
|
end
|
2018-01-18 06:41:41 +00:00
|
|
|
end
|
2017-02-17 10:22:01 +00:00
|
|
|
|
|
|
|
metric = mwan_interface:option(DummyValue, "metric", translate("Metric"))
|
2018-01-18 06:41:41 +00:00
|
|
|
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 "—"
|
2017-02-17 10:22:01 +00:00
|
|
|
end
|
2018-01-18 06:41:41 +00:00
|
|
|
end
|
2017-02-17 10:22:01 +00:00
|
|
|
|
|
|
|
return m5
|