Project

General

Profile

Download (37.9 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	firewall_rules.php
5
	part of pfSense (http://www.pfsense.com)
6
        Copyright (C) 2005 Scott Ullrich (sullrich@gmail.com)
7

    
8
	originally part of m0n0wall (http://m0n0.ch/wall)
9
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
10
	All rights reserved.
11

    
12
	Redistribution and use in source and binary forms, with or without
13
	modification, are permitted provided that the following conditions are met:
14

    
15
	1. Redistributions of source code must retain the above copyright notice,
16
	   this list of conditions and the following disclaimer.
17

    
18
	2. Redistributions in binary form must reproduce the above copyright
19
	   notice, this list of conditions and the following disclaimer in the
20
	   documentation and/or other materials provided with the distribution.
21

    
22
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
23
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
24
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
	POSSIBILITY OF SUCH DAMAGE.
32
*/
33
/*
34
	pfSense_MODULE:	filter
35
*/
36

    
37
##|+PRIV
38
##|*IDENT=page-firewall-rules
39
##|*NAME=Firewall: Rules page
40
##|*DESCR=Allow access to the 'Firewall: Rules' page.
41
##|*MATCH=firewall_rules.php*
42
##|-PRIV
43

    
44
$statusurl = "status_filter_reload.php";
45
$logurl = "diag_logs_filter.php";
46

    
47
require("guiconfig.inc");
48
require_once("functions.inc");
49
require_once("filter.inc");
50
require_once("shaper.inc");
51

    
52
$pgtitle = array(gettext("Firewall"),gettext("Rules"));
53

    
54
function delete_nat_association($id) {
55
	global $config;
56

    
57
	if (!$id || !is_array($config['nat']['rule']))
58
		return;
59

    
60
	$a_nat = &$config['nat']['rule'];
61

    
62
	foreach ($a_nat as &$natent)
63
		if ($natent['associated-rule-id'] == $id)
64
			$natent['associated-rule-id'] = '';
65
}
66

    
67
if (!is_array($config['filter']['rule'])) {
68
	$config['filter']['rule'] = array();
69
}
70
filter_rules_sort();
71
$a_filter = &$config['filter']['rule'];
72

    
73
$if = $_GET['if'];
74
if ($_POST['if'])
75
	$if = $_POST['if'];
76

    
77
$ifdescs = get_configured_interface_with_descr();
78

    
79
// Drag and drop reordering
80
if($_REQUEST['dragdroporder']) {
81
	// First create a new ruleset array and tmp arrays
82
	$a_filter_unorder = array();
83
	$a_filter_order = array();
84
	$a_filter_order_tmp = array();
85
	// Pointer to id of item being reordered
86
	$found = 0;
87
	$drag_order = $_REQUEST['dragtable'];
88
	// Next traverse through rules building a new order for interface
89
	for ($i = 0; isset($a_filter[$i]); $i++) {
90
		if($a_filter[$i]['interface'] <> $_REQUEST['if']) 
91
			$a_filter_unorder[] = $a_filter[$i];
92
		else 
93
			$a_filter_order_tmp[] = $a_filter[$i];
94
	}
95
	// Reorder rules with the posted order
96
	for ($i = 0; $i<count($drag_order); $i++) 
97
		$a_filter_order[] = $a_filter_order_tmp[$drag_order[$i]];
98
	unset($config['filter']['rule']);
99
	// Overwrite filter rules with newly created items
100
	$config['filter']['rule'] = $a_filter_order;
101
	foreach($a_filter_unorder as $aa) 
102
		$config['filter']['rule'][] = $aa;
103
	// Write configuration
104
	$config = write_config("Drag and drop firewall rules ordering update.");
105
	// Redirect back to page
106
	mark_subsystem_dirty('filter');
107
	$undo = array();
108
	foreach($_REQUEST['dragtable'] as $dt) 
109
		$undo[] = "";
110
	$counter = 0;
111
	foreach($_REQUEST['dragtable'] as $dt) {
112
		$undo[$dt] = $counter;
113
		$counter++;
114
	}
115
	foreach($undo as $dt) 
116
		$undotxt .= "&dragtable[]={$dt}";
117
	Header("Location: firewall_rules.php?if=" . $_REQUEST['if'] . "&undodrag=true" . $undotxt);
118
	exit;
119
}
120

    
121
$icmptypes = array(
122
	"" => gettext("any"),
123
	"echorep" => gettext("Echo reply"),
124
	"unreach" => gettext("Destination unreachable"),
125
	"squench" => gettext("Source quench"),
126
	"redir" => gettext("Redirect"),
127
	"althost" => gettext("Alternate Host"),
128
	"echoreq" => gettext("Echo"),
129
	"routeradv" => gettext("Router advertisement"),
130
	"routersol" => gettext("Router solicitation"),
131
	"timex" => gettext("Time exceeded"),
132
	"paramprob" => gettext("Invalid IP header"),
133
	"timereq" => gettext("Timestamp"),
134
	"timerep" => gettext("Timestamp reply"),
135
	"inforeq" => gettext("Information request"),
136
	"inforep" => gettext("Information reply"),
137
	"maskreq" => gettext("Address mask request"),
138
	"maskrep" => gettext("Address mask reply")
139
);
140

    
141
/* add group interfaces */
142
if (is_array($config['ifgroups']['ifgroupentry']))
143
	foreach($config['ifgroups']['ifgroupentry'] as $ifgen)
144
		if (have_ruleint_access($ifgen['ifname']))
145
			$iflist[$ifgen['ifname']] = $ifgen['ifname'];
146

    
147
foreach ($ifdescs as $ifent => $ifdesc)
148
	if(have_ruleint_access($ifent)) 
149
		$iflist[$ifent] = $ifdesc;
150

    
151
if ($config['l2tp']['mode'] == "server")
152
        if(have_ruleint_access("l2tp"))
153
                $iflist['l2tp'] = "L2TP VPN";
154

    
155
if ($config['pptpd']['mode'] == "server")
156
	if(have_ruleint_access("pptp")) 
157
		$iflist['pptp'] = "PPTP VPN";
158

    
159
if ($config['pppoe']['mode'] == "server")
160
	if(have_ruleint_access("pppoe")) 
161
		$iflist['pppoe'] = "PPPoE VPN";
162

    
163
/* add ipsec interfaces */
164
if (isset($config['ipsec']['enable']) || isset($config['ipsec']['mobileclients']['enable']))
165
	if(have_ruleint_access("enc0")) 
166
		$iflist["enc0"] = "IPsec";
167

    
168
/* add openvpn/tun interfaces */
169
if  ($config['openvpn']["openvpn-server"] || $config['openvpn']["openvpn-client"])
170
   	$iflist["openvpn"] = "OpenVPN";
171

    
172
if (!$if || !isset($iflist[$if])) {
173
	if ("any" == $if)
174
                $if = "FloatingRules";
175
        else if ("FloatingRules" != $if)
176
                $if = "wan";
177
}
178

    
179
if ($_POST) {
180

    
181
	$pconfig = $_POST;
182

    
183
	if ($_POST['apply']) {
184
		$retval = 0;
185
		$retval = filter_configure();
186

    
187
		clear_subsystem_dirty('filter');
188

    
189
		$savemsg = sprintf(gettext("The settings have been applied. The firewall rules are now reloading in the background. You can also %s monitor %s the reload progress"),"<a href='status_filter_reload.php'>","</a>");
190
	}
191
}
192

    
193
if ($_GET['act'] == "del") {
194
	if ($a_filter[$_GET['id']]) {
195
		if (!empty($a_filter[$_GET['id']]['associated-rule-id'])) {
196
			delete_nat_association($a_filter[$_GET['id']]['associated-rule-id']);
197
		}
198
		unset($a_filter[$_GET['id']]);
199
		write_config();
200
		mark_subsystem_dirty('filter');
201
		header("Location: firewall_rules.php?if={$if}");
202
		exit;
203
	}
204
}
205

    
206
// Handle save msg if defined
207
if($_REQUEST['savemsg']) 
208
	$savemsg = htmlentities($_REQUEST['savemsg']);
209

    
210
if (isset($_POST['del_x'])) {
211
	/* delete selected rules */
212
	if (is_array($_POST['rule']) && count($_POST['rule'])) {
213
		foreach ($_POST['rule'] as $rulei) {
214
			delete_nat_association($a_filter[$rulei]['associated-rule-id']);
215
			unset($a_filter[$rulei]);
216
		}
217
		write_config();
218
		mark_subsystem_dirty('filter');
219
		header("Location: firewall_rules.php?if={$if}");
220
		exit;
221
	}
222
} else if ($_GET['act'] == "toggle") {
223
	if ($a_filter[$_GET['id']]) {
224
                if(isset($a_filter[$_GET['id']]['disabled']))
225
                        unset($a_filter[$_GET['id']]['disabled']);
226
                else
227
                        $a_filter[$_GET['id']]['disabled'] = true;
228
		write_config();
229
		mark_subsystem_dirty('filter');
230
		header("Location: firewall_rules.php?if={$if}");
231
		exit;
232
	}
233
} else {
234
	/* yuck - IE won't send value attributes for image buttons, while Mozilla does -
235
	   so we use .x/.y to fine move button clicks instead... */
236
	unset($movebtn);
237
	foreach ($_POST as $pn => $pd) {
238
		if (preg_match("/move_(\d+)_x/", $pn, $matches)) {
239
			$movebtn = $matches[1];
240
			break;
241
		}
242
	}
243
	/* move selected rules before this rule */
244
	if (isset($movebtn) && is_array($_POST['rule']) && count($_POST['rule'])) {
245
		$a_filter_new = array();
246

    
247
		/* copy all rules < $movebtn and not selected */
248
		for ($i = 0; $i < $movebtn; $i++) {
249
			if (!in_array($i, $_POST['rule']))
250
				$a_filter_new[] = $a_filter[$i];
251
		}
252

    
253
		/* copy all selected rules */
254
		for ($i = 0; $i < count($a_filter); $i++) {
255
			if ($i == $movebtn)
256
				continue;
257
			if (in_array($i, $_POST['rule']))
258
				$a_filter_new[] = $a_filter[$i];
259
		}
260

    
261
		/* copy $movebtn rule */
262
		if ($movebtn < count($a_filter))
263
			$a_filter_new[] = $a_filter[$movebtn];
264

    
265
		/* copy all rules > $movebtn and not selected */
266
		for ($i = $movebtn+1; $i < count($a_filter); $i++) {
267
			if (!in_array($i, $_POST['rule']))
268
				$a_filter_new[] = $a_filter[$i];
269
		}
270

    
271
		$a_filter = $a_filter_new;
272
		write_config();
273
		mark_subsystem_dirty('filter');
274
		header("Location: firewall_rules.php?if={$if}");
275
		exit;
276
	}
277
}
278
$closehead = false;
279

    
280
include("head.inc");
281

    
282
echo "<script type=\"text/javascript\" language=\"javascript\" src=\"/javascript/domTT/domLib.js\"></script>";
283
echo "<script type=\"text/javascript\" language=\"javascript\" src=\"/javascript/domTT/domTT.js\"></script>";
284
echo "<script type=\"text/javascript\" language=\"javascript\" src=\"/javascript/domTT/behaviour.js\"></script>";
285
echo "<script type=\"text/javascript\" language=\"javascript\" src=\"/javascript/domTT/fadomatic.js\"></script>";
286
?>
287
</head>
288

    
289
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
290
<?php include("fbegin.inc"); ?>
291
<form action="firewall_rules.php" method="post">
292

    
293
<script type="text/javascript" language="javascript" src="/javascript/row_toggle.js">
294
</script>
295
<?php if ($savemsg) print_info_box($savemsg); ?>
296
<?php if (is_subsystem_dirty('filter')): ?><p>
297
<?php
298
if($_REQUEST['undodrag']) {
299
	foreach($_REQUEST['dragtable'] as $dt) 
300
		$dragtable .= "&dragtable[]={$dt}";
301
	print_info_box_np_undo(gettext("The firewall rule configuration has been changed.<br>You must apply the changes in order for them to take effect."), "apply" , gettext("Apply changes") , "firewall_rules.php?if={$_REQUEST['if']}&dragdroporder=true&{$dragtable}");
302
} else {
303
	print_info_box_np(gettext("The firewall rule configuration has been changed.<br>You must apply the changes in order for them to take effect."));
304
}
305
?>
306
<br>
307
<?php endif; ?>
308
<div id="loading" style="visibity:hidden">
309
	<img src="/themes/<?=$g['theme']?>/images/misc/loader.gif"> Loading, please wait...
310
	<p/>&nbsp;
311
</div>
312
<table width="100%" border="0" cellpadding="0" cellspacing="0">
313
  <tr><td class="tabnavtbl">
314
  <?php
315
	/* active tabs */
316
	$tab_array = array();
317
       if ("FloatingRules" == $if)
318
                        $active = true;
319
                else
320
                        $active = false;
321
        $tab_array[] = array(gettext("Floating"), $active, "firewall_rules.php?if=FloatingRules");
322
	$tabscounter = 0; $i = 0; foreach ($iflist as $ifent => $ifname) {
323
		if ($ifent == $if)
324
			$active = true;
325
		else
326
			$active = false;
327
		$tab_array[] = array($ifname, $active, "firewall_rules.php?if={$ifent}");
328
	}
329
	display_top_tabs($tab_array);
330
  ?>
331
  </td></tr>
332
  <tr>
333
    <td>
334
	<div id="mainarea">
335
              <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
336
                <tr id="frheader">
337
                  <td width="3%" class="list">&nbsp;</td>
338
                  <td width="5%" class="list">&nbsp;</td>
339
                  <td width="3%" class="listhdrr"><?=gettext("ID");?></td>
340
                  <td width="6%" class="listhdrr"><?=gettext("Proto");?></td>
341
                  <td width="12%" class="listhdrr"><?=gettext("Source");?></td>
342
                  <td width="6%" class="listhdrr"><?=gettext("Port");?></td>
343
                  <td width="12%" class="listhdrr"><?=gettext("Destination");?></td>
344
                  <td width="6%" class="listhdrr"><?=gettext("Port");?></td>
345
		  <td width="5%" class="listhdrr"><?=gettext("Gateway");?></td>
346
		  <td width="8%" class="listhdrr"><?=gettext("Queue");?></td>
347
		  <td width="5%" class="listhdrr"><?=gettext("Schedule");?></td>
348
                  <td width="19%" class="listhdr"><?=gettext("Description");?></td>
349
                  <td width="10%" class="list">
350
			<table border="0" cellspacing="0" cellpadding="1">
351
			   <tr>
352
				<?php
353
					$nrules = 0;
354
					for ($i = 0; isset($a_filter[$i]); $i++) {
355
						$filterent = $a_filter[$i];
356
						if ($filterent['interface'] != $if && !isset($filterent['floating']))
357
							continue;
358
						if (isset($filterent['floating']) && "FloatingRules" != $if)
359
							continue;
360
						$nrules++;
361
					}
362
				?>
363
				<td>
364
				<?php if ($nrules == 0): ?>
365
				<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x_d.gif" width="17" height="17" title="<?gettext("delete selected rules"); ?>" border="0"><?php else: ?>
366
				<input name="del" type="image" src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" title="<?=gettext("delete selected rules");?>" onclick="return confirm('<?=gettext('Do you really want to delete the selected rules?');?>')"><?php endif; ?>
367
				</td>
368
				<td align="center" valign="middle"><a href="firewall_rules_edit.php?if=<?=$if;?>&after=-1"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="<?=gettext("add new rule");?>" width="17" height="17" border="0"></a></td>
369
			   </tr>
370
			</table>
371
		  </td>
372
		</tr>
373
<?php   // 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.
374
	if (!isset($config['system']['webgui']['noantilockout']) &&
375
		(((count($config['interfaces']) > 1) && ($if == 'lan'))
376
		|| ((count($config['interfaces']) == 1) && ($if == 'wan')))): ?>
377
		<tr valign="top" id="antilockout">
378
			<td class="list">&nbsp;</td>
379
			<td class="listt" align="center"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_pass.gif" width="11" height="11" border="0"></td>
380
			<td class="listlr" style="background-color: #E0E0E0"></td>
381
			<td class="listr" style="background-color: #E0E0E0">*</td>
382
			<td class="listr" style="background-color: #E0E0E0">*</td>
383
			<td class="listr" style="background-color: #E0E0E0">*</td>
384
			<td class="listr" style="background-color: #E0E0E0"><?=$iflist[$if];?> Address</td>
385
			<td class="listr" style="background-color: #E0E0E0">*</td>
386
			<td class="listr" style="background-color: #E0E0E0">*</td>
387
			<td class="listr" style="background-color: #E0E0E0">*</td>
388
			<td class="listr" style="background-color: #E0E0E0"></td>
389
			<td class="listbg"><?=gettext("Anti-Lockout Rule");?></td>
390
			<td valign="middle" nowrap class="list">
391
			<table border="0" cellspacing="0" cellpadding="1">
392
				<tr>
393
					<td><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_left_d.gif" width="17" height="17" title="<?=gettext("move selected rules before this rule");?>"></td>
394
					<td><a href="system_advanced_admin.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" title="<?=gettext("edit rule");?>" width="17" height="17" border="0"></a></td>
395
				</tr>
396
				<tr>
397
					<td align="center" valign="middle"></td>
398
					<td><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus_d.gif" title="<?=gettext("add a new rule based on this one");?>" width="17" height="17" border="0"></td>
399
				</tr>
400
				</table>
401
			</td>
402
			</tr>
403
<?php endif; ?>
404

    
405
<?php if (isset($config['interfaces'][$if]['blockpriv'])): ?>
406
                <tr valign="top" id="frrfc1918">
407
                  <td class="list">&nbsp;</td>
408
                  <td class="listt" align="center"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_block.gif" width="11" height="11" border="0"></td>
409
                  <td class="listlr" style="background-color: #E0E0E0"></td>
410
                  <td class="listr" style="background-color: #E0E0E0">*</td>
411
                  <td class="listr" style="background-color: #E0E0E0"><?=gettext("RFC 1918 networks");?></td>
412
                  <td class="listr" style="background-color: #E0E0E0">*</td>
413
                  <td class="listr" style="background-color: #E0E0E0">*</td>
414
                  <td class="listr" style="background-color: #E0E0E0">*</td>
415
                  <td class="listr" style="background-color: #E0E0E0">*</td>
416
		<td class="listr" style="background-color: #E0E0E0">*</td>
417
	 		 <td class="listr" style="background-color: #E0E0E0"></td>
418
                  <td class="listbg"><?=gettext("Block private networks");?></td>
419
                  <td valign="middle" nowrap class="list">
420
				    <table border="0" cellspacing="0" cellpadding="1">
421
					<tr>
422
					  <td><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_left_d.gif" width="17" height="17" title="<?=gettext("move selected rules before this rule");?>"></td>
423
					  <td><a href="interfaces.php?if=<?=$if?>#rfc1918"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" title="<?=gettext("edit rule");?>" width="17" height="17" border="0"></a></td>
424
					</tr>
425
					<tr>
426
					  <td align="center" valign="middle"></td>
427
					  <td><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus_d.gif" title="<?=gettext("add a new rule based on this one");?>" width="17" height="17" border="0"></td>
428
					</tr>
429
					</table>
430
				  </td>
431
				</tr>
432
<?php endif; ?>
433
<?php if (isset($config['interfaces'][$if]['blockbogons'])): ?>
434
                <tr valign="top" id="frrfc1918">
435
                  <td class="list">&nbsp;</td>
436
                  <td class="listt" align="center"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_block.gif" width="11" height="11" border="0"></td>
437
                  <td class="listlr" style="background-color: #E0E0E0"></td>
438
                  <td class="listr" style="background-color: #E0E0E0">*</td>
439
                  <td class="listr" style="background-color: #E0E0E0"><?=gettext("Reserved/not assigned by IANA");?></td>
440
                  <td class="listr" style="background-color: #E0E0E0">*</td>
441
                  <td class="listr" style="background-color: #E0E0E0">*</td>
442
                  <td class="listr" style="background-color: #E0E0E0">*</td>
443
				  <td class="listr" style="background-color: #E0E0E0">*</td>
444
				   <td class="listr" style="background-color: #E0E0E0">*</td>
445
		  <td class="listr" style="background-color: #E0E0E0">*</td>
446
                  <td class="listbg"><?=gettext("Block bogon networks");?></td>
447
                  <td valign="middle" nowrap class="list">
448
				    <table border="0" cellspacing="0" cellpadding="1">
449
					<tr>
450
					  <td><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_left_d.gif" width="17" height="17" title="<?=gettext("move selected rules before this rule");?>"></td>
451
					  <td><a href="interfaces.php?if=<?=$if?>#rfc1918"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" title="<?=gettext("edit rule");?>" width="17" height="17" border="0"></a></td>
452
					</tr>
453
					<tr>
454
					  <td align="center" valign="middle"></td>
455
					  <td><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus_d.gif" title="<?=gettext("add a new rule based on this one");?>" width="17" height="17" border="0"></td>
456
					</tr>
457
					</table>
458
				  </td>
459
				</tr>
460
<?php endif; ?>
461
				<tbody id="dragtable" width="100%">
462
				<?php $nrules = 0; for ($i = 0; isset($a_filter[$i]); $i++):
463
					$filterent = $a_filter[$i];
464
					if ($filterent['interface'] != $if && !isset($filterent['floating']))
465
						continue;
466
					if (isset($filterent['floating']) && "FloatingRules" != $if)
467
						continue;
468
					$isadvset = firewall_check_for_advanced_options($filterent);
469
					if($isadvset)
470
						$advanced_set = "<img src=\"./themes/{$g['theme']}/images/icons/icon_advanced.gif\" title=\"" . gettext("advanced settings set") . ": {$isadvset}\" border=\"0\">";
471
					else 
472
						$advanced_set = ""
473
				?>
474
                <tr valign="top" id="fr<?=$nrules;?>">
475
                  <td class="listt">
476
					<input type="checkbox" id="frc<?=$nrules;?>" name="rule[]" value="<?=$i;?>" onClick="fr_bgcolor('<?=$nrules;?>')" style="margin: 0; padding: 0; width: 15px; height: 15px;">
477
					<?php echo $advanced_set; ?>
478
				  </td>
479
                  <td class="listt" align="center">
480
				  <?php if ($filterent['type'] == "block")
481
				  			$iconfn = "block";
482
						else if ($filterent['type'] == "reject") {
483
							$iconfn = "reject";
484
						} else
485
							$iconfn = "pass";
486
						if (isset($filterent['disabled'])) {
487
							$textss = "<span class=\"gray\">";
488
							$textse = "</span>";
489
							$iconfn .= "_d";
490
						} else {
491
							$textss = $textse = "";
492
						}
493
				  ?>
494
				  <a href="?if=<?=$if;?>&act=toggle&id=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_<?=$iconfn;?>.gif" width="11" height="11" border="0" title="<?=gettext("click to toggle enabled/disabled status");?>"></a>
495
				  <?php if (isset($filterent['log'])):
496
							$iconfnlog = "log_s";
497
						if (isset($filterent['disabled']))
498
							$iconfnlog .= "_d";
499
				  	?>
500
				  <br><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_<?=$iconfnlog;?>.gif" width="11" height="15" border="0">
501
				  <?php endif; ?>
502
				  </td>
503
				<?php
504
				
505
				//build Alias popup box
506
				$span_end = "";
507
				$alias_src_span_begin = "";
508
				$alias_src_port_span_begin = "";
509
				$alias_dst_span_begin = "";
510
				$alias_dst_port_span_begin = "";
511
				
512
				$alias_popup = rule_popup($filterent['source']['address'],pprint_port($filterent['source']['port']),$filterent['destination']['address'],pprint_port($filterent['destination']['port']));
513
				$span_end = "</U></span>";
514
					
515
				$alias_src_span_begin = $alias_popup["src"];
516
				 									
517
				$alias_src_port_span_begin = $alias_popup["srcport"];
518
													
519
				$alias_dst_span_begin = $alias_popup["dst"];
520
														
521
				$alias_dst_port_span_begin = $alias_popup["dstport"];
522
					
523
				//build Schedule popup box
524
				$a_schedules = &$config['schedules']['schedule'];
525
				$schedule_span_begin = "";
526
				$schedule_span_end = "";
527
				$sched_caption_escaped = "";
528
				$sched_content = "";
529
				$schedstatus = false;
530
				$dayArray = array (gettext('Mon'),gettext('Tues'),gettext('Wed'),gettext('Thur'),gettext('Fri'),gettext('Sat'),gettext('Sun'));
531
				$monthArray = array (gettext('January'),gettext('February'),gettext('March'),gettext('April'),gettext('May'),gettext('June'),gettext('July'),gettext('August'),gettext('September'),gettext('October'),gettext('November'),gettext('December'));
532
				if($config['schedules']['schedule'] <> "" and is_array($config['schedules']['schedule'])){
533
					foreach ($a_schedules as $schedule)
534
					{
535
						if ($schedule['name'] == $filterent['sched'] ){
536
							$schedstatus = filter_get_time_based_rule_status($schedule);
537
							
538
							foreach($schedule['timerange'] as $timerange) {
539
								$tempFriendlyTime = "";
540
								$tempID = "";
541
								$firstprint = false;
542
								if ($timerange){
543
									$dayFriendly = "";
544
									$tempFriendlyTime = "";							
545
										
546
									//get hours
547
									$temptimerange = $timerange['hour'];
548
									$temptimeseparator = strrpos($temptimerange, "-");
549
									
550
									$starttime = substr ($temptimerange, 0, $temptimeseparator); 
551
									$stoptime = substr ($temptimerange, $temptimeseparator+1); 
552
										
553
									if ($timerange['month']){
554
										$tempmontharray = explode(",", $timerange['month']);
555
										$tempdayarray = explode(",",$timerange['day']);
556
										$arraycounter = 0;
557
										$firstDayFound = false;
558
										$firstPrint = false;
559
										foreach ($tempmontharray as $monthtmp){
560
											$month = $tempmontharray[$arraycounter];
561
											$day = $tempdayarray[$arraycounter];
562
											
563
											if (!$firstDayFound)
564
											{
565
												$firstDay = $day;
566
												$firstmonth = $month;
567
												$firstDayFound = true;
568
											}
569
												
570
											$currentDay = $day;
571
											$nextDay = $tempdayarray[$arraycounter+1];
572
											$currentDay++;
573
											if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])){
574
												if ($firstPrint)
575
													$dayFriendly .= ", ";
576
												$currentDay--;
577
												if ($currentDay != $firstDay)
578
													$dayFriendly .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
579
												else
580
													$dayFriendly .=  $monthArray[$month-1] . " " . $day;
581
												$firstDayFound = false;	
582
												$firstPrint = true;
583
											}													
584
											$arraycounter++;	
585
										}
586
									}
587
									else
588
									{
589
										$tempdayFriendly = $timerange['position'];
590
										$firstDayFound = false;
591
										$tempFriendlyDayArray = explode(",", $tempdayFriendly);								
592
										$currentDay = "";
593
										$firstDay = "";
594
										$nextDay = "";
595
										$counter = 0;													
596
										foreach ($tempFriendlyDayArray as $day){
597
											if ($day != ""){
598
												if (!$firstDayFound)
599
												{
600
													$firstDay = $tempFriendlyDayArray[$counter];
601
													$firstDayFound = true;
602
												}
603
												$currentDay =$tempFriendlyDayArray[$counter];
604
												//get next day
605
												$nextDay = $tempFriendlyDayArray[$counter+1];
606
												$currentDay++;					
607
												if ($currentDay != $nextDay){
608
													if ($firstprint)
609
														$dayFriendly .= ", ";
610
													$currentDay--;
611
													if ($currentDay != $firstDay)
612
														$dayFriendly .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
613
													else
614
														$dayFriendly .= $dayArray[$firstDay-1];
615
													$firstDayFound = false;	
616
													$firstprint = true;			
617
												}
618
												$counter++;
619
											}
620
										}
621
									}		
622
									$timeFriendly = $starttime . " - " . $stoptime;
623
									$description = $timerange['rangedescr'];
624
									$sched_content .= $dayFriendly . "; " . $timeFriendly . "<br>";
625
								}
626
							}
627
							$sched_caption_escaped = str_replace("'", "\'", $schedule['descr']);
628
							$schedule_span_begin = "<span style=\"cursor: help;\" onmouseover=\"domTT_activate(this, event, 'content', '<h1>{$sched_caption_escaped}</h1><p>{$sched_content}</p>', 'trail', true, 'delay', 0, 'fade', 'both', 'fadeMax', 93, 'styleClass', 'niceTitle');\" onmouseout=\"this.style.color = ''; domTT_mouseout(this, event);\"><U>";
629
							$schedule_span_end = "</U></span>";
630
						}
631
					}
632
				}
633
				$printicon = false;
634
				$alttext = "";
635
				$image = "";
636
				if (!isset($filterent['disabled'])){
637
					 if ($schedstatus) 
638
					 { 
639
					 	if ($iconfn == "block" || $iconfn == "reject")
640
					 	{
641
					 		$image = "icon_block";
642
					 		$alttext = gettext("Traffic matching this rule is currently being denied");
643
					 	}
644
					 	else
645
					 	{
646
					 		$image = "icon_pass";
647
					 		$alttext = gettext("Traffic matching this rule is currently being allowed");
648
					 	}
649
					 	$printicon = true;
650
					  }
651
					  else if ($filterent['sched'])
652
					  { 
653
					 	if ($iconfn == "block" || $iconfn == "reject")
654
					 		$image = "icon_block_d";
655
					 	else
656
					 		$image = "icon_block";
657
					 	$alttext = gettext("This rule is not currently active because its period has expired");
658
					 	$printicon = true;				  	
659
					  }
660
				}
661
				?>
662
                  <td class="listlr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
663
                    <?=$textss;?><?php if (isset($filterent['id'])) echo $filterent['id']; else echo ""; ?><?=$textse;?>
664
                  </td>
665
                  <td class="listr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
666
                    <?=$textss;?><?php
667
			if (isset($filterent['protocol'])) {
668
				echo strtoupper($filterent['protocol']);
669
				if (strtoupper($filterent['protocol']) == "ICMP" && !empty($filterent['icmptype'])) {
670
					echo ' <span style="cursor: help;" title="ICMP type: ' . $icmptypes[$filterent['icmptype']] . '"><u>';
671
					echo $filterent['icmptype'];
672
					echo '</u></span>';
673
				}
674
			} else echo "*";
675
                    ?><?=$textse;?>
676
                  </td>
677
                  <td class="listr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
678
				    <?=$textss;?><?php echo $alias_src_span_begin;?><?php echo htmlspecialchars(pprint_address($filterent['source']));?><?php echo $alias_src_span_end;?><?=$textse;?>
679
                  </td>
680
                  <td class="listr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
681
                    <?=$textss;?><?php echo $alias_src_port_span_begin;?><?php echo htmlspecialchars(pprint_port($filterent['source']['port'])); ?><?php echo $alias_src_port_span_end;?><?=$textse;?>
682
                  </td>
683
                  <td class="listr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
684
				    <?=$textss;?><?php echo $alias_dst_span_begin;?><?php echo htmlspecialchars(pprint_address($filterent['destination'])); ?><?php echo $alias_dst_span_end;?><?=$textse;?>
685
                  </td>
686
	              <td class="listr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
687
                    <?=$textss;?><?php echo $alias_dst_port_span_begin;?><?php echo htmlspecialchars(pprint_port($filterent['destination']['port'])); ?><?php echo $alias_dst_port_span_end;?><?=$textse;?>
688
                  </td>
689
                  <td class="listr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
690
                    <?=$textss;?><?php if (isset($config['interfaces'][$filterent['gateway']]['descr'])) echo htmlspecialchars($config['interfaces'][$filterent['gateway']]['descr']); else  echo htmlspecialchars(pprint_port($filterent['gateway'])); ?><?=$textse;?>
691
                  </td>
692
				  <td class="listr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';"><?=$textss;?>
693
                          <?php
694
							if (isset($filterent['ackqueue']) && isset($filterent['defaultqueue'])) {
695
								$desc = $filterent['ackqueue'] ;
696
							    echo "<a href=\"firewall_shaper_queues.php?queue={$filterent['ackqueue']}&action=show\">{$desc}</a>";
697
								$desc = $filterent['defaultqueue'];
698
							    echo "/<a href=\"firewall_shaper_queues.php?queue={$filterent['defaultqueue']}&action=show\">{$desc}</a>";
699
							} else if (isset($filterent['defaultqueue'])) {
700
								$desc = $filterent['defaultqueue'];
701
							    echo "<a href=\"firewall_shaper_queues.php?queue={$filterent['defaultqueue']}&action=show\">{$desc}</a>"; }
702
							else echo gettext("none");
703
						  ?><?=$textse;?>
704
                        </td>
705
                  <td class="listr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';"><font color="black">
706
                    <?php if ($printicon) { ?><img src="./themes/<?= $g['theme']; ?>/images/icons/<?php echo $image; ?>.gif" title="<?php echo $alttext;?>" border="0"><?php } ?>&nbsp;<?=$textss;?><?php echo $schedule_span_begin;?><?=htmlspecialchars($filterent['sched']);?><?php echo $schedule_span_end; ?><?=$textse;?>
707
                  </td>
708
                  <td class="listbg" onClick="fr_toggle(<?=$nrules;?>)" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';" class="descr">
709
                    <?=$textss;?><?=htmlspecialchars($filterent['descr']);?>&nbsp;<?=$textse;?>
710
                  </td>
711
                  <td valign="middle" nowrap class="list">
712
				    <table border="0" cellspacing="0" cellpadding="1">
713
					<tr>
714
					  <td><input name="move_<?=$i;?>" type="image" src="./themes/<?= $g['theme']; ?>/images/icons/icon_left.gif" width="17" height="17" title="<?=gettext("move selected rules before this rule"); ?>" onMouseOver="fr_insline(<?=$nrules;?>, true)" onMouseOut="fr_insline(<?=$nrules;?>, false)"></td>
715
					  <td><a href="firewall_rules_edit.php?id=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" title="<?=gettext("edit rule"); ?>" width="17" height="17" border="0"></a></td>
716
					</tr>
717
					<tr>
718
					  <td align="center" valign="middle"><a href="firewall_rules.php?act=del&if=<?=$if;?>&id=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0" title="<?=gettext("delete rule"); ?>" onclick="return confirm('Do you really want to delete this rule?')"></a></td>
719
					  <td><a href="firewall_rules_edit.php?dup=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="<?=gettext("add a new rule based on this one"); ?>" width="17" height="17" border="0"></a></td>
720
					</tr>
721
					</table>
722
				  </td>
723
				</tr>
724
			  <?php $nrules++; endfor; ?>
725
			  </tbody>
726
			  <?php if ($nrules == 0): ?>
727
              <td class="listt"></td>
728
			  <td class="listt"></td>
729
			  <td class="listlr" colspan="10" align="center" valign="middle">
730
			  <span class="gray">
731
			  <?=gettext("No rules are currently defined for this interface"); ?><br>
732
			  <?=gettext("All incoming connections on this interface will be blocked until you add pass rules."); ?><br><br>
733
			  <?=gettext("Click the"); ?> <a href="firewall_rules_edit.php?if=<?=$if;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="<?=gettext("add new rule");?>" border="0" width="17" height="17" align="absmiddle"></a><?=gettext(" button to add a new rule.");?></span>
734
			  </td>
735
			  <?php endif; ?>
736
                <tr id="fr<?=$nrules;?>">
737
                  <td class="list"></td>
738
                  <td class="list"></td>
739
                  <td class="list">&nbsp;</td>
740
                  <td class="list">&nbsp;</td>
741
                  <td class="list">&nbsp;</td>
742
                  <td class="list">&nbsp;</td>
743
		  <td class="list">&nbsp;</td>
744
		  <td class="list">&nbsp;</td>
745
                  <td class="list">&nbsp;</td>
746
                  <td class="list">&nbsp;</td>
747
                  <td class="list">&nbsp;</td>
748
                  <td class="list">&nbsp;</td>
749
                  <td class="list">
750
				    <table border="0" cellspacing="0" cellpadding="1">
751
					<tr>
752
				      <td>
753
					  <?php if ($nrules == 0): ?><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_left_d.gif" width="17" height="17" title="<?=gettext("move selected rules to end");?>" border="0"><?php else: ?><input name="move_<?=$i;?>" type="image" src="./themes/<?= $g['theme']; ?>/images/icons/icon_left.gif" width="17" height="17" title="<?=gettext("move selected rules to end");?>" onMouseOver="fr_insline(<?=$nrules;?>, true)" onMouseOut="fr_insline(<?=$nrules;?>, false)"><?php endif; ?></td>
754
					  <td></td>
755
				    </tr>
756
					<tr>
757
					  <td>
758
					  <?php if ($nrules == 0): ?>
759
					  <img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x_d.gif" width="17" height="17" title="<?=gettext("delete selected rules");?>" border="0"><?php else: ?>
760
					  <input name="del" type="image" src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" title="<?=gettext("delete selected rules");?>" onclick="return confirm('<?=gettext('Do you really want to delete the selected rules?');?>')"><?php endif; ?>
761
					  </td>
762
			                  <td><a href="firewall_rules_edit.php?if=<?=$if;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="<?=gettext("add new rule");?>" width="17" height="17" border="0"></a></td>
763
					</tr>
764
				    </table>
765
				  </td>
766
				</tr>
767
              </table>
768
	      <table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0">
769
                <tr>
770
                  <td width="16"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_pass.gif" width="11" height="11"></td>
771
                  <td><?=gettext("pass");?></td>
772
                  <td width="14"></td>
773
                  <td width="16"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_block.gif" width="11" height="11"></td>
774
                  <td><?=gettext("block");?></td>
775
                  <td width="14"></td>
776
                  <td width="16"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_reject.gif" width="11" height="11"></td>
777
                  <td><?=gettext("reject");?></td>
778
                  <td width="14"></td>
779
                  <td width="16"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_log.gif" width="11" height="11"></td>
780
                  <td><?=gettext("log");?></td>
781
                </tr>
782
                <tr>
783
                  <td><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_pass_d.gif" width="11" height="11"></td>
784
                  <td nowrap><?=gettext("pass (disabled)");?></td>
785
                  <td>&nbsp;</td>
786
                  <td><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_block_d.gif" width="11" height="11"></td>
787
                  <td nowrap><?=gettext("block (disabled)");?></td>
788
                  <td>&nbsp;</td>
789
                  <td><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_reject_d.gif" width="11" height="11"></td>
790
                  <td nowrap><?=gettext("reject (disabled)");?></td>
791
                  <td>&nbsp;</td>
792
                  <td width="16"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_log_d.gif" width="11" height="11"></td>
793
                  <td nowrap><?=gettext("log (disabled)");?></td>
794
                </tr>
795
		<tr>
796
		  <td colspan="10">
797
  &nbsp;<p/>
798
  <strong>
799
	<span class="red"><?=gettext("Hint:");?></span>
800
  </strong><br>
801
	<ul>
802
  <li><?=gettext("Rules are evaluated on a first-match basis (i.e. " .
803
  "the action of the first rule to match a packet will be executed). " .
804
  "This means that if you use block rules, you'll have to pay attention " .
805
  "to the rule order. Everything that isn't explicitly passed is blocked " .
806
  "by default. ");?>
807
</li>
808
<li>
809
  <?=gettext("You may drag and drop rules using your mouse to reorder the rule ordering.");?>
810
</li>
811
</ul>
812
		 </td>
813
	        </tr>
814
              </table>
815
	</div>
816
    </td>
817
  </tr>
818
</table>
819
  <input type="hidden" name="if" value="<?=$if;?>">
820
  <script type="text/javascript">
821
	var number_of_rules = <?=$nrules?>;
822
<?php $nrules = 0; for ($i = 0; isset($a_filter[$i]); $i++): ?>
823
	Sortable.create("dragtable", { 
824
		tag:"tr", 
825
		format:"fr([0-9999999])",
826
		containment:["dragtable"], 
827
		onChange:function(affected) {
828
			document.body.style.cursor = 'move';
829
		},
830
		onUpdate:function(container) { 
831
			document.body.style.cursor = 'move';
832
			updateOrder(Sortable.serialize('dragtable', 'tr'));
833
		} 
834
	});
835
<?php endfor; ?>
836
	function updateOrder(order) {
837
		if(document.getElementById("redboxtable"))
838
			$('redboxtable').hide();
839
		$('loading').show();
840
		document.body.style.cursor = 'wait';
841
		document.location = 'firewall_rules.php?if=<?=$if?>&dragdroporder=true&' + Sortable.serialize('dragtable', 'tr');
842
		return;
843
	}
844
	$('loading').hide();
845
  </script>
846
</form>
847
<?php include("fend.inc"); ?>
848
</body>
849
</html>
(56-56/220)