Project

General

Profile

Download (13.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

    
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_configure();
60
		$savemsg = get_std_save_message($retval);
61
		if ($retval == 0) {
62
			if (file_exists($d_ipsecconfdirty_path))
63
				unlink($d_ipsecconfdirty_path);
64
		}
65
	} else if ($_POST['submit']) {
66
		$pconfig = $_POST;
67

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

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

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

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

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

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

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

    
121
$pgtitle = array("VPN","IPsec");
122
include("head.inc");
123

    
124
?>
125

    
126

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

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

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

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

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

    
428
<?php
429

    
430
function show_ipsec_header() {
431
	if (isset($ph1ent['mobile'])) $mobile = "&mobile=true";
432
	echo <<<EOF
433
	<tr>
434
		<td class="listhdrr">Local Network</td>
435
		<td class="listhdrr">Remote Network</td>
436
		<td class="listhdrr">P2 Protocol</td>
437
		<td class="listhdrr">P2 Transforms</td>
438
		<td class="listhdrr">P2 Auth Methods</td>
439
		<td class ="list">
440
			<a href="vpn_ipsec_phase2.php?ikeid={$ph1ent['ikeid']}{$mobile}">
441
				<img src="./themes/{$g['theme']}/images/icons/icon_plus.gif" title="add phase2 entry" width="17" height="17" border="0">
442
			</a>
443
		</td>
444
	</tr>
445

    
446
EOF;
447
	
448
}
449

    
450
?>
(193-193/210)