Project

General

Profile

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

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

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

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

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

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

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

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

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

    
92
	return ($arr);
93
}
94

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

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

    
119
	printf("<a href=\"diag_dump_states.php?ruleid=%s\" data-toggle=\"popover\" data-trigger=\"hover focus\" title=\"%s\" ",
120
	    $rulesid, gettext("States details"));
121
	printf("data-content=\"evaluations: %s<br>packets: %s<br>bytes: %s<br>states: %s<br>state creations: %s\" data-html=\"true\">",
122
	    format_number($evaluations), format_number($packets), format_bytes($bytes),
123
	    format_number($states), format_number($stcreations));
124
	printf("%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 ("any" == $if) {
199
		$if = "FloatingRules";
200
	} else if ("FloatingRules" != $if) {
201
		if (isset($iflist['wan'])) {
202
			$if = "wan";
203
		} else {
204
			$if = "FloatingRules";
205
		}
206
	}
207
}
208

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

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

    
216
		clear_subsystem_dirty('filter');
217

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
324
		$a_filter = $a_filter_new;
325

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

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

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

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

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

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

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

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

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

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

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

    
371
display_top_tabs($tab_array);
372

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
907
events.push(function() {
908

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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