Project

General

Profile

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

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

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

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

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

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

    
302
	$pconfig = $_POST;
303

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

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

    
334
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
335

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

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

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

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

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

    
415
	}
416

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

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

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

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

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

    
485
		if (isset($_POST['ipprotocol'] ))
486
			$filterent['ipprotocol'] = $_POST['ipprotocol'];
487

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

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

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

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

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

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

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

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

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

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

    
575
		if ($_POST['dscp'])
576
			$filterent['dscp'] = $_POST['dscp'];
577

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

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

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

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

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

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

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

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

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

    
644
		filter_rules_sort();
645

    
646
		write_config();
647
		mark_subsystem_dirty('filter');
648

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

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

    
660
$closehead = false;
661

    
662
$page_filename = "firewall_rules_edit.php";
663
include("head.inc");
664

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

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

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

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

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

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

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

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

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

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

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