1
|
#!/usr/local/bin/php
|
2
|
<?php
|
3
|
/* $Id$ */
|
4
|
/*
|
5
|
firewall_nat.php
|
6
|
Copyright (C) 2004 Scott Ullrich
|
7
|
All rights reserved.
|
8
|
|
9
|
originally part of m0n0wall (http://m0n0.ch/wall)
|
10
|
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
11
|
All rights reserved.
|
12
|
|
13
|
Redistribution and use in source and binary forms, with or without
|
14
|
modification, are permitted provided that the following conditions are met:
|
15
|
|
16
|
1. Redistributions of source code must retain the above copyright notice,
|
17
|
this list of conditions and the following disclaimer.
|
18
|
|
19
|
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
|
|
23
|
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
|
if (!is_array($config['nat']['rule']))
|
38
|
$config['nat']['rule'] = array();
|
39
|
|
40
|
$a_nat = &$config['nat']['rule'];
|
41
|
//nat_rules_sort();
|
42
|
|
43
|
if ($_POST) {
|
44
|
|
45
|
$pconfig = $_POST;
|
46
|
|
47
|
if ($_POST['apply']) {
|
48
|
|
49
|
write_config();
|
50
|
|
51
|
$retval = 0;
|
52
|
|
53
|
if (!file_exists($d_sysrebootreqd_path)) {
|
54
|
config_lock();
|
55
|
$retval |= filter_configure();
|
56
|
config_unlock();
|
57
|
}
|
58
|
if(stristr($retval, "error") <> true)
|
59
|
$savemsg = get_std_save_message($retval);
|
60
|
else
|
61
|
$savemsg = $retval;
|
62
|
|
63
|
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
|
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
|
}
|
127
|
|
128
|
?>
|
129
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
130
|
<html>
|
131
|
<head>
|
132
|
<title><?=gentitle("Firewall: NAT: Inbound");?></title>
|
133
|
<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
|
<p class="pgtitle">Firewall: NAT: Inbound</font></p>
|
140
|
<form action="firewall_nat.php" method="post" name="iform">
|
141
|
<script type="text/javascript" language="javascript" src="row_toggle.js">
|
142
|
</script>
|
143
|
<?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
|
<li class="tabact">Inbound</a></li>
|
152
|
<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
|
<li class="tabinact"><a href="firewall_nat_out_load_balancing.php">Outbound Load Balancing</a></li>
|
156
|
</ul>
|
157
|
</td></tr>
|
158
|
<tr>
|
159
|
<td class="tabcont">
|
160
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
161
|
<tr id="frheader">
|
162
|
<td width="3%" class="list"> </td>
|
163
|
<td width="3%" class="list"> </td>
|
164
|
<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
|
</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
|
<td class="listlr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
|
177
|
<?php
|
178
|
if (!$natent['interface'] || ($natent['interface'] == "wan"))
|
179
|
echo "WAN";
|
180
|
else
|
181
|
echo "<font color=\"#FFFFFF\">" . htmlspecialchars($config['interfaces'][$natent['interface']]['descr']);
|
182
|
?>
|
183
|
</td>
|
184
|
<td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
|
185
|
<?=strtoupper($natent['protocol']);?>
|
186
|
</td>
|
187
|
<td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
|
188
|
<?php
|
189
|
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
|
<td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
|
199
|
<?=$natent['target'];?>
|
200
|
<?php if ($natent['external-address'])
|
201
|
echo "<br>(ext.: " . $natent['external-address'] . ")";
|
202
|
?>
|
203
|
</td>
|
204
|
<td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
|
205
|
<?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
|
echo $natent['local-port'] . " - " .
|
211
|
($natent['local-port']+$endport-$beginport);
|
212
|
?>
|
213
|
</td>
|
214
|
<td class="listbg" onClick="fr_toggle(<?=$nnats;?>)" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';"><font color="#FFFFFFF">
|
215
|
<?=htmlspecialchars($natent['descr']);?>
|
216
|
</td>
|
217
|
<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
|
<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
|
</tr>
|
226
|
</table>
|
227
|
</tr>
|
228
|
<?php $i++; $nnats++; endforeach; ?>
|
229
|
<tr>
|
230
|
<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
|
<p><span class="vexpl"><span class="red"><strong>Note:<br>
|
243
|
</strong></span>It is not possible to access NATed services
|
244
|
using the WAN IP address from within the LAN (or an optional
|
245
|
network).</span></p></td>
|
246
|
</tr>
|
247
|
</table>
|
248
|
|
249
|
<?php
|
250
|
if ($pkg['tabs'] <> "") {
|
251
|
echo "</td></tr></table>";
|
252
|
}
|
253
|
?>
|
254
|
|
255
|
</form>
|
256
|
<?php include("fend.inc"); ?>
|
257
|
</body>
|
258
|
</html>
|