Project

General

Profile

Download (14.3 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	diag_ipsec.php
5
*/
6
/* ====================================================================
7
 *  Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved. 
8
 *  portions Copyright (C) 2008 Shrew Soft Inc <mgrooms@shrew.net>.
9
 *
10
 *  Parts of this code originally based on vpn_ipsec_sad.php from m0n0wall,
11
 *  Copyright (C) 2003-2004 Manuel Kasper (BSD 2 clause)
12
 *
13
 *  Redistribution and use in source and binary forms, with or without modification, 
14
 *  are permitted provided that the following conditions are met: 
15
 *
16
 *  1. Redistributions of source code must retain the above copyright notice,
17
 *      this list of conditions and the following disclaimer.
18
 *
19
 *  2. Redistributions in binary form must reproduce the above copyright
20
 *      notice, this list of conditions and the following disclaimer in
21
 *      the documentation and/or other materials provided with the
22
 *      distribution. 
23
 *
24
 *  3. All advertising materials mentioning features or use of this software 
25
 *      must display the following acknowledgment:
26
 *      "This product includes software developed by the pfSense Project
27
 *       for use in the pfSense software distribution. (http://www.pfsense.org/). 
28
 *
29
 *  4. The names "pfSense" and "pfSense Project" must not be used to
30
 *       endorse or promote products derived from this software without
31
 *       prior written permission. For written permission, please contact
32
 *       coreteam@pfsense.org.
33
 *
34
 *  5. Products derived from this software may not be called "pfSense"
35
 *      nor may "pfSense" appear in their names without prior written
36
 *      permission of the Electric Sheep Fencing, LLC.
37
 *
38
 *  6. Redistributions of any form whatsoever must retain the following
39
 *      acknowledgment:
40
 *
41
 *  "This product includes software developed by the pfSense Project
42
 *  for use in the pfSense software distribution (http://www.pfsense.org/).
43
  *
44
 *  THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
45
 *  EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46
 *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
47
 *  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
48
 *  ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
49
 *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
50
 *  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
51
 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52
 *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
53
 *  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54
 *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
55
 *  OF THE POSSIBILITY OF SUCH DAMAGE.
56
 *
57
 *  ====================================================================
58
 *
59
 */
60

    
61
/*
62
	pfSense_MODULE: ipsec
63
*/
64

    
65
##|+PRIV
66
##|*IDENT=page-status-ipsec
67
##|*NAME=Status: IPsec page
68
##|*DESCR=Allow access to the 'Status: IPsec' page.
69
##|*MATCH=diag_ipsec.php*
70
##|-PRIV
71

    
72

    
73
global $g;
74

    
75
$pgtitle = array(gettext("Status"), gettext("IPsec"));
76
$shortcut_section = "ipsec";
77

    
78
require("guiconfig.inc");
79
include("head.inc");
80
require_once("ipsec.inc");
81

    
82
if ($_GET['act'] == 'connect') {
83
	if (ctype_digit($_GET['ikeid'])) {
84
		$ph1ent = ipsec_get_phase1($_GET['ikeid']);
85
		if (!empty($ph1ent)) {
86
			if (empty($ph1ent['iketype']) || $ph1ent['iketype'] == 'ikev1') {
87
				$ph2entries = ipsec_get_number_of_phase2($_GET['ikeid']);
88
				for ($i = 0; $i < $ph2entries; $i++) {
89
					$connid = escapeshellarg("con{$_GET['ikeid']}00{$i}");
90
					mwexec("/usr/local/sbin/ipsec down {$connid}");
91
					mwexec("/usr/local/sbin/ipsec up {$connid}");
92
				}
93
			} else {
94
				mwexec("/usr/local/sbin/ipsec down con" . escapeshellarg($_GET['ikeid']));
95
				mwexec("/usr/local/sbin/ipsec up con" . escapeshellarg($_GET['ikeid']));
96
			}
97
		}
98
	}
99
} else if ($_GET['act'] == 'ikedisconnect') {
100
	if (ctype_digit($_GET['ikeid'])) {
101
		if (!empty($_GET['ikesaid']) && ctype_digit($_GET['ikesaid'])) {
102
			mwexec("/usr/local/sbin/ipsec down con" . escapeshellarg($_GET['ikeid']) . "[" . escapeshellarg($_GET['ikesaid']) . "]");
103
		} else {
104
			mwexec("/usr/local/sbin/ipsec down con" . escapeshellarg($_GET['ikeid']));
105
		}
106
	}
107
} else if ($_GET['act'] == 'childdisconnect') {
108
	if (ctype_digit($_GET['ikeid'])) {
109
		if (!empty($_GET['ikesaid']) && ctype_digit($_GET['ikesaid'])) {
110
			mwexec("/usr/local/sbin/ipsec down con" . escapeshellarg($_GET['ikeid']) . "{" . escapeshellarg($_GET['ikesaid']) . "}");
111
		}
112
	}
113
}
114

    
115
if (!is_array($config['ipsec']['phase1'])) {
116
	$config['ipsec']['phase1'] = array();
117
}
118

    
119
$a_phase1 = &$config['ipsec']['phase1'];
120

    
121
$status = ipsec_list_sa();
122

    
123
$tab_array = array();
124
$tab_array[] = array(gettext("Overview"), true, "diag_ipsec.php");
125
$tab_array[] = array(gettext("Leases"), false, "diag_ipsec_leases.php");
126
$tab_array[] = array(gettext("SAD"), false, "diag_ipsec_sad.php");
127
$tab_array[] = array(gettext("SPD"), false, "diag_ipsec_spd.php");
128
$tab_array[] = array(gettext("Logs"), false, "diag_logs.php?logfile=ipsec");
129
display_top_tabs($tab_array);
130
?>
131

    
132
<div class="panel panel-default">
133
	<div class="panel-heading">IPSec status</div>
134
	<div class="panel-body table responsive">
135
		<table class="table table-striped table-hover table-condensed">
136
			<thead>
137
				<tr>
138
					<th><?=gettext("Description")?></th>
139
					<th><?=gettext("Local ID")?></th>
140
					<th><?=gettext("Local IP")?></th>
141
					<th><?=gettext("Remote ID")?></th>
142
					<th><?=gettext("Remote IP")?></th>
143
					<th><?=gettext("Role")?></th>
144
					<th><?=gettext("Reauth")?></th>
145
					<th><?=gettext("Algo")?></th>
146
					<th><?=gettext("Status")?></th>
147
					<th></th>
148
				</tr>
149
			</thead>
150
			<tbody>
151
<?php
152
$ipsecconnected = array();
153

    
154
if (is_array($status)) {
155
	foreach ($status as $ikeid => $ikesa) {
156
	$con_id = substr($ikeid, 3);
157
		
158
		if ($ikesa['version'] == 1) {
159
			$ph1idx = substr($con_id, 0, strrpos(substr($con_id, 0, -1), '00'));
160
			$ipsecconnected[$ph1idx] = $ph1idx;
161
		} else {
162
			$ipsecconnected[$con_id] = $ph1idx = $con_id;
163
		}
164

    
165
		if ($ikesa['state'] == "ESTABLISHED") {
166
			$icon = "pass";
167
		} elseif (!isset($config['ipsec']['enable'])) {
168
			$icon = "block";
169
		} else {
170
			$icon = "reject";
171
		}
172
?>
173
				<tr>
174
					<td>
175
						<?=htmlspecialchars(ipsec_get_descr($ph1idx))?>
176
					</td>
177
					<td>
178
<?php
179
		if (!empty($ikesa['local-id'])) {
180
			if ($ikesa['local-id'] == '%any') {
181
				print(gettext('Any identifier'));
182
			} else {
183
				print(htmlspecialchars($ikesa['local-id']));
184
			}
185
		} else {
186
			print(gettext("Unknown"));
187
		}
188

    
189
?>
190
					</td>
191
					<td>
192
<?php
193
		if (!empty($ikesa['local-host'])) {
194
			print(htmlspecialchars($ikesa['local-host']));
195
		} else {
196
			print(gettext("Unknown"));
197
		}
198
		if (isset($ikesa['local-nat-t'])) {
199
			print(" NAT-T");
200
		}
201
?>
202
					</td>	
203
					<td>
204
<?php
205
		$identity = "";
206
		if (!empty($ikesa['remote-id'])) {
207
			if ($ikesa['remote-id'] == '%any') {
208
				$identity = 'Any identifier';
209
			} else {
210
				$identity = htmlspecialchars($ikesa['remote']['identification']);
211
			}
212
		}
213
		if (!empty($ikesa['remote-xauth-id'])) {
214
			echo htmlspecialchars($ikesa['remote-xauth-id']);
215
			echo "<br/>{$identity}";
216
		} elseif (!empty($ikesa['remote-eap-id'])) {
217
			echo htmlspecialchars($ikesa['remote-eap-id']);
218
			echo "<br/>{$identity}";
219
		} else {
220
			if (empty($identity)) {
221
				print(gettext("Unknown"));
222
			} else {
223
				print($identity);
224
			}
225
		}
226
?>
227
					</td>
228
					<td>
229
<?php
230
		if (!empty($ikesa['remote-host'])) {
231
			print(htmlspecialchars($ikesa['remote-host']));
232
		} else {
233
			print(gettext("Unknown"));
234
		}
235
		if (isset($ikesa['remote-nat-t'])) {
236
			print(" NAT-T");
237
		}
238
?>
239
					</td>
240
					<td>
241
						IKEv<?=htmlspecialchars($ikesa['version'])?>
242
						<br/>
243
<?php
244
		if ($ikesa['initiator'] == 'yes') {
245
			print("initiator");
246
		} else {
247
			print("responder");
248
		}
249
?>
250
					</td>
251
					<td>
252
						<?=htmlspecialchars($ikesa['reauth-time']) . gettext(" seconds");?>
253
					</td>
254
					<td>
255
						<?=htmlspecialchars($ikesa['encr-alg'])?>
256
						<br/>
257
						<?=htmlspecialchars($ikesa['integ-alg'])?>
258
						<br/>
259
						<?=htmlspecialchars($ikesa['prf-alg'])?>
260
						<br/>
261
						<?=htmlspecialchars($ikesa['dh-group'])?>
262
					</td>
263
					<td>
264
<?php
265
		if ($ikesa['state'] == 'ESTABLISHED') {
266
			print('<span style="color:green">');
267
		} else {
268
			print('<span>');
269
		}
270
?>
271
						<?=ucfirst(htmlspecialchars($ikesa['state']))?>
272
						<br/><?=htmlspecialchars($ikesa['established']) . gettext(" seconds ago")?>
273
						</span>
274
					</td>
275
					<td >
276
<?php
277
		if ($icon != "pass") {
278
?>
279
					<a href="diag_ipsec.php?act=connect&amp;ikeid=<?=$con_id; ?>" class="btn btn-xs btn-success" data-toggle="tooltip" title="Connect VPN" >
280
							<?=gettext("Connect VPN")?>
281
						</a>
282
<?php
283
		} else {
284
?>
285
						<a href="diag_ipsec.php?act=ikedisconnect&amp;ikeid=<?=$con_id; ?>" class="btn btn-xs btn-danger" data-toggle="tooltip" title="Disconnect VPN">
286
							<?=gettext("Disconnect")?>
287
						</a><br />
288
						<a href="diag_ipsec.php?act=ikedisconnect&amp;ikeid=<?=$con_id; ?>&amp;ikesaid=<?=$ikesa['uniqueid']; ?>" class="btn btn-xs btn-warning" data-toggle="tooltip" title="Disconnect VPN connection">
289
							<?=gettext("Disconnect")?>
290
						</a>
291
<?php
292
		}
293
?>
294
					</td>
295
				</tr>
296
				<tr>
297
					<td colspan = 10>
298
<?php
299
		if (is_array($ikesa['child-sas'])) {
300
?>
301
						<div id="btnchildsa-<?=$ikeid?>">
302
							<a type="button" onclick="show_childsa('childsa-<?=$ikeid?>','btnchildsa-<?=$ikeid?>');" class="btn btn-sm btn-default" />
303
								<?=gettext('Show child SA entries')?>
304
							</a>
305
						</div>
306

    
307
						<table class="table table-hover table-condensed" id="childsa-<?=$ikeid?>" style="display:none">
308
							<thead>
309
								<tr class="info">
310
									<th><?=gettext("Local subnets")?></th>
311
									<th><?=gettext("Local SPI(s)")?></th>
312
									<th><?=gettext("Remote subnets")?></th>
313
									<th><?=gettext("Times")?></th>
314
									<th><?=gettext("Algo")?></th>
315
									<th><?=gettext("Stats")?></th>
316
									<th><!-- Buttons --></th>
317
								</tr>
318
							</thead>
319
							<tbody>
320
<?php
321
			foreach ($ikesa['child-sas'] as $childid => $childsa) {
322
?>
323
								<tr>
324
									<td>
325
<?php
326
				if (is_array($childsa['local-ts'])) {
327
					foreach ($childsa['local-ts'] as $lnets) {
328
						print(htmlspecialchars(ipsec_fixup_network($lnets)) . "<br />");
329
					}
330
				} else {
331
					print(gettext("Unknown"));
332
				}
333
?>
334
									</td>
335
									<td>
336
<?php
337
				if (isset($childsa['spi-in'])) {
338
					print(gettext("Local: ") . htmlspecialchars($childsa['spi-in']));
339
				}
340
					
341
				if (isset($childsa['spi-out'])) {
342
					print('<br/>' . gettext('Remote: ') . htmlspecialchars($childsa['spi-out']));
343
				}
344
?>
345
									</td>
346
									<td>
347
<?php
348
				if (is_array($childsa['remote-ts'])) {
349
					foreach ($childsa['remote-ts'] as $rnets) {
350
						print(htmlspecialchars(ipsec_fixup_network($rnets)) . '<br />');
351
					}
352
				} else {
353
					print(gettext("Unknown"));
354
				}
355
?>
356
									</td>
357
									<td>
358
<?php
359
				print(gettext("Rekey: ") . htmlspecialchars($childsa['rekey-time']) . gettext(" seconds"));
360
				print('<br/>' . gettext('Life: ') . htmlspecialchars($childsa['life-time']) . gettext(" seconds"));
361
				print('<br/>' . gettext('Install: ') .htmlspecialchars($childsa['install-time']) . gettext(" seconds"));
362

    
363
?>
364
									</td>
365
									<td>
366
<?php
367
				print(htmlspecialchars($childsa['encr-alg']) . '<br/>');
368
				print(htmlspecialchars($childsa['integ-alg']) . '<br/>');
369
				
370
				if (!empty($childsa['prf-alg'])) {
371
					print(htmlspecialchars($childsa['prf-alg']) . '<br/>');
372
				}
373
				if (!empty($childsa['dh-group'])) {
374
					print(htmlspecialchars($childsa['dh-group']) . '<br/>');
375
				}
376
				if (!empty($childsa['esn'])) {
377
					print(htmlspecialchars($childsa['esn']) . '<br/>');
378
				}
379
				
380
				print(gettext("IPComp: "));
381
				if (!empty($childsa['cpi-in']) || !empty($childsa['cpi-out'])) {
382
					print(htmlspecialchars($childsa['cpi-in']) . " " . htmlspecialchars($childsa['cpi-out']));
383
				} else {
384
					print(gettext('none'));
385
				}
386
?>
387
									</td>
388
									<td>
389
<?php
390
				print(gettext("Bytes-In: ") . htmlspecialchars($childsa['bytes-in']) . '<br/>');
391
				print(gettext("Packets-In: ") . htmlspecialchars($childsa['packets-in']) . '<br/>');
392
				print(gettext("Bytes-Out: ") . htmlspecialchars($childsa['bytes-out']) . '<br/>');
393
				print(gettext("Packets-Out: ") . htmlspecialchars($childsa['packets-out']) . '<br/>');
394
?>
395
									</td>
396
									<td>
397
										<a href="diag_ipsec.php?act=childdisconnect&amp;ikeid=<?=$con_id; ?>&amp;ikesaid=<?=$childsa['reqid']; ?>" class="btn btn-xs btn-warning" data-toggle="tooltip" title="<?=gettext('Disconnect Child SA')?>">
398
											<?=gettext("Disconnect")?>
399
										</a>
400
									</td>
401
								</tr>
402
<?php
403
			}
404
		}
405
?>
406

    
407
							</tbody>
408
						</table>
409
					</td>
410
				</tr>
411
<?php
412
	}
413

    
414
		unset($con_id);
415
}
416

    
417
$rgmap = array();
418
foreach ($a_phase1 as $ph1ent) {
419
	if (isset($ph1ent['disabled'])) {
420
		continue;
421
	}
422
		
423
	$rgmap[$ph1ent['remote-gateway']] = $ph1ent['remote-gateway'];
424
	
425
	if ($ipsecconnected[$ph1ent['ikeid']]) {
426
		continue;
427
	}
428
?>
429
				<tr>
430
					<td>
431
<?php
432
	print(htmlspecialchars($ph1ent['descr']));
433
?>
434
					</td>
435
					<td>
436
<?php
437
	list ($myid_type, $myid_data) = ipsec_find_id($ph1ent, "local");
438
	if (empty($myid_data))
439
		print(gettext("Unknown"));
440
	else
441
		print(htmlspecialchars($myid_data));
442
?>
443
					</td>
444
					<td>
445
<?php
446
	$ph1src = ipsec_get_phase1_src($ph1ent);
447
	
448
	if (empty($ph1src))
449
		print(gettext("Unknown"));
450
	else
451
		print(htmlspecialchars($ph1src));
452
?>
453
					</td>
454
					<td>
455
<?php
456
	list ($peerid_type, $peerid_data) = ipsec_find_id($ph1ent, "peer", $rgmap);
457
	if (empty($peerid_data))
458
		print(gettext("Unknown"));
459
	else
460
		print(htmlspecialchars($peerid_data));
461
?>
462
					</td>
463
					<td>
464
<?php
465
	$ph1src = ipsec_get_phase1_dst($ph1ent);
466
	if (empty($ph1src))
467
		print(gettext("Unknown"));
468
	else
469
		print(htmlspecialchars($ph1src));
470
?>
471
					</td>
472
					<td>
473
					</td>
474
					<td>
475
					</td>
476
					<td>
477
					</td>
478
<?php
479
	if (isset($ph1ent['mobile'])) {
480
?>
481
					<td>
482
						<?=gettext("Awaiting connections")?>
483
					</td>
484
					<td>
485
					</td>
486
<?php
487
	} else {
488
?>
489
					<td>
490
						<?=gettext("Disconnected")?>
491
					</td>
492
					<td >
493
						<a href="diag_ipsec.php?act=connect&amp;ikeid=<?=$ph1ent['ikeid']; ?>" class="btn btn-xs btn-success">
494
							<?=gettext("Connect VPN")?>
495
						</a>
496
					</td>
497
<?php
498
	}
499
?>
500
					<td>
501
					</td>
502
				</tr>
503
<?php
504
}
505
unset($ipsecconnected, $phase1, $rgmap);
506
?>
507
			</tbody>
508
		</table>
509
	</div>
510
</div>
511

    
512
<script type="text/javascript">
513
//<![CDATA[
514
function show_childsa(id, buttonid) {
515
	document.getElementById(buttonid).innerHTML='';
516
	aodiv = document.getElementById(id);
517
	aodiv.style.display = "block";
518
}
519
//]]>
520
</script>
521

    
522
<?php
523
unset($status);
524
print_info_box(gettext("You can configure IPsec ") . '<a href="vpn_ipsec.php">Here</a>');
525
include("foot.inc"); ?>
(15-15/234)