Project

General

Profile

Download (34 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
$pgtitle = array("Firewall", "Rules");
45
$statusurl = "status_filter_reload.php";
46
$logurl = "diag_logs_filter.php";
47

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

    
53
function check_for_advaned_options(&$item) {
54
	$item_set = "";
55
	if($item['max'])
56
		$item_set .= "max {$item['max']} ";
57
	if($item['max-src-nodes'])
58
		$item_set .= "max-src-nodes {$item['max-src-nodes']} ";
59
	if($item['max-src-conn'])
60
		$item_set .= "max-src-conn {$item['max-src-conn']} ";
61
	if($item['max-src-states'])
62
		$item_set .= "max-src-states {$item['max-src-states']} ";
63
	if($item['statetype'] != "keep state" && $item['statetype'] != "")
64
		$item_set .= "statetype {$item['statetype']} {$item['statetype']}";
65
	if($item['statetimeout'])
66
		$item_set .= "statetimeout {$item['statetimeout']}";
67
	if($item['nosync'])
68
		$item_set .= "nosync ";
69
	if($item['max-src-conn-rate'])
70
		$item_set .= "max-src-conn-rate {$item['max-src-conn-rate']} ";
71
	if($item['max-src-conn-rates'])
72
		$item_set .= "max-src-conn-rates {$item['max-src-conn-rates']} ";
73
	return $item_set;
74
}
75

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

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

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

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

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

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

    
99
$ifdescs = get_configured_interface_with_descr();
100

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

    
133
/* add group interfaces */
134
if (is_array($config['ifgroups']['ifgroupentry']))
135
	foreach($config['ifgroups']['ifgroupentry'] as $ifgen)
136
		if (have_ruleint_access($ifgen['ifname']))
137
			$iflist[$ifgen['ifname']] = $ifgen['ifname'];
138

    
139
foreach ($ifdescs as $ifent => $ifdesc)
140
	if(have_ruleint_access($ifent)) 
141
		$iflist[$ifent] = $ifdesc;
142

    
143
if ($config['l2tp']['mode'] == "server")
144
        if(have_ruleint_access("l2tp"))
145
                $iflist['l2tp'] = "L2TP VPN";
146

    
147
if ($config['pptpd']['mode'] == "server")
148
	if(have_ruleint_access("pptp")) 
149
		$iflist['pptp'] = "PPTP VPN";
150

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

    
155
/* add ipsec interfaces */
156
if (isset($config['ipsec']['enable']) || isset($config['ipsec']['mobileclients']['enable']))
157
	if(have_ruleint_access("enc0")) 
158
		$iflist["enc0"] = "IPsec";
159

    
160
/* add openvpn/tun interfaces */
161
if  ($config['openvpn']["openvpn-server"] || $config['openvpn']["openvpn-client"])
162
   	$iflist["openvpn"] = "OpenVPN";
163

    
164
if (!$if || !isset($iflist[$if])) {
165
	if ("any" == $if)
166
                $if = "FloatingRules";
167
        else if ("FloatingRules" != $if)
168
                $if = "wan";
169
}
170

    
171
if ($_POST) {
172

    
173
	$pconfig = $_POST;
174

    
175
	if ($_POST['apply']) {
176
		$retval = 0;
177
		$retval = filter_configure();
178

    
179
		clear_subsystem_dirty('filter');
180

    
181
		$savemsg = "The settings have been applied.  The firewall rules are now reloading in the background.  You can also <a href='status_filter_reload.php'>monitor</a> the reload progress.";
182
	}
183
}
184

    
185
if ($_GET['act'] == "del") {
186
	if ($a_filter[$_GET['id']]) {
187
		if (!empty($a_filter[$_GET['id']]['associated-rule-id'])) {
188
			delete_nat_association($a_filter[$_GET['id']]['associated-rule-id']);
189
		}
190
		unset($a_filter[$_GET['id']]);
191
		write_config();
192
		mark_subsystem_dirty('filter');
193
		header("Location: firewall_rules.php?if={$if}");
194
		exit;
195
	}
196
}
197

    
198
// Handle save msg if defined
199
if($_REQUEST['savemsg']) 
200
	$savemsg = htmlentities($_REQUEST['savemsg']);
201

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

    
239
		/* copy all rules < $movebtn and not selected */
240
		for ($i = 0; $i < $movebtn; $i++) {
241
			if (!in_array($i, $_POST['rule']))
242
				$a_filter_new[] = $a_filter[$i];
243
		}
244

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

    
253
		/* copy $movebtn rule */
254
		if ($movebtn < count($a_filter))
255
			$a_filter_new[] = $a_filter[$movebtn];
256

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

    
263
		$a_filter = $a_filter_new;
264
		write_config();
265
		mark_subsystem_dirty('filter');
266
		header("Location: firewall_rules.php?if={$if}");
267
		exit;
268
	}
269
}
270
$closehead = false;
271

    
272
include("head.inc");
273

    
274
echo "<script type=\"text/javascript\" language=\"javascript\" src=\"/javascript/domTT/domLib.js\"></script>";
275
echo "<script type=\"text/javascript\" language=\"javascript\" src=\"/javascript/domTT/domTT.js\"></script>";
276
echo "<script type=\"text/javascript\" language=\"javascript\" src=\"/javascript/domTT/behaviour.js\"></script>";
277
echo "<script type=\"text/javascript\" language=\"javascript\" src=\"/javascript/domTT/fadomatic.js\"></script>";
278
?>
279
</head>
280

    
281
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
282
<?php include("fbegin.inc"); ?>
283
<form action="firewall_rules.php" method="post">
284

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