Project

General

Profile

Download (39 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	firewall_rules.php
5
	part of pfSense (http://www.pfsense.com)
6
        Copyright (C) 2005 Scott Ullrich (sullrich@gmail.com)
7

    
8
	originally part of m0n0wall (http://m0n0.ch/wall)
9
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
10
	All rights reserved.
11

    
12
	Redistribution and use in source and binary forms, with or without
13
	modification, are permitted provided that the following conditions are met:
14

    
15
	1. Redistributions of source code must retain the above copyright notice,
16
	   this list of conditions and the following disclaimer.
17

    
18
	2. Redistributions in binary form must reproduce the above copyright
19
	   notice, this list of conditions and the following disclaimer in the
20
	   documentation and/or other materials provided with the distribution.
21

    
22
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
23
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
24
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
	POSSIBILITY OF SUCH DAMAGE.
32
*/
33
/*
34
	pfSense_MODULE:	filter
35
*/
36

    
37
##|+PRIV
38
##|*IDENT=page-firewall-rules
39
##|*NAME=Firewall: Rules page
40
##|*DESCR=Allow access to the 'Firewall: Rules' page.
41
##|*MATCH=firewall_rules.php*
42
##|-PRIV
43

    
44
$statusurl = "status_filter_reload.php";
45
$logurl = "diag_logs_filter.php";
46

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

    
52
$pgtitle = array(gettext("Firewall"),gettext("Rules"));
53

    
54
function delete_nat_association($id) {
55
	global $config;
56

    
57
	if (!$id || !is_array($config['nat']['rule']))
58
		return;
59

    
60
	$a_nat = &$config['nat']['rule'];
61

    
62
	foreach ($a_nat as &$natent)
63
		if ($natent['associated-rule-id'] == $id)
64
			$natent['associated-rule-id'] = '';
65
}
66

    
67
if (!is_array($config['filter']['rule'])) {
68
	$config['filter']['rule'] = array();
69
}
70
filter_rules_sort();
71
$a_filter = &$config['filter']['rule'];
72

    
73
$if = $_GET['if'];
74
if ($_POST['if'])
75
	$if = $_POST['if'];
76

    
77
$ifdescs = get_configured_interface_with_descr();
78

    
79
// Drag and drop reordering
80
if($_REQUEST['dragdroporder']) {
81
	// First create a new ruleset array and tmp arrays
82
	$a_filter_before = array();
83
	$a_filter_order = array();
84
	$a_filter_order_tmp = array();
85
	$a_filter_after = array();
86
	$found = false;
87
	$drag_order = $_REQUEST['dragtable'];
88
	// Next traverse through rules building a new order for interface
89
	for ($i = 0; isset($a_filter[$i]); $i++) {
90
		if(( $_REQUEST['if'] == "FloatingRules" && isset($a_filter[$i]['floating']) ) || ( $a_filter[$i]['interface'] == $_REQUEST['if'] && !isset($a_filter[$i]['floating']) )) {
91
			$a_filter_order_tmp[] = $a_filter[$i];
92
			$found = true;
93
		} else if (!$found)
94
			$a_filter_before[] = $a_filter[$i];
95
		else
96
			$a_filter_after[] = $a_filter[$i];
97
	}
98
	// Reorder rules with the posted order
99
	for ($i = 0; $i<count($drag_order); $i++)
100
		$a_filter_order[] = $a_filter_order_tmp[$drag_order[$i]];
101
	// In case $drag_order didn't account for some rules, make sure we don't lose them
102
	if(count($a_filter_order) < count($a_filter_order_tmp)) {
103
		for ($i = 0; $i<count($a_filter_order_tmp); $i++)
104
			if(!in_array($i, $drag_order))
105
				$a_filter_order[] = $a_filter_order_tmp[$i];
106
	}
107
	// Overwrite filter rules with newly created items
108
	$config['filter']['rule'] = array_merge($a_filter_before, $a_filter_order, $a_filter_after);
109
	// Write configuration
110
	$config = write_config("Drag and drop firewall rules ordering update.");
111
	// Redirect back to page
112
	mark_subsystem_dirty('filter');
113
	$undo = array();
114
	foreach($_REQUEST['dragtable'] as $dt) 
115
		$undo[] = "";
116
	$counter = 0;
117
	foreach($_REQUEST['dragtable'] as $dt) {
118
		$undo[$dt] = $counter;
119
		$counter++;
120
	}
121
	foreach($undo as $dt) 
122
		$undotxt .= "&dragtable[]={$dt}";
123
	Header("Location: firewall_rules.php?if=" . $_REQUEST['if'] . "&undodrag=true" . $undotxt);
124
	exit;
125
}
126

    
127
$icmptypes = array(
128
	"" => gettext("any"),
129
	"echoreq" => gettext("Echo request"),
130
	"echorep" => gettext("Echo reply"),
131
	"unreach" => gettext("Destination unreachable"),
132
	"squench" => gettext("Source quench"),
133
	"redir" => gettext("Redirect"),
134
	"althost" => gettext("Alternate Host"),
135
	"routeradv" => gettext("Router advertisement"),
136
	"routersol" => gettext("Router solicitation"),
137
	"timex" => gettext("Time exceeded"),
138
	"paramprob" => gettext("Invalid IP header"),
139
	"timereq" => gettext("Timestamp"),
140
	"timerep" => gettext("Timestamp reply"),
141
	"inforeq" => gettext("Information request"),
142
	"inforep" => gettext("Information reply"),
143
	"maskreq" => gettext("Address mask request"),
144
	"maskrep" => gettext("Address mask reply")
145
);
146

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

    
153
foreach ($ifdescs as $ifent => $ifdesc)
154
	if(have_ruleint_access($ifent)) 
155
		$iflist[$ifent] = $ifdesc;
156

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

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

    
165
if (is_array($config['pppoes']['pppoe'])) {
166
	foreach ($config['pppoes']['pppoe'] as $pppoes)
167
		if (($pppoes['mode'] == 'server') && have_ruleint_access("pppoe"))
168
			$iflist['pppoe'] = "PPPoE Server";
169
}
170

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

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

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

    
187
if ($_POST) {
188

    
189
	$pconfig = $_POST;
190

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

    
195
		clear_subsystem_dirty('filter');
196

    
197
		$savemsg = sprintf(gettext("The settings have been applied. The firewall rules are now reloading in the background.<br/>You can also %s monitor %s the reload progress"),"<a href='status_filter_reload.php'>","</a>");
198
	}
199
}
200

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

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

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

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

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

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

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

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

    
288
include("head.inc");
289

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

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

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

    
392
		$guiport = "80";
393
		if (isset($config['system']['webgui']['port']) && $config['system']['webgui']['port'] <> "")
394
			$guiport = "{$config['system']['webgui']['port']}";
395
		if ($config['system']['webgui']['protocol'] == "https")
396
			$guiport .= "<br/>443";
397

    
398
		$sshport = "";
399
		if (isset($config['system']['enablesshd'])) {
400
			$sshport = 22;
401
		if($config['system']['ssh']['port'] <> "")
402
			$sshport = $config['system']['ssh']['port'];
403
		}
404
		$sshport = "22<br/>";
405
?>
406
		<tr valign="top" id="antilockout">
407
			<td class="list">&nbsp;</td>
408
			<td class="listt" align="center"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_pass.gif" width="11" height="11" border="0"></td>
409
			<td class="listlr" style="background-color: #E0E0E0"></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"><?=$iflist[$if];?> Address</td>
414
			<td class="listr" style="background-color: #E0E0E0"><?= $sshport . $guiport ?></td>
415
			<td class="listr" style="background-color: #E0E0E0">*</td>
416
			<td class="listr" style="background-color: #E0E0E0">*</td>
417
			<td class="listr" style="background-color: #E0E0E0"></td>
418
			<td class="listbg"><?=gettext("Anti-Lockout Rule");?></td>
419
			<td valign="middle" nowrap class="list">
420
			<table border="0" cellspacing="0" cellpadding="1">
421
				<tr>
422
					<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>
423
					<td><a href="system_advanced_admin.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" title="<?=gettext("edit rule");?>" width="17" height="17" border="0"></a></td>
424
				</tr>
425
				<tr>
426
					<td align="center" valign="middle"></td>
427
					<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>
428
				</tr>
429
				</table>
430
			</td>
431
			</tr>
432
<?php endif; ?>
433

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