1 -- Copyright 2008 Steven Barth <steven@midlink.org>
2 -- Copyright 2010-2011 Jo-Philipp Wich <jow@openwrt.org>
3 -- Licensed to the public under the Apache License 2.0.
5 local nw = require "luci.model.network"
6 local fw = require "luci.model.firewall"
7 local ds = require "luci.dispatcher"
8 local ut = require "luci.util"
11 local s, name, net, family, msrc, mdest, log, lim
15 m = Map("firewall", translate("Firewall - Zone Settings"))
16 m.redirect = luci.dispatcher.build_url("admin/network/firewall/zones")
22 local zone = fw:get_zone(arg[1])
24 luci.http.redirect(ds.build_url("admin/network/firewall/zones"))
27 m.title = "%s - %s" %{
28 translate("Firewall - Zone Settings"),
29 translatef("Zone %q", zone:name() or "?")
34 s = m:section(NamedSection, zone.sid, "zone",
35 translatef("Zone %q", zone:name()),
36 translatef("This section defines common properties of %q. \
37 The <em>input</em> and <em>output</em> options set the default \
38 policies for traffic entering and leaving this zone while the \
39 <em>forward</em> option describes the policy for forwarded traffic \
40 between different networks within the zone. \
41 <em>Covered networks</em> specifies which available networks are \
42 members of this zone.", zone:name()))
47 m.on_commit = function(map)
48 local zone = fw:get_zone(arg[1])
56 s:tab("general", translate("General Settings"))
57 s:tab("advanced", translate("Advanced Settings"))
60 name = s:taboption("general", Value, "name", translate("Name"))
62 name.forcewrite = true
63 name.datatype = "and(uciname,maxlength(11))"
65 function name.write(self, section, value)
66 if zone:name() ~= value then
67 fw:rename_zone(zone:name(), value)
74 s:taboption("general", ListValue, "input", translate("Input")),
75 s:taboption("general", ListValue, "output", translate("Output")),
76 s:taboption("general", ListValue, "forward", translate("Forward"))
79 for i, v in ipairs(p) do
80 v:value("REJECT", translate("reject"))
81 v:value("DROP", translate("drop"))
82 v:value("ACCEPT", translate("accept"))
85 s:taboption("general", Flag, "masq", translate("Masquerading"))
86 s:taboption("general", Flag, "mtu_fix", translate("MSS clamping"))
88 net = s:taboption("general", Value, "network", translate("Covered networks"))
89 net.template = "cbi/network_netlist"
90 net.widget = "checkbox"
93 function net.formvalue(self, section)
94 return Value.formvalue(self, section) or "-"
97 function net.cfgvalue(self, section)
98 return Value.cfgvalue(self, section) or name:cfgvalue(section)
101 function net.write(self, section, value)
102 zone:clear_networks()
105 for n in ut.imatch(value) do
111 family = s:taboption("advanced", ListValue, "family",
112 translate("Restrict to address family"))
114 family.rmempty = true
115 family:value("", translate("IPv4 and IPv6"))
116 family:value("ipv4", translate("IPv4 only"))
117 family:value("ipv6", translate("IPv6 only"))
119 msrc = s:taboption("advanced", DynamicList, "masq_src",
120 translate("Restrict Masquerading to given source subnets"))
123 msrc.datatype = "list(neg(or(uciname,hostname,ipmask4)))"
124 msrc.placeholder = "0.0.0.0/0"
125 msrc:depends("family", "")
126 msrc:depends("family", "ipv4")
128 mdest = s:taboption("advanced", DynamicList, "masq_dest",
129 translate("Restrict Masquerading to given destination subnets"))
131 mdest.optional = true
132 mdest.datatype = "list(neg(or(uciname,hostname,ipmask4)))"
133 mdest.placeholder = "0.0.0.0/0"
134 mdest:depends("family", "")
135 mdest:depends("family", "ipv4")
137 s:taboption("advanced", Flag, "conntrack",
138 translate("Force connection tracking"))
140 log = s:taboption("advanced", Flag, "log",
141 translate("Enable logging on this zone"))
146 lim = s:taboption("advanced", Value, "log_limit",
147 translate("Limit log messages"))
149 lim.placeholder = "10/minute"
150 lim:depends("log", "1")
153 s2 = m:section(NamedSection, zone.sid, "fwd_out",
154 translate("Inter-Zone Forwarding"),
155 translatef("The options below control the forwarding policies between \
156 this zone (%s) and other zones. <em>Destination zones</em> cover \
157 forwarded traffic <strong>originating from %q</strong>. \
158 <em>Source zones</em> match forwarded traffic from other zones \
159 <strong>targeted at %q</strong>. The forwarding rule is \
160 <em>unidirectional</em>, e.g. a forward from lan to wan does \
161 <em>not</em> imply a permission to forward from wan to lan as well.",
162 zone:name(), zone:name(), zone:name()
166 out = s2:option(Value, "out",
167 translate("Allow forward to <em>destination zones</em>:"))
170 out.widget = "checkbox"
171 out.exclude = zone:name()
172 out.template = "cbi/firewall_zonelist"
174 inp = s2:option(Value, "in",
175 translate("Allow forward from <em>source zones</em>:"))
178 inp.widget = "checkbox"
179 inp.exclude = zone:name()
180 inp.template = "cbi/firewall_zonelist"
182 function out.cfgvalue(self, section)
185 for _, f in ipairs(zone:get_forwardings_by("src")) do
188 return table.concat(v, " ")
191 function inp.cfgvalue(self, section)
194 for _, f in ipairs(zone:get_forwardings_by("dest")) do
200 function out.formvalue(self, section)
201 return Value.formvalue(self, section) or "-"
204 function inp.formvalue(self, section)
205 return Value.formvalue(self, section) or "-"
208 function out.write(self, section, value)
209 zone:del_forwardings_by("src")
212 for f in ut.imatch(value) do
213 zone:add_forwarding_to(f)
217 function inp.write(self, section, value)
218 zone:del_forwardings_by("dest")
221 for f in ut.imatch(value) do
222 zone:add_forwarding_from(f)