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 ("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
		$num_deleted = 0;
225

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

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

    
239
		if ($deleted) {
240
			if (write_config()) {
241
				mark_subsystem_dirty('filter');
242
			}
243
		}
244

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

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

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

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

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

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

    
295
		$a_filter = $a_filter_new;
296

    
297
		$config['filter']['separator'][strtolower($if)] = "";
298

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

    
306
		if (write_config()) {
307
			mark_subsystem_dirty('filter');
308
		}
309

    
310
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
311
		exit;
312
	}
313
}
314

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

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

    
321
foreach ($tab_array as $dtab) {
322
	if ($dtab[1]) {
323
		$bctab = $dtab[0];
324
		break;
325
	}
326
}
327

    
328
$pgtitle = array(gettext("Firewall"), gettext("Rules"), $bctab);
329
$shortcut_section = "firewall";
330

    
331
include("head.inc");
332
$nrules = 0;
333

    
334
if ($savemsg) {
335
	print_info_box($savemsg, 'success');
336
}
337

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

    
342
display_top_tabs($tab_array);
343

    
344
$showantilockout = false;
345
$showprivate = false;
346
$showblockbogons = false;
347

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

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

    
358
if (isset($config['interfaces'][$if]['blockbogons'])) {
359
	$showblockbogons = true;
360
}
361

    
362
/* Load the counter data of each pf rule. */
363
$rulescnt = pfSense_get_pf_rules();
364

    
365
// Update this if you add or remove columns!
366
$columns_in_table = 13;
367

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

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

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

    
467
foreach ($a_filter as $filteri => $filterent):
468

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

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

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

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

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

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

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

    
546
							//get hours
547
							$temptimerange = $timerange['hour'];
548
							$temptimeseparator = strrpos($temptimerange, "-");
549

    
550
							$starttime = substr ($temptimerange, 0, $temptimeseparator);
551
							$stoptime = substr ($temptimerange, $temptimeseparator+1);
552

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

    
563
									if (!$firstDayFound) {
564
										$firstDay = $day;
565
										$firstmonth = $month;
566
										$firstDayFound = true;
567
									}
568

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

    
682
		if (isset($filterent['protocol'])) {
683
			echo strtoupper($filterent['protocol']);
684

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

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

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

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

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

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

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

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

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

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

    
878
events.push(function() {
879

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

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

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

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

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

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

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

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

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

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

    
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
		update: function(event, ui) {
954
			$('#order-store').removeAttr('disabled');
955
			reindex_rules(ui.item.parent('tbody'));
956
			dirty = true;
957
		}
958
	});
959

    
960
	$('table tbody.user-entries').show();
961

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

    
966
		// Save the separator bar configuration
967
		save_separators();
968

    
969
		// Suppress the "Do you really want to leave the page" message
970
		saving = true;
971
	});
972

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

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

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