Project

General

Profile

Download (34.6 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
	$undo = array();
130
	foreach($_REQUEST['dragtable'] as $dt) 
131
		$undo[] = "";
132
	$counter = 0;
133
	foreach($_REQUEST['dragtable'] as $dt) {
134
		$undo[$dt] = $counter;
135
		$counter++;
136
	}
137
	foreach($undo as $dt) 
138
		$undotxt .= "&dragtable[]={$dt}";
139
	Header("Location: firewall_rules.php?if=" . $_REQUEST['if'] . "&undodrag=true" . $undotxt);
140
	exit;
141
}
142

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

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

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

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

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

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

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

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

    
181
if ($_POST) {
182

    
183
	$pconfig = $_POST;
184

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

    
189
		clear_subsystem_dirty('filter');
190

    
191
		$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.";
192
	}
193
}
194

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

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

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

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

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

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

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

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

    
282
include("head.inc");
283

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

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

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