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 FloatingRules 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'] == "match" && $_POST['defaultqueue'] == "none")
210
		$input_errors[] = gettext("Queue type rules only work with queues.");
211

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

    
246
	if (($_POST['proto'] != "tcp") && ($_POST['proto'] != "udp") && ($_POST['proto'] != "tcp/udp") && ($_POST['proto'] != "icmp")) {
247
		if($_POST['ipprotocol'] == "inet46")
248
			$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");
249
	}
250
	if (($_POST['proto'] == "icmp") && ($_POST['icmptype'] <> "")){
251
		if($_POST['ipprotocol'] == "inet46")
252
			$input_errors[] =  gettext("You can not assign a ICMP type to a rule that applies to IPv4 and IPv6");
253
	}
254

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

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

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

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

    
304
	$pconfig = $_POST;
305

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

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

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

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

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

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

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

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

    
417
	}
418

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
646
		filter_rules_sort();
647

    
648
		if (write_config())
649
			mark_subsystem_dirty('filter');
650

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

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

    
662
$closehead = false;
663

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

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

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

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

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

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

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

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

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

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

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

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