Project

General

Profile

Download (13.1 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
			clear_subsystem_dirty('natconf');
73
			clear_subsystem_dirty('filter');
74
		}
75

    
76
	}
77
}
78

    
79
if (isset($_POST['del_x'])) {
80
    /* delete selected rules */
81
    if (is_array($_POST['rule']) && count($_POST['rule'])) {
82
	    foreach ($_POST['rule'] as $rulei) {
83
		$target = $rule['target'];
84
	        unset($a_nat[$rulei]);
85
	    }
86
	    write_config();
87
	    mark_subsystem_dirty('natconf');
88
	    header("Location: firewall_nat.php");
89
	    exit;
90
	}
91

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

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

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

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

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

    
136
$pgtitle = array("Firewall","NAT","Port Forward");
137
include("head.inc");
138

    
139
echo "<script type=\"text/javascript\" language=\"javascript\" src=\"/javascript/domTT/domLib.js\"></script>";
140
echo "<script type=\"text/javascript\" language=\"javascript\" src=\"/javascript/domTT/domTT.js\"></script>";
141
echo "<script type=\"text/javascript\" language=\"javascript\" src=\"/javascript/domTT/behaviour.js\"></script>";
142
echo "<script type=\"text/javascript\" language=\"javascript\" src=\"/javascript/domTT/fadomatic.js\"></script>";
143

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

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

    
306
<?php
307
if ($pkg['tabs'] <> "") {
308
    echo "</td></tr></table>";
309
}
310
?>
311

    
312
</form>
313
<?php include("fend.inc"); ?>
314
</body>
315
</html>
(49-49/217)