Project

General

Profile

Download (34.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
 * 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("%d/%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
				echo ' <span style="cursor: help;" title="' . gettext('ICMP type') . ': ' .
724
					($filterent['ipprotocol'] == "inet6" ? $icmp6types[$filterent['icmptype']] : $icmptypes[$filterent['icmptype']]) .
725
					'"><u>';
726
				echo $filterent['icmptype'];
727
				echo '</u></span>';
728
			}
729
		} else echo "*";
730

    
731
	?>
732
						</td>
733
						<td>
734
							<?php if (isset($alias['src'])): ?>
735
								<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">
736
									<?=str_replace('_', ' ', htmlspecialchars(pprint_address($filterent['source'])))?>
737
								</a>
738
							<?php else: ?>
739
								<?=htmlspecialchars(pprint_address($filterent['source']))?>
740
							<?php endif; ?>
741
						</td>
742
						<td>
743
							<?php if (isset($alias['srcport'])): ?>
744
								<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">
745
									<?=str_replace('_', ' ', htmlspecialchars(pprint_port($filterent['source']['port'])))?>
746
								</a>
747
							<?php else: ?>
748
								<?=htmlspecialchars(pprint_port($filterent['source']['port']))?>
749
							<?php endif; ?>
750
						</td>
751
						<td>
752
							<?php if (isset($alias['dst'])): ?>
753
								<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">
754
									<?=str_replace('_', ' ', htmlspecialchars(pprint_address($filterent['destination'])))?>
755
								</a>
756
							<?php else: ?>
757
								<?=htmlspecialchars(pprint_address($filterent['destination']))?>
758
							<?php endif; ?>
759
						</td>
760
						<td>
761
							<?php if (isset($alias['dstport'])): ?>
762
								<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">
763
									<?=str_replace('_', ' ', htmlspecialchars(pprint_port($filterent['destination']['port'])))?>
764
								</a>
765
							<?php else: ?>
766
								<?=htmlspecialchars(pprint_port($filterent['destination']['port']))?>
767
							<?php endif; ?>
768
						</td>
769
						<td>
770
							<?php if (isset($config['interfaces'][$filterent['gateway']]['descr'])):?>
771
								<?=str_replace('_', ' ', htmlspecialchars($config['interfaces'][$filterent['gateway']]['descr']))?>
772
							<?php else: ?>
773
								<?=htmlspecialchars(pprint_port($filterent['gateway']))?>
774
							<?php endif; ?>
775
						</td>
776
						<td>
777
							<?php
778
								if (isset($filterent['ackqueue']) && isset($filterent['defaultqueue'])) {
779
									$desc = str_replace('_', ' ', $filterent['ackqueue']);
780
									echo "<a href=\"firewall_shaper_queues.php?queue={$filterent['ackqueue']}&amp;action=show\">{$desc}</a>";
781
									$desc = str_replace('_', ' ', $filterent['defaultqueue']);
782
									echo "/<a href=\"firewall_shaper_queues.php?queue={$filterent['defaultqueue']}&amp;action=show\">{$desc}</a>";
783
								} else if (isset($filterent['defaultqueue'])) {
784
									$desc = str_replace('_', ' ', $filterent['defaultqueue']);
785
									echo "<a href=\"firewall_shaper_queues.php?queue={$filterent['defaultqueue']}&amp;action=show\">{$desc}</a>";
786
								} else {
787
									echo gettext("none");
788
								}
789
							?>
790
						</td>
791
						<td>
792
							<?php if ($printicon) { ?>
793
								<i class="fa fa-<?=$image?> <?=$dispcolor?>" title="<?=$alttext;?>"></i>
794
							<?php } ?>
795
							<?=$schedule_span_begin;?><?=str_replace('_', ' ', htmlspecialchars($filterent['sched']));?>&nbsp;<?=$schedule_span_end;?>
796
						</td>
797
						<td>
798
							<?=htmlspecialchars($filterent['descr']);?>
799
						</td>
800
						<td class="action-icons">
801
						<!-- <?=(isset($filterent['disabled']) ? 'enable' : 'disable')?> -->
802
							<a	class="fa fa-anchor icon-pointer" id="Xmove_<?=$filteri?>" title="<?=$XmoveTitle?>"></a>
803
							<a href="firewall_rules_edit.php?id=<?=$filteri;?>" class="fa fa-pencil" title="<?=gettext('Edit')?>"></a>
804
							<a href="firewall_rules_edit.php?dup=<?=$filteri;?>" class="fa fa-clone" title="<?=gettext('Copy')?>"></a>
805
<?php if (isset($filterent['disabled'])) {
806
?>
807
							<a href="?act=toggle&amp;if=<?=htmlspecialchars($if);?>&amp;id=<?=$filteri;?>" class="fa fa-check-square-o" title="<?=gettext('Enable')?>"></a>
808
<?php } else {
809
?>
810
							<a href="?act=toggle&amp;if=<?=htmlspecialchars($if);?>&amp;id=<?=$filteri;?>" class="fa fa-ban" title="<?=gettext('Disable')?>"></a>
811
<?php }
812
?>
813
							<a href="?act=del&amp;if=<?=htmlspecialchars($if);?>&amp;id=<?=$filteri;?>" class="fa fa-trash" title="<?=gettext('Delete this rule')?>"></a>
814
						</td>
815
					</tr>
816
<?php
817
		$nrules++;
818
	}
819
endforeach;
820

    
821
// There can be separator(s) after the last rule listed.
822
if ($seprows[$nrules]) {
823
	display_separator($separators, $nrules, $columns_in_table);
824
}
825
?>
826
				</tbody>
827
			</table>
828
		</div>
829
	</div>
830

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

    
845
	<nav class="action-buttons">
846
		<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')?>">
847
			<i class="fa fa-level-up icon-embed-btn"></i>
848
			<?=gettext("Add");?>
849
		</a>
850
		<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')?>">
851
			<i class="fa fa-level-down icon-embed-btn"></i>
852
			<?=gettext("Add");?>
853
		</a>
854
		<button name="del_x" type="submit" class="btn btn-danger btn-sm" value="<?=gettext("Delete selected rules"); ?>" title="<?=gettext('Delete selected rules')?>">
855
			<i class="fa fa-trash icon-embed-btn"></i>
856
			<?=gettext("Delete"); ?>
857
		</button>
858
		<button type="submit" id="order-store" name="order-store" class="btn btn-sm btn-primary" value="store changes" disabled title="<?=gettext('Save rule order')?>">
859
			<i class="fa fa-save icon-embed-btn"></i>
860
			<?=gettext("Save")?>
861
		</button>
862
		<button type="submit" id="addsep" name="addsep" class="btn btn-sm btn-warning" title="<?=gettext('Add separator')?>">
863
			<i class="fa fa-plus icon-embed-btn"></i>
864
			<?=gettext("Separator")?>
865
		</button>
866
	</nav>
867
</form>
868

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

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

    
898
	printf(gettext("%sClick the anchor icon %s to move checked rules before the clicked row. Hold down " .
899
			"the shift key and click to move the rules after the clicked row."), '<br /><br />', '<i class="fa fa-anchor"></i>')
900
?>
901
	</div>
902
	</div>
903
</div>
904

    
905
<script type="text/javascript">
906
//<![CDATA[
907

    
908
//Need to create some variables here so that jquery/pfSenseHelpers.js can read them
909
iface = "<?=strtolower($if)?>";
910
cncltxt = '<?=gettext("Cancel")?>';
911
svtxt = '<?=gettext("Save")?>';
912
svbtnplaceholder = '<?=gettext("Enter a description, Save, then drag to final location.")?>';
913
configsection = "filter";
914

    
915
events.push(function() {
916

    
917
	// "Move to here" (anchor) action
918
	$('[id^=Xmove_]').click(function (event) {
919

    
920
		// Prevent click from toggling row
921
		event.stopImmediatePropagation();
922

    
923
		// Save the target rule position
924
		var anchor_row = $(this).parents("tr:first");
925

    
926
		if (event.shiftKey) {
927
			$($('#ruletable > tbody  > tr').get().reverse()).each(function() {
928
				ruleid = this.id.slice(2);
929

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

    
943
				if (ruleid && !isNaN(ruleid)) {
944
					if ($('#frc' + ruleid).prop('checked')) {
945
						// Move the selected rows, un-select them and add highlight class
946
						$(this).insertBefore(anchor_row);
947
						fr_toggle(ruleid, "fr");
948
						$('#fr' + ruleid).addClass("highlight");
949
					}
950
				}
951
			});
952
		}
953

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

    
963
		$(this).css("cursor", "default");
964

    
965
		// Are any rules currently selected?
966
		$('[id^=frc]').each(function () {
967
			if ($(this).prop("checked")) {
968
				ruleselected = true;
969
			}
970
		});
971

    
972
		// If so, change the icon to show the insetion point
973
		if (ruleselected) {
974
			if (e.shiftKey) {
975
				$(this).removeClass().addClass("fa fa-lg fa-arrow-down text-danger");
976
			} else {
977
				$(this).removeClass().addClass("fa fa-lg fa-arrow-up text-danger");
978
			}
979
		}
980
	}).mouseout(function(e) {
981
		$(this).removeClass().addClass("fa fa-anchor");
982
	});
983

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

    
988
	$('table tbody.user-entries').sortable({
989
		cursor: 'grabbing',
990
		scroll: true,
991
		overflow: 'scroll',
992
		scrollSensitivity: 100,
993
		update: function(event, ui) {
994
			$('#order-store').removeAttr('disabled');
995
			reindex_rules(ui.item.parent('tbody'));
996
			dirty = true;
997
		}
998
	});
999

    
1000
	$('table tbody.user-entries').show();
1001

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

    
1006
		// Save the separator bar configuration
1007
		save_separators();
1008

    
1009
		// Suppress the "Do you really want to leave the page" message
1010
		saving = true;
1011
	});
1012

    
1013
	// Provide a warning message if the user tries to change page before saving
1014
	$(window).bind('beforeunload', function(){
1015
		if ((!saving && dirty) || newSeperator) {
1016
			return ("<?=gettext('One or more rules have been moved but have not yet been saved')?>");
1017
		} else {
1018
			return undefined;
1019
		}
1020
	});
1021

    
1022
	$(document).on('keyup keydown', function(e){
1023
		if (e.shiftKey) {
1024
			$('[id^=Xmove_]').attr("title", "<?=$ShXmoveTitle?>");
1025
		} else {
1026
			$('[id^=Xmove_]').attr("title", "<?=$XmoveTitle?>");
1027
		}
1028
	});
1029
});
1030
//]]>
1031
</script>
1032

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