Project

General

Profile

Download (12 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
		if(stristr($retval, "error") <> true)
56
		    $savemsg = get_std_save_message($retval);
57
		else
58
		    $savemsg = $retval;
59

    
60
		unlink_if_exists("/tmp/config.cache");
61
		$retval |= filter_configure();
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

    
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 awwux | grep pftpx | grep \"{$target}\" | grep -v grep | awk '{ print \$2 }'");
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">
177
                    <table border="0" cellspacing="0" cellpadding="1">
178
                      <tr>
179
			<td width="17"></td>
180
                        <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>
181
                      </tr>
182
                    </table>
183
		  </td>
184
		</tr>
185
	<?php $nnats = $i = 0; foreach ($a_nat as $natent): ?>
186
                <tr valign="top" id="fr<?=$nnats;?>">
187
                  <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>
188
                  <td class="listt" align="center"></td>
189
                  <td class="listlr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
190
		    <?php
191
			if (!$natent['interface'] || ($natent['interface'] == "wan"))
192
				echo "WAN";
193
			else if(strtolower($natent['interface']) == "lan")
194
				echo "LAN";
195
			else if(strtolower($natent['interface']) == "pppoe")
196
				echo "PPPoE";
197
			else if(strtolower($natent['interface']) == "pptp")
198
				echo "PPTP";
199
			else
200
				echo strtoupper($config['interfaces'][$natent['interface']]['descr']);
201
		    ?>
202
                  </td>
203
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
204
                    <?=strtoupper($natent['protocol']);?>
205
                  </td>
206
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
207
                    <?php
208
						list($beginport, $endport) = split("-", $natent['external-port']);
209
						if ((!$endport) || ($beginport == $endport)) {
210
				  			echo $beginport;
211
							if ($wkports[$beginport])
212
								echo " (" . $wkports[$beginport] . ")";
213
							else
214
								echo "&nbsp;";
215
						} else
216
							echo $beginport . " - " . $endport;
217
				  ?>
218
                  </td>
219
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
220
                    <?=$natent['target'];?>
221
					<?php if ($natent['external-address'])
222
						echo "<br>(ext.: " . $natent['external-address'] . ")";
223
					      else
224
						echo "<br>(ext.: " . find_interface_ip(convert_friendly_interface_to_real_interface_name($natent['interface'])) . ")";
225
					?>
226
                  </td>
227
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
228
                    <?php if ((!$endport) || ($beginport == $endport)) {
229
				  			echo $natent['local-port'];
230
							if ($wkports[$natent['local-port']])
231
								echo " (" . $wkports[$natent['local-port']] . ")";
232
							else
233
								echo "&nbsp;";
234
						} else
235
							echo $natent['local-port'] . " - " .
236
								($natent['local-port']+$endport-$beginport);
237
				  ?>
238
                  </td>
239
                  <td class="listbg" onClick="fr_toggle(<?=$nnats;?>)" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
240
		  <font color="#ffffff">
241
                    <?=htmlspecialchars($natent['descr']);?>&nbsp;
242
                  </td>
243
                  <td valign="middle" class="list" nowrap>
244
                    <table border="0" cellspacing="0" cellpadding="1">
245
                      <tr>
246
                        <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>
247
                      </tr>
248
                      <tr>
249
                        <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>
250
                        <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>
251
                      </tr>
252
                    </table>
253
		</tr>
254
  	     <?php $i++; $nnats++; endforeach; ?>
255
                <tr>
256
                  <td class="list" colspan="8"></td>
257
                  <td class="list" valign="middle" nowrap>
258
                    <table border="0" cellspacing="0" cellpadding="1">
259
                      <tr>
260
                        <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>
261
                        <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>
262
                      </tr>
263
                      <tr>
264
                        <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>
265
                      </tr>
266
                    </table>
267
		  </td>
268
                </tr>
269
	</table>
270
	</div>
271
	</td>
272
  </tr>
273
</table>
274

    
275
<?php
276
if ($pkg['tabs'] <> "") {
277
    echo "</td></tr></table>";
278
}
279
?>
280

    
281
</form>
282
<?php include("fend.inc"); ?>
283
</body>
284
</html>
(43-43/175)