Project

General

Profile

Download (11.2 KB) Statistics
| Branch: | Tag: | Revision:
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 183a4aae Bill Marquette
$pgtitle = "Firewall: NAT: Port Forward";
129 6eb17647 Scott Ullrich
include("head.inc");
130
131 24f600b0 Scott Ullrich
?>
132 a8726a3d Scott Ullrich
<body link="#000000" vlink="#000000" alink="#000000">
133 5b237745 Scott Ullrich
<?php include("fbegin.inc"); ?>
134 da7ae7ef Bill Marquette
<p class="pgtitle"><?=$pgtitle?></font></p>
135 00bcbdd0 Bill Marquette
<form action="firewall_nat.php" method="post" name="iform">
136
<script type="text/javascript" language="javascript" src="row_toggle.js">
137
</script>
138 5b237745 Scott Ullrich
<?php if ($savemsg) print_info_box($savemsg); ?>
139
<?php if (file_exists($d_natconfdirty_path)): ?><p>
140 a0509c58 Scott Ullrich
<?php print_info_box_np("The NAT configuration has been changed.<br>You must apply the changes in order for them to take effect.");?>
141 5b237745 Scott Ullrich
<?php endif; ?>
142 a8726a3d Scott Ullrich
<div id="mainarea">
143 5b237745 Scott Ullrich
<table width="100%" border="0" cellpadding="0" cellspacing="0">
144
  <tr><td>
145 a8726a3d Scott Ullrich
<?php
146
	$tab_array = array();
147 183a4aae Bill Marquette
	$tab_array[0] = array("Port Forward", true, "firewall_nat.php");
148
	$tab_array[1] = array("NAT Addresses", false, "firewall_nat_server.php");
149 a8726a3d Scott Ullrich
	$tab_array[2] = array("1:1", false, "firewall_nat_1to1.php");
150
	$tab_array[3] = array("Outbound", false, "firewall_nat_out.php");
151 183a4aae Bill Marquette
	$tab_array[4] = array("Outbound Load Balancing", false, "firewall_nat_out_load_balancing.php");
152 a8726a3d Scott Ullrich
	display_top_tabs($tab_array);
153
?>
154
 </td></tr>
155 340e6dca Scott Ullrich
  <tr>
156 5b237745 Scott Ullrich
    <td class="tabcont">
157
              <table width="100%" border="0" cellpadding="0" cellspacing="0">
158 00bcbdd0 Bill Marquette
                <tr id="frheader">
159
		  <td width="3%" class="list">&nbsp;</td>
160
                  <td width="3%" class="list">&nbsp;</td>
161 5b237745 Scott Ullrich
                  <td width="5%" class="listhdrr">If</td>
162
                  <td width="5%" class="listhdrr">Proto</td>
163
                  <td width="20%" class="listhdrr">Ext. port range</td>
164
                  <td width="20%" class="listhdrr">NAT IP</td>
165
                  <td width="20%" class="listhdrr">Int. port range</td>
166
                  <td width="20%" class="listhdr">Description</td>
167
                  <td width="5%" class="list"></td>
168 00bcbdd0 Bill Marquette
		</tr>
169
	<?php $nnats = $i = 0; foreach ($a_nat as $natent): ?>
170
                <tr valign="top" id="fr<?=$nnats;?>">
171
                  <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>
172
                  <td class="listt" align="center"></td>
173 b8a0de00 Bill Marquette
                  <td class="listlr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
174 00bcbdd0 Bill Marquette
                    <?php
175
			if (!$natent['interface'] || ($natent['interface'] == "wan"))
176
				echo "WAN";
177
			else
178 44e1049c Bill Marquette
				echo htmlspecialchars($config['interfaces'][$natent['interface']]['descr']);
179 00bcbdd0 Bill Marquette
		    ?>
180 5b237745 Scott Ullrich
                  </td>
181 b8a0de00 Bill Marquette
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
182 5b237745 Scott Ullrich
                    <?=strtoupper($natent['protocol']);?>
183
                  </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 340e6dca Scott Ullrich
                    <?php
186 5b237745 Scott Ullrich
						list($beginport, $endport) = split("-", $natent['external-port']);
187
						if ((!$endport) || ($beginport == $endport)) {
188
				  			echo $beginport;
189
							if ($wkports[$beginport])
190
								echo " (" . $wkports[$beginport] . ")";
191
						} else
192
							echo $beginport . " - " . $endport;
193
				  ?>
194
                  </td>
195 b8a0de00 Bill Marquette
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
196 5b237745 Scott Ullrich
                    <?=$natent['target'];?>
197
					<?php if ($natent['external-address'])
198
						echo "<br>(ext.: " . $natent['external-address'] . ")";
199
					?>
200
                  </td>
201 b8a0de00 Bill Marquette
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
202 5b237745 Scott Ullrich
                    <?php if ((!$endport) || ($beginport == $endport)) {
203
				  			echo $natent['local-port'];
204
							if ($wkports[$natent['local-port']])
205
								echo " (" . $wkports[$natent['local-port']] . ")";
206
						} else
207 340e6dca Scott Ullrich
							echo $natent['local-port'] . " - " .
208 5b237745 Scott Ullrich
								($natent['local-port']+$endport-$beginport);
209
				  ?>
210
                  </td>
211 b8a0de00 Bill Marquette
                  <td class="listbg" onClick="fr_toggle(<?=$nnats;?>)" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';"><font color="#FFFFFFF">
212 5b237745 Scott Ullrich
                    <?=htmlspecialchars($natent['descr']);?>&nbsp;
213
                  </td>
214 00bcbdd0 Bill Marquette
                  <td valign="middle" class="list" nowrap>
215
                    <table border="0" cellspacing="0" cellpadding="1">
216
                      <tr>
217
                        <td><a href="firewall_nat_edit.php?id=<?=$i;?>"><img src="e.gif" width="17" height="17" border="0"></a></td>
218
                      </tr>
219
                      <tr>
220
                        <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>
221 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>
222 00bcbdd0 Bill Marquette
                      </tr>
223
                    </table>
224
		</tr>
225
  	     <?php $i++; $nnats++; endforeach; ?>
226 340e6dca Scott Ullrich
                <tr>
227 00bcbdd0 Bill Marquette
                  <td class="list" colspan="8"></td>
228
                  <td class="list" valign="middle" nowrap>
229
                    <table border="0" cellspacing="0" cellpadding="1">
230
                      <tr>
231
                        <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>
232
                        <td><a href="firewall_nat_edit.php"><img src="plus.gif" width="17" height="17" border="0"></a></td>
233
                      </tr>
234
                      <tr>
235
                        <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>
236
                      </tr>
237
                    </table></td>
238
                </tr>              </table>
239 5b237745 Scott Ullrich
                    <p><span class="vexpl"><span class="red"><strong>Note:<br>
240 340e6dca Scott Ullrich
                      </strong></span>It is not possible to access NATed services
241 925b8e0a Bill Marquette
                      using the WAN IP address from within the LAN (or an optional
242 5b237745 Scott Ullrich
                      network).</span></p></td>
243
  </tr>
244
</table>
245 a8726a3d Scott Ullrich
</div>
246 3d335c4d Scott Ullrich
247
<?php
248
if ($pkg['tabs'] <> "") {
249
    echo "</td></tr></table>";
250
}
251
?>
252
253
</form>
254 5b237745 Scott Ullrich
<?php include("fend.inc"); ?>
255 a8726a3d Scott Ullrich
256 af4aa061 Scott Ullrich
<script type="text/javascript">
257
NiftyCheck();
258
Rounded("div#mainarea","bl br","#FFF","#eeeeee","smooth");
259
</script>
260 a8726a3d Scott Ullrich
261 5b237745 Scott Ullrich
</body>
262
</html>