Projet

Général

Profil

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

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

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_refresh_policies();
62
		$retval = vpn_ipsec_configure();
63
		/* reload the filter in the background */
64
		filter_configure();
65
		$savemsg = get_std_save_message($retval);
66
		if ($retval >= 0) {
67
			if (is_subsystem_dirty('ipsec'))
68
				clear_subsystem_dirty('ipsec');
69
		}
70
	} else if ($_POST['submit']) {
71
		$pconfig = $_POST;
72

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

    
75
		write_config();
76

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

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

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

    
96
		/* needs to guarantee that SPDs will be removed before phase 1 */
97
		vpn_ipsec_refresh_policies();
98

    
99
		/* remove the phase1 entry */
100
		unset($a_phase1[$_GET['p1index']]);
101
		vpn_ipsec_refresh_policies();
102
		vpn_ipsec_configure();
103
		write_config();
104
		filter_configure();
105
		header("Location: vpn_ipsec.php");
106
		exit;
107
	}
108
}
109

    
110
if ($_GET['act'] == "delph2")
111
{
112
	if ($a_phase1[$_GET['p1index']] && $a_phase2[$_GET['p2index']]) {
113
		remove_tunnel_spd_policy($a_phase1[$_GET['p1index']],$a_phase2[$_GET['p2index']]);
114
		/* remove the phase2 entry */
115
		unset($a_phase2[$_GET['p2index']]);
116
		vpn_ipsec_refresh_policies();
117
		vpn_ipsec_configure();
118
		filter_configure();
119
		write_config();
120
		header("Location: vpn_ipsec.php");
121
		exit;
122
	}
123
}
124

    
125
$pgtitle = array(gettext("VPN"),gettext("IPsec"));
126
$shortcut_section = "ipsec";
127

    
128
include("head.inc");
129

    
130
?>
131

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

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

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

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

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

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

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

    
481
<?php
482
	
483
}
484

    
485
?>
(228-228/246)