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
	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 $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
					    isset($cmap[$ikeid]['p2']) && is_array($cmap[$ikeid]['p2'])) {
118
						foreach ($cmap[$ikeid]['p2'] as $p2) {
119
							$p2connected[$p2['reqid']] = $childsa['name'];
120
						}
121
					}
122
				}
123
			}
124
		}
125
		$p2disconnected = array();
126
		if (!$cmap[$ikeid]['p1']['mobile'] &&
127
		    isset($cmap[$ikeid]) &&
128
		    is_array($cmap[$ikeid]) &&
129
		    is_array($cmap[$ikeid]['p2'])) {
130
			foreach ($cmap[$ikeid]['p2'] as $p2) {
131
				if (!array_key_exists($p2['reqid'], $p2connected)) {
132
					/* This P2 is not connected */
133
					$p2conid = ipsec_conid($cmap[$ikeid]['p1'], $p2);
134
					$p2disconnected[$p2conid] = $p2;
135
				}
136
			}
137
		}
138
?>
139

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

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

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

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

    
510
	$rgmap = array();
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());
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);
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);
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-solid 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('%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/228)