Project

General

Profile

Download (15.4 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	status_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
##|+PRIV
61
##|*IDENT=page-status-ipsec
62
##|*NAME=Status: IPsec
63
##|*DESCR=Allow access to the 'Status: IPsec' page.
64
##|*MATCH=status_ipsec.php*
65
##|-PRIV
66

    
67

    
68
global $g;
69

    
70
$pgtitle = array(gettext("Status"), gettext("IPsec"), gettext("Overview"));
71
$shortcut_section = "ipsec";
72

    
73
require("guiconfig.inc");
74
include("head.inc");
75
require_once("ipsec.inc");
76

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

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

    
114
$a_phase1 = &$config['ipsec']['phase1'];
115

    
116
$status = ipsec_list_sa();
117

    
118
$tab_array = array();
119
$tab_array[] = array(gettext("Overview"), true, "status_ipsec.php");
120
$tab_array[] = array(gettext("Leases"), false, "status_ipsec_leases.php");
121
$tab_array[] = array(gettext("SADs"), false, "status_ipsec_sad.php");
122
$tab_array[] = array(gettext("SPDs"), false, "status_ipsec_spd.php");
123
display_top_tabs($tab_array);
124
?>
125

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

    
148
if (is_array($status)) {
149
	foreach ($status as $ikeid => $ikesa) {
150
		$con_id = substr($ikeid, 3);
151

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

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

    
305
						<table class="table table-hover table-condensed" id="childsa-<?=$ikeid?>" style="display:none">
306
							<thead>
307
								<tr class="bg-info">
308
									<th><?=gettext("Local subnets")?></th>
309
									<th><?=gettext("Local SPI(s)")?></th>
310
									<th><?=gettext("Remote subnets")?></th>
311
									<th><?=gettext("Times")?></th>
312
									<th><?=gettext("Algo")?></th>
313
									<th><?=gettext("Stats")?></th>
314
									<th><!-- Buttons --></th>
315
								</tr>
316
							</thead>
317
							<tbody>
318
<?php
319
			foreach ($ikesa['child-sas'] as $childid => $childsa) {
320
?>
321
								<tr>
322
									<td>
323
<?php
324
				if (is_array($childsa['local-ts'])) {
325
					foreach ($childsa['local-ts'] as $lnets) {
326
						print(htmlspecialchars(ipsec_fixup_network($lnets)) . "<br />");
327
					}
328
				} else {
329
					print(gettext("Unknown"));
330
				}
331
?>
332
									</td>
333
									<td>
334
<?php
335
				if (isset($childsa['spi-in'])) {
336
					print(gettext("Local: ") . htmlspecialchars($childsa['spi-in']));
337
				}
338

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

    
361
?>
362
									</td>
363
									<td>
364
<?php
365
				print(htmlspecialchars($childsa['encr-alg']) . '<br/>');
366
				print(htmlspecialchars($childsa['integ-alg']) . '<br/>');
367

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

    
378
				print(gettext("IPComp: "));
379
				if (!empty($childsa['cpi-in']) || !empty($childsa['cpi-out'])) {
380
					print(htmlspecialchars($childsa['cpi-in']) . " " . htmlspecialchars($childsa['cpi-out']));
381
				} else {
382
					print(gettext('none'));
383
				}
384
?>
385
									</td>
386
									<td>
387
<?php
388
				print(gettext("Bytes-In: ") . htmlspecialchars(number_format($childsa['bytes-in'])) . ' (' . htmlspecialchars(format_bytes($childsa['bytes-in'])) . ')<br/>');
389
				print(gettext("Packets-In: ") . htmlspecialchars(number_format($childsa['packets-in'])) . '<br/>');
390
				print(gettext("Bytes-Out: ") . htmlspecialchars(number_format($childsa['bytes-out'])) . ' (' . htmlspecialchars(format_bytes($childsa['bytes-out'])) . ')<br/>');
391
				print(gettext("Packets-Out: ") . htmlspecialchars(number_format($childsa['packets-out'])) . '<br/>');
392
?>
393
									</td>
394
									<td>
395
										<a href="status_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')?>">
396
											<i class="fa fa-trash icon-embed-btn"></i>
397
											<?=gettext("Disconnect")?>
398
										</a>
399
									</td>
400
								</tr>
401
<?php
402
			}
403
?>
404

    
405
							</tbody>
406
						</table>
407
					</td>
408
				</tr>
409
<?php
410
		}
411

    
412
		unset($con_id);
413
	}
414

    
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
?>
444
					</td>
445
					<td>
446
<?php
447
	$ph1src = ipsec_get_phase1_src($ph1ent);
448

    
449
	if (empty($ph1src)) {
450
		print(gettext("Unknown"));
451
	} else {
452
		print(htmlspecialchars($ph1src));
453
	}
454
?>
455
					</td>
456
					<td>
457
<?php
458
	list ($peerid_type, $peerid_data) = ipsec_find_id($ph1ent, "peer", $rgmap);
459
	if (empty($peerid_data)) {
460
		print(gettext("Unknown"));
461
	} else {
462
		print(htmlspecialchars($peerid_data));
463
	}
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
?>
475
					</td>
476
					<td>
477
					</td>
478
					<td>
479
					</td>
480
					<td>
481
					</td>
482
<?php
483
	if (isset($ph1ent['mobile'])) {
484
?>
485
					<td>
486
						<?=gettext("Awaiting connections")?>
487
					</td>
488
					<td>
489
					</td>
490
<?php
491
	} else {
492
?>
493
					<td>
494
						<?=gettext("Disconnected")?>
495
					</td>
496
					<td >
497
						<a href="status_ipsec.php?act=connect&amp;ikeid=<?=$ph1ent['ikeid']; ?>" class="btn btn-xs btn-success">
498
							<i class="fa fa-sign-in icon-embed-btn"></i>
499
							<?=gettext("Connect VPN")?>
500
						</a>
501
					</td>
502
<?php
503
	}
504
?>
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 = "table";
521
}
522
//]]>
523
</script>
524

    
525
<?php
526
unset($status);
527
if (ipsec_enabled()) {
528
?>
529
<div class="infoblock">
530
<?php
531
} else {
532
?>
533
<div class="infoblock blockopen">
534
<?php
535
}
536
print_info_box(sprintf(gettext('You can configure IPsec %1$shere%2$s.'), '<a href="vpn_ipsec.php">', '</a>'), 'info', false);
537
?>
538
</div>
539
<?php
540
include("foot.inc"); ?>
(165-165/225)