Project

General

Profile

Download (11.6 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	firewall_nat.php
5
	Copyright (C) 2004 Scott Ullrich
6
	All rights reserved.
7

    
8
	originally part of m0n0wall (http://m0n0.ch/wall)
9
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
10
	All rights reserved.
11

    
12
	Redistribution and use in source and binary forms, with or without
13
	modification, are permitted provided that the following conditions are met:
14

    
15
	1. Redistributions of source code must retain the above copyright notice,
16
	   this list of conditions and the following disclaimer.
17

    
18
	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

    
22
	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
if (!is_array($config['nat']['rule']))
37
	$config['nat']['rule'] = array();
38

    
39
$a_nat = &$config['nat']['rule'];
40

    
41
/* if a custom message has been passed along, lets process it */
42
if ($_GET['savemsg'])
43
	$savemsg = $_GET['savemsg'];
44

    
45
if ($_POST) {
46

    
47
	$pconfig = $_POST;
48

    
49
	if ($_POST['apply']) {
50

    
51
		write_config();
52

    
53
		$retval = 0;
54

    
55
		config_lock();
56
		$retval |= filter_configure();
57
		config_unlock();
58

    
59
		if(stristr($retval, "error") <> true)
60
		    $savemsg = get_std_save_message($retval);
61
		else
62
		    $savemsg = $retval;
63

    
64
		if ($retval == 0) {
65
			if (file_exists($d_natconfdirty_path))
66
				unlink($d_natconfdirty_path);
67
			if (file_exists($d_filterconfdirty_path))
68
				unlink($d_filterconfdirty_path);
69
		}
70
	}
71
}
72

    
73
if (isset($_POST['del_x'])) {
74
        /* delete selected rules */
75
        if (is_array($_POST['rule']) && count($_POST['rule'])) {
76
                foreach ($_POST['rule'] as $rulei) {
77
			$target = $rule['target'];
78
			$helpers = exec("/bin/ps auwx | grep pftpx | grep {$target} | grep -v grep | cut -d\" \" -f5");
79
			if($helpers) {
80
				/* kill ftp proxy helper */
81
				mwexec("/bin/kill {$helpers}");
82
			}
83
                        unset($a_nat[$rulei]);
84
                }
85
                write_config();
86
                touch($d_natconfdirty_path);
87
                header("Location: firewall_nat.php");
88
                exit;
89
        }
90

    
91
} else {
92
        /* yuck - IE won't send value attributes for image buttons, while Mozilla does - so we use .x/.y to find move button clicks instead... */
93
        unset($movebtn);
94
        foreach ($_POST as $pn => $pd) {
95
                if (preg_match("/move_(\d+)_x/", $pn, $matches)) {
96
                        $movebtn = $matches[1];
97
                        break;
98
                }
99
        }
100
        /* move selected rules before this rule */
101
        if (isset($movebtn) && is_array($_POST['rule']) && count($_POST['rule'])) {
102
                $a_nat_new = array();
103

    
104
                /* copy all rules < $movebtn and not selected */
105
                for ($i = 0; $i < $movebtn; $i++) {
106
                        if (!in_array($i, $_POST['rule']))
107
                                $a_nat_new[] = $a_nat[$i];
108
                }
109

    
110
                /* copy all selected rules */
111
                for ($i = 0; $i < count($a_nat); $i++) {
112
                        if ($i == $movebtn)
113
                                continue;
114
                        if (in_array($i, $_POST['rule']))
115
                                $a_nat_new[] = $a_nat[$i];
116
                }
117

    
118
                /* copy $movebtn rule */
119
                if ($movebtn < count($a_nat))
120
                        $a_nat_new[] = $a_nat[$movebtn];
121

    
122
                /* copy all rules > $movebtn and not selected */
123
                for ($i = $movebtn+1; $i < count($a_nat); $i++) {
124
                        if (!in_array($i, $_POST['rule']))
125
                                $a_nat_new[] = $a_nat[$i];
126
                }
127
                $a_nat = $a_nat_new;
128
                write_config();
129
                touch($d_natconfdirty_path);
130
                header("Location: firewall_nat.php");
131
                exit;
132
        }
133
}
134

    
135
$pgtitle = "Firewall: NAT: Port Forward";
136
include("head.inc");
137

    
138
?>
139
<body link="#000000" vlink="#000000" alink="#000000">
140
<?php include("fbegin.inc"); ?>
141
<p class="pgtitle"><?=$pgtitle?></font></p>
142
<form action="firewall_nat.php" method="post" name="iform">
143
<script type="text/javascript" language="javascript" src="row_toggle.js">
144
</script>
145
<?php if (file_exists($d_natconfdirty_path)): ?><p>
146
<?php
147
	if($savemsg)
148
		print_info_box_np("{$savemsg}<br>The NAT configuration has been changed.<br>You must apply the changes in order for them to take effect.");
149
	else
150
		print_info_box_np("The NAT configuration has been changed.<br>You must apply the changes in order for them to take effect.");
151
?>
152
<?php endif; ?>
153
<table width="100%" border="0" cellpadding="0" cellspacing="0">
154
  <tr><td>
155
<?php
156
	$tab_array = array();
157
	$tab_array[] = array("Port Forward", true, "firewall_nat.php");
158
	$tab_array[] = array("1:1", false, "firewall_nat_1to1.php");
159
	$tab_array[] = array("Outbound", false, "firewall_nat_out.php");
160
	display_top_tabs($tab_array);
161
?>
162
 </td></tr>
163
  <tr>
164
    <td>
165
	<div id="mainarea">
166
              <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
167
                <tr id="frheader">
168
		  <td width="3%" class="list">&nbsp;</td>
169
                  <td width="3%" class="list">&nbsp;</td>
170
                  <td width="5%" class="listhdrr">If</td>
171
                  <td width="5%" class="listhdrr">Proto</td>
172
                  <td width="20%" class="listhdrr">Ext. port range</td>
173
                  <td width="20%" class="listhdrr">NAT IP</td>
174
                  <td width="20%" class="listhdrr">Int. port range</td>
175
                  <td width="20%" class="listhdr">Description</td>
176
                  <td width="5%" class="list"></td>
177
		</tr>
178
	<?php $nnats = $i = 0; foreach ($a_nat as $natent): ?>
179
                <tr valign="top" id="fr<?=$nnats;?>">
180
                  <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>
181
                  <td class="listt" align="center"></td>
182
                  <td class="listlr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
183
		    <?php
184
			if (!$natent['interface'] || ($natent['interface'] == "wan"))
185
				echo "WAN";
186
			else if(strtolower($natent['interface']) == "lan")
187
				echo "LAN";
188
			else
189
				echo strtoupper($config['interfaces'][$natent['interface']]['descr']);
190
		    ?>
191
                  </td>
192
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
193
                    <?=strtoupper($natent['protocol']);?>
194
                  </td>
195
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
196
                    <?php
197
						list($beginport, $endport) = split("-", $natent['external-port']);
198
						if ((!$endport) || ($beginport == $endport)) {
199
				  			echo $beginport;
200
							if ($wkports[$beginport])
201
								echo " (" . $wkports[$beginport] . ")";
202
							else
203
								echo "&nbsp;";
204
						} else
205
							echo $beginport . " - " . $endport;
206
				  ?>
207
                  </td>
208
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
209
                    <?=$natent['target'];?>
210
					<?php if ($natent['external-address'])
211
						echo "<br>(ext.: " . $natent['external-address'] . ")";
212
					      else
213
						echo "<br>(ext.: " . find_interface_ip(convert_friendly_interface_to_real_interface_name($natent['interface'])) . ")";
214
					?>
215
                  </td>
216
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
217
                    <?php if ((!$endport) || ($beginport == $endport)) {
218
				  			echo $natent['local-port'];
219
							if ($wkports[$natent['local-port']])
220
								echo " (" . $wkports[$natent['local-port']] . ")";
221
							else
222
								echo "&nbsp;";
223
						} else
224
							echo $natent['local-port'] . " - " .
225
								($natent['local-port']+$endport-$beginport);
226
				  ?>
227
                  </td>
228
                  <td class="listbg" onClick="fr_toggle(<?=$nnats;?>)" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
229
		  <font color="#ffffff">
230
                    <?=htmlspecialchars($natent['descr']);?>&nbsp;
231
                  </td>
232
                  <td valign="middle" class="list" nowrap>
233
                    <table border="0" cellspacing="0" cellpadding="1">
234
                      <tr>
235
                        <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>
236
                      </tr>
237
                      <tr>
238
                        <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>
239
                        <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>
240
                      </tr>
241
                    </table>
242
		</tr>
243
  	     <?php $i++; $nnats++; endforeach; ?>
244
                <tr>
245
                  <td class="list" colspan="8"></td>
246
                  <td class="list" valign="middle" nowrap>
247
                    <table border="0" cellspacing="0" cellpadding="1">
248
                      <tr>
249
                        <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>
250
                        <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>
251
                      </tr>
252
                      <tr>
253
                        <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>
254
                      </tr>
255
                    </table></td>
256
                </tr>
257
	</table>
258
	</div>
259
	</td>
260
  </tr>
261
</table>
262

    
263
<?php
264
if ($pkg['tabs'] <> "") {
265
    echo "</td></tr></table>";
266
}
267
?>
268

    
269
</form>
270
<?php include("fend.inc"); ?>
271
</body>
272
</html>
(38-38/164)