Project

General

Profile

Download (35.6 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-2020 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) {
47

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

    
51
	$arr = array();
52
	foreach ($rules as $rule) {
53
		if ($rule['tracker'] === $tracker) {
54
			$arr[] = $rule;
55
		}
56
	}
57

    
58
	if (count($arr) == 0)
59
		return (NULL);
60

    
61
	return ($arr);
62
}
63

    
64
function print_states($tracker) {
65
	global $rulescnt;
66

    
67
	$rulesid = "";
68
	$bytes = 0;
69
	$states = 0;
70
	$packets = 0;
71
	$evaluations = 0;
72
	$stcreations = 0;
73
	$rules = get_pf_rules($rulescnt, $tracker);
74
	if (is_array($rules)) {
75
		foreach ($rules as $rule) {
76
			$bytes += $rule['bytes'];
77
			$states += $rule['states'];
78
			$packets += $rule['packets'];
79
			$evaluations += $rule['evaluations'];
80
			$stcreations += $rule['state creations'];
81
			if (strlen($rulesid) > 0) {
82
				$rulesid .= ",";
83
			}
84
			$rulesid .= "{$rule['id']}";
85
		}
86
	}
87

    
88
	$trackertext = !empty($tracker) ? "Tracking ID: {$tracker}<br>" : "";
89
	printf("<a href=\"diag_dump_states.php?ruleid=%s\" data-toggle=\"popover\" data-trigger=\"hover focus\" title=\"%s\" ",
90
	    $rulesid, gettext("States details"));
91
	printf("data-content=\"{$trackertext}evaluations: %s<br>packets: %s<br>bytes: %s<br>states: %s<br>state creations: %s\" data-html=\"true\" usepost>",
92
	    format_number($evaluations), format_number($packets), format_bytes($bytes),
93
	    format_number($states), format_number($stcreations));
94
	printf("%s/%s</a><br>", format_number($states), format_bytes($bytes));
95
}
96

    
97
function delete_nat_association($id) {
98
	global $config;
99

    
100
	if (!$id || !is_array($config['nat']['rule'])) {
101
		return;
102
	}
103

    
104
	$a_nat = &$config['nat']['rule'];
105

    
106
	foreach ($a_nat as &$natent) {
107
		if ($natent['associated-rule-id'] == $id) {
108
			$natent['associated-rule-id'] = '';
109
		}
110
	}
111
}
112

    
113
init_config_arr(array('filter', 'rule'));
114
filter_rules_sort();
115
$a_filter = &$config['filter']['rule'];
116

    
117
if ($_REQUEST['if']) {
118
	$if = $_REQUEST['if'];
119
}
120

    
121
$ifdescs = get_configured_interface_with_descr();
122

    
123
$iflist = filter_get_interface_list();
124

    
125
if (!$if || !isset($iflist[$if])) {
126
	if ($if != "any" && $if != "FloatingRules" && isset($iflist['wan'])) {
127
		$if = "wan";
128
	} else {
129
		$if = "FloatingRules";
130
	}
131
}
132

    
133
if ($_POST['apply']) {
134
	$retval = 0;
135
	$retval |= filter_configure();
136

    
137
	clear_subsystem_dirty('filter');
138
}
139

    
140
if ($_POST['act'] == "del") {
141
	if ($a_filter[$_POST['id']]) {
142
		if (!empty($a_filter[$_POST['id']]['associated-rule-id'])) {
143
			delete_nat_association($a_filter[$_POST['id']]['associated-rule-id']);
144
		}
145
		unset($a_filter[$_POST['id']]);
146

    
147
		// Update the separators
148
		init_config_arr(array('filter', 'separator', strtolower($if)));
149
		$a_separators = &$config['filter']['separator'][strtolower($if)];
150
		$ridx = ifridx($if, $_POST['id']);	// get rule index within interface
151
		$mvnrows = -1;
152
		move_separators($a_separators, $ridx, $mvnrows);
153

    
154
		if (write_config(gettext("Firewall: Rules - deleted a firewall rule."))) {
155
			mark_subsystem_dirty('filter');
156
		}
157

    
158
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
159
		exit;
160
	}
161
}
162

    
163
// Handle save msg if defined
164
if ($_REQUEST['savemsg']) {
165
	$savemsg = htmlentities($_REQUEST['savemsg']);
166
}
167

    
168
if (isset($_POST['del_x'])) {
169
	/* delete selected rules */
170
	$deleted = false;
171

    
172
	if (is_array($_POST['rule']) && count($_POST['rule'])) {
173
		init_config_arr(array('filter', 'separator', strtolower($if)));
174
		$a_separators = &$config['filter']['separator'][strtolower($if)];
175
		$num_deleted = 0;
176

    
177
		foreach ($_POST['rule'] as $rulei) {
178
			delete_nat_association($a_filter[$rulei]['associated-rule-id']);
179
			unset($a_filter[$rulei]);
180
			$deleted = true;
181

    
182
			// Update the separators
183
			// As rules are deleted, $ridx has to be decremented or separator position will break
184
			$ridx = ifridx($if, $rulei) - $num_deleted;	// get rule index within interface
185
			$mvnrows = -1;
186
			move_separators($a_separators, $ridx, $mvnrows);
187
			$num_deleted++;
188
		}
189

    
190
		if ($deleted) {
191
			if (write_config(gettext("Firewall: Rules - deleted selected firewall rules."))) {
192
				mark_subsystem_dirty('filter');
193
			}
194
		}
195

    
196
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
197
		exit;
198
	}
199
} else if ($_POST['act'] == "toggle") {
200
	if ($a_filter[$_POST['id']]) {
201
		if (isset($a_filter[$_POST['id']]['disabled'])) {
202
			unset($a_filter[$_POST['id']]['disabled']);
203
			$wc_msg = gettext('Firewall: Rules - enabled a firewall rule.');
204
		} else {
205
			$a_filter[$_POST['id']]['disabled'] = true;
206
			$wc_msg = gettext('Firewall: Rules - disabled a firewall rule.');
207
		}
208
		if (write_config($wc_msg)) {
209
			mark_subsystem_dirty('filter');
210
		}
211

    
212
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
213
		exit;
214
	}
215
} else if ($_POST['order-store']) {
216

    
217
	/* update rule order, POST[rule] is an array of ordered IDs */
218
	if (is_array($_POST['rule']) && !empty($_POST['rule'])) {
219
		$a_filter_new = array();
220

    
221
		// Include the rules of other interfaces listed in config before this (the selected) interface.
222
		foreach ($a_filter as $filteri_before => $filterent) {
223
			if (($filterent['interface'] == $if && !isset($filterent['floating'])) || (isset($filterent['floating']) && "FloatingRules" == $if)) {
224
				break;
225
			} else {
226
				$a_filter_new[] = $filterent;
227
			}
228
		}
229

    
230
		// Include the rules of this (the selected) interface.
231
		// If a rule is not in POST[rule], it has been deleted by the user
232
		foreach ($_POST['rule'] as $id) {
233
			$a_filter_new[] = $a_filter[$id];
234
		}
235

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

    
248
		$a_filter = $a_filter_new;
249

    
250
		$config['filter']['separator'][strtolower($if)] = "";
251

    
252
		if ($_POST['separator']) {
253
			$idx = 0;
254
			if (!is_array($config['filter']['separator'])) {
255
				$config['filter']['separator'] = array();
256
			}
257

    
258
			foreach ($_POST['separator'] as $separator) {
259
				if (!is_array($config['filter']['separator'][strtolower($separator['if'])]))  {
260
					$config['filter']['separator'][strtolower($separator['if'])] = array();
261
				}
262

    
263
				$config['filter']['separator'][strtolower($separator['if'])]['sep' . $idx++] = $separator;
264
			}
265
		}
266

    
267
		if (write_config(gettext("Firewall: Rules - reordered firewall rules."))) {
268
			mark_subsystem_dirty('filter');
269
		}
270

    
271
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
272
		exit;
273
	}
274
}
275

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

    
278
foreach ($iflist as $ifent => $ifname) {
279
	$tab_array[] = array($ifname, ($ifent == $if), "firewall_rules.php?if={$ifent}");
280
}
281

    
282
foreach ($tab_array as $dtab) {
283
	if ($dtab[1]) {
284
		$bctab = $dtab[0];
285
		break;
286
	}
287
}
288

    
289
$pgtitle = array(gettext("Firewall"), gettext("Rules"), $bctab);
290
$pglinks = array("", "firewall_rules.php", "@self");
291
$shortcut_section = "firewall";
292

    
293
include("head.inc");
294
$nrules = 0;
295

    
296
if ($savemsg) {
297
	print_info_box($savemsg, 'success');
298
}
299

    
300
if ($_POST['apply']) {
301
	print_apply_result_box($retval);
302
}
303

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

    
308
display_top_tabs($tab_array, false, 'pills');
309

    
310
$showantilockout = false;
311
$showprivate = false;
312
$showblockbogons = false;
313

    
314
if (!isset($config['system']['webgui']['noantilockout']) &&
315
    (((count($config['interfaces']) > 1) && ($if == 'lan')) ||
316
    ((count($config['interfaces']) == 1) && ($if == 'wan')))) {
317
	$showantilockout = true;
318
}
319

    
320
if (isset($config['interfaces'][$if]['blockpriv'])) {
321
	$showprivate = true;
322
}
323

    
324
if (isset($config['interfaces'][$if]['blockbogons'])) {
325
	$showblockbogons = true;
326
}
327

    
328
if (isset($config['system']['webgui']['roworderdragging'])) {
329
	$rules_header_text = gettext("Rules");
330
} else {
331
	$rules_header_text = gettext("Rules (Drag to Change Order)");
332
}
333

    
334
/* Load the counter data of each pf rule. */
335
$rulescnt = pfSense_get_pf_rules();
336

    
337
// Update this if you add or remove columns!
338
$columns_in_table = 13;
339

    
340
/* Floating rules tab has one extra column
341
 * https://redmine.pfsense.org/issues/10667 */
342
if ($if == "FloatingRules") {
343
	$columns_in_table++;
344
}
345

    
346
?>
347
<!-- Allow table to scroll when dragging outside of the display window -->
348
<style>
349
.table-responsive {
350
    clear: both;
351
    overflow-x: visible;
352
    margin-bottom: 0px;
353
}
354
</style>
355

    
356
<form method="post">
357
	<input name="if" id="if" type="hidden" value="<?=$if?>" />
358
	<div class="panel panel-default">
359
		<div class="panel-heading"><h2 class="panel-title"><?=$rules_header_text?></h2></div>
360
		<div id="mainarea" class="table-responsive panel-body">
361
			<table id="ruletable" class="table table-hover table-striped table-condensed" style="overflow-x: 'visible'">
362
				<thead>
363
					<tr>
364
						<th><input type="checkbox" id="selectAll" name="selectAll" /></th>
365
						<th><!-- status icons --></th>
366
						<th><?=gettext("States")?></th>
367
				<?php
368
					if ('FloatingRules' == $if) {
369
				?>
370
						<th><?=gettext("Interfaces")?></th>
371
				<?php
372
					}
373
				?>
374
						<th><?=gettext("Protocol")?></th>
375
						<th><?=gettext("Source")?></th>
376
						<th><?=gettext("Port")?></th>
377
						<th><?=gettext("Destination")?></th>
378
						<th><?=gettext("Port")?></th>
379
						<th><?=gettext("Gateway")?></th>
380
						<th><?=gettext("Queue")?></th>
381
						<th><?=gettext("Schedule")?></th>
382
						<th><?=gettext("Description")?></th>
383
						<th><?=gettext("Actions")?></th>
384
					</tr>
385
				</thead>
386

    
387
<?php if ($showblockbogons || $showantilockout || $showprivate) :
388
?>
389
				<tbody>
390
<?php
391
		// 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.
392
		if ($showantilockout):
393
			$alports = implode('<br />', filter_get_antilockout_ports(true));
394
?>
395
					<tr id="antilockout">
396
						<td></td>
397
						<td title="<?=gettext("traffic is passed")?>"><i class="fa fa-check text-success"></i></td>
398
						<td><?php print_states(intval(ANTILOCKOUT_TRACKER)); ?></td>
399
						<td>*</td>
400
						<td>*</td>
401
						<td>*</td>
402
						<td><?=$iflist[$if];?> Address</td>
403
						<td><?=$alports?></td>
404
						<td>*</td>
405
						<td>*</td>
406
						<td></td>
407
						<td><?=gettext("Anti-Lockout Rule");?></td>
408
						<td>
409
							<a href="system_advanced_admin.php" title="<?=gettext("Settings");?>"><i class="fa fa-cog"></i></a>
410
						</td>
411
					</tr>
412
<?php 	endif;?>
413
<?php 	if ($showprivate): ?>
414
					<tr id="private">
415
						<td></td>
416
						<td title="<?=gettext("traffic is blocked")?>"><i class="fa fa-times text-danger"></i></td>
417
						<td><?php print_states(intval(RFC1918_TRACKER)); ?></td>
418
						<td>*</td>
419
						<td><?=gettext("RFC 1918 networks");?></td>
420
						<td>*</td>
421
						<td>*</td>
422
						<td>*</td>
423
						<td>*</td>
424
						<td>*</td>
425
						<td></td>
426
						<td><?=gettext("Block private networks");?></td>
427
						<td>
428
							<a href="interfaces.php?if=<?=htmlspecialchars($if)?>" title="<?=gettext("Settings");?>" usepost><i class="fa fa-cog"></i></a>
429
						</td>
430
					</tr>
431
<?php 	endif;?>
432
<?php 	if ($showblockbogons): ?>
433
					<tr id="bogons">
434
						<td></td>
435
						<td title="<?=gettext("traffic is blocked")?>"><i class="fa fa-times text-danger"></i></td>
436
						<td><?php print_states(intval(BOGONS_TRACKER)); ?></td>
437
						<td>*</td>
438
						<td><?=sprintf(gettext("Reserved%sNot assigned by IANA"), "<br />");?></td>
439
						<td>*</td>
440
						<td>*</td>
441
						<td>*</td>
442
						<td>*</td>
443
						<td>*</td>
444
						<td></td>
445
						<td><?=gettext("Block bogon networks");?></td>
446
						<td>
447
							<a href="interfaces.php?if=<?=htmlspecialchars($if)?>" title="<?=gettext("Settings");?>" usepost><i class="fa fa-cog"></i></a>
448
						</td>
449
					</tr>
450
<?php 	endif;?>
451
			</tbody>
452
<?php endif;?>
453
			<tbody class="user-entries">
454
<?php
455
$nrules = 0;
456
$separators = $config['filter']['separator'][strtolower($if)];
457

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

    
462
foreach ($a_filter as $filteri => $filterent):
463

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

    
466
		// Display separator(s) for section beginning at rule n
467
		if ($seprows[$nrules]) {
468
			display_separator($separators, $nrules, $columns_in_table);
469
		}
470
?>
471
					<tr id="fr<?=$nrules;?>" onClick="fr_toggle(<?=$nrules;?>)" ondblclick="document.location='firewall_rules_edit.php?id=<?=$filteri;?>';" <?=(isset($filterent['disabled']) ? ' class="disabled"' : '')?>>
472
						<td>
473
							<input type="checkbox" id="frc<?=$nrules;?>" onClick="fr_toggle(<?=$nrules;?>)" name="rule[]" value="<?=$filteri;?>"/>
474
						</td>
475

    
476
	<?php
477
		if ($filterent['type'] == "block") {
478
			$iconfn = "times text-danger";
479
			$title_text = gettext("traffic is blocked");
480
		} else if ($filterent['type'] == "reject") {
481
			$iconfn = "hand-stop-o text-warning";
482
			$title_text = gettext("traffic is rejected");
483
		} else if ($filterent['type'] == "match") {
484
			$iconfn = "filter";
485
			$title_text = gettext("traffic is matched");
486
		} else {
487
			$iconfn = "check text-success";
488
			$title_text = gettext("traffic is passed");
489
		}
490
	?>
491
						<td title="<?=$title_text?>">
492
							<a href="?if=<?=htmlspecialchars($if);?>&amp;act=toggle&amp;id=<?=$filteri;?>" usepost>
493
								<i class="fa fa-<?=$iconfn?>" title="<?=gettext("click to toggle enabled/disabled status");?>"></i>
494
							</a>
495
	<?php
496
		if ($filterent['quick'] == 'yes') {
497
			print '<i class="fa fa-forward text-success" title="'. gettext("&quot;Quick&quot; rule. Applied immediately on match.") .'" style="cursor: pointer;"></i>';
498
		}
499

    
500
		$isadvset = firewall_check_for_advanced_options($filterent);
501
		if ($isadvset) {
502
			print '<i class="fa fa-cog" title="'. gettext("advanced setting") .': '. $isadvset .'"></i>';
503
		}
504

    
505
		if (isset($filterent['log'])) {
506
			print '<i class="fa fa-tasks" title="'. gettext("traffic is logged") .'" style="cursor: pointer;"></i>';
507
		}
508
	?>
509
						</td>
510
	<?php
511
		$alias = rule_columns_with_alias(
512
			$filterent['source']['address'],
513
			pprint_port($filterent['source']['port']),
514
			$filterent['destination']['address'],
515
			pprint_port($filterent['destination']['port'])
516
		);
517

    
518
		//build Schedule popup box
519
		init_config_arr(array('schedules', 'schedule'));
520
		$a_schedules = &$config['schedules']['schedule'];
521
		$schedule_span_begin = "";
522
		$schedule_span_end = "";
523
		$sched_caption_escaped = "";
524
		$sched_content = "";
525
		$schedstatus = false;
526
		$dayArray = array (gettext('Mon'), gettext('Tues'), gettext('Wed'), gettext('Thur'), gettext('Fri'), gettext('Sat'), gettext('Sun'));
527
		$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'));
528
		if ($config['schedules']['schedule'] != "" && is_array($config['schedules']['schedule'])) {
529
			$idx = 0;
530
			foreach ($a_schedules as $schedule) {
531
				if (!empty($schedule['name']) &&
532
				    $schedule['name'] == $filterent['sched']) {
533
					$schedstatus = filter_get_time_based_rule_status($schedule);
534

    
535
					foreach ($schedule['timerange'] as $timerange) {
536
						$tempFriendlyTime = "";
537
						$tempID = "";
538
						$firstprint = false;
539
						if ($timerange) {
540
							$dayFriendly = "";
541
							$tempFriendlyTime = "";
542

    
543
							//get hours
544
							$temptimerange = $timerange['hour'];
545
							$temptimeseparator = strrpos($temptimerange, "-");
546

    
547
							$starttime = substr ($temptimerange, 0, $temptimeseparator);
548
							$stoptime = substr ($temptimerange, $temptimeseparator+1);
549

    
550
							if ($timerange['month']) {
551
								$tempmontharray = explode(",", $timerange['month']);
552
								$tempdayarray = explode(",", $timerange['day']);
553
								$arraycounter = 0;
554
								$firstDayFound = false;
555
								$firstPrint = false;
556
								foreach ($tempmontharray as $monthtmp) {
557
									$month = $tempmontharray[$arraycounter];
558
									$day = $tempdayarray[$arraycounter];
559

    
560
									if (!$firstDayFound) {
561
										$firstDay = $day;
562
										$firstmonth = $month;
563
										$firstDayFound = true;
564
									}
565

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

    
736
		if (isset($filterent['protocol'])) {
737
			echo strtoupper($filterent['protocol']);
738

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

    
851
// There can be separator(s) after the last rule listed.
852
if ($seprows[$nrules]) {
853
	display_separator($separators, $nrules, $columns_in_table);
854
}
855
?>
856
				</tbody>
857
			</table>
858
		</div>
859
	</div>
860

    
861
<?php if ($nrules == 0): ?>
862
	<div class="alert alert-warning" role="alert">
863
		<p>
864
		<?php if ($_REQUEST['if'] == "FloatingRules"): ?>
865
			<?=gettext("No floating rules are currently defined.");?>
866
		<?php else: ?>
867
			<?=gettext("No rules are currently defined for this interface");?><br />
868
			<?=gettext("All incoming connections on this interface will be blocked until pass rules are added.");?>
869
		<?php endif;?>
870
			<?=gettext("Click the button to add a new rule.");?>
871
		</p>
872
	</div>
873
<?php endif;?>
874

    
875
	<nav class="action-buttons">
876
		<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')?>">
877
			<i class="fa fa-level-up icon-embed-btn"></i>
878
			<?=gettext("Add");?>
879
		</a>
880
		<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')?>">
881
			<i class="fa fa-level-down icon-embed-btn"></i>
882
			<?=gettext("Add");?>
883
		</a>
884
		<button name="del_x" type="submit" class="btn btn-danger btn-sm" value="<?=gettext("Delete selected rules"); ?>" title="<?=gettext('Delete selected rules')?>">
885
			<i class="fa fa-trash icon-embed-btn"></i>
886
			<?=gettext("Delete"); ?>
887
		</button>
888
		<button type="submit" id="order-store" name="order-store" class="btn btn-sm btn-primary" value="store changes" disabled title="<?=gettext('Save rule order')?>">
889
			<i class="fa fa-save icon-embed-btn"></i>
890
			<?=gettext("Save")?>
891
		</button>
892
		<button type="submit" id="addsep" name="addsep" class="btn btn-sm btn-warning" title="<?=gettext('Add separator')?>">
893
			<i class="fa fa-plus icon-embed-btn"></i>
894
			<?=gettext("Separator")?>
895
		</button>
896
	</nav>
897
</form>
898

    
899
<div class="infoblock">
900
	<div class="alert alert-info clearfix" role="alert"><div class="pull-left">
901
		<dl class="dl-horizontal responsive">
902
		<!-- Legend -->
903
			<dt><?=gettext('Legend')?></dt>				<dd></dd>
904
			<dt><i class="fa fa-check text-success"></i></dt>		<dd><?=gettext("Pass");?></dd>
905
			<dt><i class="fa fa-filter"></i></dt>	<dd><?=gettext("Match");?></dd>
906
			<dt><i class="fa fa-times text-danger"></i></dt>	<dd><?=gettext("Block");?></dd>
907
			<dt><i class="fa fa-hand-stop-o text-warning"></i></dt>		<dd><?=gettext("Reject");?></dd>
908
			<dt><i class="fa fa-tasks"></i></dt>	<dd> <?=gettext("Log");?></dd>
909
			<dt><i class="fa fa-cog"></i></dt>		<dd> <?=gettext("Advanced filter");?></dd>
910
			<dt><i class="fa fa-forward text-success"></i></dt><dd> <?=gettext("&quot;Quick&quot; rule. Applied immediately on match.")?></dd>
911
		</dl>
912

    
913
<?php
914
	if ("FloatingRules" != $if) {
915
		print(gettext("Rules are evaluated on a first-match basis (i.e. " .
916
			"the action of the first rule to match a packet will be executed). ") . '<br />' .
917
			gettext("This means that if block rules are used, it is important to pay attention " .
918
			"to the rule order. Everything that isn't explicitly passed is blocked " .
919
			"by default. "));
920
	} else {
921
		print(gettext("Floating rules are evaluated on a first-match basis (i.e. " .
922
			"the action of the first rule to match a packet will be executed) only " .
923
			"if the 'quick' option is checked on a rule. Otherwise they will only match if no " .
924
			"other rules match. Pay close attention to the rule order and options " .
925
			"chosen. If no rule here matches, the per-interface or default rules are used. "));
926
	}
927

    
928
	printf(gettext('%1$sClick the anchor icon %2$s to move checked rules before the clicked row. Hold down ' .
929
			'the shift key and click to move the rules after the clicked row.'), '<br /><br />', '<i class="fa fa-anchor"></i>')
930
?>
931
	</div>
932
	</div>
933
</div>
934

    
935
<script type="text/javascript">
936
//<![CDATA[
937

    
938
//Need to create some variables here so that jquery/pfSenseHelpers.js can read them
939
iface = "<?=strtolower($if)?>";
940
cncltxt = '<?=gettext("Cancel")?>';
941
svtxt = '<?=gettext("Save")?>';
942
svbtnplaceholder = '<?=gettext("Enter a description, Save, then drag to final location.")?>';
943
configsection = "filter";
944

    
945
events.push(function() {
946

    
947
	// "Move to here" (anchor) action
948
	$('[id^=Xmove_]').click(function (event) {
949

    
950
		// Prevent click from toggling row
951
		event.stopImmediatePropagation();
952

    
953
		// Save the target rule position
954
		var anchor_row = $(this).parents("tr:first");
955

    
956
		if (event.shiftKey) {
957
			$($('#ruletable > tbody  > tr').get().reverse()).each(function() {
958
				ruleid = this.id.slice(2);
959

    
960
				if (ruleid && !isNaN(ruleid)) {
961
					if ($('#frc' + ruleid).prop('checked')) {
962
						// Move the selected rows, un-select them and add highlight class
963
						$(this).insertAfter(anchor_row);
964
						fr_toggle(ruleid, "fr");
965
						$('#fr' + ruleid).addClass("highlight");
966
					}
967
				}
968
			});
969
		} else {
970
			$('#ruletable > tbody  > tr').each(function() {
971
				ruleid = this.id.slice(2);
972

    
973
				if (ruleid && !isNaN(ruleid)) {
974
					if ($('#frc' + ruleid).prop('checked')) {
975
						// Move the selected rows, un-select them and add highlight class
976
						$(this).insertBefore(anchor_row);
977
						fr_toggle(ruleid, "fr");
978
						$('#fr' + ruleid).addClass("highlight");
979
					}
980
				}
981
			});
982
		}
983

    
984
		// Temporarily set background color so user can more easily see the moved rules, then fade
985
		$('.highlight').effect("highlight", {color: "#739b4b;"}, 4000);
986
		$('#ruletable tr').removeClass("highlight");
987
		$('#order-store').removeAttr('disabled');
988
		reindex_rules($(anchor_row).parent('tbody'));
989
		dirty = true;
990
	}).mouseover(function(e) {
991
		var ruleselected = false;
992

    
993
		$(this).css("cursor", "default");
994

    
995
		// Are any rules currently selected?
996
		$('[id^=frc]').each(function () {
997
			if ($(this).prop("checked")) {
998
				ruleselected = true;
999
			}
1000
		});
1001

    
1002
		// If so, change the icon to show the insertion point
1003
		if (ruleselected) {
1004
			if (e.shiftKey) {
1005
				$(this).removeClass().addClass("fa fa-lg fa-arrow-down text-danger");
1006
			} else {
1007
				$(this).removeClass().addClass("fa fa-lg fa-arrow-up text-danger");
1008
			}
1009
		}
1010
	}).mouseout(function(e) {
1011
		$(this).removeClass().addClass("fa fa-anchor");
1012
	});
1013

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

    
1019
	$('table tbody.user-entries').sortable({
1020
		cursor: 'grabbing',
1021
		scroll: true,
1022
		overflow: 'scroll',
1023
		scrollSensitivity: 100,
1024
		update: function(event, ui) {
1025
			$('#order-store').removeAttr('disabled');
1026
			reindex_rules(ui.item.parent('tbody'));
1027
			dirty = true;
1028
		}
1029
	});
1030

    
1031
	$('table tbody.user-entries').show();
1032
<?php endif; ?>
1033

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

    
1038
		// Save the separator bar configuration
1039
		save_separators();
1040

    
1041
		// Suppress the "Do you really want to leave the page" message
1042
		saving = true;
1043
	});
1044

    
1045
	// Provide a warning message if the user tries to change page before saving
1046
	$(window).bind('beforeunload', function(){
1047
		if ((!saving && dirty) || newSeperator) {
1048
			return ("<?=gettext('One or more rules have been moved but have not yet been saved')?>");
1049
		} else {
1050
			return undefined;
1051
		}
1052
	});
1053

    
1054
	$(document).on('keyup keydown', function(e){
1055
		if (e.shiftKey) {
1056
			$('[id^=Xmove_]').attr("title", "<?=$ShXmoveTitle?>");
1057
		} else {
1058
			$('[id^=Xmove_]').attr("title", "<?=$XmoveTitle?>");
1059
		}
1060
	});
1061

    
1062
	$('#selectAll').click(function() {
1063
		var checkedStatus = this.checked;
1064
		$('#ruletable tbody tr').find('td:first :checkbox').each(function() {
1065
		$(this).prop('checked', checkedStatus);
1066
		});
1067
	});
1068
});
1069
//]]>
1070
</script>
1071

    
1072
<?php include("foot.inc");?>
(51-51/230)