Project

General

Profile

Download (68.5 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
	$pconfig['vlanprio'] = $a_filter[$id]['vlanprio'];
175
	$pconfig['vlanprioset'] = $a_filter[$id]['vlanprioset'];
176
	if (!isset($_GET['dup']))
177
		$pconfig['associated-rule-id'] = $a_filter[$id]['associated-rule-id'];
178

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

    
190
if (isset($_GET['dup']))
191
	unset($id);
192

    
193
if ($_POST) {
194
	unset($input_errors);
195

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

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

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

    
208
	if (($_POST['ipprotocol'] <> "") && ($_POST['gateway'] <> "")) {
209
		foreach($config['gateways']['gateway_group'] as $gw_group) {
210
			if($gw_group['name'] == $_POST['gateway']) {
211
				$af = explode("|", $gw_group['item'][0]);
212
				$ip = lookup_gateway_ip_by_name($af[0]);
213
				if(($_POST['ipprotocol'] == "inet6") && (!is_ipaddrv6($ip))) {
214
					$input_errors[] = gettext("You can not assign a IPv4 gateway group on IPv6 Address Family rule");
215
				}
216
				if(($_POST['ipprotocol'] == "inet") && (!is_ipaddrv4($ip))) {
217
					$input_errors[] = gettext("You can not assign a IPv6 gateway group on IPv4 Address Family rule");
218
				}
219
			}
220
		}
221
	}
222
	if (($_POST['ipprotocol'] <> "") && ($_POST['gateway'] <> "") && (is_ipaddr(lookup_gateway_ip_by_name($_POST['gateway'])))) {
223
		if(($_POST['ipprotocol'] == "inet6") && (!is_ipaddrv6(lookup_gateway_ip_by_name($_POST['gateway'])))) {
224
			$input_errors[] = gettext("You can not assign the IPv4 Gateway to a IPv6 Filter rule");
225
		}
226
		if(($_POST['ipprotocol'] == "inet") && (!is_ipaddrv4(lookup_gateway_ip_by_name($_POST['gateway'])))) {
227
			$input_errors[] = gettext("You can not assign the IPv6 Gateway to a IPv4 Filter rule");
228
		}
229
	}
230

    
231

    
232
	if (($_POST['proto'] != "tcp") && ($_POST['proto'] != "udp") && ($_POST['proto'] != "tcp/udp")) {
233
		$_POST['srcbeginport'] = 0;
234
		$_POST['srcendport'] = 0;
235
		$_POST['dstbeginport'] = 0;
236
		$_POST['dstendport'] = 0;
237
	} else {
238

    
239
		if ($_POST['srcbeginport_cust'] && !$_POST['srcbeginport'])
240
			$_POST['srcbeginport'] = $_POST['srcbeginport_cust'];
241
		if ($_POST['srcendport_cust'] && !$_POST['srcendport'])
242
			$_POST['srcendport'] = $_POST['srcendport_cust'];
243

    
244
		if ($_POST['srcbeginport'] == "any") {
245
			$_POST['srcbeginport'] = 0;
246
			$_POST['srcendport'] = 0;
247
		} else {
248
			if (!$_POST['srcendport'])
249
				$_POST['srcendport'] = $_POST['srcbeginport'];
250
		}
251
		if ($_POST['srcendport'] == "any")
252
			$_POST['srcendport'] = $_POST['srcbeginport'];
253

    
254
		if ($_POST['dstbeginport_cust'] && !$_POST['dstbeginport'])
255
			$_POST['dstbeginport'] = $_POST['dstbeginport_cust'];
256
		if ($_POST['dstendport_cust'] && !$_POST['dstendport'])
257
			$_POST['dstendport'] = $_POST['dstendport_cust'];
258

    
259
		if ($_POST['dstbeginport'] == "any") {
260
			$_POST['dstbeginport'] = 0;
261
			$_POST['dstendport'] = 0;
262
		} else {
263
			if (!$_POST['dstendport'])
264
				$_POST['dstendport'] = $_POST['dstbeginport'];
265
		}
266
		if ($_POST['dstendport'] == "any")
267
			$_POST['dstendport'] = $_POST['dstbeginport'];
268
	}
269

    
270
	if (is_specialnet($_POST['srctype'])) {
271
		$_POST['src'] = $_POST['srctype'];
272
		$_POST['srcmask'] = 0;
273
	} else if ($_POST['srctype'] == "single") {
274
		$_POST['srcmask'] = 32;
275
	}
276
	if (is_specialnet($_POST['dsttype'])) {
277
		$_POST['dst'] = $_POST['dsttype'];
278
		$_POST['dstmask'] = 0;
279
	}  else if ($_POST['dsttype'] == "single") {
280
		$_POST['dstmask'] = 32;
281
	}
282

    
283
	$pconfig = $_POST;
284

    
285
	/* input validation */
286
	$reqdfields = explode(" ", "type proto");
287
	if ( isset($a_filter[$id]['associated-rule-id'])===false ) {
288
		$reqdfields[] = "src";
289
		$reqdfields[] = "dst";
290
	}
291
	$reqdfieldsn = explode(",", "Type,Protocol");
292
	if ( isset($a_filter[$id]['associated-rule-id'])===false ) {
293
		$reqdfieldsn[] = "Source";
294
		$reqdfieldsn[] = "Destination";
295
	}
296

    
297
	if($_POST['statetype'] == "modulate state" or $_POST['statetype'] == "synproxy state") {
298
		if( $_POST['proto'] != "tcp" )
299
			$input_errors[] = sprintf(gettext("%s is only valid with protocol tcp."),$_POST['statetype']);
300
		if(($_POST['statetype'] == "synproxy state") && ($_POST['gateway'] != ""))
301
			$input_errors[] = sprintf(gettext("%s is only valid if the gateway is set to 'default'."),$_POST['statetype']);
302
	}
303
        
304
	if ( isset($a_filter[$id]['associated-rule-id'])===false &&
305
	(!(is_specialnet($_POST['srctype']) || ($_POST['srctype'] == "single"))) ) {
306
		$reqdfields[] = "srcmask";
307
		$reqdfieldsn[] = "Source bit count";
308
	}
309
	if ( isset($a_filter[$id]['associated-rule-id'])===false &&
310
	(!(is_specialnet($_POST['dsttype']) || ($_POST['dsttype'] == "single"))) ) {
311
		$reqdfields[] = "dstmask";
312
		$reqdfieldsn[] = gettext("Destination bit count");
313
	}
314

    
315
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
316

    
317
	if (!$_POST['srcbeginport']) {
318
		$_POST['srcbeginport'] = 0;
319
		$_POST['srcendport'] = 0;
320
	}
321
	if (!$_POST['dstbeginport']) {
322
		$_POST['dstbeginport'] = 0;
323
		$_POST['dstendport'] = 0;
324
	}
325

    
326
	if ($_POST['srcbeginport'] && !is_portoralias($_POST['srcbeginport']))
327
                $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']);
328
        if ($_POST['srcendport'] && !is_portoralias($_POST['srcendport']))
329
                $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']);
330
        if ($_POST['dstbeginport'] && !is_portoralias($_POST['dstbeginport']))
331
                $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']);
332
        if ($_POST['dstendport'] && !is_portoralias($_POST['dstendport']))
333
                $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']);
334
	if ( !$_POST['srcbeginport_cust'] && $_POST['srcendport_cust'])
335
		if (is_alias($_POST['srcendport_cust']))
336
			$input_errors[] = 'If you put port alias in Source port range to: field you must put the same port alias in from: field';
337
	if ( $_POST['srcbeginport_cust'] && $_POST['srcendport_cust']){
338
		if (is_alias($_POST['srcendport_cust']) && is_alias($_POST['srcendport_cust']) && $_POST['srcbeginport_cust'] != $_POST['srcendport_cust'])
339
			$input_errors[] = 'The same port alias must be used in Source port range from: and to: fields';
340
		if ((is_alias($_POST['srcbeginport_cust']) && (!is_alias($_POST['srcendport_cust']) && $_POST['srcendport_cust']!='')) || 
341
		    ((!is_alias($_POST['srcbeginport_cust']) && $_POST['srcbeginport_cust']!='') && is_alias($_POST['srcendport_cust']))) 
342
			$input_errors[] = 'You cannot specify numbers and port aliases at the same time in Source port range from: and to: field';
343
	}
344
	if ( !$_POST['dstbeginport_cust'] && $_POST['dstendport_cust'])
345
		if (is_alias($_POST['dstendport_cust']))
346
			$input_errors[] = 'If you put port alias in Destination port range to: field you must put the same port alias in from: field';
347
	if ( $_POST['dstbeginport_cust'] && $_POST['dstendport_cust']){
348
		if (is_alias($_POST['dstendport_cust']) && is_alias($_POST['dstendport_cust']) && $_POST['dstbeginport_cust'] != $_POST['dstendport_cust'])
349
			$input_errors[] = 'The same port alias must be used in Destination port range from: and to: fields';
350
		if ((is_alias($_POST['dstbeginport_cust']) && (!is_alias($_POST['dstendport_cust']) && $_POST['dstendport_cust']!='')) || 
351
		    ((!is_alias($_POST['dstbeginport_cust']) && $_POST['dstbeginport_cust']!='') && is_alias($_POST['dstendport_cust']))) 
352
			$input_errors[] = 'You cannot specify numbers and port aliases at the same time in Destination port range from: and to: field';
353
	}
354

    
355
	/* if user enters an alias and selects "network" then disallow. */
356
	if($_POST['srctype'] == "network") {
357
		if(is_alias($_POST['src']))
358
			$input_errors[] = gettext("You must specify single host or alias for alias entries.");
359
	}
360
	if($_POST['dsttype'] == "network") {
361
		if(is_alias($_POST['dst']))
362
			$input_errors[] = gettext("You must specify single host or alias for alias entries.");
363
	}
364

    
365
	if (!is_specialnet($_POST['srctype'])) {
366
		if (($_POST['src'] && !is_ipaddroralias($_POST['src']))) {
367
			$input_errors[] = sprintf(gettext("%s is not a valid source IP address or alias."),$_POST['src']);
368
		}
369
		if (($_POST['srcmask'] && !is_numericint($_POST['srcmask']))) {
370
			$input_errors[] = gettext("A valid source bit count must be specified.");
371
		}
372
	}
373
	if (!is_specialnet($_POST['dsttype'])) {
374
		if (($_POST['dst'] && !is_ipaddroralias($_POST['dst']))) {
375
			$input_errors[] = sprintf(gettext("%s is not a valid destination IP address or alias."),$_POST['dst']);
376
		}
377
		if (($_POST['dstmask'] && !is_numericint($_POST['dstmask']))) {
378
			$input_errors[] = gettext("A valid destination bit count must be specified.");
379
		}
380
	}
381
	if((is_ipaddr($_POST['src']) && is_ipaddr($_POST['dst']))) {
382
		if(!validate_address_family($_POST['src'], $_POST['dst']))
383
			$input_errors[] = sprintf(gettext("The Source IP address %s Address Family differs from the destination %s."), $_POST['src'], $_POST['dst']);
384
		if((is_ipaddrv6($_POST['src']) || is_ipaddrv6($_POST['dst'])) && ($_POST['ipprotocol'] == "inet"))
385
			$input_errors[] = gettext("You can not use IPv6 addresses in IPv4 rules.");
386
		if((is_ipaddrv4($_POST['src']) || is_ipaddrv4($_POST['dst'])) && ($_POST['ipprotocol'] == "inet6"))
387
			$input_errors[] = gettext("You can not use IPv4 addresses in IPv6 rules.");
388
	}
389

    
390
	if ($_POST['srcbeginport'] > $_POST['srcendport']) {
391
		/* swap */
392
		$tmp = $_POST['srcendport'];
393
		$_POST['srcendport'] = $_POST['srcbeginport'];
394
		$_POST['srcbeginport'] = $tmp;
395
	}
396
	if ($_POST['dstbeginport'] > $_POST['dstendport']) {
397
		/* swap */
398
		$tmp = $_POST['dstendport'];
399
		$_POST['dstendport'] = $_POST['dstbeginport'];
400
		$_POST['dstbeginport'] = $tmp;
401
	}
402
	if ($_POST['os'])
403
		if( $_POST['proto'] != "tcp" )
404
			$input_errors[] = gettext("OS detection is only valid with protocol tcp.");
405

    
406
	if ($_POST['ackqueue'] && $_POST['ackqueue'] != "none") {
407
		if ($_POST['defaultqueue'] == "none" )
408
			$input_errors[] = gettext("You have to select a queue when you select an acknowledge queue too.");
409
		else if ($_POST['ackqueue'] == $_POST['defaultqueue'])
410
			$input_errors[] = gettext("Acknowledge queue and Queue cannot be the same.");		
411
	}
412
	if (isset($_POST['floating']) && $_POST['pdnpipe'] != "none" && (empty($_POST['direction']) || $_POST['direction'] == "any"))
413
		$input_errors[] = gettext("You can not use limiters in Floating rules without choosing a direction.");
414
	if (isset($_POST['floating']) && $_POST['gateway'] != "" && (empty($_POST['direction']) || $_POST['direction'] == "any"))
415
		$input_errors[] = gettext("You can not use gateways in Floating rules without choosing a direction.");
416
	if ($_POST['pdnpipe'] && $_POST['pdnpipe'] != "none") {
417
		if ($_POST['dnpipe'] == "none" )
418
			$input_errors[] = gettext("You must select a queue for the In direction before selecting one for Out too.");
419
		else if ($_POST['pdnpipe'] == $_POST['dnpipe'])
420
			$input_errors[] = gettext("In and Out Queue cannot be the same.");
421
		else if ($pdnpipe[0] == "?" && $dnpipe[0] <> "?")
422
			$input_errors[] = gettext("You cannot select one queue and one virtual interface for IN and Out. both must be from the same type.");
423
		else if ($dnpipe[0] == "?" && $pdnpipe[0] <> "?")			
424
			$input_errors[] = gettext("You cannot select one queue and one virtual interface for IN and Out. both must be from the same type.");
425
	}
426
	if( !empty($_POST['ruleid']) && !ctype_digit($_POST['ruleid']))
427
		$input_errors[] = gettext('ID must be an integer');
428
	if($_POST['l7container'] && $_POST['l7container'] != "none") {
429
		if(!($_POST['proto'] == "tcp" || $_POST['proto'] == "udp" || $_POST['proto'] == "tcp/udp"))
430
			$input_errors[] = gettext("You can only select a layer7 container for TCP and/or UDP protocols");
431
		if ($_POST['type'] <> "pass")
432
			$input_errors[] = gettext("You can only select a layer7 container for Pass type rules.");
433
	}
434

    
435
	if (!$_POST['tcpflags_any']) {
436
		$settcpflags = array();
437
		$outoftcpflags = array();
438
		foreach ($tcpflags as $tcpflag) {
439
			if ($_POST['tcpflags1_' . $tcpflag] == "on")
440
				$settcpflags[] = $tcpflag;
441
			if ($_POST['tcpflags2_' . $tcpflag] == "on")
442
				$outoftcpflags[] = $tcpflag;
443
		}
444
		if (empty($outoftcpflags) && !empty($settcpflags))
445
			$input_errors[] = gettext("If you specify TCP flags that should be set you should specify out of which flags as well.");
446
	}
447

    
448
	// Allow extending of the firewall edit page and include custom input validation 
449
	pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/input_validation");
450

    
451
	if (!$input_errors) {
452
		$filterent = array();
453
		$filterent['id'] = $_POST['ruleid']>0?$_POST['ruleid']:'';
454
		$filterent['type'] = $_POST['type'];
455
		if (isset($_POST['interface'] ))
456
			$filterent['interface'] = $_POST['interface'];
457

    
458
		if (isset($_POST['ipprotocol'] ))
459
			$filterent['ipprotocol'] = $_POST['ipprotocol'];
460

    
461
		if ($_POST['tcpflags_any']) {
462
			$filterent['tcpflags_any'] = true;
463
		} else {
464
			$settcpflags = array();
465
			$outoftcpflags = array();
466
			foreach ($tcpflags as $tcpflag) {
467
				if ($_POST['tcpflags1_' . $tcpflag] == "on")
468
					$settcpflags[] = $tcpflag;
469
				if ($_POST['tcpflags2_' . $tcpflag] == "on")
470
					$outoftcpflags[] = $tcpflag;
471
			}
472
			if (!empty($outoftcpflags)) {
473
				$filterent['tcpflags2'] = join(",", $outoftcpflags);
474
				if (!empty($settcpflags))
475
					$filterent['tcpflags1'] = join(",", $settcpflags);
476
			}
477
		}
478

    
479
		if (isset($_POST['tag']))
480
			$filterent['tag'] = $_POST['tag'];
481
		if (isset($_POST['tagged']))
482
			$filterent['tagged'] = $_POST['tagged'];
483
		if ($if == "FloatingRules" || isset($_POST['floating'])) {
484
			$filterent['direction'] = $_POST['direction'];
485
			if (isset($_POST['quick']) && $_POST['quick'] <> "")
486
				$filterent['quick'] = $_POST['quick'];
487
			$filterent['floating'] = "yes";
488
			if (isset($_POST['interface']) && count($_POST['interface']) > 0)  {
489
				$filterent['interface'] = implode(",", $_POST['interface']);
490
			}
491
		}
492

    
493
		/* Advanced options */
494
		if ($_POST['allowopts'] == "yes")
495
			$filterent['allowopts'] = true;
496
		else
497
			unset($filterent['allowopts']);
498
		if ($_POST['disablereplyto'] == "yes")
499
			$filterent['disablereplyto'] = true;
500
		else
501
			unset($filterent['disablereplyto']);
502
		$filterent['max'] = $_POST['max'];
503
		$filterent['max-src-nodes'] = $_POST['max-src-nodes'];
504
		$filterent['max-src-conn'] = $_POST['max-src-conn'];
505
		$filterent['max-src-states'] = $_POST['max-src-states'];
506
		$filterent['statetimeout'] = $_POST['statetimeout'];
507
		$filterent['statetype'] = $_POST['statetype'];
508
		$filterent['os'] = $_POST['os'];
509

    
510
		/* Nosync directive - do not xmlrpc sync this item */
511
		if($_POST['nosync'] <> "")
512
			$filterent['nosync'] = true;
513
		else
514
			unset($filterent['nosync']);
515

    
516
		/* unless both values are provided, unset the values - ticket #650 */
517
		if($_POST['max-src-conn-rate'] <> "" and $_POST['max-src-conn-rates'] <> "") {
518
			$filterent['max-src-conn-rate'] = $_POST['max-src-conn-rate'];
519
			$filterent['max-src-conn-rates'] = $_POST['max-src-conn-rates'];
520
		} else {
521
			unset($filterent['max-src-conn-rate']);
522
			unset($filterent['max-src-conn-rates']);
523
		}
524

    
525
		if ($_POST['proto'] != "any")
526
			$filterent['protocol'] = $_POST['proto'];
527
		else
528
			unset($filterent['protocol']);
529

    
530
		if ($_POST['proto'] == "icmp" && $_POST['icmptype'])
531
			$filterent['icmptype'] = $_POST['icmptype'];
532
		else
533
			unset($filterent['icmptype']);
534

    
535
		pconfig_to_address($filterent['source'], $_POST['src'],
536
			$_POST['srcmask'], $_POST['srcnot'],
537
			$_POST['srcbeginport'], $_POST['srcendport']);
538

    
539
		pconfig_to_address($filterent['destination'], $_POST['dst'],
540
			$_POST['dstmask'], $_POST['dstnot'],
541
			$_POST['dstbeginport'], $_POST['dstendport']);
542

    
543
		if ($_POST['disabled'])
544
			$filterent['disabled'] = true;
545
		else
546
			unset($filterent['disabled']);
547

    
548
		if ($_POST['dscp'])
549
			$filterent['dscp'] = $_POST['dscp'];
550

    
551
		if ($_POST['log'])
552
			$filterent['log'] = true;
553
		else
554
			unset($filterent['log']);
555
		strncpy($filterent['descr'], $_POST['descr'], 52);
556

    
557
		if ($_POST['gateway'] != "") {
558
			$filterent['gateway'] = $_POST['gateway'];
559
		}
560
		
561
		if (isset($_POST['defaultqueue']) && $_POST['defaultqueue'] != "none") {
562
			$filterent['defaultqueue'] = $_POST['defaultqueue'];
563
			if (isset($_POST['ackqueue']) && $_POST['ackqueue'] != "none")
564
				$filterent['ackqueue'] = $_POST['ackqueue'];
565
		}
566

    
567
		if (isset($_POST['dnpipe']) && $_POST['dnpipe'] != "none") {
568
			$filterent['dnpipe'] = $_POST['dnpipe'];
569
			if (isset($_POST['pdnpipe']) && $_POST['pdnpipe'] != "none")
570
				$filterent['pdnpipe'] = $_POST['pdnpipe'];
571
		}
572

    
573
		if (isset($_POST['l7container']) && $_POST['l7container'] != "none") {
574
			$filterent['l7container'] = $_POST['l7container'];
575
		}
576
		
577
		if ($_POST['sched'] != "") {
578
			$filterent['sched'] = $_POST['sched'];
579
		}
580

    
581
		if ($_POST['vlanprio'] != "") {
582
			$filterent['vlanprio'] = $_POST['vlanprio'];
583
		}
584
		if ($_POST['vlanprioset'] != "") {
585
			$filterent['vlanprioset'] = $_POST['vlanprioset'];
586
		}
587

    
588
		// If we have an associated nat rule, make sure the source and destination doesn't change
589
		if( isset($a_filter[$id]['associated-rule-id']) ) {
590
			$filterent['interface'] = $a_filter[$id]['interface'];
591
			if (isset($a_filter[$id]['protocol']))
592
				$filterent['protocol'] = $a_filter[$id]['protocol'];
593
			else if (isset($filterent['protocol']))
594
				unset($filterent['protocol']);
595
			if ($a_filter[$id]['protocol'] == "icmp" && $a_filter[$id]['icmptype'])
596
				$filterent['icmptype'] = $a_filter[$id]['icmptype'];
597
			else if (isset($filterent['icmptype']))
598
				unset($filterent['icmptype']);
599

    
600
			$filterent['source'] = $a_filter[$id]['source'];
601
			$filterent['destination'] = $a_filter[$id]['destination'];
602
			$filterent['associated-rule-id'] = $a_filter[$id]['associated-rule-id'];
603
		}
604

    
605
		// Allow extending of the firewall edit page and include custom input validation 
606
		pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/pre_write_config");
607

    
608
		if (isset($id) && $a_filter[$id])
609
			$a_filter[$id] = $filterent;
610
		else {
611
			if (is_numeric($after))
612
				array_splice($a_filter, $after+1, 0, array($filterent));
613
			else
614
				$a_filter[] = $filterent;
615
		}
616

    
617
		filter_rules_sort();
618

    
619
		write_config();
620
		mark_subsystem_dirty('filter');
621

    
622
		if (isset($_POST['floating']))
623
			header("Location: firewall_rules.php?if=FloatingRules");
624
		else
625
			header("Location: firewall_rules.php?if=" . $_POST['interface']);
626
		exit;
627
	}
628
}
629

    
630
read_altq_config(); /* XXX: */
631
$qlist =& get_unique_queue_list();
632
read_dummynet_config(); /* XXX: */
633
$dnqlist =& get_unique_dnqueue_list();
634
read_layer7_config();
635
$l7clist =& get_l7_unique_list();
636

    
637
$pgtitle = array(gettext("Firewall"),gettext("Rules"),gettext("Edit"));
638
$statusurl = "status_filter_reload.php";
639
$logurl = "diag_logs_filter.php";
640

    
641
$closehead = false;
642

    
643
$page_filename = "firewall_rules_edit.php";
644
include("head.inc");
645

    
646
?>
647
<link rel="stylesheet" href="/javascript/chosen/chosen.css" />
648
</head>
649

    
650
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
651
<script type="text/javascript" src="/javascript/jquery.ipv4v6ify.js"></script>
652
<script src="/javascript/chosen/chosen.jquery.js" type="text/javascript"></script>
653
<?php include("fbegin.inc"); ?>
654
<?php pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/pre_input_errors"); ?>
655
<?php if ($input_errors) print_input_errors($input_errors); ?>
656

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

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

    
858
				foreach ($icmptypes as $icmptype => $descr): ?>
859
					<option value="<?=$icmptype;?>" <?php if ($icmptype == $pconfig['icmptype']) echo "selected"; ?>><?=htmlspecialchars($descr);?></option>
860
<?php 			endforeach; ?>
861
			</select>
862
			<br />
863
			<span class="vexpl"><?=gettext("If you selected ICMP for the protocol above, you may specify an ICMP type here.");?></span>
864
		</td>
865
		</tr>
866
		<tr>
867
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Source");?></td>
868
			<td width="78%" class="vtable">
869
				<input <?=$edit_disabled;?> name="srcnot" type="checkbox" id="srcnot" value="yes" <?php if ($pconfig['srcnot']) echo "checked"; ?>>
870
				<strong><?=gettext("not");?></strong>
871
				<br />
872
				<?=gettext("Use this option to invert the sense of the match.");?>
873
				<br />
874
				<br />
875
				<table border="0" cellspacing="0" cellpadding="0">
876
					<tr>
877
						<td><?=gettext("Type:");?>&nbsp;&nbsp;</td>
878
						<td>
879
							<select <?=$edit_disabled;?> name="srctype" class="formselect" onChange="typesel_change()">
880
<?php
881
								$sel = is_specialnet($pconfig['src']); ?>
882
								<option value="any"     <?php if ($pconfig['src'] == "any") { echo "selected"; } ?>><?=gettext("any");?></option>
883
								<option value="single"  <?php if (($pconfig['srcmask'] == 32) && !$sel) { echo "selected"; $sel = 1; } ?>><?=gettext("Single host or alias");?></option>
884
								<option value="network" <?php if (!$sel) echo "selected"; ?>><?=gettext("Network");?></option>
885
								<?php if(have_ruleint_access("pptp")): ?>
886
								<option value="pptp"    <?php if ($pconfig['src'] == "pptp") { echo "selected"; } ?>><?=gettext("PPTP clients");?></option>
887
								<?php endif; ?>
888
								<?php if(have_ruleint_access("pppoe")): ?>
889
								<option value="pppoe"   <?php if ($pconfig['src'] == "pppoe") { echo "selected"; } ?>><?=gettext("PPPoE clients");?></option>
890
								<?php endif; ?>								
891
								 <?php if(have_ruleint_access("l2tp")): ?>
892
                                                                <option value="l2tp"   <?php if ($pconfig['src'] == "l2tp") { echo "selected"; } ?>><?=gettext("L2TP clients");?></option>
893
                                                                <?php endif; ?>
894
<?php
895
								foreach ($ifdisp as $ifent => $ifdesc): ?>
896
								<?php if(have_ruleint_access($ifent)): ?>
897
									<option value="<?=$ifent;?>" <?php if ($pconfig['src'] == $ifent) { echo "selected"; } ?>><?=htmlspecialchars($ifdesc);?><?=gettext(" subnet");?></option>
898
									<option value="<?=$ifent;?>ip"<?php if ($pconfig['src'] ==  $ifent . "ip") { echo "selected"; } ?>>
899
										<?=$ifdesc?> <?=gettext("address");?>
900
									</option>
901
								<?php endif; ?>
902
<?php 							endforeach; ?>
903
							</select>
904
						</td>
905
					</tr>
906
					<tr>
907
						<td><?=gettext("Address:");?>&nbsp;&nbsp;</td>
908
						<td>
909
							<input <?=$edit_disabled;?> autocomplete='off' name="src" type="text" class="formfldalias ipv4v6" id="src" size="20" value="<?php if (!is_specialnet($pconfig['src'])) echo htmlspecialchars($pconfig['src']);?>"> /
910
							<select <?=$edit_disabled;?> name="srcmask" class="formselect ipv4v6" id="srcmask">
911
<?php						for ($i = 127; $i > 0; $i--): ?>
912
								<option value="<?=$i;?>" <?php if ($i == $pconfig['srcmask']) echo "selected"; ?>><?=$i;?></option>
913
<?php 						endfor; ?>
914
							</select>
915
						</td>
916
					</tr>
917
				</table>
918
				<div id="showadvancedboxspr">
919
					<p>
920
					<input <?=$edit_disabled;?> type="button" onClick="show_source_port_range()" value="<?=gettext("Advanced"); ?>"></input> - <?=gettext("Show source port range");?></a>
921
				</div>
922
			</td>
923
		</tr>
924
		<tr style="display:none" id="sprtable" name="sprtable">
925
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Source port range");?></td>
926
			<td width="78%" class="vtable">
927
				<table border="0" cellspacing="0" cellpadding="0">
928
					<tr>
929
						<td><?=gettext("from:");?>&nbsp;&nbsp;</td>
930
						<td>
931
							<select <?=$edit_disabled;?> name="srcbeginport" class="formselect" onchange="src_rep_change();ext_change()">
932
								<option value="">(<?=gettext("other"); ?>)</option>
933
								<option value="any" <?php $bfound = 0; if ($pconfig['srcbeginport'] == "any") { echo "selected"; $bfound = 1; } ?>><?=gettext("any");?></option>
934
<?php 							foreach ($wkports as $wkport => $wkportdesc): ?>
935
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcbeginport']) { echo "selected"; $bfound = 1; } ?>><?=htmlspecialchars($wkportdesc);?></option>
936
<?php 							endforeach; ?>
937
							</select>
938
							<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']); ?>">
939
						</td>
940
					</tr>
941
					<tr>
942
						<td><?=gettext("to:");?></td>
943
						<td>
944
							<select <?=$edit_disabled;?> name="srcendport" class="formselect" onchange="ext_change()">
945
								<option value="">(<?=gettext("other"); ?>)</option>
946
								<option value="any" <?php $bfound = 0; if ($pconfig['srcendport'] == "any") { echo "selected"; $bfound = 1; } ?>><?=gettext("any");?></option>
947
<?php							foreach ($wkports as $wkport => $wkportdesc): ?>
948
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcendport']) { echo "selected"; $bfound = 1; } ?>><?=htmlspecialchars($wkportdesc);?></option>
949
<?php							endforeach; ?>
950
							</select>
951
							<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']); ?>">
952
						</td>
953
					</tr>
954
				</table>
955
				<br />
956
				<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/>
957
			</td>
958
		</tr>
959
		<tr>
960
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Destination");?></td>
961
			<td width="78%" class="vtable">
962
				<input <?=$edit_disabled;?> name="dstnot" type="checkbox" id="dstnot" value="yes" <?php if ($pconfig['dstnot']) echo "checked"; ?>>
963
				<strong><?=gettext("not");?></strong>
964
					<br />
965
				<?=gettext("Use this option to invert the sense of the match.");?>
966
					<br />
967
					<br />
968
				<table border="0" cellspacing="0" cellpadding="0">
969
					<tr>
970
						<td><?=gettext("Type:");?>&nbsp;&nbsp;</td>
971
						<td>
972
							<select <?=$edit_disabled;?> name="dsttype" class="formselect" onChange="typesel_change()">
973
<?php
974
								$sel = is_specialnet($pconfig['dst']); ?>
975
								<option value="any" <?php if ($pconfig['dst'] == "any") { echo "selected"; } ?>><?=gettext("any");?></option>
976
								<option value="single" <?php if (($pconfig['dstmask'] == 32) && !$sel) { echo "selected"; $sel = 1; } ?>><?=gettext("Single host or alias");?></option>
977
								<option value="network" <?php if (!$sel) echo "selected"; ?>><?=gettext("Network");?></option>
978
								<?php if(have_ruleint_access("pptp")): ?>
979
								<option value="pptp" <?php if ($pconfig['dst'] == "pptp") { echo "selected"; } ?>><?=gettext("PPTP clients");?></option>
980
								<?php endif; ?>
981
								<?php if(have_ruleint_access("pppoe")): ?>
982
								<option value="pppoe" <?php if ($pconfig['dst'] == "pppoe") { echo "selected"; } ?>><?=gettext("PPPoE clients");?></option>
983
								<?php endif; ?>								
984
								<?php if(have_ruleint_access("l2tp")): ?>
985
                                                                <option value="l2tp" <?php if ($pconfig['dst'] == "l2tp") { echo "selected"; } ?>><?=gettext("L2TP clients");?></option>
986
                                                                <?php endif; ?>
987

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

    
1175
				<input name="statetimeout" value="<?php echo htmlspecialchars($pconfig['statetimeout']) ?>"><br>
1176
				<?=gettext("State Timeout in seconds");?>
1177
				</p>
1178

    
1179
				<p><strong><?=gettext("Note: Leave fields blank to disable that feature.");?></strong></p>
1180
			  </div>
1181
			</td>
1182
		</tr>
1183
		<tr id="tcpflags" name="tcpflags"> 
1184
			<td width="22%" valign="top" class="vncell"><?=gettext("TCP flags");?></td>
1185
			<td width="78%" class="vtable">
1186
			<div id="showtcpflagsbox" <?php if ($pconfig['tcpflags_any'] || $pconfig['tcpflags1'] || $pconfig['tcpflags2']) echo "style='display:none'"; ?>>
1187
                        	<input type="button" onClick="show_advanced_tcpflags()" value="<?=gettext("Advanced"); ?>"></input> - <?=gettext("Show advanced option");?></a>
1188
                        </div>
1189
                        <div id="showtcpflagsadv" <?php if (empty($pconfig['tcpflags_any']) && empty($pconfig['tcpflags1']) && empty($pconfig['tcpflags2'])) echo "style='display:none'"; ?>>
1190
			<div id="tcpheader" name="tcpheader">
1191
			<center>
1192
			<table border="0" cellspacing="0" cellpadding="0">
1193
			<?php 
1194
				$setflags = explode(",", $pconfig['tcpflags1']);
1195
				$outofflags = explode(",", $pconfig['tcpflags2']);
1196
				$header = "<td width='40' nowrap></td>";
1197
				$tcpflags1 = "<td width='40' nowrap>set</td>";
1198
				$tcpflags2 = "<td width='40' nowrap>out of</td>";
1199
				foreach ($tcpflags as $tcpflag) {
1200
					$header .= "<td  width='40' nowrap><strong>" . strtoupper($tcpflag) . "</strong></td>\n";
1201
					$tcpflags1 .= "<td  width='40' nowrap> <input type='checkbox' name='tcpflags1_{$tcpflag}' value='on' ";
1202
					if (array_search($tcpflag, $setflags) !== false)
1203
						$tcpflags1 .= "checked";
1204
					$tcpflags1 .= "></td>\n";
1205
					$tcpflags2 .= "<td  width='40' nowrap> <input type='checkbox' name='tcpflags2_{$tcpflag}' value='on' ";
1206
					if (array_search($tcpflag, $outofflags) !== false)
1207
						$tcpflags2 .= "checked";
1208
					$tcpflags2 .= "></td>\n";
1209
				}
1210
				echo "<tr id='tcpheader' name='tcpheader'>{$header}</tr>\n";
1211
				echo "<tr id='tcpflags1' name='tcpflags1'>{$tcpflags1}</tr>\n";
1212
				echo "<tr id='tcpflags2' name='tcpflags2'>{$tcpflags2}</tr>\n";
1213
			?>
1214
			</table>
1215
			<center>
1216
			</div>
1217
			<br/><center>
1218
			<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>
1219
			<br/>
1220
			<span class="vexpl"><?=gettext("Use this to choose TCP flags that must ". 
1221
			"be set or cleared for this rule to match.");?></span>
1222
			</div>
1223
			</td>
1224
		</tr>
1225
		<tr>
1226
			<td width="22%" valign="top" class="vncell"><?=gettext("State Type");?></td>
1227
			<td width="78%" class="vtable">
1228
				<div id="showadvstatebox" <?php if (!empty($pconfig['statetype']) && $pconfig['statetype'] != "keep state") echo "style='display:none'"; ?>>
1229
					<input type="button" onClick="show_advanced_state()" value="<?=gettext("Advanced"); ?>"></input> - <?=gettext("Show advanced option");?></a>
1230
				</div>
1231
				<div id="showstateadv" <?php if (empty($pconfig['statetype']) || $pconfig['statetype'] == "keep state") echo "style='display:none'"; ?>>
1232
					<select name="statetype">
1233
						<option value="keep state" <?php if(!isset($pconfig['statetype']) or $pconfig['statetype'] == "keep state") echo "selected"; ?>><?=gettext("keep state");?></option>
1234
						<option value="sloppy state" <?php if($pconfig['statetype'] == "sloppy state") echo "selected"; ?>><?=gettext("sloppy state");?></option>
1235
						<option value="synproxy state"<?php if($pconfig['statetype'] == "synproxy state")  echo "selected"; ?>><?=gettext("synproxy state");?></option>
1236
						<option value="none"<?php if($pconfig['statetype'] == "none") echo "selected"; ?>><?=gettext("none");?></option>
1237
					</select><br><?=gettext("Hint: Select which type of state tracking mechanism you would like to use.  If in doubt, use keep state.");?>
1238
					<p>
1239
					<table width="90%">
1240
						<tr><td width="25%"><ul><li><?=gettext("keep state");?></li></ul></td><td><?=gettext("Works with all IP protocols.");?></td></tr>
1241
						<tr><td width="25%"><ul><li><?=gettext("sloppy state");?></li></ul></td><td><?=gettext("Works with all IP protocols.");?></td></tr>
1242
						<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>
1243
						<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>
1244
					</table>
1245
					</p>
1246
			  </div>
1247
			</td>
1248
		</tr>
1249
		<tr>
1250
			<td width="22%" valign="top" class="vncell"><?=gettext("No XMLRPC Sync");?></td>
1251
			<td width="78%" class="vtable">
1252
				<div id="showadvnoxmlrpcsyncbox" <?php if ($pconfig['nosync']) echo "style='display:none'"; ?>>
1253
					<input type="button" onClick="show_advanced_noxmlrpc()" value="<?=gettext("Advanced"); ?>"></input> - <?=gettext("Show advanced option");?></a>
1254
				</div>
1255
				<div id="shownoxmlrpcadv" <?php if (empty($pconfig['nosync'])) echo "style='display:none'"; ?>>
1256
					<input type="checkbox" name="nosync"<?php if($pconfig['nosync']) echo " CHECKED"; ?>><br>
1257
					<?=gettext("Hint: This prevents the rule from automatically syncing to other CARP members.");?>
1258
				</div>
1259
			</td>
1260
		</tr>
1261
		<tr>
1262
			<td width="22%" valign="top" class="vncell"><?=gettext("802.1p");?></td>
1263
			<td width="78%" class="vtable">
1264
				<div id="showadvvlanpriobox" <?php if (!empty($pconfig['vlanprio'])) echo "style='display:none'"; ?>>
1265
					<input type="button" onClick="show_advanced_vlanprio()" value="<?=gettext("Advanced"); ?>"></input> - <?=gettext("Show advanced option");?></a>
1266
				</div>
1267
				<div id="showvlanprioadv" <?php if (empty($pconfig['vlanprio'])) echo "style='display:none'"; ?>>
1268
					<?php $vlanprio = array("none", "be", "bk", "ee", "ca", "vi", "vo", "ic", "nc"); ?>
1269
<?php
1270
					$opts = "";
1271
					foreach($vlanprio as $vprio) {
1272
						if ($vprio == $pconfig['vlanprio'])
1273
							$selected = " SELECTED";
1274
						else
1275
							$selected = "";
1276
						if ($vprio == "none")
1277
							$opts .= "<option value=\"\" {$vprio}>{$vprio}</option>\n";
1278
						else
1279
							$opts .= "<option value=\"{$vprio}\" {$selected}>" . strtoupper($vprio) . "</option>\n";
1280
					}
1281
?>
1282
					<select name='vlanprio'>
1283
					<?php echo $opts; ?>
1284
					</select>
1285
					<p><?=gettext("Choose 802.1p priority to match on");?></p>
1286
					<select name='vlanprioset'>
1287
					<?php echo $opts; ?>
1288
					</select>
1289
					<p><?=gettext("Choose 802.1p priority to apply");?></p>
1290
				</div>
1291
			</td>
1292
		</tr>
1293
		<?php
1294
			//build list of schedules
1295
			$schedules = array();
1296
			$schedules[] = "none";//leave none to leave rule enabled all the time
1297
			if(is_array($config['schedules']['schedule'])) {
1298
				foreach ($config['schedules']['schedule'] as $schedule) {
1299
					if ($schedule['name'] <> "")
1300
						$schedules[] = $schedule['name'];
1301
				}
1302
			}
1303
		?>
1304
		<tr>
1305
			<td width="22%" valign="top" class="vncell"><?=gettext("Schedule");?></td>
1306
			<td width="78%" class="vtable">
1307
				<div id="showadvschedulebox" <?php if (!empty($pconfig['sched'])) echo "style='display:none'"; ?>>
1308
					<input type="button" onClick="show_advanced_schedule()" value="<?=gettext("Advanced"); ?>"></input> - <?=gettext("Show advanced option");?></a>
1309
				</div>
1310
				<div id="showscheduleadv" <?php if (empty($pconfig['sched'])) echo "style='display:none'"; ?>>
1311
					<select name='sched'>
1312
<?php
1313
					foreach($schedules as $schedule) {
1314
						if($schedule == $pconfig['sched']) {
1315
							$selected = " SELECTED";
1316
						} else {
1317
							$selected = "";
1318
						}
1319
						if ($schedule == "none") {
1320
							echo "<option value=\"\" {$selected}>{$schedule}</option>\n";
1321
						} else {
1322
							echo "<option value=\"{$schedule}\" {$selected}>{$schedule}</option>\n";
1323
						}
1324
					}
1325
?>
1326
					</select>
1327
					<p><?=gettext("Leave as 'none' to leave the rule enabled all the time.");?></p>
1328
				</div>
1329
			</td>
1330
		</tr>
1331
		<tr>
1332
			<td width="22%" valign="top" class="vncell"><?=gettext("Gateway");?></td>
1333
			<td width="78%" class="vtable">
1334
				<div id="showadvgatewaybox" <?php if (!empty($pconfig['gateway'])) echo "style='display:none'"; ?>>
1335
					<input type="button" onClick="show_advanced_gateway()" value="<?=gettext("Advanced"); ?>"></input> - <?=gettext("Show advanced option");?></a>
1336
				</div>
1337
				<div id="showgatewayadv" <?php if (empty($pconfig['gateway'])) echo "style='display:none'"; ?>>
1338
					<select name='gateway'>
1339
					<option value="" ><?=gettext("default");?></option>
1340
<?php
1341
					/* build a list of gateways */
1342
					$gateways = return_gateways_array();
1343
					// add statically configured gateways to list
1344
					foreach($gateways as $gwname => $gw) {
1345
						if(($pconfig['ipprotocol'] == "inet6") && !is_ipaddrv6($gw['gateway']))
1346
							continue;
1347
						if(($pconfig['ipprotocol'] == "inet") && !is_ipaddrv4($gw['gateway']))
1348
							continue;
1349
						if($gw == "") 
1350
							continue;
1351
						if($gwname == $pconfig['gateway']) {
1352
							$selected = " SELECTED";
1353
						} else {
1354
							$selected = "";
1355
						}
1356
						echo "<option value=\"{$gwname}\" {$selected}>{$gw['name']} - {$gw['gateway']}</option>\n";
1357
					}
1358
					/* add gateway groups to the list */
1359
					if (is_array($config['gateways']['gateway_group'])) {
1360
						foreach($config['gateways']['gateway_group'] as $gw_group) {
1361
							$af = explode("|", $gw_group['item'][0]);
1362
							if(($pconfig['ipprotocol'] == "inet6") && !is_ipaddrv6(lookup_gateway_ip_by_name($af[0])))
1363
								continue;
1364
							if(($pconfig['ipprotocol'] == "inet") && !is_ipaddrv4(lookup_gateway_ip_by_name($af[0])))
1365
								continue;
1366
							if($gw_group['name'] == "")
1367
								continue;
1368
							if($pconfig['gateway'] == $gw_group['name']) {
1369
								$selected = " SELECTED";
1370
							} else {
1371
								$selected = "";
1372
							}
1373
							echo "<option value=\"{$gw_group['name']}\" $selected>{$gw_group['name']}</option>\n";
1374
						}
1375
					}
1376
?>
1377
					</select>
1378
					<p><?=gettext("Leave as 'default' to use the system routing table.  Or choose a gateway to utilize policy based routing.");?></p>
1379
				</div>
1380
			</td>
1381
		</tr>
1382
		<tr>
1383
			<td width="22%" valign="top" class="vncell"><?=gettext("In/Out");?></td>
1384
			<td width="78%" class="vtable">
1385
				<div id="showadvinoutbox" <?php if (!empty($pconfig['dnpipe'])) echo "style='display:none'"; ?>>
1386
					<input type="button" onClick="show_advanced_inout()" value="<?=gettext("Advanced"); ?>"></input> - <?=gettext("Show advanced option");?></a>
1387
				</div>
1388
				<div id="showinoutadv" <?php if (empty($pconfig['dnpipe'])) echo "style='display:none'"; ?>>
1389
					<select name="dnpipe">
1390
<?php
1391
		if (!is_array($dnqlist))
1392
			$dnqlist = array();
1393
		echo "<option value=\"none\"";
1394
		if (!$dnqselected) echo " SELECTED";
1395
		echo " >none</option>";
1396
		foreach ($dnqlist as $dnq => $dnqkey) {
1397
			if($dnq == "")
1398
				continue;
1399
			echo "<option value=\"$dnqkey\"";
1400
			if ($dnqkey == $pconfig['dnpipe']) {
1401
				$dnqselected = 1;
1402
				echo " SELECTED";
1403
			}
1404
			echo ">{$dnq}</option>"; 
1405
		}
1406
?>
1407
			</select> / 			
1408
			<select name="pdnpipe">
1409
<?php
1410
		$dnqselected = 0;
1411
		echo "<option value=\"none\"";
1412
		if (!$dnqselected) echo " SELECTED";
1413
		echo " >none</option>";
1414
		foreach ($dnqlist as $dnq => $dnqkey) {
1415
			if($dnq == "")
1416
				continue;
1417
			echo "<option value=\"$dnqkey\"";
1418
			if ($dnqkey == $pconfig['pdnpipe']) {
1419
				$dnqselected = 1;
1420
				echo " SELECTED";
1421
			}
1422
			echo ">{$dnq}</option>"; 
1423
		}
1424
?>
1425
				</select>
1426
				<br />
1427
				<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>
1428
				</div>
1429
			</td>
1430
		</tr>
1431

    
1432
		<tr>
1433
			<td width="22%" valign="top" class="vncell"><?=gettext("Ackqueue/Queue");?></td>
1434
			<td width="78%" class="vtable">
1435
			<div id="showadvackqueuebox" <?php if (!empty($pconfig['defaultqueue'])) echo "style='display:none'"; ?>>
1436
				<input type="button" onClick="show_advanced_ackqueue()" value="<?=gettext("Advanced"); ?>"></input> - <?=gettext("Show advanced option");?></a>
1437
			</div>
1438
			<div id="showackqueueadv" <?php if (empty($pconfig['defaultqueue'])) echo "style='display:none'"; ?>>
1439
				<select name="ackqueue">
1440
<?php
1441
			if (!is_array($qlist))
1442
				$qlist = array();
1443
			echo "<option value=\"none\"";
1444
			if (!$qselected) echo " SELECTED";
1445
			echo " >none</option>";
1446
			foreach ($qlist as $q => $qkey) {
1447
				if($q == "")
1448
					continue;
1449
				echo "<option value=\"$q\"";
1450
				if ($q == $pconfig['ackqueue']) {
1451
					$qselected = 1;
1452
					echo " SELECTED";
1453
				}
1454
				if (isset($ifdisp[$q]))
1455
					echo ">{$ifdisp[$q]}</option>";
1456
				else
1457
					echo ">{$q}</option>"; 
1458
			}
1459
?>
1460
				</select> / 			
1461
				<select name="defaultqueue">
1462
<?php
1463
			$qselected = 0;
1464
			echo "<option value=\"none\"";
1465
			if (!$qselected) echo " SELECTED";
1466
			echo " >none</option>";
1467
			foreach ($qlist as $q => $qkey) {
1468
				if($q == "")
1469
					continue;
1470
				echo "<option value=\"$q\"";
1471
				if ($q == $pconfig['defaultqueue']) {
1472
					$qselected = 1;
1473
					echo " SELECTED";
1474
				}
1475
				if (isset($ifdisp[$q]))
1476
					echo ">{$ifdisp[$q]}</option>";
1477
				else
1478
					echo ">{$q}</option>"; 
1479
			}
1480
?>
1481
				</select>
1482
					<br />
1483
					<span class="vexpl"><?=gettext("Choose the Acknowledge Queue only if you have selected Queue.");?></span>
1484
				</td>
1485
			</tr>
1486
			<tr>
1487
				<td width="22%" valign="top" class="vncell"><?=gettext("Layer7");?></td>
1488
				<td width="78%" class="vtable">
1489
					<div id="showadvlayer7box" <?php if (!empty($pconfig['l7container'])) echo "style='display:none'"; ?>>
1490
						<input type="button" onClick="show_advanced_layer7()" value="<?=gettext("Advanced"); ?>"></input> - <?=gettext("Show advanced option");?></a>
1491
					</div>
1492
					<div id="showlayer7adv" <?php if (empty($pconfig['l7container'])) echo "style='display:none'"; ?>>
1493
				<select name="l7container">
1494
<?php
1495
					if (!is_array($l7clist))
1496
						$l7clist = array();
1497
					echo "<option value=\"none\"";
1498
					echo " >none</option>";
1499
					foreach ($l7clist as $l7ckey) {
1500
						echo "<option value=\"{$l7ckey}\"";
1501
						if ($l7ckey == $pconfig['l7container']) {
1502
							echo " SELECTED";
1503
						}
1504
						echo ">{$l7ckey}</option>"; 
1505
					}
1506
?>
1507
				</select>			
1508
				<br/>
1509
				<span class="vexpl">
1510
					<?=gettext("Choose a Layer7 container to apply application protocol inspection rules. " .
1511
					"These are valid for TCP and UDP protocols only.");?>
1512
				</span>
1513
			  </div>
1514
			</td>
1515
		</tr>
1516
<?php
1517
		// Allow extending of the firewall edit page and include custom input validation 
1518
		pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/htmlphplate");
1519
?>
1520
		<tr>
1521
			<td width="22%" valign="top">&nbsp;</td>
1522
			<td width="78%">
1523
				&nbsp;<br>&nbsp;
1524
				<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>">  <input type="button" class="formbtn" value="<?=gettext("Cancel"); ?>" onclick="history.back()">
1525
<?php			if (isset($id) && $a_filter[$id]): ?>
1526
					<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>">
1527
<?php 			endif; ?>
1528
				<input name="after" type="hidden" value="<?=htmlspecialchars($after);?>">
1529
			</td>
1530
		</tr>
1531
	</table>
1532
</form>
1533
<script language="JavaScript">
1534
//<![CDATA[
1535
	ext_change();
1536
	typesel_change();
1537
	proto_change();
1538
	<?php if ( (!empty($pconfig['srcbeginport']) && $pconfig['srcbeginport'] != "any") || (!empty($pconfig['srcendport']) && $pconfig['srcendport'] != "any") ): ?>
1539
	show_source_port_range();
1540
	<?php endif; ?>
1541

    
1542
	var addressarray = <?= json_encode(get_alias_list(array("host", "network", "openvpn", "urltable"))) ?>;
1543
	var customarray  = <?= json_encode(get_alias_list("port")) ?>;
1544

    
1545
	var oTextbox1 = new AutoSuggestControl(document.getElementById("src"), new StateSuggestions(addressarray));
1546
        var oTextbox2 = new AutoSuggestControl(document.getElementById("srcbeginport_cust"), new StateSuggestions(customarray));
1547
        var oTextbox3 = new AutoSuggestControl(document.getElementById("srcendport_cust"), new StateSuggestions(customarray));
1548
        var oTextbox4 = new AutoSuggestControl(document.getElementById("dst"), new StateSuggestions(addressarray));
1549
        var oTextbox5 = new AutoSuggestControl(document.getElementById("dstbeginport_cust"), new StateSuggestions(customarray));
1550
        var oTextbox6 = new AutoSuggestControl(document.getElementById("dstendport_cust"), new StateSuggestions(customarray));
1551
//]]>
1552
</script>
1553
<?php include("fend.inc"); ?>
1554
</body>
1555
</html>
(69-69/247)