Project

General

Profile

Download (13.7 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

    
40
require("guiconfig.inc");
41

    
42
if (!is_array($config['ipsec']['phase1']))
43
	$config['ipsec']['phase1'] = array();
44

    
45
if (!is_array($config['ipsec']['phase2']))
46
	$config['ipsec']['phase2'] = array();
47

    
48
$a_phase1 = &$config['ipsec']['phase1'];
49
$a_phase2 = &$config['ipsec']['phase2'];
50

    
51
$wancfg = &$config['interfaces']['wan'];
52

    
53
$pconfig['enable'] = isset($config['ipsec']['enable']);
54

    
55
if ($_POST) {
56

    
57
	if ($_POST['apply']) {
58
		$retval = 0;
59
		$retval = vpn_ipsec_refresh_policies();
60
		$retval = vpn_ipsec_configure();
61
		$savemsg = get_std_save_message($retval);
62
		if ($retval == 0) {
63
			if (file_exists($d_ipsecconfdirty_path))
64
				unlink($d_ipsecconfdirty_path);
65
		}
66
	} else if ($_POST['submit']) {
67
		$pconfig = $_POST;
68

    
69
		$config['ipsec']['enable'] = $_POST['enable'] ? true : false;
70
		
71
		write_config();
72

    
73
		$retval = 0;
74
		config_lock();
75
		$retval = vpn_ipsec_refresh_policies();
76
		$retval = vpn_ipsec_configure();
77
		config_unlock();
78
		/* reload the filter in the background */
79
		filter_configure();
80

    
81
		$savemsg = get_std_save_message($retval);
82
		if ($retval == 0) {
83
			if (file_exists($d_ipsecconfdirty_path))
84
				unlink($d_ipsecconfdirty_path);
85
		}
86
	}
87
}
88

    
89
if ($_GET['act'] == "delph1")
90
{
91
	if ($a_phase1[$_GET['p1index']]) {
92
		/* remove static route if interface is not WAN */
93
		if ($a_phase1[$_GET['p1index']]['interface'] <> "wan")
94
			mwexec("/sbin/route delete -host {$$a_phase1[$_GET['p1index']]['remote-gateway']}");
95

    
96
		/* remove all phase2 entries that match the ikeid */
97
		$ikeid = $a_phase1[$_GET['p1index']]['ikeid'];
98
		foreach ($a_phase2 as $p2index => $ph2tmp)
99
			if ($ph2tmp['ikeid'] == $ikeid)
100
				unset($a_phase2[$p2index]);
101

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

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

    
127
$pgtitle = array("VPN","IPsec");
128
include("head.inc");
129

    
130
?>
131

    
132

    
133
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
134
<?php include("fbegin.inc"); ?>
135
<form action="vpn_ipsec.php" method="post">
136
<?php
137
	if ($savemsg)
138
		print_info_box($savemsg);
139
	if ($pconfig['enable'] && file_exists($d_ipsecconfdirty_path))
140
		print_info_box_np("The IPsec tunnel configuration has been changed.<br>You must apply the changes in order for them to take effect.");
141
?>
142
<table width="100%" border="0" cellpadding="0" cellspacing="0">
143
	<tr>
144
		<td class="tabnavtbl">
145
			<?php
146
				$tab_array = array();
147
				$tab_array[0] = array("Tunnels", true, "vpn_ipsec.php");
148
				$tab_array[1] = array("Mobile clients", false, "vpn_ipsec_mobile.php");
149
				display_top_tabs($tab_array);
150
			?>
151
		</td>
152
	</tr>
153
	<tr>
154
		<td>
155
			<div id="mainarea">
156
				<table border='1'>
157
				<table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
158
					<tr>
159
						<td class="vtable">
160
							<table border="0" cellspacing="2" cellpadding="0">
161
								<tr>
162
									<td>
163
										<input name="enable" type="checkbox" id="enable" value="yes" <?php if ($pconfig['enable']) echo "checked";?>>
164
									</td>
165
									<td>
166
										<strong>Enable IPsec</strong>
167
									</td>
168
								</tr>
169
							</table>
170
						</td>
171
					</tr>
172
					<tr>
173
						<td>
174
							<input name="submit" type="submit" class="formbtn" value="Save">
175
						</td>
176
					</tr>
177
				</table>
178
				<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
179
					<?php
180
						$i = 0;
181
						foreach ($a_phase1 as $ph1ent) {
182
							if (isset( $ph1ent['disabled'])) {
183
								$spans = "<span class=\"gray\">";
184
								$spane = "</span>";
185
							}
186
							else
187
								$spans = $spane = "";
188
						
189
						show_ipsec_header($ph1ent);
190
						$counter++; // used to deterimine if we need to output header manually (no records exist)
191
					?>					
192
					<tr valign="top" ondblclick="document.location='vpn_ipsec_phase1.php?p1index=<?=$i;?>'">
193
						<td class="listlr">
194
							<?=$spans;?>
195
							<?php
196
								if ($ph1ent['interface']) {
197
									$iflabels = get_configured_interface_with_descr();
198
									$carpips = find_number_of_needed_carp_interfaces();
199
									for( $j=0; $j<$carpips; $j++ ) {
200
										$carpip = find_interface_ip("carp" . $j);
201
										$iflabels['carp' . $j] = "CARP{$j} ({$carpip})"; 
202
									}
203
									$if = htmlspecialchars($iflabels[$ph1ent['interface']]);
204
								}
205
								else
206
									$if = "WAN";
207

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

    
310
										if (isset( $ph2ent['disabled']) || isset($ph1ent['disabled'])) {
311
											$spans = "<span class=\"gray\">";
312
											$spane = "</span>";
313
										}
314
										else
315
											$spans = $spane = "";
316
								?>
317
								<tr valign="top" ondblclick="document.location='vpn_ipsec_phase2.php?p2index=<?=$i;?>'">
318

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

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

    
443
<?php
444

    
445
function show_ipsec_header() {
446
	if (isset($ph1ent['mobile'])) $mobile = "&mobile=true";
447
	echo <<<EOF
448
	<tr>
449
		<td class="listhdrr">Remote Gateway</td>
450
		<td class="listhdrr">Mode</td>
451
		<td class="listhdrr">P1 Protocol</td>
452
		<td class="listhdrr">P1 Transforms</td>
453
		<td class="listhdrr">P1 Description</td>
454
		<td class ="list">
455
			<a href="vpn_ipsec_phase2.php?ikeid={$ph1ent['ikeid']}{$mobile}">
456
				<img src="./themes/{$g['theme']}/images/icons/icon_plus.gif" title="add phase2 entry" width="17" height="17" border="0">
457
			</a>
458
		</td>
459
	</tr>
460

    
461
EOF;
462
	
463
}
464

    
465
?>
(186-186/203)