Project

General

Profile

Download (32.4 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	firewall_rules.php
4
*/
5
/* ====================================================================
6
 *	Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
7
 *
8
 *	Some or all of this file is based on the m0n0wall project which is
9
 *	Copyright (c)  2004 Manuel Kasper (BSD 2 clause)
10
 *
11
 *	Redistribution and use in source and binary forms, with or without modification,
12
 *	are permitted provided that the following conditions are met:
13
 *
14
 *	1. Redistributions of source code must retain the above copyright notice,
15
 *		this list of conditions and the following disclaimer.
16
 *
17
 *	2. Redistributions in binary form must reproduce the above copyright
18
 *		notice, this list of conditions and the following disclaimer in
19
 *		the documentation and/or other materials provided with the
20
 *		distribution.
21
 *
22
 *	3. All advertising materials mentioning features or use of this software
23
 *		must display the following acknowledgment:
24
 *		"This product includes software developed by the pfSense Project
25
 *		 for use in the pfSense software distribution. (http://www.pfsense.org/).
26
 *
27
 *	4. The names "pfSense" and "pfSense Project" must not be used to
28
 *		 endorse or promote products derived from this software without
29
 *		 prior written permission. For written permission, please contact
30
 *		 coreteam@pfsense.org.
31
 *
32
 *	5. Products derived from this software may not be called "pfSense"
33
 *		nor may "pfSense" appear in their names without prior written
34
 *		permission of the Electric Sheep Fencing, LLC.
35
 *
36
 *	6. Redistributions of any form whatsoever must retain the following
37
 *		acknowledgment:
38
 *
39
 *	"This product includes software developed by the pfSense Project
40
 *	for use in the pfSense software distribution (http://www.pfsense.org/).
41
 *
42
 *	THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
43
 *	EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44
 *	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
45
 *	PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
46
 *	ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47
 *	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
48
 *	NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
49
 *	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50
 *	HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
51
 *	STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52
 *	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
53
 *	OF THE POSSIBILITY OF SUCH DAMAGE.
54
 *
55
 *	====================================================================
56
 *
57
 */
58

    
59
##|+PRIV
60
##|*IDENT=page-firewall-rules
61
##|*NAME=Firewall: Rules
62
##|*DESCR=Allow access to the 'Firewall: Rules' page.
63
##|*MATCH=firewall_rules.php*
64
##|-PRIV
65

    
66
require("guiconfig.inc");
67
require_once("functions.inc");
68
require_once("filter.inc");
69
require_once("ipsec.inc");
70
require_once("shaper.inc");
71

    
72
$pgtitle = array(gettext("Firewall"), gettext("Rules"));
73
$shortcut_section = "firewall";
74

    
75
function get_pf_rules($rules, $tracker) {
76

    
77
	if ($rules == NULL || !is_array($rules))
78
		return (NULL);
79

    
80
	$arr = array();
81
	foreach ($rules as $rule) {
82
		if ($rule['tracker'] === $tracker) {
83
			$arr[] = $rule;
84
		}
85
	}
86

    
87
	if (count($arr) == 0)
88
		return (NULL);
89

    
90
	return ($arr);
91
}
92

    
93
function print_states($tracker) {
94
	global $rulescnt;
95

    
96
	$rulesid = "";
97
	$bytes = 0;
98
	$states = 0;
99
	$packets = 0;
100
	$evaluations = 0;
101
	$stcreations = 0;
102
	$rules = get_pf_rules($rulescnt, $tracker);
103
	if (is_array($rules)) {
104
		foreach ($rules as $rule) {
105
			$bytes += $rule['bytes'];
106
			$states += $rule['states'];
107
			$packets += $rule['packets'];
108
			$evaluations += $rule['evaluations'];
109
			$stcreations += $rule['state creations'];
110
			if (strlen($rulesid) > 0) {
111
				$rulesid .= ",";
112
			}
113
			$rulesid .= "{$rule['id']}";
114
		}
115
	}
116

    
117
	printf("<a href=\"diag_dump_states.php?ruleid=%s\" data-toggle=\"popover\" data-trigger=\"hover focus\" title=\"%s\" ",
118
	    $rulesid, gettext("States details"));
119
	printf("data-content=\"evaluations: %s<br>packets: %s<br>bytes: %s<br>states: %s<br>state creations: %s\" data-html=\"true\">",
120
	    format_number($evaluations), format_number($packets), format_bytes($bytes),
121
	    format_number($states), format_number($stcreations));
122
	printf("%d/%s</a><br>", format_number($states), format_bytes($bytes));
123
}
124

    
125
function delete_nat_association($id) {
126
	global $config;
127

    
128
	if (!$id || !is_array($config['nat']['rule'])) {
129
		return;
130
	}
131

    
132
	$a_nat = &$config['nat']['rule'];
133

    
134
	foreach ($a_nat as &$natent) {
135
		if ($natent['associated-rule-id'] == $id) {
136
			$natent['associated-rule-id'] = '';
137
		}
138
	}
139
}
140

    
141
if (!is_array($config['filter']['rule'])) {
142
	$config['filter']['rule'] = array();
143
}
144

    
145
filter_rules_sort();
146
$a_filter = &$config['filter']['rule'];
147

    
148
$if = $_GET['if'];
149

    
150
if ($_POST['if']) {
151
	$if = $_POST['if'];
152
}
153

    
154
$ifdescs = get_configured_interface_with_descr();
155

    
156
/* add group interfaces */
157
if (is_array($config['ifgroups']['ifgroupentry'])) {
158
	foreach ($config['ifgroups']['ifgroupentry'] as $ifgen) {
159
		if (have_ruleint_access($ifgen['ifname'])) {
160
			$iflist[$ifgen['ifname']] = $ifgen['ifname'];
161
		}
162
	}
163
}
164

    
165
foreach ($ifdescs as $ifent => $ifdesc) {
166
	if (have_ruleint_access($ifent)) {
167
		$iflist[$ifent] = $ifdesc;
168
	}
169
}
170

    
171
if ($config['l2tp']['mode'] == "server") {
172
	if (have_ruleint_access("l2tp")) {
173
		$iflist['l2tp'] = gettext("L2TP VPN");
174
	}
175
}
176

    
177
if (is_array($config['pppoes']['pppoe'])) {
178
	foreach ($config['pppoes']['pppoe'] as $pppoes) {
179
		if (($pppoes['mode'] == 'server') && have_ruleint_access("pppoe")) {
180
			$iflist['pppoe'] = gettext("PPPoE Server");
181
		}
182
	}
183
}
184

    
185
/* add ipsec interfaces */
186
if (ipsec_enabled() && have_ruleint_access("enc0")) {
187
	$iflist["enc0"] = gettext("IPsec");
188
}
189

    
190
/* add openvpn/tun interfaces */
191
if ($config['openvpn']["openvpn-server"] || $config['openvpn']["openvpn-client"]) {
192
	$iflist["openvpn"] = gettext("OpenVPN");
193
}
194

    
195
if (!$if || !isset($iflist[$if])) {
196
	if ("any" == $if) {
197
		$if = "FloatingRules";
198
	} else if ("FloatingRules" != $if) {
199
		if (isset($iflist['wan'])) {
200
			$if = "wan";
201
		} else {
202
			$if = "FloatingRules";
203
		}
204
	}
205
}
206

    
207
if ($_POST) {
208
	$pconfig = $_POST;
209

    
210
	if ($_POST['apply']) {
211
		$retval = 0;
212
		$retval = filter_configure();
213

    
214
		clear_subsystem_dirty('filter');
215

    
216
		$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."),
217
									"<a href='status_filter_reload.php'>", "</a>");
218
	}
219
}
220

    
221
if ($_GET['act'] == "del") {
222
	if ($a_filter[$_GET['id']]) {
223
		if (!empty($a_filter[$_GET['id']]['associated-rule-id'])) {
224
			delete_nat_association($a_filter[$_GET['id']]['associated-rule-id']);
225
		}
226
		unset($a_filter[$_GET['id']]);
227

    
228
		// Update the separators
229
		$a_separators = &$config['filter']['separator'][strtolower($if)];
230
		$ridx = ifridx($if, $_GET['id']);	// get rule index within interface
231
		$mvnrows = -1;
232
		move_separators($a_separators, $ridx, $mvnrows);
233

    
234
		if (write_config()) {
235
			mark_subsystem_dirty('filter');
236
		}
237

    
238
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
239
		exit;
240
	}
241
}
242

    
243
// Handle save msg if defined
244
if ($_REQUEST['savemsg']) {
245
	$savemsg = htmlentities($_REQUEST['savemsg']);
246
}
247

    
248
if (isset($_POST['del_x'])) {
249
	/* delete selected rules */
250
	$deleted = false;
251

    
252
	if (is_array($_POST['rule']) && count($_POST['rule'])) {
253
		$a_separators = &$config['filter']['separator'][strtolower($if)];
254

    
255
		foreach ($_POST['rule'] as $rulei) {
256
			delete_nat_association($a_filter[$rulei]['associated-rule-id']);
257
			unset($a_filter[$rulei]);
258
			$deleted = true;
259

    
260
			// Update the separators
261
			$ridx = ifridx($if, $rulei);	// get rule index within interface
262
			$mvnrows = -1;
263
			move_separators($a_separators, $ridx, $mvnrows);
264
		}
265

    
266
		if ($deleted) {
267
			if (write_config()) {
268
				mark_subsystem_dirty('filter');
269
			}
270
		}
271

    
272
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
273
		exit;
274
	}
275
} else if ($_GET['act'] == "toggle") {
276
	if ($a_filter[$_GET['id']]) {
277
		if (isset($a_filter[$_GET['id']]['disabled'])) {
278
			unset($a_filter[$_GET['id']]['disabled']);
279
		} else {
280
			$a_filter[$_GET['id']]['disabled'] = true;
281
		}
282
		if (write_config()) {
283
			mark_subsystem_dirty('filter');
284
		}
285

    
286
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
287
		exit;
288
	}
289
} else if ($_POST['order-store']) {
290

    
291
	/* update rule order, POST[rule] is an array of ordered IDs */
292
	if (is_array($_POST['rule']) && !empty($_POST['rule'])) {
293
		$a_filter_new = array();
294

    
295
		// Include the rules of other interfaces listed in config before this (the selected) interface.
296
		foreach ($a_filter as $filteri_before => $filterent) {
297
			if (($filterent['interface'] == $if && !isset($filterent['floating'])) || (isset($filterent['floating']) && "FloatingRules" == $if)) {
298
				break;
299
			} else {
300
				$a_filter_new[] = $filterent;
301
			}
302
		}
303

    
304
		// Include the rules of this (the selected) interface.
305
		// If a rule is not in POST[rule], it has been deleted by the user
306
		foreach ($_POST['rule'] as $id) {
307
			$a_filter_new[] = $a_filter[$id];
308
		}
309

    
310
		// Include the rules of other interfaces listed in config after this (the selected) interface.
311
		foreach ($a_filter as $filteri_after => $filterent) {
312
			if ($filteri_before > $filteri_after) {
313
				continue;
314
			}
315
			if (($filterent['interface'] == $if && !isset($filterent['floating'])) || (isset($filterent['floating']) && "FloatingRules" == $if)) {
316
				continue;
317
			} else {
318
				$a_filter_new[] = $filterent;
319
			}
320
		}
321

    
322
		$a_filter = $a_filter_new;
323

    
324
		$config['filter']['separator'][strtolower($if)] = "";
325

    
326
		if ($_POST['separator']) {
327
			$idx = 0;
328
			foreach ($_POST['separator'] as $separator) {
329
				$config['filter']['separator'][strtolower($separator['if'])]['sep' . $idx++] = $separator;
330
			}
331
		}
332

    
333
		if (write_config()) {
334
			mark_subsystem_dirty('filter');
335
		}
336

    
337
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
338
		exit;
339
	}
340
}
341

    
342
$tab_array = array(array(gettext("Floating"), ("FloatingRules" == $if), "firewall_rules.php?if=FloatingRules"));
343

    
344
foreach ($iflist as $ifent => $ifname) {
345
	$tab_array[] = array($ifname, ($ifent == $if), "firewall_rules.php?if={$ifent}");
346
}
347

    
348
foreach ($tab_array as $dtab) {
349
	if ($dtab[1]) {
350
		$bctab = $dtab[0];
351
		break;
352
	}
353
}
354

    
355
$pgtitle = array(gettext("Firewall"), gettext("Rules"), $bctab);
356
$shortcut_section = "firewall";
357

    
358
include("head.inc");
359
$nrules = 0;
360

    
361
if ($savemsg) {
362
	print_info_box($savemsg, 'success');
363
}
364

    
365
if (is_subsystem_dirty('filter')) {
366
	print_apply_box(gettext("The firewall rule configuration has been changed.") . "<br />" . gettext("You must apply the changes in order for them to take effect."));
367
}
368

    
369
display_top_tabs($tab_array);
370

    
371
$showantilockout = false;
372
$showprivate = false;
373
$showblockbogons = false;
374

    
375
if (!isset($config['system']['webgui']['noantilockout']) &&
376
    (((count($config['interfaces']) > 1) && ($if == 'lan')) ||
377
    ((count($config['interfaces']) == 1) && ($if == 'wan')))) {
378
	$showantilockout = true;
379
}
380

    
381
if (isset($config['interfaces'][$if]['blockpriv'])) {
382
	$showprivate = true;
383
}
384

    
385
if (isset($config['interfaces'][$if]['blockbogons'])) {
386
	$showblockbogons = true;
387
}
388

    
389
/* Load the counter data of each pf rule. */
390
$rulescnt = pfSense_get_pf_rules();
391

    
392
// Update this if you add or remove columns!
393
$columns_in_table = 13;
394

    
395
?>
396
<form method="post">
397
	<div class="panel panel-default">
398
		<div class="panel-heading"><h2 class="panel-title"><?=gettext("Rules (Drag to Change Order)")?></h2></div>
399
		<div id="mainarea" class="table-responsive panel-body">
400
			<table id="ruletable" class="table table-hover table-striped table-condensed">
401
				<thead>
402
					<tr>
403
						<th><!-- checkbox --></th>
404
						<th><!-- status icons --></th>
405
						<th><?=gettext("States")?></th>
406
						<th><?=gettext("Protocol")?></th>
407
						<th><?=gettext("Source")?></th>
408
						<th><?=gettext("Port")?></th>
409
						<th><?=gettext("Destination")?></th>
410
						<th><?=gettext("Port")?></th>
411
						<th><?=gettext("Gateway")?></th>
412
						<th><?=gettext("Queue")?></th>
413
						<th><?=gettext("Schedule")?></th>
414
						<th><?=gettext("Description")?></th>
415
						<th><?=gettext("Actions")?></th>
416
					</tr>
417
				</thead>
418

    
419
<?php if ($showblockbogons || $showantilockout || $showprivate) :
420
?>
421
				<tbody>
422
<?php
423
		// 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.
424
		if ($showantilockout):
425
			$alports = implode('<br />', filter_get_antilockout_ports(true));
426
?>
427
					<tr id="antilockout">
428
						<td></td>
429
						<td title="<?=gettext("traffic is passed")?>"><i class="fa fa-check text-success"></i></td>
430
						<td><?php print_states(intval(ANTILOCKOUT_TRACKER)); ?></td>
431
						<td>*</td>
432
						<td>*</td>
433
						<td>*</td>
434
						<td><?=$iflist[$if];?> Address</td>
435
						<td><?=$alports?></td>
436
						<td>*</td>
437
						<td>*</td>
438
						<td></td>
439
						<td><?=gettext("Anti-Lockout Rule");?></td>
440
						<td>
441
							<a href="system_advanced_admin.php" title="<?=gettext("Settings");?>"><i class="fa fa-cog"></i></a>
442
						</td>
443
					</tr>
444
<?php 	endif;?>
445
<?php 	if ($showprivate): ?>
446
					<tr id="private">
447
						<td></td>
448
						<td title="<?=gettext("traffic is blocked")?>"><i class="fa fa-times text-danger"></i></td>
449
						<td><?php print_states(intval(RFC1918_TRACKER)); ?></td>
450
						<td>*</td>
451
						<td><?=gettext("RFC 1918 networks");?></td>
452
						<td>*</td>
453
						<td>*</td>
454
						<td>*</td>
455
						<td>*</td>
456
						<td>*</td>
457
						<td></td>
458
						<td><?=gettext("Block private networks");?></td>
459
						<td>
460
							<a href="interfaces.php?if=<?=htmlspecialchars($if)?>" title="<?=gettext("Settings");?>"><i class="fa fa-cog"></i></a>
461
						</td>
462
					</tr>
463
<?php 	endif;?>
464
<?php 	if ($showblockbogons): ?>
465
					<tr id="bogons">
466
						<td></td>
467
						<td title="<?=gettext("traffic is blocked")?>"><i class="fa fa-times text-danger"></i></td>
468
						<td><?php print_states(intval(BOGONS_TRACKER)); ?></td>
469
						<td>*</td>
470
						<td><?=sprintf(gettext("Reserved%sNot assigned by IANA"), "<br />");?></td>
471
						<td>*</td>
472
						<td>*</td>
473
						<td>*</td>
474
						<td>*</td>
475
						<td>*</td>
476
						<td></td>
477
						<td><?=gettext("Block bogon networks");?></td>
478
						<td>
479
							<a href="interfaces.php?if=<?=htmlspecialchars($if)?>" title="<?=gettext("Settings");?>"><i class="fa fa-cog"></i></a>
480
						</td>
481
					</tr>
482
<?php 	endif;?>
483
			</tbody>
484
<?php endif;?>
485
			<tbody class="user-entries">
486
<?php
487
$nrules = 0;
488
$separators = $config['filter']['separator'][strtolower($if)];
489

    
490
// Get a list of separator rows and use it to call the display separator function only for rows which there are separator(s).
491
// More efficient than looping through the list of separators on every row.
492
$seprows = separator_rows($separators);
493

    
494
foreach ($a_filter as $filteri => $filterent):
495

    
496
	if (($filterent['interface'] == $if && !isset($filterent['floating'])) || (isset($filterent['floating']) && "FloatingRules" == $if)) {
497

    
498
		// Display separator(s) for section beginning at rule n
499
		if ($seprows[$nrules]) {
500
			display_separator($separators, $nrules, $columns_in_table);
501
		}
502
?>
503
					<tr id="fr<?=$nrules;?>" onClick="fr_toggle(<?=$nrules;?>)" ondblclick="document.location='firewall_rules_edit.php?id=<?=$filteri;?>';" <?=(isset($filterent['disabled']) ? ' class="disabled"' : '')?>>
504
						<td>
505
							<input type="checkbox" id="frc<?=$nrules;?>" onClick="fr_toggle(<?=$nrules;?>)" name="rule[]" value="<?=$filteri;?>"/>
506
						</td>
507

    
508
	<?php
509
		if ($filterent['type'] == "block") {
510
			$iconfn = "times text-danger";
511
			$title_text = gettext("traffic is blocked");
512
		} else if ($filterent['type'] == "reject") {
513
			$iconfn = "hand-stop-o text-warning";
514
			$title_text = gettext("traffic is rejected");
515
		} else if ($filterent['type'] == "match") {
516
			$iconfn = "filter";
517
			$title_text = gettext("traffic is matched");
518
		} else {
519
			$iconfn = "check text-success";
520
			$title_text = gettext("traffic is passed");
521
		}
522
	?>
523
						<td title="<?=$title_text?>">
524
							<a href="?if=<?=htmlspecialchars($if);?>&amp;act=toggle&amp;id=<?=$filteri;?>">
525
								<i class="fa fa-<?=$iconfn?>" title="<?=gettext("click to toggle enabled/disabled status");?>"></i>
526
							</a>
527
	<?php
528
		if ($filterent['quick'] == 'yes') {
529
			print '<i class="fa fa-forward text-success" title="'. gettext("&quot;Quick&quot; rule. Applied immediately on match.") .'" style="cursor: pointer;"></i>';
530
		}
531

    
532
		$isadvset = firewall_check_for_advanced_options($filterent);
533
		if ($isadvset) {
534
			print '<i class="fa fa-cog" title="'. gettext("advanced setting") .': '. $isadvset .'"></i>';
535
		}
536

    
537
		if (isset($filterent['log'])) {
538
			print '<i class="fa fa-tasks" title="'. gettext("traffic is logged") .'" style="cursor: pointer;"></i>';
539
		}
540
	?>
541
						</td>
542
	<?php
543
		$alias = rule_columns_with_alias(
544
			$filterent['source']['address'],
545
			pprint_port($filterent['source']['port']),
546
			$filterent['destination']['address'],
547
			pprint_port($filterent['destination']['port'])
548
		);
549

    
550
		//build Schedule popup box
551
		$a_schedules = &$config['schedules']['schedule'];
552
		$schedule_span_begin = "";
553
		$schedule_span_end = "";
554
		$sched_caption_escaped = "";
555
		$sched_content = "";
556
		$schedstatus = false;
557
		$dayArray = array (gettext('Mon'), gettext('Tues'), gettext('Wed'), gettext('Thur'), gettext('Fri'), gettext('Sat'), gettext('Sun'));
558
		$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'));
559
		if ($config['schedules']['schedule'] != "" && is_array($config['schedules']['schedule'])) {
560
			$idx = 0;
561
			foreach ($a_schedules as $schedule) {
562
				if ($schedule['name'] == $filterent['sched']) {
563
					$schedstatus = filter_get_time_based_rule_status($schedule);
564

    
565
					foreach ($schedule['timerange'] as $timerange) {
566
						$tempFriendlyTime = "";
567
						$tempID = "";
568
						$firstprint = false;
569
						if ($timerange) {
570
							$dayFriendly = "";
571
							$tempFriendlyTime = "";
572

    
573
							//get hours
574
							$temptimerange = $timerange['hour'];
575
							$temptimeseparator = strrpos($temptimerange, "-");
576

    
577
							$starttime = substr ($temptimerange, 0, $temptimeseparator);
578
							$stoptime = substr ($temptimerange, $temptimeseparator+1);
579

    
580
							if ($timerange['month']) {
581
								$tempmontharray = explode(",", $timerange['month']);
582
								$tempdayarray = explode(",", $timerange['day']);
583
								$arraycounter = 0;
584
								$firstDayFound = false;
585
								$firstPrint = false;
586
								foreach ($tempmontharray as $monthtmp) {
587
									$month = $tempmontharray[$arraycounter];
588
									$day = $tempdayarray[$arraycounter];
589

    
590
									if (!$firstDayFound) {
591
										$firstDay = $day;
592
										$firstmonth = $month;
593
										$firstDayFound = true;
594
									}
595

    
596
									$currentDay = $day;
597
									$nextDay = $tempdayarray[$arraycounter+1];
598
									$currentDay++;
599
									if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])) {
600
										if ($firstPrint) {
601
											$dayFriendly .= ", ";
602
										}
603
										$currentDay--;
604
										if ($currentDay != $firstDay) {
605
											$dayFriendly .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
606
										} else {
607
											$dayFriendly .=	 $monthArray[$month-1] . " " . $day;
608
										}
609
										$firstDayFound = false;
610
										$firstPrint = true;
611
									}
612
									$arraycounter++;
613
								}
614
							} else {
615
								$tempdayFriendly = $timerange['position'];
616
								$firstDayFound = false;
617
								$tempFriendlyDayArray = explode(",", $tempdayFriendly);
618
								$currentDay = "";
619
								$firstDay = "";
620
								$nextDay = "";
621
								$counter = 0;
622
								foreach ($tempFriendlyDayArray as $day) {
623
									if ($day != "") {
624
										if (!$firstDayFound) {
625
											$firstDay = $tempFriendlyDayArray[$counter];
626
											$firstDayFound = true;
627
										}
628
										$currentDay =$tempFriendlyDayArray[$counter];
629
										//get next day
630
										$nextDay = $tempFriendlyDayArray[$counter+1];
631
										$currentDay++;
632
										if ($currentDay != $nextDay) {
633
											if ($firstprint) {
634
												$dayFriendly .= ", ";
635
											}
636
											$currentDay--;
637
											if ($currentDay != $firstDay) {
638
												$dayFriendly .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
639
											} else {
640
												$dayFriendly .= $dayArray[$firstDay-1];
641
											}
642
											$firstDayFound = false;
643
											$firstprint = true;
644
										}
645
										$counter++;
646
									}
647
								}
648
							}
649
							$timeFriendly = $starttime . " - " . $stoptime;
650
							$description = $timerange['rangedescr'];
651
							$sched_content .= $dayFriendly . "; " . $timeFriendly . "<br />";
652
						}
653
					}
654
					#FIXME
655
					$sched_caption_escaped = str_replace("'", "\'", $schedule['descr']);
656
					$schedule_span_begin = '<a href="/firewall_schedule_edit.php?id=' . $idx . '" data-toggle="popover" data-trigger="hover focus" title="' . $schedule['name'] . '" data-content="' .
657
						$sched_caption_escaped . '" data-html="true">';
658
					$schedule_span_end = "</a>";
659
				}
660
			}
661
			$idx++;
662
		}
663
		$printicon = false;
664
		$alttext = "";
665
		$image = "";
666
		if (!isset($filterent['disabled'])) {
667
			if ($schedstatus) {
668
				if ($filterent['type'] == "block" || $filterent['type'] == "reject") {
669
					$image = "times-circle";
670
					$dispcolor = "text-danger";
671
					$alttext = gettext("Traffic matching this rule is currently being denied");
672
				} else {
673
					$image = "play-circle";
674
					$dispcolor = "text-success";
675
					$alttext = gettext("Traffic matching this rule is currently being allowed");
676
				}
677
				$printicon = true;
678
			} else if ($filterent['sched']) {
679
				if ($filterent['type'] == "block" || $filterent['type'] == "reject") {
680
					$image = "times-circle";
681
				} else {
682
					$image = "play-circle";
683
				}
684
				$alttext = gettext("This rule is not currently active because its period has expired");
685
				$dispcolor = "text-warning";
686
				$printicon = true;
687
			}
688
		}
689
	?>
690
				<td><?php print_states(intval($filterent['tracker'])); ?></td>
691
				<td>
692
	<?php
693
		if (isset($filterent['ipprotocol'])) {
694
			switch ($filterent['ipprotocol']) {
695
				case "inet":
696
					echo "IPv4 ";
697
					break;
698
				case "inet6":
699
					echo "IPv6 ";
700
					break;
701
				case "inet46":
702
					echo "IPv4+6 ";
703
					break;
704
			}
705
		} else {
706
			echo "IPv4 ";
707
		}
708

    
709
		if (isset($filterent['protocol'])) {
710
			echo strtoupper($filterent['protocol']);
711

    
712
			if (strtoupper($filterent['protocol']) == "ICMP" && !empty($filterent['icmptype'])) {
713
				echo ' <span style="cursor: help;" title="' . gettext('ICMP type') . ': ' .
714
					($filterent['ipprotocol'] == "inet6" ? $icmp6types[$filterent['icmptype']] : $icmptypes[$filterent['icmptype']]) .
715
					'"><u>';
716
				echo $filterent['icmptype'];
717
				echo '</u></span>';
718
			}
719
		} else echo "*";
720

    
721
	?>
722
						</td>
723
						<td>
724
							<?php if (isset($alias['src'])): ?>
725
								<a href="/firewall_aliases_edit.php?id=<?=$alias['src']?>" data-toggle="popover" data-trigger="hover focus" title="<?=gettext('Alias details')?>" data-content="<?=alias_info_popup($alias['src'])?>" data-html="true">
726
									<?=htmlspecialchars(pprint_address($filterent['source']))?>
727
								</a>
728
							<?php else: ?>
729
								<?=htmlspecialchars(pprint_address($filterent['source']))?>
730
							<?php endif; ?>
731
						</td>
732
						<td>
733
							<?php if (isset($alias['srcport'])): ?>
734
								<a href="/firewall_aliases_edit.php?id=<?=$alias['srcport']?>" data-toggle="popover" data-trigger="hover focus" title="<?=gettext('Alias details')?>" data-content="<?=alias_info_popup($alias['srcport'])?>" data-html="true">
735
									<?=htmlspecialchars(pprint_port($filterent['source']['port']))?>
736
								</a>
737
							<?php else: ?>
738
								<?=htmlspecialchars(pprint_port($filterent['source']['port']))?>
739
							<?php endif; ?>
740
						</td>
741
						<td>
742
							<?php if (isset($alias['dst'])): ?>
743
								<a href="/firewall_aliases_edit.php?id=<?=$alias['dst']?>" data-toggle="popover" data-trigger="hover focus" title="<?=gettext('Alias details')?>" data-content="<?=alias_info_popup($alias['dst'])?>" data-html="true">
744
									<?=htmlspecialchars(pprint_address($filterent['destination']))?>
745
								</a>
746
							<?php else: ?>
747
								<?=htmlspecialchars(pprint_address($filterent['destination']))?>
748
							<?php endif; ?>
749
						</td>
750
						<td>
751
							<?php if (isset($alias['dstport'])): ?>
752
								<a href="/firewall_aliases_edit.php?id=<?=$alias['dstport']?>" data-toggle="popover" data-trigger="hover focus" title="<?=gettext('Alias details')?>" data-content="<?=alias_info_popup($alias['dstport'])?>" data-html="true">
753
									<?=htmlspecialchars(pprint_port($filterent['destination']['port']))?>
754
								</a>
755
							<?php else: ?>
756
								<?=htmlspecialchars(pprint_port($filterent['destination']['port']))?>
757
							<?php endif; ?>
758
						</td>
759
						<td>
760
							<?php if (isset($config['interfaces'][$filterent['gateway']]['descr'])):?>
761
								<?=htmlspecialchars($config['interfaces'][$filterent['gateway']]['descr'])?>
762
							<?php else: ?>
763
								<?=htmlspecialchars(pprint_port($filterent['gateway']))?>
764
							<?php endif; ?>
765
						</td>
766
						<td>
767
							<?php
768
								if (isset($filterent['ackqueue']) && isset($filterent['defaultqueue'])) {
769
									$desc = $filterent['ackqueue'] ;
770
									echo "<a href=\"firewall_shaper_queues.php?queue={$filterent['ackqueue']}&amp;action=show\">{$desc}</a>";
771
									$desc = $filterent['defaultqueue'];
772
									echo "/<a href=\"firewall_shaper_queues.php?queue={$filterent['defaultqueue']}&amp;action=show\">{$desc}</a>";
773
								} else if (isset($filterent['defaultqueue'])) {
774
									$desc = $filterent['defaultqueue'];
775
									echo "<a href=\"firewall_shaper_queues.php?queue={$filterent['defaultqueue']}&amp;action=show\">{$desc}</a>";
776
								} else {
777
									echo gettext("none");
778
								}
779
							?>
780
						</td>
781
						<td>
782
							<?php if ($printicon) { ?>
783
								<i class="fa fa-<?=$image?> <?=$dispcolor?>" title="<?=$alttext;?>"></i>
784
							<?php } ?>
785
							<?=$schedule_span_begin;?><?=htmlspecialchars($filterent['sched']);?>&nbsp;<?=$schedule_span_end;?>
786
						</td>
787
						<td>
788
							<?=htmlspecialchars($filterent['descr']);?>
789
						</td>
790
						<td class="action-icons">
791
						<!-- <?=(isset($filterent['disabled']) ? 'enable' : 'disable')?> -->
792
							<a	class="fa fa-anchor icon-pointer" id="Xmove_<?=$filteri?>" title="<?=gettext("Move checked rules above this one")?>"></a>
793
							<a href="firewall_rules_edit.php?id=<?=$filteri;?>" class="fa fa-pencil" title="<?=gettext('Edit')?>"></a>
794
							<a href="firewall_rules_edit.php?dup=<?=$filteri;?>" class="fa fa-clone" title="<?=gettext('Copy')?>"></a>
795
<?php if (isset($filterent['disabled'])) {
796
?>
797
							<a href="?act=toggle&amp;if=<?=htmlspecialchars($if);?>&amp;id=<?=$filteri;?>" class="fa fa-check-square-o" title="<?=gettext('Enable')?>"></a>
798
<?php } else {
799
?>
800
							<a href="?act=toggle&amp;if=<?=htmlspecialchars($if);?>&amp;id=<?=$filteri;?>" class="fa fa-ban" title="<?=gettext('Disable')?>"></a>
801
<?php }
802
?>
803
							<a href="?act=del&amp;if=<?=htmlspecialchars($if);?>&amp;id=<?=$filteri;?>" class="fa fa-trash" title="<?=gettext('Delete this rule')?>"></a>
804
						</td>
805
					</tr>
806
<?php
807
		$nrules++;
808
	}
809
endforeach;
810

    
811
// There can be separator(s) after the last rule listed.
812
if ($seprows[$nrules]) {
813
	display_separator($separators, $nrules, $columns_in_table);
814
}
815
?>
816
				</tbody>
817
			</table>
818
		</div>
819
	</div>
820

    
821
<?php if ($nrules == 0): ?>
822
	<div class="alert alert-warning" role="alert">
823
		<p>
824
		<?php if ($_REQUEST['if'] == "FloatingRules"): ?>
825
			<?=gettext("No floating rules are currently defined.");?>
826
		<?php else: ?>
827
			<?=gettext("No rules are currently defined for this interface");?><br />
828
			<?=gettext("All incoming connections on this interface will be blocked until you add pass rules.");?>
829
		<?php endif;?>
830
			<?=gettext("Click the button to add a new rule.");?>
831
		</p>
832
	</div>
833
<?php endif;?>
834

    
835
	<nav class="action-buttons">
836
		<a href="firewall_rules_edit.php?if=<?=htmlspecialchars($if);?>&amp;after=-1" role="button" class="btn btn-sm btn-success" title="<?=gettext('Add rule to the top of the list')?>">
837
			<i class="fa fa-level-up icon-embed-btn"></i>
838
			<?=gettext("Add");?>
839
		</a>
840
		<a href="firewall_rules_edit.php?if=<?=htmlspecialchars($if);?>" role="button" class="btn btn-sm btn-success" title="<?=gettext('Add rule to the end of the list')?>">
841
			<i class="fa fa-level-down icon-embed-btn"></i>
842
			<?=gettext("Add");?>
843
		</a>
844
		<button name="del_x" type="submit" class="btn btn-danger btn-sm" value="<?=gettext("Delete selected rules"); ?>" title="<?=gettext('Delete selected rules')?>">
845
			<i class="fa fa-trash icon-embed-btn"></i>
846
			<?=gettext("Delete"); ?>
847
		</button>
848
		<button type="submit" id="order-store" name="order-store" class="btn btn-sm btn-primary" value="store changes" disabled title="<?=gettext('Save rule order')?>">
849
			<i class="fa fa-save icon-embed-btn"></i>
850
			<?=gettext("Save")?>
851
		</button>
852
		<button type="submit" id="addsep" name="addsep" class="btn btn-sm btn-warning" title="<?=gettext('Add separator')?>">
853
			<i class="fa fa-plus icon-embed-btn"></i>
854
			<?=gettext("Separator")?>
855
		</button>
856
	</nav>
857
</form>
858

    
859
<div class="infoblock">
860
	<div class="alert alert-info clearfix" role="alert"><div class="pull-left">
861
		<dl class="dl-horizontal responsive">
862
		<!-- Legend -->
863
			<dt><?=gettext('Legend')?></dt>				<dd></dd>
864
			<dt><i class="fa fa-check text-success"></i></dt>		<dd><?=gettext("Pass");?></dd>
865
			<dt><i class="fa fa-filter"></i></dt>	<dd><?=gettext("Match");?></dd>
866
			<dt><i class="fa fa-times text-danger"></i></dt>	<dd><?=gettext("Block");?></dd>
867
			<dt><i class="fa fa-hand-stop-o text-warning"></i></dt>		<dd><?=gettext("Reject");?></dd>
868
			<dt><i class="fa fa-tasks"></i></dt>	<dd> <?=gettext("Log");?></dd>
869
			<dt><i class="fa fa-cog"></i></dt>		<dd> <?=gettext("Advanced filter");?></dd>
870
			<dt><i class="fa fa-forward text-success"></i></dt><dd> <?=gettext("&quot;Quick&quot; rule. Applied immediately on match.")?></dd>
871
		</dl>
872

    
873
<?php
874
	if ("FloatingRules" != $if) {
875
		print(gettext("Rules are evaluated on a first-match basis (i.e. " .
876
			"the action of the first rule to match a packet will be executed). ") . '<br />' .
877
			gettext("This means that if you use block rules, you'll have to pay attention " .
878
			"to the rule order. Everything that isn't explicitly passed is blocked " .
879
			"by default. "));
880
	} else {
881
		print(gettext("Floating rules are evaluated on a first-match basis (i.e. " .
882
			"the action of the first rule to match a packet will be executed) only " .
883
			"if the 'quick' option is checked on a rule. Otherwise they will only match if no " .
884
			"other rules match. Pay close attention to the rule order and options " .
885
			"chosen. If no rule here matches, the per-interface or default rules are used. "));
886
	}
887
?>
888
	</div>
889
	</div>
890
</div>
891

    
892
<script type="text/javascript">
893
//<![CDATA[
894

    
895
//Need to create some variables here so that jquery/pfSenseHelpers.js can read them
896
iface = "<?=strtolower($if)?>";
897
cncltxt = '<?=gettext("Cancel")?>';
898
svtxt = '<?=gettext("Save")?>';
899
svbtnplaceholder = '<?=gettext("Enter a description, Save, then drag to final location.")?>';
900
configsection = "filter";
901

    
902
events.push(function() {
903

    
904
	// "Move to here" (anchor) action
905
	$('[id^=Xmove_]').click(function (event) {
906

    
907
		// Prevent click from toggling row
908
		event.stopImmediatePropagation();
909

    
910
		// Save the target rule position
911
		var anchor_row = $(this).parents("tr:first");
912

    
913
		$('#ruletable > tbody  > tr').each(function() {
914
			ruleid = this.id.slice(2);
915

    
916
			if (ruleid && !isNaN(ruleid)) {
917
				if ($('#frc' + ruleid).prop('checked')) {
918
					// Move the selected rows, un-select them and add highlight class
919
					$(this).insertBefore(anchor_row);
920
					fr_toggle(ruleid, "fr");
921
					$('#fr' + ruleid).addClass("highlight");
922
				}
923
			}
924
		});
925

    
926
		// Temporarily set background color so user can more easily see the moved rules, then fade
927
		$('.highlight').effect("highlight", {color: "#739b4b;"}, 4000);
928
		$('#ruletable tr').removeClass("highlight");
929
		$('#order-store').removeAttr('disabled');
930
		reindex_rules($(anchor_row).parent('tbody'));
931
		dirty = true;
932

    
933
	});
934

    
935
	// Make rules sortable. Hiding the table before applying sortable, then showing it again is
936
	// a work-around for very slow sorting on FireFox
937
	$('table tbody.user-entries').hide();
938

    
939
	$('table tbody.user-entries').sortable({
940
		cursor: 'grabbing',
941
		update: function(event, ui) {
942
			$('#order-store').removeAttr('disabled');
943
			reindex_rules(ui.item.parent('tbody'));
944
			dirty = true;
945
		}
946
	});
947

    
948
	$('table tbody.user-entries').show();
949

    
950
	// Check all of the rule checkboxes so that their values are posted
951
	$('#order-store').click(function () {
952
		$('[id^=frc]').prop('checked', true);
953

    
954
		// Save the separator bar configuration
955
		save_separators();
956

    
957
		// Suppress the "Do you really want to leave the page" message
958
		saving = true;
959
	});
960

    
961
	// Provide a warning message if the user tries to change page before saving
962
	$(window).bind('beforeunload', function(){
963
		if ((!saving && dirty) || newSeperator) {
964
			return ("<?=gettext('You have moved one or more rules but have not yet saved')?>");
965
		} else {
966
			return undefined;
967
		}
968
	});
969
});
970
//]]>
971
</script>
972

    
973
<?php include("foot.inc");?>
(49-49/225)