Project

General

Profile

Download (72.1 KB) Statistics
| Branch: | Tag: | Revision:
1 5ba18897 Scott Ullrich
<?php
2 b46bfcf5 Bill Marquette
/* $Id$ */
3 5b237745 Scott Ullrich
/*
4 bdb7d6e7 Scott Ullrich
	firewall_rules_edit.php
5 e4cabb75 Scott Ullrich
	part of pfSense (http://www.pfsense.com)
6
        Copyright (C) 2005 Scott Ullrich (sullrich@gmail.com)
7 5ba18897 Scott Ullrich
8 e4cabb75 Scott Ullrich
	originally part of m0n0wall (http://m0n0.ch/wall)
9 bdb7d6e7 Scott Ullrich
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
10
	All rights reserved.
11 5ba18897 Scott Ullrich
12 bdb7d6e7 Scott Ullrich
	Redistribution and use in source and binary forms, with or without
13
	modification, are permitted provided that the following conditions are met:
14 5ba18897 Scott Ullrich
15 bdb7d6e7 Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
16
	   this list of conditions and the following disclaimer.
17 5ba18897 Scott Ullrich
18 bdb7d6e7 Scott Ullrich
	2. Redistributions in binary form must reproduce the above copyright
19
	   notice, this list of conditions and the following disclaimer in the
20
	   documentation and/or other materials provided with the distribution.
21 5ba18897 Scott Ullrich
22 bdb7d6e7 Scott Ullrich
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
23
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
24
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
	POSSIBILITY OF SUCH DAMAGE.
32 5b237745 Scott Ullrich
*/
33 7ac5a4cb Scott Ullrich
/*
34
	pfSense_MODULE:	filter
35
*/
36 5b237745 Scott Ullrich
37 6b07c15a Matthew Grooms
##|+PRIV
38
##|*IDENT=page-firewall-rules-edit
39
##|*NAME=Firewall: Rules: Edit page
40
##|*DESCR=Allow access to the 'Firewall: Rules: Edit' page.
41
##|*MATCH=firewall_rules_edit.php*
42
##|-PRIV
43
44 5b237745 Scott Ullrich
require("guiconfig.inc");
45 1a03cf69 Scott Ullrich
require("filter.inc");
46
require("shaper.inc");
47 5b237745 Scott Ullrich
48 e5e5ba51 Vinicius Coque
$specialsrcdst = explode(" ", "any pptp pppoe l2tp openvpn");
49 3331a640 Ermal Lu?i
$ifdisp = get_configured_interface_with_descr();
50 679d21bb Ermal Lu?i
foreach ($ifdisp as $kif => $kdescr) {
51 3331a640 Ermal Lu?i
	$specialsrcdst[] = "{$kif}";
52
	$specialsrcdst[] = "{$kif}ip";
53 679d21bb Ermal Lu?i
}
54 5b237745 Scott Ullrich
55
if (!is_array($config['filter']['rule'])) {
56
	$config['filter']['rule'] = array();
57
}
58
filter_rules_sort();
59
$a_filter = &$config['filter']['rule'];
60
61
$id = $_GET['id'];
62
if (is_numeric($_POST['id']))
63
	$id = $_POST['id'];
64 5ba18897 Scott Ullrich
65 5b237745 Scott Ullrich
$after = $_GET['after'];
66
67
if (isset($_POST['after']))
68
	$after = $_POST['after'];
69
70
if (isset($_GET['dup'])) {
71
	$id = $_GET['dup'];
72
	$after = $_GET['dup'];
73
}
74
75
if (isset($id) && $a_filter[$id]) {
76
	$pconfig['interface'] = $a_filter[$id]['interface'];
77 5ba18897 Scott Ullrich
78 b9e28d57 unknown
	if (isset($a_filter[$id]['id']))
79
		$pconfig['ruleid'] = $a_filter[$id]['id'];
80
81 ba1d9714 jim-p
	if ( isset($a_filter[$id]['created']) && is_array($a_filter[$id]['created']) )
82
		$pconfig['created'] = $a_filter[$id]['created'];
83
84
	if ( isset($a_filter[$id]['updated']) && is_array($a_filter[$id]['updated']) )
85
		$pconfig['updated'] = $a_filter[$id]['updated'];
86
87 5b237745 Scott Ullrich
	if (!isset($a_filter[$id]['type']))
88
		$pconfig['type'] = "pass";
89
	else
90
		$pconfig['type'] = $a_filter[$id]['type'];
91 5ba18897 Scott Ullrich
92 4633edc2 Ermal Luçi
	if (isset($a_filter[$id]['floating']) || $if == "FloatingRules") {
93 661aed33 Ermal Luçi
		$pconfig['floating'] = $a_filter[$id]['floating'];
94
		if (isset($a_filter[$id]['interface']) && $a_filter[$id]['interface'] <> "") 
95
			$pconfig['interface'] = $a_filter[$id]['interface'];
96
	}
97
	
98
	if (isset($a_filter['floating'])) 
99
		$pconfig['floating'] = "yes";
100
101
	if (isset($a_filter[$id]['direction']))
102
                $pconfig['direction'] = $a_filter[$id]['direction'];
103
104 1306c7dd Seth Mos
	if (isset($a_filter[$id]['ipprotocol']))
105
                $pconfig['ipprotocol'] = $a_filter[$id]['ipprotocol'];
106
107 5b237745 Scott Ullrich
	if (isset($a_filter[$id]['protocol']))
108
		$pconfig['proto'] = $a_filter[$id]['protocol'];
109
	else
110
		$pconfig['proto'] = "any";
111 5ba18897 Scott Ullrich
112 5b237745 Scott Ullrich
	if ($a_filter[$id]['protocol'] == "icmp")
113
		$pconfig['icmptype'] = $a_filter[$id]['icmptype'];
114 5ba18897 Scott Ullrich
115 5b237745 Scott Ullrich
	address_to_pconfig($a_filter[$id]['source'], $pconfig['src'],
116
		$pconfig['srcmask'], $pconfig['srcnot'],
117
		$pconfig['srcbeginport'], $pconfig['srcendport']);
118 5ba18897 Scott Ullrich
119 8be60f21 Scott Ullrich
	if($a_filter[$id]['os'] <> "")
120
		$pconfig['os'] = $a_filter[$id]['os'];
121 e33c8694 Bill Marquette
122 5b237745 Scott Ullrich
	address_to_pconfig($a_filter[$id]['destination'], $pconfig['dst'],
123
		$pconfig['dstmask'], $pconfig['dstnot'],
124
		$pconfig['dstbeginport'], $pconfig['dstendport']);
125
126 c5fc1b2e Ermal Luçi
	if ($a_filter[$id]['dscp'] <> "")
127
		$pconfig['dscp'] = $a_filter[$id]['dscp'];
128
129 5b237745 Scott Ullrich
	$pconfig['disabled'] = isset($a_filter[$id]['disabled']);
130
	$pconfig['log'] = isset($a_filter[$id]['log']);
131
	$pconfig['descr'] = $a_filter[$id]['descr'];
132 8c84fe43 Scott Ullrich
133 b8ed2a11 Ermal
	if (isset($a_filter[$id]['tcpflags_any']))
134
		$pconfig['tcpflags_any'] = true;
135
	else {
136
		if (isset($a_filter[$id]['tcpflags1']) && $a_filter[$id]['tcpflags1'] <> "") 
137
			$pconfig['tcpflags1'] = $a_filter[$id]['tcpflags1'];
138
		if (isset($a_filter[$id]['tcpflags2']) && $a_filter[$id]['tcpflags2'] <> "") 
139
			$pconfig['tcpflags2'] = $a_filter[$id]['tcpflags2'];
140
	}
141
142 5c1f5584 Ermal Luçi
	if (isset($a_filter[$id]['tag']) && $a_filter[$id]['tag'] <> "") 
143 661aed33 Ermal Luçi
		$pconfig['tag'] = $a_filter[$id]['tag'];
144 b6494651 Ermal Lu?i
	if (isset($a_filter[$id]['tagged']) && $a_filter[$id]['tagged'] <> "")
145 661aed33 Ermal Luçi
        	$pconfig['tagged'] = $a_filter[$id]['tagged'];
146
	if (isset($a_filter[$id]['quick']) && $a_filter[$id]['quick'])
147
		$pconfig['quick'] = $a_filter[$id]['quick'];
148 775ccea3 Ermal Luci
	if (isset($a_filter[$id]['allowopts']))
149
		$pconfig['allowopts'] = true;
150 19757916 Ermal Lu?i
	if (isset($a_filter[$id]['disablereplyto']))
151
		$pconfig['disablereplyto'] = true;
152 661aed33 Ermal Luçi
153 ed08ef3e Scott Ullrich
	/* advanced */
154 a56b2fa0 pierrepomes
	$pconfig['max'] = $a_filter[$id]['max'];
155 f1c49ff4 Scott Ullrich
	$pconfig['max-src-nodes'] = $a_filter[$id]['max-src-nodes'];
156 26dd6a54 pierrepomes
	$pconfig['max-src-conn'] = $a_filter[$id]['max-src-conn'];
157 f1c49ff4 Scott Ullrich
	$pconfig['max-src-states'] = $a_filter[$id]['max-src-states'];
158
	$pconfig['statetype'] = $a_filter[$id]['statetype'];
159 5ba18897 Scott Ullrich
	$pconfig['statetimeout'] = $a_filter[$id]['statetimeout'];
160 8c84fe43 Scott Ullrich
161 f1c49ff4 Scott Ullrich
	/* advanced - nosync */
162 8c84fe43 Scott Ullrich
	$pconfig['nosync'] = isset($a_filter[$id]['nosync']);
163 10f21e70 Scott Ullrich
164 ed08ef3e Scott Ullrich
	/* advanced - new connection per second banning*/
165
	$pconfig['max-src-conn-rate'] = $a_filter[$id]['max-src-conn-rate'];
166
	$pconfig['max-src-conn-rates'] = $a_filter[$id]['max-src-conn-rates'];
167 5ba18897 Scott Ullrich
168 e5980370 Scott Ullrich
	/* Multi-WAN next-hop support */
169 c98ddde2 Bill Marquette
	$pconfig['gateway'] = $a_filter[$id]['gateway'];
170 615b27bc Scott Dale
	
171 197bfe96 Ermal Luçi
	/* Shaper support */
172
	$pconfig['defaultqueue'] = $a_filter[$id]['defaultqueue'];
173
	$pconfig['ackqueue'] = $a_filter[$id]['ackqueue'];
174 a5fd67e1 Ermal Luçi
	$pconfig['dnpipe'] = $a_filter[$id]['dnpipe'];
175
	$pconfig['pdnpipe'] = $a_filter[$id]['pdnpipe'];
176 7e50413c Ermal Luçi
	$pconfig['l7container'] = $a_filter[$id]['l7container'];
177 197bfe96 Ermal Luçi
178 615b27bc Scott Dale
	//schedule support
179
	$pconfig['sched'] = $a_filter[$id]['sched'];
180 1346306c Ermal
	$pconfig['vlanprio'] = $a_filter[$id]['vlanprio'];
181
	$pconfig['vlanprioset'] = $a_filter[$id]['vlanprioset'];
182 35c9cd44 Erik Fonnesbeck
	if (!isset($_GET['dup']))
183
		$pconfig['associated-rule-id'] = $a_filter[$id]['associated-rule-id'];
184 c98ddde2 Bill Marquette
185 5b237745 Scott Ullrich
} else {
186
	/* defaults */
187 a23d7248 Scott Ullrich
	if ($_GET['if'])
188
		$pconfig['interface'] = $_GET['if'];
189 e5e5ba51 Vinicius Coque
	$pconfig['type'] = "pass";
190
	$pconfig['src'] = "any";
191
	$pconfig['dst'] = "any";
192 5b237745 Scott Ullrich
}
193 a133c803 Phil Davis
/* Allow the FloatingRules to work */
194 72320b88 Ermal Luçi
$if = $pconfig['interface'];
195 5b237745 Scott Ullrich
196
if (isset($_GET['dup']))
197
	unset($id);
198
199 85a236e9 Ermal
read_altq_config(); /* XXX: */
200
$qlist =& get_unique_queue_list();
201
read_dummynet_config(); /* XXX: */
202
$dnqlist =& get_unique_dnqueue_list();
203
read_layer7_config();
204
$l7clist =& get_l7_unique_list();
205
206 5b237745 Scott Ullrich
if ($_POST) {
207 99bdb17e Seth Mos
	unset($input_errors);
208 87f0be87 Chris Buechler
209 48a27d4f Erik Fonnesbeck
	if( isset($a_filter[$id]['associated-rule-id']) ) {
210
		$_POST['proto'] = $pconfig['proto'];
211
		if ($pconfig['proto'] == "icmp")
212
			$_POST['icmptype'] = $pconfig['icmptype'];
213
	}
214
215 99bdb17e Seth Mos
	if (($_POST['ipprotocol'] <> "") && ($_POST['gateway'] <> "")) {
216 ee8c34f4 smos
		$a_gatewaygroups = return_gateway_groups_array();
217 a133c803 Phil Davis
		if(is_array($config['gateways']['gateway_group'])) {
218
			foreach($config['gateways']['gateway_group'] as $gw_group) {
219
				if($gw_group['name'] == $_POST['gateway']) {
220
					$family = $a_gatewaygroups[$_POST['gateway']]['ipprotocol'];
221
					if($_POST['ipprotocol'] == $family) {
222
						continue;
223
					}
224
					if(($_POST['ipprotocol'] == "inet46") && ($_POST['ipprotocol'] != $family)) {
225
						$input_errors[] = gettext("You can not assign a gateway to a rule that applies to IPv4 and IPv6");
226
					}
227
					if(($_POST['ipprotocol'] == "inet6") && ($_POST['ipprotocol'] != $family)) {
228
						$input_errors[] = gettext("You can not assign a IPv4 gateway group on IPv6 Address Family rule");
229
					}
230
					if(($_POST['ipprotocol'] == "inet") && ($_POST['ipprotocol'] != $family)) {
231
						$input_errors[] = gettext("You can not assign a IPv6 gateway group on IPv4 Address Family rule");
232
					}
233 99bdb17e Seth Mos
				}
234
			}
235
		}
236
	}
237 9dfd60db Seth Mos
	if (($_POST['ipprotocol'] <> "") && ($_POST['gateway'] <> "") && (is_ipaddr(lookup_gateway_ip_by_name($_POST['gateway'])))) {
238 05a4cebd smos
		if(($_POST['ipprotocol'] == "inet46") && ($_POST['gateway'] <> "")) {
239
			$input_errors[] = gettext("You can not assign a gateway to a rule that applies to IPv4 and IPv6");
240
		}
241 99bdb17e Seth Mos
		if(($_POST['ipprotocol'] == "inet6") && (!is_ipaddrv6(lookup_gateway_ip_by_name($_POST['gateway'])))) {
242
			$input_errors[] = gettext("You can not assign the IPv4 Gateway to a IPv6 Filter rule");
243
		}
244
		if(($_POST['ipprotocol'] == "inet") && (!is_ipaddrv4(lookup_gateway_ip_by_name($_POST['gateway'])))) {
245
			$input_errors[] = gettext("You can not assign the IPv6 Gateway to a IPv4 Filter rule");
246
		}
247
	}
248
249 05a4cebd smos
	if (($_POST['proto'] != "tcp") && ($_POST['proto'] != "udp") && ($_POST['proto'] != "tcp/udp") && ($_POST['proto'] != "icmp")) {
250
		if($_POST['ipprotocol'] == "inet46")
251
			$input_errors[] =  gettext("You can not assign a protocol other then ICMP, TCP, UDP or TCP/UDP to a rule that applies to IPv4 and IPv6");
252
	}
253
	if (($_POST['proto'] == "icmp") && ($_POST['icmptype'] <> "")){
254
		if($_POST['ipprotocol'] == "inet46")
255
			$input_errors[] =  gettext("You can not assign a ICMP type to a rule that applies to IPv4 and IPv6");
256
	}
257
258 5b237745 Scott Ullrich
	if (($_POST['proto'] != "tcp") && ($_POST['proto'] != "udp") && ($_POST['proto'] != "tcp/udp")) {
259
		$_POST['srcbeginport'] = 0;
260
		$_POST['srcendport'] = 0;
261
		$_POST['dstbeginport'] = 0;
262
		$_POST['dstendport'] = 0;
263
	} else {
264
		if ($_POST['srcbeginport_cust'] && !$_POST['srcbeginport'])
265 90f90934 Cristian Feldman
			$_POST['srcbeginport'] = trim($_POST['srcbeginport_cust']);
266 5b237745 Scott Ullrich
		if ($_POST['srcendport_cust'] && !$_POST['srcendport'])
267 90f90934 Cristian Feldman
			$_POST['srcendport'] = trim($_POST['srcendport_cust']);
268 5b237745 Scott Ullrich
		if ($_POST['srcbeginport'] == "any") {
269
			$_POST['srcbeginport'] = 0;
270
			$_POST['srcendport'] = 0;
271 5ba18897 Scott Ullrich
		} else {
272 5b237745 Scott Ullrich
			if (!$_POST['srcendport'])
273
				$_POST['srcendport'] = $_POST['srcbeginport'];
274
		}
275
		if ($_POST['srcendport'] == "any")
276
			$_POST['srcendport'] = $_POST['srcbeginport'];
277 5ba18897 Scott Ullrich
278 5b237745 Scott Ullrich
		if ($_POST['dstbeginport_cust'] && !$_POST['dstbeginport'])
279 90f90934 Cristian Feldman
			$_POST['dstbeginport'] = trim($_POST['dstbeginport_cust']);
280 5b237745 Scott Ullrich
		if ($_POST['dstendport_cust'] && !$_POST['dstendport'])
281 90f90934 Cristian Feldman
			$_POST['dstendport'] = trim($_POST['dstendport_cust']);
282 5ba18897 Scott Ullrich
283 5b237745 Scott Ullrich
		if ($_POST['dstbeginport'] == "any") {
284
			$_POST['dstbeginport'] = 0;
285
			$_POST['dstendport'] = 0;
286 5ba18897 Scott Ullrich
		} else {
287 5b237745 Scott Ullrich
			if (!$_POST['dstendport'])
288
				$_POST['dstendport'] = $_POST['dstbeginport'];
289
		}
290
		if ($_POST['dstendport'] == "any")
291 5ba18897 Scott Ullrich
			$_POST['dstendport'] = $_POST['dstbeginport'];
292 5b237745 Scott Ullrich
	}
293 5ba18897 Scott Ullrich
294 5b237745 Scott Ullrich
	if (is_specialnet($_POST['srctype'])) {
295
		$_POST['src'] = $_POST['srctype'];
296
		$_POST['srcmask'] = 0;
297
	} else if ($_POST['srctype'] == "single") {
298 507aa90a Renato Botelho
		if (is_ipaddrv6($_POST['src']))
299
			$_POST['srcmask'] = 128;
300
		else
301
			$_POST['srcmask'] = 32;
302 5b237745 Scott Ullrich
	}
303
	if (is_specialnet($_POST['dsttype'])) {
304
		$_POST['dst'] = $_POST['dsttype'];
305
		$_POST['dstmask'] = 0;
306
	}  else if ($_POST['dsttype'] == "single") {
307 507aa90a Renato Botelho
		if (is_ipaddrv6($_POST['dst']))
308
			$_POST['dstmask'] = 128;
309
		else
310
			$_POST['dstmask'] = 32;
311 5b237745 Scott Ullrich
	}
312 5ba18897 Scott Ullrich
313 5b237745 Scott Ullrich
	$pconfig = $_POST;
314
315
	/* input validation */
316 1122a892 Erik Fonnesbeck
	$reqdfields = explode(" ", "type proto");
317
	if ( isset($a_filter[$id]['associated-rule-id'])===false ) {
318 48a27d4f Erik Fonnesbeck
		$reqdfields[] = "src";
319
		$reqdfields[] = "dst";
320 1122a892 Erik Fonnesbeck
	}
321
	$reqdfieldsn = explode(",", "Type,Protocol");
322
	if ( isset($a_filter[$id]['associated-rule-id'])===false ) {
323
		$reqdfieldsn[] = "Source";
324 473d0ff0 pierrepomes
		$reqdfieldsn[] = "Destination";
325 1122a892 Erik Fonnesbeck
	}
326 5b237745 Scott Ullrich
327 452ade89 Bill Marquette
	if($_POST['statetype'] == "modulate state" or $_POST['statetype'] == "synproxy state") {
328 c22767b1 Bill Marquette
		if( $_POST['proto'] != "tcp" )
329 11d2c529 Rafael Lucas
			$input_errors[] = sprintf(gettext("%s is only valid with protocol tcp."),$_POST['statetype']);
330 452ade89 Bill Marquette
		if(($_POST['statetype'] == "synproxy state") && ($_POST['gateway'] != ""))
331 11d2c529 Rafael Lucas
			$input_errors[] = sprintf(gettext("%s is only valid if the gateway is set to 'default'."),$_POST['statetype']);
332 452ade89 Bill Marquette
	}
333 10f7933f Chris Buechler
        
334 1122a892 Erik Fonnesbeck
	if ( isset($a_filter[$id]['associated-rule-id'])===false &&
335
	(!(is_specialnet($_POST['srctype']) || ($_POST['srctype'] == "single"))) ) {
336 5b237745 Scott Ullrich
		$reqdfields[] = "srcmask";
337
		$reqdfieldsn[] = "Source bit count";
338
	}
339 9b16b834 Ermal Lu?i
	if ( isset($a_filter[$id]['associated-rule-id'])===false &&
340 473d0ff0 pierrepomes
	(!(is_specialnet($_POST['dsttype']) || ($_POST['dsttype'] == "single"))) ) {
341 5b237745 Scott Ullrich
		$reqdfields[] = "dstmask";
342 11d2c529 Rafael Lucas
		$reqdfieldsn[] = gettext("Destination bit count");
343 5b237745 Scott Ullrich
	}
344 5ba18897 Scott Ullrich
345 5b237745 Scott Ullrich
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
346 5ba18897 Scott Ullrich
347 5b237745 Scott Ullrich
	if (!$_POST['srcbeginport']) {
348
		$_POST['srcbeginport'] = 0;
349
		$_POST['srcendport'] = 0;
350
	}
351
	if (!$_POST['dstbeginport']) {
352
		$_POST['dstbeginport'] = 0;
353
		$_POST['dstendport'] = 0;
354
	}
355 5ba18897 Scott Ullrich
356 9b45f821 Ermal Lu?i
	if ($_POST['srcbeginport'] && !is_portoralias($_POST['srcbeginport']))
357 11d2c529 Rafael Lucas
                $input_errors[] = sprintf(gettext("%s is not a valid start source port. It must be a port alias or integer between 1 and 65535."),$_POST['srcbeginposrt']);
358 90f90934 Cristian Feldman
	if ($_POST['srcendport'] && !is_portoralias($_POST['srcendport']))
359
			$input_errors[] = sprintf(gettext("%s  is not a valid end source port. It must be a port alias or integer between 1 and 65535."),$_POST['srcendport']);
360
	if ($_POST['dstbeginport'] && !is_portoralias($_POST['dstbeginport']))
361
			$input_errors[] = sprintf(gettext("%s is not a valid start destination port. It must be a port alias or integer between 1 and 65535."),$_POST['dstbeginport']);
362
	if ($_POST['dstendport'] && !is_portoralias($_POST['dstendport']))
363
			$input_errors[] = sprintf(gettext("%s is not a valid end destination port. It must be a port alias or integer between 1 and 65535."),$_POST['dstendport']);
364 5909b520 Evgeny Yurchenko
	if ( !$_POST['srcbeginport_cust'] && $_POST['srcendport_cust'])
365
		if (is_alias($_POST['srcendport_cust']))
366
			$input_errors[] = 'If you put port alias in Source port range to: field you must put the same port alias in from: field';
367
	if ( $_POST['srcbeginport_cust'] && $_POST['srcendport_cust']){
368
		if (is_alias($_POST['srcendport_cust']) && is_alias($_POST['srcendport_cust']) && $_POST['srcbeginport_cust'] != $_POST['srcendport_cust'])
369
			$input_errors[] = 'The same port alias must be used in Source port range from: and to: fields';
370
		if ((is_alias($_POST['srcbeginport_cust']) && (!is_alias($_POST['srcendport_cust']) && $_POST['srcendport_cust']!='')) || 
371
		    ((!is_alias($_POST['srcbeginport_cust']) && $_POST['srcbeginport_cust']!='') && is_alias($_POST['srcendport_cust']))) 
372
			$input_errors[] = 'You cannot specify numbers and port aliases at the same time in Source port range from: and to: field';
373
	}
374
	if ( !$_POST['dstbeginport_cust'] && $_POST['dstendport_cust'])
375
		if (is_alias($_POST['dstendport_cust']))
376
			$input_errors[] = 'If you put port alias in Destination port range to: field you must put the same port alias in from: field';
377
	if ( $_POST['dstbeginport_cust'] && $_POST['dstendport_cust']){
378
		if (is_alias($_POST['dstendport_cust']) && is_alias($_POST['dstendport_cust']) && $_POST['dstbeginport_cust'] != $_POST['dstendport_cust'])
379
			$input_errors[] = 'The same port alias must be used in Destination port range from: and to: fields';
380
		if ((is_alias($_POST['dstbeginport_cust']) && (!is_alias($_POST['dstendport_cust']) && $_POST['dstendport_cust']!='')) || 
381
		    ((!is_alias($_POST['dstbeginport_cust']) && $_POST['dstbeginport_cust']!='') && is_alias($_POST['dstendport_cust']))) 
382
			$input_errors[] = 'You cannot specify numbers and port aliases at the same time in Destination port range from: and to: field';
383
	}
384 5ba18897 Scott Ullrich
385 90f90934 Cristian Feldman
	if ($_POST['src'])
386
		$_POST['src'] = trim($_POST['src']);
387
	if ($_POST['dst'])
388
		$_POST['dst'] = trim($_POST['dst']);
389
390 0e5ddcd9 Scott Ullrich
	/* if user enters an alias and selects "network" then disallow. */
391
	if($_POST['srctype'] == "network") {
392
		if(is_alias($_POST['src']))
393 11d2c529 Rafael Lucas
			$input_errors[] = gettext("You must specify single host or alias for alias entries.");
394 0e5ddcd9 Scott Ullrich
	}
395
	if($_POST['dsttype'] == "network") {
396
		if(is_alias($_POST['dst']))
397 11d2c529 Rafael Lucas
			$input_errors[] = gettext("You must specify single host or alias for alias entries.");
398 0e5ddcd9 Scott Ullrich
	}
399
400 5b237745 Scott Ullrich
	if (!is_specialnet($_POST['srctype'])) {
401 1e578a7f Ermal Lu?i
		if (($_POST['src'] && !is_ipaddroralias($_POST['src']))) {
402 11d2c529 Rafael Lucas
			$input_errors[] = sprintf(gettext("%s is not a valid source IP address or alias."),$_POST['src']);
403 5b237745 Scott Ullrich
		}
404
		if (($_POST['srcmask'] && !is_numericint($_POST['srcmask']))) {
405 11d2c529 Rafael Lucas
			$input_errors[] = gettext("A valid source bit count must be specified.");
406 5b237745 Scott Ullrich
		}
407
	}
408
	if (!is_specialnet($_POST['dsttype'])) {
409 1e578a7f Ermal Lu?i
		if (($_POST['dst'] && !is_ipaddroralias($_POST['dst']))) {
410 11d2c529 Rafael Lucas
			$input_errors[] = sprintf(gettext("%s is not a valid destination IP address or alias."),$_POST['dst']);
411 5b237745 Scott Ullrich
		}
412
		if (($_POST['dstmask'] && !is_numericint($_POST['dstmask']))) {
413 11d2c529 Rafael Lucas
			$input_errors[] = gettext("A valid destination bit count must be specified.");
414 5b237745 Scott Ullrich
		}
415
	}
416 8c591d01 Seth Mos
	if((is_ipaddr($_POST['src']) && is_ipaddr($_POST['dst']))) {
417 270a2576 Seth Mos
		if(!validate_address_family($_POST['src'], $_POST['dst']))
418
			$input_errors[] = sprintf(gettext("The Source IP address %s Address Family differs from the destination %s."), $_POST['src'], $_POST['dst']);
419 4108dee8 Seth Mos
		if((is_ipaddrv6($_POST['src']) || is_ipaddrv6($_POST['dst'])) && ($_POST['ipprotocol'] == "inet"))
420
			$input_errors[] = gettext("You can not use IPv6 addresses in IPv4 rules.");
421
		if((is_ipaddrv4($_POST['src']) || is_ipaddrv4($_POST['dst'])) && ($_POST['ipprotocol'] == "inet6"))
422
			$input_errors[] = gettext("You can not use IPv4 addresses in IPv6 rules.");
423 05a4cebd smos
		if((is_ipaddr($_POST['src']) || is_ipaddr($_POST['dst'])) && ($_POST['ipprotocol'] == "inet46"))
424
			$input_errors[] = gettext("You can not use a IPv4 or IPv6 address in combined IPv4 + IPv6 rules.");
425
426 270a2576 Seth Mos
	}
427 5ba18897 Scott Ullrich
428 5b237745 Scott Ullrich
	if ($_POST['srcbeginport'] > $_POST['srcendport']) {
429
		/* swap */
430
		$tmp = $_POST['srcendport'];
431
		$_POST['srcendport'] = $_POST['srcbeginport'];
432
		$_POST['srcbeginport'] = $tmp;
433
	}
434
	if ($_POST['dstbeginport'] > $_POST['dstendport']) {
435
		/* swap */
436
		$tmp = $_POST['dstendport'];
437
		$_POST['dstendport'] = $_POST['dstbeginport'];
438
		$_POST['dstbeginport'] = $tmp;
439
	}
440 e33c8694 Bill Marquette
	if ($_POST['os'])
441
		if( $_POST['proto'] != "tcp" )
442 11d2c529 Rafael Lucas
			$input_errors[] = gettext("OS detection is only valid with protocol tcp.");
443 5b237745 Scott Ullrich
444 197bfe96 Ermal Luçi
	if ($_POST['ackqueue'] && $_POST['ackqueue'] != "none") {
445
		if ($_POST['defaultqueue'] == "none" )
446 11d2c529 Rafael Lucas
			$input_errors[] = gettext("You have to select a queue when you select an acknowledge queue too.");
447 197bfe96 Ermal Luçi
		else if ($_POST['ackqueue'] == $_POST['defaultqueue'])
448 11d2c529 Rafael Lucas
			$input_errors[] = gettext("Acknowledge queue and Queue cannot be the same.");		
449 197bfe96 Ermal Luçi
	}
450 6735d092 Ermal
	if (isset($_POST['floating']) && $_POST['pdnpipe'] != "none" && (empty($_POST['direction']) || $_POST['direction'] == "any"))
451 02d7e4a4 Ermal
		$input_errors[] = gettext("You can not use limiters in Floating rules without choosing a direction.");
452 622bd5e7 Ermal
	if (isset($_POST['floating']) && $_POST['gateway'] != "" && (empty($_POST['direction']) || $_POST['direction'] == "any"))
453 37d202a3 Ermal
		$input_errors[] = gettext("You can not use gateways in Floating rules without choosing a direction.");
454 a5fd67e1 Ermal Luçi
	if ($_POST['pdnpipe'] && $_POST['pdnpipe'] != "none") {
455
		if ($_POST['dnpipe'] == "none" )
456 11d2c529 Rafael Lucas
			$input_errors[] = gettext("You must select a queue for the In direction before selecting one for Out too.");
457 a5fd67e1 Ermal Luçi
		else if ($_POST['pdnpipe'] == $_POST['dnpipe'])
458 11d2c529 Rafael Lucas
			$input_errors[] = gettext("In and Out Queue cannot be the same.");
459 85a236e9 Ermal
		else if ($dnqlist[$_POST['pdnpipe']][0] == "?" && $dnqlist[$_POST['dnpipe']][0] <> "?")
460 11d2c529 Rafael Lucas
			$input_errors[] = gettext("You cannot select one queue and one virtual interface for IN and Out. both must be from the same type.");
461 85a236e9 Ermal
		else if ($dnqlist[$_POST['dnpipe']][0] == "?" && $dnqlist[$_POST['pdnpipe']][0] <> "?")                       
462 11d2c529 Rafael Lucas
			$input_errors[] = gettext("You cannot select one queue and one virtual interface for IN and Out. both must be from the same type.");
463 fbc75dd5 Ermal
		if ($_POST['direction'] == "out" && empty($_POST['gateway']))
464
			$input_errors[] = gettext("Please select a gateway, normaly the interface selected gateway, so the limiters work correctly");
465 a5fd67e1 Ermal Luçi
	}
466 b9e28d57 unknown
	if( !empty($_POST['ruleid']) && !ctype_digit($_POST['ruleid']))
467 11d2c529 Rafael Lucas
		$input_errors[] = gettext('ID must be an integer');
468 7e50413c Ermal Luçi
	if($_POST['l7container'] && $_POST['l7container'] != "none") {
469
		if(!($_POST['proto'] == "tcp" || $_POST['proto'] == "udp" || $_POST['proto'] == "tcp/udp"))
470 11d2c529 Rafael Lucas
			$input_errors[] = gettext("You can only select a layer7 container for TCP and/or UDP protocols");
471 3b184ca5 Ermal Lu?i
		if ($_POST['type'] <> "pass")
472 11d2c529 Rafael Lucas
			$input_errors[] = gettext("You can only select a layer7 container for Pass type rules.");
473 7e50413c Ermal Luçi
	}
474 197bfe96 Ermal Luçi
475 b8ed2a11 Ermal
	if (!$_POST['tcpflags_any']) {
476
		$settcpflags = array();
477
		$outoftcpflags = array();
478
		foreach ($tcpflags as $tcpflag) {
479
			if ($_POST['tcpflags1_' . $tcpflag] == "on")
480
				$settcpflags[] = $tcpflag;
481
			if ($_POST['tcpflags2_' . $tcpflag] == "on")
482
				$outoftcpflags[] = $tcpflag;
483
		}
484
		if (empty($outoftcpflags) && !empty($settcpflags))
485 11d2c529 Rafael Lucas
			$input_errors[] = gettext("If you specify TCP flags that should be set you should specify out of which flags as well.");
486 b8ed2a11 Ermal
	}
487
488 d65962a7 Scott Ullrich
	// Allow extending of the firewall edit page and include custom input validation 
489
	pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/input_validation");
490
491 5b237745 Scott Ullrich
	if (!$input_errors) {
492
		$filterent = array();
493 b9e28d57 unknown
		$filterent['id'] = $_POST['ruleid']>0?$_POST['ruleid']:'';
494 5b237745 Scott Ullrich
		$filterent['type'] = $_POST['type'];
495 661aed33 Ermal Luçi
		if (isset($_POST['interface'] ))
496
			$filterent['interface'] = $_POST['interface'];
497
498 1306c7dd Seth Mos
		if (isset($_POST['ipprotocol'] ))
499
			$filterent['ipprotocol'] = $_POST['ipprotocol'];
500
501 b8ed2a11 Ermal
		if ($_POST['tcpflags_any']) {
502
			$filterent['tcpflags_any'] = true;
503
		} else {
504
			$settcpflags = array();
505
			$outoftcpflags = array();
506
			foreach ($tcpflags as $tcpflag) {
507
				if ($_POST['tcpflags1_' . $tcpflag] == "on")
508
					$settcpflags[] = $tcpflag;
509
				if ($_POST['tcpflags2_' . $tcpflag] == "on")
510
					$outoftcpflags[] = $tcpflag;
511
			}
512
			if (!empty($outoftcpflags)) {
513
				$filterent['tcpflags2'] = join(",", $outoftcpflags);
514
				if (!empty($settcpflags))
515
					$filterent['tcpflags1'] = join(",", $settcpflags);
516
			}
517
		}
518
519 fd9ba7c0 Ermal
		if (isset($_POST['tag']))
520
			$filterent['tag'] = $_POST['tag'];
521
		if (isset($_POST['tagged']))
522
			$filterent['tagged'] = $_POST['tagged'];
523 661aed33 Ermal Luçi
		if ($if == "FloatingRules" || isset($_POST['floating'])) {
524
			$filterent['direction'] = $_POST['direction'];
525
			if (isset($_POST['quick']) && $_POST['quick'] <> "")
526
				$filterent['quick'] = $_POST['quick'];
527
			$filterent['floating'] = "yes";
528
			if (isset($_POST['interface']) && count($_POST['interface']) > 0)  {
529 f1602cc4 sullrich
				$filterent['interface'] = implode(",", $_POST['interface']);
530 661aed33 Ermal Luçi
			}
531
		}
532 d59874c1 Scott Ullrich
533 bdb7d6e7 Scott Ullrich
		/* Advanced options */
534 775ccea3 Ermal Luci
		if ($_POST['allowopts'] == "yes")
535
			$filterent['allowopts'] = true;
536
		else
537
			unset($filterent['allowopts']);
538 19757916 Ermal Lu?i
		if ($_POST['disablereplyto'] == "yes")
539
			$filterent['disablereplyto'] = true;
540
		else
541
			unset($filterent['disablereplyto']);
542 a56b2fa0 pierrepomes
		$filterent['max'] = $_POST['max'];
543 bdb7d6e7 Scott Ullrich
		$filterent['max-src-nodes'] = $_POST['max-src-nodes'];
544 26dd6a54 pierrepomes
		$filterent['max-src-conn'] = $_POST['max-src-conn'];
545 bdb7d6e7 Scott Ullrich
		$filterent['max-src-states'] = $_POST['max-src-states'];
546 5ba18897 Scott Ullrich
		$filterent['statetimeout'] = $_POST['statetimeout'];
547 fa9af164 Scott Ullrich
		$filterent['statetype'] = $_POST['statetype'];
548 e33c8694 Bill Marquette
		$filterent['os'] = $_POST['os'];
549 10f21e70 Scott Ullrich
550
		/* Nosync directive - do not xmlrpc sync this item */
551 8c84fe43 Scott Ullrich
		if($_POST['nosync'] <> "")
552 10f21e70 Scott Ullrich
			$filterent['nosync'] = true;
553
		else
554
			unset($filterent['nosync']);
555
556 3f00c1dc Scott Ullrich
		/* unless both values are provided, unset the values - ticket #650 */
557
		if($_POST['max-src-conn-rate'] <> "" and $_POST['max-src-conn-rates'] <> "") {
558
			$filterent['max-src-conn-rate'] = $_POST['max-src-conn-rate'];
559
			$filterent['max-src-conn-rates'] = $_POST['max-src-conn-rates'];
560
		} else {
561
			unset($filterent['max-src-conn-rate']);
562
			unset($filterent['max-src-conn-rates']);
563
		}
564 5ba18897 Scott Ullrich
565 5b237745 Scott Ullrich
		if ($_POST['proto'] != "any")
566
			$filterent['protocol'] = $_POST['proto'];
567
		else
568
			unset($filterent['protocol']);
569 5ba18897 Scott Ullrich
570 5b237745 Scott Ullrich
		if ($_POST['proto'] == "icmp" && $_POST['icmptype'])
571
			$filterent['icmptype'] = $_POST['icmptype'];
572
		else
573
			unset($filterent['icmptype']);
574 5ba18897 Scott Ullrich
575 5b237745 Scott Ullrich
		pconfig_to_address($filterent['source'], $_POST['src'],
576
			$_POST['srcmask'], $_POST['srcnot'],
577
			$_POST['srcbeginport'], $_POST['srcendport']);
578 5ba18897 Scott Ullrich
579 5b237745 Scott Ullrich
		pconfig_to_address($filterent['destination'], $_POST['dst'],
580
			$_POST['dstmask'], $_POST['dstnot'],
581
			$_POST['dstbeginport'], $_POST['dstendport']);
582 5ba18897 Scott Ullrich
583 f1602cc4 sullrich
		if ($_POST['disabled'])
584
			$filterent['disabled'] = true;
585
		else
586
			unset($filterent['disabled']);
587
588 c5fc1b2e Ermal Luçi
		if ($_POST['dscp'])
589
			$filterent['dscp'] = $_POST['dscp'];
590
591 f1602cc4 sullrich
		if ($_POST['log'])
592
			$filterent['log'] = true;
593
		else
594
			unset($filterent['log']);
595 c68fc1e7 Bill Marquette
		strncpy($filterent['descr'], $_POST['descr'], 52);
596 5ba18897 Scott Ullrich
597 c98ddde2 Bill Marquette
		if ($_POST['gateway'] != "") {
598
			$filterent['gateway'] = $_POST['gateway'];
599
		}
600 197bfe96 Ermal Luçi
		
601
		if (isset($_POST['defaultqueue']) && $_POST['defaultqueue'] != "none") {
602
			$filterent['defaultqueue'] = $_POST['defaultqueue'];
603
			if (isset($_POST['ackqueue']) && $_POST['ackqueue'] != "none")
604
				$filterent['ackqueue'] = $_POST['ackqueue'];
605
		}
606 c98ddde2 Bill Marquette
607 a5fd67e1 Ermal Luçi
		if (isset($_POST['dnpipe']) && $_POST['dnpipe'] != "none") {
608
			$filterent['dnpipe'] = $_POST['dnpipe'];
609
			if (isset($_POST['pdnpipe']) && $_POST['pdnpipe'] != "none")
610
				$filterent['pdnpipe'] = $_POST['pdnpipe'];
611
		}
612
613 7e50413c Ermal Luçi
		if (isset($_POST['l7container']) && $_POST['l7container'] != "none") {
614
			$filterent['l7container'] = $_POST['l7container'];
615
		}
616
		
617 615b27bc Scott Dale
		if ($_POST['sched'] != "") {
618
			$filterent['sched'] = $_POST['sched'];
619
		}
620
621 1346306c Ermal
		if ($_POST['vlanprio'] != "") {
622
			$filterent['vlanprio'] = $_POST['vlanprio'];
623
		}
624
		if ($_POST['vlanprioset'] != "") {
625
			$filterent['vlanprioset'] = $_POST['vlanprioset'];
626
		}
627
628 1122a892 Erik Fonnesbeck
		// If we have an associated nat rule, make sure the source and destination doesn't change
629 9b16b834 Ermal Lu?i
		if( isset($a_filter[$id]['associated-rule-id']) ) {
630 0bfd0f79 Erik Fonnesbeck
			$filterent['interface'] = $a_filter[$id]['interface'];
631 48a27d4f Erik Fonnesbeck
			if (isset($a_filter[$id]['protocol']))
632
				$filterent['protocol'] = $a_filter[$id]['protocol'];
633
			else if (isset($filterent['protocol']))
634
				unset($filterent['protocol']);
635
			if ($a_filter[$id]['protocol'] == "icmp" && $a_filter[$id]['icmptype'])
636
				$filterent['icmptype'] = $a_filter[$id]['icmptype'];
637
			else if (isset($filterent['icmptype']))
638
				unset($filterent['icmptype']);
639 1306c7dd Seth Mos
640 1122a892 Erik Fonnesbeck
			$filterent['source'] = $a_filter[$id]['source'];
641 473d0ff0 pierrepomes
			$filterent['destination'] = $a_filter[$id]['destination'];
642 9b16b834 Ermal Lu?i
			$filterent['associated-rule-id'] = $a_filter[$id]['associated-rule-id'];
643 473d0ff0 pierrepomes
		}
644
645 ba1d9714 jim-p
		if ( isset($a_filter[$id]['created']) && is_array($a_filter[$id]['created']) )
646
			$filterent['created'] = $a_filter[$id]['created'];
647
648
		$filterent['updated'] = make_config_revision_entry();
649
650 2ea00c3e Scott Ullrich
		// Allow extending of the firewall edit page and include custom input validation 
651
		pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/pre_write_config");
652
653 5b237745 Scott Ullrich
		if (isset($id) && $a_filter[$id])
654
			$a_filter[$id] = $filterent;
655
		else {
656 ba1d9714 jim-p
			$filterent['created'] = make_config_revision_entry();
657 5b237745 Scott Ullrich
			if (is_numeric($after))
658
				array_splice($a_filter, $after+1, 0, array($filterent));
659
			else
660
				$a_filter[] = $filterent;
661
		}
662 f4e2a352 Scott Ullrich
663 ea57ccb8 Erik Fonnesbeck
		filter_rules_sort();
664 d65962a7 Scott Ullrich
665 3a343d73 jim-p
		if (write_config())
666 bec92ab9 jim-p
			mark_subsystem_dirty('filter');
667 5ba18897 Scott Ullrich
668 661aed33 Ermal Luçi
		if (isset($_POST['floating']))
669
			header("Location: firewall_rules.php?if=FloatingRules");
670
		else
671 bb33a337 jim-p
			header("Location: firewall_rules.php?if=" . htmlspecialchars($_POST['interface']));
672 5b237745 Scott Ullrich
		exit;
673
	}
674 c60824d2 Scott Ullrich
}
675
676 11d2c529 Rafael Lucas
$pgtitle = array(gettext("Firewall"),gettext("Rules"),gettext("Edit"));
677 b32dd0a6 jim-p
$shortcut_section = "firewall";
678 3cceb5d5 jim-p
679 a1357fe0 Bill Marquette
$closehead = false;
680 8ab3e9ed Erik Kristensen
681
$page_filename = "firewall_rules_edit.php";
682 da7ae7ef Bill Marquette
include("head.inc");
683 c60824d2 Scott Ullrich
684 5b237745 Scott Ullrich
?>
685 4bb99603 Scott Ullrich
<link rel="stylesheet" href="/javascript/chosen/chosen.css" />
686 5b237745 Scott Ullrich
</head>
687
688
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
689 f51d5d57 Darren Embry
<script type="text/javascript" src="/javascript/jquery.ipv4v6ify.js"></script>
690 6134cc8f Vinicius Coque
<script src="/javascript/chosen/chosen.jquery.js" type="text/javascript"></script>
691 5b237745 Scott Ullrich
<?php include("fbegin.inc"); ?>
692 48fc39a3 Scott Ullrich
<?php pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/pre_input_errors"); ?>
693 5b237745 Scott Ullrich
<?php if ($input_errors) print_input_errors($input_errors); ?>
694 8ab3e9ed Erik Kristensen
695
<form action="firewall_rules_edit.php" method="post" name="iform" id="iform">
696 6eac9b90 Scott Ullrich
<input type='hidden' name="ruleid" value="<?=(isset($pconfig['ruleid'])&&$pconfig['ruleid']>0)?htmlspecialchars($pconfig['ruleid']):''?>">
697
698 8ab3e9ed Erik Kristensen
	<table width="100%" border="0" cellpadding="6" cellspacing="0">
699 e091cb45 Scott Ullrich
		<tr>
700 11d2c529 Rafael Lucas
			<td colspan="2" valign="top" class="listtopic"><?=gettext("Edit Firewall rule");?></td>
701 e091cb45 Scott Ullrich
		</tr>	
702 b4b7bda6 Scott Ullrich
<?php
703
		// Allow extending of the firewall edit page and include custom input validation 
704
		pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/htmlphpearly");
705
?>
706 8ab3e9ed Erik Kristensen
    	<tr>
707 11d2c529 Rafael Lucas
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Action");?></td>
708 8ab3e9ed Erik Kristensen
			<td width="78%" class="vtable">
709 b5c78501 Seth Mos
				<select name="type" class="formselect">
710 e5e5ba51 Vinicius Coque
					<?php $types = explode(" ", "Pass Block Reject"); foreach ($types as $type): ?>
711 8ab3e9ed Erik Kristensen
					<option value="<?=strtolower($type);?>" <?php if (strtolower($type) == strtolower($pconfig['type'])) echo "selected"; ?>>
712
					<?=htmlspecialchars($type);?>
713
					</option>
714
					<?php endforeach; ?>
715 a391d0ab Ermal
<?php if ($if == "FloatingRules" || isset($pconfig['floating'])): ?>
716 84464c9a Ermal
					<option value="match" <?php if ("match" == strtolower($pconfig['type'])) echo "selected"; ?>>Match</option>
717 a391d0ab Ermal
<?php endif; ?>
718 8c84fe43 Scott Ullrich
				</select>
719 8ab3e9ed Erik Kristensen
				<br/>
720
				<span class="vexpl">
721 11d2c529 Rafael Lucas
					<?=gettext("Choose what to do with packets that match the criteria specified below.");?> <br/>
722
					<?=gettext("Hint: the difference between block and reject is that with reject, a packet (TCP RST or ICMP port unreachable for UDP) is returned to the sender, whereas with block the packet is dropped silently. In either case, the original packet is discarded.");?> 
723 8ab3e9ed Erik Kristensen
				</span>
724
			</td>
725
		</tr>
726
		<tr>
727 11d2c529 Rafael Lucas
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Disabled");?></td>
728 8ab3e9ed Erik Kristensen
			<td width="78%" class="vtable">
729
				<input name="disabled" type="checkbox" id="disabled" value="yes" <?php if ($pconfig['disabled']) echo "checked"; ?>>
730 11d2c529 Rafael Lucas
				<strong><?=gettext("Disable this rule");?></strong><br />
731
				<span class="vexpl"><?=gettext("Set this option to disable this rule without removing it from the list.");?></span>
732 8ab3e9ed Erik Kristensen
			</td>
733
		</tr>
734 661aed33 Ermal Luçi
<?php if ($if == "FloatingRules" || isset($pconfig['floating'])): ?>
735
		<tr>
736 f1602cc4 sullrich
			<td width="22%" valign="top" class="vncellreq">
737
				<?=gettext("Quick");?>
738
			</td>
739
			<td width="78%" class="vtable">
740
				<input name="quick" type="checkbox" id="quick" value="yes" <?php if ($pconfig['quick']) echo "checked=\"checked\""; ?> />
741
				<strong><?=gettext("Apply the action immediately on match.");?></strong><br />
742
				<span class="vexpl"><?=gettext("Set this option if you need to apply this action to traffic that matches this rule immediately.");?></span>
743
			</td>
744
		</tr>
745 e73b001e Renato Botelho
<?php endif; ?>
746 48a27d4f Erik Fonnesbeck
<?php $edit_disabled = ""; ?>
747
<?php if( isset($pconfig['associated-rule-id']) ): ?>
748
		<tr>
749
			<td width="22%" valign="top" class="vncell"><?=gettext("Associated filter rule");?></td>
750
			<td width="78%" class="vtable">
751 e4b9d53b Warren Baker
				<span class="red"><strong><?=gettext("Note: ");?></strong></span><?=gettext("This is associated to a NAT rule.");?><br />
752 48a27d4f Erik Fonnesbeck
				<?=gettext("You cannot edit the interface, protocol, source, or destination of associated filter rules.");?><br />
753
				<br />
754
				<?php
755
					$edit_disabled = "disabled";
756
					if (is_array($config['nat']['rule'])) {
757
						foreach( $config['nat']['rule'] as $index => $nat_rule ) {
758
							if( isset($nat_rule['associated-rule-id']) && $nat_rule['associated-rule-id']==$pconfig['associated-rule-id'] ) {
759
								echo "<a href=\"firewall_nat_edit.php?id={$index}\">" . gettext("View the NAT rule") . "</a><br>";
760
								break;
761
							}
762
						}
763
					}
764
					echo "<input name='associated-rule-id' id='associated-rule-id' type='hidden' value='{$pconfig['associated-rule-id']}' >";
765
					if (!empty($pconfig['interface']))
766
						echo "<input name='interface' id='interface' type='hidden' value='{$pconfig['interface']}' >";
767
				?>
768
				<script type="text/javascript">
769
				editenabled = 0;
770
				</script>
771
			</td>
772
		</tr>
773 ee9933b6 Renato Botelho
<?php endif; ?>
774 8ab3e9ed Erik Kristensen
		<tr>
775 11d2c529 Rafael Lucas
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Interface");?></td>
776 8ab3e9ed Erik Kristensen
			<td width="78%" class="vtable">
777 48a27d4f Erik Fonnesbeck
<?php if ($if == "FloatingRules" || isset($pconfig['floating'])): ?>
778 4bb99603 Scott Ullrich
				<select name="interface[]" title="Select interfaces..." multiple style="width:350px;" class="chzn-select" tabindex="2" <?=$edit_disabled;?>>
779 ee9933b6 Renato Botelho
<?php else: ?>
780 48a27d4f Erik Fonnesbeck
				<select name="interface" class="formselect" <?=$edit_disabled;?>>
781 8ab3e9ed Erik Kristensen
<?php
782 661aed33 Ermal Luçi
   endif;
783 a7782099 Ermal Lu?i
				/* add group interfaces */
784 f1602cc4 sullrich
				if (is_array($config['ifgroups']['ifgroupentry']))
785 a7782099 Ermal Lu?i
					foreach($config['ifgroups']['ifgroupentry'] as $ifgen)
786
						if (have_ruleint_access($ifgen['ifname']))
787
							$interfaces[$ifgen['ifname']] = $ifgen['ifname'];
788 b7391125 Ermal Luçi
				$ifdescs = get_configured_interface_with_descr();
789 0040bcfa Scott Ullrich
				// Allow extending of the firewall edit page and include custom input validation 
790
				pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/pre_interfaces_edit");
791 5335811d Ermal Luçi
				foreach ($ifdescs as $ifent => $ifdesc)
792 0040bcfa Scott Ullrich
					if(have_ruleint_access($ifent))
793 f1602cc4 sullrich
							$interfaces[$ifent] = $ifdesc;
794 617f8d25 Ermal Lu?i
					if ($config['l2tp']['mode'] == "server")
795 f1602cc4 sullrich
						if(have_ruleint_access("l2tp"))
796
							$interfaces['l2tp'] = "L2TP VPN";
797 b6742927 Scott Ullrich
					if ($config['pptpd']['mode'] == "server")
798
						if(have_ruleint_access("pptp")) 
799
							$interfaces['pptp'] = "PPTP VPN";
800
					
801 93c2c1e6 jim-p
					if (is_pppoe_server_enabled() && have_ruleint_access("pppoe"))
802
						$interfaces['pppoe'] = "PPPoE VPN";
803 b6742927 Scott Ullrich
					/* add ipsec interfaces */
804 c6dfd289 jim-p
					if (isset($config['ipsec']['enable']) || isset($config['ipsec']['client']['enable']))
805 b6742927 Scott Ullrich
						if(have_ruleint_access("enc0")) 
806 0f266b2e Chris Buechler
							$interfaces["enc0"] = "IPsec";
807 bfb60ac8 Ermal Luçi
					/* add openvpn/tun interfaces */
808 d799787e Matthew Grooms
					if  ($config['openvpn']["openvpn-server"] || $config['openvpn']["openvpn-client"])
809 d030c9de Erik Fonnesbeck
						$interfaces["openvpn"] = "OpenVPN";
810 43fd29df Erik Fonnesbeck
					if (is_array($pconfig['interface']))
811
						$pconfig['interface'] = implode(",", $pconfig['interface']);
812 d030c9de Erik Fonnesbeck
					$selected_interfaces = explode(",", $pconfig['interface']);
813 8ab3e9ed Erik Kristensen
					foreach ($interfaces as $iface => $ifacename): ?>
814 74aff49c Renato Botelho
						<option value="<?=$iface;?>" <?php if ($pconfig['interface'] <> "" && ( strcasecmp($pconfig['interface'], $iface) == 0 || in_array($iface, $selected_interfaces) )) echo "selected"; ?>><?=$ifacename?></option>
815 8ab3e9ed Erik Kristensen
<?php 				endforeach; ?>
816 8c84fe43 Scott Ullrich
				</select>
817 8ab3e9ed Erik Kristensen
				<br />
818 11d2c529 Rafael Lucas
				<span class="vexpl"><?=gettext("Choose on which interface packets must come in to match this rule.");?></span>
819 8ab3e9ed Erik Kristensen
			</td>
820
		</tr>
821 661aed33 Ermal Luçi
<?php if ($if == "FloatingRules" || isset($pconfig['floating'])): ?>
822 f1602cc4 sullrich
		<tr>
823
			<td width="22%" valign="top" class="vncellreq">
824
				<?=gettext("Direction");?>
825
			</td>
826
			<td width="78%" class="vtable">
827
				<select name="direction" class="formselect">
828 e5e5ba51 Vinicius Coque
					<?php      $directions = array('any','in','out');
829 f1602cc4 sullrich
				foreach ($directions as $direction): ?>
830
				<option value="<?=$direction;?>"
831
					<?php if ($direction == $pconfig['direction']): ?>
832
						selected="selected" 
833
					<?php endif; ?>
834
					><?=$direction;?></option>
835
				<?php endforeach; ?>      
836
				</select>
837
				<input type="hidden" id="floating" name="floating" value="floating">
838
			</td>
839
		<tr>
840 661aed33 Ermal Luçi
<?php endif; ?>
841 1306c7dd Seth Mos
		<tr>
842
			<td width="22%" valign="top" class="vncellreq"><?=gettext("TCP/IP Version");?></td>
843
			<td width="78%" class="vtable">
844
				<select name="ipprotocol" class="formselect">
845 05a4cebd smos
					<?php      $ipproto = array('inet' => 'IPv4','inet6' => 'IPv6', 'inet46' => 'IPv4+IPv6' );
846 1306c7dd Seth Mos
				foreach ($ipproto as $proto => $name): ?>
847
				<option value="<?=$proto;?>"
848
					<?php if ($proto == $pconfig['ipprotocol']): ?>
849
						selected="selected" 
850
					<?php endif; ?>
851
					><?=$name;?></option>
852
				<?php endforeach; ?>      
853
				</select>
854
				<strong><?=gettext("Select the Internet Protocol version this rule applies to");?></strong><br />
855
			</td>
856
		</tr>
857 8ab3e9ed Erik Kristensen
		<tr>
858 11d2c529 Rafael Lucas
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Protocol");?></td>
859 8ab3e9ed Erik Kristensen
			<td width="78%" class="vtable">
860 48a27d4f Erik Fonnesbeck
				<select <?=$edit_disabled;?> name="proto" class="formselect" onchange="proto_change()">
861 8ab3e9ed Erik Kristensen
<?php
862 c6c26178 jim-p
				$protocols = explode(" ", "TCP UDP TCP/UDP ICMP ESP AH GRE IGMP OSPF any carp pfsync");
863 8ab3e9ed Erik Kristensen
				foreach ($protocols as $proto): ?>
864
					<option value="<?=strtolower($proto);?>" <?php if (strtolower($proto) == $pconfig['proto']) echo "selected"; ?>><?=htmlspecialchars($proto);?></option>
865
<?php 			endforeach; ?>
866
				</select>
867
				<br />
868 11d2c529 Rafael Lucas
				<span class="vexpl"><?=gettext("Choose which IP protocol this rule should match.");?> <br /> <?=gettext("Hint: in most cases, you should specify ");?><em>TCP</em> &nbsp;<?=gettext("here.");?></span>
869 8ab3e9ed Erik Kristensen
			</td>
870
		</tr>
871 3de8af0e Scott Ullrich
		<tr id="icmpbox" name="icmpbox">
872 11d2c529 Rafael Lucas
			<td valign="top" class="vncell"><?=gettext("ICMP type");?></td>
873 8ab3e9ed Erik Kristensen
			<td class="vtable">
874 48a27d4f Erik Fonnesbeck
				<select <?=$edit_disabled;?> name="icmptype" class="formselect">
875 8ab3e9ed Erik Kristensen
<?php
876
				$icmptypes = array(
877 abd67a31 Carlos Eduardo Ramos
				"" => gettext("any"),
878 a01ce4c7 jim-p
				"echoreq" => gettext("Echo request"),
879 abd67a31 Carlos Eduardo Ramos
				"echorep" => gettext("Echo reply"),
880
				"unreach" => gettext("Destination unreachable"),
881
				"squench" => gettext("Source quench"),
882
				"redir" => gettext("Redirect"),
883
				"althost" => gettext("Alternate Host"),
884
				"routeradv" => gettext("Router advertisement"),
885
				"routersol" => gettext("Router solicitation"),
886
				"timex" => gettext("Time exceeded"),
887
				"paramprob" => gettext("Invalid IP header"),
888
				"timereq" => gettext("Timestamp"),
889
				"timerep" => gettext("Timestamp reply"),
890
				"inforeq" => gettext("Information request"),
891
				"inforep" => gettext("Information reply"),
892
				"maskreq" => gettext("Address mask request"),
893
				"maskrep" => gettext("Address mask reply")
894 8ab3e9ed Erik Kristensen
				);
895
896
				foreach ($icmptypes as $icmptype => $descr): ?>
897
					<option value="<?=$icmptype;?>" <?php if ($icmptype == $pconfig['icmptype']) echo "selected"; ?>><?=htmlspecialchars($descr);?></option>
898
<?php 			endforeach; ?>
899
			</select>
900
			<br />
901 11d2c529 Rafael Lucas
			<span class="vexpl"><?=gettext("If you selected ICMP for the protocol above, you may specify an ICMP type here.");?></span>
902 8ab3e9ed Erik Kristensen
		</td>
903
		</tr>
904
		<tr>
905 11d2c529 Rafael Lucas
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Source");?></td>
906 8ab3e9ed Erik Kristensen
			<td width="78%" class="vtable">
907 48a27d4f Erik Fonnesbeck
				<input <?=$edit_disabled;?> name="srcnot" type="checkbox" id="srcnot" value="yes" <?php if ($pconfig['srcnot']) echo "checked"; ?>>
908 11d2c529 Rafael Lucas
				<strong><?=gettext("not");?></strong>
909 8ab3e9ed Erik Kristensen
				<br />
910 11d2c529 Rafael Lucas
				<?=gettext("Use this option to invert the sense of the match.");?>
911 8ab3e9ed Erik Kristensen
				<br />
912
				<br />
913
				<table border="0" cellspacing="0" cellpadding="0">
914
					<tr>
915 21600ab1 Vinicius Coque
						<td><?=gettext("Type:");?>&nbsp;&nbsp;</td>
916 8ab3e9ed Erik Kristensen
						<td>
917 48a27d4f Erik Fonnesbeck
							<select <?=$edit_disabled;?> name="srctype" class="formselect" onChange="typesel_change()">
918 87f0be87 Chris Buechler
<?php
919
								$sel = is_specialnet($pconfig['src']); ?>
920 11d2c529 Rafael Lucas
								<option value="any"     <?php if ($pconfig['src'] == "any") { echo "selected"; } ?>><?=gettext("any");?></option>
921 72f25519 Ermal
								<option value="single"
922
						<?php  if (!$sel &&
923
							    ((is_ipaddrv6($pconfig['src']) && $pconfig['srcmask'] == 128) ||
924
							    (is_ipaddrv4($pconfig['src']) && $pconfig['srcmask'] == 32) || is_alias($pconfig['src'])))
925
								{ echo "selected"; $sel = 1; } 
926
						?>
927
								> <?=gettext("Single host or alias");?></option>
928 11d2c529 Rafael Lucas
								<option value="network" <?php if (!$sel) echo "selected"; ?>><?=gettext("Network");?></option>
929 99ea4439 Scott Ullrich
								<?php if(have_ruleint_access("pptp")): ?>
930 11d2c529 Rafael Lucas
								<option value="pptp"    <?php if ($pconfig['src'] == "pptp") { echo "selected"; } ?>><?=gettext("PPTP clients");?></option>
931 99ea4439 Scott Ullrich
								<?php endif; ?>
932
								<?php if(have_ruleint_access("pppoe")): ?>
933 11d2c529 Rafael Lucas
								<option value="pppoe"   <?php if ($pconfig['src'] == "pppoe") { echo "selected"; } ?>><?=gettext("PPPoE clients");?></option>
934 99ea4439 Scott Ullrich
								<?php endif; ?>								
935 8a6bc505 Ermal Lu?i
								 <?php if(have_ruleint_access("l2tp")): ?>
936 11d2c529 Rafael Lucas
                                                                <option value="l2tp"   <?php if ($pconfig['src'] == "l2tp") { echo "selected"; } ?>><?=gettext("L2TP clients");?></option>
937 8a6bc505 Ermal Lu?i
                                                                <?php endif; ?>
938 8ab3e9ed Erik Kristensen
<?php
939 5335811d Ermal Luçi
								foreach ($ifdisp as $ifent => $ifdesc): ?>
940
								<?php if(have_ruleint_access($ifent)): ?>
941 11d2c529 Rafael Lucas
									<option value="<?=$ifent;?>" <?php if ($pconfig['src'] == $ifent) { echo "selected"; } ?>><?=htmlspecialchars($ifdesc);?><?=gettext(" subnet");?></option>
942 5335811d Ermal Luçi
									<option value="<?=$ifent;?>ip"<?php if ($pconfig['src'] ==  $ifent . "ip") { echo "selected"; } ?>>
943 11d2c529 Rafael Lucas
										<?=$ifdesc?> <?=gettext("address");?>
944 e30a5970 Scott Ullrich
									</option>
945 99ea4439 Scott Ullrich
								<?php endif; ?>
946 b7391125 Ermal Luçi
<?php 							endforeach; ?>
947 8ab3e9ed Erik Kristensen
							</select>
948
						</td>
949
					</tr>
950
					<tr>
951 21600ab1 Vinicius Coque
						<td><?=gettext("Address:");?>&nbsp;&nbsp;</td>
952 8ab3e9ed Erik Kristensen
						<td>
953 979b179d Darren Embry
							<input <?=$edit_disabled;?> autocomplete='off' name="src" type="text" class="formfldalias ipv4v6" id="src" size="20" value="<?php if (!is_specialnet($pconfig['src'])) echo htmlspecialchars($pconfig['src']);?>"> /
954
							<select <?=$edit_disabled;?> name="srcmask" class="formselect ipv4v6" id="srcmask">
955 15705bc0 Seth Mos
<?php						for ($i = 127; $i > 0; $i--): ?>
956 8ab3e9ed Erik Kristensen
								<option value="<?=$i;?>" <?php if ($i == $pconfig['srcmask']) echo "selected"; ?>><?=$i;?></option>
957
<?php 						endfor; ?>
958
							</select>
959 bdb7d6e7 Scott Ullrich
						</td>
960 8ab3e9ed Erik Kristensen
					</tr>
961
				</table>
962 22abf2ef Scott Ullrich
				<div id="showadvancedboxspr">
963
					<p>
964 48a27d4f Erik Fonnesbeck
					<input <?=$edit_disabled;?> type="button" onClick="show_source_port_range()" value="<?=gettext("Advanced"); ?>"></input> - <?=gettext("Show source port range");?></a>
965 22abf2ef Scott Ullrich
				</div>
966 8ab3e9ed Erik Kristensen
			</td>
967 e33c8694 Bill Marquette
		</tr>
968 3de8af0e Scott Ullrich
		<tr style="display:none" id="sprtable" name="sprtable">
969 11d2c529 Rafael Lucas
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Source port range");?></td>
970 8ab3e9ed Erik Kristensen
			<td width="78%" class="vtable">
971
				<table border="0" cellspacing="0" cellpadding="0">
972
					<tr>
973 21600ab1 Vinicius Coque
						<td><?=gettext("from:");?>&nbsp;&nbsp;</td>
974 8ab3e9ed Erik Kristensen
						<td>
975 48a27d4f Erik Fonnesbeck
							<select <?=$edit_disabled;?> name="srcbeginport" class="formselect" onchange="src_rep_change();ext_change()">
976 abd67a31 Carlos Eduardo Ramos
								<option value="">(<?=gettext("other"); ?>)</option>
977 11d2c529 Rafael Lucas
								<option value="any" <?php $bfound = 0; if ($pconfig['srcbeginport'] == "any") { echo "selected"; $bfound = 1; } ?>><?=gettext("any");?></option>
978 8ab3e9ed Erik Kristensen
<?php 							foreach ($wkports as $wkport => $wkportdesc): ?>
979
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcbeginport']) { echo "selected"; $bfound = 1; } ?>><?=htmlspecialchars($wkportdesc);?></option>
980
<?php 							endforeach; ?>
981 8c84fe43 Scott Ullrich
							</select>
982 dd5bf424 Scott Ullrich
							<input <?=$edit_disabled;?> autocomplete='off' class="formfldalias" name="srcbeginport_cust" id="srcbeginport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['srcbeginport']) echo htmlspecialchars($pconfig['srcbeginport']); ?>">
983 8ab3e9ed Erik Kristensen
						</td>
984
					</tr>
985
					<tr>
986 21600ab1 Vinicius Coque
						<td><?=gettext("to:");?></td>
987 8ab3e9ed Erik Kristensen
						<td>
988 48a27d4f Erik Fonnesbeck
							<select <?=$edit_disabled;?> name="srcendport" class="formselect" onchange="ext_change()">
989 abd67a31 Carlos Eduardo Ramos
								<option value="">(<?=gettext("other"); ?>)</option>
990 11d2c529 Rafael Lucas
								<option value="any" <?php $bfound = 0; if ($pconfig['srcendport'] == "any") { echo "selected"; $bfound = 1; } ?>><?=gettext("any");?></option>
991 8ab3e9ed Erik Kristensen
<?php							foreach ($wkports as $wkport => $wkportdesc): ?>
992
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcendport']) { echo "selected"; $bfound = 1; } ?>><?=htmlspecialchars($wkportdesc);?></option>
993
<?php							endforeach; ?>
994 8c84fe43 Scott Ullrich
							</select>
995 dd5bf424 Scott Ullrich
							<input <?=$edit_disabled;?> autocomplete='off' class="formfldalias" name="srcendport_cust" id="srcendport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['srcendport']) echo htmlspecialchars($pconfig['srcendport']); ?>">
996 8ab3e9ed Erik Kristensen
						</td>
997
					</tr>
998
				</table>
999
				<br />
1000 87000ded Erik Fonnesbeck
				<span class="vexpl"><?=gettext("Specify the source port or port range for this rule."); ?> <b><?=gettext("This is usually"); ?> <em><?=gettext("random"); ?></em> <?=gettext("and almost never equal to the destination port range (and should usually be"); ?> &quot;<?=gettext("any"); ?>&quot;).</b><br /><?=gettext("Hint: you can leave the"); ?> <em><?=gettext("'to'"); ?></em> <?=gettext("field empty if you only want to filter a single port.");?></span><br/>
1001 8ab3e9ed Erik Kristensen
			</td>
1002 8c84fe43 Scott Ullrich
		</tr>
1003 8ab3e9ed Erik Kristensen
		<tr>
1004 11d2c529 Rafael Lucas
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Destination");?></td>
1005 8ab3e9ed Erik Kristensen
			<td width="78%" class="vtable">
1006 48a27d4f Erik Fonnesbeck
				<input <?=$edit_disabled;?> name="dstnot" type="checkbox" id="dstnot" value="yes" <?php if ($pconfig['dstnot']) echo "checked"; ?>>
1007 11d2c529 Rafael Lucas
				<strong><?=gettext("not");?></strong>
1008 8ab3e9ed Erik Kristensen
					<br />
1009 11d2c529 Rafael Lucas
				<?=gettext("Use this option to invert the sense of the match.");?>
1010 8ab3e9ed Erik Kristensen
					<br />
1011
					<br />
1012
				<table border="0" cellspacing="0" cellpadding="0">
1013
					<tr>
1014 21600ab1 Vinicius Coque
						<td><?=gettext("Type:");?>&nbsp;&nbsp;</td>
1015 8ab3e9ed Erik Kristensen
						<td>
1016 48a27d4f Erik Fonnesbeck
							<select <?=$edit_disabled;?> name="dsttype" class="formselect" onChange="typesel_change()">
1017 87f0be87 Chris Buechler
<?php
1018
								$sel = is_specialnet($pconfig['dst']); ?>
1019 11d2c529 Rafael Lucas
								<option value="any" <?php if ($pconfig['dst'] == "any") { echo "selected"; } ?>><?=gettext("any");?></option>
1020 965c3e23 Renato Botelho
								<option value="single"
1021
								<?php  if (!$sel &&
1022
									    ((is_ipaddrv6($pconfig['dst']) && $pconfig['dstmask'] == 128) ||
1023
									    (is_ipaddrv4($pconfig['dst']) && $pconfig['dstmask'] == 32) || is_alias($pconfig['dst'])))
1024
										{ echo "selected"; $sel = 1; }
1025
								?>
1026
								><?=gettext("Single host or alias");?></option>
1027 11d2c529 Rafael Lucas
								<option value="network" <?php if (!$sel) echo "selected"; ?>><?=gettext("Network");?></option>
1028 99ea4439 Scott Ullrich
								<?php if(have_ruleint_access("pptp")): ?>
1029 11d2c529 Rafael Lucas
								<option value="pptp" <?php if ($pconfig['dst'] == "pptp") { echo "selected"; } ?>><?=gettext("PPTP clients");?></option>
1030 99ea4439 Scott Ullrich
								<?php endif; ?>
1031
								<?php if(have_ruleint_access("pppoe")): ?>
1032 11d2c529 Rafael Lucas
								<option value="pppoe" <?php if ($pconfig['dst'] == "pppoe") { echo "selected"; } ?>><?=gettext("PPPoE clients");?></option>
1033 99ea4439 Scott Ullrich
								<?php endif; ?>								
1034 3331a640 Ermal Lu?i
								<?php if(have_ruleint_access("l2tp")): ?>
1035 11d2c529 Rafael Lucas
                                                                <option value="l2tp" <?php if ($pconfig['dst'] == "l2tp") { echo "selected"; } ?>><?=gettext("L2TP clients");?></option>
1036 3331a640 Ermal Lu?i
                                                                <?php endif; ?>
1037 b7391125 Ermal Luçi
1038
<?php 							foreach ($ifdisp as $if => $ifdesc): ?>
1039
								<?php if(have_ruleint_access($if)): ?>
1040 11d2c529 Rafael Lucas
									<option value="<?=$if;?>" <?php if ($pconfig['dst'] == $if) { echo "selected"; } ?>><?=htmlspecialchars($ifdesc);?> <?=gettext("subnet");?></option>
1041 b7391125 Ermal Luçi
									<option value="<?=$if;?>ip"<?php if ($pconfig['dst'] == $if . "ip") { echo "selected"; } ?>>
1042 11d2c529 Rafael Lucas
										<?=$ifdesc;?> <?=gettext("address");?>
1043 cbff71a1 Scott Ullrich
									</option>
1044 99ea4439 Scott Ullrich
								<?php endif; ?>
1045 b7391125 Ermal Luçi
<?php 							endforeach; ?>
1046 8ab3e9ed Erik Kristensen
							</select>
1047
						</td>
1048
					</tr>
1049
					<tr>
1050 21600ab1 Vinicius Coque
						<td><?=gettext("Address:");?>&nbsp;&nbsp;</td>
1051 8ab3e9ed Erik Kristensen
						<td>
1052 979b179d Darren Embry
							<input <?=$edit_disabled;?> autocomplete='off' name="dst" type="text" class="formfldalias ipv4v6" id="dst" size="20" value="<?php if (!is_specialnet($pconfig['dst'])) echo htmlspecialchars($pconfig['dst']);?>">
1053 8ab3e9ed Erik Kristensen
							/
1054 979b179d Darren Embry
							<select <?=$edit_disabled;?> name="dstmask" class="formselect ipv4v6" id="dstmask">
1055 8ab3e9ed Erik Kristensen
<?php
1056 15705bc0 Seth Mos
							for ($i = 127; $i > 0; 
1057
$i--): ?>
1058 8ab3e9ed Erik Kristensen
								<option value="<?=$i;?>" <?php if ($i == $pconfig['dstmask']) echo "selected"; ?>><?=$i;?></option>
1059
<?php						endfor; ?>
1060
							</select>
1061
						</td>
1062
					</tr>
1063
				</table>
1064
			</td>
1065
		</tr>
1066 3de8af0e Scott Ullrich
		<tr id="dprtr" name="dprtr">
1067 11d2c529 Rafael Lucas
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Destination port range ");?></td>
1068 8ab3e9ed Erik Kristensen
			<td width="78%" class="vtable">
1069
				<table border="0" cellspacing="0" cellpadding="0">
1070
					<tr>
1071 21600ab1 Vinicius Coque
						<td><?=gettext("from:");?>&nbsp;&nbsp;</td>
1072 8ab3e9ed Erik Kristensen
						<td>
1073 48a27d4f Erik Fonnesbeck
							<select <?=$edit_disabled;?> name="dstbeginport" class="formselect" onchange="dst_rep_change();ext_change()">
1074 abd67a31 Carlos Eduardo Ramos
								<option value="">(<?=gettext("other"); ?>)</option>
1075 11d2c529 Rafael Lucas
								<option value="any" <?php $bfound = 0; if ($pconfig['dstbeginport'] == "any") { echo "selected"; $bfound = 1; } ?>><?=gettext("any");?></option>
1076 8ab3e9ed Erik Kristensen
<?php 							foreach ($wkports as $wkport => $wkportdesc): ?>
1077
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['dstbeginport']) { echo "selected"; $bfound = 1; }?>><?=htmlspecialchars($wkportdesc);?></option>
1078 3deb92f7 Renato Botelho
<?php 							endforeach; ?>
1079 8ab3e9ed Erik Kristensen
							</select>
1080 dd5bf424 Scott Ullrich
							<input <?=$edit_disabled;?> autocomplete='off' class="formfldalias" name="dstbeginport_cust" id="dstbeginport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['dstbeginport']) echo htmlspecialchars($pconfig['dstbeginport']); ?>">
1081 8ab3e9ed Erik Kristensen
						</td>
1082
					</tr>
1083
					<tr>
1084 21600ab1 Vinicius Coque
						<td><?=gettext("to:");?></td>
1085 8ab3e9ed Erik Kristensen
						<td>
1086 48a27d4f Erik Fonnesbeck
							<select <?=$edit_disabled;?> name="dstendport" class="formselect" onchange="ext_change()">
1087 abd67a31 Carlos Eduardo Ramos
								<option value="">(<?=gettext("other"); ?>)</option>
1088 11d2c529 Rafael Lucas
								<option value="any" <?php $bfound = 0; if ($pconfig['dstendport'] == "any") { echo "selected"; $bfound = 1; } ?>><?=gettext("any");?></option>
1089 8ab3e9ed Erik Kristensen
<?php							foreach ($wkports as $wkport => $wkportdesc): ?>
1090
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['dstendport']) { echo "selected"; $bfound = 1; } ?>><?=htmlspecialchars($wkportdesc);?></option>
1091
<?php 							endforeach; ?>
1092 8c84fe43 Scott Ullrich
							</select>
1093 dd5bf424 Scott Ullrich
								<input <?=$edit_disabled;?> autocomplete='off' class="formfldalias" name="dstendport_cust" id="dstendport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['dstendport']) echo htmlspecialchars($pconfig['dstendport']); ?>">
1094 8ab3e9ed Erik Kristensen
						</td>
1095
					</tr>
1096
				</table>
1097
				<br />
1098
				<span class="vexpl">
1099 11d2c529 Rafael Lucas
					<?=gettext("Specify the port or port range for the destination of the packet for this rule.");?>
1100 adb633a0 sullrich
					<br />
1101 345b9715 Carlos Eduardo Ramos
					<?=gettext("Hint: you can leave the"); ?> <em><?=gettext("'to'"); ?></em> <?=gettext("field empty if you only want to filter a single port");?>
1102 8ab3e9ed Erik Kristensen
				</span>
1103
			</td>
1104
		</tr>
1105
		<tr>
1106 11d2c529 Rafael Lucas
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Log");?></td>
1107 8ab3e9ed Erik Kristensen
			<td width="78%" class="vtable">
1108
				<input name="log" type="checkbox" id="log" value="yes" <?php if ($pconfig['log']) echo "checked"; ?>>
1109 11d2c529 Rafael Lucas
				<strong><?=gettext("Log packets that are handled by this rule");?></strong>
1110 adb633a0 sullrich
				<br />
1111 0fb885bc Carlos Eduardo Ramos
				<span class="vexpl"><?=gettext("Hint: the firewall has limited local log space. Don't turn on logging for everything. If you want to do a lot of logging, consider using a remote syslog server"); ?> (<?=gettext("see the"); ?> <a href="diag_logs_settings.php"><?=gettext("Diagnostics: System logs: Settings"); ?></a> <?=gettext("page"); ?>).</span>
1112 8ab3e9ed Erik Kristensen
			</td>
1113
		</tr>
1114 151eb2a9 sullrich
		<tr>
1115 11d2c529 Rafael Lucas
			<td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
1116 151eb2a9 sullrich
			<td width="78%" class="vtable">
1117
				<input name="descr" type="text" class="formfld unknown" id="descr" size="52" maxlength="52" value="<?=htmlspecialchars($pconfig['descr']);?>">
1118
				<br />
1119 11d2c529 Rafael Lucas
				<span class="vexpl"><?=gettext("You may enter a description here for your reference.");?></span>
1120 151eb2a9 sullrich
			</td>
1121
		</tr>
1122 8e0c3760 Ermal
<?php		if (!isset($id) || !($a_filter[$id] && firewall_check_for_advanced_options($a_filter[$id]) <> "")): ?>
1123 151eb2a9 sullrich
		<tr>
1124
			<td width="22%" valign="top">&nbsp;</td>
1125
			<td width="78%">
1126
				&nbsp;<br>&nbsp;
1127 157a6919 Carlos Eduardo Ramos
				<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>">  <input type="button" class="formbtn" value="<?=gettext("Cancel"); ?>" onclick="history.back()">
1128 151eb2a9 sullrich
<?php			if (isset($id) && $a_filter[$id]): ?>
1129 225a2f0b Scott Ullrich
					<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>">
1130 151eb2a9 sullrich
<?php 			endif; ?>
1131 225a2f0b Scott Ullrich
				<input name="after" type="hidden" value="<?=htmlspecialchars($after);?>">
1132 151eb2a9 sullrich
			</td>
1133
		</tr>
1134 8e0c3760 Ermal
<?php		endif; ?>
1135 151eb2a9 sullrich
		<tr>
1136
			<td>&nbsp;</td>
1137
		</tr>
1138
		<tr>
1139 11d2c529 Rafael Lucas
			<td colspan="2" valign="top" class="listtopic"><?=gettext("Advanced features");?></td>
1140 151eb2a9 sullrich
		</tr>	
1141 f1602cc4 sullrich
		<tr>
1142 11d2c529 Rafael Lucas
			<td width="22%" valign="top" class="vncell"><?=gettext("Source OS");?></td>
1143 e265d9f5 sullrich
			<td width="78%" class="vtable">
1144 ee9933b6 Renato Botelho
				<div id="showadvsourceosbox" <?php if ($pconfig['os']) echo "style='display:none'"; ?>>
1145 157a6919 Carlos Eduardo Ramos
					<input type="button" onClick="show_advanced_sourceos()" value="<?=gettext("Advanced"); ?>"></input> - <?=gettext("Show advanced option");?></a>
1146 adb633a0 sullrich
				</div>
1147 ee9933b6 Renato Botelho
				<div id="showsourceosadv" <?php if (empty($pconfig['os'])) echo "style='display:none'"; ?>>
1148 21600ab1 Vinicius Coque
					<?=gettext("OS Type:");?>&nbsp;
1149 adb633a0 sullrich
					<select name="os" id="os" class="formselect">
1150 f1602cc4 sullrich
<?php
1151 adb633a0 sullrich
						$ostypes = array(
1152 abd67a31 Carlos Eduardo Ramos
							 "" => gettext("any"),
1153 adb633a0 sullrich
							"AIX" => "AIX",
1154
							"Linux" => "Linux",
1155
							"FreeBSD" => "FreeBSD",
1156
							"NetBSD" => "NetBSD",
1157
							"OpenBSD" => "OpenBSD",
1158
							"Solaris" => "Solaris",
1159
							"MacOS" => "MacOS",
1160
							"Windows" => "Windows",
1161
							"Novell" => "Novell",
1162
							"NMAP" => "NMAP"
1163
			           );
1164
						foreach ($ostypes as $ostype => $descr): ?>
1165
							<option value="<?=$ostype;?>" <?php if ($ostype == $pconfig['os']) echo "selected"; ?>><?=htmlspecialchars($descr);?></option>
1166
<?php
1167
					endforeach; 
1168
?>
1169
					</select>
1170
					<br />
1171 11d2c529 Rafael Lucas
					<?=gettext("Note: this only works for TCP rules");?>
1172 adb633a0 sullrich
				</div>
1173 f1602cc4 sullrich
			</td>
1174
		</tr>
1175 30c4ae8a sullrich
		<tr>
1176 11d2c529 Rafael Lucas
			<td width="22%" valign="top" class="vncell"><?=gettext("Diffserv Code Point");?></td>
1177 30c4ae8a sullrich
			<td width="78%" class="vtable">
1178 ee9933b6 Renato Botelho
				<div id="dsadv" name="dsadv" <?php if ($pconfig['dscp']) echo "style='display:none'"; ?>>
1179 0fb885bc Carlos Eduardo Ramos
					<input type="button" onClick="show_dsdiv();" value="<?=gettext("Advanced"); ?>"> - <?=gettext("Show advanced option");?>
1180 30c4ae8a sullrich
				</div>
1181 ee9933b6 Renato Botelho
				<div id="dsdivmain" name="dsdivmain" <?php if (empty($pconfig['dscp'])) echo "style='display:none'"; ?>>
1182 30c4ae8a sullrich
					<select name="dscp" id="dscp">
1183
						<option value=""></option>
1184
						<?php foreach($firewall_rules_dscp_types as $frdt): ?>
1185
							<option value="<?=$frdt?>"<?php if($pconfig['dscp'] == $frdt) echo " SELECTED"; ?>><?=$frdt?></option>
1186
						<?php endforeach; ?>
1187
					</select>
1188
				</div>
1189
			</td>
1190
		</tr>
1191 661aed33 Ermal Luçi
		<tr>
1192 11d2c529 Rafael Lucas
			<td width="22%" valign="top" class="vncell"><?=gettext("Advanced Options");?></td>
1193 e6db3f58 Ermal Luçi
			<td width="78%" class="vtable">
1194
			<div id="aoadv" name="aoadv">
1195 0fb885bc Carlos Eduardo Ramos
				<input type="button" onClick="show_aodiv();" value="<?=gettext("Advanced"); ?>"> - <?=gettext("Show advanced option");?>
1196 e6db3f58 Ermal Luçi
			</div>
1197
			<div id="aodivmain" name="aodivmain" style="display:none">
1198 f1602cc4 sullrich
				<input type="checkbox" id="allowopts" value="yes" name="allowopts"<?php if($pconfig['allowopts'] == true) echo " checked"; ?>>
1199 a29dc11b Chris Buechler
				<br/><span class="vexpl"><?=gettext("This allows packets with IP options to pass. Otherwise they are blocked by default. This is usually only seen with multicast traffic.");?>
1200 f1602cc4 sullrich
				</span><p>
1201 19757916 Ermal Lu?i
				<input type="checkbox" id="disablereplyto" value="yes" name="disablereplyto"<?php if($pconfig['disablereplyto'] == true) echo " checked"; ?>>
1202
				<br/><span class="vexpl"><?=gettext("This will disable auto generated reply-to for this rule.");?>
1203
				</span><p>
1204 f1602cc4 sullrich
				<input name="tag" id="tag" value="<?=htmlspecialchars($pconfig['tag']);?>">
1205 345b9715 Carlos Eduardo Ramos
				<br /><span class="vexpl"><?=gettext("You can mark a packet matching this rule and use this mark to match on other NAT/filter rules. It is called"); ?> <b><?=gettext("Policy filtering"); ?></b>
1206 775ccea3 Ermal Luci
				</span><p>
1207 f1602cc4 sullrich
				<input name="tagged" id="tagged" value="<?=htmlspecialchars($pconfig['tagged']);?>">
1208
				<br /><span class="vexpl"><?=gettext("You can match packet on a mark placed before on another rule.")?>
1209
				</span> <p>
1210 dd5bf424 Scott Ullrich
				<input name="max" id="max" value="<?php echo htmlspecialchars($pconfig['max']) ?>"><br><?=gettext(" Maximum state entries this rule can create");?></p><p>
1211
				<input name="max-src-nodes" id="max-src-nodes" value="<?php echo htmlspecialchars($pconfig['max-src-nodes']) ?>"><br><?=gettext(" Maximum number of unique source hosts");?></p><p>
1212
				<input name="max-src-conn" id="max-src-conn" value="<?php echo htmlspecialchars($pconfig['max-src-conn']) ?>"><br><?=gettext(" Maximum number of established connections per host");?></p><p>
1213
				<input name="max-src-states" id="max-src-states" value="<?php echo htmlspecialchars($pconfig['max-src-states']) ?>"><br><?=gettext(" Maximum state entries per host");?></p><p>
1214
				<input name="max-src-conn-rate" id="max-src-conn-rate" value="<?php echo htmlspecialchars($pconfig['max-src-conn-rate']) ?>"> /
1215 8ab3e9ed Erik Kristensen
				<select name="max-src-conn-rates" id="max-src-conn-rates">
1216
					<option value=""<?php if(intval($pconfig['max-src-conn-rates']) < 1) echo " selected"; ?>></option>
1217
<?php				for($x=1; $x<255; $x++) {
1218
						if($x == $pconfig['max-src-conn-rates']) $selected = " selected"; else $selected = "";
1219
						echo "<option value=\"{$x}\"{$selected}>{$x}</option>\n";
1220
					} ?>
1221 47042140 Scott Ullrich
				</select><br />
1222 11d2c529 Rafael Lucas
				<?=gettext("Maximum new connections / per second(s)");?>
1223 e4d79ab0 Ermal
				</p><p>
1224 47042140 Scott Ullrich
1225 dd5bf424 Scott Ullrich
				<input name="statetimeout" value="<?php echo htmlspecialchars($pconfig['statetimeout']) ?>"><br>
1226 11d2c529 Rafael Lucas
				<?=gettext("State Timeout in seconds");?>
1227 e4d79ab0 Ermal
				</p>
1228 47042140 Scott Ullrich
1229 e4b9d53b Warren Baker
				<p><strong><?=gettext("Note: Leave fields blank to disable that feature.");?></strong></p>
1230 197b2a47 Scott Ullrich
			  </div>
1231 8ab3e9ed Erik Kristensen
			</td>
1232
		</tr>
1233 b8ed2a11 Ermal
		<tr id="tcpflags" name="tcpflags"> 
1234 11d2c529 Rafael Lucas
			<td width="22%" valign="top" class="vncell"><?=gettext("TCP flags");?></td>
1235 b8ed2a11 Ermal
			<td width="78%" class="vtable">
1236 ee9933b6 Renato Botelho
			<div id="showtcpflagsbox" <?php if ($pconfig['tcpflags_any'] || $pconfig['tcpflags1'] || $pconfig['tcpflags2']) echo "style='display:none'"; ?>>
1237 0fb885bc Carlos Eduardo Ramos
                        	<input type="button" onClick="show_advanced_tcpflags()" value="<?=gettext("Advanced"); ?>"></input> - <?=gettext("Show advanced option");?></a>
1238 b8ed2a11 Ermal
                        </div>
1239 ee9933b6 Renato Botelho
                        <div id="showtcpflagsadv" <?php if (empty($pconfig['tcpflags_any']) && empty($pconfig['tcpflags1']) && empty($pconfig['tcpflags2'])) echo "style='display:none'"; ?>>
1240 b8ed2a11 Ermal
			<div id="tcpheader" name="tcpheader">
1241
			<center>
1242
			<table border="0" cellspacing="0" cellpadding="0">
1243
			<?php 
1244
				$setflags = explode(",", $pconfig['tcpflags1']);
1245
				$outofflags = explode(",", $pconfig['tcpflags2']);
1246
				$header = "<td width='40' nowrap></td>";
1247
				$tcpflags1 = "<td width='40' nowrap>set</td>";
1248
				$tcpflags2 = "<td width='40' nowrap>out of</td>";
1249
				foreach ($tcpflags as $tcpflag) {
1250
					$header .= "<td  width='40' nowrap><strong>" . strtoupper($tcpflag) . "</strong></td>\n";
1251
					$tcpflags1 .= "<td  width='40' nowrap> <input type='checkbox' name='tcpflags1_{$tcpflag}' value='on' ";
1252
					if (array_search($tcpflag, $setflags) !== false)
1253
						$tcpflags1 .= "checked";
1254
					$tcpflags1 .= "></td>\n";
1255
					$tcpflags2 .= "<td  width='40' nowrap> <input type='checkbox' name='tcpflags2_{$tcpflag}' value='on' ";
1256
					if (array_search($tcpflag, $outofflags) !== false)
1257
						$tcpflags2 .= "checked";
1258
					$tcpflags2 .= "></td>\n";
1259
				}
1260
				echo "<tr id='tcpheader' name='tcpheader'>{$header}</tr>\n";
1261
				echo "<tr id='tcpflags1' name='tcpflags1'>{$tcpflags1}</tr>\n";
1262
				echo "<tr id='tcpflags2' name='tcpflags2'>{$tcpflags2}</tr>\n";
1263
			?>
1264
			</table>
1265
			<center>
1266
			</div>
1267
			<br/><center>
1268 11d2c529 Rafael Lucas
			<input onClick='tcpflags_anyclick(this);' type='checkbox' name='tcpflags_any' value='on' <?php if ($pconfig['tcpflags_any']) echo "checked"; ?>><strong><?=gettext("Any flags.");?></strong><br/></center>
1269 b8ed2a11 Ermal
			<br/>
1270 95938fae jim-p
			<span class="vexpl"><?=gettext("Use this to choose TCP flags that must ". 
1271 11d2c529 Rafael Lucas
			"be set or cleared for this rule to match.");?></span>
1272 b8ed2a11 Ermal
			</div>
1273
			</td>
1274
		</tr>
1275 8ab3e9ed Erik Kristensen
		<tr>
1276 11d2c529 Rafael Lucas
			<td width="22%" valign="top" class="vncell"><?=gettext("State Type");?></td>
1277 8ab3e9ed Erik Kristensen
			<td width="78%" class="vtable">
1278 ee9933b6 Renato Botelho
				<div id="showadvstatebox" <?php if (!empty($pconfig['statetype']) && $pconfig['statetype'] != "keep state") echo "style='display:none'"; ?>>
1279 0fb885bc Carlos Eduardo Ramos
					<input type="button" onClick="show_advanced_state()" value="<?=gettext("Advanced"); ?>"></input> - <?=gettext("Show advanced option");?></a>
1280 f6970b2f Scott Ullrich
				</div>
1281 ee9933b6 Renato Botelho
				<div id="showstateadv" <?php if (empty($pconfig['statetype']) || $pconfig['statetype'] == "keep state") echo "style='display:none'"; ?>>
1282 f6970b2f Scott Ullrich
					<select name="statetype">
1283 11d2c529 Rafael Lucas
						<option value="keep state" <?php if(!isset($pconfig['statetype']) or $pconfig['statetype'] == "keep state") echo "selected"; ?>><?=gettext("keep state");?></option>
1284
						<option value="sloppy state" <?php if($pconfig['statetype'] == "sloppy state") echo "selected"; ?>><?=gettext("sloppy state");?></option>
1285
						<option value="synproxy state"<?php if($pconfig['statetype'] == "synproxy state")  echo "selected"; ?>><?=gettext("synproxy state");?></option>
1286
						<option value="none"<?php if($pconfig['statetype'] == "none") echo "selected"; ?>><?=gettext("none");?></option>
1287 e4b9d53b Warren Baker
					</select><br><?=gettext("Hint: Select which type of state tracking mechanism you would like to use.  If in doubt, use keep state.");?>
1288 f6970b2f Scott Ullrich
					<p>
1289
					<table width="90%">
1290 67300ce5 Ermal
						<tr><td width="25%"><ul><li><?=gettext("keep state");?></li></ul></td><td><?=gettext("Works with all IP protocols.");?></td></tr>
1291
						<tr><td width="25%"><ul><li><?=gettext("sloppy state");?></li></ul></td><td><?=gettext("Works with all IP protocols.");?></td></tr>
1292
						<tr><td width="25%"><ul><li><?=gettext("synproxy state");?></li></ul></td><td><?=gettext("Proxies incoming TCP connections to help protect servers from spoofed TCP SYN floods. This option includes the functionality of keep state and modulate state combined.");?></td></tr>
1293
						<tr><td width="25%"><ul><li><?=gettext("none");?></li></ul></td><td><?=gettext("Do not use state mechanisms to keep track.  This is only useful if you're doing advanced queueing in certain situations.  Please check the documentation.");?></td></tr>
1294 f6970b2f Scott Ullrich
					</table>
1295
					</p>
1296
			  </div>
1297 8ab3e9ed Erik Kristensen
			</td>
1298
		</tr>
1299 10f21e70 Scott Ullrich
		<tr>
1300 11d2c529 Rafael Lucas
			<td width="22%" valign="top" class="vncell"><?=gettext("No XMLRPC Sync");?></td>
1301 10f21e70 Scott Ullrich
			<td width="78%" class="vtable">
1302 ee9933b6 Renato Botelho
				<div id="showadvnoxmlrpcsyncbox" <?php if ($pconfig['nosync']) echo "style='display:none'"; ?>>
1303 0fb885bc Carlos Eduardo Ramos
					<input type="button" onClick="show_advanced_noxmlrpc()" value="<?=gettext("Advanced"); ?>"></input> - <?=gettext("Show advanced option");?></a>
1304 0239d8ee sullrich
				</div>
1305 ee9933b6 Renato Botelho
				<div id="shownoxmlrpcadv" <?php if (empty($pconfig['nosync'])) echo "style='display:none'"; ?>>
1306 0239d8ee sullrich
					<input type="checkbox" name="nosync"<?php if($pconfig['nosync']) echo " CHECKED"; ?>><br>
1307 72711980 Renato Botelho
					<?=gettext("Hint: This prevents the rule on Master from automatically syncing to other CARP members. This does NOT prevent the rule from being overwritten on Slave.");?>
1308 0239d8ee sullrich
				</div>
1309 10f21e70 Scott Ullrich
			</td>
1310 8c84fe43 Scott Ullrich
		</tr>
1311 1346306c Ermal
		<tr>
1312
			<td width="22%" valign="top" class="vncell"><?=gettext("802.1p");?></td>
1313
			<td width="78%" class="vtable">
1314
				<div id="showadvvlanpriobox" <?php if (!empty($pconfig['vlanprio'])) echo "style='display:none'"; ?>>
1315
					<input type="button" onClick="show_advanced_vlanprio()" value="<?=gettext("Advanced"); ?>"></input> - <?=gettext("Show advanced option");?></a>
1316
				</div>
1317
				<div id="showvlanprioadv" <?php if (empty($pconfig['vlanprio'])) echo "style='display:none'"; ?>>
1318
					<?php $vlanprio = array("none", "be", "bk", "ee", "ca", "vi", "vo", "ic", "nc"); ?>
1319
<?php
1320
					$opts = "";
1321
					foreach($vlanprio as $vprio) {
1322
						if ($vprio == $pconfig['vlanprio'])
1323
							$selected = " SELECTED";
1324
						else
1325
							$selected = "";
1326
						if ($vprio == "none")
1327
							$opts .= "<option value=\"\" {$vprio}>{$vprio}</option>\n";
1328
						else
1329
							$opts .= "<option value=\"{$vprio}\" {$selected}>" . strtoupper($vprio) . "</option>\n";
1330
					}
1331
?>
1332
					<select name='vlanprio'>
1333
					<?php echo $opts; ?>
1334
					</select>
1335
					<p><?=gettext("Choose 802.1p priority to match on");?></p>
1336
					<select name='vlanprioset'>
1337
					<?php echo $opts; ?>
1338
					</select>
1339
					<p><?=gettext("Choose 802.1p priority to apply");?></p>
1340
				</div>
1341
			</td>
1342
		</tr>
1343 615b27bc Scott Dale
		<?php
1344
			//build list of schedules
1345
			$schedules = array();
1346
			$schedules[] = "none";//leave none to leave rule enabled all the time
1347 a60fd0cb Scott Ullrich
			if(is_array($config['schedules']['schedule'])) {
1348
				foreach ($config['schedules']['schedule'] as $schedule) {
1349
					if ($schedule['name'] <> "")
1350
						$schedules[] = $schedule['name'];
1351
				}
1352
			}
1353 615b27bc Scott Dale
		?>
1354
		<tr>
1355 11d2c529 Rafael Lucas
			<td width="22%" valign="top" class="vncell"><?=gettext("Schedule");?></td>
1356 615b27bc Scott Dale
			<td width="78%" class="vtable">
1357 ee9933b6 Renato Botelho
				<div id="showadvschedulebox" <?php if (!empty($pconfig['sched'])) echo "style='display:none'"; ?>>
1358 0fb885bc Carlos Eduardo Ramos
					<input type="button" onClick="show_advanced_schedule()" value="<?=gettext("Advanced"); ?>"></input> - <?=gettext("Show advanced option");?></a>
1359 0239d8ee sullrich
				</div>
1360 ee9933b6 Renato Botelho
				<div id="showscheduleadv" <?php if (empty($pconfig['sched'])) echo "style='display:none'"; ?>>
1361 0239d8ee sullrich
					<select name='sched'>
1362 615b27bc Scott Dale
<?php
1363 0239d8ee sullrich
					foreach($schedules as $schedule) {
1364
						if($schedule == $pconfig['sched']) {
1365
							$selected = " SELECTED";
1366
						} else {
1367
							$selected = "";
1368
						}
1369
						if ($schedule == "none") {
1370
							echo "<option value=\"\" {$selected}>{$schedule}</option>\n";
1371
						} else {
1372
							echo "<option value=\"{$schedule}\" {$selected}>{$schedule}</option>\n";
1373
						}
1374 615b27bc Scott Dale
					}
1375 0239d8ee sullrich
?>
1376
					</select>
1377 11d2c529 Rafael Lucas
					<p><?=gettext("Leave as 'none' to leave the rule enabled all the time.");?></p>
1378 0239d8ee sullrich
				</div>
1379 615b27bc Scott Dale
			</td>
1380
		</tr>
1381 82628210 Scott Ullrich
		<tr>
1382 11d2c529 Rafael Lucas
			<td width="22%" valign="top" class="vncell"><?=gettext("Gateway");?></td>
1383 8ab3e9ed Erik Kristensen
			<td width="78%" class="vtable">
1384 ee9933b6 Renato Botelho
				<div id="showadvgatewaybox" <?php if (!empty($pconfig['gateway'])) echo "style='display:none'"; ?>>
1385 0fb885bc Carlos Eduardo Ramos
					<input type="button" onClick="show_advanced_gateway()" value="<?=gettext("Advanced"); ?>"></input> - <?=gettext("Show advanced option");?></a>
1386 0239d8ee sullrich
				</div>
1387 ee9933b6 Renato Botelho
				<div id="showgatewayadv" <?php if (empty($pconfig['gateway'])) echo "style='display:none'"; ?>>
1388 0239d8ee sullrich
					<select name='gateway'>
1389 11d2c529 Rafael Lucas
					<option value="" ><?=gettext("default");?></option>
1390 8ab3e9ed Erik Kristensen
<?php
1391 1b38ac36 Ermal
					/* build a list of gateways */
1392
					$gateways = return_gateways_array();
1393 106804a2 Chris Buechler
					// add statically configured gateways to list
1394 1b38ac36 Ermal
					foreach($gateways as $gwname => $gw) {
1395 05a4cebd smos
						if(($pconfig['ipprotocol'] == "inet46"))
1396
							continue;
1397 889cbaef Phil Davis
						if(($pconfig['ipprotocol'] == "inet6") && !(($gw['ipprotocol'] == "inet6") || (is_ipaddrv6($gw['gateway']))))
1398 270a2576 Seth Mos
							continue;
1399 889cbaef Phil Davis
						if(($pconfig['ipprotocol'] == "inet") && !(($gw['ipprotocol'] == "inet") || (is_ipaddrv4($gw['gateway']))))
1400 270a2576 Seth Mos
							continue;
1401 0239d8ee sullrich
						if($gw == "") 
1402 0581660c Scott Ullrich
							continue;
1403 1b38ac36 Ermal
						if($gwname == $pconfig['gateway']) {
1404 4443d4d6 Scott Ullrich
							$selected = " SELECTED";
1405 1fda0968 Scott Ullrich
						} else {
1406
							$selected = "";
1407
						}
1408 1b38ac36 Ermal
						echo "<option value=\"{$gwname}\" {$selected}>{$gw['name']} - {$gw['gateway']}</option>\n";
1409 106804a2 Chris Buechler
					}
1410 0239d8ee sullrich
					/* add gateway groups to the list */
1411
					if (is_array($config['gateways']['gateway_group'])) {
1412
						foreach($config['gateways']['gateway_group'] as $gw_group) {
1413 a1c10b7f Seth Mos
							$af = explode("|", $gw_group['item'][0]);
1414 05a4cebd smos
							if(($pconfig['ipprotocol'] == "inet46"))
1415
								continue;
1416 a1c10b7f Seth Mos
							if(($pconfig['ipprotocol'] == "inet6") && !is_ipaddrv6(lookup_gateway_ip_by_name($af[0])))
1417 270a2576 Seth Mos
								continue;
1418 a1c10b7f Seth Mos
							if(($pconfig['ipprotocol'] == "inet") && !is_ipaddrv4(lookup_gateway_ip_by_name($af[0])))
1419 270a2576 Seth Mos
								continue;
1420 0239d8ee sullrich
							if($gw_group['name'] == "")
1421
								continue;
1422
							if($pconfig['gateway'] == $gw_group['name']) {
1423 270a2576 Seth Mos
								$selected = " SELECTED";
1424 0239d8ee sullrich
							} else {
1425 270a2576 Seth Mos
								$selected = "";
1426 0239d8ee sullrich
							}
1427 270a2576 Seth Mos
							echo "<option value=\"{$gw_group['name']}\" $selected>{$gw_group['name']}</option>\n";
1428 0239d8ee sullrich
						}
1429
					}
1430 8ab3e9ed Erik Kristensen
?>
1431 0239d8ee sullrich
					</select>
1432 e85604b8 Chris Buechler
					<p><?=gettext("Leave as 'default' to use the system routing table.  Or choose a gateway to utilize policy based routing.");?></p>
1433 0239d8ee sullrich
				</div>
1434 8ab3e9ed Erik Kristensen
			</td>
1435
		</tr>
1436 a5fd67e1 Ermal Luçi
		<tr>
1437 11d2c529 Rafael Lucas
			<td width="22%" valign="top" class="vncell"><?=gettext("In/Out");?></td>
1438 a5fd67e1 Ermal Luçi
			<td width="78%" class="vtable">
1439 ee9933b6 Renato Botelho
				<div id="showadvinoutbox" <?php if (!empty($pconfig['dnpipe'])) echo "style='display:none'"; ?>>
1440 0fb885bc Carlos Eduardo Ramos
					<input type="button" onClick="show_advanced_inout()" value="<?=gettext("Advanced"); ?>"></input> - <?=gettext("Show advanced option");?></a>
1441 4c263f57 sullrich
				</div>
1442 ee9933b6 Renato Botelho
				<div id="showinoutadv" <?php if (empty($pconfig['dnpipe'])) echo "style='display:none'"; ?>>
1443 4c263f57 sullrich
					<select name="dnpipe">
1444 a5fd67e1 Ermal Luçi
<?php
1445
		if (!is_array($dnqlist))
1446
			$dnqlist = array();
1447
		echo "<option value=\"none\"";
1448
		if (!$dnqselected) echo " SELECTED";
1449
		echo " >none</option>";
1450
		foreach ($dnqlist as $dnq => $dnqkey) {
1451
			if($dnq == "")
1452
				continue;
1453 85a236e9 Ermal
			echo "<option value=\"$dnq\"";
1454
			if ($dnq == $pconfig['dnpipe']) {
1455 a5fd67e1 Ermal Luçi
				$dnqselected = 1;
1456
				echo " SELECTED";
1457
			}
1458
			echo ">{$dnq}</option>"; 
1459
		}
1460
?>
1461
			</select> / 			
1462
			<select name="pdnpipe">
1463
<?php
1464
		$dnqselected = 0;
1465
		echo "<option value=\"none\"";
1466
		if (!$dnqselected) echo " SELECTED";
1467
		echo " >none</option>";
1468
		foreach ($dnqlist as $dnq => $dnqkey) {
1469
			if($dnq == "")
1470
				continue;
1471 85a236e9 Ermal
			echo "<option value=\"$dnq\"";
1472
			if ($dnq == $pconfig['pdnpipe']) {
1473 a5fd67e1 Ermal Luçi
				$dnqselected = 1;
1474
				echo " SELECTED";
1475
			}
1476
			echo ">{$dnq}</option>"; 
1477
		}
1478
?>
1479 4c263f57 sullrich
				</select>
1480 a5fd67e1 Ermal Luçi
				<br />
1481 bb8f186e Chris Buechler
				<span class="vexpl"><?=gettext("Choose the Out queue/Virtual interface only if you have also selected In.")."<br/>".gettext("The Out selection is applied to traffic leaving the interface where the rule is created, In is applied to traffic coming into the chosen interface.")."<br/>".gettext("If you are creating a floating rule, if the direction is In then the same rules apply, if the direction is out the selections are reverted Out is for incoming and In is for outgoing.");?></span>
1482 4c263f57 sullrich
				</div>
1483 a5fd67e1 Ermal Luçi
			</td>
1484
		</tr>
1485
1486 197bfe96 Ermal Luçi
		<tr>
1487 11d2c529 Rafael Lucas
			<td width="22%" valign="top" class="vncell"><?=gettext("Ackqueue/Queue");?></td>
1488 197bfe96 Ermal Luçi
			<td width="78%" class="vtable">
1489 ee9933b6 Renato Botelho
			<div id="showadvackqueuebox" <?php if (!empty($pconfig['defaultqueue'])) echo "style='display:none'"; ?>>
1490 0fb885bc Carlos Eduardo Ramos
				<input type="button" onClick="show_advanced_ackqueue()" value="<?=gettext("Advanced"); ?>"></input> - <?=gettext("Show advanced option");?></a>
1491 0239d8ee sullrich
			</div>
1492 ee9933b6 Renato Botelho
			<div id="showackqueueadv" <?php if (empty($pconfig['defaultqueue'])) echo "style='display:none'"; ?>>
1493 0239d8ee sullrich
				<select name="ackqueue">
1494 197bfe96 Ermal Luçi
<?php
1495 0239d8ee sullrich
			if (!is_array($qlist))
1496
				$qlist = array();
1497
			echo "<option value=\"none\"";
1498
			if (!$qselected) echo " SELECTED";
1499
			echo " >none</option>";
1500
			foreach ($qlist as $q => $qkey) {
1501
				if($q == "")
1502
					continue;
1503
				echo "<option value=\"$q\"";
1504
				if ($q == $pconfig['ackqueue']) {
1505
					$qselected = 1;
1506
					echo " SELECTED";
1507
				}
1508 199791f9 Ermal
				if (isset($ifdisp[$q]))
1509
					echo ">{$ifdisp[$q]}</option>";
1510
				else
1511
					echo ">{$q}</option>"; 
1512 197bfe96 Ermal Luçi
			}
1513
?>
1514 0239d8ee sullrich
				</select> / 			
1515
				<select name="defaultqueue">
1516 197bfe96 Ermal Luçi
<?php
1517 0239d8ee sullrich
			$qselected = 0;
1518
			echo "<option value=\"none\"";
1519
			if (!$qselected) echo " SELECTED";
1520
			echo " >none</option>";
1521
			foreach ($qlist as $q => $qkey) {
1522
				if($q == "")
1523
					continue;
1524
				echo "<option value=\"$q\"";
1525
				if ($q == $pconfig['defaultqueue']) {
1526
					$qselected = 1;
1527
					echo " SELECTED";
1528
				}
1529 199791f9 Ermal
				if (isset($ifdisp[$q]))
1530
					echo ">{$ifdisp[$q]}</option>";
1531
				else
1532
					echo ">{$q}</option>"; 
1533 197bfe96 Ermal Luçi
			}
1534
?>
1535 0239d8ee sullrich
				</select>
1536
					<br />
1537 11d2c529 Rafael Lucas
					<span class="vexpl"><?=gettext("Choose the Acknowledge Queue only if you have selected Queue.");?></span>
1538 0239d8ee sullrich
				</td>
1539
			</tr>
1540
			<tr>
1541 11d2c529 Rafael Lucas
				<td width="22%" valign="top" class="vncell"><?=gettext("Layer7");?></td>
1542 0239d8ee sullrich
				<td width="78%" class="vtable">
1543 ee9933b6 Renato Botelho
					<div id="showadvlayer7box" <?php if (!empty($pconfig['l7container'])) echo "style='display:none'"; ?>>
1544 0fb885bc Carlos Eduardo Ramos
						<input type="button" onClick="show_advanced_layer7()" value="<?=gettext("Advanced"); ?>"></input> - <?=gettext("Show advanced option");?></a>
1545 4c263f57 sullrich
					</div>
1546 ee9933b6 Renato Botelho
					<div id="showlayer7adv" <?php if (empty($pconfig['l7container'])) echo "style='display:none'"; ?>>
1547 0239d8ee sullrich
				<select name="l7container">
1548 7e50413c Ermal Luçi
<?php
1549 0239d8ee sullrich
					if (!is_array($l7clist))
1550 06e2a55d thompsa
						$l7clist = array();
1551 0239d8ee sullrich
					echo "<option value=\"none\"";
1552
					echo " >none</option>";
1553
					foreach ($l7clist as $l7ckey) {
1554
						echo "<option value=\"{$l7ckey}\"";
1555
						if ($l7ckey == $pconfig['l7container']) {
1556
							echo " SELECTED";
1557
						}
1558
						echo ">{$l7ckey}</option>"; 
1559
					}
1560 7e50413c Ermal Luçi
?>
1561 0239d8ee sullrich
				</select>			
1562 7e50413c Ermal Luçi
				<br/>
1563 0239d8ee sullrich
				<span class="vexpl">
1564 4fe84f51 Carlos Eduardo Ramos
					<?=gettext("Choose a Layer7 container to apply application protocol inspection rules. " .
1565
					"These are valid for TCP and UDP protocols only.");?>
1566 0239d8ee sullrich
				</span>
1567
			  </div>
1568 7e50413c Ermal Luçi
			</td>
1569
		</tr>
1570 d65962a7 Scott Ullrich
<?php
1571
		// Allow extending of the firewall edit page and include custom input validation 
1572
		pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/htmlphplate");
1573
?>
1574 ba1d9714 jim-p
<?php
1575
$has_created_time = (isset($a_filter[$id]['created']) && is_array($a_filter[$id]['created']));
1576
$has_updated_time = (isset($a_filter[$id]['updated']) && is_array($a_filter[$id]['updated']));
1577
?>
1578
		<?php if ($has_created_time || $has_updated_time): ?>
1579
		<tr>
1580
			<td>&nbsp;</td>
1581
		</tr>
1582
		<tr>
1583
			<td colspan="2" valign="top" class="listtopic"><?=gettext("Rule Information");?></td>
1584
		</tr>
1585
		<?php if ($has_created_time): ?>
1586
		<tr>
1587
			<td width="22%" valign="top" class="vncell"><?=gettext("Created");?></td>
1588
			<td width="78%" class="vtable">
1589
				<?= date(gettext("n/j/y H:i:s"), $a_filter[$id]['created']['time']) ?> <?= gettext("by") ?> <strong><?= $a_filter[$id]['created']['username'] ?></strong>
1590
			</td>
1591
		</tr>
1592
		<?php endif; ?>
1593
		<?php if ($has_updated_time): ?>
1594
		<tr>
1595
			<td width="22%" valign="top" class="vncell"><?=gettext("Updated");?></td>
1596
			<td width="78%" class="vtable">
1597
				<?= date(gettext("n/j/y H:i:s"), $a_filter[$id]['updated']['time']) ?> <?= gettext("by") ?> <strong><?= $a_filter[$id]['updated']['username'] ?></strong>
1598
			</td>
1599
		</tr>
1600
		<?php endif; ?>
1601
		<?php endif; ?>
1602 8ab3e9ed Erik Kristensen
		<tr>
1603
			<td width="22%" valign="top">&nbsp;</td>
1604
			<td width="78%">
1605 151eb2a9 sullrich
				&nbsp;<br>&nbsp;
1606 157a6919 Carlos Eduardo Ramos
				<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>">  <input type="button" class="formbtn" value="<?=gettext("Cancel"); ?>" onclick="history.back()">
1607 8ab3e9ed Erik Kristensen
<?php			if (isset($id) && $a_filter[$id]): ?>
1608 225a2f0b Scott Ullrich
					<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>">
1609 8ab3e9ed Erik Kristensen
<?php 			endif; ?>
1610 225a2f0b Scott Ullrich
				<input name="after" type="hidden" value="<?=htmlspecialchars($after);?>">
1611 8ab3e9ed Erik Kristensen
			</td>
1612 82628210 Scott Ullrich
		</tr>
1613 8ab3e9ed Erik Kristensen
	</table>
1614 5b237745 Scott Ullrich
</form>
1615
<script language="JavaScript">
1616 4dfd930e Darren Embry
//<![CDATA[
1617 8ab3e9ed Erik Kristensen
	ext_change();
1618
	typesel_change();
1619
	proto_change();
1620 3e74107e Erik Fonnesbeck
	<?php if ( (!empty($pconfig['srcbeginport']) && $pconfig['srcbeginport'] != "any") || (!empty($pconfig['srcendport']) && $pconfig['srcendport'] != "any") ): ?>
1621
	show_source_port_range();
1622
	<?php endif; ?>
1623 19757279 Scott Ullrich
1624 4dfd930e Darren Embry
	var addressarray = <?= json_encode(get_alias_list(array("host", "network", "openvpn", "urltable"))) ?>;
1625
	var customarray  = <?= json_encode(get_alias_list("port")) ?>;
1626 19757279 Scott Ullrich
1627 9eb60dcc Ermal Lu?i
	var oTextbox1 = new AutoSuggestControl(document.getElementById("src"), new StateSuggestions(addressarray));
1628
        var oTextbox2 = new AutoSuggestControl(document.getElementById("srcbeginport_cust"), new StateSuggestions(customarray));
1629
        var oTextbox3 = new AutoSuggestControl(document.getElementById("srcendport_cust"), new StateSuggestions(customarray));
1630
        var oTextbox4 = new AutoSuggestControl(document.getElementById("dst"), new StateSuggestions(addressarray));
1631
        var oTextbox5 = new AutoSuggestControl(document.getElementById("dstbeginport_cust"), new StateSuggestions(customarray));
1632
        var oTextbox6 = new AutoSuggestControl(document.getElementById("dstendport_cust"), new StateSuggestions(customarray));
1633 4dfd930e Darren Embry
//]]>
1634 5b237745 Scott Ullrich
</script>
1635
<?php include("fend.inc"); ?>
1636
</body>
1637 9b45f821 Ermal Lu?i
</html>