Project

General

Profile

Download (64.3 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	firewall_rules_edit.php
5
	part of pfSense (http://www.pfsense.com)
6
        Copyright (C) 2005 Scott Ullrich (sullrich@gmail.com)
7

    
8
	originally part of m0n0wall (http://m0n0.ch/wall)
9
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
10
	All rights reserved.
11

    
12
	Redistribution and use in source and binary forms, with or without
13
	modification, are permitted provided that the following conditions are met:
14

    
15
	1. Redistributions of source code must retain the above copyright notice,
16
	   this list of conditions and the following disclaimer.
17

    
18
	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

    
22
	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
*/
33
/*
34
	pfSense_MODULE:	filter
35
*/
36

    
37
##|+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
require("guiconfig.inc");
45
require("filter.inc");
46
require("shaper.inc");
47

    
48
$specialsrcdst = explode(" ", "any pptp pppoe l2tp openvpn");
49
$ifdisp = get_configured_interface_with_descr();
50
foreach ($ifdisp as $kif => $kdescr) {
51
	$specialsrcdst[] = "{$kif}";
52
	$specialsrcdst[] = "{$kif}ip";
53
}
54

    
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

    
65
$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

    
78
	if (isset($a_filter[$id]['id']))
79
		$pconfig['ruleid'] = $a_filter[$id]['id'];
80

    
81
	if (!isset($a_filter[$id]['type']))
82
		$pconfig['type'] = "pass";
83
	else
84
		$pconfig['type'] = $a_filter[$id]['type'];
85

    
86
	if (isset($a_filter[$id]['floating']) || $if == "FloatingRules") {
87
		$pconfig['floating'] = $a_filter[$id]['floating'];
88
		if (isset($a_filter[$id]['interface']) && $a_filter[$id]['interface'] <> "") 
89
			$pconfig['interface'] = $a_filter[$id]['interface'];
90
	}
91
	
92
	if (isset($a_filter['floating'])) 
93
		$pconfig['floating'] = "yes";
94

    
95
	if (isset($a_filter[$id]['direction']))
96
                $pconfig['direction'] = $a_filter[$id]['direction'];
97

    
98
	if (isset($a_filter[$id]['protocol']))
99
		$pconfig['proto'] = $a_filter[$id]['protocol'];
100
	else
101
		$pconfig['proto'] = "any";
102

    
103
	if ($a_filter[$id]['protocol'] == "icmp")
104
		$pconfig['icmptype'] = $a_filter[$id]['icmptype'];
105

    
106
	address_to_pconfig($a_filter[$id]['source'], $pconfig['src'],
107
		$pconfig['srcmask'], $pconfig['srcnot'],
108
		$pconfig['srcbeginport'], $pconfig['srcendport']);
109

    
110
	if($a_filter[$id]['os'] <> "")
111
		$pconfig['os'] = $a_filter[$id]['os'];
112

    
113
	address_to_pconfig($a_filter[$id]['destination'], $pconfig['dst'],
114
		$pconfig['dstmask'], $pconfig['dstnot'],
115
		$pconfig['dstbeginport'], $pconfig['dstendport']);
116

    
117
	if ($a_filter[$id]['dscp'] <> "")
118
		$pconfig['dscp'] = $a_filter[$id]['dscp'];
119

    
120
	$pconfig['disabled'] = isset($a_filter[$id]['disabled']);
121
	$pconfig['log'] = isset($a_filter[$id]['log']);
122
	$pconfig['descr'] = $a_filter[$id]['descr'];
123

    
124
	if (isset($a_filter[$id]['tcpflags_any']))
125
		$pconfig['tcpflags_any'] = true;
126
	else {
127
		if (isset($a_filter[$id]['tcpflags1']) && $a_filter[$id]['tcpflags1'] <> "") 
128
			$pconfig['tcpflags1'] = $a_filter[$id]['tcpflags1'];
129
		if (isset($a_filter[$id]['tcpflags2']) && $a_filter[$id]['tcpflags2'] <> "") 
130
			$pconfig['tcpflags2'] = $a_filter[$id]['tcpflags2'];
131
	}
132

    
133
	if (isset($a_filter[$id]['tag']) && $a_filter[$id]['tag'] <> "") 
134
		$pconfig['tag'] = $a_filter[$id]['tag'];
135
	if (isset($a_filter[$id]['tagged']) && $a_filter[$id]['tagged'] <> "")
136
        	$pconfig['tagged'] = $a_filter[$id]['tagged'];
137
	if (isset($a_filter[$id]['quick']) && $a_filter[$id]['quick'])
138
		$pconfig['quick'] = $a_filter[$id]['quick'];
139
	if (isset($a_filter[$id]['allowopts']))
140
		$pconfig['allowopts'] = true;
141
	if (isset($a_filter[$id]['disablereplyto']))
142
		$pconfig['disablereplyto'] = true;
143

    
144
	/* advanced */
145
	$pconfig['max'] = $a_filter[$id]['max'];
146
	$pconfig['max-src-nodes'] = $a_filter[$id]['max-src-nodes'];
147
	$pconfig['max-src-conn'] = $a_filter[$id]['max-src-conn'];
148
	$pconfig['max-src-states'] = $a_filter[$id]['max-src-states'];
149
	$pconfig['statetype'] = $a_filter[$id]['statetype'];
150
	$pconfig['statetimeout'] = $a_filter[$id]['statetimeout'];
151

    
152
	/* advanced - nosync */
153
	$pconfig['nosync'] = isset($a_filter[$id]['nosync']);
154

    
155
	/* advanced - new connection per second banning*/
156
	$pconfig['max-src-conn-rate'] = $a_filter[$id]['max-src-conn-rate'];
157
	$pconfig['max-src-conn-rates'] = $a_filter[$id]['max-src-conn-rates'];
158

    
159
	/* Multi-WAN next-hop support */
160
	$pconfig['gateway'] = $a_filter[$id]['gateway'];
161
	
162
	/* Shaper support */
163
	$pconfig['defaultqueue'] = $a_filter[$id]['defaultqueue'];
164
	$pconfig['ackqueue'] = $a_filter[$id]['ackqueue'];
165
	$pconfig['dnpipe'] = $a_filter[$id]['dnpipe'];
166
	$pconfig['pdnpipe'] = $a_filter[$id]['pdnpipe'];
167
	$pconfig['l7container'] = $a_filter[$id]['l7container'];
168

    
169
	//schedule support
170
	$pconfig['sched'] = $a_filter[$id]['sched'];
171
	if (!isset($_GET['dup']))
172
		$pconfig['associated-rule-id'] = $a_filter[$id]['associated-rule-id'];
173

    
174
} else {
175
	/* defaults */
176
	if ($_GET['if'])
177
		$pconfig['interface'] = $_GET['if'];
178
	$pconfig['type'] = "pass";
179
	$pconfig['src'] = "any";
180
	$pconfig['dst'] = "any";
181
}
182
/* Allow the FlotingRules to work */
183
$if = $pconfig['interface'];
184

    
185
if (isset($_GET['dup']))
186
	unset($id);
187

    
188
if ($_POST) {
189

    
190
	if( isset($a_filter[$id]['associated-rule-id']) ) {
191
		$_POST['proto'] = $pconfig['proto'];
192
		if ($pconfig['proto'] == "icmp")
193
			$_POST['icmptype'] = $pconfig['icmptype'];
194
	}
195

    
196
	if ($_POST['type'] == "reject" && $_POST['proto'] <> "tcp")
197
		$input_errors[] = gettext("Reject type rules only works when the protocol is set to TCP.");
198

    
199
	if ($_POST['type'] == "match" && $_POST['defaultqueue'] == "none")
200
		$input_errors[] = gettext("Queue type rules only work with queues.");
201

    
202
	if (($_POST['proto'] != "tcp") && ($_POST['proto'] != "udp") && ($_POST['proto'] != "tcp/udp")) {
203
		$_POST['srcbeginport'] = 0;
204
		$_POST['srcendport'] = 0;
205
		$_POST['dstbeginport'] = 0;
206
		$_POST['dstendport'] = 0;
207
	} else {
208

    
209
		if ($_POST['srcbeginport_cust'] && !$_POST['srcbeginport'])
210
			$_POST['srcbeginport'] = $_POST['srcbeginport_cust'];
211
		if ($_POST['srcendport_cust'] && !$_POST['srcendport'])
212
			$_POST['srcendport'] = $_POST['srcendport_cust'];
213

    
214
		if ($_POST['srcbeginport'] == "any") {
215
			$_POST['srcbeginport'] = 0;
216
			$_POST['srcendport'] = 0;
217
		} else {
218
			if (!$_POST['srcendport'])
219
				$_POST['srcendport'] = $_POST['srcbeginport'];
220
		}
221
		if ($_POST['srcendport'] == "any")
222
			$_POST['srcendport'] = $_POST['srcbeginport'];
223

    
224
		if ($_POST['dstbeginport_cust'] && !$_POST['dstbeginport'])
225
			$_POST['dstbeginport'] = $_POST['dstbeginport_cust'];
226
		if ($_POST['dstendport_cust'] && !$_POST['dstendport'])
227
			$_POST['dstendport'] = $_POST['dstendport_cust'];
228

    
229
		if ($_POST['dstbeginport'] == "any") {
230
			$_POST['dstbeginport'] = 0;
231
			$_POST['dstendport'] = 0;
232
		} else {
233
			if (!$_POST['dstendport'])
234
				$_POST['dstendport'] = $_POST['dstbeginport'];
235
		}
236
		if ($_POST['dstendport'] == "any")
237
			$_POST['dstendport'] = $_POST['dstbeginport'];
238
	}
239

    
240
	if (is_specialnet($_POST['srctype'])) {
241
		$_POST['src'] = $_POST['srctype'];
242
		$_POST['srcmask'] = 0;
243
	} else if ($_POST['srctype'] == "single") {
244
		$_POST['srcmask'] = 32;
245
	}
246
	if (is_specialnet($_POST['dsttype'])) {
247
		$_POST['dst'] = $_POST['dsttype'];
248
		$_POST['dstmask'] = 0;
249
	}  else if ($_POST['dsttype'] == "single") {
250
		$_POST['dstmask'] = 32;
251
	}
252

    
253
	unset($input_errors);
254
	$pconfig = $_POST;
255

    
256
	/* input validation */
257
	$reqdfields = explode(" ", "type proto");
258
	if ( isset($a_filter[$id]['associated-rule-id'])===false ) {
259
		$reqdfields[] = "src";
260
		$reqdfields[] = "dst";
261
	}
262
	$reqdfieldsn = explode(",", "Type,Protocol");
263
	if ( isset($a_filter[$id]['associated-rule-id'])===false ) {
264
		$reqdfieldsn[] = "Source";
265
		$reqdfieldsn[] = "Destination";
266
	}
267

    
268
	if($_POST['statetype'] == "modulate state" or $_POST['statetype'] == "synproxy state") {
269
		if( $_POST['proto'] != "tcp" )
270
			$input_errors[] = sprintf(gettext("%s is only valid with protocol tcp."),$_POST['statetype']);
271
		if(($_POST['statetype'] == "synproxy state") && ($_POST['gateway'] != ""))
272
			$input_errors[] = sprintf(gettext("%s is only valid if the gateway is set to 'default'."),$_POST['statetype']);
273
	}
274
        
275
	if ( isset($a_filter[$id]['associated-rule-id'])===false &&
276
	(!(is_specialnet($_POST['srctype']) || ($_POST['srctype'] == "single"))) ) {
277
		$reqdfields[] = "srcmask";
278
		$reqdfieldsn[] = "Source bit count";
279
	}
280
	if ( isset($a_filter[$id]['associated-rule-id'])===false &&
281
	(!(is_specialnet($_POST['dsttype']) || ($_POST['dsttype'] == "single"))) ) {
282
		$reqdfields[] = "dstmask";
283
		$reqdfieldsn[] = gettext("Destination bit count");
284
	}
285

    
286
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
287

    
288
	if (!$_POST['srcbeginport']) {
289
		$_POST['srcbeginport'] = 0;
290
		$_POST['srcendport'] = 0;
291
	}
292
	if (!$_POST['dstbeginport']) {
293
		$_POST['dstbeginport'] = 0;
294
		$_POST['dstendport'] = 0;
295
	}
296

    
297
	if ($_POST['srcbeginport'] && !is_portoralias($_POST['srcbeginport']))
298
                $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']);
299
        if ($_POST['srcendport'] && !is_portoralias($_POST['srcendport']))
300
                $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']);
301
        if ($_POST['dstbeginport'] && !is_portoralias($_POST['dstbeginport']))
302
                $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']);
303
        if ($_POST['dstendport'] && !is_portoralias($_POST['dstendport']))
304
                $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']);
305
	if ( !$_POST['srcbeginport_cust'] && $_POST['srcendport_cust'])
306
		if (is_alias($_POST['srcendport_cust']))
307
			$input_errors[] = 'If you put port alias in Source port range to: field you must put the same port alias in from: field';
308
	if ( $_POST['srcbeginport_cust'] && $_POST['srcendport_cust']){
309
		if (is_alias($_POST['srcendport_cust']) && is_alias($_POST['srcendport_cust']) && $_POST['srcbeginport_cust'] != $_POST['srcendport_cust'])
310
			$input_errors[] = 'The same port alias must be used in Source port range from: and to: fields';
311
		if ((is_alias($_POST['srcbeginport_cust']) && (!is_alias($_POST['srcendport_cust']) && $_POST['srcendport_cust']!='')) || 
312
		    ((!is_alias($_POST['srcbeginport_cust']) && $_POST['srcbeginport_cust']!='') && is_alias($_POST['srcendport_cust']))) 
313
			$input_errors[] = 'You cannot specify numbers and port aliases at the same time in Source port range from: and to: field';
314
	}
315
	if ( !$_POST['dstbeginport_cust'] && $_POST['dstendport_cust'])
316
		if (is_alias($_POST['dstendport_cust']))
317
			$input_errors[] = 'If you put port alias in Destination port range to: field you must put the same port alias in from: field';
318
	if ( $_POST['dstbeginport_cust'] && $_POST['dstendport_cust']){
319
		if (is_alias($_POST['dstendport_cust']) && is_alias($_POST['dstendport_cust']) && $_POST['dstbeginport_cust'] != $_POST['dstendport_cust'])
320
			$input_errors[] = 'The same port alias must be used in Destination port range from: and to: fields';
321
		if ((is_alias($_POST['dstbeginport_cust']) && (!is_alias($_POST['dstendport_cust']) && $_POST['dstendport_cust']!='')) || 
322
		    ((!is_alias($_POST['dstbeginport_cust']) && $_POST['dstbeginport_cust']!='') && is_alias($_POST['dstendport_cust']))) 
323
			$input_errors[] = 'You cannot specify numbers and port aliases at the same time in Destination port range from: and to: field';
324
	}
325

    
326
	/* if user enters an alias and selects "network" then disallow. */
327
	if($_POST['srctype'] == "network") {
328
		if(is_alias($_POST['src']))
329
			$input_errors[] = gettext("You must specify single host or alias for alias entries.");
330
	}
331
	if($_POST['dsttype'] == "network") {
332
		if(is_alias($_POST['dst']))
333
			$input_errors[] = gettext("You must specify single host or alias for alias entries.");
334
	}
335

    
336
	if (!is_specialnet($_POST['srctype'])) {
337
		if (($_POST['src'] && !is_ipaddroralias($_POST['src']))) {
338
			$input_errors[] = sprintf(gettext("%s is not a valid source IP address or alias."),$_POST['src']);
339
		}
340
		if (($_POST['srcmask'] && !is_numericint($_POST['srcmask']))) {
341
			$input_errors[] = gettext("A valid source bit count must be specified.");
342
		}
343
	}
344
	if (!is_specialnet($_POST['dsttype'])) {
345
		if (($_POST['dst'] && !is_ipaddroralias($_POST['dst']))) {
346
			$input_errors[] = sprintf(gettext("%s is not a valid destination IP address or alias."),$_POST['dst']);
347
		}
348
		if (($_POST['dstmask'] && !is_numericint($_POST['dstmask']))) {
349
			$input_errors[] = gettext("A valid destination bit count must be specified.");
350
		}
351
	}
352

    
353
	if ($_POST['srcbeginport'] > $_POST['srcendport']) {
354
		/* swap */
355
		$tmp = $_POST['srcendport'];
356
		$_POST['srcendport'] = $_POST['srcbeginport'];
357
		$_POST['srcbeginport'] = $tmp;
358
	}
359
	if ($_POST['dstbeginport'] > $_POST['dstendport']) {
360
		/* swap */
361
		$tmp = $_POST['dstendport'];
362
		$_POST['dstendport'] = $_POST['dstbeginport'];
363
		$_POST['dstbeginport'] = $tmp;
364
	}
365
	if ($_POST['os'])
366
		if( $_POST['proto'] != "tcp" )
367
			$input_errors[] = gettext("OS detection is only valid with protocol tcp.");
368

    
369
	if ($_POST['ackqueue'] && $_POST['ackqueue'] != "none") {
370
		if ($_POST['defaultqueue'] == "none" )
371
			$input_errors[] = gettext("You have to select a queue when you select an acknowledge queue too.");
372
		else if ($_POST['ackqueue'] == $_POST['defaultqueue'])
373
			$input_errors[] = gettext("Acknowledge queue and Queue cannot be the same.");		
374
	}
375
	if (isset($_POST['floating']) && $_POST['pdnpipe'] != "none" && (empty($_POST['direction']) || $_POST['direction'] == "any"))
376
		$input_errors[] = gettext("You can not use limiters in Floating rules without choosing a direction.");
377
	if (isset($_POST['floating']) && $_POST['gateway'] != "" && (empty($_POST['direction']) || $_POST['direction'] == "any"))
378
		$input_errors[] = gettext("You can not use gateways in Floating rules without choosing a direction.");
379
	if ($_POST['pdnpipe'] && $_POST['pdnpipe'] != "none") {
380
		if ($_POST['dnpipe'] == "none" )
381
			$input_errors[] = gettext("You must select a queue for the In direction before selecting one for Out too.");
382
		else if ($_POST['pdnpipe'] == $_POST['dnpipe'])
383
			$input_errors[] = gettext("In and Out Queue cannot be the same.");
384
		else if ($pdnpipe[0] == "?" && $dnpipe[0] <> "?")
385
			$input_errors[] = gettext("You cannot select one queue and one virtual interface for IN and Out. both must be from the same type.");
386
		else if ($dnpipe[0] == "?" && $pdnpipe[0] <> "?")			
387
			$input_errors[] = gettext("You cannot select one queue and one virtual interface for IN and Out. both must be from the same type.");
388
	}
389
	if( !empty($_POST['ruleid']) && !ctype_digit($_POST['ruleid']))
390
		$input_errors[] = gettext('ID must be an integer');
391
	if($_POST['l7container'] && $_POST['l7container'] != "none") {
392
		if(!($_POST['proto'] == "tcp" || $_POST['proto'] == "udp" || $_POST['proto'] == "tcp/udp"))
393
			$input_errors[] = gettext("You can only select a layer7 container for TCP and/or UDP protocols");
394
		if ($_POST['type'] <> "pass")
395
			$input_errors[] = gettext("You can only select a layer7 container for Pass type rules.");
396
	}
397

    
398
	if (!$_POST['tcpflags_any']) {
399
		$settcpflags = array();
400
		$outoftcpflags = array();
401
		foreach ($tcpflags as $tcpflag) {
402
			if ($_POST['tcpflags1_' . $tcpflag] == "on")
403
				$settcpflags[] = $tcpflag;
404
			if ($_POST['tcpflags2_' . $tcpflag] == "on")
405
				$outoftcpflags[] = $tcpflag;
406
		}
407
		if (empty($outoftcpflags) && !empty($settcpflags))
408
			$input_errors[] = gettext("If you specify TCP flags that should be set you should specify out of which flags as well.");
409
	}
410

    
411
	// Allow extending of the firewall edit page and include custom input validation 
412
	pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/input_validation");
413

    
414
	if (!$input_errors) {
415
		$filterent = array();
416
		$filterent['id'] = $_POST['ruleid']>0?$_POST['ruleid']:'';
417
		$filterent['type'] = $_POST['type'];
418
		if (isset($_POST['interface'] ))
419
			$filterent['interface'] = $_POST['interface'];
420

    
421
		if ($_POST['tcpflags_any']) {
422
			$filterent['tcpflags_any'] = true;
423
		} else {
424
			$settcpflags = array();
425
			$outoftcpflags = array();
426
			foreach ($tcpflags as $tcpflag) {
427
				if ($_POST['tcpflags1_' . $tcpflag] == "on")
428
					$settcpflags[] = $tcpflag;
429
				if ($_POST['tcpflags2_' . $tcpflag] == "on")
430
					$outoftcpflags[] = $tcpflag;
431
			}
432
			if (!empty($outoftcpflags)) {
433
				$filterent['tcpflags2'] = join(",", $outoftcpflags);
434
				if (!empty($settcpflags))
435
					$filterent['tcpflags1'] = join(",", $settcpflags);
436
			}
437
		}
438

    
439
		if (isset($_POST['tag']))
440
			$filterent['tag'] = $_POST['tag'];
441
		if (isset($_POST['tagged']))
442
			$filterent['tagged'] = $_POST['tagged'];
443
		if ($if == "FloatingRules" || isset($_POST['floating'])) {
444
			$filterent['direction'] = $_POST['direction'];
445
			if (isset($_POST['quick']) && $_POST['quick'] <> "")
446
				$filterent['quick'] = $_POST['quick'];
447
			$filterent['floating'] = "yes";
448
			if (isset($_POST['interface']) && count($_POST['interface']) > 0)  {
449
				$filterent['interface'] = implode(",", $_POST['interface']);
450
			}
451
		}
452

    
453
		/* Advanced options */
454
		if ($_POST['allowopts'] == "yes")
455
			$filterent['allowopts'] = true;
456
		else
457
			unset($filterent['allowopts']);
458
		if ($_POST['disablereplyto'] == "yes")
459
			$filterent['disablereplyto'] = true;
460
		else
461
			unset($filterent['disablereplyto']);
462
		$filterent['max'] = $_POST['max'];
463
		$filterent['max-src-nodes'] = $_POST['max-src-nodes'];
464
		$filterent['max-src-conn'] = $_POST['max-src-conn'];
465
		$filterent['max-src-states'] = $_POST['max-src-states'];
466
		$filterent['statetimeout'] = $_POST['statetimeout'];
467
		$filterent['statetype'] = $_POST['statetype'];
468
		$filterent['os'] = $_POST['os'];
469

    
470
		/* Nosync directive - do not xmlrpc sync this item */
471
		if($_POST['nosync'] <> "")
472
			$filterent['nosync'] = true;
473
		else
474
			unset($filterent['nosync']);
475

    
476
		/* unless both values are provided, unset the values - ticket #650 */
477
		if($_POST['max-src-conn-rate'] <> "" and $_POST['max-src-conn-rates'] <> "") {
478
			$filterent['max-src-conn-rate'] = $_POST['max-src-conn-rate'];
479
			$filterent['max-src-conn-rates'] = $_POST['max-src-conn-rates'];
480
		} else {
481
			unset($filterent['max-src-conn-rate']);
482
			unset($filterent['max-src-conn-rates']);
483
		}
484

    
485
		if ($_POST['proto'] != "any")
486
			$filterent['protocol'] = $_POST['proto'];
487
		else
488
			unset($filterent['protocol']);
489

    
490
		if ($_POST['proto'] == "icmp" && $_POST['icmptype'])
491
			$filterent['icmptype'] = $_POST['icmptype'];
492
		else
493
			unset($filterent['icmptype']);
494

    
495
		pconfig_to_address($filterent['source'], $_POST['src'],
496
			$_POST['srcmask'], $_POST['srcnot'],
497
			$_POST['srcbeginport'], $_POST['srcendport']);
498

    
499
		pconfig_to_address($filterent['destination'], $_POST['dst'],
500
			$_POST['dstmask'], $_POST['dstnot'],
501
			$_POST['dstbeginport'], $_POST['dstendport']);
502

    
503
		if ($_POST['disabled'])
504
			$filterent['disabled'] = true;
505
		else
506
			unset($filterent['disabled']);
507

    
508
		if ($_POST['dscp'])
509
			$filterent['dscp'] = $_POST['dscp'];
510

    
511
		if ($_POST['log'])
512
			$filterent['log'] = true;
513
		else
514
			unset($filterent['log']);
515
		strncpy($filterent['descr'], $_POST['descr'], 52);
516

    
517
		if ($_POST['gateway'] != "") {
518
			$filterent['gateway'] = $_POST['gateway'];
519
		}
520
		
521
		if (isset($_POST['defaultqueue']) && $_POST['defaultqueue'] != "none") {
522
			$filterent['defaultqueue'] = $_POST['defaultqueue'];
523
			if (isset($_POST['ackqueue']) && $_POST['ackqueue'] != "none")
524
				$filterent['ackqueue'] = $_POST['ackqueue'];
525
		}
526

    
527
		if (isset($_POST['dnpipe']) && $_POST['dnpipe'] != "none") {
528
			$filterent['dnpipe'] = $_POST['dnpipe'];
529
			if (isset($_POST['pdnpipe']) && $_POST['pdnpipe'] != "none")
530
				$filterent['pdnpipe'] = $_POST['pdnpipe'];
531
		}
532

    
533
		if (isset($_POST['l7container']) && $_POST['l7container'] != "none") {
534
			$filterent['l7container'] = $_POST['l7container'];
535
		}
536
		
537
		if ($_POST['sched'] != "") {
538
			$filterent['sched'] = $_POST['sched'];
539
		}
540

    
541
		// If we have an associated nat rule, make sure the source and destination doesn't change
542
		if( isset($a_filter[$id]['associated-rule-id']) ) {
543
			$filterent['interface'] = $a_filter[$id]['interface'];
544
			if (isset($a_filter[$id]['protocol']))
545
				$filterent['protocol'] = $a_filter[$id]['protocol'];
546
			else if (isset($filterent['protocol']))
547
				unset($filterent['protocol']);
548
			if ($a_filter[$id]['protocol'] == "icmp" && $a_filter[$id]['icmptype'])
549
				$filterent['icmptype'] = $a_filter[$id]['icmptype'];
550
			else if (isset($filterent['icmptype']))
551
				unset($filterent['icmptype']);
552
			$filterent['source'] = $a_filter[$id]['source'];
553
			$filterent['destination'] = $a_filter[$id]['destination'];
554
			$filterent['associated-rule-id'] = $a_filter[$id]['associated-rule-id'];
555
		}
556

    
557
		// Allow extending of the firewall edit page and include custom input validation 
558
		pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/pre_write_config");
559

    
560
		if (isset($id) && $a_filter[$id])
561
			$a_filter[$id] = $filterent;
562
		else {
563
			if (is_numeric($after))
564
				array_splice($a_filter, $after+1, 0, array($filterent));
565
			else
566
				$a_filter[] = $filterent;
567
		}
568

    
569
		filter_rules_sort();
570

    
571
		write_config();
572
		mark_subsystem_dirty('filter');
573

    
574
		if (isset($_POST['floating']))
575
			header("Location: firewall_rules.php?if=FloatingRules");
576
		else
577
			header("Location: firewall_rules.php?if=" . $_POST['interface']);
578
		exit;
579
	}
580
}
581

    
582
read_altq_config(); /* XXX: */
583
$qlist =& get_unique_queue_list();
584
read_dummynet_config(); /* XXX: */
585
$dnqlist =& get_unique_dnqueue_list();
586
read_layer7_config();
587
$l7clist =& get_l7_unique_list();
588

    
589
$pgtitle = array(gettext("Firewall"),gettext("Rules"),gettext("Edit"));
590
$statusurl = "status_filter_reload.php";
591
$logurl = "diag_logs_filter.php";
592

    
593
$closehead = false;
594

    
595
$page_filename = "firewall_rules_edit.php";
596
include("head.inc");
597

    
598
?>
599
<link rel="stylesheet" href="/pfCenter/javascript/chosen/chosen.css" />
600
</head>
601

    
602
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
603
<script src="/pfCenter/javascript/chosen/chosen.proto.js" type="text/javascript"></script>
604
<?php include("fbegin.inc"); ?>
605
<?php pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/pre_input_errors"); ?>
606
<?php if ($input_errors) print_input_errors($input_errors); ?>
607

    
608
<form action="firewall_rules_edit.php" method="post" name="iform" id="iform">
609
<input type='hidden' name="ruleid" value="<?=(isset($pconfig['ruleid'])&&$pconfig['ruleid']>0)?htmlspecialchars($pconfig['ruleid']):''?>">
610

    
611
	<table width="100%" border="0" cellpadding="6" cellspacing="0">
612
		<tr>
613
			<td colspan="2" valign="top" class="listtopic"><?=gettext("Edit Firewall rule");?></td>
614
		</tr>	
615
<?php
616
		// Allow extending of the firewall edit page and include custom input validation 
617
		pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/htmlphpearly");
618
?>
619
    	<tr>
620
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Action");?></td>
621
			<td width="78%" class="vtable">
622
				<select name="type" class="formselect">
623
					<?php $types = explode(" ", "Pass Block Reject"); foreach ($types as $type): ?>
624
					<option value="<?=strtolower($type);?>" <?php if (strtolower($type) == strtolower($pconfig['type'])) echo "selected"; ?>>
625
					<?=htmlspecialchars($type);?>
626
					</option>
627
					<?php endforeach; ?>
628
<?php if ($if == "FloatingRules" || isset($pconfig['floating'])): ?>
629
					<option value="match" <?php if ("match" == strtolower($pconfig['type'])) echo "selected"; ?>>Queue</option>
630
<?php endif; ?>
631
				</select>
632
				<br/>
633
				<span class="vexpl">
634
					<?=gettext("Choose what to do with packets that match the criteria specified below.");?> <br/>
635
					<?=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.");?> 
636
				</span>
637
			</td>
638
		</tr>
639
		<tr>
640
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Disabled");?></td>
641
			<td width="78%" class="vtable">
642
				<input name="disabled" type="checkbox" id="disabled" value="yes" <?php if ($pconfig['disabled']) echo "checked"; ?>>
643
				<strong><?=gettext("Disable this rule");?></strong><br />
644
				<span class="vexpl"><?=gettext("Set this option to disable this rule without removing it from the list.");?></span>
645
			</td>
646
		</tr>
647
<?php if ($if == "FloatingRules" || isset($pconfig['floating'])): ?>
648
		<tr>
649
			<td width="22%" valign="top" class="vncellreq">
650
				<?=gettext("Quick");?>
651
			</td>
652
			<td width="78%" class="vtable">
653
				<input name="quick" type="checkbox" id="quick" value="yes" <?php if ($pconfig['quick']) echo "checked=\"checked\""; ?> />
654
				<strong><?=gettext("Apply the action immediately on match.");?></strong><br />
655
				<span class="vexpl"><?=gettext("Set this option if you need to apply this action to traffic that matches this rule immediately.");?></span>
656
			</td>
657
		</tr>
658
<?php endif; ?>
659
<?php $edit_disabled = ""; ?>
660
<?php if( isset($pconfig['associated-rule-id']) ): ?>
661
		<tr>
662
			<td width="22%" valign="top" class="vncell"><?=gettext("Associated filter rule");?></td>
663
			<td width="78%" class="vtable">
664
				<span class="red"><strong><?=gettext("Note: ");?></strong></span><?=gettext("This is associated to a NAT rule.");?><br />
665
				<?=gettext("You cannot edit the interface, protocol, source, or destination of associated filter rules.");?><br />
666
				<br />
667
				<?php
668
					$edit_disabled = "disabled";
669
					if (is_array($config['nat']['rule'])) {
670
						foreach( $config['nat']['rule'] as $index => $nat_rule ) {
671
							if( isset($nat_rule['associated-rule-id']) && $nat_rule['associated-rule-id']==$pconfig['associated-rule-id'] ) {
672
								echo "<a href=\"firewall_nat_edit.php?id={$index}\">" . gettext("View the NAT rule") . "</a><br>";
673
								break;
674
							}
675
						}
676
					}
677
					echo "<input name='associated-rule-id' id='associated-rule-id' type='hidden' value='{$pconfig['associated-rule-id']}' >";
678
					if (!empty($pconfig['interface']))
679
						echo "<input name='interface' id='interface' type='hidden' value='{$pconfig['interface']}' >";
680
				?>
681
				<script type="text/javascript">
682
				editenabled = 0;
683
				</script>
684
			</td>
685
		</tr>
686
<?php endif; ?>
687
		<tr>
688
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Interface");?></td>
689
			<td width="78%" class="vtable">
690
<?php if ($if == "FloatingRules" || isset($pconfig['floating'])): ?>
691
				<select name="interface[]" multiple="true" class="formselect" size="3" <?=$edit_disabled;?>>
692
<?php else: ?>
693
				<select name="interface" class="formselect" <?=$edit_disabled;?>>
694
<?php
695
   endif;
696
				/* add group interfaces */
697
				if (is_array($config['ifgroups']['ifgroupentry']))
698
					foreach($config['ifgroups']['ifgroupentry'] as $ifgen)
699
						if (have_ruleint_access($ifgen['ifname']))
700
							$interfaces[$ifgen['ifname']] = $ifgen['ifname'];
701
				$ifdescs = get_configured_interface_with_descr();
702
				// Allow extending of the firewall edit page and include custom input validation 
703
				pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/pre_interfaces_edit");
704
				foreach ($ifdescs as $ifent => $ifdesc)
705
        				if(have_ruleint_access($ifent))
706
							$interfaces[$ifent] = $ifdesc;
707
					if ($config['l2tp']['mode'] == "server")
708
						if(have_ruleint_access("l2tp"))
709
							$interfaces['l2tp'] = "L2TP VPN";
710
					if ($config['pptpd']['mode'] == "server")
711
						if(have_ruleint_access("pptp")) 
712
							$interfaces['pptp'] = "PPTP VPN";
713
					
714
					if (is_pppoe_server_enabled() && have_ruleint_access("pppoe"))
715
						$interfaces['pppoe'] = "PPPoE VPN";
716
					/* add ipsec interfaces */
717
					if (isset($config['ipsec']['enable']) || isset($config['ipsec']['client']['enable']))
718
						if(have_ruleint_access("enc0")) 
719
							$interfaces["enc0"] = "IPsec";
720
					/* add openvpn/tun interfaces */
721
					if  ($config['openvpn']["openvpn-server"] || $config['openvpn']["openvpn-client"])
722
						$interfaces["openvpn"] = "OpenVPN";
723
					$selected_interfaces = explode(",", $pconfig['interface']);
724
					foreach ($interfaces as $iface => $ifacename): ?>
725
						<option value="<?=$iface;?>" <?php if ($pconfig['interface'] <> "" && ( strcasecmp($pconfig['interface'], $iface) == 0 || in_array($iface, $selected_interfaces) )) echo "selected"; ?>><?=$ifacename?></option>
726
<?php 				endforeach; ?>
727
				</select>
728
				<br />
729
				<span class="vexpl"><?=gettext("Choose on which interface packets must come in to match this rule.");?></span>
730
			</td>
731
		</tr>
732
<?php if ($if == "FloatingRules" || isset($pconfig['floating'])): ?>
733
		<tr>
734
			<td width="22%" valign="top" class="vncellreq">
735
				<?=gettext("Direction");?>
736
			</td>
737
			<td width="78%" class="vtable">
738
				<select name="direction" class="formselect">
739
					<?php      $directions = array('any','in','out');
740
				foreach ($directions as $direction): ?>
741
				<option value="<?=$direction;?>"
742
					<?php if ($direction == $pconfig['direction']): ?>
743
						selected="selected" 
744
					<?php endif; ?>
745
					><?=$direction;?></option>
746
				<?php endforeach; ?>      
747
				</select>
748
				<input type="hidden" id="floating" name="floating" value="floating">
749
			</td>
750
		<tr>
751
<?php endif; ?>
752
		<tr>
753
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Protocol");?></td>
754
			<td width="78%" class="vtable">
755
				<select <?=$edit_disabled;?> name="proto" class="formselect" onchange="proto_change()">
756
<?php
757
				$protocols = explode(" ", "TCP UDP TCP/UDP ICMP ESP AH GRE IGMP OSPF any carp pfsync");
758
				foreach ($protocols as $proto): ?>
759
					<option value="<?=strtolower($proto);?>" <?php if (strtolower($proto) == $pconfig['proto']) echo "selected"; ?>><?=htmlspecialchars($proto);?></option>
760
<?php 			endforeach; ?>
761
				</select>
762
				<br />
763
				<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>
764
			</td>
765
		</tr>
766
		<tr id="icmpbox" name="icmpbox">
767
			<td valign="top" class="vncell"><?=gettext("ICMP type");?></td>
768
			<td class="vtable">
769
				<select <?=$edit_disabled;?> name="icmptype" class="formselect">
770
<?php
771
				$icmptypes = array(
772
				"" => gettext("any"),
773
				"echoreq" => gettext("Echo request"),
774
				"echorep" => gettext("Echo reply"),
775
				"unreach" => gettext("Destination unreachable"),
776
				"squench" => gettext("Source quench"),
777
				"redir" => gettext("Redirect"),
778
				"althost" => gettext("Alternate Host"),
779
				"routeradv" => gettext("Router advertisement"),
780
				"routersol" => gettext("Router solicitation"),
781
				"timex" => gettext("Time exceeded"),
782
				"paramprob" => gettext("Invalid IP header"),
783
				"timereq" => gettext("Timestamp"),
784
				"timerep" => gettext("Timestamp reply"),
785
				"inforeq" => gettext("Information request"),
786
				"inforep" => gettext("Information reply"),
787
				"maskreq" => gettext("Address mask request"),
788
				"maskrep" => gettext("Address mask reply")
789
				);
790

    
791
				foreach ($icmptypes as $icmptype => $descr): ?>
792
					<option value="<?=$icmptype;?>" <?php if ($icmptype == $pconfig['icmptype']) echo "selected"; ?>><?=htmlspecialchars($descr);?></option>
793
<?php 			endforeach; ?>
794
			</select>
795
			<br />
796
			<span class="vexpl"><?=gettext("If you selected ICMP for the protocol above, you may specify an ICMP type here.");?></span>
797
		</td>
798
		</tr>
799
		<tr>
800
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Source");?></td>
801
			<td width="78%" class="vtable">
802
				<input <?=$edit_disabled;?> name="srcnot" type="checkbox" id="srcnot" value="yes" <?php if ($pconfig['srcnot']) echo "checked"; ?>>
803
				<strong><?=gettext("not");?></strong>
804
				<br />
805
				<?=gettext("Use this option to invert the sense of the match.");?>
806
				<br />
807
				<br />
808
				<table border="0" cellspacing="0" cellpadding="0">
809
					<tr>
810
						<td><?=gettext("Type:");?>&nbsp;&nbsp;</td>
811
						<td>
812
							<select <?=$edit_disabled;?> name="srctype" class="formselect" onChange="typesel_change()">
813
<?php
814
								$sel = is_specialnet($pconfig['src']); ?>
815
								<option value="any"     <?php if ($pconfig['src'] == "any") { echo "selected"; } ?>><?=gettext("any");?></option>
816
								<option value="single"  <?php if (($pconfig['srcmask'] == 32) && !$sel) { echo "selected"; $sel = 1; } ?>><?=gettext("Single host or alias");?></option>
817
								<option value="network" <?php if (!$sel) echo "selected"; ?>><?=gettext("Network");?></option>
818
								<?php if(have_ruleint_access("pptp")): ?>
819
								<option value="pptp"    <?php if ($pconfig['src'] == "pptp") { echo "selected"; } ?>><?=gettext("PPTP clients");?></option>
820
								<?php endif; ?>
821
								<?php if(have_ruleint_access("pppoe")): ?>
822
								<option value="pppoe"   <?php if ($pconfig['src'] == "pppoe") { echo "selected"; } ?>><?=gettext("PPPoE clients");?></option>
823
								<?php endif; ?>								
824
								 <?php if(have_ruleint_access("l2tp")): ?>
825
                                                                <option value="l2tp"   <?php if ($pconfig['src'] == "l2tp") { echo "selected"; } ?>><?=gettext("L2TP clients");?></option>
826
                                                                <?php endif; ?>
827
<?php
828
								foreach ($ifdisp as $ifent => $ifdesc): ?>
829
								<?php if(have_ruleint_access($ifent)): ?>
830
									<option value="<?=$ifent;?>" <?php if ($pconfig['src'] == $ifent) { echo "selected"; } ?>><?=htmlspecialchars($ifdesc);?><?=gettext(" subnet");?></option>
831
									<option value="<?=$ifent;?>ip"<?php if ($pconfig['src'] ==  $ifent . "ip") { echo "selected"; } ?>>
832
										<?=$ifdesc?> <?=gettext("address");?>
833
									</option>
834
								<?php endif; ?>
835
<?php 							endforeach; ?>
836
							</select>
837
						</td>
838
					</tr>
839
					<tr>
840
						<td><?=gettext("Address:");?>&nbsp;&nbsp;</td>
841
						<td>
842
							<input <?=$edit_disabled;?> autocomplete='off' name="src" type="text" class="formfldalias" id="src" size="20" value="<?php if (!is_specialnet($pconfig['src'])) echo htmlspecialchars($pconfig['src']);?>"> /
843
							<select <?=$edit_disabled;?> name="srcmask" class="formselect" id="srcmask">
844
<?php						for ($i = 31; $i > 0; $i--): ?>
845
								<option value="<?=$i;?>" <?php if ($i == $pconfig['srcmask']) echo "selected"; ?>><?=$i;?></option>
846
<?php 						endfor; ?>
847
							</select>
848
						</td>
849
					</tr>
850
				</table>
851
				<div id="showadvancedboxspr">
852
					<p>
853
					<input <?=$edit_disabled;?> type="button" onClick="show_source_port_range()" value="<?=gettext("Advanced"); ?>"></input> - <?=gettext("Show source port range");?></a>
854
				</div>
855
			</td>
856
		</tr>
857
		<tr style="display:none" id="sprtable" name="sprtable">
858
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Source port range");?></td>
859
			<td width="78%" class="vtable">
860
				<table border="0" cellspacing="0" cellpadding="0">
861
					<tr>
862
						<td><?=gettext("from:");?>&nbsp;&nbsp;</td>
863
						<td>
864
							<select <?=$edit_disabled;?> name="srcbeginport" class="formselect" onchange="src_rep_change();ext_change()">
865
								<option value="">(<?=gettext("other"); ?>)</option>
866
								<option value="any" <?php $bfound = 0; if ($pconfig['srcbeginport'] == "any") { echo "selected"; $bfound = 1; } ?>><?=gettext("any");?></option>
867
<?php 							foreach ($wkports as $wkport => $wkportdesc): ?>
868
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcbeginport']) { echo "selected"; $bfound = 1; } ?>><?=htmlspecialchars($wkportdesc);?></option>
869
<?php 							endforeach; ?>
870
							</select>
871
							<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']); ?>">
872
						</td>
873
					</tr>
874
					<tr>
875
						<td><?=gettext("to:");?></td>
876
						<td>
877
							<select <?=$edit_disabled;?> name="srcendport" class="formselect" onchange="ext_change()">
878
								<option value="">(<?=gettext("other"); ?>)</option>
879
								<option value="any" <?php $bfound = 0; if ($pconfig['srcendport'] == "any") { echo "selected"; $bfound = 1; } ?>><?=gettext("any");?></option>
880
<?php							foreach ($wkports as $wkport => $wkportdesc): ?>
881
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcendport']) { echo "selected"; $bfound = 1; } ?>><?=htmlspecialchars($wkportdesc);?></option>
882
<?php							endforeach; ?>
883
							</select>
884
							<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']); ?>">
885
						</td>
886
					</tr>
887
				</table>
888
				<br />
889
				<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/>
890
			</td>
891
		</tr>
892
		<tr>
893
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Destination");?></td>
894
			<td width="78%" class="vtable">
895
				<input <?=$edit_disabled;?> name="dstnot" type="checkbox" id="dstnot" value="yes" <?php if ($pconfig['dstnot']) echo "checked"; ?>>
896
				<strong><?=gettext("not");?></strong>
897
					<br />
898
				<?=gettext("Use this option to invert the sense of the match.");?>
899
					<br />
900
					<br />
901
				<table border="0" cellspacing="0" cellpadding="0">
902
					<tr>
903
						<td><?=gettext("Type:");?>&nbsp;&nbsp;</td>
904
						<td>
905
							<select <?=$edit_disabled;?> name="dsttype" class="formselect" onChange="typesel_change()">
906
<?php
907
								$sel = is_specialnet($pconfig['dst']); ?>
908
								<option value="any" <?php if ($pconfig['dst'] == "any") { echo "selected"; } ?>><?=gettext("any");?></option>
909
								<option value="single" <?php if (($pconfig['dstmask'] == 32) && !$sel) { echo "selected"; $sel = 1; } ?>><?=gettext("Single host or alias");?></option>
910
								<option value="network" <?php if (!$sel) echo "selected"; ?>><?=gettext("Network");?></option>
911
								<?php if(have_ruleint_access("pptp")): ?>
912
								<option value="pptp" <?php if ($pconfig['dst'] == "pptp") { echo "selected"; } ?>><?=gettext("PPTP clients");?></option>
913
								<?php endif; ?>
914
								<?php if(have_ruleint_access("pppoe")): ?>
915
								<option value="pppoe" <?php if ($pconfig['dst'] == "pppoe") { echo "selected"; } ?>><?=gettext("PPPoE clients");?></option>
916
								<?php endif; ?>								
917
								<?php if(have_ruleint_access("l2tp")): ?>
918
                                                                <option value="l2tp" <?php if ($pconfig['dst'] == "l2tp") { echo "selected"; } ?>><?=gettext("L2TP clients");?></option>
919
                                                                <?php endif; ?>
920

    
921
<?php 							foreach ($ifdisp as $if => $ifdesc): ?>
922
								<?php if(have_ruleint_access($if)): ?>
923
									<option value="<?=$if;?>" <?php if ($pconfig['dst'] == $if) { echo "selected"; } ?>><?=htmlspecialchars($ifdesc);?> <?=gettext("subnet");?></option>
924
									<option value="<?=$if;?>ip"<?php if ($pconfig['dst'] == $if . "ip") { echo "selected"; } ?>>
925
										<?=$ifdesc;?> <?=gettext("address");?>
926
									</option>
927
								<?php endif; ?>
928
<?php 							endforeach; ?>
929
							</select>
930
						</td>
931
					</tr>
932
					<tr>
933
						<td><?=gettext("Address:");?>&nbsp;&nbsp;</td>
934
						<td>
935
							<input <?=$edit_disabled;?> autocomplete='off' name="dst" type="text" class="formfldalias" id="dst" size="20" value="<?php if (!is_specialnet($pconfig['dst'])) echo htmlspecialchars($pconfig['dst']);?>">
936
							/
937
							<select <?=$edit_disabled;?> name="dstmask" class="formselect" id="dstmask">
938
<?php
939
							for ($i = 31; $i > 0; $i--): ?>
940
								<option value="<?=$i;?>" <?php if ($i == $pconfig['dstmask']) echo "selected"; ?>><?=$i;?></option>
941
<?php						endfor; ?>
942
							</select>
943
						</td>
944
					</tr>
945
				</table>
946
			</td>
947
		</tr>
948
		<tr id="dprtr" name="dprtr">
949
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Destination port range ");?></td>
950
			<td width="78%" class="vtable">
951
				<table border="0" cellspacing="0" cellpadding="0">
952
					<tr>
953
						<td><?=gettext("from:");?>&nbsp;&nbsp;</td>
954
						<td>
955
							<select <?=$edit_disabled;?> name="dstbeginport" class="formselect" onchange="dst_rep_change();ext_change()">
956
								<option value="">(<?=gettext("other"); ?>)</option>
957
								<option value="any" <?php $bfound = 0; if ($pconfig['dstbeginport'] == "any") { echo "selected"; $bfound = 1; } ?>><?=gettext("any");?></option>
958
<?php 							foreach ($wkports as $wkport => $wkportdesc): ?>
959
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['dstbeginport']) { echo "selected"; $bfound = 1; }?>><?=htmlspecialchars($wkportdesc);?></option>
960
<?php 							endforeach; ?>
961
							</select>
962
							<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']); ?>">
963
						</td>
964
					</tr>
965
					<tr>
966
						<td><?=gettext("to:");?></td>
967
						<td>
968
							<select <?=$edit_disabled;?> name="dstendport" class="formselect" onchange="ext_change()">
969
								<option value="">(<?=gettext("other"); ?>)</option>
970
								<option value="any" <?php $bfound = 0; if ($pconfig['dstendport'] == "any") { echo "selected"; $bfound = 1; } ?>><?=gettext("any");?></option>
971
<?php							foreach ($wkports as $wkport => $wkportdesc): ?>
972
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['dstendport']) { echo "selected"; $bfound = 1; } ?>><?=htmlspecialchars($wkportdesc);?></option>
973
<?php 							endforeach; ?>
974
							</select>
975
								<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']); ?>">
976
						</td>
977
					</tr>
978
				</table>
979
				<br />
980
				<span class="vexpl">
981
					<?=gettext("Specify the port or port range for the destination of the packet for this rule.");?>
982
					<br />
983
					<?=gettext("Hint: you can leave the"); ?> <em><?=gettext("'to'"); ?></em> <?=gettext("field empty if you only want to filter a single port");?>
984
				</span>
985
			</td>
986
		</tr>
987
		<tr>
988
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Log");?></td>
989
			<td width="78%" class="vtable">
990
				<input name="log" type="checkbox" id="log" value="yes" <?php if ($pconfig['log']) echo "checked"; ?>>
991
				<strong><?=gettext("Log packets that are handled by this rule");?></strong>
992
				<br />
993
				<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>
994
			</td>
995
		</tr>
996
		<tr>
997
			<td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
998
			<td width="78%" class="vtable">
999
				<input name="descr" type="text" class="formfld unknown" id="descr" size="52" maxlength="52" value="<?=htmlspecialchars($pconfig['descr']);?>">
1000
				<br />
1001
				<span class="vexpl"><?=gettext("You may enter a description here for your reference.");?></span>
1002
			</td>
1003
		</tr>
1004
<?php		if (!isset($id) || !($a_filter[$id] && firewall_check_for_advanced_options($a_filter[$id]) <> "")): ?>
1005
		<tr>
1006
			<td width="22%" valign="top">&nbsp;</td>
1007
			<td width="78%">
1008
				&nbsp;<br>&nbsp;
1009
				<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>">  <input type="button" class="formbtn" value="<?=gettext("Cancel"); ?>" onclick="history.back()">
1010
<?php			if (isset($id) && $a_filter[$id]): ?>
1011
					<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>">
1012
<?php 			endif; ?>
1013
				<input name="after" type="hidden" value="<?=htmlspecialchars($after);?>">
1014
			</td>
1015
		</tr>
1016
<?php		endif; ?>
1017
		<tr>
1018
			<td>&nbsp;</td>
1019
		</tr>
1020
		<tr>
1021
			<td colspan="2" valign="top" class="listtopic"><?=gettext("Advanced features");?></td>
1022
		</tr>	
1023
		<tr>
1024
			<td width="22%" valign="top" class="vncell"><?=gettext("Source OS");?></td>
1025
			<td width="78%" class="vtable">
1026
				<div id="showadvsourceosbox" <?php if ($pconfig['os']) echo "style='display:none'"; ?>>
1027
					<input type="button" onClick="show_advanced_sourceos()" value="<?=gettext("Advanced"); ?>"></input> - <?=gettext("Show advanced option");?></a>
1028
				</div>
1029
				<div id="showsourceosadv" <?php if (empty($pconfig['os'])) echo "style='display:none'"; ?>>
1030
					<?=gettext("OS Type:");?>&nbsp;
1031
					<select name="os" id="os" class="formselect">
1032
<?php
1033
						$ostypes = array(
1034
							 "" => gettext("any"),
1035
							"AIX" => "AIX",
1036
							"Linux" => "Linux",
1037
							"FreeBSD" => "FreeBSD",
1038
							"NetBSD" => "NetBSD",
1039
							"OpenBSD" => "OpenBSD",
1040
							"Solaris" => "Solaris",
1041
							"MacOS" => "MacOS",
1042
							"Windows" => "Windows",
1043
							"Novell" => "Novell",
1044
							"NMAP" => "NMAP"
1045
			           );
1046
						foreach ($ostypes as $ostype => $descr): ?>
1047
							<option value="<?=$ostype;?>" <?php if ($ostype == $pconfig['os']) echo "selected"; ?>><?=htmlspecialchars($descr);?></option>
1048
<?php
1049
					endforeach; 
1050
?>
1051
					</select>
1052
					<br />
1053
					<?=gettext("Note: this only works for TCP rules");?>
1054
				</div>
1055
			</td>
1056
		</tr>
1057
		<tr>
1058
			<td width="22%" valign="top" class="vncell"><?=gettext("Diffserv Code Point");?></td>
1059
			<td width="78%" class="vtable">
1060
				<div id="dsadv" name="dsadv" <?php if ($pconfig['dscp']) echo "style='display:none'"; ?>>
1061
					<input type="button" onClick="show_dsdiv();" value="<?=gettext("Advanced"); ?>"> - <?=gettext("Show advanced option");?>
1062
				</div>
1063
				<div id="dsdivmain" name="dsdivmain" <?php if (empty($pconfig['dscp'])) echo "style='display:none'"; ?>>
1064
					<select name="dscp" id="dscp">
1065
						<option value=""></option>
1066
						<?php foreach($firewall_rules_dscp_types as $frdt): ?>
1067
							<option value="<?=$frdt?>"<?php if($pconfig['dscp'] == $frdt) echo " SELECTED"; ?>><?=$frdt?></option>
1068
						<?php endforeach; ?>
1069
					</select>
1070
				</div>
1071
			</td>
1072
		</tr>
1073
		<tr>
1074
			<td width="22%" valign="top" class="vncell"><?=gettext("Advanced Options");?></td>
1075
			<td width="78%" class="vtable">
1076
			<div id="aoadv" name="aoadv">
1077
				<input type="button" onClick="show_aodiv();" value="<?=gettext("Advanced"); ?>"> - <?=gettext("Show advanced option");?>
1078
			</div>
1079
			<div id="aodivmain" name="aodivmain" style="display:none">
1080
				<input type="checkbox" id="allowopts" value="yes" name="allowopts"<?php if($pconfig['allowopts'] == true) echo " checked"; ?>>
1081
				<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.");?>
1082
				</span><p>
1083
				<input type="checkbox" id="disablereplyto" value="yes" name="disablereplyto"<?php if($pconfig['disablereplyto'] == true) echo " checked"; ?>>
1084
				<br/><span class="vexpl"><?=gettext("This will disable auto generated reply-to for this rule.");?>
1085
				</span><p>
1086
				<input name="tag" id="tag" value="<?=htmlspecialchars($pconfig['tag']);?>">
1087
				<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>
1088
				</span><p>
1089
				<input name="tagged" id="tagged" value="<?=htmlspecialchars($pconfig['tagged']);?>">
1090
				<br /><span class="vexpl"><?=gettext("You can match packet on a mark placed before on another rule.")?>
1091
				</span> <p>
1092
				<input name="max" id="max" value="<?php echo htmlspecialchars($pconfig['max']) ?>"><br><?=gettext(" Maximum state entries this rule can create");?></p><p>
1093
				<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>
1094
				<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>
1095
				<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>
1096
				<input name="max-src-conn-rate" id="max-src-conn-rate" value="<?php echo htmlspecialchars($pconfig['max-src-conn-rate']) ?>"> /
1097
				<select name="max-src-conn-rates" id="max-src-conn-rates">
1098
					<option value=""<?php if(intval($pconfig['max-src-conn-rates']) < 1) echo " selected"; ?>></option>
1099
<?php				for($x=1; $x<255; $x++) {
1100
						if($x == $pconfig['max-src-conn-rates']) $selected = " selected"; else $selected = "";
1101
						echo "<option value=\"{$x}\"{$selected}>{$x}</option>\n";
1102
					} ?>
1103
				</select><br />
1104
				<?=gettext("Maximum new connections / per second(s)");?>
1105
				</p><p>
1106

    
1107
				<input name="statetimeout" value="<?php echo htmlspecialchars($pconfig['statetimeout']) ?>"><br>
1108
				<?=gettext("State Timeout in seconds");?>
1109
				</p>
1110

    
1111
				<p><strong><?=gettext("Note: Leave fields blank to disable that feature.");?></strong></p>
1112
			  </div>
1113
			</td>
1114
		</tr>
1115
		<tr id="tcpflags" name="tcpflags"> 
1116
			<td width="22%" valign="top" class="vncell"><?=gettext("TCP flags");?></td>
1117
			<td width="78%" class="vtable">
1118
			<div id="showtcpflagsbox" <?php if ($pconfig['tcpflags_any'] || $pconfig['tcpflags1'] || $pconfig['tcpflags2']) echo "style='display:none'"; ?>>
1119
                        	<input type="button" onClick="show_advanced_tcpflags()" value="<?=gettext("Advanced"); ?>"></input> - <?=gettext("Show advanced option");?></a>
1120
                        </div>
1121
                        <div id="showtcpflagsadv" <?php if (empty($pconfig['tcpflags_any']) && empty($pconfig['tcpflags1']) && empty($pconfig['tcpflags2'])) echo "style='display:none'"; ?>>
1122
			<div id="tcpheader" name="tcpheader">
1123
			<center>
1124
			<table border="0" cellspacing="0" cellpadding="0">
1125
			<?php 
1126
				$setflags = explode(",", $pconfig['tcpflags1']);
1127
				$outofflags = explode(",", $pconfig['tcpflags2']);
1128
				$header = "<td width='40' nowrap></td>";
1129
				$tcpflags1 = "<td width='40' nowrap>set</td>";
1130
				$tcpflags2 = "<td width='40' nowrap>out of</td>";
1131
				foreach ($tcpflags as $tcpflag) {
1132
					$header .= "<td  width='40' nowrap><strong>" . strtoupper($tcpflag) . "</strong></td>\n";
1133
					$tcpflags1 .= "<td  width='40' nowrap> <input type='checkbox' name='tcpflags1_{$tcpflag}' value='on' ";
1134
					if (array_search($tcpflag, $setflags) !== false)
1135
						$tcpflags1 .= "checked";
1136
					$tcpflags1 .= "></td>\n";
1137
					$tcpflags2 .= "<td  width='40' nowrap> <input type='checkbox' name='tcpflags2_{$tcpflag}' value='on' ";
1138
					if (array_search($tcpflag, $outofflags) !== false)
1139
						$tcpflags2 .= "checked";
1140
					$tcpflags2 .= "></td>\n";
1141
				}
1142
				echo "<tr id='tcpheader' name='tcpheader'>{$header}</tr>\n";
1143
				echo "<tr id='tcpflags1' name='tcpflags1'>{$tcpflags1}</tr>\n";
1144
				echo "<tr id='tcpflags2' name='tcpflags2'>{$tcpflags2}</tr>\n";
1145
			?>
1146
			</table>
1147
			<center>
1148
			</div>
1149
			<br/><center>
1150
			<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>
1151
			<br/>
1152
			<span class="vexpl"><?=gettext("Use this to choose TCP flags that must ". 
1153
			"be set or cleared for this rule to match.");?></span>
1154
			</div>
1155
			</td>
1156
		</tr>
1157
		<tr>
1158
			<td width="22%" valign="top" class="vncell"><?=gettext("State Type");?></td>
1159
			<td width="78%" class="vtable">
1160
				<div id="showadvstatebox" <?php if (!empty($pconfig['statetype']) && $pconfig['statetype'] != "keep state") echo "style='display:none'"; ?>>
1161
					<input type="button" onClick="show_advanced_state()" value="<?=gettext("Advanced"); ?>"></input> - <?=gettext("Show advanced option");?></a>
1162
				</div>
1163
				<div id="showstateadv" <?php if (empty($pconfig['statetype']) || $pconfig['statetype'] == "keep state") echo "style='display:none'"; ?>>
1164
					<select name="statetype">
1165
						<option value="keep state" <?php if(!isset($pconfig['statetype']) or $pconfig['statetype'] == "keep state") echo "selected"; ?>><?=gettext("keep state");?></option>
1166
						<option value="sloppy state" <?php if($pconfig['statetype'] == "sloppy state") echo "selected"; ?>><?=gettext("sloppy state");?></option>
1167
						<option value="synproxy state"<?php if($pconfig['statetype'] == "synproxy state")  echo "selected"; ?>><?=gettext("synproxy state");?></option>
1168
						<option value="none"<?php if($pconfig['statetype'] == "none") echo "selected"; ?>><?=gettext("none");?></option>
1169
					</select><br><?=gettext("Hint: Select which type of state tracking mechanism you would like to use.  If in doubt, use keep state.");?>
1170
					<p>
1171
					<table width="90%">
1172
						<tr><td width="25%"><ul><li><?=gettext("keep state");?></li></ul></td><td><?=gettext("Works with all IP protocols.");?></td></tr>
1173
						<tr><td width="25%"><ul><li><?=gettext("sloppy state");?></li></ul></td><td><?=gettext("Works with all IP protocols.");?></td></tr>
1174
						<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>
1175
						<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>
1176
					</table>
1177
					</p>
1178
			  </div>
1179
			</td>
1180
		</tr>
1181
		<tr>
1182
			<td width="22%" valign="top" class="vncell"><?=gettext("No XMLRPC Sync");?></td>
1183
			<td width="78%" class="vtable">
1184
				<div id="showadvnoxmlrpcsyncbox" <?php if ($pconfig['nosync']) echo "style='display:none'"; ?>>
1185
					<input type="button" onClick="show_advanced_noxmlrpc()" value="<?=gettext("Advanced"); ?>"></input> - <?=gettext("Show advanced option");?></a>
1186
				</div>
1187
				<div id="shownoxmlrpcadv" <?php if (empty($pconfig['nosync'])) echo "style='display:none'"; ?>>
1188
					<input type="checkbox" name="nosync"<?php if($pconfig['nosync']) echo " CHECKED"; ?>><br>
1189
					<?=gettext("Hint: This prevents the rule from automatically syncing to other CARP members.");?>
1190
				</div>
1191
			</td>
1192
		</tr>
1193
		<?php
1194
			//build list of schedules
1195
			$schedules = array();
1196
			$schedules[] = "none";//leave none to leave rule enabled all the time
1197
			if(is_array($config['schedules']['schedule'])) {
1198
				foreach ($config['schedules']['schedule'] as $schedule) {
1199
					if ($schedule['name'] <> "")
1200
						$schedules[] = $schedule['name'];
1201
				}
1202
			}
1203
		?>
1204
		<tr>
1205
			<td width="22%" valign="top" class="vncell"><?=gettext("Schedule");?></td>
1206
			<td width="78%" class="vtable">
1207
				<div id="showadvschedulebox" <?php if (!empty($pconfig['sched'])) echo "style='display:none'"; ?>>
1208
					<input type="button" onClick="show_advanced_schedule()" value="<?=gettext("Advanced"); ?>"></input> - <?=gettext("Show advanced option");?></a>
1209
				</div>
1210
				<div id="showscheduleadv" <?php if (empty($pconfig['sched'])) echo "style='display:none'"; ?>>
1211
					<select name='sched'>
1212
<?php
1213
					foreach($schedules as $schedule) {
1214
						if($schedule == $pconfig['sched']) {
1215
							$selected = " SELECTED";
1216
						} else {
1217
							$selected = "";
1218
						}
1219
						if ($schedule == "none") {
1220
							echo "<option value=\"\" {$selected}>{$schedule}</option>\n";
1221
						} else {
1222
							echo "<option value=\"{$schedule}\" {$selected}>{$schedule}</option>\n";
1223
						}
1224
					}
1225
?>
1226
					</select>
1227
					<p><?=gettext("Leave as 'none' to leave the rule enabled all the time.");?></p>
1228
				</div>
1229
			</td>
1230
		</tr>
1231
		<tr>
1232
			<td width="22%" valign="top" class="vncell"><?=gettext("Gateway");?></td>
1233
			<td width="78%" class="vtable">
1234
				<div id="showadvgatewaybox" <?php if (!empty($pconfig['gateway'])) echo "style='display:none'"; ?>>
1235
					<input type="button" onClick="show_advanced_gateway()" value="<?=gettext("Advanced"); ?>"></input> - <?=gettext("Show advanced option");?></a>
1236
				</div>
1237
				<div id="showgatewayadv" <?php if (empty($pconfig['gateway'])) echo "style='display:none'"; ?>>
1238
					<select name='gateway'>
1239
					<option value="" ><?=gettext("default");?></option>
1240
<?php
1241
					/* build a list of gateways */
1242
					$gateways = return_gateways_array();
1243
					// add statically configured gateways to list
1244
					foreach($gateways as $gwname => $gw) {
1245
						if($gw == "") 
1246
							continue;
1247
						if($gwname == $pconfig['gateway']) {
1248
							$selected = " SELECTED";
1249
						} else {
1250
							$selected = "";
1251
						}
1252
						echo "<option value=\"{$gwname}\" {$selected}>{$gw['name']} - {$gw['gateway']}</option>\n";
1253
					}
1254
					/* add gateway groups to the list */
1255
					if (is_array($config['gateways']['gateway_group'])) {
1256
						foreach($config['gateways']['gateway_group'] as $gw_group) {
1257
							if($gw_group['name'] == "")
1258
								continue;
1259
							if($pconfig['gateway'] == $gw_group['name']) {
1260
								echo "<option value=\"{$gw_group['name']}\" SELECTED>{$gw_group['name']}</option>\n";
1261
							} else {
1262
								echo "<option value=\"{$gw_group['name']}\">{$gw_group['name']}</option>\n";
1263
							}
1264
						}
1265
					}
1266
?>
1267
					</select>
1268
					<p><?=gettext("Leave as 'default' to use the system routing table.  Or choose a gateway to utilize policy based routing.");?></p>
1269
				</div>
1270
			</td>
1271
		</tr>
1272
		<tr>
1273
			<td width="22%" valign="top" class="vncell"><?=gettext("In/Out");?></td>
1274
			<td width="78%" class="vtable">
1275
				<div id="showadvinoutbox" <?php if (!empty($pconfig['dnpipe'])) echo "style='display:none'"; ?>>
1276
					<input type="button" onClick="show_advanced_inout()" value="<?=gettext("Advanced"); ?>"></input> - <?=gettext("Show advanced option");?></a>
1277
				</div>
1278
				<div id="showinoutadv" <?php if (empty($pconfig['dnpipe'])) echo "style='display:none'"; ?>>
1279
					<select name="dnpipe">
1280
<?php
1281
		if (!is_array($dnqlist))
1282
			$dnqlist = array();
1283
		echo "<option value=\"none\"";
1284
		if (!$dnqselected) echo " SELECTED";
1285
		echo " >none</option>";
1286
		foreach ($dnqlist as $dnq => $dnqkey) {
1287
			if($dnq == "")
1288
				continue;
1289
			echo "<option value=\"$dnqkey\"";
1290
			if ($dnqkey == $pconfig['dnpipe']) {
1291
				$dnqselected = 1;
1292
				echo " SELECTED";
1293
			}
1294
			echo ">{$dnq}</option>"; 
1295
		}
1296
?>
1297
			</select> / 			
1298
			<select name="pdnpipe">
1299
<?php
1300
		$dnqselected = 0;
1301
		echo "<option value=\"none\"";
1302
		if (!$dnqselected) echo " SELECTED";
1303
		echo " >none</option>";
1304
		foreach ($dnqlist as $dnq => $dnqkey) {
1305
			if($dnq == "")
1306
				continue;
1307
			echo "<option value=\"$dnqkey\"";
1308
			if ($dnqkey == $pconfig['pdnpipe']) {
1309
				$dnqselected = 1;
1310
				echo " SELECTED";
1311
			}
1312
			echo ">{$dnq}</option>"; 
1313
		}
1314
?>
1315
				</select>
1316
				<br />
1317
				<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>
1318
				</div>
1319
			</td>
1320
		</tr>
1321

    
1322
		<tr>
1323
			<td width="22%" valign="top" class="vncell"><?=gettext("Ackqueue/Queue");?></td>
1324
			<td width="78%" class="vtable">
1325
			<div id="showadvackqueuebox" <?php if (!empty($pconfig['defaultqueue'])) echo "style='display:none'"; ?>>
1326
				<input type="button" onClick="show_advanced_ackqueue()" value="<?=gettext("Advanced"); ?>"></input> - <?=gettext("Show advanced option");?></a>
1327
			</div>
1328
			<div id="showackqueueadv" <?php if (empty($pconfig['defaultqueue'])) echo "style='display:none'"; ?>>
1329
				<select name="ackqueue">
1330
<?php
1331
			if (!is_array($qlist))
1332
				$qlist = array();
1333
			echo "<option value=\"none\"";
1334
			if (!$qselected) echo " SELECTED";
1335
			echo " >none</option>";
1336
			foreach ($qlist as $q => $qkey) {
1337
				if($q == "")
1338
					continue;
1339
				echo "<option value=\"$q\"";
1340
				if ($q == $pconfig['ackqueue']) {
1341
					$qselected = 1;
1342
					echo " SELECTED";
1343
				}
1344
				if (isset($ifdisp[$q]))
1345
					echo ">{$ifdisp[$q]}</option>";
1346
				else
1347
					echo ">{$q}</option>"; 
1348
			}
1349
?>
1350
				</select> / 			
1351
				<select name="defaultqueue">
1352
<?php
1353
			$qselected = 0;
1354
			echo "<option value=\"none\"";
1355
			if (!$qselected) echo " SELECTED";
1356
			echo " >none</option>";
1357
			foreach ($qlist as $q => $qkey) {
1358
				if($q == "")
1359
					continue;
1360
				echo "<option value=\"$q\"";
1361
				if ($q == $pconfig['defaultqueue']) {
1362
					$qselected = 1;
1363
					echo " SELECTED";
1364
				}
1365
				if (isset($ifdisp[$q]))
1366
					echo ">{$ifdisp[$q]}</option>";
1367
				else
1368
					echo ">{$q}</option>"; 
1369
			}
1370
?>
1371
				</select>
1372
					<br />
1373
					<span class="vexpl"><?=gettext("Choose the Acknowledge Queue only if you have selected Queue.");?></span>
1374
				</td>
1375
			</tr>
1376
			<tr>
1377
				<td width="22%" valign="top" class="vncell"><?=gettext("Layer7");?></td>
1378
				<td width="78%" class="vtable">
1379
					<div id="showadvlayer7box" <?php if (!empty($pconfig['l7container'])) echo "style='display:none'"; ?>>
1380
						<input type="button" onClick="show_advanced_layer7()" value="<?=gettext("Advanced"); ?>"></input> - <?=gettext("Show advanced option");?></a>
1381
					</div>
1382
					<div id="showlayer7adv" <?php if (empty($pconfig['l7container'])) echo "style='display:none'"; ?>>
1383
				<select name="l7container">
1384
<?php
1385
					if (!is_array($l7clist))
1386
						$l7clist = array();
1387
					echo "<option value=\"none\"";
1388
					echo " >none</option>";
1389
					foreach ($l7clist as $l7ckey) {
1390
						echo "<option value=\"{$l7ckey}\"";
1391
						if ($l7ckey == $pconfig['l7container']) {
1392
							echo " SELECTED";
1393
						}
1394
						echo ">{$l7ckey}</option>"; 
1395
					}
1396
?>
1397
				</select>			
1398
				<br/>
1399
				<span class="vexpl">
1400
					<?=gettext("Choose a Layer7 container to apply application protocol inspection rules. " .
1401
					"These are valid for TCP and UDP protocols only.");?>
1402
				</span>
1403
			  </div>
1404
			</td>
1405
		</tr>
1406
<?php
1407
		// Allow extending of the firewall edit page and include custom input validation 
1408
		pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/htmlphplate");
1409
?>
1410
		<tr>
1411
			<td width="22%" valign="top">&nbsp;</td>
1412
			<td width="78%">
1413
				&nbsp;<br>&nbsp;
1414
				<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>">  <input type="button" class="formbtn" value="<?=gettext("Cancel"); ?>" onclick="history.back()">
1415
<?php			if (isset($id) && $a_filter[$id]): ?>
1416
					<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>">
1417
<?php 			endif; ?>
1418
				<input name="after" type="hidden" value="<?=htmlspecialchars($after);?>">
1419
			</td>
1420
		</tr>
1421
	</table>
1422
</form>
1423
<script language="JavaScript">
1424
<!--
1425
	ext_change();
1426
	typesel_change();
1427
	proto_change();
1428
	<?php if ( (!empty($pconfig['srcbeginport']) && $pconfig['srcbeginport'] != "any") || (!empty($pconfig['srcendport']) && $pconfig['srcendport'] != "any") ): ?>
1429
	show_source_port_range();
1430
	<?php endif; ?>
1431

    
1432
<?php
1433
	$isfirst = 0;
1434
	$aliases = "";
1435
	$addrisfirst = 0;
1436
	$aliasesaddr = "";
1437
	if($config['aliases']['alias'] <> "" and is_array($config['aliases']['alias']))
1438
		foreach($config['aliases']['alias'] as $alias_name) {
1439
			switch ($alias_name['type']) {
1440
			case "port":
1441
				if($isfirst == 1) $portaliases .= ",";
1442
				$portaliases .= "'" . $alias_name['name'] . "'";
1443
				$isfirst = 1;
1444
				break;
1445
			case "host":
1446
			case "network":
1447
			case "openvpn":
1448
			case "urltable":
1449
				if($addrisfirst == 1) $aliasesaddr .= ",";
1450
				$aliasesaddr .= "'" . $alias_name['name'] . "'";
1451
				$addrisfirst = 1;
1452
				break;
1453
			default:
1454
				break;
1455
			}
1456
		}
1457
?>
1458

    
1459
	var addressarray=new Array(<?php echo $aliasesaddr; ?>);
1460
	var customarray=new Array(<?php echo $portaliases; ?>);
1461

    
1462
	var oTextbox1 = new AutoSuggestControl(document.getElementById("src"), new StateSuggestions(addressarray));
1463
        var oTextbox2 = new AutoSuggestControl(document.getElementById("srcbeginport_cust"), new StateSuggestions(customarray));
1464
        var oTextbox3 = new AutoSuggestControl(document.getElementById("srcendport_cust"), new StateSuggestions(customarray));
1465
        var oTextbox4 = new AutoSuggestControl(document.getElementById("dst"), new StateSuggestions(addressarray));
1466
        var oTextbox5 = new AutoSuggestControl(document.getElementById("dstbeginport_cust"), new StateSuggestions(customarray));
1467
        var oTextbox6 = new AutoSuggestControl(document.getElementById("dstendport_cust"), new StateSuggestions(customarray));
1468
//-->
1469
</script>
1470
<?php include("fend.inc"); ?>
1471
</body>
1472
</html>
(63-63/228)