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
init_config_arr(array('filter', 'rule'));
112
filter_rules_sort();
113
$a_filter = &$config['filter']['rule'];
114

    
115
if ($_REQUEST['if']) {
116
	$if = $_REQUEST['if'];
117
}
118

    
119
$ifdescs = get_configured_interface_with_descr();
120

    
121
$iflist = filter_get_interface_list();
122

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

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

    
135
	clear_subsystem_dirty('filter');
136
}
137

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
246
		$a_filter = $a_filter_new;
247

    
248
		$config['filter']['separator'][strtolower($if)] = "";
249

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

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

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

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

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

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

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

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

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

    
291
include("head.inc");
292
$nrules = 0;
293

    
294
if ($savemsg) {
295
	print_info_box($savemsg, 'success');
296
}
297

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

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

    
306
display_top_tabs($tab_array, false, 'pills');
307

    
308
$showantilockout = false;
309
$showprivate = false;
310
$showblockbogons = false;
311

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
519
					foreach ($schedule['timerange'] as $timerange) {
520
						$tempFriendlyTime = "";
521
						$tempID = "";
522
						$firstprint = false;
523
						if ($timerange) {
524
							$dayFriendly = "";
525
							$tempFriendlyTime = "";
526

    
527
							//get hours
528
							$temptimerange = $timerange['hour'];
529
							$temptimeseparator = strrpos($temptimerange, "-");
530

    
531
							$starttime = substr ($temptimerange, 0, $temptimeseparator);
532
							$stoptime = substr ($temptimerange, $temptimeseparator+1);
533

    
534
							if ($timerange['month']) {
535
								$tempmontharray = explode(",", $timerange['month']);
536
								$tempdayarray = explode(",", $timerange['day']);
537
								$arraycounter = 0;
538
								$firstDayFound = false;
539
								$firstPrint = false;
540
								foreach ($tempmontharray as $monthtmp) {
541
									$month = $tempmontharray[$arraycounter];
542
									$day = $tempdayarray[$arraycounter];
543

    
544
									if (!$firstDayFound) {
545
										$firstDay = $day;
546
										$firstmonth = $month;
547
										$firstDayFound = true;
548
									}
549

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

    
663
		if (isset($filterent['protocol'])) {
664
			echo strtoupper($filterent['protocol']);
665

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

    
772
// There can be separator(s) after the last rule listed.
773
if ($seprows[$nrules]) {
774
	display_separator($separators, $nrules, $columns_in_table);
775
}
776
?>
777
				</tbody>
778
			</table>
779
		</div>
780
	</div>
781

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

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

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

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

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

    
856
<script type="text/javascript">
857
//<![CDATA[
858

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

    
866
events.push(function() {
867

    
868
	// "Move to here" (anchor) action
869
	$('[id^=Xmove_]').click(function (event) {
870

    
871
		// Prevent click from toggling row
872
		event.stopImmediatePropagation();
873

    
874
		// Save the target rule position
875
		var anchor_row = $(this).parents("tr:first");
876

    
877
		if (event.shiftKey) {
878
			$($('#ruletable > tbody  > tr').get().reverse()).each(function() {
879
				ruleid = this.id.slice(2);
880

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

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

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

    
914
		$(this).css("cursor", "default");
915

    
916
		// Are any rules currently selected?
917
		$('[id^=frc]').each(function () {
918
			if ($(this).prop("checked")) {
919
				ruleselected = true;
920
			}
921
		});
922

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

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

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

    
952
	$('table tbody.user-entries').show();
953
<?php endif; ?>
954

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

    
959
		// Save the separator bar configuration
960
		save_separators();
961

    
962
		// Suppress the "Do you really want to leave the page" message
963
		saving = true;
964
	});
965

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

    
975
	$(document).on('keyup keydown', function(e){
976
		if (e.shiftKey) {
977
			$('[id^=Xmove_]').attr("title", "<?=$ShXmoveTitle?>");
978
		} else {
979
			$('[id^=Xmove_]').attr("title", "<?=$XmoveTitle?>");
980
		}
981
	});
982

    
983
	$('#selectAll').click(function() {
984
		var checkedStatus = this.checked;
985
		$('#ruletable tbody tr').find('td:first :checkbox').each(function() {
986
		$(this).prop('checked', checkedStatus);
987
		});
988
	});
989
});
990
//]]>
991
</script>
992

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