Project

General

Profile

Download (13.5 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
		config_lock();
60
		$retval = vpn_ipsec_refresh_policies();
61
		$retval = vpn_ipsec_configure();
62
		config_unlock();
63
		/* reload the filter in the background */
64
		filter_configure();
65
		$savemsg = get_std_save_message($retval);
66
		if ($retval == 0) {
67
			if (file_exists($d_ipsecconfdirty_path))
68
				unlink($d_ipsecconfdirty_path);
69
		}
70
	} else if ($_POST['submit']) {
71
		$pconfig = $_POST;
72

    
73
		$config['ipsec']['enable'] = $_POST['enable'] ? true : false;
74
		
75
		write_config();
76
	}
77
}
78

    
79
if ($_GET['act'] == "delph1")
80
{
81
	if ($a_phase1[$_GET['p1index']]) {
82
		/* remove static route if interface is not WAN */
83
		if ($a_phase1[$_GET['p1index']]['interface'] <> "wan")
84
			mwexec("/sbin/route delete -host {$$a_phase1[$_GET['p1index']]['remote-gateway']}");
85

    
86
		/* remove all phase2 entries that match the ikeid */
87
		$ikeid = $a_phase1[$_GET['p1index']]['ikeid'];
88
		foreach ($a_phase2 as $p2index => $ph2tmp)
89
			if ($ph2tmp['ikeid'] == $ikeid)
90
				unset($a_phase2[$p2index]);
91

    
92
		/* remove the phase1 entry */
93
		unset($a_phase1[$_GET['p1index']]);
94
		vpn_ipsec_refresh_policies();
95
		vpn_ipsec_configure();
96
		filter_configure();
97
		write_config();
98
		header("Location: vpn_ipsec.php");
99
		exit;
100
	}
101
}
102

    
103
if ($_GET['act'] == "delph2")
104
{
105
	if ($a_phase2[$_GET['p2index']]) {
106
		/* remove the phase2 entry */
107
		unset($a_phase2[$_GET['p2index']]);
108
		vpn_ipsec_refresh_policies();
109
		vpn_ipsec_configure();
110
		filter_configure();
111
		write_config();
112
		header("Location: vpn_ipsec.php");
113
		exit;
114
	}
115
}
116

    
117
$pgtitle = array("VPN","IPsec");
118
include("head.inc");
119

    
120
?>
121

    
122

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

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

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

    
309
									<td nowrap class="listlr">
310
										<?=$spans;?>
311
											<?=$ph2ent['mode'];?>
312
										<?=$spane;?>
313
									</td>
314
									<?php if($ph2ent['mode'] == "tunnel"): ?>
315
									<td nowrap class="listr">
316
										<?=$spans;?>
317
											<?=ipsec_idinfo_to_text($ph2ent['localid']); ?>
318
										<?=$spane;?>
319
									</td>
320
									<td nowrap class="listr">
321
										<?=$spans;?>
322
											<?=ipsec_idinfo_to_text($ph2ent['remoteid']); ?>
323
										<?=$spane;?>
324
									</td>
325
									<?php endif; ?>
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">P1 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
?>
(189-189/206)