Project

General

Profile

Download (12.2 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

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

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

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

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

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

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

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

    
127
		/* copy all selected rules */
128
		for ($i = 0; $i < count($a_1to1); $i++) {
129
			if ($i == $movebtn) {
130
				continue;
131
			}
132
			if (in_array($i, $_POST['rule'])) {
133
				$a_1to1_new[] = $a_1to1[$i];
134
			}
135
		}
136

    
137
		/* copy $movebtn rule */
138
		if ($movebtn < count($a_1to1)) {
139
			$a_1to1_new[] = $a_1to1[$movebtn];
140
		}
141

    
142
		/* copy all rules > $movebtn and not selected */
143
		for ($i = $movebtn+1; $i < count($a_1to1); $i++) {
144
			if (!in_array($i, $_POST['rule'])) {
145
				$a_1to1_new[] = $a_1to1[$i];
146
			}
147
		}
148
		if (count($a_1to1_new) > 0) {
149
			$a_1to1 = $a_1to1_new;
150
		}
151

    
152
		if (write_config()) {
153
			mark_subsystem_dirty('natconf');
154
		}
155
		header("Location: firewall_nat_1to1.php");
156
		exit;
157
	}
158
}
159

    
160
$pgtitle = array(gettext("Firewall"),gettext("NAT"),gettext("1:1"));
161
include("head.inc");
162

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