1
|
<?php
|
2
|
/* $Id$ */
|
3
|
/*
|
4
|
firewall_nat_out.php
|
5
|
Copyright (C) 2004 Scott Ullrich
|
6
|
All rights reserved.
|
7
|
|
8
|
originally part of m0n0wall (http://m0n0.ch/wall)
|
9
|
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
10
|
All rights reserved.
|
11
|
|
12
|
Redistribution and use in source and binary forms, with or without
|
13
|
modification, 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 the
|
20
|
documentation and/or other materials provided with the distribution.
|
21
|
|
22
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
23
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
24
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
25
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
26
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
27
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
28
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
29
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
30
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
31
|
POSSIBILITY OF SUCH DAMAGE.
|
32
|
*/
|
33
|
/*
|
34
|
pfSense_MODULE: nat
|
35
|
*/
|
36
|
|
37
|
##|+PRIV
|
38
|
##|*IDENT=page-firewall-nat-outbound
|
39
|
##|*NAME=Firewall: NAT: Outbound page
|
40
|
##|*DESCR=Allow access to the 'Firewall: NAT: Outbound' page.
|
41
|
##|*MATCH=firewall_nat_out.php*
|
42
|
##|-PRIV
|
43
|
|
44
|
require("guiconfig.inc");
|
45
|
require_once("functions.inc");
|
46
|
require_once("filter.inc");
|
47
|
require_once("shaper.inc");
|
48
|
|
49
|
if (!is_array($config['nat']['advancedoutbound']))
|
50
|
$config['nat']['advancedoutbound'] = array();
|
51
|
|
52
|
if (!is_array($config['nat']['advancedoutbound']['rule']))
|
53
|
$config['nat']['advancedoutbound']['rule'] = array();
|
54
|
|
55
|
$a_out = &$config['nat']['advancedoutbound']['rule'];
|
56
|
|
57
|
if ($_POST['apply']) {
|
58
|
write_config();
|
59
|
|
60
|
$retval = 0;
|
61
|
$retval |= filter_configure();
|
62
|
|
63
|
if(stristr($retval, "error") <> true)
|
64
|
$savemsg = get_std_save_message($retval);
|
65
|
else
|
66
|
$savemsg = $retval;
|
67
|
|
68
|
if ($retval == 0) {
|
69
|
clear_subsystem_dirty('natconf');
|
70
|
clear_subsystem_dirty('filter');
|
71
|
}
|
72
|
}
|
73
|
|
74
|
|
75
|
|
76
|
if (isset($_POST['save']) && $_POST['save'] == "Save") {
|
77
|
/* mutually exclusive settings - if user wants advanced NAT, we don't generate automatic rules */
|
78
|
switch ($_POST['advancedoripsec']) {
|
79
|
case "ipsecpassthru":
|
80
|
$config['nat']['ipsecpassthru']['enable'] = true;
|
81
|
unset($config['nat']['advancedoutbound']['enable']);
|
82
|
if(count($config['nat']['advancedoutbound']['rule']) == 0)
|
83
|
unset($config['nat']['advancedoutbound']['rule']);
|
84
|
break;
|
85
|
case "advancedoutboundnat":
|
86
|
$was_enabled = isset($config['nat']['advancedoutbound']['enable']);
|
87
|
$config['nat']['advancedoutbound']['enable'] = true;
|
88
|
if (isset($config['nat']['ipsecpassthru']['enable']))
|
89
|
unset($config['nat']['ipsecpassthru']['enable']);
|
90
|
if($was_enabled == false) {
|
91
|
/*
|
92
|
* user has enabled advanced outbound nat -- lets automatically create entries
|
93
|
* for all of the interfaces to make life easier on the pip-o-chap
|
94
|
*/
|
95
|
$ifdescrs = get_configured_interface_with_descr();
|
96
|
|
97
|
foreach($ifdescrs as $if => $ifdesc) {
|
98
|
if (interface_has_gateway($if))
|
99
|
continue;
|
100
|
if($ifdesc == "wan")
|
101
|
continue;
|
102
|
$natent = array();
|
103
|
$osipaddr = get_interface_ip($if);
|
104
|
$ossubnet = get_interface_subnet($if);
|
105
|
if (!is_ipaddr($osipaddr) || empty($ossubnet))
|
106
|
continue;
|
107
|
$osn = gen_subnet($osipaddr, $ossubnet);
|
108
|
$natent['source']['network'] = "{$osn}/{$ossubnet}";
|
109
|
$natent['sourceport'] = "";
|
110
|
$natent['descr'] = "Auto created rule for {$ifdesc}";
|
111
|
$natent['target'] = "";
|
112
|
$natent['interface'] = "wan";
|
113
|
$natent['destination']['any'] = true;
|
114
|
$natent['natport'] = "";
|
115
|
$a_out[] = $natent;
|
116
|
}
|
117
|
$savemsg = "Default rules for each interface have been created.";
|
118
|
}
|
119
|
break;
|
120
|
}
|
121
|
write_config();
|
122
|
mark_subsystem_dirty('natconf');
|
123
|
header("Location: firewall_nat_out.php");
|
124
|
exit;
|
125
|
}
|
126
|
|
127
|
if (isset($_POST['del_x'])) {
|
128
|
/* delete selected rules */
|
129
|
if (is_array($_POST['rule']) && count($_POST['rule'])) {
|
130
|
foreach ($_POST['rule'] as $rulei) {
|
131
|
unset($a_out[$rulei]);
|
132
|
}
|
133
|
write_config();
|
134
|
mark_subsystem_dirty('natconf');
|
135
|
header("Location: firewall_nat_out.php");
|
136
|
exit;
|
137
|
}
|
138
|
|
139
|
} else {
|
140
|
/* yuck - IE won't send value attributes for image buttons, while Mozilla does - so we use .x/.y to find move button clicks instead... */
|
141
|
unset($movebtn);
|
142
|
foreach ($_POST as $pn => $pd) {
|
143
|
if (preg_match("/move_(\d+)_x/", $pn, $matches)) {
|
144
|
$movebtn = $matches[1];
|
145
|
break;
|
146
|
}
|
147
|
}
|
148
|
/* move selected rules before this rule */
|
149
|
if (isset($movebtn) && is_array($_POST['rule']) && count($_POST['rule'])) {
|
150
|
$a_out_new = array();
|
151
|
|
152
|
/* copy all rules < $movebtn and not selected */
|
153
|
for ($i = 0; $i < $movebtn; $i++) {
|
154
|
if (!in_array($i, $_POST['rule']))
|
155
|
$a_out_new[] = $a_out[$i];
|
156
|
}
|
157
|
|
158
|
/* copy all selected rules */
|
159
|
for ($i = 0; $i < count($a_out); $i++) {
|
160
|
if ($i == $movebtn)
|
161
|
continue;
|
162
|
if (in_array($i, $_POST['rule']))
|
163
|
$a_out_new[] = $a_out[$i];
|
164
|
}
|
165
|
|
166
|
/* copy $movebtn rule */
|
167
|
if ($movebtn < count($a_out))
|
168
|
$a_out_new[] = $a_out[$movebtn];
|
169
|
|
170
|
/* copy all rules > $movebtn and not selected */
|
171
|
for ($i = $movebtn+1; $i < count($a_out); $i++) {
|
172
|
if (!in_array($i, $_POST['rule']))
|
173
|
$a_out_new[] = $a_out[$i];
|
174
|
}
|
175
|
if (count($a_out_new) > 0)
|
176
|
$a_out = $a_out_new;
|
177
|
else
|
178
|
unset($config['nat']['advancedoutbound']);
|
179
|
|
180
|
write_config();
|
181
|
mark_subsystem_dirty('natconf');
|
182
|
header("Location: firewall_nat_out.php");
|
183
|
exit;
|
184
|
}
|
185
|
}
|
186
|
|
187
|
|
188
|
$pgtitle = array("Firewall","NAT","Outbound");
|
189
|
include("head.inc");
|
190
|
|
191
|
?>
|
192
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
193
|
<?php include("fbegin.inc"); ?>
|
194
|
<form action="firewall_nat_out.php" method="post" name="iform">
|
195
|
<script type="text/javascript" language="javascript" src="/javascript/row_toggle.js">
|
196
|
</script>
|
197
|
<?php if ($savemsg) print_info_box($savemsg); ?>
|
198
|
<?php if (is_subsystem_dirty('natconf')): ?><p>
|
199
|
<?php print_info_box_np("The NAT configuration has been changed.<br>You must apply the changes in order for them to take effect.");?><br>
|
200
|
<?php endif; ?>
|
201
|
<table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr><td>
|
202
|
<?php
|
203
|
$tab_array = array();
|
204
|
$tab_array[] = array("Port Forward", false, "firewall_nat.php");
|
205
|
$tab_array[] = array("1:1", false, "firewall_nat_1to1.php");
|
206
|
$tab_array[] = array("Outbound", true, "firewall_nat_out.php");
|
207
|
display_top_tabs($tab_array);
|
208
|
?>
|
209
|
</td></tr>
|
210
|
<tr>
|
211
|
<td>
|
212
|
<div id="mainarea">
|
213
|
<table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
|
214
|
<tr>
|
215
|
<td class="vtable"><p>
|
216
|
<input name="advancedoripsec" type="radio" id="ipsecpassthru" value="ipsecpassthru" <?php if (isset($config['nat']['ipsecpassthru']['enable'])) echo "checked";?>>
|
217
|
<strong><?=gettext("Automatic outbound NAT rule generation (IPsec passthrough)");?></strong></p>
|
218
|
</td>
|
219
|
</tr>
|
220
|
<tr>
|
221
|
<td class="vtable"><p>
|
222
|
<input name="advancedoripsec" type="radio" id="advancedoutbound" value="advancedoutboundnat" <?php if (isset($config['nat']['advancedoutbound']['enable'])) echo "checked";?>>
|
223
|
<strong><?=gettext("Manual Outbound NAT rule generation (Advanced Outbound NAT (AON))");?></strong></p></td>
|
224
|
</tr>
|
225
|
<tr>
|
226
|
<td> <input name="save" type="submit" class="formbtn" value="Save">
|
227
|
</td>
|
228
|
</tr>
|
229
|
<tr>
|
230
|
<td colspan="2"><p><span class="vexpl"><span class="red"><strong>Note:<br>
|
231
|
</strong></span>If advanced outbound NAT is enabled, no outbound NAT
|
232
|
rules will be automatically generated any longer. Instead, only the mappings
|
233
|
you specify below will be used. With advanced outbound NAT disabled,
|
234
|
a mapping is automatically created for each interface's subnet
|
235
|
(except WAN). If you use target addresses other than the WAN interface's
|
236
|
IP address, then depending on the way your WAN connection is setup, you
|
237
|
may also need a <a href="firewall_virtual_ip.php">Virtual IP</a>.</span><br>
|
238
|
<br>
|
239
|
You may enter your own mappings below.</p>
|
240
|
</td>
|
241
|
</tr>
|
242
|
</table>
|
243
|
<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
|
244
|
<tr id="frheader">
|
245
|
<td width="3%" class="list"> </td>
|
246
|
<td width="3%" class="list"> </td>
|
247
|
<td width="10%" class="listhdrr">Interface</td>
|
248
|
<td width="15%" class="listhdrr">Source</td>
|
249
|
<td width="10%" class="listhdrr">Source Port</td>
|
250
|
<td width="15%" class="listhdrr">Destination</td>
|
251
|
<td width="10%" class="listhdrr">Destination Port</td>
|
252
|
<td width="15%" class="listhdrr">NAT Address</td>
|
253
|
<td width="10%" class="listhdrr">NAT Port</td>
|
254
|
<td width="10%" class="listhdrr">Static Port</td>
|
255
|
<td width="25%" class="listhdr">Description</td>
|
256
|
<td width="5%" class="list">
|
257
|
<table border="0" cellspacing="0" cellpadding="1">
|
258
|
<tr>
|
259
|
<td width="17"></td>
|
260
|
<td><a href="firewall_nat_out_edit.php"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" title="add new mapping"></a></td>
|
261
|
</tr>
|
262
|
</table>
|
263
|
</td>
|
264
|
</tr>
|
265
|
<?php $nnats = $i = 0; foreach ($a_out as $natent): ?>
|
266
|
<tr valign="top" id="fr<?=$nnats;?>">
|
267
|
<td class="listt"><input type="checkbox" id="frc<?=$nnats;?>" name="rule[]" value="<?=$i;?>" onClick="fr_bgcolor('<?=$nnats;?>')" style="margin: 0; padding: 0; width: 15px; height: 15px;"></td>
|
268
|
<td class="listt" align="center"></td>
|
269
|
<td class="listlr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_out_edit.php?id=<?=$nnats;?>';">
|
270
|
<?php
|
271
|
if (!$natent['interface'] || ($natent['interface'] == "wan"))
|
272
|
echo "WAN";
|
273
|
else if (!$natent['interface'] || ($natent['interface'] == "lan"))
|
274
|
echo "LAN";
|
275
|
else if ($natent['interface'] == "openvpn")
|
276
|
echo "OpenVPN";
|
277
|
else
|
278
|
echo htmlspecialchars($config['interfaces'][$natent['interface']]['descr']);
|
279
|
?>
|
280
|
|
281
|
</td>
|
282
|
<td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_out_edit.php?id=<?=$nnats;?>';">
|
283
|
<?=$natent['source']['network'];?>
|
284
|
</td>
|
285
|
<td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_out_edit.php?id=<?=$nnats;?>';">
|
286
|
<?php
|
287
|
if (!$natent['sourceport'])
|
288
|
echo "*";
|
289
|
else
|
290
|
echo $natent['sourceport'];
|
291
|
?>
|
292
|
</td>
|
293
|
<td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_out_edit.php?id=<?=$nnats;?>';">
|
294
|
<?php
|
295
|
if (isset($natent['destination']['any']))
|
296
|
echo "*";
|
297
|
else {
|
298
|
if (isset($natent['destination']['not']))
|
299
|
echo "! ";
|
300
|
echo $natent['destination']['address'];
|
301
|
}
|
302
|
?>
|
303
|
</td>
|
304
|
<td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_out_edit.php?id=<?=$nnats;?>';">
|
305
|
<?php
|
306
|
if (!$natent['dstport'])
|
307
|
echo "*";
|
308
|
else
|
309
|
echo $natent['dstport'];
|
310
|
?>
|
311
|
</td>
|
312
|
<td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_out_edit.php?id=<?=$nnats;?>';">
|
313
|
<?php
|
314
|
if (!$natent['target'])
|
315
|
echo "*";
|
316
|
else
|
317
|
echo $natent['target'];
|
318
|
?>
|
319
|
</td>
|
320
|
<td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_out_edit.php?id=<?=$nnats;?>';">
|
321
|
<?php
|
322
|
if (!$natent['natport'])
|
323
|
echo "*";
|
324
|
else
|
325
|
echo $natent['natport'];
|
326
|
?>
|
327
|
</td>
|
328
|
<td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_out_edit.php?id=<?=$nnats;?>';">
|
329
|
<?php
|
330
|
if(isset($natent['staticnatport']))
|
331
|
echo "<CENTER>YES</CENTER>";
|
332
|
else
|
333
|
echo "<CENTER>NO</CENTER>";
|
334
|
?>
|
335
|
</td>
|
336
|
<td class="listbg" onClick="fr_toggle(<?=$nnats;?>)" ondblclick="document.location='firewall_nat_out_edit.php?id=<?=$nnats;?>';">
|
337
|
<?=htmlspecialchars($natent['descr']);?>
|
338
|
</td>
|
339
|
<td class="list" valign="middle" nowrap>
|
340
|
<table border="0" cellspacing="0" cellpadding="1">
|
341
|
<tr>
|
342
|
<td><a href="firewall_nat_out_edit.php?id=<?=$i;?>"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0" title="edit mapping"></a></td>
|
343
|
</tr>
|
344
|
<tr>
|
345
|
<td><input onmouseover="fr_insline(<?=$nnats;?>, true)" onmouseout="fr_insline(<?=$nnats;?>, false)" name="move_<?=$i;?>" src="/themes/<?= $g['theme']; ?>/images/icons/icon_left.gif" title="move selected rules before this rule" height="17" type="image" width="17" border="0"></td>
|
346
|
<td><a href="firewall_nat_out_edit.php?dup=<?=$i;?>"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="add a new nat based on this one" width="17" height="17" border="0"></a></td>
|
347
|
</tr>
|
348
|
</table>
|
349
|
<?php $i++; $nnats++; endforeach; ?>
|
350
|
<tr>
|
351
|
<td class="list" colspan="11"></td>
|
352
|
<td class="list" valign="middle" nowrap>
|
353
|
<table border="0" cellspacing="0" cellpadding="1">
|
354
|
<tr>
|
355
|
<td><?php if ($nnats == 0): ?><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_left_d.gif" width="17" height="17" title="move selected mappings to end" border="0"><?php else: ?><input name="move_<?=$i;?>" type="image" src="/themes/<?= $g['theme']; ?>/images/icons/icon_left.gif" width="17" height="17" title="move selected mappings to end" border="0"><?php endif; ?></td>
|
356
|
<td><a href="firewall_nat_out_edit.php"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" title="add new mapping"></a></td>
|
357
|
</tr>
|
358
|
<tr>
|
359
|
<td><?php if ($nnats == 0): ?><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_x_d.gif" width="17" height="17" title="delete selected rules" border="0"><?php else: ?><input name="del" type="image" src="/themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" title="delete selected mappings" onclick="return confirm('Do you really want to delete the selected mappings?')"><?php endif; ?></td>
|
360
|
</tr>
|
361
|
</table></td>
|
362
|
</tr>
|
363
|
</table>
|
364
|
</div>
|
365
|
</td>
|
366
|
</tr>
|
367
|
</table>
|
368
|
</form>
|
369
|
<?php include("fend.inc"); ?>
|
370
|
</body>
|
371
|
</html>
|