Project

General

Profile

Download (11.3 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
<table width="100%" border="0" cellpadding="0" cellspacing="0">
143
  <tr><td>
144 a8726a3d Scott Ullrich
<?php
145
	$tab_array = array();
146 1425e067 Bill Marquette
	$tab_array[] = array("Port Forward", true, "firewall_nat.php");
147
	$tab_array[] = array("1:1", false, "firewall_nat_1to1.php");
148
	$tab_array[] = array("Outbound", false, "firewall_nat_out.php");
149 a8726a3d Scott Ullrich
	display_top_tabs($tab_array);
150
?>
151
 </td></tr>
152 340e6dca Scott Ullrich
  <tr>
153 d732f186 Bill Marquette
    <td>
154
	<div id="mainarea">
155
              <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
156 00bcbdd0 Bill Marquette
                <tr id="frheader">
157
		  <td width="3%" class="list">&nbsp;</td>
158
                  <td width="3%" class="list">&nbsp;</td>
159 5b237745 Scott Ullrich
                  <td width="5%" class="listhdrr">If</td>
160
                  <td width="5%" class="listhdrr">Proto</td>
161
                  <td width="20%" class="listhdrr">Ext. port range</td>
162
                  <td width="20%" class="listhdrr">NAT IP</td>
163
                  <td width="20%" class="listhdrr">Int. port range</td>
164
                  <td width="20%" class="listhdr">Description</td>
165
                  <td width="5%" class="list"></td>
166 00bcbdd0 Bill Marquette
		</tr>
167
	<?php $nnats = $i = 0; foreach ($a_nat as $natent): ?>
168
                <tr valign="top" id="fr<?=$nnats;?>">
169
                  <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>
170
                  <td class="listt" align="center"></td>
171 b8a0de00 Bill Marquette
                  <td class="listlr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
172 8b1fab53 Scott Ullrich
		    <?php
173 00bcbdd0 Bill Marquette
			if (!$natent['interface'] || ($natent['interface'] == "wan"))
174
				echo "WAN";
175
			else
176 44e1049c Bill Marquette
				echo htmlspecialchars($config['interfaces'][$natent['interface']]['descr']);
177 00bcbdd0 Bill Marquette
		    ?>
178 5b237745 Scott Ullrich
                  </td>
179 b8a0de00 Bill Marquette
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
180 5b237745 Scott Ullrich
                    <?=strtoupper($natent['protocol']);?>
181
                  </td>
182 b8a0de00 Bill Marquette
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
183 340e6dca Scott Ullrich
                    <?php
184 5b237745 Scott Ullrich
						list($beginport, $endport) = split("-", $natent['external-port']);
185
						if ((!$endport) || ($beginport == $endport)) {
186
				  			echo $beginport;
187
							if ($wkports[$beginport])
188
								echo " (" . $wkports[$beginport] . ")";
189
						} else
190
							echo $beginport . " - " . $endport;
191
				  ?>
192
                  </td>
193 b8a0de00 Bill Marquette
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
194 5b237745 Scott Ullrich
                    <?=$natent['target'];?>
195
					<?php if ($natent['external-address'])
196
						echo "<br>(ext.: " . $natent['external-address'] . ")";
197
					?>
198
                  </td>
199 b8a0de00 Bill Marquette
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
200 5b237745 Scott Ullrich
                    <?php if ((!$endport) || ($beginport == $endport)) {
201
				  			echo $natent['local-port'];
202
							if ($wkports[$natent['local-port']])
203
								echo " (" . $wkports[$natent['local-port']] . ")";
204
						} else
205 340e6dca Scott Ullrich
							echo $natent['local-port'] . " - " .
206 5b237745 Scott Ullrich
								($natent['local-port']+$endport-$beginport);
207
				  ?>
208
                  </td>
209 8b1fab53 Scott Ullrich
                  <td class="listbg" onClick="fr_toggle(<?=$nnats;?>)" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
210
		  <font color="#ffffff">
211 5b237745 Scott Ullrich
                    <?=htmlspecialchars($natent['descr']);?>&nbsp;
212
                  </td>
213 00bcbdd0 Bill Marquette
                  <td valign="middle" class="list" nowrap>
214
                    <table border="0" cellspacing="0" cellpadding="1">
215
                      <tr>
216 f057bae4 Bill Marquette
                        <td><a href="firewall_nat_edit.php?id=<?=$i;?>"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0" title="edit rule"></a></td>
217 00bcbdd0 Bill Marquette
                      </tr>
218
                      <tr>
219 677c0869 Erik Kristensen
                        <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>
220
                        <td><a href="firewall_nat_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>
221 00bcbdd0 Bill Marquette
                      </tr>
222
                    </table>
223
		</tr>
224
  	     <?php $i++; $nnats++; endforeach; ?>
225 340e6dca Scott Ullrich
                <tr>
226 00bcbdd0 Bill Marquette
                  <td class="list" colspan="8"></td>
227
                  <td class="list" valign="middle" nowrap>
228
                    <table border="0" cellspacing="0" cellpadding="1">
229
                      <tr>
230 677c0869 Erik Kristensen
                        <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>
231
                        <td><a href="firewall_nat_edit.php"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a></td>
232 00bcbdd0 Bill Marquette
                      </tr>
233
                      <tr>
234 a99e956f Erik Kristensen
                        <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>
235 00bcbdd0 Bill Marquette
                      </tr>
236
                    </table></td>
237 d732f186 Bill Marquette
                </tr>
238
        <tr><td colspan="8"><p><span class="vexpl"><span class="red"><strong>Note:<br>
239 340e6dca Scott Ullrich
                      </strong></span>It is not possible to access NATed services
240 925b8e0a Bill Marquette
                      using the WAN IP address from within the LAN (or an optional
241 5b237745 Scott Ullrich
                      network).</span></p></td>
242 d732f186 Bill Marquette
		    </tr>
243
	</table>
244
	</div>
245
	</td>
246 5b237745 Scott Ullrich
  </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>