Project

General

Profile

Download (36.4 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 check_for_advanced_options(&$item) {
55
	$item_set = "";
56
	if($item['max'])
57
		$item_set .= "max {$item['max']} ";
58
	if($item['max-src-nodes'])
59
		$item_set .= "max-src-nodes {$item['max-src-nodes']} ";
60
	if($item['max-src-conn'])
61
		$item_set .= "max-src-conn {$item['max-src-conn']} ";
62
	if($item['max-src-states'])
63
		$item_set .= "max-src-states {$item['max-src-states']} ";
64
	if($item['statetype'] != "keep state" && $item['statetype'] != "")
65
		$item_set .= "statetype {$item['statetype']} ";
66
	if($item['statetimeout'])
67
		$item_set .= "statetimeout {$item['statetimeout']} ";
68
	if($item['nosync'])
69
		$item_set .= "nosync ";
70
	if($item['max-src-conn-rate'])
71
		$item_set .= "max-src-conn-rate {$item['max-src-conn-rate']} ";
72
	if($item['max-src-conn-rates'])
73
		$item_set .= "max-src-conn-rates {$item['max-src-conn-rates']} ";
74
	if($item['gateway'])
75
		$item_set .= "gateway {$item['gateway']} ";
76
	if($item['dnpipe'])
77
		$item_set .= "limiter {$item['dnpipe']} ";
78
	if($item['pdnpipe'])
79
		$item_set .= "limiter {$item['pdnpipe']} ";
80
	if($item['l7container'])
81
		$item_set .= "layer7 {$item['l7container']} ";
82
	if($item['tag'])
83
		$item_set .= "tag {$item['tag']} ";
84
	if($item['tagged'])
85
		$item_set .= "tagged {$item['tagged']} ";
86
	if(isset($item['allowopts']))
87
		$item_set .= "allowopts ";
88
	if(isset($item['disablereplyto']))
89
		$item_set .= "disable reply-to";
90
	if($item['tcpflags_any'] || $item['tcpflags1'] || $item['tcpflags2'])
91
		$item_set .= "tcpflags set";
92
	
93
	return $item_set;
94
}
95

    
96
function delete_nat_association($id) {
97
	global $config;
98

    
99
	if (!$id || !is_array($config['nat']['rule']))
100
		return;
101

    
102
	$a_nat = &$config['nat']['rule'];
103

    
104
	foreach ($a_nat as &$natent)
105
		if ($natent['associated-rule-id'] == $id)
106
			$natent['associated-rule-id'] = '';
107
}
108

    
109
if (!is_array($config['filter']['rule'])) {
110
	$config['filter']['rule'] = array();
111
}
112
filter_rules_sort();
113
$a_filter = &$config['filter']['rule'];
114

    
115
$if = $_GET['if'];
116
if ($_POST['if'])
117
	$if = $_POST['if'];
118

    
119
$ifdescs = get_configured_interface_with_descr();
120

    
121
// Drag and drop reordering
122
if($_REQUEST['dragdroporder']) {
123
	// First create a new ruleset array and tmp arrays
124
	$a_filter_unorder = array();
125
	$a_filter_order = array();
126
	$a_filter_order_tmp = array();
127
	// Pointer to id of item being reordered
128
	$found = 0;
129
	$drag_order = $_REQUEST['dragtable'];
130
	// Next traverse through rules building a new order for interface
131
	for ($i = 0; isset($a_filter[$i]); $i++) {
132
		if($a_filter[$i]['interface'] <> $_REQUEST['if']) 
133
			$a_filter_unorder[] = $a_filter[$i];
134
		else 
135
			$a_filter_order_tmp[] = $a_filter[$i];
136
	}
137
	// Reorder rules with the posted order
138
	for ($i = 0; $i<count($drag_order); $i++) 
139
		$a_filter_order[] = $a_filter_order_tmp[$drag_order[$i]];
140
	unset($config['filter']['rule']);
141
	// Overwrite filter rules with newly created items
142
	$config['filter']['rule'] = $a_filter_order;
143
	foreach($a_filter_unorder as $aa) 
144
		$config['filter']['rule'][] = $aa;
145
	// Write configuration
146
	$config = write_config("Drag and drop firewall rules ordering update.");
147
	// Redirect back to page
148
	mark_subsystem_dirty('filter');
149
	$undo = array();
150
	foreach($_REQUEST['dragtable'] as $dt) 
151
		$undo[] = "";
152
	$counter = 0;
153
	foreach($_REQUEST['dragtable'] as $dt) {
154
		$undo[$dt] = $counter;
155
		$counter++;
156
	}
157
	foreach($undo as $dt) 
158
		$undotxt .= "&dragtable[]={$dt}";
159
	Header("Location: firewall_rules.php?if=" . $_REQUEST['if'] . "&undodrag=true" . $undotxt);
160
	exit;
161
}
162

    
163
/* add group interfaces */
164
if (is_array($config['ifgroups']['ifgroupentry']))
165
	foreach($config['ifgroups']['ifgroupentry'] as $ifgen)
166
		if (have_ruleint_access($ifgen['ifname']))
167
			$iflist[$ifgen['ifname']] = $ifgen['ifname'];
168

    
169
foreach ($ifdescs as $ifent => $ifdesc)
170
	if(have_ruleint_access($ifent)) 
171
		$iflist[$ifent] = $ifdesc;
172

    
173
if ($config['l2tp']['mode'] == "server")
174
        if(have_ruleint_access("l2tp"))
175
                $iflist['l2tp'] = "L2TP VPN";
176

    
177
if ($config['pptpd']['mode'] == "server")
178
	if(have_ruleint_access("pptp")) 
179
		$iflist['pptp'] = "PPTP VPN";
180

    
181
if ($config['pppoe']['mode'] == "server")
182
	if(have_ruleint_access("pppoe")) 
183
		$iflist['pppoe'] = "PPPoE VPN";
184

    
185
/* add ipsec interfaces */
186
if (isset($config['ipsec']['enable']) || isset($config['ipsec']['mobileclients']['enable']))
187
	if(have_ruleint_access("enc0")) 
188
		$iflist["enc0"] = "IPsec";
189

    
190
/* add openvpn/tun interfaces */
191
if  ($config['openvpn']["openvpn-server"] || $config['openvpn']["openvpn-client"])
192
   	$iflist["openvpn"] = "OpenVPN";
193

    
194
if (!$if || !isset($iflist[$if])) {
195
	if ("any" == $if)
196
                $if = "FloatingRules";
197
        else if ("FloatingRules" != $if)
198
                $if = "wan";
199
}
200

    
201
if ($_POST) {
202

    
203
	$pconfig = $_POST;
204

    
205
	if ($_POST['apply']) {
206
		$retval = 0;
207
		$retval = filter_configure();
208

    
209
		clear_subsystem_dirty('filter');
210

    
211
		$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>");
212
	}
213
}
214

    
215
if ($_GET['act'] == "del") {
216
	if ($a_filter[$_GET['id']]) {
217
		if (!empty($a_filter[$_GET['id']]['associated-rule-id'])) {
218
			delete_nat_association($a_filter[$_GET['id']]['associated-rule-id']);
219
		}
220
		unset($a_filter[$_GET['id']]);
221
		write_config();
222
		mark_subsystem_dirty('filter');
223
		header("Location: firewall_rules.php?if={$if}");
224
		exit;
225
	}
226
}
227

    
228
// Handle save msg if defined
229
if($_REQUEST['savemsg']) 
230
	$savemsg = htmlentities($_REQUEST['savemsg']);
231

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

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

    
275
		/* copy all selected rules */
276
		for ($i = 0; $i < count($a_filter); $i++) {
277
			if ($i == $movebtn)
278
				continue;
279
			if (in_array($i, $_POST['rule']))
280
				$a_filter_new[] = $a_filter[$i];
281
		}
282

    
283
		/* copy $movebtn rule */
284
		if ($movebtn < count($a_filter))
285
			$a_filter_new[] = $a_filter[$movebtn];
286

    
287
		/* copy all rules > $movebtn and not selected */
288
		for ($i = $movebtn+1; $i < count($a_filter); $i++) {
289
			if (!in_array($i, $_POST['rule']))
290
				$a_filter_new[] = $a_filter[$i];
291
		}
292

    
293
		$a_filter = $a_filter_new;
294
		write_config();
295
		mark_subsystem_dirty('filter');
296
		header("Location: firewall_rules.php?if={$if}");
297
		exit;
298
	}
299
}
300
$closehead = false;
301

    
302
include("head.inc");
303

    
304
echo "<script type=\"text/javascript\" language=\"javascript\" src=\"/javascript/domTT/domLib.js\"></script>";
305
echo "<script type=\"text/javascript\" language=\"javascript\" src=\"/javascript/domTT/domTT.js\"></script>";
306
echo "<script type=\"text/javascript\" language=\"javascript\" src=\"/javascript/domTT/behaviour.js\"></script>";
307
echo "<script type=\"text/javascript\" language=\"javascript\" src=\"/javascript/domTT/fadomatic.js\"></script>";
308
?>
309
</head>
310

    
311
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
312
<?php include("fbegin.inc"); ?>
313
<form action="firewall_rules.php" method="post">
314

    
315
<script type="text/javascript" language="javascript" src="/javascript/row_toggle.js">
316
</script>
317
<?php if ($savemsg) print_info_box($savemsg); ?>
318
<?php if (is_subsystem_dirty('filter')): ?><p>
319
<?php
320
if($_REQUEST['undodrag']) {
321
	foreach($_REQUEST['dragtable'] as $dt) 
322
		$dragtable .= "&dragtable[]={$dt}";
323
	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}");
324
} else {
325
	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."));
326
}
327
?>
328
<br>
329
<?php endif; ?>
330
<div id="loading" style="visibity:hidden">
331
	<img src="/themes/<?=$g['theme']?>/images/misc/loader.gif"> Loading, please wait...
332
	<p/>&nbsp;
333
</div>
334
<table width="100%" border="0" cellpadding="0" cellspacing="0">
335
  <tr><td class="tabnavtbl">
336
  <?php
337
	/* active tabs */
338
	$tab_array = array();
339
       if ("FloatingRules" == $if)
340
                        $active = true;
341
                else
342
                        $active = false;
343
        $tab_array[] = array(gettext("Floating"), $active, "firewall_rules.php?if=FloatingRules");
344
	$tabscounter = 0; $i = 0; foreach ($iflist as $ifent => $ifname) {
345
		if ($ifent == $if)
346
			$active = true;
347
		else
348
			$active = false;
349
		$tab_array[] = array($ifname, $active, "firewall_rules.php?if={$ifent}");
350
	}
351
	display_top_tabs($tab_array);
352
  ?>
353
  </td></tr>
354
  <tr>
355
    <td>
356
	<div id="mainarea">
357
              <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
358
                <tr id="frheader">
359
                  <td width="3%" class="list">&nbsp;</td>
360
                  <td width="5%" class="list">&nbsp;</td>
361
                  <td width="3%" class="listhdrr"><?=gettext("ID");?></td>
362
                  <td width="6%" class="listhdrr"><?=gettext("Proto");?></td>
363
                  <td width="12%" class="listhdrr"><?=gettext("Source");?></td>
364
                  <td width="6%" class="listhdrr"><?=gettext("Port");?></td>
365
                  <td width="12%" class="listhdrr"><?=gettext("Destination");?></td>
366
                  <td width="6%" class="listhdrr"><?=gettext("Port");?></td>
367
		  <td width="5%" class="listhdrr"><?=gettext("Gateway");?></td>
368
		  <td width="8%" class="listhdrr"><?=gettext("Queue");?></td>
369
		  <td width="5%" class="listhdrr"><?=gettext("Schedule");?></td>
370
                  <td width="19%" class="listhdr"><?=gettext("Description");?></td>
371
                  <td width="10%" class="list">
372
			<table border="0" cellspacing="0" cellpadding="1">
373
			   <tr>
374
				<?php
375
					$nrules = 0;
376
					for ($i = 0; isset($a_filter[$i]); $i++) {
377
						$filterent = $a_filter[$i];
378
						if ($filterent['interface'] != $if && !isset($filterent['floating']))
379
							continue;
380
						if (isset($filterent['floating']) && "FloatingRules" != $if)
381
							continue;
382
						$nrules++;
383
					}
384
				?>
385
				<td>
386
				<?php if ($nrules == 0): ?>
387
				<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x_d.gif" width="17" height="17" title="<?gettext("delete selected rules"); ?>" border="0"><?php else: ?>
388
				<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; ?>
389
				</td>
390
				<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>
391
			   </tr>
392
			</table>
393
		  </td>
394
		</tr>
395
<?php if (isset($config['interfaces'][$if]['blockpriv'])): ?>
396
                <tr valign="top" id="frrfc1918">
397
                  <td class="list">&nbsp;</td>
398
                  <td class="listt" align="center"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_block.gif" width="11" height="11" border="0"></td>
399
                  <td class="listlr" style="background-color: #E0E0E0"></td>
400
                  <td class="listr" style="background-color: #E0E0E0">*</td>
401
                  <td class="listr" style="background-color: #E0E0E0"><?=gettext("RFC 1918 networks");?></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">*</td>
406
		<td class="listr" style="background-color: #E0E0E0">*</td>
407
	 		 <td class="listr" style="background-color: #E0E0E0"></td>
408
                  <td class="listbg"><?=gettext("Block private networks");?></td>
409
                  <td valign="middle" nowrap class="list">
410
				    <table border="0" cellspacing="0" cellpadding="1">
411
					<tr>
412
					  <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>
413
					  <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>
414
					</tr>
415
					<tr>
416
					  <td align="center" valign="middle"></td>
417
					  <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>
418
					</tr>
419
					</table>
420
				  </td>
421
				</tr>
422
<?php endif; ?>
423
<?php if (isset($config['interfaces'][$if]['blockbogons'])): ?>
424
                <tr valign="top" id="frrfc1918">
425
                  <td class="list">&nbsp;</td>
426
                  <td class="listt" align="center"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_block.gif" width="11" height="11" border="0"></td>
427
                  <td class="listlr" style="background-color: #E0E0E0"></td>
428
                  <td class="listr" style="background-color: #E0E0E0">*</td>
429
                  <td class="listr" style="background-color: #E0E0E0"><?=gettext("Reserved/not assigned by IANA");?></td>
430
                  <td class="listr" style="background-color: #E0E0E0">*</td>
431
                  <td class="listr" style="background-color: #E0E0E0">*</td>
432
                  <td class="listr" style="background-color: #E0E0E0">*</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="listbg"><?=gettext("Block bogon networks");?></td>
437
                  <td valign="middle" nowrap class="list">
438
				    <table border="0" cellspacing="0" cellpadding="1">
439
					<tr>
440
					  <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>
441
					  <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>
442
					</tr>
443
					<tr>
444
					  <td align="center" valign="middle"></td>
445
					  <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>
446
					</tr>
447
					</table>
448
				  </td>
449
				</tr>
450
<?php endif; ?>
451
				<tbody id="dragtable" width="100%">
452
				<?php $nrules = 0; for ($i = 0; isset($a_filter[$i]); $i++):
453
					$filterent = $a_filter[$i];
454
					if ($filterent['interface'] != $if && !isset($filterent['floating']))
455
						continue;
456
					if (isset($filterent['floating']) && "FloatingRules" != $if)
457
						continue;
458
					$isadvset = heck_for_advanced_options($filterent);
459
					if($isadvset)
460
						$advanced_set = "<img src=\"./themes/{$g['theme']}/images/icons/icon_advanced.gif\" title=\"" . gettext("advanced settings set") . ": {$isadvset}\" border=\"0\">";
461
					else 
462
						$advanced_set = ""
463
				?>
464
                <tr valign="top" id="fr<?=$nrules;?>">
465
                  <td class="listt">
466
					<input type="checkbox" id="frc<?=$nrules;?>" name="rule[]" value="<?=$i;?>" onClick="fr_bgcolor('<?=$nrules;?>')" style="margin: 0; padding: 0; width: 15px; height: 15px;">
467
					<?php echo $advanced_set; ?>
468
				  </td>
469
                  <td class="listt" align="center">
470
				  <?php if ($filterent['type'] == "block")
471
				  			$iconfn = "block";
472
						else if ($filterent['type'] == "reject") {
473
							$iconfn = "reject";
474
						} else
475
							$iconfn = "pass";
476
						if (isset($filterent['disabled'])) {
477
							$textss = "<span class=\"gray\">";
478
							$textse = "</span>";
479
							$iconfn .= "_d";
480
						} else {
481
							$textss = $textse = "";
482
						}
483
				  ?>
484
				  <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>
485
				  <?php if (isset($filterent['log'])):
486
							$iconfnlog = "log_s";
487
						if (isset($filterent['disabled']))
488
							$iconfnlog .= "_d";
489
				  	?>
490
				  <br><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_<?=$iconfnlog;?>.gif" width="11" height="15" border="0">
491
				  <?php endif; ?>
492
				  </td>
493
				<?php
494
				
495
				//build Alias popup box
496
				$span_end = "";
497
				$alias_src_span_begin = "";
498
				$alias_src_port_span_begin = "";
499
				$alias_dst_span_begin = "";
500
				$alias_dst_port_span_begin = "";
501
				
502
				$alias_popup = rule_popup($filterent['source']['address'],pprint_port($filterent['source']['port']),$filterent['destination']['address'],pprint_port($filterent['destination']['port']));
503
				$span_end = "</U></span>";
504
					
505
				$alias_src_span_begin = $alias_popup["src"];
506
				 									
507
				$alias_src_port_span_begin = $alias_popup["srcport"];
508
													
509
				$alias_dst_span_begin = $alias_popup["dst"];
510
														
511
				$alias_dst_port_span_begin = $alias_popup["dstport"];
512
					
513
				//build Schedule popup box
514
				$a_schedules = &$config['schedules']['schedule'];
515
				$schedule_span_begin = "";
516
				$schedule_span_end = "";
517
				$sched_caption_escaped = "";
518
				$sched_content = "";
519
				$schedstatus = false;
520
				$dayArray = array (gettext('Mon'),gettext('Tues'),gettext('Wed'),gettext('Thur'),gettext('Fri'),gettext('Sat'),gettext('Sun'));
521
				$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'));
522
				if($config['schedules']['schedule'] <> "" and is_array($config['schedules']['schedule'])){
523
					foreach ($a_schedules as $schedule)
524
					{
525
						if ($schedule['name'] == $filterent['sched'] ){
526
							$schedstatus = filter_get_time_based_rule_status($schedule);
527
							
528
							foreach($schedule['timerange'] as $timerange) {
529
								$tempFriendlyTime = "";
530
								$tempID = "";
531
								$firstprint = false;
532
								if ($timerange){
533
									$dayFriendly = "";
534
									$tempFriendlyTime = "";							
535
										
536
									//get hours
537
									$temptimerange = $timerange['hour'];
538
									$temptimeseparator = strrpos($temptimerange, "-");
539
									
540
									$starttime = substr ($temptimerange, 0, $temptimeseparator); 
541
									$stoptime = substr ($temptimerange, $temptimeseparator+1); 
542
										
543
									if ($timerange['month']){
544
										$tempmontharray = explode(",", $timerange['month']);
545
										$tempdayarray = explode(",",$timerange['day']);
546
										$arraycounter = 0;
547
										$firstDayFound = false;
548
										$firstPrint = false;
549
										foreach ($tempmontharray as $monthtmp){
550
											$month = $tempmontharray[$arraycounter];
551
											$day = $tempdayarray[$arraycounter];
552
											
553
											if (!$firstDayFound)
554
											{
555
												$firstDay = $day;
556
												$firstmonth = $month;
557
												$firstDayFound = true;
558
											}
559
												
560
											$currentDay = $day;
561
											$nextDay = $tempdayarray[$arraycounter+1];
562
											$currentDay++;
563
											if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])){
564
												if ($firstPrint)
565
													$dayFriendly .= ", ";
566
												$currentDay--;
567
												if ($currentDay != $firstDay)
568
													$dayFriendly .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
569
												else
570
													$dayFriendly .=  $monthArray[$month-1] . " " . $day;
571
												$firstDayFound = false;	
572
												$firstPrint = true;
573
											}													
574
											$arraycounter++;	
575
										}
576
									}
577
									else
578
									{
579
										$tempdayFriendly = $timerange['position'];
580
										$firstDayFound = false;
581
										$tempFriendlyDayArray = explode(",", $tempdayFriendly);								
582
										$currentDay = "";
583
										$firstDay = "";
584
										$nextDay = "";
585
										$counter = 0;													
586
										foreach ($tempFriendlyDayArray as $day){
587
											if ($day != ""){
588
												if (!$firstDayFound)
589
												{
590
													$firstDay = $tempFriendlyDayArray[$counter];
591
													$firstDayFound = true;
592
												}
593
												$currentDay =$tempFriendlyDayArray[$counter];
594
												//get next day
595
												$nextDay = $tempFriendlyDayArray[$counter+1];
596
												$currentDay++;					
597
												if ($currentDay != $nextDay){
598
													if ($firstprint)
599
														$dayFriendly .= ", ";
600
													$currentDay--;
601
													if ($currentDay != $firstDay)
602
														$dayFriendly .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
603
													else
604
														$dayFriendly .= $dayArray[$firstDay-1];
605
													$firstDayFound = false;	
606
													$firstprint = true;			
607
												}
608
												$counter++;
609
											}
610
										}
611
									}		
612
									$timeFriendly = $starttime . " - " . $stoptime;
613
									$description = $timerange['rangedescr'];
614
									$sched_content .= $dayFriendly . "; " . $timeFriendly . "<br>";
615
								}
616
							}
617
							$sched_caption_escaped = str_replace("'", "\'", $schedule['descr']);
618
							$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>";
619
							$schedule_span_end = "</U></span>";
620
						}
621
					}
622
				}
623
				$printicon = false;
624
				$alttext = "";
625
				$image = "";
626
				if (!isset($filterent['disabled'])){
627
					 if ($schedstatus) 
628
					 { 
629
					 	if ($iconfn == "block" || $iconfn == "reject")
630
					 	{
631
					 		$image = "icon_block";
632
					 		$alttext = gettext("Traffic matching this rule is currently being denied");
633
					 	}
634
					 	else
635
					 	{
636
					 		$image = "icon_pass";
637
					 		$alttext = gettext("Traffic matching this rule is currently being allowed");
638
					 	}
639
					 	$printicon = true;
640
					  }
641
					  else if ($filterent['sched'])
642
					  { 
643
					 	if ($iconfn == "block" || $iconfn == "reject")
644
					 		$image = "icon_block_d";
645
					 	else
646
					 		$image = "icon_block";
647
					 	$alttext = gettext("This rule is not currently active because its period has expired");
648
					 	$printicon = true;				  	
649
					  }
650
				}
651
				?>
652
                  <td class="listlr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
653
                    <?=$textss;?><?php if (isset($filterent['id'])) echo $filterent['id']; else echo ""; ?><?=$textse;?>
654
                  </td>
655
                  <td class="listr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
656
                    <?=$textss;?><?php if (isset($filterent['protocol'])) echo strtoupper($filterent['protocol']); else echo "*"; ?><?=$textse;?>
657
                  </td>
658
                  <td class="listr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
659
				    <?=$textss;?><?php echo $alias_src_span_begin;?><?php echo htmlspecialchars(pprint_address($filterent['source']));?><?php echo $alias_src_span_end;?><?=$textse;?>
660
                  </td>
661
                  <td class="listr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
662
                    <?=$textss;?><?php echo $alias_src_port_span_begin;?><?php echo htmlspecialchars(pprint_port($filterent['source']['port'])); ?><?php echo $alias_src_port_span_end;?><?=$textse;?>
663
                  </td>
664
                  <td class="listr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
665
				    <?=$textss;?><?php echo $alias_dst_span_begin;?><?php echo htmlspecialchars(pprint_address($filterent['destination'])); ?><?php echo $alias_dst_span_end;?><?=$textse;?>
666
                  </td>
667
	              <td class="listr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
668
                    <?=$textss;?><?php echo $alias_dst_port_span_begin;?><?php echo htmlspecialchars(pprint_port($filterent['destination']['port'])); ?><?php echo $alias_dst_port_span_end;?><?=$textse;?>
669
                  </td>
670
                  <td class="listr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
671
                    <?=$textss;?><?php if (isset($config['interfaces'][$filterent['gateway']]['descr'])) echo htmlspecialchars($config['interfaces'][$filterent['gateway']]['descr']); else  echo htmlspecialchars(pprint_port($filterent['gateway'])); ?><?=$textse;?>
672
                  </td>
673
				  <td class="listr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';"><?=$textss;?>
674
                          <?php
675
							if (isset($filterent['ackqueue']) && isset($filterent['defaultqueue'])) {
676
								$desc = $filterent['ackqueue'] ;
677
							    echo "<a href=\"firewall_shaper_queues.php?queue={$filterent['ackqueue']}&action=show\">{$desc}</a>";
678
								$desc = $filterent['defaultqueue'];
679
							    echo "/<a href=\"firewall_shaper_queues.php?queue={$filterent['defaultqueue']}&action=show\">{$desc}</a>";
680
							} else if (isset($filterent['defaultqueue'])) {
681
								$desc = $filterent['defaultqueue'];
682
							    echo "<a href=\"firewall_shaper_queues.php?queue={$filterent['defaultqueue']}&action=show\">{$desc}</a>"; }
683
							else echo gettext("none");
684
						  ?><?=$textse;?>
685
                        </td>
686
                  <td class="listr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';"><font color="black">
687
                    <?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;?>
688
                  </td>
689
                  <td class="listbg" onClick="fr_toggle(<?=$nrules;?>)" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';" class="descr">
690
                    <?=$textss;?><?=htmlspecialchars($filterent['descr']);?>&nbsp;<?=$textse;?>
691
                  </td>
692
                  <td valign="middle" nowrap class="list">
693
				    <table border="0" cellspacing="0" cellpadding="1">
694
					<tr>
695
					  <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>
696
					  <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>
697
					</tr>
698
					<tr>
699
					  <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>
700
					  <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>
701
					</tr>
702
					</table>
703
				  </td>
704
				</tr>
705
			  <?php $nrules++; endfor; ?>
706
			  </tbody>
707
			  <?php if ($nrules == 0): ?>
708
              <td class="listt"></td>
709
			  <td class="listt"></td>
710
			  <td class="listlr" colspan="10" align="center" valign="middle">
711
			  <span class="gray">
712
			  <?=gettext("No rules are currently defined for this interface"); ?><br>
713
			  <?=gettext("All incoming connections on this interface will be blocked until you add pass rules."); ?><br><br>
714
			  <?=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>
715
			  </td>
716
			  <?php endif; ?>
717
                <tr id="fr<?=$nrules;?>">
718
                  <td class="list"></td>
719
                  <td class="list"></td>
720
                  <td class="list">&nbsp;</td>
721
                  <td class="list">&nbsp;</td>
722
                  <td class="list">&nbsp;</td>
723
                  <td class="list">&nbsp;</td>
724
		  <td class="list">&nbsp;</td>
725
		  <td class="list">&nbsp;</td>
726
                  <td class="list">&nbsp;</td>
727
                  <td class="list">&nbsp;</td>
728
                  <td class="list">&nbsp;</td>
729
                  <td class="list">&nbsp;</td>
730
                  <td class="list">
731
				    <table border="0" cellspacing="0" cellpadding="1">
732
					<tr>
733
				      <td>
734
					  <?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>
735
					  <td></td>
736
				    </tr>
737
					<tr>
738
					  <td>
739
					  <?php if ($nrules == 0): ?>
740
					  <img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x_d.gif" width="17" height="17" title="<?=gettext("delete selected rules");?>" border="0"><?php else: ?>
741
					  <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; ?>
742
					  </td>
743
			                  <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>
744
					</tr>
745
				    </table>
746
				  </td>
747
				</tr>
748
              </table>
749
	      <table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0">
750
                <tr>
751
                  <td width="16"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_pass.gif" width="11" height="11"></td>
752
                  <td><?=gettext("pass");?></td>
753
                  <td width="14"></td>
754
                  <td width="16"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_block.gif" width="11" height="11"></td>
755
                  <td><?=gettext("block");?></td>
756
                  <td width="14"></td>
757
                  <td width="16"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_reject.gif" width="11" height="11"></td>
758
                  <td><?=gettext("reject");?></td>
759
                  <td width="14"></td>
760
                  <td width="16"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_log.gif" width="11" height="11"></td>
761
                  <td><?=gettext("log");?></td>
762
                </tr>
763
                <tr>
764
                  <td><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_pass_d.gif" width="11" height="11"></td>
765
                  <td nowrap><?=gettext("pass (disabled)");?></td>
766
                  <td>&nbsp;</td>
767
                  <td><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_block_d.gif" width="11" height="11"></td>
768
                  <td nowrap><?=gettext("block (disabled)");?></td>
769
                  <td>&nbsp;</td>
770
                  <td><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_reject_d.gif" width="11" height="11"></td>
771
                  <td nowrap><?=gettext("reject (disabled)");?></td>
772
                  <td>&nbsp;</td>
773
                  <td width="16"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_log_d.gif" width="11" height="11"></td>
774
                  <td nowrap><?=gettext("log (disabled)");?></td>
775
                </tr>
776
		<tr>
777
		  <td colspan="10">
778
  &nbsp;<p/>
779
  <strong>
780
	<span class="red"><?=gettext("Hint:");?></span>
781
  </strong><br>
782
	<ul>
783
  <li><?=gettext("Rules are evaluated on a first-match basis (i.e. " .
784
  "the action of the first rule to match a packet will be executed). " .
785
  "This means that if you use block rules, you'll have to pay attention " .
786
  "to the rule order. Everything that isn't explicitly passed is blocked " .
787
  "by default. ");?>
788
</li>
789
<li>
790
  <?=gettext("You may drag and drop rules using your mouse to reorder the rule ordering.");?>
791
</li>
792
</ul>
793
		 </td>
794
	        </tr>
795
              </table>
796
	</div>
797
    </td>
798
  </tr>
799
</table>
800
  <input type="hidden" name="if" value="<?=$if;?>">
801
  <script type="text/javascript">
802
	var number_of_rules = <?=$nrules?>;
803
<?php $nrules = 0; for ($i = 0; isset($a_filter[$i]); $i++): ?>
804
	Sortable.create("dragtable", { 
805
		tag:"tr", 
806
		format:"fr([0-9999999])",
807
		containment:["dragtable"], 
808
		onChange:function(affected) {
809
			document.body.style.cursor = 'move';
810
		},
811
		onUpdate:function(container) { 
812
			document.body.style.cursor = 'move';
813
			updateOrder(Sortable.serialize('dragtable', 'tr'));
814
		} 
815
	});
816
<?php endfor; ?>
817
	function updateOrder(order) {
818
		if(document.getElementById("redboxtable"))
819
			$('redboxtable').hide();
820
		$('loading').show();
821
		document.body.style.cursor = 'wait';
822
		document.location = 'firewall_rules.php?if=<?=$if?>&dragdroporder=true&' + Sortable.serialize('dragtable', 'tr');
823
		return;
824
	}
825
	$('loading').hide();
826
  </script>
827
</form>
828
<?php include("fend.inc"); ?>
829
</body>
830
</html>
(57-57/222)