Project

General

Profile

Download (38.4 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	firewall_rules.php
5
	part of pfSense (https://www.pfsense.org)
6
	Copyright (C) 2005 Scott Ullrich (sullrich@gmail.com)
7
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
8

    
9
	originally part of m0n0wall (http://m0n0.ch/wall)
10
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
11
	All rights reserved.
12

    
13
	Redistribution and use in source and binary forms, with or without
14
	modification, are permitted provided that the following conditions are met:
15

    
16
	1. Redistributions of source code must retain the above copyright notice,
17
	   this list of conditions and the following disclaimer.
18

    
19
	2. Redistributions in binary form must reproduce the above copyright
20
	   notice, this list of conditions and the following disclaimer in the
21
	   documentation and/or other materials provided with the distribution.
22

    
23
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
24
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
25
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
27
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
	POSSIBILITY OF SUCH DAMAGE.
33
*/
34
/*
35
	pfSense_MODULE:	filter
36
*/
37

    
38
##|+PRIV
39
##|*IDENT=page-firewall-rules
40
##|*NAME=Firewall: Rules page
41
##|*DESCR=Allow access to the 'Firewall: Rules' page.
42
##|*MATCH=firewall_rules.php*
43
##|-PRIV
44

    
45
require("guiconfig.inc");
46
require_once("functions.inc");
47
require_once("filter.inc");
48
require_once("shaper.inc");
49

    
50
$pgtitle = array(gettext("Firewall"), gettext("Rules"));
51
$shortcut_section = "firewall";
52

    
53
function delete_nat_association($id) {
54
	global $config;
55

    
56
	if (!$id || !is_array($config['nat']['rule'])) {
57
		return;
58
	}
59

    
60
	$a_nat = &$config['nat']['rule'];
61

    
62
	foreach ($a_nat as &$natent) {
63
		if ($natent['associated-rule-id'] == $id) {
64
			$natent['associated-rule-id'] = '';
65
		}
66
	}
67
}
68

    
69
if (!is_array($config['filter']['rule'])) {
70
	$config['filter']['rule'] = array();
71
}
72
filter_rules_sort();
73
$a_filter = &$config['filter']['rule'];
74

    
75
$if = $_GET['if'];
76
if ($_POST['if']) {
77
	$if = $_POST['if'];
78
}
79

    
80
$ifdescs = get_configured_interface_with_descr();
81

    
82
/* add group interfaces */
83
if (is_array($config['ifgroups']['ifgroupentry'])) {
84
	foreach ($config['ifgroups']['ifgroupentry'] as $ifgen) {
85
		if (have_ruleint_access($ifgen['ifname'])) {
86
			$iflist[$ifgen['ifname']] = $ifgen['ifname'];
87
		}
88
	}
89
}
90

    
91
foreach ($ifdescs as $ifent => $ifdesc) {
92
	if (have_ruleint_access($ifent)) {
93
		$iflist[$ifent] = $ifdesc;
94
	}
95
}
96

    
97
if ($config['l2tp']['mode'] == "server") {
98
	if (have_ruleint_access("l2tp")) {
99
		$iflist['l2tp'] = "L2TP VPN";
100
	}
101
}
102

    
103
if ($config['pptpd']['mode'] == "server") {
104
	if (have_ruleint_access("pptp")) {
105
		$iflist['pptp'] = "PPTP VPN";
106
	}
107
}
108

    
109
if (is_array($config['pppoes']['pppoe'])) {
110
	foreach ($config['pppoes']['pppoe'] as $pppoes) {
111
		if (($pppoes['mode'] == 'server') && have_ruleint_access("pppoe")) {
112
			$iflist['pppoe'] = "PPPoE Server";
113
		}
114
	}
115
}
116

    
117
/* add ipsec interfaces */
118
if (isset($config['ipsec']['enable']) || isset($config['ipsec']['client']['enable'])) {
119
	if (have_ruleint_access("enc0")) {
120
		$iflist["enc0"] = "IPsec";
121
	}
122
}
123

    
124
/* add openvpn/tun interfaces */
125
if ($config['openvpn']["openvpn-server"] || $config['openvpn']["openvpn-client"]) {
126
	$iflist["openvpn"] = "OpenVPN";
127
}
128

    
129
pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/interfaces_override");
130

    
131
if (!$if || !isset($iflist[$if])) {
132
	if ("any" == $if) {
133
		$if = "FloatingRules";
134
	} else if ("FloatingRules" != $if) {
135
		if (isset($iflist['wan'])) {
136
			$if = "wan";
137
		} else {
138
			$if = "FloatingRules";
139
		}
140
	}
141
}
142

    
143
if ($_POST) {
144

    
145
	$pconfig = $_POST;
146

    
147
	if ($_POST['apply']) {
148
		$retval = 0;
149
		$retval = filter_configure();
150

    
151
		clear_subsystem_dirty('filter');
152

    
153
		pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/apply");
154

    
155
		$savemsg = sprintf(gettext("The settings have been applied. The firewall rules are now reloading in the background.<br />You can also %s monitor %s the reload progress"), "<a href='status_filter_reload.php'>", "</a>");
156
	}
157
}
158

    
159
if ($_GET['act'] == "del") {
160
	if ($a_filter[$_GET['id']]) {
161
		if (!empty($a_filter[$_GET['id']]['associated-rule-id'])) {
162
			delete_nat_association($a_filter[$_GET['id']]['associated-rule-id']);
163
		}
164
		unset($a_filter[$_GET['id']]);
165
		if (write_config()) {
166
			mark_subsystem_dirty('filter');
167
		}
168
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
169
		exit;
170
	}
171
}
172

    
173
// Handle save msg if defined
174
if ($_REQUEST['savemsg']) {
175
	$savemsg = htmlentities($_REQUEST['savemsg']);
176
}
177

    
178
if (isset($_POST['del_x'])) {
179
	/* delete selected rules */
180
	if (is_array($_POST['rule']) && count($_POST['rule'])) {
181
		foreach ($_POST['rule'] as $rulei) {
182
			delete_nat_association($a_filter[$rulei]['associated-rule-id']);
183
			unset($a_filter[$rulei]);
184
		}
185
		if (write_config()) {
186
			mark_subsystem_dirty('filter');
187
		}
188
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
189
		exit;
190
	}
191
} else if ($_GET['act'] == "toggle") {
192
	if ($a_filter[$_GET['id']]) {
193
		if (isset($a_filter[$_GET['id']]['disabled'])) {
194
			unset($a_filter[$_GET['id']]['disabled']);
195
		} else {
196
			$a_filter[$_GET['id']]['disabled'] = true;
197
		}
198
		if (write_config()) {
199
			mark_subsystem_dirty('filter');
200
		}
201
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
202
		exit;
203
	}
204
} else {
205
	/* yuck - IE won't send value attributes for image buttons, while Mozilla does -
206
	   so we use .x/.y to fine move button clicks instead... */
207
	unset($movebtn);
208
	foreach ($_POST as $pn => $pd) {
209
		if (preg_match("/move_(\d+)_x/", $pn, $matches)) {
210
			$movebtn = $matches[1];
211
			break;
212
		}
213
	}
214
	/* move selected rules before this rule */
215
	if (isset($movebtn) && is_array($_POST['rule']) && count($_POST['rule'])) {
216
		$a_filter_new = array();
217

    
218
		/* copy all rules < $movebtn and not selected */
219
		for ($i = 0; $i < $movebtn; $i++) {
220
			if (!in_array($i, $_POST['rule'])) {
221
				$a_filter_new[] = $a_filter[$i];
222
			}
223
		}
224

    
225
		/* copy all selected rules */
226
		for ($i = 0; $i < count($a_filter); $i++) {
227
			if ($i == $movebtn) {
228
				continue;
229
			}
230
			if (in_array($i, $_POST['rule'])) {
231
				$a_filter_new[] = $a_filter[$i];
232
			}
233
		}
234

    
235
		/* copy $movebtn rule */
236
		if ($movebtn < count($a_filter)) {
237
			$a_filter_new[] = $a_filter[$movebtn];
238
		}
239

    
240
		/* copy all rules > $movebtn and not selected */
241
		for ($i = $movebtn+1; $i < count($a_filter); $i++) {
242
			if (!in_array($i, $_POST['rule'])) {
243
				$a_filter_new[] = $a_filter[$i];
244
			}
245
		}
246

    
247
		$a_filter = $a_filter_new;
248
		if (write_config()) {
249
			mark_subsystem_dirty('filter');
250
		}
251
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
252
		exit;
253
	}
254
}
255
$closehead = false;
256

    
257
include("head.inc");
258
?>
259
<link type="text/css" rel="stylesheet" href="/javascript/chosen/chosen.css" />
260
</head>
261

    
262
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
263
<script src="/javascript/chosen/chosen.jquery.js" type="text/javascript"></script>
264
<?php include("fbegin.inc"); ?>
265
<form action="firewall_rules.php" method="post">
266

    
267
<script type="text/javascript" src="/javascript/row_toggle.js"></script>
268
<?php if ($savemsg) print_info_box($savemsg); ?>
269
<?php if (is_subsystem_dirty('filter')): ?><p>
270
<?php	print_info_box_np(gettext("The firewall rule configuration has been changed.") . "<br />" . gettext("You must apply the changes in order for them to take effect."), "apply", "", true); ?>
271
<br />
272
<?php endif; ?>
273
<?php
274
	pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/before_table");
275
?>
276
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="firewall rules">
277
	<tr><td class="tabnavtbl">
278
	<?php
279
	/* active tabs */
280
	$tab_array = array();
281
	if ("FloatingRules" == $if) {
282
		$active = true;
283
	} else {
284
		$active = false;
285
	}
286
	$tab_array[] = array(gettext("Floating"), $active, "firewall_rules.php?if=FloatingRules");
287
	$tabscounter = 0;
288
	$i = 0;
289
	foreach ($iflist as $ifent => $ifname) {
290
		if ($ifent == $if) {
291
			$active = true;
292
		} else {
293
			$active = false;
294
		}
295
		$tab_array[] = array($ifname, $active, "firewall_rules.php?if={$ifent}");
296
	}
297
	display_top_tabs($tab_array);
298
	?>
299
	</td></tr>
300
	<tr><td>
301
		<div id="mainarea">
302
		<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="main area">
303
			<?php
304
				pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/before_first_tr");
305
			?>
306
			<tr id="frheader">
307
				<td width="3%" class="list">&nbsp;</td>
308
				<td width="5%" class="list">&nbsp;</td>
309
				<td width="3%" class="listhdrr"><?=gettext("ID");?></td>
310
				<?php
311
					pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/pre_id_tablehead");
312
				?>
313
				<?php
314
					if ('FloatingRules' == $if) {
315
				?>
316
				<td width="3%" class="listhdrr"><?=gettext('Interfaces');?></td>
317
				<?php
318
					}
319
				?>
320
				<td width="6%" class="listhdrr"><?=gettext("Proto");?></td>
321
				<td width="12%" class="listhdrr"><?=gettext("Source");?></td>
322
				<td width="6%" class="listhdrr"><?=gettext("Port");?></td>
323
				<td width="12%" class="listhdrr"><?=gettext("Destination");?></td>
324
				<td width="6%" class="listhdrr"><?=gettext("Port");?></td>
325
				<td width="5%" class="listhdrr"><?=gettext("Gateway");?></td>
326
				<td width="8%" class="listhdrr"><?=gettext("Queue");?></td>
327
				<td width="5%" class="listhdrr"><?=gettext("Schedule");?></td>
328
				<?php
329
					pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/pre_desc_tablehead");
330
				?>
331
				<td width="19%" class="listhdr"><?=gettext("Description");?></td>
332
				<td width="10%" class="list">
333
					<table border="0" cellspacing="0" cellpadding="1" summary="delete selected rules">
334
						<tr>
335
						<?php
336
							$nrules = 0;
337
							for ($i = 0; isset($a_filter[$i]); $i++) {
338
								$filterent = $a_filter[$i];
339
								if ($filterent['interface'] != $if && !isset($filterent['floating'])) {
340
									continue;
341
								}
342
								if (isset($filterent['floating']) && "FloatingRules" != $if) {
343
									continue;
344
								}
345
								$nrules++;
346
							}
347
						?>
348
							<td>
349
							<?php if ($nrules == 0): ?>
350
								<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x_d.gif" width="17" height="17" title="<?gettext("delete selected rules"); ?>" border="0" alt="delete" /><?php else: ?>
351
								<input name="del" type="image" src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" style="width:17;height:17" title="<?=gettext("delete selected rules");?>" onclick="return confirm('<?=gettext('Do you really want to delete the selected rules?');?>')" />
352
							<?php endif; ?>
353
							</td>
354
							<td align="center" valign="middle">
355
								<a href="firewall_rules_edit.php?if=<?=htmlspecialchars($if);?>&amp;after=-1">
356
									<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="<?=gettext("add new rule");?>" width="17" height="17" border="0" alt="add" />
357
								</a>
358
							</td>
359
						</tr>
360
					</table>
361
				</td>
362
			</tr>
363
			<?php   // Show the anti-lockout rule if it's enabled, and we are on LAN with an if count > 1, or WAN with an if count of 1.
364
				if (!isset($config['system']['webgui']['noantilockout']) &&
365
				    (((count($config['interfaces']) > 1) && ($if == 'lan')) ||
366
				     ((count($config['interfaces']) == 1) && ($if == 'wan')))):
367

    
368
					$alports = implode('<br />', filter_get_antilockout_ports(true));
369
			?>
370
			<tr valign="top" id="antilockout">
371
				<td class="list">&nbsp;</td>
372
				<td class="listt" align="center"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_pass.gif" width="11" height="11" border="0" alt="pass" /></td>
373
				<td class="listlr" style="background-color: #E0E0E0">&nbsp;</td>
374
				<?php
375
					pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/pre_id_tr_antilockout");
376
				?>
377
				<td class="listr" style="background-color: #E0E0E0">*</td>
378
				<td class="listr" style="background-color: #E0E0E0">*</td>
379
				<td class="listr" style="background-color: #E0E0E0">*</td>
380
				<td class="listr" style="background-color: #E0E0E0"><?=$iflist[$if];?> Address</td>
381
				<td class="listr" style="background-color: #E0E0E0"><?= $alports ?></td>
382
				<td class="listr" style="background-color: #E0E0E0">*</td>
383
				<td class="listr" style="background-color: #E0E0E0">*</td>
384
				<td class="listr" style="background-color: #E0E0E0">&nbsp;</td>
385
				<td class="listbg"><?=gettext("Anti-Lockout Rule");?></td>
386
				<td valign="middle" class="list nowrap">
387
					<table border="0" cellspacing="0" cellpadding="1" summary="move rules before">
388
						<tr>
389
							<td><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_left_d.gif" width="17" height="17" title="<?=gettext("move selected rules before this rule");?>" alt="move" /></td>
390
							<td><a href="system_advanced_admin.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" title="<?=gettext("edit rule");?>" width="17" height="17" border="0" alt="edit" /></a></td>
391
						</tr>
392
						<tr>
393
							<td align="center" valign="middle"></td>
394
							<td><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus_d.gif" title="<?=gettext("add a new rule based on this one");?>" width="17" height="17" border="0" alt="add" /></td>
395
						</tr>
396
					</table>
397
				</td>
398
			</tr>
399
<?php endif; ?>
400

    
401
<?php if (isset($config['interfaces'][$if]['blockpriv'])): ?>
402
			<tr valign="top" id="frrfc1918">
403
				<td class="list">&nbsp;</td>
404
				<td class="listt" align="center"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_block.gif" width="11" height="11" border="0" alt="block" /></td>
405
				<td class="listlr" style="background-color: #E0E0E0">&nbsp;</td>
406
				<td class="listr" style="background-color: #E0E0E0">*</td>
407
				<td class="listr" style="background-color: #E0E0E0"><?=gettext("RFC 1918 networks");?></td>
408
				<td class="listr" style="background-color: #E0E0E0">*</td>
409
				<td class="listr" style="background-color: #E0E0E0">*</td>
410
				<td class="listr" style="background-color: #E0E0E0">*</td>
411
				<td class="listr" style="background-color: #E0E0E0">*</td>
412
				<td class="listr" style="background-color: #E0E0E0">*</td>
413
				<td class="listr" style="background-color: #E0E0E0">&nbsp;</td>
414
				<td class="listbg"><?=gettext("Block private networks");?></td>
415
				<td valign="middle" class="list nowrap">
416
					<table border="0" cellspacing="0" cellpadding="1" summary="move rules before">
417
						<tr>
418
							<td><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_left_d.gif" width="17" height="17" title="<?=gettext("move selected rules before this rule");?>" alt="edit" /></td>
419
							<td><a href="interfaces.php?if=<?=htmlspecialchars($if)?>#rfc1918"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" title="<?=gettext("edit rule");?>" width="17" height="17" border="0" alt="edit" /></a></td>
420
						</tr>
421
						<tr>
422
							<td align="center" valign="middle"></td>
423
							<td><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus_d.gif" title="<?=gettext("add a new rule based on this one");?>" width="17" height="17" border="0" alt="add" /></td>
424
						</tr>
425
					</table>
426
				</td>
427
			</tr>
428
<?php endif; ?>
429
<?php if (isset($config['interfaces'][$if]['blockbogons'])): ?>
430
			<tr valign="top" id="frrfc1918">
431
				<td class="list">&nbsp;</td>
432
				<td class="listt" align="center"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_block.gif" width="11" height="11" border="0" alt="block" /></td>
433
				<td class="listlr" style="background-color: #E0E0E0">&nbsp;</td>
434
				<td class="listr" style="background-color: #E0E0E0">*</td>
435
				<td class="listr" style="background-color: #E0E0E0"><?=gettext("Reserved/not assigned by IANA");?></td>
436
				<td class="listr" style="background-color: #E0E0E0">*</td>
437
				<td class="listr" style="background-color: #E0E0E0">*</td>
438
				<td class="listr" style="background-color: #E0E0E0">*</td>
439
				<td class="listr" style="background-color: #E0E0E0">*</td>
440
				<td class="listr" style="background-color: #E0E0E0">*</td>
441
				<td class="listr" style="background-color: #E0E0E0">*</td>
442
				<td class="listbg"><?=gettext("Block bogon networks");?></td>
443
				<td valign="middle" class="list nowrap">
444
					<table border="0" cellspacing="0" cellpadding="1" summary="move rules before">
445
						<tr>
446
							<td><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_left_d.gif" width="17" height="17" title="<?=gettext("move selected rules before this rule");?>" alt="move" /></td>
447
							<td><a href="interfaces.php?if=<?=htmlspecialchars($if)?>#rfc1918"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" title="<?=gettext("edit rule");?>" width="17" height="17" border="0" alt=" edit" /></a></td>
448
						</tr>
449
						<tr>
450
							<td align="center" valign="middle"></td>
451
							<td><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus_d.gif" title="<?=gettext("add a new rule based on this one");?>" width="17" height="17" border="0" alt="add" /></td>
452
						</tr>
453
					</table>
454
				</td>
455
			</tr>
456
<?php endif; ?>
457
			<tbody>
458
<?php
459
	$nrules = 0;
460
	for ($i = 0; isset($a_filter[$i]); $i++):
461
		pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/row_start");
462
		$filterent = $a_filter[$i];
463
		if ($filterent['interface'] != $if && !isset($filterent['floating'])) {
464
			continue;
465
		}
466
		if (isset($filterent['floating']) && "FloatingRules" != $if) {
467
			continue;
468
		}
469
		$isadvset = firewall_check_for_advanced_options($filterent);
470
		if ($isadvset) {
471
			$advanced_set = "<img src=\"./themes/{$g['theme']}/images/icons/icon_advanced.gif\" title=\"" . gettext("advanced settings set") . ": {$isadvset}\" border=\"0\" alt=\"advanced\" />";
472
		} else {
473
			$advanced_set = "";
474
		}
475
?>
476
			<tr valign="top" id="fr<?=$nrules;?>">
477
				<td class="listt">
478
					<input type="checkbox" id="frc<?=$nrules;?>" name="rule[]" value="<?=$i;?>" onclick="fr_bgcolor('<?=$nrules;?>')" style="margin: 0; padding: 0; width: 15px; height: 15px;" />
479
					<?php echo $advanced_set; ?>
480
				</td>
481
				<td class="listt" align="center">
482
				<?php
483
					if ($filterent['type'] == "block") {
484
						$iconfn = "block";
485
					} else if ($filterent['type'] == "reject") {
486
						$iconfn = "reject";
487
					} else if ($filterent['type'] == "match") {
488
						$iconfn = "match";
489
					} else {
490
						$iconfn = "pass";
491
					}
492
					if (isset($filterent['disabled'])) {
493
						$textss = "<span class=\"gray\">";
494
						$textse = "</span>";
495
						$iconfn .= "_d";
496
					} else {
497
						$textss = $textse = "";
498
					}
499
				?>
500
					<a href="?if=<?=htmlspecialchars($if);?>&amp;act=toggle&amp;id=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_<?=$iconfn;?>.gif" width="11" height="11" border="0" title="<?=gettext("click to toggle enabled/disabled status");?>" alt="icon" /></a>
501
<?php
502
	if (isset($filterent['log'])):
503
		$iconfnlog = "log_s";
504
		if (isset($filterent['disabled'])) {
505
			$iconfnlog .= "_d";
506
		}
507
?>
508
					<br /><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_<?=$iconfnlog;?>.gif" width="11" height="15" border="0" alt="icon" />
509
<?php endif; ?>
510
				</td>
511
			<?php
512

    
513
				//build Alias popup box
514
				$alias_src_span_begin = "";
515
				$alias_src_port_span_begin = "";
516
				$alias_dst_span_begin = "";
517
				$alias_dst_port_span_begin = "";
518

    
519
				$alias_popup = rule_popup($filterent['source']['address'], pprint_port($filterent['source']['port']), $filterent['destination']['address'], pprint_port($filterent['destination']['port']));
520

    
521
				$alias_src_span_begin = $alias_popup["src"];
522
				$alias_src_port_span_begin = $alias_popup["srcport"];
523
				$alias_dst_span_begin = $alias_popup["dst"];
524
				$alias_dst_port_span_begin = $alias_popup["dstport"];
525

    
526
				$alias_src_span_end = $alias_popup["src_end"];
527
				$alias_src_port_span_end = $alias_popup["srcport_end"];
528
				$alias_dst_span_end = $alias_popup["dst_end"];
529
				$alias_dst_port_span_end = $alias_popup["dstport_end"];
530

    
531
				//build Schedule popup box
532
				$a_schedules = &$config['schedules']['schedule'];
533
				$schedule_span_begin = "";
534
				$schedule_span_end = "";
535
				$sched_caption_escaped = "";
536
				$sched_content = "";
537
				$schedstatus = false;
538
				$dayArray = array (gettext('Mon'), gettext('Tues'), gettext('Wed'), gettext('Thur'), gettext('Fri'), gettext('Sat'), gettext('Sun'));
539
				$monthArray = array (gettext('January'), gettext('February'), gettext('March'), gettext('April'), gettext('May'), gettext('June'), gettext('July'), gettext('August'), gettext('September'), gettext('October'), gettext('November'), gettext('December'));
540
				if ($config['schedules']['schedule'] <> "" and is_array($config['schedules']['schedule'])) {
541
					foreach ($a_schedules as $schedule) {
542
						if ($schedule['name'] == $filterent['sched']) {
543
							$schedstatus = filter_get_time_based_rule_status($schedule);
544

    
545
							foreach ($schedule['timerange'] as $timerange) {
546
								$tempFriendlyTime = "";
547
								$tempID = "";
548
								$firstprint = false;
549
								if ($timerange) {
550
									$dayFriendly = "";
551
									$tempFriendlyTime = "";
552

    
553
									//get hours
554
									$temptimerange = $timerange['hour'];
555
									$temptimeseparator = strrpos($temptimerange, "-");
556

    
557
									$starttime = substr ($temptimerange, 0, $temptimeseparator);
558
									$stoptime = substr ($temptimerange, $temptimeseparator+1);
559

    
560
									if ($timerange['month']) {
561
										$tempmontharray = explode(",", $timerange['month']);
562
										$tempdayarray = explode(",", $timerange['day']);
563
										$arraycounter = 0;
564
										$firstDayFound = false;
565
										$firstPrint = false;
566
										foreach ($tempmontharray as $monthtmp) {
567
											$month = $tempmontharray[$arraycounter];
568
											$day = $tempdayarray[$arraycounter];
569

    
570
											if (!$firstDayFound) {
571
												$firstDay = $day;
572
												$firstmonth = $month;
573
												$firstDayFound = true;
574
											}
575

    
576
											$currentDay = $day;
577
											$nextDay = $tempdayarray[$arraycounter+1];
578
											$currentDay++;
579
											if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])) {
580
												if ($firstPrint) {
581
													$dayFriendly .= ", ";
582
												}
583
												$currentDay--;
584
												if ($currentDay != $firstDay) {
585
													$dayFriendly .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
586
												} else {
587
													$dayFriendly .= $monthArray[$month-1] . " " . $day;
588
												}
589
												$firstDayFound = false;
590
												$firstPrint = true;
591
											}
592
											$arraycounter++;
593
										}
594
									} else {
595
										$tempdayFriendly = $timerange['position'];
596
										$firstDayFound = false;
597
										$tempFriendlyDayArray = explode(",", $tempdayFriendly);
598
										$currentDay = "";
599
										$firstDay = "";
600
										$nextDay = "";
601
										$counter = 0;
602
										foreach ($tempFriendlyDayArray as $day) {
603
											if ($day != "") {
604
												if (!$firstDayFound) {
605
													$firstDay = $tempFriendlyDayArray[$counter];
606
													$firstDayFound = true;
607
												}
608
												$currentDay =$tempFriendlyDayArray[$counter];
609
												//get next day
610
												$nextDay = $tempFriendlyDayArray[$counter+1];
611
												$currentDay++;
612
												if ($currentDay != $nextDay) {
613
													if ($firstprint) {
614
														$dayFriendly .= ", ";
615
													}
616
													$currentDay--;
617
													if ($currentDay != $firstDay) {
618
														$dayFriendly .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
619
													} else {
620
														$dayFriendly .= $dayArray[$firstDay-1];
621
													}
622
													$firstDayFound = false;
623
													$firstprint = true;
624
												}
625
												$counter++;
626
											}
627
										}
628
									}
629
									$timeFriendly = $starttime . " - " . $stoptime;
630
									$description = $timerange['rangedescr'];
631
									$sched_content .= $dayFriendly . "; " . $timeFriendly . "<br />";
632
								}
633
							}
634
							$sched_caption_escaped = str_replace("'", "\'", $schedule['descr']);
635
							$schedule_span_begin = "<span style=\"cursor: help;\" onmouseover=\"domTT_activate(this, event, 'content', '<h1>{$sched_caption_escaped}</h1><p>{$sched_content}</p>', 'trail', true, 'delay', 0, 'fade', 'both', 'fadeMax', 93, 'styleClass', 'niceTitle');\" onmouseout=\"this.style.color = ''; domTT_mouseout(this, event);\"><u>";
636
							$schedule_span_end = "</u></span>";
637
						}
638
					}
639
				}
640
				$printicon = false;
641
				$alttext = "";
642
				$image = "";
643
				if (!isset($filterent['disabled'])) {
644
					if ($schedstatus) {
645
						if ($iconfn == "block" || $iconfn == "reject") {
646
							$image = "icon_block";
647
							$alttext = gettext("Traffic matching this rule is currently being denied");
648
						} else {
649
							$image = "icon_pass";
650
							$alttext = gettext("Traffic matching this rule is currently being allowed");
651
						}
652
						$printicon = true;
653
					} else if ($filterent['sched']) {
654
						if ($iconfn == "block" || $iconfn == "reject") {
655
							$image = "icon_block_d";
656
						} else {
657
							$image = "icon_block";
658
						}
659
						$alttext = gettext("This rule is not currently active because its period has expired");
660
						$printicon = true;
661
					}
662
				}
663
			?>
664
				<td class="listlr" onclick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
665
					<?=$textss;?><?php if (isset($filterent['id'])) echo $filterent['id']."&nbsp;"; else echo "&nbsp;"; ?><?=$textse;?>
666
				</td>
667
			<?php
668
				pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/pre_id_tr");
669
			?>
670
			<?php
671
				if ('FloatingRules' == $if) {
672
			?>
673
				<td class="listr" onclick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
674
					<?=$textss;?>
675
			<?php
676
					if (isset($filterent['interface'])) {
677
						$selected_interfaces = explode(',', $filterent['interface']);
678
						unset($selected_descs);
679
						foreach ($selected_interfaces as $interface) {
680
							if (isset($ifdescs[$interface])) {
681
								$selected_descs[] = $ifdescs[$interface];
682
							} else {
683
								switch ($interface) {
684
									case 'l2tp':
685
										if ($config['l2tp']['mode'] == 'server') {
686
											$selected_descs[] = 'L2TP VPN';
687
										}
688
										break;
689
									case 'pptp':
690
										if ($config['pptpd']['mode'] == 'server') {
691
											$selected_descs[] = 'PPTP VPN';
692
										}
693
										break;
694
									case 'pppoe':
695
										if (is_pppoe_server_enabled()) {
696
											$selected_descs[] = 'PPPoE Server';
697
										}
698
										break;
699
									case 'enc0':
700
										if (isset($config['ipsec']['enable']) || isset($config['ipsec']['client']['enable'])) {
701
											$selected_descs[] = 'IPsec';
702
										}
703
										break;
704
									case 'openvpn':
705
										if ($config['openvpn']['openvpn-server'] || $config['openvpn']['openvpn-client']) {
706
											$selected_descs[] = 'OpenVPN';
707
										}
708
										break;
709
									default:
710
										$selected_descs[] = $interface;
711
										break;
712
								}
713
							}
714
						}
715

    
716
						echo implode('<br/>', $selected_descs);
717
					}
718
			?>
719
					<?=$textse;?>
720
				</td>
721
			<?php
722
				}
723
			?>
724
				<td class="listr" onclick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
725
					<?=$textss;?>
726
			<?php
727
				if (isset($filterent['ipprotocol'])) {
728
					switch ($filterent['ipprotocol']) {
729
						case "inet":
730
							echo "IPv4 ";
731
							break;
732
						case "inet6":
733
							echo "IPv6 ";
734
							break;
735
						case "inet46":
736
							echo "IPv4+6 ";
737
							break;
738
					}
739
				} else {
740
					echo "IPv4 ";
741
				}
742
				if (isset($filterent['protocol'])) {
743
					echo strtoupper($filterent['protocol']);
744
					if (strtoupper($filterent['protocol']) == "ICMP" && !empty($filterent['icmptype'])) {
745
						echo ' <span style="cursor: help;" title="ICMP type: ' .
746
							($filterent['ipprotocol'] == "inet6" ? $icmp6types[$filterent['icmptype']] : $icmptypes[$filterent['icmptype']]) .
747
							'"><u>';
748
						echo $filterent['icmptype'];
749
						echo '</u></span>';
750
					}
751
				} else {
752
					echo "*";
753
				}
754
			?>
755
					<?=$textse;?>
756
				</td>
757
				<td class="listr" onclick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
758
					<?=$textss;?><?php echo $alias_src_span_begin;?><?php echo htmlspecialchars(pprint_address($filterent['source']));?><?php echo $alias_src_span_end;?><?=$textse;?>
759
				</td>
760
				<td class="listr" onclick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
761
					<?=$textss;?><?php echo $alias_src_port_span_begin;?><?php echo htmlspecialchars(pprint_port($filterent['source']['port'])); ?><?php echo $alias_src_port_span_end;?><?=$textse;?>
762
				</td>
763
				<td class="listr" onclick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
764
					<?=$textss;?><?php echo $alias_dst_span_begin;?><?php echo htmlspecialchars(pprint_address($filterent['destination'])); ?><?php echo $alias_dst_span_end;?><?=$textse;?>
765
				</td>
766
				<td class="listr" onclick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
767
					<?=$textss;?><?php echo $alias_dst_port_span_begin;?><?php echo htmlspecialchars(pprint_port($filterent['destination']['port'])); ?><?php echo $alias_dst_port_span_end;?><?=$textse;?>
768
				</td>
769
				<td class="listr" onclick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
770
					<?=$textss;?><?php if (isset($config['interfaces'][$filterent['gateway']]['descr'])) echo htmlspecialchars($config['interfaces'][$filterent['gateway']]['descr']); else echo htmlspecialchars(pprint_port($filterent['gateway'])); ?><?=$textse;?>
771
				</td>
772
				<td class="listr" onclick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
773
					<?=$textss;?>
774
			<?php
775
				if (isset($filterent['ackqueue']) && isset($filterent['defaultqueue'])) {
776
					$desc = $filterent['ackqueue'] ;
777
					echo "<a href=\"firewall_shaper_queues.php?queue={$filterent['ackqueue']}&amp;action=show\">{$desc}</a>";
778
					$desc = $filterent['defaultqueue'];
779
					echo "/<a href=\"firewall_shaper_queues.php?queue={$filterent['defaultqueue']}&amp;action=show\">{$desc}</a>";
780
				} else if (isset($filterent['defaultqueue'])) {
781
					$desc = $filterent['defaultqueue'];
782
					echo "<a href=\"firewall_shaper_queues.php?queue={$filterent['defaultqueue']}&amp;action=show\">{$desc}</a>";
783
				} else {
784
					echo gettext("none");
785
				}
786
			?>
787
					<?=$textse;?>
788
				</td>
789
				<td class="listr" onclick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
790
					<font color="black">
791
						<?php if ($printicon) { ?><img src="./themes/<?= $g['theme']; ?>/images/icons/<?php echo $image; ?>.gif" title="<?php echo $alttext;?>" border="0" alt="icon" /><?php } ?><?=$textss;?><?php echo $schedule_span_begin;?><?=htmlspecialchars($filterent['sched']);?>&nbsp;<?php echo $schedule_span_end; ?><?=$textse;?>
792
					</font>
793
				</td>
794
			<?php
795
				pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/pre_descr_tr");
796
			?>
797
				<td class="listbg descr" onclick="fr_toggle(<?=$nrules;?>)" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
798
					<?=$textss;?><?=htmlspecialchars($filterent['descr']);?>&nbsp;<?=$textse;?>
799
				</td>
800
				<td valign="middle" class="list nowrap">
801
					<table border="0" cellspacing="0" cellpadding="1" summary="move before">
802
						<tr>
803
							<td><input name="move_<?=$i;?>" type="image" src="./themes/<?= $g['theme']; ?>/images/icons/icon_left.gif" style="width:17;height:17" title="<?=gettext("move selected rules before this rule"); ?>" onmouseover="fr_insline(<?=$nrules;?>, true)" onmouseout="fr_insline(<?=$nrules;?>, false)" /></td>
804
							<td><a href="firewall_rules_edit.php?id=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" title="<?=gettext("edit rule"); ?>" width="17" height="17" border="0" alt="edit" /></a></td>
805
						</tr>
806
						<tr>
807
							<td align="center" valign="middle"><a href="firewall_rules.php?act=del&amp;if=<?=htmlspecialchars($if);?>&amp;id=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0" title="<?=gettext("delete rule"); ?>" onclick="return confirm('Do you really want to delete this rule?')" alt="delete" /></a></td>
808
							<td><a href="firewall_rules_edit.php?dup=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="<?=gettext("add a new rule based on this one"); ?>" width="17" height="17" border="0" alt="add" /></a></td>
809
						</tr>
810
					</table>
811
				</td>
812
			</tr>
813
			<?php $nrules++; endfor; ?>
814
			<tr><td></td></tr>
815
			</tbody>
816
<?php if ($nrules == 0): ?>
817
			<tr>
818
				<td class="listt"></td>
819
				<td class="listt"></td>
820
	<?php
821
		if ($_REQUEST['if'] == "FloatingRules") {
822
			$ncolumns = "11";
823
		} else {
824
			$ncolumns = "10";
825
		}
826
	?>
827
				<td class="listlr" colspan=<?=$ncolumns;?> align="center" valign="middle">
828
					<span class="gray">
829
	<?php if ($_REQUEST['if'] == "FloatingRules"): ?>
830
					<?=gettext("No floating rules are currently defined."); ?><br /><br />
831
	<?php else: ?>
832
					<?=gettext("No rules are currently defined for this interface"); ?><br />
833
					<?=gettext("All incoming connections on this interface will be blocked until you add pass rules."); ?><br /><br />
834
	<?php endif; ?>
835
					<?=gettext("Click the"); ?> <a href="firewall_rules_edit.php?if=<?=htmlspecialchars($if);?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="<?=gettext("add new rule");?>" border="0" width="17" height="17" align="middle" alt="add" /></a><?=gettext(" button to add a new rule.");?></span>
836
				</td>
837
			</tr>
838
<?php endif; ?>
839
			<tr id="fr<?=$nrules;?>">
840
				<td class="list"></td>
841
				<td class="list"></td>
842
			<?php
843
				pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/pre_id_tr_belowtable");
844
			?>
845
				<td class="list">&nbsp;</td>
846
				<td class="list">&nbsp;</td>
847
				<td class="list">&nbsp;</td>
848
				<td class="list">&nbsp;</td>
849
				<td class="list">&nbsp;</td>
850
				<td class="list">&nbsp;</td>
851
				<td class="list">&nbsp;</td>
852
				<td class="list">&nbsp;</td>
853
				<td class="list">&nbsp;</td>
854
				<td class="list">&nbsp;</td>
855
				<td class="list">
856
					<table border="0" cellspacing="0" cellpadding="1" summary="move rules">
857
						<tr>
858
							<td>
859
								<?php if ($nrules == 0): ?><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_left_d.gif" width="17" height="17" title="<?=gettext("move selected rules to end");?>" border="0" alt="move" /><?php else: ?><input name="move_<?=$i;?>" type="image" src="./themes/<?= $g['theme']; ?>/images/icons/icon_left.gif" style="width:17;height:17" title="<?=gettext("move selected rules to end");?>" onmouseover="fr_insline(<?=$nrules;?>, true)" onmouseout="fr_insline(<?=$nrules;?>, false)" /><?php endif; ?>
860
							</td>
861
							<td></td>
862
						</tr>
863
						<tr>
864
							<td>
865
<?php if ($nrules == 0): ?>
866
								<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x_d.gif" width="17" height="17" title="<?=gettext("delete selected rules");?>" border="0" alt="delete" /><?php else: ?>
867
								<input name="del" type="image" src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" style="width:17;height:17" title="<?=gettext("delete selected rules");?>" onclick="return confirm('<?=gettext('Do you really want to delete the selected rules?');?>')" />
868
<?php endif; ?>
869
							</td>
870
							<td>
871
								<a href="firewall_rules_edit.php?if=<?=htmlspecialchars($if);?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="<?=gettext("add new rule");?>" width="17" height="17" border="0" alt="add" /></a>
872
							</td>
873
						</tr>
874
					</table>
875
				</td>
876
			</tr>
877
		</table>
878
		<table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0" summary="icons">
879
			<tr>
880
				<td width="16"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_pass.gif" width="11" height="11" alt="pass" /></td>
881
				<td width="100"><?=gettext("pass");?></td>
882
				<td width="14"></td>
883
				<td width="16"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_match.gif" width="11" height="11" alt="match" /></td>
884
				<td width="100"><?=gettext("match");?></td>
885
				<td width="14"></td>
886
				<td width="16"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_block.gif" width="11" height="11" alt="block" /></td>
887
				<td width="100"><?=gettext("block");?></td>
888
				<td width="14"></td>
889
				<td width="16"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_reject.gif" width="11" height="11" alt="reject" /></td>
890
				<td width="100"><?=gettext("reject");?></td>
891
				<td width="14"></td>
892
				<td width="16"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_log.gif" width="11" height="11" alt="log" /></td>
893
				<td width="100"><?=gettext("log");?></td>
894
			</tr>
895
			<tr>
896
				<td><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_pass_d.gif" width="11" height="11" alt="pass disabled" /></td>
897
				<td class="nowrap"><?=gettext("pass (disabled)");?></td>
898
				<td>&nbsp;</td>
899
				<td><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_match_d.gif" width="11" height="11" alt="match disabled" /></td>
900
				<td class="nowrap"><?=gettext("match (disabled)");?></td>
901
				<td>&nbsp;</td>
902
				<td><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_block_d.gif" width="11" height="11" alt="block disabled" /></td>
903
				<td class="nowrap"><?=gettext("block (disabled)");?></td>
904
				<td>&nbsp;</td>
905
				<td><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_reject_d.gif" width="11" height="11" alt="reject disabled" /></td>
906
				<td class="nowrap"><?=gettext("reject (disabled)");?></td>
907
				<td>&nbsp;</td>
908
				<td width="16"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_log_d.gif" width="11" height="11" alt="log disabled" /></td>
909
				<td class="nowrap"><?=gettext("log (disabled)");?></td>
910
			</tr>
911
			<tr>
912
				<td colspan="10">
913
					<p>&nbsp;</p>
914
					<strong>
915
						<span class="red"><?=gettext("Hint:");?></span>
916
					</strong><br />
917
					<ul>
918
					<?php if ("FloatingRules" != $if): ?>
919
						<li><?=gettext("Rules are evaluated on a first-match basis (i.e. " .
920
						"the action of the first rule to match a packet will be executed). " .
921
						"This means that if you use block rules, you'll have to pay attention " .
922
						"to the rule order. Everything that isn't explicitly passed is blocked " .
923
						"by default. ");?>
924
						</li>
925
					<?php else: ?>
926
						<li><?=gettext("Floating rules are evaluated on a first-match basis (i.e. " .
927
						"the action of the first rule to match a packet will be executed) only " .
928
						"if the 'quick' option is checked on a rule. Otherwise they will only apply if no " .
929
						"other rules match. Pay close attention to the rule order and options " .
930
						"chosen. If no rule here matches, the per-interface or default rules are used. ");?>
931
						</li>
932
					<?php endif; ?>
933
					</ul>
934
				</td>
935
			</tr>
936
		</table>
937
		</div>
938
	</td></tr>
939
</table>
940
<input type="hidden" name="if" value="<?=htmlspecialchars($if);?>" />
941
</form>
942
<?php include("fend.inc"); ?>
943
</body>
944
</html>
(71-71/252)