Project

General

Profile

Download (42.3 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-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8
 * Copyright (c) 2014-2022 Rubicon Communications, LLC (Netgate)
9
 * All rights reserved.
10
 *
11
 * originally based on m0n0wall (http://m0n0.ch/wall)
12
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
13
 * All rights reserved.
14
 *
15
 * Licensed under the Apache License, Version 2.0 (the "License");
16
 * you may not use this file except in compliance with the License.
17
 * You may obtain a copy of the License at
18
 *
19
 * http://www.apache.org/licenses/LICENSE-2.0
20
 *
21
 * Unless required by applicable law or agreed to in writing, software
22
 * distributed under the License is distributed on an "AS IS" BASIS,
23
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
 * See the License for the specific language governing permissions and
25
 * limitations under the License.
26
 */
27

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

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

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

    
44
$shortcut_section = "firewall";
45

    
46
function get_pf_rules($rules, $tracker_start, $tracker_end) {
47

    
48
	if ($rules == NULL || !is_array($rules)) {
49
		return (NULL);
50
	}
51

    
52
	$arr = array();
53
	foreach ($rules as $rule) {
54
		if ($rule['tracker'] >= $tracker_start &&
55
		    $rule['tracker'] <= $tracker_end) {
56
			$arr[] = $rule;
57
		}
58
	}
59

    
60
	if (count($arr) == 0)
61
		return (NULL);
62

    
63
	return ($arr);
64
}
65

    
66
function print_states($tracker_start, $tracker_end = -1) {
67
	global $rulescnt;
68

    
69
	if (empty($tracker_start)) {
70
		return;
71
	}
72

    
73
	if ($tracker_end === -1) {
74
		$tracker_end = $tracker_start;
75
	} elseif ($tracker_end < $tracker_start) {
76
		return;
77
	}
78

    
79
	$rulesid = "";
80
	$bytes = 0;
81
	$states = 0;
82
	$packets = 0;
83
	$evaluations = 0;
84
	$stcreations = 0;
85
	$rules = get_pf_rules($rulescnt, $tracker_start, $tracker_end);
86
	if (is_array($rules)) {
87
		foreach ($rules as $rule) {
88
			$bytes += $rule['bytes'];
89
			$states += $rule['states'];
90
			$packets += $rule['packets'];
91
			$evaluations += $rule['evaluations'];
92
			$stcreations += $rule['state creations'];
93
			if (strlen($rulesid) > 0) {
94
				$rulesid .= ",";
95
			}
96
			$rulesid .= "{$rule['id']}";
97
		}
98
	}
99

    
100
	$trackertext = "Tracking ID: {$tracker_start}";
101
	if ($tracker_end != $tracker_start) {
102
		$trackertext .= '-' . $tracker_end;
103
	}
104
	$trackertext .= "<br />";
105

    
106
	printf("<a href=\"diag_dump_states.php?ruleid=%s\" " .
107
	    "data-toggle=\"popover\" data-trigger=\"hover focus\" " .
108
	    "title=\"%s\" ", $rulesid, gettext("States details"));
109
	printf("data-content=\"{$trackertext}evaluations: %s<br />packets: " .
110
	    "%s<br />bytes: %s<br />states: %s<br />state creations: " .
111
	    "%s\" data-html=\"true\" usepost>",
112
	    format_number($evaluations), format_number($packets),
113
	    format_bytes($bytes), format_number($states),
114
	    format_number($stcreations));
115
	printf("%s/%s</a><br />", format_number($states), format_bytes($bytes));
116
}
117

    
118
function delete_nat_association($id) {
119
	global $config;
120

    
121
	if (!$id || !is_array($config['nat']['rule'])) {
122
		return;
123
	}
124

    
125
	$a_nat = &$config['nat']['rule'];
126

    
127
	foreach ($a_nat as &$natent) {
128
		if ($natent['associated-rule-id'] == $id) {
129
			$natent['associated-rule-id'] = '';
130
		}
131
	}
132
}
133

    
134
init_config_arr(array('filter', 'rule'));
135
filter_rules_sort();
136
$a_filter = &$config['filter']['rule'];
137

    
138
if ($_REQUEST['if']) {
139
	$if = $_REQUEST['if'];
140
}
141

    
142
$ifdescs = get_configured_interface_with_descr();
143

    
144
$iflist = filter_get_interface_list();
145

    
146
if (!$if || !isset($iflist[$if])) {
147
	if ($if != "any" && $if != "FloatingRules" && isset($iflist['wan'])) {
148
		$if = "wan";
149
	} else {
150
		$if = "FloatingRules";
151
	}
152
}
153

    
154
if ($_POST['apply']) {
155
	$retval = 0;
156
	$retval |= filter_configure();
157

    
158
	clear_subsystem_dirty('filter');
159
}
160

    
161
if ($_POST['act'] == "del") {
162
	if ($a_filter[$_POST['id']]) {
163
		if (!empty($a_filter[$_POST['id']]['associated-rule-id'])) {
164
			delete_nat_association($a_filter[$_POST['id']]['associated-rule-id']);
165
		}
166
		unset($a_filter[$_POST['id']]);
167

    
168
		// Update the separators
169
		init_config_arr(array('filter', 'separator', strtolower($if)));
170
		$a_separators = &$config['filter']['separator'][strtolower($if)];
171
		$ridx = ifridx($if, $_POST['id']);	// get rule index within interface
172
		$mvnrows = -1;
173
		move_separators($a_separators, $ridx, $mvnrows);
174

    
175
		if (write_config(gettext("Firewall: Rules - deleted a firewall rule."))) {
176
			mark_subsystem_dirty('filter');
177
		}
178

    
179
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
180
		exit;
181
	}
182
}
183

    
184
if (($_POST['act'] == 'killid') &&
185
    (!empty($_POST['tracker'])) &&
186
    (!empty($if))) {
187
	mwexec("/sbin/pfctl -k label -k " . escapeshellarg("id:{$_POST['tracker']}"));
188
	header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
189
	exit;
190
}
191

    
192
// Handle save msg if defined
193
if ($_REQUEST['savemsg']) {
194
	$savemsg = htmlentities($_REQUEST['savemsg']);
195
}
196

    
197
if (isset($_POST['del_x'])) {
198
	if (is_array($_POST['rule']) && count($_POST['rule'])) {
199
		init_config_arr(array('filter', 'separator', strtolower($if)));
200
		$a_separators = &$config['filter']['separator'][strtolower($if)];
201

    
202
		$num_deleted = 0;
203

    
204
		foreach ($_POST['rule'] as $rulei) {
205
			delete_nat_association($a_filter[$rulei]['associated-rule-id']);
206
			unset($a_filter[$rulei]);
207

    
208
			// Update the separators
209
			// As rules are deleted, $ridx has to be decremented or separator position will break
210
			if (count($_POST['rule']) == 1) { // Need special handling of single rule deletion
211
				$ridx = ifridx($if, $rulei);
212
			} else {
213
				$ridx = ifridx($if, $rulei) - $num_deleted + 1;
214
			}
215

    
216
			$mvnrows = -1;
217
			move_separators($a_separators, $ridx, $mvnrows);
218

    
219
			$num_deleted++;
220
		}
221

    
222
		if ($num_deleted) {
223
			if (write_config(gettext("Firewall: Rules - deleted selected firewall rules."))) {
224
				mark_subsystem_dirty('filter');
225
			}
226
		}
227

    
228
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
229
		exit;
230
	}
231
} elseif (isset($_POST['toggle_x'])) {
232
	if (is_array($_POST['rule']) && count($_POST['rule'])) {
233
		foreach ($_POST['rule'] as $rulei) {
234
			if (isset($a_filter[$rulei]['disabled'])) {
235
				unset($a_filter[$rulei]['disabled']);
236
			} else {
237
				$a_filter[$rulei]['disabled'] = true;
238
			}
239
		}
240
		if (write_config(gettext("Firewall: Rules - toggle selected firewall rules."))) {
241
			mark_subsystem_dirty('filter');
242
		}
243

    
244
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
245
		exit;
246
	}
247
} else if ($_POST['act'] == "toggle") {
248
	if ($a_filter[$_POST['id']]) {
249
		if (isset($a_filter[$_POST['id']]['disabled'])) {
250
			unset($a_filter[$_POST['id']]['disabled']);
251
			$wc_msg = gettext('Firewall: Rules - enabled a firewall rule.');
252
		} else {
253
			$a_filter[$_POST['id']]['disabled'] = true;
254
			$wc_msg = gettext('Firewall: Rules - disabled a firewall rule.');
255
		}
256
		if (write_config($wc_msg)) {
257
			mark_subsystem_dirty('filter');
258
		}
259

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

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

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

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

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

    
298
		if ($a_filter !== $a_filter_new) {
299
			$a_filter = $a_filter_new;
300
			$dirty = true;
301
		}
302
	}
303

    
304
	$a_separators = &$config['filter']['separator'][strtolower($if)];
305

    
306
	/* update separator order, POST[separator] is an array of ordered IDs */
307
	if (is_array($_POST['separator']) && !empty($_POST['separator'])) {
308
		$new_separator = array();
309
		$idx = 0;
310

    
311
		foreach ($_POST['separator'] as $separator) {
312
			$new_separator['sep' . $idx++] = $separator;
313
		}
314

    
315
		if ($a_separators !== $new_separator) {
316
			$a_separators = $new_separator;
317
			$updated = true;
318
		}
319
	} else if (!empty($a_separators)) {
320
		$a_separators = "";
321
		$updated = true;
322
	}
323

    
324
	if ($updated || $dirty) {
325
		if (write_config(gettext("Firewall: Rules - reordered firewall rules."))) {
326
			if ($dirty) {
327
				mark_subsystem_dirty('filter');
328
			}
329
		}
330
	}
331

    
332
	header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
333
	exit;
334
} elseif (isset($_POST['dstif']) && !empty($_POST['dstif']) &&
335
    isset($iflist[$_POST['dstif']]) && have_ruleint_access($_POST['dstif']) && 
336
    is_array($_POST['rule']) && count($_POST['rule'])) {
337
    	$confiflist = get_configured_interface_list();
338
	foreach ($_POST['rule'] as $rulei) {
339
		$filterent = $a_filter[$rulei];
340
		$filterent['tracker'] = (int)microtime(true);
341
		$filterent['interface'] = $_POST['dstif'];
342
		if ($_POST['convertif'] && ($if != $_POST['dstif']) &&
343
		    in_array($_POST['dstif'], $confiflist)) {
344
			if (isset($filterent['source']['network']) &&
345
			    ($filterent['source']['network'] == $if)) {
346
				$filterent['source']['network'] = $_POST['dstif'];
347
			}
348
			if (isset($filterent['destination']['network']) &&
349
			    ($filterent['destination']['network'] == $if)) {
350
				$filterent['destination']['network'] = $_POST['dstif'];
351
			}
352
			if (isset($filterent['source']['network']) &&
353
			    ($filterent['source']['network'] == ($if . 'ip'))) {
354
				$filterent['source']['network'] = $_POST['dstif'] . $ip;
355
			}
356
			if (isset($filterent['destination']['network']) &&
357
			    ($filterent['destination']['network'] == ($if . 'ip'))) {
358
				$filterent['destination']['network'] = $_POST['dstif'] . $ip;
359
			}
360
		}
361
		$a_filter[] = $filterent;
362
	}
363
	if (write_config(gettext("Firewall: Rules - copying selected firewall rules."))) {
364
		mark_subsystem_dirty('filter');
365
	}
366

    
367
	header("Location: firewall_rules.php?if=" . htmlspecialchars($_POST['dstif']));
368
	exit;
369
}
370

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

    
373
foreach ($iflist as $ifent => $ifname) {
374
	$tab_array[] = array($ifname, ($ifent == $if), "firewall_rules.php?if={$ifent}");
375
}
376

    
377
foreach ($tab_array as $dtab) {
378
	if ($dtab[1]) {
379
		$bctab = $dtab[0];
380
		break;
381
	}
382
}
383

    
384
$pgtitle = array(gettext("Firewall"), gettext("Rules"), $bctab);
385
$pglinks = array("", "firewall_rules.php", "@self");
386
$shortcut_section = "firewall";
387

    
388
include("head.inc");
389
$nrules = 0;
390

    
391
if ($savemsg) {
392
	print_info_box($savemsg, 'success');
393
}
394

    
395
if ($_POST['apply']) {
396
	print_apply_result_box($retval);
397
}
398

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

    
403
display_top_tabs($tab_array, false, 'pills');
404

    
405
$showantilockout = false;
406
$showprivate = false;
407
$showblockbogons = false;
408

    
409
if (!isset($config['system']['webgui']['noantilockout']) &&
410
    (((count($config['interfaces']) > 1) && ($if == 'lan')) ||
411
    ((count($config['interfaces']) == 1) && ($if == 'wan')))) {
412
	$showantilockout = true;
413
}
414

    
415
if (isset($config['interfaces'][$if]['blockpriv'])) {
416
	$showprivate = true;
417
}
418

    
419
if (isset($config['interfaces'][$if]['blockbogons'])) {
420
	$showblockbogons = true;
421
}
422

    
423
if (isset($config['system']['webgui']['roworderdragging'])) {
424
	$rules_header_text = gettext("Rules");
425
} else {
426
	$rules_header_text = gettext("Rules (Drag to Change Order)");
427
}
428

    
429
/* Load the counter data of each pf rule. */
430
$rulescnt = pfSense_get_pf_rules();
431

    
432
// Update this if you add or remove columns!
433
$columns_in_table = 13;
434

    
435
/* Floating rules tab has one extra column
436
 * https://redmine.pfsense.org/issues/10667 */
437
if ($if == "FloatingRules") {
438
	$columns_in_table++;
439
}
440

    
441
?>
442
<!-- Allow table to scroll when dragging outside of the display window -->
443
<style>
444
.table-responsive {
445
    clear: both;
446
    overflow-x: visible;
447
    margin-bottom: 0px;
448
}
449
</style>
450

    
451
<form id="mainform" method="post">
452
	<input name="if" id="if" type="hidden" value="<?=$if?>" />
453
	<input name="dstif" id="dstif" type="hidden" value="" />
454
	<input name="convertif" id="convertif" type="hidden" value="" />
455
	<div class="panel panel-default">
456
		<div class="panel-heading"><h2 class="panel-title"><?=$rules_header_text?></h2></div>
457
		<div id="mainarea" class="table-responsive panel-body">
458
			<table id="ruletable" class="table table-hover table-striped table-condensed" style="overflow-x: 'visible'">
459
				<thead>
460
					<tr>
461
						<th><input type="checkbox" id="selectAll" name="selectAll" /></th>
462
						<th><!-- status icons --></th>
463
						<th><?=gettext("States")?></th>
464
				<?php
465
					if ('FloatingRules' == $if) {
466
				?>
467
						<th><?=gettext("Interfaces")?></th>
468
				<?php
469
					}
470
				?>
471
						<th><?=gettext("Protocol")?></th>
472
						<th><?=gettext("Source")?></th>
473
						<th><?=gettext("Port")?></th>
474
						<th><?=gettext("Destination")?></th>
475
						<th><?=gettext("Port")?></th>
476
						<th><?=gettext("Gateway")?></th>
477
						<th><?=gettext("Queue")?></th>
478
						<th><?=gettext("Schedule")?></th>
479
						<th><?=gettext("Description")?></th>
480
						<th><?=gettext("Actions")?></th>
481
					</tr>
482
				</thead>
483

    
484
<?php if ($showblockbogons || $showantilockout || $showprivate) :
485
?>
486
				<tbody>
487
<?php
488
		// 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.
489
		if ($showantilockout):
490
			$alports = implode('<br />', filter_get_antilockout_ports(true));
491
?>
492
					<tr id="antilockout">
493
						<td></td>
494
						<td title="<?=gettext("traffic is passed")?>"><i class="fa fa-check text-success"></i></td>
495
						<td><?php print_states(intval(ANTILOCKOUT_TRACKER_START), intval(ANTILOCKOUT_TRACKER_END)); ?></td>
496
						<td>*</td>
497
						<td>*</td>
498
						<td>*</td>
499
						<td><?=$iflist[$if];?> Address</td>
500
						<td><?=$alports?></td>
501
						<td>*</td>
502
						<td>*</td>
503
						<td></td>
504
						<td><?=gettext("Anti-Lockout Rule");?></td>
505
						<td>
506
							<a href="system_advanced_admin.php" title="<?=gettext("Settings");?>"><i class="fa fa-cog"></i></a>
507
						</td>
508
					</tr>
509
<?php 	endif;?>
510
<?php 	if ($showprivate): ?>
511
					<tr id="private">
512
						<td></td>
513
						<td title="<?=gettext("traffic is blocked")?>"><i class="fa fa-times text-danger"></i></td>
514
						<td><?php print_states(intval(RFC1918_TRACKER_START), intval(RFC1918_TRACKER_END)); ?></td>
515
						<td>*</td>
516
						<td><?=gettext("RFC 1918 networks");?></td>
517
						<td>*</td>
518
						<td>*</td>
519
						<td>*</td>
520
						<td>*</td>
521
						<td>*</td>
522
						<td></td>
523
						<td><?=gettext("Block private networks");?></td>
524
						<td>
525
							<a href="interfaces.php?if=<?=htmlspecialchars($if)?>" title="<?=gettext("Settings");?>" usepost><i class="fa fa-cog"></i></a>
526
						</td>
527
					</tr>
528
<?php 	endif;?>
529
<?php 	if ($showblockbogons): ?>
530
					<tr id="bogons">
531
						<td></td>
532
						<td title="<?=gettext("traffic is blocked")?>"><i class="fa fa-times text-danger"></i></td>
533
						<td><?php print_states(intval(BOGONS_TRACKER_START), intval(BOGONS_TRACKER_END)); ?></td>
534
						<td>*</td>
535
						<td><?=sprintf(gettext("Reserved%sNot assigned by IANA"), "<br />");?></td>
536
						<td>*</td>
537
						<td>*</td>
538
						<td>*</td>
539
						<td>*</td>
540
						<td>*</td>
541
						<td></td>
542
						<td><?=gettext("Block bogon networks");?></td>
543
						<td>
544
							<a href="interfaces.php?if=<?=htmlspecialchars($if)?>" title="<?=gettext("Settings");?>" usepost><i class="fa fa-cog"></i></a>
545
						</td>
546
					</tr>
547
<?php 	endif;?>
548
			</tbody>
549
<?php endif;?>
550
			<tbody class="user-entries">
551
<?php
552
$nrules = 0;
553
$separators = $config['filter']['separator'][strtolower($if)];
554

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

    
559
/* Cache gateway status for this page load.
560
 * See https://redmine.pfsense.org/issues/12174 */
561
$gateways_status = return_gateways_status(true);
562

    
563
foreach ($a_filter as $filteri => $filterent):
564

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

    
567
		// Display separator(s) for section beginning at rule n
568
		if ($seprows[$nrules]) {
569
			display_separator($separators, $nrules, $columns_in_table);
570
		}
571
?>
572
					<tr id="fr<?=$nrules;?>" onClick="fr_toggle(<?=$nrules;?>)" ondblclick="document.location='firewall_rules_edit.php?id=<?=$filteri;?>';" <?=(isset($filterent['disabled']) ? ' class="disabled"' : '')?>>
573
						<td>
574
							<input type="checkbox" id="frc<?=$nrules;?>" onClick="fr_toggle(<?=$nrules;?>)" name="rule[]" value="<?=$filteri;?>"/>
575
						</td>
576

    
577
	<?php
578
		if ($filterent['type'] == "block") {
579
			$iconfn = "times text-danger";
580
			$title_text = gettext("traffic is blocked");
581
		} else if ($filterent['type'] == "reject") {
582
			$iconfn = "hand-stop-o text-warning";
583
			$title_text = gettext("traffic is rejected");
584
		} else if ($filterent['type'] == "match") {
585
			$iconfn = "filter";
586
			$title_text = gettext("traffic is matched");
587
		} else {
588
			$iconfn = "check text-success";
589
			$title_text = gettext("traffic is passed");
590
		}
591
	?>
592
						<td title="<?=$title_text?>">
593
							<a href="?if=<?=htmlspecialchars($if);?>&amp;act=toggle&amp;id=<?=$filteri;?>" usepost>
594
								<i class="fa fa-<?=$iconfn?>" title="<?=gettext("click to toggle enabled/disabled status");?>"></i>
595
							</a>
596
	<?php
597
		if ($filterent['quick'] == 'yes') {
598
			print '<i class="fa fa-forward text-success" title="'. gettext("&quot;Quick&quot; rule. Applied immediately on match.") .'" style="cursor: pointer;"></i>';
599
		}
600

    
601
		$isadvset = firewall_check_for_advanced_options($filterent);
602
		if ($isadvset) {
603
			print '<i class="fa fa-cog" title="'. gettext("advanced setting") .': '. $isadvset .'" style="cursor: pointer;"></i>';
604
		}
605

    
606
		if (isset($filterent['log'])) {
607
			print '<i class="fa fa-tasks" title="'. gettext("traffic is logged") .'" style="cursor: pointer;"></i>';
608
		}
609

    
610
		if (isset($filterent['direction']) && ($if == "FloatingRules")) {
611
			if ($filterent['direction'] == 'in') {
612
				print '<i class="fa fa-arrow-circle-o-left" title="'. gettext("direction is in") .'" style="cursor: pointer;"></i>';
613
			} elseif ($filterent['direction'] == 'out') {
614
				print '<i class="fa fa-arrow-circle-o-right" title="'. gettext("direction is out") .'" style="cursor: pointer;"></i>';
615
			}
616
		}
617
	?>
618
						</td>
619
	<?php
620
		$alias = rule_columns_with_alias(
621
			$filterent['source']['address'],
622
			pprint_port($filterent['source']['port']),
623
			$filterent['destination']['address'],
624
			pprint_port($filterent['destination']['port'])
625
		);
626

    
627
		//build Schedule popup box
628
		init_config_arr(array('schedules', 'schedule'));
629
		$a_schedules = &$config['schedules']['schedule'];
630
		$schedule_span_begin = "";
631
		$schedule_span_end = "";
632
		$sched_caption_escaped = "";
633
		$sched_content = "";
634
		$schedstatus = false;
635
		$dayArray = array (gettext('Mon'), gettext('Tues'), gettext('Wed'), gettext('Thur'), gettext('Fri'), gettext('Sat'), gettext('Sun'));
636
		$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'));
637
		if ($config['schedules']['schedule'] != "" && is_array($config['schedules']['schedule'])) {
638
			$idx = 0;
639
			foreach ($a_schedules as $schedule) {
640
				if (!empty($schedule['name']) &&
641
				    $schedule['name'] == $filterent['sched']) {
642
					$schedstatus = filter_get_time_based_rule_status($schedule);
643

    
644
					foreach ($schedule['timerange'] as $timerange) {
645
						$tempFriendlyTime = "";
646
						$tempID = "";
647
						$firstprint = false;
648
						if ($timerange) {
649
							$dayFriendly = "";
650
							$tempFriendlyTime = "";
651

    
652
							//get hours
653
							$temptimerange = $timerange['hour'];
654
							$temptimeseparator = strrpos($temptimerange, "-");
655

    
656
							$starttime = substr ($temptimerange, 0, $temptimeseparator);
657
							$stoptime = substr ($temptimerange, $temptimeseparator+1);
658

    
659
							if ($timerange['month']) {
660
								$tempmontharray = explode(",", $timerange['month']);
661
								$tempdayarray = explode(",", $timerange['day']);
662
								$arraycounter = 0;
663
								$firstDayFound = false;
664
								$firstPrint = false;
665
								foreach ($tempmontharray as $monthtmp) {
666
									$month = $tempmontharray[$arraycounter];
667
									$day = $tempdayarray[$arraycounter];
668

    
669
									if (!$firstDayFound) {
670
										$firstDay = $day;
671
										$firstmonth = $month;
672
										$firstDayFound = true;
673
									}
674

    
675
									$currentDay = $day;
676
									$nextDay = $tempdayarray[$arraycounter+1];
677
									$currentDay++;
678
									if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])) {
679
										if ($firstPrint) {
680
											$dayFriendly .= ", ";
681
										}
682
										$currentDay--;
683
										if ($currentDay != $firstDay) {
684
											$dayFriendly .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
685
										} else {
686
											$dayFriendly .=	 $monthArray[$month-1] . " " . $day;
687
										}
688
										$firstDayFound = false;
689
										$firstPrint = true;
690
									}
691
									$arraycounter++;
692
								}
693
							} else {
694
								$tempdayFriendly = $timerange['position'];
695
								$firstDayFound = false;
696
								$tempFriendlyDayArray = explode(",", $tempdayFriendly);
697
								$currentDay = "";
698
								$firstDay = "";
699
								$nextDay = "";
700
								$counter = 0;
701
								foreach ($tempFriendlyDayArray as $day) {
702
									if ($day != "") {
703
										if (!$firstDayFound) {
704
											$firstDay = $tempFriendlyDayArray[$counter];
705
											$firstDayFound = true;
706
										}
707
										$currentDay =$tempFriendlyDayArray[$counter];
708
										//get next day
709
										$nextDay = $tempFriendlyDayArray[$counter+1];
710
										$currentDay++;
711
										if ($currentDay != $nextDay) {
712
											if ($firstprint) {
713
												$dayFriendly .= ", ";
714
											}
715
											$currentDay--;
716
											if ($currentDay != $firstDay) {
717
												$dayFriendly .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
718
											} else {
719
												$dayFriendly .= $dayArray[$firstDay-1];
720
											}
721
											$firstDayFound = false;
722
											$firstprint = true;
723
										}
724
										$counter++;
725
									}
726
								}
727
							}
728
							$timeFriendly = $starttime . " - " . $stoptime;
729
							$description = $timerange['rangedescr'];
730
							$sched_content .= $dayFriendly . "; " . $timeFriendly . "<br />";
731
						}
732
					}
733
					#FIXME
734
					$sched_caption_escaped = str_replace("'", "\'", $schedule['descr']);
735
					$schedule_span_begin = '<a href="/firewall_schedule_edit.php?id=' . $idx . '" data-toggle="popover" data-trigger="hover focus" title="' . $schedule['name'] . '" data-content="' .
736
						$sched_caption_escaped . '" data-html="true">';
737
					$schedule_span_end = "</a>";
738
				}
739
				$idx++;
740
			}
741
		}
742
		$printicon = false;
743
		$alttext = "";
744
		$image = "";
745
		if (!isset($filterent['disabled'])) {
746
			if ($schedstatus) {
747
				if ($filterent['type'] == "block" || $filterent['type'] == "reject") {
748
					$image = "times-circle";
749
					$dispcolor = "text-danger";
750
					$alttext = gettext("Traffic matching this rule is currently being denied");
751
				} else {
752
					$image = "play-circle";
753
					$dispcolor = "text-success";
754
					$alttext = gettext("Traffic matching this rule is currently being allowed");
755
				}
756
				$printicon = true;
757
			} else if ($filterent['sched']) {
758
				if ($filterent['type'] == "block" || $filterent['type'] == "reject") {
759
					$image = "times-circle";
760
				} else {
761
					$image = "play-circle";
762
				}
763
				$alttext = gettext("This rule is not currently active because its period has expired");
764
				$dispcolor = "text-warning";
765
				$printicon = true;
766
			}
767
		}
768
	?>
769
				<td><?php print_states(intval($filterent['tracker'])); ?></td>
770
	<?php
771
		if ($if == 'FloatingRules') {
772
	?>
773
			<td onclick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
774
	<?php
775
			if (isset($filterent['interface'])) {
776
				$selected_interfaces = explode(',', $filterent['interface']);
777
				unset($selected_descs);
778
				foreach ($selected_interfaces as $interface) {
779
					if (isset($ifdescs[$interface])) {
780
						$selected_descs[] = $ifdescs[$interface];
781
					} else {
782
						switch ($interface) {
783
						case 'l2tp':
784
							if ($config['l2tp']['mode'] == 'server')
785
								$selected_descs[] = 'L2TP VPN';
786
							break;
787
						case 'pppoe':
788
							if (is_pppoe_server_enabled())
789
								$selected_descs[] = 'PPPoE Server';
790
							break;
791
						case 'enc0':
792
							if (ipsec_enabled())
793
								$selected_descs[] = 'IPsec';
794
							break;
795
						case 'openvpn':
796
							if  ($config['openvpn']['openvpn-server'] || $config['openvpn']['openvpn-client'])
797
								$selected_descs[] = 'OpenVPN';
798
							break;
799
						case 'any':
800
							$selected_descs[] = 'Any';
801
							break;
802
						default:
803
							$selected_descs[] = $interface;
804
							break;
805
						}
806
					}
807
				}
808
				if (!empty($selected_descs)) {
809
					$desclist = '';
810
					$desclength = 0;
811
					foreach ($selected_descs as $descid => $desc) {
812
						$desclength += strlen($desc);
813
						if ($desclength > 18) {
814
							$desclist .= ',<br/>';
815
							$desclength = 0;
816
						} elseif ($desclist) {
817
							$desclist .= ', ';
818
							$desclength += 2;
819
						}
820
						$desclist .= $desc;
821
					}
822
					echo $desclist;
823
				}
824
			}
825
	?>
826
			</td>
827
	<?php
828
		}
829
	?>
830
			<td>
831
	<?php
832
		if (isset($filterent['ipprotocol'])) {
833
			switch ($filterent['ipprotocol']) {
834
				case "inet":
835
					echo "IPv4 ";
836
					break;
837
				case "inet6":
838
					echo "IPv6 ";
839
					break;
840
				case "inet46":
841
					echo "IPv4+6 ";
842
					break;
843
			}
844
		} else {
845
			echo "IPv4 ";
846
		}
847

    
848
		if (isset($filterent['protocol'])) {
849
			echo strtoupper($filterent['protocol']);
850

    
851
			if (strtoupper($filterent['protocol']) == "ICMP" && !empty($filterent['icmptype'])) {
852
				// replace each comma-separated icmptype item by its (localised) full description
853
				$t = 	implode(', ',
854
						array_map(
855
						        function($type) {
856
								global $icmptypes;
857
								return $icmptypes[$type]['descrip'];
858
							},
859
							explode(',', $filterent['icmptype'])
860
						)
861
					);
862
				echo sprintf('<br /><div style="cursor:help;padding:1px;line-height:1.1em;max-height:2.5em;max-width:180px;overflow-y:auto;overflow-x:hidden" title="%s:%s%s"><small><u>%s</u></small></div>', gettext('ICMP subtypes'), chr(13), $t, str_replace(',', '</u>, <u>',$filterent['icmptype']));
863
			}
864
		} else {
865
			echo " *";
866
		}
867
	?>
868
						</td>
869
						<td>
870
							<?php if (isset($alias['src'])): ?>
871
								<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">
872
									<?=str_replace('_', '_<wbr>', htmlspecialchars(pprint_address($filterent['source'])))?>
873
								</a>
874
							<?php else: ?>
875
								<?=htmlspecialchars(pprint_address($filterent['source']))?>
876
							<?php endif; ?>
877
						</td>
878
						<td>
879
							<?php if (isset($alias['srcport'])): ?>
880
								<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">
881
									<?=str_replace('_', '_<wbr>', htmlspecialchars(pprint_port($filterent['source']['port'])))?>
882
								</a>
883
							<?php else: ?>
884
								<?=htmlspecialchars(pprint_port($filterent['source']['port']))?>
885
							<?php endif; ?>
886
						</td>
887
						<td>
888
							<?php if (isset($alias['dst'])): ?>
889
								<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">
890
									<?=str_replace('_', '_<wbr>', htmlspecialchars(pprint_address($filterent['destination'])))?>
891
								</a>
892
							<?php else: ?>
893
								<?=htmlspecialchars(pprint_address($filterent['destination']))?>
894
							<?php endif; ?>
895
						</td>
896
						<td>
897
							<?php if (isset($alias['dstport'])): ?>
898
								<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">
899
									<?=str_replace('_', '_<wbr>', htmlspecialchars(pprint_port($filterent['destination']['port'])))?>
900
								</a>
901
							<?php else: ?>
902
								<?=htmlspecialchars(pprint_port($filterent['destination']['port']))?>
903
							<?php endif; ?>
904
						</td>
905
						<td>
906
							<?php if (isset($filterent['gateway'])): ?>
907
								<?php
908
									/* Cache gateway status for this page load.
909
									 * See https://redmine.pfsense.org/issues/12174 */
910
									if (!is_array($gw_info)) {
911
										$gw_info = array();
912
									}
913
									if (empty($gw_info[$filterent['gateway']])) {
914
										$gw_info[$filterent['gateway']] = gateway_info_popup($filterent['gateway'], $gateways_status);
915
									}
916
								?>
917
								<?php if (!empty($gw_info[$filterent['gateway']])): ?>
918
									<?=$gw_info[$filterent['gateway']]?>
919
								<?php else: ?>
920
									<span>
921
								<?php endif; ?>
922
							<?php else: ?>
923
								<span>
924
							<?php endif; ?>
925
								<?php if (isset($config['interfaces'][$filterent['gateway']]['descr'])): ?>
926
									<?=str_replace('_', '_<wbr>', htmlspecialchars($config['interfaces'][$filterent['gateway']]['descr']))?>
927
								<?php else: ?>
928
									<?=htmlspecialchars(pprint_port($filterent['gateway']))?>
929
								<?php endif; ?>
930
							</span>
931
						</td>
932
						<td>
933
							<?php
934
								if (isset($filterent['ackqueue']) && isset($filterent['defaultqueue'])) {
935
									$desc = str_replace('_', ' ', $filterent['ackqueue']);
936
									echo "<a href=\"firewall_shaper_queues.php?queue={$filterent['ackqueue']}&amp;action=show\">{$desc}</a>";
937
									$desc = str_replace('_', '_<wbr>', $filterent['defaultqueue']);
938
									echo "/<a href=\"firewall_shaper_queues.php?queue={$filterent['defaultqueue']}&amp;action=show\">{$desc}</a>";
939
								} else if (isset($filterent['defaultqueue'])) {
940
									$desc = str_replace('_', '_<wbr>', $filterent['defaultqueue']);
941
									echo "<a href=\"firewall_shaper_queues.php?queue={$filterent['defaultqueue']}&amp;action=show\">{$desc}</a>";
942
								} else {
943
									echo gettext("none");
944
								}
945
							?>
946
						</td>
947
						<td>
948
							<?php if ($printicon) { ?>
949
								<i class="fa fa-<?=$image?> <?=$dispcolor?>" title="<?=$alttext;?>"></i>
950
							<?php } ?>
951
							<?=$schedule_span_begin;?><?=str_replace('_', '_<wbr>', htmlspecialchars($filterent['sched']));?>&nbsp;<?=$schedule_span_end;?>
952
						</td>
953
						<td>
954
							<?=htmlspecialchars($filterent['descr']);?>
955
						</td>
956
						<td class="action-icons">
957
						<!-- <?=(isset($filterent['disabled']) ? 'enable' : 'disable')?> -->
958
							<a	class="fa fa-anchor icon-pointer" id="Xmove_<?=$filteri?>" title="<?=$XmoveTitle?>"></a>
959
							<a href="firewall_rules_edit.php?id=<?=$filteri;?>" class="fa fa-pencil" title="<?=gettext('Edit')?>"></a>
960
							<a href="firewall_rules_edit.php?dup=<?=$filteri;?>" class="fa fa-clone" title="<?=gettext('Copy')?>"></a>
961
<?php if (isset($filterent['disabled'])) {
962
?>
963
							<a href="?act=toggle&amp;if=<?=htmlspecialchars($if);?>&amp;id=<?=$filteri;?>" class="fa fa-check-square-o" title="<?=gettext('Enable')?>" usepost></a>
964
<?php } else {
965
?>
966
							<a href="?act=toggle&amp;if=<?=htmlspecialchars($if);?>&amp;id=<?=$filteri;?>" class="fa fa-ban" title="<?=gettext('Disable')?>" usepost></a>
967
<?php }
968
?>
969
							<a href="?act=del&amp;if=<?=htmlspecialchars($if);?>&amp;id=<?=$filteri;?>" class="fa fa-trash" title="<?=gettext('Delete this rule')?>" usepost></a>
970
<?php if (($filterent['type'] == 'pass') &&
971
	    !empty($filterent['tracker'])): ?>
972
							<a href="?act=killid&amp;if=<?=htmlspecialchars($if);?>&amp;id=<?=$filteri;?>&amp;tracker=<?=$filterent['tracker']?>" class="fa fa-times do-confirm" title="<?=gettext('Kill states on this interface created by this rule')?>" usepost></a>
973
<?php endif; ?>
974
						</td>
975
					</tr>
976
<?php
977
		$nrules++;
978
	}
979
endforeach;
980

    
981
// There can be separator(s) after the last rule listed.
982
if ($seprows[$nrules]) {
983
	display_separator($separators, $nrules, $columns_in_table);
984
}
985
?>
986
				</tbody>
987
			</table>
988
		</div>
989
	</div>
990

    
991
<?php if ($nrules == 0): ?>
992
	<div class="alert alert-warning" role="alert">
993
		<p>
994
		<?php if ($_REQUEST['if'] == "FloatingRules"): ?>
995
			<?=gettext("No floating rules are currently defined.");?>
996
		<?php else: ?>
997
			<?=gettext("No rules are currently defined for this interface");?><br />
998
			<?=gettext("All incoming connections on this interface will be blocked until pass rules are added.");?>
999
		<?php endif;?>
1000
			<?=gettext("Click the button to add a new rule.");?>
1001
		</p>
1002
	</div>
1003
<?php endif;?>
1004

    
1005
	<nav class="action-buttons">
1006
		<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')?>">
1007
			<i class="fa fa-level-up icon-embed-btn"></i>
1008
			<?=gettext("Add");?>
1009
		</a>
1010
		<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')?>">
1011
			<i class="fa fa-level-down icon-embed-btn"></i>
1012
			<?=gettext("Add");?>
1013
		</a>
1014
		<button id="del_x" name="del_x" type="submit" class="btn btn-danger btn-sm" value="<?=gettext("Delete selected rules"); ?>" disabled title="<?=gettext('Delete selected rules')?>">
1015
			<i class="fa fa-trash icon-embed-btn"></i>
1016
			<?=gettext("Delete"); ?>
1017
		</button>
1018
		<button id="toggle_x" name="toggle_x" type="submit" class="btn btn-primary btn-sm" value="<?=gettext("Toggle selected rules"); ?>" disabled title="<?=gettext('Toggle selected rules')?>">
1019
			<i class="fa fa-ban icon-embed-btn"></i>
1020
			<?=gettext("Toggle"); ?>
1021
		</button>
1022
		<?php if ($if != 'FloatingRules'):?>
1023
		<button id="copy_x" name="copy_x" type="button" class="btn btn-primary btn-sm" value="<?=gettext("Copy selected rules"); ?>" disabled title="<?=gettext('Copy selected rules')?>" data-toggle="modal" data-target="#rulescopy">
1024
			<i class="fa fa-clone icon-embed-btn"></i>
1025
			<?=gettext("Copy"); ?>
1026
		</button>
1027
		<?php endif;?>
1028
		<button type="submit" id="order-store" name="order-store" class="btn btn-sm btn-primary" value="store changes" disabled title="<?=gettext('Save rule order')?>">
1029
			<i class="fa fa-save icon-embed-btn"></i>
1030
			<?=gettext("Save")?>
1031
		</button>
1032
		<button type="submit" id="addsep" name="addsep" class="btn btn-sm btn-warning" title="<?=gettext('Add separator')?>">
1033
			<i class="fa fa-plus icon-embed-btn"></i>
1034
			<?=gettext("Separator")?>
1035
		</button>
1036
	</nav>
1037
</form>
1038
<?php
1039
// Create a Modal object to display Rules Copy window
1040
$form = new Form(false);
1041
$modal = new Modal('Copy selected rules', 'rulescopy', true);
1042
$modal->addInput(new Form_Select(
1043
	'copyr_dstif',
1044
	'*Destination Interface',
1045
	$if,
1046
	filter_get_interface_list()
1047
))->setHelp('Select the destination interface where the rules should be copied. Rules will be added after existing rules on that interface.');
1048
$modal->addInput(new Form_Checkbox(
1049
	'copyr_convertif',
1050
	'Convert interface definitions',
1051
	'Enable Interface Address/Net conversion',
1052
	false
1053
))->setHelp('Convert source Interface Address/Net definitions to the destination Interface Address/Net.%1$s' .
1054
	    'For example: LAN Address -> OPT1 Address, or LAN net -> OPT1 net.%1$s' . 
1055
	    'Interface groups and some special interfaces (IPsec, OpenVPN), do not support this feature.', '<br />');
1056
$btncopyrules = new Form_Button(
1057
	'copyr',
1058
	'Paste',
1059
	null,
1060
	'fa-clone'
1061
);
1062
$btncopyrules->setAttribute('type','button')->addClass('btn-success');
1063
$btncancelcopyrules = new Form_Button(
1064
	'cancel_copyr',
1065
	'Cancel',
1066
	null,
1067
	'fa-undo'
1068
);
1069
$btncancelcopyrules->setAttribute('type','button')->addClass('btn-warning');
1070
$modal->addInput(new Form_StaticText(
1071
	null,
1072
	$btncopyrules . $btncancelcopyrules
1073
));
1074
$form->add($modal);
1075
print($form);
1076
?>
1077
<div class="infoblock">
1078
	<div class="alert alert-info clearfix" role="alert"><div class="pull-left">
1079
		<dl class="dl-horizontal responsive">
1080
		<!-- Legend -->
1081
			<dt><?=gettext('Legend')?></dt>				<dd></dd>
1082
			<dt><i class="fa fa-check text-success"></i></dt>		<dd><?=gettext("Pass");?></dd>
1083
			<dt><i class="fa fa-filter"></i></dt>	<dd><?=gettext("Match");?></dd>
1084
			<dt><i class="fa fa-times text-danger"></i></dt>	<dd><?=gettext("Block");?></dd>
1085
			<dt><i class="fa fa-hand-stop-o text-warning"></i></dt>		<dd><?=gettext("Reject");?></dd>
1086
			<dt><i class="fa fa-tasks"></i></dt>	<dd> <?=gettext("Log");?></dd>
1087
			<dt><i class="fa fa-cog"></i></dt>		<dd> <?=gettext("Advanced filter");?></dd>
1088
			<dt><i class="fa fa-forward text-success"></i></dt><dd> <?=gettext("&quot;Quick&quot; rule. Applied immediately on match.")?></dd>
1089
		</dl>
1090

    
1091
<?php
1092
	if ("FloatingRules" != $if) {
1093
		print(gettext("Rules are evaluated on a first-match basis (i.e. " .
1094
			"the action of the first rule to match a packet will be executed). ") . '<br />' .
1095
			gettext("This means that if block rules are used, it is important to pay attention " .
1096
			"to the rule order. Everything that isn't explicitly passed is blocked " .
1097
			"by default. "));
1098
	} else {
1099
		print(gettext("Floating rules are evaluated on a first-match basis (i.e. " .
1100
			"the action of the first rule to match a packet will be executed) only " .
1101
			"if the 'quick' option is checked on a rule. Otherwise they will only match if no " .
1102
			"other rules match. Pay close attention to the rule order and options " .
1103
			"chosen. If no rule here matches, the per-interface or default rules are used. "));
1104
	}
1105

    
1106
	printf(gettext('%1$sClick the anchor icon %2$s to move checked rules before the clicked row. Hold down ' .
1107
			'the shift key and click to move the rules after the clicked row.'), '<br /><br />', '<i class="fa fa-anchor"></i>');
1108
?>
1109
	</div>
1110
	</div>
1111
</div>
1112

    
1113
<script type="text/javascript">
1114
//<![CDATA[
1115

    
1116
//Need to create some variables here so that jquery/pfSenseHelpers.js can read them
1117
iface = "<?=strtolower($if)?>";
1118
cncltxt = '<?=gettext("Cancel")?>';
1119
svtxt = '<?=gettext("Save")?>';
1120
svbtnplaceholder = '<?=gettext("Enter a description, Save, then drag to final location.")?>';
1121
configsection = "filter";
1122

    
1123
events.push(function() {
1124

    
1125
	// "Move to here" (anchor) action
1126
	$('[id^=Xmove_]').click(function (event) {
1127

    
1128
		// Prevent click from toggling row
1129
		event.stopImmediatePropagation();
1130

    
1131
		// Save the target rule position
1132
		var anchor_row = $(this).parents("tr:first");
1133

    
1134
		if (event.shiftKey) {
1135
			$($('#ruletable > tbody  > tr').get().reverse()).each(function() {
1136
				ruleid = this.id.slice(2);
1137

    
1138
				if (ruleid && !isNaN(ruleid)) {
1139
					if ($('#frc' + ruleid).prop('checked')) {
1140
						// Move the selected rows, un-select them and add highlight class
1141
						$(this).insertAfter(anchor_row);
1142
						fr_toggle(ruleid, "fr");
1143
						$('#fr' + ruleid).addClass("highlight");
1144
					}
1145
				}
1146
			});
1147
		} else {
1148
			$('#ruletable > tbody  > tr').each(function() {
1149
				ruleid = this.id.slice(2);
1150

    
1151
				if (ruleid && !isNaN(ruleid)) {
1152
					if ($('#frc' + ruleid).prop('checked')) {
1153
						// Move the selected rows, un-select them and add highlight class
1154
						$(this).insertBefore(anchor_row);
1155
						fr_toggle(ruleid, "fr");
1156
						$('#fr' + ruleid).addClass("highlight");
1157
					}
1158
				}
1159
			});
1160
		}
1161

    
1162
		// Temporarily set background color so user can more easily see the moved rules, then fade
1163
		$('.highlight').effect("highlight", {color: "#739b4b;"}, 4000);
1164
		$('#ruletable tr').removeClass("highlight");
1165
		$('#order-store').removeAttr('disabled');
1166
		reindex_rules($(anchor_row).parent('tbody'));
1167
		dirty = true;
1168
	}).mouseover(function(e) {
1169
		var ruleselected = false;
1170

    
1171
		$(this).css("cursor", "default");
1172

    
1173
		// Are any rules currently selected?
1174
		$('[id^=frc]').each(function () {
1175
			if ($(this).prop("checked")) {
1176
				ruleselected = true;
1177
			}
1178
		});
1179

    
1180
		// If so, change the icon to show the insertion point
1181
		if (ruleselected) {
1182
			if (e.shiftKey) {
1183
				$(this).removeClass().addClass("fa fa-lg fa-arrow-down text-danger");
1184
			} else {
1185
				$(this).removeClass().addClass("fa fa-lg fa-arrow-up text-danger");
1186
			}
1187
		}
1188
	}).mouseout(function(e) {
1189
		$(this).removeClass().addClass("fa fa-anchor");
1190
	});
1191

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

    
1197
	$('table tbody.user-entries').sortable({
1198
		cursor: 'grabbing',
1199
		scroll: true,
1200
		overflow: 'scroll',
1201
		scrollSensitivity: 100,
1202
		update: function(event, ui) {
1203
			$('#order-store').removeAttr('disabled');
1204
			reindex_rules(ui.item.parent('tbody'));
1205
			dirty = true;
1206
		}
1207
	});
1208

    
1209
	$('table tbody.user-entries').show();
1210
<?php endif; ?>
1211

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

    
1216
		// Save the separator bar configuration
1217
		save_separators();
1218

    
1219
		// Suppress the "Do you really want to leave the page" message
1220
		saving = true;
1221
	});
1222

    
1223
	$('[id^=fr]').click(function () {
1224
		buttonsmode('frc', ['del_x', 'toggle_x', 'copy_x']);
1225
	});
1226

    
1227
	// Provide a warning message if the user tries to change page before saving
1228
	$(window).bind('beforeunload', function(){
1229
		if ((!saving && dirty) || newSeperator) {
1230
			return ("<?=gettext('One or more rules have been moved but have not yet been saved')?>");
1231
		} else {
1232
			return undefined;
1233
		}
1234
	});
1235

    
1236
	$(document).on('keyup keydown', function(e){
1237
		if (e.shiftKey) {
1238
			$('[id^=Xmove_]').attr("title", "<?=$ShXmoveTitle?>");
1239
		} else {
1240
			$('[id^=Xmove_]').attr("title", "<?=$XmoveTitle?>");
1241
		}
1242
	});
1243

    
1244
	$('#selectAll').click(function() {
1245
		var checkedStatus = this.checked;
1246
		$('#ruletable tbody tr').find('td:first :checkbox').each(function() {
1247
		$(this).prop('checked', checkedStatus);
1248
		});
1249
		buttonsmode('frc', ['del_x', 'toggle_x', 'copy_x']);
1250
	});
1251

    
1252
	$("#copyr").click(function() {
1253
		$("#rulescopy").modal('hide');
1254
		$("#dstif").val($("#copyr_dstif").val());
1255
		$("#convertif").val($("#copyr_convertif").val());
1256
		document.getElementById('mainform').submit();
1257
	});
1258

    
1259
	$("#cancel_copyr").click(function() {
1260
		$("#rulescopy").modal('hide');
1261
	});
1262

    
1263
});
1264
//]]>
1265
</script>
1266

    
1267
<?php include("foot.inc");?>
(50-50/228)