Project

General

Profile

Download (33.5 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(gettext("Firewall: Rules - deleted a firewall rule."))) {
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(gettext("Firewall: Rules - deleted selected firewall rules."))) {
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
			$wc_msg = gettext('Firewall: Rules - enabled a firewall rule.');
239
		} else {
240
			$a_filter[$_POST['id']]['disabled'] = true;
241
			$wc_msg = gettext('Firewall: Rules - disabled a firewall rule.');
242
		}
243
		if (write_config($wc_msg)) {
244
			mark_subsystem_dirty('filter');
245
		}
246

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

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

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

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

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

    
283
		$a_filter = $a_filter_new;
284

    
285
		$config['filter']['separator'][strtolower($if)] = "";
286

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

    
294
		if (write_config(gettext("Firewall: Rules - reordered firewall rules."))) {
295
			mark_subsystem_dirty('filter');
296
		}
297

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

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

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

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

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

    
320
include("head.inc");
321
$nrules = 0;
322

    
323
if ($savemsg) {
324
	print_info_box($savemsg, 'success');
325
}
326

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

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

    
335
display_top_tabs($tab_array, false, 'pills');
336

    
337
$showantilockout = false;
338
$showprivate = false;
339
$showblockbogons = false;
340

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

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

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

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

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

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

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

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

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

    
470
foreach ($a_filter as $filteri => $filterent):
471

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

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

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

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

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

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

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

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

    
553
							$starttime = substr ($temptimerange, 0, $temptimeseparator);
554
							$stoptime = substr ($temptimerange, $temptimeseparator+1);
555

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

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

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

    
685
		if (isset($filterent['protocol'])) {
686
			echo strtoupper($filterent['protocol']);
687

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

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

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

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

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

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

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

    
878
<script type="text/javascript">
879
//<![CDATA[
880

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

    
888
events.push(function() {
889

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

    
893
		// Prevent click from toggling row
894
		event.stopImmediatePropagation();
895

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

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

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

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

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

    
936
		$(this).css("cursor", "default");
937

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

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

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

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

    
974
	$('table tbody.user-entries').show();
975
<?php endif; ?>
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");?>
(51-51/231)