Project

General

Profile

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

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

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

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

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

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

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

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

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

    
92
	return ($arr);
93
}
94

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

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

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

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

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

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

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

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

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

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

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

    
156
$ifdescs = get_configured_interface_with_descr();
157

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

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

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

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

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

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

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

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

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

    
212
		clear_subsystem_dirty('filter');
213

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
323
		$a_filter = $a_filter_new;
324

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

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

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

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

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

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

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

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

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

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

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

    
370
display_top_tabs($tab_array);
371

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

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

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

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

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

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

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

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

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

    
495
foreach ($a_filter as $filteri => $filterent):
496

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

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

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

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

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

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

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

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

    
578
							$starttime = substr ($temptimerange, 0, $temptimeseparator);
579
							$stoptime = substr ($temptimerange, $temptimeseparator+1);
580

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

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

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

    
710
		if (isset($filterent['protocol'])) {
711
			echo strtoupper($filterent['protocol']);
712

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

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

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

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

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

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

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

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

    
896
<script type="text/javascript">
897
//<![CDATA[
898

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

    
906
events.push(function() {
907

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

    
911
		// Prevent click from toggling row
912
		event.stopImmediatePropagation();
913

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

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

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

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

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

    
954
		$(this).css("cursor", "default");
955

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

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

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

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

    
988
	$('table tbody.user-entries').show();
989

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

    
994
		// Save the separator bar configuration
995
		save_separators();
996

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

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

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

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