Project

General

Profile

Download (31.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
$pgtitle = array(gettext("Firewall"), gettext("Rules"));
73
$shortcut_section = "firewall";
74

    
75
function get_pf_rules($rules, $tracker) {
76

    
77
	if ($rules == NULL || !is_array($rules))
78
		return (NULL);
79

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

    
87
	if (count($arr) == 0)
88
		return (NULL);
89

    
90
	return ($arr);
91
}
92

    
93
function print_states($tracker) {
94
	global $rulescnt;
95

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

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

    
125
function delete_nat_association($id) {
126
	global $config;
127

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

    
132
	$a_nat = &$config['nat']['rule'];
133

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

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

    
145
filter_rules_sort();
146
$a_filter = &$config['filter']['rule'];
147

    
148
$if = $_GET['if'];
149

    
150
if ($_POST['if']) {
151
	$if = $_POST['if'];
152
}
153

    
154
$ifdescs = get_configured_interface_with_descr();
155

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

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

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

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

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

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

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

    
207
if ($_POST) {
208
	$pconfig = $_POST;
209

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

    
214
		clear_subsystem_dirty('filter');
215

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

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

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

    
234
		if (write_config()) {
235
			mark_subsystem_dirty('filter');
236
		}
237

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

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

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

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

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

    
260
			// Update the separators
261
			$ridx = ifridx($if, $rulei);	// get rule index within interface
262
			$mvnrows = -1;
263
			move_separators($a_separators, $ridx, $mvnrows);
264
		}
265

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

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

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

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

    
295
		// get the rules of other interfaces listed in config before this interface.
296
		for ($i = 0; (isset($a_filter[$i]) && 
297
			(($a_filter[$i]['interface'] != $if && !isset($a_filter[$i]['floating'])) || (isset($a_filter[$i]['floating']) && "FloatingRules" != $if)) 
298
			); $i++) {
299
			$a_filter_new[] = $a_filter[$i];
300
		}
301

    
302
		// include the rules of this interface.
303
		// if a rule is not in POST[rule], it has been deleted by the user
304
		foreach ($_POST['rule'] as $id) {
305
			$a_filter_new[] = $a_filter[$id];
306
		}
307

    
308
		// get the rules of other interfaces listed in config after this interface.
309
		for ( ; (isset($a_filter[$i])); $i++) {
310
			if (($a_filter[$i]['interface'] != $if && !isset($a_filter[$i]['floating'])) || (isset($a_filter[$i]['floating']) && "FloatingRules" != $if)) {
311
				$a_filter_new[] = $a_filter[$i];
312
			}
313
		}
314

    
315
		$a_filter = $a_filter_new;
316

    
317
		$config['filter']['separator'][strtolower($if)] = "";
318

    
319
		if ($_POST['separator']) {
320
			$idx = 0;
321
			foreach ($_POST['separator'] as $separator) {
322
				$config['filter']['separator'][strtolower($separator['if'])]['sep' . $idx++] = $separator;
323
			}
324
		}
325

    
326
		if (write_config()) {
327
			mark_subsystem_dirty('filter');
328
		}
329

    
330
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
331
		exit;
332
	}
333
}
334

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

    
337
foreach ($iflist as $ifent => $ifname) {
338
	$tab_array[] = array($ifname, ($ifent == $if), "firewall_rules.php?if={$ifent}");
339
}
340

    
341
foreach ($tab_array as $dtab) {
342
	if ($dtab[1]) {
343
		$bctab = $dtab[0];
344
		break;
345
	}
346
}
347

    
348
$pgtitle = array(gettext("Firewall"), gettext("Rules"), $bctab);
349
$shortcut_section = "firewall";
350

    
351
include("head.inc");
352
$nrules = 0;
353

    
354
if ($savemsg) {
355
	print_info_box($savemsg, 'success');
356
}
357

    
358
if (is_subsystem_dirty('filter')) {
359
	print_apply_box(gettext("The firewall rule configuration has been changed.") . "<br />" . gettext("You must apply the changes in order for them to take effect."));
360
}
361

    
362
display_top_tabs($tab_array);
363

    
364
$showantilockout = false;
365
$showprivate = false;
366
$showblockbogons = false;
367

    
368
if (!isset($config['system']['webgui']['noantilockout']) &&
369
    (((count($config['interfaces']) > 1) && ($if == 'lan')) ||
370
    ((count($config['interfaces']) == 1) && ($if == 'wan')))) {
371
	$showantilockout = true;
372
}
373

    
374
if (isset($config['interfaces'][$if]['blockpriv'])) {
375
	$showprivate = true;
376
}
377

    
378
if (isset($config['interfaces'][$if]['blockbogons'])) {
379
	$showblockbogons = true;
380
}
381

    
382
/* Load the counter data of each pf rule. */
383
$rulescnt = pfSense_get_pf_rules();
384

    
385
// Update this if you add or remove columns!
386
$columns_in_table = 13;
387

    
388
?>
389
<form method="post">
390
	<div class="panel panel-default">
391
		<div class="panel-heading"><h2 class="panel-title"><?=gettext("Rules (Drag to Change Order)")?></h2></div>
392
		<div id="mainarea" class="table-responsive panel-body">
393
			<table id="ruletable" class="table table-hover table-striped table-condensed">
394
				<thead>
395
					<tr>
396
						<th><!-- checkbox --></th>
397
						<th><!-- status icons --></th>
398
						<th><?=gettext("States")?></th>
399
						<th><?=gettext("Protocol")?></th>
400
						<th><?=gettext("Source")?></th>
401
						<th><?=gettext("Port")?></th>
402
						<th><?=gettext("Destination")?></th>
403
						<th><?=gettext("Port")?></th>
404
						<th><?=gettext("Gateway")?></th>
405
						<th><?=gettext("Queue")?></th>
406
						<th><?=gettext("Schedule")?></th>
407
						<th><?=gettext("Description")?></th>
408
						<th><?=gettext("Actions")?></th>
409
					</tr>
410
				</thead>
411

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

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

    
487
foreach ($a_filter as $filteri => $filterent):
488

    
489
	$i = $filteri;
490

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

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

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

    
527
		$isadvset = firewall_check_for_advanced_options($filterent);
528
		if ($isadvset) {
529
			print '<i class="fa fa-cog" title="'. gettext("advanced setting") .': '. $isadvset .'"></i>';
530
		}
531

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

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

    
560
					foreach ($schedule['timerange'] as $timerange) {
561
						$tempFriendlyTime = "";
562
						$tempID = "";
563
						$firstprint = false;
564
						if ($timerange) {
565
							$dayFriendly = "";
566
							$tempFriendlyTime = "";
567

    
568
							//get hours
569
							$temptimerange = $timerange['hour'];
570
							$temptimeseparator = strrpos($temptimerange, "-");
571

    
572
							$starttime = substr ($temptimerange, 0, $temptimeseparator);
573
							$stoptime = substr ($temptimerange, $temptimeseparator+1);
574

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

    
585
									if (!$firstDayFound) {
586
										$firstDay = $day;
587
										$firstmonth = $month;
588
										$firstDayFound = true;
589
									}
590

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

    
704
		if (isset($filterent['protocol'])) {
705
			echo strtoupper($filterent['protocol']);
706

    
707
			if (strtoupper($filterent['protocol']) == "ICMP" && !empty($filterent['icmptype'])) {
708
				echo ' <span style="cursor: help;" title="' . gettext('ICMP type') . ': ' .
709
					($filterent['ipprotocol'] == "inet6" ? $icmp6types[$filterent['icmptype']] : $icmptypes[$filterent['icmptype']]) .
710
					'"><u>';
711
				echo $filterent['icmptype'];
712
				echo '</u></span>';
713
			}
714
		} else echo "*";
715

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

    
805
// There can be separator(s) after the last rule listed.
806
if ($seprows[$nrules]) {
807
	display_separator($separators, $nrules, $columns_in_table);
808
}
809
?>
810
				</tbody>
811
			</table>
812
		</div>
813
	</div>
814

    
815
<?php if ($nrules == 0): ?>
816
	<div class="alert alert-warning" role="alert">
817
		<p>
818
		<?php if ($_REQUEST['if'] == "FloatingRules"): ?>
819
			<?=gettext("No floating rules are currently defined.");?>
820
		<?php else: ?>
821
			<?=gettext("No rules are currently defined for this interface");?><br />
822
			<?=gettext("All incoming connections on this interface will be blocked until you add pass rules.");?>
823
		<?php endif;?>
824
			<?=gettext("Click the button to add a new rule.");?>
825
		</p>
826
	</div>
827
<?php endif;?>
828

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

    
853
<div class="infoblock">
854
	<div class="alert alert-info clearfix" role="alert"><div class="pull-left">
855
		<dl class="dl-horizontal responsive">
856
		<!-- Legend -->
857
			<dt><?=gettext('Legend')?></dt>				<dd></dd>
858
			<dt><i class="fa fa-check text-success"></i></dt>		<dd><?=gettext("Pass");?></dd>
859
			<dt><i class="fa fa-filter"></i></dt>	<dd><?=gettext("Match");?></dd>
860
			<dt><i class="fa fa-times text-danger"></i></dt>	<dd><?=gettext("Block");?></dd>
861
			<dt><i class="fa fa-hand-stop-o text-warning"></i></dt>		<dd><?=gettext("Reject");?></dd>
862
			<dt><i class="fa fa-tasks"></i></dt>	<dd> <?=gettext("Log");?></dd>
863
			<dt><i class="fa fa-cog"></i></dt>		<dd> <?=gettext("Advanced filter");?></dd>
864
			<dt><i class="fa fa-forward text-success"></i></dt><dd> <?=gettext("&quot;Quick&quot; rule. Applied immediately on match.")?></dd>
865
		</dl>
866

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

    
886
<script type="text/javascript">
887
//<![CDATA[
888

    
889
//Need to create some variables here so that jquery/pfSenseHelpers.js can read them
890
iface = "<?=strtolower($if)?>";
891
cncltxt = '<?=gettext("Cancel")?>';
892
svtxt = '<?=gettext("Save")?>';
893
svbtnplaceholder = '<?=gettext("Enter a description, Save, then drag to final location.")?>';
894
configsection = "filter";
895

    
896
events.push(function() {
897

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

    
902
	$('table tbody.user-entries').sortable({
903
		cursor: 'grabbing',
904
		update: function(event, ui) {
905
			$('#order-store').removeAttr('disabled');
906
			reindex_rules(ui.item.parent('tbody'));
907
			dirty = true;
908
		}
909
	});
910

    
911
	$('table tbody.user-entries').show();
912

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

    
917
		// Save the separator bar configuration
918
		save_separators();
919

    
920
		// Suppress the "Do you really want to leave the page" message
921
		saving = true;
922
	});
923

    
924
	// provide a warning message if the user tries to change page before saving
925
	$(window).bind('beforeunload', function(){
926
		if ((!saving && dirty) || newSeperator) {
927
			return ("<?=gettext('You have moved one or more rules but have not yet saved')?>");
928
		} else {
929
			return undefined;
930
		}
931
	});
932

    
933
});
934
//]]>
935
</script>
936

    
937
<?php include("foot.inc");?>
(49-49/229)