Project

General

Profile

Download (33.1 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-2016 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
	printf("<a href=\"diag_dump_states.php?ruleid=%s\" data-toggle=\"popover\" data-trigger=\"hover focus\" title=\"%s\" ",
87
	    $rulesid, gettext("States details"));
88
	printf("data-content=\"evaluations: %s<br>packets: %s<br>bytes: %s<br>states: %s<br>state creations: %s\" data-html=\"true\" usepost>",
89
	    format_number($evaluations), format_number($packets), format_bytes($bytes),
90
	    format_number($states), format_number($stcreations));
91
	printf("%s/%s</a><br>", format_number($states), format_bytes($bytes));
92
}
93

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

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

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

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

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

    
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
/* add group interfaces */
124
if (is_array($config['ifgroups']['ifgroupentry'])) {
125
	foreach ($config['ifgroups']['ifgroupentry'] as $ifgen) {
126
		if (have_ruleint_access($ifgen['ifname'])) {
127
			$iflist[$ifgen['ifname']] = $ifgen['ifname'];
128
		}
129
	}
130
}
131

    
132
foreach ($ifdescs as $ifent => $ifdesc) {
133
	if (have_ruleint_access($ifent)) {
134
		$iflist[$ifent] = $ifdesc;
135
	}
136
}
137

    
138
if ($config['l2tp']['mode'] == "server") {
139
	if (have_ruleint_access("l2tp")) {
140
		$iflist['l2tp'] = gettext("L2TP VPN");
141
	}
142
}
143

    
144
if (is_array($config['pppoes']['pppoe'])) {
145
	foreach ($config['pppoes']['pppoe'] as $pppoes) {
146
		if (($pppoes['mode'] == 'server') && have_ruleint_access("pppoe")) {
147
			$iflist['pppoe'] = gettext("PPPoE Server");
148
		}
149
	}
150
}
151

    
152
/* add ipsec interfaces */
153
if (ipsec_enabled() && have_ruleint_access("enc0")) {
154
	$iflist["enc0"] = gettext("IPsec");
155
}
156

    
157
/* add openvpn/tun interfaces */
158
if ($config['openvpn']["openvpn-server"] || $config['openvpn']["openvpn-client"]) {
159
	$iflist["openvpn"] = gettext("OpenVPN");
160
}
161

    
162
if (!$if || !isset($iflist[$if])) {
163
	if ($if != "any" && $if != "FloatingRules" && isset($iflist['wan'])) {
164
		$if = "wan";
165
	} else {
166
		$if = "FloatingRules";
167
	}
168
}
169

    
170
if ($_POST['apply']) {
171
	$retval = 0;
172
	$retval |= filter_configure();
173

    
174
	clear_subsystem_dirty('filter');
175
}
176

    
177
if ($_POST['act'] == "del") {
178
	if ($a_filter[$_POST['id']]) {
179
		if (!empty($a_filter[$_POST['id']]['associated-rule-id'])) {
180
			delete_nat_association($a_filter[$_POST['id']]['associated-rule-id']);
181
		}
182
		unset($a_filter[$_POST['id']]);
183

    
184
		// Update the separators
185
		$a_separators = &$config['filter']['separator'][strtolower($if)];
186
		$ridx = ifridx($if, $_POST['id']);	// get rule index within interface
187
		$mvnrows = -1;
188
		move_separators($a_separators, $ridx, $mvnrows);
189

    
190
		if (write_config()) {
191
			mark_subsystem_dirty('filter');
192
		}
193

    
194
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
195
		exit;
196
	}
197
}
198

    
199
// Handle save msg if defined
200
if ($_REQUEST['savemsg']) {
201
	$savemsg = htmlentities($_REQUEST['savemsg']);
202
}
203

    
204
if (isset($_POST['del_x'])) {
205
	/* delete selected rules */
206
	$deleted = false;
207

    
208
	if (is_array($_POST['rule']) && count($_POST['rule'])) {
209
		$a_separators = &$config['filter']['separator'][strtolower($if)];
210
		$num_deleted = 0;
211

    
212
		foreach ($_POST['rule'] as $rulei) {
213
			delete_nat_association($a_filter[$rulei]['associated-rule-id']);
214
			unset($a_filter[$rulei]);
215
			$deleted = true;
216

    
217
			// Update the separators
218
			// As rules are deleted, $ridx has to be decremented or separator position will break
219
			$ridx = ifridx($if, $rulei) - $num_deleted;	// get rule index within interface
220
			$mvnrows = -1;
221
			move_separators($a_separators, $ridx, $mvnrows);
222
			$num_deleted++;
223
		}
224

    
225
		if ($deleted) {
226
			if (write_config()) {
227
				mark_subsystem_dirty('filter');
228
			}
229
		}
230

    
231
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
232
		exit;
233
	}
234
} else if ($_POST['act'] == "toggle") {
235
	if ($a_filter[$_POST['id']]) {
236
		if (isset($a_filter[$_POST['id']]['disabled'])) {
237
			unset($a_filter[$_POST['id']]['disabled']);
238
		} else {
239
			$a_filter[$_POST['id']]['disabled'] = true;
240
		}
241
		if (write_config()) {
242
			mark_subsystem_dirty('filter');
243
		}
244

    
245
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
246
		exit;
247
	}
248
} else if ($_POST['order-store']) {
249

    
250
	/* update rule order, POST[rule] is an array of ordered IDs */
251
	if (is_array($_POST['rule']) && !empty($_POST['rule'])) {
252
		$a_filter_new = array();
253

    
254
		// Include the rules of other interfaces listed in config before this (the selected) interface.
255
		foreach ($a_filter as $filteri_before => $filterent) {
256
			if (($filterent['interface'] == $if && !isset($filterent['floating'])) || (isset($filterent['floating']) && "FloatingRules" == $if)) {
257
				break;
258
			} else {
259
				$a_filter_new[] = $filterent;
260
			}
261
		}
262

    
263
		// Include the rules of this (the selected) interface.
264
		// If a rule is not in POST[rule], it has been deleted by the user
265
		foreach ($_POST['rule'] as $id) {
266
			$a_filter_new[] = $a_filter[$id];
267
		}
268

    
269
		// Include the rules of other interfaces listed in config after this (the selected) interface.
270
		foreach ($a_filter as $filteri_after => $filterent) {
271
			if ($filteri_before > $filteri_after) {
272
				continue;
273
			}
274
			if (($filterent['interface'] == $if && !isset($filterent['floating'])) || (isset($filterent['floating']) && "FloatingRules" == $if)) {
275
				continue;
276
			} else {
277
				$a_filter_new[] = $filterent;
278
			}
279
		}
280

    
281
		$a_filter = $a_filter_new;
282

    
283
		$config['filter']['separator'][strtolower($if)] = "";
284

    
285
		if ($_POST['separator']) {
286
			$idx = 0;
287
			foreach ($_POST['separator'] as $separator) {
288
				$config['filter']['separator'][strtolower($separator['if'])]['sep' . $idx++] = $separator;
289
			}
290
		}
291

    
292
		if (write_config()) {
293
			mark_subsystem_dirty('filter');
294
		}
295

    
296
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
297
		exit;
298
	}
299
}
300

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

    
303
foreach ($iflist as $ifent => $ifname) {
304
	$tab_array[] = array($ifname, ($ifent == $if), "firewall_rules.php?if={$ifent}");
305
}
306

    
307
foreach ($tab_array as $dtab) {
308
	if ($dtab[1]) {
309
		$bctab = $dtab[0];
310
		break;
311
	}
312
}
313

    
314
$pgtitle = array(gettext("Firewall"), gettext("Rules"), $bctab);
315
$pglinks = array("", "firewall_rules.php", "@self");
316
$shortcut_section = "firewall";
317

    
318
include("head.inc");
319
$nrules = 0;
320

    
321
if ($savemsg) {
322
	print_info_box($savemsg, 'success');
323
}
324

    
325
if ($_POST['apply']) {
326
	print_apply_result_box($retval);
327
}
328

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

    
333
display_top_tabs($tab_array, false, 'pills', "usepost");
334

    
335
$showantilockout = false;
336
$showprivate = false;
337
$showblockbogons = false;
338

    
339
if (!isset($config['system']['webgui']['noantilockout']) &&
340
    (((count($config['interfaces']) > 1) && ($if == 'lan')) ||
341
    ((count($config['interfaces']) == 1) && ($if == 'wan')))) {
342
	$showantilockout = true;
343
}
344

    
345
if (isset($config['interfaces'][$if]['blockpriv'])) {
346
	$showprivate = true;
347
}
348

    
349
if (isset($config['interfaces'][$if]['blockbogons'])) {
350
	$showblockbogons = true;
351
}
352

    
353
/* Load the counter data of each pf rule. */
354
$rulescnt = pfSense_get_pf_rules();
355

    
356
// Update this if you add or remove columns!
357
$columns_in_table = 13;
358

    
359
?>
360
<!-- Allow table to scroll when dragging outside of the display window -->
361
<style>
362
.table-responsive {
363
    clear: both;
364
    overflow-x: visible;
365
    margin-bottom: 0px;
366
}
367
</style>
368

    
369
<form method="post">
370
	<input name="if" id="if" type="hidden" value="<?=$if?>" />
371
	<div class="panel panel-default">
372
		<div class="panel-heading"><h2 class="panel-title"><?=gettext("Rules (Drag to Change Order)")?></h2></div>
373
		<div id="mainarea" class="table-responsive panel-body">
374
			<table id="ruletable" class="table table-hover table-striped table-condensed" style="overflow-x: 'visible'">
375
				<thead>
376
					<tr>
377
						<th><!-- checkbox --></th>
378
						<th><!-- status icons --></th>
379
						<th><?=gettext("States")?></th>
380
						<th><?=gettext("Protocol")?></th>
381
						<th><?=gettext("Source")?></th>
382
						<th><?=gettext("Port")?></th>
383
						<th><?=gettext("Destination")?></th>
384
						<th><?=gettext("Port")?></th>
385
						<th><?=gettext("Gateway")?></th>
386
						<th><?=gettext("Queue")?></th>
387
						<th><?=gettext("Schedule")?></th>
388
						<th><?=gettext("Description")?></th>
389
						<th><?=gettext("Actions")?></th>
390
					</tr>
391
				</thead>
392

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

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

    
468
foreach ($a_filter as $filteri => $filterent):
469

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

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

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

    
506
		$isadvset = firewall_check_for_advanced_options($filterent);
507
		if ($isadvset) {
508
			print '<i class="fa fa-cog" title="'. gettext("advanced setting") .': '. $isadvset .'"></i>';
509
		}
510

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

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

    
539
					foreach ($schedule['timerange'] as $timerange) {
540
						$tempFriendlyTime = "";
541
						$tempID = "";
542
						$firstprint = false;
543
						if ($timerange) {
544
							$dayFriendly = "";
545
							$tempFriendlyTime = "";
546

    
547
							//get hours
548
							$temptimerange = $timerange['hour'];
549
							$temptimeseparator = strrpos($temptimerange, "-");
550

    
551
							$starttime = substr ($temptimerange, 0, $temptimeseparator);
552
							$stoptime = substr ($temptimerange, $temptimeseparator+1);
553

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

    
564
									if (!$firstDayFound) {
565
										$firstDay = $day;
566
										$firstmonth = $month;
567
										$firstDayFound = true;
568
									}
569

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

    
683
		if (isset($filterent['protocol'])) {
684
			echo strtoupper($filterent['protocol']);
685

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

    
792
// There can be separator(s) after the last rule listed.
793
if ($seprows[$nrules]) {
794
	display_separator($separators, $nrules, $columns_in_table);
795
}
796
?>
797
				</tbody>
798
			</table>
799
		</div>
800
	</div>
801

    
802
<?php if ($nrules == 0): ?>
803
	<div class="alert alert-warning" role="alert">
804
		<p>
805
		<?php if ($_REQUEST['if'] == "FloatingRules"): ?>
806
			<?=gettext("No floating rules are currently defined.");?>
807
		<?php else: ?>
808
			<?=gettext("No rules are currently defined for this interface");?><br />
809
			<?=gettext("All incoming connections on this interface will be blocked until pass rules are added.");?>
810
		<?php endif;?>
811
			<?=gettext("Click the button to add a new rule.");?>
812
		</p>
813
	</div>
814
<?php endif;?>
815

    
816
	<nav class="action-buttons">
817
		<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')?>">
818
			<i class="fa fa-level-up icon-embed-btn"></i>
819
			<?=gettext("Add");?>
820
		</a>
821
		<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')?>">
822
			<i class="fa fa-level-down icon-embed-btn"></i>
823
			<?=gettext("Add");?>
824
		</a>
825
		<button name="del_x" type="submit" class="btn btn-danger btn-sm" value="<?=gettext("Delete selected rules"); ?>" title="<?=gettext('Delete selected rules')?>">
826
			<i class="fa fa-trash icon-embed-btn"></i>
827
			<?=gettext("Delete"); ?>
828
		</button>
829
		<button type="submit" id="order-store" name="order-store" class="btn btn-sm btn-primary" value="store changes" disabled title="<?=gettext('Save rule order')?>">
830
			<i class="fa fa-save icon-embed-btn"></i>
831
			<?=gettext("Save")?>
832
		</button>
833
		<button type="submit" id="addsep" name="addsep" class="btn btn-sm btn-warning" title="<?=gettext('Add separator')?>">
834
			<i class="fa fa-plus icon-embed-btn"></i>
835
			<?=gettext("Separator")?>
836
		</button>
837
	</nav>
838
</form>
839

    
840
<div class="infoblock">
841
	<div class="alert alert-info clearfix" role="alert"><div class="pull-left">
842
		<dl class="dl-horizontal responsive">
843
		<!-- Legend -->
844
			<dt><?=gettext('Legend')?></dt>				<dd></dd>
845
			<dt><i class="fa fa-check text-success"></i></dt>		<dd><?=gettext("Pass");?></dd>
846
			<dt><i class="fa fa-filter"></i></dt>	<dd><?=gettext("Match");?></dd>
847
			<dt><i class="fa fa-times text-danger"></i></dt>	<dd><?=gettext("Block");?></dd>
848
			<dt><i class="fa fa-hand-stop-o text-warning"></i></dt>		<dd><?=gettext("Reject");?></dd>
849
			<dt><i class="fa fa-tasks"></i></dt>	<dd> <?=gettext("Log");?></dd>
850
			<dt><i class="fa fa-cog"></i></dt>		<dd> <?=gettext("Advanced filter");?></dd>
851
			<dt><i class="fa fa-forward text-success"></i></dt><dd> <?=gettext("&quot;Quick&quot; rule. Applied immediately on match.")?></dd>
852
		</dl>
853

    
854
<?php
855
	if ("FloatingRules" != $if) {
856
		print(gettext("Rules are evaluated on a first-match basis (i.e. " .
857
			"the action of the first rule to match a packet will be executed). ") . '<br />' .
858
			gettext("This means that if block rules are used, it is important to pay attention " .
859
			"to the rule order. Everything that isn't explicitly passed is blocked " .
860
			"by default. "));
861
	} else {
862
		print(gettext("Floating rules are evaluated on a first-match basis (i.e. " .
863
			"the action of the first rule to match a packet will be executed) only " .
864
			"if the 'quick' option is checked on a rule. Otherwise they will only match if no " .
865
			"other rules match. Pay close attention to the rule order and options " .
866
			"chosen. If no rule here matches, the per-interface or default rules are used. "));
867
	}
868

    
869
	printf(gettext('%1$sClick the anchor icon %2$s to move checked rules before the clicked row. Hold down ' .
870
			'the shift key and click to move the rules after the clicked row.'), '<br /><br />', '<i class="fa fa-anchor"></i>')
871
?>
872
	</div>
873
	</div>
874
</div>
875

    
876
<script type="text/javascript">
877
//<![CDATA[
878

    
879
//Need to create some variables here so that jquery/pfSenseHelpers.js can read them
880
iface = "<?=strtolower($if)?>";
881
cncltxt = '<?=gettext("Cancel")?>';
882
svtxt = '<?=gettext("Save")?>';
883
svbtnplaceholder = '<?=gettext("Enter a description, Save, then drag to final location.")?>';
884
configsection = "filter";
885

    
886
events.push(function() {
887

    
888
	// "Move to here" (anchor) action
889
	$('[id^=Xmove_]').click(function (event) {
890

    
891
		// Prevent click from toggling row
892
		event.stopImmediatePropagation();
893

    
894
		// Save the target rule position
895
		var anchor_row = $(this).parents("tr:first");
896

    
897
		if (event.shiftKey) {
898
			$($('#ruletable > tbody  > tr').get().reverse()).each(function() {
899
				ruleid = this.id.slice(2);
900

    
901
				if (ruleid && !isNaN(ruleid)) {
902
					if ($('#frc' + ruleid).prop('checked')) {
903
						// Move the selected rows, un-select them and add highlight class
904
						$(this).insertAfter(anchor_row);
905
						fr_toggle(ruleid, "fr");
906
						$('#fr' + ruleid).addClass("highlight");
907
					}
908
				}
909
			});
910
		} else {
911
			$('#ruletable > tbody  > tr').each(function() {
912
				ruleid = this.id.slice(2);
913

    
914
				if (ruleid && !isNaN(ruleid)) {
915
					if ($('#frc' + ruleid).prop('checked')) {
916
						// Move the selected rows, un-select them and add highlight class
917
						$(this).insertBefore(anchor_row);
918
						fr_toggle(ruleid, "fr");
919
						$('#fr' + ruleid).addClass("highlight");
920
					}
921
				}
922
			});
923
		}
924

    
925
		// Temporarily set background color so user can more easily see the moved rules, then fade
926
		$('.highlight').effect("highlight", {color: "#739b4b;"}, 4000);
927
		$('#ruletable tr').removeClass("highlight");
928
		$('#order-store').removeAttr('disabled');
929
		reindex_rules($(anchor_row).parent('tbody'));
930
		dirty = true;
931
	}).mouseover(function(e) {
932
		var ruleselected = false;
933

    
934
		$(this).css("cursor", "default");
935

    
936
		// Are any rules currently selected?
937
		$('[id^=frc]').each(function () {
938
			if ($(this).prop("checked")) {
939
				ruleselected = true;
940
			}
941
		});
942

    
943
		// If so, change the icon to show the insetion point
944
		if (ruleselected) {
945
			if (e.shiftKey) {
946
				$(this).removeClass().addClass("fa fa-lg fa-arrow-down text-danger");
947
			} else {
948
				$(this).removeClass().addClass("fa fa-lg fa-arrow-up text-danger");
949
			}
950
		}
951
	}).mouseout(function(e) {
952
		$(this).removeClass().addClass("fa fa-anchor");
953
	});
954

    
955
	// Make rules sortable. Hiding the table before applying sortable, then showing it again is
956
	// a work-around for very slow sorting on FireFox
957
	$('table tbody.user-entries').hide();
958

    
959
	$('table tbody.user-entries').sortable({
960
		cursor: 'grabbing',
961
		scroll: true,
962
		overflow: 'scroll',
963
		scrollSensitivity: 100,
964
		update: function(event, ui) {
965
			$('#order-store').removeAttr('disabled');
966
			reindex_rules(ui.item.parent('tbody'));
967
			dirty = true;
968
		}
969
	});
970

    
971
	$('table tbody.user-entries').show();
972

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

    
977
		// Save the separator bar configuration
978
		save_separators();
979

    
980
		// Suppress the "Do you really want to leave the page" message
981
		saving = true;
982
	});
983

    
984
	// Provide a warning message if the user tries to change page before saving
985
	$(window).bind('beforeunload', function(){
986
		if ((!saving && dirty) || newSeperator) {
987
			return ("<?=gettext('One or more rules have been moved but have not yet been saved')?>");
988
		} else {
989
			return undefined;
990
		}
991
	});
992

    
993
	$(document).on('keyup keydown', function(e){
994
		if (e.shiftKey) {
995
			$('[id^=Xmove_]').attr("title", "<?=$ShXmoveTitle?>");
996
		} else {
997
			$('[id^=Xmove_]').attr("title", "<?=$XmoveTitle?>");
998
		}
999
	});
1000
});
1001
//]]>
1002
</script>
1003

    
1004
<?php include("foot.inc");?>
(45-45/223)