Project

General

Profile

Download (17.8 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 9573afa8 Stephen Beaver
require("guiconfig.inc");
68
require_once("ipsec.inc");
69 6b07c15a Matthew Grooms
70 a93e56c5 Matthew Grooms
global $g;
71
72 9573afa8 Stephen Beaver
// If this is just an AJAX call to update the table body, just generate the body and quit
73
if ($_REQUEST['ajax']) {
74
	print_ipsec_body();
75
	exit;
76
}
77 a93e56c5 Matthew Grooms
78 17402c63 Ermal
if ($_GET['act'] == 'connect') {
79
	if (ctype_digit($_GET['ikeid'])) {
80 483c3b5b Ermal LUÇI
		$ph1ent = ipsec_get_phase1($_GET['ikeid']);
81
		if (!empty($ph1ent)) {
82 9d51fcde Chris Buechler
			if (empty($ph1ent['iketype']) || $ph1ent['iketype'] == 'ikev1' || isset($ph1ent['splitconn'])) {
83 483c3b5b Ermal LUÇI
				$ph2entries = ipsec_get_number_of_phase2($_GET['ikeid']);
84
				for ($i = 0; $i < $ph2entries; $i++) {
85
					$connid = escapeshellarg("con{$_GET['ikeid']}00{$i}");
86 c5d8cbe0 Chris Buechler
					mwexec_bg("/usr/local/sbin/ipsec down {$connid}");
87 b866103e Chris Buechler
					mwexec_bg("/usr/local/sbin/ipsec up {$connid}");
88 483c3b5b Ermal LUÇI
				}
89
			} else {
90 c5d8cbe0 Chris Buechler
				mwexec_bg("/usr/local/sbin/ipsec down con" . escapeshellarg($_GET['ikeid']));
91 b866103e Chris Buechler
				mwexec_bg("/usr/local/sbin/ipsec up con" . escapeshellarg($_GET['ikeid']));
92 483c3b5b Ermal LUÇI
			}
93
		}
94 6e8b0ec3 jim-p
	}
95 17402c63 Ermal
} else if ($_GET['act'] == 'ikedisconnect') {
96
	if (ctype_digit($_GET['ikeid'])) {
97 5f601060 Phil Davis
		if (!empty($_GET['ikesaid']) && ctype_digit($_GET['ikesaid'])) {
98 c5d8cbe0 Chris Buechler
			mwexec_bg("/usr/local/sbin/ipsec down con" . escapeshellarg($_GET['ikeid']) . "[" . escapeshellarg($_GET['ikesaid']) . "]");
99 5f601060 Phil Davis
		} else {
100 c5d8cbe0 Chris Buechler
			mwexec_bg("/usr/local/sbin/ipsec down con" . escapeshellarg($_GET['ikeid']));
101 5f601060 Phil Davis
		}
102 614be051 bcyrill
	}
103 e952906e Ermal
} else if ($_GET['act'] == 'childdisconnect') {
104
	if (ctype_digit($_GET['ikeid'])) {
105 5f601060 Phil Davis
		if (!empty($_GET['ikesaid']) && ctype_digit($_GET['ikesaid'])) {
106 c5d8cbe0 Chris Buechler
			mwexec_bg("/usr/local/sbin/ipsec down con" . escapeshellarg($_GET['ikeid']) . "{" . escapeshellarg($_GET['ikesaid']) . "}");
107 5f601060 Phil Davis
		}
108 6e0b68bf jim-p
	}
109
}
110
111 5f601060 Phil Davis
if (!is_array($config['ipsec']['phase1'])) {
112 3795cc0a sbeaver
	$config['ipsec']['phase1'] = array();
113 5f601060 Phil Davis
}
114 a93e56c5 Matthew Grooms
115 9573afa8 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 9573afa8 Stephen Beaver
	$a_phase1 = &$config['ipsec']['phase1'];
120
	$status = ipsec_list_sa();
121
	$ipsecconnected = array();
122 a93e56c5 Matthew Grooms
123 9573afa8 Stephen Beaver
	if (is_array($status)) {
124
		foreach ($status as $ikeid => $ikesa) {
125
			$con_id = substr($ikeid, 3);
126 3795cc0a sbeaver
127 9573afa8 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 9573afa8 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 9573afa8 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 9573afa8 Stephen Beaver
				print(gettext("Unknown"));
148 5f601060 Phil Davis
			}
149 86b2861c Matt Smith
150 9573afa8 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 9573afa8 Stephen Beaver
				print(gettext("Unknown"));
157 86b2861c Matt Smith
			}
158 9573afa8 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
				print("NAT-T");
167
			}
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 9573afa8 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
			print("<br/>" . htmlspecialchars($ikesa['established']) . gettext(" seconds (" . convert_seconds_to_hms($ikesa['established']) . ") ago"));
247
			print("</span>");
248
			print("</td>\n");
249
			print("<td>\n");
250
251
			if ($ikesa['state'] != 'ESTABLISHED') {
252
253
			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"). '" >');
254
			print('<i class="fa fa-sign-in icon-embed-btn"></i>');
255
			print(gettext("Connect VPN"));
256
			print("</a>\n");
257
258 86b2861c Matt Smith
			} else {
259 9573afa8 Stephen Beaver
260
				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") . '">');
261
				print('<i class="fa fa-trash icon-embed-btn"></i>');
262
				print(gettext("Disconnect"));
263
				print("</a><br />\n");
264
265
			}
266
267
			print("</td>\n");
268
			print("</tr>\n");
269
			print("<tr>\n");
270
			print("<td colspan = 10>\n");
271
272
			if (is_array($ikesa['child-sas']) && (count($ikesa['child-sas']) > 0)) {
273
274
				print('<div id="btnchildsa-' . $ikeid . '">');
275
				print('<a type="button" onclick="show_childsa(\'childsa-' . $ikeid . '\',\'btnchildsa-' . $ikeid. '\');" class="btn btn-sm btn-info">');
276
				print('<i class="fa fa-plus-circle icon-embed-btn"></i>');
277
				print(gettext('Show child SA entries'));
278
				print("</a>\n");
279
				print("	</div>\n");
280
281
				print('<table class="table table-hover table-condensed" id="childsa-' . $ikeid . '" style="display:none">');
282
				print("<thead>\n");
283
				print('<tr class="bg-info">');
284
				print('<th><?=gettext("Local subnets")?></th>');
285
				print('<th><?=gettext("Local SPI(s)")?></th>');
286
				print('<th><?=gettext("Remote subnets")?></th>');
287
				print('<th><?=gettext("Times")?></th>');
288
				print('<th><?=gettext("Algo")?></th>');
289
				print('<th><?=gettext("Stats")?></th>');
290
				print('<th><!-- Buttons --></th>');
291
				print("</tr\n");
292
				print("</thead>\n");
293
				print("<tbody>\n");
294
295
				foreach ($ikesa['child-sas'] as $childid => $childsa) {
296
					print("<tr>");
297
					print("<td>\n");
298
299
					if (is_array($childsa['local-ts'])) {
300
						foreach ($childsa['local-ts'] as $lnets) {
301
							print(htmlspecialchars(ipsec_fixup_network($lnets)) . "<br />");
302
						}
303
					} else {
304
						print(gettext("Unknown"));
305
					}
306
307
					print("</td>\n");
308
					print("<td>\n");
309
310
					if (isset($childsa['spi-in'])) {
311
						print(gettext("Local: ") . htmlspecialchars($childsa['spi-in']));
312
					}
313
314
					if (isset($childsa['spi-out'])) {
315
						print('<br/>' . gettext('Remote: ') . htmlspecialchars($childsa['spi-out']));
316
					}
317
318
					print("</td>\n");
319
					print("<td>\n");
320
321
					if (is_array($childsa['remote-ts'])) {
322
						foreach ($childsa['remote-ts'] as $rnets) {
323
							print(htmlspecialchars(ipsec_fixup_network($rnets)) . '<br />');
324
						}
325
					} else {
326
						print(gettext("Unknown"));
327
					}
328
329
					print("</td>\n");
330
					print("<td>\n");
331
332
					print(gettext("Rekey: ") . htmlspecialchars($childsa['rekey-time']) . gettext(" seconds (") . convert_seconds_to_hms($childsa['rekey-time']) . ")");
333
					print('<br/>' . gettext('Life: ') . htmlspecialchars($childsa['life-time']) . gettext(" seconds (") . convert_seconds_to_hms($childsa['life-time']) . ")");
334
					print('<br/>' . gettext('Install: ') .htmlspecialchars($childsa['install-time']) . gettext(" seconds (") . convert_seconds_to_hms($childsa['install-time']) . ")");
335
336
337
					print("</td>\n");
338
					print("<td>\n");
339
340
					print(htmlspecialchars($childsa['encr-alg']) . '<br/>');
341
					print(htmlspecialchars($childsa['integ-alg']) . '<br/>');
342
343
					if (!empty($childsa['prf-alg'])) {
344
						print(htmlspecialchars($childsa['prf-alg']) . '<br/>');
345
					}
346
347
					if (!empty($childsa['dh-group'])) {
348
						print(htmlspecialchars($childsa['dh-group']) . '<br/>');
349
					}
350
351
					if (!empty($childsa['esn'])) {
352
						print(htmlspecialchars($childsa['esn']) . '<br/>');
353
					}
354
355
					print(gettext("IPComp: "));
356
					if (!empty($childsa['cpi-in']) || !empty($childsa['cpi-out'])) {
357
						print(htmlspecialchars($childsa['cpi-in']) . " " . htmlspecialchars($childsa['cpi-out']));
358
					} else {
359
						print(gettext('none'));
360
					}
361
362
					print("</td>\n");
363
					print("<td>\n");
364
365
					print(gettext("Bytes-In: ") . htmlspecialchars(number_format($childsa['bytes-in'])) . ' (' . htmlspecialchars(format_bytes($childsa['bytes-in'])) . ')<br/>');
366
					print(gettext("Packets-In: ") . htmlspecialchars(number_format($childsa['packets-in'])) . '<br/>');
367
					print(gettext("Bytes-Out: ") . htmlspecialchars(number_format($childsa['bytes-out'])) . ' (' . htmlspecialchars(format_bytes($childsa['bytes-out'])) . ')<br/>');
368
					print(gettext("Packets-Out: ") . htmlspecialchars(number_format($childsa['packets-out'])) . '<br/>');
369
370
					print("</td>\n");
371
					print("<td>\n");
372
					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') . '">');
373
					print('<i class="fa fa-trash icon-embed-btn"></i>');
374
					print(gettext("Disconnect"));
375
					print("</a>\n");
376
					print("</td>\n");
377
					print("</tr>\n");
378
379
				}
380
381
				print("</tbody>\n");
382
				print("	</table>\n");
383
				print("</td>\n");
384 017ca0c0 Stephen Beaver
				print("</tr>\n");
385 9573afa8 Stephen Beaver
386 3795cc0a sbeaver
			}
387 9573afa8 Stephen Beaver
388
			unset($con_id);
389 86b2861c Matt Smith
		}
390 9573afa8 Stephen Beaver
391
	}
392
393
	$rgmap = array();
394
	foreach ($a_phase1 as $ph1ent) {
395
		if (isset($ph1ent['disabled'])) {
396
			continue;
397 86b2861c Matt Smith
		}
398 9573afa8 Stephen Beaver
399
		$rgmap[$ph1ent['remote-gateway']] = $ph1ent['remote-gateway'];
400
401
		if ($ipsecconnected[$ph1ent['ikeid']]) {
402
			continue;
403 86b2861c Matt Smith
		}
404 9573afa8 Stephen Beaver
405
		print("<tr>\n");
406
		print("<td>\n");
407
408
		print(htmlspecialchars($ph1ent['descr']));
409
		print("</td>\n");
410
		print("<td>\n");
411
		list ($myid_type, $myid_data) = ipsec_find_id($ph1ent, "local");
412
413
		if (empty($myid_data)) {
414
			print(gettext("Unknown"));
415 86b2861c Matt Smith
		} else {
416 9573afa8 Stephen Beaver
			print(htmlspecialchars($myid_data));
417 86b2861c Matt Smith
		}
418 9573afa8 Stephen Beaver
419
		print("</td>\n");
420
		print("<td>\n");
421
		$ph1src = ipsec_get_phase1_src($ph1ent);
422
423
		if (empty($ph1src)) {
424
			print(gettext("Unknown"));
425 86b2861c Matt Smith
		} else {
426 9573afa8 Stephen Beaver
			print(htmlspecialchars($ph1src));
427 86b2861c Matt Smith
		}
428 9573afa8 Stephen Beaver
429
		print("</td>\n");
430
		print("<td>\n");
431
432
		list ($peerid_type, $peerid_data) = ipsec_find_id($ph1ent, "peer", $rgmap);
433
434
		if (empty($peerid_data)) {
435
			print(gettext("Unknown"));
436 86b2861c Matt Smith
		} else {
437 9573afa8 Stephen Beaver
			print(htmlspecialchars($peerid_data));
438 86b2861c Matt Smith
		}
439 9573afa8 Stephen Beaver
		print("			</td>\n");
440
		print("			<td>\n");
441
		$ph1src = ipsec_get_phase1_dst($ph1ent);
442 0da0d43e Phil Davis
443 9573afa8 Stephen Beaver
		if (empty($ph1src)) {
444
			print(gettext("Unknown"));
445
		} else {
446
			print(htmlspecialchars($ph1src));
447
		}
448 3795cc0a sbeaver
449 9573afa8 Stephen Beaver
		print("</td>\n");
450
		print("<td>\n");
451
		print("</td>\n");
452
		print("<td>\n");
453
		print("</td>\n");
454
		print("<td>\n");
455
		print("</td>\n");
456 0da0d43e Phil Davis
457 9573afa8 Stephen Beaver
		if (isset($ph1ent['mobile'])) {
458 0da0d43e Phil Davis
459 9573afa8 Stephen Beaver
			print("<td>\n");
460
			print(gettext("Awaiting connections"));
461
			print("</td>\n");
462
			print("<td>\n");
463
			print("</td>\n");
464
			print("</td>\n");
465
		} else {
466 3795cc0a sbeaver
467 9573afa8 Stephen Beaver
			print("<td>\n");
468
			print(gettext("Disconnected"));
469
			print("</td>\n");
470
			print("<td>\n");
471
			print('<a href="status_ipsec.php?act=connect&amp;ikeid=' . $ph1ent['ikeid'] . '" class="btn btn-xs btn-success">');
472
			print('<i class="fa fa-sign-in icon-embed-btn"></i>');
473
			print(gettext("Connect VPN"));
474
			print("</a>\n");
475
			print("</td>\n");
476 3795cc0a sbeaver
477 9573afa8 Stephen Beaver
		}
478
		print("</tr>\n");
479 97242546 Matt Smith
	}
480
481 9573afa8 Stephen Beaver
	unset($ipsecconnected, $phase1, $rgmap);
482 86b2861c Matt Smith
}
483 3795cc0a sbeaver
484 9573afa8 Stephen Beaver
$pgtitle = array(gettext("Status"), gettext("IPsec"), gettext("Overview"));
485
$shortcut_section = "ipsec";
486 0da0d43e Phil Davis
487 9573afa8 Stephen Beaver
include("head.inc");
488 0da0d43e Phil Davis
489 9573afa8 Stephen Beaver
$tab_array = array();
490
$tab_array[] = array(gettext("Overview"), true, "status_ipsec.php");
491
$tab_array[] = array(gettext("Leases"), false, "status_ipsec_leases.php");
492
$tab_array[] = array(gettext("SADs"), false, "status_ipsec_sad.php");
493
$tab_array[] = array(gettext("SPDs"), false, "status_ipsec_spd.php");
494
display_top_tabs($tab_array);
495 3795cc0a sbeaver
?>
496 0da0d43e Phil Davis
497 9573afa8 Stephen Beaver
<div class="panel panel-default">
498
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("IPsec Status");?></h2></div>
499
	<div class="panel-body table-responsive">
500
		<table class="table table-striped table-condensed table-hover sortable-theme-bootstrap" data-sortable>
501
			<thead>
502
				<tr>
503
					<th><?=gettext("Description")?></th>
504
					<th><?=gettext("Local ID")?></th>
505
					<th><?=gettext("Local IP")?></th>
506
					<th><?=gettext("Remote ID")?></th>
507
					<th><?=gettext("Remote IP")?></th>
508
					<th><?=gettext("Role")?></th>
509
					<th><?=gettext("Reauth")?></th>
510
					<th><?=gettext("Algo")?></th>
511
					<th><?=gettext("Status")?></th>
512
					<th></th>
513
				</tr>
514
			</thead>
515
			<tbody id="ipsec-body">
516
				<tr>
517
					<td colspan="9">
518
						<?=print_info_box(gettext("Collecting IPSec status information"), warning, "")?>
519 3795cc0a sbeaver
					</td>
520
				</tr>
521
			</tbody>
522 c7fbdd6c Ermal
		</table>
523
	</div>
524 3795cc0a sbeaver
</div>
525
526
<?php
527
unset($status);
528 9573afa8 Stephen Beaver
529 d2c1089f Phil Davis
if (ipsec_enabled()) {
530 9573afa8 Stephen Beaver
	print('<div class="infoblock">');
531 d2c1089f Phil Davis
} else {
532 9573afa8 Stephen Beaver
	print('<div class="infoblock blockopen">');
533 d2c1089f Phil Davis
}
534 9573afa8 Stephen Beaver
535 4a22d33f Stephen Beaver
print_info_box(sprintf(gettext('IPsec can be configured %1$shere%2$s.'), '<a href="vpn_ipsec.php">', '</a>'), 'info', false);
536 d2c1089f Phil Davis
?>
537
</div>
538 9573afa8 Stephen Beaver
539
<script type="text/javascript">
540
//<![CDATA[
541
542
// Array in which to keep hte SA show/hide state
543
sa_open = new Array();
544
545
function show_childsa(id, buttonid) {
546
	$('#' + id).show();
547
	$('#' + buttonid).hide();
548
549
	// Record the ID of the SA we have revealed so that it can automatically be shown on AJAX reload
550
	idnum = id.replace( /^\D+/g, '');
551
	sa_open[idnum] = true;
552
}
553
554
events.push(function() {
555
	ajax_lock = false;	// Mutex so we don't make a call until the previous call is finished
556
	sa_open = [];
557
558
	// Fetch the tbody contents from the server
559
	function update_table() {
560
		if (ajax_lock) {
561
			return;
562
		}
563
564
		ajax_lock = true;
565
566
		ajaxRequest = $.ajax(
567
			{
568
				url: "/status_ipsec.php",
569
				type: "post",
570
				data: {
571
					ajax: 	"ajax"
572
				}
573
			}
574
		);
575
576
		// Deal with the results of the above ajax call
577
		ajaxRequest.done(function (response, textStatus, jqXHR) {
578
			$('#ipsec-body').html(response);
579
			ajax_lock = false;
580
581
			// Check the sa_open array for SAs we have chosen to show
582
			$('[id^=childsa-con]').each(function(idx) {
583
				sa_idx = idx + 1;
584
585
				if (sa_open[sa_idx]) {
586
					show_childsa("childsa-con" + sa_idx, "btnchildsa-con" + sa_idx);
587
				}
588
			});
589
590
			// and do it again
591
			setTimeout(update_table, 5000);
592
		});
593
	}
594
595
	// Populate the tbody on page load
596
	update_table();
597
});
598
//]]>
599
</script>
600
601 d2c1089f Phil Davis
<?php
602 3795cc0a sbeaver
include("foot.inc"); ?>