Project

General

Profile

Download (20 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($_POST['ikeid']);
54
				for ($i = 0; $i < $ph2entries; $i++) {
55
					$connid = escapeshellarg("con{$_POST['ikeid']}00{$i}");
56
					if ($_POST['act'] != 'childconnect') {
57
						mwexec_bg("/usr/local/sbin/swanctl --terminate --child {$connid}");
58
					}
59
					mwexec_bg("/usr/local/sbin/swanctl --initiate --child {$connid}");
60
				}
61
			} else {
62
				if ($_POST['act'] != 'childconnect') {
63
					mwexec_bg("/usr/local/sbin/swanctl --terminate --ike con" . escapeshellarg($_POST['ikeid'] . '000'));
64
				}
65
				mwexec_bg("/usr/local/sbin/swanctl --initiate --child con" . escapeshellarg($_POST['ikeid'] . '000'));
66
			}
67
		}
68
	}
69
} else if ($_POST['act'] == 'ikedisconnect') {
70

    
71
	if (!empty($_POST['ikesaid']) && ctype_digit($_POST['ikesaid'])) {
72
		mwexec_bg("/usr/local/sbin/swanctl --terminate --ike " . escapeshellarg($_POST['ikeid']) . " --ike-id " .escapeshellarg($_POST['ikesaid']));
73
	} else {
74
		mwexec_bg("/usr/local/sbin/swanctl --terminate --ike " . escapeshellarg($_POST['ikeid']));
75
	}
76
} else if ($_POST['act'] == 'childdisconnect') {
77
	//pull out number from id
78
		if (!empty($_POST['ikesaid']) && ctype_digit($_POST['ikesaid'])) {
79
			mwexec_bg("/usr/local/sbin/swanctl --terminate --child " . escapeshellarg($_POST['ikeid']) . " --child-id " . escapeshellarg($_POST['ikesaid']));
80
		}
81
}
82

    
83
// Table body is composed here so that it can be more easily updated via AJAX
84
function print_ipsec_body() {
85
	global $config;
86
	$a_phase1 = &$config['ipsec']['phase1'];
87
	$status = ipsec_list_sa();
88
	$ipsecconnected = array();
89
	if (is_array($status)) {
90
		foreach ($status as $ikeid => $ikesa) {
91
			//check which array format
92
			if(isset($ikesa['con-id'])){
93
				$con_id = substr($ikesa['con-id'],3);
94
			}else{
95
				$con_id = filter_var($ikeid, FILTER_SANITIZE_NUMBER_INT);
96
			}
97
			if ($ikesa['version'] == 1) {
98
				$ph1idx = substr($con_id, 0, strrpos(substr($con_id, 0, -1), '00'));
99
				$ipsecconnected[$ph1idx] = $ph1idx;
100
			} else {
101
				if (!ipsec_ikeid_used($con_id)) {
102
					// probably a v2 with split connection then
103
					$ph1idx = substr($con_id, 0, strrpos(substr($con_id, 0, -1), '00'));
104
					$ipsecconnected[$ph1idx] = $ph1idx;
105
				} else {
106
					$ipsecconnected[$con_id] = $ph1idx = $con_id;
107
				}
108
			}
109

    
110
			print("<tr>\n");
111

    
112
			print("<td>\n");
113
			print(htmlspecialchars($ikesa['con-id'])) . ":\n";
114
			print('#' . htmlspecialchars($ikesa['uniqueid']));
115
			print("</td>\n");
116

    
117
			print("<td>\n");
118
			if (is_array($a_phase1) && htmlspecialchars(ipsec_get_descr($ph1idx)) == "") {
119
				foreach ($a_phase1 as $ph1) {
120
					if($con_id == $ph1['ikeid'] && isset($ph1['mobile']) ){
121
						print(htmlspecialchars($ph1['descr']));
122
						break;
123
					}
124
				}
125
			}
126
			print(htmlspecialchars(ipsec_get_descr($ph1idx)));
127
			print("</td>\n");
128

    
129
			print("<td>\n");
130

    
131
			print("<b>ID:</b> ");
132
			if (!empty($ikesa['local-id'])) {
133
				if ($ikesa['local-id'] == '%any') {
134
					print(gettext('Any identifier'));
135
				} else {
136
					print(htmlspecialchars($ikesa['local-id']));
137
				}
138
			} else {
139
				print(gettext("Unknown"));
140
			}
141

    
142
			print("<br/>");
143
			print("<b>Host:</b> ");
144

    
145
			if (!empty($ikesa['local-host'])) {
146
				$lhost = $ikesa['local-host'];
147
				if (!empty($ikesa['local-port'])) {
148
					if (is_ipaddrv6($ikesa['local-host'])) {
149
						$lhost = "[{$lhost}]";
150
					}
151
					$lhost .= ":{$ikesa['local-port']}";
152
				}
153
				print(htmlspecialchars($lhost));
154

    
155
			} else {
156
				print(gettext("Unknown"));
157
			}
158

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

    
162
			/*
163
			 * XXX: local-nat-t was defined by pfSense
164
			 * When strongswan team accepted the change, they changed it to
165
			 * nat-local. Keep both for a while and remove local-nat-t in
166
			 * the future
167
			 */
168
			if (isset($ikesa['local-nat-t']) || isset($ikesa['nat-local'])) {
169
				print(" NAT-T");
170
			}
171

    
172
			print("</td>\n");
173
			print("<td>\n");
174

    
175
			print("<b>ID:</b> ");
176

    
177
			$identity = "";
178
			if (!empty($ikesa['remote-id'])) {
179
				if ($ikesa['remote-id'] == '%any') {
180
					$identity = htmlspecialchars(gettext('Any identifier'));
181
				} else {
182
					$identity = htmlspecialchars($ikesa['remote-id']);
183
				}
184
			}
185

    
186
			if (!empty($ikesa['remote-xauth-id'])) {
187
				echo htmlspecialchars($ikesa['remote-xauth-id']);
188
				echo "<br/>{$identity}";
189
			} elseif (!empty($ikesa['remote-eap-id'])) {
190
				echo htmlspecialchars($ikesa['remote-eap-id']);
191
				echo "<br/>{$identity}";
192
			} else {
193
				if (empty($identity)) {
194
					print(gettext("Unknown"));
195
				} else {
196
					print($identity);
197
				}
198
			}
199

    
200
			print("<br/>");
201
			print("<b>Host:</b> ");
202

    
203
			if (!empty($ikesa['remote-host'])) {
204
				$rhost = $ikesa['remote-host'];
205
				if (!empty($ikesa['remote-port'])) {
206
					if (is_ipaddrv6($ikesa['remote-host'])) {
207
						$rhost = "[{$rhost}]";
208
					}
209
					$rhost .= ":{$ikesa['remote-port']}";
210
				}
211
				print(htmlspecialchars($rhost));
212
			} else {
213
				print(gettext("Unknown"));
214
			}
215
			/*
216
			 * XXX: remote-nat-t was defined by pfSense
217
			 * When strongswan team accepted the change, they changed it to
218
			 * nat-remote. Keep both for a while and remove remote-nat-t in
219
			 * the future
220
			 */
221
			if (isset($ikesa['remote-nat-t']) || isset($ikesa['nat-remote'])) {
222
				print(" NAT-T");
223
			}
224

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

    
228
			print("</td>\n");
229
			print("<td>\n");
230
			print("IKEv" . htmlspecialchars($ikesa['version']));
231
			print("<br/>\n");
232

    
233
			if ($ikesa['initiator'] == 'yes') {
234
				print("initiator");
235
			} else {
236
				print("responder");
237
			}
238

    
239
			print("</td>\n");
240
			print("<td>\n");
241
			if ($ikesa['version'] == 2) {
242
				print("<b>" . gettext("Rekey:") . "</b> ");
243
				if (!empty($ikesa['rekey-time'])) {
244
					print(htmlspecialchars($ikesa['rekey-time']) . gettext("s (") . convert_seconds_to_dhms($ikesa['rekey-time']) . ")");
245
				} else {
246
					print(gettext("Disabled"));
247
				}
248
				print("<br/>");
249
			}
250
			print("<b>" . gettext("Reauth:") . "</b> ");
251
			if (!empty($ikesa['reauth-time'])) {
252
				print(htmlspecialchars($ikesa['reauth-time']) . gettext("s (") . convert_seconds_to_dhms($ikesa['reauth-time']) . ")");
253
			} else {
254
				print(gettext("Disabled"));
255
			}
256
			print("</td>\n");
257
			print("<td>\n");
258
			print(htmlspecialchars($ikesa['encr-alg']));
259
			if (!empty($ikesa['encr-keysize'])) {
260
				print(" (" . htmlspecialchars($ikesa['encr-keysize']) . ")");
261
			}
262
			print("<br/>");
263
			print(htmlspecialchars($ikesa['integ-alg']));
264
			print("<br/>");
265
			print(htmlspecialchars($ikesa['prf-alg']));
266
			print("<br/>\n");
267
			print(htmlspecialchars($ikesa['dh-group']));
268
			print("</td>\n");
269
			print("<td>\n");
270

    
271
			if ($ikesa['state'] == 'ESTABLISHED') {
272
				print('<span class="text-success">');
273
			} else {
274
				print('<span>');
275
			}
276

    
277
			print(ucfirst(htmlspecialchars($ikesa['state'])));
278

    
279
			if ($ikesa['state'] == 'ESTABLISHED') {
280
				print("<br/>");
281
				printf(gettext('%1$s seconds (%2$s) ago'), htmlspecialchars($ikesa['established']), convert_seconds_to_dhms($ikesa['established']));
282
			}
283

    
284
			print("</span><br /><br />");
285

    
286
			if ($ikesa['state'] != 'ESTABLISHED') {
287

    
288
				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>');
289
				print('<i class="fa fa-sign-in icon-embed-btn"></i>');
290
				print(gettext("Connect VPN"));
291
				print("</a>\n");
292

    
293
			} else {
294

    
295
				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>');
296
				print('<i class="fa fa-trash icon-embed-btn"></i>');
297
				print(gettext("Disconnect"));
298
				print("</a><br />\n");
299

    
300
			}
301
			if (empty($ikesa['child-sas'])) {
302
				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>');
303
				print('<i class="fa fa-sign-in icon-embed-btn"></i>');
304
				print(gettext("Connect Children"));
305
				print("</a>\n");
306
			}
307

    
308
			print("</td>\n");
309
			print("</tr>\n");
310
			print("<tr>\n");
311
			print("<td colspan = 10>\n");
312

    
313
			if (is_array($ikesa['child-sas']) && (count($ikesa['child-sas']) > 0)) {
314
				$child_key = "";
315
				foreach ($ikesa['child-sas'] as $key => $val){
316
					$child_key = $key;
317
					break;
318
				}
319

    
320
				print('<div>');
321
				print('<a type="button" id="btnchildsa-'. $child_key .  '" class="btn btn-sm btn-info">');
322
				print('<i class="fa fa-plus-circle icon-embed-btn"></i>');
323
				print(sprintf(gettext('Show child SA entries (%d)'), count($ikesa['child-sas'])));
324
				print("</a>\n");
325
				print("	</div>\n");
326

    
327
				print('<table class="table table-hover table-condensed" id="childsa-'.$child_key . '" style="display:none">');
328
				print("<thead>\n");
329
				print('<tr class="bg-info">');
330
				print('<th>' . gettext("IPsec ID") . '</th>');
331
				print('<th>' . gettext("Local subnets") . '</th>');
332
				print('<th>' . gettext("Local SPI(s)") . '</th>');
333
				print('<th>' . gettext("Remote subnets") . '</th>');
334
				print('<th>' . gettext("Times") . '</th>');
335
				print('<th>' . gettext("Algo") . '</th>');
336
				print('<th>' . gettext("Stats") . '</th>');
337
				print('<th><!-- Buttons --></th>');
338
				print("</tr\n");
339
				print("</thead>\n");
340
				print("<tbody>\n");
341

    
342
				foreach ($ikesa['child-sas'] as $childid => $childsa) {
343
					print("<tr>");
344
					print("<td>\n");
345
					print($childsa['name'] . ":<br />");
346
					print("#" . $childsa['uniqueid']);
347
					print("</td>\n");
348
					print("<td>\n");
349

    
350
					if (is_array($childsa['local-ts'])) {
351
						foreach ($childsa['local-ts'] as $lnets) {
352
							print(htmlspecialchars(ipsec_fixup_network($lnets)) . "<br />");
353
						}
354
					} else {
355
						print(gettext("Unknown"));
356
					}
357

    
358
					print("</td>\n");
359
					print("<td>\n");
360

    
361
					if (isset($childsa['spi-in'])) {
362
						print("<b>" . gettext("Local:") . "</b> " . htmlspecialchars($childsa['spi-in']));
363
					}
364

    
365
					if (isset($childsa['spi-out'])) {
366
						print("<br/>");
367
						print("<b>" . gettext('Remote:') . "</b> " . htmlspecialchars($childsa['spi-out']));
368
					}
369

    
370
					print("</td>\n");
371
					print("<td>\n");
372

    
373
					if (is_array($childsa['remote-ts'])) {
374
						foreach ($childsa['remote-ts'] as $rnets) {
375
							print(htmlspecialchars(ipsec_fixup_network($rnets)) . '<br />');
376
						}
377
					} else {
378
						print(gettext("Unknown"));
379
					}
380

    
381
					print("</td>\n");
382
					print("<td>\n");
383

    
384
					printf(gettext('%3$sRekey: %4$s%1$s seconds (%2$s)'), htmlspecialchars($childsa['rekey-time']), convert_seconds_to_dhms($childsa['rekey-time']), "<b>", "</b>");
385
					print('<br/>');
386
					printf(gettext('%3$sLife: %4$s%1$s seconds (%2$s)'), htmlspecialchars($childsa['life-time']), convert_seconds_to_dhms($childsa['life-time']), "<b>", "</b>");
387
					print('<br/>');
388
					printf(gettext('%3$sInstall: %4$s%1$s seconds (%2$s)'), htmlspecialchars($childsa['install-time']), convert_seconds_to_dhms($childsa['install-time']), "<b>", "</b>");
389

    
390

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

    
394
					print(htmlspecialchars($childsa['encr-alg']));
395
					if (!empty($childsa['encr-keysize'])) {
396
						print(" (" . htmlspecialchars($childsa['encr-keysize']) . ")");
397
					}
398
					print('<br/>');
399

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

    
402
					if (!empty($childsa['prf-alg'])) {
403
						print(htmlspecialchars($childsa['prf-alg']) . '<br/>');
404
					}
405

    
406
					if (!empty($childsa['dh-group'])) {
407
						print(htmlspecialchars($childsa['dh-group']) . '<br/>');
408
					}
409

    
410
					if (!empty($childsa['esn'])) {
411
						print(htmlspecialchars($childsa['esn']) . '<br/>');
412
					}
413

    
414
					print(gettext("IPComp: "));
415
					if (!empty($childsa['cpi-in']) || !empty($childsa['cpi-out'])) {
416
						print(htmlspecialchars($childsa['cpi-in']) . " " . htmlspecialchars($childsa['cpi-out']));
417
					} else {
418
						print(gettext('none'));
419
					}
420

    
421
					print("</td>\n");
422
					print("<td>\n");
423

    
424
					print("<b>" . gettext("Bytes-In:") . "</b> " . htmlspecialchars(number_format($childsa['bytes-in'])) . ' (' . htmlspecialchars(format_bytes($childsa['bytes-in'])) . ')<br/>');
425
					print("<b>" . gettext("Packets-In:") . "</b> " . htmlspecialchars(number_format($childsa['packets-in'])) . '<br/>');
426
					print("<b>" . gettext("Bytes-Out:") . "</b> " . htmlspecialchars(number_format($childsa['bytes-out'])) . ' (' . htmlspecialchars(format_bytes($childsa['bytes-out'])) . ')<br/>');
427
					print("<b>" . gettext("Packets-Out:") . "</b> " . htmlspecialchars(number_format($childsa['packets-out'])) . '<br/>');
428

    
429
					print("</td>\n");
430
					print("<td>\n");
431
					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>');
432
					print('<i class="fa fa-trash icon-embed-btn"></i>');
433
					print(gettext("Disconnect"));
434
					print("</a>\n");
435
					print("</td>\n");
436
					print("</tr>\n");
437

    
438
				}
439

    
440
				print("</tbody>\n");
441
				print("	</table>\n");
442
				print("</td>\n");
443
				print("</tr>\n");
444

    
445
			}
446

    
447
			unset($con_id);
448
		}
449

    
450
	}
451

    
452
	$rgmap = array();
453
	if (is_array($a_phase1)) {
454
		foreach ($a_phase1 as $ph1ent) {
455
			if (isset($ph1ent['disabled'])) {
456
				continue;
457
			}
458

    
459
			$rgmap[$ph1ent['remote-gateway']] = $ph1ent['remote-gateway'];
460

    
461
			if ($ipsecconnected[$ph1ent['ikeid']]) {
462
				continue;
463
			}
464

    
465
			print("<tr>\n");
466
			print("<td></td>\n");
467
			print("<td>\n");
468
			print(htmlspecialchars($ph1ent['descr']));
469
			print("</td>\n");
470
			print("<td>\n");
471
			print("<b>ID:</b> \n");
472
			list ($myid_type, $myid_data) = ipsec_find_id($ph1ent, "local");
473

    
474
			if (empty($myid_data)) {
475
				print(gettext("Unknown"));
476
			} else {
477
				print(htmlspecialchars($myid_data));
478
			}
479

    
480
			print("<br/>\n");
481
			print("<b>Host:</b> \n");
482
			$ph1src = ipsec_get_phase1_src($ph1ent);
483

    
484
			if (empty($ph1src)) {
485
				print(gettext("Unknown"));
486
			} else {
487
				print(htmlspecialchars(str_replace(',', ', ', $ph1src)));
488
			}
489

    
490
			print("</td>\n");
491
			print("<td>\n");
492

    
493
			print("<b>ID:</b> \n");
494

    
495
			list ($peerid_type, $peerid_data) = ipsec_find_id($ph1ent, "peer", $rgmap);
496

    
497
			if (empty($peerid_data)) {
498
				print(gettext("Unknown"));
499
			} else {
500
				print(htmlspecialchars($peerid_data));
501
			}
502

    
503
			print("<br/>\n");
504
			print("<b>Host:</b> \n");
505

    
506
			$ph1src = ipsec_get_phase1_dst($ph1ent);
507

    
508
			if (empty($ph1src)) {
509
				print(gettext("Unknown"));
510
			} else {
511
				print(htmlspecialchars($ph1src));
512
			}
513

    
514
			print("</td>\n");
515
			print("<td>\n");
516
			print("</td>\n");
517
			print("<td>\n");
518
			print("</td>\n");
519
			print("<td>\n");
520
			print("</td>\n");
521

    
522
			if (isset($ph1ent['mobile'])) {
523

    
524
				print("<td>\n");
525
				print(gettext("Awaiting connections"));
526
				print("</td>\n");
527
				print("<td>\n");
528
				print("</td>\n");
529
				print("</td>\n");
530
			} else {
531

    
532
				print("<td>\n");
533
				print(gettext("Disconnected"));
534
				print("<br/>\n");
535
				print('<a href="status_ipsec.php?act=connect&amp;ikeid=' . $ph1ent['ikeid'] . '" class="btn btn-xs btn-success" usepost>');
536
				print('<i class="fa fa-sign-in icon-embed-btn"></i>');
537
				print(gettext("Connect VPN"));
538
				print("</a>\n");
539
				print("</td>\n");
540

    
541
			}
542
			print("</tr>\n");
543
		}
544
	}
545

    
546
	unset($ipsecconnected, $phase1, $rgmap);
547
}
548

    
549
$pgtitle = array(gettext("Status"), gettext("IPsec"), gettext("Overview"));
550
$pglinks = array("", "@self", "@self");
551
$shortcut_section = "ipsec";
552

    
553
include("head.inc");
554

    
555
$tab_array = array();
556
$tab_array[] = array(gettext("Overview"), true, "status_ipsec.php");
557
$tab_array[] = array(gettext("Leases"), false, "status_ipsec_leases.php");
558
$tab_array[] = array(gettext("SADs"), false, "status_ipsec_sad.php");
559
$tab_array[] = array(gettext("SPDs"), false, "status_ipsec_spd.php");
560
display_top_tabs($tab_array);
561
?>
562

    
563
<div class="panel panel-default">
564
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("IPsec Status");?></h2></div>
565
	<div class="panel-body table-responsive">
566
		<table class="table table-striped table-condensed table-hover sortable-theme-bootstrap" data-sortable>
567
			<thead>
568
				<tr>
569
					<th><?=gettext("IPsec ID")?></th>
570
					<th><?=gettext("Description")?></th>
571
					<th><?=gettext("Local")?></th>
572
					<th><?=gettext("Remote")?></th>
573
					<th><?=gettext("Role")?></th>
574
					<th><?=gettext("Timers")?></th>
575
					<th><?=gettext("Algo")?></th>
576
					<th><?=gettext("Status")?></th>
577
					<th></th>
578
				</tr>
579
			</thead>
580
			<tbody id="ipsec-body">
581
				<tr>
582
					<td colspan="10">
583
						<?=print_info_box(gettext("Collecting IPsec status information."), "warning", "")?>
584
					</td>
585
				</tr>
586
			</tbody>
587
		</table>
588
	</div>
589
</div>
590

    
591
<?php
592
unset($status);
593

    
594
if (ipsec_enabled()) {
595
	print('<div class="infoblock">');
596
} else {
597
	print('<div class="infoblock blockopen">');
598
}
599

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

    
604
<script type="text/javascript">
605
//<![CDATA[
606

    
607
events.push(function() {
608
	ajax_lock = false;		// Mutex so we don't make a call until the previous call is finished
609
	sa_open = new Array();	// Array in which to keep the child SA show/hide state
610
	tryCount = 3;
611
	// Fetch the tbody contents from the server
612
	function update_table() {
613
		if (ajax_lock) {
614
			return;
615
		}
616

    
617
		ajax_lock = true;
618

    
619
		ajaxRequest = $.ajax(
620
			{
621
				url: "/status_ipsec.php",
622
				type: "post",
623
				data: {
624
					ajax: 	"ajax"
625
				},
626
				error: function(xhr, textStatus, errorThrown){
627
					//alert("error.... retrying");
628
					if (tryCount > 0){
629
						tryCount --;
630
						ajax_lock = false;
631
						update_table();
632
					}
633
					return;
634
				}
635
			}
636
		);
637

    
638
		// Deal with the results of the above ajax call
639
		ajaxRequest.done(function (response, textStatus, jqXHR) {
640
			if(textStatus === "success"){
641
				tryCount =3;
642
			}
643
			if (!response) {
644
				response = '<tr><td colspan="10"><?=print_info_box(addslashes(gettext("No IPsec status information available.")), "warning", "")?></td></tr>';
645
			}
646

    
647
			$('#ipsec-body').html(response);
648
			ajax_lock = false;
649

    
650
			// Update "Show child SA" handlers
651
			$('[id^=btnchildsa-]').click(function () {
652
				show_childsa($(this).prop("id").replace( 'btnchildsa-', ''));
653
			});
654

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

    
659
				if (sa_open[sa_idx]) {
660
					show_childsa(sa_idx);
661
				}
662
			});
663

    
664
			// re-attached the GET to POST handler
665
			interceptGET();
666

    
667
			// and do it again
668
			setTimeout(update_table, 5000);
669
		});
670
	}
671

    
672
	function show_childsa(said) {
673
		sa_open[said] = true;
674
		$('#childsa-' + said).show();
675
		$('#btnchildsa-' + said).hide();
676
	}
677

    
678
	// Populate the tbody on page load
679
	update_table();
680
});
681
//]]>
682
</script>
683

    
684
<?php
685
include("foot.inc"); ?>
(165-165/229)