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
require("functions.inc");
40
require("guiconfig.inc");
41
require_once("ipsec.inc");
42
require_once("vpn.inc");
43

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

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

    
50
$a_phase1 = &$config['ipsec']['phase1'];
51
$a_phase2 = &$config['ipsec']['phase2'];
52

    
53
$wancfg = &$config['interfaces']['wan'];
54

    
55
$pconfig['enable'] = isset($config['ipsec']['enable']);
56

    
57
if ($_POST) {
58

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

    
73
		$config['ipsec']['enable'] = $_POST['enable'] ? true : false;
74

    
75
		if(!$config['ipsec']['enable']) {
76
			if(is_process_running("racoon")) 
77
				mwexec("killall racoon");
78
		} else {
79
			$retval = vpn_ipsec_configure();
80
		}
81

    
82
		write_config();
83
	}
84
}
85

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

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

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

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

    
124
$pgtitle = array("VPN","IPsec");
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("The IPsec tunnel configuration has been changed.<br>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("Tunnels", true, "vpn_ipsec.php");
144
				$tab_array[1] = array("Mobile clients", false, "vpn_ipsec_mobile.php");
145
				$tab_array[2] = array("Logs", false, "diag_logs_ipsec.php");
146
				display_top_tabs($tab_array);
147
			?>
148
		</td>
149
	</tr>
150
	<tr>
151
		<td>
152
			<div id="mainarea">
153
				<table border='1'>
154
				<table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
155
					<tr>
156
						<td class="vtable">
157
							<table border="0" cellspacing="2" cellpadding="0">
158
								<tr>
159
									<td>
160
										<input name="enable" type="checkbox" id="enable" value="yes" <?php if ($pconfig['enable']) echo "checked";?>>
161
									</td>
162
									<td>
163
										<strong>Enable IPsec</strong>
164
									</td>
165
								</tr>
166
							</table>
167
						</td>
168
					</tr>
169
					<tr>
170
						<td>
171
							<input name="submit" type="submit" class="formbtn" value="Save">
172
						</td>
173
					</tr>
174
				</table>
175
				<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
176
					<?php
177
						$i = 0;
178
						foreach ($a_phase1 as $ph1ent) {
179
							if (isset( $ph1ent['disabled'])) {
180
								$spans = "<span class=\"gray\">";
181
								$spane = "</span>";
182
							}
183
							else
184
								$spans = $spane = "";
185
						
186
						show_ipsec_header($ph1ent);
187
						$counter++; // used to deterimine if we need to output header manually (no records exist)
188
					?>					
189
					<tr valign="top" ondblclick="document.location='vpn_ipsec_phase1.php?p1index=<?=$i;?>'">
190
						<td class="listlr">
191
							<?=$spans;?>
192
							<?php
193
								if ($ph1ent['interface']) {
194
									$iflabels = get_configured_interface_with_descr();
195
									$carplist = get_configured_carp_interface_list();
196
									foreach ($carplist as $cif => $carpip)
197
										$iflabels[$cif] = strtoupper($cif) . " ({$carpip})"; 
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">Mode</td>
284
									<?php if($ph2ent['mode'] == "tunnel"): ?>
285
									<td class="listhdrr">Local Subnet</td>
286
									<td class="listhdrr">Remote Subnet</td>
287
									<?php endif; ?>
288
									<td class="listhdrr">P2 Protocol</td>
289
									<td class="listhdrr">P2 Transforms</td>
290
									<td class="listhdrr">P2 Auth Methods</td>
291
									<td class ="list">
292
										<a href="vpn_ipsec_phase2.php?ikeid=<?=$ph1ent['ikeid'];?><?php if (isset($ph1ent['mobile'])) echo "&mobile=true";?>">
293
											<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="add phase2 entry" width="17" height="17" border="0">
294
										</a>
295
									</td>
296
								</tr>
297
								<?php
298
									$j = 0;
299
									foreach ($a_phase2 as $ph2ent) {
300
										if ($ph2ent['ikeid'] != $ph1ent['ikeid']) {
301
											$j++;
302
											continue;
303
										}
304

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

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

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

    
438
<?php
439

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

    
456
EOF;
457
	
458
}
459

    
460
?>
(197-197/214)