Project

General

Profile

Download (35.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 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
	return $item_set;
75
}
76

    
77
function delete_nat_association($id) {
78
	global $config;
79

    
80
	if (!$id || !is_array($config['nat']['rule']))
81
		return;
82

    
83
	$a_nat = &$config['nat']['rule'];
84

    
85
	foreach ($a_nat as &$natent)
86
		if ($natent['associated-rule-id'] == $id)
87
			$natent['associated-rule-id'] = '';
88
}
89

    
90
if (!is_array($config['filter']['rule'])) {
91
	$config['filter']['rule'] = array();
92
}
93
filter_rules_sort();
94
$a_filter = &$config['filter']['rule'];
95

    
96
$if = $_GET['if'];
97
if ($_POST['if'])
98
	$if = $_POST['if'];
99

    
100
$ifdescs = get_configured_interface_with_descr();
101

    
102
// Drag and drop reordering
103
if($_REQUEST['dragdroporder']) {
104
	// First create a new ruleset array and tmp arrays
105
	$a_filter_unorder = array();
106
	$a_filter_order = array();
107
	$a_filter_order_tmp = array();
108
	// Pointer to id of item being reordered
109
	$found = 0;
110
	$drag_order = $_REQUEST['dragtable'];
111
	// Next traverse through rules building a new order for interface
112
	for ($i = 0; isset($a_filter[$i]); $i++) {
113
		if($a_filter[$i]['interface'] <> $_REQUEST['if']) 
114
			$a_filter_unorder[] = $a_filter[$i];
115
		else 
116
			$a_filter_order_tmp[] = $a_filter[$i];
117
	}
118
	// Reorder rules with the posted order
119
	for ($i = 0; $i<count($drag_order); $i++) 
120
		$a_filter_order[] = $a_filter_order_tmp[$drag_order[$i]];
121
	unset($config['filter']['rule']);
122
	// Overwrite filter rules with newly created items
123
	$config['filter']['rule'] = $a_filter_order;
124
	foreach($a_filter_unorder as $aa) 
125
		$config['filter']['rule'][] = $aa;
126
	// Write configuration
127
	$config = write_config("Drag and drop firewall rules ordering update.");
128
	// Redirect back to page
129
	mark_subsystem_dirty('filter');
130
	$undo = array();
131
	foreach($_REQUEST['dragtable'] as $dt) 
132
		$undo[] = "";
133
	$counter = 0;
134
	foreach($_REQUEST['dragtable'] as $dt) {
135
		$undo[$dt] = $counter;
136
		$counter++;
137
	}
138
	foreach($undo as $dt) 
139
		$undotxt .= "&dragtable[]={$dt}";
140
	Header("Location: firewall_rules.php?if=" . $_REQUEST['if'] . "&undodrag=true" . $undotxt);
141
	exit;
142
}
143

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

    
150
foreach ($ifdescs as $ifent => $ifdesc)
151
	if(have_ruleint_access($ifent)) 
152
		$iflist[$ifent] = $ifdesc;
153

    
154
if ($config['l2tp']['mode'] == "server")
155
        if(have_ruleint_access("l2tp"))
156
                $iflist['l2tp'] = "L2TP VPN";
157

    
158
if ($config['pptpd']['mode'] == "server")
159
	if(have_ruleint_access("pptp")) 
160
		$iflist['pptp'] = "PPTP VPN";
161

    
162
if ($config['pppoe']['mode'] == "server")
163
	if(have_ruleint_access("pppoe")) 
164
		$iflist['pppoe'] = "PPPoE VPN";
165

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

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

    
175
if (!$if || !isset($iflist[$if])) {
176
	if ("any" == $if)
177
                $if = "FloatingRules";
178
        else if ("FloatingRules" != $if)
179
                $if = "wan";
180
}
181

    
182
if ($_POST) {
183

    
184
	$pconfig = $_POST;
185

    
186
	if ($_POST['apply']) {
187
		$retval = 0;
188
		$retval = filter_configure();
189

    
190
		clear_subsystem_dirty('filter');
191

    
192
		$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>");
193
	}
194
}
195

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

    
209
// Handle save msg if defined
210
if($_REQUEST['savemsg']) 
211
	$savemsg = htmlentities($_REQUEST['savemsg']);
212

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

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

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

    
264
		/* copy $movebtn rule */
265
		if ($movebtn < count($a_filter))
266
			$a_filter_new[] = $a_filter[$movebtn];
267

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

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

    
283
include("head.inc");
284

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

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

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