Project

General

Profile

Download (16.2 KB) Statistics
| Branch: | Tag: | Revision:
1 cf7d1057 Scott Ullrich
<?php
2
/*
3 c5d81585 Renato Botelho
 * status_ipsec.php
4 86b2861c Matt Smith
 *
5 c5d81585 Renato Botelho
 * part of pfSense (https://www.pfsense.org)
6 81299b5c Renato Botelho
 * Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
7 c5d81585 Renato Botelho
 * All rights reserved.
8 fd9ebcd5 Stephen Beaver
 *
9 c5d81585 Renato Botelho
 * originally based on m0n0wall (http://m0n0.ch/wall)
10
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
11
 * All rights reserved.
12 fd9ebcd5 Stephen Beaver
 *
13 b12ea3fb Renato Botelho
 * Licensed under the Apache License, Version 2.0 (the "License");
14
 * you may not use this file except in compliance with the License.
15
 * You may obtain a copy of the License at
16 fd9ebcd5 Stephen Beaver
 *
17 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
18 fd9ebcd5 Stephen Beaver
 *
19 b12ea3fb Renato Botelho
 * Unless required by applicable law or agreed to in writing, software
20
 * distributed under the License is distributed on an "AS IS" BASIS,
21
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
 * See the License for the specific language governing permissions and
23
 * limitations under the License.
24 fd9ebcd5 Stephen Beaver
 */
25 cf7d1057 Scott Ullrich
26 6b07c15a Matthew Grooms
##|+PRIV
27
##|*IDENT=page-status-ipsec
28 5230f468 jim-p
##|*NAME=Status: IPsec
29 6b07c15a Matthew Grooms
##|*DESCR=Allow access to the 'Status: IPsec' page.
30 1af5edbf Stephen Beaver
##|*MATCH=status_ipsec.php*
31 6b07c15a Matthew Grooms
##|-PRIV
32
33 c81ef6e2 Phil Davis
require_once("guiconfig.inc");
34 4260c32a Stephen Beaver
require_once("ipsec.inc");
35 6b07c15a Matthew Grooms
36 a93e56c5 Matthew Grooms
global $g;
37
38 4b5f2ab3 Phil Davis
if (!is_array($config['ipsec']['phase1'])) {
39
	$config['ipsec']['phase1'] = array();
40
}
41
42 4260c32a Stephen Beaver
// 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 a93e56c5 Matthew Grooms
48 17402c63 Ermal
if ($_GET['act'] == 'connect') {
49
	if (ctype_digit($_GET['ikeid'])) {
50 483c3b5b Ermal LUÇI
		$ph1ent = ipsec_get_phase1($_GET['ikeid']);
51
		if (!empty($ph1ent)) {
52 9d51fcde Chris Buechler
			if (empty($ph1ent['iketype']) || $ph1ent['iketype'] == 'ikev1' || isset($ph1ent['splitconn'])) {
53 483c3b5b Ermal LUÇI
				$ph2entries = ipsec_get_number_of_phase2($_GET['ikeid']);
54
				for ($i = 0; $i < $ph2entries; $i++) {
55
					$connid = escapeshellarg("con{$_GET['ikeid']}00{$i}");
56 c5d8cbe0 Chris Buechler
					mwexec_bg("/usr/local/sbin/ipsec down {$connid}");
57 b866103e Chris Buechler
					mwexec_bg("/usr/local/sbin/ipsec up {$connid}");
58 483c3b5b Ermal LUÇI
				}
59
			} else {
60 c5d8cbe0 Chris Buechler
				mwexec_bg("/usr/local/sbin/ipsec down con" . escapeshellarg($_GET['ikeid']));
61 b866103e Chris Buechler
				mwexec_bg("/usr/local/sbin/ipsec up con" . escapeshellarg($_GET['ikeid']));
62 483c3b5b Ermal LUÇI
			}
63
		}
64 6e8b0ec3 jim-p
	}
65 17402c63 Ermal
} else if ($_GET['act'] == 'ikedisconnect') {
66
	if (ctype_digit($_GET['ikeid'])) {
67 5f601060 Phil Davis
		if (!empty($_GET['ikesaid']) && ctype_digit($_GET['ikesaid'])) {
68 c5d8cbe0 Chris Buechler
			mwexec_bg("/usr/local/sbin/ipsec down con" . escapeshellarg($_GET['ikeid']) . "[" . escapeshellarg($_GET['ikesaid']) . "]");
69 5f601060 Phil Davis
		} else {
70 c5d8cbe0 Chris Buechler
			mwexec_bg("/usr/local/sbin/ipsec down con" . escapeshellarg($_GET['ikeid']));
71 5f601060 Phil Davis
		}
72 614be051 bcyrill
	}
73 e952906e Ermal
} else if ($_GET['act'] == 'childdisconnect') {
74
	if (ctype_digit($_GET['ikeid'])) {
75 5f601060 Phil Davis
		if (!empty($_GET['ikesaid']) && ctype_digit($_GET['ikesaid'])) {
76 c5d8cbe0 Chris Buechler
			mwexec_bg("/usr/local/sbin/ipsec down con" . escapeshellarg($_GET['ikeid']) . "{" . escapeshellarg($_GET['ikesaid']) . "}");
77 5f601060 Phil Davis
		}
78 6e0b68bf jim-p
	}
79
}
80
81 4260c32a Stephen Beaver
// Table body is composed here so that it can be more easily updated via AJAX
82
function print_ipsec_body() {
83
	global $config;
84 a93e56c5 Matthew Grooms
85 4260c32a Stephen Beaver
	$a_phase1 = &$config['ipsec']['phase1'];
86
	$status = ipsec_list_sa();
87
	$ipsecconnected = array();
88 a93e56c5 Matthew Grooms
89 4260c32a Stephen Beaver
	if (is_array($status)) {
90
		foreach ($status as $ikeid => $ikesa) {
91
			$con_id = substr($ikeid, 3);
92 3795cc0a sbeaver
93 4260c32a Stephen Beaver
			if ($ikesa['version'] == 1) {
94
				$ph1idx = substr($con_id, 0, strrpos(substr($con_id, 0, -1), '00'));
95
				$ipsecconnected[$ph1idx] = $ph1idx;
96
			} else {
97
				$ipsecconnected[$con_id] = $ph1idx = $con_id;
98
			}
99 3795cc0a sbeaver
100 4260c32a Stephen Beaver
			print("<tr>\n");
101
			print("<td>\n");
102
			print(htmlspecialchars(ipsec_get_descr($ph1idx)));
103
			print("</td>\n");
104
			print("<td>\n");
105 0da0d43e Phil Davis
106 4260c32a Stephen Beaver
			if (!empty($ikesa['local-id'])) {
107
				if ($ikesa['local-id'] == '%any') {
108
					print(gettext('Any identifier'));
109
				} else {
110
					print(htmlspecialchars($ikesa['local-id']));
111
				}
112 5f601060 Phil Davis
			} else {
113 4260c32a Stephen Beaver
				print(gettext("Unknown"));
114 5f601060 Phil Davis
			}
115 86b2861c Matt Smith
116 4260c32a Stephen Beaver
			print("</td>\n");
117
			print("<td>\n");
118
119
			if (!empty($ikesa['local-host'])) {
120
				print(htmlspecialchars($ikesa['local-host']));
121 86b2861c Matt Smith
			} else {
122 4260c32a Stephen Beaver
				print(gettext("Unknown"));
123 86b2861c Matt Smith
			}
124 4260c32a Stephen Beaver
125
			/*
126
			 * XXX: local-nat-t was defined by pfSense
127
			 * When strongswan team accepted the change, they changed it to
128
			 * nat-local. Keep both for a while and remove local-nat-t in
129
			 * the future
130
			 */
131
			if (isset($ikesa['local-nat-t']) || isset($ikesa['nat-local'])) {
132 e96b20f6 Jose Luis Duran
				print(" NAT-T");
133 4260c32a Stephen Beaver
			}
134
135
			print("</td>\n");
136
			print("<td>\n");
137
138
			$identity = "";
139
			if (!empty($ikesa['remote-id'])) {
140
				if ($ikesa['remote-id'] == '%any') {
141
					$identity = htmlspecialchars(gettext('Any identifier'));
142
				} else {
143
					$identity = htmlspecialchars($ikesa['remote-id']);
144
				}
145
			}
146
147
			if (!empty($ikesa['remote-xauth-id'])) {
148
				echo htmlspecialchars($ikesa['remote-xauth-id']);
149
				echo "<br/>{$identity}";
150
			} elseif (!empty($ikesa['remote-eap-id'])) {
151
				echo htmlspecialchars($ikesa['remote-eap-id']);
152
				echo "<br/>{$identity}";
153
			} else {
154
				if (empty($identity)) {
155
					print(gettext("Unknown"));
156
				} else {
157
					print($identity);
158
				}
159
			}
160
161
			print("</td>\n");
162
			print("<td>\n");
163
164
			if (!empty($ikesa['remote-host'])) {
165
				print(htmlspecialchars($ikesa['remote-host']));
166
			} else {
167 3795cc0a sbeaver
				print(gettext("Unknown"));
168 4260c32a Stephen Beaver
			}
169
			/*
170
			 * XXX: remote-nat-t was defined by pfSense
171
			 * When strongswan team accepted the change, they changed it to
172
			 * nat-remote. Keep both for a while and remove remote-nat-t in
173
			 * the future
174
			 */
175
			if (isset($ikesa['remote-nat-t']) || isset($ikesa['nat-remote'])) {
176
				print(" NAT-T");
177
			}
178
179
			print("</td>\n");
180
			print("<td>\n");
181
			print("IKEv" . htmlspecialchars($ikesa['version']));
182
			print("<br/>\n");
183
184
			if ($ikesa['initiator'] == 'yes') {
185
				print("initiator");
186
			} else {
187
				print("responder");
188
			}
189
190
			print("</td>\n");
191
			print("<td>\n");
192 c57e936a stilez
			print(htmlspecialchars($ikesa['reauth-time']) . gettext(" seconds (") . convert_seconds_to_dhms($ikesa['reauth-time']) . ")");
193 4260c32a Stephen Beaver
			print("</td>\n");
194
			print("<td>\n");
195
			print(htmlspecialchars($ikesa['encr-alg']));
196
			print("<br/>");
197
			print(htmlspecialchars($ikesa['integ-alg']));
198
			print("<br/>");
199
			print(htmlspecialchars($ikesa['prf-alg']));
200
			print("<br/>\n");
201
			print(htmlspecialchars($ikesa['dh-group']));
202
			print("</td>\n");
203
			print("<td>\n");
204
205
			if ($ikesa['state'] == 'ESTABLISHED') {
206
				print('<span class="text-success">');
207
			} else {
208
				print('<span>');
209
			}
210
211
			print(ucfirst(htmlspecialchars($ikesa['state'])));
212 9e820b59 Phil Davis
213
			if ($ikesa['state'] == 'ESTABLISHED') {
214 c57e936a stilez
				print("<br/>" . htmlspecialchars($ikesa['established']) . gettext(" seconds (") . convert_seconds_to_dhms($ikesa['established']) . gettext(") ago"));
215 9e820b59 Phil Davis
			}
216
217 4260c32a Stephen Beaver
			print("</span>");
218
			print("</td>\n");
219
			print("<td>\n");
220
221
			if ($ikesa['state'] != 'ESTABLISHED') {
222
223 9e820b59 Phil Davis
				print('<a href="status_ipsec.php?act=connect&amp;ikeid=' . $con_id . '" class="btn btn-xs btn-success" data-toggle="tooltip" title="' . gettext("Connect VPN"). '" >');
224
				print('<i class="fa fa-sign-in icon-embed-btn"></i>');
225
				print(gettext("Connect VPN"));
226
				print("</a>\n");
227 4260c32a Stephen Beaver
228 86b2861c Matt Smith
			} else {
229 4260c32a Stephen Beaver
230
				print('<a href="status_ipsec.php?act=ikedisconnect&amp;ikeid=' . $con_id . '" class="btn btn-xs btn-danger" data-toggle="tooltip" title="' . gettext("Disconnect VPN") . '">');
231
				print('<i class="fa fa-trash icon-embed-btn"></i>');
232
				print(gettext("Disconnect"));
233
				print("</a><br />\n");
234
235
			}
236
237
			print("</td>\n");
238
			print("</tr>\n");
239
			print("<tr>\n");
240
			print("<td colspan = 10>\n");
241
242
			if (is_array($ikesa['child-sas']) && (count($ikesa['child-sas']) > 0)) {
243
244 067551a4 Stephen Beaver
				print('<div>');
245
				print('<a type="button" id="btnchildsa-' . $ikeid .  '" class="btn btn-sm btn-info">');
246 4260c32a Stephen Beaver
				print('<i class="fa fa-plus-circle icon-embed-btn"></i>');
247
				print(gettext('Show child SA entries'));
248
				print("</a>\n");
249
				print("	</div>\n");
250
251
				print('<table class="table table-hover table-condensed" id="childsa-' . $ikeid . '" style="display:none">');
252
				print("<thead>\n");
253
				print('<tr class="bg-info">');
254
				print('<th><?=gettext("Local subnets")?></th>');
255
				print('<th><?=gettext("Local SPI(s)")?></th>');
256
				print('<th><?=gettext("Remote subnets")?></th>');
257
				print('<th><?=gettext("Times")?></th>');
258
				print('<th><?=gettext("Algo")?></th>');
259
				print('<th><?=gettext("Stats")?></th>');
260
				print('<th><!-- Buttons --></th>');
261
				print("</tr\n");
262
				print("</thead>\n");
263
				print("<tbody>\n");
264
265
				foreach ($ikesa['child-sas'] as $childid => $childsa) {
266
					print("<tr>");
267
					print("<td>\n");
268
269
					if (is_array($childsa['local-ts'])) {
270
						foreach ($childsa['local-ts'] as $lnets) {
271
							print(htmlspecialchars(ipsec_fixup_network($lnets)) . "<br />");
272
						}
273
					} else {
274
						print(gettext("Unknown"));
275
					}
276
277
					print("</td>\n");
278
					print("<td>\n");
279
280
					if (isset($childsa['spi-in'])) {
281
						print(gettext("Local: ") . htmlspecialchars($childsa['spi-in']));
282
					}
283
284
					if (isset($childsa['spi-out'])) {
285
						print('<br/>' . gettext('Remote: ') . htmlspecialchars($childsa['spi-out']));
286
					}
287
288
					print("</td>\n");
289
					print("<td>\n");
290
291
					if (is_array($childsa['remote-ts'])) {
292
						foreach ($childsa['remote-ts'] as $rnets) {
293
							print(htmlspecialchars(ipsec_fixup_network($rnets)) . '<br />');
294
						}
295
					} else {
296
						print(gettext("Unknown"));
297
					}
298
299
					print("</td>\n");
300
					print("<td>\n");
301
302 c57e936a stilez
					print(gettext("Rekey: ") . htmlspecialchars($childsa['rekey-time']) . gettext(" seconds (") . convert_seconds_to_dhms($childsa['rekey-time']) . ")");
303
					print('<br/>' . gettext('Life: ') . htmlspecialchars($childsa['life-time']) . gettext(" seconds (") . convert_seconds_to_dhms($childsa['life-time']) . ")");
304
					print('<br/>' . gettext('Install: ') .htmlspecialchars($childsa['install-time']) . gettext(" seconds (") . convert_seconds_to_dhms($childsa['install-time']) . ")");
305 4260c32a Stephen Beaver
306
307
					print("</td>\n");
308
					print("<td>\n");
309
310
					print(htmlspecialchars($childsa['encr-alg']) . '<br/>');
311
					print(htmlspecialchars($childsa['integ-alg']) . '<br/>');
312
313
					if (!empty($childsa['prf-alg'])) {
314
						print(htmlspecialchars($childsa['prf-alg']) . '<br/>');
315
					}
316
317
					if (!empty($childsa['dh-group'])) {
318
						print(htmlspecialchars($childsa['dh-group']) . '<br/>');
319
					}
320
321
					if (!empty($childsa['esn'])) {
322
						print(htmlspecialchars($childsa['esn']) . '<br/>');
323
					}
324
325
					print(gettext("IPComp: "));
326
					if (!empty($childsa['cpi-in']) || !empty($childsa['cpi-out'])) {
327
						print(htmlspecialchars($childsa['cpi-in']) . " " . htmlspecialchars($childsa['cpi-out']));
328
					} else {
329
						print(gettext('none'));
330
					}
331
332
					print("</td>\n");
333
					print("<td>\n");
334
335
					print(gettext("Bytes-In: ") . htmlspecialchars(number_format($childsa['bytes-in'])) . ' (' . htmlspecialchars(format_bytes($childsa['bytes-in'])) . ')<br/>');
336
					print(gettext("Packets-In: ") . htmlspecialchars(number_format($childsa['packets-in'])) . '<br/>');
337
					print(gettext("Bytes-Out: ") . htmlspecialchars(number_format($childsa['bytes-out'])) . ' (' . htmlspecialchars(format_bytes($childsa['bytes-out'])) . ')<br/>');
338
					print(gettext("Packets-Out: ") . htmlspecialchars(number_format($childsa['packets-out'])) . '<br/>');
339
340
					print("</td>\n");
341
					print("<td>\n");
342
					print('<a href="status_ipsec.php?act=childdisconnect&amp;ikeid=' . $con_id . '&amp;ikesaid=' . $childsa['uniqueid'] . '" class="btn btn-xs btn-warning" data-toggle="tooltip" title="' . gettext('Disconnect Child SA') . '">');
343
					print('<i class="fa fa-trash icon-embed-btn"></i>');
344
					print(gettext("Disconnect"));
345
					print("</a>\n");
346
					print("</td>\n");
347
					print("</tr>\n");
348
349
				}
350
351
				print("</tbody>\n");
352
				print("	</table>\n");
353
				print("</td>\n");
354 9723b525 Stephen Beaver
				print("</tr>\n");
355 4260c32a Stephen Beaver
356 3795cc0a sbeaver
			}
357 4260c32a Stephen Beaver
358
			unset($con_id);
359 86b2861c Matt Smith
		}
360 4260c32a Stephen Beaver
361
	}
362
363
	$rgmap = array();
364 4b5f2ab3 Phil Davis
	if (is_array($a_phase1)) {
365
		foreach ($a_phase1 as $ph1ent) {
366
			if (isset($ph1ent['disabled'])) {
367
				continue;
368
			}
369 4260c32a Stephen Beaver
370 4b5f2ab3 Phil Davis
			$rgmap[$ph1ent['remote-gateway']] = $ph1ent['remote-gateway'];
371 4260c32a Stephen Beaver
372 4b5f2ab3 Phil Davis
			if ($ipsecconnected[$ph1ent['ikeid']]) {
373
				continue;
374
			}
375 4260c32a Stephen Beaver
376 4b5f2ab3 Phil Davis
			print("<tr>\n");
377
			print("<td>\n");
378 4260c32a Stephen Beaver
379 4b5f2ab3 Phil Davis
			print(htmlspecialchars($ph1ent['descr']));
380
			print("</td>\n");
381
			print("<td>\n");
382
			list ($myid_type, $myid_data) = ipsec_find_id($ph1ent, "local");
383 4260c32a Stephen Beaver
384 4b5f2ab3 Phil Davis
			if (empty($myid_data)) {
385
				print(gettext("Unknown"));
386
			} else {
387
				print(htmlspecialchars($myid_data));
388
			}
389 4260c32a Stephen Beaver
390 4b5f2ab3 Phil Davis
			print("</td>\n");
391
			print("<td>\n");
392
			$ph1src = ipsec_get_phase1_src($ph1ent);
393 4260c32a Stephen Beaver
394 4b5f2ab3 Phil Davis
			if (empty($ph1src)) {
395
				print(gettext("Unknown"));
396
			} else {
397
				print(htmlspecialchars($ph1src));
398
			}
399 4260c32a Stephen Beaver
400 4b5f2ab3 Phil Davis
			print("</td>\n");
401
			print("<td>\n");
402 0da0d43e Phil Davis
403 4b5f2ab3 Phil Davis
			list ($peerid_type, $peerid_data) = ipsec_find_id($ph1ent, "peer", $rgmap);
404 3795cc0a sbeaver
405 4b5f2ab3 Phil Davis
			if (empty($peerid_data)) {
406
				print(gettext("Unknown"));
407
			} else {
408
				print(htmlspecialchars($peerid_data));
409
			}
410
			print("			</td>\n");
411
			print("			<td>\n");
412
			$ph1src = ipsec_get_phase1_dst($ph1ent);
413 0da0d43e Phil Davis
414 4b5f2ab3 Phil Davis
			if (empty($ph1src)) {
415
				print(gettext("Unknown"));
416
			} else {
417
				print(htmlspecialchars($ph1src));
418
			}
419 0da0d43e Phil Davis
420 4260c32a Stephen Beaver
			print("</td>\n");
421
			print("<td>\n");
422
			print("</td>\n");
423
			print("<td>\n");
424
			print("</td>\n");
425
			print("<td>\n");
426
			print("</td>\n");
427 3795cc0a sbeaver
428 4b5f2ab3 Phil Davis
			if (isset($ph1ent['mobile'])) {
429
430
				print("<td>\n");
431
				print(gettext("Awaiting connections"));
432
				print("</td>\n");
433
				print("<td>\n");
434
				print("</td>\n");
435
				print("</td>\n");
436
			} else {
437
438
				print("<td>\n");
439
				print(gettext("Disconnected"));
440
				print("</td>\n");
441
				print("<td>\n");
442
				print('<a href="status_ipsec.php?act=connect&amp;ikeid=' . $ph1ent['ikeid'] . '" class="btn btn-xs btn-success">');
443
				print('<i class="fa fa-sign-in icon-embed-btn"></i>');
444
				print(gettext("Connect VPN"));
445
				print("</a>\n");
446
				print("</td>\n");
447
448
			}
449
			print("</tr>\n");
450 4260c32a Stephen Beaver
		}
451 97242546 Matt Smith
	}
452
453 4260c32a Stephen Beaver
	unset($ipsecconnected, $phase1, $rgmap);
454 86b2861c Matt Smith
}
455 3795cc0a sbeaver
456 4260c32a Stephen Beaver
$pgtitle = array(gettext("Status"), gettext("IPsec"), gettext("Overview"));
457
$shortcut_section = "ipsec";
458 0da0d43e Phil Davis
459 4260c32a Stephen Beaver
include("head.inc");
460 0da0d43e Phil Davis
461 4260c32a Stephen Beaver
$tab_array = array();
462
$tab_array[] = array(gettext("Overview"), true, "status_ipsec.php");
463
$tab_array[] = array(gettext("Leases"), false, "status_ipsec_leases.php");
464
$tab_array[] = array(gettext("SADs"), false, "status_ipsec_sad.php");
465
$tab_array[] = array(gettext("SPDs"), false, "status_ipsec_spd.php");
466
display_top_tabs($tab_array);
467 3795cc0a sbeaver
?>
468 0da0d43e Phil Davis
469 4260c32a Stephen Beaver
<div class="panel panel-default">
470
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("IPsec Status");?></h2></div>
471
	<div class="panel-body table-responsive">
472
		<table class="table table-striped table-condensed table-hover sortable-theme-bootstrap" data-sortable>
473
			<thead>
474
				<tr>
475
					<th><?=gettext("Description")?></th>
476
					<th><?=gettext("Local ID")?></th>
477
					<th><?=gettext("Local IP")?></th>
478
					<th><?=gettext("Remote ID")?></th>
479
					<th><?=gettext("Remote IP")?></th>
480
					<th><?=gettext("Role")?></th>
481
					<th><?=gettext("Reauth")?></th>
482
					<th><?=gettext("Algo")?></th>
483
					<th><?=gettext("Status")?></th>
484
					<th></th>
485
				</tr>
486
			</thead>
487
			<tbody id="ipsec-body">
488
				<tr>
489 fc48da17 NOYB
					<td colspan="10">
490 499adf73 Phil Davis
						<?=print_info_box(gettext("Collecting IPsec status information."), "warning", "")?>
491 3795cc0a sbeaver
					</td>
492
				</tr>
493
			</tbody>
494 c7fbdd6c Ermal
		</table>
495
	</div>
496 3795cc0a sbeaver
</div>
497
498
<?php
499
unset($status);
500 4260c32a Stephen Beaver
501 d2c1089f Phil Davis
if (ipsec_enabled()) {
502 4260c32a Stephen Beaver
	print('<div class="infoblock">');
503 d2c1089f Phil Davis
} else {
504 4260c32a Stephen Beaver
	print('<div class="infoblock blockopen">');
505 d2c1089f Phil Davis
}
506 4260c32a Stephen Beaver
507 530c7ccf NOYB
print_info_box(sprintf(gettext('IPsec can be configured %1$shere%2$s.'), '<a href="vpn_ipsec.php">', '</a>'), 'info', false);
508 d2c1089f Phil Davis
?>
509
</div>
510 4260c32a Stephen Beaver
511
<script type="text/javascript">
512
//<![CDATA[
513
514
events.push(function() {
515 067551a4 Stephen Beaver
	ajax_lock = false;		// Mutex so we don't make a call until the previous call is finished
516
	sa_open = new Array();	// Array in which to keep the child SA show/hide state
517 4260c32a Stephen Beaver
518
	// Fetch the tbody contents from the server
519
	function update_table() {
520
		if (ajax_lock) {
521
			return;
522
		}
523
524
		ajax_lock = true;
525
526
		ajaxRequest = $.ajax(
527
			{
528
				url: "/status_ipsec.php",
529
				type: "post",
530
				data: {
531
					ajax: 	"ajax"
532
				}
533
			}
534
		);
535
536
		// Deal with the results of the above ajax call
537
		ajaxRequest.done(function (response, textStatus, jqXHR) {
538 fc48da17 NOYB
539
			if (!response) {
540 499adf73 Phil Davis
				response = '<tr><td colspan="10"><?=print_info_box(gettext("No IPsec status information available."), "warning", "")?></td></tr>';
541 fc48da17 NOYB
			}
542
543 4260c32a Stephen Beaver
			$('#ipsec-body').html(response);
544
			ajax_lock = false;
545
546 067551a4 Stephen Beaver
			// Update "Show child SA" handlers
547
			$('[id^=btnchildsa-]').click(function () {
548
				show_childsa($(this).prop("id").replace( /^\D+/g, ''));
549
			});
550
551
			// Check the sa_open array for child SAs that have been opened
552 4260c32a Stephen Beaver
			$('[id^=childsa-con]').each(function(idx) {
553 067551a4 Stephen Beaver
				sa_idx = $(this).prop("id").replace( /^\D+/g, '');
554 4260c32a Stephen Beaver
555
				if (sa_open[sa_idx]) {
556 067551a4 Stephen Beaver
					show_childsa(sa_idx);
557 4260c32a Stephen Beaver
				}
558
			});
559
560
			// and do it again
561
			setTimeout(update_table, 5000);
562
		});
563
	}
564
565 067551a4 Stephen Beaver
	function show_childsa(said) {
566
		sa_open[said] = true;
567
		$('#childsa-con' + said).show();
568
		$('#btnchildsa-con' + said).hide();
569
	}
570
571 4260c32a Stephen Beaver
	// Populate the tbody on page load
572
	update_table();
573
});
574
//]]>
575
</script>
576
577 d2c1089f Phil Davis
<?php
578 3795cc0a sbeaver
include("foot.inc"); ?>