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