Project

General

Profile

Download (13.8 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * firewall_nat.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8
 * Copyright (c) 2014-2022 Rubicon Communications, LLC (Netgate)
9
 * All rights reserved.
10
 *
11
 * originally based on m0n0wall (http://m0n0.ch/wall)
12
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
13
 * All rights reserved.
14
 *
15
 * Licensed under the Apache License, Version 2.0 (the "License");
16
 * you may not use this file except in compliance with the License.
17
 * You may obtain a copy of the License at
18
 *
19
 * http://www.apache.org/licenses/LICENSE-2.0
20
 *
21
 * Unless required by applicable law or agreed to in writing, software
22
 * distributed under the License is distributed on an "AS IS" BASIS,
23
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
 * See the License for the specific language governing permissions and
25
 * limitations under the License.
26
 */
27

    
28
##|+PRIV
29
##|*IDENT=page-firewall-nat-portforward
30
##|*NAME=Firewall: NAT: Port Forward
31
##|*DESCR=Allow access to the 'Firewall: NAT: Port Forward' page.
32
##|*MATCH=firewall_nat.php*
33
##|-PRIV
34

    
35
require_once("guiconfig.inc");
36
require_once("functions.inc");
37
require_once("filter.inc");
38
require_once("shaper.inc");
39
require_once("itemid.inc");
40
require_once("firewall_nat.inc");
41

    
42
init_config_arr(array('nat', 'rule'));
43
$a_nat = &$config['nat']['rule'];
44

    
45
// Process $_POST/$_REQUEST =======================================================================
46
if ($_REQUEST['savemsg']) {
47
	$savemsg = $_REQUEST['savemsg'];
48
}
49

    
50
if (array_key_exists('order-store', $_REQUEST) && have_natpfruleint_access($natent['interface'])) {
51
	reorderNATrules($_POST);
52
} else if ($_POST['apply'] && have_natpfruleint_access($natent['interface'])) {
53
	$retval = applyNATrules();
54
} else if (($_POST['act'] == "del") && have_natpfruleint_access($natent['interface'])) {
55
	if ($a_nat[$_POST['id']]) {
56
		deleteNATrule($_POST);
57
	}
58
} else if (isset($_POST['del_x']) && have_natpfruleint_access($natent['interface'])) {
59
	/* delete selected rules */
60
	if (is_array($_POST['rule']) && count($_POST['rule'])) {
61
		deleteMultipleNATrules($_POST);
62
	}
63
} elseif (($_POST['act'] == "toggle") && have_natpfruleint_access($natent['interface'])) {
64
	if ($a_nat[$_POST['id']]) {
65
		toggleNATrule($_POST);
66
	}
67
}
68

    
69
// Construct the page =============================================================================
70
$pgtitle = array(gettext("Firewall"), gettext("NAT"), gettext("Port Forward"));
71
$pglinks = array("", "@self", "@self");
72
include("head.inc");
73

    
74
if ($_POST['apply']) {
75
	print_apply_result_box($retval);
76
}
77

    
78
if (is_subsystem_dirty('natconf') && have_natpfruleint_access($natent['interface'])) {
79
	print_apply_box(gettext('The NAT configuration has been changed.') . '<br />' .
80
					gettext('The changes must be applied for them to take effect.'));
81
}
82

    
83
$tab_array = array();
84
$tab_array[] = array(gettext("Port Forward"), true, "firewall_nat.php");
85
$tab_array[] = array(gettext("1:1"), false, "firewall_nat_1to1.php");
86
$tab_array[] = array(gettext("Outbound"), false, "firewall_nat_out.php");
87
$tab_array[] = array(gettext("NPt"), false, "firewall_nat_npt.php");
88
display_top_tabs($tab_array);
89

    
90
$columns_in_table = 13;
91
?>
92
<!-- Allow table to scroll when dragging outside of the display window -->
93
<style>
94
.table-responsive {
95
    clear: both;
96
    overflow-x: visible;
97
    margin-bottom: 0px;
98
}
99
</style>
100

    
101
<form action="firewall_nat.php" method="post" name="iform">
102
	<div class="panel panel-default">
103
		<div class="panel-heading"><h2 class="panel-title"><?=gettext('Rules')?></h2></div>
104
		<div class="panel-body table-responsive">
105
			<table id="ruletable" class="table table-striped table-hover table-condensed">
106
				<thead>
107
					<tr>
108
						<th style="padding-left:10px;">  <input type="checkbox" id="selectAll" name="selectAll" /></th>
109
						<th><!-- Icon --></th>
110
						<th><!-- Rule type --></th>
111
						<th><?=gettext("Interface")?></th>
112
						<th><?=gettext("Protocol")?></th>
113
						<th><?=gettext("Source Address")?></th>
114
						<th><?=gettext("Source Ports")?></th>
115
						<th><?=gettext("Dest. Address")?></th>
116
						<th><?=gettext("Dest. Ports")?></th>
117
						<th><?=gettext("NAT IP")?></th>
118
						<th><?=gettext("NAT Ports")?></th>
119
						<th><?=gettext("Description")?></th>
120
						<th><?=gettext("Actions")?></th>
121
					</tr>
122
				</thead>
123
				<tbody class='user-entries'>
124
<?php
125

    
126
$nnats = $i = 0;
127
$separators = $config['nat']['separator'];
128

    
129
// Get a list of separator rows and use it to call the display separator function only for rows which there are separator(s).
130
// More efficient than looping through the list of separators on every row.
131
$seprows = separator_rows($separators);
132

    
133
foreach ($a_nat as $natent):
134

    
135
	// Display separator(s) for section beginning at rule n
136
	if ($seprows[$nnats]) {
137
		display_separator($separators, $nnats, $columns_in_table);
138
	}
139

    
140
	$localport = $natent['local-port'];
141

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

    
144
	if ($dstendport && is_port($localport)) {
145
		$localendport = $natent['local-port'] + $dstendport - $dstbeginport;
146
		$localport	 .= '-' . $localendport;
147
	}
148

    
149
	$alias = rule_columns_with_alias(
150
		$natent['source']['address'],
151
		pprint_port($natent['source']['port']),
152
		$natent['destination']['address'],
153
		pprint_port($natent['destination']['port']),
154
		$natent['target'],
155
		$localport
156
	);
157

    
158
	if (isset($natent['disabled'])) {
159
		$iconfn = "pass_d";
160
		$trclass = 'class="disabled"';
161
	} else {
162
		$iconfn = "pass";
163
		$trclass = '';
164
	}
165

    
166
	if (is_specialnet($natent['target'])) {
167
		foreach ($ifdisp as $kif => $kdescr) {
168
			if ($natent['target'] == "{$kif}ip") {
169
				$natent['target'] = $kdescr . ' address';
170
				break;
171
			}
172
		}
173
	}
174
?>
175

    
176
					<tr id="fr<?=$nnats;?>" <?=$trclass?> onClick="fr_toggle(<?=$nnats;?>)" ondblclick="document.location='firewall_nat_edit.php?id=<?=$i;?>';">
177
						<td >
178
<?php	if (have_natpfruleint_access($natent['interface'])): ?>
179
							<input type="checkbox" id="frc<?=$nnats;?>" onClick="fr_toggle(<?=$nnats;?>)" name="rule[]" value="<?=$i;?>"/>
180
<?php	endif; ?>
181
						</td>
182
						<td>
183
<?php	if (have_natpfruleint_access($natent['interface'])): ?>
184
							<a href="?act=toggle&amp;id=<?=$i?>" usepost>
185
								<i class="fa fa-check" title="<?=gettext("click to toggle enabled/disabled status")?>"></i>
186
							</a>
187
<?php	endif; ?>
188
<?php 	if (isset($natent['nordr'])) { ?>
189
								&nbsp;<i class="fa fa-hand-stop-o text-danger" title="<?=gettext("Negated: This rule excludes NAT from a later rule")?>"></i>
190
<?php 	} ?>
191
						</td>
192
						<td>
193
<?php
194
	if ($natent['associated-rule-id'] == "pass"):
195
?>
196
							<i class="fa fa-play" title="<?=gettext("All traffic matching this NAT entry is passed")?>"></i>
197
<?php
198
	elseif (!empty($natent['associated-rule-id'])):
199
?>
200
							<i class="fa fa-random" title="<?=sprintf(gettext("Firewall rule ID %s is managed by this rule"), htmlspecialchars($natent['associated-rule-id']))?>"></i>
201
<?php
202
	endif;
203
?>
204
						</td>
205
						<td>
206
							<?=$textss?>
207
<?php
208
	if (!$natent['interface']) {
209
		echo htmlspecialchars(convert_friendly_interface_to_friendly_descr("wan"));
210
	} else {
211
		echo htmlspecialchars(convert_friendly_interface_to_friendly_descr($natent['interface']));
212
	}
213
?>
214
							<?=$textse?>
215
						</td>
216

    
217
						<td>
218
							<?=$textss?><?=strtoupper($natent['protocol'])?><?=$textse?>
219
						</td>
220

    
221
						<td>
222

    
223

    
224
<?php
225
	if (isset($alias['src'])):
226
?>
227
							<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">
228
<?php
229
	endif;
230
?>
231
							<?=str_replace('_', '_<wbr>', htmlspecialchars(pprint_address($natent['source'])))?>
232
<?php
233
	if (isset($alias['src'])):
234
?>
235
							</a>
236
<?php
237
	endif;
238
?>
239
						</td>
240
						<td>
241
<?php
242
	if (isset($alias['srcport'])):
243
?>
244
							<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">
245
<?php
246
	endif;
247
?>
248
							<?=str_replace('_', '_<wbr>', htmlspecialchars(pprint_port($natent['source']['port'])))?>
249
<?php
250
	if (isset($alias['srcport'])):
251
?>
252
							</a>
253
<?php
254
	endif;
255
?>
256
						</td>
257

    
258
						<td>
259
<?php
260
	if (isset($alias['dst'])):
261
?>
262
							<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">
263
<?php
264
	endif;
265
?>
266
							<?=str_replace('_', '_<wbr>', htmlspecialchars(pprint_address($natent['destination'])))?>
267
<?php
268
	if (isset($alias['dst'])):
269
?>
270
							</a>
271
<?php
272
	endif;
273
?>
274
						</td>
275
						<td>
276
<?php
277
	if (isset($alias['dstport'])):
278
?>
279
							<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">
280
<?php
281
	endif;
282
?>
283
							<?=str_replace('_', '_<wbr>', htmlspecialchars(pprint_port($natent['destination']['port'])))?>
284
<?php
285
	if (isset($alias['dstport'])):
286
?>
287
							</a>
288
<?php
289
	endif;
290
?>
291
						</td>
292
						<td>
293
<?php
294
	if (isset($alias['target'])):
295
?>
296
							<a href="/firewall_aliases_edit.php?id=<?=$alias['target']?>" data-toggle="popover" data-trigger="hover focus" title="<?=gettext('Alias details')?>" data-content="<?=alias_info_popup($alias['target'])?>" data-html="true" >
297
<?php
298
	endif;
299
?>
300

    
301
							<?=str_replace('_', '_<wbr>', htmlspecialchars($natent['target']))?>
302
<?php
303
	if (isset($alias['target'])):
304
?>
305
							</a>
306
<?php
307
	endif;
308
?>
309
						</td>
310
						<td>
311
<?php
312
	if (isset($alias['targetport'])):
313
?>
314
							<a href="/firewall_aliases_edit.php?id=<?=$alias['targetport']?>" data-toggle="popover" data-trigger="hover focus" title="<?=gettext('Alias details')?>" data-content="<?=alias_info_popup($alias['targetport'])?>" data-html="true">
315
<?php
316
	endif;
317
?>
318
							<?=str_replace('_', '_<wbr>', htmlspecialchars(pprint_port($localport)))?>
319
<?php
320
	if (isset($alias['targetport'])):
321
?>
322
							</a>
323
<?php
324
	endif;
325
?>
326
						</td>
327

    
328
						<td>
329
							<?=htmlspecialchars($natent['descr'])?>
330
						</td>
331
						<td>
332
<?php	if (have_natpfruleint_access($natent['interface'])): ?>
333
							<a class="fa fa-pencil" title="<?=gettext("Edit rule"); ?>" href="firewall_nat_edit.php?id=<?=$i?>"></a>
334
							<a class="fa fa-clone"	  title="<?=gettext("Add a new NAT based on this one")?>" href="firewall_nat_edit.php?dup=<?=$i?>"></a>
335
							<a class="fa fa-trash"	title="<?=gettext("Delete rule")?>" href="firewall_nat.php?act=del&amp;id=<?=$i?>" usepost></a>
336
<?php	else: ?>
337
							-
338
<?php	endif; ?>
339
						</td>
340
					</tr>
341
<?php
342
	$i++;
343
	$nnats++;
344

    
345
endforeach;
346

    
347
// There can be separator(s) after the last rule listed.
348
if ($seprows[$nnats]) {
349
	display_separator($separators, $nnats, $columns_in_table);
350
}
351
?>
352
				</tbody>
353
			</table>
354
		</div>
355
	</div>
356

    
357
<?php	if (have_natpfruleint_access($natent['interface'])): ?>
358
	<nav class="action-buttons">
359
		<a href="firewall_nat_edit.php?after=-1" class="btn btn-sm btn-success" title="<?=gettext('Add rule to the top of the list')?>">
360
			<i class="fa fa-level-up icon-embed-btn"></i>
361
			<?=gettext('Add')?>
362
		</a>
363
		<a href="firewall_nat_edit.php" class="btn btn-sm btn-success" title="<?=gettext('Add rule to the end of the list')?>">
364
			<i class="fa fa-level-down icon-embed-btn"></i>
365
			<?=gettext('Add')?>
366
		</a>
367
		<button name="del_x" type="submit" class="btn btn-danger btn-sm" title="<?=gettext('Delete selected rules')?>">
368
			<i class="fa fa-trash icon-embed-btn"></i>
369
			<?=gettext("Delete"); ?>
370
		</button>
371
		<button type="submit" id="order-store" name="order-store" class="btn btn-primary btn-sm" disabled title="<?=gettext('Save rule order')?>">
372
			<i class="fa fa-save icon-embed-btn"></i>
373
			<?=gettext("Save")?>
374
		</button>
375
		<button type="submit" id="addsep" name="addsep" class="btn btn-sm btn-warning" title="<?=gettext('Add separator')?>">
376
			<i class="fa fa-plus icon-embed-btn"></i>
377
			<?=gettext("Separator")?>
378
		</button>
379
	</nav>
380
<?php	endif; ?>
381
</form>
382

    
383
<script type="text/javascript">
384
//<![CDATA[
385
//Need to create some variables here so that jquery/pfSenseHelpers.js can read them
386
iface = "<?=strtolower($if)?>";
387
cncltxt = '<?=gettext("Cancel")?>';
388
svtxt = '<?=gettext("Save")?>';
389
svbtnplaceholder = '<?=gettext("Enter a description, Save, then drag to final location.")?>';
390
configsection = "nat";
391
dirty = false;
392

    
393
events.push(function() {
394

    
395
<?php if(!isset($config['system']['webgui']['roworderdragging'])): ?>
396
	// Make rules sortable
397
	$('table tbody.user-entries').sortable({
398
		cursor: 'grabbing',
399
		update: function(event, ui) {
400
			$('#order-store').removeAttr('disabled');
401
			dirty = true;
402
			reindex_rules(ui.item.parent('tbody'));
403
			dirty = true;
404
		}
405
	});
406
<?php endif; ?>
407

    
408
	// Check all of the rule checkboxes so that their values are posted
409
	$('#order-store').click(function () {
410
	   $('[id^=frc]').prop('checked', true);
411

    
412
		// Save the separator bar configuration
413
		save_separators();
414

    
415
		// Suppress the "Do you really want to leave the page" message
416
		saving = true;
417

    
418
	});
419

    
420
	// Globals
421
	saving = false;
422
	dirty = false;
423

    
424
	// provide a warning message if the user tries to change page before saving
425
	// Unfortunately the custom message is not supported in modern browsers, but he user wil lat
426
	// least see a generic warning message
427
	$(window).bind('beforeunload', function(){
428
		if (!saving && dirty) {
429
			return ("<?=gettext('One or more Port Forward rules have been moved but have not yet been saved')?>");
430
		} else {
431
			return undefined;
432
		}
433
	});
434

    
435
	$('#selectAll').click(function() {
436
		var checkedStatus = this.checked;
437
		$('#ruletable tbody tr').find('td:first :checkbox').each(function() {
438
		$(this).prop('checked', checkedStatus);
439
		});
440
	});
441
});
442
//]]>
443
</script>
444
<?php
445

    
446
if (count($a_nat) > 0) {
447
?>
448
<!-- Legend -->
449
<div>
450
	<dl class="dl-horizontal responsive">
451
		<dt><?=gettext('Legend')?></dt>					<dd></dd>
452
		<dt><i class="fa fa-play"></i></dt>			<dd><?=gettext('Pass')?></dd>
453
		<dt><i class="fa fa-random"></i></dt>		<dd><?=gettext('Linked rule')?></dd>
454
	</dl>
455
</div>
456

    
457
<?php
458
}
459

    
460
include("foot.inc");
(42-42/228)