Project

General

Profile

Download (34.8 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
 * Redistribution and use in source and binary forms, with or without
14
 * modification, are permitted provided that the following conditions are met:
15
 *
16
 * 1. Redistributions of source code must retain the above copyright notice,
17
 *    this list of conditions and the following disclaimer.
18
 *
19
 * 2. Redistributions in binary form must reproduce the above copyright
20
 *    notice, this list of conditions and the following disclaimer in
21
 *    the documentation and/or other materials provided with the
22
 *    distribution.
23
 *
24
 * 3. All advertising materials mentioning features or use of this software
25
 *    must display the following acknowledgment:
26
 *    "This product includes software developed by the pfSense Project
27
 *    for use in the pfSense® software distribution. (http://www.pfsense.org/).
28
 *
29
 * 4. The names "pfSense" and "pfSense Project" must not be used to
30
 *    endorse or promote products derived from this software without
31
 *    prior written permission. For written permission, please contact
32
 *    coreteam@pfsense.org.
33
 *
34
 * 5. Products derived from this software may not be called "pfSense"
35
 *    nor may "pfSense" appear in their names without prior written
36
 *    permission of the Electric Sheep Fencing, LLC.
37
 *
38
 * 6. Redistributions of any form whatsoever must retain the following
39
 *    acknowledgment:
40
 *
41
 * "This product includes software developed by the pfSense Project
42
 * for use in the pfSense software distribution (http://www.pfsense.org/).
43
 *
44
 * THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
45
 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
47
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
48
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
49
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
50
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
51
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
53
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
55
 * OF THE POSSIBILITY OF SUCH DAMAGE.
56
 */
57

    
58
##|+PRIV
59
##|*IDENT=page-firewall-rules
60
##|*NAME=Firewall: Rules
61
##|*DESCR=Allow access to the 'Firewall: Rules' page.
62
##|*MATCH=firewall_rules.php*
63
##|-PRIV
64

    
65
require_once("guiconfig.inc");
66
require_once("functions.inc");
67
require_once("filter.inc");
68
require_once("ipsec.inc");
69
require_once("shaper.inc");
70

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

    
74
$pgtitle = array(gettext("Firewall"), gettext("Rules"));
75
$shortcut_section = "firewall";
76

    
77
function get_pf_rules($rules, $tracker) {
78

    
79
	if ($rules == NULL || !is_array($rules))
80
		return (NULL);
81

    
82
	$arr = array();
83
	foreach ($rules as $rule) {
84
		if ($rule['tracker'] === $tracker) {
85
			$arr[] = $rule;
86
		}
87
	}
88

    
89
	if (count($arr) == 0)
90
		return (NULL);
91

    
92
	return ($arr);
93
}
94

    
95
function print_states($tracker) {
96
	global $rulescnt;
97

    
98
	$rulesid = "";
99
	$bytes = 0;
100
	$states = 0;
101
	$packets = 0;
102
	$evaluations = 0;
103
	$stcreations = 0;
104
	$rules = get_pf_rules($rulescnt, $tracker);
105
	if (is_array($rules)) {
106
		foreach ($rules as $rule) {
107
			$bytes += $rule['bytes'];
108
			$states += $rule['states'];
109
			$packets += $rule['packets'];
110
			$evaluations += $rule['evaluations'];
111
			$stcreations += $rule['state creations'];
112
			if (strlen($rulesid) > 0) {
113
				$rulesid .= ",";
114
			}
115
			$rulesid .= "{$rule['id']}";
116
		}
117
	}
118

    
119
	printf("<a href=\"diag_dump_states.php?ruleid=%s\" data-toggle=\"popover\" data-trigger=\"hover focus\" title=\"%s\" ",
120
	    $rulesid, gettext("States details"));
121
	printf("data-content=\"evaluations: %s<br>packets: %s<br>bytes: %s<br>states: %s<br>state creations: %s\" data-html=\"true\">",
122
	    format_number($evaluations), format_number($packets), format_bytes($bytes),
123
	    format_number($states), format_number($stcreations));
124
	printf("%s/%s</a><br>", format_number($states), format_bytes($bytes));
125
}
126

    
127
function delete_nat_association($id) {
128
	global $config;
129

    
130
	if (!$id || !is_array($config['nat']['rule'])) {
131
		return;
132
	}
133

    
134
	$a_nat = &$config['nat']['rule'];
135

    
136
	foreach ($a_nat as &$natent) {
137
		if ($natent['associated-rule-id'] == $id) {
138
			$natent['associated-rule-id'] = '';
139
		}
140
	}
141
}
142

    
143
if (!is_array($config['filter']['rule'])) {
144
	$config['filter']['rule'] = array();
145
}
146

    
147
filter_rules_sort();
148
$a_filter = &$config['filter']['rule'];
149

    
150
$if = $_GET['if'];
151

    
152
if ($_POST['if']) {
153
	$if = $_POST['if'];
154
}
155

    
156
$ifdescs = get_configured_interface_with_descr();
157

    
158
/* add group interfaces */
159
if (is_array($config['ifgroups']['ifgroupentry'])) {
160
	foreach ($config['ifgroups']['ifgroupentry'] as $ifgen) {
161
		if (have_ruleint_access($ifgen['ifname'])) {
162
			$iflist[$ifgen['ifname']] = $ifgen['ifname'];
163
		}
164
	}
165
}
166

    
167
foreach ($ifdescs as $ifent => $ifdesc) {
168
	if (have_ruleint_access($ifent)) {
169
		$iflist[$ifent] = $ifdesc;
170
	}
171
}
172

    
173
if ($config['l2tp']['mode'] == "server") {
174
	if (have_ruleint_access("l2tp")) {
175
		$iflist['l2tp'] = gettext("L2TP VPN");
176
	}
177
}
178

    
179
if (is_array($config['pppoes']['pppoe'])) {
180
	foreach ($config['pppoes']['pppoe'] as $pppoes) {
181
		if (($pppoes['mode'] == 'server') && have_ruleint_access("pppoe")) {
182
			$iflist['pppoe'] = gettext("PPPoE Server");
183
		}
184
	}
185
}
186

    
187
/* add ipsec interfaces */
188
if (ipsec_enabled() && have_ruleint_access("enc0")) {
189
	$iflist["enc0"] = gettext("IPsec");
190
}
191

    
192
/* add openvpn/tun interfaces */
193
if ($config['openvpn']["openvpn-server"] || $config['openvpn']["openvpn-client"]) {
194
	$iflist["openvpn"] = gettext("OpenVPN");
195
}
196

    
197
if (!$if || !isset($iflist[$if])) {
198
	if ($if != "any" && $if != "FloatingRules" && isset($iflist['wan'])) {
199
		$if = "wan";
200
	} else {
201
		$if = "FloatingRules";
202
	}
203
}
204

    
205
if ($_POST) {
206
	$pconfig = $_POST;
207

    
208
	if ($_POST['apply']) {
209
		$retval = 0;
210
		$retval = filter_configure();
211

    
212
		clear_subsystem_dirty('filter');
213

    
214
		$savemsg = sprintf(gettext("The settings have been applied. The firewall rules are now reloading in the background.<br />%s Monitor %s the reload progress."),
215
									"<a href='status_filter_reload.php'>", "</a>");
216
	}
217
}
218

    
219
if ($_GET['act'] == "del") {
220
	if ($a_filter[$_GET['id']]) {
221
		if (!empty($a_filter[$_GET['id']]['associated-rule-id'])) {
222
			delete_nat_association($a_filter[$_GET['id']]['associated-rule-id']);
223
		}
224
		unset($a_filter[$_GET['id']]);
225

    
226
		// Update the separators
227
		$a_separators = &$config['filter']['separator'][strtolower($if)];
228
		$ridx = ifridx($if, $_GET['id']);	// get rule index within interface
229
		$mvnrows = -1;
230
		move_separators($a_separators, $ridx, $mvnrows);
231

    
232
		if (write_config()) {
233
			mark_subsystem_dirty('filter');
234
		}
235

    
236
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
237
		exit;
238
	}
239
}
240

    
241
// Handle save msg if defined
242
if ($_REQUEST['savemsg']) {
243
	$savemsg = htmlentities($_REQUEST['savemsg']);
244
}
245

    
246
if (isset($_POST['del_x'])) {
247
	/* delete selected rules */
248
	$deleted = false;
249

    
250
	if (is_array($_POST['rule']) && count($_POST['rule'])) {
251
		$a_separators = &$config['filter']['separator'][strtolower($if)];
252
		$num_deleted = 0;
253

    
254
		foreach ($_POST['rule'] as $rulei) {
255
			delete_nat_association($a_filter[$rulei]['associated-rule-id']);
256
			unset($a_filter[$rulei]);
257
			$deleted = true;
258

    
259
			// Update the separators
260
			// As rules are deleted, $ridx has to be decremented or separator position will break
261
			$ridx = ifridx($if, $rulei) - $num_deleted;	// get rule index within interface
262
			$mvnrows = -1;
263
			move_separators($a_separators, $ridx, $mvnrows);
264
			$num_deleted++;
265
		}
266

    
267
		if ($deleted) {
268
			if (write_config()) {
269
				mark_subsystem_dirty('filter');
270
			}
271
		}
272

    
273
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
274
		exit;
275
	}
276
} else if ($_GET['act'] == "toggle") {
277
	if ($a_filter[$_GET['id']]) {
278
		if (isset($a_filter[$_GET['id']]['disabled'])) {
279
			unset($a_filter[$_GET['id']]['disabled']);
280
		} else {
281
			$a_filter[$_GET['id']]['disabled'] = true;
282
		}
283
		if (write_config()) {
284
			mark_subsystem_dirty('filter');
285
		}
286

    
287
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
288
		exit;
289
	}
290
} else if ($_POST['order-store']) {
291

    
292
	/* update rule order, POST[rule] is an array of ordered IDs */
293
	if (is_array($_POST['rule']) && !empty($_POST['rule'])) {
294
		$a_filter_new = array();
295

    
296
		// Include the rules of other interfaces listed in config before this (the selected) interface.
297
		foreach ($a_filter as $filteri_before => $filterent) {
298
			if (($filterent['interface'] == $if && !isset($filterent['floating'])) || (isset($filterent['floating']) && "FloatingRules" == $if)) {
299
				break;
300
			} else {
301
				$a_filter_new[] = $filterent;
302
			}
303
		}
304

    
305
		// Include the rules of this (the selected) interface.
306
		// If a rule is not in POST[rule], it has been deleted by the user
307
		foreach ($_POST['rule'] as $id) {
308
			$a_filter_new[] = $a_filter[$id];
309
		}
310

    
311
		// Include the rules of other interfaces listed in config after this (the selected) interface.
312
		foreach ($a_filter as $filteri_after => $filterent) {
313
			if ($filteri_before > $filteri_after) {
314
				continue;
315
			}
316
			if (($filterent['interface'] == $if && !isset($filterent['floating'])) || (isset($filterent['floating']) && "FloatingRules" == $if)) {
317
				continue;
318
			} else {
319
				$a_filter_new[] = $filterent;
320
			}
321
		}
322

    
323
		$a_filter = $a_filter_new;
324

    
325
		$config['filter']['separator'][strtolower($if)] = "";
326

    
327
		if ($_POST['separator']) {
328
			$idx = 0;
329
			foreach ($_POST['separator'] as $separator) {
330
				$config['filter']['separator'][strtolower($separator['if'])]['sep' . $idx++] = $separator;
331
			}
332
		}
333

    
334
		if (write_config()) {
335
			mark_subsystem_dirty('filter');
336
		}
337

    
338
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
339
		exit;
340
	}
341
}
342

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

    
345
foreach ($iflist as $ifent => $ifname) {
346
	$tab_array[] = array($ifname, ($ifent == $if), "firewall_rules.php?if={$ifent}");
347
}
348

    
349
foreach ($tab_array as $dtab) {
350
	if ($dtab[1]) {
351
		$bctab = $dtab[0];
352
		break;
353
	}
354
}
355

    
356
$pgtitle = array(gettext("Firewall"), gettext("Rules"), $bctab);
357
$shortcut_section = "firewall";
358

    
359
include("head.inc");
360
$nrules = 0;
361

    
362
if ($savemsg) {
363
	print_info_box($savemsg, 'success');
364
}
365

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

    
370
display_top_tabs($tab_array);
371

    
372
$showantilockout = false;
373
$showprivate = false;
374
$showblockbogons = false;
375

    
376
if (!isset($config['system']['webgui']['noantilockout']) &&
377
    (((count($config['interfaces']) > 1) && ($if == 'lan')) ||
378
    ((count($config['interfaces']) == 1) && ($if == 'wan')))) {
379
	$showantilockout = true;
380
}
381

    
382
if (isset($config['interfaces'][$if]['blockpriv'])) {
383
	$showprivate = true;
384
}
385

    
386
if (isset($config['interfaces'][$if]['blockbogons'])) {
387
	$showblockbogons = true;
388
}
389

    
390
/* Load the counter data of each pf rule. */
391
$rulescnt = pfSense_get_pf_rules();
392

    
393
// Update this if you add or remove columns!
394
$columns_in_table = 13;
395

    
396
?>
397
<!-- Allow table to scroll when dragging outside of the display window -->
398
<style>
399
.table-responsive {
400
    clear: both;
401
    overflow-x: visible;
402
    margin-bottom: 0px;
403
}
404
</style>
405

    
406
<form method="post">
407
	<div class="panel panel-default">
408
		<div class="panel-heading"><h2 class="panel-title"><?=gettext("Rules (Drag to Change Order)")?></h2></div>
409
		<div id="mainarea" class="table-responsive panel-body">
410
			<table id="ruletable" class="table table-hover table-striped table-condensed" style="overflow-x: 'visible'">
411
				<thead>
412
					<tr>
413
						<th><!-- checkbox --></th>
414
						<th><!-- status icons --></th>
415
						<th><?=gettext("States")?></th>
416
						<th><?=gettext("Protocol")?></th>
417
						<th><?=gettext("Source")?></th>
418
						<th><?=gettext("Port")?></th>
419
						<th><?=gettext("Destination")?></th>
420
						<th><?=gettext("Port")?></th>
421
						<th><?=gettext("Gateway")?></th>
422
						<th><?=gettext("Queue")?></th>
423
						<th><?=gettext("Schedule")?></th>
424
						<th><?=gettext("Description")?></th>
425
						<th><?=gettext("Actions")?></th>
426
					</tr>
427
				</thead>
428

    
429
<?php if ($showblockbogons || $showantilockout || $showprivate) :
430
?>
431
				<tbody>
432
<?php
433
		// 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.
434
		if ($showantilockout):
435
			$alports = implode('<br />', filter_get_antilockout_ports(true));
436
?>
437
					<tr id="antilockout">
438
						<td></td>
439
						<td title="<?=gettext("traffic is passed")?>"><i class="fa fa-check text-success"></i></td>
440
						<td><?php print_states(intval(ANTILOCKOUT_TRACKER)); ?></td>
441
						<td>*</td>
442
						<td>*</td>
443
						<td>*</td>
444
						<td><?=$iflist[$if];?> Address</td>
445
						<td><?=$alports?></td>
446
						<td>*</td>
447
						<td>*</td>
448
						<td></td>
449
						<td><?=gettext("Anti-Lockout Rule");?></td>
450
						<td>
451
							<a href="system_advanced_admin.php" title="<?=gettext("Settings");?>"><i class="fa fa-cog"></i></a>
452
						</td>
453
					</tr>
454
<?php 	endif;?>
455
<?php 	if ($showprivate): ?>
456
					<tr id="private">
457
						<td></td>
458
						<td title="<?=gettext("traffic is blocked")?>"><i class="fa fa-times text-danger"></i></td>
459
						<td><?php print_states(intval(RFC1918_TRACKER)); ?></td>
460
						<td>*</td>
461
						<td><?=gettext("RFC 1918 networks");?></td>
462
						<td>*</td>
463
						<td>*</td>
464
						<td>*</td>
465
						<td>*</td>
466
						<td>*</td>
467
						<td></td>
468
						<td><?=gettext("Block private networks");?></td>
469
						<td>
470
							<a href="interfaces.php?if=<?=htmlspecialchars($if)?>" title="<?=gettext("Settings");?>"><i class="fa fa-cog"></i></a>
471
						</td>
472
					</tr>
473
<?php 	endif;?>
474
<?php 	if ($showblockbogons): ?>
475
					<tr id="bogons">
476
						<td></td>
477
						<td title="<?=gettext("traffic is blocked")?>"><i class="fa fa-times text-danger"></i></td>
478
						<td><?php print_states(intval(BOGONS_TRACKER)); ?></td>
479
						<td>*</td>
480
						<td><?=sprintf(gettext("Reserved%sNot assigned by IANA"), "<br />");?></td>
481
						<td>*</td>
482
						<td>*</td>
483
						<td>*</td>
484
						<td>*</td>
485
						<td>*</td>
486
						<td></td>
487
						<td><?=gettext("Block bogon networks");?></td>
488
						<td>
489
							<a href="interfaces.php?if=<?=htmlspecialchars($if)?>" title="<?=gettext("Settings");?>"><i class="fa fa-cog"></i></a>
490
						</td>
491
					</tr>
492
<?php 	endif;?>
493
			</tbody>
494
<?php endif;?>
495
			<tbody class="user-entries">
496
<?php
497
$nrules = 0;
498
$separators = $config['filter']['separator'][strtolower($if)];
499

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

    
504
foreach ($a_filter as $filteri => $filterent):
505

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

    
508
		// Display separator(s) for section beginning at rule n
509
		if ($seprows[$nrules]) {
510
			display_separator($separators, $nrules, $columns_in_table);
511
		}
512
?>
513
					<tr id="fr<?=$nrules;?>" onClick="fr_toggle(<?=$nrules;?>)" ondblclick="document.location='firewall_rules_edit.php?id=<?=$filteri;?>';" <?=(isset($filterent['disabled']) ? ' class="disabled"' : '')?>>
514
						<td>
515
							<input type="checkbox" id="frc<?=$nrules;?>" onClick="fr_toggle(<?=$nrules;?>)" name="rule[]" value="<?=$filteri;?>"/>
516
						</td>
517

    
518
	<?php
519
		if ($filterent['type'] == "block") {
520
			$iconfn = "times text-danger";
521
			$title_text = gettext("traffic is blocked");
522
		} else if ($filterent['type'] == "reject") {
523
			$iconfn = "hand-stop-o text-warning";
524
			$title_text = gettext("traffic is rejected");
525
		} else if ($filterent['type'] == "match") {
526
			$iconfn = "filter";
527
			$title_text = gettext("traffic is matched");
528
		} else {
529
			$iconfn = "check text-success";
530
			$title_text = gettext("traffic is passed");
531
		}
532
	?>
533
						<td title="<?=$title_text?>">
534
							<a href="?if=<?=htmlspecialchars($if);?>&amp;act=toggle&amp;id=<?=$filteri;?>">
535
								<i class="fa fa-<?=$iconfn?>" title="<?=gettext("click to toggle enabled/disabled status");?>"></i>
536
							</a>
537
	<?php
538
		if ($filterent['quick'] == 'yes') {
539
			print '<i class="fa fa-forward text-success" title="'. gettext("&quot;Quick&quot; rule. Applied immediately on match.") .'" style="cursor: pointer;"></i>';
540
		}
541

    
542
		$isadvset = firewall_check_for_advanced_options($filterent);
543
		if ($isadvset) {
544
			print '<i class="fa fa-cog" title="'. gettext("advanced setting") .': '. $isadvset .'"></i>';
545
		}
546

    
547
		if (isset($filterent['log'])) {
548
			print '<i class="fa fa-tasks" title="'. gettext("traffic is logged") .'" style="cursor: pointer;"></i>';
549
		}
550
	?>
551
						</td>
552
	<?php
553
		$alias = rule_columns_with_alias(
554
			$filterent['source']['address'],
555
			pprint_port($filterent['source']['port']),
556
			$filterent['destination']['address'],
557
			pprint_port($filterent['destination']['port'])
558
		);
559

    
560
		//build Schedule popup box
561
		$a_schedules = &$config['schedules']['schedule'];
562
		$schedule_span_begin = "";
563
		$schedule_span_end = "";
564
		$sched_caption_escaped = "";
565
		$sched_content = "";
566
		$schedstatus = false;
567
		$dayArray = array (gettext('Mon'), gettext('Tues'), gettext('Wed'), gettext('Thur'), gettext('Fri'), gettext('Sat'), gettext('Sun'));
568
		$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'));
569
		if ($config['schedules']['schedule'] != "" && is_array($config['schedules']['schedule'])) {
570
			$idx = 0;
571
			foreach ($a_schedules as $schedule) {
572
				if ($schedule['name'] == $filterent['sched']) {
573
					$schedstatus = filter_get_time_based_rule_status($schedule);
574

    
575
					foreach ($schedule['timerange'] as $timerange) {
576
						$tempFriendlyTime = "";
577
						$tempID = "";
578
						$firstprint = false;
579
						if ($timerange) {
580
							$dayFriendly = "";
581
							$tempFriendlyTime = "";
582

    
583
							//get hours
584
							$temptimerange = $timerange['hour'];
585
							$temptimeseparator = strrpos($temptimerange, "-");
586

    
587
							$starttime = substr ($temptimerange, 0, $temptimeseparator);
588
							$stoptime = substr ($temptimerange, $temptimeseparator+1);
589

    
590
							if ($timerange['month']) {
591
								$tempmontharray = explode(",", $timerange['month']);
592
								$tempdayarray = explode(",", $timerange['day']);
593
								$arraycounter = 0;
594
								$firstDayFound = false;
595
								$firstPrint = false;
596
								foreach ($tempmontharray as $monthtmp) {
597
									$month = $tempmontharray[$arraycounter];
598
									$day = $tempdayarray[$arraycounter];
599

    
600
									if (!$firstDayFound) {
601
										$firstDay = $day;
602
										$firstmonth = $month;
603
										$firstDayFound = true;
604
									}
605

    
606
									$currentDay = $day;
607
									$nextDay = $tempdayarray[$arraycounter+1];
608
									$currentDay++;
609
									if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])) {
610
										if ($firstPrint) {
611
											$dayFriendly .= ", ";
612
										}
613
										$currentDay--;
614
										if ($currentDay != $firstDay) {
615
											$dayFriendly .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
616
										} else {
617
											$dayFriendly .=	 $monthArray[$month-1] . " " . $day;
618
										}
619
										$firstDayFound = false;
620
										$firstPrint = true;
621
									}
622
									$arraycounter++;
623
								}
624
							} else {
625
								$tempdayFriendly = $timerange['position'];
626
								$firstDayFound = false;
627
								$tempFriendlyDayArray = explode(",", $tempdayFriendly);
628
								$currentDay = "";
629
								$firstDay = "";
630
								$nextDay = "";
631
								$counter = 0;
632
								foreach ($tempFriendlyDayArray as $day) {
633
									if ($day != "") {
634
										if (!$firstDayFound) {
635
											$firstDay = $tempFriendlyDayArray[$counter];
636
											$firstDayFound = true;
637
										}
638
										$currentDay =$tempFriendlyDayArray[$counter];
639
										//get next day
640
										$nextDay = $tempFriendlyDayArray[$counter+1];
641
										$currentDay++;
642
										if ($currentDay != $nextDay) {
643
											if ($firstprint) {
644
												$dayFriendly .= ", ";
645
											}
646
											$currentDay--;
647
											if ($currentDay != $firstDay) {
648
												$dayFriendly .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
649
											} else {
650
												$dayFriendly .= $dayArray[$firstDay-1];
651
											}
652
											$firstDayFound = false;
653
											$firstprint = true;
654
										}
655
										$counter++;
656
									}
657
								}
658
							}
659
							$timeFriendly = $starttime . " - " . $stoptime;
660
							$description = $timerange['rangedescr'];
661
							$sched_content .= $dayFriendly . "; " . $timeFriendly . "<br />";
662
						}
663
					}
664
					#FIXME
665
					$sched_caption_escaped = str_replace("'", "\'", $schedule['descr']);
666
					$schedule_span_begin = '<a href="/firewall_schedule_edit.php?id=' . $idx . '" data-toggle="popover" data-trigger="hover focus" title="' . $schedule['name'] . '" data-content="' .
667
						$sched_caption_escaped . '" data-html="true">';
668
					$schedule_span_end = "</a>";
669
				}
670
				$idx++;
671
			}
672
		}
673
		$printicon = false;
674
		$alttext = "";
675
		$image = "";
676
		if (!isset($filterent['disabled'])) {
677
			if ($schedstatus) {
678
				if ($filterent['type'] == "block" || $filterent['type'] == "reject") {
679
					$image = "times-circle";
680
					$dispcolor = "text-danger";
681
					$alttext = gettext("Traffic matching this rule is currently being denied");
682
				} else {
683
					$image = "play-circle";
684
					$dispcolor = "text-success";
685
					$alttext = gettext("Traffic matching this rule is currently being allowed");
686
				}
687
				$printicon = true;
688
			} else if ($filterent['sched']) {
689
				if ($filterent['type'] == "block" || $filterent['type'] == "reject") {
690
					$image = "times-circle";
691
				} else {
692
					$image = "play-circle";
693
				}
694
				$alttext = gettext("This rule is not currently active because its period has expired");
695
				$dispcolor = "text-warning";
696
				$printicon = true;
697
			}
698
		}
699
	?>
700
				<td><?php print_states(intval($filterent['tracker'])); ?></td>
701
				<td>
702
	<?php
703
		if (isset($filterent['ipprotocol'])) {
704
			switch ($filterent['ipprotocol']) {
705
				case "inet":
706
					echo "IPv4 ";
707
					break;
708
				case "inet6":
709
					echo "IPv6 ";
710
					break;
711
				case "inet46":
712
					echo "IPv4+6 ";
713
					break;
714
			}
715
		} else {
716
			echo "IPv4 ";
717
		}
718

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

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

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

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

    
852
	<nav class="action-buttons">
853
		<a href="firewall_rules_edit.php?if=<?=htmlspecialchars($if);?>&amp;after=-1" role="button" class="btn btn-sm btn-success" title="<?=gettext('Add rule to the top of the list')?>">
854
			<i class="fa fa-level-up icon-embed-btn"></i>
855
			<?=gettext("Add");?>
856
		</a>
857
		<a href="firewall_rules_edit.php?if=<?=htmlspecialchars($if);?>" role="button" class="btn btn-sm btn-success" title="<?=gettext('Add rule to the end of the list')?>">
858
			<i class="fa fa-level-down icon-embed-btn"></i>
859
			<?=gettext("Add");?>
860
		</a>
861
		<button name="del_x" type="submit" class="btn btn-danger btn-sm" value="<?=gettext("Delete selected rules"); ?>" title="<?=gettext('Delete selected rules')?>">
862
			<i class="fa fa-trash icon-embed-btn"></i>
863
			<?=gettext("Delete"); ?>
864
		</button>
865
		<button type="submit" id="order-store" name="order-store" class="btn btn-sm btn-primary" value="store changes" disabled title="<?=gettext('Save rule order')?>">
866
			<i class="fa fa-save icon-embed-btn"></i>
867
			<?=gettext("Save")?>
868
		</button>
869
		<button type="submit" id="addsep" name="addsep" class="btn btn-sm btn-warning" title="<?=gettext('Add separator')?>">
870
			<i class="fa fa-plus icon-embed-btn"></i>
871
			<?=gettext("Separator")?>
872
		</button>
873
	</nav>
874
</form>
875

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

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

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

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

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

    
922
events.push(function() {
923

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

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

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

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

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

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

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

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

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

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

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

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

    
1007
	$('table tbody.user-entries').show();
1008

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

    
1013
		// Save the separator bar configuration
1014
		save_separators();
1015

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

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

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

    
1040
<?php include("foot.inc");?>
(48-48/227)