Project

General

Profile

Download (12.1 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	firewall_nat_1to1.php
5
	part of m0n0wall (http://m0n0.ch/wall)
6

    
7
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
8
	All rights reserved.
9

    
10
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
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-1-1
39
##|*NAME=Firewall: NAT: 1:1 page
40
##|*DESCR=Allow access to the 'Firewall: NAT: 1:1' page.
41
##|*MATCH=firewall_nat_1to1.php*
42
##|-PRIV
43

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

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

    
52
$a_1to1 = &$config['nat']['onetoone'];
53

    
54
if ($_POST) {
55
	$pconfig = $_POST;
56

    
57
	if ($_POST['apply']) {
58
		$retval = 0;
59
		$retval |= filter_configure();
60
		$savemsg = get_std_save_message($retval);
61

    
62
		if ($retval == 0) {
63
			clear_subsystem_dirty('natconf');
64
			clear_subsystem_dirty('filter');
65
		}
66
	}
67
}
68

    
69
if ($_GET['act'] == "del") {
70
	if ($a_1to1[$_GET['id']]) {
71
		unset($a_1to1[$_GET['id']]);
72
		if (write_config())
73
			mark_subsystem_dirty('natconf');
74
		header("Location: firewall_nat_1to1.php");
75
		exit;
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
			unset($a_1to1[$rulei]);
84
		}
85
		if (write_config())
86
			mark_subsystem_dirty('natconf');
87
		header("Location: firewall_nat_1to1.php");
88
		exit;
89
	}
90

    
91
} else if ($_GET['act'] == "toggle") {
92
	if ($a_1to1[$_GET['id']]) {
93
		if(isset($a_1to1[$_GET['id']]['disabled']))
94
			unset($a_1to1[$_GET['id']]['disabled']);
95
		else
96
			$a_1to1[$_GET['id']]['disabled'] = true;
97
		if (write_config("Firewall: NAT: Outbound, enable/disable NAT rule"))
98
			mark_subsystem_dirty('natconf');
99
		header("Location: firewall_nat_1to1.php");
100
		exit;
101
	}
102
} else {
103
	/* yuck - IE won't send value attributes for image buttons, while Mozilla does - so we use .x/.y to find move button clicks instead... */
104
	unset($movebtn);
105
	foreach ($_POST as $pn => $pd) {
106
		if (preg_match("/move_(\d+)_x/", $pn, $matches)) {
107
			$movebtn = $matches[1];
108
			break;
109
		}
110
	}
111
	/* move selected rules before this rule */
112
	if (isset($movebtn) && is_array($_POST['rule']) && count($_POST['rule'])) {
113
		$a_1to1_new = array();
114

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

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

    
129
		/* copy $movebtn rule */
130
		if ($movebtn < count($a_1to1))
131
			$a_1to1_new[] = $a_1to1[$movebtn];
132

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

    
141
		if (write_config())
142
			mark_subsystem_dirty('natconf');
143
		header("Location: firewall_nat_1to1.php");
144
		exit;
145
	}
146
}
147

    
148
$pgtitle = array(gettext("Firewall"),gettext("NAT"),gettext("1:1"));
149
include("head.inc");
150

    
151
?>
152
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
153
<?php include("fbegin.inc"); ?>
154
<form action="firewall_nat_1to1.php" method="post">
155
<script type="text/javascript" src="/javascript/row_toggle.js"></script>
156
<?php
157
if ($savemsg)
158
	print_info_box($savemsg);
159
if (is_subsystem_dirty('natconf'))
160
	print_info_box_np(gettext("The NAT configuration has been changed.") .
161
		"<br />" .
162
		gettext("You must apply the changes in order for them to take effect."));
163
?>
164
<br />
165
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="firewall nat 1to1">
166
	<tr><td>
167
<?php
168
		$tab_array = array();
169
		$tab_array[] = array(gettext("Port Forward"), false, "firewall_nat.php");
170
		$tab_array[] = array(gettext("1:1"), true, "firewall_nat_1to1.php");
171
		$tab_array[] = array(gettext("Outbound"), false, "firewall_nat_out.php");
172
		$tab_array[] = array(gettext("NPt"), false, "firewall_nat_npt.php");
173
		display_top_tabs($tab_array);
174
?>
175
	</td></tr>
176
	<tr><td>
177
		<div id="mainarea">
178
		<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="main area">
179
			<tr id="frheader">
180
				<td width="3%" class="list">&nbsp;</td>
181
				<td width="3%" class="list">&nbsp;</td>
182
				<td width="10%" class="listhdrr"><?=gettext("Interface"); ?></td>
183
				<td width="15%" class="listhdrr"><?=gettext("External IP"); ?></td>
184
				<td width="15%" class="listhdrr"><?=gettext("Internal IP"); ?></td>
185
				<td width="15%" class="listhdrr"><?=gettext("Destination IP"); ?></td>
186
				<td width="29%" class="listhdr"><?=gettext("Description"); ?></td>
187
				<td width="10%" class="list">
188
					<table border="0" cellspacing="0" cellpadding="1" summary="edit">
189
						<tr>
190
							<td width="17"></td>
191
							<td valign="middle">
192
								<a href="firewall_nat_1to1_edit.php">
193
									<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" title="<?=gettext("add rule"); ?>" alt="add" />
194
								</a>
195
							</td>
196
						</tr>
197
					</table>
198
				</td>
199
			</tr>
200
<?php
201
		$textse = "</span>";
202
		$i = 0;
203
		foreach ($a_1to1 as $natent):
204
			if (isset($natent['disabled'])) {
205
				$textss = "<span class=\"gray\">";
206
				$iconfn = "pass_d";
207
			} else {
208
				$textss = "<span>";
209
				$iconfn = "pass";
210
			}
211
?>
212
			<tr valign="top" id="fr<?=$i;?>">
213
				<td class="listt">
214
					<input type="checkbox" id="frc<?=$i;?>" name="rule[]" value="<?=$i;?>" onclick="fr_bgcolor('<?=$i;?>')" style="margin: 0; padding: 0; width: 15px; height: 15px;" />
215
				</td>
216
				<td class="listt" align="center">
217
					<a href="?act=toggle&amp;id=<?=$i;?>">
218
						<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_<?=$iconfn;?>.gif" width="11" height="11" border="0"
219
							title="<?=gettext("click to toggle enabled/disabled status");?>" alt="icon" />
220
					</a>
221
				</td>
222
				<td class="listlr" onclick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='firewall_nat_1to1_edit.php?id=<?=$i;?>';">
223
<?php
224
					echo $textss;
225
					if (!$natent['interface'])
226
						echo htmlspecialchars(convert_friendly_interface_to_friendly_descr("wan"));
227
					else
228
						echo htmlspecialchars(convert_friendly_interface_to_friendly_descr($natent['interface']));
229
					echo $textse;
230
?>
231
				</td>
232
				<td class="listr" onclick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='firewall_nat_1to1_edit.php?id=<?=$i;?>';">
233
<?php
234
					$source_net = pprint_address($natent['source']);
235
					$source_cidr = strstr($source_net, '/');
236
					echo $textss . $natent['external'] . $source_cidr . $textse;
237
?>
238
				</td>
239
				<td class="listr" onclick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='firewall_nat_1to1_edit.php?id=<?=$i;?>';">
240
<?php
241
					echo $textss . $source_net . $textse;
242
?>
243
				</td>
244
				<td class="listr" onclick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='firewall_nat_1to1_edit.php?id=<?=$i;?>';">
245
<?php
246
					echo $textss . pprint_address($natent['destination']) . $textse;
247
?>
248
				</td>
249
				<td class="listbg" onclick="fr_toggle(<?=$i;?>)" ondblclick="document.location='firewall_nat_1to1_edit.php?id=<?=$i;?>';">
250
<?php
251
					echo $textss . htmlspecialchars($natent['descr']) . '&nbsp;' . $textse;
252
?>
253
				</td>
254
				<td class="list nowrap" valign="middle">
255
					<table border="0" cellspacing="0" cellpadding="1" summary="move">
256
						<tr>
257
							<td>
258
								<input onmouseover="fr_insline(<?=$i;?>, true)" onmouseout="fr_insline(<?=$i;?>, false)" name="move_<?=$i;?>"
259
									src="/themes/<?= $g['theme']; ?>/images/icons/icon_left.gif"
260
									title="<?=gettext("move selected rules before this rule");?>"
261
									type="image" style="height:17;width:17;border:0" />
262
							</td>
263
							<td>
264
								<a href="firewall_nat_1to1_edit.php?id=<?=$i;?>">
265
									<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0" title="<?=gettext("edit rule");?>" alt="edit" />
266
								</a>
267
							</td>
268
						</tr>
269
						<tr>
270
							<td align="center" valign="middle">
271
								<a href="firewall_nat_1to1.php?act=del&amp;id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this rule?");?>')">
272
									<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0" title="<?=gettext("delete rule");?>" alt="delete" />
273
								</a>
274
							</td>
275
							<td>
276
								<a href="firewall_nat_1to1_edit.php?dup=<?=$i;?>">
277
									<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="<?=gettext("add a new rule based on this one");?>" width="17" height="17" border="0" alt="duplicate" />
278
								</a>
279
							</td>
280
						</tr>
281
					</table>
282
				</td>
283
			</tr>
284
<?php
285
			$i++;
286
		endforeach;
287
?>
288
			<tr>
289
				<td class="list" colspan="7"></td>
290
				<td class="list nowrap" valign="middle">
291
					<table border="0" cellspacing="0" cellpadding="1" summary="edit">
292
						<tr>
293
							<td>
294
<?php
295
							if ($i == 0):
296
?>
297
								<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_left_d.gif" width="17" height="17"
298
									title="<?=gettext("move selected mappings to end");?>" border="0" alt="move" />
299
<?php
300
							else:
301
?>
302
								<input name="move_<?=$i;?>" type="image" src="/themes/<?= $g['theme']; ?>/images/icons/icon_left.gif"
303
									style="width:17;height:17;border:0" title="<?=gettext("move selected mappings to end");?>" />
304
<?php
305
							endif;
306
?>
307
							</td>
308
							<td>
309
								<a href="firewall_nat_1to1_edit.php">
310
									<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"
311
									title="<?=gettext("add new mapping");?>" alt="add" />
312
								</a>
313
							</td>
314
						</tr>
315
						<tr>
316
							<td>
317
<?php
318
							if ($i == 0):
319
?>
320
								<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_x_d.gif" width="17" height="17"
321
									title="<?=gettext("delete selected rules");?>" border="0" alt="delete" />
322
<?php
323
							else:
324
?>
325
								<input name="del" type="image" src="/themes/<?= $g['theme']; ?>/images/icons/icon_x.gif"
326
									style="width:17;height:17" title="<?=gettext("delete selected mappings");?>"
327
									onclick="return confirm('<?=gettext("Do you really want to delete the selected mappings?");?>')" />
328
<?php
329
							endif;
330
?>
331
							</td>
332
						</tr>
333
					</table>
334
				</td>
335
			</tr>
336
			<tr>
337
				<td colspan="7">
338
					<p><span class="vexpl">
339
						<span class="red"><strong><?=gettext("Note:"); ?><br /></strong></span>
340
						<?=gettext("Depending on the way your WAN connection is setup, you may also need a"); ?>
341
						<a href="firewall_virtual_ip.php"><?=gettext("Virtual IP."); ?></a><br />
342
						<?=gettext("If you add a 1:1 NAT entry for any of the interface IPs on this system, " .
343
							"it will make this system inaccessible on that IP address. i.e. if " .
344
							"you use your WAN IP address, any services on this system (IPsec, OpenVPN server, etc.) " .
345
							"using the WAN IP address will no longer function."); ?>
346
					</span></p>
347
				</td>
348
			</tr>
349
		</table>
350
		</div>
351
	</td></tr>
352
</table>
353
</form>
354
<?php include("fend.inc"); ?>
355
</body>
356
</html>
(64-64/252)