Project

General

Profile

Download (15.1 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
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
display_top_tabs($tab_array);
128
?>
129

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

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

    
156
		if ($ikesa['version'] == 1) {
157
			$ph1idx = substr($con_id, 0, strrpos(substr($con_id, 0, -1), '00'));
158
			$ipsecconnected[$ph1idx] = $ph1idx;
159
		} else {
160
			$ipsecconnected[$con_id] = $ph1idx = $con_id;
161
		}
162
?>
163
				<tr>
164
					<td>
165
						<?=htmlspecialchars(ipsec_get_descr($ph1idx))?>
166
					</td>
167
					<td>
168
<?php
169
		if (!empty($ikesa['local-id'])) {
170
			if ($ikesa['local-id'] == '%any') {
171
				print(gettext('Any identifier'));
172
			} else {
173
				print(htmlspecialchars($ikesa['local-id']));
174
			}
175
		} else {
176
			print(gettext("Unknown"));
177
		}
178

    
179
?>
180
					</td>
181
					<td>
182
<?php
183
		if (!empty($ikesa['local-host'])) {
184
			print(htmlspecialchars($ikesa['local-host']));
185
		} else {
186
			print(gettext("Unknown"));
187
		}
188
		/*
189
		 * XXX: local-nat-t was defined by pfSense
190
		 * When strongswan team accepted the change, they changed it to
191
		 * nat-local. Keep both for a while and remove local-nat-t in
192
		 * the future
193
		 */
194
		if (isset($ikesa['local-nat-t']) || isset($ikesa['nat-local'])) {
195
			print(" NAT-T");
196
		}
197
?>
198
					</td>
199
					<td>
200
<?php
201
		$identity = "";
202
		if (!empty($ikesa['remote-id'])) {
203
			if ($ikesa['remote-id'] == '%any') {
204
				$identity = 'Any identifier';
205
			} else {
206
				$identity = htmlspecialchars($ikesa['remote']['identification']);
207
			}
208
		}
209
		if (!empty($ikesa['remote-xauth-id'])) {
210
			echo htmlspecialchars($ikesa['remote-xauth-id']);
211
			echo "<br/>{$identity}";
212
		} elseif (!empty($ikesa['remote-eap-id'])) {
213
			echo htmlspecialchars($ikesa['remote-eap-id']);
214
			echo "<br/>{$identity}";
215
		} else {
216
			if (empty($identity)) {
217
				print(gettext("Unknown"));
218
			} else {
219
				print($identity);
220
			}
221
		}
222
?>
223
					</td>
224
					<td>
225
<?php
226
		if (!empty($ikesa['remote-host'])) {
227
			print(htmlspecialchars($ikesa['remote-host']));
228
		} else {
229
			print(gettext("Unknown"));
230
		}
231
		/*
232
		 * XXX: remote-nat-t was defined by pfSense
233
		 * When strongswan team accepted the change, they changed it to
234
		 * nat-remote. Keep both for a while and remove remote-nat-t in
235
		 * the future
236
		 */
237
		if (isset($ikesa['remote-nat-t']) || isset($ikesa['nat-remote'])) {
238
			print(" NAT-T");
239
		}
240
?>
241
					</td>
242
					<td>
243
						IKEv<?=htmlspecialchars($ikesa['version'])?>
244
						<br/>
245
<?php
246
		if ($ikesa['initiator'] == 'yes') {
247
			print("initiator");
248
		} else {
249
			print("responder");
250
		}
251
?>
252
					</td>
253
					<td>
254
						<?=htmlspecialchars($ikesa['reauth-time']) . gettext(" seconds (") . convert_seconds_to_hms($ikesa['reauth-time']) . ")";?>
255
					</td>
256
					<td>
257
						<?=htmlspecialchars($ikesa['encr-alg'])?>
258
						<br/>
259
						<?=htmlspecialchars($ikesa['integ-alg'])?>
260
						<br/>
261
						<?=htmlspecialchars($ikesa['prf-alg'])?>
262
						<br/>
263
						<?=htmlspecialchars($ikesa['dh-group'])?>
264
					</td>
265
					<td>
266
<?php
267
		if ($ikesa['state'] == 'ESTABLISHED') {
268
			print('<span style="color:green">');
269
		} else {
270
			print('<span>');
271
		}
272
?>
273
						<?=ucfirst(htmlspecialchars($ikesa['state']))?>
274
						<br/><?=htmlspecialchars($ikesa['established']) . gettext(" seconds (" . convert_seconds_to_hms($ikesa['established']) . ") ago")?>
275
						</span>
276
					</td>
277
					<td >
278
<?php
279
		if ($ikesa['state'] != 'ESTABLISHED') {
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['uniqueid']; ?>" class="btn btn-xs btn-warning" data-toggle="tooltip" title="Disconnect VPN connection">
291
							<?=gettext("Disconnect")?>
292
						</a>
293
<?php
294
		}
295
?>
296
					</td>
297
				</tr>
298
				<tr>
299
					<td colspan = 10>
300
<?php
301
		if (is_array($ikesa['child-sas']) && (count($ikesa['child-sas']) > 0)) {
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
			foreach ($ikesa['child-sas'] as $childid => $childsa) {
324
?>
325
								<tr>
326
									<td>
327
<?php
328
				if (is_array($childsa['local-ts'])) {
329
					foreach ($childsa['local-ts'] as $lnets) {
330
						print(htmlspecialchars(ipsec_fixup_network($lnets)) . "<br />");
331
					}
332
				} else {
333
					print(gettext("Unknown"));
334
				}
335
?>
336
									</td>
337
									<td>
338
<?php
339
				if (isset($childsa['spi-in'])) {
340
					print(gettext("Local: ") . htmlspecialchars($childsa['spi-in']));
341
				}
342

    
343
				if (isset($childsa['spi-out'])) {
344
					print('<br/>' . gettext('Remote: ') . htmlspecialchars($childsa['spi-out']));
345
				}
346
?>
347
									</td>
348
									<td>
349
<?php
350
				if (is_array($childsa['remote-ts'])) {
351
					foreach ($childsa['remote-ts'] as $rnets) {
352
						print(htmlspecialchars(ipsec_fixup_network($rnets)) . '<br />');
353
					}
354
				} else {
355
					print(gettext("Unknown"));
356
				}
357
?>
358
									</td>
359
									<td>
360
<?php
361
				print(gettext("Rekey: ") . htmlspecialchars($childsa['rekey-time']) . gettext(" seconds (") . convert_seconds_to_hms($childsa['rekey-time']) . ")");
362
				print('<br/>' . gettext('Life: ') . htmlspecialchars($childsa['life-time']) . gettext(" seconds (") . convert_seconds_to_hms($childsa['life-time']) . ")" );
363
				print('<br/>' . gettext('Install: ') .htmlspecialchars($childsa['install-time']) . gettext(" seconds (") . convert_seconds_to_hms($childsa['install-time']) . ")" );
364

    
365
?>
366
									</td>
367
									<td>
368
<?php
369
				print(htmlspecialchars($childsa['encr-alg']) . '<br/>');
370
				print(htmlspecialchars($childsa['integ-alg']) . '<br/>');
371

    
372
				if (!empty($childsa['prf-alg'])) {
373
					print(htmlspecialchars($childsa['prf-alg']) . '<br/>');
374
				}
375
				if (!empty($childsa['dh-group'])) {
376
					print(htmlspecialchars($childsa['dh-group']) . '<br/>');
377
				}
378
				if (!empty($childsa['esn'])) {
379
					print(htmlspecialchars($childsa['esn']) . '<br/>');
380
				}
381

    
382
				print(gettext("IPComp: "));
383
				if (!empty($childsa['cpi-in']) || !empty($childsa['cpi-out'])) {
384
					print(htmlspecialchars($childsa['cpi-in']) . " " . htmlspecialchars($childsa['cpi-out']));
385
				} else {
386
					print(gettext('none'));
387
				}
388
?>
389
									</td>
390
									<td>
391
<?php
392
				print(gettext("Bytes-In: ") . htmlspecialchars(number_format($childsa['bytes-in'])) . ' (' . htmlspecialchars(format_bytes($childsa['bytes-in'])) . ')<br/>');
393
				print(gettext("Packets-In: ") . htmlspecialchars(number_format($childsa['packets-in'])) . '<br/>');
394
				print(gettext("Bytes-Out: ") . htmlspecialchars(number_format($childsa['bytes-out'])) . ' (' . htmlspecialchars(format_bytes($childsa['bytes-out'])) . ')<br/>');
395
				print(gettext("Packets-Out: ") . htmlspecialchars(number_format($childsa['packets-out'])) . '<br/>');
396
?>
397
									</td>
398
									<td>
399
										<a href="diag_ipsec.php?act=childdisconnect&amp;ikeid=<?=$con_id; ?>&amp;ikesaid=<?=$childsa['uniqueid']; ?>" class="btn btn-xs btn-warning" data-toggle="tooltip" title="<?=gettext('Disconnect Child SA')?>">
400
											<?=gettext("Disconnect")?>
401
										</a>
402
									</td>
403
								</tr>
404
<?php
405
			}
406
?>
407

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

    
415
		unset($con_id);
416
	}
417

    
418
}
419

    
420
$rgmap = array();
421
foreach ($a_phase1 as $ph1ent) {
422
	if (isset($ph1ent['disabled'])) {
423
		continue;
424
	}
425

    
426
	$rgmap[$ph1ent['remote-gateway']] = $ph1ent['remote-gateway'];
427

    
428
	if ($ipsecconnected[$ph1ent['ikeid']]) {
429
		continue;
430
	}
431
?>
432
				<tr>
433
					<td>
434
<?php
435
	print(htmlspecialchars($ph1ent['descr']));
436
?>
437
					</td>
438
					<td>
439
<?php
440
	list ($myid_type, $myid_data) = ipsec_find_id($ph1ent, "local");
441
	if (empty($myid_data))
442
		print(gettext("Unknown"));
443
	else
444
		print(htmlspecialchars($myid_data));
445
?>
446
					</td>
447
					<td>
448
<?php
449
	$ph1src = ipsec_get_phase1_src($ph1ent);
450

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

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

    
525
<?php
526
unset($status);
527
print_info_box(gettext("You can configure IPsec ") . '<a href="vpn_ipsec.php">Here</a>');
528
include("foot.inc"); ?>
(15-15/228)