policy.lua 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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.
  4. dsp = require "luci.dispatcher"
  5. uci = require "uci"
  6. function policyCheck()
  7. local policy_error = {}
  8. uci.cursor():foreach("mwan3", "policy",
  9. function (section)
  10. policy_error[section[".name"]] = false
  11. if string.len(section[".name"]) > 15 then
  12. policy_error[section[".name"]] = true
  13. end
  14. end
  15. )
  16. return policy_error
  17. end
  18. function policyError(policy_error)
  19. local warnings = ""
  20. for i, k in pairs(policy_error) do
  21. if policy_error[i] == true then
  22. warnings = warnings .. string.format("<strong>%s</strong><br />",
  23. translatef("WARNING: Policy %s has exceeding the maximum name of 15 characters", i)
  24. )
  25. end
  26. end
  27. return warnings
  28. end
  29. m5 = Map("mwan3", translate("MWAN - Policies"),
  30. policyError(policyCheck()))
  31. mwan_policy = m5:section(TypedSection, "policy", nil,
  32. translate("Policies are profiles grouping one or more members controlling how MWAN distributes traffic<br />" ..
  33. "Member interfaces with lower metrics are used first<br />" ..
  34. "Member interfaces with the same metric will be load-balanced<br />" ..
  35. "Load-balanced member interfaces distribute more traffic out those with higher weights<br />" ..
  36. "Names may contain characters A-Z, a-z, 0-9, _ and no spaces<br />" ..
  37. "Names must be 15 characters or less<br />" ..
  38. "Policies may not share the same name as configured interfaces, members or rules"))
  39. mwan_policy.addremove = true
  40. mwan_policy.dynamic = false
  41. mwan_policy.sectionhead = translate("Policy")
  42. mwan_policy.sortable = true
  43. mwan_policy.template = "cbi/tblsection"
  44. mwan_policy.extedit = dsp.build_url("admin", "network", "mwan", "policy", "%s")
  45. function mwan_policy.create(self, section)
  46. TypedSection.create(self, section)
  47. m5.uci:save("mwan3")
  48. luci.http.redirect(dsp.build_url("admin", "network", "mwan", "policy", section))
  49. end
  50. use_member = mwan_policy:option(DummyValue, "use_member", translate("Members assigned"))
  51. use_member.rawhtml = true
  52. function use_member.cfgvalue(self, s)
  53. local memberConfig, memberList = self.map:get(s, "use_member"), ""
  54. if memberConfig then
  55. for k,v in pairs(memberConfig) do
  56. memberList = memberList .. v .. "<br />"
  57. end
  58. return memberList
  59. else
  60. return "&#8212;"
  61. end
  62. end
  63. last_resort = mwan_policy:option(DummyValue, "last_resort", translate("Last resort"))
  64. last_resort.rawhtml = true
  65. function last_resort.cfgvalue(self, s)
  66. local action = self.map:get(s, "last_resort")
  67. if action == "blackhole" then
  68. return translate("blackhole (drop)")
  69. elseif action == "default" then
  70. return translate("default (use main routing table)")
  71. else
  72. return translate("unreachable (reject)")
  73. end
  74. end
  75. return m5