Project

General

Profile

Download (33.4 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-2018 Rubicon Communications, LLC (Netgate)
7
 * All rights reserved.
8
 *
9
 * originally based on m0n0wall (http://m0n0.ch/wall)
10
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
11
 * All rights reserved.
12
 *
13
 * Licensed under the Apache License, Version 2.0 (the "License");
14
 * you may not use this file except in compliance with the License.
15
 * You may obtain a copy of the License at
16
 *
17
 * http://www.apache.org/licenses/LICENSE-2.0
18
 *
19
 * Unless required by applicable law or agreed to in writing, software
20
 * distributed under the License is distributed on an "AS IS" BASIS,
21
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
 * See the License for the specific language governing permissions and
23
 * limitations under the License.
24
 */
25

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

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

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

    
42
$shortcut_section = "firewall";
43

    
44
function get_pf_rules($rules, $tracker) {
45

    
46
	if ($rules == NULL || !is_array($rules))
47
		return (NULL);
48

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

    
56
	if (count($arr) == 0)
57
		return (NULL);
58

    
59
	return ($arr);
60
}
61

    
62
function print_states($tracker) {
63
	global $rulescnt;
64

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

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

    
95
function delete_nat_association($id) {
96
	global $config;
97

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

    
102
	$a_nat = &$config['nat']['rule'];
103

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

    
111
if (!is_array($config['filter'])) {
112
	$config['filter'] = array();
113
}
114

    
115
if (!is_array($config['filter']['rule'])) {
116
	$config['filter']['rule'] = array();
117
}
118

    
119
filter_rules_sort();
120
$a_filter = &$config['filter']['rule'];
121

    
122
if ($_REQUEST['if']) {
123
	$if = $_REQUEST['if'];
124
}
125

    
126
$ifdescs = get_configured_interface_with_descr();
127

    
128
$iflist = filter_get_interface_list();
129

    
130
if (!$if || !isset($iflist[$if])) {
131
	if ($if != "any" && $if != "FloatingRules" && isset($iflist['wan'])) {
132
		$if = "wan";
133
	} else {
134
		$if = "FloatingRules";
135
	}
136
}
137

    
138
if ($_POST['apply']) {
139
	$retval = 0;
140
	$retval |= filter_configure();
141

    
142
	clear_subsystem_dirty('filter');
143
}
144

    
145
if ($_POST['act'] == "del") {
146
	if ($a_filter[$_POST['id']]) {
147
		if (!empty($a_filter[$_POST['id']]['associated-rule-id'])) {
148
			delete_nat_association($a_filter[$_POST['id']]['associated-rule-id']);
149
		}
150
		unset($a_filter[$_POST['id']]);
151

    
152
		// Update the separators
153
		$a_separators = &$config['filter']['separator'][strtolower($if)];
154
		$ridx = ifridx($if, $_POST['id']);	// get rule index within interface
155
		$mvnrows = -1;
156
		move_separators($a_separators, $ridx, $mvnrows);
157

    
158
		if (write_config(gettext("Firewall: Rules - deleted a firewall rule."))) {
159
			mark_subsystem_dirty('filter');
160
		}
161

    
162
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
163
		exit;
164
	}
165
}
166

    
167
// Handle save msg if defined
168
if ($_REQUEST['savemsg']) {
169
	$savemsg = htmlentities($_REQUEST['savemsg']);
170
}
171

    
172
if (isset($_POST['del_x'])) {
173
	/* delete selected rules */
174
	$deleted = false;
175

    
176
	if (is_array($_POST['rule']) && count($_POST['rule'])) {
177
		$a_separators = &$config['filter']['separator'][strtolower($if)];
178
		$num_deleted = 0;
179

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

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

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

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

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

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

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

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

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

    
251
		$a_filter = $a_filter_new;
252

    
253
		$config['filter']['separator'][strtolower($if)] = "";
254

    
255
		if ($_POST['separator']) {
256
			$idx = 0;
257
			if (!is_array($config['filter']['separator'])) {
258
				$config['filter']['separator'] = array();
259
			}
260

    
261
			foreach ($_POST['separator'] as $separator) {
262
				if (!is_array($config['filter']['separator'][strtolower($separator['if'])]))  {
263
					$config['filter']['separator'][strtolower($separator['if'])] = array();
264
				}
265

    
266
				$config['filter']['separator'][strtolower($separator['if'])]['sep' . $idx++] = $separator;
267
			}
268
		}
269

    
270
		if (write_config(gettext("Firewall: Rules - reordered firewall rules."))) {
271
			mark_subsystem_dirty('filter');
272
		}
273

    
274
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
275
		exit;
276
	}
277
}
278

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

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

    
285
foreach ($tab_array as $dtab) {
286
	if ($dtab[1]) {
287
		$bctab = $dtab[0];
288
		break;
289
	}
290
}
291

    
292
$pgtitle = array(gettext("Firewall"), gettext("Rules"), $bctab);
293
$pglinks = array("", "firewall_rules.php", "@self");
294
$shortcut_section = "firewall";
295

    
296
include("head.inc");
297
$nrules = 0;
298

    
299
if ($savemsg) {
300
	print_info_box($savemsg, 'success');
301
}
302

    
303
if ($_POST['apply']) {
304
	print_apply_result_box($retval);
305
}
306

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

    
311
display_top_tabs($tab_array, false, 'pills');
312

    
313
$showantilockout = false;
314
$showprivate = false;
315
$showblockbogons = false;
316

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

    
323
if (isset($config['interfaces'][$if]['blockpriv'])) {
324
	$showprivate = true;
325
}
326

    
327
if (isset($config['interfaces'][$if]['blockbogons'])) {
328
	$showblockbogons = true;
329
}
330

    
331
/* Load the counter data of each pf rule. */
332
$rulescnt = pfSense_get_pf_rules();
333

    
334
// Update this if you add or remove columns!
335
$columns_in_table = 13;
336

    
337
?>
338
<!-- Allow table to scroll when dragging outside of the display window -->
339
<style>
340
.table-responsive {
341
    clear: both;
342
    overflow-x: visible;
343
    margin-bottom: 0px;
344
}
345
</style>
346

    
347
<form method="post">
348
	<input name="if" id="if" type="hidden" value="<?=$if?>" />
349
	<div class="panel panel-default">
350
		<div class="panel-heading"><h2 class="panel-title"><?=gettext("Rules (Drag to Change Order)")?></h2></div>
351
		<div id="mainarea" class="table-responsive panel-body">
352
			<table id="ruletable" class="table table-hover table-striped table-condensed" style="overflow-x: 'visible'">
353
				<thead>
354
					<tr>
355
						<th><input type="checkbox" id="selectAll" name="selectAll" /></th>
356
						<th><!-- status icons --></th>
357
						<th><?=gettext("States")?></th>
358
						<th><?=gettext("Protocol")?></th>
359
						<th><?=gettext("Source")?></th>
360
						<th><?=gettext("Port")?></th>
361
						<th><?=gettext("Destination")?></th>
362
						<th><?=gettext("Port")?></th>
363
						<th><?=gettext("Gateway")?></th>
364
						<th><?=gettext("Queue")?></th>
365
						<th><?=gettext("Schedule")?></th>
366
						<th><?=gettext("Description")?></th>
367
						<th><?=gettext("Actions")?></th>
368
					</tr>
369
				</thead>
370

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

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

    
446
foreach ($a_filter as $filteri => $filterent):
447

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

    
450
		// Display separator(s) for section beginning at rule n
451
		if ($seprows[$nrules]) {
452
			display_separator($separators, $nrules, $columns_in_table);
453
		}
454
?>
455
					<tr id="fr<?=$nrules;?>" onClick="fr_toggle(<?=$nrules;?>)" ondblclick="document.location='firewall_rules_edit.php?id=<?=$filteri;?>';" <?=(isset($filterent['disabled']) ? ' class="disabled"' : '')?>>
456
						<td>
457
							<input type="checkbox" id="frc<?=$nrules;?>" onClick="fr_toggle(<?=$nrules;?>)" name="rule[]" value="<?=$filteri;?>"/>
458
						</td>
459

    
460
	<?php
461
		if ($filterent['type'] == "block") {
462
			$iconfn = "times text-danger";
463
			$title_text = gettext("traffic is blocked");
464
		} else if ($filterent['type'] == "reject") {
465
			$iconfn = "hand-stop-o text-warning";
466
			$title_text = gettext("traffic is rejected");
467
		} else if ($filterent['type'] == "match") {
468
			$iconfn = "filter";
469
			$title_text = gettext("traffic is matched");
470
		} else {
471
			$iconfn = "check text-success";
472
			$title_text = gettext("traffic is passed");
473
		}
474
	?>
475
						<td title="<?=$title_text?>">
476
							<a href="?if=<?=htmlspecialchars($if);?>&amp;act=toggle&amp;id=<?=$filteri;?>" usepost>
477
								<i class="fa fa-<?=$iconfn?>" title="<?=gettext("click to toggle enabled/disabled status");?>"></i>
478
							</a>
479
	<?php
480
		if ($filterent['quick'] == 'yes') {
481
			print '<i class="fa fa-forward text-success" title="'. gettext("&quot;Quick&quot; rule. Applied immediately on match.") .'" style="cursor: pointer;"></i>';
482
		}
483

    
484
		$isadvset = firewall_check_for_advanced_options($filterent);
485
		if ($isadvset) {
486
			print '<i class="fa fa-cog" title="'. gettext("advanced setting") .': '. $isadvset .'"></i>';
487
		}
488

    
489
		if (isset($filterent['log'])) {
490
			print '<i class="fa fa-tasks" title="'. gettext("traffic is logged") .'" style="cursor: pointer;"></i>';
491
		}
492
	?>
493
						</td>
494
	<?php
495
		$alias = rule_columns_with_alias(
496
			$filterent['source']['address'],
497
			pprint_port($filterent['source']['port']),
498
			$filterent['destination']['address'],
499
			pprint_port($filterent['destination']['port'])
500
		);
501

    
502
		if (!is_array($config['schedules'])) {
503
			$config['schedules'] = array();
504
		}
505

    
506
		if (!is_array($config['schedules']['schedule'])) {
507
			$config['schedules']['schedule'] = array();
508
		}
509
		//build Schedule popup box
510
		$a_schedules = &$config['schedules']['schedule'];
511
		$schedule_span_begin = "";
512
		$schedule_span_end = "";
513
		$sched_caption_escaped = "";
514
		$sched_content = "";
515
		$schedstatus = false;
516
		$dayArray = array (gettext('Mon'), gettext('Tues'), gettext('Wed'), gettext('Thur'), gettext('Fri'), gettext('Sat'), gettext('Sun'));
517
		$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'));
518
		if ($config['schedules']['schedule'] != "" && is_array($config['schedules']['schedule'])) {
519
			$idx = 0;
520
			foreach ($a_schedules as $schedule) {
521
				if ($schedule['name'] == $filterent['sched']) {
522
					$schedstatus = filter_get_time_based_rule_status($schedule);
523

    
524
					foreach ($schedule['timerange'] as $timerange) {
525
						$tempFriendlyTime = "";
526
						$tempID = "";
527
						$firstprint = false;
528
						if ($timerange) {
529
							$dayFriendly = "";
530
							$tempFriendlyTime = "";
531

    
532
							//get hours
533
							$temptimerange = $timerange['hour'];
534
							$temptimeseparator = strrpos($temptimerange, "-");
535

    
536
							$starttime = substr ($temptimerange, 0, $temptimeseparator);
537
							$stoptime = substr ($temptimerange, $temptimeseparator+1);
538

    
539
							if ($timerange['month']) {
540
								$tempmontharray = explode(",", $timerange['month']);
541
								$tempdayarray = explode(",", $timerange['day']);
542
								$arraycounter = 0;
543
								$firstDayFound = false;
544
								$firstPrint = false;
545
								foreach ($tempmontharray as $monthtmp) {
546
									$month = $tempmontharray[$arraycounter];
547
									$day = $tempdayarray[$arraycounter];
548

    
549
									if (!$firstDayFound) {
550
										$firstDay = $day;
551
										$firstmonth = $month;
552
										$firstDayFound = true;
553
									}
554

    
555
									$currentDay = $day;
556
									$nextDay = $tempdayarray[$arraycounter+1];
557
									$currentDay++;
558
									if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])) {
559
										if ($firstPrint) {
560
											$dayFriendly .= ", ";
561
										}
562
										$currentDay--;
563
										if ($currentDay != $firstDay) {
564
											$dayFriendly .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
565
										} else {
566
											$dayFriendly .=	 $monthArray[$month-1] . " " . $day;
567
										}
568
										$firstDayFound = false;
569
										$firstPrint = true;
570
									}
571
									$arraycounter++;
572
								}
573
							} else {
574
								$tempdayFriendly = $timerange['position'];
575
								$firstDayFound = false;
576
								$tempFriendlyDayArray = explode(",", $tempdayFriendly);
577
								$currentDay = "";
578
								$firstDay = "";
579
								$nextDay = "";
580
								$counter = 0;
581
								foreach ($tempFriendlyDayArray as $day) {
582
									if ($day != "") {
583
										if (!$firstDayFound) {
584
											$firstDay = $tempFriendlyDayArray[$counter];
585
											$firstDayFound = true;
586
										}
587
										$currentDay =$tempFriendlyDayArray[$counter];
588
										//get next day
589
										$nextDay = $tempFriendlyDayArray[$counter+1];
590
										$currentDay++;
591
										if ($currentDay != $nextDay) {
592
											if ($firstprint) {
593
												$dayFriendly .= ", ";
594
											}
595
											$currentDay--;
596
											if ($currentDay != $firstDay) {
597
												$dayFriendly .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
598
											} else {
599
												$dayFriendly .= $dayArray[$firstDay-1];
600
											}
601
											$firstDayFound = false;
602
											$firstprint = true;
603
										}
604
										$counter++;
605
									}
606
								}
607
							}
608
							$timeFriendly = $starttime . " - " . $stoptime;
609
							$description = $timerange['rangedescr'];
610
							$sched_content .= $dayFriendly . "; " . $timeFriendly . "<br />";
611
						}
612
					}
613
					#FIXME
614
					$sched_caption_escaped = str_replace("'", "\'", $schedule['descr']);
615
					$schedule_span_begin = '<a href="/firewall_schedule_edit.php?id=' . $idx . '" data-toggle="popover" data-trigger="hover focus" title="' . $schedule['name'] . '" data-content="' .
616
						$sched_caption_escaped . '" data-html="true">';
617
					$schedule_span_end = "</a>";
618
				}
619
				$idx++;
620
			}
621
		}
622
		$printicon = false;
623
		$alttext = "";
624
		$image = "";
625
		if (!isset($filterent['disabled'])) {
626
			if ($schedstatus) {
627
				if ($filterent['type'] == "block" || $filterent['type'] == "reject") {
628
					$image = "times-circle";
629
					$dispcolor = "text-danger";
630
					$alttext = gettext("Traffic matching this rule is currently being denied");
631
				} else {
632
					$image = "play-circle";
633
					$dispcolor = "text-success";
634
					$alttext = gettext("Traffic matching this rule is currently being allowed");
635
				}
636
				$printicon = true;
637
			} else if ($filterent['sched']) {
638
				if ($filterent['type'] == "block" || $filterent['type'] == "reject") {
639
					$image = "times-circle";
640
				} else {
641
					$image = "play-circle";
642
				}
643
				$alttext = gettext("This rule is not currently active because its period has expired");
644
				$dispcolor = "text-warning";
645
				$printicon = true;
646
			}
647
		}
648
	?>
649
				<td><?php print_states(intval($filterent['tracker'])); ?></td>
650
				<td>
651
	<?php
652
		if (isset($filterent['ipprotocol'])) {
653
			switch ($filterent['ipprotocol']) {
654
				case "inet":
655
					echo "IPv4 ";
656
					break;
657
				case "inet6":
658
					echo "IPv6 ";
659
					break;
660
				case "inet46":
661
					echo "IPv4+6 ";
662
					break;
663
			}
664
		} else {
665
			echo "IPv4 ";
666
		}
667

    
668
		if (isset($filterent['protocol'])) {
669
			echo strtoupper($filterent['protocol']);
670

    
671
			if (strtoupper($filterent['protocol']) == "ICMP" && !empty($filterent['icmptype'])) {
672
				// replace each comma-separated icmptype item by its (localised) full description
673
				$t = 	implode(', ',
674
						array_map(
675
						        function($type) {
676
								global $icmptypes;
677
								return $icmptypes[$type]['descrip'];
678
							},
679
							explode(',', $filterent['icmptype'])
680
						)
681
					);
682
				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']));
683
			}
684
		} else {
685
			echo " *";
686
		}
687
	?>
688
						</td>
689
						<td>
690
							<?php if (isset($alias['src'])): ?>
691
								<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">
692
									<?=str_replace('_', '_<wbr>', htmlspecialchars(pprint_address($filterent['source'])))?>
693
								</a>
694
							<?php else: ?>
695
								<?=htmlspecialchars(pprint_address($filterent['source']))?>
696
							<?php endif; ?>
697
						</td>
698
						<td>
699
							<?php if (isset($alias['srcport'])): ?>
700
								<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">
701
									<?=str_replace('_', '_<wbr>', htmlspecialchars(pprint_port($filterent['source']['port'])))?>
702
								</a>
703
							<?php else: ?>
704
								<?=htmlspecialchars(pprint_port($filterent['source']['port']))?>
705
							<?php endif; ?>
706
						</td>
707
						<td>
708
							<?php if (isset($alias['dst'])): ?>
709
								<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">
710
									<?=str_replace('_', '_<wbr>', htmlspecialchars(pprint_address($filterent['destination'])))?>
711
								</a>
712
							<?php else: ?>
713
								<?=htmlspecialchars(pprint_address($filterent['destination']))?>
714
							<?php endif; ?>
715
						</td>
716
						<td>
717
							<?php if (isset($alias['dstport'])): ?>
718
								<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">
719
									<?=str_replace('_', '_<wbr>', htmlspecialchars(pprint_port($filterent['destination']['port'])))?>
720
								</a>
721
							<?php else: ?>
722
								<?=htmlspecialchars(pprint_port($filterent['destination']['port']))?>
723
							<?php endif; ?>
724
						</td>
725
						<td>
726
							<?php if (isset($config['interfaces'][$filterent['gateway']]['descr'])):?>
727
								<?=str_replace('_', '_<wbr>', htmlspecialchars($config['interfaces'][$filterent['gateway']]['descr']))?>
728
							<?php else: ?>
729
								<?=htmlspecialchars(pprint_port($filterent['gateway']))?>
730
							<?php endif; ?>
731
						</td>
732
						<td>
733
							<?php
734
								if (isset($filterent['ackqueue']) && isset($filterent['defaultqueue'])) {
735
									$desc = str_replace('_', ' ', $filterent['ackqueue']);
736
									echo "<a href=\"firewall_shaper_queues.php?queue={$filterent['ackqueue']}&amp;action=show\">{$desc}</a>";
737
									$desc = str_replace('_', '_<wbr>', $filterent['defaultqueue']);
738
									echo "/<a href=\"firewall_shaper_queues.php?queue={$filterent['defaultqueue']}&amp;action=show\">{$desc}</a>";
739
								} else if (isset($filterent['defaultqueue'])) {
740
									$desc = str_replace('_', '_<wbr>', $filterent['defaultqueue']);
741
									echo "<a href=\"firewall_shaper_queues.php?queue={$filterent['defaultqueue']}&amp;action=show\">{$desc}</a>";
742
								} else {
743
									echo gettext("none");
744
								}
745
							?>
746
						</td>
747
						<td>
748
							<?php if ($printicon) { ?>
749
								<i class="fa fa-<?=$image?> <?=$dispcolor?>" title="<?=$alttext;?>"></i>
750
							<?php } ?>
751
							<?=$schedule_span_begin;?><?=str_replace('_', '_<wbr>', htmlspecialchars($filterent['sched']));?>&nbsp;<?=$schedule_span_end;?>
752
						</td>
753
						<td>
754
							<?=htmlspecialchars($filterent['descr']);?>
755
						</td>
756
						<td class="action-icons">
757
						<!-- <?=(isset($filterent['disabled']) ? 'enable' : 'disable')?> -->
758
							<a	class="fa fa-anchor icon-pointer" id="Xmove_<?=$filteri?>" title="<?=$XmoveTitle?>"></a>
759
							<a href="firewall_rules_edit.php?id=<?=$filteri;?>" class="fa fa-pencil" title="<?=gettext('Edit')?>"></a>
760
							<a href="firewall_rules_edit.php?dup=<?=$filteri;?>" class="fa fa-clone" title="<?=gettext('Copy')?>"></a>
761
<?php if (isset($filterent['disabled'])) {
762
?>
763
							<a href="?act=toggle&amp;if=<?=htmlspecialchars($if);?>&amp;id=<?=$filteri;?>" class="fa fa-check-square-o" title="<?=gettext('Enable')?>" usepost></a>
764
<?php } else {
765
?>
766
							<a href="?act=toggle&amp;if=<?=htmlspecialchars($if);?>&amp;id=<?=$filteri;?>" class="fa fa-ban" title="<?=gettext('Disable')?>" usepost></a>
767
<?php }
768
?>
769
							<a href="?act=del&amp;if=<?=htmlspecialchars($if);?>&amp;id=<?=$filteri;?>" class="fa fa-trash" title="<?=gettext('Delete this rule')?>" usepost></a>
770
						</td>
771
					</tr>
772
<?php
773
		$nrules++;
774
	}
775
endforeach;
776

    
777
// There can be separator(s) after the last rule listed.
778
if ($seprows[$nrules]) {
779
	display_separator($separators, $nrules, $columns_in_table);
780
}
781
?>
782
				</tbody>
783
			</table>
784
		</div>
785
	</div>
786

    
787
<?php if ($nrules == 0): ?>
788
	<div class="alert alert-warning" role="alert">
789
		<p>
790
		<?php if ($_REQUEST['if'] == "FloatingRules"): ?>
791
			<?=gettext("No floating rules are currently defined.");?>
792
		<?php else: ?>
793
			<?=gettext("No rules are currently defined for this interface");?><br />
794
			<?=gettext("All incoming connections on this interface will be blocked until pass rules are added.");?>
795
		<?php endif;?>
796
			<?=gettext("Click the button to add a new rule.");?>
797
		</p>
798
	</div>
799
<?php endif;?>
800

    
801
	<nav class="action-buttons">
802
		<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')?>">
803
			<i class="fa fa-level-up icon-embed-btn"></i>
804
			<?=gettext("Add");?>
805
		</a>
806
		<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')?>">
807
			<i class="fa fa-level-down icon-embed-btn"></i>
808
			<?=gettext("Add");?>
809
		</a>
810
		<button name="del_x" type="submit" class="btn btn-danger btn-sm" value="<?=gettext("Delete selected rules"); ?>" title="<?=gettext('Delete selected rules')?>">
811
			<i class="fa fa-trash icon-embed-btn"></i>
812
			<?=gettext("Delete"); ?>
813
		</button>
814
		<button type="submit" id="order-store" name="order-store" class="btn btn-sm btn-primary" value="store changes" disabled title="<?=gettext('Save rule order')?>">
815
			<i class="fa fa-save icon-embed-btn"></i>
816
			<?=gettext("Save")?>
817
		</button>
818
		<button type="submit" id="addsep" name="addsep" class="btn btn-sm btn-warning" title="<?=gettext('Add separator')?>">
819
			<i class="fa fa-plus icon-embed-btn"></i>
820
			<?=gettext("Separator")?>
821
		</button>
822
	</nav>
823
</form>
824

    
825
<div class="infoblock">
826
	<div class="alert alert-info clearfix" role="alert"><div class="pull-left">
827
		<dl class="dl-horizontal responsive">
828
		<!-- Legend -->
829
			<dt><?=gettext('Legend')?></dt>				<dd></dd>
830
			<dt><i class="fa fa-check text-success"></i></dt>		<dd><?=gettext("Pass");?></dd>
831
			<dt><i class="fa fa-filter"></i></dt>	<dd><?=gettext("Match");?></dd>
832
			<dt><i class="fa fa-times text-danger"></i></dt>	<dd><?=gettext("Block");?></dd>
833
			<dt><i class="fa fa-hand-stop-o text-warning"></i></dt>		<dd><?=gettext("Reject");?></dd>
834
			<dt><i class="fa fa-tasks"></i></dt>	<dd> <?=gettext("Log");?></dd>
835
			<dt><i class="fa fa-cog"></i></dt>		<dd> <?=gettext("Advanced filter");?></dd>
836
			<dt><i class="fa fa-forward text-success"></i></dt><dd> <?=gettext("&quot;Quick&quot; rule. Applied immediately on match.")?></dd>
837
		</dl>
838

    
839
<?php
840
	if ("FloatingRules" != $if) {
841
		print(gettext("Rules are evaluated on a first-match basis (i.e. " .
842
			"the action of the first rule to match a packet will be executed). ") . '<br />' .
843
			gettext("This means that if block rules are used, it is important to pay attention " .
844
			"to the rule order. Everything that isn't explicitly passed is blocked " .
845
			"by default. "));
846
	} else {
847
		print(gettext("Floating rules are evaluated on a first-match basis (i.e. " .
848
			"the action of the first rule to match a packet will be executed) only " .
849
			"if the 'quick' option is checked on a rule. Otherwise they will only match if no " .
850
			"other rules match. Pay close attention to the rule order and options " .
851
			"chosen. If no rule here matches, the per-interface or default rules are used. "));
852
	}
853

    
854
	printf(gettext('%1$sClick the anchor icon %2$s to move checked rules before the clicked row. Hold down ' .
855
			'the shift key and click to move the rules after the clicked row.'), '<br /><br />', '<i class="fa fa-anchor"></i>')
856
?>
857
	</div>
858
	</div>
859
</div>
860

    
861
<script type="text/javascript">
862
//<![CDATA[
863

    
864
//Need to create some variables here so that jquery/pfSenseHelpers.js can read them
865
iface = "<?=strtolower($if)?>";
866
cncltxt = '<?=gettext("Cancel")?>';
867
svtxt = '<?=gettext("Save")?>';
868
svbtnplaceholder = '<?=gettext("Enter a description, Save, then drag to final location.")?>';
869
configsection = "filter";
870

    
871
events.push(function() {
872

    
873
	// "Move to here" (anchor) action
874
	$('[id^=Xmove_]').click(function (event) {
875

    
876
		// Prevent click from toggling row
877
		event.stopImmediatePropagation();
878

    
879
		// Save the target rule position
880
		var anchor_row = $(this).parents("tr:first");
881

    
882
		if (event.shiftKey) {
883
			$($('#ruletable > tbody  > tr').get().reverse()).each(function() {
884
				ruleid = this.id.slice(2);
885

    
886
				if (ruleid && !isNaN(ruleid)) {
887
					if ($('#frc' + ruleid).prop('checked')) {
888
						// Move the selected rows, un-select them and add highlight class
889
						$(this).insertAfter(anchor_row);
890
						fr_toggle(ruleid, "fr");
891
						$('#fr' + ruleid).addClass("highlight");
892
					}
893
				}
894
			});
895
		} else {
896
			$('#ruletable > tbody  > tr').each(function() {
897
				ruleid = this.id.slice(2);
898

    
899
				if (ruleid && !isNaN(ruleid)) {
900
					if ($('#frc' + ruleid).prop('checked')) {
901
						// Move the selected rows, un-select them and add highlight class
902
						$(this).insertBefore(anchor_row);
903
						fr_toggle(ruleid, "fr");
904
						$('#fr' + ruleid).addClass("highlight");
905
					}
906
				}
907
			});
908
		}
909

    
910
		// Temporarily set background color so user can more easily see the moved rules, then fade
911
		$('.highlight').effect("highlight", {color: "#739b4b;"}, 4000);
912
		$('#ruletable tr').removeClass("highlight");
913
		$('#order-store').removeAttr('disabled');
914
		reindex_rules($(anchor_row).parent('tbody'));
915
		dirty = true;
916
	}).mouseover(function(e) {
917
		var ruleselected = false;
918

    
919
		$(this).css("cursor", "default");
920

    
921
		// Are any rules currently selected?
922
		$('[id^=frc]').each(function () {
923
			if ($(this).prop("checked")) {
924
				ruleselected = true;
925
			}
926
		});
927

    
928
		// If so, change the icon to show the insertion point
929
		if (ruleselected) {
930
			if (e.shiftKey) {
931
				$(this).removeClass().addClass("fa fa-lg fa-arrow-down text-danger");
932
			} else {
933
				$(this).removeClass().addClass("fa fa-lg fa-arrow-up text-danger");
934
			}
935
		}
936
	}).mouseout(function(e) {
937
		$(this).removeClass().addClass("fa fa-anchor");
938
	});
939

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

    
945
	$('table tbody.user-entries').sortable({
946
		cursor: 'grabbing',
947
		scroll: true,
948
		overflow: 'scroll',
949
		scrollSensitivity: 100,
950
		update: function(event, ui) {
951
			$('#order-store').removeAttr('disabled');
952
			reindex_rules(ui.item.parent('tbody'));
953
			dirty = true;
954
		}
955
	});
956

    
957
	$('table tbody.user-entries').show();
958
<?php endif; ?>
959

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

    
964
		// Save the separator bar configuration
965
		save_separators();
966

    
967
		// Suppress the "Do you really want to leave the page" message
968
		saving = true;
969
	});
970

    
971
	// Provide a warning message if the user tries to change page before saving
972
	$(window).bind('beforeunload', function(){
973
		if ((!saving && dirty) || newSeperator) {
974
			return ("<?=gettext('One or more rules have been moved but have not yet been saved')?>");
975
		} else {
976
			return undefined;
977
		}
978
	});
979

    
980
	$(document).on('keyup keydown', function(e){
981
		if (e.shiftKey) {
982
			$('[id^=Xmove_]').attr("title", "<?=$ShXmoveTitle?>");
983
		} else {
984
			$('[id^=Xmove_]').attr("title", "<?=$XmoveTitle?>");
985
		}
986
	});
987

    
988
	$('#selectAll').click(function() {
989
		var checkedStatus = this.checked;
990
		$('#ruletable tbody tr').find('td:first :checkbox').each(function() {
991
		$(this).prop('checked', checkedStatus);
992
		});
993
	});
994
});
995
//]]>
996
</script>
997

    
998
<?php include("foot.inc");?>
(50-50/234)