Project

General

Profile

Download (38.8 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 ($config['pppoe']['mode'] == "server")
166
	if(have_ruleint_access("pppoe")) 
167
		$iflist['pppoe'] = "PPPoE VPN";
168

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

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

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

    
185
if ($_POST) {
186

    
187
	$pconfig = $_POST;
188

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

    
193
		clear_subsystem_dirty('filter');
194

    
195
		$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>");
196
	}
197
}
198

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

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

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

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

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

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

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

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

    
286
include("head.inc");
287

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

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

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

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

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

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