You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

266 lines
9.0 KiB

  1. -- ------ extra functions ------ --
  2. function iface_check() -- find issues with too many interfaces, reliability and metric
  3. uci.cursor():foreach("mwan3", "interface",
  4. function (section)
  5. local ifname = section[".name"]
  6. ifnum = ifnum+1 -- count number of mwan3 interfaces configured
  7. -- create list of metrics for none and duplicate checking
  8. local metlkp = ut.trim(sys.exec("uci get -p /var/state network." .. ifname .. ".metric"))
  9. if metlkp == "" then
  10. err_found = 1
  11. err_nomet_list = err_nomet_list .. ifname .. " "
  12. else
  13. metric_list = metric_list .. ifname .. " " .. metlkp .. "\n"
  14. end
  15. -- check if any interfaces have a higher reliability requirement than tracking IPs configured
  16. local tipnum = tonumber(ut.trim(sys.exec("echo $(uci get -p /var/state mwan3." .. ifname .. ".track_ip) | wc -w")))
  17. if tipnum > 0 then
  18. local relnum = tonumber(ut.trim(sys.exec("uci get -p /var/state mwan3." .. ifname .. ".reliability")))
  19. if relnum and relnum > tipnum then
  20. err_found = 1
  21. err_rel_list = err_rel_list .. ifname .. " "
  22. end
  23. end
  24. -- check if any interfaces are not properly configured in /etc/config/network or have no default route in main routing table
  25. if ut.trim(sys.exec("uci get -p /var/state network." .. ifname)) == "interface" then
  26. local ifdev = ut.trim(sys.exec("uci get -p /var/state network." .. ifname .. ".ifname"))
  27. if ifdev == "uci: Entry not found" or ifdev == "" then
  28. err_found = 1
  29. err_netcfg_list = err_netcfg_list .. ifname .. " "
  30. err_route_list = err_route_list .. ifname .. " "
  31. else
  32. local rtcheck = ut.trim(sys.exec("route -n | awk '{ if ($8 == \"" .. ifdev .. "\" && $1 == \"0.0.0.0\" && $3 == \"0.0.0.0\") print $1 }'"))
  33. if rtcheck == "" then
  34. err_found = 1
  35. err_route_list = err_route_list .. ifname .. " "
  36. end
  37. end
  38. else
  39. err_found = 1
  40. err_netcfg_list = err_netcfg_list .. ifname .. " "
  41. err_route_list = err_route_list .. ifname .. " "
  42. end
  43. end
  44. )
  45. -- check if any interfaces have duplicate metrics
  46. local metric_dupnums = sys.exec("echo '" .. metric_list .. "' | awk '{ print $2 }' | uniq -d")
  47. if metric_dupnums ~= "" then
  48. err_found = 1
  49. local metric_dupes = ""
  50. for line in metric_dupnums:gmatch("[^\r\n]+") do
  51. metric_dupes = sys.exec("echo '" .. metric_list .. "' | grep '" .. line .. "' | awk '{ print $1 }'")
  52. err_dupmet_list = err_dupmet_list .. metric_dupes
  53. end
  54. err_dupmet_list = sys.exec("echo '" .. err_dupmet_list .. "' | tr '\n' ' '")
  55. end
  56. end
  57. function iface_warn() -- display status and warning messages at the top of the page
  58. local warns = ""
  59. if ifnum <= 250 then
  60. warns = "<strong>There are currently " .. ifnum .. " of 250 supported interfaces configured</strong>"
  61. else
  62. warns = "<font color=\"ff0000\"><strong>WARNING: " .. ifnum .. " interfaces are configured exceeding the maximum of 250!</strong></font>"
  63. end
  64. if err_rel_list ~= " " then
  65. warns = warns .. "<br /><br /><font color=\"ff0000\"><strong>WARNING: some interfaces have a higher reliability requirement than there are tracking IP addresses!</strong></font>"
  66. end
  67. if err_route_list ~= " " then
  68. warns = warns .. "<br /><br /><font color=\"ff0000\"><strong>WARNING: some interfaces have no default route in the main routing table!</strong></font>"
  69. end
  70. if err_netcfg_list ~= " " then
  71. warns = warns .. "<br /><br /><font color=\"ff0000\"><strong>WARNING: some interfaces are configured incorrectly or not at all in /etc/config/network!</strong></font>"
  72. end
  73. if err_nomet_list ~= " " then
  74. warns = warns .. "<br /><br /><font color=\"ff0000\"><strong>WARNING: some interfaces have no metric configured in /etc/config/network!</strong></font>"
  75. end
  76. if err_dupmet_list ~= " " then
  77. warns = warns .. "<br /><br /><font color=\"ff0000\"><strong>WARNING: some interfaces have duplicate metrics configured in /etc/config/network!</strong></font>"
  78. end
  79. return warns
  80. end
  81. -- ------ interface configuration ------ --
  82. dsp = require "luci.dispatcher"
  83. sys = require "luci.sys"
  84. ut = require "luci.util"
  85. ifnum = 0
  86. metric_list = ""
  87. err_found = 0
  88. err_dupmet_list = " "
  89. err_netcfg_list = " "
  90. err_nomet_list = " "
  91. err_rel_list = " "
  92. err_route_list = " "
  93. iface_check()
  94. m5 = Map("mwan3", translate("MWAN3 Multi-WAN Interface Configuration"),
  95. translate(iface_warn()))
  96. m5:append(Template("mwan3/mwan3_config_css"))
  97. mwan_interface = m5:section(TypedSection, "interface", translate("Interfaces"),
  98. translate("MWAN3 supports up to 250 physical and/or logical interfaces<br />" ..
  99. "MWAN3 requires that all interfaces have a unique metric configured in /etc/config/network<br />" ..
  100. "Names must match the interface name found in /etc/config/network (see advanced tab)<br />" ..
  101. "Names may contain characters A-Z, a-z, 0-9, _ and no spaces<br />" ..
  102. "Interfaces may not share the same name as configured members, policies or rules"))
  103. mwan_interface.addremove = true
  104. mwan_interface.dynamic = false
  105. mwan_interface.sectionhead = "Interface"
  106. mwan_interface.sortable = true
  107. mwan_interface.template = "cbi/tblsection"
  108. mwan_interface.extedit = dsp.build_url("admin", "network", "mwan3", "configuration", "interface", "%s")
  109. function mwan_interface.create(self, section)
  110. TypedSection.create(self, section)
  111. m5.uci:save("mwan3")
  112. luci.http.redirect(dsp.build_url("admin", "network", "mwan3", "configuration", "interface", section))
  113. end
  114. enabled = mwan_interface:option(DummyValue, "enabled", translate("Enabled"))
  115. enabled.rawhtml = true
  116. function enabled.cfgvalue(self, s)
  117. if self.map:get(s, "enabled") == "1" then
  118. return "Yes"
  119. else
  120. return "No"
  121. end
  122. end
  123. track_ip = mwan_interface:option(DummyValue, "track_ip", translate("Tracking IP"))
  124. track_ip.rawhtml = true
  125. function track_ip.cfgvalue(self, s)
  126. local str = ""
  127. tracked = self.map:get(s, "track_ip")
  128. if tracked then
  129. for k,v in pairs(tracked) do
  130. str = str .. v .. "<br />"
  131. end
  132. return str
  133. else
  134. return "&#8212;"
  135. end
  136. end
  137. reliability = mwan_interface:option(DummyValue, "reliability", translate("Tracking reliability"))
  138. reliability.rawhtml = true
  139. function reliability.cfgvalue(self, s)
  140. if tracked then
  141. return self.map:get(s, "reliability") or "&#8212;"
  142. else
  143. return "&#8212;"
  144. end
  145. end
  146. count = mwan_interface:option(DummyValue, "count", translate("Ping count"))
  147. count.rawhtml = true
  148. function count.cfgvalue(self, s)
  149. if tracked then
  150. return self.map:get(s, "count") or "&#8212;"
  151. else
  152. return "&#8212;"
  153. end
  154. end
  155. timeout = mwan_interface:option(DummyValue, "timeout", translate("Ping timeout"))
  156. timeout.rawhtml = true
  157. function timeout.cfgvalue(self, s)
  158. if tracked then
  159. local tcheck = self.map:get(s, "timeout")
  160. if tcheck then
  161. return tcheck .. "s"
  162. else
  163. return "&#8212;"
  164. end
  165. else
  166. return "&#8212;"
  167. end
  168. end
  169. interval = mwan_interface:option(DummyValue, "interval", translate("Ping interval"))
  170. interval.rawhtml = true
  171. function interval.cfgvalue(self, s)
  172. if tracked then
  173. local icheck = self.map:get(s, "interval")
  174. if icheck then
  175. return icheck .. "s"
  176. else
  177. return "&#8212;"
  178. end
  179. else
  180. return "&#8212;"
  181. end
  182. end
  183. down = mwan_interface:option(DummyValue, "down", translate("Interface down"))
  184. down.rawhtml = true
  185. function down.cfgvalue(self, s)
  186. if tracked then
  187. return self.map:get(s, "down") or "&#8212;"
  188. else
  189. return "&#8212;"
  190. end
  191. end
  192. up = mwan_interface:option(DummyValue, "up", translate("Interface up"))
  193. up.rawhtml = true
  194. function up.cfgvalue(self, s)
  195. if tracked then
  196. return self.map:get(s, "up") or "&#8212;"
  197. else
  198. return "&#8212;"
  199. end
  200. end
  201. metric = mwan_interface:option(DummyValue, "metric", translate("Metric"))
  202. metric.rawhtml = true
  203. function metric.cfgvalue(self, s)
  204. local metcheck = sys.exec("uci get -p /var/state network." .. s .. ".metric")
  205. if metcheck ~= "" then
  206. return metcheck
  207. else
  208. return "&#8212;"
  209. end
  210. end
  211. errors = mwan_interface:option(DummyValue, "errors", translate("Errors"))
  212. errors.rawhtml = true
  213. function errors.cfgvalue(self, s)
  214. if err_found == 1 then
  215. local mouseover, linebrk = "", ""
  216. if string.find(err_rel_list, " " .. s .. " ") then
  217. mouseover = "Higher reliability requirement than there are tracking IP addresses"
  218. linebrk = "&#10;&#10;"
  219. end
  220. if string.find(err_route_list, " " .. s .. " ") then
  221. mouseover = mouseover .. linebrk .. "No default route in the main routing table"
  222. linebrk = "&#10;&#10;"
  223. end
  224. if string.find(err_netcfg_list, " " .. s .. " ") then
  225. mouseover = mouseover .. linebrk .. "Configured incorrectly or not at all in /etc/config/network"
  226. linebrk = "&#10;&#10;"
  227. end
  228. if string.find(err_nomet_list, " " .. s .. " ") then
  229. mouseover = mouseover .. linebrk .. "No metric configured in /etc/config/network"
  230. linebrk = "&#10;&#10;"
  231. end
  232. if string.find(err_dupmet_list, " " .. s .. " ") then
  233. mouseover = mouseover .. linebrk .. "Duplicate metric configured in /etc/config/network"
  234. end
  235. if mouseover == "" then
  236. return ""
  237. else
  238. return "<span title=\"" .. mouseover .. "\"><img src=\"/luci-static/resources/cbi/reset.gif\" alt=\"error\"></img></span>"
  239. end
  240. else
  241. return ""
  242. end
  243. end
  244. return m5