Projet

Général

Profil

Télécharger (12 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / firewall_nat_1to1.php @ fab1cd2f

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
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12

    
13
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15

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

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

    
35
##|+PRIV
36
##|*IDENT=page-firewall-nat-1-1
37
##|*NAME=Firewall: NAT: 1:1 page
38
##|*DESCR=Allow access to the 'Firewall: NAT: 1:1' page.
39
##|*MATCH=firewall_nat_1to1.php*
40
##|-PRIV
41

    
42
require("guiconfig.inc");
43
require_once("functions.inc");
44
require_once("filter.inc");
45
require_once("shaper.inc");
46

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

    
50
$a_1to1 = &$config['nat']['onetoone'];
51

    
52
if ($_POST) {
53
	$pconfig = $_POST;
54

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

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

    
67
if ($_GET['act'] == "del") {
68
	if ($a_1to1[$_GET['id']]) {
69
		unset($a_1to1[$_GET['id']]);
70
		if (write_config())
71
			mark_subsystem_dirty('natconf');
72
		header("Location: firewall_nat_1to1.php");
73
		exit;
74
	}
75
}
76

    
77
if (isset($_POST['del_x'])) {
78
	/* delete selected rules */
79
	if (is_array($_POST['rule']) && count($_POST['rule'])) {
80
		foreach ($_POST['rule'] as $rulei) {
81
			unset($a_1to1[$rulei]);
82
		}
83
		if (write_config())
84
			mark_subsystem_dirty('natconf');
85
		header("Location: firewall_nat_1to1.php");
86
		exit;
87
	}
88

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

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

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

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

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

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

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

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