Project

General

Profile

Download (35 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
?>
341
<!-- Allow table to scroll when dragging outside of the display window -->
342
<style>
343
.table-responsive {
344
    clear: both;
345
    overflow-x: visible;
346
    margin-bottom: 0px;
347
}
348
</style>
349

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

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

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

    
456
foreach ($a_filter as $filteri => $filterent):
457

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

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

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

    
494
		$isadvset = firewall_check_for_advanced_options($filterent);
495
		if ($isadvset) {
496
			print '<i class="fa fa-cog" title="'. gettext("advanced setting") .': '. $isadvset .'"></i>';
497
		}
498

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

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

    
529
					foreach ($schedule['timerange'] as $timerange) {
530
						$tempFriendlyTime = "";
531
						$tempID = "";
532
						$firstprint = false;
533
						if ($timerange) {
534
							$dayFriendly = "";
535
							$tempFriendlyTime = "";
536

    
537
							//get hours
538
							$temptimerange = $timerange['hour'];
539
							$temptimeseparator = strrpos($temptimerange, "-");
540

    
541
							$starttime = substr ($temptimerange, 0, $temptimeseparator);
542
							$stoptime = substr ($temptimerange, $temptimeseparator+1);
543

    
544
							if ($timerange['month']) {
545
								$tempmontharray = explode(",", $timerange['month']);
546
								$tempdayarray = explode(",", $timerange['day']);
547
								$arraycounter = 0;
548
								$firstDayFound = false;
549
								$firstPrint = false;
550
								foreach ($tempmontharray as $monthtmp) {
551
									$month = $tempmontharray[$arraycounter];
552
									$day = $tempdayarray[$arraycounter];
553

    
554
									if (!$firstDayFound) {
555
										$firstDay = $day;
556
										$firstmonth = $month;
557
										$firstDayFound = true;
558
									}
559

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

    
719
		if (isset($filterent['protocol'])) {
720
			echo strtoupper($filterent['protocol']);
721

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

    
828
// There can be separator(s) after the last rule listed.
829
if ($seprows[$nrules]) {
830
	display_separator($separators, $nrules, $columns_in_table);
831
}
832
?>
833
				</tbody>
834
			</table>
835
		</div>
836
	</div>
837

    
838
<?php if ($nrules == 0): ?>
839
	<div class="alert alert-warning" role="alert">
840
		<p>
841
		<?php if ($_REQUEST['if'] == "FloatingRules"): ?>
842
			<?=gettext("No floating rules are currently defined.");?>
843
		<?php else: ?>
844
			<?=gettext("No rules are currently defined for this interface");?><br />
845
			<?=gettext("All incoming connections on this interface will be blocked until pass rules are added.");?>
846
		<?php endif;?>
847
			<?=gettext("Click the button to add a new rule.");?>
848
		</p>
849
	</div>
850
<?php endif;?>
851

    
852
	<nav class="action-buttons">
853
		<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')?>">
854
			<i class="fa fa-level-up icon-embed-btn"></i>
855
			<?=gettext("Add");?>
856
		</a>
857
		<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')?>">
858
			<i class="fa fa-level-down icon-embed-btn"></i>
859
			<?=gettext("Add");?>
860
		</a>
861
		<button name="del_x" type="submit" class="btn btn-danger btn-sm" value="<?=gettext("Delete selected rules"); ?>" title="<?=gettext('Delete selected rules')?>">
862
			<i class="fa fa-trash icon-embed-btn"></i>
863
			<?=gettext("Delete"); ?>
864
		</button>
865
		<button type="submit" id="order-store" name="order-store" class="btn btn-sm btn-primary" value="store changes" disabled title="<?=gettext('Save rule order')?>">
866
			<i class="fa fa-save icon-embed-btn"></i>
867
			<?=gettext("Save")?>
868
		</button>
869
		<button type="submit" id="addsep" name="addsep" class="btn btn-sm btn-warning" title="<?=gettext('Add separator')?>">
870
			<i class="fa fa-plus icon-embed-btn"></i>
871
			<?=gettext("Separator")?>
872
		</button>
873
	</nav>
874
</form>
875

    
876
<div class="infoblock">
877
	<div class="alert alert-info clearfix" role="alert"><div class="pull-left">
878
		<dl class="dl-horizontal responsive">
879
		<!-- Legend -->
880
			<dt><?=gettext('Legend')?></dt>				<dd></dd>
881
			<dt><i class="fa fa-check text-success"></i></dt>		<dd><?=gettext("Pass");?></dd>
882
			<dt><i class="fa fa-filter"></i></dt>	<dd><?=gettext("Match");?></dd>
883
			<dt><i class="fa fa-times text-danger"></i></dt>	<dd><?=gettext("Block");?></dd>
884
			<dt><i class="fa fa-hand-stop-o text-warning"></i></dt>		<dd><?=gettext("Reject");?></dd>
885
			<dt><i class="fa fa-tasks"></i></dt>	<dd> <?=gettext("Log");?></dd>
886
			<dt><i class="fa fa-cog"></i></dt>		<dd> <?=gettext("Advanced filter");?></dd>
887
			<dt><i class="fa fa-forward text-success"></i></dt><dd> <?=gettext("&quot;Quick&quot; rule. Applied immediately on match.")?></dd>
888
		</dl>
889

    
890
<?php
891
	if ("FloatingRules" != $if) {
892
		print(gettext("Rules are evaluated on a first-match basis (i.e. " .
893
			"the action of the first rule to match a packet will be executed). ") . '<br />' .
894
			gettext("This means that if block rules are used, it is important to pay attention " .
895
			"to the rule order. Everything that isn't explicitly passed is blocked " .
896
			"by default. "));
897
	} else {
898
		print(gettext("Floating rules are evaluated on a first-match basis (i.e. " .
899
			"the action of the first rule to match a packet will be executed) only " .
900
			"if the 'quick' option is checked on a rule. Otherwise they will only match if no " .
901
			"other rules match. Pay close attention to the rule order and options " .
902
			"chosen. If no rule here matches, the per-interface or default rules are used. "));
903
	}
904

    
905
	printf(gettext('%1$sClick the anchor icon %2$s to move checked rules before the clicked row. Hold down ' .
906
			'the shift key and click to move the rules after the clicked row.'), '<br /><br />', '<i class="fa fa-anchor"></i>')
907
?>
908
	</div>
909
	</div>
910
</div>
911

    
912
<script type="text/javascript">
913
//<![CDATA[
914

    
915
//Need to create some variables here so that jquery/pfSenseHelpers.js can read them
916
iface = "<?=strtolower($if)?>";
917
cncltxt = '<?=gettext("Cancel")?>';
918
svtxt = '<?=gettext("Save")?>';
919
svbtnplaceholder = '<?=gettext("Enter a description, Save, then drag to final location.")?>';
920
configsection = "filter";
921

    
922
events.push(function() {
923

    
924
	// "Move to here" (anchor) action
925
	$('[id^=Xmove_]').click(function (event) {
926

    
927
		// Prevent click from toggling row
928
		event.stopImmediatePropagation();
929

    
930
		// Save the target rule position
931
		var anchor_row = $(this).parents("tr:first");
932

    
933
		if (event.shiftKey) {
934
			$($('#ruletable > tbody  > tr').get().reverse()).each(function() {
935
				ruleid = this.id.slice(2);
936

    
937
				if (ruleid && !isNaN(ruleid)) {
938
					if ($('#frc' + ruleid).prop('checked')) {
939
						// Move the selected rows, un-select them and add highlight class
940
						$(this).insertAfter(anchor_row);
941
						fr_toggle(ruleid, "fr");
942
						$('#fr' + ruleid).addClass("highlight");
943
					}
944
				}
945
			});
946
		} else {
947
			$('#ruletable > tbody  > tr').each(function() {
948
				ruleid = this.id.slice(2);
949

    
950
				if (ruleid && !isNaN(ruleid)) {
951
					if ($('#frc' + ruleid).prop('checked')) {
952
						// Move the selected rows, un-select them and add highlight class
953
						$(this).insertBefore(anchor_row);
954
						fr_toggle(ruleid, "fr");
955
						$('#fr' + ruleid).addClass("highlight");
956
					}
957
				}
958
			});
959
		}
960

    
961
		// Temporarily set background color so user can more easily see the moved rules, then fade
962
		$('.highlight').effect("highlight", {color: "#739b4b;"}, 4000);
963
		$('#ruletable tr').removeClass("highlight");
964
		$('#order-store').removeAttr('disabled');
965
		reindex_rules($(anchor_row).parent('tbody'));
966
		dirty = true;
967
	}).mouseover(function(e) {
968
		var ruleselected = false;
969

    
970
		$(this).css("cursor", "default");
971

    
972
		// Are any rules currently selected?
973
		$('[id^=frc]').each(function () {
974
			if ($(this).prop("checked")) {
975
				ruleselected = true;
976
			}
977
		});
978

    
979
		// If so, change the icon to show the insertion point
980
		if (ruleselected) {
981
			if (e.shiftKey) {
982
				$(this).removeClass().addClass("fa fa-lg fa-arrow-down text-danger");
983
			} else {
984
				$(this).removeClass().addClass("fa fa-lg fa-arrow-up text-danger");
985
			}
986
		}
987
	}).mouseout(function(e) {
988
		$(this).removeClass().addClass("fa fa-anchor");
989
	});
990

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

    
996
	$('table tbody.user-entries').sortable({
997
		cursor: 'grabbing',
998
		scroll: true,
999
		overflow: 'scroll',
1000
		scrollSensitivity: 100,
1001
		update: function(event, ui) {
1002
			$('#order-store').removeAttr('disabled');
1003
			reindex_rules(ui.item.parent('tbody'));
1004
			dirty = true;
1005
		}
1006
	});
1007

    
1008
	$('table tbody.user-entries').show();
1009
<?php endif; ?>
1010

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

    
1015
		// Save the separator bar configuration
1016
		save_separators();
1017

    
1018
		// Suppress the "Do you really want to leave the page" message
1019
		saving = true;
1020
	});
1021

    
1022
	// Provide a warning message if the user tries to change page before saving
1023
	$(window).bind('beforeunload', function(){
1024
		if ((!saving && dirty) || newSeperator) {
1025
			return ("<?=gettext('One or more rules have been moved but have not yet been saved')?>");
1026
		} else {
1027
			return undefined;
1028
		}
1029
	});
1030

    
1031
	$(document).on('keyup keydown', function(e){
1032
		if (e.shiftKey) {
1033
			$('[id^=Xmove_]').attr("title", "<?=$ShXmoveTitle?>");
1034
		} else {
1035
			$('[id^=Xmove_]').attr("title", "<?=$XmoveTitle?>");
1036
		}
1037
	});
1038

    
1039
	$('#selectAll').click(function() {
1040
		var checkedStatus = this.checked;
1041
		$('#ruletable tbody tr').find('td:first :checkbox').each(function() {
1042
		$(this).prop('checked', checkedStatus);
1043
		});
1044
	});
1045
});
1046
//]]>
1047
</script>
1048

    
1049
<?php include("foot.inc");?>
(51-51/227)