Project

General

Profile

Download (20.8 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * status_ipsec.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8
 * Copyright (c) 2014-2021 Rubicon Communications, LLC (Netgate)
9
 * All rights reserved.
10
 *
11
 * originally based on m0n0wall (http://m0n0.ch/wall)
12
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
13
 * All rights reserved.
14
 *
15
 * Licensed under the Apache License, Version 2.0 (the "License");
16
 * you may not use this file except in compliance with the License.
17
 * You may obtain a copy of the License at
18
 *
19
 * http://www.apache.org/licenses/LICENSE-2.0
20
 *
21
 * Unless required by applicable law or agreed to in writing, software
22
 * distributed under the License is distributed on an "AS IS" BASIS,
23
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
 * See the License for the specific language governing permissions and
25
 * limitations under the License.
26
 */
27

    
28
##|+PRIV
29
##|*IDENT=page-status-ipsec
30
##|*NAME=Status: IPsec
31
##|*DESCR=Allow access to the 'Status: IPsec' page.
32
##|*MATCH=status_ipsec.php*
33
##|-PRIV
34

    
35
require_once("guiconfig.inc");
36
require_once("ipsec.inc");
37
require_once("service-utils.inc");
38

    
39
if ($_POST['act'] == 'connect') {
40
	/* Assume type is IKE */
41
	$type = empty($_POST['type']) ? 'ike' : $_POST['type'];
42
	ipsec_initiate_by_conid($type, $_POST['conid']);
43
} elseif ($_POST['act'] == 'disconnect') {
44
	/* Assume type is IKE */
45
	$type = empty($_POST['type']) ? 'ike' : $_POST['type'];
46
	ipsec_terminate_by_conid($type, $_POST['conid'], $_POST['uniqueid']);
47
}
48

    
49
// If this is just an AJAX call to update the table body, just generate the body and quit
50
if ($_REQUEST['ajax']) {
51
	print_ipsec_body();
52
	exit;
53
}
54

    
55
// Table body is composed here so that it can be more easily updated via AJAX
56
function print_ipsec_body() {
57
	global $config;
58

    
59
	if (!ipsec_enabled()) {
60
?>
61
<tr>
62
	<td colspan="10">
63
		<?php print_info_box(addslashes(gettext("IPsec is disabled.")), "warning", ""); ?>
64
	</td>
65
</tr>
66
<?php
67
		return;
68
	}
69
	if (!get_service_status(array('name' => 'ipsec'))) {
70
?>
71
<tr>
72
	<td colspan="10">
73
		<?php print_info_box(addslashes(gettext("IPsec daemon is stopped.")), "warning", ""); ?>
74
	</td>
75
</tr>
76
<?php
77
		return;
78
	}
79

    
80
	$cmap = ipsec_map_config_by_id();
81
	$status = ipsec_list_sa();
82

    
83
	$p1conids = array_column($status, 'con-id');
84
	$p1uniqueids = array_column($status, 'uniqueid');
85
	array_multisort($p1conids, SORT_NATURAL,
86
			$p1uniqueids, SORT_NUMERIC,
87
			$status);
88

    
89
	$p1connected = array();
90
	$p2connected = array();
91
	if (!is_array($status)) {
92
		$status = array();
93
	}
94
	foreach ($status as $ikesa) {
95
		list($ikeid, $reqid) = ipsec_id_by_conid($ikesa['con-id']);
96
		if (!array_key_exists($ikeid, $cmap)) {
97
			// Doesn't match known tunnel
98
			$p1connected[$ikesa['con-id']] = $ikesa['con-id'];
99
		} else {
100
			$p1connected[$ikeid] = $ph1idx = $ikeid;
101
		}
102
		if (array_key_exists('child-sas', $ikesa) && is_array($ikesa['child-sas'])) {
103
			$p2conids = array_column($ikesa['child-sas'], 'name');
104
			$p2uniqueids = array_column($ikesa['child-sas'], 'uniqueid');
105
			array_multisort($p2conids, SORT_NATURAL,
106
					$p2uniqueids, SORT_NUMERIC,
107
					$ikesa['child-sas']);
108

    
109
			foreach ($ikesa['child-sas'] as $childid => $childsa) {
110
				list($childikeid, $childreqid) = ipsec_id_by_conid($childsa['name']);
111
				if ($childreqid != null) {
112
					$p2connected[$childreqid] = $childsa['name'];
113
				} else {
114
					/* If this is IKEv2 w/o Split, mark all reqids for the P1 as connected */
115
					if ($cmap[$childikeid]['p1']['iketype'] == 'ikev2' &&
116
					    !isset($cmap[$childikeid]['p1']['splitconn'])) {
117
						foreach ($cmap[$ikeid]['p2'] as $p2) {
118
							$p2connected[$p2['reqid']] = $childsa['name'];
119
						}
120
					}
121
				}
122
			}
123
		}
124
		$p2disconnected = array();
125
		if (!$cmap[$ikeid]['p1']['mobile'] &&
126
		    isset($cmap[$ikeid]) &&
127
		    is_array($cmap[$ikeid]) &&
128
		    is_array($cmap[$ikeid]['p2'])) {
129
			foreach ($cmap[$ikeid]['p2'] as $p2) {
130
				if (!array_key_exists($p2['reqid'], $p2connected)) {
131
					/* This P2 is not connected */
132
					$p2conid = ipsec_conid($cmap[$ikeid]['p1'], $p2);
133
					$p2disconnected[$p2conid] = $p2;
134
				}
135
			}
136
		}
137
?>
138

    
139
<tr>
140
	<td>
141
		<?= htmlspecialchars($ikesa['con-id']) ?>
142
		#<?= htmlspecialchars($ikesa['uniqueid']) ?>
143
	</td>
144
	<td>
145
		<?= htmlspecialchars($cmap[$ikeid]['p1']['descr']) ?>
146
		<br/>
147
		<a class="fa fa-pencil" href="vpn_ipsec_phase1.php?ikeid=<?= htmlspecialchars($ikeid) ?>"
148
			title="<?= htmlspecialchars(gettext("Edit Phase 1 Entry")) ?>">
149
		</a>
150
	</td>
151
	<td>
152
		<b>ID:</b>
153
<?php
154
		$localid = gettext("Unknown");
155
		if (!empty($ikesa['local-id'])) {
156
			if ($ikesa['local-id'] == '%any') {
157
				$localid = gettext('Any identifier');
158
			} else {
159
				$localid = $ikesa['local-id'];
160
			}
161
		}
162
?>
163
		<?= htmlspecialchars($localid) ?>
164
		<br/>
165
		<b><?= htmlspecialchars(gettext("Host:")); ?></b>
166
<?php
167
		$lhost = gettext("Unknown");
168
		if (!empty($ikesa['local-host'])) {
169
			$lhost = $ikesa['local-host'];
170
			if (!empty($ikesa['local-port'])) {
171
				if (is_ipaddrv6($ikesa['local-host'])) {
172
					$lhost = "[{$lhost}]";
173
				}
174
				$lhost .= ":{$ikesa['local-port']}";
175
			}
176
		}
177
?>
178
		<?= htmlspecialchars($lhost) ?>
179
		<br/>
180
		<b>SPI:</b>
181
		<?= htmlspecialchars( ($ikesa['initiator'] == 'yes') ? $ikesa['initiator-spi'] : $ikesa['responder-spi'] ) ?>
182
<?php		if (isset($ikesa['nat-local'])): ?>
183
			<?= htmlspecialchars(gettext("NAT-T")); ?>
184
<?php		endif; ?>
185
	</td>
186
	<td>
187
		<b>ID:</b>
188
<?php
189
		$identity = "";
190
		if (!empty($ikesa['remote-id'])) {
191
			if ($ikesa['remote-id'] == '%any') {
192
				$identity = gettext('Any identifier');
193
			} else {
194
				$identity = $ikesa['remote-id'];
195
			}
196
		}
197
		$remoteid = "";
198
		if (!empty($ikesa['remote-xauth-id'])) {
199
			$remoteid = $ikesa['remote-xauth-id'];
200
		} elseif (!empty($ikesa['remote-eap-id'])) {
201
			$remoteid = $ikesa['remote-eap-id'];
202
		} else {
203
			if (empty($identity)) {
204
				$identity = gettext("Unknown");
205
			}
206
		}
207
?>
208
<?php		if (!empty($remoteid)): ?>
209
		<?= htmlspecialchars($remoteid) ?><br/>
210
<?php		endif; ?>
211
		<?= htmlspecialchars($identity) ?>
212
		<br/>
213
		<b><?= htmlspecialchars(gettext("Host:")); ?></b>
214
<?php
215
		$rhost = gettext("Unknown");
216
		if (!empty($ikesa['remote-host'])) {
217
			$rhost = $ikesa['remote-host'];
218
			if (!empty($ikesa['remote-port'])) {
219
				if (is_ipaddrv6($ikesa['remote-host'])) {
220
					$rhost = "[{$rhost}]";
221
				}
222
				$rhost .= ":{$ikesa['remote-port']}";
223
			}
224
		}
225
?>
226
		<?= htmlspecialchars($rhost) ?>
227
<?php		if (isset($ikesa['nat-remote'])): ?>
228
		<?= htmlspecialchars(gettext("NAT-T")); ?>
229
<?php		endif; ?>
230
		<br/>
231
		<b>SPI:</b>
232
		<?= htmlspecialchars( ($ikesa['initiator'] == 'yes') ? $ikesa['responder-spi'] : $ikesa['initiator-spi'] ) ?>
233
	</td>
234
	<td>
235
		IKEv<?= htmlspecialchars($ikesa['version']) ?><br/>
236
<?php		if ($ikesa['initiator'] == 'yes'): ?>
237
		<?= htmlspecialchars(gettext("Initiator")); ?>
238
<?php		else: ?>
239
		<?= htmlspecialchars(gettext("Responder")); ?>
240
<?php		endif; ?>
241
	</td>
242
	<td>
243
<?php		if ($ikesa['version'] == 2): ?>
244
		<b><?= htmlspecialchars(gettext("Rekey:")) ?></b>
245
<?php			if (!empty($ikesa['rekey-time'])): ?>
246
		<?= htmlspecialchars($ikesa['rekey-time']) ?>s
247
		(<?= convert_seconds_to_dhms($ikesa['rekey-time']) ?>)
248
<?php			else: ?>
249
		<?= htmlspecialchars(gettext("Disabled")) ?>
250
<?php			endif; ?>
251
		<br/>
252
<?php		endif; ?>
253
		<b><?= htmlspecialchars(gettext("Reauth:")) ?></b>
254
<?php		if (!empty($ikesa['reauth-time'])): ?>
255
		<?= htmlspecialchars(htmlspecialchars($ikesa['reauth-time'])) ?>s
256
		(<?= convert_seconds_to_dhms($ikesa['reauth-time']) ?>)
257
<?php		else: ?>
258
		<?= htmlspecialchars(gettext("Disabled")) ?>
259
<?php		endif; ?>
260
	</td>
261
	<td>
262
		<?= htmlspecialchars($ikesa['encr-alg']) ?>
263
<?php		if (!empty($ikesa['encr-keysize'])): ?>
264
		(<?= htmlspecialchars($ikesa['encr-keysize']) ?>)
265
<?php		endif; ?>
266
		<br/>
267
		<?= htmlspecialchars($ikesa['integ-alg']) ?><br/>
268
		<?= htmlspecialchars($ikesa['prf-alg']) ?><br/>
269
		<?= htmlspecialchars($ikesa['dh-group']) ?><br/>
270
	</td>
271
	<td>
272
		<span<?= ($ikesa['state'] == 'ESTABLISHED') ? ' class="text-success"' : '' ; ?>>
273
		<?= htmlspecialchars(ucfirst(strtolower($ikesa['state']))) ?>
274
<?php		if ($ikesa['state'] == 'ESTABLISHED'): ?>
275
		<br/>
276
		<? printf(gettext('%1$s seconds (%2$s) ago'), htmlspecialchars($ikesa['established']), convert_seconds_to_dhms($ikesa['established'])) ?>
277
<?php		endif; ?>
278
		</span>
279
		<br/>
280
		<br/>
281
<?php		if ($ikesa['state'] != 'ESTABLISHED'): ?>
282
		<?= ipsec_status_button('ajax', 'connect', 'all', $ikesa['con-id'], null, true) ?>
283
<?php		else: ?>
284
		<?= ipsec_status_button('ajax', 'disconnect', 'ike', $ikesa['con-id'], $ikesa['uniqueid'], true) ?>
285
<?php		endif; ?>
286
		<br>
287
<?php		if (empty($ikesa['child-sas'])): ?>
288
		<br/>
289
		<?= ipsec_status_button('ajax', 'connect', 'all', $ikesa['con-id'], null, true) ?>
290
<?php			endif; ?>
291
	</td>
292
</tr>
293
<tr>
294
	<td colspan="10">
295
<?php		$child_key = "{$ikesa['con-id']}_{$ikesa['uniqueid']}_children"; ?>
296
	<div>
297
<?php		if ((count($ikesa['child-sas']) + count($p2disconnected)) > 0): ?>
298
		<a type="button" id="btnchildsa-<?= htmlspecialchars($child_key) ?>" class="btn btn-sm btn-info">
299
		<i class="fa fa-plus-circle icon-embed-btn"></i>
300
		<?= htmlspecialchars(gettext('Show child SA entries')) ?>
301
<?php
302
			$p2counts = count($ikesa['child-sas']) . " " . gettext("Connected");
303
			if (count($p2disconnected) > 0) {
304
				$p2counts .= ", " . count($p2disconnected) . " " . gettext("Disconnected");
305
			}
306
?>
307
		(<?= htmlspecialchars($p2counts) ?>)
308
<?php		endif; ?>
309
		</a>
310
	</div>
311
	<table class="table table-hover table-condensed" id="childsa-<?= htmlspecialchars($child_key) ?>" style="display:none">
312
	<thead>
313
	<tr class="bg-info">
314
		<th><?= htmlspecialchars(gettext("ID")) ?></th>
315
		<th><?= htmlspecialchars(gettext("Description")) ?></th>
316
		<th><?= htmlspecialchars(gettext("Local")) ?></th>
317
		<th><?= htmlspecialchars(gettext("SPI(s)")) ?></th>
318
		<th><?= htmlspecialchars(gettext("Remote")) ?></th>
319
		<th><?= htmlspecialchars(gettext("Times")) ?></th>
320
		<th><?= htmlspecialchars(gettext("Algo")) ?></th>
321
		<th><?= htmlspecialchars(gettext("Stats")) ?></th>
322
		<th><!-- Buttons --></th>
323
	</tr>
324
	</thead>
325
	<tbody>
326
<?php		if (is_array($ikesa['child-sas']) && (count($ikesa['child-sas']) > 0)) {
327
			foreach ($ikesa['child-sas'] as $childid => $childsa) {
328
				list($childikeid, $childreqid) = ipsec_id_by_conid($childsa['name']);
329
?>
330
	<tr>
331
		<td>
332
			<?= htmlspecialchars($childsa['name']) ?>:<br />
333
			#<?= htmlspecialchars($childsa['uniqueid']) ?>
334
		</td>
335
		<td>
336
<?php
337
				$p2descr = "";
338
				$p2uid = "";
339
				if (!empty($childreqid)) {
340
					/* IKEv1 or IKEv2+Split */
341
					$p2descr = $cmap[$childikeid]['p2'][$childreqid]['descr'];
342
					$p2uid = $cmap[$childikeid]['p2'][$childreqid]['uniqid'];
343
				} else {
344
					$childreqid = array_key_first($cmap[$childikeid]['p2']);
345
					$p2uid = $cmap[$childikeid]['p2'][$childreqid]['uniqid'];
346
					if (count($cmap[$childikeid]['p2']) > 1) {
347
						$p2descr = gettext("Multiple");
348
					} else {
349
						$p2descr = $cmap[$childikeid]['p2'][$childreqid]['descr'];
350
					}
351
				}
352
?>
353
			<?= htmlspecialchars($p2descr) ?>
354
<?php				if (!empty($p2uid) && ($p2descr != gettext("Multiple"))): ?>
355
			<br/>
356
			<a class="fa fa-pencil" href="vpn_ipsec_phase2.php?uniqid=<?= htmlspecialchars($p2uid) ?>"
357
				title="<?= gettext("Edit Phase 2 Entry") ?>">
358
			</a>
359
<?php				endif ?>
360
		</td>
361
		<td>
362
<?php
363
				$lnetlist = array();
364
				if (is_array($childsa['local-ts'])) {
365
					foreach ($childsa['local-ts'] as $lnets) {
366
						$lnetlist[] = htmlspecialchars(ipsec_fixup_network($lnets));
367
					}
368
				} else {
369
					$lnetlist[] = htmlspecialchars(gettext("Unknown"));
370
				}
371
?>
372
			<?= htmlspecialchars(implode('<br/>', $lnetlist)) ?>
373
		</td>
374
		<td>
375
<?php
376
				if (isset($childsa['spi-in'])) {
377
?>
378
			<b><?= htmlspecialchars(gettext("Local:")) ?></b>
379
			<?= htmlspecialchars($childsa['spi-in']) ?>
380
<?php
381
				}
382
				if (isset($childsa['spi-out'])) {
383
?>
384
			<br/>
385
			<b><?= htmlspecialchars(gettext("Remote:")) ?></b>
386
			<?= htmlspecialchars($childsa['spi-out']) ?>
387
<?php
388
				}
389
?>
390
		</td>
391
		<td>
392
<?php
393
				$rnetlist = array();
394
				if (is_array($childsa['remote-ts'])) {
395
					foreach ($childsa['remote-ts'] as $rnets) {
396
						$rnetlist[] = htmlspecialchars(ipsec_fixup_network($rnets));
397
					}
398
				} else {
399
					$rnetlist[] = htmlspecialchars(gettext("Unknown"));
400
				}
401
?>
402
			<?= htmlspecialchars(implode('<br/>', $rnetlist)) ?>
403
		</td>
404
		<td>
405
			<b><?= htmlspecialchars(gettext("Rekey:")) ?></b>
406
			<?= htmlspecialchars($childsa['rekey-time']) ?>s
407
			(<?= convert_seconds_to_dhms($childsa['rekey-time']) ?>)
408
			<br/>
409

    
410
			<b><?= htmlspecialchars(gettext("Life:")) ?></b>
411
			<?= htmlspecialchars($childsa['life-time']) ?>s
412
			(<?= convert_seconds_to_dhms($childsa['life-time']) ?>)
413
			<br/>
414

    
415
			<b><?= htmlspecialchars(gettext("Install:")) ?></b>
416
			<?= htmlspecialchars($childsa['install-time']) ?>s
417
			(<?= convert_seconds_to_dhms($childsa['install-time']) ?>)
418
		</td>
419
		<td>
420
			<?= htmlspecialchars($childsa['encr-alg']) ?>
421
<?php				if (!empty($childsa['encr-keysize'])): ?>
422
			(<?= htmlspecialchars($childsa['encr-keysize']) ?>)
423
<?php				endif; ?>
424
			<br/>
425
			<?= htmlspecialchars($childsa['integ-alg']) ?>
426
			<br/>
427
<?php				if (!empty($childsa['prf-alg'])): ?>
428
			<?= htmlspecialchars($childsa['prf-alg']) ?>
429
			<br/>
430
<?php				endif; ?>
431
<?php				if (!empty($childsa['dh-group'])): ?>
432
			<?= htmlspecialchars($childsa['dh-group']) ?>
433
			<br/>
434
<?php				endif; ?>
435
<?php				if (!empty($childsa['esn'])): ?>
436
			<?= htmlspecialchars($childsa['esn']) ?>
437
			<br/>
438
<?php				endif;
439
				$ipcomp = gettext('None');
440
				if (!empty($childsa['cpi-in']) || !empty($childsa['cpi-out'])) {
441
					$ipcomp = "{$childsa['cpi-in']} {$childsa['cpi-out']}";
442
				}
443
?>
444
			<?= htmlspecialchars(gettext("IPComp: ")) ?> <?= htmlspecialchars($ipcomp) ?>
445
		</td>
446
		<td>
447
			<b><?= htmlspecialchars(gettext("Bytes-In:")) ?></b>
448
			<?= htmlspecialchars(number_format($childsa['bytes-in'])) ?>
449
			(<?= htmlspecialchars(format_bytes($childsa['bytes-in'])) ?>)
450
			<br/>
451
			<b><?= htmlspecialchars(gettext("Packets-In:")) ?></b>
452
			<?= htmlspecialchars(number_format($childsa['packets-in'])) ?>
453
			<br/>
454
			<b><?= htmlspecialchars(gettext("Bytes-Out:")) ?></b>
455
			<?= htmlspecialchars(number_format($childsa['bytes-out'])) ?>
456
			(<?= htmlspecialchars(format_bytes($childsa['bytes-out'])) ?>)
457
			<br/>
458
			<b><?= htmlspecialchars(gettext("Packets-Out:")) ?></b>
459
			<?= htmlspecialchars(number_format($childsa['packets-out'])) ?>
460
			<br/>
461
		</td>
462
		<td>
463

    
464
			<?= htmlspecialchars(ucfirst(strtolower($childsa['state']))) ?><br/>
465
			<?= ipsec_status_button('ajax', 'disconnect', 'child', $childsa['name'], $childsa['uniqueid'], true) ?>
466
		</td>
467
<?php
468
			}
469
?>
470
	</tr>
471
<?php
472
		}
473
			foreach ($p2disconnected as $p2conid => $p2) {
474
?>
475
	<tr>
476
		<td><?= htmlspecialchars($p2conid) ?></td>
477
		<td>
478
			<?= htmlspecialchars($p2['descr']) ?>
479
			<br/>
480
			<a class="fa fa-pencil" href="vpn_ipsec_phase2.php?uniqid=<?= htmlspecialchars($p2['uniqid']) ?>"
481
				title="<?= htmlspecialchars(gettext("Edit Phase 2 Entry")) ?>">
482
			</a>
483
		</td>
484
		<td>
485
			<?= htmlspecialchars(ipsec_idinfo_to_cidr($p2['localid'], false, $p2['mode'])) ?>
486
		</td>
487
		<td><!-- SPI n/a --></td>
488
		<td>
489
			<?= htmlspecialchars(ipsec_idinfo_to_cidr($p2['remoteid'], false, $p2['mode'])) ?>
490
		</td>
491
		<td><!-- Times n/a --></td>
492
		<td><!-- Algo is too much here --></td>
493
		<td><!-- Stats n/a --></td>
494
		<td>
495
			<?= htmlspecialchars(gettext("Disconnected")) ?><br/>
496
			<?= ipsec_status_button('ajax', 'connect', 'child', $p2conid, null, true) ?>
497
		</td>
498
	</tr>
499
<?php
500
			}
501
?>
502
	</tbody>
503
	</table>
504
	</td>
505
</tr>
506
<?php
507
	}
508

    
509
	$rgmap = array();
510
	$gateways_status = return_gateways_status(true);
511

    
512
	foreach ($cmap as $p1) {
513
		if (!array_key_exists('p1', $p1) ||
514
		    isset($p1['p1']['disabled'])) {
515
			continue;
516
		}
517
		$ph1ent = &$p1['p1'];
518
		$rgmap[$ph1ent['remote-gateway']] = $ph1ent['remote-gateway'];
519
		if ($p1connected[$ph1ent['ikeid']]) {
520
			continue;
521
		}
522
?>
523
<tr>
524
	<td>
525
		<?= htmlspecialchars(ipsec_conid($ph1ent)) ?>
526
	</td>
527
	<td>
528
		<?= htmlspecialchars($ph1ent['descr']) ?>
529
	</td>
530
	<td>
531
		<b><?= htmlspecialchars(gettext("ID:")) ?></b>
532
<?php
533
		list ($myid_type, $myid_data) = ipsec_find_id($ph1ent, "local", array(), $gateways_status);
534
		if (empty($myid_data)) {
535
			$myid_data = gettext("Unknown");
536
		}
537
?>
538
		<?= htmlspecialchars($myid_data) ?>
539
		<br/>
540
		<b><?= htmlspecialchars(gettext("Host:")) ?></b>
541
<?php
542
		$ph1src = ipsec_get_phase1_src($ph1ent, $gateways_status);
543
		if (empty($ph1src)) {
544
			$ph1src = gettext("Unknown");
545
		} else {
546
			$ph1src = str_replace(',', ', ', $ph1src);
547
		}
548
?>
549
		<?= htmlspecialchars($ph1src) ?>
550
	</td>
551
	<td>
552
<?php		if (!isset($ph1ent['mobile'])): ?>
553
		<b><?= htmlspecialchars(gettext("ID:")) ?></b>
554
<?php
555
		list ($peerid_type, $peerid_data) = ipsec_find_id($ph1ent, "peer", $rgmap, $gateways_status);
556
		if (empty($peerid_data)) {
557
			$peerid_data = gettext("Unknown");
558
		}
559
?>
560
		<?= htmlspecialchars($peerid_data) ?>
561
		<br/>
562
		<b><?= htmlspecialchars(gettext("Host:")) ?></b>
563
<?php
564
		$ph1dst = ipsec_get_phase1_dst($ph1ent);
565
		if (empty($ph1dst)) {
566
			$ph1dst = print(gettext("Unknown"));
567
		}
568
?>
569
		<?= htmlspecialchars($ph1dst) ?>
570
<?php		else: ?>
571
		<?= htmlspecialchars(gettext("Mobile Clients")) ?>
572
<?php		endif; ?>
573
	</td>
574
	<td></td>
575
	<td></td>
576
	<td></td>
577
	<td>
578
<?php		if (isset($ph1ent['mobile'])): ?>
579
		<?= htmlspecialchars(gettext("Awaiting connections")) ?>
580
<?php		else: ?>
581
		<?= htmlspecialchars(gettext("Disconnected")) ?>
582
		<br/>
583
		<?= ipsec_status_button('ajax', 'connect', 'all', ipsec_conid($ph1ent), null, true) ?>
584
		<br/><br/>
585
		<?= ipsec_status_button('ajax', 'connect', 'ike', ipsec_conid($ph1ent), null, true) ?>
586

    
587
<?php		endif; ?>
588
	</td>
589
</tr>
590
<?php
591
	}
592
	unset($p1connected, $p2connected, $p2disconnected, $rgmap);
593
}
594

    
595
$pgtitle = array(gettext("Status"), gettext("IPsec"), gettext("Overview"));
596
$pglinks = array("", "@self", "@self");
597
$shortcut_section = "ipsec";
598

    
599
include("head.inc");
600

    
601
$tab_array = array();
602
$tab_array[] = array(gettext("Overview"), true, "status_ipsec.php");
603
$tab_array[] = array(gettext("Leases"), false, "status_ipsec_leases.php");
604
$tab_array[] = array(gettext("SADs"), false, "status_ipsec_sad.php");
605
$tab_array[] = array(gettext("SPDs"), false, "status_ipsec_spd.php");
606
display_top_tabs($tab_array);
607
?>
608

    
609
<div class="panel panel-default">
610
	<div class="panel-heading"><h2 class="panel-title"><?= htmlspecialchars(gettext("IPsec Status")); ?></h2></div>
611
	<div class="panel-body table-responsive">
612
		<table class="table table-striped table-condensed table-hover sortable-theme-bootstrap" data-sortable>
613
			<thead>
614
				<tr>
615
					<th><?= htmlspecialchars(gettext("ID")) ?></th>
616
					<th><?= htmlspecialchars(gettext("Description") )?></th>
617
					<th><?= htmlspecialchars(gettext("Local")) ?></th>
618
					<th><?= htmlspecialchars(gettext("Remote")) ?></th>
619
					<th><?= htmlspecialchars(gettext("Role")) ?></th>
620
					<th><?= htmlspecialchars(gettext("Timers")) ?></th>
621
					<th><?= htmlspecialchars(gettext("Algo")) ?></th>
622
					<th><?= htmlspecialchars(gettext("Status")) ?></th>
623
				</tr>
624
			</thead>
625
			<tbody id="ipsec-body">
626
				<tr>
627
					<td colspan="10">
628
						<?= print_info_box('<i class="fa fa-gear fa-spin"></i>&nbsp;&nbsp;' .
629
						   gettext("Collecting IPsec status information."), "warning", "") ?>
630
					</td>
631
				</tr>
632
			</tbody>
633
		</table>
634
	</div>
635
</div>
636

    
637
<?php
638
unset($status);
639

    
640
if (ipsec_enabled()) {
641
	print('<div class="infoblock">');
642
} else {
643
	print('<div class="infoblock blockopen">');
644
}
645

    
646
print_info_box(sprintf(gettext('IPsec is not enabled. %1$sConfigure IPsec%2$s.'), '<a href="vpn_ipsec.php">', '</a>'), 'info', false);
647
?>
648
</div>
649

    
650
<script type="text/javascript">
651
//<![CDATA[
652

    
653
events.push(function() {
654
	ajax_lock = false;		// Mutex so we don't make a call until the previous call is finished
655
	sa_open = new Array();	// Array in which to keep the child SA show/hide state
656
	tryCount = 3;
657
	// Fetch the tbody contents from the server
658
	function update_table() {
659
		if (ajax_lock) {
660
			return;
661
		}
662

    
663
		ajax_lock = true;
664

    
665
		ajaxRequest = $.ajax(
666
			{
667
				url: "/status_ipsec.php",
668
				type: "post",
669
				data: {
670
					ajax: 	"ajax"
671
				},
672
				error: function(xhr, textStatus, errorThrown){
673
					//alert("error.... retrying");
674
					if (tryCount > 0){
675
						tryCount --;
676
						ajax_lock = false;
677
						update_table();
678
					}
679
					return;
680
				}
681
			}
682
		);
683

    
684
		// Deal with the results of the above ajax call
685
		ajaxRequest.done(function (response, textStatus, jqXHR) {
686
			if(textStatus === "success"){
687
				tryCount =3;
688
			}
689
			if (!response) {
690
				response = '<tr><td colspan="10"><?=print_info_box(addslashes(gettext("No IPsec status information available.")), "warning", "")?></td></tr>';
691
			}
692

    
693
			$('#ipsec-body').html(response);
694
			ajax_lock = false;
695

    
696
			// Update "Show child SA" handlers
697
			$('[id^=btnchildsa-]').click(function () {
698
				show_childsa($(this).prop("id").replace( 'btnchildsa-', ''));
699
			});
700

    
701
			// Check the sa_open array for child SAs that have been opened
702
			$('[id^=childsa-]').each(function(idx) {
703
				sa_idx = $(this).prop("id").replace( 'childsa-', '');
704

    
705
				if (sa_open[sa_idx]) {
706
					show_childsa(sa_idx);
707
				}
708
			});
709

    
710
			// re-attached the GET to POST handler
711
			interceptGET();
712

    
713
			// and do it again
714
			setTimeout(update_table, 5000);
715
		});
716
	}
717

    
718
	function show_childsa(said) {
719
		sa_open[said] = true;
720
		$('#childsa-' + said).show();
721
		$('#btnchildsa-' + said).hide();
722
	}
723

    
724
	// Populate the tbody on page load
725
	update_table();
726
});
727
//]]>
728
</script>
729

    
730
<?php
731
include("foot.inc"); ?>
(165-165/227)