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.

100 lines
3.4 KiB

  1. -- ------ extra functions ------ --
  2. function rule_check() -- determine if rule needs a protocol specified
  3. local sport = ut.trim(sys.exec("uci get -p /var/state mwan3." .. arg[1] .. ".src_port"))
  4. local dport = ut.trim(sys.exec("uci get -p /var/state mwan3." .. arg[1] .. ".dest_port"))
  5. if sport ~= "" or dport ~= "" then -- ports configured
  6. local proto = ut.trim(sys.exec("uci get -p /var/state mwan3." .. arg[1] .. ".proto"))
  7. if proto == "" or proto == "all" then -- no or improper protocol
  8. err_proto = 1
  9. end
  10. end
  11. end
  12. function rule_warn() -- display warning message at the top of the page
  13. if err_proto == 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 cbi_add_policy(field)
  20. uci.cursor():foreach("mwan3", "policy",
  21. function (section)
  22. field:value(section[".name"])
  23. end
  24. )
  25. end
  26. function cbi_add_protocol(field)
  27. local protos = 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(protos, "%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. err_proto = 0
  38. rule_check()
  39. m5 = Map("mwan3", translate("MWAN3 Multi-WAN Rule Configuration - ") .. arg[1],
  40. translate(rule_warn()))
  41. m5.redirect = dsp.build_url("admin", "network", "mwan3", "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. cbi_add_protocol(proto)
  66. use_policy = mwan_rule:option(Value, "use_policy", translate("Policy assigned"))
  67. cbi_add_policy(use_policy)
  68. use_policy:value("unreachable", translate("unreachable (reject)"))
  69. use_policy:value("blackhole", translate("blackhole (drop)"))
  70. use_policy:value("default", translate("default (use main routing table)"))
  71. -- ------ currently configured policies ------ --
  72. mwan_policy = m5:section(TypedSection, "policy", translate("Currently Configured Policies"))
  73. mwan_policy.addremove = false
  74. mwan_policy.dynamic = false
  75. mwan_policy.sortable = false
  76. mwan_policy.template = "cbi/tblsection"
  77. return m5