Project

General

Profile

Download (39.5 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
		pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/apply");
198

    
199
		$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>");
200
	}
201
}
202

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

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

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

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

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

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

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

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

    
290
include("head.inc");
291

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

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

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

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

    
400
		$sshport = "";
401
		if (isset($config['system']['enablesshd'])) {
402
			$sshport = 22;
403
		if($config['system']['ssh']['port'] <> "")
404
			$sshport = $config['system']['ssh']['port'];
405
		}
406
		$sshport = "22<br/>";
407
?>
408
		<tr valign="top" id="antilockout">
409
			<td class="list">&nbsp;</td>
410
			<td class="listt" align="center"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_pass.gif" width="11" height="11" border="0"></td>
411
			<td class="listlr" style="background-color: #E0E0E0"></td>
412
<?php
413
				pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/pre_id_tr_antilockout");
414
?>
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="listr" style="background-color: #E0E0E0"><?=$iflist[$if];?> Address</td>
419
			<td class="listr" style="background-color: #E0E0E0"><?= $sshport . $guiport ?></td>
420
			<td class="listr" style="background-color: #E0E0E0">*</td>
421
			<td class="listr" style="background-color: #E0E0E0">*</td>
422
			<td class="listr" style="background-color: #E0E0E0"></td>
423
			<td class="listbg"><?=gettext("Anti-Lockout Rule");?></td>
424
			<td valign="middle" nowrap class="list">
425
			<table border="0" cellspacing="0" cellpadding="1">
426
				<tr>
427
					<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>
428
					<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>
429
				</tr>
430
				<tr>
431
					<td align="center" valign="middle"></td>
432
					<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>
433
				</tr>
434
				</table>
435
			</td>
436
			</tr>
437
<?php endif; ?>
438

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