Project

General

Profile

Download (13.1 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
					<tr>
185
						<td class="listhdrr">Interface<br>Remote gw</td>
186
						<td class="listhdrr">P1 mode</td>
187
						<td class="listhdrr">P1 Enc. Algo</td>
188
						<td class="listhdrr">P1 Hash Algo</td>
189
						<td class="listhdr">Description</td>
190
						<td class="list" >
191
							<table border="0" cellspacing="0" cellpadding="o">
192
								<tr>
193
									<td width="17" heigth="17"></td>
194
									<td>
195
										<a href="vpn_ipsec_phase1.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="add phase1 entry" width="17" height="17" border="0"></a>
196
									</td>
197
								</tr>
198
							</table>
199
						</td>
200
					</tr>					
201
					<tr valign="top" ondblclick="document.location='vpn_ipsec_phase1.php?p1index=<?=$i;?>'">
202
						<td class="listlr">
203
							<?=$spans;?>
204
							<?php
205
								if ($ph1ent['interface']) {
206
									$iflabels = get_configured_interface_with_descr();
207
									$carpips = find_number_of_needed_carp_interfaces();
208
									for( $j=0; $j<$carpips; $j++ ) {
209
										$carpip = find_interface_ip("carp" . $j);
210
										$iflabels['carp' . $j] = "CARP{$j} ({$carpip})"; 
211
									}
212
									$if = htmlspecialchars($iflabels[$ph1ent['interface']]);
213
								}
214
								else
215
									$if = "WAN";
216

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

    
316
										if (isset( $ph2ent['disabled']) || isset($ph1ent['disabled'])) {
317
											$spans = "<span class=\"gray\">";
318
											$spane = "</span>";
319
										}
320
										else
321
											$spans = $spane = "";
322
								?>
323
								<tr valign="top" ondblclick="document.location='vpn_ipsec_phase2.php?p2index=<?=$i;?>'">
324

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

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