Project

General

Profile

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

    
60
/*
61
	pfSense_MODULE: ipsec
62
*/
63

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

    
71

    
72
global $g;
73

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

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

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

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

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

    
120
$status = ipsec_list_sa();
121

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

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

    
153
if (is_array($status)) {
154
	foreach ($status as $ikeid => $ikesa) {
155
	$con_id = substr($ikeid, 3);
156

    
157
		if ($ikesa['version'] == 1) {
158
			$ph1idx = substr($con_id, 0, strrpos(substr($con_id, 0, -1), '00'));
159
			$ipsecconnected[$ph1idx] = $ph1idx;
160
		} else {
161
			$ipsecconnected[$con_id] = $ph1idx = $con_id;
162
		}
163

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

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

    
318
						<table class="table table-hover table-condensed" id="childsa-<?=$ikeid?>" style="display:none">
319
							<thead>
320
								<tr class="info">
321
									<th><?=gettext("Local subnets")?></th>
322
									<th><?=gettext("Local SPI(s)")?></th>
323
									<th><?=gettext("Remote subnets")?></th>
324
									<th><?=gettext("Times")?></th>
325
									<th><?=gettext("Algo")?></th>
326
									<th><?=gettext("Stats")?></th>
327
									<th><!-- Buttons --></th>
328
								</tr>
329
							</thead>
330
							<tbody>
331
<?php
332
			foreach ($ikesa['child-sas'] as $childid => $childsa) {
333
?>
334
								<tr>
335
									<td>
336
<?php
337
				if (is_array($childsa['local-ts'])) {
338
					foreach ($childsa['local-ts'] as $lnets) {
339
						print(htmlspecialchars(ipsec_fixup_network($lnets)) . "<br />");
340
					}
341
				} else {
342
					print(gettext("Unknown"));
343
				}
344
?>
345
									</td>
346
									<td>
347
<?php
348
				if (isset($childsa['spi-in'])) {
349
					print(gettext("Local: ") . htmlspecialchars($childsa['spi-in']));
350
				}
351

    
352
				if (isset($childsa['spi-out'])) {
353
					print('<br/>' . gettext('Remote: ') . htmlspecialchars($childsa['spi-out']));
354
				}
355
?>
356
									</td>
357
									<td>
358
<?php
359
				if (is_array($childsa['remote-ts'])) {
360
					foreach ($childsa['remote-ts'] as $rnets) {
361
						print(htmlspecialchars(ipsec_fixup_network($rnets)) . '<br />');
362
					}
363
				} else {
364
					print(gettext("Unknown"));
365
				}
366
?>
367
									</td>
368
									<td>
369
<?php
370
				print(gettext("Rekey: ") . htmlspecialchars($childsa['rekey-time']) . gettext(" seconds"));
371
				print('<br/>' . gettext('Life: ') . htmlspecialchars($childsa['life-time']) . gettext(" seconds"));
372
				print('<br/>' . gettext('Install: ') .htmlspecialchars($childsa['install-time']) . gettext(" seconds"));
373

    
374
?>
375
									</td>
376
									<td>
377
<?php
378
				print(htmlspecialchars($childsa['encr-alg']) . '<br/>');
379
				print(htmlspecialchars($childsa['integ-alg']) . '<br/>');
380

    
381
				if (!empty($childsa['prf-alg'])) {
382
					print(htmlspecialchars($childsa['prf-alg']) . '<br/>');
383
				}
384
				if (!empty($childsa['dh-group'])) {
385
					print(htmlspecialchars($childsa['dh-group']) . '<br/>');
386
				}
387
				if (!empty($childsa['esn'])) {
388
					print(htmlspecialchars($childsa['esn']) . '<br/>');
389
				}
390

    
391
				print(gettext("IPComp: "));
392
				if (!empty($childsa['cpi-in']) || !empty($childsa['cpi-out'])) {
393
					print(htmlspecialchars($childsa['cpi-in']) . " " . htmlspecialchars($childsa['cpi-out']));
394
				} else {
395
					print(gettext('none'));
396
				}
397
?>
398
									</td>
399
									<td>
400
<?php
401
				print(gettext("Bytes-In: ") . htmlspecialchars($childsa['bytes-in']) . '<br/>');
402
				print(gettext("Packets-In: ") . htmlspecialchars($childsa['packets-in']) . '<br/>');
403
				print(gettext("Bytes-Out: ") . htmlspecialchars($childsa['bytes-out']) . '<br/>');
404
				print(gettext("Packets-Out: ") . htmlspecialchars($childsa['packets-out']) . '<br/>');
405
?>
406
									</td>
407
									<td>
408
										<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')?>">
409
											<?=gettext("Disconnect")?>
410
										</a>
411
									</td>
412
								</tr>
413
<?php
414
			}
415
		}
416
?>
417

    
418
							</tbody>
419
						</table>
420
					</td>
421
				</tr>
422
<?php
423
	}
424

    
425
		unset($con_id);
426
}
427

    
428
$rgmap = array();
429
foreach ($a_phase1 as $ph1ent) {
430
	if (isset($ph1ent['disabled'])) {
431
		continue;
432
	}
433

    
434
	$rgmap[$ph1ent['remote-gateway']] = $ph1ent['remote-gateway'];
435

    
436
	if ($ipsecconnected[$ph1ent['ikeid']]) {
437
		continue;
438
	}
439
?>
440
				<tr>
441
					<td>
442
<?php
443
	print(htmlspecialchars($ph1ent['descr']));
444
?>
445
					</td>
446
					<td>
447
<?php
448
	list ($myid_type, $myid_data) = ipsec_find_id($ph1ent, "local");
449
	if (empty($myid_data))
450
		print(gettext("Unknown"));
451
	else
452
		print(htmlspecialchars($myid_data));
453
?>
454
					</td>
455
					<td>
456
<?php
457
	$ph1src = ipsec_get_phase1_src($ph1ent);
458

    
459
	if (empty($ph1src))
460
		print(gettext("Unknown"));
461
	else
462
		print(htmlspecialchars($ph1src));
463
?>
464
					</td>
465
					<td>
466
<?php
467
	list ($peerid_type, $peerid_data) = ipsec_find_id($ph1ent, "peer", $rgmap);
468
	if (empty($peerid_data))
469
		print(gettext("Unknown"));
470
	else
471
		print(htmlspecialchars($peerid_data));
472
?>
473
					</td>
474
					<td>
475
<?php
476
	$ph1src = ipsec_get_phase1_dst($ph1ent);
477
	if (empty($ph1src))
478
		print(gettext("Unknown"));
479
	else
480
		print(htmlspecialchars($ph1src));
481
?>
482
					</td>
483
					<td>
484
					</td>
485
					<td>
486
					</td>
487
					<td>
488
					</td>
489
<?php
490
	if (isset($ph1ent['mobile'])) {
491
?>
492
					<td>
493
						<?=gettext("Awaiting connections")?>
494
					</td>
495
					<td>
496
					</td>
497
<?php
498
	} else {
499
?>
500
					<td>
501
						<?=gettext("Disconnected")?>
502
					</td>
503
					<td >
504
						<a href="diag_ipsec.php?act=connect&amp;ikeid=<?=$ph1ent['ikeid']; ?>" class="btn btn-xs btn-success">
505
							<?=gettext("Connect VPN")?>
506
						</a>
507
					</td>
508
<?php
509
	}
510
?>
511
					<td>
512
					</td>
513
				</tr>
514
<?php
515
}
516
unset($ipsecconnected, $phase1, $rgmap);
517
?>
518
			</tbody>
519
		</table>
520
	</div>
521
</div>
522

    
523
<script type="text/javascript">
524
//<![CDATA[
525
function show_childsa(id, buttonid) {
526
	document.getElementById(buttonid).innerHTML='';
527
	aodiv = document.getElementById(id);
528
	aodiv.style.display = "block";
529
}
530
//]]>
531
</script>
532

    
533
<?php
534
unset($status);
535
print_info_box(gettext("You can configure IPsec ") . '<a href="vpn_ipsec.php">Here</a>');
536
include("foot.inc"); ?>
(15-15/234)