Project

General

Profile

Download (36.3 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * firewall_rules.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8
 * Copyright (c) 2014-2021 Rubicon Communications, LLC (Netgate)
9
 * All rights reserved.
10
 *
11
 * originally based on m0n0wall (http://m0n0.ch/wall)
12
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
13
 * All rights reserved.
14
 *
15
 * Licensed under the Apache License, Version 2.0 (the "License");
16
 * you may not use this file except in compliance with the License.
17
 * You may obtain a copy of the License at
18
 *
19
 * http://www.apache.org/licenses/LICENSE-2.0
20
 *
21
 * Unless required by applicable law or agreed to in writing, software
22
 * distributed under the License is distributed on an "AS IS" BASIS,
23
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
 * See the License for the specific language governing permissions and
25
 * limitations under the License.
26
 */
27

    
28
##|+PRIV
29
##|*IDENT=page-firewall-rules
30
##|*NAME=Firewall: Rules
31
##|*DESCR=Allow access to the 'Firewall: Rules' page.
32
##|*MATCH=firewall_rules.php*
33
##|-PRIV
34

    
35
require_once("guiconfig.inc");
36
require_once("functions.inc");
37
require_once("filter.inc");
38
require_once("ipsec.inc");
39
require_once("shaper.inc");
40

    
41
$XmoveTitle = gettext("Move checked rules above this one. Shift+Click to move checked rules below.");
42
$ShXmoveTitle = gettext("Move checked rules below this one. Release shift to move checked rules above.");
43

    
44
$shortcut_section = "firewall";
45

    
46
function get_pf_rules($rules, $tracker_start, $tracker_end) {
47

    
48
	if ($rules == NULL || !is_array($rules)) {
49
		return (NULL);
50
	}
51

    
52
	$arr = array();
53
	foreach ($rules as $rule) {
54
		if ($rule['tracker'] >= $tracker_start &&
55
		    $rule['tracker'] <= $tracker_end) {
56
			$arr[] = $rule;
57
		}
58
	}
59

    
60
	if (count($arr) == 0)
61
		return (NULL);
62

    
63
	return ($arr);
64
}
65

    
66
function print_states($tracker_start, $tracker_end = -1) {
67
	global $rulescnt;
68

    
69
	if (empty($tracker_start)) {
70
		return;
71
	}
72

    
73
	if ($tracker_end === -1) {
74
		$tracker_end = $tracker_start;
75
	} elseif ($tracker_end < $tracker_start) {
76
		return;
77
	}
78

    
79
	$rulesid = "";
80
	$bytes = 0;
81
	$states = 0;
82
	$packets = 0;
83
	$evaluations = 0;
84
	$stcreations = 0;
85
	$rules = get_pf_rules($rulescnt, $tracker_start, $tracker_end);
86
	if (is_array($rules)) {
87
		foreach ($rules as $rule) {
88
			$bytes += $rule['bytes'];
89
			$states += $rule['states'];
90
			$packets += $rule['packets'];
91
			$evaluations += $rule['evaluations'];
92
			$stcreations += $rule['state creations'];
93
			if (strlen($rulesid) > 0) {
94
				$rulesid .= ",";
95
			}
96
			$rulesid .= "{$rule['id']}";
97
		}
98
	}
99

    
100
	$trackertext = "Tracking ID: {$tracker_start}";
101
	if ($tracker_end != $tracker_start) {
102
		$trackertext .= '-' . $tracker_end;
103
	}
104
	$trackertext .= "<br />";
105

    
106
	printf("<a href=\"diag_dump_states.php?ruleid=%s\" " .
107
	    "data-toggle=\"popover\" data-trigger=\"hover focus\" " .
108
	    "title=\"%s\" ", $rulesid, gettext("States details"));
109
	printf("data-content=\"{$trackertext}evaluations: %s<br />packets: " .
110
	    "%s<br />bytes: %s<br />states: %s<br />state creations: " .
111
	    "%s\" data-html=\"true\" usepost>",
112
	    format_number($evaluations), format_number($packets),
113
	    format_bytes($bytes), format_number($states),
114
	    format_number($stcreations));
115
	printf("%s/%s</a><br />", format_number($states), format_bytes($bytes));
116
}
117

    
118
function delete_nat_association($id) {
119
	global $config;
120

    
121
	if (!$id || !is_array($config['nat']['rule'])) {
122
		return;
123
	}
124

    
125
	$a_nat = &$config['nat']['rule'];
126

    
127
	foreach ($a_nat as &$natent) {
128
		if ($natent['associated-rule-id'] == $id) {
129
			$natent['associated-rule-id'] = '';
130
		}
131
	}
132
}
133

    
134
init_config_arr(array('filter', 'rule'));
135
filter_rules_sort();
136
$a_filter = &$config['filter']['rule'];
137

    
138
if ($_REQUEST['if']) {
139
	$if = $_REQUEST['if'];
140
}
141

    
142
$ifdescs = get_configured_interface_with_descr();
143

    
144
$iflist = filter_get_interface_list();
145

    
146
if (!$if || !isset($iflist[$if])) {
147
	if ($if != "any" && $if != "FloatingRules" && isset($iflist['wan'])) {
148
		$if = "wan";
149
	} else {
150
		$if = "FloatingRules";
151
	}
152
}
153

    
154
if ($_POST['apply']) {
155
	$retval = 0;
156
	$retval |= filter_configure();
157

    
158
	clear_subsystem_dirty('filter');
159
}
160

    
161
if ($_POST['act'] == "del") {
162
	if ($a_filter[$_POST['id']]) {
163
		if (!empty($a_filter[$_POST['id']]['associated-rule-id'])) {
164
			delete_nat_association($a_filter[$_POST['id']]['associated-rule-id']);
165
		}
166
		unset($a_filter[$_POST['id']]);
167

    
168
		// Update the separators
169
		init_config_arr(array('filter', 'separator', strtolower($if)));
170
		$a_separators = &$config['filter']['separator'][strtolower($if)];
171
		$ridx = ifridx($if, $_POST['id']);	// get rule index within interface
172
		$mvnrows = -1;
173
		move_separators($a_separators, $ridx, $mvnrows);
174

    
175
		if (write_config(gettext("Firewall: Rules - deleted a firewall rule."))) {
176
			mark_subsystem_dirty('filter');
177
		}
178

    
179
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
180
		exit;
181
	}
182
}
183

    
184
// Handle save msg if defined
185
if ($_REQUEST['savemsg']) {
186
	$savemsg = htmlentities($_REQUEST['savemsg']);
187
}
188

    
189
if (isset($_POST['del_x'])) {
190
	/* delete selected rules */
191
	$deleted = false;
192

    
193
	if (is_array($_POST['rule']) && count($_POST['rule'])) {
194
		init_config_arr(array('filter', 'separator', strtolower($if)));
195
		$a_separators = &$config['filter']['separator'][strtolower($if)];
196
		$num_deleted = 0;
197

    
198
		foreach ($_POST['rule'] as $rulei) {
199
			delete_nat_association($a_filter[$rulei]['associated-rule-id']);
200
			unset($a_filter[$rulei]);
201
			$deleted = true;
202

    
203
			// Update the separators
204
			// As rules are deleted, $ridx has to be decremented or separator position will break
205
			$ridx = ifridx($if, $rulei) - $num_deleted;	// get rule index within interface
206
			$mvnrows = -1;
207
			move_separators($a_separators, $ridx, $mvnrows);
208
			$num_deleted++;
209
		}
210

    
211
		if ($deleted) {
212
			if (write_config(gettext("Firewall: Rules - deleted selected firewall rules."))) {
213
				mark_subsystem_dirty('filter');
214
			}
215
		}
216

    
217
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
218
		exit;
219
	}
220
} else if ($_POST['act'] == "toggle") {
221
	if ($a_filter[$_POST['id']]) {
222
		if (isset($a_filter[$_POST['id']]['disabled'])) {
223
			unset($a_filter[$_POST['id']]['disabled']);
224
			$wc_msg = gettext('Firewall: Rules - enabled a firewall rule.');
225
		} else {
226
			$a_filter[$_POST['id']]['disabled'] = true;
227
			$wc_msg = gettext('Firewall: Rules - disabled a firewall rule.');
228
		}
229
		if (write_config($wc_msg)) {
230
			mark_subsystem_dirty('filter');
231
		}
232

    
233
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
234
		exit;
235
	}
236
} else if ($_POST['order-store']) {
237
	$updated = false;
238
	$dirty = false;
239

    
240
	/* update rule order, POST[rule] is an array of ordered IDs */
241
	if (is_array($_POST['rule']) && !empty($_POST['rule'])) {
242
		$a_filter_new = array();
243

    
244
		// Include the rules of other interfaces listed in config before this (the selected) interface.
245
		foreach ($a_filter as $filteri_before => $filterent) {
246
			if (($filterent['interface'] == $if && !isset($filterent['floating'])) || (isset($filterent['floating']) && "FloatingRules" == $if)) {
247
				break;
248
			} else {
249
				$a_filter_new[] = $filterent;
250
			}
251
		}
252

    
253
		// Include the rules of this (the selected) interface.
254
		// If a rule is not in POST[rule], it has been deleted by the user
255
		foreach ($_POST['rule'] as $id) {
256
			$a_filter_new[] = $a_filter[$id];
257
		}
258

    
259
		// Include the rules of other interfaces listed in config after this (the selected) interface.
260
		foreach ($a_filter as $filteri_after => $filterent) {
261
			if ($filteri_before > $filteri_after) {
262
				continue;
263
			}
264
			if (($filterent['interface'] == $if && !isset($filterent['floating'])) || (isset($filterent['floating']) && "FloatingRules" == $if)) {
265
				continue;
266
			} else {
267
				$a_filter_new[] = $filterent;
268
			}
269
		}
270

    
271
		if ($a_filter !== $a_filter_new) {
272
			$a_filter = $a_filter_new;
273
			$dirty = true;
274
		}
275
	}
276

    
277
	$a_separators = &$config['filter']['separator'][strtolower($if)];
278

    
279
	/* update separator order, POST[separator] is an array of ordered IDs */
280
	if (is_array($_POST['separator']) && !empty($_POST['separator'])) {
281
		$new_separator = array();
282
		$idx = 0;
283

    
284
		foreach ($_POST['separator'] as $separator) {
285
			$new_separator['sep' . $idx++] = $separator;
286
		}
287

    
288
		if ($a_separators !== $new_separator) {
289
			$a_separators = $new_separator;
290
			$updated = true;
291
		}
292
	} else if (!empty($a_separators)) {
293
		$a_separators = "";
294
		$updated = true;
295
	}
296

    
297
	if ($updated || $dirty) {
298
		if (write_config(gettext("Firewall: Rules - reordered firewall rules."))) {
299
			if ($dirty) {
300
				mark_subsystem_dirty('filter');
301
			}
302
		}
303
	}
304

    
305
	header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
306
	exit;
307
}
308

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

    
311
foreach ($iflist as $ifent => $ifname) {
312
	$tab_array[] = array($ifname, ($ifent == $if), "firewall_rules.php?if={$ifent}");
313
}
314

    
315
foreach ($tab_array as $dtab) {
316
	if ($dtab[1]) {
317
		$bctab = $dtab[0];
318
		break;
319
	}
320
}
321

    
322
$pgtitle = array(gettext("Firewall"), gettext("Rules"), $bctab);
323
$pglinks = array("", "firewall_rules.php", "@self");
324
$shortcut_section = "firewall";
325

    
326
include("head.inc");
327
$nrules = 0;
328

    
329
if ($savemsg) {
330
	print_info_box($savemsg, 'success');
331
}
332

    
333
if ($_POST['apply']) {
334
	print_apply_result_box($retval);
335
}
336

    
337
if (is_subsystem_dirty('filter')) {
338
	print_apply_box(gettext("The firewall rule configuration has been changed.") . "<br />" . gettext("The changes must be applied for them to take effect."));
339
}
340

    
341
display_top_tabs($tab_array, false, 'pills');
342

    
343
$showantilockout = false;
344
$showprivate = false;
345
$showblockbogons = false;
346

    
347
if (!isset($config['system']['webgui']['noantilockout']) &&
348
    (((count($config['interfaces']) > 1) && ($if == 'lan')) ||
349
    ((count($config['interfaces']) == 1) && ($if == 'wan')))) {
350
	$showantilockout = true;
351
}
352

    
353
if (isset($config['interfaces'][$if]['blockpriv'])) {
354
	$showprivate = true;
355
}
356

    
357
if (isset($config['interfaces'][$if]['blockbogons'])) {
358
	$showblockbogons = true;
359
}
360

    
361
if (isset($config['system']['webgui']['roworderdragging'])) {
362
	$rules_header_text = gettext("Rules");
363
} else {
364
	$rules_header_text = gettext("Rules (Drag to Change Order)");
365
}
366

    
367
/* Load the counter data of each pf rule. */
368
$rulescnt = pfSense_get_pf_rules();
369

    
370
// Update this if you add or remove columns!
371
$columns_in_table = 13;
372

    
373
/* Floating rules tab has one extra column
374
 * https://redmine.pfsense.org/issues/10667 */
375
if ($if == "FloatingRules") {
376
	$columns_in_table++;
377
}
378

    
379
?>
380
<!-- Allow table to scroll when dragging outside of the display window -->
381
<style>
382
.table-responsive {
383
    clear: both;
384
    overflow-x: visible;
385
    margin-bottom: 0px;
386
}
387
</style>
388

    
389
<form method="post">
390
	<input name="if" id="if" type="hidden" value="<?=$if?>" />
391
	<div class="panel panel-default">
392
		<div class="panel-heading"><h2 class="panel-title"><?=$rules_header_text?></h2></div>
393
		<div id="mainarea" class="table-responsive panel-body">
394
			<table id="ruletable" class="table table-hover table-striped table-condensed" style="overflow-x: 'visible'">
395
				<thead>
396
					<tr>
397
						<th><input type="checkbox" id="selectAll" name="selectAll" /></th>
398
						<th><!-- status icons --></th>
399
						<th><?=gettext("States")?></th>
400
				<?php
401
					if ('FloatingRules' == $if) {
402
				?>
403
						<th><?=gettext("Interfaces")?></th>
404
				<?php
405
					}
406
				?>
407
						<th><?=gettext("Protocol")?></th>
408
						<th><?=gettext("Source")?></th>
409
						<th><?=gettext("Port")?></th>
410
						<th><?=gettext("Destination")?></th>
411
						<th><?=gettext("Port")?></th>
412
						<th><?=gettext("Gateway")?></th>
413
						<th><?=gettext("Queue")?></th>
414
						<th><?=gettext("Schedule")?></th>
415
						<th><?=gettext("Description")?></th>
416
						<th><?=gettext("Actions")?></th>
417
					</tr>
418
				</thead>
419

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

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

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

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

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

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

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

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

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

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

    
576
							//get hours
577
							$temptimerange = $timerange['hour'];
578
							$temptimeseparator = strrpos($temptimerange, "-");
579

    
580
							$starttime = substr ($temptimerange, 0, $temptimeseparator);
581
							$stoptime = substr ($temptimerange, $temptimeseparator+1);
582

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

    
593
									if (!$firstDayFound) {
594
										$firstDay = $day;
595
										$firstmonth = $month;
596
										$firstDayFound = true;
597
									}
598

    
599
									$currentDay = $day;
600
									$nextDay = $tempdayarray[$arraycounter+1];
601
									$currentDay++;
602
									if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])) {
603
										if ($firstPrint) {
604
											$dayFriendly .= ", ";
605
										}
606
										$currentDay--;
607
										if ($currentDay != $firstDay) {
608
											$dayFriendly .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
609
										} else {
610
											$dayFriendly .=	 $monthArray[$month-1] . " " . $day;
611
										}
612
										$firstDayFound = false;
613
										$firstPrint = true;
614
									}
615
									$arraycounter++;
616
								}
617
							} else {
618
								$tempdayFriendly = $timerange['position'];
619
								$firstDayFound = false;
620
								$tempFriendlyDayArray = explode(",", $tempdayFriendly);
621
								$currentDay = "";
622
								$firstDay = "";
623
								$nextDay = "";
624
								$counter = 0;
625
								foreach ($tempFriendlyDayArray as $day) {
626
									if ($day != "") {
627
										if (!$firstDayFound) {
628
											$firstDay = $tempFriendlyDayArray[$counter];
629
											$firstDayFound = true;
630
										}
631
										$currentDay =$tempFriendlyDayArray[$counter];
632
										//get next day
633
										$nextDay = $tempFriendlyDayArray[$counter+1];
634
										$currentDay++;
635
										if ($currentDay != $nextDay) {
636
											if ($firstprint) {
637
												$dayFriendly .= ", ";
638
											}
639
											$currentDay--;
640
											if ($currentDay != $firstDay) {
641
												$dayFriendly .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
642
											} else {
643
												$dayFriendly .= $dayArray[$firstDay-1];
644
											}
645
											$firstDayFound = false;
646
											$firstprint = true;
647
										}
648
										$counter++;
649
									}
650
								}
651
							}
652
							$timeFriendly = $starttime . " - " . $stoptime;
653
							$description = $timerange['rangedescr'];
654
							$sched_content .= $dayFriendly . "; " . $timeFriendly . "<br />";
655
						}
656
					}
657
					#FIXME
658
					$sched_caption_escaped = str_replace("'", "\'", $schedule['descr']);
659
					$schedule_span_begin = '<a href="/firewall_schedule_edit.php?id=' . $idx . '" data-toggle="popover" data-trigger="hover focus" title="' . $schedule['name'] . '" data-content="' .
660
						$sched_caption_escaped . '" data-html="true">';
661
					$schedule_span_end = "</a>";
662
				}
663
				$idx++;
664
			}
665
		}
666
		$printicon = false;
667
		$alttext = "";
668
		$image = "";
669
		if (!isset($filterent['disabled'])) {
670
			if ($schedstatus) {
671
				if ($filterent['type'] == "block" || $filterent['type'] == "reject") {
672
					$image = "times-circle";
673
					$dispcolor = "text-danger";
674
					$alttext = gettext("Traffic matching this rule is currently being denied");
675
				} else {
676
					$image = "play-circle";
677
					$dispcolor = "text-success";
678
					$alttext = gettext("Traffic matching this rule is currently being allowed");
679
				}
680
				$printicon = true;
681
			} else if ($filterent['sched']) {
682
				if ($filterent['type'] == "block" || $filterent['type'] == "reject") {
683
					$image = "times-circle";
684
				} else {
685
					$image = "play-circle";
686
				}
687
				$alttext = gettext("This rule is not currently active because its period has expired");
688
				$dispcolor = "text-warning";
689
				$printicon = true;
690
			}
691
		}
692
	?>
693
				<td><?php print_states(intval($filterent['tracker'])); ?></td>
694
	<?php
695
		if ($if == 'FloatingRules') {
696
	?>
697
			<td onclick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
698
	<?php
699
			if (isset($filterent['interface'])) {
700
				$selected_interfaces = explode(',', $filterent['interface']);
701
				unset($selected_descs);
702
				foreach ($selected_interfaces as $interface) {
703
					if (isset($ifdescs[$interface])) {
704
						$selected_descs[] = $ifdescs[$interface];
705
					} else {
706
						switch ($interface) {
707
						case 'l2tp':
708
							if ($config['l2tp']['mode'] == 'server')
709
								$selected_descs[] = 'L2TP VPN';
710
							break;
711
						case 'pppoe':
712
							if (is_pppoe_server_enabled())
713
								$selected_descs[] = 'PPPoE Server';
714
							break;
715
						case 'enc0':
716
							if (ipsec_enabled())
717
								$selected_descs[] = 'IPsec';
718
							break;
719
						case 'openvpn':
720
							if  ($config['openvpn']['openvpn-server'] || $config['openvpn']['openvpn-client'])
721
								$selected_descs[] = 'OpenVPN';
722
							break;
723
						default:
724
							$selected_descs[] = $interface;
725
							break;
726
						}
727
					}
728
				}
729
				if (!empty($selected_descs)) {
730
					$desclist = '';
731
					$desclength = 0;
732
					foreach ($selected_descs as $descid => $desc) {
733
						$desclength += strlen($desc);
734
						if ($desclength > 18) {
735
							$desclist .= ',<br/>';
736
							$desclength = 0;
737
						} elseif ($desclist) {
738
							$desclist .= ', ';
739
							$desclength += 2;
740
						}
741
						$desclist .= $desc;
742
					}
743
					echo $desclist;
744
				}
745
			}
746
	?>
747
			</td>
748
	<?php
749
		}
750
	?>
751
			<td>
752
	<?php
753
		if (isset($filterent['ipprotocol'])) {
754
			switch ($filterent['ipprotocol']) {
755
				case "inet":
756
					echo "IPv4 ";
757
					break;
758
				case "inet6":
759
					echo "IPv6 ";
760
					break;
761
				case "inet46":
762
					echo "IPv4+6 ";
763
					break;
764
			}
765
		} else {
766
			echo "IPv4 ";
767
		}
768

    
769
		if (isset($filterent['protocol'])) {
770
			echo strtoupper($filterent['protocol']);
771

    
772
			if (strtoupper($filterent['protocol']) == "ICMP" && !empty($filterent['icmptype'])) {
773
				// replace each comma-separated icmptype item by its (localised) full description
774
				$t = 	implode(', ',
775
						array_map(
776
						        function($type) {
777
								global $icmptypes;
778
								return $icmptypes[$type]['descrip'];
779
							},
780
							explode(',', $filterent['icmptype'])
781
						)
782
					);
783
				echo sprintf('<br /><div style="cursor:help;padding:1px;line-height:1.1em;max-height:2.5em;max-width:180px;overflow-y:auto;overflow-x:hidden" title="%s:%s%s"><small><u>%s</u></small></div>', gettext('ICMP subtypes'), chr(13), $t, str_replace(',', '</u>, <u>',$filterent['icmptype']));
784
			}
785
		} else {
786
			echo " *";
787
		}
788
	?>
789
						</td>
790
						<td>
791
							<?php if (isset($alias['src'])): ?>
792
								<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">
793
									<?=str_replace('_', '_<wbr>', htmlspecialchars(pprint_address($filterent['source'])))?>
794
								</a>
795
							<?php else: ?>
796
								<?=htmlspecialchars(pprint_address($filterent['source']))?>
797
							<?php endif; ?>
798
						</td>
799
						<td>
800
							<?php if (isset($alias['srcport'])): ?>
801
								<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">
802
									<?=str_replace('_', '_<wbr>', htmlspecialchars(pprint_port($filterent['source']['port'])))?>
803
								</a>
804
							<?php else: ?>
805
								<?=htmlspecialchars(pprint_port($filterent['source']['port']))?>
806
							<?php endif; ?>
807
						</td>
808
						<td>
809
							<?php if (isset($alias['dst'])): ?>
810
								<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">
811
									<?=str_replace('_', '_<wbr>', htmlspecialchars(pprint_address($filterent['destination'])))?>
812
								</a>
813
							<?php else: ?>
814
								<?=htmlspecialchars(pprint_address($filterent['destination']))?>
815
							<?php endif; ?>
816
						</td>
817
						<td>
818
							<?php if (isset($alias['dstport'])): ?>
819
								<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">
820
									<?=str_replace('_', '_<wbr>', htmlspecialchars(pprint_port($filterent['destination']['port'])))?>
821
								</a>
822
							<?php else: ?>
823
								<?=htmlspecialchars(pprint_port($filterent['destination']['port']))?>
824
							<?php endif; ?>
825
						</td>
826
						<td>
827
							<?php if (isset($filterent['gateway'])): ?>
828
								<span data-toggle="popover" data-trigger="hover focus" title="<?=gettext('Gateways details')?>" data-content="<?=gateway_info_popup($filterent['gateway'])?>" data-html="true">
829
							<?php else: ?>
830
								<span>
831
							<?php endif; ?>
832
								<?php if (isset($config['interfaces'][$filterent['gateway']]['descr'])): ?>
833
									<?=str_replace('_', '_<wbr>', htmlspecialchars($config['interfaces'][$filterent['gateway']]['descr']))?>
834
								<?php else: ?>
835
									<?=htmlspecialchars(pprint_port($filterent['gateway']))?>
836
								<?php endif; ?>
837
							</span>
838
						</td>
839
						<td>
840
							<?php
841
								if (isset($filterent['ackqueue']) && isset($filterent['defaultqueue'])) {
842
									$desc = str_replace('_', ' ', $filterent['ackqueue']);
843
									echo "<a href=\"firewall_shaper_queues.php?queue={$filterent['ackqueue']}&amp;action=show\">{$desc}</a>";
844
									$desc = str_replace('_', '_<wbr>', $filterent['defaultqueue']);
845
									echo "/<a href=\"firewall_shaper_queues.php?queue={$filterent['defaultqueue']}&amp;action=show\">{$desc}</a>";
846
								} else if (isset($filterent['defaultqueue'])) {
847
									$desc = str_replace('_', '_<wbr>', $filterent['defaultqueue']);
848
									echo "<a href=\"firewall_shaper_queues.php?queue={$filterent['defaultqueue']}&amp;action=show\">{$desc}</a>";
849
								} else {
850
									echo gettext("none");
851
								}
852
							?>
853
						</td>
854
						<td>
855
							<?php if ($printicon) { ?>
856
								<i class="fa fa-<?=$image?> <?=$dispcolor?>" title="<?=$alttext;?>"></i>
857
							<?php } ?>
858
							<?=$schedule_span_begin;?><?=str_replace('_', '_<wbr>', htmlspecialchars($filterent['sched']));?>&nbsp;<?=$schedule_span_end;?>
859
						</td>
860
						<td>
861
							<?=htmlspecialchars($filterent['descr']);?>
862
						</td>
863
						<td class="action-icons">
864
						<!-- <?=(isset($filterent['disabled']) ? 'enable' : 'disable')?> -->
865
							<a	class="fa fa-anchor icon-pointer" id="Xmove_<?=$filteri?>" title="<?=$XmoveTitle?>"></a>
866
							<a href="firewall_rules_edit.php?id=<?=$filteri;?>" class="fa fa-pencil" title="<?=gettext('Edit')?>"></a>
867
							<a href="firewall_rules_edit.php?dup=<?=$filteri;?>" class="fa fa-clone" title="<?=gettext('Copy')?>"></a>
868
<?php if (isset($filterent['disabled'])) {
869
?>
870
							<a href="?act=toggle&amp;if=<?=htmlspecialchars($if);?>&amp;id=<?=$filteri;?>" class="fa fa-check-square-o" title="<?=gettext('Enable')?>" usepost></a>
871
<?php } else {
872
?>
873
							<a href="?act=toggle&amp;if=<?=htmlspecialchars($if);?>&amp;id=<?=$filteri;?>" class="fa fa-ban" title="<?=gettext('Disable')?>" usepost></a>
874
<?php }
875
?>
876
							<a href="?act=del&amp;if=<?=htmlspecialchars($if);?>&amp;id=<?=$filteri;?>" class="fa fa-trash" title="<?=gettext('Delete this rule')?>" usepost></a>
877
						</td>
878
					</tr>
879
<?php
880
		$nrules++;
881
	}
882
endforeach;
883

    
884
// There can be separator(s) after the last rule listed.
885
if ($seprows[$nrules]) {
886
	display_separator($separators, $nrules, $columns_in_table);
887
}
888
?>
889
				</tbody>
890
			</table>
891
		</div>
892
	</div>
893

    
894
<?php if ($nrules == 0): ?>
895
	<div class="alert alert-warning" role="alert">
896
		<p>
897
		<?php if ($_REQUEST['if'] == "FloatingRules"): ?>
898
			<?=gettext("No floating rules are currently defined.");?>
899
		<?php else: ?>
900
			<?=gettext("No rules are currently defined for this interface");?><br />
901
			<?=gettext("All incoming connections on this interface will be blocked until pass rules are added.");?>
902
		<?php endif;?>
903
			<?=gettext("Click the button to add a new rule.");?>
904
		</p>
905
	</div>
906
<?php endif;?>
907

    
908
	<nav class="action-buttons">
909
		<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')?>">
910
			<i class="fa fa-level-up icon-embed-btn"></i>
911
			<?=gettext("Add");?>
912
		</a>
913
		<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')?>">
914
			<i class="fa fa-level-down icon-embed-btn"></i>
915
			<?=gettext("Add");?>
916
		</a>
917
		<button name="del_x" type="submit" class="btn btn-danger btn-sm" value="<?=gettext("Delete selected rules"); ?>" title="<?=gettext('Delete selected rules')?>">
918
			<i class="fa fa-trash icon-embed-btn"></i>
919
			<?=gettext("Delete"); ?>
920
		</button>
921
		<button type="submit" id="order-store" name="order-store" class="btn btn-sm btn-primary" value="store changes" disabled title="<?=gettext('Save rule order')?>">
922
			<i class="fa fa-save icon-embed-btn"></i>
923
			<?=gettext("Save")?>
924
		</button>
925
		<button type="submit" id="addsep" name="addsep" class="btn btn-sm btn-warning" title="<?=gettext('Add separator')?>">
926
			<i class="fa fa-plus icon-embed-btn"></i>
927
			<?=gettext("Separator")?>
928
		</button>
929
	</nav>
930
</form>
931

    
932
<div class="infoblock">
933
	<div class="alert alert-info clearfix" role="alert"><div class="pull-left">
934
		<dl class="dl-horizontal responsive">
935
		<!-- Legend -->
936
			<dt><?=gettext('Legend')?></dt>				<dd></dd>
937
			<dt><i class="fa fa-check text-success"></i></dt>		<dd><?=gettext("Pass");?></dd>
938
			<dt><i class="fa fa-filter"></i></dt>	<dd><?=gettext("Match");?></dd>
939
			<dt><i class="fa fa-times text-danger"></i></dt>	<dd><?=gettext("Block");?></dd>
940
			<dt><i class="fa fa-hand-stop-o text-warning"></i></dt>		<dd><?=gettext("Reject");?></dd>
941
			<dt><i class="fa fa-tasks"></i></dt>	<dd> <?=gettext("Log");?></dd>
942
			<dt><i class="fa fa-cog"></i></dt>		<dd> <?=gettext("Advanced filter");?></dd>
943
			<dt><i class="fa fa-forward text-success"></i></dt><dd> <?=gettext("&quot;Quick&quot; rule. Applied immediately on match.")?></dd>
944
		</dl>
945

    
946
<?php
947
	if ("FloatingRules" != $if) {
948
		print(gettext("Rules are evaluated on a first-match basis (i.e. " .
949
			"the action of the first rule to match a packet will be executed). ") . '<br />' .
950
			gettext("This means that if block rules are used, it is important to pay attention " .
951
			"to the rule order. Everything that isn't explicitly passed is blocked " .
952
			"by default. "));
953
	} else {
954
		print(gettext("Floating rules are evaluated on a first-match basis (i.e. " .
955
			"the action of the first rule to match a packet will be executed) only " .
956
			"if the 'quick' option is checked on a rule. Otherwise they will only match if no " .
957
			"other rules match. Pay close attention to the rule order and options " .
958
			"chosen. If no rule here matches, the per-interface or default rules are used. "));
959
	}
960

    
961
	printf(gettext('%1$sClick the anchor icon %2$s to move checked rules before the clicked row. Hold down ' .
962
			'the shift key and click to move the rules after the clicked row.'), '<br /><br />', '<i class="fa fa-anchor"></i>')
963
?>
964
	</div>
965
	</div>
966
</div>
967

    
968
<script type="text/javascript">
969
//<![CDATA[
970

    
971
//Need to create some variables here so that jquery/pfSenseHelpers.js can read them
972
iface = "<?=strtolower($if)?>";
973
cncltxt = '<?=gettext("Cancel")?>';
974
svtxt = '<?=gettext("Save")?>';
975
svbtnplaceholder = '<?=gettext("Enter a description, Save, then drag to final location.")?>';
976
configsection = "filter";
977

    
978
events.push(function() {
979

    
980
	// "Move to here" (anchor) action
981
	$('[id^=Xmove_]').click(function (event) {
982

    
983
		// Prevent click from toggling row
984
		event.stopImmediatePropagation();
985

    
986
		// Save the target rule position
987
		var anchor_row = $(this).parents("tr:first");
988

    
989
		if (event.shiftKey) {
990
			$($('#ruletable > tbody  > tr').get().reverse()).each(function() {
991
				ruleid = this.id.slice(2);
992

    
993
				if (ruleid && !isNaN(ruleid)) {
994
					if ($('#frc' + ruleid).prop('checked')) {
995
						// Move the selected rows, un-select them and add highlight class
996
						$(this).insertAfter(anchor_row);
997
						fr_toggle(ruleid, "fr");
998
						$('#fr' + ruleid).addClass("highlight");
999
					}
1000
				}
1001
			});
1002
		} else {
1003
			$('#ruletable > tbody  > tr').each(function() {
1004
				ruleid = this.id.slice(2);
1005

    
1006
				if (ruleid && !isNaN(ruleid)) {
1007
					if ($('#frc' + ruleid).prop('checked')) {
1008
						// Move the selected rows, un-select them and add highlight class
1009
						$(this).insertBefore(anchor_row);
1010
						fr_toggle(ruleid, "fr");
1011
						$('#fr' + ruleid).addClass("highlight");
1012
					}
1013
				}
1014
			});
1015
		}
1016

    
1017
		// Temporarily set background color so user can more easily see the moved rules, then fade
1018
		$('.highlight').effect("highlight", {color: "#739b4b;"}, 4000);
1019
		$('#ruletable tr').removeClass("highlight");
1020
		$('#order-store').removeAttr('disabled');
1021
		reindex_rules($(anchor_row).parent('tbody'));
1022
		dirty = true;
1023
	}).mouseover(function(e) {
1024
		var ruleselected = false;
1025

    
1026
		$(this).css("cursor", "default");
1027

    
1028
		// Are any rules currently selected?
1029
		$('[id^=frc]').each(function () {
1030
			if ($(this).prop("checked")) {
1031
				ruleselected = true;
1032
			}
1033
		});
1034

    
1035
		// If so, change the icon to show the insertion point
1036
		if (ruleselected) {
1037
			if (e.shiftKey) {
1038
				$(this).removeClass().addClass("fa fa-lg fa-arrow-down text-danger");
1039
			} else {
1040
				$(this).removeClass().addClass("fa fa-lg fa-arrow-up text-danger");
1041
			}
1042
		}
1043
	}).mouseout(function(e) {
1044
		$(this).removeClass().addClass("fa fa-anchor");
1045
	});
1046

    
1047
<?php if(!isset($config['system']['webgui']['roworderdragging'])): ?>
1048
	// Make rules sortable. Hiding the table before applying sortable, then showing it again is
1049
	// a work-around for very slow sorting on FireFox
1050
	$('table tbody.user-entries').hide();
1051

    
1052
	$('table tbody.user-entries').sortable({
1053
		cursor: 'grabbing',
1054
		scroll: true,
1055
		overflow: 'scroll',
1056
		scrollSensitivity: 100,
1057
		update: function(event, ui) {
1058
			$('#order-store').removeAttr('disabled');
1059
			reindex_rules(ui.item.parent('tbody'));
1060
			dirty = true;
1061
		}
1062
	});
1063

    
1064
	$('table tbody.user-entries').show();
1065
<?php endif; ?>
1066

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

    
1071
		// Save the separator bar configuration
1072
		save_separators();
1073

    
1074
		// Suppress the "Do you really want to leave the page" message
1075
		saving = true;
1076
	});
1077

    
1078
	// Provide a warning message if the user tries to change page before saving
1079
	$(window).bind('beforeunload', function(){
1080
		if ((!saving && dirty) || newSeperator) {
1081
			return ("<?=gettext('One or more rules have been moved but have not yet been saved')?>");
1082
		} else {
1083
			return undefined;
1084
		}
1085
	});
1086

    
1087
	$(document).on('keyup keydown', function(e){
1088
		if (e.shiftKey) {
1089
			$('[id^=Xmove_]').attr("title", "<?=$ShXmoveTitle?>");
1090
		} else {
1091
			$('[id^=Xmove_]').attr("title", "<?=$XmoveTitle?>");
1092
		}
1093
	});
1094

    
1095
	$('#selectAll').click(function() {
1096
		var checkedStatus = this.checked;
1097
		$('#ruletable tbody tr').find('td:first :checkbox').each(function() {
1098
		$(this).prop('checked', checkedStatus);
1099
		});
1100
	});
1101
});
1102
//]]>
1103
</script>
1104

    
1105
<?php include("foot.inc");?>
(50-50/229)