Project

General

Profile

Download (12.4 KB) Statistics
| Branch: | Tag: | Revision:
1 340e6dca Scott Ullrich
<?php
2 b46bfcf5 Bill Marquette
/* $Id$ */
3 5b237745 Scott Ullrich
/*
4
	firewall_nat.php
5
*/
6 fd9ebcd5 Stephen Beaver
/* ====================================================================
7 7c540a5c Stephen Beaver
 *	Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
8
 *	Copyright (c)  2004 Scott Ullrich
9 fd9ebcd5 Stephen Beaver
 *	Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>
10
 *	originally part of m0n0wall (http://m0n0.ch/wall)
11
 *
12 7c540a5c Stephen Beaver
 *	Redistribution and use in source and binary forms, with or without modification,
13
 *	are permitted provided that the following conditions are met:
14 fd9ebcd5 Stephen Beaver
 *
15 7c540a5c Stephen Beaver
 *	1. Redistributions of source code must retain the above copyright notice,
16
 *		this list of conditions and the following disclaimer.
17 fd9ebcd5 Stephen Beaver
 *
18 7c540a5c Stephen Beaver
 *	2. Redistributions in binary form must reproduce the above copyright
19
 *		notice, this list of conditions and the following disclaimer in
20
 *		the documentation and/or other materials provided with the
21
 *		distribution.
22 fd9ebcd5 Stephen Beaver
 *
23 7c540a5c Stephen Beaver
 *	3. All advertising materials mentioning features or use of this software
24
 *		must display the following acknowledgment:
25
 *		"This product includes software developed by the pfSense Project
26
 *		 for use in the pfSense software distribution. (http://www.pfsense.org/).
27 fd9ebcd5 Stephen Beaver
 *
28 7c540a5c Stephen Beaver
 *	4. The names "pfSense" and "pfSense Project" must not be used to
29
 *		 endorse or promote products derived from this software without
30
 *		 prior written permission. For written permission, please contact
31
 *		 coreteam@pfsense.org.
32 fd9ebcd5 Stephen Beaver
 *
33 7c540a5c Stephen Beaver
 *	5. Products derived from this software may not be called "pfSense"
34
 *		nor may "pfSense" appear in their names without prior written
35
 *		permission of the Electric Sheep Fencing, LLC.
36 fd9ebcd5 Stephen Beaver
 *
37 7c540a5c Stephen Beaver
 *	6. Redistributions of any form whatsoever must retain the following
38
 *		acknowledgment:
39 fd9ebcd5 Stephen Beaver
 *
40 7c540a5c Stephen Beaver
 *	"This product includes software developed by the pfSense Project
41
 *	for use in the pfSense software distribution (http://www.pfsense.org/).
42 fd9ebcd5 Stephen Beaver
  *
43 7c540a5c Stephen Beaver
 *	THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
44
 *	EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45
 *	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
46
 *	PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
47
 *	ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48
 *	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
49
 *	NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
50
 *	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
51
 *	HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
52
 *	STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
53
 *	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
54
 *	OF THE POSSIBILITY OF SUCH DAMAGE.
55 fd9ebcd5 Stephen Beaver
 *
56 7c540a5c Stephen Beaver
 *	====================================================================
57 fd9ebcd5 Stephen Beaver
 *
58
 */
59 7ac5a4cb Scott Ullrich
/*
60 0e6ac11d Stephen Beaver
	pfSense_MODULE: nat
61 7ac5a4cb Scott Ullrich
*/
62 5b237745 Scott Ullrich
63 6b07c15a Matthew Grooms
##|+PRIV
64
##|*IDENT=page-firewall-nat-portforward
65
##|*NAME=Firewall: NAT: Port Forward page
66
##|*DESCR=Allow access to the 'Firewall: NAT: Port Forward' page.
67
##|*MATCH=firewall_nat.php*
68
##|-PRIV
69
70 5b237745 Scott Ullrich
require("guiconfig.inc");
71 7a927e67 Scott Ullrich
require_once("functions.inc");
72
require_once("filter.inc");
73
require_once("shaper.inc");
74 483e6de8 Scott Ullrich
require_once("itemid.inc");
75 5b237745 Scott Ullrich
76 37ba954d Phil Davis
if (!is_array($config['nat']['rule'])) {
77 5b237745 Scott Ullrich
	$config['nat']['rule'] = array();
78 37ba954d Phil Davis
}
79 fbe94068 Scott Ullrich
80 5b237745 Scott Ullrich
$a_nat = &$config['nat']['rule'];
81
82 8bbab8a3 Stephen Beaver
/* update rule order, POST[rule] is an array of ordered IDs */
83 6cb366de Stephen Beaver
if($_POST['order-store']) {
84
	if (is_array($_POST['rule']) && !empty($_POST['rule'])) {
85
		$a_nat_new = array();
86 8bbab8a3 Stephen Beaver
87 6cb366de Stephen Beaver
		// if a rule is not in POST[rule], it has been deleted by the user
88
		foreach ($_POST['rule'] as $id)
89
			$a_nat_new[] = $a_nat[$id];
90 8bbab8a3 Stephen Beaver
91 6cb366de Stephen Beaver
		$a_nat = $a_nat_new;
92 dbbd22f9 Stephen Beaver
93 6cb366de Stephen Beaver
		if (write_config())
94
			mark_subsystem_dirty('filter');
95 dbbd22f9 Stephen Beaver
96 6cb366de Stephen Beaver
		header("Location: firewall_nat.php");
97
		exit;
98
	}
99 8bbab8a3 Stephen Beaver
}
100
101 514dbaf8 Scott Ullrich
/* if a custom message has been passed along, lets process it */
102 37ba954d Phil Davis
if ($_GET['savemsg']) {
103 514dbaf8 Scott Ullrich
	$savemsg = $_GET['savemsg'];
104 37ba954d Phil Davis
}
105 514dbaf8 Scott Ullrich
106 5b237745 Scott Ullrich
if ($_POST) {
107
	$pconfig = $_POST;
108
109
	if ($_POST['apply']) {
110 e8c2c890 Bill Marquette
111 5b237745 Scott Ullrich
		$retval = 0;
112 7a6c350f Scott Ullrich
113 e2c9ef13 Scott Ullrich
		$retval |= filter_configure();
114 05da8941 Erik Fonnesbeck
		$savemsg = get_std_save_message($retval);
115 7d04082e Scott Ullrich
116 1a700ea6 Scott Ullrich
		pfSense_handle_custom_code("/usr/local/pkg/firewall_nat/apply");
117
118 5b237745 Scott Ullrich
		if ($retval == 0) {
119 a368a026 Ermal Lu?i
			clear_subsystem_dirty('natconf');
120
			clear_subsystem_dirty('filter');
121 5b237745 Scott Ullrich
		}
122 7d04082e Scott Ullrich
123 5b237745 Scott Ullrich
	}
124
}
125
126 759d0de1 Renato Botelho
if ($_GET['act'] == "del") {
127
	if ($a_nat[$_GET['id']]) {
128 3a343d73 jim-p
129 759d0de1 Renato Botelho
		if (isset($a_nat[$_GET['id']]['associated-rule-id'])) {
130
			delete_id($a_nat[$_GET['id']]['associated-rule-id'], $config['filter']['rule']);
131 3a343d73 jim-p
			$want_dirty_filter = true;
132 759d0de1 Renato Botelho
		}
133
		unset($a_nat[$_GET['id']]);
134 3a343d73 jim-p
135
		if (write_config()) {
136
			mark_subsystem_dirty('natconf');
137 37ba954d Phil Davis
			if ($want_dirty_filter) {
138 3a343d73 jim-p
				mark_subsystem_dirty('filter');
139 37ba954d Phil Davis
			}
140 3a343d73 jim-p
		}
141 0e6ac11d Stephen Beaver
142 759d0de1 Renato Botelho
		header("Location: firewall_nat.php");
143
		exit;
144
	}
145
}
146
147 00bcbdd0 Bill Marquette
if (isset($_POST['del_x'])) {
148 0e6ac11d Stephen Beaver
	/* delete selected rules */
149
	if (is_array($_POST['rule']) && count($_POST['rule'])) {
150
		foreach ($_POST['rule'] as $rulei) {
151 049a688e Ermal Lu?i
		$target = $rule['target'];
152 b9e28d57 unknown
			// Check for filter rule associations
153 6c07db48 Phil Davis
			if (isset($a_nat[$rulei]['associated-rule-id'])) {
154 9b16b834 Ermal Lu?i
				delete_id($a_nat[$rulei]['associated-rule-id'], $config['filter']['rule']);
155 7d5b007c Sjon Hortensius
156 b9e28d57 unknown
				mark_subsystem_dirty('filter');
157
			}
158 6cb366de Stephen Beaver
159 0e6ac11d Stephen Beaver
			unset($a_nat[$rulei]);
160
		}
161 6cb366de Stephen Beaver
162 37ba954d Phil Davis
		if (write_config()) {
163 3a343d73 jim-p
			mark_subsystem_dirty('natconf');
164 37ba954d Phil Davis
		}
165 6cb366de Stephen Beaver
166 3a343d73 jim-p
		header("Location: firewall_nat.php");
167
		exit;
168 4b9a670c Scott Ullrich
	}
169 0e6ac11d Stephen Beaver
}
170
171 d16a49ae Colin Fleming
$closehead = false;
172 6c07db48 Phil Davis
$pgtitle = array(gettext("Firewall"), gettext("NAT"), gettext("Port Forward"));
173 6eb17647 Scott Ullrich
include("head.inc");
174
175 0e6ac11d Stephen Beaver
if ($savemsg)
176
	print_info_box($savemsg, 'success');
177
178
if (is_subsystem_dirty('natconf'))
179
	print_info_box_np(gettext('The NAT configuration has been changed.') . '<br />' .
180
					  gettext('You must apply the changes in order for them to take effect.') . '<br />');
181 2a9db752 Scott Dale
182 0e6ac11d Stephen Beaver
$tab_array = array();
183
$tab_array[] = array(gettext("Port Forward"), true, "firewall_nat.php");
184
$tab_array[] = array(gettext("1:1"), false, "firewall_nat_1to1.php");
185
$tab_array[] = array(gettext("Outbound"), false, "firewall_nat_out.php");
186
$tab_array[] = array(gettext("NPt"), false, "firewall_nat_npt.php");
187
display_top_tabs($tab_array);
188 24f600b0 Scott Ullrich
?>
189 d16a49ae Colin Fleming
190 00bcbdd0 Bill Marquette
<form action="firewall_nat.php" method="post" name="iform">
191 8bbab8a3 Stephen Beaver
	<div class="panel panel-default">
192
		<div class="panel-heading"><?=gettext('Rules')?></div>
193
		<div class="panel-body table-responsive">
194
			<table class="table table-striped table-hover table-condensed">
195
				<thead>
196
					<tr>
197 7c540a5c Stephen Beaver
						<th><!-- Checkbox --></th>
198 8bbab8a3 Stephen Beaver
						<th><!-- Rule type --></th>
199
						<th><?=gettext("If")?></th>
200
						<th><?=gettext("Proto")?></th>
201
						<th><?=gettext("Src. addr")?></th>
202
						<th><?=gettext("Src. ports")?></th>
203
						<th><?=gettext("Dest. addr")?></th>
204
						<th><?=gettext("Dest. ports")?></th>
205
						<th><?=gettext("NAT IP")?></th>
206
						<th><?=gettext("NAT Ports")?></th>
207
						<th><?=gettext("Description")?></th>
208
						<th><?=gettext("Actions")?></th>
209
					</tr>
210
				</thead>
211
				<tbody class='user-entries'>
212 0e6ac11d Stephen Beaver
<?php
213 dbbd22f9 Stephen Beaver
214 0e6ac11d Stephen Beaver
$nnats = $i = 0;
215
216
foreach ($a_nat as $natent):
217
218 dbbd22f9 Stephen Beaver
	$alias = rule_columns_with_alias(
219
		$natent['source']['address'],
220
		pprint_port($natent['source']['port']),
221
		$natent['destination']['address'],
222
		pprint_port($natent['destination']['port'])
223
	);
224 0e6ac11d Stephen Beaver
225 dbbd22f9 Stephen Beaver
	/* if user does not have access to edit an interface skip on to the next record */
226 e6f34d22 Phil Davis
	if (!have_natpfruleint_access($natent['interface']))
227 dbbd22f9 Stephen Beaver
		continue;
228 0e6ac11d Stephen Beaver
?>
229 7c540a5c Stephen Beaver
230
					<tr id="fr<?=$nnats;?>" onClick="fr_toggle(<?=$nnats;?>)" ondblclick="document.location='firewall_nat_edit.php?id=<?=$i;?>';">
231
						<td >
232
							<input type="checkbox" id="frc<?=$nnats;?>" onClick="fr_toggle(<?=$nnats;?>)" name="rule[]" value="<?=$i;?>"/>
233
						</td>
234 8bbab8a3 Stephen Beaver
						<td>
235 0e6ac11d Stephen Beaver
<?php
236 e6f34d22 Phil Davis
	if ($natent['associated-rule-id'] == "pass"):
237 0e6ac11d Stephen Beaver
?>
238 7abddc12 Stephen Beaver
							<i class="icon-play" title="<?=gettext("All traffic matching this NAT entry is passed")?>"></i>
239 a8726a3d Scott Ullrich
<?php
240 dbbd22f9 Stephen Beaver
	elseif (!empty($natent['associated-rule-id'])):
241 a8726a3d Scott Ullrich
?>
242 7abddc12 Stephen Beaver
							<i class="icon-random" title="<?=gettext("Firewall rule ID ")?><?=htmlspecialchars($nnatid)?> . <?=gettext('is managed by this rule')?>"></i>
243 0e6ac11d Stephen Beaver
<?php
244 dbbd22f9 Stephen Beaver
	endif;
245 0e6ac11d Stephen Beaver
?>
246 8bbab8a3 Stephen Beaver
						</td>
247 91d452c7 Stephen Beaver
						<td>
248 8bbab8a3 Stephen Beaver
							<?=$textss?>
249 0e6ac11d Stephen Beaver
<?php
250 dbbd22f9 Stephen Beaver
	if (!$natent['interface'])
251
		echo htmlspecialchars(convert_friendly_interface_to_friendly_descr("wan"));
252
	else
253
		echo htmlspecialchars(convert_friendly_interface_to_friendly_descr($natent['interface']));
254 0e6ac11d Stephen Beaver
?>
255 8bbab8a3 Stephen Beaver
							<?=$textse?>
256
						</td>
257 dbbd22f9 Stephen Beaver
258 91d452c7 Stephen Beaver
						<td>
259 8bbab8a3 Stephen Beaver
							<?=$textss?><?=strtoupper($natent['protocol'])?><?=$textse?>
260
						</td>
261 dbbd22f9 Stephen Beaver
262 91d452c7 Stephen Beaver
						<td>
263 dbbd22f9 Stephen Beaver
264
265
<?php
266
	if (isset($alias['src'])):
267
?>
268
							<a href="/firewall_aliases_edit.php?id=<?=$alias['src']?>" data-toggle="popover" data-trigger="hover focus" title="Alias details" data-content="<?=alias_info_popup($alias['src'])?>" data-html="true">
269
<?php
270
	endif;
271
?>
272
							<?=htmlspecialchars(pprint_address($natent['source']))?>
273
<?php
274
	if (isset($alias['src'])):
275
?>
276
							<i class='icon icon-pencil'></i></a>
277
<?php
278
	endif;
279
?>
280 8bbab8a3 Stephen Beaver
						</td>
281 91d452c7 Stephen Beaver
						<td>
282 dbbd22f9 Stephen Beaver
<?php
283
	if (isset($alias['srcport'])):
284
?>
285
							<a href="/firewall_aliases_edit.php?id=<?=$alias['srcport']?>" data-toggle="popover" data-trigger="hover focus" title="Alias details" data-content="<?=alias_info_popup($alias['srcport'])?>" data-html="true">
286
<?php
287
	endif;
288
?>
289
							<?=htmlspecialchars(pprint_port($natent['source']['port']))?>
290
<?php
291
	if (isset($alias['srcport'])):
292
?>
293
							<i class='icon icon-pencil'></i></a>
294
<?php
295
	endif;
296
?>
297 8bbab8a3 Stephen Beaver
						</td>
298 dbbd22f9 Stephen Beaver
299 91d452c7 Stephen Beaver
						<td>
300 dbbd22f9 Stephen Beaver
<?php
301
	if (isset($alias['dst'])):
302
?>
303
							<a href="/firewall_aliases_edit.php?id=<?=$alias['dst']?>" data-toggle="popover" data-trigger="hover focus" title="Alias details" data-content="<?=alias_info_popup($alias['dst'])?>" data-html="true">
304
<?php
305
	endif;
306
?>
307
							<?=htmlspecialchars(pprint_address($natent['destination']))?>
308
<?php
309
	if (isset($alias['dst'])):
310
?>
311
							<i class='icon icon-pencil'></i></a>
312
<?php
313
	endif;
314
?>
315 8bbab8a3 Stephen Beaver
						</td>
316 91d452c7 Stephen Beaver
						<td>
317 dbbd22f9 Stephen Beaver
<?php
318
	if (isset($alias['dstport'])):
319
?>
320
							<a href="/firewall_aliases_edit.php?id=<?=$alias['dstport']?>" data-toggle="popover" data-trigger="hover focus" title="Alias details" data-content="<?=alias_info_popup($alias['dstport'])?>" data-html="true">
321
<?php
322
	endif;
323
?>
324
							<?=htmlspecialchars(pprint_port($natent['destination']['port']))?>
325
<?php
326
	if (isset($alias['dstport'])):
327
?>
328
							<i class='icon icon-pencil'></i></a>
329
<?php
330
	endif;
331
?>
332 8bbab8a3 Stephen Beaver
						</td>
333 dbbd22f9 Stephen Beaver
334 91d452c7 Stephen Beaver
						<td >
335 dbbd22f9 Stephen Beaver
							<?=htmlspecialchars($natent['target'])?>
336 8bbab8a3 Stephen Beaver
						</td>
337 91d452c7 Stephen Beaver
						<td>
338 0e6ac11d Stephen Beaver
<?php
339 dbbd22f9 Stephen Beaver
	$localport = $natent['local-port'];
340 0e6ac11d Stephen Beaver
341 dbbd22f9 Stephen Beaver
	list($dstbeginport, $dstendport) = explode("-", $natent['destination']['port']);
342 0e6ac11d Stephen Beaver
343 dbbd22f9 Stephen Beaver
	if ($dstendport) {
344
		$localendport = $natent['local-port'] + $dstendport - $dstbeginport;
345
		$localport	 .= '-' . $localendport;
346
	}
347 0e6ac11d Stephen Beaver
?>
348 dbbd22f9 Stephen Beaver
							<?=htmlspecialchars(pprint_port($localport))?>
349 8bbab8a3 Stephen Beaver
						</td>
350 dbbd22f9 Stephen Beaver
351 91d452c7 Stephen Beaver
						<td>
352 dbbd22f9 Stephen Beaver
							<?=htmlspecialchars($natent['descr'])?>
353 8bbab8a3 Stephen Beaver
						</td>
354 91d452c7 Stephen Beaver
						<td>
355 8bbab8a3 Stephen Beaver
							<a class="btn btn-xs btn-info"	title="<?=gettext("Edit rule"); ?>" href="firewall_nat_edit.php?id=<?=$i?>"><?=gettext("Edit"); ?></a>
356
							<a class="btn btn-xs btn-danger"  title="<?=gettext("Delete rule")?>" href="firewall_nat.php?act=del&amp;id=<?=$i?>"><?=gettext("Del")?></a>
357
							<a class="btn btn-xs btn-success"	  title="<?=gettext("Add a new NAT based on this one")?>" href="firewall_nat_edit.php?dup=<?=$i?>"><?=gettext("Clone")?></a>
358
						</td>
359
					</tr>
360 0e6ac11d Stephen Beaver
<?php
361
	$i++;
362
	$nnats++;
363
endforeach;
364
?>
365 8bbab8a3 Stephen Beaver
				</tbody>
366
			</table>
367
		</div>
368 4cf530c4 Stephen Beaver
	</div>
369 dbbd22f9 Stephen Beaver
370 4cf530c4 Stephen Beaver
	<div class="pull-right">
371
		<a href="firewall_nat_edit.php?after=-1" class="btn btn-sm btn-success" title="<?=gettext('Add new rule')?>"><?=gettext('Add new rule')?></a>
372 6cb366de Stephen Beaver
		<input name="del_x" type="submit" class="btn btn-danger btn-sm" value="<?=gettext("Delete selected rules"); ?>"	 />
373
		<input type="submit" id="order-store" name="order-store" class="btn btn-primary btn-sm" value="<?=gettext("Save changes")?>" disabled="disabled" />
374 d732f186 Bill Marquette
	</div>
375 0e6ac11d Stephen Beaver
</form>
376 3d335c4d Scott Ullrich
377 7c540a5c Stephen Beaver
<script>
378
function fr_toggle(id, prefix) {
379
	if (!prefix)
380
		prefix = 'fr';
381
382
	var checkbox = document.getElementById(prefix + 'c' + id);
383
	checkbox.checked = !checkbox.checked;
384
	fr_bgcolor(id, prefix);
385
}
386
387
function fr_bgcolor(id, prefix) {
388
	if (!prefix)
389
		prefix = 'fr';
390
391
	var row = document.getElementById(prefix + id);
392
	var checkbox = document.getElementById(prefix + 'c' + id);
393
	var cells = row.getElementsByTagName('td');
394
	var cellcnt = cells.length;
395
396
	for (i = 0; i < cellcnt-1; i++) {
397
		cells[i].style.backgroundColor = checkbox.checked ? "#DDF4FF" : "#FFFFFF";
398
	}
399
}
400
</script>
401
402 4cf530c4 Stephen Beaver
<script>
403
events.push(function() {
404
	// Make rules draggable/sortable
405
	$('table tbody.user-entries').sortable({
406
		cursor: 'grabbing',
407
		update: function(event, ui) {
408
			$('#order-store').removeAttr('disabled');
409
		}
410
	});
411 6cb366de Stephen Beaver
412
	// Check all of the rule checkboxes so that their values are posted
413
	$('#order-store').click(function () {
414
	   $('[id^=frc]').prop('checked', true);
415
	});
416 4cf530c4 Stephen Beaver
});
417
</script>
418 3d335c4d Scott Ullrich
<?php
419 0e6ac11d Stephen Beaver
420 e6f34d22 Phil Davis
if (count($a_nat) > 0) {
421 3d335c4d Scott Ullrich
?>
422 0e6ac11d Stephen Beaver
<!-- Legend -->
423
<div>
424
	<dl class="dl-horizontal responsive">
425
		<dt><?=gettext('Legend')?></dt>					<dd></dd>
426
		<dt><i class="icon icon-play"></i></dt>			<dd><?=gettext('Pass')?></dd>
427
		<dt><i class="icon icon-random"></i></dt>		<dd><?=gettext('Linked rule')?></dd>
428
	</dl>
429
</div>
430 3d335c4d Scott Ullrich
431 0e6ac11d Stephen Beaver
<?php
432
}
433
434
include("foot.inc");