Project

General

Profile

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

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

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

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

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

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

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

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

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

    
93
	return ($arr);
94
}
95

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

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

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

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

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

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

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

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

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

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

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

    
157
$ifdescs = get_configured_interface_with_descr();
158

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

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

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

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

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

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

    
198
if (!$if || !isset($iflist[$if])) {
199
	if ("any" == $if) {
200
		$if = "FloatingRules";
201
	} else if ("FloatingRules" != $if) {
202
		if (isset($iflist['wan'])) {
203
			$if = "wan";
204
		} else {
205
			$if = "FloatingRules";
206
		}
207
	}
208
}
209

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

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

    
217
		clear_subsystem_dirty('filter');
218

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

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

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

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

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

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

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

    
255
	if (is_array($_POST['rule']) && count($_POST['rule'])) {
256
		$a_separators = &$config['filter']['separator'][strtolower($if)];
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
			$ridx = ifridx($if, $rulei);	// get rule index within interface
265
			$mvnrows = -1;
266
			move_separators($a_separators, $ridx, $mvnrows);
267
		}
268

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

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

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

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

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

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

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

    
325
		$a_filter = $a_filter_new;
326

    
327
		$config['filter']['separator'][strtolower($if)] = "";
328

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

    
336
		if (write_config()) {
337
			mark_subsystem_dirty('filter');
338
		}
339

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

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

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

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

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

    
361
include("head.inc");
362
$nrules = 0;
363

    
364
if ($savemsg) {
365
	print_info_box($savemsg, 'success');
366
}
367

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

    
372
display_top_tabs($tab_array);
373

    
374
$showantilockout = false;
375
$showprivate = false;
376
$showblockbogons = false;
377

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

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

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

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

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

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

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

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

    
497
foreach ($a_filter as $filteri => $filterent):
498

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

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

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

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

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

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

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

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

    
580
							$starttime = substr ($temptimerange, 0, $temptimeseparator);
581
							$stoptime = substr ($temptimerange, $temptimeseparator+1);
582

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

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

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

    
712
		if (isset($filterent['protocol'])) {
713
			echo strtoupper($filterent['protocol']);
714

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

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

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

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

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

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

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

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

    
898
<script type="text/javascript">
899
//<![CDATA[
900

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

    
908
events.push(function() {
909

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

    
913
		// Prevent click from toggling row
914
		event.stopImmediatePropagation();
915

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

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

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

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

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

    
956
		$(this).css("cursor", "default");
957

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

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

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

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

    
990
	$('table tbody.user-entries').show();
991

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

    
996
		// Save the separator bar configuration
997
		save_separators();
998

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

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

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

    
1023
<?php include("foot.inc");?>
(49-49/225)