Projet

Général

Profil

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

univnautes / usr / local / www / vpn_ipsec.php @ 9694d32c

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']] && $a_phase2[$_GET['p2index']]) {
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	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 if (!isset($ph1ent['mobile'])): ?>
274
								<tr>
275
									<td>
276
									</td>
277
									<td>
278
										<a href="vpn_ipsec_phase1.php?dup=<?=$i;?>">
279
											<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="<?=gettext("copy phase1 entry"); ?>" width="17" height="17" border="0" alt="add" />
280
										</a>
281
									</td>
282
								</tr>
283
								<?php endif; ?>
284
							</table>
285
						</td>
286
					</tr>
287
					<tr>
288
						<td class="listrborder" colspan="6">
289
							<div id="shph2but-<?=$i?>">
290
								<?php
291
									$phase2count=0;
292
									foreach ($a_phase2 as $ph2ent) {
293
										if ($ph2ent['ikeid'] != $ph1ent['ikeid']) 
294
											continue;
295
										$phase2count++;
296
									}
297
								?>								
298
								<input type="button" onclick="show_phase2('tdph2-<?=$i?>','shph2but-<?=$i?>')" value="+" /> - <?php printf(gettext("Show %s Phase-2 entries"), $phase2count); ?>
299
							</div>
300
							<table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0" id="tdph2-<?=$i?>" style="display:none" summary="phase-2 entries">
301
								<tr>
302
									<td class="listhdrr"><?=gettext("Mode"); ?></td>
303
									<?php if(($ph2ent['mode'] == "tunnel") or ($ph2ent['mode'] == "tunnel6")): ?>
304
									<td class="listhdrr"><?=gettext("Local Subnet"); ?></td>
305
									<td class="listhdrr"><?=gettext("Remote Subnet"); ?></td>
306
									<?php endif; ?>
307
									<td class="listhdrr"><?=gettext("P2 Protocol"); ?></td>
308
									<td class="listhdrr"><?=gettext("P2 Transforms"); ?></td>
309
									<td class="listhdrr"><?=gettext("P2 Auth Methods"); ?></td>
310
									<td class ="list">
311
										<a href="vpn_ipsec_phase2.php?ikeid=<?=$ph1ent['ikeid'];?><?php if (isset($ph1ent['mobile'])) echo "&amp;mobile=true";?>">
312
											<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="<?=gettext("add phase2 entry"); ?>" width="17" height="17" border="0" alt="add" />
313
										</a>
314
									</td>
315
								</tr>
316
							<?php
317
									foreach ($a_phase2 as $ph2ent):
318
										if ($ph2ent['ikeid'] != $ph1ent['ikeid'])
319
											continue;
320

    
321
										if (isset( $ph2ent['disabled']) || isset($ph1ent['disabled'])) {
322
											$spans = "<span class=\"gray\">";
323
											$spane = "</span>";
324
										}
325
										else
326
											$spans = $spane = "";
327
							?>
328
								<tr valign="top" ondblclick="document.location='vpn_ipsec_phase2.php?p2index=<?=$ph2ent['uniqid'];?>'">
329

    
330
									<td class="listlr nowrap">
331
										<?=$spans;?>
332
											<?=$ph2ent['mode'];?>
333
										<?=$spane;?>
334
									</td>
335
									<?php 
336
										if(($ph2ent['mode'] <> "tunnel") and ($ph2ent['mode'] <> "tunnel6")) {
337
											echo "<td class=\"listr nowrap\">&nbsp;</td><td class=\"listr nowrap\">&nbsp;</td>";
338
										} 
339
									?>
340
									<?php if(($ph2ent['mode'] == "tunnel") or ($ph2ent['mode'] == "tunnel6")): ?>
341
									<td class="listr nowrap">
342
										<?=$spans;?>
343
											<?=ipsec_idinfo_to_text($ph2ent['localid']); ?>
344
										<?=$spane;?>
345
									</td>
346
									<td class="listr nowrap">
347
										<?=$spans;?>
348
											<?=ipsec_idinfo_to_text($ph2ent['remoteid']); ?>
349
										<?=$spane;?>
350
									</td>
351
									<?php endif; ?>
352
									<td class="listr nowrap">
353
										<?=$spans;?>
354
											<?php echo $p2_protos[$ph2ent['protocol']];	?>
355
										<?=$spane;?>
356
									</td>
357
									<td class="listr">
358
										<?=$spans;?>
359
										<?php
360
											foreach ($ph2ent['encryption-algorithm-option'] as $k => $ph2ea) {
361
												if ($k)
362
													echo ", ";
363
												echo $p2_ealgos[$ph2ea['name']]['name'];
364
												if ($ph2ea['keylen']) {
365
													if ($ph2ea['keylen']=="auto")
366
														echo " (" . gettext("auto") . ")";
367
													else
368
														echo " ({$ph2ea['keylen']} " . gettext("bits") . ")";
369
												}
370
											}
371
										?>
372
										<?=$spane;?>
373
									</td>
374
									<td class="listr nowrap">
375
										<?=$spans;?>
376
										<?php
377
											if (!empty($ph2ent['hash-algorithm-option']) && is_array($ph2ent['hash-algorithm-option'])) {
378
												foreach ($ph2ent['hash-algorithm-option'] as $k => $ph2ha) {
379
													if ($k)
380
														echo ", ";
381
													echo $p2_halgos[$ph2ha];
382
												}
383
											}
384
										?>
385
										<?=$spane;?>
386
									</td>
387
									<td class="list nowrap">
388
										<a href="vpn_ipsec_phase2.php?p2index=<?=$ph2ent['uniqid'];?>">
389
											<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" title="<?=gettext("edit phase2 entry"); ?>" width="17" height="17" border="0" alt="edit" />
390
										</a>
391
										<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?"); ?>')">
392
											<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" title="<?=gettext("delete phase2 entry"); ?>" width="17" height="17" border="0" alt="delete" />
393
										</a>
394
										<a href="vpn_ipsec_phase2.php?dup=<?=$ph2ent['uniqid'];?>">
395
											<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" />
396
										</a>
397
									</td>
398
								</tr>
399

    
400
								<?php endforeach; ?>
401

    
402
							</table>
403
						</td>
404
					</tr>
405
					<tr>
406
						<td>
407
							&nbsp;
408
						</td>
409
					</tr>
410
					<?php
411
							$i++;
412
						}
413
					if(!$counter)
414
						show_ipsec_header($ph1ent);
415
					?>
416
					<tr>
417
						<td class="list" colspan="6"></td>
418
						<td class="list">
419
							<table border="0" cellspacing="0" cellpadding="1" summary="add">
420
								<tr>
421
									<td width="17"></td>
422
									<td>
423
										<a href="vpn_ipsec_phase1.php">
424
											<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="<?=gettext("add phase1 entry"); ?>" width="17" height="17" border="0" alt="add" />
425
										</a>
426
									</td>
427
								</tr>
428
							</table>
429
						</td>
430
					</tr>
431
					<tr>
432
						<td colspan="7">
433
							<p>
434
								<span class="vexpl">
435
									<span class="red">
436
										<strong><?=gettext("Note"); ?>:<br /></strong>
437
									</span>
438
								<?=gettext("You can check your IPsec status at"); ?> <a href="diag_ipsec.php"><?=gettext("Status:IPsec"); ?></a>.<br />
439
									<?=gettext("IPsec Debug Mode can be enabled at"); ?> <a href="vpn_ipsec_settings.php"><?=gettext("VPN:IPsec:Advanced Settings"); ?></a>.<br />
440
									<?=gettext("IPsec can be set to prefer older SAs at"); ?> <a href="vpn_ipsec_settings.php"><?=gettext("VPN:IPsec:Advanced Settings"); ?></a>.
441
								</span>
442
							</p>
443
						</td>
444
					</tr>
445
				</table>
446
			</div>
447
		</td>
448
	</tr>
449
</table>
450
</form>
451
<?php include("fend.inc"); ?>
452
<script type="text/javascript">
453
//<![CDATA[
454
function show_phase2(id, buttonid) {
455
	document.getElementById(buttonid).innerHTML='';
456
	aodiv = document.getElementById(id);
457
	aodiv.style.display = "block";
458
}
459
//]]>
460
</script>
461
</body>
462
</html>
463

    
464
<?php
465

    
466
function show_ipsec_header($ph1ent) {
467
	global $g;
468
	if (isset($ph1ent['mobile'])) 
469
		$mobile = "&mobile=true";
470
	?>
471
	<tr>
472
		<td class="listhdrr"><?=gettext("IKE"); ?></td>
473
		<td class="listhdrr"><?=gettext("Remote Gateway"); ?></td>
474
		<td class="listhdrr"><?=gettext("Mode"); ?></td>
475
		<td class="listhdrr"><?=gettext("P1 Protocol"); ?></td>
476
		<td class="listhdrr"><?=gettext("P1 Transforms"); ?></td>
477
		<td class="listhdrr"><?=gettext("P1 Description"); ?></td>
478
		<td class ="list">
479
		</td>
480
	</tr>
481

    
482
<?php
483
	
484
}
485

    
486
?>
(236-236/255)