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