Project

General

Profile

Download (14.3 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
$wancfg = &$config['interfaces']['wan'];
56

    
57
$pconfig['enable'] = isset($config['ipsec']['enable']);
58

    
59
if ($_POST) {
60

    
61
	if ($_POST['apply']) {
62
		$retval = 0;
63
		$retval = vpn_ipsec_refresh_policies();
64
		$retval = vpn_ipsec_configure();
65
		/* reload the filter in the background */
66
		filter_configure();
67
		$savemsg = get_std_save_message($retval);
68
		if ($retval == 0) {
69
			if (is_subsystem_dirty('ipsec'))
70
				clear_subsystem_dirty('ipsec');
71
		}
72
	} else if ($_POST['submit']) {
73
		$pconfig = $_POST;
74

    
75
		$config['ipsec']['enable'] = $_POST['enable'] ? true : false;
76

    
77
		write_config();
78

    
79
		$retval = vpn_ipsec_configure();
80
	}
81
}
82

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

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

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

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

    
121
$pgtitle = array(gettext("VPN"),gettext("IPsec"));
122
$statusurl = "diag_ipsec.php";
123
$logurl = "diag_logs_ipsec.php";
124

    
125
include("head.inc");
126

    
127
?>
128

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

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

    
304
										if (isset( $ph2ent['disabled']) || isset($ph1ent['disabled'])) {
305
											$spans = "<span class=\"gray\">";
306
											$spane = "</span>";
307
										}
308
										else
309
											$spans = $spane = "";
310
								?>
311
								<tr valign="top" ondblclick="document.location='vpn_ipsec_phase2.php?p2index=<?=$j;?>'">
312

    
313
									<td nowrap class="listlr">
314
										<?=$spans;?>
315
											<?=$ph2ent['mode'];?>
316
										<?=$spane;?>
317
									</td>
318
									<?php 
319
										if($ph2ent['mode'] <> "tunnel") {
320
											echo "<td nowrap class=\"listr\">&nbsp;</td><td nowrap class=\"listr\">&nbsp;</td>";
321
										} 
322
									?>
323
									<?php if($ph2ent['mode'] == "tunnel"): ?>
324
									<td nowrap class="listr">
325
										<?=$spans;?>
326
											<?=ipsec_idinfo_to_text($ph2ent['localid']); ?>
327
										<?=$spane;?>
328
									</td>
329
									<td nowrap class="listr">
330
										<?=$spans;?>
331
											<?=ipsec_idinfo_to_text($ph2ent['remoteid']); ?>
332
										<?=$spane;?>
333
									</td>
334
									<?php endif; ?>
335
									<td nowrap class="listr">
336
										<?=$spans;?>
337
											<?php echo $p2_protos[$ph2ent['protocol']];	?>
338
										<?=$spane;?>
339
									</td>
340
									<td class="listr">
341
										<?=$spans;?>
342
										<?php
343
											$k = 0;
344
											foreach ($ph2ent['encryption-algorithm-option'] as $ph2ea) {
345
												if ($k++)
346
													echo ", ";
347
												echo $p2_ealgos[$ph2ea['name']]['name'];
348
												if ($ph2ea['keylen']) {
349
													if ($ph2ea['keylen']=="auto")
350
														echo " (" . gettext("auto") . ")";
351
													else
352
														echo " ({$ph2ea['keylen']} " . gettext("bits") . ")";
353
												}
354
											}
355
										?>
356
										<?=$spane;?>
357
									</td>
358
									<td nowrap class="listr">
359
										<?=$spans;?>
360
										<?php
361
											$k = 0;
362
											foreach ($ph2ent['hash-algorithm-option'] as $ph2ha) {
363
												if ($k++)
364
													echo ", ";
365
												echo $p2_halgos[$ph2ha];
366
											}
367
										?>
368
										<?=$spane;?>
369
									</td>
370
									<td nowrap class="list">
371
										<a href="vpn_ipsec_phase2.php?p2index=<?=$j;?>">
372
											<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" title="<?=gettext("edit phase2 entry"); ?>" width="17" height="17" border="0">
373
										</a>
374
										<a href="vpn_ipsec.php?act=delph2&p2index=<?=$j;?>" onclick="return confirm('<?=gettext("Do you really want to delete this phase2 entry?"); ?>')">
375
											<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" title="<?=gettext("delete phase2 entry"); ?>" width="17" height="17" border="0">
376
										</a>
377
									</td>
378
								</tr>
379

    
380
								<?php
381
										$j++;
382
									}
383
								?>
384
							</table>
385
						</td>
386
					</tr>
387
					<tr>
388
						<td>
389
							&nbsp;
390
						</td>
391
					</tr>
392
					<?php
393
							$i++;
394
						}
395
					if(!$counter)
396
						show_ipsec_header($ph1ent);
397
					?>
398
					<tr>
399
						<td class="list" colspan="5"></td>
400
						<td class="list">
401
							<table border="0" cellspacing="0" cellpadding="1">
402
								<tr>
403
									<td width="17"></td>
404
									<td>
405
										<a href="vpn_ipsec_phase1.php">
406
											<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="<?=gettext("add phase1 entry"); ?>" width="17" height="17" border="0">
407
										</a>
408
									</td>
409
								</tr>
410
							</table>
411
						<td>
412
					</tr>
413
					<tr>
414
						<td colspan="4">
415
							<p>
416
								<span class="vexpl">
417
									<span class="red">
418
										<strong><?=gettext("Note"); ?>:<br></strong>
419
									</span>
420
									<?=gettext("You can check your IPsec status at"); ?> <a href="diag_ipsec.php"><?=gettext("Status:IPsec"); ?></a>.
421
								</span>
422
							</p>
423
						</td>
424
					</tr>
425
				</table>
426
			</div>
427
		</td>
428
	</tr>
429
</table>
430
</form>
431
<?php include("fend.inc"); ?>
432
<script type="text/javascript">
433
function show_phase2(id, buttonid) {
434
	document.getElementById(buttonid).innerHTML='';
435
	aodiv = document.getElementById(id);
436
	aodiv.style.display = "block";
437
}
438
</script>
439
</body>
440
</html>
441

    
442
<?php
443

    
444
function show_ipsec_header($ph1ent) {
445
	global $g;
446
	if (isset($ph1ent['mobile'])) 
447
		$mobile = "&mobile=true";
448
	echo <<<EOF
449
	<tr>
450
		<td class="listhdrr"><?=gettext("Remote Gateway"); ?></td>
451
		<td class="listhdrr"><?=gettext("Mode"); ?></td>
452
		<td class="listhdrr"><?=gettext("P1 Protocol"); ?></td>
453
		<td class="listhdrr"><?=gettext("P1 Transforms"); ?></td>
454
		<td class="listhdrr"><?=gettext("P1 Description"); ?></td>
455
		<td class ="list">
456
		</td>
457
	</tr>
458

    
459
EOF;
460
	
461
}
462

    
463
?>
(202-202/220)