Project

General

Profile

Download (12.2 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	firewall_nat.php
4
*/
5
/* ====================================================================
6
 *	Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
7
 *
8
 *	Some or all of this file is based on the m0n0wall project which is
9
 *	Copyright (c)  2004 Manuel Kasper (BSD 2 clause)
10
 *
11
 *	Redistribution and use in source and binary forms, with or without modification,
12
 *	are permitted provided that the following conditions are met:
13
 *
14
 *	1. Redistributions of source code must retain the above copyright notice,
15
 *		this list of conditions and the following disclaimer.
16
 *
17
 *	2. Redistributions in binary form must reproduce the above copyright
18
 *		notice, this list of conditions and the following disclaimer in
19
 *		the documentation and/or other materials provided with the
20
 *		distribution.
21
 *
22
 *	3. All advertising materials mentioning features or use of this software
23
 *		must display the following acknowledgment:
24
 *		"This product includes software developed by the pfSense Project
25
 *		 for use in the pfSense software distribution. (http://www.pfsense.org/).
26
 *
27
 *	4. The names "pfSense" and "pfSense Project" must not be used to
28
 *		 endorse or promote products derived from this software without
29
 *		 prior written permission. For written permission, please contact
30
 *		 coreteam@pfsense.org.
31
 *
32
 *	5. Products derived from this software may not be called "pfSense"
33
 *		nor may "pfSense" appear in their names without prior written
34
 *		permission of the Electric Sheep Fencing, LLC.
35
 *
36
 *	6. Redistributions of any form whatsoever must retain the following
37
 *		acknowledgment:
38
 *
39
 *	"This product includes software developed by the pfSense Project
40
 *	for use in the pfSense software distribution (http://www.pfsense.org/).
41
 *
42
 *	THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
43
 *	EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44
 *	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
45
 *	PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
46
 *	ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47
 *	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
48
 *	NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
49
 *	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50
 *	HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
51
 *	STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52
 *	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
53
 *	OF THE POSSIBILITY OF SUCH DAMAGE.
54
 *
55
 *	====================================================================
56
 *
57
 */
58

    
59
##|+PRIV
60
##|*IDENT=page-firewall-nat-portforward
61
##|*NAME=Firewall: NAT: Port Forward
62
##|*DESCR=Allow access to the 'Firewall: NAT: Port Forward' page.
63
##|*MATCH=firewall_nat.php*
64
##|-PRIV
65

    
66
require("guiconfig.inc");
67
require_once("functions.inc");
68
require_once("filter.inc");
69
require_once("shaper.inc");
70
require_once("itemid.inc");
71

    
72
if (!is_array($config['nat']['rule'])) {
73
	$config['nat']['rule'] = array();
74
}
75

    
76
$a_nat = &$config['nat']['rule'];
77

    
78
/* update rule order, POST[rule] is an array of ordered IDs */
79
if (array_key_exists('order-store', $_POST)) {
80
	if (is_array($_POST['rule']) && !empty($_POST['rule'])) {
81
		$a_nat_new = array();
82

    
83
		// if a rule is not in POST[rule], it has been deleted by the user
84
		foreach ($_POST['rule'] as $id) {
85
			$a_nat_new[] = $a_nat[$id];
86
		}
87

    
88
		$a_nat = $a_nat_new;
89

    
90
		if (write_config()) {
91
			mark_subsystem_dirty('filter');
92
		}
93

    
94
		header("Location: firewall_nat.php");
95
		exit;
96
	}
97
}
98

    
99
/* if a custom message has been passed along, lets process it */
100
if ($_GET['savemsg']) {
101
	$savemsg = $_GET['savemsg'];
102
}
103

    
104
if ($_POST) {
105
	$pconfig = $_POST;
106

    
107
	if ($_POST['apply']) {
108

    
109
		$retval = 0;
110

    
111
		$retval |= filter_configure();
112
		$savemsg = get_std_save_message($retval);
113

    
114
		pfSense_handle_custom_code("/usr/local/pkg/firewall_nat/apply");
115

    
116
		if ($retval == 0) {
117
			clear_subsystem_dirty('natconf');
118
			clear_subsystem_dirty('filter');
119
		}
120

    
121
	}
122
}
123

    
124
if ($_GET['act'] == "del") {
125
	if ($a_nat[$_GET['id']]) {
126

    
127
		if (isset($a_nat[$_GET['id']]['associated-rule-id'])) {
128
			delete_id($a_nat[$_GET['id']]['associated-rule-id'], $config['filter']['rule']);
129
			$want_dirty_filter = true;
130
		}
131
		unset($a_nat[$_GET['id']]);
132

    
133
		if (write_config()) {
134
			mark_subsystem_dirty('natconf');
135
			if ($want_dirty_filter) {
136
				mark_subsystem_dirty('filter');
137
			}
138
		}
139

    
140
		header("Location: firewall_nat.php");
141
		exit;
142
	}
143
}
144

    
145
if (isset($_POST['del_x'])) {
146
	/* delete selected rules */
147
	if (is_array($_POST['rule']) && count($_POST['rule'])) {
148
		foreach ($_POST['rule'] as $rulei) {
149
		$target = $rule['target'];
150
			// Check for filter rule associations
151
			if (isset($a_nat[$rulei]['associated-rule-id'])) {
152
				delete_id($a_nat[$rulei]['associated-rule-id'], $config['filter']['rule']);
153

    
154
				mark_subsystem_dirty('filter');
155
			}
156

    
157
			unset($a_nat[$rulei]);
158
		}
159

    
160
		if (write_config()) {
161
			mark_subsystem_dirty('natconf');
162
		}
163

    
164
		header("Location: firewall_nat.php");
165
		exit;
166
	}
167
}
168

    
169
$closehead = false;
170
$pgtitle = array(gettext("Firewall"), gettext("NAT"), gettext("Port Forward"));
171
include("head.inc");
172

    
173
if ($savemsg) {
174
	print_info_box($savemsg, 'success');
175
}
176

    
177
if (is_subsystem_dirty('natconf')) {
178
	print_info_box_np(gettext('The NAT configuration has been changed.') . '<br />' .
179
					  gettext('You must apply the changes in order for them to take effect.') . '<br />');
180
}
181

    
182
$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
?>
189

    
190
<form action="firewall_nat.php" method="post" name="iform">
191
	<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
						<th><!-- Checkbox --></th>
198
						<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
<?php
213

    
214
$nnats = $i = 0;
215

    
216
foreach ($a_nat as $natent):
217

    
218
	$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

    
225
	/* if user does not have access to edit an interface skip on to the next record */
226
	if (!have_natpfruleint_access($natent['interface'])) {
227
		continue;
228
	}
229
?>
230

    
231
					<tr id="fr<?=$nnats;?>" onClick="fr_toggle(<?=$nnats;?>)" ondblclick="document.location='firewall_nat_edit.php?id=<?=$i;?>';">
232
						<td >
233
							<input type="checkbox" id="frc<?=$nnats;?>" onClick="fr_toggle(<?=$nnats;?>)" name="rule[]" value="<?=$i;?>"/>
234
						</td>
235
						<td>
236
<?php
237
	if ($natent['associated-rule-id'] == "pass"):
238
?>
239
							<i class="fa fa-play" title="<?=gettext("All traffic matching this NAT entry is passed")?>"></i>
240
<?php
241
	elseif (!empty($natent['associated-rule-id'])):
242
?>
243
							<i class="fa fa-random" title="<?=gettext("Firewall rule ID ")?><?=htmlspecialchars($natent['associated-rule-id'])?> . <?=gettext('is managed by this rule')?>"></i>
244
<?php
245
	endif;
246
?>
247
						</td>
248
						<td>
249
							<?=$textss?>
250
<?php
251
	if (!$natent['interface']) {
252
		echo htmlspecialchars(convert_friendly_interface_to_friendly_descr("wan"));
253
	} else {
254
		echo htmlspecialchars(convert_friendly_interface_to_friendly_descr($natent['interface']));
255
	}
256
?>
257
							<?=$textse?>
258
						</td>
259

    
260
						<td>
261
							<?=$textss?><?=strtoupper($natent['protocol'])?><?=$textse?>
262
						</td>
263

    
264
						<td>
265

    
266

    
267
<?php
268
	if (isset($alias['src'])):
269
?>
270
							<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">
271
<?php
272
	endif;
273
?>
274
							<?=htmlspecialchars(pprint_address($natent['source']))?>
275
<?php
276
	if (isset($alias['src'])):
277
?>
278
							<i class='fa fa-pencil'></i></a>
279
<?php
280
	endif;
281
?>
282
						</td>
283
						<td>
284
<?php
285
	if (isset($alias['srcport'])):
286
?>
287
							<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">
288
<?php
289
	endif;
290
?>
291
							<?=htmlspecialchars(pprint_port($natent['source']['port']))?>
292
<?php
293
	if (isset($alias['srcport'])):
294
?>
295
							<i class='fa fa-pencil'></i></a>
296
<?php
297
	endif;
298
?>
299
						</td>
300

    
301
						<td>
302
<?php
303
	if (isset($alias['dst'])):
304
?>
305
							<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">
306
<?php
307
	endif;
308
?>
309
							<?=htmlspecialchars(pprint_address($natent['destination']))?>
310
<?php
311
	if (isset($alias['dst'])):
312
?>
313
							<i class='fa fa-pencil'></i></a>
314
<?php
315
	endif;
316
?>
317
						</td>
318
						<td>
319
<?php
320
	if (isset($alias['dstport'])):
321
?>
322
							<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">
323
<?php
324
	endif;
325
?>
326
							<?=htmlspecialchars(pprint_port($natent['destination']['port']))?>
327
<?php
328
	if (isset($alias['dstport'])):
329
?>
330
							<i class='fa fa-pencil'></i></a>
331
<?php
332
	endif;
333
?>
334
						</td>
335

    
336
						<td >
337
							<?=htmlspecialchars($natent['target'])?>
338
						</td>
339
						<td>
340
<?php
341
	$localport = $natent['local-port'];
342

    
343
	list($dstbeginport, $dstendport) = explode("-", $natent['destination']['port']);
344

    
345
	if ($dstendport) {
346
		$localendport = $natent['local-port'] + $dstendport - $dstbeginport;
347
		$localport	 .= '-' . $localendport;
348
	}
349
?>
350
							<?=htmlspecialchars(pprint_port($localport))?>
351
						</td>
352

    
353
						<td>
354
							<?=htmlspecialchars($natent['descr'])?>
355
						</td>
356
						<td>
357
							<a class="fa fa-pencil" title="<?=gettext("Edit rule"); ?>" href="firewall_nat_edit.php?id=<?=$i?>"></a>
358
							<a class="fa fa-clone"	  title="<?=gettext("Add a new NAT based on this one")?>" href="firewall_nat_edit.php?dup=<?=$i?>"></a>
359
							<a class="fa fa-trash"	title="<?=gettext("Delete rule")?>" href="firewall_nat.php?act=del&amp;id=<?=$i?>"></a>
360
						</td>
361
					</tr>
362
<?php
363
	$i++;
364
	$nnats++;
365
endforeach;
366
?>
367
				</tbody>
368
			</table>
369
		</div>
370
	</div>
371

    
372
	<nav class="action-buttons">
373
		<a href="firewall_nat_edit.php?after=-1" class="btn btn-sm btn-success" title="<?=gettext('Add rule to the top of the list')?>">
374
			<i class="fa fa-level-up icon-embed-btn"></i>
375
			<?=gettext('Add')?>
376
		</a>
377
		<a href="firewall_nat_edit.php" class="btn btn-sm btn-success" title="<?=gettext('Add rule to the end of the list')?>">
378
			<i class="fa fa-level-down icon-embed-btn"></i>
379
			<?=gettext('Add')?>
380
		</a>
381
		<button name="del_x" type="submit" class="btn btn-danger btn-sm" title="<?=gettext('Delete selected rules')?>">
382
			<i class="fa fa-trash icon-embed-btn"></i>
383
			<?=gettext("Delete"); ?>
384
		</button>
385
		<button type="submit" id="order-store" name="order-store" class="btn btn-primary btn-sm" disabled title="<?=gettext('Save rule order')?>">
386
			<i class="fa fa-save icon-embed-btn"></i>
387
			<?=gettext("Save")?>
388
		</button>
389
	</nav>
390
</form>
391

    
392
<script type="text/javascript">
393
//<![CDATA[
394
events.push(function() {
395

    
396
	// Make rules sortable
397
	$('table tbody.user-entries').sortable({
398
		cursor: 'grabbing',
399
		update: function(event, ui) {
400
			$('#order-store').removeAttr('disabled');
401
		}
402
	});
403

    
404
	// Check all of the rule checkboxes so that their values are posted
405
	$('#order-store').click(function () {
406
	   $('[id^=frc]').prop('checked', true);
407
	});
408
});
409
//]]>
410
</script>
411
<?php
412

    
413
if (count($a_nat) > 0) {
414
?>
415
<!-- Legend -->
416
<div>
417
	<dl class="dl-horizontal responsive">
418
		<dt><?=gettext('Legend')?></dt>					<dd></dd>
419
		<dt><i class="fa fa-play"></i></dt>			<dd><?=gettext('Pass')?></dd>
420
		<dt><i class="fa fa-random"></i></dt>		<dd><?=gettext('Linked rule')?></dd>
421
	</dl>
422
</div>
423

    
424
<?php
425
}
426

    
427
include("foot.inc");
(41-41/228)