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
$pgtitle = array(gettext("Firewall"), gettext("Rules"));
43
$shortcut_section = "firewall";
44

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

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

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

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

    
60
	return ($arr);
61
}
62

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

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

    
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=\"evaluations: %s<br>packets: %s<br>bytes: %s<br>states: %s<br>state creations: %s\" data-html=\"true\">",
90
	    format_number($evaluations), format_number($packets), format_bytes($bytes),
91
	    format_number($states), format_number($stcreations));
92
	printf("%s/%s</a><br>", format_number($states), format_bytes($bytes));
93
}
94

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

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

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

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

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

    
115
filter_rules_sort();
116
$a_filter = &$config['filter']['rule'];
117

    
118
$if = $_GET['if'];
119

    
120
if ($_POST['if']) {
121
	$if = $_POST['if'];
122
}
123

    
124
$ifdescs = get_configured_interface_with_descr();
125

    
126
/* add group interfaces */
127
if (is_array($config['ifgroups']['ifgroupentry'])) {
128
	foreach ($config['ifgroups']['ifgroupentry'] as $ifgen) {
129
		if (have_ruleint_access($ifgen['ifname'])) {
130
			$iflist[$ifgen['ifname']] = $ifgen['ifname'];
131
		}
132
	}
133
}
134

    
135
foreach ($ifdescs as $ifent => $ifdesc) {
136
	if (have_ruleint_access($ifent)) {
137
		$iflist[$ifent] = $ifdesc;
138
	}
139
}
140

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

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

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

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

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

    
173
if ($_POST) {
174
	$pconfig = $_POST;
175

    
176
	if ($_POST['apply']) {
177
		$retval = 0;
178
		$retval = filter_configure();
179

    
180
		clear_subsystem_dirty('filter');
181

    
182
		$savemsg = sprintf(gettext("The settings have been applied. The firewall rules are now reloading in the background.<br />%s Monitor %s the reload progress."),
183
									"<a href='status_filter_reload.php'>", "</a>");
184
	}
185
}
186

    
187
if ($_GET['act'] == "del") {
188
	if ($a_filter[$_GET['id']]) {
189
		if (!empty($a_filter[$_GET['id']]['associated-rule-id'])) {
190
			delete_nat_association($a_filter[$_GET['id']]['associated-rule-id']);
191
		}
192
		unset($a_filter[$_GET['id']]);
193

    
194
		// Update the separators
195
		$a_separators = &$config['filter']['separator'][strtolower($if)];
196
		$ridx = ifridx($if, $_GET['id']);	// get rule index within interface
197
		$mvnrows = -1;
198
		move_separators($a_separators, $ridx, $mvnrows);
199

    
200
		if (write_config()) {
201
			mark_subsystem_dirty('filter');
202
		}
203

    
204
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
205
		exit;
206
	}
207
}
208

    
209
// Handle save msg if defined
210
if ($_REQUEST['savemsg']) {
211
	$savemsg = htmlentities($_REQUEST['savemsg']);
212
}
213

    
214
if (isset($_POST['del_x'])) {
215
	/* delete selected rules */
216
	$deleted = false;
217

    
218
	if (is_array($_POST['rule']) && count($_POST['rule'])) {
219
		$a_separators = &$config['filter']['separator'][strtolower($if)];
220
		$num_deleted = 0;
221

    
222
		foreach ($_POST['rule'] as $rulei) {
223
			delete_nat_association($a_filter[$rulei]['associated-rule-id']);
224
			unset($a_filter[$rulei]);
225
			$deleted = true;
226

    
227
			// Update the separators
228
			// As rules are deleted, $ridx has to be decremented or separator position will break
229
			$ridx = ifridx($if, $rulei) - $num_deleted;	// get rule index within interface
230
			$mvnrows = -1;
231
			move_separators($a_separators, $ridx, $mvnrows);
232
			$num_deleted++;
233
		}
234

    
235
		if ($deleted) {
236
			if (write_config()) {
237
				mark_subsystem_dirty('filter');
238
			}
239
		}
240

    
241
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
242
		exit;
243
	}
244
} else if ($_GET['act'] == "toggle") {
245
	if ($a_filter[$_GET['id']]) {
246
		if (isset($a_filter[$_GET['id']]['disabled'])) {
247
			unset($a_filter[$_GET['id']]['disabled']);
248
		} else {
249
			$a_filter[$_GET['id']]['disabled'] = true;
250
		}
251
		if (write_config()) {
252
			mark_subsystem_dirty('filter');
253
		}
254

    
255
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
256
		exit;
257
	}
258
} else if ($_POST['order-store']) {
259

    
260
	/* update rule order, POST[rule] is an array of ordered IDs */
261
	if (is_array($_POST['rule']) && !empty($_POST['rule'])) {
262
		$a_filter_new = array();
263

    
264
		// Include the rules of other interfaces listed in config before this (the selected) interface.
265
		foreach ($a_filter as $filteri_before => $filterent) {
266
			if (($filterent['interface'] == $if && !isset($filterent['floating'])) || (isset($filterent['floating']) && "FloatingRules" == $if)) {
267
				break;
268
			} else {
269
				$a_filter_new[] = $filterent;
270
			}
271
		}
272

    
273
		// Include the rules of this (the selected) interface.
274
		// If a rule is not in POST[rule], it has been deleted by the user
275
		foreach ($_POST['rule'] as $id) {
276
			$a_filter_new[] = $a_filter[$id];
277
		}
278

    
279
		// Include the rules of other interfaces listed in config after this (the selected) interface.
280
		foreach ($a_filter as $filteri_after => $filterent) {
281
			if ($filteri_before > $filteri_after) {
282
				continue;
283
			}
284
			if (($filterent['interface'] == $if && !isset($filterent['floating'])) || (isset($filterent['floating']) && "FloatingRules" == $if)) {
285
				continue;
286
			} else {
287
				$a_filter_new[] = $filterent;
288
			}
289
		}
290

    
291
		$a_filter = $a_filter_new;
292

    
293
		$config['filter']['separator'][strtolower($if)] = "";
294

    
295
		if ($_POST['separator']) {
296
			$idx = 0;
297
			foreach ($_POST['separator'] as $separator) {
298
				$config['filter']['separator'][strtolower($separator['if'])]['sep' . $idx++] = $separator;
299
			}
300
		}
301

    
302
		if (write_config()) {
303
			mark_subsystem_dirty('filter');
304
		}
305

    
306
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
307
		exit;
308
	}
309
}
310

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

    
313
foreach ($iflist as $ifent => $ifname) {
314
	$tab_array[] = array($ifname, ($ifent == $if), "firewall_rules.php?if={$ifent}");
315
}
316

    
317
foreach ($tab_array as $dtab) {
318
	if ($dtab[1]) {
319
		$bctab = $dtab[0];
320
		break;
321
	}
322
}
323

    
324
$pgtitle = array(gettext("Firewall"), gettext("Rules"), $bctab);
325
$shortcut_section = "firewall";
326

    
327
include("head.inc");
328
$nrules = 0;
329

    
330
if ($savemsg) {
331
	print_info_box($savemsg, 'success');
332
}
333

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

    
338
display_top_tabs($tab_array);
339

    
340
$showantilockout = false;
341
$showprivate = false;
342
$showblockbogons = false;
343

    
344
if (!isset($config['system']['webgui']['noantilockout']) &&
345
    (((count($config['interfaces']) > 1) && ($if == 'lan')) ||
346
    ((count($config['interfaces']) == 1) && ($if == 'wan')))) {
347
	$showantilockout = true;
348
}
349

    
350
if (isset($config['interfaces'][$if]['blockpriv'])) {
351
	$showprivate = true;
352
}
353

    
354
if (isset($config['interfaces'][$if]['blockbogons'])) {
355
	$showblockbogons = true;
356
}
357

    
358
/* Load the counter data of each pf rule. */
359
$rulescnt = pfSense_get_pf_rules();
360

    
361
// Update this if you add or remove columns!
362
$columns_in_table = 13;
363

    
364
?>
365
<!-- Allow table to scroll when dragging outside of the display window -->
366
<style>
367
.table-responsive {
368
    clear: both;
369
    overflow-x: visible;
370
    margin-bottom: 0px;
371
}
372
</style>
373

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

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

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

    
472
foreach ($a_filter as $filteri => $filterent):
473

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

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

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

    
510
		$isadvset = firewall_check_for_advanced_options($filterent);
511
		if ($isadvset) {
512
			print '<i class="fa fa-cog" title="'. gettext("advanced setting") .': '. $isadvset .'"></i>';
513
		}
514

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

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

    
543
					foreach ($schedule['timerange'] as $timerange) {
544
						$tempFriendlyTime = "";
545
						$tempID = "";
546
						$firstprint = false;
547
						if ($timerange) {
548
							$dayFriendly = "";
549
							$tempFriendlyTime = "";
550

    
551
							//get hours
552
							$temptimerange = $timerange['hour'];
553
							$temptimeseparator = strrpos($temptimerange, "-");
554

    
555
							$starttime = substr ($temptimerange, 0, $temptimeseparator);
556
							$stoptime = substr ($temptimerange, $temptimeseparator+1);
557

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

    
568
									if (!$firstDayFound) {
569
										$firstDay = $day;
570
										$firstmonth = $month;
571
										$firstDayFound = true;
572
									}
573

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

    
687
		if (isset($filterent['protocol'])) {
688
			echo strtoupper($filterent['protocol']);
689

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

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

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

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

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

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

    
873
	printf(gettext("%sClick the anchor icon %s to move checked rules before the clicked row. Hold down " .
874
			"the shift key and click to move the rules after the clicked row."), '<br /><br />', '<i class="fa fa-anchor"></i>')
875
?>
876
	</div>
877
	</div>
878
</div>
879

    
880
<script type="text/javascript">
881
//<![CDATA[
882

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

    
890
events.push(function() {
891

    
892
	// "Move to here" (anchor) action
893
	$('[id^=Xmove_]').click(function (event) {
894

    
895
		// Prevent click from toggling row
896
		event.stopImmediatePropagation();
897

    
898
		// Save the target rule position
899
		var anchor_row = $(this).parents("tr:first");
900

    
901
		if (event.shiftKey) {
902
			$($('#ruletable > tbody  > tr').get().reverse()).each(function() {
903
				ruleid = this.id.slice(2);
904

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

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

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

    
938
		$(this).css("cursor", "default");
939

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

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

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

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

    
975
	$('table tbody.user-entries').show();
976

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

    
981
		// Save the separator bar configuration
982
		save_separators();
983

    
984
		// Suppress the "Do you really want to leave the page" message
985
		saving = true;
986
	});
987

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

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

    
1008
<?php include("foot.inc");?>
(47-47/225)