Project

General

Profile

Download (20.6 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

    
38
global $g;
39

    
40
init_config_arr(array('ipsec', 'phase1'));
41

    
42
// If this is just an AJAX call to update the table body, just generate the body and quit
43
if ($_REQUEST['ajax']) {
44
	print_ipsec_body();
45
	exit;
46
}
47

    
48
if (($_POST['act'] == 'connect') || ($_POST['act'] == 'childconnect')) {
49
	if (ctype_digit($_POST['ikeid'])) {
50
		$ph1ent = ipsec_get_phase1($_POST['ikeid']);
51
		if (!empty($ph1ent)) {
52
			if (empty($ph1ent['iketype']) || ($ph1ent['iketype'] == 'ikev1') || isset($ph1ent['splitconn'])) {
53
				$ph2entries = ipsec_get_number_of_phase2($ph1ent['ikeid']);
54
				for ($i = 0; $i < $ph2entries; $i++) {
55
					if (get_ipsecifnum($ph1ent['ikeid'], $i)) {
56
						$connum = get_ipsecifnum($ph1ent['ikeid'], $i);
57
					} else {
58
						$connum = "{$ph1ent['ikeid']}00000";
59
					}
60
					$connid = escapeshellarg("con" . $connum);
61
					if ($_POST['act'] != 'childconnect') {
62
						mwexec_bg("/usr/local/sbin/swanctl --terminate --child {$connid}");
63
					}
64
					mwexec_bg("/usr/local/sbin/swanctl --initiate --child {$connid}");
65
				}
66
			} else {
67
				if (get_ipsecifnum($ph1ent['ikeid'], 0)) {
68
					$connum = get_ipsecifnum($ph1ent['ikeid'], 0);
69
				} else {
70
					$connum = "{$ph1ent['ikeid']}00000";
71
				}
72
				if ($_POST['act'] != 'childconnect') {
73
					mwexec_bg("/usr/local/sbin/swanctl --terminate --ike " . escapeshellarg("con{$connum}"));
74
				}
75
				mwexec_bg("/usr/local/sbin/swanctl --initiate --child " . escapeshellarg("con{$connum}"));
76
			}
77
		}
78
	}
79
} else if ($_POST['act'] == 'ikedisconnect') {
80
	if (!empty($_POST['ikesaid']) && ctype_digit($_POST['ikesaid'])) {
81
		mwexec_bg("/usr/local/sbin/swanctl --terminate --ike " . escapeshellarg($_POST['ikeid']) . " --ike-id " .escapeshellarg($_POST['ikesaid']));
82
	} else {
83
		mwexec_bg("/usr/local/sbin/swanctl --terminate --ike " . escapeshellarg($_POST['ikeid']));
84
	}
85
} else if ($_POST['act'] == 'childdisconnect') {
86
	//pull out number from id
87
		if (!empty($_POST['ikesaid']) && ctype_digit($_POST['ikesaid'])) {
88
			mwexec_bg("/usr/local/sbin/swanctl --terminate --child " . escapeshellarg($_POST['ikeid']) . " --child-id " . escapeshellarg($_POST['ikesaid']));
89
		}
90
}
91

    
92
// Table body is composed here so that it can be more easily updated via AJAX
93
function print_ipsec_body() {
94
	global $config;
95
	$a_phase1 = &$config['ipsec']['phase1'];
96
	$conmap = array();
97
	foreach ($a_phase1 as $ph1ent) {
98
		if (get_ipsecifnum($ph1ent['ikeid'], 0)) {
99
			$cname = "con" . get_ipsecifnum($ph1ent['ikeid'], 0);
100
		} else {
101
			$cname = "con{$ph1ent['ikeid']}00000";
102
		}
103
		$conmap[$cname] = $ph1ent['ikeid'];
104
	}
105

    
106
	$status = ipsec_list_sa();
107
	$ipsecconnected = array();
108
	if (is_array($status)) {
109
		foreach ($status as $ikeid => $ikesa) {
110
			//check which array format
111
			if (isset($ikesa['con-id'])) {
112
				$con_id = substr($ikesa['con-id'], 3);
113
			} else {
114
				$con_id = filter_var($ikeid, FILTER_SANITIZE_NUMBER_INT);
115
			}
116
			$con_name = "con" . $con_id;
117
			if ($ikesa['version'] == 1) {
118
				$ph1idx = $conmap[$con_name];
119
				$ipsecconnected[$ph1idx] = $ph1idx;
120
			} else {
121
				if (!ipsec_ikeid_used($con_id)) {
122
					// probably a v2 with split connection then
123
					$ph1idx = $conmap[$con_name];
124
					$ipsecconnected[$ph1idx] = $ph1idx;
125
				} else {
126
					$ipsecconnected[$con_id] = $ph1idx = $con_id;
127
				}
128
			}
129

    
130
			print("<tr>\n");
131

    
132
			print("<td>\n");
133
			print(htmlspecialchars($ikesa['con-id'])) . ":\n";
134
			print('#' . htmlspecialchars($ikesa['uniqueid']));
135
			print("</td>\n");
136

    
137
			print("<td>\n");
138
			if (is_array($a_phase1) && htmlspecialchars(ipsec_get_descr($ph1idx)) == "") {
139
				foreach ($a_phase1 as $ph1) {
140
					if ($con_id == $ph1['ikeid'] && isset($ph1['mobile'])) {
141
						print(htmlspecialchars($ph1['descr']));
142
						break;
143
					}
144
				}
145
			}
146
			print(htmlspecialchars(ipsec_get_descr($ph1idx)));
147
			print("</td>\n");
148

    
149
			print("<td>\n");
150

    
151
			print("<b>ID:</b> ");
152
			if (!empty($ikesa['local-id'])) {
153
				if ($ikesa['local-id'] == '%any') {
154
					print(gettext('Any identifier'));
155
				} else {
156
					print(htmlspecialchars($ikesa['local-id']));
157
				}
158
			} else {
159
				print(gettext("Unknown"));
160
			}
161

    
162
			print("<br/>");
163
			print("<b>Host:</b> ");
164

    
165
			if (!empty($ikesa['local-host'])) {
166
				$lhost = $ikesa['local-host'];
167
				if (!empty($ikesa['local-port'])) {
168
					if (is_ipaddrv6($ikesa['local-host'])) {
169
						$lhost = "[{$lhost}]";
170
					}
171
					$lhost .= ":{$ikesa['local-port']}";
172
				}
173
				print(htmlspecialchars($lhost));
174

    
175
			} else {
176
				print(gettext("Unknown"));
177
			}
178

    
179
			print("<br/>");
180
			print("<b>SPI:</b> " . htmlspecialchars( ($ikesa['initiator'] == 'yes') ? $ikesa['initiator-spi'] : $ikesa['responder-spi'] ));
181

    
182
			/*
183
			 * XXX: local-nat-t was defined by pfSense
184
			 * When strongswan team accepted the change, they changed it to
185
			 * nat-local. Keep both for a while and remove local-nat-t in
186
			 * the future
187
			 */
188
			if (isset($ikesa['local-nat-t']) || isset($ikesa['nat-local'])) {
189
				print(" NAT-T");
190
			}
191

    
192
			print("</td>\n");
193
			print("<td>\n");
194

    
195
			print("<b>ID:</b> ");
196

    
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

    
206
			if (!empty($ikesa['remote-xauth-id'])) {
207
				echo htmlspecialchars($ikesa['remote-xauth-id']);
208
				echo "<br/>{$identity}";
209
			} elseif (!empty($ikesa['remote-eap-id'])) {
210
				echo htmlspecialchars($ikesa['remote-eap-id']);
211
				echo "<br/>{$identity}";
212
			} else {
213
				if (empty($identity)) {
214
					print(gettext("Unknown"));
215
				} else {
216
					print($identity);
217
				}
218
			}
219

    
220
			print("<br/>");
221
			print("<b>Host:</b> ");
222

    
223
			if (!empty($ikesa['remote-host'])) {
224
				$rhost = $ikesa['remote-host'];
225
				if (!empty($ikesa['remote-port'])) {
226
					if (is_ipaddrv6($ikesa['remote-host'])) {
227
						$rhost = "[{$rhost}]";
228
					}
229
					$rhost .= ":{$ikesa['remote-port']}";
230
				}
231
				print(htmlspecialchars($rhost));
232
			} else {
233
				print(gettext("Unknown"));
234
			}
235
			/*
236
			 * XXX: remote-nat-t was defined by pfSense
237
			 * When strongswan team accepted the change, they changed it to
238
			 * nat-remote. Keep both for a while and remove remote-nat-t in
239
			 * the future
240
			 */
241
			if (isset($ikesa['remote-nat-t']) || isset($ikesa['nat-remote'])) {
242
				print(" NAT-T");
243
			}
244

    
245
			print("<br/>");
246
			print("<b>SPI:</b> " . htmlspecialchars( ($ikesa['initiator'] == 'yes') ? $ikesa['responder-spi'] : $ikesa['initiator-spi'] ));
247

    
248
			print("</td>\n");
249
			print("<td>\n");
250
			print("IKEv" . htmlspecialchars($ikesa['version']));
251
			print("<br/>\n");
252

    
253
			if ($ikesa['initiator'] == 'yes') {
254
				print("initiator");
255
			} else {
256
				print("responder");
257
			}
258

    
259
			print("</td>\n");
260
			print("<td>\n");
261
			if ($ikesa['version'] == 2) {
262
				print("<b>" . gettext("Rekey:") . "</b> ");
263
				if (!empty($ikesa['rekey-time'])) {
264
					print(htmlspecialchars($ikesa['rekey-time']) . gettext("s (") . convert_seconds_to_dhms($ikesa['rekey-time']) . ")");
265
				} else {
266
					print(gettext("Disabled"));
267
				}
268
				print("<br/>");
269
			}
270
			print("<b>" . gettext("Reauth:") . "</b> ");
271
			if (!empty($ikesa['reauth-time'])) {
272
				print(htmlspecialchars($ikesa['reauth-time']) . gettext("s (") . convert_seconds_to_dhms($ikesa['reauth-time']) . ")");
273
			} else {
274
				print(gettext("Disabled"));
275
			}
276
			print("</td>\n");
277
			print("<td>\n");
278
			print(htmlspecialchars($ikesa['encr-alg']));
279
			if (!empty($ikesa['encr-keysize'])) {
280
				print(" (" . htmlspecialchars($ikesa['encr-keysize']) . ")");
281
			}
282
			print("<br/>");
283
			print(htmlspecialchars($ikesa['integ-alg']));
284
			print("<br/>");
285
			print(htmlspecialchars($ikesa['prf-alg']));
286
			print("<br/>\n");
287
			print(htmlspecialchars($ikesa['dh-group']));
288
			print("</td>\n");
289
			print("<td>\n");
290

    
291
			if ($ikesa['state'] == 'ESTABLISHED') {
292
				print('<span class="text-success">');
293
			} else {
294
				print('<span>');
295
			}
296

    
297
			print(ucfirst(htmlspecialchars($ikesa['state'])));
298

    
299
			if ($ikesa['state'] == 'ESTABLISHED') {
300
				print("<br/>");
301
				printf(gettext('%1$s seconds (%2$s) ago'), htmlspecialchars($ikesa['established']), convert_seconds_to_dhms($ikesa['established']));
302
			}
303

    
304
			print("</span><br /><br />");
305

    
306
			if ($ikesa['state'] != 'ESTABLISHED') {
307

    
308
				print('<a href="status_ipsec.php?act=connect&amp;ikeid=' . $con_id . '&amp;ikesaid=' .$ikesa['uniqueid'] . '" class="btn btn-xs btn-success" data-toggle="tooltip" title="' . gettext("Connect VPN"). '" usepost>');
309
				print('<i class="fa fa-sign-in icon-embed-btn"></i>');
310
				print(gettext("Connect VPN"));
311
				print("</a>\n");
312

    
313
			} else {
314

    
315
				print('<a href="status_ipsec.php?act=ikedisconnect&amp;ikeid=' . $ikesa['con-id']. '&amp;ikesaid=' .$ikesa['uniqueid'] . '"class="btn btn-xs btn-danger" data-toggle="tooltip" title="' . gettext("Disconnect VPN") . '" usepost>');
316
				print('<i class="fa fa-trash icon-embed-btn"></i>');
317
				print(gettext("Disconnect"));
318
				print("</a><br />\n");
319

    
320
			}
321
			if (empty($ikesa['child-sas'])) {
322
				print('<br/><a href="status_ipsec.php?act=childconnect&amp;ikeid=' . substr($con_id, 0, -3) . '" class="btn btn-xs btn-success" data-toggle="tooltip" title="' . gettext("Connect Children"). '" usepost>');
323
				print('<i class="fa fa-sign-in icon-embed-btn"></i>');
324
				print(gettext("Connect Children"));
325
				print("</a>\n");
326
			}
327

    
328
			print("</td>\n");
329
			print("</tr>\n");
330
			print("<tr>\n");
331
			print("<td colspan = 10>\n");
332

    
333
			if (is_array($ikesa['child-sas']) && (count($ikesa['child-sas']) > 0)) {
334
				$child_key = "";
335
				foreach ($ikesa['child-sas'] as $key => $val){
336
					$child_key = $key;
337
					break;
338
				}
339

    
340
				print('<div>');
341
				print('<a type="button" id="btnchildsa-'. $child_key .  '" class="btn btn-sm btn-info">');
342
				print('<i class="fa fa-plus-circle icon-embed-btn"></i>');
343
				print(sprintf(gettext('Show child SA entries (%d)'), count($ikesa['child-sas'])));
344
				print("</a>\n");
345
				print("	</div>\n");
346

    
347
				print('<table class="table table-hover table-condensed" id="childsa-'.$child_key . '" style="display:none">');
348
				print("<thead>\n");
349
				print('<tr class="bg-info">');
350
				print('<th>' . gettext("IPsec ID") . '</th>');
351
				print('<th>' . gettext("Local subnets") . '</th>');
352
				print('<th>' . gettext("Local SPI(s)") . '</th>');
353
				print('<th>' . gettext("Remote subnets") . '</th>');
354
				print('<th>' . gettext("Times") . '</th>');
355
				print('<th>' . gettext("Algo") . '</th>');
356
				print('<th>' . gettext("Stats") . '</th>');
357
				print('<th><!-- Buttons --></th>');
358
				print("</tr\n");
359
				print("</thead>\n");
360
				print("<tbody>\n");
361

    
362
				foreach ($ikesa['child-sas'] as $childid => $childsa) {
363
					print("<tr>");
364
					print("<td>\n");
365
					print($childsa['name'] . ":<br />");
366
					print("#" . $childsa['uniqueid']);
367
					print("</td>\n");
368
					print("<td>\n");
369

    
370
					if (is_array($childsa['local-ts'])) {
371
						foreach ($childsa['local-ts'] as $lnets) {
372
							print(htmlspecialchars(ipsec_fixup_network($lnets)) . "<br />");
373
						}
374
					} else {
375
						print(gettext("Unknown"));
376
					}
377

    
378
					print("</td>\n");
379
					print("<td>\n");
380

    
381
					if (isset($childsa['spi-in'])) {
382
						print("<b>" . gettext("Local:") . "</b> " . htmlspecialchars($childsa['spi-in']));
383
					}
384

    
385
					if (isset($childsa['spi-out'])) {
386
						print("<br/>");
387
						print("<b>" . gettext('Remote:') . "</b> " . htmlspecialchars($childsa['spi-out']));
388
					}
389

    
390
					print("</td>\n");
391
					print("<td>\n");
392

    
393
					if (is_array($childsa['remote-ts'])) {
394
						foreach ($childsa['remote-ts'] as $rnets) {
395
							print(htmlspecialchars(ipsec_fixup_network($rnets)) . '<br />');
396
						}
397
					} else {
398
						print(gettext("Unknown"));
399
					}
400

    
401
					print("</td>\n");
402
					print("<td>\n");
403

    
404
					printf(gettext('%3$sRekey: %4$s%1$s seconds (%2$s)'), htmlspecialchars($childsa['rekey-time']), convert_seconds_to_dhms($childsa['rekey-time']), "<b>", "</b>");
405
					print('<br/>');
406
					printf(gettext('%3$sLife: %4$s%1$s seconds (%2$s)'), htmlspecialchars($childsa['life-time']), convert_seconds_to_dhms($childsa['life-time']), "<b>", "</b>");
407
					print('<br/>');
408
					printf(gettext('%3$sInstall: %4$s%1$s seconds (%2$s)'), htmlspecialchars($childsa['install-time']), convert_seconds_to_dhms($childsa['install-time']), "<b>", "</b>");
409

    
410

    
411
					print("</td>\n");
412
					print("<td>\n");
413

    
414
					print(htmlspecialchars($childsa['encr-alg']));
415
					if (!empty($childsa['encr-keysize'])) {
416
						print(" (" . htmlspecialchars($childsa['encr-keysize']) . ")");
417
					}
418
					print('<br/>');
419

    
420
					print(htmlspecialchars($childsa['integ-alg']) . '<br/>');
421

    
422
					if (!empty($childsa['prf-alg'])) {
423
						print(htmlspecialchars($childsa['prf-alg']) . '<br/>');
424
					}
425

    
426
					if (!empty($childsa['dh-group'])) {
427
						print(htmlspecialchars($childsa['dh-group']) . '<br/>');
428
					}
429

    
430
					if (!empty($childsa['esn'])) {
431
						print(htmlspecialchars($childsa['esn']) . '<br/>');
432
					}
433

    
434
					print(gettext("IPComp: "));
435
					if (!empty($childsa['cpi-in']) || !empty($childsa['cpi-out'])) {
436
						print(htmlspecialchars($childsa['cpi-in']) . " " . htmlspecialchars($childsa['cpi-out']));
437
					} else {
438
						print(gettext('none'));
439
					}
440

    
441
					print("</td>\n");
442
					print("<td>\n");
443

    
444
					print("<b>" . gettext("Bytes-In:") . "</b> " . htmlspecialchars(number_format($childsa['bytes-in'])) . ' (' . htmlspecialchars(format_bytes($childsa['bytes-in'])) . ')<br/>');
445
					print("<b>" . gettext("Packets-In:") . "</b> " . htmlspecialchars(number_format($childsa['packets-in'])) . '<br/>');
446
					print("<b>" . gettext("Bytes-Out:") . "</b> " . htmlspecialchars(number_format($childsa['bytes-out'])) . ' (' . htmlspecialchars(format_bytes($childsa['bytes-out'])) . ')<br/>');
447
					print("<b>" . gettext("Packets-Out:") . "</b> " . htmlspecialchars(number_format($childsa['packets-out'])) . '<br/>');
448

    
449
					print("</td>\n");
450
					print("<td>\n");
451
					print('<a href="status_ipsec.php?act=childdisconnect&amp;ikeid=' . $childsa['name'] . '&amp;ikesaid=' . $childsa['uniqueid'] . '" class="btn btn-xs btn-warning" data-toggle="tooltip" title="' . gettext('Disconnect Child SA') . '" usepost>');
452
					print('<i class="fa fa-trash icon-embed-btn"></i>');
453
					print(gettext("Disconnect"));
454
					print("</a>\n");
455
					print("</td>\n");
456
					print("</tr>\n");
457

    
458
				}
459

    
460
				print("</tbody>\n");
461
				print("	</table>\n");
462
				print("</td>\n");
463
				print("</tr>\n");
464

    
465
			}
466

    
467
			unset($con_id);
468
		}
469

    
470
	}
471

    
472
	$rgmap = array();
473
	if (is_array($a_phase1)) {
474
		foreach ($a_phase1 as $ph1ent) {
475
			if (isset($ph1ent['disabled'])) {
476
				continue;
477
			}
478

    
479
			$rgmap[$ph1ent['remote-gateway']] = $ph1ent['remote-gateway'];
480

    
481
			if ($ipsecconnected[$ph1ent['ikeid']]) {
482
				continue;
483
			}
484

    
485
			print("<tr>\n");
486
			print("<td></td>\n");
487
			print("<td>\n");
488
			print(htmlspecialchars($ph1ent['descr']));
489
			print("</td>\n");
490
			print("<td>\n");
491
			print("<b>ID:</b> \n");
492
			list ($myid_type, $myid_data) = ipsec_find_id($ph1ent, "local");
493

    
494
			if (empty($myid_data)) {
495
				print(gettext("Unknown"));
496
			} else {
497
				print(htmlspecialchars($myid_data));
498
			}
499

    
500
			print("<br/>\n");
501
			print("<b>Host:</b> \n");
502
			$ph1src = ipsec_get_phase1_src($ph1ent);
503

    
504
			if (empty($ph1src)) {
505
				print(gettext("Unknown"));
506
			} else {
507
				print(htmlspecialchars(str_replace(',', ', ', $ph1src)));
508
			}
509

    
510
			print("</td>\n");
511
			print("<td>\n");
512

    
513
			print("<b>ID:</b> \n");
514

    
515
			list ($peerid_type, $peerid_data) = ipsec_find_id($ph1ent, "peer", $rgmap);
516

    
517
			if (empty($peerid_data)) {
518
				print(gettext("Unknown"));
519
			} else {
520
				print(htmlspecialchars($peerid_data));
521
			}
522

    
523
			print("<br/>\n");
524
			print("<b>Host:</b> \n");
525

    
526
			$ph1src = ipsec_get_phase1_dst($ph1ent);
527

    
528
			if (empty($ph1src)) {
529
				print(gettext("Unknown"));
530
			} else {
531
				print(htmlspecialchars($ph1src));
532
			}
533

    
534
			print("</td>\n");
535
			print("<td>\n");
536
			print("</td>\n");
537
			print("<td>\n");
538
			print("</td>\n");
539
			print("<td>\n");
540
			print("</td>\n");
541

    
542
			if (isset($ph1ent['mobile'])) {
543

    
544
				print("<td>\n");
545
				print(gettext("Awaiting connections"));
546
				print("</td>\n");
547
				print("<td>\n");
548
				print("</td>\n");
549
				print("</td>\n");
550
			} else {
551

    
552
				print("<td>\n");
553
				print(gettext("Disconnected"));
554
				print("<br/>\n");
555
				print('<a href="status_ipsec.php?act=connect&amp;ikeid=' . $ph1ent['ikeid'] . '" class="btn btn-xs btn-success" usepost>');
556
				print('<i class="fa fa-sign-in icon-embed-btn"></i>');
557
				print(gettext("Connect VPN"));
558
				print("</a>\n");
559
				print("</td>\n");
560

    
561
			}
562
			print("</tr>\n");
563
		}
564
	}
565

    
566
	unset($ipsecconnected, $phase1, $rgmap);
567
}
568

    
569
$pgtitle = array(gettext("Status"), gettext("IPsec"), gettext("Overview"));
570
$pglinks = array("", "@self", "@self");
571
$shortcut_section = "ipsec";
572

    
573
include("head.inc");
574

    
575
$tab_array = array();
576
$tab_array[] = array(gettext("Overview"), true, "status_ipsec.php");
577
$tab_array[] = array(gettext("Leases"), false, "status_ipsec_leases.php");
578
$tab_array[] = array(gettext("SADs"), false, "status_ipsec_sad.php");
579
$tab_array[] = array(gettext("SPDs"), false, "status_ipsec_spd.php");
580
display_top_tabs($tab_array);
581
?>
582

    
583
<div class="panel panel-default">
584
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("IPsec Status");?></h2></div>
585
	<div class="panel-body table-responsive">
586
		<table class="table table-striped table-condensed table-hover sortable-theme-bootstrap" data-sortable>
587
			<thead>
588
				<tr>
589
					<th><?=gettext("IPsec ID")?></th>
590
					<th><?=gettext("Description")?></th>
591
					<th><?=gettext("Local")?></th>
592
					<th><?=gettext("Remote")?></th>
593
					<th><?=gettext("Role")?></th>
594
					<th><?=gettext("Timers")?></th>
595
					<th><?=gettext("Algo")?></th>
596
					<th><?=gettext("Status")?></th>
597
					<th></th>
598
				</tr>
599
			</thead>
600
			<tbody id="ipsec-body">
601
				<tr>
602
					<td colspan="10">
603
						<?=print_info_box('<i class="fa fa-gear fa-spin"></i>&nbsp;&nbsp;' .
604
						   gettext("Collecting IPsec status information."), "warning", "")?>
605
					</td>
606
				</tr>
607
			</tbody>
608
		</table>
609
	</div>
610
</div>
611

    
612
<?php
613
unset($status);
614

    
615
if (ipsec_enabled()) {
616
	print('<div class="infoblock">');
617
} else {
618
	print('<div class="infoblock blockopen">');
619
}
620

    
621
print_info_box(sprintf(gettext('IPsec can be configured %1$shere%2$s.'), '<a href="vpn_ipsec.php">', '</a>'), 'info', false);
622
?>
623
</div>
624

    
625
<script type="text/javascript">
626
//<![CDATA[
627

    
628
events.push(function() {
629
	ajax_lock = false;		// Mutex so we don't make a call until the previous call is finished
630
	sa_open = new Array();	// Array in which to keep the child SA show/hide state
631
	tryCount = 3;
632
	// Fetch the tbody contents from the server
633
	function update_table() {
634
		if (ajax_lock) {
635
			return;
636
		}
637

    
638
		ajax_lock = true;
639

    
640
		ajaxRequest = $.ajax(
641
			{
642
				url: "/status_ipsec.php",
643
				type: "post",
644
				data: {
645
					ajax: 	"ajax"
646
				},
647
				error: function(xhr, textStatus, errorThrown){
648
					//alert("error.... retrying");
649
					if (tryCount > 0){
650
						tryCount --;
651
						ajax_lock = false;
652
						update_table();
653
					}
654
					return;
655
				}
656
			}
657
		);
658

    
659
		// Deal with the results of the above ajax call
660
		ajaxRequest.done(function (response, textStatus, jqXHR) {
661
			if(textStatus === "success"){
662
				tryCount =3;
663
			}
664
			if (!response) {
665
				response = '<tr><td colspan="10"><?=print_info_box(addslashes(gettext("No IPsec status information available.")), "warning", "")?></td></tr>';
666
			}
667

    
668
			$('#ipsec-body').html(response);
669
			ajax_lock = false;
670

    
671
			// Update "Show child SA" handlers
672
			$('[id^=btnchildsa-]').click(function () {
673
				show_childsa($(this).prop("id").replace( 'btnchildsa-', ''));
674
			});
675

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

    
680
				if (sa_open[sa_idx]) {
681
					show_childsa(sa_idx);
682
				}
683
			});
684

    
685
			// re-attached the GET to POST handler
686
			interceptGET();
687

    
688
			// and do it again
689
			setTimeout(update_table, 5000);
690
		});
691
	}
692

    
693
	function show_childsa(said) {
694
		sa_open[said] = true;
695
		$('#childsa-' + said).show();
696
		$('#btnchildsa-' + said).hide();
697
	}
698

    
699
	// Populate the tbody on page load
700
	update_table();
701
});
702
//]]>
703
</script>
704

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