Project

General

Profile

Download (64.8 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]['ipprotocol']))
99
                $pconfig['ipprotocol'] = $a_filter[$id]['ipprotocol'];
100

    
101
	if (isset($a_filter[$id]['protocol']))
102
		$pconfig['proto'] = $a_filter[$id]['protocol'];
103
	else
104
		$pconfig['proto'] = "any";
105

    
106
	if ($a_filter[$id]['protocol'] == "icmp")
107
		$pconfig['icmptype'] = $a_filter[$id]['icmptype'];
108

    
109
	address_to_pconfig($a_filter[$id]['source'], $pconfig['src'],
110
		$pconfig['srcmask'], $pconfig['srcnot'],
111
		$pconfig['srcbeginport'], $pconfig['srcendport']);
112

    
113
	if($a_filter[$id]['os'] <> "")
114
		$pconfig['os'] = $a_filter[$id]['os'];
115

    
116
	address_to_pconfig($a_filter[$id]['destination'], $pconfig['dst'],
117
		$pconfig['dstmask'], $pconfig['dstnot'],
118
		$pconfig['dstbeginport'], $pconfig['dstendport']);
119

    
120
	if ($a_filter[$id]['dscp'] <> "")
121
		$pconfig['dscp'] = $a_filter[$id]['dscp'];
122

    
123
	$pconfig['disabled'] = isset($a_filter[$id]['disabled']);
124
	$pconfig['log'] = isset($a_filter[$id]['log']);
125
	$pconfig['descr'] = $a_filter[$id]['descr'];
126

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

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

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

    
155
	/* advanced - nosync */
156
	$pconfig['nosync'] = isset($a_filter[$id]['nosync']);
157

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

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

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

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

    
188
if (isset($_GET['dup']))
189
	unset($id);
190

    
191
if ($_POST) {
192

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

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

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

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

    
212
		if ($_POST['srcbeginport_cust'] && !$_POST['srcbeginport'])
213
			$_POST['srcbeginport'] = $_POST['srcbeginport_cust'];
214
		if ($_POST['srcendport_cust'] && !$_POST['srcendport'])
215
			$_POST['srcendport'] = $_POST['srcendport_cust'];
216

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

    
227
		if ($_POST['dstbeginport_cust'] && !$_POST['dstbeginport'])
228
			$_POST['dstbeginport'] = $_POST['dstbeginport_cust'];
229
		if ($_POST['dstendport_cust'] && !$_POST['dstendport'])
230
			$_POST['dstendport'] = $_POST['dstendport_cust'];
231

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

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

    
256
	unset($input_errors);
257
	$pconfig = $_POST;
258

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

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

    
289
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
290

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

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

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

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

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

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

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

    
414
	// Allow extending of the firewall edit page and include custom input validation 
415
	pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/input_validation");
416

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

    
424
		if (isset($_POST['ipprotocol'] ))
425
			$filterent['ipprotocol'] = $_POST['ipprotocol'];
426

    
427
		if ($_POST['tcpflags_any']) {
428
			$filterent['tcpflags_any'] = true;
429
		} else {
430
			$settcpflags = array();
431
			$outoftcpflags = array();
432
			foreach ($tcpflags as $tcpflag) {
433
				if ($_POST['tcpflags1_' . $tcpflag] == "on")
434
					$settcpflags[] = $tcpflag;
435
				if ($_POST['tcpflags2_' . $tcpflag] == "on")
436
					$outoftcpflags[] = $tcpflag;
437
			}
438
			if (!empty($outoftcpflags)) {
439
				$filterent['tcpflags2'] = join(",", $outoftcpflags);
440
				if (!empty($settcpflags))
441
					$filterent['tcpflags1'] = join(",", $settcpflags);
442
			}
443
		}
444

    
445
		if (isset($_POST['tag']))
446
			$filterent['tag'] = $_POST['tag'];
447
		if (isset($_POST['tagged']))
448
			$filterent['tagged'] = $_POST['tagged'];
449
		if ($if == "FloatingRules" || isset($_POST['floating'])) {
450
			$filterent['direction'] = $_POST['direction'];
451
			if (isset($_POST['quick']) && $_POST['quick'] <> "")
452
				$filterent['quick'] = $_POST['quick'];
453
			$filterent['floating'] = "yes";
454
			if (isset($_POST['interface']) && count($_POST['interface']) > 0)  {
455
				$filterent['interface'] = implode(",", $_POST['interface']);
456
			}
457
		}
458

    
459
		/* Advanced options */
460
		if ($_POST['allowopts'] == "yes")
461
			$filterent['allowopts'] = true;
462
		else
463
			unset($filterent['allowopts']);
464
		if ($_POST['disablereplyto'] == "yes")
465
			$filterent['disablereplyto'] = true;
466
		else
467
			unset($filterent['disablereplyto']);
468
		$filterent['max'] = $_POST['max'];
469
		$filterent['max-src-nodes'] = $_POST['max-src-nodes'];
470
		$filterent['max-src-conn'] = $_POST['max-src-conn'];
471
		$filterent['max-src-states'] = $_POST['max-src-states'];
472
		$filterent['statetimeout'] = $_POST['statetimeout'];
473
		$filterent['statetype'] = $_POST['statetype'];
474
		$filterent['os'] = $_POST['os'];
475

    
476
		/* Nosync directive - do not xmlrpc sync this item */
477
		if($_POST['nosync'] <> "")
478
			$filterent['nosync'] = true;
479
		else
480
			unset($filterent['nosync']);
481

    
482
		/* unless both values are provided, unset the values - ticket #650 */
483
		if($_POST['max-src-conn-rate'] <> "" and $_POST['max-src-conn-rates'] <> "") {
484
			$filterent['max-src-conn-rate'] = $_POST['max-src-conn-rate'];
485
			$filterent['max-src-conn-rates'] = $_POST['max-src-conn-rates'];
486
		} else {
487
			unset($filterent['max-src-conn-rate']);
488
			unset($filterent['max-src-conn-rates']);
489
		}
490

    
491
		if ($_POST['proto'] != "any")
492
			$filterent['protocol'] = $_POST['proto'];
493
		else
494
			unset($filterent['protocol']);
495

    
496
		if ($_POST['proto'] == "icmp" && $_POST['icmptype'])
497
			$filterent['icmptype'] = $_POST['icmptype'];
498
		else
499
			unset($filterent['icmptype']);
500

    
501
		pconfig_to_address($filterent['source'], $_POST['src'],
502
			$_POST['srcmask'], $_POST['srcnot'],
503
			$_POST['srcbeginport'], $_POST['srcendport']);
504

    
505
		pconfig_to_address($filterent['destination'], $_POST['dst'],
506
			$_POST['dstmask'], $_POST['dstnot'],
507
			$_POST['dstbeginport'], $_POST['dstendport']);
508

    
509
		if ($_POST['disabled'])
510
			$filterent['disabled'] = true;
511
		else
512
			unset($filterent['disabled']);
513

    
514
		if ($_POST['dscp'])
515
			$filterent['dscp'] = $_POST['dscp'];
516

    
517
		if ($_POST['log'])
518
			$filterent['log'] = true;
519
		else
520
			unset($filterent['log']);
521
		strncpy($filterent['descr'], $_POST['descr'], 52);
522

    
523
		if ($_POST['gateway'] != "") {
524
			$filterent['gateway'] = $_POST['gateway'];
525
		}
526
		
527
		if (isset($_POST['defaultqueue']) && $_POST['defaultqueue'] != "none") {
528
			$filterent['defaultqueue'] = $_POST['defaultqueue'];
529
			if (isset($_POST['ackqueue']) && $_POST['ackqueue'] != "none")
530
				$filterent['ackqueue'] = $_POST['ackqueue'];
531
		}
532

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

    
539
		if (isset($_POST['l7container']) && $_POST['l7container'] != "none") {
540
			$filterent['l7container'] = $_POST['l7container'];
541
		}
542
		
543
		if ($_POST['sched'] != "") {
544
			$filterent['sched'] = $_POST['sched'];
545
		}
546

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

    
559
			$filterent['source'] = $a_filter[$id]['source'];
560
			$filterent['destination'] = $a_filter[$id]['destination'];
561
			$filterent['associated-rule-id'] = $a_filter[$id]['associated-rule-id'];
562
		}
563

    
564
		// Allow extending of the firewall edit page and include custom input validation 
565
		pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/pre_write_config");
566

    
567
		if (isset($id) && $a_filter[$id])
568
			$a_filter[$id] = $filterent;
569
		else {
570
			if (is_numeric($after))
571
				array_splice($a_filter, $after+1, 0, array($filterent));
572
			else
573
				$a_filter[] = $filterent;
574
		}
575

    
576
		filter_rules_sort();
577

    
578
		write_config();
579
		mark_subsystem_dirty('filter');
580

    
581
		if (isset($_POST['floating']))
582
			header("Location: firewall_rules.php?if=FloatingRules");
583
		else
584
			header("Location: firewall_rules.php?if=" . $_POST['interface']);
585
		exit;
586
	}
587
}
588

    
589
read_altq_config(); /* XXX: */
590
$qlist =& get_unique_queue_list();
591
read_dummynet_config(); /* XXX: */
592
$dnqlist =& get_unique_dnqueue_list();
593
read_layer7_config();
594
$l7clist =& get_l7_unique_list();
595

    
596
$pgtitle = array(gettext("Firewall"),gettext("Rules"),gettext("Edit"));
597
$statusurl = "status_filter_reload.php";
598
$logurl = "diag_logs_filter.php";
599

    
600
$closehead = false;
601

    
602
$page_filename = "firewall_rules_edit.php";
603
include("head.inc");
604

    
605
?>
606

    
607
</head>
608

    
609
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
610
<?php include("fbegin.inc"); ?>
611
<?php if ($input_errors) print_input_errors($input_errors); ?>
612

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

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

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

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

    
1129
				<input name="statetimeout" value="<?php echo htmlspecialchars($pconfig['statetimeout']) ?>"><br>
1130
				<?=gettext("State Timeout in seconds");?>
1131
				</p>
1132

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

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

    
1454
<?php
1455
	$isfirst = 0;
1456
	$aliases = "";
1457
	$addrisfirst = 0;
1458
	$aliasesaddr = "";
1459
	if($config['aliases']['alias'] <> "" and is_array($config['aliases']['alias']))
1460
		foreach($config['aliases']['alias'] as $alias_name) {
1461
			switch ($alias_name['type']) {
1462
			case "port":
1463
				if($isfirst == 1) $portaliases .= ",";
1464
				$portaliases .= "'" . $alias_name['name'] . "'";
1465
				$isfirst = 1;
1466
				break;
1467
			case "host":
1468
			case "network":
1469
			case "openvpn":
1470
			case "urltable":
1471
				if($addrisfirst == 1) $aliasesaddr .= ",";
1472
				$aliasesaddr .= "'" . $alias_name['name'] . "'";
1473
				$addrisfirst = 1;
1474
				break;
1475
			default:
1476
				break;
1477
			}
1478
		}
1479
?>
1480

    
1481
	var addressarray=new Array(<?php echo $aliasesaddr; ?>);
1482
	var customarray=new Array(<?php echo $portaliases; ?>);
1483

    
1484
	var oTextbox1 = new AutoSuggestControl(document.getElementById("src"), new StateSuggestions(addressarray));
1485
        var oTextbox2 = new AutoSuggestControl(document.getElementById("srcbeginport_cust"), new StateSuggestions(customarray));
1486
        var oTextbox3 = new AutoSuggestControl(document.getElementById("srcendport_cust"), new StateSuggestions(customarray));
1487
        var oTextbox4 = new AutoSuggestControl(document.getElementById("dst"), new StateSuggestions(addressarray));
1488
        var oTextbox5 = new AutoSuggestControl(document.getElementById("dstbeginport_cust"), new StateSuggestions(customarray));
1489
        var oTextbox6 = new AutoSuggestControl(document.getElementById("dstendport_cust"), new StateSuggestions(customarray));
1490
//-->
1491
</script>
1492
<?php include("fend.inc"); ?>
1493
</body>
1494
</html>
(64-64/232)