Project

General

Profile

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