Project

General

Profile

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