Project

General

Profile

Download (36.2 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
foreach ($a_filter as $filteri => $filterent):
491

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

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

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

    
528
		$isadvset = firewall_check_for_advanced_options($filterent);
529
		if ($isadvset) {
530
			print '<i class="fa fa-cog" title="'. gettext("advanced setting") .': '. $isadvset .'"></i>';
531
		}
532

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

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

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

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

    
575
							$starttime = substr ($temptimerange, 0, $temptimeseparator);
576
							$stoptime = substr ($temptimerange, $temptimeseparator+1);
577

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

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

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

    
764
		if (isset($filterent['protocol'])) {
765
			echo strtoupper($filterent['protocol']);
766

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

    
879
// There can be separator(s) after the last rule listed.
880
if ($seprows[$nrules]) {
881
	display_separator($separators, $nrules, $columns_in_table);
882
}
883
?>
884
				</tbody>
885
			</table>
886
		</div>
887
	</div>
888

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

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

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

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

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

    
963
<script type="text/javascript">
964
//<![CDATA[
965

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

    
973
events.push(function() {
974

    
975
	// "Move to here" (anchor) action
976
	$('[id^=Xmove_]').click(function (event) {
977

    
978
		// Prevent click from toggling row
979
		event.stopImmediatePropagation();
980

    
981
		// Save the target rule position
982
		var anchor_row = $(this).parents("tr:first");
983

    
984
		if (event.shiftKey) {
985
			$($('#ruletable > tbody  > tr').get().reverse()).each(function() {
986
				ruleid = this.id.slice(2);
987

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

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

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

    
1021
		$(this).css("cursor", "default");
1022

    
1023
		// Are any rules currently selected?
1024
		$('[id^=frc]').each(function () {
1025
			if ($(this).prop("checked")) {
1026
				ruleselected = true;
1027
			}
1028
		});
1029

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

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

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

    
1059
	$('table tbody.user-entries').show();
1060
<?php endif; ?>
1061

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

    
1066
		// Save the separator bar configuration
1067
		save_separators();
1068

    
1069
		// Suppress the "Do you really want to leave the page" message
1070
		saving = true;
1071
	});
1072

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

    
1082
	$(document).on('keyup keydown', function(e){
1083
		if (e.shiftKey) {
1084
			$('[id^=Xmove_]').attr("title", "<?=$ShXmoveTitle?>");
1085
		} else {
1086
			$('[id^=Xmove_]').attr("title", "<?=$XmoveTitle?>");
1087
		}
1088
	});
1089

    
1090
	$('#selectAll').click(function() {
1091
		var checkedStatus = this.checked;
1092
		$('#ruletable tbody tr').find('td:first :checkbox').each(function() {
1093
		$(this).prop('checked', checkedStatus);
1094
		});
1095
	});
1096
});
1097
//]]>
1098
</script>
1099

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