Project

General

Profile

Download (64.9 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 pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/pre_input_errors"); ?>
612
<?php if ($input_errors) print_input_errors($input_errors); ?>
613

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

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

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

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

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

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

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

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

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

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