Project

General

Profile

Download (11 KB) Statistics
| Branch: | Tag: | Revision:
1 340e6dca Scott Ullrich
<?php
2 b46bfcf5 Bill Marquette
/* $Id$ */
3 5b237745 Scott Ullrich
/*
4
	firewall_nat.php
5 c55b323d Scott Ullrich
	Copyright (C) 2004 Scott Ullrich
6
	All rights reserved.
7 340e6dca Scott Ullrich
8 c55b323d Scott Ullrich
	originally part of m0n0wall (http://m0n0.ch/wall)
9 5b237745 Scott Ullrich
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
10
	All rights reserved.
11 340e6dca Scott Ullrich
12 5b237745 Scott Ullrich
	Redistribution and use in source and binary forms, with or without
13
	modification, are permitted provided that the following conditions are met:
14 340e6dca Scott Ullrich
15 5b237745 Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
16
	   this list of conditions and the following disclaimer.
17 340e6dca Scott Ullrich
18 5b237745 Scott Ullrich
	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 340e6dca Scott Ullrich
22 5b237745 Scott Ullrich
	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
require("guiconfig.inc");
35
36 e8c2c890 Bill Marquette
if (!is_array($config['nat']['rule']))
37 5b237745 Scott Ullrich
	$config['nat']['rule'] = array();
38 fbe94068 Scott Ullrich
39 5b237745 Scott Ullrich
$a_nat = &$config['nat']['rule'];
40
41
if ($_POST) {
42
43
	$pconfig = $_POST;
44
45
	if ($_POST['apply']) {
46 e8c2c890 Bill Marquette
47
		write_config();
48
49 5b237745 Scott Ullrich
		$retval = 0;
50 12f974a4 Scott Ullrich
		
51
		config_lock();
52
		$retval |= filter_configure();
53
		config_unlock();
54 e8c2c890 Bill Marquette
55 b2774343 Scott Ullrich
		if(stristr($retval, "error") <> true)
56 2a71debf Scott Ullrich
		    $savemsg = get_std_save_message($retval);
57
		else
58
		    $savemsg = $retval;
59 340e6dca Scott Ullrich
60 5b237745 Scott Ullrich
		if ($retval == 0) {
61
			if (file_exists($d_natconfdirty_path))
62
				unlink($d_natconfdirty_path);
63
			if (file_exists($d_filterconfdirty_path))
64
				unlink($d_filterconfdirty_path);
65
		}
66
	}
67
}
68
69 00bcbdd0 Bill Marquette
if (isset($_POST['del_x'])) {
70
        /* delete selected rules */
71
        if (is_array($_POST['rule']) && count($_POST['rule'])) {
72
                foreach ($_POST['rule'] as $rulei) {
73 25b71fd4 Scott Ullrich
			$target = $rule['target'];
74
			$helpers = exec("/bin/ps auwx | grep pftpx | grep {$target} | grep -v grep | cut -d\" \" -f5");
75 48cb8115 Scott Ullrich
			if($helpers) {
76
				/* kill ftp proxy helper */
77 25b71fd4 Scott Ullrich
				mwexec("/bin/kill {$helpers}");
78
			}
79 00bcbdd0 Bill Marquette
                        unset($a_nat[$rulei]);
80
                }
81
                write_config();
82
                touch($d_natconfdirty_path);
83
                header("Location: firewall_nat.php");
84
                exit;
85
        }
86
87
} else {
88
        /* yuck - IE won't send value attributes for image buttons, while Mozilla does - so we use .x/.y to find move button clicks instead... */
89
        unset($movebtn);
90
        foreach ($_POST as $pn => $pd) {
91
                if (preg_match("/move_(\d+)_x/", $pn, $matches)) {
92
                        $movebtn = $matches[1];
93
                        break;
94
                }
95
        }
96
        /* move selected rules before this rule */
97
        if (isset($movebtn) && is_array($_POST['rule']) && count($_POST['rule'])) {
98
                $a_nat_new = array();
99
100
                /* copy all rules < $movebtn and not selected */
101
                for ($i = 0; $i < $movebtn; $i++) {
102
                        if (!in_array($i, $_POST['rule']))
103
                                $a_nat_new[] = $a_nat[$i];
104
                }
105
106
                /* copy all selected rules */
107
                for ($i = 0; $i < count($a_nat); $i++) {
108
                        if ($i == $movebtn)
109
                                continue;
110
                        if (in_array($i, $_POST['rule']))
111
                                $a_nat_new[] = $a_nat[$i];
112
                }
113
114
                /* copy $movebtn rule */
115
                if ($movebtn < count($a_nat))
116
                        $a_nat_new[] = $a_nat[$movebtn];
117
118
                /* copy all rules > $movebtn and not selected */
119
                for ($i = $movebtn+1; $i < count($a_nat); $i++) {
120
                        if (!in_array($i, $_POST['rule']))
121
                                $a_nat_new[] = $a_nat[$i];
122
                }
123
                $a_nat = $a_nat_new;
124
                write_config();
125
                touch($d_natconfdirty_path);
126
                header("Location: firewall_nat.php");
127
                exit;
128
        }
129 5b237745 Scott Ullrich
}
130 00bcbdd0 Bill Marquette
131 183a4aae Bill Marquette
$pgtitle = "Firewall: NAT: Port Forward";
132 6eb17647 Scott Ullrich
include("head.inc");
133
134 24f600b0 Scott Ullrich
?>
135 a8726a3d Scott Ullrich
<body link="#000000" vlink="#000000" alink="#000000">
136 5b237745 Scott Ullrich
<?php include("fbegin.inc"); ?>
137 da7ae7ef Bill Marquette
<p class="pgtitle"><?=$pgtitle?></font></p>
138 00bcbdd0 Bill Marquette
<form action="firewall_nat.php" method="post" name="iform">
139
<script type="text/javascript" language="javascript" src="row_toggle.js">
140
</script>
141 5b237745 Scott Ullrich
<?php if ($savemsg) print_info_box($savemsg); ?>
142
<?php if (file_exists($d_natconfdirty_path)): ?><p>
143 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.");?>
144 5b237745 Scott Ullrich
<?php endif; ?>
145
<table width="100%" border="0" cellpadding="0" cellspacing="0">
146
  <tr><td>
147 a8726a3d Scott Ullrich
<?php
148
	$tab_array = array();
149 1425e067 Bill Marquette
	$tab_array[] = array("Port Forward", true, "firewall_nat.php");
150
	$tab_array[] = array("1:1", false, "firewall_nat_1to1.php");
151
	$tab_array[] = array("Outbound", false, "firewall_nat_out.php");
152 a8726a3d Scott Ullrich
	display_top_tabs($tab_array);
153
?>
154
 </td></tr>
155 340e6dca Scott Ullrich
  <tr>
156 d732f186 Bill Marquette
    <td>
157
	<div id="mainarea">
158
              <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
159 00bcbdd0 Bill Marquette
                <tr id="frheader">
160
		  <td width="3%" class="list">&nbsp;</td>
161
                  <td width="3%" class="list">&nbsp;</td>
162 5b237745 Scott Ullrich
                  <td width="5%" class="listhdrr">If</td>
163
                  <td width="5%" class="listhdrr">Proto</td>
164
                  <td width="20%" class="listhdrr">Ext. port range</td>
165
                  <td width="20%" class="listhdrr">NAT IP</td>
166
                  <td width="20%" class="listhdrr">Int. port range</td>
167
                  <td width="20%" class="listhdr">Description</td>
168
                  <td width="5%" class="list"></td>
169 00bcbdd0 Bill Marquette
		</tr>
170
	<?php $nnats = $i = 0; foreach ($a_nat as $natent): ?>
171
                <tr valign="top" id="fr<?=$nnats;?>">
172
                  <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>
173
                  <td class="listt" align="center"></td>
174 b8a0de00 Bill Marquette
                  <td class="listlr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
175 8b1fab53 Scott Ullrich
		    <?php
176 00bcbdd0 Bill Marquette
			if (!$natent['interface'] || ($natent['interface'] == "wan"))
177
				echo "WAN";
178
			else
179 ec9f26f2 Scott Ullrich
				echo strtoupper($natent['interface']);
180 00bcbdd0 Bill Marquette
		    ?>
181 5b237745 Scott Ullrich
                  </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 5b237745 Scott Ullrich
                    <?=strtoupper($natent['protocol']);?>
184
                  </td>
185 b8a0de00 Bill Marquette
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
186 340e6dca Scott Ullrich
                    <?php
187 5b237745 Scott Ullrich
						list($beginport, $endport) = split("-", $natent['external-port']);
188
						if ((!$endport) || ($beginport == $endport)) {
189
				  			echo $beginport;
190
							if ($wkports[$beginport])
191
								echo " (" . $wkports[$beginport] . ")";
192
						} else
193
							echo $beginport . " - " . $endport;
194
				  ?>
195
                  </td>
196 b8a0de00 Bill Marquette
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
197 5b237745 Scott Ullrich
                    <?=$natent['target'];?>
198
					<?php if ($natent['external-address'])
199
						echo "<br>(ext.: " . $natent['external-address'] . ")";
200
					?>
201
                  </td>
202 b8a0de00 Bill Marquette
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
203 5b237745 Scott Ullrich
                    <?php if ((!$endport) || ($beginport == $endport)) {
204
				  			echo $natent['local-port'];
205
							if ($wkports[$natent['local-port']])
206
								echo " (" . $wkports[$natent['local-port']] . ")";
207
						} else
208 340e6dca Scott Ullrich
							echo $natent['local-port'] . " - " .
209 5b237745 Scott Ullrich
								($natent['local-port']+$endport-$beginport);
210
				  ?>
211
                  </td>
212 8b1fab53 Scott Ullrich
                  <td class="listbg" onClick="fr_toggle(<?=$nnats;?>)" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
213
		  <font color="#ffffff">
214 5b237745 Scott Ullrich
                    <?=htmlspecialchars($natent['descr']);?>&nbsp;
215
                  </td>
216 00bcbdd0 Bill Marquette
                  <td valign="middle" class="list" nowrap>
217
                    <table border="0" cellspacing="0" cellpadding="1">
218
                      <tr>
219 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>
220 00bcbdd0 Bill Marquette
                      </tr>
221
                      <tr>
222 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>
223
                        <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>
224 00bcbdd0 Bill Marquette
                      </tr>
225
                    </table>
226
		</tr>
227
  	     <?php $i++; $nnats++; endforeach; ?>
228 340e6dca Scott Ullrich
                <tr>
229 00bcbdd0 Bill Marquette
                  <td class="list" colspan="8"></td>
230
                  <td class="list" valign="middle" nowrap>
231
                    <table border="0" cellspacing="0" cellpadding="1">
232
                      <tr>
233 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>
234
                        <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>
235 00bcbdd0 Bill Marquette
                      </tr>
236
                      <tr>
237 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>
238 00bcbdd0 Bill Marquette
                      </tr>
239
                    </table></td>
240 d732f186 Bill Marquette
                </tr>
241
	</table>
242
	</div>
243
	</td>
244 5b237745 Scott Ullrich
  </tr>
245
</table>
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
</body>
256
</html>