Project

General

Profile

Download (13.5 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
<?php
2
/*
3
	vpn_ipsec.php
4 e2411886 Scott Ullrich
	part of m0n0wall (http://m0n0.ch/wall)
5 574a2b47 Scott Ullrich
6 e2411886 Scott Ullrich
	Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>.
7 a93e56c5 Matthew Grooms
	Copyright (C) 2008 Shrew Soft Inc
8 cfc707f7 Scott Ullrich
	All rights reserved.
9 574a2b47 Scott Ullrich
10 5b237745 Scott Ullrich
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12 574a2b47 Scott Ullrich
13 5b237745 Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15 574a2b47 Scott Ullrich
16 5b237745 Scott Ullrich
	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 574a2b47 Scott Ullrich
20 5b237745 Scott Ullrich
	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 6b07c15a Matthew Grooms
##|+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 5b237745 Scott Ullrich
require("guiconfig.inc");
40 7a927e67 Scott Ullrich
require_once("functions.inc");
41
require_once("filter.inc");
42
require_once("shaper.inc");
43 483e6de8 Scott Ullrich
require_once("ipsec.inc");
44
require_once("vpn.inc");
45 5b237745 Scott Ullrich
46 a93e56c5 Matthew Grooms
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 e2411886 Scott Ullrich
$wancfg = &$config['interfaces']['wan'];
56 5b237745 Scott Ullrich
57
$pconfig['enable'] = isset($config['ipsec']['enable']);
58
59
if ($_POST) {
60
61
	if ($_POST['apply']) {
62
		$retval = 0;
63 647c7c48 Seth Mos
		$retval = vpn_ipsec_refresh_policies();
64 3851094f Scott Ullrich
		$retval = vpn_ipsec_configure();
65 04b46591 Ermal Lu?i
		/* reload the filter in the background */
66
		filter_configure();
67 5b237745 Scott Ullrich
		$savemsg = get_std_save_message($retval);
68
		if ($retval == 0) {
69 a368a026 Ermal Lu?i
			if (is_subsystem_dirty('ipsec'))
70
				clear_subsystem_dirty('ipsec');
71 5b237745 Scott Ullrich
		}
72
	} else if ($_POST['submit']) {
73
		$pconfig = $_POST;
74 574a2b47 Scott Ullrich
75 5b237745 Scott Ullrich
		$config['ipsec']['enable'] = $_POST['enable'] ? true : false;
76 c20acc35 Scott Ullrich
77
		if(!$config['ipsec']['enable']) {
78
			if(is_process_running("racoon")) 
79
				mwexec("killall racoon");
80
		} else {
81
			$retval = vpn_ipsec_configure();
82
		}
83
84 5b237745 Scott Ullrich
		write_config();
85
	}
86
}
87
88 a93e56c5 Matthew Grooms
if ($_GET['act'] == "delph1")
89
{
90
	if ($a_phase1[$_GET['p1index']]) {
91 6de5d673 Seth Mos
		/* remove static route if interface is not WAN */
92 99bbd213 Matthew Grooms
		if ($a_phase1[$_GET['p1index']]['interface'] <> "wan")
93 fbc8af8f sullrich
			mwexec("/sbin/route delete -host {$a_phase1[$_GET['p1index']]['remote-gateway']}");
94 a93e56c5 Matthew Grooms
95
		/* remove all phase2 entries that match the ikeid */
96
		$ikeid = $a_phase1[$_GET['p1index']]['ikeid'];
97 99bbd213 Matthew Grooms
		foreach ($a_phase2 as $p2index => $ph2tmp)
98
			if ($ph2tmp['ikeid'] == $ikeid)
99 a93e56c5 Matthew Grooms
				unset($a_phase2[$p2index]);
100
101
		/* remove the phase1 entry */
102
		unset($a_phase1[$_GET['p1index']]);
103 647c7c48 Seth Mos
		vpn_ipsec_refresh_policies();
104
		vpn_ipsec_configure();
105 a93e56c5 Matthew Grooms
		write_config();
106 72bd8df5 Ermal Lu?i
		filter_configure();
107 a93e56c5 Matthew Grooms
		header("Location: vpn_ipsec.php");
108
		exit;
109
	}
110
}
111
112
if ($_GET['act'] == "delph2")
113
{
114
	if ($a_phase2[$_GET['p2index']]) {
115
		/* remove the phase2 entry */
116
		unset($a_phase2[$_GET['p2index']]);
117 647c7c48 Seth Mos
		vpn_ipsec_refresh_policies();
118
		vpn_ipsec_configure();
119 3fdb04a6 Scott Ullrich
		filter_configure();
120 5b237745 Scott Ullrich
		write_config();
121
		header("Location: vpn_ipsec.php");
122
		exit;
123
	}
124
}
125 4df96eff Scott Ullrich
126 d88c6a9f Scott Ullrich
$pgtitle = array("VPN","IPsec");
127 4df96eff Scott Ullrich
include("head.inc");
128
129 53d4b84d Scott Ullrich
?>
130 422f27c0 Scott Ullrich
131
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
132 5b237745 Scott Ullrich
<?php include("fbegin.inc"); ?>
133
<form action="vpn_ipsec.php" method="post">
134 323d040b Scott Ullrich
<?php
135 a93e56c5 Matthew Grooms
	if ($savemsg)
136
		print_info_box($savemsg);
137 a368a026 Ermal Lu?i
	if ($pconfig['enable'] && is_subsystem_dirty('ipsec'))
138 a93e56c5 Matthew Grooms
		print_info_box_np("The IPsec tunnel configuration has been changed.<br>You must apply the changes in order for them to take effect.");
139 574a2b47 Scott Ullrich
?>
140 a93e56c5 Matthew Grooms
<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("Tunnels", true, "vpn_ipsec.php");
146 3462a529 Matthew Grooms
				$tab_array[1] = array("Mobile clients", false, "vpn_ipsec_mobile.php");
147 09725e76 Chris Buechler
				$tab_array[2] = array("Logs", false, "diag_logs_ipsec.php");
148 a93e56c5 Matthew Grooms
				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 667725ce Matthew Grooms
							<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>Enable IPsec</strong>
165
									</td>
166
								</tr>
167
							</table>
168 a93e56c5 Matthew Grooms
						</td>
169
					</tr>
170
					<tr>
171
						<td>
172
							<input name="submit" type="submit" class="formbtn" value="Save">
173
						</td>
174
					</tr>
175
				</table>
176
				<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
177 5bba8dfb Scott Ullrich
					<?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 96162327 Scott Ullrich
						
187
						show_ipsec_header($ph1ent);
188 4494cf6a Chris Buechler
						$counter++; // used to determine if we need to output header manually (no records exist)
189 96162327 Scott Ullrich
					?>					
190 a0d4c5da Matthew Grooms
					<tr valign="top" ondblclick="document.location='vpn_ipsec_phase1.php?p1index=<?=$i;?>'">
191
						<td class="listlr">
192 a93e56c5 Matthew Grooms
							<?=$spans;?>
193
							<?php
194
								if ($ph1ent['interface']) {
195
									$iflabels = get_configured_interface_with_descr();
196 abcb2bed Ermal Lu?i
									$carplist = get_configured_carp_interface_list();
197
									foreach ($carplist as $cif => $carpip)
198
										$iflabels[$cif] = strtoupper($cif) . " ({$carpip})"; 
199 a93e56c5 Matthew Grooms
									$if = htmlspecialchars($iflabels[$ph1ent['interface']]);
200
								}
201
								else
202
									$if = "WAN";
203
204 3462a529 Matthew Grooms
								if (!isset($ph1ent['mobile']))
205
									echo $if."<br>".$ph1ent['remote-gateway'];
206
								else
207
									echo $if."<br><strong>Mobile Client</strong>";
208 a93e56c5 Matthew Grooms
							?>
209
							<?=$spane;?>
210
						</td>
211 a0d4c5da Matthew Grooms
						<td class="listr">
212 a93e56c5 Matthew Grooms
							<?=$spans;?>
213
							<?=$ph1ent['mode'];?>
214
							<?=$spane;?>
215
						</td>
216 a0d4c5da Matthew Grooms
						<td class="listr">
217 a93e56c5 Matthew Grooms
							<?=$spans;?>
218
							<?=$p1_ealgos[$ph1ent['encryption-algorithm']['name']]['name'];?>
219
							<?php
220
								if ($ph1ent['encryption-algorithm']['keylen']) {
221
									if ($ph1ent['encryption-algorithm']['keylen']=="auto")
222
										echo " (auto)";
223
									else
224
										echo " ({$ph1ent['encryption-algorithm']['keylen']} bits)";
225
								}
226
							?>
227
							<?=$spane;?>
228
						</td>
229 a0d4c5da Matthew Grooms
						<td class="listr">
230 a93e56c5 Matthew Grooms
							<?=$spans;?>
231
							<?=$p1_halgos[$ph1ent['hash-algorithm']];?>
232
							<?=$spane;?>
233
						</td>
234 b9056c39 Scott Ullrich
						<td class="listbg">
235 a93e56c5 Matthew Grooms
							<?=$spans;?>
236 b9056c39 Scott Ullrich
							<?=htmlspecialchars($ph1ent['descr']);?>&nbsp;
237 a93e56c5 Matthew Grooms
							<?=$spane;?>
238
						</td>
239
						<td valign="middle" nowrap class="list">
240
							<table border="0" cellspacing="0" cellpadding="1">
241
								<tr>
242
									<td>
243
										<a href="vpn_ipsec_phase1.php?p1index=<?=$i;?>">
244
											<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" title="edit phase1 entry" width="17" height="17" border="0">
245
										</a>
246
									</td>
247
									<td>
248
										<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?')">
249
											<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" title="delete phase1 entry" width="17" height="17" border="0">
250
										</a>
251
									</td>
252
								</tr>
253 fce61eda Matthew Grooms
								<?php if (!isset($ph1ent['mobile'])): ?>
254 a93e56c5 Matthew Grooms
								<tr>
255
									<td>
256
									</td>
257
									<td>
258
										<a href="vpn_ipsec_phase1.php?dup=<?=$i;?>">
259
											<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="copy phase1 entry" width="17" height="17" border="0">
260
										</a>
261
									</td>
262
								</tr>
263 fce61eda Matthew Grooms
								<?php endif; ?>
264 a93e56c5 Matthew Grooms
							</table>
265
						</td>
266
					</tr>
267
					<tr>
268 abd378bf Scott Ullrich
						<td class="listrborder" colspan="5">
269 0a95b653 Scott Ullrich
							<div id="shph2but-<?=$i?>">
270 e1b74950 Scott Ullrich
								<?php
271
									$phase2count=0;
272 b2a189a8 Scott Ullrich
									foreach ($a_phase2 as $ph2ent) {
273 c82c89ac Scott Ullrich
										if ($ph2ent['ikeid'] != $ph1ent['ikeid']) 
274 b2a189a8 Scott Ullrich
											continue;
275
										if (isset( $ph2ent['disabled']) || isset($ph1ent['disabled'])) 
276
											continue;
277 e1b74950 Scott Ullrich
										$phase2count++;
278 b2a189a8 Scott Ullrich
									}
279 e1b74950 Scott Ullrich
								?>								
280
								<input  type="button" onClick="show_phase2('tdph2-<?=$i?>','shph2but-<?=$i?>')" value="+"></input> - Show <?=$phase2count?> Phase-2 entries</a>
281 0a95b653 Scott Ullrich
							</div>
282
							<table class="tabcont" width="100%" height="100%" border="0" cellspacing="0" cellpadding="0" id="tdph2-<?=$i?>" style="display:none">
283 a93e56c5 Matthew Grooms
								<tr>
284 4b96b367 mgrooms
									<td class="listhdrr">Mode</td>
285
									<?php if($ph2ent['mode'] == "tunnel"): ?>
286 fabd8cdb Seth Mos
									<td class="listhdrr">Local Subnet</td>
287
									<td class="listhdrr">Remote Subnet</td>
288 4b96b367 mgrooms
									<?php endif; ?>
289 fabd8cdb Seth Mos
									<td class="listhdrr">P2 Protocol</td>
290
									<td class="listhdrr">P2 Transforms</td>
291
									<td class="listhdrr">P2 Auth Methods</td>
292 a93e56c5 Matthew Grooms
									<td class ="list">
293 3462a529 Matthew Grooms
										<a href="vpn_ipsec_phase2.php?ikeid=<?=$ph1ent['ikeid'];?><?php if (isset($ph1ent['mobile'])) echo "&mobile=true";?>">
294 a93e56c5 Matthew Grooms
											<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="add phase2 entry" width="17" height="17" border="0">
295
										</a>
296
									</td>
297
								</tr>
298
								<?php
299
									$j = 0;
300
									foreach ($a_phase2 as $ph2ent) {
301
										if ($ph2ent['ikeid'] != $ph1ent['ikeid']) {
302
											$j++;
303
											continue;
304
										}
305
306
										if (isset( $ph2ent['disabled']) || isset($ph1ent['disabled'])) {
307
											$spans = "<span class=\"gray\">";
308
											$spane = "</span>";
309
										}
310
										else
311
											$spans = $spane = "";
312
								?>
313 4da0e32a Seth Mos
								<tr valign="top" ondblclick="document.location='vpn_ipsec_phase2.php?p2index=<?=$j;?>'">
314 3462a529 Matthew Grooms
315 a0d4c5da Matthew Grooms
									<td nowrap class="listlr">
316 4b96b367 mgrooms
										<?=$spans;?>
317
											<?=$ph2ent['mode'];?>
318
										<?=$spane;?>
319
									</td>
320
									<?php if($ph2ent['mode'] == "tunnel"): ?>
321
									<td nowrap class="listr">
322 a93e56c5 Matthew Grooms
										<?=$spans;?>
323 3462a529 Matthew Grooms
											<?=ipsec_idinfo_to_text($ph2ent['localid']); ?>
324 a93e56c5 Matthew Grooms
										<?=$spane;?>
325
									</td>
326 a0d4c5da Matthew Grooms
									<td nowrap class="listr">
327 a93e56c5 Matthew Grooms
										<?=$spans;?>
328 3462a529 Matthew Grooms
											<?=ipsec_idinfo_to_text($ph2ent['remoteid']); ?>
329 a93e56c5 Matthew Grooms
										<?=$spane;?>
330
									</td>
331 4b96b367 mgrooms
									<?php endif; ?>
332 a0d4c5da Matthew Grooms
									<td nowrap class="listr">
333 a93e56c5 Matthew Grooms
										<?=$spans;?>
334 3462a529 Matthew Grooms
											<?php echo $p2_protos[$ph2ent['protocol']];	?>
335 a93e56c5 Matthew Grooms
										<?=$spane;?>
336
									</td>
337 a0d4c5da Matthew Grooms
									<td class="listr">
338 a93e56c5 Matthew Grooms
										<?=$spans;?>
339
										<?php
340
											$k = 0;
341
											foreach ($ph2ent['encryption-algorithm-option'] as $ph2ea) {
342
												if ($k++)
343
													echo ", ";
344
												echo $p2_ealgos[$ph2ea['name']]['name'];
345
												if ($ph2ea['keylen']) {
346
													if ($ph2ea['keylen']=="auto")
347
														echo " (auto)";
348
													else
349
														echo " ({$ph2ea['keylen']} bits)";
350
												}
351
											}
352
										?>
353
										<?=$spane;?>
354
									</td>
355 a0d4c5da Matthew Grooms
									<td nowrap class="listr">
356 a93e56c5 Matthew Grooms
										<?=$spans;?>
357
										<?php
358
											$k = 0;
359
											foreach ($ph2ent['hash-algorithm-option'] as $ph2ha) {
360
												if ($k++)
361
													echo ", ";
362
												echo $p2_halgos[$ph2ha];
363
											}
364
										?>
365
										<?=$spane;?>
366
									</td>
367
									<td nowrap class="list">
368
										<a href="vpn_ipsec_phase2.php?p2index=<?=$j;?>">
369
											<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" title="edit phase2 entry" width="17" height="17" border="0">
370
										</a>
371
										<a href="vpn_ipsec.php?act=delph2&p2index=<?=$j;?>" onclick="return confirm('Do you really want to delete this phase2 entry?')">
372
											<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" title="delete phase2 entry" width="17" height="17" border="0">
373
										</a>
374
									</td>
375
								</tr>
376 3462a529 Matthew Grooms
377 a93e56c5 Matthew Grooms
								<?php
378
										$j++;
379
									}
380
								?>
381
							</table>
382
						</td>
383
					</tr>
384 0a95b653 Scott Ullrich
					<tr>
385
						<td>
386
							&nbsp;
387
						</td>
388
					</tr>
389 a93e56c5 Matthew Grooms
					<?php
390
							$i++;
391
						}
392 96162327 Scott Ullrich
					if(!$counter)
393 83221d3b sullrich
						show_ipsec_header($ph1ent);
394 5b237745 Scott Ullrich
					?>
395 a93e56c5 Matthew Grooms
					<tr>
396
						<td class="list" colspan="5"></td>
397
						<td class="list">
398
							<table border="0" cellspacing="0" cellpadding="1">
399
								<tr>
400
									<td width="17"></td>
401
									<td>
402
										<a href="vpn_ipsec_phase1.php">
403
											<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="add phase1 entry" width="17" height="17" border="0">
404
										</a>
405
									</td>
406
								</tr>
407
							</table>
408
						<td>
409
					</tr>
410
					<tr>
411
						<td colspan="4">
412
							<p>
413
								<span class="vexpl">
414
									<span class="red">
415
										<strong>Note:<br></strong>
416
									</span>
417
									You can check your IPsec status at <a href="diag_ipsec.php">Status:IPsec</a>.
418
								</span>
419
							</p>
420
						</td>
421
					</tr>
422
				</table>
423
			</div>
424
		</td>
425 5b237745 Scott Ullrich
	</tr>
426
</table>
427
</form>
428
<?php include("fend.inc"); ?>
429 0a95b653 Scott Ullrich
<script type="text/javascript">
430
function show_phase2(id, buttonid) {
431
	document.getElementById(buttonid).innerHTML='';
432
	aodiv = document.getElementById(id);
433
	aodiv.style.display = "block";
434
}
435
</script>
436 323d040b Scott Ullrich
</body>
437
</html>
438 96162327 Scott Ullrich
439
<?php
440
441 afcda0d0 sullrich
function show_ipsec_header($ph1ent) {
442
	global $g;
443 83221d3b sullrich
	if (isset($ph1ent['mobile'])) 
444
		$mobile = "&mobile=true";
445 96162327 Scott Ullrich
	echo <<<EOF
446
	<tr>
447 fabd8cdb Seth Mos
		<td class="listhdrr">Remote Gateway</td>
448
		<td class="listhdrr">Mode</td>
449
		<td class="listhdrr">P1 Protocol</td>
450
		<td class="listhdrr">P1 Transforms</td>
451 87e07f52 mgrooms
		<td class="listhdrr">P1 Description</td>
452 96162327 Scott Ullrich
		<td class ="list">
453
		</td>
454
	</tr>
455
456
EOF;
457
	
458
}
459
460 04831121 Bill Marquette
?>