Project

General

Profile

Download (15.6 KB) Statistics
| Branch: | Tag: | Revision:
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
				remove_tunnel_spd_policy($a_phase1[$_GET['p1index']],$a_phase2[$p2index]);
92
				unset($a_phase2[$p2index]);
93
			}
94

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

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

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

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

    
127
include("head.inc");
128

    
129
?>
130

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

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

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

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

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

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

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

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

    
463
<?php
464

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

    
480
<?php
481
	
482
}
483

    
484
?>
(231-231/249)