Project

General

Profile

Download (13.4 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">Local Subnet</td>
289
									<td class="listhdrr">Remote Subnet</td>
290
									<td class="listhdrr">P2 Protocol</td>
291
									<td class="listhdrr">P2 Transforms</td>
292
									<td class="listhdrr">P2 Auth Methods</td>
293
									<td class ="list">
294
										<a href="vpn_ipsec_phase2.php?ikeid=<?=$ph1ent['ikeid'];?><?php if (isset($ph1ent['mobile'])) echo "&mobile=true";?>">
295
											<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="add phase2 entry" width="17" height="17" border="0">
296
										</a>
297
									</td>
298
								</tr>
299
								<?php
300
									$j = 0;
301
									foreach ($a_phase2 as $ph2ent) {
302
										if ($ph2ent['ikeid'] != $ph1ent['ikeid']) {
303
											$j++;
304
											continue;
305
										}
306

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

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

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

    
433
<?php
434

    
435
function show_ipsec_header() {
436
	if (isset($ph1ent['mobile'])) $mobile = "&mobile=true";
437
	echo <<<EOF
438
	<tr>
439
		<td class="listhdrr">Remote Gateway</td>
440
		<td class="listhdrr">Mode</td>
441
		<td class="listhdrr">P1 Protocol</td>
442
		<td class="listhdrr">P1 Transforms</td>
443
		<td class="listhdrr">P2 DEscription</td>
444
		<td class ="list">
445
			<a href="vpn_ipsec_phase2.php?ikeid={$ph1ent['ikeid']}{$mobile}">
446
				<img src="./themes/{$g['theme']}/images/icons/icon_plus.gif" title="add phase2 entry" width="17" height="17" border="0">
447
			</a>
448
		</td>
449
	</tr>
450

    
451
EOF;
452
	
453
}
454

    
455
?>
(199-199/216)