Project

General

Profile

Download (16.6 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
		if(stristr($retval, "error") <> true)
70
		    $savemsg = get_std_save_message($retval);
71
		else
72
		    $savemsg = $retval;
73

    
74
		unlink_if_exists("/tmp/config.cache");
75
		$retval |= filter_configure();
76

    
77
		if ($retval == 0) {
78
			clear_subsystem_dirty('natconf');
79
			clear_subsystem_dirty('filter');
80
		}
81

    
82
	}
83
}
84

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

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

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

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

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

    
144
                /* copy $movebtn rule */
145
                if ($movebtn < count($a_nat))
146
                        $a_nat_new[] = $a_nat[$movebtn];
147

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

    
161
$pgtitle = array("Firewall","NAT","Port Forward");
162
include("head.inc");
163

    
164
echo "<script type=\"text/javascript\" language=\"javascript\" src=\"/javascript/domTT/domLib.js\"></script>";
165
echo "<script type=\"text/javascript\" language=\"javascript\" src=\"/javascript/domTT/domTT.js\"></script>";
166
echo "<script type=\"text/javascript\" language=\"javascript\" src=\"/javascript/domTT/behaviour.js\"></script>";
167
echo "<script type=\"text/javascript\" language=\"javascript\" src=\"/javascript/domTT/fadomatic.js\"></script>";
168

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

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

    
231
		$alias_src_span_begin      = $alias_popup["src"];
232
		$alias_src_port_span_begin = $alias_popup["srcport"];
233
		$alias_dst_span_begin      = $alias_popup["dst"];
234
		$alias_dst_port_span_begin = $alias_popup["dstport"];
235

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

    
238
		$alias_target_span_begin     = $alias_popup["dst"];
239
		$alias_local_port_span_begin = $alias_popup["dstport"];
240

    
241
		if (isset($natent['disabled']))
242
			$textss = "<span class=\"gray\">";
243
		else
244
			$textss = "<span>";
245

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

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

    
278
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
279
				    <?=$textss;?><?php echo $alias_src_span_begin;?><?php echo htmlspecialchars(pprint_address($natent['source']));?><?php echo $alias_src_span_end;?><?=$textse;?>
280
                  </td>
281
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
282
				    <?=$textss;?><?php echo $alias_src_port_span_begin;?><?php echo htmlspecialchars(pprint_port($natent['source']['port']));?><?php echo $alias_src_port_span_end;?><?=$textse;?>
283
                  </td>
284

    
285
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
286
				    <?=$textss;?><?php echo $alias_dst_span_begin;?><?php echo htmlspecialchars(pprint_address($natent['destination']));?><?php echo $alias_dst_span_end;?><?=$textse;?>
287
                  </td>
288
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
289
				    <?=$textss;?><?php echo $alias_dst_port_span_begin;?><?php echo htmlspecialchars(pprint_port($natent['destination']['port']));?><?php echo $alias_dst_port_span_end;?><?=$textse;?>
290
                  </td>
291

    
292
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
293
				    <?=$textss;?><?php echo $alias_target_span_begin;?><?php echo htmlspecialchars($natent['target']);?><?php echo $alias_target_span_end;?><?=$textse;?>
294
                  </td>
295
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
296
					<?php
297
						$localport = $natent['local-port'];
298

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

    
301
						if ($dstendport) {
302
							$localendport = $natent['local-port'] + $dstendport - $dstbeginport;
303
							$localport   .= '-' . $localendport;
304
						}
305
					?>
306
				    <?=$textss;?><?php echo $alias_local_port_span_begin;?><?php echo htmlspecialchars(pprint_port($localport));?><?php echo $alias_local_port_span_end;?><?=$textse;?>
307
                  </td>
308

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

    
363
<?php
364
if ($pkg['tabs'] <> "") {
365
    echo "</td></tr></table>";
366
}
367
?>
368

    
369
</form>
370
<?php include("fend.inc"); ?>
371
</body>
372
</html>
(50-50/221)