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

    
78
	$cmap = ipsec_map_config_by_id();
79
	$status = ipsec_list_sa();
80

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

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

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

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

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

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

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

    
508
	$rgmap = array();
509

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

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

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

    
597
include("head.inc");
598

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

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

    
635
<?php
636
unset($status);
637

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

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

    
648
<script type="text/javascript">
649
//<![CDATA[
650

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

    
661
		ajax_lock = true;
662

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

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

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

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

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

    
703
				if (sa_open[sa_idx]) {
704
					show_childsa(sa_idx);
705
				}
706
			});
707

    
708
			// re-attached the GET to POST handler
709
			interceptGET();
710

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

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

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

    
728
<?php
729
include("foot.inc"); ?>
(169-169/232)