Fix broken repository link in target/makeccs
[librecmc/librecmc.git] / package / luci / applications / luci-app-firewall / luasrc / model / cbi / firewall / rule-details.lua
1 -- Copyright 2008 Steven Barth <steven@midlink.org>
2 -- Copyright 2010-2012 Jo-Philipp Wich <jow@openwrt.org>
3 -- Licensed to the public under the Apache License 2.0.
4 local dsp = require "luci.dispatcher"
5 local ft = require "luci.tools.firewall"
6 local nw = require "luci.model.network"
7 local m, s, o, v, _
8
9 arg[1] = arg[1] or ""
10
11 m = Map("firewall",
12         translate("Firewall - Traffic Rules"),
13         translate("This page allows you to change advanced properties of the \
14                    traffic rule entry, such as matched source and destination \
15                            hosts."))
16
17 m.redirect = dsp.build_url("admin/network/firewall/rules")
18
19 nw.init(m.uci)
20
21 local rule_type = m.uci:get("firewall", arg[1])
22 if rule_type == "redirect" and m:get(arg[1], "target") ~= "SNAT" then
23         rule_type = nil
24 end
25
26 if not rule_type then
27         luci.http.redirect(m.redirect)
28         return
29
30 --
31 -- SNAT
32 --
33 elseif rule_type == "redirect" then
34
35         local name = m:get(arg[1], "name") or m:get(arg[1], "_name")
36         if not name or #name == 0 then
37                 name = translate("(Unnamed SNAT)")
38         else
39                 name = "SNAT %s" % name
40         end
41
42         m.title = "%s - %s" %{ translate("Firewall - Traffic Rules"), name }
43
44         s = m:section(NamedSection, arg[1], "redirect", "")
45         s.anonymous = true
46         s.addremove = false
47
48
49         ft.opt_enabled(s, Button)
50         ft.opt_name(s, Value, translate("Name"))
51
52
53         o = s:option(Value, "proto",
54                 translate("Protocol"),
55                 translate("You may specify multiple by selecting \"-- custom --\" and \
56                            then entering protocols separated by space."))
57
58         o:value("all", "All protocols")
59         o:value("tcp udp", "TCP+UDP")
60         o:value("tcp", "TCP")
61         o:value("udp", "UDP")
62         o:value("icmp", "ICMP")
63
64         function o.cfgvalue(...)
65                 local v = Value.cfgvalue(...)
66                 if not v or v == "tcpudp" then
67                         return "tcp udp"
68                 end
69                 return v
70         end
71
72
73         o = s:option(Value, "src", translate("Source zone"))
74         o.nocreate = true
75         o.default = "wan"
76         o.template = "cbi/firewall_zonelist"
77
78
79         o = s:option(Value, "src_ip", translate("Source IP address"))
80         o.rmempty = true
81         o.datatype = "neg(ipmask4)"
82         o.placeholder = translate("any")
83
84         luci.sys.net.ipv4_hints(function(ip, name)
85                 o:value(ip, "%s (%s)" %{ ip, name })
86         end)
87
88
89         o = s:option(Value, "src_port",
90                 translate("Source port"),
91                 translate("Match incoming traffic originating from the given source \
92                         port or port range on the client host."))
93         o.rmempty = true
94         o.datatype = "neg(portrange)"
95         o.placeholder = translate("any")
96
97         o:depends("proto", "tcp")
98         o:depends("proto", "udp")
99         o:depends("proto", "tcp udp")
100         o:depends("proto", "tcpudp")
101
102         o = s:option(Value, "dest", translate("Destination zone"))
103         o.nocreate = true
104         o.default = "lan"
105         o.template = "cbi/firewall_zonelist"
106
107
108         o = s:option(Value, "dest_ip", translate("Destination IP address"))
109         o.datatype = "neg(ipmask4)"
110
111         luci.sys.net.ipv4_hints(function(ip, name)
112                 o:value(ip, "%s (%s)" %{ ip, name })
113         end)
114
115
116         o = s:option(Value, "dest_port",
117                 translate("Destination port"),
118                 translate("Match forwarded traffic to the given destination port or \
119                         port range."))
120
121         o.rmempty = true
122         o.placeholder = translate("any")
123         o.datatype = "neg(portrange)"
124
125         o:depends("proto", "tcp")
126         o:depends("proto", "udp")
127         o:depends("proto", "tcp udp")
128         o:depends("proto", "tcpudp")
129
130         o = s:option(Value, "src_dip",
131                 translate("SNAT IP address"),
132                 translate("Rewrite matched traffic to the given address."))
133         o.rmempty = false
134         o.datatype = "ip4addr"
135
136         for _, v in ipairs(nw:get_interfaces()) do
137                 local a
138                 for _, a in ipairs(v:ipaddrs()) do
139                         o:value(a:host():string(), '%s (%s)' %{
140                                 a:host():string(), v:shortname()
141                         })
142                 end
143         end
144
145
146         o = s:option(Value, "src_dport", translate("SNAT port"),
147                 translate("Rewrite matched traffic to the given source port. May be \
148                         left empty to only rewrite the IP address."))
149         o.datatype = "portrange"
150         o.rmempty = true
151         o.placeholder = translate('Do not rewrite')
152
153         o:depends("proto", "tcp")
154         o:depends("proto", "udp")
155         o:depends("proto", "tcp udp")
156         o:depends("proto", "tcpudp")
157
158         s:option(Value, "extra",
159                 translate("Extra arguments"),
160                 translate("Passes additional arguments to iptables. Use with care!"))
161
162
163 --
164 -- Rule
165 --
166 else
167         local name = m:get(arg[1], "name") or m:get(arg[1], "_name")
168         if not name or #name == 0 then
169                 name = translate("(Unnamed Rule)")
170         end
171
172         m.title = "%s - %s" %{ translate("Firewall - Traffic Rules"), name }
173
174
175         s = m:section(NamedSection, arg[1], "rule", "")
176         s.anonymous = true
177         s.addremove = false
178
179         ft.opt_enabled(s, Button)
180         ft.opt_name(s, Value, translate("Name"))
181
182
183         o = s:option(ListValue, "family", translate("Restrict to address family"))
184         o.rmempty = true
185         o:value("", translate("IPv4 and IPv6"))
186         o:value("ipv4", translate("IPv4 only"))
187         o:value("ipv6", translate("IPv6 only"))
188
189
190         o = s:option(Value, "proto", translate("Protocol"))
191         o:value("all", translate("Any"))
192         o:value("tcp udp", "TCP+UDP")
193         o:value("tcp", "TCP")
194         o:value("udp", "UDP")
195         o:value("icmp", "ICMP")
196
197         function o.cfgvalue(...)
198                 local v = Value.cfgvalue(...)
199                 if not v or v == "tcpudp" then
200                         return "tcp udp"
201                 end
202                 return v
203         end
204
205
206         o = s:option(DropDown, "icmp_type", translate("Match ICMP type"))
207         o.multiple = true
208         o.display = 10
209         o.dropdown = 10
210         o.custom = true
211         o.cast = "table"
212
213         o:value("", "any")
214         o:value("echo-reply")
215         o:value("destination-unreachable")
216         o:value("network-unreachable")
217         o:value("host-unreachable")
218         o:value("protocol-unreachable")
219         o:value("port-unreachable")
220         o:value("fragmentation-needed")
221         o:value("source-route-failed")
222         o:value("network-unknown")
223         o:value("host-unknown")
224         o:value("network-prohibited")
225         o:value("host-prohibited")
226         o:value("TOS-network-unreachable")
227         o:value("TOS-host-unreachable")
228         o:value("communication-prohibited")
229         o:value("host-precedence-violation")
230         o:value("precedence-cutoff")
231         o:value("source-quench")
232         o:value("redirect")
233         o:value("network-redirect")
234         o:value("host-redirect")
235         o:value("TOS-network-redirect")
236         o:value("TOS-host-redirect")
237         o:value("echo-request")
238         o:value("router-advertisement")
239         o:value("router-solicitation")
240         o:value("time-exceeded")
241         o:value("ttl-zero-during-transit")
242         o:value("ttl-zero-during-reassembly")
243         o:value("parameter-problem")
244         o:value("ip-header-bad")
245         o:value("required-option-missing")
246         o:value("timestamp-request")
247         o:value("timestamp-reply")
248         o:value("address-mask-request")
249         o:value("address-mask-reply")
250
251         o:depends("proto", "icmp")
252
253
254         o = s:option(Value, "src", translate("Source zone"))
255         o.nocreate = true
256         o.allowany = true
257         o.allowlocal = "src"
258         o.template = "cbi/firewall_zonelist"
259
260
261         o = s:option(Value, "src_mac", translate("Source MAC address"))
262         o.datatype = "list(macaddr)"
263         o.placeholder = translate("any")
264
265         luci.sys.net.mac_hints(function(mac, name)
266                 o:value(mac, "%s (%s)" %{ mac, name })
267         end)
268
269
270         o = s:option(Value, "src_ip", translate("Source address"))
271         o.datatype = "list(neg(ipmask))"
272         o.placeholder = translate("any")
273
274         luci.sys.net.ipv4_hints(function(ip, name)
275                 o:value(ip, "%s (%s)" %{ ip, name })
276         end)
277
278
279         o = s:option(Value, "src_port", translate("Source port"))
280         o.datatype = "list(neg(portrange))"
281         o.placeholder = translate("any")
282
283         o:depends("proto", "tcp")
284         o:depends("proto", "udp")
285         o:depends("proto", "tcp udp")
286         o:depends("proto", "tcpudp")
287
288         o = s:option(Value, "dest_local", translate("Output zone"))
289         o.nocreate = true
290         o.allowany = true
291         o.template = "cbi/firewall_zonelist"
292         o.alias = "dest"
293         o:depends("src", "")
294
295         o = s:option(Value, "dest_remote", translate("Destination zone"))
296         o.nocreate = true
297         o.allowany = true
298         o.allowlocal = true
299         o.template = "cbi/firewall_zonelist"
300         o.alias = "dest"
301         o:depends({["src"] = "", ["!reverse"] = true})
302
303
304         o = s:option(Value, "dest_ip", translate("Destination address"))
305         o.datatype = "list(neg(ipmask))"
306         o.placeholder = translate("any")
307
308         luci.sys.net.ipv4_hints(function(ip, name)
309                 o:value(ip, "%s (%s)" %{ ip, name })
310         end)
311
312
313         o = s:option(Value, "dest_port", translate("Destination port"))
314         o.datatype = "list(neg(portrange))"
315         o.placeholder = translate("any")
316
317         o:depends("proto", "tcp")
318         o:depends("proto", "udp")
319         o:depends("proto", "tcp udp")
320         o:depends("proto", "tcpudp")
321
322         o = s:option(ListValue, "target", translate("Action"))
323         o.default = "ACCEPT"
324         o:value("DROP", translate("drop"))
325         o:value("ACCEPT", translate("accept"))
326         o:value("REJECT", translate("reject"))
327         o:value("NOTRACK", translate("don't track"))
328
329
330         s:option(Value, "extra",
331                 translate("Extra arguments"),
332                 translate("Passes additional arguments to iptables. Use with care!"))
333 end
334
335 o = s:option(DropDown, "weekdays", translate("Week Days"))
336 o.multiple = true
337 o.display = 5
338 o:value("Sun", translate("Sunday"))
339 o:value("Mon", translate("Monday"))
340 o:value("Tue", translate("Tuesday"))
341 o:value("Wed", translate("Wednesday"))
342 o:value("Thu", translate("Thursday"))
343 o:value("Fri", translate("Friday"))
344 o:value("Sat", translate("Saturday"))
345
346 o = s:option(DropDown, "monthdays", translate("Month Days"))
347 o.multiple = true
348 o.display = 15
349 for i = 1,31 do
350         o:value(translate(i))
351 end
352
353 o = s:option(Value, "start_time", translate("Start Time (hh:mm:ss)"))
354 o.datatype = "timehhmmss"
355 o = s:option(Value, "stop_time", translate("Stop Time (hh:mm:ss)"))
356 o.datatype = "timehhmmss"
357 o = s:option(Value, "start_date", translate("Start Date (yyyy-mm-dd)"))
358 o.datatype = "dateyyyymmdd"
359 o = s:option(Value, "stop_date", translate("Stop Date (yyyy-mm-dd)"))
360 o.datatype = "dateyyyymmdd"
361
362 o = s:option(Flag, "utc_time", translate("Time in UTC"))
363 o.default = o.disabled
364
365 return m