Project

General

Profile

Download (17.5 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	firewall_nat.php
5
	Copyright (C) 2004 Scott Ullrich
6
        Copyright (C) 2013-2014 Electric Sheep Fencing, LP
7
	All rights reserved.
8

    
9
	originally part of m0n0wall (http://m0n0.ch/wall)
10
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
11
	All rights reserved.
12

    
13
	Redistribution and use in source and binary forms, with or without
14
	modification, are permitted provided that the following conditions are met:
15

    
16
	1. Redistributions of source code must retain the above copyright notice,
17
	   this list of conditions and the following disclaimer.
18

    
19
	2. Redistributions in binary form must reproduce the above copyright
20
	   notice, this list of conditions and the following disclaimer in the
21
	   documentation and/or other materials provided with the distribution.
22

    
23
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
24
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
25
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
27
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
	POSSIBILITY OF SUCH DAMAGE.
33
*/
34
/*
35
	pfSense_MODULE:	nat
36
*/
37

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

    
45
require("guiconfig.inc");
46
require_once("functions.inc");
47
require_once("filter.inc");
48
require_once("shaper.inc");
49
require_once("itemid.inc");
50

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

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

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

    
60
if ($_POST) {
61

    
62
	$pconfig = $_POST;
63

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

    
66
		write_config();
67

    
68
		$retval = 0;
69

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

    
74
		pfSense_handle_custom_code("/usr/local/pkg/firewall_nat/apply");
75

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

    
81
	}
82
}
83

    
84
if ($_GET['act'] == "del") {
85
	if ($a_nat[$_GET['id']]) {
86

    
87
		if (isset($a_nat[$_GET['id']]['associated-rule-id'])) {
88
			delete_id($a_nat[$_GET['id']]['associated-rule-id'], $config['filter']['rule']);
89
			$want_dirty_filter = true;
90
		}
91
		unset($a_nat[$_GET['id']]);
92

    
93
		if (write_config()) {
94
			mark_subsystem_dirty('natconf');
95
			if ($want_dirty_filter)
96
				mark_subsystem_dirty('filter');
97
		}
98
		header("Location: firewall_nat.php");
99
		exit;
100
	}
101
}
102

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

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

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

    
141
                /* copy all selected rules */
142
                for ($i = 0; $i < count($a_nat); $i++) {
143
                        if ($i == $movebtn)
144
                                continue;
145
                        if (in_array($i, $_POST['rule']))
146
                                $a_nat_new[] = $a_nat[$i];
147
                }
148

    
149
                /* copy $movebtn rule */
150
                if ($movebtn < count($a_nat))
151
                        $a_nat_new[] = $a_nat[$movebtn];
152

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

    
166
$closehead = false;
167
$pgtitle = array(gettext("Firewall"),gettext("NAT"),gettext("Port Forward"));
168
include("head.inc");
169

    
170
echo "<script type=\"text/javascript\" src=\"/javascript/domTT/domLib.js\"></script>";
171
echo "<script type=\"text/javascript\" src=\"/javascript/domTT/domTT.js\"></script>";
172
echo "<script type=\"text/javascript\" src=\"/javascript/domTT/behaviour.js\"></script>";
173
echo "<script type=\"text/javascript\" src=\"/javascript/domTT/fadomatic.js\"></script>";
174

    
175
?>
176
</head>
177

    
178
<body link="#000000" vlink="#000000" alink="#000000">
179
<?php include("fbegin.inc"); ?>
180
<form action="firewall_nat.php" method="post" name="iform">
181
<script type="text/javascript" src="/javascript/row_toggle.js"></script>
182
<?php if ($savemsg) print_info_box($savemsg); ?>
183
<?php if (is_subsystem_dirty('natconf')): ?>
184
<?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 />
185
<?php endif; ?>
186
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="firewall nat">
187
  <tr><td>
188
<?php
189
	$tab_array = array();
190
	$tab_array[] = array(gettext("Port Forward"), true, "firewall_nat.php");
191
	$tab_array[] = array(gettext("1:1"), false, "firewall_nat_1to1.php");
192
	$tab_array[] = array(gettext("Outbound"), false, "firewall_nat_out.php");
193
	$tab_array[] = array(gettext("NPt"), false, "firewall_nat_npt.php");
194
	display_top_tabs($tab_array);
195
?>
196
 </td></tr>
197
  <tr>
198
    <td>
199
	<div id="mainarea">
200
              <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="main area">
201
                <tr id="frheader">
202
		  <td width="3%" class="list">&nbsp;</td>
203
                  <td width="3%" class="list">&nbsp;</td>
204
		  <td width="5%" class="listhdrr"><?=gettext("If");?></td>
205
		  <td width="5%" class="listhdrr"><?=gettext("Proto");?></td>
206
		  <td width="11%" class="listhdrr nowrap"><?=gettext("Src. addr");?></td>
207
		  <td width="11%" class="listhdrr nowrap"><?=gettext("Src. ports");?></td>
208
		  <td width="11%" class="listhdrr nowrap"><?=gettext("Dest. addr");?></td>
209
		  <td width="11%" class="listhdrr nowrap"><?=gettext("Dest. ports");?></td>
210
		  <td width="11%" class="listhdrr nowrap"><?=gettext("NAT IP");?></td>
211
		  <td width="11%" class="listhdrr nowrap"><?=gettext("NAT Ports");?></td>
212
		  <td width="11%" class="listhdr"><?=gettext("Description");?></td>
213
                  <td width="5%" class="list">
214
                    <table border="0" cellspacing="0" cellpadding="1" summary="list">
215
                      <tr>
216
			<td width="17">
217
			<?php if (count($a_nat) == 0): ?>
218
				<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x_d.gif" width="17" height="17" title="<?=gettext("delete selected rules");?>" border="0" alt="delete" />
219
			<?php else: ?>
220
				<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?");?>')" />
221
			<?php endif; ?>
222
			</td>
223
                        <td><a href="firewall_nat_edit.php?after=-1"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" alt="add" /></a></td>
224
                      </tr>
225
                    </table>
226
		  </td>
227
		</tr>
228
	<?php $nnats = $i = 0; foreach ($a_nat as $natent): ?>
229
	<?php 
230
	
231
		//build Alias popup box
232
		$span_end = "</U></span>";
233

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

    
236
		$alias_src_span_begin      = $alias_popup["src"];
237
		$alias_src_port_span_begin = $alias_popup["srcport"];
238
		$alias_dst_span_begin      = $alias_popup["dst"];
239
		$alias_dst_port_span_begin = $alias_popup["dstport"];
240

    
241
		$alias_src_span_end        = $alias_popup["src_end"];
242
		$alias_src_port_span_end   = $alias_popup["srcport_end"];
243
		$alias_dst_span_end        = $alias_popup["dst_end"];
244
		$alias_dst_port_span_end   = $alias_popup["dstport_end"];
245

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

    
248
		$alias_target_span_begin     = $alias_popup["dst"];
249
		$alias_local_port_span_begin = $alias_popup["dstport"];
250

    
251
		$alias_target_span_end       = $alias_popup["dst_end"];
252
		$alias_local_port_span_end   = $alias_popup["dstport_end"];
253

    
254
		if (isset($natent['disabled']))
255
			$textss = "<span class=\"gray\">";
256
		else
257
			$textss = "<span>";
258

    
259
		$textse = "</span>";
260
	
261
		/* if user does not have access to edit an interface skip on to the next record */
262
		if(!have_natpfruleint_access($natent['interface'])) 
263
			continue;
264
	?>
265
                <tr valign="top" id="fr<?=$nnats;?>">
266
                  <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>
267
                  <td class="listt" align="center">
268
					<?php if($natent['associated-rule-id'] == "pass"): ?>
269
					<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_pass.gif" title="<?=gettext("All traffic matching this NAT entry is passed"); ?>" border="0" alt="pass" />
270
					<?php elseif (!empty($natent['associated-rule-id'])): ?>
271
					<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" alt="change" />
272
					<?php endif; ?>
273
				  </td>
274
                  <td class="listlr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
275
                    <?=$textss;?>
276
		    <?php
277
			if (!$natent['interface'])
278
				echo htmlspecialchars(convert_friendly_interface_to_friendly_descr("wan"));
279
			else
280
				echo htmlspecialchars(convert_friendly_interface_to_friendly_descr($natent['interface']));
281
		    ?>
282
                    <?=$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;?><?=strtoupper($natent['protocol']);?><?=$textse;?>
287
                  </td>
288

    
289
                  <td class="listr" onclick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
290
				    <?=$textss;?><?php echo $alias_src_span_begin;?><?php echo htmlspecialchars(pprint_address($natent['source']));?><?php echo $alias_src_span_end;?><?=$textse;?>
291
                  </td>
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_src_port_span_begin;?><?php echo htmlspecialchars(pprint_port($natent['source']['port']));?><?php echo $alias_src_port_span_end;?><?=$textse;?>
294
                  </td>
295

    
296
                  <td class="listr" onclick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
297
				    <?=$textss;?><?php echo $alias_dst_span_begin;?><?php echo htmlspecialchars(pprint_address($natent['destination']));?><?php echo $alias_dst_span_end;?><?=$textse;?>
298
                  </td>
299
                  <td class="listr" onclick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
300
				    <?=$textss;?><?php echo $alias_dst_port_span_begin;?><?php echo htmlspecialchars(pprint_port($natent['destination']['port']));?><?php echo $alias_dst_port_span_end;?><?=$textse;?>
301
                  </td>
302

    
303
                  <td class="listr" onclick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
304
				    <?=$textss;?><?php echo $alias_target_span_begin;?><?php echo htmlspecialchars($natent['target']);?><?php echo $alias_target_span_end;?><?=$textse;?>
305
                  </td>
306
                  <td class="listr" onclick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
307
					<?php
308
						$localport = $natent['local-port'];
309

    
310
						list($dstbeginport, $dstendport) = explode("-", $natent['destination']['port']);
311

    
312
						if ($dstendport) {
313
							$localendport = $natent['local-port'] + $dstendport - $dstbeginport;
314
							$localport   .= '-' . $localendport;
315
						}
316
					?>
317
				    <?=$textss;?><?php echo $alias_local_port_span_begin;?><?php echo htmlspecialchars(pprint_port($localport));?><?php echo $alias_local_port_span_end;?><?=$textse;?>
318
                  </td>
319

    
320
                  <td class="listbg" onclick="fr_toggle(<?=$nnats;?>)" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
321
				  <?=$textss;?><?=htmlspecialchars($natent['descr']);?>&nbsp;<?=$textse;?>
322
                  </td>
323
                  <td valign="middle" class="list nowrap">
324
                    <table border="0" cellspacing="0" cellpadding="1" summary="move">
325
                      <tr>
326
			<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>
327
                        <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>
328
                      </tr>
329
                      <tr>
330
					    <td align="center" valign="middle"><a href="firewall_nat.php?act=del&amp;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");?>" alt="delete" /></a></td>
331
			<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" alt="add" /></a></td>
332
                      </tr>
333
                    </table>
334
		</tr>
335
  	     <?php $i++; $nnats++; endforeach; ?>
336
                <tr>
337
                  <td class="list" colspan="8"></td>
338
                  <td>&nbsp;</td>
339
                  <td>&nbsp;</td>
340
                  <td>&nbsp;</td>
341
                  <td class="list nowrap" valign="middle">
342
                    <table border="0" cellspacing="0" cellpadding="1" summary="move">
343
                      <tr>
344
			<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" alt="move" /><?php else: ?><input name="move_<?=$i;?>" type="image" src="/themes/<?= $g['theme']; ?>/images/icons/icon_left.gif" style="width:17;height:17;border:0" title="<?=gettext("move selected rules to end");?>" /><?php endif; ?></td>
345
                      </tr>
346
                      <tr>
347
			<td width="17">
348
			<?php if (count($a_nat) == 0): ?>
349
				<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x_d.gif" width="17" height="17" title="<?=gettext("delete selected rules");?>" border="0" alt="delete" />
350
			<?php else: ?>
351
				<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?");?>')" />
352
			<?php endif; ?>
353
			</td>
354
                        <td><a href="firewall_nat_edit.php"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" alt="add" /></a></td>
355
                      </tr>
356
                    </table>
357
		  </td>
358
		</tr>
359
		<tr><td>&nbsp;</td></tr>
360
          <tr>
361
            <td width="16"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_pass.gif" width="11" height="11" alt="pass" /></td>
362
            <td colspan="3"><?=gettext("pass"); ?></td>
363
			</tr>
364
		   <tr>
365
            <td width="14"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_chain.png" width="11" height="11" alt="chain" /></td>
366
	    <td colspan="3"><?=gettext("linked rule");?></td>
367
          </tr>
368
    </table>
369
	</div>
370
	</td>
371
  </tr>
372
</table>
373

    
374
<?php
375
if ($pkg['tabs'] <> "") {
376
    echo "</td></tr></table>";
377
}
378
?>
379

    
380
</form>
381
<?php include("fend.inc"); ?>
382
</body>
383
</html>
(63-63/256)