1
|
<?php
|
2
|
/* $Id$ */
|
3
|
/*
|
4
|
firewall_nat.php
|
5
|
*/
|
6
|
/* ====================================================================
|
7
|
* Copyright (c) 2004-2015 Electric Sheep Fencing, LLC. All rights reserved.
|
8
|
* Copyright (c) 2004 Scott Ullrich
|
9
|
* Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>
|
10
|
* originally part of m0n0wall (http://m0n0.ch/wall)
|
11
|
*
|
12
|
* Redistribution and use in source and binary forms, with or without modification,
|
13
|
* 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
|
20
|
* the documentation and/or other materials provided with the
|
21
|
* distribution.
|
22
|
*
|
23
|
* 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
|
*
|
28
|
* 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
|
*
|
33
|
* 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
|
*
|
37
|
* 6. Redistributions of any form whatsoever must retain the following
|
38
|
* acknowledgment:
|
39
|
*
|
40
|
* "This product includes software developed by the pfSense Project
|
41
|
* for use in the pfSense software distribution (http://www.pfsense.org/).
|
42
|
*
|
43
|
* 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
|
*
|
56
|
* ====================================================================
|
57
|
*
|
58
|
*/
|
59
|
/*
|
60
|
pfSense_MODULE: nat
|
61
|
*/
|
62
|
|
63
|
##|+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
|
require("guiconfig.inc");
|
71
|
require_once("functions.inc");
|
72
|
require_once("filter.inc");
|
73
|
require_once("shaper.inc");
|
74
|
require_once("itemid.inc");
|
75
|
|
76
|
if (!is_array($config['nat']['rule'])) {
|
77
|
$config['nat']['rule'] = array();
|
78
|
}
|
79
|
|
80
|
$a_nat = &$config['nat']['rule'];
|
81
|
|
82
|
/* update rule order, POST[rule] is an array of ordered IDs */
|
83
|
if($_POST['order-store']) {
|
84
|
if (is_array($_POST['rule']) && !empty($_POST['rule'])) {
|
85
|
$a_nat_new = array();
|
86
|
|
87
|
// 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
|
|
91
|
$a_nat = $a_nat_new;
|
92
|
|
93
|
if (write_config())
|
94
|
mark_subsystem_dirty('filter');
|
95
|
|
96
|
header("Location: firewall_nat.php");
|
97
|
exit;
|
98
|
}
|
99
|
}
|
100
|
|
101
|
/* if a custom message has been passed along, lets process it */
|
102
|
if ($_GET['savemsg']) {
|
103
|
$savemsg = $_GET['savemsg'];
|
104
|
}
|
105
|
|
106
|
if ($_POST) {
|
107
|
$pconfig = $_POST;
|
108
|
|
109
|
if ($_POST['apply']) {
|
110
|
|
111
|
$retval = 0;
|
112
|
|
113
|
$retval |= filter_configure();
|
114
|
$savemsg = get_std_save_message($retval);
|
115
|
|
116
|
pfSense_handle_custom_code("/usr/local/pkg/firewall_nat/apply");
|
117
|
|
118
|
if ($retval == 0) {
|
119
|
clear_subsystem_dirty('natconf');
|
120
|
clear_subsystem_dirty('filter');
|
121
|
}
|
122
|
|
123
|
}
|
124
|
}
|
125
|
|
126
|
if ($_GET['act'] == "del") {
|
127
|
if ($a_nat[$_GET['id']]) {
|
128
|
|
129
|
if (isset($a_nat[$_GET['id']]['associated-rule-id'])) {
|
130
|
delete_id($a_nat[$_GET['id']]['associated-rule-id'], $config['filter']['rule']);
|
131
|
$want_dirty_filter = true;
|
132
|
}
|
133
|
unset($a_nat[$_GET['id']]);
|
134
|
|
135
|
if (write_config()) {
|
136
|
mark_subsystem_dirty('natconf');
|
137
|
if ($want_dirty_filter) {
|
138
|
mark_subsystem_dirty('filter');
|
139
|
}
|
140
|
}
|
141
|
|
142
|
header("Location: firewall_nat.php");
|
143
|
exit;
|
144
|
}
|
145
|
}
|
146
|
|
147
|
if (isset($_POST['del_x'])) {
|
148
|
/* delete selected rules */
|
149
|
if (is_array($_POST['rule']) && count($_POST['rule'])) {
|
150
|
foreach ($_POST['rule'] as $rulei) {
|
151
|
$target = $rule['target'];
|
152
|
// Check for filter rule associations
|
153
|
if (isset($a_nat[$rulei]['associated-rule-id'])) {
|
154
|
delete_id($a_nat[$rulei]['associated-rule-id'], $config['filter']['rule']);
|
155
|
|
156
|
mark_subsystem_dirty('filter');
|
157
|
}
|
158
|
|
159
|
unset($a_nat[$rulei]);
|
160
|
}
|
161
|
|
162
|
if (write_config()) {
|
163
|
mark_subsystem_dirty('natconf');
|
164
|
}
|
165
|
|
166
|
header("Location: firewall_nat.php");
|
167
|
exit;
|
168
|
}
|
169
|
}
|
170
|
|
171
|
$closehead = false;
|
172
|
$pgtitle = array(gettext("Firewall"), gettext("NAT"), gettext("Port Forward"));
|
173
|
include("head.inc");
|
174
|
|
175
|
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
|
|
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
|
<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
|
<td>
|
235
|
<?php
|
236
|
if ($natent['associated-rule-id'] == "pass"):
|
237
|
?>
|
238
|
<i class="icon-play" title="<?=gettext("All traffic matching this NAT entry is passed")?>"></i>
|
239
|
<?php
|
240
|
elseif (!empty($natent['associated-rule-id'])):
|
241
|
?>
|
242
|
<i class="icon-random" title="<?=gettext("Firewall rule ID ")?><?=htmlspecialchars($nnatid)?> . <?=gettext('is managed by this rule')?>"></i>
|
243
|
<?php
|
244
|
endif;
|
245
|
?>
|
246
|
</td>
|
247
|
<td>
|
248
|
<?=$textss?>
|
249
|
<?php
|
250
|
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
|
?>
|
255
|
<?=$textse?>
|
256
|
</td>
|
257
|
|
258
|
<td>
|
259
|
<?=$textss?><?=strtoupper($natent['protocol'])?><?=$textse?>
|
260
|
</td>
|
261
|
|
262
|
<td>
|
263
|
|
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
|
</td>
|
281
|
<td>
|
282
|
<?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
|
</td>
|
298
|
|
299
|
<td>
|
300
|
<?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
|
</td>
|
316
|
<td>
|
317
|
<?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
|
</td>
|
333
|
|
334
|
<td >
|
335
|
<?=htmlspecialchars($natent['target'])?>
|
336
|
</td>
|
337
|
<td>
|
338
|
<?php
|
339
|
$localport = $natent['local-port'];
|
340
|
|
341
|
list($dstbeginport, $dstendport) = explode("-", $natent['destination']['port']);
|
342
|
|
343
|
if ($dstendport) {
|
344
|
$localendport = $natent['local-port'] + $dstendport - $dstbeginport;
|
345
|
$localport .= '-' . $localendport;
|
346
|
}
|
347
|
?>
|
348
|
<?=htmlspecialchars(pprint_port($localport))?>
|
349
|
</td>
|
350
|
|
351
|
<td>
|
352
|
<?=htmlspecialchars($natent['descr'])?>
|
353
|
</td>
|
354
|
<td>
|
355
|
<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&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
|
<?php
|
361
|
$i++;
|
362
|
$nnats++;
|
363
|
endforeach;
|
364
|
?>
|
365
|
</tbody>
|
366
|
</table>
|
367
|
</div>
|
368
|
</div>
|
369
|
|
370
|
<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
|
<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
|
</div>
|
375
|
</form>
|
376
|
|
377
|
<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
|
<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
|
|
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
|
});
|
417
|
</script>
|
418
|
<?php
|
419
|
|
420
|
if (count($a_nat) > 0) {
|
421
|
?>
|
422
|
<!-- 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
|
|
431
|
<?php
|
432
|
}
|
433
|
|
434
|
include("foot.inc");
|