Project

General

Profile

Download (13.7 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
	pfSense_MODULE:	nat
35
*/
36

    
37
##|+PRIV
38
##|*IDENT=page-firewall-nat-portforward
39
##|*NAME=Firewall: NAT: Port Forward page
40
##|*DESCR=Allow access to the 'Firewall: NAT: Port Forward' page.
41
##|*MATCH=firewall_nat.php*
42
##|-PRIV
43

    
44
require("guiconfig.inc");
45

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

    
49
$a_nat = &$config['nat']['rule'];
50

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

    
55
if ($_POST) {
56

    
57
	$pconfig = $_POST;
58

    
59
	if ($_POST['apply']) {
60

    
61
		write_config();
62

    
63
		$retval = 0;
64

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

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

    
73
		if ($retval == 0) {
74
			clear_subsystem_dirty('natconf');
75
			clear_subsystem_dirty('filter');
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
			// Check for filter rule associations
87
			if (isset($a_nat[$rulei]['associated-filter-rule-id'])){
88
				delete_id($a_nat[$rulei]['associated-filter-rule-id'], $config['filter']['rule']);
89
				
90
				mark_subsystem_dirty('filter');
91
			}
92
	        unset($a_nat[$rulei]);
93
	    }
94
	    write_config();
95
	    mark_subsystem_dirty('natconf');
96
	    header("Location: firewall_nat.php");
97
	    exit;
98
	}
99

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

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

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

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

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

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

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

    
152
?>
153
<body link="#000000" vlink="#000000" alink="#000000">
154
<?php include("fbegin.inc"); ?>
155
<form action="firewall_nat.php" method="post" name="iform">
156
<script type="text/javascript" language="javascript" src="/javascript/row_toggle.js"></script>
157
<?php if (is_subsystem_dirty('natconf')): ?><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">
229
					<?php if(isset($natent['associated-filter-rule-id']) && $natent['associated-filter-rule-id']>0): ?>
230
					<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_chain.png" width="17" height="17" title="Firewall rule ID <?=htmlspecialchars($natent['associated-filter-rule-id']); ?> is managed with this rule" border="0">
231
					<?php endif; ?>
232
				  </td>
233
                  <td class="listlr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
234
		    <?php
235
			if (!$natent['interface'] || ($natent['interface'] == "wan"))
236
				echo "WAN";
237
			else if(strtolower($natent['interface']) == "lan")
238
				echo "LAN";
239
			else
240
				echo strtoupper($config['interfaces'][$natent['interface']]['descr']);
241
		    ?>
242
                  </td>
243
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
244
                    <?=strtoupper($natent['protocol']);?>
245
                  </td>
246
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
247
                    <?php
248
						list($beginport, $endport) = split("-", $natent['external-port']);
249
						if ((!$endport) || ($beginport == $endport)) {
250
							echo $alias_src_port_span_begin;
251
				  			echo $beginport;
252
							if ($wkports[$beginport])
253
								echo " (" . $wkports[$beginport] . ")";
254
							else
255
								echo "&nbsp;";
256
							echo $span_end;
257
						} else
258
							echo $beginport . " - " . $endport;
259
				  ?>
260
                  </td>
261
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
262
                    <?php echo $alias_dst_span_begin;?><?=$natent['target'];?><?php echo $span_end;?>
263
					<?php if ($natent['external-address'])
264
						echo "<br>(ext.: " . $natent['external-address'] . ")";
265
					      else
266
						echo "<br>(ext.: " . find_interface_ip(convert_friendly_interface_to_real_interface_name($natent['interface'])) . ")";
267
					?>
268
                  </td>
269
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
270
                    <?php if ((!$endport) || ($beginport == $endport)) {
271
				  			echo $alias_dst_port_span_begin;
272
                    		echo $natent['local-port'];
273
							if ($wkports[$natent['local-port']])
274
								echo " (" . $wkports[$natent['local-port']] . ")";
275
							else
276
								echo "&nbsp;";
277
							echo $span_end;
278
						} else
279
							echo $natent['local-port'] . " - " .
280
								($natent['local-port']+$endport-$beginport);
281
				  ?>
282
                  </td>
283
                  <td class="listbg" onClick="fr_toggle(<?=$nnats;?>)" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
284
                    <?=htmlspecialchars($natent['descr']);?>&nbsp;
285
                  </td>
286
                  <td valign="middle" class="list" nowrap>
287
                    <table border="0" cellspacing="0" cellpadding="1">
288
                      <tr>
289
                        <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>
290
                      </tr>
291
                      <tr>
292
                        <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>
293
                        <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>
294
                      </tr>
295
                    </table>
296
		</tr>
297
  	     <?php $i++; $nnats++; endforeach; ?>
298
                <tr>
299
                  <td class="list" colspan="8"></td>
300
                  <td class="list" valign="middle" nowrap>
301
                    <table border="0" cellspacing="0" cellpadding="1">
302
                      <tr>
303
                        <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>
304
                        <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>
305
                      </tr>
306
                      <tr>
307
                        <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>
308
                      </tr>
309
                    </table>
310
		  </td>
311
                </tr>
312
	</table>
313
	</div>
314
	</td>
315
  </tr>
316
</table>
317

    
318
<?php
319
if ($pkg['tabs'] <> "") {
320
    echo "</td></tr></table>";
321
}
322
?>
323

    
324
</form>
325
<?php include("fend.inc"); ?>
326
</body>
327
</html>
(51-51/217)