Project

General

Profile

Download (33.6 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-2018 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
 * Licensed under the Apache License, Version 2.0 (the "License");
14
 * you may not use this file except in compliance with the License.
15
 * You may obtain a copy of the License at
16
 *
17
 * http://www.apache.org/licenses/LICENSE-2.0
18
 *
19
 * Unless required by applicable law or agreed to in writing, software
20
 * distributed under the License is distributed on an "AS IS" BASIS,
21
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
 * See the License for the specific language governing permissions and
23
 * limitations under the License.
24
 */
25

    
26
##|+PRIV
27
##|*IDENT=page-firewall-rules
28
##|*NAME=Firewall: Rules
29
##|*DESCR=Allow access to the 'Firewall: Rules' page.
30
##|*MATCH=firewall_rules.php*
31
##|-PRIV
32

    
33
require_once("guiconfig.inc");
34
require_once("functions.inc");
35
require_once("filter.inc");
36
require_once("ipsec.inc");
37
require_once("shaper.inc");
38

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

    
42
$shortcut_section = "firewall";
43

    
44
function get_pf_rules($rules, $tracker) {
45

    
46
	if ($rules == NULL || !is_array($rules))
47
		return (NULL);
48

    
49
	$arr = array();
50
	foreach ($rules as $rule) {
51
		if ($rule['tracker'] === $tracker) {
52
			$arr[] = $rule;
53
		}
54
	}
55

    
56
	if (count($arr) == 0)
57
		return (NULL);
58

    
59
	return ($arr);
60
}
61

    
62
function print_states($tracker) {
63
	global $rulescnt;
64

    
65
	$rulesid = "";
66
	$bytes = 0;
67
	$states = 0;
68
	$packets = 0;
69
	$evaluations = 0;
70
	$stcreations = 0;
71
	$rules = get_pf_rules($rulescnt, $tracker);
72
	if (is_array($rules)) {
73
		foreach ($rules as $rule) {
74
			$bytes += $rule['bytes'];
75
			$states += $rule['states'];
76
			$packets += $rule['packets'];
77
			$evaluations += $rule['evaluations'];
78
			$stcreations += $rule['state creations'];
79
			if (strlen($rulesid) > 0) {
80
				$rulesid .= ",";
81
			}
82
			$rulesid .= "{$rule['id']}";
83
		}
84
	}
85

    
86
	$trackertext = !empty($tracker) ? "Tracking ID: {$tracker}<br>" : "";
87
	printf("<a href=\"diag_dump_states.php?ruleid=%s\" data-toggle=\"popover\" data-trigger=\"hover focus\" title=\"%s\" ",
88
	    $rulesid, gettext("States details"));
89
	printf("data-content=\"{$trackertext}evaluations: %s<br>packets: %s<br>bytes: %s<br>states: %s<br>state creations: %s\" data-html=\"true\" usepost>",
90
	    format_number($evaluations), format_number($packets), format_bytes($bytes),
91
	    format_number($states), format_number($stcreations));
92
	printf("%s/%s</a><br>", format_number($states), format_bytes($bytes));
93
}
94

    
95
function delete_nat_association($id) {
96
	global $config;
97

    
98
	if (!$id || !is_array($config['nat']['rule'])) {
99
		return;
100
	}
101

    
102
	$a_nat = &$config['nat']['rule'];
103

    
104
	foreach ($a_nat as &$natent) {
105
		if ($natent['associated-rule-id'] == $id) {
106
			$natent['associated-rule-id'] = '';
107
		}
108
	}
109
}
110

    
111
if (!is_array($config['filter'])) {
112
	$config['filter'] = array();
113
}
114

    
115
if (!is_array($config['filter']['rule'])) {
116
	$config['filter']['rule'] = array();
117
}
118

    
119
filter_rules_sort();
120
$a_filter = &$config['filter']['rule'];
121

    
122
if ($_REQUEST['if']) {
123
	$if = $_REQUEST['if'];
124
}
125

    
126
$ifdescs = get_configured_interface_with_descr();
127

    
128
$iflist = filter_get_interface_list();
129

    
130
if (!$if || !isset($iflist[$if])) {
131
	if ($if != "any" && $if != "FloatingRules" && isset($iflist['wan'])) {
132
		$if = "wan";
133
	} else {
134
		$if = "FloatingRules";
135
	}
136
}
137

    
138
if ($_POST['apply']) {
139
	$retval = 0;
140
	$retval |= filter_configure();
141

    
142
	clear_subsystem_dirty('filter');
143
}
144

    
145
if ($_POST['act'] == "del") {
146
	if ($a_filter[$_POST['id']]) {
147
		if (!empty($a_filter[$_POST['id']]['associated-rule-id'])) {
148
			delete_nat_association($a_filter[$_POST['id']]['associated-rule-id']);
149
		}
150
		unset($a_filter[$_POST['id']]);
151

    
152
		// Update the separators
153
		$a_separators = &$config['filter']['separator'][strtolower($if)];
154
		$ridx = ifridx($if, $_POST['id']);	// get rule index within interface
155
		$mvnrows = -1;
156
		move_separators($a_separators, $ridx, $mvnrows);
157

    
158
		if (write_config(gettext("Firewall: Rules - deleted a firewall rule."))) {
159
			mark_subsystem_dirty('filter');
160
		}
161

    
162
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
163
		exit;
164
	}
165
}
166

    
167
// Handle save msg if defined
168
if ($_REQUEST['savemsg']) {
169
	$savemsg = htmlentities($_REQUEST['savemsg']);
170
}
171

    
172
if (isset($_POST['del_x'])) {
173
	/* delete selected rules */
174
	$deleted = false;
175

    
176
	if (is_array($_POST['rule']) && count($_POST['rule'])) {
177
		$a_separators = &$config['filter']['separator'][strtolower($if)];
178
		$num_deleted = 0;
179

    
180
		foreach ($_POST['rule'] as $rulei) {
181
			delete_nat_association($a_filter[$rulei]['associated-rule-id']);
182
			unset($a_filter[$rulei]);
183
			$deleted = true;
184

    
185
			// Update the separators
186
			// As rules are deleted, $ridx has to be decremented or separator position will break
187
			$ridx = ifridx($if, $rulei) - $num_deleted;	// get rule index within interface
188
			$mvnrows = -1;
189
			move_separators($a_separators, $ridx, $mvnrows);
190
			$num_deleted++;
191
		}
192

    
193
		if ($deleted) {
194
			if (write_config(gettext("Firewall: Rules - deleted selected firewall rules."))) {
195
				mark_subsystem_dirty('filter');
196
			}
197
		}
198

    
199
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
200
		exit;
201
	}
202
} else if ($_POST['act'] == "toggle") {
203
	if ($a_filter[$_POST['id']]) {
204
		if (isset($a_filter[$_POST['id']]['disabled'])) {
205
			unset($a_filter[$_POST['id']]['disabled']);
206
			$wc_msg = gettext('Firewall: Rules - enabled a firewall rule.');
207
		} else {
208
			$a_filter[$_POST['id']]['disabled'] = true;
209
			$wc_msg = gettext('Firewall: Rules - disabled a firewall rule.');
210
		}
211
		if (write_config($wc_msg)) {
212
			mark_subsystem_dirty('filter');
213
		}
214

    
215
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
216
		exit;
217
	}
218
} else if ($_POST['order-store']) {
219

    
220
	/* update rule order, POST[rule] is an array of ordered IDs */
221
	if (is_array($_POST['rule']) && !empty($_POST['rule'])) {
222
		$a_filter_new = array();
223

    
224
		// Include the rules of other interfaces listed in config before this (the selected) interface.
225
		foreach ($a_filter as $filteri_before => $filterent) {
226
			if (($filterent['interface'] == $if && !isset($filterent['floating'])) || (isset($filterent['floating']) && "FloatingRules" == $if)) {
227
				break;
228
			} else {
229
				$a_filter_new[] = $filterent;
230
			}
231
		}
232

    
233
		// Include the rules of this (the selected) interface.
234
		// If a rule is not in POST[rule], it has been deleted by the user
235
		foreach ($_POST['rule'] as $id) {
236
			$a_filter_new[] = $a_filter[$id];
237
		}
238

    
239
		// Include the rules of other interfaces listed in config after this (the selected) interface.
240
		foreach ($a_filter as $filteri_after => $filterent) {
241
			if ($filteri_before > $filteri_after) {
242
				continue;
243
			}
244
			if (($filterent['interface'] == $if && !isset($filterent['floating'])) || (isset($filterent['floating']) && "FloatingRules" == $if)) {
245
				continue;
246
			} else {
247
				$a_filter_new[] = $filterent;
248
			}
249
		}
250

    
251
		$a_filter = $a_filter_new;
252

    
253
		$config['filter']['separator'][strtolower($if)] = "";
254

    
255
		if ($_POST['separator']) {
256
			$idx = 0;
257
			if (!is_array($config['filter']['separator'])) {
258
				$config['filter']['separator'] = array();
259
			}
260

    
261
			foreach ($_POST['separator'] as $separator) {
262
				if (!is_array($config['filter']['separator'][strtolower($separator['if'])]))  {
263
					$config['filter']['separator'][strtolower($separator['if'])] = array();
264
				}
265

    
266
				$config['filter']['separator'][strtolower($separator['if'])]['sep' . $idx++] = $separator;
267
			}
268
		}
269

    
270
		if (write_config(gettext("Firewall: Rules - reordered firewall rules."))) {
271
			mark_subsystem_dirty('filter');
272
		}
273

    
274
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
275
		exit;
276
	}
277
}
278

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

    
281
foreach ($iflist as $ifent => $ifname) {
282
	$tab_array[] = array($ifname, ($ifent == $if), "firewall_rules.php?if={$ifent}");
283
}
284

    
285
foreach ($tab_array as $dtab) {
286
	if ($dtab[1]) {
287
		$bctab = $dtab[0];
288
		break;
289
	}
290
}
291

    
292
$pgtitle = array(gettext("Firewall"), gettext("Rules"), $bctab);
293
$pglinks = array("", "firewall_rules.php", "@self");
294
$shortcut_section = "firewall";
295

    
296
include("head.inc");
297
$nrules = 0;
298

    
299
if ($savemsg) {
300
	print_info_box($savemsg, 'success');
301
}
302

    
303
if ($_POST['apply']) {
304
	print_apply_result_box($retval);
305
}
306

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

    
311
display_top_tabs($tab_array, false, 'pills');
312

    
313
$showantilockout = false;
314
$showprivate = false;
315
$showblockbogons = false;
316

    
317
if (!isset($config['system']['webgui']['noantilockout']) &&
318
    (((count($config['interfaces']) > 1) && ($if == 'lan')) ||
319
    ((count($config['interfaces']) == 1) && ($if == 'wan')))) {
320
	$showantilockout = true;
321
}
322

    
323
if (isset($config['interfaces'][$if]['blockpriv'])) {
324
	$showprivate = true;
325
}
326

    
327
if (isset($config['interfaces'][$if]['blockbogons'])) {
328
	$showblockbogons = true;
329
}
330

    
331
if (isset($config['system']['webgui']['roworderdragging'])) {
332
	$rules_header_text = gettext("Rules");
333
} else {
334
	$rules_header_text = gettext("Rules (Drag to Change Order)");
335
}
336

    
337
/* Load the counter data of each pf rule. */
338
$rulescnt = pfSense_get_pf_rules();
339

    
340
// Update this if you add or remove columns!
341
$columns_in_table = 13;
342

    
343
?>
344
<!-- Allow table to scroll when dragging outside of the display window -->
345
<style>
346
.table-responsive {
347
    clear: both;
348
    overflow-x: visible;
349
    margin-bottom: 0px;
350
}
351
</style>
352

    
353
<form method="post">
354
	<input name="if" id="if" type="hidden" value="<?=$if?>" />
355
	<div class="panel panel-default">
356
		<div class="panel-heading"><h2 class="panel-title"><?=$rules_header_text?></h2></div>
357
		<div id="mainarea" class="table-responsive panel-body">
358
			<table id="ruletable" class="table table-hover table-striped table-condensed" style="overflow-x: 'visible'">
359
				<thead>
360
					<tr>
361
						<th><input type="checkbox" id="selectAll" name="selectAll" /></th>
362
						<th><!-- status icons --></th>
363
						<th><?=gettext("States")?></th>
364
						<th><?=gettext("Protocol")?></th>
365
						<th><?=gettext("Source")?></th>
366
						<th><?=gettext("Port")?></th>
367
						<th><?=gettext("Destination")?></th>
368
						<th><?=gettext("Port")?></th>
369
						<th><?=gettext("Gateway")?></th>
370
						<th><?=gettext("Queue")?></th>
371
						<th><?=gettext("Schedule")?></th>
372
						<th><?=gettext("Description")?></th>
373
						<th><?=gettext("Actions")?></th>
374
					</tr>
375
				</thead>
376

    
377
<?php if ($showblockbogons || $showantilockout || $showprivate) :
378
?>
379
				<tbody>
380
<?php
381
		// 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.
382
		if ($showantilockout):
383
			$alports = implode('<br />', filter_get_antilockout_ports(true));
384
?>
385
					<tr id="antilockout">
386
						<td></td>
387
						<td title="<?=gettext("traffic is passed")?>"><i class="fa fa-check text-success"></i></td>
388
						<td><?php print_states(intval(ANTILOCKOUT_TRACKER)); ?></td>
389
						<td>*</td>
390
						<td>*</td>
391
						<td>*</td>
392
						<td><?=$iflist[$if];?> Address</td>
393
						<td><?=$alports?></td>
394
						<td>*</td>
395
						<td>*</td>
396
						<td></td>
397
						<td><?=gettext("Anti-Lockout Rule");?></td>
398
						<td>
399
							<a href="system_advanced_admin.php" title="<?=gettext("Settings");?>"><i class="fa fa-cog"></i></a>
400
						</td>
401
					</tr>
402
<?php 	endif;?>
403
<?php 	if ($showprivate): ?>
404
					<tr id="private">
405
						<td></td>
406
						<td title="<?=gettext("traffic is blocked")?>"><i class="fa fa-times text-danger"></i></td>
407
						<td><?php print_states(intval(RFC1918_TRACKER)); ?></td>
408
						<td>*</td>
409
						<td><?=gettext("RFC 1918 networks");?></td>
410
						<td>*</td>
411
						<td>*</td>
412
						<td>*</td>
413
						<td>*</td>
414
						<td>*</td>
415
						<td></td>
416
						<td><?=gettext("Block private networks");?></td>
417
						<td>
418
							<a href="interfaces.php?if=<?=htmlspecialchars($if)?>" title="<?=gettext("Settings");?>" usepost><i class="fa fa-cog"></i></a>
419
						</td>
420
					</tr>
421
<?php 	endif;?>
422
<?php 	if ($showblockbogons): ?>
423
					<tr id="bogons">
424
						<td></td>
425
						<td title="<?=gettext("traffic is blocked")?>"><i class="fa fa-times text-danger"></i></td>
426
						<td><?php print_states(intval(BOGONS_TRACKER)); ?></td>
427
						<td>*</td>
428
						<td><?=sprintf(gettext("Reserved%sNot assigned by IANA"), "<br />");?></td>
429
						<td>*</td>
430
						<td>*</td>
431
						<td>*</td>
432
						<td>*</td>
433
						<td>*</td>
434
						<td></td>
435
						<td><?=gettext("Block bogon networks");?></td>
436
						<td>
437
							<a href="interfaces.php?if=<?=htmlspecialchars($if)?>" title="<?=gettext("Settings");?>" usepost><i class="fa fa-cog"></i></a>
438
						</td>
439
					</tr>
440
<?php 	endif;?>
441
			</tbody>
442
<?php endif;?>
443
			<tbody class="user-entries">
444
<?php
445
$nrules = 0;
446
$separators = $config['filter']['separator'][strtolower($if)];
447

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

    
452
foreach ($a_filter as $filteri => $filterent):
453

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

    
456
		// Display separator(s) for section beginning at rule n
457
		if ($seprows[$nrules]) {
458
			display_separator($separators, $nrules, $columns_in_table);
459
		}
460
?>
461
					<tr id="fr<?=$nrules;?>" onClick="fr_toggle(<?=$nrules;?>)" ondblclick="document.location='firewall_rules_edit.php?id=<?=$filteri;?>';" <?=(isset($filterent['disabled']) ? ' class="disabled"' : '')?>>
462
						<td>
463
							<input type="checkbox" id="frc<?=$nrules;?>" onClick="fr_toggle(<?=$nrules;?>)" name="rule[]" value="<?=$filteri;?>"/>
464
						</td>
465

    
466
	<?php
467
		if ($filterent['type'] == "block") {
468
			$iconfn = "times text-danger";
469
			$title_text = gettext("traffic is blocked");
470
		} else if ($filterent['type'] == "reject") {
471
			$iconfn = "hand-stop-o text-warning";
472
			$title_text = gettext("traffic is rejected");
473
		} else if ($filterent['type'] == "match") {
474
			$iconfn = "filter";
475
			$title_text = gettext("traffic is matched");
476
		} else {
477
			$iconfn = "check text-success";
478
			$title_text = gettext("traffic is passed");
479
		}
480
	?>
481
						<td title="<?=$title_text?>">
482
							<a href="?if=<?=htmlspecialchars($if);?>&amp;act=toggle&amp;id=<?=$filteri;?>" usepost>
483
								<i class="fa fa-<?=$iconfn?>" title="<?=gettext("click to toggle enabled/disabled status");?>"></i>
484
							</a>
485
	<?php
486
		if ($filterent['quick'] == 'yes') {
487
			print '<i class="fa fa-forward text-success" title="'. gettext("&quot;Quick&quot; rule. Applied immediately on match.") .'" style="cursor: pointer;"></i>';
488
		}
489

    
490
		$isadvset = firewall_check_for_advanced_options($filterent);
491
		if ($isadvset) {
492
			print '<i class="fa fa-cog" title="'. gettext("advanced setting") .': '. $isadvset .'"></i>';
493
		}
494

    
495
		if (isset($filterent['log'])) {
496
			print '<i class="fa fa-tasks" title="'. gettext("traffic is logged") .'" style="cursor: pointer;"></i>';
497
		}
498
	?>
499
						</td>
500
	<?php
501
		$alias = rule_columns_with_alias(
502
			$filterent['source']['address'],
503
			pprint_port($filterent['source']['port']),
504
			$filterent['destination']['address'],
505
			pprint_port($filterent['destination']['port'])
506
		);
507

    
508
		if (!is_array($config['schedules'])) {
509
			$config['schedules'] = array();
510
		}
511

    
512
		if (!is_array($config['schedules']['schedule'])) {
513
			$config['schedules']['schedule'] = array();
514
		}
515
		//build Schedule popup box
516
		$a_schedules = &$config['schedules']['schedule'];
517
		$schedule_span_begin = "";
518
		$schedule_span_end = "";
519
		$sched_caption_escaped = "";
520
		$sched_content = "";
521
		$schedstatus = false;
522
		$dayArray = array (gettext('Mon'), gettext('Tues'), gettext('Wed'), gettext('Thur'), gettext('Fri'), gettext('Sat'), gettext('Sun'));
523
		$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'));
524
		if ($config['schedules']['schedule'] != "" && is_array($config['schedules']['schedule'])) {
525
			$idx = 0;
526
			foreach ($a_schedules as $schedule) {
527
				if ($schedule['name'] == $filterent['sched']) {
528
					$schedstatus = filter_get_time_based_rule_status($schedule);
529

    
530
					foreach ($schedule['timerange'] as $timerange) {
531
						$tempFriendlyTime = "";
532
						$tempID = "";
533
						$firstprint = false;
534
						if ($timerange) {
535
							$dayFriendly = "";
536
							$tempFriendlyTime = "";
537

    
538
							//get hours
539
							$temptimerange = $timerange['hour'];
540
							$temptimeseparator = strrpos($temptimerange, "-");
541

    
542
							$starttime = substr ($temptimerange, 0, $temptimeseparator);
543
							$stoptime = substr ($temptimerange, $temptimeseparator+1);
544

    
545
							if ($timerange['month']) {
546
								$tempmontharray = explode(",", $timerange['month']);
547
								$tempdayarray = explode(",", $timerange['day']);
548
								$arraycounter = 0;
549
								$firstDayFound = false;
550
								$firstPrint = false;
551
								foreach ($tempmontharray as $monthtmp) {
552
									$month = $tempmontharray[$arraycounter];
553
									$day = $tempdayarray[$arraycounter];
554

    
555
									if (!$firstDayFound) {
556
										$firstDay = $day;
557
										$firstmonth = $month;
558
										$firstDayFound = true;
559
									}
560

    
561
									$currentDay = $day;
562
									$nextDay = $tempdayarray[$arraycounter+1];
563
									$currentDay++;
564
									if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])) {
565
										if ($firstPrint) {
566
											$dayFriendly .= ", ";
567
										}
568
										$currentDay--;
569
										if ($currentDay != $firstDay) {
570
											$dayFriendly .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
571
										} else {
572
											$dayFriendly .=	 $monthArray[$month-1] . " " . $day;
573
										}
574
										$firstDayFound = false;
575
										$firstPrint = true;
576
									}
577
									$arraycounter++;
578
								}
579
							} else {
580
								$tempdayFriendly = $timerange['position'];
581
								$firstDayFound = false;
582
								$tempFriendlyDayArray = explode(",", $tempdayFriendly);
583
								$currentDay = "";
584
								$firstDay = "";
585
								$nextDay = "";
586
								$counter = 0;
587
								foreach ($tempFriendlyDayArray as $day) {
588
									if ($day != "") {
589
										if (!$firstDayFound) {
590
											$firstDay = $tempFriendlyDayArray[$counter];
591
											$firstDayFound = true;
592
										}
593
										$currentDay =$tempFriendlyDayArray[$counter];
594
										//get next day
595
										$nextDay = $tempFriendlyDayArray[$counter+1];
596
										$currentDay++;
597
										if ($currentDay != $nextDay) {
598
											if ($firstprint) {
599
												$dayFriendly .= ", ";
600
											}
601
											$currentDay--;
602
											if ($currentDay != $firstDay) {
603
												$dayFriendly .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
604
											} else {
605
												$dayFriendly .= $dayArray[$firstDay-1];
606
											}
607
											$firstDayFound = false;
608
											$firstprint = true;
609
										}
610
										$counter++;
611
									}
612
								}
613
							}
614
							$timeFriendly = $starttime . " - " . $stoptime;
615
							$description = $timerange['rangedescr'];
616
							$sched_content .= $dayFriendly . "; " . $timeFriendly . "<br />";
617
						}
618
					}
619
					#FIXME
620
					$sched_caption_escaped = str_replace("'", "\'", $schedule['descr']);
621
					$schedule_span_begin = '<a href="/firewall_schedule_edit.php?id=' . $idx . '" data-toggle="popover" data-trigger="hover focus" title="' . $schedule['name'] . '" data-content="' .
622
						$sched_caption_escaped . '" data-html="true">';
623
					$schedule_span_end = "</a>";
624
				}
625
				$idx++;
626
			}
627
		}
628
		$printicon = false;
629
		$alttext = "";
630
		$image = "";
631
		if (!isset($filterent['disabled'])) {
632
			if ($schedstatus) {
633
				if ($filterent['type'] == "block" || $filterent['type'] == "reject") {
634
					$image = "times-circle";
635
					$dispcolor = "text-danger";
636
					$alttext = gettext("Traffic matching this rule is currently being denied");
637
				} else {
638
					$image = "play-circle";
639
					$dispcolor = "text-success";
640
					$alttext = gettext("Traffic matching this rule is currently being allowed");
641
				}
642
				$printicon = true;
643
			} else if ($filterent['sched']) {
644
				if ($filterent['type'] == "block" || $filterent['type'] == "reject") {
645
					$image = "times-circle";
646
				} else {
647
					$image = "play-circle";
648
				}
649
				$alttext = gettext("This rule is not currently active because its period has expired");
650
				$dispcolor = "text-warning";
651
				$printicon = true;
652
			}
653
		}
654
	?>
655
				<td><?php print_states(intval($filterent['tracker'])); ?></td>
656
				<td>
657
	<?php
658
		if (isset($filterent['ipprotocol'])) {
659
			switch ($filterent['ipprotocol']) {
660
				case "inet":
661
					echo "IPv4 ";
662
					break;
663
				case "inet6":
664
					echo "IPv6 ";
665
					break;
666
				case "inet46":
667
					echo "IPv4+6 ";
668
					break;
669
			}
670
		} else {
671
			echo "IPv4 ";
672
		}
673

    
674
		if (isset($filterent['protocol'])) {
675
			echo strtoupper($filterent['protocol']);
676

    
677
			if (strtoupper($filterent['protocol']) == "ICMP" && !empty($filterent['icmptype'])) {
678
				// replace each comma-separated icmptype item by its (localised) full description
679
				$t = 	implode(', ',
680
						array_map(
681
						        function($type) {
682
								global $icmptypes;
683
								return $icmptypes[$type]['descrip'];
684
							},
685
							explode(',', $filterent['icmptype'])
686
						)
687
					);
688
				echo sprintf('<br /><div style="cursor:help;padding:1px;line-height:1.1em;max-height:2.5em;max-width:180px;overflow-y:auto;overflow-x:hidden" title="%s:%s%s"><small><u>%s</u></small></div>', gettext('ICMP subtypes'), chr(13), $t, str_replace(',', '</u>, <u>',$filterent['icmptype']));
689
			}
690
		} else {
691
			echo " *";
692
		}
693
	?>
694
						</td>
695
						<td>
696
							<?php if (isset($alias['src'])): ?>
697
								<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">
698
									<?=str_replace('_', '_<wbr>', htmlspecialchars(pprint_address($filterent['source'])))?>
699
								</a>
700
							<?php else: ?>
701
								<?=htmlspecialchars(pprint_address($filterent['source']))?>
702
							<?php endif; ?>
703
						</td>
704
						<td>
705
							<?php if (isset($alias['srcport'])): ?>
706
								<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">
707
									<?=str_replace('_', '_<wbr>', htmlspecialchars(pprint_port($filterent['source']['port'])))?>
708
								</a>
709
							<?php else: ?>
710
								<?=htmlspecialchars(pprint_port($filterent['source']['port']))?>
711
							<?php endif; ?>
712
						</td>
713
						<td>
714
							<?php if (isset($alias['dst'])): ?>
715
								<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">
716
									<?=str_replace('_', '_<wbr>', htmlspecialchars(pprint_address($filterent['destination'])))?>
717
								</a>
718
							<?php else: ?>
719
								<?=htmlspecialchars(pprint_address($filterent['destination']))?>
720
							<?php endif; ?>
721
						</td>
722
						<td>
723
							<?php if (isset($alias['dstport'])): ?>
724
								<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">
725
									<?=str_replace('_', '_<wbr>', htmlspecialchars(pprint_port($filterent['destination']['port'])))?>
726
								</a>
727
							<?php else: ?>
728
								<?=htmlspecialchars(pprint_port($filterent['destination']['port']))?>
729
							<?php endif; ?>
730
						</td>
731
						<td>
732
							<?php if (isset($config['interfaces'][$filterent['gateway']]['descr'])):?>
733
								<?=str_replace('_', '_<wbr>', htmlspecialchars($config['interfaces'][$filterent['gateway']]['descr']))?>
734
							<?php else: ?>
735
								<?=htmlspecialchars(pprint_port($filterent['gateway']))?>
736
							<?php endif; ?>
737
						</td>
738
						<td>
739
							<?php
740
								if (isset($filterent['ackqueue']) && isset($filterent['defaultqueue'])) {
741
									$desc = str_replace('_', ' ', $filterent['ackqueue']);
742
									echo "<a href=\"firewall_shaper_queues.php?queue={$filterent['ackqueue']}&amp;action=show\">{$desc}</a>";
743
									$desc = str_replace('_', '_<wbr>', $filterent['defaultqueue']);
744
									echo "/<a href=\"firewall_shaper_queues.php?queue={$filterent['defaultqueue']}&amp;action=show\">{$desc}</a>";
745
								} else if (isset($filterent['defaultqueue'])) {
746
									$desc = str_replace('_', '_<wbr>', $filterent['defaultqueue']);
747
									echo "<a href=\"firewall_shaper_queues.php?queue={$filterent['defaultqueue']}&amp;action=show\">{$desc}</a>";
748
								} else {
749
									echo gettext("none");
750
								}
751
							?>
752
						</td>
753
						<td>
754
							<?php if ($printicon) { ?>
755
								<i class="fa fa-<?=$image?> <?=$dispcolor?>" title="<?=$alttext;?>"></i>
756
							<?php } ?>
757
							<?=$schedule_span_begin;?><?=str_replace('_', '_<wbr>', htmlspecialchars($filterent['sched']));?>&nbsp;<?=$schedule_span_end;?>
758
						</td>
759
						<td>
760
							<?=htmlspecialchars($filterent['descr']);?>
761
						</td>
762
						<td class="action-icons">
763
						<!-- <?=(isset($filterent['disabled']) ? 'enable' : 'disable')?> -->
764
							<a	class="fa fa-anchor icon-pointer" id="Xmove_<?=$filteri?>" title="<?=$XmoveTitle?>"></a>
765
							<a href="firewall_rules_edit.php?id=<?=$filteri;?>" class="fa fa-pencil" title="<?=gettext('Edit')?>"></a>
766
							<a href="firewall_rules_edit.php?dup=<?=$filteri;?>" class="fa fa-clone" title="<?=gettext('Copy')?>"></a>
767
<?php if (isset($filterent['disabled'])) {
768
?>
769
							<a href="?act=toggle&amp;if=<?=htmlspecialchars($if);?>&amp;id=<?=$filteri;?>" class="fa fa-check-square-o" title="<?=gettext('Enable')?>" usepost></a>
770
<?php } else {
771
?>
772
							<a href="?act=toggle&amp;if=<?=htmlspecialchars($if);?>&amp;id=<?=$filteri;?>" class="fa fa-ban" title="<?=gettext('Disable')?>" usepost></a>
773
<?php }
774
?>
775
							<a href="?act=del&amp;if=<?=htmlspecialchars($if);?>&amp;id=<?=$filteri;?>" class="fa fa-trash" title="<?=gettext('Delete this rule')?>" usepost></a>
776
						</td>
777
					</tr>
778
<?php
779
		$nrules++;
780
	}
781
endforeach;
782

    
783
// There can be separator(s) after the last rule listed.
784
if ($seprows[$nrules]) {
785
	display_separator($separators, $nrules, $columns_in_table);
786
}
787
?>
788
				</tbody>
789
			</table>
790
		</div>
791
	</div>
792

    
793
<?php if ($nrules == 0): ?>
794
	<div class="alert alert-warning" role="alert">
795
		<p>
796
		<?php if ($_REQUEST['if'] == "FloatingRules"): ?>
797
			<?=gettext("No floating rules are currently defined.");?>
798
		<?php else: ?>
799
			<?=gettext("No rules are currently defined for this interface");?><br />
800
			<?=gettext("All incoming connections on this interface will be blocked until pass rules are added.");?>
801
		<?php endif;?>
802
			<?=gettext("Click the button to add a new rule.");?>
803
		</p>
804
	</div>
805
<?php endif;?>
806

    
807
	<nav class="action-buttons">
808
		<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')?>">
809
			<i class="fa fa-level-up icon-embed-btn"></i>
810
			<?=gettext("Add");?>
811
		</a>
812
		<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')?>">
813
			<i class="fa fa-level-down icon-embed-btn"></i>
814
			<?=gettext("Add");?>
815
		</a>
816
		<button name="del_x" type="submit" class="btn btn-danger btn-sm" value="<?=gettext("Delete selected rules"); ?>" title="<?=gettext('Delete selected rules')?>">
817
			<i class="fa fa-trash icon-embed-btn"></i>
818
			<?=gettext("Delete"); ?>
819
		</button>
820
		<button type="submit" id="order-store" name="order-store" class="btn btn-sm btn-primary" value="store changes" disabled title="<?=gettext('Save rule order')?>">
821
			<i class="fa fa-save icon-embed-btn"></i>
822
			<?=gettext("Save")?>
823
		</button>
824
		<button type="submit" id="addsep" name="addsep" class="btn btn-sm btn-warning" title="<?=gettext('Add separator')?>">
825
			<i class="fa fa-plus icon-embed-btn"></i>
826
			<?=gettext("Separator")?>
827
		</button>
828
	</nav>
829
</form>
830

    
831
<div class="infoblock">
832
	<div class="alert alert-info clearfix" role="alert"><div class="pull-left">
833
		<dl class="dl-horizontal responsive">
834
		<!-- Legend -->
835
			<dt><?=gettext('Legend')?></dt>				<dd></dd>
836
			<dt><i class="fa fa-check text-success"></i></dt>		<dd><?=gettext("Pass");?></dd>
837
			<dt><i class="fa fa-filter"></i></dt>	<dd><?=gettext("Match");?></dd>
838
			<dt><i class="fa fa-times text-danger"></i></dt>	<dd><?=gettext("Block");?></dd>
839
			<dt><i class="fa fa-hand-stop-o text-warning"></i></dt>		<dd><?=gettext("Reject");?></dd>
840
			<dt><i class="fa fa-tasks"></i></dt>	<dd> <?=gettext("Log");?></dd>
841
			<dt><i class="fa fa-cog"></i></dt>		<dd> <?=gettext("Advanced filter");?></dd>
842
			<dt><i class="fa fa-forward text-success"></i></dt><dd> <?=gettext("&quot;Quick&quot; rule. Applied immediately on match.")?></dd>
843
		</dl>
844

    
845
<?php
846
	if ("FloatingRules" != $if) {
847
		print(gettext("Rules are evaluated on a first-match basis (i.e. " .
848
			"the action of the first rule to match a packet will be executed). ") . '<br />' .
849
			gettext("This means that if block rules are used, it is important to pay attention " .
850
			"to the rule order. Everything that isn't explicitly passed is blocked " .
851
			"by default. "));
852
	} else {
853
		print(gettext("Floating rules are evaluated on a first-match basis (i.e. " .
854
			"the action of the first rule to match a packet will be executed) only " .
855
			"if the 'quick' option is checked on a rule. Otherwise they will only match if no " .
856
			"other rules match. Pay close attention to the rule order and options " .
857
			"chosen. If no rule here matches, the per-interface or default rules are used. "));
858
	}
859

    
860
	printf(gettext('%1$sClick the anchor icon %2$s to move checked rules before the clicked row. Hold down ' .
861
			'the shift key and click to move the rules after the clicked row.'), '<br /><br />', '<i class="fa fa-anchor"></i>')
862
?>
863
	</div>
864
	</div>
865
</div>
866

    
867
<script type="text/javascript">
868
//<![CDATA[
869

    
870
//Need to create some variables here so that jquery/pfSenseHelpers.js can read them
871
iface = "<?=strtolower($if)?>";
872
cncltxt = '<?=gettext("Cancel")?>';
873
svtxt = '<?=gettext("Save")?>';
874
svbtnplaceholder = '<?=gettext("Enter a description, Save, then drag to final location.")?>';
875
configsection = "filter";
876

    
877
events.push(function() {
878

    
879
	// "Move to here" (anchor) action
880
	$('[id^=Xmove_]').click(function (event) {
881

    
882
		// Prevent click from toggling row
883
		event.stopImmediatePropagation();
884

    
885
		// Save the target rule position
886
		var anchor_row = $(this).parents("tr:first");
887

    
888
		if (event.shiftKey) {
889
			$($('#ruletable > tbody  > tr').get().reverse()).each(function() {
890
				ruleid = this.id.slice(2);
891

    
892
				if (ruleid && !isNaN(ruleid)) {
893
					if ($('#frc' + ruleid).prop('checked')) {
894
						// Move the selected rows, un-select them and add highlight class
895
						$(this).insertAfter(anchor_row);
896
						fr_toggle(ruleid, "fr");
897
						$('#fr' + ruleid).addClass("highlight");
898
					}
899
				}
900
			});
901
		} else {
902
			$('#ruletable > tbody  > tr').each(function() {
903
				ruleid = this.id.slice(2);
904

    
905
				if (ruleid && !isNaN(ruleid)) {
906
					if ($('#frc' + ruleid).prop('checked')) {
907
						// Move the selected rows, un-select them and add highlight class
908
						$(this).insertBefore(anchor_row);
909
						fr_toggle(ruleid, "fr");
910
						$('#fr' + ruleid).addClass("highlight");
911
					}
912
				}
913
			});
914
		}
915

    
916
		// Temporarily set background color so user can more easily see the moved rules, then fade
917
		$('.highlight').effect("highlight", {color: "#739b4b;"}, 4000);
918
		$('#ruletable tr').removeClass("highlight");
919
		$('#order-store').removeAttr('disabled');
920
		reindex_rules($(anchor_row).parent('tbody'));
921
		dirty = true;
922
	}).mouseover(function(e) {
923
		var ruleselected = false;
924

    
925
		$(this).css("cursor", "default");
926

    
927
		// Are any rules currently selected?
928
		$('[id^=frc]').each(function () {
929
			if ($(this).prop("checked")) {
930
				ruleselected = true;
931
			}
932
		});
933

    
934
		// If so, change the icon to show the insertion point
935
		if (ruleselected) {
936
			if (e.shiftKey) {
937
				$(this).removeClass().addClass("fa fa-lg fa-arrow-down text-danger");
938
			} else {
939
				$(this).removeClass().addClass("fa fa-lg fa-arrow-up text-danger");
940
			}
941
		}
942
	}).mouseout(function(e) {
943
		$(this).removeClass().addClass("fa fa-anchor");
944
	});
945

    
946
<?php if(!isset($config['system']['webgui']['roworderdragging'])): ?>
947
	// Make rules sortable. Hiding the table before applying sortable, then showing it again is
948
	// a work-around for very slow sorting on FireFox
949
	$('table tbody.user-entries').hide();
950

    
951
	$('table tbody.user-entries').sortable({
952
		cursor: 'grabbing',
953
		scroll: true,
954
		overflow: 'scroll',
955
		scrollSensitivity: 100,
956
		update: function(event, ui) {
957
			$('#order-store').removeAttr('disabled');
958
			reindex_rules(ui.item.parent('tbody'));
959
			dirty = true;
960
		}
961
	});
962

    
963
	$('table tbody.user-entries').show();
964
<?php endif; ?>
965

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

    
970
		// Save the separator bar configuration
971
		save_separators();
972

    
973
		// Suppress the "Do you really want to leave the page" message
974
		saving = true;
975
	});
976

    
977
	// Provide a warning message if the user tries to change page before saving
978
	$(window).bind('beforeunload', function(){
979
		if ((!saving && dirty) || newSeperator) {
980
			return ("<?=gettext('One or more rules have been moved but have not yet been saved')?>");
981
		} else {
982
			return undefined;
983
		}
984
	});
985

    
986
	$(document).on('keyup keydown', function(e){
987
		if (e.shiftKey) {
988
			$('[id^=Xmove_]').attr("title", "<?=$ShXmoveTitle?>");
989
		} else {
990
			$('[id^=Xmove_]').attr("title", "<?=$XmoveTitle?>");
991
		}
992
	});
993

    
994
	$('#selectAll').click(function() {
995
		var checkedStatus = this.checked;
996
		$('#ruletable tbody tr').find('td:first :checkbox').each(function() {
997
		$(this).prop('checked', checkedStatus);
998
		});
999
	});
1000
});
1001
//]]>
1002
</script>
1003

    
1004
<?php include("foot.inc");?>
(50-50/234)