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
|
pfSense_MODULE: nat
|
60
|
*/
|
61
|
|
62
|
##|+PRIV
|
63
|
##|*IDENT=page-firewall-nat-portforward
|
64
|
##|*NAME=Firewall: NAT: Port Forward page
|
65
|
##|*DESCR=Allow access to the 'Firewall: NAT: Port Forward' page.
|
66
|
##|*MATCH=firewall_nat.php*
|
67
|
##|-PRIV
|
68
|
|
69
|
require("guiconfig.inc");
|
70
|
require_once("functions.inc");
|
71
|
require_once("filter.inc");
|
72
|
require_once("shaper.inc");
|
73
|
require_once("itemid.inc");
|
74
|
|
75
|
if (!is_array($config['nat']['rule'])) {
|
76
|
$config['nat']['rule'] = array();
|
77
|
}
|
78
|
|
79
|
$a_nat = &$config['nat']['rule'];
|
80
|
|
81
|
/* update rule order, POST[rule] is an array of ordered IDs */
|
82
|
if($_POST['order-store']) {
|
83
|
if (is_array($_POST['rule']) && !empty($_POST['rule'])) {
|
84
|
$a_nat_new = array();
|
85
|
|
86
|
// if a rule is not in POST[rule], it has been deleted by the user
|
87
|
foreach ($_POST['rule'] as $id)
|
88
|
$a_nat_new[] = $a_nat[$id];
|
89
|
|
90
|
$a_nat = $a_nat_new;
|
91
|
|
92
|
if (write_config())
|
93
|
mark_subsystem_dirty('filter');
|
94
|
|
95
|
header("Location: firewall_nat.php");
|
96
|
exit;
|
97
|
}
|
98
|
}
|
99
|
|
100
|
/* if a custom message has been passed along, lets process it */
|
101
|
if ($_GET['savemsg']) {
|
102
|
$savemsg = $_GET['savemsg'];
|
103
|
}
|
104
|
|
105
|
if ($_POST) {
|
106
|
$pconfig = $_POST;
|
107
|
|
108
|
if ($_POST['apply']) {
|
109
|
|
110
|
$retval = 0;
|
111
|
|
112
|
$retval |= filter_configure();
|
113
|
$savemsg = get_std_save_message($retval);
|
114
|
|
115
|
pfSense_handle_custom_code("/usr/local/pkg/firewall_nat/apply");
|
116
|
|
117
|
if ($retval == 0) {
|
118
|
clear_subsystem_dirty('natconf');
|
119
|
clear_subsystem_dirty('filter');
|
120
|
}
|
121
|
|
122
|
}
|
123
|
}
|
124
|
|
125
|
if ($_GET['act'] == "del") {
|
126
|
if ($a_nat[$_GET['id']]) {
|
127
|
|
128
|
if (isset($a_nat[$_GET['id']]['associated-rule-id'])) {
|
129
|
delete_id($a_nat[$_GET['id']]['associated-rule-id'], $config['filter']['rule']);
|
130
|
$want_dirty_filter = true;
|
131
|
}
|
132
|
unset($a_nat[$_GET['id']]);
|
133
|
|
134
|
if (write_config()) {
|
135
|
mark_subsystem_dirty('natconf');
|
136
|
if ($want_dirty_filter) {
|
137
|
mark_subsystem_dirty('filter');
|
138
|
}
|
139
|
}
|
140
|
|
141
|
header("Location: firewall_nat.php");
|
142
|
exit;
|
143
|
}
|
144
|
}
|
145
|
|
146
|
if (isset($_POST['del_x'])) {
|
147
|
/* delete selected rules */
|
148
|
if (is_array($_POST['rule']) && count($_POST['rule'])) {
|
149
|
foreach ($_POST['rule'] as $rulei) {
|
150
|
$target = $rule['target'];
|
151
|
// Check for filter rule associations
|
152
|
if (isset($a_nat[$rulei]['associated-rule-id'])) {
|
153
|
delete_id($a_nat[$rulei]['associated-rule-id'], $config['filter']['rule']);
|
154
|
|
155
|
mark_subsystem_dirty('filter');
|
156
|
}
|
157
|
|
158
|
unset($a_nat[$rulei]);
|
159
|
}
|
160
|
|
161
|
if (write_config()) {
|
162
|
mark_subsystem_dirty('natconf');
|
163
|
}
|
164
|
|
165
|
header("Location: firewall_nat.php");
|
166
|
exit;
|
167
|
}
|
168
|
}
|
169
|
|
170
|
$closehead = false;
|
171
|
$pgtitle = array(gettext("Firewall"), gettext("NAT"), gettext("Port Forward"));
|
172
|
include("head.inc");
|
173
|
|
174
|
if ($savemsg)
|
175
|
print_info_box($savemsg, 'success');
|
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
|
$tab_array = array();
|
182
|
$tab_array[] = array(gettext("Port Forward"), true, "firewall_nat.php");
|
183
|
$tab_array[] = array(gettext("1:1"), false, "firewall_nat_1to1.php");
|
184
|
$tab_array[] = array(gettext("Outbound"), false, "firewall_nat_out.php");
|
185
|
$tab_array[] = array(gettext("NPt"), false, "firewall_nat_npt.php");
|
186
|
display_top_tabs($tab_array);
|
187
|
?>
|
188
|
|
189
|
<form action="firewall_nat.php" method="post" name="iform">
|
190
|
<div class="panel panel-default">
|
191
|
<div class="panel-heading"><?=gettext('Rules')?></div>
|
192
|
<div class="panel-body table-responsive">
|
193
|
<table class="table table-striped table-hover table-condensed">
|
194
|
<thead>
|
195
|
<tr>
|
196
|
<th><!-- Checkbox --></th>
|
197
|
<th><!-- Rule type --></th>
|
198
|
<th><?=gettext("If")?></th>
|
199
|
<th><?=gettext("Proto")?></th>
|
200
|
<th><?=gettext("Src. addr")?></th>
|
201
|
<th><?=gettext("Src. ports")?></th>
|
202
|
<th><?=gettext("Dest. addr")?></th>
|
203
|
<th><?=gettext("Dest. ports")?></th>
|
204
|
<th><?=gettext("NAT IP")?></th>
|
205
|
<th><?=gettext("NAT Ports")?></th>
|
206
|
<th><?=gettext("Description")?></th>
|
207
|
<th><?=gettext("Actions")?></th>
|
208
|
</tr>
|
209
|
</thead>
|
210
|
<tbody class='user-entries'>
|
211
|
<?php
|
212
|
|
213
|
$nnats = $i = 0;
|
214
|
|
215
|
foreach ($a_nat as $natent):
|
216
|
|
217
|
$alias = rule_columns_with_alias(
|
218
|
$natent['source']['address'],
|
219
|
pprint_port($natent['source']['port']),
|
220
|
$natent['destination']['address'],
|
221
|
pprint_port($natent['destination']['port'])
|
222
|
);
|
223
|
|
224
|
/* if user does not have access to edit an interface skip on to the next record */
|
225
|
if (!have_natpfruleint_access($natent['interface']))
|
226
|
continue;
|
227
|
?>
|
228
|
|
229
|
<tr id="fr<?=$nnats;?>" onClick="fr_toggle(<?=$nnats;?>)" ondblclick="document.location='firewall_nat_edit.php?id=<?=$i;?>';">
|
230
|
<td >
|
231
|
<input type="checkbox" id="frc<?=$nnats;?>" onClick="fr_toggle(<?=$nnats;?>)" name="rule[]" value="<?=$i;?>"/>
|
232
|
</td>
|
233
|
<td>
|
234
|
<?php
|
235
|
if ($natent['associated-rule-id'] == "pass"):
|
236
|
?>
|
237
|
<i class="icon-play" title="<?=gettext("All traffic matching this NAT entry is passed")?>"></i>
|
238
|
<?php
|
239
|
elseif (!empty($natent['associated-rule-id'])):
|
240
|
?>
|
241
|
<i class="icon-random" title="<?=gettext("Firewall rule ID ")?><?=htmlspecialchars($nnatid)?> . <?=gettext('is managed by this rule')?>"></i>
|
242
|
<?php
|
243
|
endif;
|
244
|
?>
|
245
|
</td>
|
246
|
<td>
|
247
|
<?=$textss?>
|
248
|
<?php
|
249
|
if (!$natent['interface'])
|
250
|
echo htmlspecialchars(convert_friendly_interface_to_friendly_descr("wan"));
|
251
|
else
|
252
|
echo htmlspecialchars(convert_friendly_interface_to_friendly_descr($natent['interface']));
|
253
|
?>
|
254
|
<?=$textse?>
|
255
|
</td>
|
256
|
|
257
|
<td>
|
258
|
<?=$textss?><?=strtoupper($natent['protocol'])?><?=$textse?>
|
259
|
</td>
|
260
|
|
261
|
<td>
|
262
|
|
263
|
|
264
|
<?php
|
265
|
if (isset($alias['src'])):
|
266
|
?>
|
267
|
<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">
|
268
|
<?php
|
269
|
endif;
|
270
|
?>
|
271
|
<?=htmlspecialchars(pprint_address($natent['source']))?>
|
272
|
<?php
|
273
|
if (isset($alias['src'])):
|
274
|
?>
|
275
|
<i class='icon icon-pencil'></i></a>
|
276
|
<?php
|
277
|
endif;
|
278
|
?>
|
279
|
</td>
|
280
|
<td>
|
281
|
<?php
|
282
|
if (isset($alias['srcport'])):
|
283
|
?>
|
284
|
<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">
|
285
|
<?php
|
286
|
endif;
|
287
|
?>
|
288
|
<?=htmlspecialchars(pprint_port($natent['source']['port']))?>
|
289
|
<?php
|
290
|
if (isset($alias['srcport'])):
|
291
|
?>
|
292
|
<i class='icon icon-pencil'></i></a>
|
293
|
<?php
|
294
|
endif;
|
295
|
?>
|
296
|
</td>
|
297
|
|
298
|
<td>
|
299
|
<?php
|
300
|
if (isset($alias['dst'])):
|
301
|
?>
|
302
|
<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">
|
303
|
<?php
|
304
|
endif;
|
305
|
?>
|
306
|
<?=htmlspecialchars(pprint_address($natent['destination']))?>
|
307
|
<?php
|
308
|
if (isset($alias['dst'])):
|
309
|
?>
|
310
|
<i class='icon icon-pencil'></i></a>
|
311
|
<?php
|
312
|
endif;
|
313
|
?>
|
314
|
</td>
|
315
|
<td>
|
316
|
<?php
|
317
|
if (isset($alias['dstport'])):
|
318
|
?>
|
319
|
<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">
|
320
|
<?php
|
321
|
endif;
|
322
|
?>
|
323
|
<?=htmlspecialchars(pprint_port($natent['destination']['port']))?>
|
324
|
<?php
|
325
|
if (isset($alias['dstport'])):
|
326
|
?>
|
327
|
<i class='icon icon-pencil'></i></a>
|
328
|
<?php
|
329
|
endif;
|
330
|
?>
|
331
|
</td>
|
332
|
|
333
|
<td >
|
334
|
<?=htmlspecialchars($natent['target'])?>
|
335
|
</td>
|
336
|
<td>
|
337
|
<?php
|
338
|
$localport = $natent['local-port'];
|
339
|
|
340
|
list($dstbeginport, $dstendport) = explode("-", $natent['destination']['port']);
|
341
|
|
342
|
if ($dstendport) {
|
343
|
$localendport = $natent['local-port'] + $dstendport - $dstbeginport;
|
344
|
$localport .= '-' . $localendport;
|
345
|
}
|
346
|
?>
|
347
|
<?=htmlspecialchars(pprint_port($localport))?>
|
348
|
</td>
|
349
|
|
350
|
<td>
|
351
|
<?=htmlspecialchars($natent['descr'])?>
|
352
|
</td>
|
353
|
<td>
|
354
|
<a class="fa fa-pencil" title="<?=gettext("Edit rule"); ?>" href="firewall_nat_edit.php?id=<?=$i?>"></a>
|
355
|
<a class="fa fa-clone" title="<?=gettext("Add a new NAT based on this one")?>" href="firewall_nat_edit.php?dup=<?=$i?>"></a>
|
356
|
<a class="fa fa-trash" title="<?=gettext("Delete rule")?>" href="firewall_nat.php?act=del&id=<?=$i?>" onclick="return confirm('<?=gettext("Are you sure you want to delete this rule?")?>')"></a>
|
357
|
</td>
|
358
|
</tr>
|
359
|
<?php
|
360
|
$i++;
|
361
|
$nnats++;
|
362
|
endforeach;
|
363
|
?>
|
364
|
</tbody>
|
365
|
</table>
|
366
|
</div>
|
367
|
</div>
|
368
|
|
369
|
<nav class="action-buttons">
|
370
|
<a href="firewall_nat_edit.php?after=-1" class="btn btn-sm btn-success" title="<?=gettext('Add new rule')?>">
|
371
|
<i class="fa fa-plus icon-embed-btn"></i>
|
372
|
<?=gettext('Add')?>
|
373
|
</a>
|
374
|
<button name="del_x" type="submit" class="btn btn-danger btn-sm">
|
375
|
<i class="fa fa-trash icon-embed-btn"></i>
|
376
|
<?=gettext("Delete"); ?>
|
377
|
</button>
|
378
|
<button type="submit" id="order-store" name="order-store" class="btn btn-primary btn-sm" disabled="disabled">
|
379
|
<i class="fa fa-save icon-embed-btn"></i>
|
380
|
<?=gettext("Save")?>
|
381
|
</button>
|
382
|
</nav>
|
383
|
</form>
|
384
|
|
385
|
<script>
|
386
|
events.push(function() {
|
387
|
|
388
|
stripe_table();
|
389
|
|
390
|
// Make rules sortable
|
391
|
$('table tbody.user-entries').sortable({
|
392
|
cursor: 'grabbing',
|
393
|
update: function(event, ui) {
|
394
|
$('#order-store').removeAttr('disabled');
|
395
|
stripe_table();
|
396
|
}
|
397
|
});
|
398
|
|
399
|
// Check all of the rule checkboxes so that their values are posted
|
400
|
$('#order-store').click(function () {
|
401
|
$('[id^=frc]').prop('checked', true);
|
402
|
});
|
403
|
});
|
404
|
</script>
|
405
|
<?php
|
406
|
|
407
|
if (count($a_nat) > 0) {
|
408
|
?>
|
409
|
<!-- Legend -->
|
410
|
<div>
|
411
|
<dl class="dl-horizontal responsive">
|
412
|
<dt><?=gettext('Legend')?></dt> <dd></dd>
|
413
|
<dt><i class="icon icon-play"></i></dt> <dd><?=gettext('Pass')?></dd>
|
414
|
<dt><i class="icon icon-random"></i></dt> <dd><?=gettext('Linked rule')?></dd>
|
415
|
</dl>
|
416
|
</div>
|
417
|
|
418
|
<?php
|
419
|
}
|
420
|
|
421
|
include("foot.inc");
|