Project

General

Profile

Download (36.7 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
require("guiconfig.inc");
35

    
36
$specialsrcdst = explode(" ", "any wanip lanip lan pptp pppoe");
37

    
38
if (!is_array($config['filter']['rule'])) {
39
	$config['filter']['rule'] = array();
40
}
41
filter_rules_sort();
42
$a_filter = &$config['filter']['rule'];
43

    
44
$id = $_GET['id'];
45
if (is_numeric($_POST['id']))
46
	$id = $_POST['id'];
47

    
48
$after = $_GET['after'];
49

    
50
if (isset($_POST['after']))
51
	$after = $_POST['after'];
52

    
53
if (isset($_GET['dup'])) {
54
	$id = $_GET['dup'];
55
	$after = $_GET['dup'];
56
}
57

    
58
if($id > -1) {
59
	$if = $a_filter[$id]['interface'];
60
	$security_url = "firewall_rules_edit.php?if=". strtolower($if);
61
	if (!isSystemAdmin($HTTP_SERVER_VARS['AUTH_USER'])) {
62
		log_error("Checking for {$security_url}");
63
		if(!in_array($security_url, $allowed)) {
64
			// User does not have access
65
	//		echo "displaying error {$security_url}"; print_r($allowed);
66
			echo display_error_form("401", "Unauthorized. You do not have access to edit rules on the interface {$if}");
67
			exit;
68
		}
69
	}
70
}
71

    
72
if (isset($id) && $a_filter[$id]) {
73
	$pconfig['interface'] = $a_filter[$id]['interface'];
74

    
75
	if (!isset($a_filter[$id]['type']))
76
		$pconfig['type'] = "pass";
77
	else
78
		$pconfig['type'] = $a_filter[$id]['type'];
79

    
80
	if (isset($a_filter[$id]['protocol']))
81
		$pconfig['proto'] = $a_filter[$id]['protocol'];
82
	else
83
		$pconfig['proto'] = "any";
84

    
85
	if ($a_filter[$id]['protocol'] == "icmp")
86
		$pconfig['icmptype'] = $a_filter[$id]['icmptype'];
87

    
88
	address_to_pconfig($a_filter[$id]['source'], $pconfig['src'],
89
		$pconfig['srcmask'], $pconfig['srcnot'],
90
		$pconfig['srcbeginport'], $pconfig['srcendport']);
91

    
92
	if($a_filter[$id]['os'] <> "")
93
		$pconfig['os'] = $a_filter[$id]['os'];
94

    
95
	address_to_pconfig($a_filter[$id]['destination'], $pconfig['dst'],
96
		$pconfig['dstmask'], $pconfig['dstnot'],
97
		$pconfig['dstbeginport'], $pconfig['dstendport']);
98

    
99
	$pconfig['disabled'] = isset($a_filter[$id]['disabled']);
100
	$pconfig['log'] = isset($a_filter[$id]['log']);
101
	$pconfig['descr'] = $a_filter[$id]['descr'];
102

    
103
	/* advanced */
104
        $pconfig['max-src-nodes'] = $a_filter[$id]['max-src-nodes'];
105
        $pconfig['max-src-states'] = $a_filter[$id]['max-src-states'];
106
        $pconfig['statetype'] = $a_filter[$id]['statetype'];
107
	$pconfig['statetimeout'] = $a_filter[$id]['statetimeout'];
108

    
109
	$pconfig['nosync'] = isset($a_filter[$id]['nosync']);
110

    
111
	/* advanced - new connection per second banning*/
112
	$pconfig['max-src-conn-rate'] = $a_filter[$id]['max-src-conn-rate'];
113
	$pconfig['max-src-conn-rates'] = $a_filter[$id]['max-src-conn-rates'];
114

    
115
	/* Multi-WAN next-hop support */
116
	$pconfig['gateway'] = $a_filter[$id]['gateway'];
117
	
118
	//schedule support
119
	$pconfig['sched'] = $a_filter[$id]['sched'];
120

    
121
} else {
122
	/* defaults */
123
	if ($_GET['if'])
124
		$pconfig['interface'] = $_GET['if'];
125
	$pconfig['type'] = "pass";
126
	$pconfig['src'] = "any";
127
	$pconfig['dst'] = "any";
128
}
129

    
130
if (isset($_GET['dup']))
131
	unset($id);
132

    
133
if ($_POST) {
134

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

    
138
	if (($_POST['proto'] != "tcp") && ($_POST['proto'] != "udp") && ($_POST['proto'] != "tcp/udp")) {
139
		$_POST['srcbeginport'] = 0;
140
		$_POST['srcendport'] = 0;
141
		$_POST['dstbeginport'] = 0;
142
		$_POST['dstendport'] = 0;
143
	} else {
144

    
145
		if ($_POST['srcbeginport_cust'] && !$_POST['srcbeginport'])
146
			$_POST['srcbeginport'] = $_POST['srcbeginport_cust'];
147
		if ($_POST['srcendport_cust'] && !$_POST['srcendport'])
148
			$_POST['srcendport'] = $_POST['srcendport_cust'];
149

    
150
		if ($_POST['srcbeginport'] == "any") {
151
			$_POST['srcbeginport'] = 0;
152
			$_POST['srcendport'] = 0;
153
		} else {
154
			if (!$_POST['srcendport'])
155
				$_POST['srcendport'] = $_POST['srcbeginport'];
156
		}
157
		if ($_POST['srcendport'] == "any")
158
			$_POST['srcendport'] = $_POST['srcbeginport'];
159

    
160
		if ($_POST['dstbeginport_cust'] && !$_POST['dstbeginport'])
161
			$_POST['dstbeginport'] = $_POST['dstbeginport_cust'];
162
		if ($_POST['dstendport_cust'] && !$_POST['dstendport'])
163
			$_POST['dstendport'] = $_POST['dstendport_cust'];
164

    
165
		if ($_POST['dstbeginport'] == "any") {
166
			$_POST['dstbeginport'] = 0;
167
			$_POST['dstendport'] = 0;
168
		} else {
169
			if (!$_POST['dstendport'])
170
				$_POST['dstendport'] = $_POST['dstbeginport'];
171
		}
172
		if ($_POST['dstendport'] == "any")
173
			$_POST['dstendport'] = $_POST['dstbeginport'];
174
	}
175

    
176
	if (is_specialnet($_POST['srctype'])) {
177
		$_POST['src'] = $_POST['srctype'];
178
		$_POST['srcmask'] = 0;
179
	} else if ($_POST['srctype'] == "single") {
180
		$_POST['srcmask'] = 32;
181
	}
182
	if (is_specialnet($_POST['dsttype'])) {
183
		$_POST['dst'] = $_POST['dsttype'];
184
		$_POST['dstmask'] = 0;
185
	}  else if ($_POST['dsttype'] == "single") {
186
		$_POST['dstmask'] = 32;
187
	}
188

    
189
	unset($input_errors);
190
	$pconfig = $_POST;
191

    
192
	/*  run through $_POST items encoding HTML entties so that the user
193
	 *  cannot think he is slick and perform a XSS attack on the unwilling 
194
	 */
195
	foreach ($_POST as $key => $value) {
196
		$temp = $value;
197
		$newpost = htmlentities($temp);
198
		if($newpost <> $temp) 
199
			$input_errors[] = "Invalid characters detected ($temp).  Please remove invalid characters and save again.";
200
	}
201

    
202
	/* input validation */
203
	$reqdfields = explode(" ", "type interface proto src dst");
204
	$reqdfieldsn = explode(",", "Type,Interface,Protocol,Source,Destination");
205

    
206

    
207
	if($_POST['statetype'] == "modulate state" or $_POST['statetype'] == "synproxy state") {
208
		if( $_POST['proto'] != "tcp" )
209
			$input_errors[] = "{$_POST['statetype']} is only valid with protocol tcp.";
210
		if(($_POST['statetype'] == "synproxy state") && ($_POST['gateway'] != ""))
211
			$input_errors[] = "{$_POST['statetype']} is only valid if the gateway is set to 'default'.";
212
	}
213

    
214

    
215
	if (!(is_specialnet($_POST['srctype']) || ($_POST['srctype'] == "single"))) {
216
		$reqdfields[] = "srcmask";
217
		$reqdfieldsn[] = "Source bit count";
218
	}
219
	if (!(is_specialnet($_POST['dsttype']) || ($_POST['dsttype'] == "single"))) {
220
		$reqdfields[] = "dstmask";
221
		$reqdfieldsn[] = "Destination bit count";
222
	}
223

    
224
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
225

    
226
	if (!$_POST['srcbeginport']) {
227
		$_POST['srcbeginport'] = 0;
228
		$_POST['srcendport'] = 0;
229
	}
230
	if (!$_POST['dstbeginport']) {
231
		$_POST['dstbeginport'] = 0;
232
		$_POST['dstendport'] = 0;
233
	}
234

    
235
	if (($_POST['srcbeginport'] && !alias_expand($_POST['srcbeginport']) && !is_port($_POST['srcbeginport']))) {
236
		$input_errors[] = "The start source port must be an alias or integer between 1 and 65535.";
237
	}
238
	if (($_POST['srcendport'] && !alias_expand($_POST['srcendport']) && !is_port($_POST['srcendport']))) {
239
		$input_errors[] = "The end source port must be an alias or integer between 1 and 65535.";
240
	}
241
	if (($_POST['dstbeginport'] && !alias_expand($_POST['dstbeginport']) && !is_port($_POST['dstbeginport']))) {
242
		$input_errors[] = "The start destination port must be an alias or integer between 1 and 65535.";
243
	}
244
	if (($_POST['dstendport'] && !alias_expand($_POST['dstbeginport']) && !is_port($_POST['dstendport']))) {
245
		$input_errors[] = "The end destination port must be an alias or integer between 1 and 65535.";
246
	}
247

    
248
	/* if user enters an alias and selects "network" then disallow. */
249
	if($_POST['srctype'] == "network") {
250
		if(is_alias($_POST['src']))
251
			$input_errors[] = "You must specify single host or alias for alias entries.";
252
	}
253
	if($_POST['dsttype'] == "network") {
254
		if(is_alias($_POST['dst']))
255
			$input_errors[] = "You must specify single host or alias for alias entries.";
256
	}
257

    
258
	if (!is_specialnet($_POST['srctype'])) {
259
		if (($_POST['src'] && !is_ipaddroranyalias($_POST['src']))) {
260
			$input_errors[] = "A valid source IP address or alias must be specified.";
261
		}
262
		if (($_POST['srcmask'] && !is_numericint($_POST['srcmask']))) {
263
			$input_errors[] = "A valid source bit count must be specified.";
264
		}
265
	}
266
	if (!is_specialnet($_POST['dsttype'])) {
267
		if (($_POST['dst'] && !is_ipaddroranyalias($_POST['dst']))) {
268
			$input_errors[] = "A valid destination IP address or alias must be specified.";
269
		}
270
		if (($_POST['dstmask'] && !is_numericint($_POST['dstmask']))) {
271
			$input_errors[] = "A valid destination bit count must be specified.";
272
		}
273
	}
274

    
275
	if ($_POST['srcbeginport'] > $_POST['srcendport']) {
276
		/* swap */
277
		$tmp = $_POST['srcendport'];
278
		$_POST['srcendport'] = $_POST['srcbeginport'];
279
		$_POST['srcbeginport'] = $tmp;
280
	}
281
	if ($_POST['dstbeginport'] > $_POST['dstendport']) {
282
		/* swap */
283
		$tmp = $_POST['dstendport'];
284
		$_POST['dstendport'] = $_POST['dstbeginport'];
285
		$_POST['dstbeginport'] = $tmp;
286
	}
287
	if ($_POST['os'])
288
		if( $_POST['proto'] != "tcp" )
289
			$input_errors[] = "OS detection is only valid with protocol tcp.";
290

    
291
	if (!$input_errors) {
292
		$filterent = array();
293
		$filterent['type'] = $_POST['type'];
294
		$filterent['interface'] = $_POST['interface'];
295

    
296
		/* Advanced options */
297
		$filterent['max-src-nodes'] = $_POST['max-src-nodes'];
298
		$filterent['max-src-states'] = $_POST['max-src-states'];
299
		$filterent['statetimeout'] = $_POST['statetimeout'];
300
		$filterent['statetype'] = $_POST['statetype'];
301
		$filterent['os'] = $_POST['os'];
302

    
303
		/* Nosync directive - do not xmlrpc sync this item */
304
		if($_POST['nosync'] <> "")
305
			$filterent['nosync'] = true;
306
		else
307
			unset($filterent['nosync']);
308

    
309
		/* unless both values are provided, unset the values - ticket #650 */
310
		if($_POST['max-src-conn-rate'] <> "" and $_POST['max-src-conn-rates'] <> "") {
311
			$filterent['max-src-conn-rate'] = $_POST['max-src-conn-rate'];
312
			$filterent['max-src-conn-rates'] = $_POST['max-src-conn-rates'];
313
		} else {
314
			unset($filterent['max-src-conn-rate']);
315
			unset($filterent['max-src-conn-rates']);
316
		}
317

    
318
		if ($_POST['proto'] != "any")
319
			$filterent['protocol'] = $_POST['proto'];
320
		else
321
			unset($filterent['protocol']);
322

    
323
		if ($_POST['proto'] == "icmp" && $_POST['icmptype'])
324
			$filterent['icmptype'] = $_POST['icmptype'];
325
		else
326
			unset($filterent['icmptype']);
327

    
328
		pconfig_to_address($filterent['source'], $_POST['src'],
329
			$_POST['srcmask'], $_POST['srcnot'],
330
			$_POST['srcbeginport'], $_POST['srcendport']);
331

    
332
		pconfig_to_address($filterent['destination'], $_POST['dst'],
333
			$_POST['dstmask'], $_POST['dstnot'],
334
			$_POST['dstbeginport'], $_POST['dstendport']);
335

    
336
                if ($_POST['disabled'])
337
                        $filterent['disabled'] = true;
338
                else
339
                        unset($filterent['disabled']);
340
                if ($_POST['log'])
341
                        $filterent['log'] = true;
342
                else
343
                        unset($filterent['log']);
344
		strncpy($filterent['descr'], $_POST['descr'], 52);
345

    
346
		if ($_POST['gateway'] != "") {
347
			$filterent['gateway'] = $_POST['gateway'];
348
		}
349

    
350
		if ($_POST['sched'] != "") {
351
			$filterent['sched'] = $_POST['sched'];
352
		}
353

    
354
		if (isset($id) && $a_filter[$id])
355
			$a_filter[$id] = $filterent;
356
		else {
357
			if (is_numeric($after))
358
				array_splice($a_filter, $after+1, 0, array($filterent));
359
			else
360
				$a_filter[] = $filterent;
361
		}
362

    
363
		write_config();
364
		touch($d_filterconfdirty_path);
365

    
366
		header("Location: firewall_rules.php?if=" . $_POST['interface']);
367
		exit;
368
	}
369
}
370

    
371
$pgtitle = array("Firewall","Rules","Edit");
372
$closehead = false;
373

    
374
$page_filename = "firewall_rules_edit.php";
375
include("head.inc");
376

    
377
?>
378

    
379
</head>
380

    
381
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
382
<?php include("fbegin.inc"); ?>
383
<?php if ($input_errors) print_input_errors($input_errors); ?>
384

    
385
<form action="firewall_rules_edit.php" method="post" name="iform" id="iform">
386
	<table width="100%" border="0" cellpadding="6" cellspacing="0">
387
    	<tr>
388
			<td width="22%" valign="top" class="vncellreq">Action</td>
389
			<td width="78%" class="vtable">
390
				<select name="type" class="formselect">
391
					<?php $types = explode(" ", "Pass Block Reject"); foreach ($types as $type): ?>
392
					<option value="<?=strtolower($type);?>" <?php if (strtolower($type) == strtolower($pconfig['type'])) echo "selected"; ?>>
393
					<?=htmlspecialchars($type);?>
394
					</option>
395
					<?php endforeach; ?>
396
				</select>
397
				<br/>
398
				<span class="vexpl">
399
					Choose what to do with packets that match the criteria specified below. <br/>
400
					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. Reject only works when the protocol is set to either TCP or UDP (but not &quot;TCP/UDP&quot;) below.
401
				</span>
402
			</td>
403
		</tr>
404
		<tr>
405
			<td width="22%" valign="top" class="vncellreq">Disabled</td>
406
			<td width="78%" class="vtable">
407
				<input name="disabled" type="checkbox" id="disabled" value="yes" <?php if ($pconfig['disabled']) echo "checked"; ?>>
408
				<strong>Disable this rule</strong><br />
409
				<span class="vexpl">Set this option to disable this rule without removing it from the list.</span>
410
			</td>
411
		</tr>
412
		<tr>
413
			<td width="22%" valign="top" class="vncellreq">Interface</td>
414
			<td width="78%" class="vtable">
415
				<select name="interface" class="formselect">
416
<?php
417

    
418
					$interfaces = array();
419
					
420
					if(have_ruleint_access("lan")) 
421
						$interfaces['lan'] = "LAN";
422
					if(have_ruleint_access("wan")) 
423
						$interfaces['wan'] = "WAN";
424
						
425
					for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) 
426
						if(have_ruleint_access("opt{$i}")) 
427
							$interfaces['opt' . $i] = $config['interfaces']['opt' . $i]['descr'];
428
					
429
					if ($config['pptpd']['mode'] == "server")
430
						if(have_ruleint_access("pptp")) 
431
							$interfaces['pptp'] = "PPTP VPN";
432
					
433
					if ($config['pppoe']['mode'] == "server")
434
						if(have_ruleint_access("pppoe")) 
435
							$interfaces['pppoe'] = "PPPoE VPN";
436
					
437
					/* add ipsec interfaces */
438
					if (isset($config['ipsec']['enable']) || isset($config['ipsec']['mobileclients']['enable']))
439
						if(have_ruleint_access("enc0")) 
440
							$interfaces["enc0"] = "IPSEC";
441

    
442
					foreach ($interfaces as $iface => $ifacename): ?>
443
						<option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected"; ?>><?=htmlspecialchars($ifacename);?></option>
444
<?php 				endforeach; ?>
445
				</select>
446
				<br />
447
				<span class="vexpl">Choose on which interface packets must come in to match this rule.</span>
448
			</td>
449
		</tr>
450
		<tr>
451
			<td width="22%" valign="top" class="vncellreq">Protocol</td>
452
			<td width="78%" class="vtable">
453
				<select name="proto" class="formselect" onchange="proto_change()">
454
<?php
455
				$protocols = explode(" ", "TCP UDP TCP/UDP ICMP ESP AH GRE IGMP any carp pfsync");
456
				foreach ($protocols as $proto): ?>
457
					<option value="<?=strtolower($proto);?>" <?php if (strtolower($proto) == $pconfig['proto']) echo "selected"; ?>><?=htmlspecialchars($proto);?></option>
458
<?php 			endforeach; ?>
459
				</select>
460
				<br />
461
				<span class="vexpl">Choose which IP protocol this rule should match. <br /> Hint: in most cases, you should specify <em>TCP</em> &nbsp;here.</span>
462
			</td>
463
		</tr>
464
		<tr id="icmpbox" name="icmpbox">
465
			<td valign="top" class="vncell">ICMP type</td>
466
			<td class="vtable">
467
				<select name="icmptype" class="formselect">
468
<?php
469
				$icmptypes = array(
470
				"" => "any",
471
				"echorep" => "Echo reply",
472
				"unreach" => "Destination unreachable",
473
				"squench" => "Source quench",
474
				"redir" => "Redirect",
475
				"althost" => "Alternate Host",
476
				"echoreq" => "Echo",
477
				"routeradv" => "Router advertisement",
478
				"routersol" => "Router solicitation",
479
				"timex" => "Time exceeded",
480
				"paramprob" => "Invalid IP header",
481
				"timereq" => "Timestamp",
482
				"timerep" => "Timestamp reply",
483
				"inforeq" => "Information request",
484
				"inforep" => "Information reply",
485
				"maskreq" => "Address mask request",
486
				"maskrep" => "Address mask reply"
487
				);
488

    
489
				foreach ($icmptypes as $icmptype => $descr): ?>
490
					<option value="<?=$icmptype;?>" <?php if ($icmptype == $pconfig['icmptype']) echo "selected"; ?>><?=htmlspecialchars($descr);?></option>
491
<?php 			endforeach; ?>
492
			</select>
493
			<br />
494
			<span class="vexpl">If you selected ICMP for the protocol above, you may specify an ICMP type here.</span>
495
		</td>
496
		</tr>
497
		<tr>
498
			<td width="22%" valign="top" class="vncellreq">Source</td>
499
			<td width="78%" class="vtable">
500
				<input name="srcnot" type="checkbox" id="srcnot" value="yes" <?php if ($pconfig['srcnot']) echo "checked"; ?>>
501
				<strong>not</strong>
502
				<br />
503
				Use this option to invert the sense of the match.
504
				<br />
505
				<br />
506
				<table border="0" cellspacing="0" cellpadding="0">
507
					<tr>
508
						<td>Type:&nbsp;&nbsp;</td>
509
						<td>
510
							<select name="srctype" class="formselect" onChange="typesel_change()">
511
<?php
512
								$sel = is_specialnet($pconfig['src']); ?>
513
								<option value="any"     <?php if ($pconfig['src'] == "any") { echo "selected"; } ?>>any</option>
514
								<option value="single"  <?php if (($pconfig['srcmask'] == 32) && !$sel) { echo "selected"; $sel = 1; } ?>>Single host or alias</option>
515
								<option value="network" <?php if (!$sel) echo "selected"; ?>>Network</option>
516
								<?php if(have_ruleint_access("wan")): ?>
517
								<option value="wanip" 	<?php if ($pconfig['src'] == "wanip") { echo "selected"; } ?>>WAN address</option>
518
								<?php endif; ?>
519
								<?php if(have_ruleint_access("lan")): ?>
520
								<option value="lanip" 	<?php if ($pconfig['src'] == "lanip") { echo "selected"; } ?>>LAN address</option>
521
								<?php endif; ?>
522
								<?php if(have_ruleint_access("lan")): ?>
523
								<option value="lan"     <?php if ($pconfig['src'] == "lan") { echo "selected"; } ?>>LAN subnet</option>
524
								<?php endif; ?>
525
								<?php if(have_ruleint_access("pptp")): ?>
526
								<option value="pptp"    <?php if ($pconfig['src'] == "pptp") { echo "selected"; } ?>>PPTP clients</option>
527
								<?php endif; ?>
528
								<?php if(have_ruleint_access("pppoe")): ?>
529
								<option value="pppoe"   <?php if ($pconfig['src'] == "pppoe") { echo "selected"; } ?>>PPPoE clients</option>
530
								<?php endif; ?>								
531
<?php
532
								for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++): ?>
533
								<?php if(have_ruleint_access("opt{$i}")): ?>
534
									<option value="opt<?=$i;?>" <?php if ($pconfig['src'] == "opt" . $i) { echo "selected"; } ?>><?=htmlspecialchars($config['interfaces']['opt' . $i]['descr']);?> subnet</option>
535
									<option value="opt<?=$i;?>ip"<?php if ($pconfig['src'] == "opt" . $i . "ip") { echo "selected"; } ?>>
536
										<?=$config['interfaces']['opt' . $i]['descr']?> address
537
									</option>
538
								<?php endif; ?>
539
<?php 							endfor; ?>
540
							</select>
541
						</td>
542
					</tr>
543
					<tr>
544
						<td>Address:&nbsp;&nbsp;</td>
545
						<td>
546
							<input autocomplete='off' name="src" type="text" class="formfldalias" id="src" size="20" value="<?php if (!is_specialnet($pconfig['src'])) echo htmlspecialchars($pconfig['src']);?>"> /
547
							<select name="srcmask" class="formselect" id="srcmask">
548
<?php						for ($i = 31; $i > 0; $i--): ?>
549
								<option value="<?=$i;?>" <?php if ($i == $pconfig['srcmask']) echo "selected"; ?>><?=$i;?></option>
550
<?php 						endfor; ?>
551
							</select>
552
						</td>
553
					</tr>
554
				</table>
555
				<div id="showadvancedboxspr">
556
					<p>
557
					<input type="button" onClick="show_source_port_range()" value="Advanced"></input> - Show source port range</a>
558
				</div>
559
			</td>
560
		</tr>
561
		<tr style="display:none" id="sprtable" name="sprtable">
562
			<td width="22%" valign="top" class="vncellreq">Source port range</td>
563
			<td width="78%" class="vtable">
564
				<table border="0" cellspacing="0" cellpadding="0">
565
					<tr>
566
						<td>from:&nbsp;&nbsp;</td>
567
						<td>
568
							<select name="srcbeginport" class="formselect" onchange="src_rep_change();ext_change()">
569
								<option value="">(other)</option>
570
								<option value="any" <?php $bfound = 0; if ($pconfig['srcbeginport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
571
<?php 							foreach ($wkports as $wkport => $wkportdesc): ?>
572
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcbeginport']) { echo "selected"; $bfound = 1; } ?>><?=htmlspecialchars($wkportdesc);?></option>
573
<?php 							endforeach; ?>
574
							</select>
575
							<input autocomplete='off' class="formfldalias" name="srcbeginport_cust" id="srcbeginport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['srcbeginport']) echo $pconfig['srcbeginport']; ?>">
576
						</td>
577
					</tr>
578
					<tr>
579
						<td>to:</td>
580
						<td>
581
							<select name="srcendport" class="formselect" onchange="ext_change()">
582
								<option value="">(other)</option>
583
								<option value="any" <?php $bfound = 0; if ($pconfig['srcendport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
584
<?php							foreach ($wkports as $wkport => $wkportdesc): ?>
585
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcendport']) { echo "selected"; $bfound = 1; } ?>><?=htmlspecialchars($wkportdesc);?></option>
586
<?php							endforeach; ?>
587
							</select>
588
							<input autocomplete='off' class="formfldalias" name="srcendport_cust" id="srcendport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['srcendport']) echo $pconfig['srcendport']; ?>">
589
						</td>
590
					</tr>
591
				</table>
592
				<br />
593
				<span class="vexpl">Specify the port or port range for the source of the packet for this rule. This is usually not equal to the destination port range (and is often &quot;any&quot;). <br /> Hint: you can leave the <em>'to'</em> field empty if you only want to filter a single port</span><br/>
594
				<span class="vexpl"><B>NOTE:</B> You will not need to enter anything here in 99.99999% of the circumstances.  If you're unsure, do not enter anything here!</span>
595
			</td>
596
		</tr>
597
		<tr>
598
			<td width="22%" valign="top" class="vncellreq">Source OS</td>
599
			<td width="78%" class="vtable">OS Type:&nbsp;
600
				<select name="os" id="os" class="formselect">
601
<?php
602
		           $ostypes = array(
603
						 "" => "any",
604
		                 "AIX" => "AIX",
605
		                 "Linux" => "Linux",
606
		                 "FreeBSD" => "FreeBSD",
607
		                 "NetBSD" => "NetBSD",
608
		                 "OpenBSD" => "OpenBSD",
609
		                 "Solaris" => "Solaris",
610
		                 "MacOS" => "MacOS",
611
		                 "Windows" => "Windows",
612
		                 "Novell" => "Novell",
613
		                 "NMAP" => "NMAP"
614
		           );
615

    
616
					foreach ($ostypes as $ostype => $descr): ?>
617
						<option value="<?=$ostype;?>" <?php if ($ostype == $pconfig['os']) echo "selected"; ?>><?=htmlspecialchars($descr);?></option>
618
<?php				endforeach; ?>
619
				</select>
620
				<br />
621
				Note: this only works for TCP rules
622
			</td>
623
		</tr>
624
		<tr>
625
			<td width="22%" valign="top" class="vncellreq">Destination</td>
626
			<td width="78%" class="vtable">
627
				<input name="dstnot" type="checkbox" id="dstnot" value="yes" <?php if ($pconfig['dstnot']) echo "checked"; ?>>
628
				<strong>not</strong>
629
					<br />
630
				Use this option to invert the sense of the match.
631
					<br />
632
					<br />
633
				<table border="0" cellspacing="0" cellpadding="0">
634
					<tr>
635
						<td>Type:&nbsp;&nbsp;</td>
636
						<td>
637
							<select name="dsttype" class="formselect" onChange="typesel_change()">
638
<?php
639
								$sel = is_specialnet($pconfig['dst']); ?>
640
								<option value="any" <?php if ($pconfig['dst'] == "any") { echo "selected"; } ?>>any</option>
641
								<option value="single" <?php if (($pconfig['dstmask'] == 32) && !$sel) { echo "selected"; $sel = 1; } ?>>Single host or alias</option>
642
								<option value="network" <?php if (!$sel) echo "selected"; ?>>Network</option>
643
								<?php if(have_ruleint_access("wan")): ?>
644
								<option value="wanip" <?php if ($pconfig['dst'] == "wanip") { echo "selected"; } ?>>WAN address</option>
645
								<?php endif; ?>
646
								<?php if(have_ruleint_access("lan")): ?>
647
								<option value="lanip" <?php if ($pconfig['dst'] == "lanip") { echo "selected"; } ?>>LAN address</option>
648
								<?php endif; ?>
649
								<?php if(have_ruleint_access("lan")): ?>
650
								<option value="lan" <?php if ($pconfig['dst'] == "lan") { echo "selected"; } ?>>LAN subnet</option>
651
								<?php endif; ?>
652
								<?php if(have_ruleint_access("pptp")): ?>
653
								<option value="pptp" <?php if ($pconfig['dst'] == "pptp") { echo "selected"; } ?>>PPTP clients</option>
654
								<?php endif; ?>
655
								<?php if(have_ruleint_access("pppoe")): ?>
656
								<option value="pppoe" <?php if ($pconfig['dst'] == "pppoe") { echo "selected"; } ?>>PPPoE clients</option>
657
								<?php endif; ?>								
658
								
659
<?php 							for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++): ?>
660
								<?php if(have_ruleint_access("opt{$i}")): ?>
661
									<option value="opt<?=$i;?>" <?php if ($pconfig['dst'] == "opt" . $i) { echo "selected"; } ?>><?=htmlspecialchars($config['interfaces']['opt' . $i]['descr']);?> subnet</option>
662
									<option value="opt<?=$i;?>ip"<?php if ($pconfig['dst'] == "opt" . $i . "ip") { echo "selected"; } ?>>
663
										<?=$config['interfaces']['opt' . $i]['descr']?> address
664
									</option>
665
								<?php endif; ?>
666
<?php 							endfor; ?>
667
							</select>
668
						</td>
669
					</tr>
670
					<tr>
671
						<td>Address:&nbsp;&nbsp;</td>
672
						<td>
673
							<input name="dst" type="text" class="formfldalias" id="dst" size="20" value="<?php if (!is_specialnet($pconfig['dst'])) echo htmlspecialchars($pconfig['dst']);?>">
674
							/
675
							<select name="dstmask" class="formselect" id="dstmask">
676
<?php
677
							for ($i = 31; $i > 0; $i--): ?>
678
								<option value="<?=$i;?>" <?php if ($i == $pconfig['dstmask']) echo "selected"; ?>><?=$i;?></option>
679
<?php						endfor; ?>
680
							</select>
681
						</td>
682
					</tr>
683
				</table>
684

    
685
			</td>
686
		</tr>
687
		<tr id="dprtr" name="dprtr">
688
			<td width="22%" valign="top" class="vncellreq">Destination port range </td>
689
			<td width="78%" class="vtable">
690
				<table border="0" cellspacing="0" cellpadding="0">
691
					<tr>
692
						<td>from:&nbsp;&nbsp;</td>
693
						<td>
694
							<select name="dstbeginport" class="formselect" onchange="dst_rep_change();ext_change()">
695
								<option value="">(other)</option>
696
								<option value="any" <?php $bfound = 0; if ($pconfig['dstbeginport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
697
<?php 							foreach ($wkports as $wkport => $wkportdesc): ?>
698
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['dstbeginport']) { echo "selected"; $bfound = 1; }?>><?=htmlspecialchars($wkportdesc);?></option>
699
<?php 							endforeach; ?>
700
							</select>
701
							<input autocomplete='off' class="formfldalias" name="dstbeginport_cust" id="dstbeginport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['dstbeginport']) echo $pconfig['dstbeginport']; ?>">
702
						</td>
703
					</tr>
704
					<tr>
705
						<td>to:</td>
706
						<td>
707
							<select name="dstendport" class="formselect" onchange="ext_change()">
708
								<option value="">(other)</option>
709
								<option value="any" <?php $bfound = 0; if ($pconfig['dstendport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
710
<?php							foreach ($wkports as $wkport => $wkportdesc): ?>
711
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['dstendport']) { echo "selected"; $bfound = 1; } ?>><?=htmlspecialchars($wkportdesc);?></option>
712
<?php 							endforeach; ?>
713
							</select>
714
							<input autocomplete='off' class="formfldalias" name="dstendport_cust" id="dstendport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['dstendport']) echo $pconfig['dstendport']; ?>">
715
						</td>
716
					</tr>
717
				</table>
718
				<br />
719
				<span class="vexpl">
720
					Specify the port or port range for the destination of the packet for this rule.
721
						<br />
722
					Hint: you can leave the <em>'to'</em> field empty if you only want to filter a single port
723
				</span>
724
			</td>
725
		</tr>
726
		<tr>
727
			<td width="22%" valign="top" class="vncellreq">Log</td>
728
			<td width="78%" class="vtable">
729
				<input name="log" type="checkbox" id="log" value="yes" <?php if ($pconfig['log']) echo "checked"; ?>>
730
				<strong>Log packets that are handled by this rule</strong>
731
					<br />
732
				<span class="vexpl">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 (see the <a href="diag_logs_settings.php">Diagnostics: System logs: Settings</a> page).</span>
733
			</td>
734
		</tr>
735
		<tr>
736
			<td width="22%" valign="top" class="vncell">Advanced Options</td>
737
			<td width="78%" class="vtable">
738
			<div id="aoadv" name="aoadv">
739
				<input type="button" onClick="show_aodiv();" value="Advanced"> - Show advanced options
740
			</div>
741
			<div id="aodivmain" name="aodivmain" style="display:none">
742
				<input name="max-src-nodes" id="max-src-nodes" value="<?php echo $pconfig['max-src-nodes'] ?>"><br> Simultaneous client connection limit<p>
743
				<input name="max-src-states" id="max-src-states" value="<?php echo $pconfig['max-src-states'] ?>"><br> Maximum state entries per host<p>
744
				<input name="max-src-conn-rate" id="max-src-conn-rate" value="<?php echo $pconfig['max-src-conn-rate'] ?>"> /
745
				<select name="max-src-conn-rates" id="max-src-conn-rates">
746
					<option value=""<?php if(intval($pconfig['max-src-conn-rates']) < 1) echo " selected"; ?>></option>
747
<?php				for($x=1; $x<255; $x++) {
748
						if($x == $pconfig['max-src-conn-rates']) $selected = " selected"; else $selected = "";
749
						echo "<option value=\"{$x}\"{$selected}>{$x}</option>\n";
750
					} ?>
751
				</select><br />
752
				Maximum new connections / per second
753
				<p>
754

    
755
				<input name="statetimeout" value="<?php echo $pconfig['statetimeout'] ?>"><br>
756
				State Timeout in seconds
757
				<p />
758

    
759
				<p><strong>NOTE: Leave these fields blank to disable this feature.</strong>
760
			  </div>
761
			</td>
762
		</tr>
763
		<tr>
764
			<td width="22%" valign="top" class="vncell">State Type</td>
765
			<td width="78%" class="vtable">
766
				<div id="showadvstatebox">
767
					<input type="button" onClick="show_advanced_state()" value="Advanced"></input> - Show state</a>
768
				</div>
769
				<div id="showstateadv" style="display:none">
770
					<select name="statetype">
771
						<option value="keep state" <?php if(!isset($pconfig['statetype']) or $pconfig['statetype'] == "keep state") echo "selected"; ?>>keep state</option>
772
						<option value="modulate state" <?php if($pconfig['statetype'] == "modulate state")  echo "selected"; ?>>modulate state</option>
773
						<option value="synproxy state"<?php if($pconfig['statetype'] == "synproxy state")  echo "selected"; ?>>synproxy state</option>
774
						<option value="none"<?php if($pconfig['statetype'] == "none") echo "selected"; ?>>none</option>
775
					</select><br>HINT: Select which type of state tracking mechanism you would like to use.  If in doubt, use keep state.
776
					<p>
777
					<table width="90%">
778
						<tr><td width="25%"><ul><li>keep state</li></td><td>Works with all IP protocols.</ul></td></tr>
779
						<tr><td width="25%"><ul><li>modulate state</li></td><td>Works only with TCP. {$g['product_name']} will generate strong Initial Sequence Numbers (ISNs) for packets matching this rule.</li></ul></td></tr>
780
						<tr><td width="25%"><ul><li>synproxy state</li></td><td>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.</ul></td></tr>
781
						<tr><td width="25%"><ul><li>none</li></td><td>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.</ul></td></tr>
782
					</table>
783
					</p>
784
			  </div>
785
			</td>
786
		</tr>
787
		<tr>
788
			<td width="22%" valign="top" class="vncell">No XMLRPC Sync</td>
789
			<td width="78%" class="vtable">
790
				<input type="checkbox" name="nosync"<?php if($pconfig['nosync']) echo " CHECKED"; ?>><br>
791
				HINT: This prevents the rule from automatically syncing to other carp members.
792
			</td>
793
		</tr>
794
		<?php
795
			//build list of schedules
796
			$schedules = array();
797
			$schedules[] = "none";//leave none to leave rule enabled all the time
798
			if(is_array($config['schedules']['schedule'])) {
799
				foreach ($config['schedules']['schedule'] as $schedule) {
800
					if ($schedule['name'] <> "")
801
						$schedules[] = $schedule['name'];
802
				}
803
			}
804
		?>
805
		<tr>
806
			<td width="22%" valign="top" class="vncell">Schedule</td>
807
			<td width="78%" class="vtable">
808
				<select name='sched'>
809
<?php
810
				foreach($schedules as $schedule) {
811
					if($schedule == $pconfig['sched']) {
812
						$selected = " SELECTED";
813
					} else {
814
						$selected = "";
815
					}
816
					if ($schedule == "none") {
817
						echo "<option value=\"\" {$selected}>{$schedule}</option>\n";
818
					} else {
819
						echo "<option value=\"{$schedule}\" {$selected}>{$schedule}</option>\n";
820
					}
821
				}?>
822
				</select>
823
				<p>Leave as 'none' to leave the rule enabled all the time.</p>
824
				<strong>NOTE:  schedule logic can be a bit different.  Click <a target="_new" href='firewall_rules_schedule_logic.php'>here</a> for more information.</strong>
825
			</td>
826
		</tr>
827
		
828
<?php
829
			/* build a list of gateways */
830
			$gateways = array();
831
			$gateways[] = "default"; // default to don't use this feature :)
832
			foreach($config['gateways']['gateway_item'] as $gw_item) {
833
			if($gw_item['gateway'] <> "")
834
				$gateways[] = $gw_item['name'];
835
			}
836
?>
837
		<tr>
838
			<td width="22%" valign="top" class="vncell">Gateway</td>
839
			<td width="78%" class="vtable">
840
				<select name='gateway'>
841
<?php
842
				foreach($gateways as $gw) {
843
					if($gw == "") 
844
						continue;
845
					if($gw == $pconfig['gateway']) {
846
						$selected = " SELECTED";
847
					} else {
848
						$selected = "";
849
					}
850
					if ($gw == "default") {
851
						echo "<option value=\"\" {$selected}>{$gw}</option>\n";
852
					} else {
853
						$gwip = lookup_gateway_ip_by_name($gw);
854
						echo "<option value=\"{$gw}\" {$selected}>{$gw} - {$gwip}</option>\n";
855
					}
856
				}
857
				if(is_array($config['load_balancer']['lbpool'])) {
858
					foreach($config['load_balancer']['lbpool'] as $lb) {
859
						if($lb['name'] == "") 
860
							continue;
861
						if($pconfig['gateway'] == $lb['name']) {
862
							echo "<option value=\"{$lb['name']}\" SELECTED>{$lb['name']}</option>\n";
863
						} else {
864
							echo "<option value=\"{$lb['name']}\">{$lb['name']}</option>\n";
865
						}
866
					}
867
				}
868
				for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
869
					if($config['interfaces']['opt' . $i]['ipaddr'] == "dhcp") {
870
						$descr = $config['interfaces']['opt' . $i]['descr'];
871
						if ($pconfig['gateway'] == "opt{$i}") {
872
							$selected = " SELECTED";
873
						} else {
874
							$selected = "";
875
						}
876
						if($descr <> "") 
877
							echo "<option value=\"opt{$i}\" {$selected}>OPT{$i} - {$descr}</option>\n";
878
					}
879
				}
880
?>
881
				</select>
882
				<p><strong>Leave as 'default' to use the system routing table.  Or choose a gateway to utilize policy based routing.</strong></p>
883
			</td>
884
		</tr>
885
		<tr>
886
			<td width="22%" valign="top" class="vncell">Description</td>
887
			<td width="78%" class="vtable">
888
				<input name="descr" type="text" class="formfld unknown" id="descr" size="52" maxlength="52" value="<?=htmlspecialchars($pconfig['descr']);?>">
889
				<br />
890
				<span class="vexpl">You may enter a description here for your reference (not parsed).</span>
891
			</td>
892
		</tr>
893
		<tr>
894
			<td width="22%" valign="top">&nbsp;</td>
895
			<td width="78%">
896
				<input name="Submit" type="submit" class="formbtn" value="Save">  <input type="button" class="formbtn" value="Cancel" onclick="history.back()">
897
<?php			if (isset($id) && $a_filter[$id]): ?>
898
					<input name="id" type="hidden" value="<?=$id;?>">
899
<?php 			endif; ?>
900
				<input name="after" type="hidden" value="<?=$after;?>">
901
			</td>
902
		</tr>
903
	</table>
904
</form>
905
<script language="JavaScript">
906
<!--
907
	ext_change();
908
	typesel_change();
909
	proto_change();
910

    
911
<?php
912
	$isfirst = 0;
913
	$aliases = "";
914
	$addrisfirst = 0;
915
	$aliasesaddr = "";
916
	if($config['aliases']['alias'] <> "" and is_array($config['aliases']['alias']))
917
		foreach($config['aliases']['alias'] as $alias_name) {
918
			if(!stristr($alias_name['address'], ".")) {
919
				if($isfirst == 1) $aliases .= ",";
920
				$aliases .= "'" . $alias_name['name'] . "'";
921
				$isfirst = 1;
922
			} else {
923
				if($addrisfirst == 1) $aliasesaddr .= ",";
924
				$aliasesaddr .= "'" . $alias_name['name'] . "'";
925
				$addrisfirst = 1;
926
			}
927
		}
928
?>
929

    
930
	var addressarray=new Array(<?php echo $aliasesaddr; ?>);
931
	var customarray=new Array(<?php echo $aliases; ?>);
932

    
933
//-->
934
</script>
935

    
936

    
937
<?php include("fend.inc"); ?>
938
</body>
939
</html>
940

    
(51-51/186)