forward-details.lua 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. -- Copyright 2011 Jo-Philipp Wich <jow@openwrt.org>
  2. -- Licensed to the public under the Apache License 2.0.
  3. local sys = require "luci.sys"
  4. local dsp = require "luci.dispatcher"
  5. local ft = require "luci.tools.firewall"
  6. local m, s, o
  7. arg[1] = arg[1] or ""
  8. m = Map("firewall",
  9. translate("Firewall - Port Forwards"),
  10. translate("This page allows you to change advanced properties of the port \
  11. forwarding entry. In most cases there is no need to modify \
  12. those settings."))
  13. m.redirect = dsp.build_url("admin/network/firewall/forwards")
  14. if m.uci:get("firewall", arg[1]) ~= "redirect" then
  15. luci.http.redirect(m.redirect)
  16. return
  17. else
  18. local name = m:get(arg[1], "name") or m:get(arg[1], "_name")
  19. if not name or #name == 0 then
  20. name = translate("(Unnamed Entry)")
  21. end
  22. m.title = "%s - %s" %{ translate("Firewall - Port Forwards"), name }
  23. end
  24. s = m:section(NamedSection, arg[1], "redirect", "")
  25. s.anonymous = true
  26. s.addremove = false
  27. ft.opt_enabled(s, Button)
  28. ft.opt_name(s, Value, translate("Name"))
  29. o = s:option(Value, "proto", translate("Protocol"))
  30. o:value("tcp udp", "TCP+UDP")
  31. o:value("tcp", "TCP")
  32. o:value("udp", "UDP")
  33. o:value("icmp", "ICMP")
  34. function o.cfgvalue(...)
  35. local v = Value.cfgvalue(...)
  36. if not v or v == "tcpudp" then
  37. return "tcp udp"
  38. end
  39. return v
  40. end
  41. o = s:option(Value, "src", translate("Source zone"))
  42. o.nocreate = true
  43. o.default = "wan"
  44. o.template = "cbi/firewall_zonelist"
  45. o = s:option(DynamicList, "src_mac",
  46. translate("Source MAC address"),
  47. translate("Only match incoming traffic from these MACs."))
  48. o.rmempty = true
  49. o.datatype = "neg(macaddr)"
  50. o.placeholder = translate("any")
  51. luci.sys.net.mac_hints(function(mac, name)
  52. o:value(mac, "%s (%s)" %{ mac, name })
  53. end)
  54. o = s:option(Value, "src_ip",
  55. translate("Source IP address"),
  56. translate("Only match incoming traffic from this IP or range."))
  57. o.rmempty = true
  58. o.datatype = "neg(ip4addr)"
  59. o.placeholder = translate("any")
  60. luci.sys.net.ipv4_hints(function(ip, name)
  61. o:value(ip, "%s (%s)" %{ ip, name })
  62. end)
  63. o = s:option(Value, "src_port",
  64. translate("Source port"),
  65. translate("Only match incoming traffic originating from the given source port or port range on the client host"))
  66. o.rmempty = true
  67. o.datatype = "neg(portrange)"
  68. o.placeholder = translate("any")
  69. o = s:option(Value, "src_dip",
  70. translate("External IP address"),
  71. translate("Only match incoming traffic directed at the given IP address."))
  72. luci.sys.net.ipv4_hints(function(ip, name)
  73. o:value(ip, "%s (%s)" %{ ip, name })
  74. end)
  75. o.rmempty = true
  76. o.datatype = "neg(ip4addr)"
  77. o.placeholder = translate("any")
  78. o = s:option(Value, "src_dport", translate("External port"),
  79. translate("Match incoming traffic directed at the given " ..
  80. "destination port or port range on this host"))
  81. o.datatype = "neg(portrange)"
  82. o = s:option(Value, "dest", translate("Internal zone"))
  83. o.nocreate = true
  84. o.default = "lan"
  85. o.template = "cbi/firewall_zonelist"
  86. o = s:option(Value, "dest_ip", translate("Internal IP address"),
  87. translate("Redirect matched incoming traffic to the specified \
  88. internal host"))
  89. o.datatype = "ip4addr"
  90. luci.sys.net.ipv4_hints(function(ip, name)
  91. o:value(ip, "%s (%s)" %{ ip, name })
  92. end)
  93. o = s:option(Value, "dest_port",
  94. translate("Internal port"),
  95. translate("Redirect matched incoming traffic to the given port on \
  96. the internal host"))
  97. o.placeholder = translate("any")
  98. o.datatype = "portrange"
  99. o = s:option(Flag, "reflection", translate("Enable NAT Loopback"))
  100. o.rmempty = true
  101. o.default = o.enabled
  102. o.cfgvalue = function(...)
  103. return Flag.cfgvalue(...) or "1"
  104. end
  105. s:option(Value, "extra",
  106. translate("Extra arguments"),
  107. translate("Passes additional arguments to iptables. Use with care!"))
  108. return m