Project

General

Profile

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

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

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

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

    
18
	2. Redistributions in binary form must reproduce the above copyright
19
	   notice, this list of conditions and the following disclaimer in the
20
	   documentation and/or other materials provided with the distribution.
21

    
22
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
23
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
24
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
	POSSIBILITY OF SUCH DAMAGE.
32
*/
33
/*
34
	pfSense_MODULE:	filter
35
*/
36

    
37
##|+PRIV
38
##|*IDENT=page-firewall-rules-edit
39
##|*NAME=Firewall: Rules: Edit page
40
##|*DESCR=Allow access to the 'Firewall: Rules: Edit' page.
41
##|*MATCH=firewall_rules_edit.php*
42
##|-PRIV
43

    
44
require("guiconfig.inc");
45
require("filter.inc");
46
require("shaper.inc");
47

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

    
55
if (!is_array($config['filter']['rule'])) {
56
	$config['filter']['rule'] = array();
57
}
58
filter_rules_sort();
59
$a_filter = &$config['filter']['rule'];
60

    
61
$id = $_GET['id'];
62
if (is_numeric($_POST['id']))
63
	$id = $_POST['id'];
64

    
65
$after = $_GET['after'];
66

    
67
if (isset($_POST['after']))
68
	$after = $_POST['after'];
69

    
70
if (isset($_GET['dup'])) {
71
	$id = $_GET['dup'];
72
	$after = $_GET['dup'];
73
}
74

    
75
if (isset($id) && $a_filter[$id]) {
76
	$pconfig['interface'] = $a_filter[$id]['interface'];
77

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

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

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

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

    
98
	if (isset($a_filter[$id]['ipprotocol']))
99
                $pconfig['ipprotocol'] = $a_filter[$id]['ipprotocol'];
100

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

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

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

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

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

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

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

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

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

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

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

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

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

    
172
	//schedule support
173
	$pconfig['sched'] = $a_filter[$id]['sched'];
174
	$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
read_altq_config(); /* XXX: */
194
$qlist =& get_unique_queue_list();
195
read_dummynet_config(); /* XXX: */
196
$dnqlist =& get_unique_dnqueue_list();
197
read_layer7_config();
198
$l7clist =& get_l7_unique_list();
199

    
200
if ($_POST) {
201
	unset($input_errors);
202

    
203
	if( isset($a_filter[$id]['associated-rule-id']) ) {
204
		$_POST['proto'] = $pconfig['proto'];
205
		if ($pconfig['proto'] == "icmp")
206
			$_POST['icmptype'] = $pconfig['icmptype'];
207
	}
208

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

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

    
215
	if (($_POST['ipprotocol'] <> "") && ($_POST['gateway'] <> "")) {
216
		$a_gatewaygroups = return_gateway_groups_array();
217
		foreach($config['gateways']['gateway_group'] as $gw_group) {
218
			if($gw_group['name'] == $_POST['gateway']) {
219
				$family = $a_gatewaygroups[$_POST['gateway']]['ipprotocol'];
220
				if($_POST['ipprotocol'] == $family) {
221
					continue;
222
				}
223
				if(($_POST['ipprotocol'] == "inet46") && ($_POST['ipprotocol'] != $family)) {
224
					$input_errors[] = gettext("You can not assign a gateway to a rule that applies to IPv4 and IPv6");
225
				}
226
				if(($_POST['ipprotocol'] == "inet6") && ($_POST['ipprotocol'] != $family)) {
227
					$input_errors[] = gettext("You can not assign a IPv4 gateway group on IPv6 Address Family rule");
228
				}
229
				if(($_POST['ipprotocol'] == "inet") && ($_POST['ipprotocol'] != $family)) {
230
					$input_errors[] = gettext("You can not assign a IPv6 gateway group on IPv4 Address Family rule");
231
				}
232
			}
233
		}
234
	}
235
	if (($_POST['ipprotocol'] <> "") && ($_POST['gateway'] <> "") && (is_ipaddr(lookup_gateway_ip_by_name($_POST['gateway'])))) {
236
		if(($_POST['ipprotocol'] == "inet46") && ($_POST['gateway'] <> "")) {
237
			$input_errors[] = gettext("You can not assign a gateway to a rule that applies to IPv4 and IPv6");
238
		}
239
		if(($_POST['ipprotocol'] == "inet6") && (!is_ipaddrv6(lookup_gateway_ip_by_name($_POST['gateway'])))) {
240
			$input_errors[] = gettext("You can not assign the IPv4 Gateway to a IPv6 Filter rule");
241
		}
242
		if(($_POST['ipprotocol'] == "inet") && (!is_ipaddrv4(lookup_gateway_ip_by_name($_POST['gateway'])))) {
243
			$input_errors[] = gettext("You can not assign the IPv6 Gateway to a IPv4 Filter rule");
244
		}
245
	}
246

    
247
	if (($_POST['proto'] != "tcp") && ($_POST['proto'] != "udp") && ($_POST['proto'] != "tcp/udp") && ($_POST['proto'] != "icmp")) {
248
		if($_POST['ipprotocol'] == "inet46")
249
			$input_errors[] =  gettext("You can not assign a protocol other then ICMP, TCP, UDP or TCP/UDP to a rule that applies to IPv4 and IPv6");
250
	}
251
	if (($_POST['proto'] == "icmp") && ($_POST['icmptype'] <> "")){
252
		if($_POST['ipprotocol'] == "inet46")
253
			$input_errors[] =  gettext("You can not assign a ICMP type to a rule that applies to IPv4 and IPv6");
254
	}
255

    
256
	if (($_POST['proto'] != "tcp") && ($_POST['proto'] != "udp") && ($_POST['proto'] != "tcp/udp")) {
257
		$_POST['srcbeginport'] = 0;
258
		$_POST['srcendport'] = 0;
259
		$_POST['dstbeginport'] = 0;
260
		$_POST['dstendport'] = 0;
261
	} else {
262
		if ($_POST['srcbeginport_cust'] && !$_POST['srcbeginport'])
263
			$_POST['srcbeginport'] = trim($_POST['srcbeginport_cust']);
264
		if ($_POST['srcendport_cust'] && !$_POST['srcendport'])
265
			$_POST['srcendport'] = trim($_POST['srcendport_cust']);
266
		if ($_POST['srcbeginport'] == "any") {
267
			$_POST['srcbeginport'] = 0;
268
			$_POST['srcendport'] = 0;
269
		} else {
270
			if (!$_POST['srcendport'])
271
				$_POST['srcendport'] = $_POST['srcbeginport'];
272
		}
273
		if ($_POST['srcendport'] == "any")
274
			$_POST['srcendport'] = $_POST['srcbeginport'];
275

    
276
		if ($_POST['dstbeginport_cust'] && !$_POST['dstbeginport'])
277
			$_POST['dstbeginport'] = trim($_POST['dstbeginport_cust']);
278
		if ($_POST['dstendport_cust'] && !$_POST['dstendport'])
279
			$_POST['dstendport'] = trim($_POST['dstendport_cust']);
280

    
281
		if ($_POST['dstbeginport'] == "any") {
282
			$_POST['dstbeginport'] = 0;
283
			$_POST['dstendport'] = 0;
284
		} else {
285
			if (!$_POST['dstendport'])
286
				$_POST['dstendport'] = $_POST['dstbeginport'];
287
		}
288
		if ($_POST['dstendport'] == "any")
289
			$_POST['dstendport'] = $_POST['dstbeginport'];
290
	}
291

    
292
	if (is_specialnet($_POST['srctype'])) {
293
		$_POST['src'] = $_POST['srctype'];
294
		$_POST['srcmask'] = 0;
295
	} else if ($_POST['srctype'] == "single") {
296
		$_POST['srcmask'] = 32;
297
	}
298
	if (is_specialnet($_POST['dsttype'])) {
299
		$_POST['dst'] = $_POST['dsttype'];
300
		$_POST['dstmask'] = 0;
301
	}  else if ($_POST['dsttype'] == "single") {
302
		$_POST['dstmask'] = 32;
303
	}
304

    
305
	$pconfig = $_POST;
306

    
307
	/* input validation */
308
	$reqdfields = explode(" ", "type proto");
309
	if ( isset($a_filter[$id]['associated-rule-id'])===false ) {
310
		$reqdfields[] = "src";
311
		$reqdfields[] = "dst";
312
	}
313
	$reqdfieldsn = explode(",", "Type,Protocol");
314
	if ( isset($a_filter[$id]['associated-rule-id'])===false ) {
315
		$reqdfieldsn[] = "Source";
316
		$reqdfieldsn[] = "Destination";
317
	}
318

    
319
	if($_POST['statetype'] == "modulate state" or $_POST['statetype'] == "synproxy state") {
320
		if( $_POST['proto'] != "tcp" )
321
			$input_errors[] = sprintf(gettext("%s is only valid with protocol tcp."),$_POST['statetype']);
322
		if(($_POST['statetype'] == "synproxy state") && ($_POST['gateway'] != ""))
323
			$input_errors[] = sprintf(gettext("%s is only valid if the gateway is set to 'default'."),$_POST['statetype']);
324
	}
325
        
326
	if ( isset($a_filter[$id]['associated-rule-id'])===false &&
327
	(!(is_specialnet($_POST['srctype']) || ($_POST['srctype'] == "single"))) ) {
328
		$reqdfields[] = "srcmask";
329
		$reqdfieldsn[] = "Source bit count";
330
	}
331
	if ( isset($a_filter[$id]['associated-rule-id'])===false &&
332
	(!(is_specialnet($_POST['dsttype']) || ($_POST['dsttype'] == "single"))) ) {
333
		$reqdfields[] = "dstmask";
334
		$reqdfieldsn[] = gettext("Destination bit count");
335
	}
336

    
337
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
338

    
339
	if (!$_POST['srcbeginport']) {
340
		$_POST['srcbeginport'] = 0;
341
		$_POST['srcendport'] = 0;
342
	}
343
	if (!$_POST['dstbeginport']) {
344
		$_POST['dstbeginport'] = 0;
345
		$_POST['dstendport'] = 0;
346
	}
347

    
348
	if ($_POST['srcbeginport'] && !is_portoralias($_POST['srcbeginport']))
349
                $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']);
350
	if ($_POST['srcendport'] && !is_portoralias($_POST['srcendport']))
351
			$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']);
352
	if ($_POST['dstbeginport'] && !is_portoralias($_POST['dstbeginport']))
353
			$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']);
354
	if ($_POST['dstendport'] && !is_portoralias($_POST['dstendport']))
355
			$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']);
356
	if ( !$_POST['srcbeginport_cust'] && $_POST['srcendport_cust'])
357
		if (is_alias($_POST['srcendport_cust']))
358
			$input_errors[] = 'If you put port alias in Source port range to: field you must put the same port alias in from: field';
359
	if ( $_POST['srcbeginport_cust'] && $_POST['srcendport_cust']){
360
		if (is_alias($_POST['srcendport_cust']) && is_alias($_POST['srcendport_cust']) && $_POST['srcbeginport_cust'] != $_POST['srcendport_cust'])
361
			$input_errors[] = 'The same port alias must be used in Source port range from: and to: fields';
362
		if ((is_alias($_POST['srcbeginport_cust']) && (!is_alias($_POST['srcendport_cust']) && $_POST['srcendport_cust']!='')) || 
363
		    ((!is_alias($_POST['srcbeginport_cust']) && $_POST['srcbeginport_cust']!='') && is_alias($_POST['srcendport_cust']))) 
364
			$input_errors[] = 'You cannot specify numbers and port aliases at the same time in Source port range from: and to: field';
365
	}
366
	if ( !$_POST['dstbeginport_cust'] && $_POST['dstendport_cust'])
367
		if (is_alias($_POST['dstendport_cust']))
368
			$input_errors[] = 'If you put port alias in Destination port range to: field you must put the same port alias in from: field';
369
	if ( $_POST['dstbeginport_cust'] && $_POST['dstendport_cust']){
370
		if (is_alias($_POST['dstendport_cust']) && is_alias($_POST['dstendport_cust']) && $_POST['dstbeginport_cust'] != $_POST['dstendport_cust'])
371
			$input_errors[] = 'The same port alias must be used in Destination port range from: and to: fields';
372
		if ((is_alias($_POST['dstbeginport_cust']) && (!is_alias($_POST['dstendport_cust']) && $_POST['dstendport_cust']!='')) || 
373
		    ((!is_alias($_POST['dstbeginport_cust']) && $_POST['dstbeginport_cust']!='') && is_alias($_POST['dstendport_cust']))) 
374
			$input_errors[] = 'You cannot specify numbers and port aliases at the same time in Destination port range from: and to: field';
375
	}
376

    
377
	if ($_POST['src'])
378
		$_POST['src'] = trim($_POST['src']);
379
	if ($_POST['dst'])
380
		$_POST['dst'] = trim($_POST['dst']);
381

    
382
	/* if user enters an alias and selects "network" then disallow. */
383
	if($_POST['srctype'] == "network") {
384
		if(is_alias($_POST['src']))
385
			$input_errors[] = gettext("You must specify single host or alias for alias entries.");
386
	}
387
	if($_POST['dsttype'] == "network") {
388
		if(is_alias($_POST['dst']))
389
			$input_errors[] = gettext("You must specify single host or alias for alias entries.");
390
	}
391

    
392
	if (!is_specialnet($_POST['srctype'])) {
393
		if (($_POST['src'] && !is_ipaddroralias($_POST['src']))) {
394
			$input_errors[] = sprintf(gettext("%s is not a valid source IP address or alias."),$_POST['src']);
395
		}
396
		if (($_POST['srcmask'] && !is_numericint($_POST['srcmask']))) {
397
			$input_errors[] = gettext("A valid source bit count must be specified.");
398
		}
399
	}
400
	if (!is_specialnet($_POST['dsttype'])) {
401
		if (($_POST['dst'] && !is_ipaddroralias($_POST['dst']))) {
402
			$input_errors[] = sprintf(gettext("%s is not a valid destination IP address or alias."),$_POST['dst']);
403
		}
404
		if (($_POST['dstmask'] && !is_numericint($_POST['dstmask']))) {
405
			$input_errors[] = gettext("A valid destination bit count must be specified.");
406
		}
407
	}
408
	if((is_ipaddr($_POST['src']) && is_ipaddr($_POST['dst']))) {
409
		if(!validate_address_family($_POST['src'], $_POST['dst']))
410
			$input_errors[] = sprintf(gettext("The Source IP address %s Address Family differs from the destination %s."), $_POST['src'], $_POST['dst']);
411
		if((is_ipaddrv6($_POST['src']) || is_ipaddrv6($_POST['dst'])) && ($_POST['ipprotocol'] == "inet"))
412
			$input_errors[] = gettext("You can not use IPv6 addresses in IPv4 rules.");
413
		if((is_ipaddrv4($_POST['src']) || is_ipaddrv4($_POST['dst'])) && ($_POST['ipprotocol'] == "inet6"))
414
			$input_errors[] = gettext("You can not use IPv4 addresses in IPv6 rules.");
415
		if((is_ipaddr($_POST['src']) || is_ipaddr($_POST['dst'])) && ($_POST['ipprotocol'] == "inet46"))
416
			$input_errors[] = gettext("You can not use a IPv4 or IPv6 address in combined IPv4 + IPv6 rules.");
417

    
418
	}
419

    
420
	if ($_POST['srcbeginport'] > $_POST['srcendport']) {
421
		/* swap */
422
		$tmp = $_POST['srcendport'];
423
		$_POST['srcendport'] = $_POST['srcbeginport'];
424
		$_POST['srcbeginport'] = $tmp;
425
	}
426
	if ($_POST['dstbeginport'] > $_POST['dstendport']) {
427
		/* swap */
428
		$tmp = $_POST['dstendport'];
429
		$_POST['dstendport'] = $_POST['dstbeginport'];
430
		$_POST['dstbeginport'] = $tmp;
431
	}
432
	if ($_POST['os'])
433
		if( $_POST['proto'] != "tcp" )
434
			$input_errors[] = gettext("OS detection is only valid with protocol tcp.");
435

    
436
	if ($_POST['ackqueue'] && $_POST['ackqueue'] != "none") {
437
		if ($_POST['defaultqueue'] == "none" )
438
			$input_errors[] = gettext("You have to select a queue when you select an acknowledge queue too.");
439
		else if ($_POST['ackqueue'] == $_POST['defaultqueue'])
440
			$input_errors[] = gettext("Acknowledge queue and Queue cannot be the same.");		
441
	}
442
	if (isset($_POST['floating']) && $_POST['pdnpipe'] != "none" && (empty($_POST['direction']) || $_POST['direction'] == "any"))
443
		$input_errors[] = gettext("You can not use limiters in Floating rules without choosing a direction.");
444
	if (isset($_POST['floating']) && $_POST['gateway'] != "" && (empty($_POST['direction']) || $_POST['direction'] == "any"))
445
		$input_errors[] = gettext("You can not use gateways in Floating rules without choosing a direction.");
446
	if ($_POST['pdnpipe'] && $_POST['pdnpipe'] != "none") {
447
		if ($_POST['dnpipe'] == "none" )
448
			$input_errors[] = gettext("You must select a queue for the In direction before selecting one for Out too.");
449
		else if ($_POST['pdnpipe'] == $_POST['dnpipe'])
450
			$input_errors[] = gettext("In and Out Queue cannot be the same.");
451
		else if ($dnqlist[$_POST['pdnpipe']][0] == "?" && $dnqlist[$_POST['dnpipe']][0] <> "?")
452
			$input_errors[] = gettext("You cannot select one queue and one virtual interface for IN and Out. both must be from the same type.");
453
		else if ($dnqlist[$_POST['dnpipe']][0] == "?" && $dnqlist[$_POST['pdnpipe']][0] <> "?")                       
454
			$input_errors[] = gettext("You cannot select one queue and one virtual interface for IN and Out. both must be from the same type.");
455
	}
456
	if( !empty($_POST['ruleid']) && !ctype_digit($_POST['ruleid']))
457
		$input_errors[] = gettext('ID must be an integer');
458
	if($_POST['l7container'] && $_POST['l7container'] != "none") {
459
		if(!($_POST['proto'] == "tcp" || $_POST['proto'] == "udp" || $_POST['proto'] == "tcp/udp"))
460
			$input_errors[] = gettext("You can only select a layer7 container for TCP and/or UDP protocols");
461
		if ($_POST['type'] <> "pass")
462
			$input_errors[] = gettext("You can only select a layer7 container for Pass type rules.");
463
	}
464

    
465
	if (!$_POST['tcpflags_any']) {
466
		$settcpflags = array();
467
		$outoftcpflags = array();
468
		foreach ($tcpflags as $tcpflag) {
469
			if ($_POST['tcpflags1_' . $tcpflag] == "on")
470
				$settcpflags[] = $tcpflag;
471
			if ($_POST['tcpflags2_' . $tcpflag] == "on")
472
				$outoftcpflags[] = $tcpflag;
473
		}
474
		if (empty($outoftcpflags) && !empty($settcpflags))
475
			$input_errors[] = gettext("If you specify TCP flags that should be set you should specify out of which flags as well.");
476
	}
477

    
478
	// Allow extending of the firewall edit page and include custom input validation 
479
	pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/input_validation");
480

    
481
	if (!$input_errors) {
482
		$filterent = array();
483
		$filterent['id'] = $_POST['ruleid']>0?$_POST['ruleid']:'';
484
		$filterent['type'] = $_POST['type'];
485
		if (isset($_POST['interface'] ))
486
			$filterent['interface'] = $_POST['interface'];
487

    
488
		if (isset($_POST['ipprotocol'] ))
489
			$filterent['ipprotocol'] = $_POST['ipprotocol'];
490

    
491
		if ($_POST['tcpflags_any']) {
492
			$filterent['tcpflags_any'] = true;
493
		} else {
494
			$settcpflags = array();
495
			$outoftcpflags = array();
496
			foreach ($tcpflags as $tcpflag) {
497
				if ($_POST['tcpflags1_' . $tcpflag] == "on")
498
					$settcpflags[] = $tcpflag;
499
				if ($_POST['tcpflags2_' . $tcpflag] == "on")
500
					$outoftcpflags[] = $tcpflag;
501
			}
502
			if (!empty($outoftcpflags)) {
503
				$filterent['tcpflags2'] = join(",", $outoftcpflags);
504
				if (!empty($settcpflags))
505
					$filterent['tcpflags1'] = join(",", $settcpflags);
506
			}
507
		}
508

    
509
		if (isset($_POST['tag']))
510
			$filterent['tag'] = $_POST['tag'];
511
		if (isset($_POST['tagged']))
512
			$filterent['tagged'] = $_POST['tagged'];
513
		if ($if == "FloatingRules" || isset($_POST['floating'])) {
514
			$filterent['direction'] = $_POST['direction'];
515
			if (isset($_POST['quick']) && $_POST['quick'] <> "")
516
				$filterent['quick'] = $_POST['quick'];
517
			$filterent['floating'] = "yes";
518
			if (isset($_POST['interface']) && count($_POST['interface']) > 0)  {
519
				$filterent['interface'] = implode(",", $_POST['interface']);
520
			}
521
		}
522

    
523
		/* Advanced options */
524
		if ($_POST['allowopts'] == "yes")
525
			$filterent['allowopts'] = true;
526
		else
527
			unset($filterent['allowopts']);
528
		if ($_POST['disablereplyto'] == "yes")
529
			$filterent['disablereplyto'] = true;
530
		else
531
			unset($filterent['disablereplyto']);
532
		$filterent['max'] = $_POST['max'];
533
		$filterent['max-src-nodes'] = $_POST['max-src-nodes'];
534
		$filterent['max-src-conn'] = $_POST['max-src-conn'];
535
		$filterent['max-src-states'] = $_POST['max-src-states'];
536
		$filterent['statetimeout'] = $_POST['statetimeout'];
537
		$filterent['statetype'] = $_POST['statetype'];
538
		$filterent['os'] = $_POST['os'];
539

    
540
		/* Nosync directive - do not xmlrpc sync this item */
541
		if($_POST['nosync'] <> "")
542
			$filterent['nosync'] = true;
543
		else
544
			unset($filterent['nosync']);
545

    
546
		/* unless both values are provided, unset the values - ticket #650 */
547
		if($_POST['max-src-conn-rate'] <> "" and $_POST['max-src-conn-rates'] <> "") {
548
			$filterent['max-src-conn-rate'] = $_POST['max-src-conn-rate'];
549
			$filterent['max-src-conn-rates'] = $_POST['max-src-conn-rates'];
550
		} else {
551
			unset($filterent['max-src-conn-rate']);
552
			unset($filterent['max-src-conn-rates']);
553
		}
554

    
555
		if ($_POST['proto'] != "any")
556
			$filterent['protocol'] = $_POST['proto'];
557
		else
558
			unset($filterent['protocol']);
559

    
560
		if ($_POST['proto'] == "icmp" && $_POST['icmptype'])
561
			$filterent['icmptype'] = $_POST['icmptype'];
562
		else
563
			unset($filterent['icmptype']);
564

    
565
		pconfig_to_address($filterent['source'], $_POST['src'],
566
			$_POST['srcmask'], $_POST['srcnot'],
567
			$_POST['srcbeginport'], $_POST['srcendport']);
568

    
569
		pconfig_to_address($filterent['destination'], $_POST['dst'],
570
			$_POST['dstmask'], $_POST['dstnot'],
571
			$_POST['dstbeginport'], $_POST['dstendport']);
572

    
573
		if ($_POST['disabled'])
574
			$filterent['disabled'] = true;
575
		else
576
			unset($filterent['disabled']);
577

    
578
		if ($_POST['dscp'])
579
			$filterent['dscp'] = $_POST['dscp'];
580

    
581
		if ($_POST['log'])
582
			$filterent['log'] = true;
583
		else
584
			unset($filterent['log']);
585
		strncpy($filterent['descr'], $_POST['descr'], 52);
586

    
587
		if ($_POST['gateway'] != "") {
588
			$filterent['gateway'] = $_POST['gateway'];
589
		}
590
		
591
		if (isset($_POST['defaultqueue']) && $_POST['defaultqueue'] != "none") {
592
			$filterent['defaultqueue'] = $_POST['defaultqueue'];
593
			if (isset($_POST['ackqueue']) && $_POST['ackqueue'] != "none")
594
				$filterent['ackqueue'] = $_POST['ackqueue'];
595
		}
596

    
597
		if (isset($_POST['dnpipe']) && $_POST['dnpipe'] != "none") {
598
			$filterent['dnpipe'] = $_POST['dnpipe'];
599
			if (isset($_POST['pdnpipe']) && $_POST['pdnpipe'] != "none")
600
				$filterent['pdnpipe'] = $_POST['pdnpipe'];
601
		}
602

    
603
		if (isset($_POST['l7container']) && $_POST['l7container'] != "none") {
604
			$filterent['l7container'] = $_POST['l7container'];
605
		}
606
		
607
		if ($_POST['sched'] != "") {
608
			$filterent['sched'] = $_POST['sched'];
609
		}
610

    
611
		if ($_POST['vlanprio'] != "") {
612
			$filterent['vlanprio'] = $_POST['vlanprio'];
613
		}
614
		if ($_POST['vlanprioset'] != "") {
615
			$filterent['vlanprioset'] = $_POST['vlanprioset'];
616
		}
617

    
618
		// If we have an associated nat rule, make sure the source and destination doesn't change
619
		if( isset($a_filter[$id]['associated-rule-id']) ) {
620
			$filterent['interface'] = $a_filter[$id]['interface'];
621
			if (isset($a_filter[$id]['protocol']))
622
				$filterent['protocol'] = $a_filter[$id]['protocol'];
623
			else if (isset($filterent['protocol']))
624
				unset($filterent['protocol']);
625
			if ($a_filter[$id]['protocol'] == "icmp" && $a_filter[$id]['icmptype'])
626
				$filterent['icmptype'] = $a_filter[$id]['icmptype'];
627
			else if (isset($filterent['icmptype']))
628
				unset($filterent['icmptype']);
629

    
630
			$filterent['source'] = $a_filter[$id]['source'];
631
			$filterent['destination'] = $a_filter[$id]['destination'];
632
			$filterent['associated-rule-id'] = $a_filter[$id]['associated-rule-id'];
633
		}
634

    
635
		// Allow extending of the firewall edit page and include custom input validation 
636
		pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/pre_write_config");
637

    
638
		if (isset($id) && $a_filter[$id])
639
			$a_filter[$id] = $filterent;
640
		else {
641
			if (is_numeric($after))
642
				array_splice($a_filter, $after+1, 0, array($filterent));
643
			else
644
				$a_filter[] = $filterent;
645
		}
646

    
647
		filter_rules_sort();
648

    
649
		write_config();
650
		mark_subsystem_dirty('filter');
651

    
652
		if (isset($_POST['floating']))
653
			header("Location: firewall_rules.php?if=FloatingRules");
654
		else
655
			header("Location: firewall_rules.php?if=" . $_POST['interface']);
656
		exit;
657
	}
658
}
659

    
660
$pgtitle = array(gettext("Firewall"),gettext("Rules"),gettext("Edit"));
661
$shortcut_section = "firewall";
662

    
663
$closehead = false;
664

    
665
$page_filename = "firewall_rules_edit.php";
666
include("head.inc");
667

    
668
?>
669
<link rel="stylesheet" href="/javascript/chosen/chosen.css" />
670
</head>
671

    
672
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
673
<script type="text/javascript" src="/javascript/jquery.ipv4v6ify.js"></script>
674
<script src="/javascript/chosen/chosen.jquery.js" type="text/javascript"></script>
675
<?php include("fbegin.inc"); ?>
676
<?php pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/pre_input_errors"); ?>
677
<?php if ($input_errors) print_input_errors($input_errors); ?>
678

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

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

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

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

    
1197
				<input name="statetimeout" value="<?php echo htmlspecialchars($pconfig['statetimeout']) ?>"><br>
1198
				<?=gettext("State Timeout in seconds");?>
1199
				</p>
1200

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

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

    
1568
	var addressarray = <?= json_encode(get_alias_list(array("host", "network", "openvpn", "urltable"))) ?>;
1569
	var customarray  = <?= json_encode(get_alias_list("port")) ?>;
1570

    
1571
	var oTextbox1 = new AutoSuggestControl(document.getElementById("src"), new StateSuggestions(addressarray));
1572
        var oTextbox2 = new AutoSuggestControl(document.getElementById("srcbeginport_cust"), new StateSuggestions(customarray));
1573
        var oTextbox3 = new AutoSuggestControl(document.getElementById("srcendport_cust"), new StateSuggestions(customarray));
1574
        var oTextbox4 = new AutoSuggestControl(document.getElementById("dst"), new StateSuggestions(addressarray));
1575
        var oTextbox5 = new AutoSuggestControl(document.getElementById("dstbeginport_cust"), new StateSuggestions(customarray));
1576
        var oTextbox6 = new AutoSuggestControl(document.getElementById("dstendport_cust"), new StateSuggestions(customarray));
1577
//]]>
1578
</script>
1579
<?php include("fend.inc"); ?>
1580
</body>
1581
</html>
(69-69/250)