1 |
5b237745
|
Scott Ullrich
|
#!/usr/local/bin/php
|
2 |
340e6dca
|
Scott Ullrich
|
<?php
|
3 |
b46bfcf5
|
Bill Marquette
|
/* $Id$ */
|
4 |
5b237745
|
Scott Ullrich
|
/*
|
5 |
|
|
firewall_nat.php
|
6 |
c55b323d
|
Scott Ullrich
|
Copyright (C) 2004 Scott Ullrich
|
7 |
|
|
All rights reserved.
|
8 |
340e6dca
|
Scott Ullrich
|
|
9 |
c55b323d
|
Scott Ullrich
|
originally part of m0n0wall (http://m0n0.ch/wall)
|
10 |
5b237745
|
Scott Ullrich
|
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
11 |
|
|
All rights reserved.
|
12 |
340e6dca
|
Scott Ullrich
|
|
13 |
5b237745
|
Scott Ullrich
|
Redistribution and use in source and binary forms, with or without
|
14 |
|
|
modification, are permitted provided that the following conditions are met:
|
15 |
340e6dca
|
Scott Ullrich
|
|
16 |
5b237745
|
Scott Ullrich
|
1. Redistributions of source code must retain the above copyright notice,
|
17 |
|
|
this list of conditions and the following disclaimer.
|
18 |
340e6dca
|
Scott Ullrich
|
|
19 |
5b237745
|
Scott Ullrich
|
2. Redistributions in binary form must reproduce the above copyright
|
20 |
|
|
notice, this list of conditions and the following disclaimer in the
|
21 |
|
|
documentation and/or other materials provided with the distribution.
|
22 |
340e6dca
|
Scott Ullrich
|
|
23 |
5b237745
|
Scott Ullrich
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
24 |
|
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
25 |
|
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
26 |
|
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
27 |
|
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
28 |
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
29 |
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
30 |
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
31 |
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
32 |
|
|
POSSIBILITY OF SUCH DAMAGE.
|
33 |
|
|
*/
|
34 |
|
|
|
35 |
|
|
require("guiconfig.inc");
|
36 |
|
|
|
37 |
e8c2c890
|
Bill Marquette
|
if (!is_array($config['nat']['rule']))
|
38 |
5b237745
|
Scott Ullrich
|
$config['nat']['rule'] = array();
|
39 |
fbe94068
|
Scott Ullrich
|
|
40 |
5b237745
|
Scott Ullrich
|
$a_nat = &$config['nat']['rule'];
|
41 |
00bcbdd0
|
Bill Marquette
|
//nat_rules_sort();
|
42 |
5b237745
|
Scott Ullrich
|
|
43 |
|
|
if ($_POST) {
|
44 |
|
|
|
45 |
|
|
$pconfig = $_POST;
|
46 |
|
|
|
47 |
|
|
if ($_POST['apply']) {
|
48 |
e8c2c890
|
Bill Marquette
|
|
49 |
|
|
write_config();
|
50 |
|
|
|
51 |
5b237745
|
Scott Ullrich
|
$retval = 0;
|
52 |
e8c2c890
|
Bill Marquette
|
|
53 |
5b237745
|
Scott Ullrich
|
if (!file_exists($d_sysrebootreqd_path)) {
|
54 |
|
|
config_lock();
|
55 |
|
|
$retval |= filter_configure();
|
56 |
|
|
config_unlock();
|
57 |
|
|
}
|
58 |
b2774343
|
Scott Ullrich
|
if(stristr($retval, "error") <> true)
|
59 |
2a71debf
|
Scott Ullrich
|
$savemsg = get_std_save_message($retval);
|
60 |
|
|
else
|
61 |
|
|
$savemsg = $retval;
|
62 |
340e6dca
|
Scott Ullrich
|
|
63 |
5b237745
|
Scott Ullrich
|
if ($retval == 0) {
|
64 |
|
|
if (file_exists($d_natconfdirty_path))
|
65 |
|
|
unlink($d_natconfdirty_path);
|
66 |
|
|
if (file_exists($d_filterconfdirty_path))
|
67 |
|
|
unlink($d_filterconfdirty_path);
|
68 |
|
|
}
|
69 |
|
|
}
|
70 |
|
|
}
|
71 |
|
|
|
72 |
00bcbdd0
|
Bill Marquette
|
if (isset($_POST['del_x'])) {
|
73 |
|
|
/* delete selected rules */
|
74 |
|
|
if (is_array($_POST['rule']) && count($_POST['rule'])) {
|
75 |
|
|
foreach ($_POST['rule'] as $rulei) {
|
76 |
|
|
unset($a_nat[$rulei]);
|
77 |
|
|
}
|
78 |
|
|
write_config();
|
79 |
|
|
touch($d_natconfdirty_path);
|
80 |
|
|
header("Location: firewall_nat.php");
|
81 |
|
|
exit;
|
82 |
|
|
}
|
83 |
|
|
|
84 |
|
|
} else {
|
85 |
|
|
/* yuck - IE won't send value attributes for image buttons, while Mozilla does - so we use .x/.y to find move button clicks instead... */
|
86 |
|
|
unset($movebtn);
|
87 |
|
|
foreach ($_POST as $pn => $pd) {
|
88 |
|
|
if (preg_match("/move_(\d+)_x/", $pn, $matches)) {
|
89 |
|
|
$movebtn = $matches[1];
|
90 |
|
|
break;
|
91 |
|
|
}
|
92 |
|
|
}
|
93 |
|
|
/* move selected rules before this rule */
|
94 |
|
|
if (isset($movebtn) && is_array($_POST['rule']) && count($_POST['rule'])) {
|
95 |
|
|
$a_nat_new = array();
|
96 |
|
|
|
97 |
|
|
/* copy all rules < $movebtn and not selected */
|
98 |
|
|
for ($i = 0; $i < $movebtn; $i++) {
|
99 |
|
|
if (!in_array($i, $_POST['rule']))
|
100 |
|
|
$a_nat_new[] = $a_nat[$i];
|
101 |
|
|
}
|
102 |
|
|
|
103 |
|
|
/* copy all selected rules */
|
104 |
|
|
for ($i = 0; $i < count($a_nat); $i++) {
|
105 |
|
|
if ($i == $movebtn)
|
106 |
|
|
continue;
|
107 |
|
|
if (in_array($i, $_POST['rule']))
|
108 |
|
|
$a_nat_new[] = $a_nat[$i];
|
109 |
|
|
}
|
110 |
|
|
|
111 |
|
|
/* copy $movebtn rule */
|
112 |
|
|
if ($movebtn < count($a_nat))
|
113 |
|
|
$a_nat_new[] = $a_nat[$movebtn];
|
114 |
|
|
|
115 |
|
|
/* copy all rules > $movebtn and not selected */
|
116 |
|
|
for ($i = $movebtn+1; $i < count($a_nat); $i++) {
|
117 |
|
|
if (!in_array($i, $_POST['rule']))
|
118 |
|
|
$a_nat_new[] = $a_nat[$i];
|
119 |
|
|
}
|
120 |
|
|
$a_nat = $a_nat_new;
|
121 |
|
|
write_config();
|
122 |
|
|
touch($d_natconfdirty_path);
|
123 |
|
|
header("Location: firewall_nat.php");
|
124 |
|
|
exit;
|
125 |
|
|
}
|
126 |
5b237745
|
Scott Ullrich
|
}
|
127 |
00bcbdd0
|
Bill Marquette
|
|
128 |
5b237745
|
Scott Ullrich
|
?>
|
129 |
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
130 |
|
|
<html>
|
131 |
|
|
<head>
|
132 |
e8074dcd
|
Bill Marquette
|
<title><?=gentitle("Firewall: NAT: Inbound");?></title>
|
133 |
5b237745
|
Scott Ullrich
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
134 |
|
|
<link href="gui.css" rel="stylesheet" type="text/css">
|
135 |
|
|
</head>
|
136 |
|
|
|
137 |
|
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
138 |
|
|
<?php include("fbegin.inc"); ?>
|
139 |
e8074dcd
|
Bill Marquette
|
<p class="pgtitle">Firewall: NAT: Inbound</font></p>
|
140 |
00bcbdd0
|
Bill Marquette
|
<form action="firewall_nat.php" method="post" name="iform">
|
141 |
|
|
<script type="text/javascript" language="javascript" src="row_toggle.js">
|
142 |
|
|
</script>
|
143 |
5b237745
|
Scott Ullrich
|
<?php if ($savemsg) print_info_box($savemsg); ?>
|
144 |
|
|
<?php if (file_exists($d_natconfdirty_path)): ?><p>
|
145 |
|
|
<?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>
|
146 |
|
|
<input name="apply" type="submit" class="formbtn" id="apply" value="Apply changes"></p>
|
147 |
|
|
<?php endif; ?>
|
148 |
|
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
149 |
|
|
<tr><td>
|
150 |
|
|
<ul id="tabnav">
|
151 |
fbe94068
|
Scott Ullrich
|
<li class="tabact">Inbound</a></li>
|
152 |
5b237745
|
Scott Ullrich
|
<li class="tabinact"><a href="firewall_nat_server.php">Server NAT</a></li>
|
153 |
|
|
<li class="tabinact"><a href="firewall_nat_1to1.php">1:1</a></li>
|
154 |
|
|
<li class="tabinact"><a href="firewall_nat_out.php">Outbound</a></li>
|
155 |
c55b323d
|
Scott Ullrich
|
<li class="tabinact"><a href="firewall_nat_out_load_balancing.php">Outbound Load Balancing</a></li>
|
156 |
5b237745
|
Scott Ullrich
|
</ul>
|
157 |
|
|
</td></tr>
|
158 |
340e6dca
|
Scott Ullrich
|
<tr>
|
159 |
5b237745
|
Scott Ullrich
|
<td class="tabcont">
|
160 |
|
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
161 |
00bcbdd0
|
Bill Marquette
|
<tr id="frheader">
|
162 |
|
|
<td width="3%" class="list"> </td>
|
163 |
|
|
<td width="3%" class="list"> </td>
|
164 |
5b237745
|
Scott Ullrich
|
<td width="5%" class="listhdrr">If</td>
|
165 |
|
|
<td width="5%" class="listhdrr">Proto</td>
|
166 |
|
|
<td width="20%" class="listhdrr">Ext. port range</td>
|
167 |
|
|
<td width="20%" class="listhdrr">NAT IP</td>
|
168 |
|
|
<td width="20%" class="listhdrr">Int. port range</td>
|
169 |
|
|
<td width="20%" class="listhdr">Description</td>
|
170 |
|
|
<td width="5%" class="list"></td>
|
171 |
00bcbdd0
|
Bill Marquette
|
</tr>
|
172 |
|
|
<?php $nnats = $i = 0; foreach ($a_nat as $natent): ?>
|
173 |
|
|
<tr valign="top" id="fr<?=$nnats;?>">
|
174 |
|
|
<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>
|
175 |
|
|
<td class="listt" align="center"></td>
|
176 |
b8a0de00
|
Bill Marquette
|
<td class="listlr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
|
177 |
00bcbdd0
|
Bill Marquette
|
<?php
|
178 |
|
|
if (!$natent['interface'] || ($natent['interface'] == "wan"))
|
179 |
|
|
echo "WAN";
|
180 |
|
|
else
|
181 |
44e1049c
|
Bill Marquette
|
echo htmlspecialchars($config['interfaces'][$natent['interface']]['descr']);
|
182 |
00bcbdd0
|
Bill Marquette
|
?>
|
183 |
5b237745
|
Scott Ullrich
|
</td>
|
184 |
b8a0de00
|
Bill Marquette
|
<td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
|
185 |
5b237745
|
Scott Ullrich
|
<?=strtoupper($natent['protocol']);?>
|
186 |
|
|
</td>
|
187 |
b8a0de00
|
Bill Marquette
|
<td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
|
188 |
340e6dca
|
Scott Ullrich
|
<?php
|
189 |
5b237745
|
Scott Ullrich
|
list($beginport, $endport) = split("-", $natent['external-port']);
|
190 |
|
|
if ((!$endport) || ($beginport == $endport)) {
|
191 |
|
|
echo $beginport;
|
192 |
|
|
if ($wkports[$beginport])
|
193 |
|
|
echo " (" . $wkports[$beginport] . ")";
|
194 |
|
|
} else
|
195 |
|
|
echo $beginport . " - " . $endport;
|
196 |
|
|
?>
|
197 |
|
|
</td>
|
198 |
b8a0de00
|
Bill Marquette
|
<td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
|
199 |
5b237745
|
Scott Ullrich
|
<?=$natent['target'];?>
|
200 |
|
|
<?php if ($natent['external-address'])
|
201 |
|
|
echo "<br>(ext.: " . $natent['external-address'] . ")";
|
202 |
|
|
?>
|
203 |
|
|
</td>
|
204 |
b8a0de00
|
Bill Marquette
|
<td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
|
205 |
5b237745
|
Scott Ullrich
|
<?php if ((!$endport) || ($beginport == $endport)) {
|
206 |
|
|
echo $natent['local-port'];
|
207 |
|
|
if ($wkports[$natent['local-port']])
|
208 |
|
|
echo " (" . $wkports[$natent['local-port']] . ")";
|
209 |
|
|
} else
|
210 |
340e6dca
|
Scott Ullrich
|
echo $natent['local-port'] . " - " .
|
211 |
5b237745
|
Scott Ullrich
|
($natent['local-port']+$endport-$beginport);
|
212 |
|
|
?>
|
213 |
|
|
</td>
|
214 |
b8a0de00
|
Bill Marquette
|
<td class="listbg" onClick="fr_toggle(<?=$nnats;?>)" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';"><font color="#FFFFFFF">
|
215 |
5b237745
|
Scott Ullrich
|
<?=htmlspecialchars($natent['descr']);?>
|
216 |
|
|
</td>
|
217 |
00bcbdd0
|
Bill Marquette
|
<td valign="middle" class="list" nowrap>
|
218 |
|
|
<table border="0" cellspacing="0" cellpadding="1">
|
219 |
|
|
<tr>
|
220 |
|
|
<td><a href="firewall_nat_edit.php?id=<?=$i;?>"><img src="e.gif" width="17" height="17" border="0"></a></td>
|
221 |
|
|
</tr>
|
222 |
|
|
<tr>
|
223 |
|
|
<td><input onmouseover="fr_insline(<?=$nnats;?>, true)" onmouseout="fr_insline(<?=$nnats;?>, false)" name="move_<?=$i;?>" src="left.gif" title="move selected rules before this rule" height="17" type="image" width="17" border="0"></td>
|
224 |
4a991889
|
Bill Marquette
|
<td><a href="firewall_nat_edit.php?dup=<?=$i;?>"><img src="plus.gif" title="add a new nat based on this one" width="17" height="17" border="0"></a></td>
|
225 |
00bcbdd0
|
Bill Marquette
|
</tr>
|
226 |
|
|
</table>
|
227 |
|
|
</tr>
|
228 |
|
|
<?php $i++; $nnats++; endforeach; ?>
|
229 |
340e6dca
|
Scott Ullrich
|
<tr>
|
230 |
00bcbdd0
|
Bill Marquette
|
<td class="list" colspan="8"></td>
|
231 |
|
|
<td class="list" valign="middle" nowrap>
|
232 |
|
|
<table border="0" cellspacing="0" cellpadding="1">
|
233 |
|
|
<tr>
|
234 |
|
|
<td><?php if ($nnats == 0): ?><img src="left_d.gif" width="17" height="17" title="move selected mappings to end" border="0"><?php else: ?><input name="move_<?=$i;?>" type="image" src="left.gif" width="17" height="17" title="move selected mappings to end" border="0"><?php endif; ?></td>
|
235 |
|
|
<td><a href="firewall_nat_edit.php"><img src="plus.gif" width="17" height="17" border="0"></a></td>
|
236 |
|
|
</tr>
|
237 |
|
|
<tr>
|
238 |
|
|
<td><?php if ($nnats == 0): ?><img src="x_d.gif" width="17" height="17" title="delete selected rules" border="0"><?php else: ?><input name="del" type="image" src="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>
|
239 |
|
|
</tr>
|
240 |
|
|
</table></td>
|
241 |
|
|
</tr> </table>
|
242 |
5b237745
|
Scott Ullrich
|
<p><span class="vexpl"><span class="red"><strong>Note:<br>
|
243 |
340e6dca
|
Scott Ullrich
|
</strong></span>It is not possible to access NATed services
|
244 |
925b8e0a
|
Bill Marquette
|
using the WAN IP address from within the LAN (or an optional
|
245 |
5b237745
|
Scott Ullrich
|
network).</span></p></td>
|
246 |
|
|
</tr>
|
247 |
|
|
</table>
|
248 |
3d335c4d
|
Scott Ullrich
|
|
249 |
|
|
<?php
|
250 |
|
|
if ($pkg['tabs'] <> "") {
|
251 |
|
|
echo "</td></tr></table>";
|
252 |
|
|
}
|
253 |
|
|
?>
|
254 |
|
|
|
255 |
|
|
</form>
|
256 |
5b237745
|
Scott Ullrich
|
<?php include("fend.inc"); ?>
|
257 |
|
|
</body>
|
258 |
|
|
</html>
|