Project

General

Profile

Download (34.3 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 Electric Sheep Fencing, LLC
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 ("any" == $if) {
199
		$if = "FloatingRules";
200
	} else if ("FloatingRules" != $if) {
201
		if (isset($iflist['wan'])) {
202
			$if = "wan";
203
		} else {
204
			$if = "FloatingRules";
205
		}
206
	}
207
}
208

    
209
if ($_POST) {
210
	$pconfig = $_POST;
211

    
212
	if ($_POST['apply']) {
213
		$retval = 0;
214
		$retval = filter_configure();
215

    
216
		clear_subsystem_dirty('filter');
217

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

    
223
if ($_GET['act'] == "del") {
224
	if ($a_filter[$_GET['id']]) {
225
		if (!empty($a_filter[$_GET['id']]['associated-rule-id'])) {
226
			delete_nat_association($a_filter[$_GET['id']]['associated-rule-id']);
227
		}
228
		unset($a_filter[$_GET['id']]);
229

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

    
236
		if (write_config()) {
237
			mark_subsystem_dirty('filter');
238
		}
239

    
240
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
241
		exit;
242
	}
243
}
244

    
245
// Handle save msg if defined
246
if ($_REQUEST['savemsg']) {
247
	$savemsg = htmlentities($_REQUEST['savemsg']);
248
}
249

    
250
if (isset($_POST['del_x'])) {
251
	/* delete selected rules */
252
	$deleted = false;
253

    
254
	if (is_array($_POST['rule']) && count($_POST['rule'])) {
255
		$a_separators = &$config['filter']['separator'][strtolower($if)];
256
		$num_deleted = 0;
257

    
258
		foreach ($_POST['rule'] as $rulei) {
259
			delete_nat_association($a_filter[$rulei]['associated-rule-id']);
260
			unset($a_filter[$rulei]);
261
			$deleted = true;
262

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

    
271
		if ($deleted) {
272
			if (write_config()) {
273
				mark_subsystem_dirty('filter');
274
			}
275
		}
276

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

    
291
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
292
		exit;
293
	}
294
} else if ($_POST['order-store']) {
295

    
296
	/* update rule order, POST[rule] is an array of ordered IDs */
297
	if (is_array($_POST['rule']) && !empty($_POST['rule'])) {
298
		$a_filter_new = array();
299

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

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

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

    
327
		$a_filter = $a_filter_new;
328

    
329
		$config['filter']['separator'][strtolower($if)] = "";
330

    
331
		if ($_POST['separator']) {
332
			$idx = 0;
333
			foreach ($_POST['separator'] as $separator) {
334
				$config['filter']['separator'][strtolower($separator['if'])]['sep' . $idx++] = $separator;
335
			}
336
		}
337

    
338
		if (write_config()) {
339
			mark_subsystem_dirty('filter');
340
		}
341

    
342
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
343
		exit;
344
	}
345
}
346

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

    
349
foreach ($iflist as $ifent => $ifname) {
350
	$tab_array[] = array($ifname, ($ifent == $if), "firewall_rules.php?if={$ifent}");
351
}
352

    
353
foreach ($tab_array as $dtab) {
354
	if ($dtab[1]) {
355
		$bctab = $dtab[0];
356
		break;
357
	}
358
}
359

    
360
$pgtitle = array(gettext("Firewall"), gettext("Rules"), $bctab);
361
$shortcut_section = "firewall";
362

    
363
include("head.inc");
364
$nrules = 0;
365

    
366
if ($savemsg) {
367
	print_info_box($savemsg, 'success');
368
}
369

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

    
374
display_top_tabs($tab_array);
375

    
376
$showantilockout = false;
377
$showprivate = false;
378
$showblockbogons = false;
379

    
380
if (!isset($config['system']['webgui']['noantilockout']) &&
381
    (((count($config['interfaces']) > 1) && ($if == 'lan')) ||
382
    ((count($config['interfaces']) == 1) && ($if == 'wan')))) {
383
	$showantilockout = true;
384
}
385

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

    
390
if (isset($config['interfaces'][$if]['blockbogons'])) {
391
	$showblockbogons = true;
392
}
393

    
394
/* Load the counter data of each pf rule. */
395
$rulescnt = pfSense_get_pf_rules();
396

    
397
// Update this if you add or remove columns!
398
$columns_in_table = 13;
399

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

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

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

    
499
foreach ($a_filter as $filteri => $filterent):
500

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

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

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

    
537
		$isadvset = firewall_check_for_advanced_options($filterent);
538
		if ($isadvset) {
539
			print '<i class="fa fa-cog" title="'. gettext("advanced setting") .': '. $isadvset .'"></i>';
540
		}
541

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

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

    
570
					foreach ($schedule['timerange'] as $timerange) {
571
						$tempFriendlyTime = "";
572
						$tempID = "";
573
						$firstprint = false;
574
						if ($timerange) {
575
							$dayFriendly = "";
576
							$tempFriendlyTime = "";
577

    
578
							//get hours
579
							$temptimerange = $timerange['hour'];
580
							$temptimeseparator = strrpos($temptimerange, "-");
581

    
582
							$starttime = substr ($temptimerange, 0, $temptimeseparator);
583
							$stoptime = substr ($temptimerange, $temptimeseparator+1);
584

    
585
							if ($timerange['month']) {
586
								$tempmontharray = explode(",", $timerange['month']);
587
								$tempdayarray = explode(",", $timerange['day']);
588
								$arraycounter = 0;
589
								$firstDayFound = false;
590
								$firstPrint = false;
591
								foreach ($tempmontharray as $monthtmp) {
592
									$month = $tempmontharray[$arraycounter];
593
									$day = $tempdayarray[$arraycounter];
594

    
595
									if (!$firstDayFound) {
596
										$firstDay = $day;
597
										$firstmonth = $month;
598
										$firstDayFound = true;
599
									}
600

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

    
714
		if (isset($filterent['protocol'])) {
715
			echo strtoupper($filterent['protocol']);
716

    
717
			if (strtoupper($filterent['protocol']) == "ICMP" && !empty($filterent['icmptype'])) {
718
				echo ' <span style="cursor: help;" title="' . gettext('ICMP type') . ': ' .
719
					($filterent['ipprotocol'] == "inet6" ? $icmp6types[$filterent['icmptype']] : $icmptypes[$filterent['icmptype']]) .
720
					'"><u>';
721
				echo $filterent['icmptype'];
722
				echo '</u></span>';
723
			}
724
		} else echo "*";
725

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

    
816
// There can be separator(s) after the last rule listed.
817
if ($seprows[$nrules]) {
818
	display_separator($separators, $nrules, $columns_in_table);
819
}
820
?>
821
				</tbody>
822
			</table>
823
		</div>
824
	</div>
825

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

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

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

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

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

    
900
<script type="text/javascript">
901
//<![CDATA[
902

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

    
910
events.push(function() {
911

    
912
	// "Move to here" (anchor) action
913
	$('[id^=Xmove_]').click(function (event) {
914

    
915
		// Prevent click from toggling row
916
		event.stopImmediatePropagation();
917

    
918
		// Save the target rule position
919
		var anchor_row = $(this).parents("tr:first");
920

    
921
		if (event.shiftKey) {
922
			$($('#ruletable > tbody  > tr').get().reverse()).each(function() {
923
				ruleid = this.id.slice(2);
924

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

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

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

    
958
		$(this).css("cursor", "default");
959

    
960
		// Are any rules currently selected?
961
		$('[id^=frc]').each(function () {
962
			if ($(this).prop("checked")) {
963
				ruleselected = true;
964
			}
965
		});
966

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

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

    
983
	$('table tbody.user-entries').sortable({
984
		cursor: 'grabbing',
985
		update: function(event, ui) {
986
			$('#order-store').removeAttr('disabled');
987
			reindex_rules(ui.item.parent('tbody'));
988
			dirty = true;
989
		}
990
	});
991

    
992
	$('table tbody.user-entries').show();
993

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

    
998
		// Save the separator bar configuration
999
		save_separators();
1000

    
1001
		// Suppress the "Do you really want to leave the page" message
1002
		saving = true;
1003
	});
1004

    
1005
	// Provide a warning message if the user tries to change page before saving
1006
	$(window).bind('beforeunload', function(){
1007
		if ((!saving && dirty) || newSeperator) {
1008
			return ("<?=gettext('One or more rules have been moved but have not yet been saved')?>");
1009
		} else {
1010
			return undefined;
1011
		}
1012
	});
1013

    
1014
	$(document).on('keyup keydown', function(e){
1015
		if (e.shiftKey) {
1016
			$('[id^=Xmove_]').attr("title", "<?=$ShXmoveTitle?>");
1017
		} else {
1018
			$('[id^=Xmove_]').attr("title", "<?=$XmoveTitle?>");
1019
		}
1020
	});
1021
});
1022
//]]>
1023
</script>
1024

    
1025
<?php include("foot.inc");?>
(48-48/225)