Projet

Général

Profil

Télécharger (15,7 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / vpn_ipsec.php @ e0fb12c1

1
<?php
2
/*
3
	vpn_ipsec.php
4
	part of m0n0wall (http://m0n0.ch/wall)
5

    
6
	Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>.
7
	Copyright (C) 2008 Shrew Soft Inc
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
##|+PRIV
33
##|*IDENT=page-vpn-ipsec
34
##|*NAME=VPN: IPsec page
35
##|*DESCR=Allow access to the 'VPN: IPsec' page.
36
##|*MATCH=vpn_ipsec.php*
37
##|-PRIV
38

    
39
require("guiconfig.inc");
40
require_once("functions.inc");
41
require_once("filter.inc");
42
require_once("shaper.inc");
43
require_once("ipsec.inc");
44
require_once("vpn.inc");
45

    
46
if (!is_array($config['ipsec']['phase1']))
47
	$config['ipsec']['phase1'] = array();
48

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

    
52
$a_phase1 = &$config['ipsec']['phase1'];
53
$a_phase2 = &$config['ipsec']['phase2'];
54

    
55
$pconfig['enable'] = isset($config['ipsec']['enable']);
56

    
57
if ($_POST) {
58

    
59
	if ($_POST['apply']) {
60
		$retval = 0;
61
		$retval = vpn_ipsec_configure();
62
		/* reload the filter in the background */
63
		filter_configure();
64
		$savemsg = get_std_save_message($retval);
65
		if ($retval >= 0) {
66
			if (is_subsystem_dirty('ipsec'))
67
				clear_subsystem_dirty('ipsec');
68
		}
69
	} else if ($_POST['submit']) {
70
		$pconfig = $_POST;
71

    
72
		$config['ipsec']['enable'] = $_POST['enable'] ? true : false;
73

    
74
		write_config();
75

    
76
		$retval = vpn_ipsec_configure();
77
	}
78
}
79

    
80
if ($_GET['act'] == "delph1")
81
{
82
	if ($a_phase1[$_GET['p1index']]) {
83
		/* remove static route if interface is not WAN */
84
		if ($a_phase1[$_GET['p1index']]['interface'] <> "wan")
85
			mwexec("/sbin/route delete -host {$a_phase1[$_GET['p1index']]['remote-gateway']}");
86

    
87
		/* remove all phase2 entries that match the ikeid */
88
		$ikeid = $a_phase1[$_GET['p1index']]['ikeid'];
89
		foreach ($a_phase2 as $p2index => $ph2tmp)
90
			if ($ph2tmp['ikeid'] == $ikeid) {
91
				unset($a_phase2[$p2index]);
92
			}
93

    
94
		/* remove the phase1 entry */
95
		unset($a_phase1[$_GET['p1index']]);
96
		write_config();
97
		mark_subsystem_dirty('ipsec');
98
		header("Location: vpn_ipsec.php");
99
		exit;
100
	}
101
}
102

    
103
if ($_GET['act'] == "delph2")
104
{
105
	if ($a_phase1[$_GET['p1index']]) {
106
		/* remove the phase2 entry */
107
		foreach ($a_phase2 as $ph2idx => $ph2) {
108
			if ($ph2['uniqid'] == $_GET['p2index']) {
109
				unset($a_phase2[$ph2idx]);
110
				write_config();
111
				mark_subsystem_dirty('ipsec');
112
				break;
113
			}
114
		}
115
		header("Location: vpn_ipsec.php");
116
		exit;
117
	}
118
}
119

    
120
$pgtitle = array(gettext("VPN"),gettext("IPsec"));
121
$shortcut_section = "ipsec";
122

    
123
include("head.inc");
124

    
125
?>
126

    
127
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
128
<?php include("fbegin.inc"); ?>
129
<form action="vpn_ipsec.php" method="post">
130
<?php
131
	if ($savemsg)
132
		print_info_box($savemsg);
133
	if ($pconfig['enable'] && is_subsystem_dirty('ipsec'))
134
		print_info_box_np(gettext("The IPsec tunnel configuration has been changed") . ".<br />" . gettext("You must apply the changes in order for them to take effect."));
135
?>
136
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="vpn ipsec">
137
	<tr>
138
		<td class="tabnavtbl">
139
<?php
140
			$tab_array = array();
141
			$tab_array[0] = array(gettext("Tunnels"), true, "vpn_ipsec.php");
142
			$tab_array[1] = array(gettext("Mobile clients"), false, "vpn_ipsec_mobile.php");
143
			$tab_array[2] = array(gettext("Pre-Shared Keys"), false, "vpn_ipsec_keys.php");
144
			$tab_array[3] = array(gettext("Advanced Settings"), false, "vpn_ipsec_settings.php");
145
			display_top_tabs($tab_array);
146
?>
147
		</td>
148
	</tr>
149
	<tr>
150
		<td>
151
			<div id="mainarea">
152
				<table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area">
153
					<tr>
154
						<td class="vtable">
155
							<table border="0" cellspacing="2" cellpadding="0" summary="enable">
156
								<tr>
157
									<td>
158
										<input name="enable" type="checkbox" id="enable" value="yes" <?php if ($pconfig['enable']) echo "checked=\"checked\"";?> />
159
									</td>
160
									<td>
161
										<strong><?=gettext("Enable IPsec"); ?></strong>
162
									</td>
163
								</tr>
164
							</table>
165
						</td>
166
					</tr>
167
					<tr>
168
						<td>
169
							<input name="submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" />
170
						</td>
171
					</tr>
172
				</table>
173
				<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="phase-1 entries">
174
<?php
175
				$i = 0;
176
				foreach ($a_phase1 as $ph1ent):
177
					if (isset( $ph1ent['disabled'])) {
178
						$spans = "<span class=\"gray\">";
179
						$spane = "</span>";
180
					}
181
					else
182
						$spans = $spane = "";
183

    
184
					show_ipsec_header($ph1ent);
185
					$counter++; // used to determine if we need to output header manually (no records exist)
186
?>
187
					<tr valign="top" ondblclick="document.location='vpn_ipsec_phase1.php?p1index=<?=$i;?>'">
188
						<td class="listlr">
189
							<?=$spans;?>
190
<?php
191
							if (empty($ph1ent['iketype']) || $ph1ent['iketype'] == "ikev1")
192
								echo "V1";
193
							else
194
								echo "V2";
195
?>
196
							<?=$spane;?>
197
						</td>
198
						<td class="listr">
199
							<?=$spans;?>
200
<?php
201
							if ($ph1ent['interface']) {
202
								$iflabels = get_configured_interface_with_descr();
203

    
204
								$carplist = get_configured_carp_interface_list();
205
								foreach ($carplist as $cif => $carpip)
206
									$iflabels[$cif] = $carpip." (".get_vip_descr($carpip).")";
207

    
208
								$aliaslist = get_configured_ip_aliases_list();
209
								foreach ($aliaslist as $aliasip => $aliasif)
210
									$iflabels[$aliasip] = $aliasip." (".get_vip_descr($aliasip).")";
211

    
212
								$grouplist = return_gateway_groups_array();
213
								foreach ($grouplist as $name => $group) {
214
									if($group[0]['vip'] <> "")
215
										$vipif = $group[0]['vip'];
216
									else
217
										$vipif = $group[0]['int'];
218
									$iflabels[$name] = "GW Group {$name}";
219
								}
220
								$if = htmlspecialchars($iflabels[$ph1ent['interface']]);
221
							}
222
							else
223
								$if = "WAN";
224

    
225
							if (!isset($ph1ent['mobile']))
226
								echo $if."<br />".$ph1ent['remote-gateway'];
227
							else
228
								echo $if."<br /><strong>" . gettext("Mobile Client") . "</strong>";
229
?>
230
							<?=$spane;?>
231
						</td>
232
						<td class="listr">
233
							<?=$spans;?>
234
							<?=$ph1ent['mode'];?>
235
							<?=$spane;?>
236
						</td>
237
						<td class="listr">
238
							<?=$spans;?>
239
							<?=$p1_ealgos[$ph1ent['encryption-algorithm']['name']]['name'];?>
240
<?php
241
							if ($ph1ent['encryption-algorithm']['keylen']) {
242
								if ($ph1ent['encryption-algorithm']['keylen']=="auto")
243
									echo " (" . gettext("auto") . ")";
244
								else
245
									echo " ({$ph1ent['encryption-algorithm']['keylen']} " . gettext("bits") . ")";
246
							}
247
?>
248
							<?=$spane;?>
249
						</td>
250
						<td class="listr">
251
							<?=$spans;?>
252
							<?=$p1_halgos[$ph1ent['hash-algorithm']];?>
253
							<?=$spane;?>
254
						</td>
255
						<td class="listbg">
256
							<?=$spans;?>
257
							<?=htmlspecialchars($ph1ent['descr']);?>&nbsp;
258
							<?=$spane;?>
259
						</td>
260
						<td valign="middle" class="list nowrap">
261
							<table border="0" cellspacing="0" cellpadding="1" summary="icons">
262
								<tr>
263
									<td>
264
										<a href="vpn_ipsec_phase1.php?p1index=<?=$i;?>">
265
											<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" title="<?=gettext("edit phase1 entry"); ?>" width="17" height="17" border="0" alt="edit" />
266
										</a>
267
									</td>
268
									<td>
269
										<a href="vpn_ipsec.php?act=delph1&amp;p1index=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this phase1 and all associated phase2 entries?"); ?>')">
270
											<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" title="<?=gettext("delete phase1 entry"); ?>" width="17" height="17" border="0" alt="delete" />
271
										</a>
272
									</td>
273
								</tr>
274
<?php
275
							if (!isset($ph1ent['mobile'])):
276
?>
277
								<tr>
278
									<td>
279
									</td>
280
									<td>
281
										<a href="vpn_ipsec_phase1.php?dup=<?=$i;?>">
282
											<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="<?=gettext("copy phase1 entry"); ?>" width="17" height="17" border="0" alt="add" />
283
										</a>
284
									</td>
285
								</tr>
286
<?php
287
							endif;
288
?>
289
							</table>
290
						</td>
291
					</tr>
292
					<tr>
293
						<td class="listrborder" colspan="6">
294
							<div id="shph2but-<?=$i?>">
295
<?php
296
								$phase2count=0;
297
								foreach ($a_phase2 as $ph2ent) {
298
									if ($ph2ent['ikeid'] != $ph1ent['ikeid'])
299
										continue;
300
									$phase2count++;
301
								}
302
?>
303
								<input type="button" onclick="show_phase2('tdph2-<?=$i?>','shph2but-<?=$i?>')" value="+" /> - <?php printf(gettext("Show %s Phase-2 entries"), $phase2count); ?>
304
							</div>
305
							<table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0" id="tdph2-<?=$i?>" style="display:none" summary="phase-2 entries">
306
								<tr>
307
									<td class="listhdrr"><?=gettext("Mode"); ?></td>
308
<?php
309
								if(($ph2ent['mode'] == "tunnel") or ($ph2ent['mode'] == "tunnel6")):
310
?>
311
									<td class="listhdrr"><?=gettext("Local Subnet"); ?></td>
312
									<td class="listhdrr"><?=gettext("Remote Subnet"); ?></td>
313
<?php
314
								endif;
315
?>
316
									<td class="listhdrr"><?=gettext("P2 Protocol"); ?></td>
317
									<td class="listhdrr"><?=gettext("P2 Transforms"); ?></td>
318
									<td class="listhdrr"><?=gettext("P2 Auth Methods"); ?></td>
319
									<td class ="list">
320
										<a href="vpn_ipsec_phase2.php?ikeid=<?=$ph1ent['ikeid'];?><?php if (isset($ph1ent['mobile'])) echo "&amp;mobile=true";?>">
321
											<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="<?=gettext("add phase2 entry"); ?>" width="17" height="17" border="0" alt="add" />
322
										</a>
323
									</td>
324
								</tr>
325
<?php
326
								foreach ($a_phase2 as $ph2ent):
327
									if ($ph2ent['ikeid'] != $ph1ent['ikeid'])
328
										continue;
329

    
330
									if (isset( $ph2ent['disabled']) || isset($ph1ent['disabled'])) {
331
										$spans = "<span class=\"gray\">";
332
										$spane = "</span>";
333
									} else
334
										$spans = $spane = "";
335
?>
336
								<tr valign="top" ondblclick="document.location='vpn_ipsec_phase2.php?p2index=<?=$ph2ent['uniqid'];?>'">
337

    
338
									<td class="listlr nowrap">
339
										<?=$spans;?>
340
										<?=$ph2ent['mode'];?>
341
										<?=$spane;?>
342
									</td>
343
<?php
344
									if(($ph2ent['mode'] <> "tunnel") and ($ph2ent['mode'] <> "tunnel6")) {
345
										echo "<td class=\"listr nowrap\">&nbsp;</td><td class=\"listr nowrap\">&nbsp;</td>";
346
									}
347
?>
348
<?php
349
									if(($ph2ent['mode'] == "tunnel") or ($ph2ent['mode'] == "tunnel6")):
350
?>
351
										<td class="listr nowrap">
352
											<?=$spans;?>
353
												<?=ipsec_idinfo_to_text($ph2ent['localid']); ?>
354
											<?=$spane;?>
355
										</td>
356
										<td class="listr nowrap">
357
											<?=$spans;?>
358
												<?=ipsec_idinfo_to_text($ph2ent['remoteid']); ?>
359
											<?=$spane;?>
360
										</td>
361
<?php
362
									endif;
363
?>
364
									<td class="listr nowrap">
365
										<?=$spans;?>
366
										<?php echo $p2_protos[$ph2ent['protocol']]; ?>
367
										<?=$spane;?>
368
									</td>
369
									<td class="listr">
370
										<?=$spans;?>
371
<?php
372
										foreach ($ph2ent['encryption-algorithm-option'] as $k => $ph2ea) {
373
											if ($k)
374
												echo ", ";
375
											echo $p2_ealgos[$ph2ea['name']]['name'];
376
											if ($ph2ea['keylen']) {
377
												if ($ph2ea['keylen']=="auto")
378
													echo " (" . gettext("auto") . ")";
379
												else
380
													echo " ({$ph2ea['keylen']} " . gettext("bits") . ")";
381
											}
382
										}
383
?>
384
										<?=$spane;?>
385
									</td>
386
									<td class="listr nowrap">
387
										<?=$spans;?>
388
<?php
389
										if (!empty($ph2ent['hash-algorithm-option']) && is_array($ph2ent['hash-algorithm-option'])) {
390
											foreach ($ph2ent['hash-algorithm-option'] as $k => $ph2ha) {
391
												if ($k)
392
													echo ", ";
393
												echo $p2_halgos[$ph2ha];
394
											}
395
										}
396
?>
397
										<?=$spane;?>
398
									</td>
399
									<td class="list nowrap">
400
										<a href="vpn_ipsec_phase2.php?p2index=<?=$ph2ent['uniqid'];?>">
401
											<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" title="<?=gettext("edit phase2 entry"); ?>" width="17" height="17" border="0" alt="edit" />
402
										</a>
403
										<a href="vpn_ipsec.php?act=delph2&amp;p1index=<?=$i;?>&amp;p2index=<?=$ph2ent['uniqid'];?>" onclick="return confirm('<?=gettext("Do you really want to delete this phase2 entry?"); ?>')">
404
											<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" title="<?=gettext("delete phase2 entry"); ?>" width="17" height="17" border="0" alt="delete" />
405
										</a>
406
										<a href="vpn_ipsec_phase2.php?dup=<?=$ph2ent['uniqid'];?>">
407
											<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="<?=gettext("add a new Phase 2 based on this one"); ?>" width="17" height="17" border="0" alt="add" />
408
										</a>
409
									</td>
410
								</tr>
411
<?php
412
								endforeach;
413
?>
414
							</table>
415
						</td>
416
					</tr>
417
					<tr>
418
						<td>
419
							&nbsp;
420
						</td>
421
					</tr>
422
<?php
423
					$i++;
424
				endforeach;  // $a_phase1 as $ph1ent
425
				if(!$counter)
426
					show_ipsec_header($ph1ent);
427
?>
428
					<tr>
429
						<td class="list" colspan="6"></td>
430
						<td class="list">
431
							<table border="0" cellspacing="0" cellpadding="1" summary="add">
432
								<tr>
433
									<td width="17"></td>
434
									<td>
435
										<a href="vpn_ipsec_phase1.php">
436
											<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="<?=gettext("add phase1 entry"); ?>" width="17" height="17" border="0" alt="add" />
437
										</a>
438
									</td>
439
								</tr>
440
							</table>
441
						</td>
442
					</tr>
443
					<tr>
444
						<td colspan="7">
445
							<p>
446
								<span class="vexpl">
447
									<span class="red">
448
										<strong><?=gettext("Note"); ?>:<br /></strong>
449
									</span>
450
								<?=gettext("You can check your IPsec status at"); ?> <a href="diag_ipsec.php"><?=gettext("Status:IPsec"); ?></a>.<br />
451
									<?=gettext("IPsec Debug Mode can be enabled at"); ?> <a href="vpn_ipsec_settings.php"><?=gettext("VPN:IPsec:Advanced Settings"); ?></a>.<br />
452
									<?=gettext("IPsec can be set to prefer older SAs at"); ?> <a href="vpn_ipsec_settings.php"><?=gettext("VPN:IPsec:Advanced Settings"); ?></a>.
453
								</span>
454
							</p>
455
						</td>
456
					</tr>
457
				</table>
458
			</div>
459
		</td>
460
	</tr>
461
</table>
462
</form>
463
<?php include("fend.inc"); ?>
464
<script type="text/javascript">
465
//<![CDATA[
466
function show_phase2(id, buttonid) {
467
	document.getElementById(buttonid).innerHTML='';
468
	aodiv = document.getElementById(id);
469
	aodiv.style.display = "block";
470
}
471
//]]>
472
</script>
473
</body>
474
</html>
475

    
476
<?php
477

    
478
function show_ipsec_header($ph1ent) {
479
	global $g;
480
	if (isset($ph1ent['mobile']))
481
		$mobile = "&mobile=true";
482
	?>
483
	<tr>
484
		<td class="listhdrr"><?=gettext("IKE"); ?></td>
485
		<td class="listhdrr"><?=gettext("Remote Gateway"); ?></td>
486
		<td class="listhdrr"><?=gettext("Mode"); ?></td>
487
		<td class="listhdrr"><?=gettext("P1 Protocol"); ?></td>
488
		<td class="listhdrr"><?=gettext("P1 Transforms"); ?></td>
489
		<td class="listhdrr"><?=gettext("P1 Description"); ?></td>
490
		<td class="list">
491
		</td>
492
	</tr>
493

    
494
<?php
495

    
496
}
497

    
498
?>
(236-236/255)