Projet

Général

Profil

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

univnautes / usr / local / www / vpn_ipsec.php @ 7ec7e24f

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
?>
186
					<tr valign="top" ondblclick="document.location='vpn_ipsec_phase1.php?p1index=<?=$i;?>'">
187
						<td class="listlr">
188
							<?=$spans;?>
189
<?php
190
							if (empty($ph1ent['iketype']) || $ph1ent['iketype'] == "ikev1")
191
								echo "V1";
192
							else
193
								echo "V2";
194
?>
195
							<?=$spane;?>
196
						</td>
197
						<td class="listr">
198
							<?=$spans;?>
199
<?php
200
							if ($ph1ent['interface']) {
201
								$iflabels = get_configured_interface_with_descr();
202

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

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

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

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

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

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

    
475
<?php
476

    
477
function show_ipsec_header($ph1ent) {
478

    
479
?>
480
	<tr>
481
		<td class="listhdrr"><?=gettext("IKE"); ?></td>
482
		<td class="listhdrr"><?=gettext("Remote Gateway"); ?></td>
483
		<td class="listhdrr"><?=gettext("Mode"); ?></td>
484
		<td class="listhdrr"><?=gettext("P1 Protocol"); ?></td>
485
		<td class="listhdrr"><?=gettext("P1 Transforms"); ?></td>
486
		<td class="listhdrr"><?=gettext("P1 Description"); ?></td>
487
		<td class="list">
488
		</td>
489
	</tr>
490

    
491
<?php
492

    
493
}
494

    
495
?>
(236-236/255)