Project

General

Profile

Download (32.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-2016 Rubicon Communications, LLC (Netgate)
7
 * All rights reserved.
8
 *
9
 * originally based on m0n0wall (http://m0n0.ch/wall)
10
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
11
 * All rights reserved.
12
 *
13
 * 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 ($if != "any" && $if != "FloatingRules" && isset($iflist['wan'])) {
167
		$if = "wan";
168
	} else {
169
		$if = "FloatingRules";
170
	}
171
}
172

    
173
if ($_POST) {
174
	$pconfig = $_POST;
175

    
176
	if ($_POST['apply']) {
177
		$retval = 0;
178
		$retval = filter_configure();
179

    
180
		clear_subsystem_dirty('filter');
181

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

    
187
if ($_GET['act'] == "del") {
188
	if ($a_filter[$_GET['id']]) {
189
		if (!empty($a_filter[$_GET['id']]['associated-rule-id'])) {
190
			delete_nat_association($a_filter[$_GET['id']]['associated-rule-id']);
191
		}
192
		unset($a_filter[$_GET['id']]);
193

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

    
200
		if (write_config()) {
201
			mark_subsystem_dirty('filter');
202
		}
203

    
204
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
205
		exit;
206
	}
207
}
208

    
209
// Handle save msg if defined
210
if ($_REQUEST['savemsg']) {
211
	$savemsg = htmlentities($_REQUEST['savemsg']);
212
}
213

    
214
if (isset($_POST['del_x'])) {
215
	/* delete selected rules */
216
	$deleted = false;
217

    
218
	if (is_array($_POST['rule']) && count($_POST['rule'])) {
219
		$a_separators = &$config['filter']['separator'][strtolower($if)];
220
		$num_deleted = 0;
221

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

    
227
			// Update the separators
228
			// As rules are deleted, $ridx has to be decremented or separator position will break
229
			$ridx = ifridx($if, $rulei) - $num_deleted;	// get rule index within interface
230
			$mvnrows = -1;
231
			move_separators($a_separators, $ridx, $mvnrows);
232
			$num_deleted++;
233
		}
234

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

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

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

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

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

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

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

    
291
		$a_filter = $a_filter_new;
292

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

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

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

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

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

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

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

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

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

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

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

    
338
display_top_tabs($tab_array);
339

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
874
events.push(function() {
875

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
989
<?php include("foot.inc");?>
(47-47/226)