1 -- Copyright 2014 Aedan Renner <chipdankly@gmail.com
2 -- Copyright 2018 Florian Eckert <fe@dev.tdt.de>
3 -- Licensed to the public under the GNU General Public License v2.
5 dsp = require "luci.dispatcher"
8 function interfaceWarnings(overview, count)
11 warnings = string.format("<strong>%s</strong><br />",
12 translatef("There are currently %d of 250 supported interfaces configured", count)
15 warnings = string.format("<strong>%s</strong><br />",
16 translatef("WARNING: %d interfaces are configured exceeding the maximum of 250!", count)
20 for i, k in pairs(overview) do
21 if overview[i]["network"] == false then
22 warnings = warnings .. string.format("<strong>%s</strong><br />",
23 translatef("WARNING: Interface %s are not found in /etc/config/network", i)
27 if overview[i]["default_route"] == false then
28 warnings = warnings .. string.format("<strong>%s</strong><br />",
29 translatef("WARNING: Interface %s has no default route in the main routing table", i)
33 if overview[i]["reliability"] == false then
34 warnings = warnings .. string.format("<strong>%s</strong><br />",
35 translatef("WARNING: Interface %s has a higher reliability " ..
36 "requirement than tracking hosts (%d)", i, overview[i]["tracking"])
40 if overview[i]["duplicate_metric"] == true then
41 warnings = warnings .. string.format("<strong>%s</strong><br />",
42 translatef("WARNING: Interface %s has a duplicate metric %s configured", i, overview[i]["metric"])
50 function configCheck()
53 local duplicate_metric = {}
54 uci.cursor():foreach("mwan3", "interface",
56 local uci = uci.cursor(nil, "/var/state")
57 local iface = section[".name"]
60 local network = uci:get("network", iface)
61 overview[iface]["network"] = false
62 if network ~= nil then
63 overview[iface]["network"] = true
65 local device = uci:get("network", iface, "ifname")
67 overview[iface]["device"] = device
70 local metric = uci:get("network", iface, "metric")
72 overview[iface]["metric"] = metric
73 overview[iface]["duplicate_metric"] = false
74 for _, m in ipairs(duplicate_metric) do
76 overview[iface]["duplicate_metric"] = true
79 table.insert(duplicate_metric, metric)
82 local dump = require("luci.util").ubus("network.interface.%s" % iface, "status", {})
83 overview[iface]["default_route"] = false
84 if dump and dump.route then
86 for _, route in ipairs(dump.route) do
87 if dump.route[_].target == "0.0.0.0" then
88 overview[iface]["default_route"] = true
94 local trackingNumber = uci:get("mwan3", iface, "track_ip")
95 overview[iface]["tracking"] = 0
96 if trackingNumber and #trackingNumber > 0 then
97 overview[iface]["tracking"] = #trackingNumber
98 overview[iface]["reliability"] = false
99 local reliabilityNumber = tonumber(uci:get("mwan3", iface, "reliability"))
100 if reliabilityNumber and reliabilityNumber <= #trackingNumber then
101 overview[iface]["reliability"] = true
106 return overview, count
109 m5 = Map("mwan3", translate("MWAN - Interfaces"),
110 interfaceWarnings(configCheck()))
112 mwan_interface = m5:section(TypedSection, "interface", nil,
113 translate("MWAN supports up to 250 physical and/or logical interfaces<br />" ..
114 "MWAN requires that all interfaces have a unique metric configured in /etc/config/network<br />" ..
115 "Names must match the interface name found in /etc/config/network (see advanced tab)<br />" ..
116 "Names may contain characters A-Z, a-z, 0-9, _ and no spaces<br />" ..
117 "Interfaces may not share the same name as configured members, policies or rules"))
118 mwan_interface.addremove = true
119 mwan_interface.dynamic = false
120 mwan_interface.sectionhead = translate("Interface")
121 mwan_interface.sortable = false
122 mwan_interface.template = "cbi/tblsection"
123 mwan_interface.extedit = dsp.build_url("admin", "network", "mwan", "interface", "%s")
124 function mwan_interface.create(self, section)
125 TypedSection.create(self, section)
127 luci.http.redirect(dsp.build_url("admin", "network", "mwan", "interface", section))
130 enabled = mwan_interface:option(DummyValue, "enabled", translate("Enabled"))
131 enabled.rawhtml = true
132 function enabled.cfgvalue(self, s)
133 if self.map:get(s, "enabled") == "1" then
134 return translate("Yes")
136 return translate("No")
140 track_method = mwan_interface:option(DummyValue, "track_method", translate("Tracking method"))
141 track_method.rawhtml = true
142 function track_method.cfgvalue(self, s)
143 local tracked = self.map:get(s, "track_ip")
145 return self.map:get(s, "track_method") or "—"
151 reliability = mwan_interface:option(DummyValue, "reliability", translate("Tracking reliability"))
152 reliability.rawhtml = true
153 function reliability.cfgvalue(self, s)
154 local tracked = self.map:get(s, "track_ip")
156 return self.map:get(s, "reliability") or "—"
162 interval = mwan_interface:option(DummyValue, "interval", translate("Ping interval"))
163 interval.rawhtml = true
164 function interval.cfgvalue(self, s)
165 local tracked = self.map:get(s, "track_ip")
167 local intervalValue = self.map:get(s, "interval")
168 if intervalValue then
169 return intervalValue .. "s"
178 down = mwan_interface:option(DummyValue, "down", translate("Interface down"))
180 function down.cfgvalue(self, s)
181 local tracked = self.map:get(s, "track_ip")
183 return self.map:get(s, "down") or "—"
189 up = mwan_interface:option(DummyValue, "up", translate("Interface up"))
191 function up.cfgvalue(self, s)
192 local tracked = self.map:get(s, "track_ip")
194 return self.map:get(s, "up") or "—"
200 metric = mwan_interface:option(DummyValue, "metric", translate("Metric"))
201 metric.rawhtml = true
202 function metric.cfgvalue(self, s)
203 local uci = uci.cursor(nil, "/var/state")
204 local metric = uci:get("network", s, "metric")