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.

190 lines
7.1 KiB

  1. -- ------ extra functions ------ --
  2. function interfaceCheck()
  3. metricValue = ut.trim(sys.exec("uci get -p /var/state network." .. arg[1] .. ".metric"))
  4. if metricValue == "" then -- no metric
  5. errorNoMetric = 1
  6. else -- if metric exists create list of interface metrics to compare against for duplicates
  7. uci.cursor():foreach("mwan3", "interface",
  8. function (section)
  9. local metricValue = ut.trim(sys.exec("uci get -p /var/state network." .. section[".name"] .. ".metric"))
  10. metricList = metricList .. section[".name"] .. " " .. metricValue .. "\n"
  11. end
  12. )
  13. -- compare metric against list
  14. local metricDuplicateNumbers, metricDuplicates = sys.exec("echo '" .. metricList .. "' | awk '{print $2}' | uniq -d"), ""
  15. for line in metricDuplicateNumbers:gmatch("[^\r\n]+") do
  16. metricDuplicates = sys.exec("echo '" .. metricList .. "' | grep '" .. line .. "' | awk '{print $1}'")
  17. errorDuplicateMetricList = errorDuplicateMetricList .. metricDuplicates
  18. end
  19. if sys.exec("echo '" .. errorDuplicateMetricList .. "' | grep -w " .. arg[1]) ~= "" then
  20. errorDuplicateMetric = 1
  21. end
  22. end
  23. -- check if this interface has a higher reliability requirement than track IPs configured
  24. local trackingNumber = tonumber(ut.trim(sys.exec("echo $(uci get -p /var/state mwan3." .. arg[1] .. ".track_ip) | wc -w")))
  25. if trackingNumber > 0 then
  26. local reliabilityNumber = tonumber(ut.trim(sys.exec("uci get -p /var/state mwan3." .. arg[1] .. ".reliability")))
  27. if reliabilityNumber and reliabilityNumber > trackingNumber then
  28. errorReliability = 1
  29. end
  30. end
  31. -- check if any interfaces are not properly configured in /etc/config/network or have no default route in main routing table
  32. if ut.trim(sys.exec("uci get -p /var/state network." .. arg[1])) == "interface" then
  33. local interfaceDevice = ut.trim(sys.exec("uci get -p /var/state network." .. arg[1] .. ".ifname"))
  34. if interfaceDevice == "uci: Entry not found" or interfaceDevice == "" then
  35. errorNetConfig = 1
  36. errorRoute = 1
  37. else
  38. local routeCheck = ut.trim(sys.exec("route -n | awk '{if ($8 == \"" .. interfaceDevice .. "\" && $1 == \"0.0.0.0\" && $3 == \"0.0.0.0\") print $1}'"))
  39. if routeCheck == "" then
  40. errorRoute = 1
  41. end
  42. end
  43. else
  44. errorNetConfig = 1
  45. errorRoute = 1
  46. end
  47. end
  48. function interfaceWarnings() -- display warning messages at the top of the page
  49. local warns, lineBreak = "", ""
  50. if errorReliability == 1 then
  51. warns = "<font color=\"ff0000\"><strong>WARNING: this interface has a higher reliability requirement than there are tracking IP addresses!</strong></font>"
  52. lineBreak = "<br /><br />"
  53. end
  54. if errorRoute == 1 then
  55. warns = warns .. lineBreak .. "<font color=\"ff0000\"><strong>WARNING: this interface has no default route in the main routing table!</strong></font>"
  56. lineBreak = "<br /><br />"
  57. end
  58. if errorNetConfig == 1 then
  59. warns = warns .. lineBreak .. "<font color=\"ff0000\"><strong>WARNING: this interface is configured incorrectly or not at all in /etc/config/network!</strong></font>"
  60. lineBreak = "<br /><br />"
  61. end
  62. if errorNoMetric == 1 then
  63. warns = warns .. lineBreak .. "<font color=\"ff0000\"><strong>WARNING: this interface has no metric configured in /etc/config/network!</strong></font>"
  64. elseif errorDuplicateMetric == 1 then
  65. warns = warns .. lineBreak .. "<font color=\"ff0000\"><strong>WARNING: this and other interfaces have duplicate metrics configured in /etc/config/network!</strong></font>"
  66. end
  67. return warns
  68. end
  69. -- ------ interface configuration ------ --
  70. dsp = require "luci.dispatcher"
  71. sys = require "luci.sys"
  72. ut = require "luci.util"
  73. arg[1] = arg[1] or ""
  74. metricValue = ""
  75. metricList = ""
  76. errorDuplicateMetricList = ""
  77. errorNoMetric = 0
  78. errorDuplicateMetric = 0
  79. errorRoute = 0
  80. errorNetConfig = 0
  81. errorReliability = 0
  82. interfaceCheck()
  83. m5 = Map("mwan3", translate("MWAN Interface Configuration - " .. arg[1]),
  84. translate(interfaceWarnings()))
  85. m5.redirect = dsp.build_url("admin", "network", "mwan", "configuration", "interface")
  86. mwan_interface = m5:section(NamedSection, arg[1], "interface", "")
  87. mwan_interface.addremove = false
  88. mwan_interface.dynamic = false
  89. enabled = mwan_interface:option(ListValue, "enabled", translate("Enabled"))
  90. enabled.default = "1"
  91. enabled:value("1", translate("Yes"))
  92. enabled:value("0", translate("No"))
  93. track_ip = mwan_interface:option(DynamicList, "track_ip", translate("Tracking IP"),
  94. translate("This IP address will be pinged to dermine if the link is up or down. Leave blank to assume interface is always online"))
  95. track_ip.datatype = "ipaddr"
  96. reliability = mwan_interface:option(Value, "reliability", translate("Tracking reliability"),
  97. translate("Acceptable values: 1-100. This many Tracking IP addresses must respond for the link to be deemed up"))
  98. reliability.datatype = "range(1, 100)"
  99. reliability.default = "1"
  100. count = mwan_interface:option(ListValue, "count", translate("Ping count"))
  101. count.default = "1"
  102. count:value("1")
  103. count:value("2")
  104. count:value("3")
  105. count:value("4")
  106. count:value("5")
  107. timeout = mwan_interface:option(ListValue, "timeout", translate("Ping timeout"))
  108. timeout.default = "2"
  109. timeout:value("1", translate("1 second"))
  110. timeout:value("2", translate("2 seconds"))
  111. timeout:value("3", translate("3 seconds"))
  112. timeout:value("4", translate("4 seconds"))
  113. timeout:value("5", translate("5 seconds"))
  114. timeout:value("6", translate("6 seconds"))
  115. timeout:value("7", translate("7 seconds"))
  116. timeout:value("8", translate("8 seconds"))
  117. timeout:value("9", translate("9 seconds"))
  118. timeout:value("10", translate("10 seconds"))
  119. interval = mwan_interface:option(ListValue, "interval", translate("Ping interval"))
  120. interval.default = "5"
  121. interval:value("1", translate("1 second"))
  122. interval:value("3", translate("3 seconds"))
  123. interval:value("5", translate("5 seconds"))
  124. interval:value("10", translate("10 seconds"))
  125. interval:value("20", translate("20 seconds"))
  126. interval:value("30", translate("30 seconds"))
  127. interval:value("60", translate("1 minute"))
  128. interval:value("300", translate("5 minutes"))
  129. interval:value("600", translate("10 minutes"))
  130. interval:value("900", translate("15 minutes"))
  131. interval:value("1800", translate("30 minutes"))
  132. interval:value("3600", translate("1 hour"))
  133. down = mwan_interface:option(ListValue, "down", translate("Interface down"),
  134. translate("Interface will be deemed down after this many failed ping tests"))
  135. down.default = "3"
  136. down:value("1")
  137. down:value("2")
  138. down:value("3")
  139. down:value("4")
  140. down:value("5")
  141. down:value("6")
  142. down:value("7")
  143. down:value("8")
  144. down:value("9")
  145. down:value("10")
  146. up = mwan_interface:option(ListValue, "up", translate("Interface up"),
  147. translate("Downed interface will be deemed up after this many successful ping tests"))
  148. up.default = "3"
  149. up:value("1")
  150. up:value("2")
  151. up:value("3")
  152. up:value("4")
  153. up:value("5")
  154. up:value("6")
  155. up:value("7")
  156. up:value("8")
  157. up:value("9")
  158. up:value("10")
  159. metric = mwan_interface:option(DummyValue, "metric", translate("Metric"),
  160. translate("This displays the metric assigned to this interface in /etc/config/network"))
  161. metric.rawhtml = true
  162. function metric.cfgvalue(self, s)
  163. if errorNoMetric == 0 then
  164. return metricValue
  165. else
  166. return "&#8212;"
  167. end
  168. end
  169. return m5