Project

General

Profile

Download (16.9 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
require_once("functions.inc");
46
require_once("filter.inc");
47
require_once("shaper.inc");
48
require_once("itemid.inc");
49

    
50
if (!is_array($config['nat']['rule']))
51
	$config['nat']['rule'] = array();
52

    
53
$a_nat = &$config['nat']['rule'];
54

    
55
/* if a custom message has been passed along, lets process it */
56
if ($_GET['savemsg'])
57
	$savemsg = $_GET['savemsg'];
58

    
59
if ($_POST) {
60

    
61
	$pconfig = $_POST;
62

    
63
	if ($_POST['apply']) {
64

    
65
		write_config();
66

    
67
		$retval = 0;
68

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

    
73
		if ($retval == 0) {
74
			clear_subsystem_dirty('natconf');
75
			clear_subsystem_dirty('filter');
76
		}
77

    
78
	}
79
}
80

    
81
if ($_GET['act'] == "del") {
82
	if ($a_nat[$_GET['id']]) {
83
		if (isset($a_nat[$_GET['id']]['associated-rule-id'])) {
84
			delete_id($a_nat[$_GET['id']]['associated-rule-id'], $config['filter']['rule']);
85
			mark_subsystem_dirty('filter');
86
		}
87
		unset($a_nat[$_GET['id']]);
88
		write_config();
89
		mark_subsystem_dirty('natconf');
90
		header("Location: firewall_nat.php");
91
		exit;
92
	}
93
}
94

    
95
if (isset($_POST['del_x'])) {
96
    /* delete selected rules */
97
    if (is_array($_POST['rule']) && count($_POST['rule'])) {
98
	    foreach ($_POST['rule'] as $rulei) {
99
		$target = $rule['target'];
100
			// Check for filter rule associations
101
			if (isset($a_nat[$rulei]['associated-rule-id'])){
102
				delete_id($a_nat[$rulei]['associated-rule-id'], $config['filter']['rule']);
103
				
104
				mark_subsystem_dirty('filter');
105
			}
106
	        unset($a_nat[$rulei]);
107
	    }
108
	    write_config();
109
	    mark_subsystem_dirty('natconf');
110
	    header("Location: firewall_nat.php");
111
	    exit;
112
	}
113

    
114
} else {
115
        /* yuck - IE won't send value attributes for image buttons, while Mozilla does - so we use .x/.y to find move button clicks instead... */
116
        unset($movebtn);
117
        foreach ($_POST as $pn => $pd) {
118
                if (preg_match("/move_(\d+)_x/", $pn, $matches)) {
119
                        $movebtn = $matches[1];
120
                        break;
121
                }
122
        }
123
        /* move selected rules before this rule */
124
        if (isset($movebtn) && is_array($_POST['rule']) && count($_POST['rule'])) {
125
                $a_nat_new = array();
126

    
127
                /* copy all rules < $movebtn and not selected */
128
                for ($i = 0; $i < $movebtn; $i++) {
129
                        if (!in_array($i, $_POST['rule']))
130
                                $a_nat_new[] = $a_nat[$i];
131
                }
132

    
133
                /* copy all selected rules */
134
                for ($i = 0; $i < count($a_nat); $i++) {
135
                        if ($i == $movebtn)
136
                                continue;
137
                        if (in_array($i, $_POST['rule']))
138
                                $a_nat_new[] = $a_nat[$i];
139
                }
140

    
141
                /* copy $movebtn rule */
142
                if ($movebtn < count($a_nat))
143
                        $a_nat_new[] = $a_nat[$movebtn];
144

    
145
                /* copy all rules > $movebtn and not selected */
146
                for ($i = $movebtn+1; $i < count($a_nat); $i++) {
147
                        if (!in_array($i, $_POST['rule']))
148
                                $a_nat_new[] = $a_nat[$i];
149
                }
150
                $a_nat = $a_nat_new;
151
                write_config();
152
		mark_subsystem_dirty('natconf');
153
                header("Location: firewall_nat.php");
154
                exit;
155
        }
156
}
157

    
158
$pgtitle = array(gettext("Firewall"),gettext("NAT"),gettext("Port Forward"));
159
include("head.inc");
160

    
161
echo "<script type=\"text/javascript\" language=\"javascript\" src=\"/javascript/domTT/domLib.js\"></script>";
162
echo "<script type=\"text/javascript\" language=\"javascript\" src=\"/javascript/domTT/domTT.js\"></script>";
163
echo "<script type=\"text/javascript\" language=\"javascript\" src=\"/javascript/domTT/behaviour.js\"></script>";
164
echo "<script type=\"text/javascript\" language=\"javascript\" src=\"/javascript/domTT/fadomatic.js\"></script>";
165

    
166
?>
167
<body link="#000000" vlink="#000000" alink="#000000">
168
<?php include("fbegin.inc"); ?>
169
<form action="firewall_nat.php" method="post" name="iform">
170
<script type="text/javascript" language="javascript" src="/javascript/row_toggle.js"></script>
171
<?php if ($savemsg) print_info_box($savemsg); ?>
172
<?php if (is_subsystem_dirty('natconf')): ?><p>
173
<?php print_info_box_np(gettext("The NAT configuration has been changed") . ".<br>" . gettext("You must apply the changes in order for them to take effect."));?><br>
174
<?php endif; ?>
175
<table width="100%" border="0" cellpadding="0" cellspacing="0">
176
  <tr><td>
177
<?php
178
	$tab_array = array();
179
	$tab_array[] = array(gettext("Port Forward"), true, "firewall_nat.php");
180
	$tab_array[] = array(gettext("1:1"), false, "firewall_nat_1to1.php");
181
	$tab_array[] = array(gettext("Outbound"), false, "firewall_nat_out.php");
182
	$tab_array[] = array(gettext("NPt"), false, "firewall_nat_npt.php");
183
	display_top_tabs($tab_array);
184
?>
185
 </td></tr>
186
  <tr>
187
    <td>
188
	<div id="mainarea">
189
              <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
190
                <tr id="frheader">
191
		  <td width="3%" class="list">&nbsp;</td>
192
                  <td width="3%" class="list">&nbsp;</td>
193
		  <td width="5%" class="listhdrr"><?=gettext("If");?></td>
194
		  <td width="5%" class="listhdrr"><?=gettext("Proto");?></td>
195
		  <td width="11%" class="listhdrr"><nobr><?=gettext("Src. addr");?></nobr></td>
196
		  <td width="11%" class="listhdrr"><nobr><?=gettext("Src. ports");?></nobr></td>
197
		  <td width="11%" class="listhdrr"><nobr><?=gettext("Dest. addr");?></nobr></td>
198
		  <td width="11%" class="listhdrr"><nobr><?=gettext("Dest. ports");?></nobr></td>
199
		  <td width="11%" class="listhdrr"><nobr><?=gettext("NAT IP");?></nobr></td>
200
		  <td width="11%" class="listhdrr"><nobr><?=gettext("NAT Ports");?></nobr></td>
201
		  <td width="11%" class="listhdr"><?=gettext("Description");?></td>
202
                  <td width="5%" class="list">
203
                    <table border="0" cellspacing="0" cellpadding="1">
204
                      <tr>
205
			<td width="17">
206
			<?php if (count($a_nat) == 0): ?>
207
				<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x_d.gif" width="17" height="17" title="<?=gettext("delete selected rules");?>" border="0">
208
			<?php else: ?>
209
				<input name="del" type="image" src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" title="<?=gettext("delete selected rules"); ?>" onclick="return confirm('<?=gettext("Do you really want to delete the selected rules?");?>')">
210
			<?php endif; ?>
211
			</td>
212
                        <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>
213
                      </tr>
214
                    </table>
215
		  </td>
216
		</tr>
217
	<?php $nnats = $i = 0; foreach ($a_nat as $natent): ?>
218
	<?php 
219
	
220
		//build Alias popup box
221
		$span_end = "</U></span>";
222

    
223
		$alias_popup = rule_popup($natent['source']['address'], pprint_port($natent['source']['port']), $natent['destination']['address'], pprint_port($natent['destination']['port']));
224

    
225
		$alias_src_span_begin      = $alias_popup["src"];
226
		$alias_src_port_span_begin = $alias_popup["srcport"];
227
		$alias_dst_span_begin      = $alias_popup["dst"];
228
		$alias_dst_port_span_begin = $alias_popup["dstport"];
229

    
230
		$alias_popup = rule_popup("","",$natent['target'], pprint_port($natent['local-port']));
231

    
232
		$alias_target_span_begin     = $alias_popup["dst"];
233
		$alias_local_port_span_begin = $alias_popup["dstport"];
234

    
235
		if (isset($natent['disabled']))
236
			$textss = "<span class=\"gray\">";
237
		else
238
			$textss = "<span>";
239

    
240
		$textse = "</span>";
241
	
242
		/* if user does not have access to edit an interface skip on to the next record */
243
		if(!have_natpfruleint_access($natent['interface'])) 
244
			continue;
245
	?>
246
                <tr valign="top" id="fr<?=$nnats;?>">
247
                  <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>
248
                  <td class="listt" align="center">
249
					<?php if($natent['associated-rule-id'] == "pass"): ?>
250
					<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_pass.gif" title="<?=gettext("All traffic matching this NAT entry is passed"); ?>" border="0">
251
					<?php elseif (!empty($natent['associated-rule-id'])): ?>
252
					<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_chain.png" width="17" height="17" title="<?=gettext("Firewall rule ID"); ?> <?=htmlspecialchars($nnatid); ?> <?=gettext("is managed with this rule"); ?>" border="0">
253
					<?php endif; ?>
254
				  </td>
255
                  <td class="listlr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
256
                    <?=$textss;?>
257
		    <?php
258
			if (!$natent['interface'])
259
				echo htmlspecialchars(convert_friendly_interface_to_friendly_descr("wan"));
260
			else
261
				echo htmlspecialchars(convert_friendly_interface_to_friendly_descr($natent['interface']));
262
		    ?>
263
                    <?=$textse;?>
264
                  </td>
265

    
266
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
267
					<?=$textss;?><?=strtoupper($natent['protocol']);?><?=$textse;?>
268
                  </td>
269

    
270
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
271
				    <?=$textss;?><?php echo $alias_src_span_begin;?><?php echo htmlspecialchars(pprint_address($natent['source']));?><?php echo $alias_src_span_end;?><?=$textse;?>
272
                  </td>
273
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
274
				    <?=$textss;?><?php echo $alias_src_port_span_begin;?><?php echo htmlspecialchars(pprint_port($natent['source']['port']));?><?php echo $alias_src_port_span_end;?><?=$textse;?>
275
                  </td>
276

    
277
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
278
				    <?=$textss;?><?php echo $alias_dst_span_begin;?><?php echo htmlspecialchars(pprint_address($natent['destination']));?><?php echo $alias_dst_span_end;?><?=$textse;?>
279
                  </td>
280
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
281
				    <?=$textss;?><?php echo $alias_dst_port_span_begin;?><?php echo htmlspecialchars(pprint_port($natent['destination']['port']));?><?php echo $alias_dst_port_span_end;?><?=$textse;?>
282
                  </td>
283

    
284
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
285
				    <?=$textss;?><?php echo $alias_target_span_begin;?><?php echo htmlspecialchars($natent['target']);?><?php echo $alias_target_span_end;?><?=$textse;?>
286
                  </td>
287
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
288
					<?php
289
						$localport = $natent['local-port'];
290

    
291
						list($dstbeginport, $dstendport) = split("-", $natent['destination']['port']);
292

    
293
						if ($dstendport) {
294
							$localendport = $natent['local-port'] + $dstendport - $dstbeginport;
295
							$localport   .= '-' . $localendport;
296
						}
297
					?>
298
				    <?=$textss;?><?php echo $alias_local_port_span_begin;?><?php echo htmlspecialchars(pprint_port($localport));?><?php echo $alias_local_port_span_end;?><?=$textse;?>
299
                  </td>
300

    
301
                  <td class="listbg" onClick="fr_toggle(<?=$nnats;?>)" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
302
				  <?=$textss;?><?=htmlspecialchars($natent['descr']);?>&nbsp;<?=$textse;?>
303
                  </td>
304
                  <td valign="middle" class="list" nowrap>
305
                    <table border="0" cellspacing="0" cellpadding="1">
306
                      <tr>
307
			<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="<?=gettext("move selected rules before this rule");?>" height="17" type="image" width="17" border="0"></td>
308
                        <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="<?=gettext("edit rule"); ?>"></a></td>
309
                      </tr>
310
                      <tr>
311
					    <td align="center" valign="middle"><a href="firewall_nat.php?act=del&id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this rule?");?>')"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0" title="<?=gettext("delete rule");?>"></a></td>
312
			<td><a href="firewall_nat_edit.php?dup=<?=$i;?>"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="<?=gettext("add a new nat based on this one");?>" width="17" height="17" border="0"></a></td>
313
                      </tr>
314
                    </table>
315
		</tr>
316
  	     <?php $i++; $nnats++; endforeach; ?>
317
                <tr>
318
                  <td class="list" colspan="8"></td>
319
                  <td>&nbsp;</td>
320
                  <td>&nbsp;</td>
321
                  <td>&nbsp;</td>
322
                  <td class="list" valign="middle" nowrap>
323
                    <table border="0" cellspacing="0" cellpadding="1">
324
                      <tr>
325
			<td><?php if ($nnats == 0): ?><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_left_d.gif" width="17" height="17" title="<?=gettext("move selected rules 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="<?=gettext("move selected rules to end");?>" border="0"><?php endif; ?></td>
326
                      </tr>
327
                      <tr>
328
			<td width="17">
329
			<?php if (count($a_nat) == 0): ?>
330
				<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x_d.gif" width="17" height="17" title="<?=gettext("delete selected rules");?>" border="0">
331
			<?php else: ?>
332
				<input name="del" type="image" src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" title="<?=gettext("delete selected rules"); ?>" onclick="return confirm('<?=gettext("Do you really want to delete the selected rules?");?>')">
333
			<?php endif; ?>
334
			</td>
335
                        <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>
336
                      </tr>
337
                    </table>
338
		  </td>
339
		</tr>
340
		<tr><td>&nbsp;</td></tr>
341
          <tr>
342
            <td width="16"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_pass.gif" width="11" height="11"></td>
343
            <td colspan="3"><?=gettext("pass"); ?></td>
344
			</tr>
345
		   <tr>
346
            <td width="14"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_chain.png" width="11" height="11"></td>
347
	    <td colspan="3"><?=gettext("linked rule");?></td>
348
          </tr>
349
    </table>
350
	</div>
351
	</td>
352
  </tr>
353
</table>
354

    
355
<?php
356
if ($pkg['tabs'] <> "") {
357
    echo "</td></tr></table>";
358
}
359
?>
360

    
361
</form>
362
<?php include("fend.inc"); ?>
363
</body>
364
</html>
(55-55/232)