Project

General

Profile

Download (13 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
} else if ($_GET['act'] == "toggle") {
168
	if ($a_nat[$_GET['id']]) {
169
		if (isset($a_nat[$_GET['id']]['disabled'])) {
170
			unset($a_nat[$_GET['id']]['disabled']);
171
		} else {
172
			$a_nat[$_GET['id']]['disabled'] = true;
173
		}
174
		if (write_config(gettext("Firewall: NAT: Port forward, enable/disable NAT rule"))) {
175
			mark_subsystem_dirty('natconf');
176
		}
177
		header("Location: firewall_nat.php");
178
		exit;
179
	}
180
}
181

    
182
$pgtitle = array(gettext("Firewall"), gettext("NAT"), gettext("Port Forward"));
183
include("head.inc");
184

    
185
if ($savemsg) {
186
	print_info_box($savemsg, 'success');
187
}
188

    
189
if (is_subsystem_dirty('natconf')) {
190
	print_apply_box(gettext('The NAT configuration has been changed.') . '<br />' .
191
					gettext('You must apply the changes in order for them to take effect.'));
192
}
193

    
194
$tab_array = array();
195
$tab_array[] = array(gettext("Port Forward"), true, "firewall_nat.php");
196
$tab_array[] = array(gettext("1:1"), false, "firewall_nat_1to1.php");
197
$tab_array[] = array(gettext("Outbound"), false, "firewall_nat_out.php");
198
$tab_array[] = array(gettext("NPt"), false, "firewall_nat_npt.php");
199
display_top_tabs($tab_array);
200
?>
201

    
202
<form action="firewall_nat.php" method="post" name="iform">
203
	<div class="panel panel-default">
204
		<div class="panel-heading"><h2 class="panel-title"><?=gettext('Rules')?></h2></div>
205
		<div class="panel-body table-responsive">
206
			<table class="table table-striped table-hover table-condensed">
207
				<thead>
208
					<tr>
209
						<th><!-- Checkbox --></th>
210
						<th><!-- Icon --></th>
211
						<th><!-- Rule type --></th>
212
						<th><?=gettext("Interface")?></th>
213
						<th><?=gettext("Protocol")?></th>
214
						<th><?=gettext("Source Address")?></th>
215
						<th><?=gettext("Source Ports")?></th>
216
						<th><?=gettext("Dest. Address")?></th>
217
						<th><?=gettext("Dest. Ports")?></th>
218
						<th><?=gettext("NAT IP")?></th>
219
						<th><?=gettext("NAT Ports")?></th>
220
						<th><?=gettext("Description")?></th>
221
						<th><?=gettext("Actions")?></th>
222
					</tr>
223
				</thead>
224
				<tbody class='user-entries'>
225
<?php
226

    
227
$nnats = $i = 0;
228

    
229
foreach ($a_nat as $natent):
230

    
231
	$alias = rule_columns_with_alias(
232
		$natent['source']['address'],
233
		pprint_port($natent['source']['port']),
234
		$natent['destination']['address'],
235
		pprint_port($natent['destination']['port'])
236
	);
237

    
238
	/* if user does not have access to edit an interface skip on to the next record */
239
	if (!have_natpfruleint_access($natent['interface'])) {
240
		continue;
241
	}
242

    
243
	if (isset($natent['disabled'])) {
244
		$iconfn = "pass_d";
245
		$trclass = 'class="disabled"';
246
	} else {
247
		$iconfn = "pass";
248
		$trclass = '';
249
	}
250
?>
251

    
252
					<tr id="fr<?=$nnats;?>" <?=$trclass?> onClick="fr_toggle(<?=$nnats;?>)" ondblclick="document.location='firewall_nat_edit.php?id=<?=$i;?>';">
253
						<td >
254
							<input type="checkbox" id="frc<?=$nnats;?>" onClick="fr_toggle(<?=$nnats;?>)" name="rule[]" value="<?=$i;?>"/>
255
						</td>
256
						<td>
257
							<a href="?act=toggle&amp;id=<?=$i?>">
258
								<i class="fa <?= ($iconfn == "pass") ? "fa-check":"fa-times"?>" title="<?=gettext("click to toggle enabled/disabled status")?>"></i>
259
							</a>
260
						</td>
261
						<td>
262
<?php
263
	if ($natent['associated-rule-id'] == "pass"):
264
?>
265
							<i class="fa fa-play" title="<?=gettext("All traffic matching this NAT entry is passed")?>"></i>
266
<?php
267
	elseif (!empty($natent['associated-rule-id'])):
268
?>
269
							<i class="fa fa-random" title="<?=sprintf(gettext("Firewall rule ID %s is managed by this rule"), htmlspecialchars($natent['associated-rule-id']))?>"></i>
270
<?php
271
	endif;
272
?>
273
						</td>
274
						<td>
275
							<?=$textss?>
276
<?php
277
	if (!$natent['interface']) {
278
		echo htmlspecialchars(convert_friendly_interface_to_friendly_descr("wan"));
279
	} else {
280
		echo htmlspecialchars(convert_friendly_interface_to_friendly_descr($natent['interface']));
281
	}
282
?>
283
							<?=$textse?>
284
						</td>
285

    
286
						<td>
287
							<?=$textss?><?=strtoupper($natent['protocol'])?><?=$textse?>
288
						</td>
289

    
290
						<td>
291

    
292

    
293
<?php
294
	if (isset($alias['src'])):
295
?>
296
							<a href="/firewall_aliases_edit.php?id=<?=$alias['src']?>" data-toggle="popover" data-trigger="hover focus" title="<?=gettext('Alias details')?>" data-content="<?=alias_info_popup($alias['src'])?>" data-html="true">
297
<?php
298
	endif;
299
?>
300
							<?=htmlspecialchars(pprint_address($natent['source']))?>
301
<?php
302
	if (isset($alias['src'])):
303
?>
304
							<i class='fa fa-pencil'></i></a>
305
<?php
306
	endif;
307
?>
308
						</td>
309
						<td>
310
<?php
311
	if (isset($alias['srcport'])):
312
?>
313
							<a href="/firewall_aliases_edit.php?id=<?=$alias['srcport']?>" data-toggle="popover" data-trigger="hover focus" title="<?=gettext('Alias details')?>" data-content="<?=alias_info_popup($alias['srcport'])?>" data-html="true">
314
<?php
315
	endif;
316
?>
317
							<?=htmlspecialchars(pprint_port($natent['source']['port']))?>
318
<?php
319
	if (isset($alias['srcport'])):
320
?>
321
							<i class='fa fa-pencil'></i></a>
322
<?php
323
	endif;
324
?>
325
						</td>
326

    
327
						<td>
328
<?php
329
	if (isset($alias['dst'])):
330
?>
331
							<a href="/firewall_aliases_edit.php?id=<?=$alias['dst']?>" data-toggle="popover" data-trigger="hover focus" title="<?=gettext('Alias details')?>" data-content="<?=alias_info_popup($alias['dst'])?>" data-html="true">
332
<?php
333
	endif;
334
?>
335
							<?=htmlspecialchars(pprint_address($natent['destination']))?>
336
<?php
337
	if (isset($alias['dst'])):
338
?>
339
							<i class='fa fa-pencil'></i></a>
340
<?php
341
	endif;
342
?>
343
						</td>
344
						<td>
345
<?php
346
	if (isset($alias['dstport'])):
347
?>
348
							<a href="/firewall_aliases_edit.php?id=<?=$alias['dstport']?>" data-toggle="popover" data-trigger="hover focus" title="<?=gettext('Alias details')?>" data-content="<?=alias_info_popup($alias['dstport'])?>" data-html="true">
349
<?php
350
	endif;
351
?>
352
							<?=htmlspecialchars(pprint_port($natent['destination']['port']))?>
353
<?php
354
	if (isset($alias['dstport'])):
355
?>
356
							<i class='fa fa-pencil'></i></a>
357
<?php
358
	endif;
359
?>
360
						</td>
361

    
362
						<td >
363
							<?=htmlspecialchars($natent['target'])?>
364
						</td>
365
						<td>
366
<?php
367
	$localport = $natent['local-port'];
368

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

    
371
	if ($dstendport) {
372
		$localendport = $natent['local-port'] + $dstendport - $dstbeginport;
373
		$localport	 .= '-' . $localendport;
374
	}
375
?>
376
							<?=htmlspecialchars(pprint_port($localport))?>
377
						</td>
378

    
379
						<td>
380
							<?=htmlspecialchars($natent['descr'])?>
381
						</td>
382
						<td>
383
							<a class="fa fa-pencil" title="<?=gettext("Edit rule"); ?>" href="firewall_nat_edit.php?id=<?=$i?>"></a>
384
							<a class="fa fa-clone"	  title="<?=gettext("Add a new NAT based on this one")?>" href="firewall_nat_edit.php?dup=<?=$i?>"></a>
385
							<a class="fa fa-trash"	title="<?=gettext("Delete rule")?>" href="firewall_nat.php?act=del&amp;id=<?=$i?>"></a>
386
						</td>
387
					</tr>
388
<?php
389
	$i++;
390
	$nnats++;
391
endforeach;
392
?>
393
				</tbody>
394
			</table>
395
		</div>
396
	</div>
397

    
398
	<nav class="action-buttons">
399
		<a href="firewall_nat_edit.php?after=-1" class="btn btn-sm btn-success" title="<?=gettext('Add rule to the top of the list')?>">
400
			<i class="fa fa-level-up icon-embed-btn"></i>
401
			<?=gettext('Add')?>
402
		</a>
403
		<a href="firewall_nat_edit.php" class="btn btn-sm btn-success" title="<?=gettext('Add rule to the end of the list')?>">
404
			<i class="fa fa-level-down icon-embed-btn"></i>
405
			<?=gettext('Add')?>
406
		</a>
407
		<button name="del_x" type="submit" class="btn btn-danger btn-sm" title="<?=gettext('Delete selected rules')?>">
408
			<i class="fa fa-trash icon-embed-btn"></i>
409
			<?=gettext("Delete"); ?>
410
		</button>
411
		<button type="submit" id="order-store" name="order-store" class="btn btn-primary btn-sm" disabled title="<?=gettext('Save rule order')?>">
412
			<i class="fa fa-save icon-embed-btn"></i>
413
			<?=gettext("Save")?>
414
		</button>
415
	</nav>
416
</form>
417

    
418
<script type="text/javascript">
419
//<![CDATA[
420
events.push(function() {
421

    
422
	// Make rules sortable
423
	$('table tbody.user-entries').sortable({
424
		cursor: 'grabbing',
425
		update: function(event, ui) {
426
			$('#order-store').removeAttr('disabled');
427
		}
428
	});
429

    
430
	// Check all of the rule checkboxes so that their values are posted
431
	$('#order-store').click(function () {
432
	   $('[id^=frc]').prop('checked', true);
433
	});
434
});
435
//]]>
436
</script>
437
<?php
438

    
439
if (count($a_nat) > 0) {
440
?>
441
<!-- Legend -->
442
<div>
443
	<dl class="dl-horizontal responsive">
444
		<dt><?=gettext('Legend')?></dt>					<dd></dd>
445
		<dt><i class="fa fa-play"></i></dt>			<dd><?=gettext('Pass')?></dd>
446
		<dt><i class="fa fa-random"></i></dt>		<dd><?=gettext('Linked rule')?></dd>
447
	</dl>
448
</div>
449

    
450
<?php
451
}
452

    
453
include("foot.inc");
(41-41/229)