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
require("functions.inc");
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
		/* reload the filter in the background */
62
		filter_configure();
63
		$savemsg = get_std_save_message($retval);
64
		if ($retval == 0) {
65
			if (is_subsystem_dirty('ipsec'))
66
				clear_subsystem_dirty('ipsec');
67
		}
68
	} else if ($_POST['submit']) {
69
		$pconfig = $_POST;
70

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

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

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

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

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

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

    
118
?>
119

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

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

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

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

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

    
430
<?php
431

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

    
448
EOF;
449
	
450
}
451

    
452
?>
(200-200/217)