Project

General

Profile

Download (36.8 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
	if (is_array($_POST['rule']) && count($_POST['rule'])) {
191
		init_config_arr(array('filter', 'separator', strtolower($if)));
192
		$a_separators = &$config['filter']['separator'][strtolower($if)];
193

    
194
		$first_idx = 0;		
195
		$num_deleted = 0;
196
		foreach ($_POST['rule'] as $rulei) {
197
			delete_nat_association($a_filter[$rulei]['associated-rule-id']);
198
			unset($a_filter[$rulei]);
199

    
200
			// Capture first changed filter index for later separator shifting
201
			if (!$first_idx) $first_idx = ifridx($if, $rulei);
202
			$num_deleted++;
203
		}
204

    
205
		if ($num_deleted) {
206
			move_separators($a_separators, $first_idx, -$num_deleted);
207
			if (write_config(gettext("Firewall: Rules - deleted selected firewall rules."))) {
208
				mark_subsystem_dirty('filter');
209
			}
210
		}
211

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

    
228
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
229
		exit;
230
	}
231
} else if ($_POST['order-store']) {
232
	$updated = false;
233
	$dirty = false;
234

    
235
	/* update rule order, POST[rule] is an array of ordered IDs */
236
	if (is_array($_POST['rule']) && !empty($_POST['rule'])) {
237
		$a_filter_new = array();
238

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

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

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

    
266
		if ($a_filter !== $a_filter_new) {
267
			$a_filter = $a_filter_new;
268
			$dirty = true;
269
		}
270
	}
271

    
272
	$a_separators = &$config['filter']['separator'][strtolower($if)];
273

    
274
	/* update separator order, POST[separator] is an array of ordered IDs */
275
	if (is_array($_POST['separator']) && !empty($_POST['separator'])) {
276
		$new_separator = array();
277
		$idx = 0;
278

    
279
		foreach ($_POST['separator'] as $separator) {
280
			$new_separator['sep' . $idx++] = $separator;
281
		}
282

    
283
		if ($a_separators !== $new_separator) {
284
			$a_separators = $new_separator;
285
			$updated = true;
286
		}
287
	} else if (!empty($a_separators)) {
288
		$a_separators = "";
289
		$updated = true;
290
	}
291

    
292
	if ($updated || $dirty) {
293
		if (write_config(gettext("Firewall: Rules - reordered firewall rules."))) {
294
			if ($dirty) {
295
				mark_subsystem_dirty('filter');
296
			}
297
		}
298
	}
299

    
300
	header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
301
	exit;
302
}
303

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

    
306
foreach ($iflist as $ifent => $ifname) {
307
	$tab_array[] = array($ifname, ($ifent == $if), "firewall_rules.php?if={$ifent}");
308
}
309

    
310
foreach ($tab_array as $dtab) {
311
	if ($dtab[1]) {
312
		$bctab = $dtab[0];
313
		break;
314
	}
315
}
316

    
317
$pgtitle = array(gettext("Firewall"), gettext("Rules"), $bctab);
318
$pglinks = array("", "firewall_rules.php", "@self");
319
$shortcut_section = "firewall";
320

    
321
include("head.inc");
322
$nrules = 0;
323

    
324
if ($savemsg) {
325
	print_info_box($savemsg, 'success');
326
}
327

    
328
if ($_POST['apply']) {
329
	print_apply_result_box($retval);
330
}
331

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

    
336
display_top_tabs($tab_array, false, 'pills');
337

    
338
$showantilockout = false;
339
$showprivate = false;
340
$showblockbogons = false;
341

    
342
if (!isset($config['system']['webgui']['noantilockout']) &&
343
    (((count($config['interfaces']) > 1) && ($if == 'lan')) ||
344
    ((count($config['interfaces']) == 1) && ($if == 'wan')))) {
345
	$showantilockout = true;
346
}
347

    
348
if (isset($config['interfaces'][$if]['blockpriv'])) {
349
	$showprivate = true;
350
}
351

    
352
if (isset($config['interfaces'][$if]['blockbogons'])) {
353
	$showblockbogons = true;
354
}
355

    
356
if (isset($config['system']['webgui']['roworderdragging'])) {
357
	$rules_header_text = gettext("Rules");
358
} else {
359
	$rules_header_text = gettext("Rules (Drag to Change Order)");
360
}
361

    
362
/* Load the counter data of each pf rule. */
363
$rulescnt = pfSense_get_pf_rules();
364

    
365
// Update this if you add or remove columns!
366
$columns_in_table = 13;
367

    
368
/* Floating rules tab has one extra column
369
 * https://redmine.pfsense.org/issues/10667 */
370
if ($if == "FloatingRules") {
371
	$columns_in_table++;
372
}
373

    
374
?>
375
<!-- Allow table to scroll when dragging outside of the display window -->
376
<style>
377
.table-responsive {
378
    clear: both;
379
    overflow-x: visible;
380
    margin-bottom: 0px;
381
}
382
</style>
383

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

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

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

    
490
/* Cache gateway status for this page load.
491
 * See https://redmine.pfsense.org/issues/12174 */
492
$gateways_status = return_gateways_status(true);
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;?>" usepost>
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
		init_config_arr(array('schedules', 'schedule'));
552
		$a_schedules = &$config['schedules']['schedule'];
553
		$schedule_span_begin = "";
554
		$schedule_span_end = "";
555
		$sched_caption_escaped = "";
556
		$sched_content = "";
557
		$schedstatus = false;
558
		$dayArray = array (gettext('Mon'), gettext('Tues'), gettext('Wed'), gettext('Thur'), gettext('Fri'), gettext('Sat'), gettext('Sun'));
559
		$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'));
560
		if ($config['schedules']['schedule'] != "" && is_array($config['schedules']['schedule'])) {
561
			$idx = 0;
562
			foreach ($a_schedules as $schedule) {
563
				if (!empty($schedule['name']) &&
564
				    $schedule['name'] == $filterent['sched']) {
565
					$schedstatus = filter_get_time_based_rule_status($schedule);
566

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

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

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

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

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

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

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

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

    
897
// There can be separator(s) after the last rule listed.
898
if ($seprows[$nrules]) {
899
	display_separator($separators, $nrules, $columns_in_table);
900
}
901
?>
902
				</tbody>
903
			</table>
904
		</div>
905
	</div>
906

    
907
<?php if ($nrules == 0): ?>
908
	<div class="alert alert-warning" role="alert">
909
		<p>
910
		<?php if ($_REQUEST['if'] == "FloatingRules"): ?>
911
			<?=gettext("No floating rules are currently defined.");?>
912
		<?php else: ?>
913
			<?=gettext("No rules are currently defined for this interface");?><br />
914
			<?=gettext("All incoming connections on this interface will be blocked until pass rules are added.");?>
915
		<?php endif;?>
916
			<?=gettext("Click the button to add a new rule.");?>
917
		</p>
918
	</div>
919
<?php endif;?>
920

    
921
	<nav class="action-buttons">
922
		<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')?>">
923
			<i class="fa fa-level-up icon-embed-btn"></i>
924
			<?=gettext("Add");?>
925
		</a>
926
		<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')?>">
927
			<i class="fa fa-level-down icon-embed-btn"></i>
928
			<?=gettext("Add");?>
929
		</a>
930
		<button name="del_x" type="submit" class="btn btn-danger btn-sm" value="<?=gettext("Delete selected rules"); ?>" title="<?=gettext('Delete selected rules')?>">
931
			<i class="fa fa-trash icon-embed-btn"></i>
932
			<?=gettext("Delete"); ?>
933
		</button>
934
		<button type="submit" id="order-store" name="order-store" class="btn btn-sm btn-primary" value="store changes" disabled title="<?=gettext('Save rule order')?>">
935
			<i class="fa fa-save icon-embed-btn"></i>
936
			<?=gettext("Save")?>
937
		</button>
938
		<button type="submit" id="addsep" name="addsep" class="btn btn-sm btn-warning" title="<?=gettext('Add separator')?>">
939
			<i class="fa fa-plus icon-embed-btn"></i>
940
			<?=gettext("Separator")?>
941
		</button>
942
	</nav>
943
</form>
944

    
945
<div class="infoblock">
946
	<div class="alert alert-info clearfix" role="alert"><div class="pull-left">
947
		<dl class="dl-horizontal responsive">
948
		<!-- Legend -->
949
			<dt><?=gettext('Legend')?></dt>				<dd></dd>
950
			<dt><i class="fa fa-check text-success"></i></dt>		<dd><?=gettext("Pass");?></dd>
951
			<dt><i class="fa fa-filter"></i></dt>	<dd><?=gettext("Match");?></dd>
952
			<dt><i class="fa fa-times text-danger"></i></dt>	<dd><?=gettext("Block");?></dd>
953
			<dt><i class="fa fa-hand-stop-o text-warning"></i></dt>		<dd><?=gettext("Reject");?></dd>
954
			<dt><i class="fa fa-tasks"></i></dt>	<dd> <?=gettext("Log");?></dd>
955
			<dt><i class="fa fa-cog"></i></dt>		<dd> <?=gettext("Advanced filter");?></dd>
956
			<dt><i class="fa fa-forward text-success"></i></dt><dd> <?=gettext("&quot;Quick&quot; rule. Applied immediately on match.")?></dd>
957
		</dl>
958

    
959
<?php
960
	if ("FloatingRules" != $if) {
961
		print(gettext("Rules are evaluated on a first-match basis (i.e. " .
962
			"the action of the first rule to match a packet will be executed). ") . '<br />' .
963
			gettext("This means that if block rules are used, it is important to pay attention " .
964
			"to the rule order. Everything that isn't explicitly passed is blocked " .
965
			"by default. "));
966
	} else {
967
		print(gettext("Floating rules are evaluated on a first-match basis (i.e. " .
968
			"the action of the first rule to match a packet will be executed) only " .
969
			"if the 'quick' option is checked on a rule. Otherwise they will only match if no " .
970
			"other rules match. Pay close attention to the rule order and options " .
971
			"chosen. If no rule here matches, the per-interface or default rules are used. "));
972
	}
973

    
974
	printf(gettext('%1$sClick the anchor icon %2$s to move checked rules before the clicked row. Hold down ' .
975
			'the shift key and click to move the rules after the clicked row.'), '<br /><br />', '<i class="fa fa-anchor"></i>')
976
?>
977
	</div>
978
	</div>
979
</div>
980

    
981
<script type="text/javascript">
982
//<![CDATA[
983

    
984
//Need to create some variables here so that jquery/pfSenseHelpers.js can read them
985
iface = "<?=strtolower($if)?>";
986
cncltxt = '<?=gettext("Cancel")?>';
987
svtxt = '<?=gettext("Save")?>';
988
svbtnplaceholder = '<?=gettext("Enter a description, Save, then drag to final location.")?>';
989
configsection = "filter";
990

    
991
events.push(function() {
992

    
993
	// "Move to here" (anchor) action
994
	$('[id^=Xmove_]').click(function (event) {
995

    
996
		// Prevent click from toggling row
997
		event.stopImmediatePropagation();
998

    
999
		// Save the target rule position
1000
		var anchor_row = $(this).parents("tr:first");
1001

    
1002
		if (event.shiftKey) {
1003
			$($('#ruletable > tbody  > tr').get().reverse()).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).insertAfter(anchor_row);
1010
						fr_toggle(ruleid, "fr");
1011
						$('#fr' + ruleid).addClass("highlight");
1012
					}
1013
				}
1014
			});
1015
		} else {
1016
			$('#ruletable > tbody  > tr').each(function() {
1017
				ruleid = this.id.slice(2);
1018

    
1019
				if (ruleid && !isNaN(ruleid)) {
1020
					if ($('#frc' + ruleid).prop('checked')) {
1021
						// Move the selected rows, un-select them and add highlight class
1022
						$(this).insertBefore(anchor_row);
1023
						fr_toggle(ruleid, "fr");
1024
						$('#fr' + ruleid).addClass("highlight");
1025
					}
1026
				}
1027
			});
1028
		}
1029

    
1030
		// Temporarily set background color so user can more easily see the moved rules, then fade
1031
		$('.highlight').effect("highlight", {color: "#739b4b;"}, 4000);
1032
		$('#ruletable tr').removeClass("highlight");
1033
		$('#order-store').removeAttr('disabled');
1034
		reindex_rules($(anchor_row).parent('tbody'));
1035
		dirty = true;
1036
	}).mouseover(function(e) {
1037
		var ruleselected = false;
1038

    
1039
		$(this).css("cursor", "default");
1040

    
1041
		// Are any rules currently selected?
1042
		$('[id^=frc]').each(function () {
1043
			if ($(this).prop("checked")) {
1044
				ruleselected = true;
1045
			}
1046
		});
1047

    
1048
		// If so, change the icon to show the insertion point
1049
		if (ruleselected) {
1050
			if (e.shiftKey) {
1051
				$(this).removeClass().addClass("fa fa-lg fa-arrow-down text-danger");
1052
			} else {
1053
				$(this).removeClass().addClass("fa fa-lg fa-arrow-up text-danger");
1054
			}
1055
		}
1056
	}).mouseout(function(e) {
1057
		$(this).removeClass().addClass("fa fa-anchor");
1058
	});
1059

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

    
1065
	$('table tbody.user-entries').sortable({
1066
		cursor: 'grabbing',
1067
		scroll: true,
1068
		overflow: 'scroll',
1069
		scrollSensitivity: 100,
1070
		update: function(event, ui) {
1071
			$('#order-store').removeAttr('disabled');
1072
			reindex_rules(ui.item.parent('tbody'));
1073
			dirty = true;
1074
		}
1075
	});
1076

    
1077
	$('table tbody.user-entries').show();
1078
<?php endif; ?>
1079

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

    
1084
		// Save the separator bar configuration
1085
		save_separators();
1086

    
1087
		// Suppress the "Do you really want to leave the page" message
1088
		saving = true;
1089
	});
1090

    
1091
	// Provide a warning message if the user tries to change page before saving
1092
	$(window).bind('beforeunload', function(){
1093
		if ((!saving && dirty) || newSeperator) {
1094
			return ("<?=gettext('One or more rules have been moved but have not yet been saved')?>");
1095
		} else {
1096
			return undefined;
1097
		}
1098
	});
1099

    
1100
	$(document).on('keyup keydown', function(e){
1101
		if (e.shiftKey) {
1102
			$('[id^=Xmove_]').attr("title", "<?=$ShXmoveTitle?>");
1103
		} else {
1104
			$('[id^=Xmove_]').attr("title", "<?=$XmoveTitle?>");
1105
		}
1106
	});
1107

    
1108
	$('#selectAll').click(function() {
1109
		var checkedStatus = this.checked;
1110
		$('#ruletable tbody tr').find('td:first :checkbox').each(function() {
1111
		$(this).prop('checked', checkedStatus);
1112
		});
1113
	});
1114
});
1115
//]]>
1116
</script>
1117

    
1118
<?php include("foot.inc");?>
(50-50/227)