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.

113 lines
4.1 KiB

  1. -- ------ extra functions ------ --
  2. function ruleCheck() -- determine if rule needs a protocol specified
  3. local sourcePort = ut.trim(sys.exec("uci get -p /var/state mwan3." .. arg[1] .. ".src_port"))
  4. local destPort = ut.trim(sys.exec("uci get -p /var/state mwan3." .. arg[1] .. ".dest_port"))
  5. if sourcePort ~= "" or destPort ~= "" then -- ports configured
  6. local protocol = ut.trim(sys.exec("uci get -p /var/state mwan3." .. arg[1] .. ".proto"))
  7. if protocol == "" or protocol == "all" then -- no or improper protocol
  8. error_protocol = 1
  9. end
  10. end
  11. end
  12. function ruleWarn() -- display warning message at the top of the page
  13. if error_protocol == 1 then
  14. return "<font color=\"ff0000\"><strong>WARNING: this rule is incorrectly configured with no or improper protocol specified! Please configure a specific protocol!</strong></font>"
  15. else
  16. return ""
  17. end
  18. end
  19. function cbiAddPolicy(field)
  20. uci.cursor():foreach("mwan3", "policy",
  21. function (section)
  22. field:value(section[".name"])
  23. end
  24. )
  25. end
  26. function cbiAddProtocol(field)
  27. local protocols = ut.trim(sys.exec("cat /etc/protocols | grep ' # ' | awk '{print $1}' | grep -vw -e 'ip' -e 'tcp' -e 'udp' -e 'icmp' -e 'esp' | grep -v 'ipv6' | sort | tr '\n' ' '"))
  28. for p in string.gmatch(protocols, "%S+") do
  29. field:value(p)
  30. end
  31. end
  32. -- ------ rule configuration ------ --
  33. dsp = require "luci.dispatcher"
  34. sys = require "luci.sys"
  35. ut = require "luci.util"
  36. arg[1] = arg[1] or ""
  37. error_protocol = 0
  38. ruleCheck()
  39. m5 = Map("mwan3", translate("MWAN Rule Configuration - ") .. arg[1],
  40. translate(ruleWarn()))
  41. m5.redirect = dsp.build_url("admin", "network", "mwan", "configuration", "rule")
  42. mwan_rule = m5:section(NamedSection, arg[1], "rule", "")
  43. mwan_rule.addremove = false
  44. mwan_rule.dynamic = false
  45. src_ip = mwan_rule:option(Value, "src_ip", translate("Source address"),
  46. translate("Supports CIDR notation (eg \"192.168.100.0/24\") without quotes"))
  47. src_ip.datatype = ipaddr
  48. src_port = mwan_rule:option(Value, "src_port", translate("Source port"),
  49. translate("May be entered as a single or multiple port(s) (eg \"22\" or \"80,443\") or as a portrange (eg \"1024:2048\") without quotes"))
  50. dest_ip = mwan_rule:option(Value, "dest_ip", translate("Destination address"),
  51. translate("Supports CIDR notation (eg \"192.168.100.0/24\") without quotes"))
  52. dest_ip.datatype = ipaddr
  53. dest_port = mwan_rule:option(Value, "dest_port", translate("Destination port"),
  54. translate("May be entered as a single or multiple port(s) (eg \"22\" or \"80,443\") or as a portrange (eg \"1024:2048\") without quotes"))
  55. proto = mwan_rule:option(Value, "proto", translate("Protocol"),
  56. translate("View the contents of /etc/protocols for protocol descriptions"))
  57. proto.default = "all"
  58. proto.rmempty = false
  59. proto:value("all")
  60. proto:value("ip")
  61. proto:value("tcp")
  62. proto:value("udp")
  63. proto:value("icmp")
  64. proto:value("esp")
  65. cbiAddProtocol(proto)
  66. sticky = mwan_rule:option(ListValue, "sticky", translate("Sticky"),
  67. translate("Traffic from the same source IP address that previously matched this rule within the sticky timeout period will use the same WAN interface"))
  68. sticky.default = "0"
  69. sticky:value("1", translate("Yes"))
  70. sticky:value("0", translate("No"))
  71. timeout = mwan_rule:option(Value, "timeout", translate("Sticky timeout"),
  72. translate("Seconds. Acceptable values: 1-1000000. Defaults to 600 if not set"))
  73. timeout.datatype = "range(1, 1000000)"
  74. ipset = mwan_rule:option(Value, "ipset", translate("IPset"),
  75. translate("Name of IPset rule. Requires IPset rule in /etc/dnsmasq.conf (eg \"ipset=/youtube.com/youtube\")"))
  76. use_policy = mwan_rule:option(Value, "use_policy", translate("Policy assigned"))
  77. cbiAddPolicy(use_policy)
  78. use_policy:value("unreachable", translate("unreachable (reject)"))
  79. use_policy:value("blackhole", translate("blackhole (drop)"))
  80. use_policy:value("default", translate("default (use main routing table)"))
  81. -- ------ currently configured policies ------ --
  82. mwan_policy = m5:section(TypedSection, "policy", translate("Currently Configured Policies"))
  83. mwan_policy.addremove = false
  84. mwan_policy.dynamic = false
  85. mwan_policy.sortable = false
  86. mwan_policy.template = "cbi/tblsection"
  87. return m5