Project

General

Profile

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

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

    
188
if (isset($_GET['dup']))
189
	unset($id);
190

    
191
if ($_POST) {
192
	unset($input_errors);
193

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

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

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

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

    
229

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

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

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

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

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

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

    
281
	$pconfig = $_POST;
282

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

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

    
313
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
314

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

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

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

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

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

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

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

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

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

    
456
		if (isset($_POST['ipprotocol'] ))
457
			$filterent['ipprotocol'] = $_POST['ipprotocol'];
458

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

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

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

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

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

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

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

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

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

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

    
546
		if ($_POST['dscp'])
547
			$filterent['dscp'] = $_POST['dscp'];
548

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

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

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

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

    
579
		// If we have an associated nat rule, make sure the source and destination doesn't change
580
		if( isset($a_filter[$id]['associated-rule-id']) ) {
581
			$filterent['interface'] = $a_filter[$id]['interface'];
582
			if (isset($a_filter[$id]['protocol']))
583
				$filterent['protocol'] = $a_filter[$id]['protocol'];
584
			else if (isset($filterent['protocol']))
585
				unset($filterent['protocol']);
586
			if ($a_filter[$id]['protocol'] == "icmp" && $a_filter[$id]['icmptype'])
587
				$filterent['icmptype'] = $a_filter[$id]['icmptype'];
588
			else if (isset($filterent['icmptype']))
589
				unset($filterent['icmptype']);
590

    
591
			$filterent['source'] = $a_filter[$id]['source'];
592
			$filterent['destination'] = $a_filter[$id]['destination'];
593
			$filterent['associated-rule-id'] = $a_filter[$id]['associated-rule-id'];
594
		}
595

    
596
		// Allow extending of the firewall edit page and include custom input validation 
597
		pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/pre_write_config");
598

    
599
		if (isset($id) && $a_filter[$id])
600
			$a_filter[$id] = $filterent;
601
		else {
602
			if (is_numeric($after))
603
				array_splice($a_filter, $after+1, 0, array($filterent));
604
			else
605
				$a_filter[] = $filterent;
606
		}
607

    
608
		filter_rules_sort();
609

    
610
		write_config();
611
		mark_subsystem_dirty('filter');
612

    
613
		if (isset($_POST['floating']))
614
			header("Location: firewall_rules.php?if=FloatingRules");
615
		else
616
			header("Location: firewall_rules.php?if=" . $_POST['interface']);
617
		exit;
618
	}
619
}
620

    
621
read_altq_config(); /* XXX: */
622
$qlist =& get_unique_queue_list();
623
read_dummynet_config(); /* XXX: */
624
$dnqlist =& get_unique_dnqueue_list();
625
read_layer7_config();
626
$l7clist =& get_l7_unique_list();
627

    
628
$pgtitle = array(gettext("Firewall"),gettext("Rules"),gettext("Edit"));
629
$statusurl = "status_filter_reload.php";
630
$logurl = "diag_logs_filter.php";
631

    
632
$closehead = false;
633

    
634
$page_filename = "firewall_rules_edit.php";
635
include("head.inc");
636

    
637
?>
638
<link rel="stylesheet" href="/javascript/chosen/chosen.css" />
639
</head>
640

    
641
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
642
<script type="text/javascript" src="/javascript/jquery.ipv4v6ify.js"></script>
643
<script src="/javascript/chosen/chosen.jquery.js" type="text/javascript"></script>
644
<?php include("fbegin.inc"); ?>
645
<?php pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/pre_input_errors"); ?>
646
<?php if ($input_errors) print_input_errors($input_errors); ?>
647

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

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

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

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

    
1164
				<input name="statetimeout" value="<?php echo htmlspecialchars($pconfig['statetimeout']) ?>"><br>
1165
				<?=gettext("State Timeout in seconds");?>
1166
				</p>
1167

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

    
1389
		<tr>
1390
			<td width="22%" valign="top" class="vncell"><?=gettext("Ackqueue/Queue");?></td>
1391
			<td width="78%" class="vtable">
1392
			<div id="showadvackqueuebox" <?php if (!empty($pconfig['defaultqueue'])) echo "style='display:none'"; ?>>
1393
				<input type="button" onClick="show_advanced_ackqueue()" value="<?=gettext("Advanced"); ?>"></input> - <?=gettext("Show advanced option");?></a>
1394
			</div>
1395
			<div id="showackqueueadv" <?php if (empty($pconfig['defaultqueue'])) echo "style='display:none'"; ?>>
1396
				<select name="ackqueue">
1397
<?php
1398
			if (!is_array($qlist))
1399
				$qlist = array();
1400
			echo "<option value=\"none\"";
1401
			if (!$qselected) echo " SELECTED";
1402
			echo " >none</option>";
1403
			foreach ($qlist as $q => $qkey) {
1404
				if($q == "")
1405
					continue;
1406
				echo "<option value=\"$q\"";
1407
				if ($q == $pconfig['ackqueue']) {
1408
					$qselected = 1;
1409
					echo " SELECTED";
1410
				}
1411
				if (isset($ifdisp[$q]))
1412
					echo ">{$ifdisp[$q]}</option>";
1413
				else
1414
					echo ">{$q}</option>"; 
1415
			}
1416
?>
1417
				</select> / 			
1418
				<select name="defaultqueue">
1419
<?php
1420
			$qselected = 0;
1421
			echo "<option value=\"none\"";
1422
			if (!$qselected) echo " SELECTED";
1423
			echo " >none</option>";
1424
			foreach ($qlist as $q => $qkey) {
1425
				if($q == "")
1426
					continue;
1427
				echo "<option value=\"$q\"";
1428
				if ($q == $pconfig['defaultqueue']) {
1429
					$qselected = 1;
1430
					echo " SELECTED";
1431
				}
1432
				if (isset($ifdisp[$q]))
1433
					echo ">{$ifdisp[$q]}</option>";
1434
				else
1435
					echo ">{$q}</option>"; 
1436
			}
1437
?>
1438
				</select>
1439
					<br />
1440
					<span class="vexpl"><?=gettext("Choose the Acknowledge Queue only if you have selected Queue.");?></span>
1441
				</td>
1442
			</tr>
1443
			<tr>
1444
				<td width="22%" valign="top" class="vncell"><?=gettext("Layer7");?></td>
1445
				<td width="78%" class="vtable">
1446
					<div id="showadvlayer7box" <?php if (!empty($pconfig['l7container'])) echo "style='display:none'"; ?>>
1447
						<input type="button" onClick="show_advanced_layer7()" value="<?=gettext("Advanced"); ?>"></input> - <?=gettext("Show advanced option");?></a>
1448
					</div>
1449
					<div id="showlayer7adv" <?php if (empty($pconfig['l7container'])) echo "style='display:none'"; ?>>
1450
				<select name="l7container">
1451
<?php
1452
					if (!is_array($l7clist))
1453
						$l7clist = array();
1454
					echo "<option value=\"none\"";
1455
					echo " >none</option>";
1456
					foreach ($l7clist as $l7ckey) {
1457
						echo "<option value=\"{$l7ckey}\"";
1458
						if ($l7ckey == $pconfig['l7container']) {
1459
							echo " SELECTED";
1460
						}
1461
						echo ">{$l7ckey}</option>"; 
1462
					}
1463
?>
1464
				</select>			
1465
				<br/>
1466
				<span class="vexpl">
1467
					<?=gettext("Choose a Layer7 container to apply application protocol inspection rules. " .
1468
					"These are valid for TCP and UDP protocols only.");?>
1469
				</span>
1470
			  </div>
1471
			</td>
1472
		</tr>
1473
<?php
1474
		// Allow extending of the firewall edit page and include custom input validation 
1475
		pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/htmlphplate");
1476
?>
1477
		<tr>
1478
			<td width="22%" valign="top">&nbsp;</td>
1479
			<td width="78%">
1480
				&nbsp;<br>&nbsp;
1481
				<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>">  <input type="button" class="formbtn" value="<?=gettext("Cancel"); ?>" onclick="history.back()">
1482
<?php			if (isset($id) && $a_filter[$id]): ?>
1483
					<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>">
1484
<?php 			endif; ?>
1485
				<input name="after" type="hidden" value="<?=htmlspecialchars($after);?>">
1486
			</td>
1487
		</tr>
1488
	</table>
1489
</form>
1490
<script language="JavaScript">
1491
<!--
1492
	ext_change();
1493
	typesel_change();
1494
	proto_change();
1495
	<?php if ( (!empty($pconfig['srcbeginport']) && $pconfig['srcbeginport'] != "any") || (!empty($pconfig['srcendport']) && $pconfig['srcendport'] != "any") ): ?>
1496
	show_source_port_range();
1497
	<?php endif; ?>
1498

    
1499
<?php
1500
	$isfirst = 0;
1501
	$aliases = "";
1502
	$addrisfirst = 0;
1503
	$aliasesaddr = "";
1504
	if($config['aliases']['alias'] <> "" and is_array($config['aliases']['alias']))
1505
		foreach($config['aliases']['alias'] as $alias_name) {
1506
			switch ($alias_name['type']) {
1507
			case "port":
1508
				if($isfirst == 1) $portaliases .= ",";
1509
				$portaliases .= "'" . $alias_name['name'] . "'";
1510
				$isfirst = 1;
1511
				break;
1512
			case "host":
1513
			case "network":
1514
			case "openvpn":
1515
			case "urltable":
1516
				if($addrisfirst == 1) $aliasesaddr .= ",";
1517
				$aliasesaddr .= "'" . $alias_name['name'] . "'";
1518
				$addrisfirst = 1;
1519
				break;
1520
			default:
1521
				break;
1522
			}
1523
		}
1524
?>
1525

    
1526
	var addressarray=new Array(<?php echo $aliasesaddr; ?>);
1527
	var customarray=new Array(<?php echo $portaliases; ?>);
1528

    
1529
	var oTextbox1 = new AutoSuggestControl(document.getElementById("src"), new StateSuggestions(addressarray));
1530
        var oTextbox2 = new AutoSuggestControl(document.getElementById("srcbeginport_cust"), new StateSuggestions(customarray));
1531
        var oTextbox3 = new AutoSuggestControl(document.getElementById("srcendport_cust"), new StateSuggestions(customarray));
1532
        var oTextbox4 = new AutoSuggestControl(document.getElementById("dst"), new StateSuggestions(addressarray));
1533
        var oTextbox5 = new AutoSuggestControl(document.getElementById("dstbeginport_cust"), new StateSuggestions(customarray));
1534
        var oTextbox6 = new AutoSuggestControl(document.getElementById("dstendport_cust"), new StateSuggestions(customarray));
1535
//-->
1536
</script>
1537
<?php include("fend.inc"); ?>
1538
</body>
1539
</html>
(66-66/240)