Project

General

Profile

Download (38.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_before = array();
83
	$a_filter_order = array();
84
	$a_filter_order_tmp = array();
85
	$a_filter_after = array();
86
	$found = false;
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(( $_REQUEST['if'] == "FloatingRules" && isset($a_filter[$i]['floating']) ) || ( $a_filter[$i]['interface'] == $_REQUEST['if'] && !isset($a_filter[$i]['floating']) )) {
91
			$a_filter_order_tmp[] = $a_filter[$i];
92
			$found = true;
93
		} else if (!$found)
94
			$a_filter_before[] = $a_filter[$i];
95
		else
96
			$a_filter_after[] = $a_filter[$i];
97
	}
98
	// Reorder rules with the posted order
99
	for ($i = 0; $i<count($drag_order); $i++)
100
		$a_filter_order[] = $a_filter_order_tmp[$drag_order[$i]];
101
	// In case $drag_order didn't account for some rules, make sure we don't lose them
102
	if(count($a_filter_order) < count($a_filter_order_tmp)) {
103
		for ($i = 0; $i<count($a_filter_order_tmp); $i++)
104
			if(!in_array($i, $drag_order))
105
				$a_filter_order[] = $a_filter_order_tmp[$i];
106
	}
107
	// Overwrite filter rules with newly created items
108
	$config['filter']['rule'] = array_merge($a_filter_before, $a_filter_order, $a_filter_after);
109
	// Write configuration
110
	$config = write_config("Drag and drop firewall rules ordering update.");
111
	// Redirect back to page
112
	mark_subsystem_dirty('filter');
113
	$undo = array();
114
	foreach($_REQUEST['dragtable'] as $dt) 
115
		$undo[] = "";
116
	$counter = 0;
117
	foreach($_REQUEST['dragtable'] as $dt) {
118
		$undo[$dt] = $counter;
119
		$counter++;
120
	}
121
	foreach($undo as $dt) 
122
		$undotxt .= "&dragtable[]={$dt}";
123
	Header("Location: firewall_rules.php?if=" . $_REQUEST['if'] . "&undodrag=true" . $undotxt);
124
	exit;
125
}
126

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

    
147
/* add group interfaces */
148
if (is_array($config['ifgroups']['ifgroupentry']))
149
	foreach($config['ifgroups']['ifgroupentry'] as $ifgen)
150
		if (have_ruleint_access($ifgen['ifname']))
151
			$iflist[$ifgen['ifname']] = $ifgen['ifname'];
152

    
153
foreach ($ifdescs as $ifent => $ifdesc)
154
	if(have_ruleint_access($ifent)) 
155
		$iflist[$ifent] = $ifdesc;
156

    
157
if ($config['l2tp']['mode'] == "server")
158
        if(have_ruleint_access("l2tp"))
159
                $iflist['l2tp'] = "L2TP VPN";
160

    
161
if ($config['pptpd']['mode'] == "server")
162
	if(have_ruleint_access("pptp")) 
163
		$iflist['pptp'] = "PPTP VPN";
164

    
165
if (is_array($config['pppoes']['pppoe'])) {
166
	foreach ($config['pppoes']['pppoe'] as $pppoes)
167
		if (($pppoes['mode'] == 'server') && have_ruleint_access("pppoe"))
168
			$iflist['pppoe'] = "PPPoE Server";
169
}
170

    
171
/* add ipsec interfaces */
172
if (isset($config['ipsec']['enable']) || isset($config['ipsec']['mobileclients']['enable']))
173
	if(have_ruleint_access("enc0")) 
174
		$iflist["enc0"] = "IPsec";
175

    
176
/* add openvpn/tun interfaces */
177
if  ($config['openvpn']["openvpn-server"] || $config['openvpn']["openvpn-client"])
178
   	$iflist["openvpn"] = "OpenVPN";
179

    
180
if (!$if || !isset($iflist[$if])) {
181
	if ("any" == $if)
182
                $if = "FloatingRules";
183
        else if ("FloatingRules" != $if)
184
                $if = "wan";
185
}
186

    
187
if ($_POST) {
188

    
189
	$pconfig = $_POST;
190

    
191
	if ($_POST['apply']) {
192
		$retval = 0;
193
		$retval = filter_configure();
194

    
195
		clear_subsystem_dirty('filter');
196

    
197
		$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>");
198
	}
199
}
200

    
201
if ($_GET['act'] == "del") {
202
	if ($a_filter[$_GET['id']]) {
203
		if (!empty($a_filter[$_GET['id']]['associated-rule-id'])) {
204
			delete_nat_association($a_filter[$_GET['id']]['associated-rule-id']);
205
		}
206
		unset($a_filter[$_GET['id']]);
207
		write_config();
208
		mark_subsystem_dirty('filter');
209
		header("Location: firewall_rules.php?if={$if}");
210
		exit;
211
	}
212
}
213

    
214
// Handle save msg if defined
215
if($_REQUEST['savemsg']) 
216
	$savemsg = htmlentities($_REQUEST['savemsg']);
217

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

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

    
261
		/* copy all selected rules */
262
		for ($i = 0; $i < count($a_filter); $i++) {
263
			if ($i == $movebtn)
264
				continue;
265
			if (in_array($i, $_POST['rule']))
266
				$a_filter_new[] = $a_filter[$i];
267
		}
268

    
269
		/* copy $movebtn rule */
270
		if ($movebtn < count($a_filter))
271
			$a_filter_new[] = $a_filter[$movebtn];
272

    
273
		/* copy all rules > $movebtn and not selected */
274
		for ($i = $movebtn+1; $i < count($a_filter); $i++) {
275
			if (!in_array($i, $_POST['rule']))
276
				$a_filter_new[] = $a_filter[$i];
277
		}
278

    
279
		$a_filter = $a_filter_new;
280
		write_config();
281
		mark_subsystem_dirty('filter');
282
		header("Location: firewall_rules.php?if={$if}");
283
		exit;
284
	}
285
}
286
$closehead = false;
287

    
288
include("head.inc");
289

    
290
echo "<script type=\"text/javascript\" language=\"javascript\" src=\"/javascript/domTT/domLib.js\"></script>";
291
echo "<script type=\"text/javascript\" language=\"javascript\" src=\"/javascript/domTT/domTT.js\"></script>";
292
echo "<script type=\"text/javascript\" language=\"javascript\" src=\"/javascript/domTT/behaviour.js\"></script>";
293
echo "<script type=\"text/javascript\" language=\"javascript\" src=\"/javascript/domTT/fadomatic.js\"></script>";
294
?>
295
</head>
296

    
297
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
298
<?php include("fbegin.inc"); ?>
299
<form action="firewall_rules.php" method="post">
300

    
301
<script type="text/javascript" language="javascript" src="/javascript/row_toggle.js">
302
</script>
303
<?php if ($savemsg) print_info_box($savemsg); ?>
304
<?php if (is_subsystem_dirty('filter')): ?><p>
305
<?php
306
if($_REQUEST['undodrag']) {
307
	foreach($_REQUEST['dragtable'] as $dt) 
308
		$dragtable .= "&dragtable[]={$dt}";
309
	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}");
310
} else {
311
	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."));
312
}
313
?>
314
<br>
315
<?php endif; ?>
316
<div id="loading" style="visibity:hidden">
317
	<img src="/themes/<?=$g['theme']?>/images/misc/loader.gif"> Loading, please wait...
318
	<p/>&nbsp;
319
</div>
320
<table width="100%" border="0" cellpadding="0" cellspacing="0">
321
  <tr><td class="tabnavtbl">
322
  <?php
323
	/* active tabs */
324
	$tab_array = array();
325
       if ("FloatingRules" == $if)
326
                        $active = true;
327
                else
328
                        $active = false;
329
        $tab_array[] = array(gettext("Floating"), $active, "firewall_rules.php?if=FloatingRules");
330
	$tabscounter = 0; $i = 0; foreach ($iflist as $ifent => $ifname) {
331
		if ($ifent == $if)
332
			$active = true;
333
		else
334
			$active = false;
335
		$tab_array[] = array($ifname, $active, "firewall_rules.php?if={$ifent}");
336
	}
337
	display_top_tabs($tab_array);
338
  ?>
339
  </td></tr>
340
  <tr>
341
    <td>
342
	<div id="mainarea">
343
              <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
344
                <tr id="frheader">
345
                  <td width="3%" class="list">&nbsp;</td>
346
                  <td width="5%" class="list">&nbsp;</td>
347
                  <td width="3%" class="listhdrr"><?=gettext("ID");?></td>
348
                  <td width="6%" class="listhdrr"><?=gettext("Proto");?></td>
349
                  <td width="12%" class="listhdrr"><?=gettext("Source");?></td>
350
                  <td width="6%" class="listhdrr"><?=gettext("Port");?></td>
351
                  <td width="12%" class="listhdrr"><?=gettext("Destination");?></td>
352
                  <td width="6%" class="listhdrr"><?=gettext("Port");?></td>
353
		  <td width="5%" class="listhdrr"><?=gettext("Gateway");?></td>
354
		  <td width="8%" class="listhdrr"><?=gettext("Queue");?></td>
355
		  <td width="5%" class="listhdrr"><?=gettext("Schedule");?></td>
356
                  <td width="19%" class="listhdr"><?=gettext("Description");?></td>
357
                  <td width="10%" class="list">
358
			<table border="0" cellspacing="0" cellpadding="1">
359
			   <tr>
360
				<?php
361
					$nrules = 0;
362
					for ($i = 0; isset($a_filter[$i]); $i++) {
363
						$filterent = $a_filter[$i];
364
						if ($filterent['interface'] != $if && !isset($filterent['floating']))
365
							continue;
366
						if (isset($filterent['floating']) && "FloatingRules" != $if)
367
							continue;
368
						$nrules++;
369
					}
370
				?>
371
				<td>
372
				<?php if ($nrules == 0): ?>
373
				<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x_d.gif" width="17" height="17" title="<?gettext("delete selected rules"); ?>" border="0"><?php else: ?>
374
				<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; ?>
375
				</td>
376
				<td align="center" valign="middle"><a href="firewall_rules_edit.php?if=<?=htmlspecialchars($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>
377
			   </tr>
378
			</table>
379
		  </td>
380
		</tr>
381
<?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.
382
	if (!isset($config['system']['webgui']['noantilockout']) &&
383
		(((count($config['interfaces']) > 1) && ($if == 'lan'))
384
		|| ((count($config['interfaces']) == 1) && ($if == 'wan')))):
385

    
386
		$guiport = "80";
387
		if (isset($config['system']['webgui']['port']) && $config['system']['webgui']['port'] <> "")
388
			$guiport = "{$config['system']['webgui']['port']}";
389
		if ($config['system']['webgui']['protocol'] == "https")
390
			$guiport .= "<br/>443";
391

    
392
		$sshport = "";
393
		if (isset($config['system']['enablesshd'])) {
394
			$sshport = 22;
395
		if($config['system']['ssh']['port'] <> "")
396
			$sshport = $config['system']['ssh']['port'];
397
		}
398
		$sshport = "22<br/>";
399
?>
400
		<tr valign="top" id="antilockout">
401
			<td class="list">&nbsp;</td>
402
			<td class="listt" align="center"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_pass.gif" width="11" height="11" border="0"></td>
403
			<td class="listlr" style="background-color: #E0E0E0"></td>
404
			<td class="listr" style="background-color: #E0E0E0">*</td>
405
			<td class="listr" style="background-color: #E0E0E0">*</td>
406
			<td class="listr" style="background-color: #E0E0E0">*</td>
407
			<td class="listr" style="background-color: #E0E0E0"><?=$iflist[$if];?> Address</td>
408
			<td class="listr" style="background-color: #E0E0E0"><?= $sshport . $guiport ?></td>
409
			<td class="listr" style="background-color: #E0E0E0">*</td>
410
			<td class="listr" style="background-color: #E0E0E0">*</td>
411
			<td class="listr" style="background-color: #E0E0E0"></td>
412
			<td class="listbg"><?=gettext("Anti-Lockout Rule");?></td>
413
			<td valign="middle" nowrap class="list">
414
			<table border="0" cellspacing="0" cellpadding="1">
415
				<tr>
416
					<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>
417
					<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>
418
				</tr>
419
				<tr>
420
					<td align="center" valign="middle"></td>
421
					<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>
422
				</tr>
423
				</table>
424
			</td>
425
			</tr>
426
<?php endif; ?>
427

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