Project

General

Profile

Download (36.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-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8
 * Copyright (c) 2014-2020 Rubicon Communications, LLC (Netgate)
9
 * All rights reserved.
10
 *
11
 * originally based on m0n0wall (http://m0n0.ch/wall)
12
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
13
 * All rights reserved.
14
 *
15
 * Licensed under the Apache License, Version 2.0 (the "License");
16
 * you may not use this file except in compliance with the License.
17
 * You may obtain a copy of the License at
18
 *
19
 * http://www.apache.org/licenses/LICENSE-2.0
20
 *
21
 * Unless required by applicable law or agreed to in writing, software
22
 * distributed under the License is distributed on an "AS IS" BASIS,
23
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
 * See the License for the specific language governing permissions and
25
 * limitations under the License.
26
 */
27

    
28
##|+PRIV
29
##|*IDENT=page-firewall-rules
30
##|*NAME=Firewall: Rules
31
##|*DESCR=Allow access to the 'Firewall: Rules' page.
32
##|*MATCH=firewall_rules.php*
33
##|-PRIV
34

    
35
require_once("guiconfig.inc");
36
require_once("functions.inc");
37
require_once("filter.inc");
38
require_once("ipsec.inc");
39
require_once("shaper.inc");
40

    
41
$XmoveTitle = gettext("Move checked rules above this one. Shift+Click to move checked rules below.");
42
$ShXmoveTitle = gettext("Move checked rules below this one. Release shift to move checked rules above.");
43

    
44
$shortcut_section = "firewall";
45

    
46
function get_pf_rules($rules, $tracker_start, $tracker_end) {
47

    
48
	if ($rules == NULL || !is_array($rules)) {
49
		return (NULL);
50
	}
51

    
52
	$arr = array();
53
	foreach ($rules as $rule) {
54
		if ($rule['tracker'] >= $tracker_start &&
55
		    $rule['tracker'] <= $tracker_end) {
56
			$arr[] = $rule;
57
		}
58
	}
59

    
60
	if (count($arr) == 0)
61
		return (NULL);
62

    
63
	return ($arr);
64
}
65

    
66
function print_states($tracker_start, $tracker_end = -1) {
67
	global $rulescnt;
68

    
69
	if (empty($tracker_start)) {
70
		return;
71
	}
72

    
73
	if ($tracker_end === -1) {
74
		$tracker_end = $tracker_start;
75
	} elseif ($tracker_end < $tracker_start) {
76
		return;
77
	}
78

    
79
	$rulesid = "";
80
	$bytes = 0;
81
	$states = 0;
82
	$packets = 0;
83
	$evaluations = 0;
84
	$stcreations = 0;
85
	$rules = get_pf_rules($rulescnt, $tracker_start, $tracker_end);
86
	if (is_array($rules)) {
87
		foreach ($rules as $rule) {
88
			$bytes += $rule['bytes'];
89
			$states += $rule['states'];
90
			$packets += $rule['packets'];
91
			$evaluations += $rule['evaluations'];
92
			$stcreations += $rule['state creations'];
93
			if (strlen($rulesid) > 0) {
94
				$rulesid .= ",";
95
			}
96
			$rulesid .= "{$rule['id']}";
97
		}
98
	}
99

    
100
	$trackertext = "Tracking ID: {$tracker_start}";
101
	if ($tracker_end != $tracker_start) {
102
		$trackertext .= '-' . $tracker_end;
103
	}
104
	$trackertext .= "<br />";
105

    
106
	printf("<a href=\"diag_dump_states.php?ruleid=%s\" " .
107
	    "data-toggle=\"popover\" data-trigger=\"hover focus\" " .
108
	    "title=\"%s\" ", $rulesid, gettext("States details"));
109
	printf("data-content=\"{$trackertext}evaluations: %s<br />packets: " .
110
	    "%s<br />bytes: %s<br />states: %s<br />state creations: " .
111
	    "%s\" data-html=\"true\" usepost>",
112
	    format_number($evaluations), format_number($packets),
113
	    format_bytes($bytes), format_number($states),
114
	    format_number($stcreations));
115
	printf("%s/%s</a><br />", format_number($states), format_bytes($bytes));
116
}
117

    
118
function delete_nat_association($id) {
119
	global $config;
120

    
121
	if (!$id || !is_array($config['nat']['rule'])) {
122
		return;
123
	}
124

    
125
	$a_nat = &$config['nat']['rule'];
126

    
127
	foreach ($a_nat as &$natent) {
128
		if ($natent['associated-rule-id'] == $id) {
129
			$natent['associated-rule-id'] = '';
130
		}
131
	}
132
}
133

    
134
init_config_arr(array('filter', 'rule'));
135
filter_rules_sort();
136
$a_filter = &$config['filter']['rule'];
137

    
138
if ($_REQUEST['if']) {
139
	$if = $_REQUEST['if'];
140
}
141

    
142
$ifdescs = get_configured_interface_with_descr();
143

    
144
$iflist = filter_get_interface_list();
145

    
146
if (!$if || !isset($iflist[$if])) {
147
	if ($if != "any" && $if != "FloatingRules" && isset($iflist['wan'])) {
148
		$if = "wan";
149
	} else {
150
		$if = "FloatingRules";
151
	}
152
}
153

    
154
if ($_POST['apply']) {
155
	$retval = 0;
156
	$retval |= filter_configure();
157

    
158
	clear_subsystem_dirty('filter');
159
}
160

    
161
if ($_POST['act'] == "del") {
162
	if ($a_filter[$_POST['id']]) {
163
		if (!empty($a_filter[$_POST['id']]['associated-rule-id'])) {
164
			delete_nat_association($a_filter[$_POST['id']]['associated-rule-id']);
165
		}
166
		unset($a_filter[$_POST['id']]);
167

    
168
		// Update the separators
169
		init_config_arr(array('filter', 'separator', strtolower($if)));
170
		$a_separators = &$config['filter']['separator'][strtolower($if)];
171
		$ridx = ifridx($if, $_POST['id']);	// get rule index within interface
172
		$mvnrows = -1;
173
		move_separators($a_separators, $ridx, $mvnrows);
174

    
175
		if (write_config(gettext("Firewall: Rules - deleted a firewall rule."))) {
176
			mark_subsystem_dirty('filter');
177
		}
178

    
179
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
180
		exit;
181
	}
182
}
183

    
184
// Handle save msg if defined
185
if ($_REQUEST['savemsg']) {
186
	$savemsg = htmlentities($_REQUEST['savemsg']);
187
}
188

    
189
if (isset($_POST['del_x'])) {
190
	/* delete selected rules */
191
	$deleted = false;
192

    
193
	if (is_array($_POST['rule']) && count($_POST['rule'])) {
194
		init_config_arr(array('filter', 'separator', strtolower($if)));
195
		$a_separators = &$config['filter']['separator'][strtolower($if)];
196
		$num_deleted = 0;
197

    
198
		foreach ($_POST['rule'] as $rulei) {
199
			delete_nat_association($a_filter[$rulei]['associated-rule-id']);
200
			unset($a_filter[$rulei]);
201
			$deleted = true;
202

    
203
			// Update the separators
204
			// As rules are deleted, $ridx has to be decremented or separator position will break
205
			$ridx = ifridx($if, $rulei) - $num_deleted;	// get rule index within interface
206
			$mvnrows = -1;
207
			move_separators($a_separators, $ridx, $mvnrows);
208
			$num_deleted++;
209
		}
210

    
211
		if ($deleted) {
212
			if (write_config(gettext("Firewall: Rules - deleted selected firewall rules."))) {
213
				mark_subsystem_dirty('filter');
214
			}
215
		}
216

    
217
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
218
		exit;
219
	}
220
} else if ($_POST['act'] == "toggle") {
221
	if ($a_filter[$_POST['id']]) {
222
		if (isset($a_filter[$_POST['id']]['disabled'])) {
223
			unset($a_filter[$_POST['id']]['disabled']);
224
			$wc_msg = gettext('Firewall: Rules - enabled a firewall rule.');
225
		} else {
226
			$a_filter[$_POST['id']]['disabled'] = true;
227
			$wc_msg = gettext('Firewall: Rules - disabled a firewall rule.');
228
		}
229
		if (write_config($wc_msg)) {
230
			mark_subsystem_dirty('filter');
231
		}
232

    
233
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
234
		exit;
235
	}
236
} else if ($_POST['order-store']) {
237

    
238
	/* update rule order, POST[rule] is an array of ordered IDs */
239
	if (is_array($_POST['rule']) && !empty($_POST['rule'])) {
240
		$a_filter_new = array();
241

    
242
		// Include the rules of other interfaces listed in config before this (the selected) interface.
243
		foreach ($a_filter as $filteri_before => $filterent) {
244
			if (($filterent['interface'] == $if && !isset($filterent['floating'])) || (isset($filterent['floating']) && "FloatingRules" == $if)) {
245
				break;
246
			} else {
247
				$a_filter_new[] = $filterent;
248
			}
249
		}
250

    
251
		// Include the rules of this (the selected) interface.
252
		// If a rule is not in POST[rule], it has been deleted by the user
253
		foreach ($_POST['rule'] as $id) {
254
			$a_filter_new[] = $a_filter[$id];
255
		}
256

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

    
269
		$a_filter = $a_filter_new;
270

    
271
		$config['filter']['separator'][strtolower($if)] = "";
272

    
273
		if ($_POST['separator']) {
274
			$idx = 0;
275
			if (!is_array($config['filter']['separator'])) {
276
				$config['filter']['separator'] = array();
277
			}
278

    
279
			foreach ($_POST['separator'] as $separator) {
280
				if (!is_array($config['filter']['separator'][strtolower($separator['if'])]))  {
281
					$config['filter']['separator'][strtolower($separator['if'])] = array();
282
				}
283

    
284
				$config['filter']['separator'][strtolower($separator['if'])]['sep' . $idx++] = $separator;
285
			}
286
		}
287

    
288
		if (write_config(gettext("Firewall: Rules - reordered firewall rules."))) {
289
			mark_subsystem_dirty('filter');
290
		}
291

    
292
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
293
		exit;
294
	}
295
}
296

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

    
299
foreach ($iflist as $ifent => $ifname) {
300
	$tab_array[] = array($ifname, ($ifent == $if), "firewall_rules.php?if={$ifent}");
301
}
302

    
303
foreach ($tab_array as $dtab) {
304
	if ($dtab[1]) {
305
		$bctab = $dtab[0];
306
		break;
307
	}
308
}
309

    
310
$pgtitle = array(gettext("Firewall"), gettext("Rules"), $bctab);
311
$pglinks = array("", "firewall_rules.php", "@self");
312
$shortcut_section = "firewall";
313

    
314
include("head.inc");
315
$nrules = 0;
316

    
317
if ($savemsg) {
318
	print_info_box($savemsg, 'success');
319
}
320

    
321
if ($_POST['apply']) {
322
	print_apply_result_box($retval);
323
}
324

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

    
329
display_top_tabs($tab_array, false, 'pills');
330

    
331
$showantilockout = false;
332
$showprivate = false;
333
$showblockbogons = false;
334

    
335
if (!isset($config['system']['webgui']['noantilockout']) &&
336
    (((count($config['interfaces']) > 1) && ($if == 'lan')) ||
337
    ((count($config['interfaces']) == 1) && ($if == 'wan')))) {
338
	$showantilockout = true;
339
}
340

    
341
if (isset($config['interfaces'][$if]['blockpriv'])) {
342
	$showprivate = true;
343
}
344

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

    
349
if (isset($config['system']['webgui']['roworderdragging'])) {
350
	$rules_header_text = gettext("Rules");
351
} else {
352
	$rules_header_text = gettext("Rules (Drag to Change Order)");
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
/* Floating rules tab has one extra column
362
 * https://redmine.pfsense.org/issues/10667 */
363
if ($if == "FloatingRules") {
364
	$columns_in_table++;
365
}
366

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

    
377
<form method="post">
378
	<input name="if" id="if" type="hidden" value="<?=$if?>" />
379
	<div class="panel panel-default">
380
		<div class="panel-heading"><h2 class="panel-title"><?=$rules_header_text?></h2></div>
381
		<div id="mainarea" class="table-responsive panel-body">
382
			<table id="ruletable" class="table table-hover table-striped table-condensed" style="overflow-x: 'visible'">
383
				<thead>
384
					<tr>
385
						<th><input type="checkbox" id="selectAll" name="selectAll" /></th>
386
						<th><!-- status icons --></th>
387
						<th><?=gettext("States")?></th>
388
				<?php
389
					if ('FloatingRules' == $if) {
390
				?>
391
						<th><?=gettext("Interfaces")?></th>
392
				<?php
393
					}
394
				?>
395
						<th><?=gettext("Protocol")?></th>
396
						<th><?=gettext("Source")?></th>
397
						<th><?=gettext("Port")?></th>
398
						<th><?=gettext("Destination")?></th>
399
						<th><?=gettext("Port")?></th>
400
						<th><?=gettext("Gateway")?></th>
401
						<th><?=gettext("Queue")?></th>
402
						<th><?=gettext("Schedule")?></th>
403
						<th><?=gettext("Description")?></th>
404
						<th><?=gettext("Actions")?></th>
405
					</tr>
406
				</thead>
407

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

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

    
483
foreach ($a_filter as $filteri => $filterent):
484

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

    
487
		// Display separator(s) for section beginning at rule n
488
		if ($seprows[$nrules]) {
489
			display_separator($separators, $nrules, $columns_in_table);
490
		}
491
?>
492
					<tr id="fr<?=$nrules;?>" onClick="fr_toggle(<?=$nrules;?>)" ondblclick="document.location='firewall_rules_edit.php?id=<?=$filteri;?>';" <?=(isset($filterent['disabled']) ? ' class="disabled"' : '')?>>
493
						<td>
494
							<input type="checkbox" id="frc<?=$nrules;?>" onClick="fr_toggle(<?=$nrules;?>)" name="rule[]" value="<?=$filteri;?>"/>
495
						</td>
496

    
497
	<?php
498
		if ($filterent['type'] == "block") {
499
			$iconfn = "times text-danger";
500
			$title_text = gettext("traffic is blocked");
501
		} else if ($filterent['type'] == "reject") {
502
			$iconfn = "hand-stop-o text-warning";
503
			$title_text = gettext("traffic is rejected");
504
		} else if ($filterent['type'] == "match") {
505
			$iconfn = "filter";
506
			$title_text = gettext("traffic is matched");
507
		} else {
508
			$iconfn = "check text-success";
509
			$title_text = gettext("traffic is passed");
510
		}
511
	?>
512
						<td title="<?=$title_text?>">
513
							<a href="?if=<?=htmlspecialchars($if);?>&amp;act=toggle&amp;id=<?=$filteri;?>" usepost>
514
								<i class="fa fa-<?=$iconfn?>" title="<?=gettext("click to toggle enabled/disabled status");?>"></i>
515
							</a>
516
	<?php
517
		if ($filterent['quick'] == 'yes') {
518
			print '<i class="fa fa-forward text-success" title="'. gettext("&quot;Quick&quot; rule. Applied immediately on match.") .'" style="cursor: pointer;"></i>';
519
		}
520

    
521
		$isadvset = firewall_check_for_advanced_options($filterent);
522
		if ($isadvset) {
523
			print '<i class="fa fa-cog" title="'. gettext("advanced setting") .': '. $isadvset .'"></i>';
524
		}
525

    
526
		if (isset($filterent['log'])) {
527
			print '<i class="fa fa-tasks" title="'. gettext("traffic is logged") .'" style="cursor: pointer;"></i>';
528
		}
529
	?>
530
						</td>
531
	<?php
532
		$alias = rule_columns_with_alias(
533
			$filterent['source']['address'],
534
			pprint_port($filterent['source']['port']),
535
			$filterent['destination']['address'],
536
			pprint_port($filterent['destination']['port'])
537
		);
538

    
539
		//build Schedule popup box
540
		init_config_arr(array('schedules', 'schedule'));
541
		$a_schedules = &$config['schedules']['schedule'];
542
		$schedule_span_begin = "";
543
		$schedule_span_end = "";
544
		$sched_caption_escaped = "";
545
		$sched_content = "";
546
		$schedstatus = false;
547
		$dayArray = array (gettext('Mon'), gettext('Tues'), gettext('Wed'), gettext('Thur'), gettext('Fri'), gettext('Sat'), gettext('Sun'));
548
		$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'));
549
		if ($config['schedules']['schedule'] != "" && is_array($config['schedules']['schedule'])) {
550
			$idx = 0;
551
			foreach ($a_schedules as $schedule) {
552
				if (!empty($schedule['name']) &&
553
				    $schedule['name'] == $filterent['sched']) {
554
					$schedstatus = filter_get_time_based_rule_status($schedule);
555

    
556
					foreach ($schedule['timerange'] as $timerange) {
557
						$tempFriendlyTime = "";
558
						$tempID = "";
559
						$firstprint = false;
560
						if ($timerange) {
561
							$dayFriendly = "";
562
							$tempFriendlyTime = "";
563

    
564
							//get hours
565
							$temptimerange = $timerange['hour'];
566
							$temptimeseparator = strrpos($temptimerange, "-");
567

    
568
							$starttime = substr ($temptimerange, 0, $temptimeseparator);
569
							$stoptime = substr ($temptimerange, $temptimeseparator+1);
570

    
571
							if ($timerange['month']) {
572
								$tempmontharray = explode(",", $timerange['month']);
573
								$tempdayarray = explode(",", $timerange['day']);
574
								$arraycounter = 0;
575
								$firstDayFound = false;
576
								$firstPrint = false;
577
								foreach ($tempmontharray as $monthtmp) {
578
									$month = $tempmontharray[$arraycounter];
579
									$day = $tempdayarray[$arraycounter];
580

    
581
									if (!$firstDayFound) {
582
										$firstDay = $day;
583
										$firstmonth = $month;
584
										$firstDayFound = true;
585
									}
586

    
587
									$currentDay = $day;
588
									$nextDay = $tempdayarray[$arraycounter+1];
589
									$currentDay++;
590
									if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])) {
591
										if ($firstPrint) {
592
											$dayFriendly .= ", ";
593
										}
594
										$currentDay--;
595
										if ($currentDay != $firstDay) {
596
											$dayFriendly .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
597
										} else {
598
											$dayFriendly .=	 $monthArray[$month-1] . " " . $day;
599
										}
600
										$firstDayFound = false;
601
										$firstPrint = true;
602
									}
603
									$arraycounter++;
604
								}
605
							} else {
606
								$tempdayFriendly = $timerange['position'];
607
								$firstDayFound = false;
608
								$tempFriendlyDayArray = explode(",", $tempdayFriendly);
609
								$currentDay = "";
610
								$firstDay = "";
611
								$nextDay = "";
612
								$counter = 0;
613
								foreach ($tempFriendlyDayArray as $day) {
614
									if ($day != "") {
615
										if (!$firstDayFound) {
616
											$firstDay = $tempFriendlyDayArray[$counter];
617
											$firstDayFound = true;
618
										}
619
										$currentDay =$tempFriendlyDayArray[$counter];
620
										//get next day
621
										$nextDay = $tempFriendlyDayArray[$counter+1];
622
										$currentDay++;
623
										if ($currentDay != $nextDay) {
624
											if ($firstprint) {
625
												$dayFriendly .= ", ";
626
											}
627
											$currentDay--;
628
											if ($currentDay != $firstDay) {
629
												$dayFriendly .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
630
											} else {
631
												$dayFriendly .= $dayArray[$firstDay-1];
632
											}
633
											$firstDayFound = false;
634
											$firstprint = true;
635
										}
636
										$counter++;
637
									}
638
								}
639
							}
640
							$timeFriendly = $starttime . " - " . $stoptime;
641
							$description = $timerange['rangedescr'];
642
							$sched_content .= $dayFriendly . "; " . $timeFriendly . "<br />";
643
						}
644
					}
645
					#FIXME
646
					$sched_caption_escaped = str_replace("'", "\'", $schedule['descr']);
647
					$schedule_span_begin = '<a href="/firewall_schedule_edit.php?id=' . $idx . '" data-toggle="popover" data-trigger="hover focus" title="' . $schedule['name'] . '" data-content="' .
648
						$sched_caption_escaped . '" data-html="true">';
649
					$schedule_span_end = "</a>";
650
				}
651
				$idx++;
652
			}
653
		}
654
		$printicon = false;
655
		$alttext = "";
656
		$image = "";
657
		if (!isset($filterent['disabled'])) {
658
			if ($schedstatus) {
659
				if ($filterent['type'] == "block" || $filterent['type'] == "reject") {
660
					$image = "times-circle";
661
					$dispcolor = "text-danger";
662
					$alttext = gettext("Traffic matching this rule is currently being denied");
663
				} else {
664
					$image = "play-circle";
665
					$dispcolor = "text-success";
666
					$alttext = gettext("Traffic matching this rule is currently being allowed");
667
				}
668
				$printicon = true;
669
			} else if ($filterent['sched']) {
670
				if ($filterent['type'] == "block" || $filterent['type'] == "reject") {
671
					$image = "times-circle";
672
				} else {
673
					$image = "play-circle";
674
				}
675
				$alttext = gettext("This rule is not currently active because its period has expired");
676
				$dispcolor = "text-warning";
677
				$printicon = true;
678
			}
679
		}
680
	?>
681
				<td><?php print_states(intval($filterent['tracker'])); ?></td>
682
	<?php
683
		if ($if == 'FloatingRules') {
684
	?>
685
			<td onclick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
686
	<?php
687
			if (isset($filterent['interface'])) {
688
				$selected_interfaces = explode(',', $filterent['interface']);
689
				unset($selected_descs);
690
				foreach ($selected_interfaces as $interface) {
691
					if (isset($ifdescs[$interface])) {
692
						$selected_descs[] = $ifdescs[$interface];
693
					} else {
694
						switch ($interface) {
695
						case 'l2tp':
696
							if ($config['l2tp']['mode'] == 'server')
697
								$selected_descs[] = 'L2TP VPN';
698
							break;
699
						case 'pppoe':
700
							if (is_pppoe_server_enabled())
701
								$selected_descs[] = 'PPPoE Server';
702
							break;
703
						case 'enc0':
704
							if (ipsec_enabled())
705
								$selected_descs[] = 'IPsec';
706
							break;
707
						case 'openvpn':
708
							if  ($config['openvpn']['openvpn-server'] || $config['openvpn']['openvpn-client'])
709
								$selected_descs[] = 'OpenVPN';
710
							break;
711
						default:
712
							$selected_descs[] = $interface;
713
							break;
714
						}
715
					}
716
				}
717
				if (!empty($selected_descs)) {
718
					$desclist = '';
719
					$desclength = 0;
720
					foreach ($selected_descs as $descid => $desc) {
721
						$desclength += strlen($desc);
722
						if ($desclength > 18) {
723
							$desclist .= ',<br/>';
724
							$desclength = 0;
725
						} elseif ($desclist) {
726
							$desclist .= ', ';
727
							$desclength += 2;
728
						}
729
						$desclist .= $desc;
730
					}
731
					echo $desclist;
732
				}
733
			}
734
	?>
735
			</td>
736
	<?php
737
		}
738
	?>
739
			<td>
740
	<?php
741
		if (isset($filterent['ipprotocol'])) {
742
			switch ($filterent['ipprotocol']) {
743
				case "inet":
744
					echo "IPv4 ";
745
					break;
746
				case "inet6":
747
					echo "IPv6 ";
748
					break;
749
				case "inet46":
750
					echo "IPv4+6 ";
751
					break;
752
			}
753
		} else {
754
			echo "IPv4 ";
755
		}
756

    
757
		if (isset($filterent['protocol'])) {
758
			echo strtoupper($filterent['protocol']);
759

    
760
			if (strtoupper($filterent['protocol']) == "ICMP" && !empty($filterent['icmptype'])) {
761
				// replace each comma-separated icmptype item by its (localised) full description
762
				$t = 	implode(', ',
763
						array_map(
764
						        function($type) {
765
								global $icmptypes;
766
								return $icmptypes[$type]['descrip'];
767
							},
768
							explode(',', $filterent['icmptype'])
769
						)
770
					);
771
				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']));
772
			}
773
		} else {
774
			echo " *";
775
		}
776
	?>
777
						</td>
778
						<td>
779
							<?php if (isset($alias['src'])): ?>
780
								<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">
781
									<?=str_replace('_', '_<wbr>', htmlspecialchars(pprint_address($filterent['source'])))?>
782
								</a>
783
							<?php else: ?>
784
								<?=htmlspecialchars(pprint_address($filterent['source']))?>
785
							<?php endif; ?>
786
						</td>
787
						<td>
788
							<?php if (isset($alias['srcport'])): ?>
789
								<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">
790
									<?=str_replace('_', '_<wbr>', htmlspecialchars(pprint_port($filterent['source']['port'])))?>
791
								</a>
792
							<?php else: ?>
793
								<?=htmlspecialchars(pprint_port($filterent['source']['port']))?>
794
							<?php endif; ?>
795
						</td>
796
						<td>
797
							<?php if (isset($alias['dst'])): ?>
798
								<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">
799
									<?=str_replace('_', '_<wbr>', htmlspecialchars(pprint_address($filterent['destination'])))?>
800
								</a>
801
							<?php else: ?>
802
								<?=htmlspecialchars(pprint_address($filterent['destination']))?>
803
							<?php endif; ?>
804
						</td>
805
						<td>
806
							<?php if (isset($alias['dstport'])): ?>
807
								<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">
808
									<?=str_replace('_', '_<wbr>', htmlspecialchars(pprint_port($filterent['destination']['port'])))?>
809
								</a>
810
							<?php else: ?>
811
								<?=htmlspecialchars(pprint_port($filterent['destination']['port']))?>
812
							<?php endif; ?>
813
						</td>
814
						<td>
815
							<?php if (isset($filterent['gateway'])): ?>
816
								<span data-toggle="popover" data-trigger="hover focus" title="<?=gettext('Gateways details')?>" data-content="<?=gateway_info_popup($filterent['gateway'])?>" data-html="true">
817
							<?php else: ?>
818
								<span>
819
							<?php endif; ?>
820
								<?php if (isset($config['interfaces'][$filterent['gateway']]['descr'])): ?>
821
									<?=str_replace('_', '_<wbr>', htmlspecialchars($config['interfaces'][$filterent['gateway']]['descr']))?>
822
								<?php else: ?>
823
									<?=htmlspecialchars(pprint_port($filterent['gateway']))?>
824
								<?php endif; ?>
825
							</span>
826
						</td>
827
						<td>
828
							<?php
829
								if (isset($filterent['ackqueue']) && isset($filterent['defaultqueue'])) {
830
									$desc = str_replace('_', ' ', $filterent['ackqueue']);
831
									echo "<a href=\"firewall_shaper_queues.php?queue={$filterent['ackqueue']}&amp;action=show\">{$desc}</a>";
832
									$desc = str_replace('_', '_<wbr>', $filterent['defaultqueue']);
833
									echo "/<a href=\"firewall_shaper_queues.php?queue={$filterent['defaultqueue']}&amp;action=show\">{$desc}</a>";
834
								} else if (isset($filterent['defaultqueue'])) {
835
									$desc = str_replace('_', '_<wbr>', $filterent['defaultqueue']);
836
									echo "<a href=\"firewall_shaper_queues.php?queue={$filterent['defaultqueue']}&amp;action=show\">{$desc}</a>";
837
								} else {
838
									echo gettext("none");
839
								}
840
							?>
841
						</td>
842
						<td>
843
							<?php if ($printicon) { ?>
844
								<i class="fa fa-<?=$image?> <?=$dispcolor?>" title="<?=$alttext;?>"></i>
845
							<?php } ?>
846
							<?=$schedule_span_begin;?><?=str_replace('_', '_<wbr>', htmlspecialchars($filterent['sched']));?>&nbsp;<?=$schedule_span_end;?>
847
						</td>
848
						<td>
849
							<?=htmlspecialchars($filterent['descr']);?>
850
						</td>
851
						<td class="action-icons">
852
						<!-- <?=(isset($filterent['disabled']) ? 'enable' : 'disable')?> -->
853
							<a	class="fa fa-anchor icon-pointer" id="Xmove_<?=$filteri?>" title="<?=$XmoveTitle?>"></a>
854
							<a href="firewall_rules_edit.php?id=<?=$filteri;?>" class="fa fa-pencil" title="<?=gettext('Edit')?>"></a>
855
							<a href="firewall_rules_edit.php?dup=<?=$filteri;?>" class="fa fa-clone" title="<?=gettext('Copy')?>"></a>
856
<?php if (isset($filterent['disabled'])) {
857
?>
858
							<a href="?act=toggle&amp;if=<?=htmlspecialchars($if);?>&amp;id=<?=$filteri;?>" class="fa fa-check-square-o" title="<?=gettext('Enable')?>" usepost></a>
859
<?php } else {
860
?>
861
							<a href="?act=toggle&amp;if=<?=htmlspecialchars($if);?>&amp;id=<?=$filteri;?>" class="fa fa-ban" title="<?=gettext('Disable')?>" usepost></a>
862
<?php }
863
?>
864
							<a href="?act=del&amp;if=<?=htmlspecialchars($if);?>&amp;id=<?=$filteri;?>" class="fa fa-trash" title="<?=gettext('Delete this rule')?>" usepost></a>
865
						</td>
866
					</tr>
867
<?php
868
		$nrules++;
869
	}
870
endforeach;
871

    
872
// There can be separator(s) after the last rule listed.
873
if ($seprows[$nrules]) {
874
	display_separator($separators, $nrules, $columns_in_table);
875
}
876
?>
877
				</tbody>
878
			</table>
879
		</div>
880
	</div>
881

    
882
<?php if ($nrules == 0): ?>
883
	<div class="alert alert-warning" role="alert">
884
		<p>
885
		<?php if ($_REQUEST['if'] == "FloatingRules"): ?>
886
			<?=gettext("No floating rules are currently defined.");?>
887
		<?php else: ?>
888
			<?=gettext("No rules are currently defined for this interface");?><br />
889
			<?=gettext("All incoming connections on this interface will be blocked until pass rules are added.");?>
890
		<?php endif;?>
891
			<?=gettext("Click the button to add a new rule.");?>
892
		</p>
893
	</div>
894
<?php endif;?>
895

    
896
	<nav class="action-buttons">
897
		<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')?>">
898
			<i class="fa fa-level-up icon-embed-btn"></i>
899
			<?=gettext("Add");?>
900
		</a>
901
		<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')?>">
902
			<i class="fa fa-level-down icon-embed-btn"></i>
903
			<?=gettext("Add");?>
904
		</a>
905
		<button name="del_x" type="submit" class="btn btn-danger btn-sm" value="<?=gettext("Delete selected rules"); ?>" title="<?=gettext('Delete selected rules')?>">
906
			<i class="fa fa-trash icon-embed-btn"></i>
907
			<?=gettext("Delete"); ?>
908
		</button>
909
		<button type="submit" id="order-store" name="order-store" class="btn btn-sm btn-primary" value="store changes" disabled title="<?=gettext('Save rule order')?>">
910
			<i class="fa fa-save icon-embed-btn"></i>
911
			<?=gettext("Save")?>
912
		</button>
913
		<button type="submit" id="addsep" name="addsep" class="btn btn-sm btn-warning" title="<?=gettext('Add separator')?>">
914
			<i class="fa fa-plus icon-embed-btn"></i>
915
			<?=gettext("Separator")?>
916
		</button>
917
	</nav>
918
</form>
919

    
920
<div class="infoblock">
921
	<div class="alert alert-info clearfix" role="alert"><div class="pull-left">
922
		<dl class="dl-horizontal responsive">
923
		<!-- Legend -->
924
			<dt><?=gettext('Legend')?></dt>				<dd></dd>
925
			<dt><i class="fa fa-check text-success"></i></dt>		<dd><?=gettext("Pass");?></dd>
926
			<dt><i class="fa fa-filter"></i></dt>	<dd><?=gettext("Match");?></dd>
927
			<dt><i class="fa fa-times text-danger"></i></dt>	<dd><?=gettext("Block");?></dd>
928
			<dt><i class="fa fa-hand-stop-o text-warning"></i></dt>		<dd><?=gettext("Reject");?></dd>
929
			<dt><i class="fa fa-tasks"></i></dt>	<dd> <?=gettext("Log");?></dd>
930
			<dt><i class="fa fa-cog"></i></dt>		<dd> <?=gettext("Advanced filter");?></dd>
931
			<dt><i class="fa fa-forward text-success"></i></dt><dd> <?=gettext("&quot;Quick&quot; rule. Applied immediately on match.")?></dd>
932
		</dl>
933

    
934
<?php
935
	if ("FloatingRules" != $if) {
936
		print(gettext("Rules are evaluated on a first-match basis (i.e. " .
937
			"the action of the first rule to match a packet will be executed). ") . '<br />' .
938
			gettext("This means that if block rules are used, it is important to pay attention " .
939
			"to the rule order. Everything that isn't explicitly passed is blocked " .
940
			"by default. "));
941
	} else {
942
		print(gettext("Floating rules are evaluated on a first-match basis (i.e. " .
943
			"the action of the first rule to match a packet will be executed) only " .
944
			"if the 'quick' option is checked on a rule. Otherwise they will only match if no " .
945
			"other rules match. Pay close attention to the rule order and options " .
946
			"chosen. If no rule here matches, the per-interface or default rules are used. "));
947
	}
948

    
949
	printf(gettext('%1$sClick the anchor icon %2$s to move checked rules before the clicked row. Hold down ' .
950
			'the shift key and click to move the rules after the clicked row.'), '<br /><br />', '<i class="fa fa-anchor"></i>')
951
?>
952
	</div>
953
	</div>
954
</div>
955

    
956
<script type="text/javascript">
957
//<![CDATA[
958

    
959
//Need to create some variables here so that jquery/pfSenseHelpers.js can read them
960
iface = "<?=strtolower($if)?>";
961
cncltxt = '<?=gettext("Cancel")?>';
962
svtxt = '<?=gettext("Save")?>';
963
svbtnplaceholder = '<?=gettext("Enter a description, Save, then drag to final location.")?>';
964
configsection = "filter";
965

    
966
events.push(function() {
967

    
968
	// "Move to here" (anchor) action
969
	$('[id^=Xmove_]').click(function (event) {
970

    
971
		// Prevent click from toggling row
972
		event.stopImmediatePropagation();
973

    
974
		// Save the target rule position
975
		var anchor_row = $(this).parents("tr:first");
976

    
977
		if (event.shiftKey) {
978
			$($('#ruletable > tbody  > tr').get().reverse()).each(function() {
979
				ruleid = this.id.slice(2);
980

    
981
				if (ruleid && !isNaN(ruleid)) {
982
					if ($('#frc' + ruleid).prop('checked')) {
983
						// Move the selected rows, un-select them and add highlight class
984
						$(this).insertAfter(anchor_row);
985
						fr_toggle(ruleid, "fr");
986
						$('#fr' + ruleid).addClass("highlight");
987
					}
988
				}
989
			});
990
		} else {
991
			$('#ruletable > tbody  > tr').each(function() {
992
				ruleid = this.id.slice(2);
993

    
994
				if (ruleid && !isNaN(ruleid)) {
995
					if ($('#frc' + ruleid).prop('checked')) {
996
						// Move the selected rows, un-select them and add highlight class
997
						$(this).insertBefore(anchor_row);
998
						fr_toggle(ruleid, "fr");
999
						$('#fr' + ruleid).addClass("highlight");
1000
					}
1001
				}
1002
			});
1003
		}
1004

    
1005
		// Temporarily set background color so user can more easily see the moved rules, then fade
1006
		$('.highlight').effect("highlight", {color: "#739b4b;"}, 4000);
1007
		$('#ruletable tr').removeClass("highlight");
1008
		$('#order-store').removeAttr('disabled');
1009
		reindex_rules($(anchor_row).parent('tbody'));
1010
		dirty = true;
1011
	}).mouseover(function(e) {
1012
		var ruleselected = false;
1013

    
1014
		$(this).css("cursor", "default");
1015

    
1016
		// Are any rules currently selected?
1017
		$('[id^=frc]').each(function () {
1018
			if ($(this).prop("checked")) {
1019
				ruleselected = true;
1020
			}
1021
		});
1022

    
1023
		// If so, change the icon to show the insertion point
1024
		if (ruleselected) {
1025
			if (e.shiftKey) {
1026
				$(this).removeClass().addClass("fa fa-lg fa-arrow-down text-danger");
1027
			} else {
1028
				$(this).removeClass().addClass("fa fa-lg fa-arrow-up text-danger");
1029
			}
1030
		}
1031
	}).mouseout(function(e) {
1032
		$(this).removeClass().addClass("fa fa-anchor");
1033
	});
1034

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

    
1040
	$('table tbody.user-entries').sortable({
1041
		cursor: 'grabbing',
1042
		scroll: true,
1043
		overflow: 'scroll',
1044
		scrollSensitivity: 100,
1045
		update: function(event, ui) {
1046
			$('#order-store').removeAttr('disabled');
1047
			reindex_rules(ui.item.parent('tbody'));
1048
			dirty = true;
1049
		}
1050
	});
1051

    
1052
	$('table tbody.user-entries').show();
1053
<?php endif; ?>
1054

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

    
1059
		// Save the separator bar configuration
1060
		save_separators();
1061

    
1062
		// Suppress the "Do you really want to leave the page" message
1063
		saving = true;
1064
	});
1065

    
1066
	// Provide a warning message if the user tries to change page before saving
1067
	$(window).bind('beforeunload', function(){
1068
		if ((!saving && dirty) || newSeperator) {
1069
			return ("<?=gettext('One or more rules have been moved but have not yet been saved')?>");
1070
		} else {
1071
			return undefined;
1072
		}
1073
	});
1074

    
1075
	$(document).on('keyup keydown', function(e){
1076
		if (e.shiftKey) {
1077
			$('[id^=Xmove_]').attr("title", "<?=$ShXmoveTitle?>");
1078
		} else {
1079
			$('[id^=Xmove_]').attr("title", "<?=$XmoveTitle?>");
1080
		}
1081
	});
1082

    
1083
	$('#selectAll').click(function() {
1084
		var checkedStatus = this.checked;
1085
		$('#ruletable tbody tr').find('td:first :checkbox').each(function() {
1086
		$(this).prop('checked', checkedStatus);
1087
		});
1088
	});
1089
});
1090
//]]>
1091
</script>
1092

    
1093
<?php include("foot.inc");?>
(51-51/230)