Project

General

Profile

Download (31.7 KB) Statistics
| Branch: | Tag: | Revision:
1 b2ffe419 Scott Ullrich
<?php
2 5b237745 Scott Ullrich
/*
3 37e2071c Scott Ullrich
	firewall_rules.php
4 5b237745 Scott Ullrich
*/
5 fd9ebcd5 Stephen Beaver
/* ====================================================================
6 6cb366de Stephen Beaver
 *	Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
7 9da2cf1c Stephen Beaver
 *
8 cb41dd63 Renato Botelho
 *	Some or all of this file is based on the m0n0wall project which is
9
 *	Copyright (c)  2004 Manuel Kasper (BSD 2 clause)
10 fd9ebcd5 Stephen Beaver
 *
11 6cb366de Stephen Beaver
 *	Redistribution and use in source and binary forms, with or without modification,
12
 *	are permitted provided that the following conditions are met:
13 fd9ebcd5 Stephen Beaver
 *
14 6cb366de Stephen Beaver
 *	1. Redistributions of source code must retain the above copyright notice,
15
 *		this list of conditions and the following disclaimer.
16 fd9ebcd5 Stephen Beaver
 *
17 6cb366de Stephen Beaver
 *	2. Redistributions in binary form must reproduce the above copyright
18
 *		notice, this list of conditions and the following disclaimer in
19
 *		the documentation and/or other materials provided with the
20
 *		distribution.
21 fd9ebcd5 Stephen Beaver
 *
22 6cb366de Stephen Beaver
 *	3. All advertising materials mentioning features or use of this software
23
 *		must display the following acknowledgment:
24
 *		"This product includes software developed by the pfSense Project
25
 *		 for use in the pfSense software distribution. (http://www.pfsense.org/).
26 fd9ebcd5 Stephen Beaver
 *
27 6cb366de Stephen Beaver
 *	4. The names "pfSense" and "pfSense Project" must not be used to
28
 *		 endorse or promote products derived from this software without
29
 *		 prior written permission. For written permission, please contact
30
 *		 coreteam@pfsense.org.
31 fd9ebcd5 Stephen Beaver
 *
32 6cb366de Stephen Beaver
 *	5. Products derived from this software may not be called "pfSense"
33
 *		nor may "pfSense" appear in their names without prior written
34
 *		permission of the Electric Sheep Fencing, LLC.
35 fd9ebcd5 Stephen Beaver
 *
36 6cb366de Stephen Beaver
 *	6. Redistributions of any form whatsoever must retain the following
37
 *		acknowledgment:
38 fd9ebcd5 Stephen Beaver
 *
39 6cb366de Stephen Beaver
 *	"This product includes software developed by the pfSense Project
40
 *	for use in the pfSense software distribution (http://www.pfsense.org/).
41 919d91f9 Phil Davis
 *
42 6cb366de Stephen Beaver
 *	THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
43
 *	EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44
 *	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
45
 *	PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
46
 *	ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47
 *	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
48
 *	NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
49
 *	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50
 *	HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
51
 *	STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52
 *	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
53
 *	OF THE POSSIBILITY OF SUCH DAMAGE.
54 fd9ebcd5 Stephen Beaver
 *
55 6cb366de Stephen Beaver
 *	====================================================================
56 fd9ebcd5 Stephen Beaver
 *
57
 */
58 5b237745 Scott Ullrich
59 6b07c15a Matthew Grooms
##|+PRIV
60
##|*IDENT=page-firewall-rules
61 5230f468 jim-p
##|*NAME=Firewall: Rules
62 6b07c15a Matthew Grooms
##|*DESCR=Allow access to the 'Firewall: Rules' page.
63
##|*MATCH=firewall_rules.php*
64
##|-PRIV
65
66 5b237745 Scott Ullrich
require("guiconfig.inc");
67 7a927e67 Scott Ullrich
require_once("functions.inc");
68
require_once("filter.inc");
69 179ab6b3 Luiz Otavio O Souza
require_once("ipsec.inc");
70 7a927e67 Scott Ullrich
require_once("shaper.inc");
71 5b237745 Scott Ullrich
72 6c07db48 Phil Davis
$pgtitle = array(gettext("Firewall"), gettext("Rules"));
73 b32dd0a6 jim-p
$shortcut_section = "firewall";
74 7a808e01 Carlos Eduardo Ramos
75 00c82782 Renato Botelho
function delete_nat_association($id) {
76
	global $config;
77
78 603d3c16 Phil Davis
	if (!$id || !is_array($config['nat']['rule'])) {
79 673d29c0 Renato Botelho
		return;
80 603d3c16 Phil Davis
	}
81 673d29c0 Renato Botelho
82 00c82782 Renato Botelho
	$a_nat = &$config['nat']['rule'];
83
84 603d3c16 Phil Davis
	foreach ($a_nat as &$natent) {
85
		if ($natent['associated-rule-id'] == $id) {
86 00c82782 Renato Botelho
			$natent['associated-rule-id'] = '';
87 603d3c16 Phil Davis
		}
88
	}
89 673d29c0 Renato Botelho
}
90
91 5b237745 Scott Ullrich
if (!is_array($config['filter']['rule'])) {
92
	$config['filter']['rule'] = array();
93
}
94 c821a6cd Stephen Beaver
95 5b237745 Scott Ullrich
filter_rules_sort();
96
$a_filter = &$config['filter']['rule'];
97
98 07bd3f83 Scott Ullrich
$if = $_GET['if'];
99 824329d2 Stephen Beaver
100 603d3c16 Phil Davis
if ($_POST['if']) {
101 07bd3f83 Scott Ullrich
	$if = $_POST['if'];
102 603d3c16 Phil Davis
}
103 b2ffe419 Scott Ullrich
104 cbe3ea96 Ermal Luçi
$ifdescs = get_configured_interface_with_descr();
105 07bd3f83 Scott Ullrich
106 90ba56ad Scott Ullrich
/* add group interfaces */
107 603d3c16 Phil Davis
if (is_array($config['ifgroups']['ifgroupentry'])) {
108
	foreach ($config['ifgroups']['ifgroupentry'] as $ifgen) {
109
		if (have_ruleint_access($ifgen['ifname'])) {
110 90ba56ad Scott Ullrich
			$iflist[$ifgen['ifname']] = $ifgen['ifname'];
111 603d3c16 Phil Davis
		}
112
	}
113
}
114 90ba56ad Scott Ullrich
115 603d3c16 Phil Davis
foreach ($ifdescs as $ifent => $ifdesc) {
116
	if (have_ruleint_access($ifent)) {
117 aef4dc74 Ermal Luçi
		$iflist[$ifent] = $ifdesc;
118 603d3c16 Phil Davis
	}
119
}
120 88bcd1d2 Scott Dale
121 603d3c16 Phil Davis
if ($config['l2tp']['mode'] == "server") {
122
	if (have_ruleint_access("l2tp")) {
123 d62e733b Phil Davis
		$iflist['l2tp'] = gettext("L2TP VPN");
124 603d3c16 Phil Davis
	}
125
}
126 617f8d25 Ermal Lu?i
127 b0899ee4 Ermal
if (is_array($config['pppoes']['pppoe'])) {
128 603d3c16 Phil Davis
	foreach ($config['pppoes']['pppoe'] as $pppoes) {
129
		if (($pppoes['mode'] == 'server') && have_ruleint_access("pppoe")) {
130 d62e733b Phil Davis
			$iflist['pppoe'] = gettext("PPPoE Server");
131 603d3c16 Phil Davis
		}
132
	}
133 b0899ee4 Ermal
}
134 0c554ff6 Scott Ullrich
135 88bcd1d2 Scott Dale
/* add ipsec interfaces */
136 67c2baf1 Phil Davis
if (ipsec_enabled() && have_ruleint_access("enc0")) {
137 d62e733b Phil Davis
	$iflist["enc0"] = gettext("IPsec");
138 67c2baf1 Phil Davis
}
139 07bd3f83 Scott Ullrich
140 bfb60ac8 Ermal Luçi
/* add openvpn/tun interfaces */
141 6c07db48 Phil Davis
if ($config['openvpn']["openvpn-server"] || $config['openvpn']["openvpn-client"]) {
142 d62e733b Phil Davis
	$iflist["openvpn"] = gettext("OpenVPN");
143 603d3c16 Phil Davis
}
144 bfb60ac8 Ermal Luçi
145 92125c97 Ermal Luçi
if (!$if || !isset($iflist[$if])) {
146 603d3c16 Phil Davis
	if ("any" == $if) {
147 56dda8e0 Renato Botelho
		$if = "FloatingRules";
148 603d3c16 Phil Davis
	} else if ("FloatingRules" != $if) {
149
		if (isset($iflist['wan'])) {
150 0416d9a0 Darren Embry
			$if = "wan";
151 603d3c16 Phil Davis
		} else {
152 0416d9a0 Darren Embry
			$if = "FloatingRules";
153 603d3c16 Phil Davis
		}
154 0416d9a0 Darren Embry
	}
155 92125c97 Ermal Luçi
}
156 07bd3f83 Scott Ullrich
157 5b237745 Scott Ullrich
if ($_POST) {
158 c64c9278 Stephen Beaver
159 5b237745 Scott Ullrich
	$pconfig = $_POST;
160
161
	if ($_POST['apply']) {
162 37e2071c Scott Ullrich
		$retval = 0;
163 9a7e416c Scott Ullrich
		$retval = filter_configure();
164
165 a368a026 Ermal Lu?i
		clear_subsystem_dirty('filter');
166 a985eac2 Scott Ullrich
167 824329d2 Stephen Beaver
		$savemsg = sprintf(gettext("The settings have been applied. The firewall rules are now reloading in the background.<br />You can also %s monitor %s the reload progress"),
168
									"<a href='status_filter_reload.php'>", "</a>");
169 5b237745 Scott Ullrich
	}
170
}
171
172 d97c50cd Bill Marquette
if ($_GET['act'] == "del") {
173 673d29c0 Renato Botelho
	if ($a_filter[$_GET['id']]) {
174
		if (!empty($a_filter[$_GET['id']]['associated-rule-id'])) {
175 00c82782 Renato Botelho
			delete_nat_association($a_filter[$_GET['id']]['associated-rule-id']);
176 673d29c0 Renato Botelho
		}
177
		unset($a_filter[$_GET['id']]);
178 603d3c16 Phil Davis
		if (write_config()) {
179 bec92ab9 jim-p
			mark_subsystem_dirty('filter');
180 603d3c16 Phil Davis
		}
181 6cb366de Stephen Beaver
182 e653b6e1 jim-p
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
183 673d29c0 Renato Botelho
		exit;
184
	}
185 d97c50cd Bill Marquette
}
186
187 32c58070 Scott Ullrich
// Handle save msg if defined
188 603d3c16 Phil Davis
if ($_REQUEST['savemsg']) {
189 32c58070 Scott Ullrich
	$savemsg = htmlentities($_REQUEST['savemsg']);
190 603d3c16 Phil Davis
}
191 32c58070 Scott Ullrich
192 6cb366de Stephen Beaver
if (isset($_POST['del_x'])) {
193
	/* delete selected rules */
194
	$deleted = false;
195
196
	if (is_array($_POST['rule']) && count($_POST['rule'])) {
197
		foreach ($_POST['rule'] as $rulei) {
198
			delete_nat_association($a_filter[$rulei]['associated-rule-id']);
199
			unset($a_filter[$rulei]);
200
			$deleted = true;
201
		}
202
203 67c2baf1 Phil Davis
		if ($deleted) {
204 6cb366de Stephen Beaver
			if (write_config()) {
205
				mark_subsystem_dirty('filter');
206
			}
207
		}
208
209
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
210
		exit;
211
	}
212
} else if ($_GET['act'] == "toggle") {
213 07bd3f83 Scott Ullrich
	if ($a_filter[$_GET['id']]) {
214 603d3c16 Phil Davis
		if (isset($a_filter[$_GET['id']]['disabled'])) {
215 56dda8e0 Renato Botelho
			unset($a_filter[$_GET['id']]['disabled']);
216 603d3c16 Phil Davis
		} else {
217 56dda8e0 Renato Botelho
			$a_filter[$_GET['id']]['disabled'] = true;
218 603d3c16 Phil Davis
		}
219
		if (write_config()) {
220 bec92ab9 jim-p
			mark_subsystem_dirty('filter');
221 603d3c16 Phil Davis
		}
222 6cb366de Stephen Beaver
223 e653b6e1 jim-p
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
224 5b237745 Scott Ullrich
		exit;
225
	}
226 67c2baf1 Phil Davis
} else if ($_POST['order-store']) {
227 ea5665c7 Sjon Hortensius
	/* update rule order, POST[rule] is an array of ordered IDs */
228
	if (is_array($_POST['rule']) && !empty($_POST['rule'])) {
229 07bd3f83 Scott Ullrich
		$a_filter_new = array();
230 b2ffe419 Scott Ullrich
231 ea5665c7 Sjon Hortensius
		// if a rule is not in POST[rule], it has been deleted by the user
232 67c2baf1 Phil Davis
		foreach ($_POST['rule'] as $id) {
233 ea5665c7 Sjon Hortensius
			$a_filter_new[] = $a_filter[$id];
234 67c2baf1 Phil Davis
		}
235 b2ffe419 Scott Ullrich
236 07bd3f83 Scott Ullrich
		$a_filter = $a_filter_new;
237 c64c9278 Stephen Beaver
238 a361a19b Stephen Beaver
		$config['filter']['separator'][strtolower($if)] = "";
239 c64c9278 Stephen Beaver
240
		if ($_POST['separator']) {
241
			$idx = 0;
242
			foreach ($_POST['separator'] as $separator) {
243 a361a19b Stephen Beaver
				$config['filter']['separator'][strtolower($separator['if'])]['sep' . $idx++] = $separator;
244 c64c9278 Stephen Beaver
			}
245
		}
246
247 603d3c16 Phil Davis
		if (write_config()) {
248 bec92ab9 jim-p
			mark_subsystem_dirty('filter');
249 603d3c16 Phil Davis
		}
250 6cb366de Stephen Beaver
251 e653b6e1 jim-p
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
252 5b237745 Scott Ullrich
		exit;
253
	}
254
}
255
256 df95836a Stephen Beaver
$tab_array = array(array(gettext("Floating"), ("FloatingRules" == $if), "firewall_rules.php?if=FloatingRules"));
257
258 67c2baf1 Phil Davis
foreach ($iflist as $ifent => $ifname) {
259 df95836a Stephen Beaver
	$tab_array[] = array($ifname, ($ifent == $if), "firewall_rules.php?if={$ifent}");
260 67c2baf1 Phil Davis
}
261 df95836a Stephen Beaver
262
foreach ($tab_array as $dtab) {
263 67c2baf1 Phil Davis
	if ($dtab[1]) {
264 df95836a Stephen Beaver
		$bctab = $dtab[0];
265
		break;
266
	}
267
}
268
269
$pgtitle = array(gettext("Firewall"), gettext("Rules"), $bctab);
270
$shortcut_section = "firewall";
271
272 9a25487b Scott Ullrich
include("head.inc");
273 3b2c83b8 Sjon Hortensius
$nrules = 0;
274
275 67c2baf1 Phil Davis
if ($savemsg) {
276 42a6bcbd Stephen Beaver
	print_info_box($savemsg, 'success');
277 67c2baf1 Phil Davis
}
278 42a6bcbd Stephen Beaver
279 67c2baf1 Phil Davis
if (is_subsystem_dirty('filter')) {
280 3b3a95e5 Phil Davis
	print_apply_box(gettext("The firewall rule configuration has been changed.") . "<br />" . gettext("You must apply the changes in order for them to take effect."));
281 67c2baf1 Phil Davis
}
282 3b2c83b8 Sjon Hortensius
283
display_top_tabs($tab_array);
284 ea5665c7 Sjon Hortensius
285 3b2c83b8 Sjon Hortensius
?>
286 c821a6cd Stephen Beaver
<form method="post">
287
	<div class="panel panel-default">
288 95fa5cce Phil Davis
		<div class="panel-heading"><h2 class="panel-title"><?=gettext("Rules (Drag to change order)")?></h2></div>
289 c821a6cd Stephen Beaver
		<div id="mainarea" class="table-responsive panel-body">
290 576437f5 Stephen Beaver
			<table id="ruletable" class="table table-hover table-striped table-condensed">
291 c821a6cd Stephen Beaver
				<thead>
292
					<tr>
293 6cb366de Stephen Beaver
						<th><!-- checkbox --></th>
294 c821a6cd Stephen Beaver
						<th><!-- status icons --></th>
295 66c62a1a NewEraCracker
						<th><?=gettext("Protocol")?></th>
296 f25dac2d Stephen Beaver
						<th><?=gettext("Source")?></th>
297
						<th><?=gettext("Port")?></th>
298
						<th><?=gettext("Destination")?></th>
299
						<th><?=gettext("Port")?></th>
300
						<th><?=gettext("Gateway")?></th>
301
						<th><?=gettext("Queue")?></th>
302
						<th><?=gettext("Schedule")?></th>
303
						<th><?=gettext("Description")?></th>
304
						<th><?=gettext("Actions")?></th>
305 c821a6cd Stephen Beaver
					</tr>
306
				</thead>
307
				<tbody>
308 3b2c83b8 Sjon Hortensius
<?php
309 ea5665c7 Sjon Hortensius
		// 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.
310
	if (!isset($config['system']['webgui']['noantilockout']) &&
311 c64c9278 Stephen Beaver
		(((count($config['interfaces']) > 1) && ($if == 'lan')) ||
312
		 ((count($config['interfaces']) == 1) && ($if == 'wan')))):
313 ea5665c7 Sjon Hortensius
		$alports = implode('<br />', filter_get_antilockout_ports(true));
314 3b2c83b8 Sjon Hortensius
?>
315 b54ae90f Jared Dillard
					<tr id="antilockout">
316 6cb366de Stephen Beaver
						<td></td>
317 29620ab5 Jared Dillard
						<td title="<?=gettext("traffic is passed")?>"><i class="fa fa-check text-success"></i></td>
318 c821a6cd Stephen Beaver
						<td>*</td>
319
						<td>*</td>
320
						<td>*</td>
321
						<td><?=$iflist[$if];?> Address</td>
322
						<td><?=$alports?></td>
323
						<td>*</td>
324
						<td>*</td>
325
						<td></td>
326 b54ae90f Jared Dillard
						<td><?=gettext("Anti-Lockout Rule");?></td>
327 c821a6cd Stephen Beaver
						<td>
328 45e849c1 Jared Dillard
							<a href="system_advanced_admin.php" title="<?=gettext("Settings");?>"><i class="fa fa-cog"></i></a>
329 c821a6cd Stephen Beaver
						</td>
330
					</tr>
331 3b2c83b8 Sjon Hortensius
<?php endif;?>
332 f1f60c92 Ermal Luçi
<?php if (isset($config['interfaces'][$if]['blockpriv'])): ?>
333 b54ae90f Jared Dillard
					<tr id="frrfc1918">
334 6cb366de Stephen Beaver
						<td></td>
335 29620ab5 Jared Dillard
						<td title="<?=gettext("traffic is blocked")?>"><i class="fa fa-times text-danger"></i></td>
336 c821a6cd Stephen Beaver
						<td>*</td>
337
						<td><?=gettext("RFC 1918 networks");?></td>
338
						<td>*</td>
339
						<td>*</td>
340
						<td>*</td>
341
						<td>*</td>
342
						<td>*</td>
343
						<td></td>
344 b54ae90f Jared Dillard
						<td><?=gettext("Block private networks");?></td>
345 c821a6cd Stephen Beaver
						<td>
346 45e849c1 Jared Dillard
							<a href="interfaces.php?if=<?=htmlspecialchars($if)?>" title="<?=gettext("Settings");?>"><i class="fa fa-cog"></i></a>
347 c821a6cd Stephen Beaver
						</td>
348
					</tr>
349 3b2c83b8 Sjon Hortensius
<?php endif;?>
350 f1f60c92 Ermal Luçi
<?php if (isset($config['interfaces'][$if]['blockbogons'])): ?>
351 b54ae90f Jared Dillard
					<tr id="frrfc1918">
352 6cb366de Stephen Beaver
					<td></td>
353 29620ab5 Jared Dillard
						<td title="<?=gettext("traffic is blocked")?>"><i class="fa fa-times text-danger"></i></td>
354 c821a6cd Stephen Beaver
						<td>*</td>
355
						<td><?=gettext("Reserved/not assigned by IANA");?></td>
356
						<td>*</td>
357
						<td>*</td>
358
						<td>*</td>
359
						<td>*</td>
360
						<td>*</td>
361 ea548271 Phil Davis
						<td></td>
362 b54ae90f Jared Dillard
						<td><?=gettext("Block bogon networks");?></td>
363 c821a6cd Stephen Beaver
						<td>
364 45e849c1 Jared Dillard
							<a href="interfaces.php?if=<?=htmlspecialchars($if)?>" title="<?=gettext("Settings");?>"><i class="fa fa-cog"></i></a>
365 c821a6cd Stephen Beaver
						</td>
366
					</tr>
367 3b2c83b8 Sjon Hortensius
<?php endif;?>
368 c821a6cd Stephen Beaver
			</tbody>
369 3b2c83b8 Sjon Hortensius
370 c821a6cd Stephen Beaver
			<tbody class="user-entries">
371 6cb366de Stephen Beaver
<?php
372
$nrules = 0;
373 c64c9278 Stephen Beaver
$seps = 0;
374 a361a19b Stephen Beaver
375 5b2f5ce2 Stephen Beaver
// There can be a separator before any rules are listed
376
if ($config['filter']['separator'][strtolower($if)]['sep0']['row'][0] == "fr-1") {
377
	print('<tr class="ui-sortable-handle separator">' .
378
		'<td bgcolor="#cce5ff" colspan="11">' . '<font color="#002699">' . $config['filter']['separator'][strtolower($if)]['sep0']['text'] . '</font></td>' .
379
		'<td  bgcolor="#cce5ff"><a href="#"><i class="fa fa-trash no-confirm sepdel" title="delete this separator"></i></a></td>' .
380
		'</tr>' . "\n");
381 a361a19b Stephen Beaver
}
382
383 6cb366de Stephen Beaver
for ($i = 0; isset($a_filter[$i]); $i++):
384 56dda8e0 Renato Botelho
	$filterent = $a_filter[$i];
385 6cb366de Stephen Beaver
386 67c2baf1 Phil Davis
	if (($filterent['interface'] != $if && !isset($filterent['floating'])) || (isset($filterent['floating']) && "FloatingRules" != $if)) {
387 04fd7017 Stephen Beaver
		$display = 'style="display: none;"';
388 824329d2 Stephen Beaver
	} else {
389
		$display = "";
390 04fd7017 Stephen Beaver
	}
391 c64c9278 Stephen Beaver
392 56dda8e0 Renato Botelho
?>
393 04fd7017 Stephen Beaver
					<tr id="fr<?=$nrules;?>" <?=$display?> onClick="fr_toggle(<?=$nrules;?>)" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';" <?=(isset($filterent['disabled']) ? ' class="disabled"' : '')?>>
394 6cb366de Stephen Beaver
						<td >
395
							<input type="checkbox" id="frc<?=$nrules;?>" onClick="fr_toggle(<?=$nrules;?>)" name="rule[]" value="<?=$i;?>"/>
396
						</td>
397
398 3b2c83b8 Sjon Hortensius
	<?php
399 d08aeac1 Phil Davis
		if ($filterent['type'] == "block") {
400 29620ab5 Jared Dillard
			$iconfn = "times text-danger";
401 d08aeac1 Phil Davis
			$title_text = gettext("traffic is blocked");
402
		} else if ($filterent['type'] == "reject") {
403 29620ab5 Jared Dillard
			$iconfn = "hand-stop-o text-warning";
404 d08aeac1 Phil Davis
			$title_text = gettext("traffic is rejected");
405
		} else if ($filterent['type'] == "match") {
406 3b2c83b8 Sjon Hortensius
			$iconfn = "filter";
407 d08aeac1 Phil Davis
			$title_text = gettext("traffic is matched");
408
		} else {
409 29620ab5 Jared Dillard
			$iconfn = "check text-success";
410 d08aeac1 Phil Davis
			$title_text = gettext("traffic is passed");
411
		}
412 3b2c83b8 Sjon Hortensius
	?>
413 d08aeac1 Phil Davis
						<td title="<?=$title_text?>">
414
415 1b7379f9 Jared Dillard
							<i class="fa fa-<?=$iconfn?>"></i>
416 3b2c83b8 Sjon Hortensius
	<?php
417
		$isadvset = firewall_check_for_advanced_options($filterent);
418 67c2baf1 Phil Davis
		if ($isadvset) {
419 7ea65674 Jared Dillard
			print '<i class="fa fa-cog" title="'. gettext("advanced setting") .': '. $isadvset .'"></i>';
420 67c2baf1 Phil Davis
		}
421 3b2c83b8 Sjon Hortensius
422 67c2baf1 Phil Davis
		if (isset($filterent['log'])) {
423 1b7379f9 Jared Dillard
			print '<i class="fa fa-tasks" title="'. gettext("traffic is logged") .'"></i>';
424 67c2baf1 Phil Davis
		}
425 3b2c83b8 Sjon Hortensius
	?>
426 d08aeac1 Phil Davis
						</td>
427 3b2c83b8 Sjon Hortensius
	<?php
428
		$alias = rule_columns_with_alias(
429
			$filterent['source']['address'],
430
			pprint_port($filterent['source']['port']),
431
			$filterent['destination']['address'],
432
			pprint_port($filterent['destination']['port'])
433
		);
434
435
		//build Schedule popup box
436
		$a_schedules = &$config['schedules']['schedule'];
437
		$schedule_span_begin = "";
438
		$schedule_span_end = "";
439
		$sched_caption_escaped = "";
440
		$sched_content = "";
441
		$schedstatus = false;
442 e6f34d22 Phil Davis
		$dayArray = array (gettext('Mon'), gettext('Tues'), gettext('Wed'), gettext('Thur'), gettext('Fri'), gettext('Sat'), gettext('Sun'));
443
		$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'));
444 ea5665c7 Sjon Hortensius
		if ($config['schedules']['schedule'] != "" && is_array($config['schedules']['schedule'])) {
445 bdfea2e7 Stephen Beaver
			$idx = 0;
446 67c2baf1 Phil Davis
			foreach ($a_schedules as $schedule) {
447 e6f34d22 Phil Davis
				if ($schedule['name'] == $filterent['sched']) {
448 3b2c83b8 Sjon Hortensius
					$schedstatus = filter_get_time_based_rule_status($schedule);
449
450 e6f34d22 Phil Davis
					foreach ($schedule['timerange'] as $timerange) {
451 3b2c83b8 Sjon Hortensius
						$tempFriendlyTime = "";
452
						$tempID = "";
453
						$firstprint = false;
454 e6f34d22 Phil Davis
						if ($timerange) {
455 3b2c83b8 Sjon Hortensius
							$dayFriendly = "";
456
							$tempFriendlyTime = "";
457
458
							//get hours
459
							$temptimerange = $timerange['hour'];
460
							$temptimeseparator = strrpos($temptimerange, "-");
461
462
							$starttime = substr ($temptimerange, 0, $temptimeseparator);
463
							$stoptime = substr ($temptimerange, $temptimeseparator+1);
464
465 e6f34d22 Phil Davis
							if ($timerange['month']) {
466 3b2c83b8 Sjon Hortensius
								$tempmontharray = explode(",", $timerange['month']);
467 e6f34d22 Phil Davis
								$tempdayarray = explode(",", $timerange['day']);
468 3b2c83b8 Sjon Hortensius
								$arraycounter = 0;
469
								$firstDayFound = false;
470
								$firstPrint = false;
471 e6f34d22 Phil Davis
								foreach ($tempmontharray as $monthtmp) {
472 3b2c83b8 Sjon Hortensius
									$month = $tempmontharray[$arraycounter];
473
									$day = $tempdayarray[$arraycounter];
474
475 67c2baf1 Phil Davis
									if (!$firstDayFound) {
476 3b2c83b8 Sjon Hortensius
										$firstDay = $day;
477
										$firstmonth = $month;
478
										$firstDayFound = true;
479
									}
480
481
									$currentDay = $day;
482
									$nextDay = $tempdayarray[$arraycounter+1];
483
									$currentDay++;
484 e6f34d22 Phil Davis
									if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])) {
485 67c2baf1 Phil Davis
										if ($firstPrint) {
486 3b2c83b8 Sjon Hortensius
											$dayFriendly .= ", ";
487 67c2baf1 Phil Davis
										}
488 3b2c83b8 Sjon Hortensius
										$currentDay--;
489 67c2baf1 Phil Davis
										if ($currentDay != $firstDay) {
490 3b2c83b8 Sjon Hortensius
											$dayFriendly .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
491 67c2baf1 Phil Davis
										} else {
492 c821a6cd Stephen Beaver
											$dayFriendly .=	 $monthArray[$month-1] . " " . $day;
493 67c2baf1 Phil Davis
										}
494 8ce97a08 Scott Dale
										$firstDayFound = false;
495 3b2c83b8 Sjon Hortensius
										$firstPrint = true;
496
									}
497
									$arraycounter++;
498
								}
499 67c2baf1 Phil Davis
							} else {
500 3b2c83b8 Sjon Hortensius
								$tempdayFriendly = $timerange['position'];
501
								$firstDayFound = false;
502
								$tempFriendlyDayArray = explode(",", $tempdayFriendly);
503
								$currentDay = "";
504
								$firstDay = "";
505
								$nextDay = "";
506
								$counter = 0;
507 e6f34d22 Phil Davis
								foreach ($tempFriendlyDayArray as $day) {
508
									if ($day != "") {
509 67c2baf1 Phil Davis
										if (!$firstDayFound) {
510 3b2c83b8 Sjon Hortensius
											$firstDay = $tempFriendlyDayArray[$counter];
511
											$firstDayFound = true;
512 8ce97a08 Scott Dale
										}
513 3b2c83b8 Sjon Hortensius
										$currentDay =$tempFriendlyDayArray[$counter];
514
										//get next day
515
										$nextDay = $tempFriendlyDayArray[$counter+1];
516
										$currentDay++;
517 e6f34d22 Phil Davis
										if ($currentDay != $nextDay) {
518 67c2baf1 Phil Davis
											if ($firstprint) {
519 3b2c83b8 Sjon Hortensius
												$dayFriendly .= ", ";
520 67c2baf1 Phil Davis
											}
521 3b2c83b8 Sjon Hortensius
											$currentDay--;
522 67c2baf1 Phil Davis
											if ($currentDay != $firstDay) {
523 3b2c83b8 Sjon Hortensius
												$dayFriendly .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
524 67c2baf1 Phil Davis
											} else {
525 3b2c83b8 Sjon Hortensius
												$dayFriendly .= $dayArray[$firstDay-1];
526 67c2baf1 Phil Davis
											}
527 3b2c83b8 Sjon Hortensius
											$firstDayFound = false;
528
											$firstprint = true;
529
										}
530
										$counter++;
531 56dda8e0 Renato Botelho
									}
532 8ce97a08 Scott Dale
								}
533 2a113ca9 Scott Dale
							}
534 3b2c83b8 Sjon Hortensius
							$timeFriendly = $starttime . " - " . $stoptime;
535
							$description = $timerange['rangedescr'];
536
							$sched_content .= $dayFriendly . "; " . $timeFriendly . "<br />";
537 56dda8e0 Renato Botelho
						}
538
					}
539 ea5665c7 Sjon Hortensius
					#FIXME
540 3b2c83b8 Sjon Hortensius
					$sched_caption_escaped = str_replace("'", "\'", $schedule['descr']);
541 bdfea2e7 Stephen Beaver
					$schedule_span_begin = '<a href="/firewall_schedule_edit.php?id=' . $idx . '" data-toggle="popover" data-trigger="hover focus" title="' . $schedule['name'] . '" data-content="' .
542 c64c9278 Stephen Beaver
						$sched_caption_escaped . '" data-html="true">';
543 bdfea2e7 Stephen Beaver
					$schedule_span_end = "";
544 616dd997 Scott Dale
				}
545 3b2c83b8 Sjon Hortensius
			}
546 bdfea2e7 Stephen Beaver
			$idx++;
547 3b2c83b8 Sjon Hortensius
		}
548
		$printicon = false;
549
		$alttext = "";
550
		$image = "";
551
		if (!isset($filterent['disabled'])) {
552
			if ($schedstatus) {
553 5db29ca7 Phil Davis
				if ($filterent['type'] == "block" || $filterent['type'] == "reject") {
554 7ea65674 Jared Dillard
					$image = "times-circle";
555 bdfea2e7 Stephen Beaver
					$dispcolor = "text-danger";
556 3b2c83b8 Sjon Hortensius
					$alttext = gettext("Traffic matching this rule is currently being denied");
557 56dda8e0 Renato Botelho
				} else {
558 7ea65674 Jared Dillard
					$image = "play-circle";
559 bdfea2e7 Stephen Beaver
					$dispcolor = "text-success";
560 3b2c83b8 Sjon Hortensius
					$alttext = gettext("Traffic matching this rule is currently being allowed");
561 be81b340 Erik Fonnesbeck
				}
562 3b2c83b8 Sjon Hortensius
				$printicon = true;
563
			} else if ($filterent['sched']) {
564 5db29ca7 Phil Davis
				if ($filterent['type'] == "block" || $filterent['type'] == "reject") {
565 7ea65674 Jared Dillard
					$image = "times-circle";
566 67c2baf1 Phil Davis
				} else {
567 5db29ca7 Phil Davis
					$image = "play-circle";
568 67c2baf1 Phil Davis
				}
569 3b2c83b8 Sjon Hortensius
				$alttext = gettext("This rule is not currently active because its period has expired");
570 5db29ca7 Phil Davis
				$dispcolor = "text-warning";
571 3b2c83b8 Sjon Hortensius
				$printicon = true;
572
			}
573
		}
574
	?>
575 ea5665c7 Sjon Hortensius
				<td>
576 3b2c83b8 Sjon Hortensius
	<?php
577
		if (isset($filterent['ipprotocol'])) {
578 e6f34d22 Phil Davis
			switch ($filterent['ipprotocol']) {
579 3b2c83b8 Sjon Hortensius
				case "inet":
580
					echo "IPv4 ";
581
					break;
582
				case "inet6":
583
					echo "IPv6 ";
584
					break;
585
				case "inet46":
586
					echo "IPv4+6 ";
587
					break;
588
			}
589
		} else {
590
			echo "IPv4 ";
591
		}
592
593
		if (isset($filterent['protocol'])) {
594
			echo strtoupper($filterent['protocol']);
595
596
			if (strtoupper($filterent['protocol']) == "ICMP" && !empty($filterent['icmptype'])) {
597 d62e733b Phil Davis
				echo ' <span style="cursor: help;" title="' . gettext('ICMP type') . ': ' .
598 e6f34d22 Phil Davis
					($filterent['ipprotocol'] == "inet6" ? $icmp6types[$filterent['icmptype']] : $icmptypes[$filterent['icmptype']]) .
599 3b2c83b8 Sjon Hortensius
					'"><u>';
600
				echo $filterent['icmptype'];
601
				echo '</u></span>';
602
			}
603
		} else echo "*";
604 e83aaa50 Stephen Beaver
605 3b2c83b8 Sjon Hortensius
	?>
606 c821a6cd Stephen Beaver
						</td>
607
						<td>
608
							<?php if (isset($alias['src'])): ?>
609 d62e733b Phil Davis
								<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">
610 c821a6cd Stephen Beaver
							<?php endif; ?>
611
							<?=htmlspecialchars(pprint_address($filterent['source']))?>
612
						</td>
613
						<td>
614
							<?php if (isset($alias['srcport'])): ?>
615 d62e733b Phil Davis
								<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">
616 c821a6cd Stephen Beaver
							<?php endif; ?>
617
							<?=htmlspecialchars(pprint_port($filterent['source']['port']))?>
618
						</td>
619
						<td>
620
							<?php if (isset($alias['dst'])): ?>
621 d62e733b Phil Davis
								<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">
622 c821a6cd Stephen Beaver
							<?php endif; ?>
623 2754e7e6 Stephen Beaver
							<?=htmlspecialchars(pprint_address($filterent['destination']))?>
624 c821a6cd Stephen Beaver
						</td>
625
						<td>
626
							<?php if (isset($alias['dstport'])): ?>
627 d62e733b Phil Davis
								<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">
628 c821a6cd Stephen Beaver
							<?php endif; ?>
629
							<?=htmlspecialchars(pprint_port($filterent['destination']['port']))?>
630
						</td>
631
						<td>
632
							<?php if (isset($config['interfaces'][$filterent['gateway']]['descr'])):?>
633
								<?=htmlspecialchars($config['interfaces'][$filterent['gateway']]['descr'])?>
634
							<?php else: ?>
635
								<?=htmlspecialchars(pprint_port($filterent['gateway']))?>
636
							<?php endif; ?>
637
						</td>
638
						<td>
639
							<?php
640
								if (isset($filterent['ackqueue']) && isset($filterent['defaultqueue'])) {
641
									$desc = $filterent['ackqueue'] ;
642
									echo "<a href=\"firewall_shaper_queues.php?queue={$filterent['ackqueue']}&amp;action=show\">{$desc}</a>";
643
									$desc = $filterent['defaultqueue'];
644
									echo "/<a href=\"firewall_shaper_queues.php?queue={$filterent['defaultqueue']}&amp;action=show\">{$desc}</a>";
645
								} else if (isset($filterent['defaultqueue'])) {
646
									$desc = $filterent['defaultqueue'];
647
									echo "<a href=\"firewall_shaper_queues.php?queue={$filterent['defaultqueue']}&amp;action=show\">{$desc}</a>";
648 67c2baf1 Phil Davis
								} else {
649 c821a6cd Stephen Beaver
									echo gettext("none");
650 67c2baf1 Phil Davis
								}
651 c821a6cd Stephen Beaver
							?>
652
						</td>
653
						<td>
654 995df6c3 Stephen Beaver
							<?php if ($printicon) { ?>
655 bdfea2e7 Stephen Beaver
								<i class="fa fa-<?=$image?> <?=$dispcolor?>" title="<?=$alttext;?>" alt="icon"></i>
656 995df6c3 Stephen Beaver
							<?php } ?>
657 c821a6cd Stephen Beaver
							<?=$schedule_span_begin;?><?=htmlspecialchars($filterent['sched']);?>&nbsp;<?=$schedule_span_end;?>
658
						</td>
659 b54ae90f Jared Dillard
						<td>
660 c821a6cd Stephen Beaver
							<?=htmlspecialchars($filterent['descr']);?>
661
						</td>
662 45e849c1 Jared Dillard
						<td class="action-icons">
663 f25dac2d Stephen Beaver
						<!-- <?=(isset($filterent['disabled']) ? 'enable' : 'disable')?> -->
664 3193d853 Phil Davis
							<a href="firewall_rules_edit.php?id=<?=$i;?>" class="fa fa-pencil" title="<?=gettext('Edit')?>"></a>
665 f25dac2d Stephen Beaver
							<a href="firewall_rules_edit.php?dup=<?=$i;?>" class="fa fa-clone" title="<?=gettext('Copy')?>"></a>
666
<?php if (isset($filterent['disabled'])) {
667
?>
668
							<a href="?act=toggle&amp;if=<?=htmlspecialchars($if);?>&amp;id=<?=$i;?>" class="fa fa-check-square-o" title="<?=gettext('Enable')?>"></a>
669
<?php } else {
670
?>
671
							<a href="?act=toggle&amp;if=<?=htmlspecialchars($if);?>&amp;id=<?=$i;?>" class="fa fa-ban" title="<?=gettext('Disable')?>"></a>
672
<?php }
673
?>
674 33f0b0d5 Stephen Beaver
							<a href="?act=del&amp;if=<?=htmlspecialchars($if);?>&amp;id=<?=$i;?>" class="fa fa-trash" title="<?=gettext('Delete')?>"></a>
675 c821a6cd Stephen Beaver
						</td>
676
					</tr>
677
<?php
678 c64c9278 Stephen Beaver
		if (isset($config['filter']['separator'][strtolower($if)]['sep0'])) {
679
			foreach ($config['filter']['separator'][strtolower($if)] as $rulesep) {
680
				if ($rulesep['row']['0'] == "fr" . $nrules) {
681 e582bccc Stephen Beaver
					$cellcolor = $rulesep['color'];
682 c64c9278 Stephen Beaver
					print('<tr class="ui-sortable-handle separator">' .
683 e582bccc Stephen Beaver
						'<td class="' . $cellcolor . '" colspan="11">' . '<font class="' . $cellcolor . '">' . $rulesep['text'] . '</font></td>' .
684
						'<td  class="' . $cellcolor . '"><a href="#"><i class="fa fa-trash no-confirm sepdel" title="delete this separator"></i></a></td>' .
685 c64c9278 Stephen Beaver
						'</tr>' . "\n");
686
				}
687
			}
688
		}
689
690 6cb366de Stephen Beaver
		$nrules++;
691 c821a6cd Stephen Beaver
		endfor;
692
?>
693
				</tbody>
694
			</table>
695
		</div>
696
	</div>
697 3b2c83b8 Sjon Hortensius
698
<?php if ($nrules == 0): ?>
699
	<div class="alert alert-warning" role="alert">
700 06966500 Sander van Leeuwen
		<p>
701 3b2c83b8 Sjon Hortensius
		<?php if ($_REQUEST['if'] == "FloatingRules"): ?>
702
			<?=gettext("No floating rules are currently defined.");?>
703
		<?php else: ?>
704
			<?=gettext("No rules are currently defined for this interface");?><br />
705
			<?=gettext("All incoming connections on this interface will be blocked until you add pass rules.");?>
706
		<?php endif;?>
707 06966500 Sander van Leeuwen
			<?=gettext("Click the button to add a new rule.");?>
708
		</p>
709 3b2c83b8 Sjon Hortensius
	</div>
710
<?php endif;?>
711
712 c10cb196 Stephen Beaver
	<nav class="action-buttons">
713 270de3df Stephen Beaver
		<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')?>">
714
			<i class="fa fa-level-up icon-embed-btn"></i>
715 09415b9e Stephen Beaver
			<?=gettext("Add");?>
716 c821a6cd Stephen Beaver
		</a>
717 270de3df Stephen Beaver
		<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')?>">
718
			<i class="fa fa-level-down icon-embed-btn"></i>
719
			<?=gettext("Add");?>
720
		</a>
721
		<button name="del_x" type="submit" class="btn btn-danger btn-sm" value="<?=gettext("Delete selected rules"); ?>" title="<?=gettext('Delete selected rules')?>">
722 9d5a20cf heper
			<i class="fa fa-trash icon-embed-btn"></i>
723 09415b9e Stephen Beaver
			<?=gettext("Delete"); ?>
724
		</button>
725 c4b60a9a Colin Fleming
		<button type="submit" id="order-store" name="order-store" class="btn btn-sm btn-primary" value="store changes" disabled title="<?=gettext('Save rule order')?>">
726 9d5a20cf heper
			<i class="fa fa-save icon-embed-btn"></i>
727 09415b9e Stephen Beaver
			<?=gettext("Save")?>
728
		</button>
729 576437f5 Stephen Beaver
		<button type="submit" id="addsep" name="addsep" class="btn btn-sm btn-warning" title="<?=gettext('Add separator')?>">
730
			<i class="fa fa-plus icon-embed-btn"></i>
731
			<?=gettext("Separator")?>
732
		</button>
733 c821a6cd Stephen Beaver
	</nav>
734
</form>
735
736 35681930 Stephen Beaver
<div class="infoblock">
737 c97a3f34 Phil Davis
	<div class="alert alert-info clearfix" role="alert"><div class="pull-left">
738 270de3df Stephen Beaver
		<dl class="dl-horizontal responsive">
739
		<!-- Legend -->
740
			<dt><?=gettext('Legend')?></dt>				<dd></dd>
741 29620ab5 Jared Dillard
			<dt><i class="fa fa-check text-success"></i></dt>		<dd><?=gettext("Pass");?></dd>
742 1b7379f9 Jared Dillard
			<dt><i class="fa fa-filter"></i></dt>	<dd><?=gettext("Match");?></dd>
743 29620ab5 Jared Dillard
			<dt><i class="fa fa-times text-danger"></i></dt>	<dd><?=gettext("Block");?></dd>
744
			<dt><i class="fa fa-hand-stop-o text-warning"></i></dt>		<dd><?=gettext("Reject");?></dd>
745 1b7379f9 Jared Dillard
			<dt><i class="fa fa-tasks"></i></dt>	<dd> <?=gettext("Log");?></dd>
746 7ea65674 Jared Dillard
			<dt><i class="fa fa-cog"></i></dt>		<dd> <?=gettext("Advanced filter");?></dd>
747 270de3df Stephen Beaver
		</dl>
748
749 824329d2 Stephen Beaver
<?php
750 67c2baf1 Phil Davis
	if ("FloatingRules" != $if) {
751 270de3df Stephen Beaver
		print(gettext("Rules are evaluated on a first-match basis (i.e. " .
752 09415b9e Stephen Beaver
			"the action of the first rule to match a packet will be executed). ") . '<br />' .
753
			gettext("This means that if you use block rules, you'll have to pay attention " .
754
			"to the rule order. Everything that isn't explicitly passed is blocked " .
755 270de3df Stephen Beaver
			"by default. "));
756 67c2baf1 Phil Davis
	} else {
757 270de3df Stephen Beaver
		print(gettext("Floating rules are evaluated on a first-match basis (i.e. " .
758 09415b9e Stephen Beaver
			"the action of the first rule to match a packet will be executed) only " .
759 04fd7017 Stephen Beaver
			"if the 'quick' option is checked on a rule. Otherwise they will only match if no " .
760 09415b9e Stephen Beaver
			"other rules match. Pay close attention to the rule order and options " .
761 270de3df Stephen Beaver
			"chosen. If no rule here matches, the per-interface or default rules are used. "));
762 67c2baf1 Phil Davis
	}
763 824329d2 Stephen Beaver
?>
764 270de3df Stephen Beaver
	</div>
765 ab6b1f47 NOYB
	</div>
766 09415b9e Stephen Beaver
</div>
767 2f4323b5 Stephen Beaver
768 8fd9052f Colin Fleming
<script type="text/javascript">
769
//<![CDATA[
770 ea5665c7 Sjon Hortensius
events.push(function() {
771 2f4323b5 Stephen Beaver
772 ea5665c7 Sjon Hortensius
	// Make rules sortable
773
	$('table tbody.user-entries').sortable({
774
		cursor: 'grabbing',
775
		update: function(event, ui) {
776
			$('#order-store').removeAttr('disabled');
777 5d7b915d Stephen Beaver
			dirty = true;
778 ea5665c7 Sjon Hortensius
		}
779
	});
780
781 6cb366de Stephen Beaver
	// Check all of the rule checkboxes so that their values are posted
782
	$('#order-store').click(function () {
783 301e4aa0 Stephen Beaver
		$('[id^=frc]').prop('checked', true);
784
785
		// Save the separator bar configuration
786
		save_separators();
787 5d7b915d Stephen Beaver
788
		// Suppress the "Do you really want to leave the page" message
789
		saving = true;
790 6cb366de Stephen Beaver
	});
791 576437f5 Stephen Beaver
792 301e4aa0 Stephen Beaver
	// Separator bar stuff ------------------------------------------------------------------------
793 78b4b127 Stephen Beaver
794
	// Globals
795
	gColor = 'bg-info';
796
	newSeperator = false;
797 5d7b915d Stephen Beaver
	saving = false;
798
	dirty = false;
799 78b4b127 Stephen Beaver
800 576437f5 Stephen Beaver
	$("#addsep").prop('type' ,'button');
801
802 c64c9278 Stephen Beaver
	$("#addsep").click(function() {
803 78b4b127 Stephen Beaver
		if (newSeperator) {
804
			return(false);
805
		}
806 c64c9278 Stephen Beaver
807 78b4b127 Stephen Beaver
		gColor = 'bg-info';
808 e582bccc Stephen Beaver
		// Inset a temporary bar in which the user can enter some optional text
809 78b4b127 Stephen Beaver
		$('#ruletable > tbody:last').append('<tr>' +
810
			'<td class="' + gColor + '" colspan="10"><input id="newsep" placeholder="<?=gettext("Enter a description, Save, then drag to final location.")?>" class="col-md-12" type="text"></input></td>' +
811
			'<td class="' + gColor + '" colspan="2"><button class="btn btn-default btn-sm" id="btnnewsep"><?=gettext("Save")?></button>' +
812 e582bccc Stephen Beaver
			'<button class="btn btn-default btn-sm" id="btncncsep"><?=gettext("Cancel")?></button>' +
813
			'&nbsp;&nbsp;&nbsp;&nbsp;' +
814 78b4b127 Stephen Beaver
			'&nbsp;&nbsp;<a href="#" id="sepclrblue" value="bg-info"><i class="fa fa-circle text-info"></i></a>' +
815
			'&nbsp;&nbsp;<a href="#" id="sepclrred" value="bg-danger"><i class="fa fa-circle text-danger"></i></a>' +
816
			'&nbsp;&nbsp;<a href="#" id="sepclrgreen" value="bg-success"><i class="fa fa-circle text-success"></i></a>' +
817
			'&nbsp;&nbsp;<a href="#" id="sepclrorange" value="bg-warning"><i class="fa fa-circle text-warning"></i></a>' +
818 e582bccc Stephen Beaver
			'</td></tr>');
819 576437f5 Stephen Beaver
820 836cefa0 Stephen Beaver
		$('#newsep').focus();
821 78b4b127 Stephen Beaver
		newSeperator = true;
822 836cefa0 Stephen Beaver
823 576437f5 Stephen Beaver
		$("#btnnewsep").prop('type' ,'button');
824
825 5d7b915d Stephen Beaver
		// Watch escape and enter keys
826
		$('#newsep').keyup(function(e) {
827
			if(e.which == 27) {
828
				$('#btncncsep').trigger('click');
829
			}
830
		});
831
832
		$('#newsep').keypress(function(e) {
833
			if(e.which == 13) {
834
				$('#btnnewsep').trigger('click');
835
			}
836
		});
837
838 e582bccc Stephen Beaver
		handle_colors();
839
840 301e4aa0 Stephen Beaver
		// Remove the temporary separator bar and replace it with the final version containing the
841
		// user's text and a delete icon
842 576437f5 Stephen Beaver
		$("#btnnewsep").click(function() {
843 8a34b991 Stephen Beaver
			var septext = escapeHtml($('#newsep').val());
844 576437f5 Stephen Beaver
			$('#ruletable > tbody:last >tr:last').remove();
845 c64c9278 Stephen Beaver
			$('#ruletable > tbody:last').append('<tr class="ui-sortable-handle separator">' +
846 e582bccc Stephen Beaver
				'<td class="' + gColor + '" colspan="11">' + '<font class="' + gColor + '">' + septext + '</font></td>' +
847
				'<td class="' + gColor + '"><a href="#"><i class="fa fa-trash sepdel"></i></a>' +
848 c64c9278 Stephen Beaver
				'</tr>');
849
850
			$('#order-store').removeAttr('disabled');
851 78b4b127 Stephen Beaver
			newSeperator = false;
852 5d7b915d Stephen Beaver
			dirty = true;
853 78b4b127 Stephen Beaver
		});
854
855
		// Cancel button
856
		$('#btncncsep').click(function(e) {
857
			e.preventDefault();
858
			$(this).parents('tr').remove();
859
			newSeperator = false;
860 576437f5 Stephen Beaver
		});
861 c64c9278 Stephen Beaver
	});
862 301e4aa0 Stephen Beaver
863 836cefa0 Stephen Beaver
	// Delete a separator row
864 a683fa0a Stephen Beaver
	$(function(){
865 301e4aa0 Stephen Beaver
		$('table').on('click','tr a .sepdel',function(e){
866 a683fa0a Stephen Beaver
			e.preventDefault();
867
			$(this).parents('tr').remove();
868 c64c9278 Stephen Beaver
			$('#order-store').removeAttr('disabled');
869 5d7b915d Stephen Beaver
			dirty = true;
870 a683fa0a Stephen Beaver
		});
871
	});
872 301e4aa0 Stephen Beaver
873 5d7b915d Stephen Beaver
	// Compose an inout array containing the row #, color and text for each separator
874 301e4aa0 Stephen Beaver
	function save_separators() {
875 c64c9278 Stephen Beaver
		var seprow = 0;
876
		var sepinput;
877
		var sepnum = 0;
878
879
		$('#ruletable > tbody > tr').each(function() {
880
			if ($(this).hasClass('separator')) {
881
				seprow = $(this).prev('tr').attr("id");
882 a361a19b Stephen Beaver
				if (seprow == undefined) {
883
					seprow = "fr-1";
884 c64c9278 Stephen Beaver
				}
885
886
				sepinput = '<input type="hidden" name="separator[' + sepnum + '][row]" value="' + seprow + '"></input>';
887
				$('form').append(sepinput);
888 4979fb6a Stephen Beaver
				sepinput = '<input type="hidden" name="separator[' + sepnum + '][text]" value="' + escapeHtml($(this).find('td').text()) + '"></input>';
889 c64c9278 Stephen Beaver
				$('form').append(sepinput);
890 e582bccc Stephen Beaver
				sepinput = '<input type="hidden" name="separator[' + sepnum + '][color]" value="' + $(this).find('td').prop('class') + '"></input>';
891 c64c9278 Stephen Beaver
				$('form').append(sepinput);
892 a361a19b Stephen Beaver
				sepinput = '<input type="hidden" name="separator[' + sepnum + '][if]" value="<?=strtolower($if)?>"></input>';
893 c64c9278 Stephen Beaver
				$('form').append(sepinput);
894
				sepnum++;
895
			}
896
897
			if ($(this).parent('tbody').hasClass('user-entries')) {
898
				seprow++;
899
			}
900
		});
901 301e4aa0 Stephen Beaver
	}
902
903 e582bccc Stephen Beaver
	function handle_colors() {
904
		$('[id^=sepclr]').prop("type", "button");
905
906
		$('[id^=sepclr]').click(function () {
907 5d7b915d Stephen Beaver
			var color =	 $(this).attr('value');
908 e582bccc Stephen Beaver
			// Clear all the color classes
909 78b4b127 Stephen Beaver
			$(this).parent('td').prop('class', '');
910
			$(this).parent('td').prev('td').prop('class', '');
911 e582bccc Stephen Beaver
			// Install our new color class
912 78b4b127 Stephen Beaver
			$(this).parent('td').addClass(color);
913
			$(this).parent('td').prev('td').addClass(color);
914 e582bccc Stephen Beaver
			// Set the global color
915 78b4b127 Stephen Beaver
			gColor = color;
916 e582bccc Stephen Beaver
		});
917
	}
918
919 2794ddb4 Stephen Beaver
	// provide a warning message if the user tries to change page before saving
920 5d7b915d Stephen Beaver
	$(window).bind('beforeunload', function(){
921
		if ((!saving && dirty) || newSeperator) {
922
			return ("<?=gettext('You have moved one or more rules but have now yet saved')?>");
923
		} else {
924
			return undefined;
925
		}
926
	});
927
928 301e4aa0 Stephen Beaver
	//JS equivalent to PHP htmlspecialchars()
929 8a34b991 Stephen Beaver
	function escapeHtml(text) {
930
		var map = {
931
			'&': '&amp;',
932
			'<': '&lt;',
933
			'>': '&gt;',
934
			'"': '&quot;',
935
			"'": '&#039;'
936
		};
937
938
		return text.replace(/[&<>"']/g, function(m) { return map[m]; });
939
	}
940 301e4aa0 Stephen Beaver
	// --------------------------------------------------------------------------------------------
941 65a0e193 Stephen Beaver
});
942 8fd9052f Colin Fleming
//]]>
943 ea5665c7 Sjon Hortensius
</script>
944 824329d2 Stephen Beaver
945 c9d46a8e Renato Botelho
<?php include("foot.inc");?>