Project

General

Profile

Download (18.1 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 e3c0d75e Luiz Souza
 * Copyright (c) 2004-2018 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 3093b965 Graham Collinson
				if (!ipsec_ikeid_used($con_id)) {
130
					// probably a v2 with split connection then
131
					$ph1idx = substr($con_id, 0, strrpos(substr($con_id, 0, -1), '00'));
132
					$ipsecconnected[$ph1idx] = $ph1idx;
133
				} else {
134
					$ipsecconnected[$con_id] = $ph1idx = $con_id;
135
				}
136 9573afa8 Stephen Beaver
			}
137 3795cc0a sbeaver
138 9573afa8 Stephen Beaver
			print("<tr>\n");
139
			print("<td>\n");
140
			print(htmlspecialchars(ipsec_get_descr($ph1idx)));
141
			print("</td>\n");
142
			print("<td>\n");
143 0da0d43e Phil Davis
144 9573afa8 Stephen Beaver
			if (!empty($ikesa['local-id'])) {
145
				if ($ikesa['local-id'] == '%any') {
146
					print(gettext('Any identifier'));
147
				} else {
148
					print(htmlspecialchars($ikesa['local-id']));
149
				}
150 5f601060 Phil Davis
			} else {
151 9573afa8 Stephen Beaver
				print(gettext("Unknown"));
152 5f601060 Phil Davis
			}
153 86b2861c Matt Smith
154 9573afa8 Stephen Beaver
			print("</td>\n");
155
			print("<td>\n");
156
157
			if (!empty($ikesa['local-host'])) {
158
				print(htmlspecialchars($ikesa['local-host']));
159 86b2861c Matt Smith
			} else {
160 9573afa8 Stephen Beaver
				print(gettext("Unknown"));
161 86b2861c Matt Smith
			}
162 9573afa8 Stephen Beaver
163
			/*
164
			 * XXX: local-nat-t was defined by pfSense
165
			 * When strongswan team accepted the change, they changed it to
166
			 * nat-local. Keep both for a while and remove local-nat-t in
167
			 * the future
168
			 */
169
			if (isset($ikesa['local-nat-t']) || isset($ikesa['nat-local'])) {
170 c7445ef5 Stephen Beaver
				print(" NAT-T");
171 9573afa8 Stephen Beaver
			}
172
173
			print("</td>\n");
174
			print("<td>\n");
175
176
			$identity = "";
177
			if (!empty($ikesa['remote-id'])) {
178
				if ($ikesa['remote-id'] == '%any') {
179
					$identity = htmlspecialchars(gettext('Any identifier'));
180
				} else {
181
					$identity = htmlspecialchars($ikesa['remote-id']);
182
				}
183
			}
184
185
			if (!empty($ikesa['remote-xauth-id'])) {
186
				echo htmlspecialchars($ikesa['remote-xauth-id']);
187
				echo "<br/>{$identity}";
188
			} elseif (!empty($ikesa['remote-eap-id'])) {
189
				echo htmlspecialchars($ikesa['remote-eap-id']);
190
				echo "<br/>{$identity}";
191
			} else {
192
				if (empty($identity)) {
193
					print(gettext("Unknown"));
194
				} else {
195
					print($identity);
196
				}
197
			}
198
199
			print("</td>\n");
200
			print("<td>\n");
201
202
			if (!empty($ikesa['remote-host'])) {
203
				print(htmlspecialchars($ikesa['remote-host']));
204
			} else {
205 3795cc0a sbeaver
				print(gettext("Unknown"));
206 9573afa8 Stephen Beaver
			}
207
			/*
208
			 * XXX: remote-nat-t was defined by pfSense
209
			 * When strongswan team accepted the change, they changed it to
210
			 * nat-remote. Keep both for a while and remove remote-nat-t in
211
			 * the future
212
			 */
213
			if (isset($ikesa['remote-nat-t']) || isset($ikesa['nat-remote'])) {
214
				print(" NAT-T");
215
			}
216
217
			print("</td>\n");
218
			print("<td>\n");
219
			print("IKEv" . htmlspecialchars($ikesa['version']));
220
			print("<br/>\n");
221
222
			if ($ikesa['initiator'] == 'yes') {
223
				print("initiator");
224
			} else {
225
				print("responder");
226
			}
227
228
			print("</td>\n");
229
			print("<td>\n");
230 11e09114 stilez
			print(htmlspecialchars($ikesa['reauth-time']) . gettext(" seconds (") . convert_seconds_to_dhms($ikesa['reauth-time']) . ")");
231 9573afa8 Stephen Beaver
			print("</td>\n");
232
			print("<td>\n");
233
			print(htmlspecialchars($ikesa['encr-alg']));
234
			print("<br/>");
235
			print(htmlspecialchars($ikesa['integ-alg']));
236
			print("<br/>");
237
			print(htmlspecialchars($ikesa['prf-alg']));
238
			print("<br/>\n");
239
			print(htmlspecialchars($ikesa['dh-group']));
240
			print("</td>\n");
241
			print("<td>\n");
242
243
			if ($ikesa['state'] == 'ESTABLISHED') {
244
				print('<span class="text-success">');
245
			} else {
246
				print('<span>');
247
			}
248
249
			print(ucfirst(htmlspecialchars($ikesa['state'])));
250 e2fba23c Stephen Beaver
251
			if ($ikesa['state'] == 'ESTABLISHED') {
252 11e09114 stilez
				print("<br/>" . htmlspecialchars($ikesa['established']) . gettext(" seconds (") . convert_seconds_to_dhms($ikesa['established']) . gettext(") ago"));
253 e2fba23c Stephen Beaver
			}
254
255 9573afa8 Stephen Beaver
			print("</span>");
256
			print("</td>\n");
257
			print("<td>\n");
258
259
			if ($ikesa['state'] != 'ESTABLISHED') {
260
261 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"). '" >');
262
				print('<i class="fa fa-sign-in icon-embed-btn"></i>');
263
				print(gettext("Connect VPN"));
264
				print("</a>\n");
265 9573afa8 Stephen Beaver
266 86b2861c Matt Smith
			} else {
267 9573afa8 Stephen Beaver
268
				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") . '">');
269
				print('<i class="fa fa-trash icon-embed-btn"></i>');
270
				print(gettext("Disconnect"));
271
				print("</a><br />\n");
272
273
			}
274
275
			print("</td>\n");
276
			print("</tr>\n");
277
			print("<tr>\n");
278
			print("<td colspan = 10>\n");
279
280
			if (is_array($ikesa['child-sas']) && (count($ikesa['child-sas']) > 0)) {
281
282 cccb1e1a Stephen Beaver
				print('<div>');
283
				print('<a type="button" id="btnchildsa-' . $ikeid .  '" class="btn btn-sm btn-info">');
284 9573afa8 Stephen Beaver
				print('<i class="fa fa-plus-circle icon-embed-btn"></i>');
285
				print(gettext('Show child SA entries'));
286
				print("</a>\n");
287
				print("	</div>\n");
288
289
				print('<table class="table table-hover table-condensed" id="childsa-' . $ikeid . '" style="display:none">');
290
				print("<thead>\n");
291
				print('<tr class="bg-info">');
292
				print('<th><?=gettext("Local subnets")?></th>');
293
				print('<th><?=gettext("Local SPI(s)")?></th>');
294
				print('<th><?=gettext("Remote subnets")?></th>');
295
				print('<th><?=gettext("Times")?></th>');
296
				print('<th><?=gettext("Algo")?></th>');
297
				print('<th><?=gettext("Stats")?></th>');
298
				print('<th><!-- Buttons --></th>');
299
				print("</tr\n");
300
				print("</thead>\n");
301
				print("<tbody>\n");
302
303
				foreach ($ikesa['child-sas'] as $childid => $childsa) {
304
					print("<tr>");
305
					print("<td>\n");
306
307
					if (is_array($childsa['local-ts'])) {
308
						foreach ($childsa['local-ts'] as $lnets) {
309
							print(htmlspecialchars(ipsec_fixup_network($lnets)) . "<br />");
310
						}
311
					} else {
312
						print(gettext("Unknown"));
313
					}
314
315
					print("</td>\n");
316
					print("<td>\n");
317
318
					if (isset($childsa['spi-in'])) {
319
						print(gettext("Local: ") . htmlspecialchars($childsa['spi-in']));
320
					}
321
322
					if (isset($childsa['spi-out'])) {
323
						print('<br/>' . gettext('Remote: ') . htmlspecialchars($childsa['spi-out']));
324
					}
325
326
					print("</td>\n");
327
					print("<td>\n");
328
329
					if (is_array($childsa['remote-ts'])) {
330
						foreach ($childsa['remote-ts'] as $rnets) {
331
							print(htmlspecialchars(ipsec_fixup_network($rnets)) . '<br />');
332
						}
333
					} else {
334
						print(gettext("Unknown"));
335
					}
336
337
					print("</td>\n");
338
					print("<td>\n");
339
340 11e09114 stilez
					print(gettext("Rekey: ") . htmlspecialchars($childsa['rekey-time']) . gettext(" seconds (") . convert_seconds_to_dhms($childsa['rekey-time']) . ")");
341
					print('<br/>' . gettext('Life: ') . htmlspecialchars($childsa['life-time']) . gettext(" seconds (") . convert_seconds_to_dhms($childsa['life-time']) . ")");
342
					print('<br/>' . gettext('Install: ') .htmlspecialchars($childsa['install-time']) . gettext(" seconds (") . convert_seconds_to_dhms($childsa['install-time']) . ")");
343 9573afa8 Stephen Beaver
344
345
					print("</td>\n");
346
					print("<td>\n");
347
348
					print(htmlspecialchars($childsa['encr-alg']) . '<br/>');
349
					print(htmlspecialchars($childsa['integ-alg']) . '<br/>');
350
351
					if (!empty($childsa['prf-alg'])) {
352
						print(htmlspecialchars($childsa['prf-alg']) . '<br/>');
353
					}
354
355
					if (!empty($childsa['dh-group'])) {
356
						print(htmlspecialchars($childsa['dh-group']) . '<br/>');
357
					}
358
359
					if (!empty($childsa['esn'])) {
360
						print(htmlspecialchars($childsa['esn']) . '<br/>');
361
					}
362
363
					print(gettext("IPComp: "));
364
					if (!empty($childsa['cpi-in']) || !empty($childsa['cpi-out'])) {
365
						print(htmlspecialchars($childsa['cpi-in']) . " " . htmlspecialchars($childsa['cpi-out']));
366
					} else {
367
						print(gettext('none'));
368
					}
369
370
					print("</td>\n");
371
					print("<td>\n");
372
373
					print(gettext("Bytes-In: ") . htmlspecialchars(number_format($childsa['bytes-in'])) . ' (' . htmlspecialchars(format_bytes($childsa['bytes-in'])) . ')<br/>');
374
					print(gettext("Packets-In: ") . htmlspecialchars(number_format($childsa['packets-in'])) . '<br/>');
375
					print(gettext("Bytes-Out: ") . htmlspecialchars(number_format($childsa['bytes-out'])) . ' (' . htmlspecialchars(format_bytes($childsa['bytes-out'])) . ')<br/>');
376
					print(gettext("Packets-Out: ") . htmlspecialchars(number_format($childsa['packets-out'])) . '<br/>');
377
378
					print("</td>\n");
379
					print("<td>\n");
380
					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') . '">');
381
					print('<i class="fa fa-trash icon-embed-btn"></i>');
382
					print(gettext("Disconnect"));
383
					print("</a>\n");
384
					print("</td>\n");
385
					print("</tr>\n");
386
387
				}
388
389
				print("</tbody>\n");
390
				print("	</table>\n");
391
				print("</td>\n");
392 017ca0c0 Stephen Beaver
				print("</tr>\n");
393 9573afa8 Stephen Beaver
394 3795cc0a sbeaver
			}
395 9573afa8 Stephen Beaver
396
			unset($con_id);
397 86b2861c Matt Smith
		}
398 9573afa8 Stephen Beaver
399
	}
400
401
	$rgmap = array();
402 713f69e2 Stephen Beaver
	if (is_array($a_phase1)) {
403
		foreach ($a_phase1 as $ph1ent) {
404
			if (isset($ph1ent['disabled'])) {
405
				continue;
406
			}
407 9573afa8 Stephen Beaver
408 713f69e2 Stephen Beaver
			$rgmap[$ph1ent['remote-gateway']] = $ph1ent['remote-gateway'];
409 9573afa8 Stephen Beaver
410 713f69e2 Stephen Beaver
			if ($ipsecconnected[$ph1ent['ikeid']]) {
411
				continue;
412
			}
413 9573afa8 Stephen Beaver
414 713f69e2 Stephen Beaver
			print("<tr>\n");
415
			print("<td>\n");
416 9573afa8 Stephen Beaver
417 713f69e2 Stephen Beaver
			print(htmlspecialchars($ph1ent['descr']));
418
			print("</td>\n");
419
			print("<td>\n");
420
			list ($myid_type, $myid_data) = ipsec_find_id($ph1ent, "local");
421 9573afa8 Stephen Beaver
422 713f69e2 Stephen Beaver
			if (empty($myid_data)) {
423
				print(gettext("Unknown"));
424
			} else {
425
				print(htmlspecialchars($myid_data));
426
			}
427 9573afa8 Stephen Beaver
428 713f69e2 Stephen Beaver
			print("</td>\n");
429
			print("<td>\n");
430
			$ph1src = ipsec_get_phase1_src($ph1ent);
431 9573afa8 Stephen Beaver
432 713f69e2 Stephen Beaver
			if (empty($ph1src)) {
433
				print(gettext("Unknown"));
434
			} else {
435
				print(htmlspecialchars($ph1src));
436
			}
437 9573afa8 Stephen Beaver
438 713f69e2 Stephen Beaver
			print("</td>\n");
439
			print("<td>\n");
440 0da0d43e Phil Davis
441 713f69e2 Stephen Beaver
			list ($peerid_type, $peerid_data) = ipsec_find_id($ph1ent, "peer", $rgmap);
442 3795cc0a sbeaver
443 713f69e2 Stephen Beaver
			if (empty($peerid_data)) {
444
				print(gettext("Unknown"));
445
			} else {
446
				print(htmlspecialchars($peerid_data));
447
			}
448
			print("			</td>\n");
449
			print("			<td>\n");
450
			$ph1src = ipsec_get_phase1_dst($ph1ent);
451 0da0d43e Phil Davis
452 713f69e2 Stephen Beaver
			if (empty($ph1src)) {
453
				print(gettext("Unknown"));
454
			} else {
455
				print(htmlspecialchars($ph1src));
456
			}
457 0da0d43e Phil Davis
458 9573afa8 Stephen Beaver
			print("</td>\n");
459
			print("<td>\n");
460
			print("</td>\n");
461
			print("<td>\n");
462
			print("</td>\n");
463
			print("<td>\n");
464
			print("</td>\n");
465 3795cc0a sbeaver
466 713f69e2 Stephen Beaver
			if (isset($ph1ent['mobile'])) {
467
468
				print("<td>\n");
469
				print(gettext("Awaiting connections"));
470
				print("</td>\n");
471
				print("<td>\n");
472
				print("</td>\n");
473
				print("</td>\n");
474
			} else {
475
476
				print("<td>\n");
477
				print(gettext("Disconnected"));
478
				print("</td>\n");
479
				print("<td>\n");
480
				print('<a href="status_ipsec.php?act=connect&amp;ikeid=' . $ph1ent['ikeid'] . '" class="btn btn-xs btn-success">');
481
				print('<i class="fa fa-sign-in icon-embed-btn"></i>');
482
				print(gettext("Connect VPN"));
483
				print("</a>\n");
484
				print("</td>\n");
485
486
			}
487
			print("</tr>\n");
488 9573afa8 Stephen Beaver
		}
489 97242546 Matt Smith
	}
490
491 9573afa8 Stephen Beaver
	unset($ipsecconnected, $phase1, $rgmap);
492 86b2861c Matt Smith
}
493 3795cc0a sbeaver
494 9573afa8 Stephen Beaver
$pgtitle = array(gettext("Status"), gettext("IPsec"), gettext("Overview"));
495 de02dc29 Phil Davis
$pglinks = array("", "@self", "@self");
496 9573afa8 Stephen Beaver
$shortcut_section = "ipsec";
497 0da0d43e Phil Davis
498 9573afa8 Stephen Beaver
include("head.inc");
499 0da0d43e Phil Davis
500 9573afa8 Stephen Beaver
$tab_array = array();
501
$tab_array[] = array(gettext("Overview"), true, "status_ipsec.php");
502
$tab_array[] = array(gettext("Leases"), false, "status_ipsec_leases.php");
503
$tab_array[] = array(gettext("SADs"), false, "status_ipsec_sad.php");
504
$tab_array[] = array(gettext("SPDs"), false, "status_ipsec_spd.php");
505
display_top_tabs($tab_array);
506 3795cc0a sbeaver
?>
507 0da0d43e Phil Davis
508 9573afa8 Stephen Beaver
<div class="panel panel-default">
509
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("IPsec Status");?></h2></div>
510
	<div class="panel-body table-responsive">
511
		<table class="table table-striped table-condensed table-hover sortable-theme-bootstrap" data-sortable>
512
			<thead>
513
				<tr>
514
					<th><?=gettext("Description")?></th>
515
					<th><?=gettext("Local ID")?></th>
516
					<th><?=gettext("Local IP")?></th>
517
					<th><?=gettext("Remote ID")?></th>
518
					<th><?=gettext("Remote IP")?></th>
519
					<th><?=gettext("Role")?></th>
520
					<th><?=gettext("Reauth")?></th>
521
					<th><?=gettext("Algo")?></th>
522
					<th><?=gettext("Status")?></th>
523
					<th></th>
524
				</tr>
525
			</thead>
526
			<tbody id="ipsec-body">
527
				<tr>
528 d8257e0e NOYB
					<td colspan="10">
529 1ca5d09f Phil Davis
						<?=print_info_box(gettext("Collecting IPsec status information."), "warning", "")?>
530 3795cc0a sbeaver
					</td>
531
				</tr>
532
			</tbody>
533 c7fbdd6c Ermal
		</table>
534
	</div>
535 3795cc0a sbeaver
</div>
536
537
<?php
538
unset($status);
539 9573afa8 Stephen Beaver
540 d2c1089f Phil Davis
if (ipsec_enabled()) {
541 9573afa8 Stephen Beaver
	print('<div class="infoblock">');
542 d2c1089f Phil Davis
} else {
543 9573afa8 Stephen Beaver
	print('<div class="infoblock blockopen">');
544 d2c1089f Phil Davis
}
545 9573afa8 Stephen Beaver
546 4a22d33f Stephen Beaver
print_info_box(sprintf(gettext('IPsec can be configured %1$shere%2$s.'), '<a href="vpn_ipsec.php">', '</a>'), 'info', false);
547 d2c1089f Phil Davis
?>
548
</div>
549 9573afa8 Stephen Beaver
550
<script type="text/javascript">
551
//<![CDATA[
552
553
events.push(function() {
554 cccb1e1a Stephen Beaver
	ajax_lock = false;		// Mutex so we don't make a call until the previous call is finished
555
	sa_open = new Array();	// Array in which to keep the child SA show/hide state
556 9573afa8 Stephen Beaver
557
	// Fetch the tbody contents from the server
558
	function update_table() {
559
		if (ajax_lock) {
560
			return;
561
		}
562
563
		ajax_lock = true;
564
565
		ajaxRequest = $.ajax(
566
			{
567
				url: "/status_ipsec.php",
568
				type: "post",
569
				data: {
570
					ajax: 	"ajax"
571
				}
572
			}
573
		);
574
575
		// Deal with the results of the above ajax call
576
		ajaxRequest.done(function (response, textStatus, jqXHR) {
577 d8257e0e NOYB
578
			if (!response) {
579 1ca5d09f Phil Davis
				response = '<tr><td colspan="10"><?=print_info_box(gettext("No IPsec status information available."), "warning", "")?></td></tr>';
580 d8257e0e NOYB
			}
581
582 9573afa8 Stephen Beaver
			$('#ipsec-body').html(response);
583
			ajax_lock = false;
584
585 cccb1e1a Stephen Beaver
			// Update "Show child SA" handlers
586
			$('[id^=btnchildsa-]').click(function () {
587
				show_childsa($(this).prop("id").replace( /^\D+/g, ''));
588
			});
589
590
			// Check the sa_open array for child SAs that have been opened
591 9573afa8 Stephen Beaver
			$('[id^=childsa-con]').each(function(idx) {
592 cccb1e1a Stephen Beaver
				sa_idx = $(this).prop("id").replace( /^\D+/g, '');
593 9573afa8 Stephen Beaver
594
				if (sa_open[sa_idx]) {
595 cccb1e1a Stephen Beaver
					show_childsa(sa_idx);
596 9573afa8 Stephen Beaver
				}
597
			});
598
599
			// and do it again
600
			setTimeout(update_table, 5000);
601
		});
602
	}
603
604 cccb1e1a Stephen Beaver
	function show_childsa(said) {
605
		sa_open[said] = true;
606
		$('#childsa-con' + said).show();
607
		$('#btnchildsa-con' + said).hide();
608
	}
609
610 9573afa8 Stephen Beaver
	// Populate the tbody on page load
611
	update_table();
612
});
613
//]]>
614
</script>
615
616 d2c1089f Phil Davis
<?php
617 3795cc0a sbeaver
include("foot.inc"); ?>