1 dsp = require "luci.dispatcher"
4 function interfaceWarnings(overview, count)
7 warnings = string.format("<strong>%s</strong></br>",
8 translatef("There are currently %d of 250 supported interfaces configured", count)
11 warnings = string.format("<strong>%s</strong></br>",
12 translatef("WARNING: %d interfaces are configured exceeding the maximum of 250!", count)
16 for i, k in pairs(overview) do
17 if overview[i]["network"] == false then
18 warnings = warnings .. string.format("<strong>%s</strong></br>",
19 translatef("WARNING: Interface %s are not found in /etc/config/network", i)
23 if overview[i]["default_route"] == false then
24 warnings = warnings .. string.format("<strong>%s</strong></br>",
25 translatef("WARNING: Interface %s has no default route in the main routing table", i)
29 if overview[i]["reliability"] == false then
30 warnings = warnings .. string.format("<strong>%s</strong></br>",
31 translatef("WARNING: Interface %s has a higher reliability " ..
32 "requirement than tracking hosts (%d)", i, overview[i]["tracking"])
36 if overview[i]["duplicate_metric"] == true then
37 warnings = warnings .. string.format("<strong>%s</strong></br>",
38 translatef("WARNING: Interface %s has a duplicate metric %s configured", i, overview[i]["metric"])
46 function configCheck()
49 local duplicate_metric = {}
50 uci.cursor():foreach("mwan3", "interface",
52 local uci = uci.cursor(nil, "/var/state")
53 local iface = section[".name"]
56 local network = uci:get("network", iface)
57 overview[iface]["network"] = false
58 if network ~= nil then
59 overview[iface]["network"] = true
61 local device = uci:get("network", iface, "ifname")
63 overview[iface]["device"] = device
66 local metric = uci:get("network", iface, "metric")
68 overview[iface]["metric"] = metric
69 overview[iface]["duplicate_metric"] = false
70 for _, m in ipairs(duplicate_metric) do
72 overview[iface]["duplicate_metric"] = true
75 table.insert(duplicate_metric, metric)
78 local dump = require("luci.util").ubus("network.interface.%s" % iface, "status", {})
79 overview[iface]["default_route"] = false
82 for _, route in ipairs(dump.route) do
83 if dump.route[_].target == "0.0.0.0" then
84 overview[iface]["default_route"] = true
90 local trackingNumber = uci:get("mwan3", iface, "track_ip")
91 overview[iface]["tracking"] = 0
92 if #trackingNumber > 0 then
93 overview[iface]["tracking"] = #trackingNumber
94 overview[iface]["reliability"] = false
95 local reliabilityNumber = tonumber(uci:get("mwan3", iface, "reliability"))
96 if reliabilityNumber and reliabilityNumber <= #trackingNumber then
97 overview[iface]["reliability"] = true
102 return overview, count
105 m5 = Map("mwan3", translate("MWAN - Interfaces"),
106 interfaceWarnings(configCheck()))
109 mwan_interface = m5:section(TypedSection, "interface", nil,
110 translate("MWAN supports up to 250 physical and/or logical interfaces<br />" ..
111 "MWAN requires that all interfaces have a unique metric configured in /etc/config/network<br />" ..
112 "Names must match the interface name found in /etc/config/network (see advanced tab)<br />" ..
113 "Names may contain characters A-Z, a-z, 0-9, _ and no spaces<br />" ..
114 "Interfaces may not share the same name as configured members, policies or rules"))
115 mwan_interface.addremove = true
116 mwan_interface.dynamic = false
117 mwan_interface.sectionhead = translate("Interface")
118 mwan_interface.sortable = false
119 mwan_interface.template = "cbi/tblsection"
120 mwan_interface.extedit = dsp.build_url("admin", "network", "mwan", "interface", "%s")
121 function mwan_interface.create(self, section)
122 TypedSection.create(self, section)
124 luci.http.redirect(dsp.build_url("admin", "network", "mwan", "interface", section))
128 enabled = mwan_interface:option(DummyValue, "enabled", translate("Enabled"))
129 enabled.rawhtml = true
130 function enabled.cfgvalue(self, s)
131 if self.map:get(s, "enabled") == "1" then
132 return translate("Yes")
134 return translate("No")
138 track_method = mwan_interface:option(DummyValue, "track_method", translate("Tracking method"))
139 track_method.rawhtml = true
140 function track_method.cfgvalue(self, s)
141 local tracked = self.map:get(s, "track_ip")
143 return self.map:get(s, "track_method") or "—"
149 reliability = mwan_interface:option(DummyValue, "reliability", translate("Tracking reliability"))
150 reliability.rawhtml = true
151 function reliability.cfgvalue(self, s)
152 local tracked = self.map:get(s, "track_ip")
154 return self.map:get(s, "reliability") or "—"
160 interval = mwan_interface:option(DummyValue, "interval", translate("Ping interval"))
161 interval.rawhtml = true
162 function interval.cfgvalue(self, s)
163 local tracked = self.map:get(s, "track_ip")
165 local intervalValue = self.map:get(s, "interval")
166 if intervalValue then
167 return intervalValue .. "s"
176 down = mwan_interface:option(DummyValue, "down", translate("Interface down"))
178 function down.cfgvalue(self, s)
179 local tracked = self.map:get(s, "track_ip")
181 return self.map:get(s, "down") or "—"
187 up = mwan_interface:option(DummyValue, "up", translate("Interface up"))
189 function up.cfgvalue(self, s)
190 local tracked = self.map:get(s, "track_ip")
192 return self.map:get(s, "up") or "—"
198 metric = mwan_interface:option(DummyValue, "metric", translate("Metric"))
199 metric.rawhtml = true
200 function metric.cfgvalue(self, s)
201 local uci = uci.cursor(nil, "/var/state")
202 local metric = uci:get("network", s, "metric")