Project

General

Profile

Download (15 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
 *  Copyright (c)  2004, 2005 Scott Ullrich
9
 *
10
 *  Redistribution and use in source and binary forms, with or without modification, 
11
 *  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
18
 *      the documentation and/or other materials provided with the
19
 *      distribution. 
20
 *
21
 *  3. All advertising materials mentioning features or use of this software 
22
 *      must display the following acknowledgment:
23
 *      "This product includes software developed by the pfSense Project
24
 *       for use in the pfSense software distribution. (http://www.pfsense.org/). 
25
 *
26
 *  4. The names "pfSense" and "pfSense Project" must not be used to
27
 *       endorse or promote products derived from this software without
28
 *       prior written permission. For written permission, please contact
29
 *       coreteam@pfsense.org.
30
 *
31
 *  5. Products derived from this software may not be called "pfSense"
32
 *      nor may "pfSense" appear in their names without prior written
33
 *      permission of the Electric Sheep Fencing, LLC.
34
 *
35
 *  6. Redistributions of any form whatsoever must retain the following
36
 *      acknowledgment:
37
 *
38
 *  "This product includes software developed by the pfSense Project
39
 *  for use in the pfSense software distribution (http://www.pfsense.org/).
40
  *
41
 *  THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
42
 *  EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43
 *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
44
 *  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
45
 *  ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
46
 *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
47
 *  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
48
 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49
 *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
50
 *  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
51
 *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
52
 *  OF THE POSSIBILITY OF SUCH DAMAGE.
53
 *
54
 *  ====================================================================
55
 *
56
 */
57

    
58
/*
59
	pfSense_MODULE: ipsec
60
*/
61

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

    
69

    
70
global $g;
71

    
72
$pgtitle = array(gettext("Status"), gettext("IPsec"));
73
$shortcut_section = "ipsec";
74

    
75
require("guiconfig.inc");
76
include("head.inc");
77
require_once("ipsec.inc");
78

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

    
112
if (!is_array($config['ipsec']['phase1'])) {
113
	$config['ipsec']['phase1'] = array();
114
}
115

    
116
$a_phase1 = &$config['ipsec']['phase1'];
117

    
118
$status = ipsec_smp_dump_status();
119

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

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

    
151
if (is_array($status['query']) && is_array($status['query']['ikesalist']) && is_array($status['query']['ikesalist']['ikesa'])):
152
	foreach ($status['query']['ikesalist']['ikesa'] as $ikeid => $ikesa):
153
		$con_id = substr($ikesa['peerconfig'], 3);
154
		
155
		if ($ikesa['version'] == 1) {
156
			$ph1idx = substr($con_id, 0, strrpos(substr($con_id, 0, -1), '00'));
157
			$ipsecconnected[$ph1idx] = $ph1idx;
158
		} else {
159
			$ipsecconnected[$con_id] = $ph1idx = $con_id;
160
		}
161

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

    
187
			if (ipsec_phase1_status($status['query']['ikesalist']['ikesa'], $ikesa['id'])) {
188
				$icon = "pass";
189
			} elseif (!isset($config['ipsec']['enable'])) {
190
				$icon = "block";
191
			} else {
192
				$icon = "reject";
193
			}
194
?>
195
					</td>
196
					<td>
197
<?php
198
			if (!is_array($ikesa['local']))
199
				print(gettext("Unknown"));
200
			else {
201
				if (!empty($ikesa['local']['address']))
202
					print(htmlspecialchars($ikesa['local']['address']) . '<br/>' .	gettext('Port: ') . htmlspecialchars($ikesa['local']['port']));
203
				else
204
					print(gettext("Unknown"));
205
				if ($ikesa['local']['port'] == '4500')
206
					print(" NAT-T");
207
			}
208
?>
209
					</td>	
210
					<td>
211
<?php
212
			if (!is_array($ikesa['remote']))
213
				print(gettext("Unknown"));
214
			else {
215
				$identity = "";
216
				if (!empty($ikesa['remote']['identification'])) {
217
					if ($ikesa['remote']['identification'] == '%any')
218
						$identity = 'Any identifier';
219
					else
220
						$identity = htmlspecialchars($ikesa['remote']['identification']);
221
				}
222

    
223
				if (is_array($ikesa['remote']['auth']) && !empty($ikesa['remote']['auth'][0]['identity'])) {
224
					print(htmlspecialchars($ikesa['remote']['auth'][0]['identity']));
225
					print('<br/>' . $identity);
226
				} else {
227
					if (empty($identity))
228
						print(gettext("Unknown"));
229
					else
230
						print($identity);
231
				}
232
			}
233
?>
234
					</td>
235
					<td>
236
<?php
237
			if (!is_array($ikesa['remote']))
238
				print(gettext("Unknown"));
239
			else {
240
				if (!empty($ikesa['remote']['address']))
241
					print(htmlspecialchars($ikesa['remote']['address']) . '<br/>' . gettext('Port: ') . htmlspecialchars($ikesa['remote']['port']));
242
				else
243
					print(gettext("Unknown"));
244
				if ($ikesa['remote']['port'] == '4500')
245
					print(" NAT-T");
246
			}
247
?>
248
					</td>
249
					<td>
250
						IKEv<?=htmlspecialchars($ikesa['version'])?>
251
						<br/>
252
						<?=htmlspecialchars($ikesa['role'])?>
253
					</td>
254
					<td>
255
						<?=htmlspecialchars($ikesa['reauth']);?>
256
					</td>
257
					<td>
258
						<?=htmlspecialchars($ikesa['encalg'])?>
259
						<br/>
260
						<?=htmlspecialchars($ikesa['intalg'])?>
261
						<br/>
262
						<?=htmlspecialchars($ikesa['prfalg'])?>
263
						<br/>
264
						<?=htmlspecialchars($ikesa['dhgroup'])?>
265
					</td>
266
					<td>
267
<?php
268
			if ($ikesa['status'] == 'established')
269
				print('<span style="color:green">');
270
			else
271
				print('<span>');
272
?>
273
						<?=ucfirst(htmlspecialchars($ikesa['status']))?>
274
						<br/><?=htmlspecialchars($ikesa['established'])?>
275
						</span>
276
					</td>
277
					<td >
278
<?php
279
				if ($icon != "pass"):
280
?>
281
					<a href="diag_ipsec.php?act=connect&amp;ikeid=<?=$con_id; ?>" class="btn btn-xs btn-success" data-toggle="tooltip" title="Connect VPN" >
282
							<?=gettext("Connect VPN")?>
283
						</a>
284
<?php
285
				else:
286
?>
287
						<a href="diag_ipsec.php?act=ikedisconnect&amp;ikeid=<?=$con_id; ?>" class="btn btn-xs btn-danger" data-toggle="tooltip" title="Disconnect VPN">
288
							<?=gettext("Disconnect")?>
289
						</a><br />
290
						<a href="diag_ipsec.php?act=ikedisconnect&amp;ikeid=<?=$con_id; ?>&amp;ikesaid=<?=$ikesa['id']; ?>" class="btn btn-xs btn-warning" data-toggle="tooltip" title="Disconnect VPN connection">
291
							<?=gettext("Disconnect")?>
292
						</a>
293
<?php
294
				endif;
295
?>
296
					</td>
297
				</tr>
298
				<tr>
299
					<td colspan = 10>
300
<?php
301
		    if (is_array($ikesa['childsalist'])):
302
?>
303
						<div id="btnchildsa-<?=$ikeid?>">
304
							<a type="button" onclick="show_childsa('childsa-<?=$ikeid?>','btnchildsa-<?=$ikeid?>');" class="btn btn-sm btn-default" />
305
								<?=gettext('Show child SA entries')?>
306
							</a>
307
						</div>
308

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

    
364
?>
365
									</td>
366
									<td>
367
<?php
368
				print(htmlspecialchars($childsa['encalg']) . '<br/>');
369
				print(htmlspecialchars($childsa['intalg']) . '<br/>');
370
				
371
				if (!empty($childsa['prfalg']))
372
					print(htmlspecialchars($childsa['prfalg']) . '<br/>');
373
				
374
				if (!empty($childsa['dhgroup']))
375
					print(htmlspecialchars($childsa['dhgroup']) . '<br/>');
376
				
377
				if (!empty($childsa['esn']))
378
					print(htmlspecialchars($childsa['esn']) . '<br/>');
379
				
380
				print(gettext("IPComp: ") . htmlspecialchars($childsa['ipcomp']));
381
?>
382
									</td>
383
									<td>
384
<?php
385
				print(gettext("Bytes-In: ") . htmlspecialchars($childsa['bytesin']) . '<br/>');
386
				print(gettext("Packets-In: ") . htmlspecialchars($childsa['packetsin']) . '<br/>');
387
				print(gettext("Bytes-Out: ") . htmlspecialchars($childsa['bytesout']) . '<br/>');
388
				print(gettext("Packets-Out: ") . htmlspecialchars($childsa['packetsout']) . '<br/>');
389
?>
390
									</td>
391
									<td>
392
										<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')?>">
393
											<?=gettext("Disconnect")?>
394
										</a>
395
									</td>
396
								</tr>
397
<?php
398
				endforeach;
399
			endif;
400
?>
401

    
402
							</tbody>
403
						</table>
404
					</td>
405
				</tr>
406
<?php
407
		endif;
408

    
409
		unset($con_id);
410
	endforeach;
411
endif;
412

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

    
506
<script type="text/javascript">
507
//<![CDATA[
508
function show_childsa(id, buttonid) {
509
	document.getElementById(buttonid).innerHTML='';
510
	aodiv = document.getElementById(id);
511
	aodiv.style.display = "block";
512
}
513
//]]>
514
</script>
515

    
516
<?php
517
unset($status);
518
print_info_box(gettext("You can configure IPsec ") . '<a href="vpn_ipsec.php">Here</a>');
519
include("foot.inc"); ?>
(15-15/235)