Projet

Général

Profil

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

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

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
		vpn_ipsec_configure();
97
		write_config();
98
		filter_configure();
99
		header("Location: vpn_ipsec.php");
100
		exit;
101
	}
102
}
103

    
104
if ($_GET['act'] == "delph2")
105
{
106
	if ($a_phase1[$_GET['p1index']] && $a_phase2[$_GET['p2index']]) {
107
		/* remove the phase2 entry */
108
		unset($a_phase2[$_GET['p2index']]);
109
		vpn_ipsec_configure();
110
		filter_configure();
111
		write_config();
112
		header("Location: vpn_ipsec.php");
113
		exit;
114
	}
115
}
116

    
117
$pgtitle = array(gettext("VPN"),gettext("IPsec"));
118
$shortcut_section = "ipsec";
119

    
120
include("head.inc");
121

    
122
?>
123

    
124
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
125
<?php include("fbegin.inc"); ?>
126
<form action="vpn_ipsec.php" method="post">
127
<?php
128
	if ($savemsg)
129
		print_info_box($savemsg);
130
	if ($pconfig['enable'] && is_subsystem_dirty('ipsec'))
131
		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."));
132
?>
133
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="vpn ipsec">
134
	<tr>
135
		<td class="tabnavtbl">
136
			<?php
137
				$tab_array = array();
138
				$tab_array[0] = array(gettext("Tunnels"), true, "vpn_ipsec.php");
139
				$tab_array[1] = array(gettext("Mobile clients"), false, "vpn_ipsec_mobile.php");
140
				$tab_array[2] = array(gettext("Pre-Shared Keys"), false, "vpn_ipsec_keys.php");
141
				$tab_array[3] = array(gettext("Advanced Settings"), false, "vpn_ipsec_settings.php");
142
				display_top_tabs($tab_array);
143
			?>
144
		</td>
145
	</tr>
146
	<tr>
147
		<td>
148
			<div id="mainarea">
149
				<table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area">
150
					<tr>
151
						<td class="vtable">
152
							<table border="0" cellspacing="2" cellpadding="0" summary="enable">
153
								<tr>
154
									<td>
155
										<input name="enable" type="checkbox" id="enable" value="yes" <?php if ($pconfig['enable']) echo "checked=\"checked\"";?> />
156
									</td>
157
									<td>
158
										<strong><?=gettext("Enable IPsec"); ?></strong>
159
									</td>
160
								</tr>
161
							</table>
162
						</td>
163
					</tr>
164
					<tr>
165
						<td>
166
							<input name="submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" />
167
						</td>
168
					</tr>
169
				</table>
170
				<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="phase-1 entries">
171
					<?php
172
						$i = 0;
173
						foreach ($a_phase1 as $ph1ent) {
174
							if (isset( $ph1ent['disabled'])) {
175
								$spans = "<span class=\"gray\">";
176
								$spane = "</span>";
177
							}
178
							else
179
								$spans = $spane = "";
180
						
181
						show_ipsec_header($ph1ent);
182
						$counter++; // used to determine if we need to output header manually (no records exist)
183
					?>					
184
					<tr valign="top" ondblclick="document.location='vpn_ipsec_phase1.php?p1index=<?=$i;?>'">
185
						<td class="listlr">
186
							<?=$spans;?>
187
							<?php	if (empty($ph1ent['iketype']) || $ph1ent['iketype'] == "ikev1")
188
									echo "V1";
189
								else
190
									echo "V2";
191
							?>
192
							<?=$spane;?>
193
						</td>
194
						<td class="listr">
195
							<?=$spans;?>
196
							<?php
197
								if ($ph1ent['interface']) {
198
									$iflabels = get_configured_interface_with_descr();
199

    
200
									$carplist = get_configured_carp_interface_list();
201
									foreach ($carplist as $cif => $carpip)
202
										$iflabels[$cif] = $carpip." (".get_vip_descr($carpip).")";
203

    
204
									$aliaslist = get_configured_ip_aliases_list();
205
									foreach ($aliaslist as $aliasip => $aliasif)
206
										$iflabels[$aliasip] = $aliasip." (".get_vip_descr($aliasip).")";
207

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

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

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

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

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

    
468
<?php
469

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

    
486
<?php
487
	
488
}
489

    
490
?>
(235-235/254)