1 dsp = require "luci.dispatcher"
2 sys = require "luci.sys"
3 ut = require "luci.util"
5 function interfaceWarnings(overview, count)
8 warnings = string.format("<strong>%s</strong></br>",
9 translatef("There are currently %d of 250 supported interfaces configured", count)
12 warnings = string.format("<strong>%s</strong></br>",
13 translatef("WARNING: %d interfaces are configured exceeding the maximum of 250!", count)
17 for i, k in pairs(overview) do
18 if overview[i]["network"] == false then
19 warnings = warnings .. string.format("<strong>%s</strong></br>",
20 translatef("WARNING: Interface %s are not found in /etc/config/network", i)
24 if overview[i]["default_route"] == false then
25 warnings = warnings .. string.format("<strong>%s</strong></br>",
26 translatef("WARNING: Interface %s has no default route in the main routing table", i)
30 if overview[i]["reliability"] == false then
31 warnings = warnings .. string.format("<strong>%s</strong></br>",
32 translatef("WARNING: Interface %s has a higher reliability " ..
33 "requirement than tracking hosts (%d)", i, overview[i]["tracking"])
37 if overview[i]["duplicate_metric"] == true then
38 warnings = warnings .. string.format("<strong>%s</strong></br>",
39 translatef("WARNING: Interface %s has a duplicate metric %s configured", i, overview[i]["metric"])
47 function configCheck()
50 local duplicate_metric = {}
51 uci.cursor():foreach("mwan3", "interface",
53 local uci = uci.cursor(nil, "/var/state")
54 local iface = section[".name"]
57 local network = uci:get("network", iface)
58 overview[iface]["network"] = false
59 if network ~= nil then
60 overview[iface]["network"] = true
62 local device = uci:get("network", iface, "ifname")
64 overview[iface]["device"] = device
67 local metric = uci:get("network", iface, "metric")
69 overview[iface]["metric"] = metric
70 overview[iface]["duplicate_metric"] = false
71 for _, m in ipairs(duplicate_metric) do
73 overview[iface]["duplicate_metric"] = true
76 table.insert(duplicate_metric, metric)
79 local dump = require("luci.util").ubus("network.interface.%s" % iface, "status", {})
80 overview[iface]["default_route"] = false
83 for _, route in ipairs(dump.route) do
84 if dump.route[_].target == "0.0.0.0" then
85 overview[iface]["default_route"] = true
91 local trackingNumber = uci:get("mwan3", iface, "track_ip")
92 overview[iface]["tracking"] = 0
93 if #trackingNumber > 0 then
94 overview[iface]["tracking"] = #trackingNumber
95 overview[iface]["reliability"] = false
96 local reliabilityNumber = tonumber(uci:get("mwan3", iface, "reliability"))
97 if reliabilityNumber and reliabilityNumber <= #trackingNumber then
98 overview[iface]["reliability"] = true
103 return overview, count
106 m5 = Map("mwan3", translate("MWAN - Interfaces"),
107 interfaceWarnings(configCheck()))
110 mwan_interface = m5:section(TypedSection, "interface", nil,
111 translate("MWAN supports up to 250 physical and/or logical interfaces<br />" ..
112 "MWAN requires that all interfaces have a unique metric configured in /etc/config/network<br />" ..
113 "Names must match the interface name found in /etc/config/network (see advanced tab)<br />" ..
114 "Names may contain characters A-Z, a-z, 0-9, _ and no spaces<br />" ..
115 "Interfaces may not share the same name as configured members, policies or rules"))
116 mwan_interface.addremove = true
117 mwan_interface.dynamic = false
118 mwan_interface.sectionhead = translate("Interface")
119 mwan_interface.sortable = false
120 mwan_interface.template = "cbi/tblsection"
121 mwan_interface.extedit = dsp.build_url("admin", "network", "mwan", "interface", "%s")
122 function mwan_interface.create(self, section)
123 TypedSection.create(self, section)
125 luci.http.redirect(dsp.build_url("admin", "network", "mwan", "interface", section))
129 enabled = mwan_interface:option(DummyValue, "enabled", translate("Enabled"))
130 enabled.rawhtml = true
131 function enabled.cfgvalue(self, s)
132 if self.map:get(s, "enabled") == "1" then
139 track_method = mwan_interface:option(DummyValue, "track_method", translate("Tracking method"))
140 track_method.rawhtml = true
141 function track_method.cfgvalue(self, s)
142 local tracked = self.map:get(s, "track_ip")
144 return self.map:get(s, "track_method") or "—"
150 reliability = mwan_interface:option(DummyValue, "reliability", translate("Tracking reliability"))
151 reliability.rawhtml = true
152 function reliability.cfgvalue(self, s)
153 local tracked = self.map:get(s, "track_ip")
155 return self.map:get(s, "reliability") or "—"
161 interval = mwan_interface:option(DummyValue, "interval", translate("Ping interval"))
162 interval.rawhtml = true
163 function interval.cfgvalue(self, s)
164 local tracked = self.map:get(s, "track_ip")
166 local intervalValue = self.map:get(s, "interval")
167 if intervalValue then
168 return intervalValue .. "s"
177 down = mwan_interface:option(DummyValue, "down", translate("Interface down"))
179 function down.cfgvalue(self, s)
180 local tracked = self.map:get(s, "track_ip")
182 return self.map:get(s, "down") or "—"
188 up = mwan_interface:option(DummyValue, "up", translate("Interface up"))
190 function up.cfgvalue(self, s)
191 local tracked = self.map:get(s, "track_ip")
193 return self.map:get(s, "up") or "—"
199 metric = mwan_interface:option(DummyValue, "metric", translate("Metric"))
200 metric.rawhtml = true
201 function metric.cfgvalue(self, s)
202 local uci = uci.cursor(nil, "/var/state")
203 local metric = uci:get("network", s, "metric")