Project

General

Profile

Download (65.7 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
	if((is_ipaddr($_POST['src']) && is_ipaddr($_POST['dst'])) {
356
		if(!validate_address_family($_POST['src'], $_POST['dst']))
357
			$input_errors[] = sprintf(gettext("The Source IP address %s Address Family differs from the destination %s."), $_POST['src'], $_POST['dst']);
358
	}
359

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

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

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

    
418
	// Allow extending of the firewall edit page and include custom input validation 
419
	pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/input_validation");
420

    
421
	if (!$input_errors) {
422
		$filterent = array();
423
		$filterent['id'] = $_POST['ruleid']>0?$_POST['ruleid']:'';
424
		$filterent['type'] = $_POST['type'];
425
		if (isset($_POST['interface'] ))
426
			$filterent['interface'] = $_POST['interface'];
427

    
428
		if (isset($_POST['ipprotocol'] ))
429
			$filterent['ipprotocol'] = $_POST['ipprotocol'];
430

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

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

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

    
480
		/* Nosync directive - do not xmlrpc sync this item */
481
		if($_POST['nosync'] <> "")
482
			$filterent['nosync'] = true;
483
		else
484
			unset($filterent['nosync']);
485

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

    
495
		if ($_POST['proto'] != "any")
496
			$filterent['protocol'] = $_POST['proto'];
497
		else
498
			unset($filterent['protocol']);
499

    
500
		if ($_POST['proto'] == "icmp" && $_POST['icmptype'])
501
			$filterent['icmptype'] = $_POST['icmptype'];
502
		else
503
			unset($filterent['icmptype']);
504

    
505
		pconfig_to_address($filterent['source'], $_POST['src'],
506
			$_POST['srcmask'], $_POST['srcnot'],
507
			$_POST['srcbeginport'], $_POST['srcendport']);
508

    
509
		pconfig_to_address($filterent['destination'], $_POST['dst'],
510
			$_POST['dstmask'], $_POST['dstnot'],
511
			$_POST['dstbeginport'], $_POST['dstendport']);
512

    
513
		if ($_POST['disabled'])
514
			$filterent['disabled'] = true;
515
		else
516
			unset($filterent['disabled']);
517

    
518
		if ($_POST['dscp'])
519
			$filterent['dscp'] = $_POST['dscp'];
520

    
521
		if ($_POST['log'])
522
			$filterent['log'] = true;
523
		else
524
			unset($filterent['log']);
525
		strncpy($filterent['descr'], $_POST['descr'], 52);
526

    
527
		if ($_POST['gateway'] != "") {
528
			$filterent['gateway'] = $_POST['gateway'];
529
		}
530
		
531
		if (isset($_POST['defaultqueue']) && $_POST['defaultqueue'] != "none") {
532
			$filterent['defaultqueue'] = $_POST['defaultqueue'];
533
			if (isset($_POST['ackqueue']) && $_POST['ackqueue'] != "none")
534
				$filterent['ackqueue'] = $_POST['ackqueue'];
535
		}
536

    
537
		if (isset($_POST['dnpipe']) && $_POST['dnpipe'] != "none") {
538
			$filterent['dnpipe'] = $_POST['dnpipe'];
539
			if (isset($_POST['pdnpipe']) && $_POST['pdnpipe'] != "none")
540
				$filterent['pdnpipe'] = $_POST['pdnpipe'];
541
		}
542

    
543
		if (isset($_POST['l7container']) && $_POST['l7container'] != "none") {
544
			$filterent['l7container'] = $_POST['l7container'];
545
		}
546
		
547
		if ($_POST['sched'] != "") {
548
			$filterent['sched'] = $_POST['sched'];
549
		}
550

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

    
563
			$filterent['source'] = $a_filter[$id]['source'];
564
			$filterent['destination'] = $a_filter[$id]['destination'];
565
			$filterent['associated-rule-id'] = $a_filter[$id]['associated-rule-id'];
566
		}
567

    
568
		// Allow extending of the firewall edit page and include custom input validation 
569
		pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/pre_write_config");
570

    
571
		if (isset($id) && $a_filter[$id])
572
			$a_filter[$id] = $filterent;
573
		else {
574
			if (is_numeric($after))
575
				array_splice($a_filter, $after+1, 0, array($filterent));
576
			else
577
				$a_filter[] = $filterent;
578
		}
579

    
580
		filter_rules_sort();
581

    
582
		write_config();
583
		mark_subsystem_dirty('filter');
584

    
585
		if (isset($_POST['floating']))
586
			header("Location: firewall_rules.php?if=FloatingRules");
587
		else
588
			header("Location: firewall_rules.php?if=" . $_POST['interface']);
589
		exit;
590
	}
591
}
592

    
593
read_altq_config(); /* XXX: */
594
$qlist =& get_unique_queue_list();
595
read_dummynet_config(); /* XXX: */
596
$dnqlist =& get_unique_dnqueue_list();
597
read_layer7_config();
598
$l7clist =& get_l7_unique_list();
599

    
600
$pgtitle = array(gettext("Firewall"),gettext("Rules"),gettext("Edit"));
601
$statusurl = "status_filter_reload.php";
602
$logurl = "diag_logs_filter.php";
603

    
604
$closehead = false;
605

    
606
$page_filename = "firewall_rules_edit.php";
607
include("head.inc");
608

    
609
?>
610
<link rel="stylesheet" href="/javascript/chosen/chosen.css" />
611
</head>
612

    
613
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
614
<script src="/javascript/chosen/chosen.proto.js" type="text/javascript"></script>
615
<?php include("fbegin.inc"); ?>
616
<?php pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/pre_input_errors"); ?>
617
<?php if ($input_errors) print_input_errors($input_errors); ?>
618

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

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

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

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

    
1135
				<input name="statetimeout" value="<?php echo htmlspecialchars($pconfig['statetimeout']) ?>"><br>
1136
				<?=gettext("State Timeout in seconds");?>
1137
				</p>
1138

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

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

    
1469
<?php
1470
	$isfirst = 0;
1471
	$aliases = "";
1472
	$addrisfirst = 0;
1473
	$aliasesaddr = "";
1474
	if($config['aliases']['alias'] <> "" and is_array($config['aliases']['alias']))
1475
		foreach($config['aliases']['alias'] as $alias_name) {
1476
			switch ($alias_name['type']) {
1477
			case "port":
1478
				if($isfirst == 1) $portaliases .= ",";
1479
				$portaliases .= "'" . $alias_name['name'] . "'";
1480
				$isfirst = 1;
1481
				break;
1482
			case "host":
1483
			case "network":
1484
			case "openvpn":
1485
			case "urltable":
1486
				if($addrisfirst == 1) $aliasesaddr .= ",";
1487
				$aliasesaddr .= "'" . $alias_name['name'] . "'";
1488
				$addrisfirst = 1;
1489
				break;
1490
			default:
1491
				break;
1492
			}
1493
		}
1494
?>
1495

    
1496
	var addressarray=new Array(<?php echo $aliasesaddr; ?>);
1497
	var customarray=new Array(<?php echo $portaliases; ?>);
1498

    
1499
	var oTextbox1 = new AutoSuggestControl(document.getElementById("src"), new StateSuggestions(addressarray));
1500
        var oTextbox2 = new AutoSuggestControl(document.getElementById("srcbeginport_cust"), new StateSuggestions(customarray));
1501
        var oTextbox3 = new AutoSuggestControl(document.getElementById("srcendport_cust"), new StateSuggestions(customarray));
1502
        var oTextbox4 = new AutoSuggestControl(document.getElementById("dst"), new StateSuggestions(addressarray));
1503
        var oTextbox5 = new AutoSuggestControl(document.getElementById("dstbeginport_cust"), new StateSuggestions(customarray));
1504
        var oTextbox6 = new AutoSuggestControl(document.getElementById("dstendport_cust"), new StateSuggestions(customarray));
1505
//-->
1506
</script>
1507
<?php include("fend.inc"); ?>
1508
</body>
1509
</html>
(64-64/232)