Project

General

Profile

Download (13.3 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
##|+PRIV
35
##|*IDENT=page-firewall-nat-portforward
36
##|*NAME=Firewall: NAT: Port Forward page
37
##|*DESCR=Allow access to the 'Firewall: NAT: Port Forward' page.
38
##|*MATCH=firewall_nat.php*
39
##|-PRIV
40

    
41

    
42
require("guiconfig.inc");
43

    
44
if (!is_array($config['nat']['rule']))
45
	$config['nat']['rule'] = array();
46

    
47
$a_nat = &$config['nat']['rule'];
48

    
49
/* if a custom message has been passed along, lets process it */
50
if ($_GET['savemsg'])
51
	$savemsg = $_GET['savemsg'];
52

    
53
if ($_POST) {
54

    
55
	$pconfig = $_POST;
56

    
57
	if ($_POST['apply']) {
58

    
59
		write_config();
60

    
61
		$retval = 0;
62

    
63
		if(stristr($retval, "error") <> true)
64
		    $savemsg = get_std_save_message($retval);
65
		else
66
		    $savemsg = $retval;
67

    
68
		unlink_if_exists("/tmp/config.cache");
69
		$retval |= filter_configure();
70

    
71
		if ($retval == 0) {
72
			if (file_exists($d_natconfdirty_path))
73
				unlink($d_natconfdirty_path);
74
			if (file_exists($d_filterconfdirty_path))
75
				unlink($d_filterconfdirty_path);
76
		}
77

    
78
	}
79
}
80

    
81
if (isset($_POST['del_x'])) {
82
    /* delete selected rules */
83
    if (is_array($_POST['rule']) && count($_POST['rule'])) {
84
	    foreach ($_POST['rule'] as $rulei) {
85
			$target = $rule['target'];
86
			$helpers = exec("/bin/ps awwux | grep pftpx | grep \"{$target}\" | grep -v grep | awk '{ print \$2 }'");
87
			if($helpers) {
88
				/* kill ftp proxy helper */
89
				mwexec("/bin/kill {$helpers}");
90
			}
91
	        unset($a_nat[$rulei]);
92
	    }
93
	    write_config();
94
	    touch($d_natconfdirty_path);
95
	    header("Location: firewall_nat.php");
96
	    exit;
97
	}
98

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

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

    
118
                /* copy all selected rules */
119
                for ($i = 0; $i < count($a_nat); $i++) {
120
                        if ($i == $movebtn)
121
                                continue;
122
                        if (in_array($i, $_POST['rule']))
123
                                $a_nat_new[] = $a_nat[$i];
124
                }
125

    
126
                /* copy $movebtn rule */
127
                if ($movebtn < count($a_nat))
128
                        $a_nat_new[] = $a_nat[$movebtn];
129

    
130
                /* copy all rules > $movebtn and not selected */
131
                for ($i = $movebtn+1; $i < count($a_nat); $i++) {
132
                        if (!in_array($i, $_POST['rule']))
133
                                $a_nat_new[] = $a_nat[$i];
134
                }
135
                $a_nat = $a_nat_new;
136
                write_config();
137
                touch($d_natconfdirty_path);
138
                header("Location: firewall_nat.php");
139
                exit;
140
        }
141
}
142

    
143
$pgtitle = array("Firewall","NAT","Port Forward");
144
include("head.inc");
145

    
146
echo "<script type=\"text/javascript\" language=\"javascript\" src=\"/javascript/domTT/domLib.js\"></script>";
147
echo "<script type=\"text/javascript\" language=\"javascript\" src=\"/javascript/domTT/domTT.js\"></script>";
148
echo "<script type=\"text/javascript\" language=\"javascript\" src=\"/javascript/domTT/behaviour.js\"></script>";
149
echo "<script type=\"text/javascript\" language=\"javascript\" src=\"/javascript/domTT/fadomatic.js\"></script>";
150

    
151
?>
152
<body link="#000000" vlink="#000000" alink="#000000">
153
<?php include("fbegin.inc"); ?>
154
<form action="firewall_nat.php" method="post" name="iform">
155
<script type="text/javascript" language="javascript" src="row_toggle.js">
156
</script>
157
<?php if (file_exists($d_natconfdirty_path)): ?><p>
158
<?php
159
	if($savemsg)
160
		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.");
161
	else
162
		print_info_box_np("The NAT configuration has been changed.<br>You must apply the changes in order for them to take effect.");
163
?>
164
<?php endif; ?>
165
<table width="100%" border="0" cellpadding="0" cellspacing="0">
166
  <tr><td>
167
<?php
168
	$tab_array = array();
169
	$tab_array[] = array("Port Forward", true, "firewall_nat.php");
170
	$tab_array[] = array("1:1", false, "firewall_nat_1to1.php");
171
	$tab_array[] = array("Outbound", false, "firewall_nat_out.php");
172
	display_top_tabs($tab_array);
173
?>
174
 </td></tr>
175
  <tr>
176
    <td>
177
	<div id="mainarea">
178
              <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
179
                <tr id="frheader">
180
		  <td width="3%" class="list">&nbsp;</td>
181
                  <td width="3%" class="list">&nbsp;</td>
182
                  <td width="5%" class="listhdrr">If</td>
183
                  <td width="5%" class="listhdrr">Proto</td>
184
                  <td width="20%" class="listhdrr">Ext. port range</td>
185
                  <td width="20%" class="listhdrr">NAT IP</td>
186
                  <td width="20%" class="listhdrr">Int. port range</td>
187
                  <td width="20%" class="listhdr">Description</td>
188
                  <td width="5%" class="list">
189
                    <table border="0" cellspacing="0" cellpadding="1">
190
                      <tr>
191
			<td width="17"></td>
192
                        <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>
193
                      </tr>
194
                    </table>
195
		  </td>
196
		</tr>
197
	<?php $nnats = $i = 0; foreach ($a_nat as $natent): ?>
198
	<?php 
199
	
200
		//build Alias popup box
201
		$span_begin = "";
202
		$span_end = "";
203
		$alias_src_port_span_begin = "";
204
		$alias_dst_span_begin = "";
205
		$alias_dst_port_span_begin = "";
206
		
207
		list($beginport, $endport) = split("-", $natent['external-port']);		
208
		
209
		$alias_popup = rule_popup("",$beginport,$natent['target'],$natent['local-port']);
210
		$span_end = "</U></span>";
211
			
212
		 									
213
		$alias_src_port_span_begin = $alias_popup["srcport"];
214
											
215
		$alias_dst_span_begin = $alias_popup["dst"];
216
												
217
		$alias_dst_port_span_begin = $alias_popup["dstport"];
218
													
219
		
220

    
221
	
222
		/* if user does not have access to edit an interface skip on to the next record */
223
		if(!have_natpfruleint_access($natent['interface'])) 
224
			continue;
225
	?>
226
                <tr valign="top" id="fr<?=$nnats;?>">
227
                  <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>
228
                  <td class="listt" align="center"></td>
229
                  <td class="listlr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
230
		    <?php
231
			if (!$natent['interface'] || ($natent['interface'] == "wan"))
232
				echo "WAN";
233
			else if(strtolower($natent['interface']) == "lan")
234
				echo "LAN";
235
			else
236
				echo strtoupper($config['interfaces'][$natent['interface']]['descr']);
237
		    ?>
238
                  </td>
239
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
240
                    <?=strtoupper($natent['protocol']);?>
241
                  </td>
242
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
243
                    <?php
244
						list($beginport, $endport) = split("-", $natent['external-port']);
245
						if ((!$endport) || ($beginport == $endport)) {
246
							echo $alias_src_port_span_begin;
247
				  			echo $beginport;
248
							if ($wkports[$beginport])
249
								echo " (" . $wkports[$beginport] . ")";
250
							else
251
								echo "&nbsp;";
252
							echo $span_end;
253
						} else
254
							echo $beginport . " - " . $endport;
255
				  ?>
256
                  </td>
257
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
258
                    <?php echo $alias_dst_span_begin;?><?=$natent['target'];?><?php echo $span_end;?>
259
					<?php if ($natent['external-address'])
260
						echo "<br>(ext.: " . $natent['external-address'] . ")";
261
					      else
262
						echo "<br>(ext.: " . find_interface_ip(convert_friendly_interface_to_real_interface_name($natent['interface'])) . ")";
263
					?>
264
                  </td>
265
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
266
                    <?php if ((!$endport) || ($beginport == $endport)) {
267
				  			echo $alias_dst_port_span_begin;
268
                    		echo $natent['local-port'];
269
							if ($wkports[$natent['local-port']])
270
								echo " (" . $wkports[$natent['local-port']] . ")";
271
							else
272
								echo "&nbsp;";
273
							echo $span_end;
274
						} else
275
							echo $natent['local-port'] . " - " .
276
								($natent['local-port']+$endport-$beginport);
277
				  ?>
278
                  </td>
279
                  <td class="listbg" onClick="fr_toggle(<?=$nnats;?>)" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
280
                    <?=htmlspecialchars($natent['descr']);?>&nbsp;
281
                  </td>
282
                  <td valign="middle" class="list" nowrap>
283
                    <table border="0" cellspacing="0" cellpadding="1">
284
                      <tr>
285
                        <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>
286
                      </tr>
287
                      <tr>
288
                        <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>
289
                        <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>
290
                      </tr>
291
                    </table>
292
		</tr>
293
  	     <?php $i++; $nnats++; endforeach; ?>
294
                <tr>
295
                  <td class="list" colspan="8"></td>
296
                  <td class="list" valign="middle" nowrap>
297
                    <table border="0" cellspacing="0" cellpadding="1">
298
                      <tr>
299
                        <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>
300
                        <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>
301
                      </tr>
302
                      <tr>
303
                        <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>
304
                      </tr>
305
                    </table>
306
		  </td>
307
                </tr>
308
	</table>
309
	</div>
310
	</td>
311
  </tr>
312
</table>
313

    
314
<?php
315
if ($pkg['tabs'] <> "") {
316
    echo "</td></tr></table>";
317
}
318
?>
319

    
320
</form>
321
<?php include("fend.inc"); ?>
322
</body>
323
</html>
(44-44/210)