1
|
<?php
|
2
|
/* $Id$ */
|
3
|
/*
|
4
|
firewall_nat_1to1.php
|
5
|
*/
|
6
|
/* ====================================================================
|
7
|
* Copyright (c) 2004-2015 Electric Sheep Fencing, LLC. All rights reserved.
|
8
|
* Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>
|
9
|
* part of m0n0wall (http://m0n0.ch/wall)
|
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-1-1
|
64
|
##|*NAME=Firewall: NAT: 1:1 page
|
65
|
##|*DESCR=Allow access to the 'Firewall: NAT: 1:1' page.
|
66
|
##|*MATCH=firewall_nat_1to1.php*
|
67
|
##|-PRIV
|
68
|
|
69
|
require("guiconfig.inc");
|
70
|
require_once("functions.inc");
|
71
|
require_once("filter.inc");
|
72
|
require_once("shaper.inc");
|
73
|
|
74
|
if (!is_array($config['nat']['onetoone'])) {
|
75
|
$config['nat']['onetoone'] = array();
|
76
|
}
|
77
|
|
78
|
$a_1to1 = &$config['nat']['onetoone'];
|
79
|
|
80
|
/* update rule order, POST[rule] is an array of ordered IDs */
|
81
|
if (is_array($_POST['rule']) && !empty($_POST['rule'])) {
|
82
|
$a_1to1_new = array();
|
83
|
|
84
|
// if a rule is not in POST[rule], it has been deleted by the user
|
85
|
foreach ($_POST['rule'] as $id)
|
86
|
$a_1to1_new[] = $a_1to1[$id];
|
87
|
|
88
|
$a_1to1 = $a_1to1_new;
|
89
|
|
90
|
if (write_config())
|
91
|
mark_subsystem_dirty('filter');
|
92
|
|
93
|
header("Location: firewall_nat_1to1.php");
|
94
|
exit;
|
95
|
}
|
96
|
|
97
|
if ($_POST) {
|
98
|
$pconfig = $_POST;
|
99
|
|
100
|
if ($_POST['apply']) {
|
101
|
$retval = 0;
|
102
|
$retval |= filter_configure();
|
103
|
$savemsg = get_std_save_message($retval);
|
104
|
|
105
|
if ($retval == 0) {
|
106
|
clear_subsystem_dirty('natconf');
|
107
|
clear_subsystem_dirty('filter');
|
108
|
}
|
109
|
}
|
110
|
}
|
111
|
|
112
|
if ($_GET['act'] == "del") {
|
113
|
if ($a_1to1[$_GET['id']]) {
|
114
|
unset($a_1to1[$_GET['id']]);
|
115
|
if (write_config()) {
|
116
|
mark_subsystem_dirty('natconf');
|
117
|
}
|
118
|
header("Location: firewall_nat_1to1.php");
|
119
|
exit;
|
120
|
}
|
121
|
}
|
122
|
|
123
|
if (isset($_POST['del_x'])) {
|
124
|
/* delete selected rules */
|
125
|
if (is_array($_POST['rule']) && count($_POST['rule'])) {
|
126
|
foreach ($_POST['rule'] as $rulei) {
|
127
|
unset($a_1to1[$rulei]);
|
128
|
}
|
129
|
if (write_config()) {
|
130
|
mark_subsystem_dirty('natconf');
|
131
|
}
|
132
|
header("Location: firewall_nat_1to1.php");
|
133
|
exit;
|
134
|
}
|
135
|
|
136
|
} else if ($_GET['act'] == "toggle") {
|
137
|
if ($a_1to1[$_GET['id']]) {
|
138
|
if (isset($a_1to1[$_GET['id']]['disabled'])) {
|
139
|
unset($a_1to1[$_GET['id']]['disabled']);
|
140
|
} else {
|
141
|
$a_1to1[$_GET['id']]['disabled'] = true;
|
142
|
}
|
143
|
if (write_config("Firewall: NAT: Outbound, enable/disable NAT rule")) {
|
144
|
mark_subsystem_dirty('natconf');
|
145
|
}
|
146
|
header("Location: firewall_nat_1to1.php");
|
147
|
exit;
|
148
|
}
|
149
|
} else {
|
150
|
/* yuck - IE won't send value attributes for image buttons, while Mozilla does - so we use .x/.y to find move button clicks instead... */
|
151
|
unset($movebtn);
|
152
|
foreach ($_POST as $pn => $pd) {
|
153
|
if (preg_match("/move_(\d+)_x/", $pn, $matches)) {
|
154
|
$movebtn = $matches[1];
|
155
|
break;
|
156
|
}
|
157
|
}
|
158
|
/* move selected rules before this rule */
|
159
|
if (isset($movebtn) && is_array($_POST['rule']) && count($_POST['rule'])) {
|
160
|
$a_1to1_new = array();
|
161
|
|
162
|
/* copy all rules < $movebtn and not selected */
|
163
|
for ($i = 0; $i < $movebtn; $i++) {
|
164
|
if (!in_array($i, $_POST['rule'])) {
|
165
|
$a_1to1_new[] = $a_1to1[$i];
|
166
|
}
|
167
|
}
|
168
|
|
169
|
/* copy all selected rules */
|
170
|
for ($i = 0; $i < count($a_1to1); $i++) {
|
171
|
if ($i == $movebtn) {
|
172
|
continue;
|
173
|
}
|
174
|
if (in_array($i, $_POST['rule'])) {
|
175
|
$a_1to1_new[] = $a_1to1[$i];
|
176
|
}
|
177
|
}
|
178
|
|
179
|
/* copy $movebtn rule */
|
180
|
if ($movebtn < count($a_1to1)) {
|
181
|
$a_1to1_new[] = $a_1to1[$movebtn];
|
182
|
}
|
183
|
|
184
|
/* copy all rules > $movebtn and not selected */
|
185
|
for ($i = $movebtn+1; $i < count($a_1to1); $i++) {
|
186
|
if (!in_array($i, $_POST['rule'])) {
|
187
|
$a_1to1_new[] = $a_1to1[$i];
|
188
|
}
|
189
|
}
|
190
|
if (count($a_1to1_new) > 0) {
|
191
|
$a_1to1 = $a_1to1_new;
|
192
|
}
|
193
|
|
194
|
if (write_config()) {
|
195
|
mark_subsystem_dirty('natconf');
|
196
|
}
|
197
|
header("Location: firewall_nat_1to1.php");
|
198
|
exit;
|
199
|
}
|
200
|
}
|
201
|
|
202
|
$pgtitle = array(gettext("Firewall"), gettext("NAT"), gettext("1:1"));
|
203
|
include("head.inc");
|
204
|
|
205
|
if ($savemsg)
|
206
|
print_info_box($savemsg, 'success');
|
207
|
|
208
|
if (is_subsystem_dirty('natconf'))
|
209
|
print_info_box_np(gettext('The NAT configuration has been changed.') . '<br />' .
|
210
|
gettext('You must apply the changes in order for them to take effect.') . '<br />');
|
211
|
|
212
|
$tab_array = array();
|
213
|
$tab_array[] = array(gettext("Port Forward"), false, "firewall_nat.php");
|
214
|
$tab_array[] = array(gettext("1:1"), true, "firewall_nat_1to1.php");
|
215
|
$tab_array[] = array(gettext("Outbound"), false, "firewall_nat_out.php");
|
216
|
$tab_array[] = array(gettext("NPt"), false, "firewall_nat_npt.php");
|
217
|
display_top_tabs($tab_array);
|
218
|
?>
|
219
|
<form action="firewall_nat_1to1.php" method="post">
|
220
|
<div class="panel panel-default">
|
221
|
<div class="panel-heading"><?=gettext("NAT 1 to 1 mappings")?></div>
|
222
|
<div id="mainarea" class="table-responsive panel-body">
|
223
|
<table class="table table-striped table-hover table-condensed">
|
224
|
<thead>
|
225
|
<tr>
|
226
|
<th><!-- icon --></th>
|
227
|
<th><?=gettext("Interface"); ?></th>
|
228
|
<th><?=gettext("External IP"); ?></th>
|
229
|
<th><?=gettext("Internal IP"); ?></th>
|
230
|
<th><?=gettext("Destination IP"); ?></th>
|
231
|
<th><?=gettext("Description"); ?></th>
|
232
|
<th><?=gettext('Actions')?></th>
|
233
|
</tr>
|
234
|
</thead>
|
235
|
<tbody class="user-entries">
|
236
|
<?php
|
237
|
$textse = "</span>";
|
238
|
$i = 0;
|
239
|
foreach ($a_1to1 as $natent):
|
240
|
if (isset($natent['disabled'])) {
|
241
|
$textss = "<span class=\"gray\">";
|
242
|
$iconfn = "pass_d";
|
243
|
} else {
|
244
|
$textss = "<span>";
|
245
|
$iconfn = "pass";
|
246
|
}
|
247
|
?>
|
248
|
<tr id="fr<?=$i?>">
|
249
|
<td>
|
250
|
<a href="?act=toggle&id=<?=$i?>">
|
251
|
<i class="<?= ($iconfn == "pass") ? "icon-ok":"icon-remove"?>" title="<?=gettext("click to toggle enabled/disabled status")?>"></i>
|
252
|
</a>
|
253
|
</td>
|
254
|
<td>
|
255
|
<?php
|
256
|
echo $textss;
|
257
|
if (!$natent['interface']) {
|
258
|
echo htmlspecialchars(convert_friendly_interface_to_friendly_descr("wan"));
|
259
|
} else {
|
260
|
echo htmlspecialchars(convert_friendly_interface_to_friendly_descr($natent['interface']));
|
261
|
}
|
262
|
echo $textse;
|
263
|
?>
|
264
|
</td>
|
265
|
<td>
|
266
|
<input type="hidden" name="rule[]" value="<?=$i?>" />
|
267
|
<?php
|
268
|
$source_net = pprint_address($natent['source']);
|
269
|
$source_cidr = strstr($source_net, '/');
|
270
|
echo $textss . $natent['external'] . $source_cidr . $textse;
|
271
|
?>
|
272
|
</td>
|
273
|
<td>
|
274
|
<?php
|
275
|
echo $textss . $source_net . $textse;
|
276
|
?>
|
277
|
</td>
|
278
|
<td>
|
279
|
<?php
|
280
|
echo $textss . pprint_address($natent['destination']) . $textse;
|
281
|
?>
|
282
|
</td>
|
283
|
<td>
|
284
|
<?php
|
285
|
echo $textss . htmlspecialchars($natent['descr']) . ' ' . $textse;
|
286
|
?>
|
287
|
</td>
|
288
|
|
289
|
<td>
|
290
|
<a class="btn btn-xs btn-info" title="<?=gettext("Edit rule")?>" href="firewall_nat_1to1.php?id=<?=$i?>"><?=gettext("Edit")?></a>
|
291
|
<a class="btn btn-xs btn-danger" title="<?=gettext("Delete rule")?>" href="firewall_nat_1to1.php?act=del&id=<?=$i?>"><?=gettext("Del")?></a>
|
292
|
<a class="btn btn-xs btn-success" title="<?=gettext("Add a new rule based on this one")?>" href="firewall_nat_1to1_edit.php?dup=<?=$i?>"><?=gettext("Clone")?></a>
|
293
|
</td>
|
294
|
|
295
|
</tr>
|
296
|
<?php
|
297
|
$i++;
|
298
|
endforeach;
|
299
|
?>
|
300
|
</tbody>
|
301
|
</table>
|
302
|
</div>
|
303
|
</div>
|
304
|
|
305
|
<nav class="action-buttons">
|
306
|
<a href="firewall_nat_1to1_edit.php?after=-1" class="btn btn-sm btn-success" title="<?=gettext('Add new mapping')?>"><?=gettext('Add new mapping')?></a>
|
307
|
<input type="submit" id="order-store" class="btn btn-primary btn-sm" value="store changes" disabled="disabled" />
|
308
|
</nav>
|
309
|
</form>
|
310
|
|
311
|
<div>
|
312
|
<?php
|
313
|
|
314
|
print_info_box(gettext('Depending on the way your WAN connection is setup, you may also need a ') . '<a href="firewall_virtual_ip.php">' .
|
315
|
gettext("Virtual IP.") . '</a>' . '<br />' .
|
316
|
gettext('If you add a 1:1 NAT entry for any of the interface IPs on this system, ' .
|
317
|
'it will make this system inaccessible on that IP address. i.e. if ' .
|
318
|
'you use your WAN IP address, any services on this system (IPsec, OpenVPN server, etc.) ' .
|
319
|
'using the WAN IP address will no longer function.'));
|
320
|
?>
|
321
|
</div>
|
322
|
|
323
|
<script>
|
324
|
events.push(function() {
|
325
|
// Make rules draggable/sortable
|
326
|
$('table tbody.user-entries').sortable({
|
327
|
cursor: 'grabbing',
|
328
|
update: function(event, ui) {
|
329
|
$('#order-store').removeAttr('disabled');
|
330
|
}
|
331
|
});
|
332
|
});
|
333
|
</script>
|
334
|
<?php include("foot.inc"); ?>
|