Project

General

Profile

Download (42.1 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
		$first_idx = 0;		
203
		$num_deleted = 0;
204
		foreach ($_POST['rule'] as $rulei) {
205
			delete_nat_association($a_filter[$rulei]['associated-rule-id']);
206
			unset($a_filter[$rulei]);
207

    
208
			// Capture first changed filter index for later separator shifting
209
			if (!$first_idx) $first_idx = ifridx($if, $rulei);
210
			$num_deleted++;
211
		}
212

    
213
		if ($num_deleted) {
214
			move_separators($a_separators, $first_idx, -$num_deleted);
215
			if (write_config(gettext("Firewall: Rules - deleted selected firewall rules."))) {
216
				mark_subsystem_dirty('filter');
217
			}
218
		}
219

    
220
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
221
		exit;
222
	}
223
} elseif (isset($_POST['toggle_x'])) {
224
	if (is_array($_POST['rule']) && count($_POST['rule'])) {
225
		foreach ($_POST['rule'] as $rulei) {
226
			if (isset($a_filter[$rulei]['disabled'])) {
227
				unset($a_filter[$rulei]['disabled']);
228
			} else {
229
				$a_filter[$rulei]['disabled'] = true;
230
			}
231
		}
232
		if (write_config(gettext("Firewall: Rules - toggle selected firewall rules."))) {
233
			mark_subsystem_dirty('filter');
234
		}
235

    
236
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
237
		exit;
238
	}
239
} else if ($_POST['act'] == "toggle") {
240
	if ($a_filter[$_POST['id']]) {
241
		if (isset($a_filter[$_POST['id']]['disabled'])) {
242
			unset($a_filter[$_POST['id']]['disabled']);
243
			$wc_msg = gettext('Firewall: Rules - enabled a firewall rule.');
244
		} else {
245
			$a_filter[$_POST['id']]['disabled'] = true;
246
			$wc_msg = gettext('Firewall: Rules - disabled a firewall rule.');
247
		}
248
		if (write_config($wc_msg)) {
249
			mark_subsystem_dirty('filter');
250
		}
251

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

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

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

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

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

    
290
		if ($a_filter !== $a_filter_new) {
291
			$a_filter = $a_filter_new;
292
			$dirty = true;
293
		}
294
	}
295

    
296
	$a_separators = &$config['filter']['separator'][strtolower($if)];
297

    
298
	/* update separator order, POST[separator] is an array of ordered IDs */
299
	if (is_array($_POST['separator']) && !empty($_POST['separator'])) {
300
		$new_separator = array();
301
		$idx = 0;
302

    
303
		foreach ($_POST['separator'] as $separator) {
304
			$new_separator['sep' . $idx++] = $separator;
305
		}
306

    
307
		if ($a_separators !== $new_separator) {
308
			$a_separators = $new_separator;
309
			$updated = true;
310
		}
311
	} else if (!empty($a_separators)) {
312
		$a_separators = "";
313
		$updated = true;
314
	}
315

    
316
	if ($updated || $dirty) {
317
		if (write_config(gettext("Firewall: Rules - reordered firewall rules."))) {
318
			if ($dirty) {
319
				mark_subsystem_dirty('filter');
320
			}
321
		}
322
	}
323

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

    
359
	header("Location: firewall_rules.php?if=" . htmlspecialchars($_POST['dstif']));
360
	exit;
361
}
362

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

    
365
foreach ($iflist as $ifent => $ifname) {
366
	$tab_array[] = array($ifname, ($ifent == $if), "firewall_rules.php?if={$ifent}");
367
}
368

    
369
foreach ($tab_array as $dtab) {
370
	if ($dtab[1]) {
371
		$bctab = $dtab[0];
372
		break;
373
	}
374
}
375

    
376
$pgtitle = array(gettext("Firewall"), gettext("Rules"), $bctab);
377
$pglinks = array("", "firewall_rules.php", "@self");
378
$shortcut_section = "firewall";
379

    
380
include("head.inc");
381
$nrules = 0;
382

    
383
if ($savemsg) {
384
	print_info_box($savemsg, 'success');
385
}
386

    
387
if ($_POST['apply']) {
388
	print_apply_result_box($retval);
389
}
390

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

    
395
display_top_tabs($tab_array, false, 'pills');
396

    
397
$showantilockout = false;
398
$showprivate = false;
399
$showblockbogons = false;
400

    
401
if (!isset($config['system']['webgui']['noantilockout']) &&
402
    (((count($config['interfaces']) > 1) && ($if == 'lan')) ||
403
    ((count($config['interfaces']) == 1) && ($if == 'wan')))) {
404
	$showantilockout = true;
405
}
406

    
407
if (isset($config['interfaces'][$if]['blockpriv'])) {
408
	$showprivate = true;
409
}
410

    
411
if (isset($config['interfaces'][$if]['blockbogons'])) {
412
	$showblockbogons = true;
413
}
414

    
415
if (isset($config['system']['webgui']['roworderdragging'])) {
416
	$rules_header_text = gettext("Rules");
417
} else {
418
	$rules_header_text = gettext("Rules (Drag to Change Order)");
419
}
420

    
421
/* Load the counter data of each pf rule. */
422
$rulescnt = pfSense_get_pf_rules();
423

    
424
// Update this if you add or remove columns!
425
$columns_in_table = 13;
426

    
427
/* Floating rules tab has one extra column
428
 * https://redmine.pfsense.org/issues/10667 */
429
if ($if == "FloatingRules") {
430
	$columns_in_table++;
431
}
432

    
433
?>
434
<!-- Allow table to scroll when dragging outside of the display window -->
435
<style>
436
.table-responsive {
437
    clear: both;
438
    overflow-x: visible;
439
    margin-bottom: 0px;
440
}
441
</style>
442

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

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

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

    
551
/* Cache gateway status for this page load.
552
 * See https://redmine.pfsense.org/issues/12174 */
553
$gateways_status = return_gateways_status(true);
554

    
555
foreach ($a_filter as $filteri => $filterent):
556

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

    
559
		// Display separator(s) for section beginning at rule n
560
		if ($seprows[$nrules]) {
561
			display_separator($separators, $nrules, $columns_in_table);
562
		}
563
?>
564
					<tr id="fr<?=$nrules;?>" onClick="fr_toggle(<?=$nrules;?>)" ondblclick="document.location='firewall_rules_edit.php?id=<?=$filteri;?>';" <?=(isset($filterent['disabled']) ? ' class="disabled"' : '')?>>
565
						<td>
566
							<input type="checkbox" id="frc<?=$nrules;?>" onClick="fr_toggle(<?=$nrules;?>)" name="rule[]" value="<?=$filteri;?>"/>
567
						</td>
568

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

    
593
		$isadvset = firewall_check_for_advanced_options($filterent);
594
		if ($isadvset) {
595
			print '<i class="fa fa-cog" title="'. gettext("advanced setting") .': '. $isadvset .'" style="cursor: pointer;"></i>';
596
		}
597

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

    
602
		if (isset($filterent['direction']) && ($if == "FloatingRules")) {
603
			if ($filterent['direction'] == 'in') {
604
				print '<i class="fa fa-arrow-circle-o-left" title="'. gettext("direction is in") .'" style="cursor: pointer;"></i>';
605
			} elseif ($filterent['direction'] == 'out') {
606
				print '<i class="fa fa-arrow-circle-o-right" title="'. gettext("direction is out") .'" style="cursor: pointer;"></i>';
607
			}
608
		}
609
	?>
610
						</td>
611
	<?php
612
		$alias = rule_columns_with_alias(
613
			$filterent['source']['address'],
614
			pprint_port($filterent['source']['port']),
615
			$filterent['destination']['address'],
616
			pprint_port($filterent['destination']['port'])
617
		);
618

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

    
636
					foreach ($schedule['timerange'] as $timerange) {
637
						$tempFriendlyTime = "";
638
						$tempID = "";
639
						$firstprint = false;
640
						if ($timerange) {
641
							$dayFriendly = "";
642
							$tempFriendlyTime = "";
643

    
644
							//get hours
645
							$temptimerange = $timerange['hour'];
646
							$temptimeseparator = strrpos($temptimerange, "-");
647

    
648
							$starttime = substr ($temptimerange, 0, $temptimeseparator);
649
							$stoptime = substr ($temptimerange, $temptimeseparator+1);
650

    
651
							if ($timerange['month']) {
652
								$tempmontharray = explode(",", $timerange['month']);
653
								$tempdayarray = explode(",", $timerange['day']);
654
								$arraycounter = 0;
655
								$firstDayFound = false;
656
								$firstPrint = false;
657
								foreach ($tempmontharray as $monthtmp) {
658
									$month = $tempmontharray[$arraycounter];
659
									$day = $tempdayarray[$arraycounter];
660

    
661
									if (!$firstDayFound) {
662
										$firstDay = $day;
663
										$firstmonth = $month;
664
										$firstDayFound = true;
665
									}
666

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

    
840
		if (isset($filterent['protocol'])) {
841
			echo strtoupper($filterent['protocol']);
842

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

    
973
// There can be separator(s) after the last rule listed.
974
if ($seprows[$nrules]) {
975
	display_separator($separators, $nrules, $columns_in_table);
976
}
977
?>
978
				</tbody>
979
			</table>
980
		</div>
981
	</div>
982

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

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

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

    
1098
	printf(gettext('%1$sClick the anchor icon %2$s to move checked rules before the clicked row. Hold down ' .
1099
			'the shift key and click to move the rules after the clicked row.'), '<br /><br />', '<i class="fa fa-anchor"></i>');
1100
?>
1101
	</div>
1102
	</div>
1103
</div>
1104

    
1105
<script type="text/javascript">
1106
//<![CDATA[
1107

    
1108
//Need to create some variables here so that jquery/pfSenseHelpers.js can read them
1109
iface = "<?=strtolower($if)?>";
1110
cncltxt = '<?=gettext("Cancel")?>';
1111
svtxt = '<?=gettext("Save")?>';
1112
svbtnplaceholder = '<?=gettext("Enter a description, Save, then drag to final location.")?>';
1113
configsection = "filter";
1114

    
1115
events.push(function() {
1116

    
1117
	// "Move to here" (anchor) action
1118
	$('[id^=Xmove_]').click(function (event) {
1119

    
1120
		// Prevent click from toggling row
1121
		event.stopImmediatePropagation();
1122

    
1123
		// Save the target rule position
1124
		var anchor_row = $(this).parents("tr:first");
1125

    
1126
		if (event.shiftKey) {
1127
			$($('#ruletable > tbody  > tr').get().reverse()).each(function() {
1128
				ruleid = this.id.slice(2);
1129

    
1130
				if (ruleid && !isNaN(ruleid)) {
1131
					if ($('#frc' + ruleid).prop('checked')) {
1132
						// Move the selected rows, un-select them and add highlight class
1133
						$(this).insertAfter(anchor_row);
1134
						fr_toggle(ruleid, "fr");
1135
						$('#fr' + ruleid).addClass("highlight");
1136
					}
1137
				}
1138
			});
1139
		} else {
1140
			$('#ruletable > tbody  > tr').each(function() {
1141
				ruleid = this.id.slice(2);
1142

    
1143
				if (ruleid && !isNaN(ruleid)) {
1144
					if ($('#frc' + ruleid).prop('checked')) {
1145
						// Move the selected rows, un-select them and add highlight class
1146
						$(this).insertBefore(anchor_row);
1147
						fr_toggle(ruleid, "fr");
1148
						$('#fr' + ruleid).addClass("highlight");
1149
					}
1150
				}
1151
			});
1152
		}
1153

    
1154
		// Temporarily set background color so user can more easily see the moved rules, then fade
1155
		$('.highlight').effect("highlight", {color: "#739b4b;"}, 4000);
1156
		$('#ruletable tr').removeClass("highlight");
1157
		$('#order-store').removeAttr('disabled');
1158
		reindex_rules($(anchor_row).parent('tbody'));
1159
		dirty = true;
1160
	}).mouseover(function(e) {
1161
		var ruleselected = false;
1162

    
1163
		$(this).css("cursor", "default");
1164

    
1165
		// Are any rules currently selected?
1166
		$('[id^=frc]').each(function () {
1167
			if ($(this).prop("checked")) {
1168
				ruleselected = true;
1169
			}
1170
		});
1171

    
1172
		// If so, change the icon to show the insertion point
1173
		if (ruleselected) {
1174
			if (e.shiftKey) {
1175
				$(this).removeClass().addClass("fa fa-lg fa-arrow-down text-danger");
1176
			} else {
1177
				$(this).removeClass().addClass("fa fa-lg fa-arrow-up text-danger");
1178
			}
1179
		}
1180
	}).mouseout(function(e) {
1181
		$(this).removeClass().addClass("fa fa-anchor");
1182
	});
1183

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

    
1189
	$('table tbody.user-entries').sortable({
1190
		cursor: 'grabbing',
1191
		scroll: true,
1192
		overflow: 'scroll',
1193
		scrollSensitivity: 100,
1194
		update: function(event, ui) {
1195
			$('#order-store').removeAttr('disabled');
1196
			reindex_rules(ui.item.parent('tbody'));
1197
			dirty = true;
1198
		}
1199
	});
1200

    
1201
	$('table tbody.user-entries').show();
1202
<?php endif; ?>
1203

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

    
1208
		// Save the separator bar configuration
1209
		save_separators();
1210

    
1211
		// Suppress the "Do you really want to leave the page" message
1212
		saving = true;
1213
	});
1214

    
1215
	$('[id^=fr]').click(function () {
1216
		buttonsmode('frc', ['del_x', 'toggle_x', 'copy_x']);
1217
	});
1218

    
1219
	// Provide a warning message if the user tries to change page before saving
1220
	$(window).bind('beforeunload', function(){
1221
		if ((!saving && dirty) || newSeperator) {
1222
			return ("<?=gettext('One or more rules have been moved but have not yet been saved')?>");
1223
		} else {
1224
			return undefined;
1225
		}
1226
	});
1227

    
1228
	$(document).on('keyup keydown', function(e){
1229
		if (e.shiftKey) {
1230
			$('[id^=Xmove_]').attr("title", "<?=$ShXmoveTitle?>");
1231
		} else {
1232
			$('[id^=Xmove_]').attr("title", "<?=$XmoveTitle?>");
1233
		}
1234
	});
1235

    
1236
	$('#selectAll').click(function() {
1237
		var checkedStatus = this.checked;
1238
		$('#ruletable tbody tr').find('td:first :checkbox').each(function() {
1239
		$(this).prop('checked', checkedStatus);
1240
		});
1241
		buttonsmode('frc', ['del_x', 'toggle_x', 'copy_x']);
1242
	});
1243

    
1244
	$("#copyr").click(function() {
1245
		$("#rulescopy").modal('hide');
1246
		$("#dstif").val($("#copyr_dstif").val());
1247
		$("#convertif").val($("#copyr_convertif").val());
1248
		document.getElementById('mainform').submit();
1249
	});
1250

    
1251
	$("#cancel_copyr").click(function() {
1252
		$("#rulescopy").modal('hide');
1253
	});
1254

    
1255
});
1256
//]]>
1257
</script>
1258

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