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.

95 lines
3.0 KiB

  1. -- ------ extra functions ------ --
  2. function policyCheck() -- check to see if any policy names exceed the maximum of 15 characters
  3. uci.cursor():foreach("mwan3", "policy",
  4. function (section)
  5. if string.len(section[".name"]) > 15 then
  6. nameTooLong = 1
  7. err_name_list = err_name_list .. section[".name"] .. " "
  8. end
  9. end
  10. )
  11. end
  12. function policyWarn() -- display status and warning messages at the top of the page
  13. if nameTooLong == 1 then
  14. return "<font color=\"ff0000\"><strong>WARNING: Some policies have names exceeding the maximum of 15 characters!</strong></font>"
  15. else
  16. return ""
  17. end
  18. end
  19. -- ------ policy configuration ------ --
  20. ds = require "luci.dispatcher"
  21. sys = require "luci.sys"
  22. nameTooLong = 0
  23. err_name_list = " "
  24. policyCheck()
  25. m5 = Map("mwan3", translate("MWAN Policy Configuration"),
  26. translate(policyWarn()))
  27. m5:append(Template("mwan/config_css"))
  28. mwan_policy = m5:section(TypedSection, "policy", translate("Policies"),
  29. translate("Policies are profiles grouping one or more members controlling how MWAN distributes traffic<br />" ..
  30. "Member interfaces with lower metrics are used first. Interfaces with the same metric load-balance<br />" ..
  31. "Load-balanced member interfaces distribute more traffic out those with higher weights<br />" ..
  32. "Names may contain characters A-Z, a-z, 0-9, _ and no spaces. Names must be 15 characters or less<br />" ..
  33. "Policies may not share the same name as configured interfaces, members or rules"))
  34. mwan_policy.addremove = true
  35. mwan_policy.dynamic = false
  36. mwan_policy.sectionhead = "Policy"
  37. mwan_policy.sortable = true
  38. mwan_policy.template = "cbi/tblsection"
  39. mwan_policy.extedit = ds.build_url("admin", "network", "mwan", "configuration", "policy", "%s")
  40. function mwan_policy.create(self, section)
  41. TypedSection.create(self, section)
  42. m5.uci:save("mwan3")
  43. luci.http.redirect(ds.build_url("admin", "network", "mwan", "configuration", "policy", section))
  44. end
  45. use_member = mwan_policy:option(DummyValue, "use_member", translate("Members assigned"))
  46. use_member.rawhtml = true
  47. function use_member.cfgvalue(self, s)
  48. local memberConfig, memberList = self.map:get(s, "use_member"), ""
  49. if memberConfig then
  50. for k,v in pairs(memberConfig) do
  51. memberList = memberList .. v .. "<br />"
  52. end
  53. return memberList
  54. else
  55. return "&#8212;"
  56. end
  57. end
  58. last_resort = mwan_policy:option(DummyValue, "last_resort", translate("Last resort"))
  59. last_resort.rawhtml = true
  60. function last_resort.cfgvalue(self, s)
  61. local action = self.map:get(s, "last_resort")
  62. if action == "blackhole" then
  63. return "blackhole (drop)"
  64. elseif action == "default" then
  65. return "default (use main routing table)"
  66. else
  67. return "unreachable (reject)"
  68. end
  69. end
  70. errors = mwan_policy:option(DummyValue, "errors", translate("Errors"))
  71. errors.rawhtml = true
  72. function errors.cfgvalue(self, s)
  73. if not string.find(err_name_list, " " .. s .. " ") then
  74. return ""
  75. else
  76. return "<span title=\"Name exceeds 15 characters\"><img src=\"/luci-static/resources/cbi/reset.gif\" alt=\"error\"></img></span>"
  77. end
  78. end
  79. return m5