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.

109 lines
4.0 KiB

  1. -- ------ extra functions ------ --
  2. function rule_check() -- determine if rules needs a proper protocol configured
  3. uci.cursor():foreach("mwan3", "rule",
  4. function (section)
  5. local sport = ut.trim(sys.exec("uci get -p /var/state mwan3." .. section[".name"] .. ".src_port"))
  6. local dport = ut.trim(sys.exec("uci get -p /var/state mwan3." .. section[".name"] .. ".dest_port"))
  7. if sport ~= "" or dport ~= "" then -- ports configured
  8. local proto = ut.trim(sys.exec("uci get -p /var/state mwan3." .. section[".name"] .. ".proto"))
  9. if proto == "" or proto == "all" then -- no or improper protocol
  10. err_proto_list = err_proto_list .. section[".name"] .. " "
  11. end
  12. end
  13. end
  14. )
  15. end
  16. function rule_warn() -- display warning messages at the top of the page
  17. if err_proto_list ~= " " then
  18. return "<font color=\"ff0000\"><strong>WARNING: some rules have a port configured with no or improper protocol specified! Please configure a specific protocol!</strong></font>"
  19. else
  20. return ""
  21. end
  22. end
  23. -- ------ rule configuration ------ --
  24. dsp = require "luci.dispatcher"
  25. sys = require "luci.sys"
  26. ut = require "luci.util"
  27. err_proto = 0
  28. err_proto_list = " "
  29. rule_check()
  30. m5 = Map("mwan3", translate("MWAN3 Multi-WAN Traffic Rule Configuration"),
  31. translate(rule_warn()))
  32. m5:append(Template("mwan3/mwan3_config_css"))
  33. mwan_rule = m5:section(TypedSection, "rule", translate("Traffic Rules"),
  34. translate("Rules specify which traffic will use a particular MWAN3 policy based on IP address, port or protocol<br />" ..
  35. "Rules are matched from top to bottom. Rules below a matching rule are ignored. Traffic not matching any rule is routed using the main routing table<br />" ..
  36. "Traffic destined for known (other than default) networks is handled by the main routing table. Traffic matching a rule, but all WAN interfaces for that policy are down will be blackholed<br />" ..
  37. "Names may contain characters A-Z, a-z, 0-9, _ and no spaces<br />" ..
  38. "Rules may not share the same name as configured interfaces, members or policies"))
  39. mwan_rule.addremove = true
  40. mwan_rule.anonymous = false
  41. mwan_rule.dynamic = false
  42. mwan_rule.sectionhead = "Rule"
  43. mwan_rule.sortable = true
  44. mwan_rule.template = "cbi/tblsection"
  45. mwan_rule.extedit = dsp.build_url("admin", "network", "mwan3", "configuration", "rule", "%s")
  46. function mwan_rule.create(self, section)
  47. TypedSection.create(self, section)
  48. m5.uci:save("mwan3")
  49. luci.http.redirect(dsp.build_url("admin", "network", "mwan3", "configuration", "rule", section))
  50. end
  51. src_ip = mwan_rule:option(DummyValue, "src_ip", translate("Source address"))
  52. src_ip.rawhtml = true
  53. function src_ip.cfgvalue(self, s)
  54. return self.map:get(s, "src_ip") or "&#8212;"
  55. end
  56. src_port = mwan_rule:option(DummyValue, "src_port", translate("Source port"))
  57. src_port.rawhtml = true
  58. function src_port.cfgvalue(self, s)
  59. return self.map:get(s, "src_port") or "&#8212;"
  60. end
  61. dest_ip = mwan_rule:option(DummyValue, "dest_ip", translate("Destination address"))
  62. dest_ip.rawhtml = true
  63. function dest_ip.cfgvalue(self, s)
  64. return self.map:get(s, "dest_ip") or "&#8212;"
  65. end
  66. dest_port = mwan_rule:option(DummyValue, "dest_port", translate("Destination port"))
  67. dest_port.rawhtml = true
  68. function dest_port.cfgvalue(self, s)
  69. return self.map:get(s, "dest_port") or "&#8212;"
  70. end
  71. proto = mwan_rule:option(DummyValue, "proto", translate("Protocol"))
  72. proto.rawhtml = true
  73. function proto.cfgvalue(self, s)
  74. return self.map:get(s, "proto") or "all"
  75. end
  76. use_policy = mwan_rule:option(DummyValue, "use_policy", translate("Policy assigned"))
  77. use_policy.rawhtml = true
  78. function use_policy.cfgvalue(self, s)
  79. return self.map:get(s, "use_policy") or "&#8212;"
  80. end
  81. errors = mwan_rule:option(DummyValue, "errors", translate("Errors"))
  82. errors.rawhtml = true
  83. function errors.cfgvalue(self, s)
  84. if not string.find(err_proto_list, " " .. s .. " ") then
  85. return ""
  86. else
  87. return "<span title=\"No protocol specified\"><img src=\"/luci-static/resources/cbi/reset.gif\" alt=\"error\"></img></span>"
  88. end
  89. end
  90. return m5