Project

General

Profile

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

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

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

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

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

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

    
301
	$pconfig = $_POST;
302

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

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

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

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

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

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

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

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

    
414
	}
415

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
645
		filter_rules_sort();
646

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

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

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

    
661
$closehead = false;
662

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

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

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

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

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

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

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

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

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

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

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

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