Project

General

Profile

Download (32.5 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
 * 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
$pgtitle = array(gettext("Firewall"), gettext("Rules"));
43
$shortcut_section = "firewall";
44

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

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

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

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

    
60
	return ($arr);
61
}
62

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

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

    
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=\"evaluations: %s<br>packets: %s<br>bytes: %s<br>states: %s<br>state creations: %s\" data-html=\"true\">",
90
	    format_number($evaluations), format_number($packets), format_bytes($bytes),
91
	    format_number($states), format_number($stcreations));
92
	printf("%d/%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']['rule'])) {
112
	$config['filter']['rule'] = array();
113
}
114

    
115
filter_rules_sort();
116
$a_filter = &$config['filter']['rule'];
117

    
118
$if = $_GET['if'];
119

    
120
if ($_POST['if']) {
121
	$if = $_POST['if'];
122
}
123

    
124
$ifdescs = get_configured_interface_with_descr();
125

    
126
/* add group interfaces */
127
if (is_array($config['ifgroups']['ifgroupentry'])) {
128
	foreach ($config['ifgroups']['ifgroupentry'] as $ifgen) {
129
		if (have_ruleint_access($ifgen['ifname'])) {
130
			$iflist[$ifgen['ifname']] = $ifgen['ifname'];
131
		}
132
	}
133
}
134

    
135
foreach ($ifdescs as $ifent => $ifdesc) {
136
	if (have_ruleint_access($ifent)) {
137
		$iflist[$ifent] = $ifdesc;
138
	}
139
}
140

    
141
if ($config['l2tp']['mode'] == "server") {
142
	if (have_ruleint_access("l2tp")) {
143
		$iflist['l2tp'] = gettext("L2TP VPN");
144
	}
145
}
146

    
147
if (is_array($config['pppoes']['pppoe'])) {
148
	foreach ($config['pppoes']['pppoe'] as $pppoes) {
149
		if (($pppoes['mode'] == 'server') && have_ruleint_access("pppoe")) {
150
			$iflist['pppoe'] = gettext("PPPoE Server");
151
		}
152
	}
153
}
154

    
155
/* add ipsec interfaces */
156
if (ipsec_enabled() && have_ruleint_access("enc0")) {
157
	$iflist["enc0"] = gettext("IPsec");
158
}
159

    
160
/* add openvpn/tun interfaces */
161
if ($config['openvpn']["openvpn-server"] || $config['openvpn']["openvpn-client"]) {
162
	$iflist["openvpn"] = gettext("OpenVPN");
163
}
164

    
165
if (!$if || !isset($iflist[$if])) {
166
	if ("any" == $if) {
167
		$if = "FloatingRules";
168
	} else if ("FloatingRules" != $if) {
169
		if (isset($iflist['wan'])) {
170
			$if = "wan";
171
		} else {
172
			$if = "FloatingRules";
173
		}
174
	}
175
}
176

    
177
if ($_POST) {
178
	$pconfig = $_POST;
179

    
180
	if ($_POST['apply']) {
181
		$retval = 0;
182
		$retval = filter_configure();
183

    
184
		clear_subsystem_dirty('filter');
185

    
186
		$savemsg = sprintf(gettext("The settings have been applied. The firewall rules are now reloading in the background.<br />%s Monitor %s the reload progress."),
187
									"<a href='status_filter_reload.php'>", "</a>");
188
	}
189
}
190

    
191
if ($_GET['act'] == "del") {
192
	if ($a_filter[$_GET['id']]) {
193
		if (!empty($a_filter[$_GET['id']]['associated-rule-id'])) {
194
			delete_nat_association($a_filter[$_GET['id']]['associated-rule-id']);
195
		}
196
		unset($a_filter[$_GET['id']]);
197

    
198
		// Update the separators
199
		$a_separators = &$config['filter']['separator'][strtolower($if)];
200
		$ridx = ifridx($if, $_GET['id']);	// get rule index within interface
201
		$mvnrows = -1;
202
		move_separators($a_separators, $ridx, $mvnrows);
203

    
204
		if (write_config()) {
205
			mark_subsystem_dirty('filter');
206
		}
207

    
208
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
209
		exit;
210
	}
211
}
212

    
213
// Handle save msg if defined
214
if ($_REQUEST['savemsg']) {
215
	$savemsg = htmlentities($_REQUEST['savemsg']);
216
}
217

    
218
if (isset($_POST['del_x'])) {
219
	/* delete selected rules */
220
	$deleted = false;
221

    
222
	if (is_array($_POST['rule']) && count($_POST['rule'])) {
223
		$a_separators = &$config['filter']['separator'][strtolower($if)];
224

    
225
		foreach ($_POST['rule'] as $rulei) {
226
			delete_nat_association($a_filter[$rulei]['associated-rule-id']);
227
			unset($a_filter[$rulei]);
228
			$deleted = true;
229

    
230
			// Update the separators
231
			$ridx = ifridx($if, $rulei);	// get rule index within interface
232
			$mvnrows = -1;
233
			move_separators($a_separators, $ridx, $mvnrows);
234
		}
235

    
236
		if ($deleted) {
237
			if (write_config()) {
238
				mark_subsystem_dirty('filter');
239
			}
240
		}
241

    
242
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
243
		exit;
244
	}
245
} else if ($_GET['act'] == "toggle") {
246
	if ($a_filter[$_GET['id']]) {
247
		if (isset($a_filter[$_GET['id']]['disabled'])) {
248
			unset($a_filter[$_GET['id']]['disabled']);
249
		} else {
250
			$a_filter[$_GET['id']]['disabled'] = true;
251
		}
252
		if (write_config()) {
253
			mark_subsystem_dirty('filter');
254
		}
255

    
256
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
257
		exit;
258
	}
259
} else if ($_POST['order-store']) {
260

    
261
	/* update rule order, POST[rule] is an array of ordered IDs */
262
	if (is_array($_POST['rule']) && !empty($_POST['rule'])) {
263
		$a_filter_new = array();
264

    
265
		// Include the rules of other interfaces listed in config before this (the selected) interface.
266
		foreach ($a_filter as $filteri_before => $filterent) {
267
			if (($filterent['interface'] == $if && !isset($filterent['floating'])) || (isset($filterent['floating']) && "FloatingRules" == $if)) {
268
				break;
269
			} else {
270
				$a_filter_new[] = $filterent;
271
			}
272
		}
273

    
274
		// Include the rules of this (the selected) interface.
275
		// If a rule is not in POST[rule], it has been deleted by the user
276
		foreach ($_POST['rule'] as $id) {
277
			$a_filter_new[] = $a_filter[$id];
278
		}
279

    
280
		// Include the rules of other interfaces listed in config after this (the selected) interface.
281
		foreach ($a_filter as $filteri_after => $filterent) {
282
			if ($filteri_before > $filteri_after) {
283
				continue;
284
			}
285
			if (($filterent['interface'] == $if && !isset($filterent['floating'])) || (isset($filterent['floating']) && "FloatingRules" == $if)) {
286
				continue;
287
			} else {
288
				$a_filter_new[] = $filterent;
289
			}
290
		}
291

    
292
		$a_filter = $a_filter_new;
293

    
294
		$config['filter']['separator'][strtolower($if)] = "";
295

    
296
		if ($_POST['separator']) {
297
			$idx = 0;
298
			foreach ($_POST['separator'] as $separator) {
299
				$config['filter']['separator'][strtolower($separator['if'])]['sep' . $idx++] = $separator;
300
			}
301
		}
302

    
303
		if (write_config()) {
304
			mark_subsystem_dirty('filter');
305
		}
306

    
307
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
308
		exit;
309
	}
310
}
311

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

    
314
foreach ($iflist as $ifent => $ifname) {
315
	$tab_array[] = array($ifname, ($ifent == $if), "firewall_rules.php?if={$ifent}");
316
}
317

    
318
foreach ($tab_array as $dtab) {
319
	if ($dtab[1]) {
320
		$bctab = $dtab[0];
321
		break;
322
	}
323
}
324

    
325
$pgtitle = array(gettext("Firewall"), gettext("Rules"), $bctab);
326
$shortcut_section = "firewall";
327

    
328
include("head.inc");
329
$nrules = 0;
330

    
331
if ($savemsg) {
332
	print_info_box($savemsg, 'success');
333
}
334

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

    
339
display_top_tabs($tab_array);
340

    
341
$showantilockout = false;
342
$showprivate = false;
343
$showblockbogons = false;
344

    
345
if (!isset($config['system']['webgui']['noantilockout']) &&
346
    (((count($config['interfaces']) > 1) && ($if == 'lan')) ||
347
    ((count($config['interfaces']) == 1) && ($if == 'wan')))) {
348
	$showantilockout = true;
349
}
350

    
351
if (isset($config['interfaces'][$if]['blockpriv'])) {
352
	$showprivate = true;
353
}
354

    
355
if (isset($config['interfaces'][$if]['blockbogons'])) {
356
	$showblockbogons = true;
357
}
358

    
359
/* Load the counter data of each pf rule. */
360
$rulescnt = pfSense_get_pf_rules();
361

    
362
// Update this if you add or remove columns!
363
$columns_in_table = 13;
364

    
365
?>
366
<form method="post">
367
	<div class="panel panel-default">
368
		<div class="panel-heading"><h2 class="panel-title"><?=gettext("Rules (Drag to Change Order)")?></h2></div>
369
		<div id="mainarea" class="table-responsive panel-body">
370
			<table id="ruletable" class="table table-hover table-striped table-condensed">
371
				<thead>
372
					<tr>
373
						<th><!-- checkbox --></th>
374
						<th><!-- status icons --></th>
375
						<th><?=gettext("States")?></th>
376
						<th><?=gettext("Protocol")?></th>
377
						<th><?=gettext("Source")?></th>
378
						<th><?=gettext("Port")?></th>
379
						<th><?=gettext("Destination")?></th>
380
						<th><?=gettext("Port")?></th>
381
						<th><?=gettext("Gateway")?></th>
382
						<th><?=gettext("Queue")?></th>
383
						<th><?=gettext("Schedule")?></th>
384
						<th><?=gettext("Description")?></th>
385
						<th><?=gettext("Actions")?></th>
386
					</tr>
387
				</thead>
388

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

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

    
464
foreach ($a_filter as $filteri => $filterent):
465

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

    
468
		// Display separator(s) for section beginning at rule n
469
		if ($seprows[$nrules]) {
470
			display_separator($separators, $nrules, $columns_in_table);
471
		}
472
?>
473
					<tr id="fr<?=$nrules;?>" onClick="fr_toggle(<?=$nrules;?>)" ondblclick="document.location='firewall_rules_edit.php?id=<?=$filteri;?>';" <?=(isset($filterent['disabled']) ? ' class="disabled"' : '')?>>
474
						<td>
475
							<input type="checkbox" id="frc<?=$nrules;?>" onClick="fr_toggle(<?=$nrules;?>)" name="rule[]" value="<?=$filteri;?>"/>
476
						</td>
477

    
478
	<?php
479
		if ($filterent['type'] == "block") {
480
			$iconfn = "times text-danger";
481
			$title_text = gettext("traffic is blocked");
482
		} else if ($filterent['type'] == "reject") {
483
			$iconfn = "hand-stop-o text-warning";
484
			$title_text = gettext("traffic is rejected");
485
		} else if ($filterent['type'] == "match") {
486
			$iconfn = "filter";
487
			$title_text = gettext("traffic is matched");
488
		} else {
489
			$iconfn = "check text-success";
490
			$title_text = gettext("traffic is passed");
491
		}
492
	?>
493
						<td title="<?=$title_text?>">
494
							<a href="?if=<?=htmlspecialchars($if);?>&amp;act=toggle&amp;id=<?=$filteri;?>">
495
								<i class="fa fa-<?=$iconfn?>" title="<?=gettext("click to toggle enabled/disabled status");?>"></i>
496
							</a>
497
	<?php
498
		if ($filterent['quick'] == 'yes') {
499
			print '<i class="fa fa-forward text-success" title="'. gettext("&quot;Quick&quot; rule. Applied immediately on match.") .'" style="cursor: pointer;"></i>';
500
		}
501

    
502
		$isadvset = firewall_check_for_advanced_options($filterent);
503
		if ($isadvset) {
504
			print '<i class="fa fa-cog" title="'. gettext("advanced setting") .': '. $isadvset .'"></i>';
505
		}
506

    
507
		if (isset($filterent['log'])) {
508
			print '<i class="fa fa-tasks" title="'. gettext("traffic is logged") .'" style="cursor: pointer;"></i>';
509
		}
510
	?>
511
						</td>
512
	<?php
513
		$alias = rule_columns_with_alias(
514
			$filterent['source']['address'],
515
			pprint_port($filterent['source']['port']),
516
			$filterent['destination']['address'],
517
			pprint_port($filterent['destination']['port'])
518
		);
519

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

    
535
					foreach ($schedule['timerange'] as $timerange) {
536
						$tempFriendlyTime = "";
537
						$tempID = "";
538
						$firstprint = false;
539
						if ($timerange) {
540
							$dayFriendly = "";
541
							$tempFriendlyTime = "";
542

    
543
							//get hours
544
							$temptimerange = $timerange['hour'];
545
							$temptimeseparator = strrpos($temptimerange, "-");
546

    
547
							$starttime = substr ($temptimerange, 0, $temptimeseparator);
548
							$stoptime = substr ($temptimerange, $temptimeseparator+1);
549

    
550
							if ($timerange['month']) {
551
								$tempmontharray = explode(",", $timerange['month']);
552
								$tempdayarray = explode(",", $timerange['day']);
553
								$arraycounter = 0;
554
								$firstDayFound = false;
555
								$firstPrint = false;
556
								foreach ($tempmontharray as $monthtmp) {
557
									$month = $tempmontharray[$arraycounter];
558
									$day = $tempdayarray[$arraycounter];
559

    
560
									if (!$firstDayFound) {
561
										$firstDay = $day;
562
										$firstmonth = $month;
563
										$firstDayFound = true;
564
									}
565

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

    
679
		if (isset($filterent['protocol'])) {
680
			echo strtoupper($filterent['protocol']);
681

    
682
			if (strtoupper($filterent['protocol']) == "ICMP" && !empty($filterent['icmptype'])) {
683
				echo ' <span style="cursor: help;" title="' . gettext('ICMP type') . ': ' .
684
					($filterent['ipprotocol'] == "inet6" ? $icmp6types[$filterent['icmptype']] : $icmptypes[$filterent['icmptype']]) .
685
					'"><u>';
686
				echo $filterent['icmptype'];
687
				echo '</u></span>';
688
			}
689
		} else echo "*";
690

    
691
	?>
692
						</td>
693
						<td>
694
							<?php if (isset($alias['src'])): ?>
695
								<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">
696
									<?=str_replace('_', ' ', htmlspecialchars(pprint_address($filterent['source'])))?>
697
								</a>
698
							<?php else: ?>
699
								<?=htmlspecialchars(pprint_address($filterent['source']))?>
700
							<?php endif; ?>
701
						</td>
702
						<td>
703
							<?php if (isset($alias['srcport'])): ?>
704
								<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">
705
									<?=str_replace('_', ' ', htmlspecialchars(pprint_port($filterent['source']['port'])))?>
706
								</a>
707
							<?php else: ?>
708
								<?=htmlspecialchars(pprint_port($filterent['source']['port']))?>
709
							<?php endif; ?>
710
						</td>
711
						<td>
712
							<?php if (isset($alias['dst'])): ?>
713
								<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">
714
									<?=str_replace('_', ' ', htmlspecialchars(pprint_address($filterent['destination'])))?>
715
								</a>
716
							<?php else: ?>
717
								<?=htmlspecialchars(pprint_address($filterent['destination']))?>
718
							<?php endif; ?>
719
						</td>
720
						<td>
721
							<?php if (isset($alias['dstport'])): ?>
722
								<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">
723
									<?=str_replace('_', ' ', htmlspecialchars(pprint_port($filterent['destination']['port'])))?>
724
								</a>
725
							<?php else: ?>
726
								<?=htmlspecialchars(pprint_port($filterent['destination']['port']))?>
727
							<?php endif; ?>
728
						</td>
729
						<td>
730
							<?php if (isset($config['interfaces'][$filterent['gateway']]['descr'])):?>
731
								<?=str_replace('_', ' ', htmlspecialchars($config['interfaces'][$filterent['gateway']]['descr']))?>
732
							<?php else: ?>
733
								<?=htmlspecialchars(pprint_port($filterent['gateway']))?>
734
							<?php endif; ?>
735
						</td>
736
						<td>
737
							<?php
738
								if (isset($filterent['ackqueue']) && isset($filterent['defaultqueue'])) {
739
									$desc = str_replace('_', ' ', $filterent['ackqueue']);
740
									echo "<a href=\"firewall_shaper_queues.php?queue={$filterent['ackqueue']}&amp;action=show\">{$desc}</a>";
741
									$desc = str_replace('_', ' ', $filterent['defaultqueue']);
742
									echo "/<a href=\"firewall_shaper_queues.php?queue={$filterent['defaultqueue']}&amp;action=show\">{$desc}</a>";
743
								} else if (isset($filterent['defaultqueue'])) {
744
									$desc = str_replace('_', ' ', $filterent['defaultqueue']);
745
									echo "<a href=\"firewall_shaper_queues.php?queue={$filterent['defaultqueue']}&amp;action=show\">{$desc}</a>";
746
								} else {
747
									echo gettext("none");
748
								}
749
							?>
750
						</td>
751
						<td>
752
							<?php if ($printicon) { ?>
753
								<i class="fa fa-<?=$image?> <?=$dispcolor?>" title="<?=$alttext;?>"></i>
754
							<?php } ?>
755
							<?=$schedule_span_begin;?><?=str_replace('_', ' ', htmlspecialchars($filterent['sched']));?>&nbsp;<?=$schedule_span_end;?>
756
						</td>
757
						<td>
758
							<?=htmlspecialchars($filterent['descr']);?>
759
						</td>
760
						<td class="action-icons">
761
						<!-- <?=(isset($filterent['disabled']) ? 'enable' : 'disable')?> -->
762
							<a	class="fa fa-anchor icon-pointer" id="Xmove_<?=$filteri?>" title="<?=$XmoveTitle?>"></a>
763
							<a href="firewall_rules_edit.php?id=<?=$filteri;?>" class="fa fa-pencil" title="<?=gettext('Edit')?>"></a>
764
							<a href="firewall_rules_edit.php?dup=<?=$filteri;?>" class="fa fa-clone" title="<?=gettext('Copy')?>"></a>
765
<?php if (isset($filterent['disabled'])) {
766
?>
767
							<a href="?act=toggle&amp;if=<?=htmlspecialchars($if);?>&amp;id=<?=$filteri;?>" class="fa fa-check-square-o" title="<?=gettext('Enable')?>"></a>
768
<?php } else {
769
?>
770
							<a href="?act=toggle&amp;if=<?=htmlspecialchars($if);?>&amp;id=<?=$filteri;?>" class="fa fa-ban" title="<?=gettext('Disable')?>"></a>
771
<?php }
772
?>
773
							<a href="?act=del&amp;if=<?=htmlspecialchars($if);?>&amp;id=<?=$filteri;?>" class="fa fa-trash" title="<?=gettext('Delete this rule')?>"></a>
774
						</td>
775
					</tr>
776
<?php
777
		$nrules++;
778
	}
779
endforeach;
780

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

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

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

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

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

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

    
865
<script type="text/javascript">
866
//<![CDATA[
867

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

    
875
events.push(function() {
876

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

    
880
		// Prevent click from toggling row
881
		event.stopImmediatePropagation();
882

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

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

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

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

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

    
923
		$(this).css("cursor", "default");
924

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

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

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

    
948
	$('table tbody.user-entries').sortable({
949
		cursor: 'grabbing',
950
		update: function(event, ui) {
951
			$('#order-store').removeAttr('disabled');
952
			reindex_rules(ui.item.parent('tbody'));
953
			dirty = true;
954
		}
955
	});
956

    
957
	$('table tbody.user-entries').show();
958

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

    
963
		// Save the separator bar configuration
964
		save_separators();
965

    
966
		// Suppress the "Do you really want to leave the page" message
967
		saving = true;
968
	});
969

    
970
	// Provide a warning message if the user tries to change page before saving
971
	$(window).bind('beforeunload', function(){
972
		if ((!saving && dirty) || newSeperator) {
973
			return ("<?=gettext('One or more rules have been moved but have not yet been saved')?>");
974
		} else {
975
			return undefined;
976
		}
977
	});
978

    
979
	$(document).on('keyup keydown', function(e){
980
		if (e.shiftKey) {
981
			$('[id^=Xmove_]').attr("title", "<?=$ShXmoveTitle?>");
982
		} else {
983
			$('[id^=Xmove_]').attr("title", "<?=$XmoveTitle?>");
984
		}
985
	});
986
});
987
//]]>
988
</script>
989

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