Project

General

Profile

Download (17.6 KB) Statistics
| Branch: | Tag: | Revision:
1 cf7d1057 Scott Ullrich
<?php
2
/*
3 c5d81585 Renato Botelho
 * status_ipsec.php
4 86b2861c Matt Smith
 *
5 c5d81585 Renato Botelho
 * part of pfSense (https://www.pfsense.org)
6 b8f91b7c Luiz Souza
 * Copyright (c) 2004-2018 Rubicon Communications, LLC (Netgate)
7 c5d81585 Renato Botelho
 * All rights reserved.
8 fd9ebcd5 Stephen Beaver
 *
9 c5d81585 Renato Botelho
 * originally based on m0n0wall (http://m0n0.ch/wall)
10
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
11
 * All rights reserved.
12 fd9ebcd5 Stephen Beaver
 *
13 b12ea3fb Renato Botelho
 * Licensed under the Apache License, Version 2.0 (the "License");
14
 * you may not use this file except in compliance with the License.
15
 * You may obtain a copy of the License at
16 fd9ebcd5 Stephen Beaver
 *
17 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
18 fd9ebcd5 Stephen Beaver
 *
19 b12ea3fb Renato Botelho
 * Unless required by applicable law or agreed to in writing, software
20
 * distributed under the License is distributed on an "AS IS" BASIS,
21
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
 * See the License for the specific language governing permissions and
23
 * limitations under the License.
24 fd9ebcd5 Stephen Beaver
 */
25 cf7d1057 Scott Ullrich
26 6b07c15a Matthew Grooms
##|+PRIV
27
##|*IDENT=page-status-ipsec
28 5230f468 jim-p
##|*NAME=Status: IPsec
29 6b07c15a Matthew Grooms
##|*DESCR=Allow access to the 'Status: IPsec' page.
30 1af5edbf Stephen Beaver
##|*MATCH=status_ipsec.php*
31 6b07c15a Matthew Grooms
##|-PRIV
32
33 c81ef6e2 Phil Davis
require_once("guiconfig.inc");
34 4260c32a Stephen Beaver
require_once("ipsec.inc");
35 6b07c15a Matthew Grooms
36 a93e56c5 Matthew Grooms
global $g;
37
38 e3df164a Stephen Jones
if(!is_array($config['ipsec'])){
39
	$config['ipsec'] = array();
40
}
41
42 4b5f2ab3 Phil Davis
if (!is_array($config['ipsec']['phase1'])) {
43
	$config['ipsec']['phase1'] = array();
44
}
45
46 4260c32a Stephen Beaver
// If this is just an AJAX call to update the table body, just generate the body and quit
47
if ($_REQUEST['ajax']) {
48
	print_ipsec_body();
49
	exit;
50
}
51 a93e56c5 Matthew Grooms
52 64d53c69 Steve Beaver
if ($_POST['act'] == 'connect') {
53
	if (ctype_digit($_POST['ikeid'])) {
54
		$ph1ent = ipsec_get_phase1($_POST['ikeid']);
55 483c3b5b Ermal LUÇI
		if (!empty($ph1ent)) {
56 9d51fcde Chris Buechler
			if (empty($ph1ent['iketype']) || $ph1ent['iketype'] == 'ikev1' || isset($ph1ent['splitconn'])) {
57 64d53c69 Steve Beaver
				$ph2entries = ipsec_get_number_of_phase2($_POST['ikeid']);
58 483c3b5b Ermal LUÇI
				for ($i = 0; $i < $ph2entries; $i++) {
59 64d53c69 Steve Beaver
					$connid = escapeshellarg("con{$_POST['ikeid']}00{$i}");
60 c5d8cbe0 Chris Buechler
					mwexec_bg("/usr/local/sbin/ipsec down {$connid}");
61 b866103e Chris Buechler
					mwexec_bg("/usr/local/sbin/ipsec up {$connid}");
62 483c3b5b Ermal LUÇI
				}
63
			} else {
64 64d53c69 Steve Beaver
				mwexec_bg("/usr/local/sbin/ipsec down con" . escapeshellarg($_POST['ikeid']));
65
				mwexec_bg("/usr/local/sbin/ipsec up con" . escapeshellarg($_POST['ikeid']));
66 483c3b5b Ermal LUÇI
			}
67
		}
68 6e8b0ec3 jim-p
	}
69 64d53c69 Steve Beaver
} else if ($_POST['act'] == 'ikedisconnect') {
70 130f3c92 Stephen Jones
71 64d53c69 Steve Beaver
	if (ctype_digit($_POST['ikeid'])) {
72
		if (!empty($_POST['ikesaid']) && ctype_digit($_POST['ikesaid'])) {
73 130f3c92 Stephen Jones
			mwexec_bg("/usr/local/sbin/ipsec down " ."'" . "con" . escapeshellarg($_POST['ikeid']) . "[" . escapeshellarg($_POST['ikesaid']) . "]" . "'");
74 5f601060 Phil Davis
		} else {
75 64d53c69 Steve Beaver
			mwexec_bg("/usr/local/sbin/ipsec down con" . escapeshellarg($_POST['ikeid']));
76 5f601060 Phil Davis
		}
77 614be051 bcyrill
	}
78 64d53c69 Steve Beaver
} else if ($_POST['act'] == 'childdisconnect') {
79 130f3c92 Stephen Jones
	//pull out number from id
80
	$id_val = filter_var($_POST['ikeid'], FILTER_SANITIZE_NUMBER_INT);
81
82
	if (ctype_digit($id_val)) {
83 64d53c69 Steve Beaver
		if (!empty($_POST['ikesaid']) && ctype_digit($_POST['ikesaid'])) {
84 130f3c92 Stephen Jones
			mwexec_bg("/usr/local/sbin/ipsec down con" . escapeshellarg($id_val) . "{" . escapeshellarg($_POST['ikesaid']) . "}");
85 5f601060 Phil Davis
		}
86 6e0b68bf jim-p
	}
87
}
88
89 4260c32a Stephen Beaver
// Table body is composed here so that it can be more easily updated via AJAX
90
function print_ipsec_body() {
91
	global $config;
92
	$a_phase1 = &$config['ipsec']['phase1'];
93
	$status = ipsec_list_sa();
94
	$ipsecconnected = array();
95
	if (is_array($status)) {
96
		foreach ($status as $ikeid => $ikesa) {
97 130f3c92 Stephen Jones
			//check which array format
98
			if(isset($ikesa['con-id'])){
99
				$con_id = substr($ikesa['con-id'],3);
100
			}else{
101
				$con_id = filter_var($ikeid, FILTER_SANITIZE_NUMBER_INT);
102
			}
103 4260c32a Stephen Beaver
			if ($ikesa['version'] == 1) {
104
				$ph1idx = substr($con_id, 0, strrpos(substr($con_id, 0, -1), '00'));
105
				$ipsecconnected[$ph1idx] = $ph1idx;
106
			} else {
107 109a304e Graham Collinson
				if (!ipsec_ikeid_used($con_id)) {
108
					// probably a v2 with split connection then
109
					$ph1idx = substr($con_id, 0, strrpos(substr($con_id, 0, -1), '00'));
110
					$ipsecconnected[$ph1idx] = $ph1idx;
111
				} else {
112
					$ipsecconnected[$con_id] = $ph1idx = $con_id;
113
				}
114 4260c32a Stephen Beaver
			}
115 3795cc0a sbeaver
116 4260c32a Stephen Beaver
			print("<tr>\n");
117
			print("<td>\n");
118 80392e01 Stephen Jones
			if (is_array($a_phase1) && htmlspecialchars(ipsec_get_descr($ph1idx)) == "") {
119 29c1ecb8 Stephen Jones
				foreach ($a_phase1 as $ph1) {
120 80392e01 Stephen Jones
					if($con_id == $ph1['ikeid'] && isset($ph1['mobile']) ){
121
						print(htmlspecialchars($ph1['descr']));
122 29c1ecb8 Stephen Jones
						break;
123
					}
124
				}
125
			}
126 4260c32a Stephen Beaver
			print(htmlspecialchars(ipsec_get_descr($ph1idx)));
127
			print("</td>\n");
128
			print("<td>\n");
129 0da0d43e Phil Davis
130 4260c32a Stephen Beaver
			if (!empty($ikesa['local-id'])) {
131
				if ($ikesa['local-id'] == '%any') {
132
					print(gettext('Any identifier'));
133
				} else {
134
					print(htmlspecialchars($ikesa['local-id']));
135
				}
136 5f601060 Phil Davis
			} else {
137 4260c32a Stephen Beaver
				print(gettext("Unknown"));
138 5f601060 Phil Davis
			}
139 86b2861c Matt Smith
140 4260c32a Stephen Beaver
			print("</td>\n");
141
			print("<td>\n");
142
143
			if (!empty($ikesa['local-host'])) {
144
				print(htmlspecialchars($ikesa['local-host']));
145 86b2861c Matt Smith
			} else {
146 4260c32a Stephen Beaver
				print(gettext("Unknown"));
147 86b2861c Matt Smith
			}
148 4260c32a Stephen Beaver
149
			/*
150
			 * XXX: local-nat-t was defined by pfSense
151
			 * When strongswan team accepted the change, they changed it to
152
			 * nat-local. Keep both for a while and remove local-nat-t in
153
			 * the future
154
			 */
155
			if (isset($ikesa['local-nat-t']) || isset($ikesa['nat-local'])) {
156 e96b20f6 Jose Luis Duran
				print(" NAT-T");
157 4260c32a Stephen Beaver
			}
158
159
			print("</td>\n");
160
			print("<td>\n");
161
162
			$identity = "";
163
			if (!empty($ikesa['remote-id'])) {
164
				if ($ikesa['remote-id'] == '%any') {
165
					$identity = htmlspecialchars(gettext('Any identifier'));
166
				} else {
167
					$identity = htmlspecialchars($ikesa['remote-id']);
168
				}
169
			}
170
171
			if (!empty($ikesa['remote-xauth-id'])) {
172
				echo htmlspecialchars($ikesa['remote-xauth-id']);
173
				echo "<br/>{$identity}";
174
			} elseif (!empty($ikesa['remote-eap-id'])) {
175
				echo htmlspecialchars($ikesa['remote-eap-id']);
176
				echo "<br/>{$identity}";
177
			} else {
178
				if (empty($identity)) {
179
					print(gettext("Unknown"));
180
				} else {
181
					print($identity);
182
				}
183
			}
184
185
			print("</td>\n");
186
			print("<td>\n");
187
188
			if (!empty($ikesa['remote-host'])) {
189
				print(htmlspecialchars($ikesa['remote-host']));
190
			} else {
191 3795cc0a sbeaver
				print(gettext("Unknown"));
192 4260c32a Stephen Beaver
			}
193
			/*
194
			 * XXX: remote-nat-t was defined by pfSense
195
			 * When strongswan team accepted the change, they changed it to
196
			 * nat-remote. Keep both for a while and remove remote-nat-t in
197
			 * the future
198
			 */
199
			if (isset($ikesa['remote-nat-t']) || isset($ikesa['nat-remote'])) {
200
				print(" NAT-T");
201
			}
202
203
			print("</td>\n");
204
			print("<td>\n");
205
			print("IKEv" . htmlspecialchars($ikesa['version']));
206
			print("<br/>\n");
207
208
			if ($ikesa['initiator'] == 'yes') {
209
				print("initiator");
210
			} else {
211
				print("responder");
212
			}
213
214
			print("</td>\n");
215
			print("<td>\n");
216 c57e936a stilez
			print(htmlspecialchars($ikesa['reauth-time']) . gettext(" seconds (") . convert_seconds_to_dhms($ikesa['reauth-time']) . ")");
217 4260c32a Stephen Beaver
			print("</td>\n");
218
			print("<td>\n");
219
			print(htmlspecialchars($ikesa['encr-alg']));
220
			print("<br/>");
221
			print(htmlspecialchars($ikesa['integ-alg']));
222
			print("<br/>");
223
			print(htmlspecialchars($ikesa['prf-alg']));
224
			print("<br/>\n");
225
			print(htmlspecialchars($ikesa['dh-group']));
226
			print("</td>\n");
227
			print("<td>\n");
228
229
			if ($ikesa['state'] == 'ESTABLISHED') {
230
				print('<span class="text-success">');
231
			} else {
232
				print('<span>');
233
			}
234
235
			print(ucfirst(htmlspecialchars($ikesa['state'])));
236 9e820b59 Phil Davis
237
			if ($ikesa['state'] == 'ESTABLISHED') {
238 7f0d6ccf Phil Davis
				print("<br/>");
239
				printf(gettext('%1$s seconds (%2$s) ago'), htmlspecialchars($ikesa['established']), convert_seconds_to_dhms($ikesa['established']));
240 9e820b59 Phil Davis
			}
241
242 4260c32a Stephen Beaver
			print("</span>");
243
			print("</td>\n");
244
			print("<td>\n");
245
246
			if ($ikesa['state'] != 'ESTABLISHED') {
247
248 1144e24c Steve Beaver
				print('<a href="status_ipsec.php?act=connect&amp;ikeid=' . $con_id . '&amp;ikesaid=' .$ikesa['uniqueid'] . '" class="btn btn-xs btn-success" data-toggle="tooltip" title="' . gettext("Connect VPN"). '" usepost>');
249 9e820b59 Phil Davis
				print('<i class="fa fa-sign-in icon-embed-btn"></i>');
250
				print(gettext("Connect VPN"));
251
				print("</a>\n");
252 4260c32a Stephen Beaver
253 86b2861c Matt Smith
			} else {
254 4260c32a Stephen Beaver
255 1144e24c Steve Beaver
				print('<a href="status_ipsec.php?act=ikedisconnect&amp;ikeid=' . $con_id . '&amp;ikesaid=' .$ikesa['uniqueid'] . '"class="btn btn-xs btn-danger" data-toggle="tooltip" title="' . gettext("Disconnect VPN") . '" usepost>');
256 4260c32a Stephen Beaver
				print('<i class="fa fa-trash icon-embed-btn"></i>');
257
				print(gettext("Disconnect"));
258
				print("</a><br />\n");
259
260
			}
261
262
			print("</td>\n");
263
			print("</tr>\n");
264
			print("<tr>\n");
265
			print("<td colspan = 10>\n");
266
267
			if (is_array($ikesa['child-sas']) && (count($ikesa['child-sas']) > 0)) {
268 130f3c92 Stephen Jones
				$child_key = "";
269
				foreach ($ikesa['child-sas'] as $key => $val){
270
					$child_key = $key;
271
					break;
272
				}
273 4260c32a Stephen Beaver
274 067551a4 Stephen Beaver
				print('<div>');
275 130f3c92 Stephen Jones
				print('<a type="button" id="btnchildsa-'. $child_key .  '" class="btn btn-sm btn-info">');
276 4260c32a Stephen Beaver
				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 130f3c92 Stephen Jones
				print('<table class="table table-hover table-condensed" id="childsa-'.$child_key . '" style="display:none">');
282 4260c32a Stephen Beaver
				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 7f0d6ccf Phil Davis
					printf(gettext('Rekey: %1$s seconds (%2$s)'), htmlspecialchars($childsa['rekey-time']), convert_seconds_to_dhms($childsa['rekey-time']));
333
					print('<br/>');
334
					printf(gettext('Life: %1$s seconds (%2$s)'), htmlspecialchars($childsa['life-time']), convert_seconds_to_dhms($childsa['life-time']));
335
					print('<br/>');
336
					printf(gettext('Install: %1$s seconds (%2$s)'), htmlspecialchars($childsa['install-time']), convert_seconds_to_dhms($childsa['install-time']));
337 4260c32a 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 130f3c92 Stephen Jones
					print('<a href="status_ipsec.php?act=childdisconnect&amp;ikeid=' . $childsa['name'] . '&amp;ikesaid=' . $childsa['uniqueid'] . '" class="btn btn-xs btn-warning" data-toggle="tooltip" title="' . gettext('Disconnect Child SA') . '" usepost>');
375 4260c32a Stephen Beaver
					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 9723b525 Stephen Beaver
				print("</tr>\n");
387 4260c32a Stephen Beaver
388 3795cc0a sbeaver
			}
389 4260c32a Stephen Beaver
390
			unset($con_id);
391 86b2861c Matt Smith
		}
392 4260c32a Stephen Beaver
393
	}
394
395
	$rgmap = array();
396 4b5f2ab3 Phil Davis
	if (is_array($a_phase1)) {
397
		foreach ($a_phase1 as $ph1ent) {
398
			if (isset($ph1ent['disabled'])) {
399
				continue;
400
			}
401 4260c32a Stephen Beaver
402 4b5f2ab3 Phil Davis
			$rgmap[$ph1ent['remote-gateway']] = $ph1ent['remote-gateway'];
403 4260c32a Stephen Beaver
404 4b5f2ab3 Phil Davis
			if ($ipsecconnected[$ph1ent['ikeid']]) {
405
				continue;
406
			}
407 4260c32a Stephen Beaver
408 4b5f2ab3 Phil Davis
			print("<tr>\n");
409
			print("<td>\n");
410 4260c32a Stephen Beaver
411 4b5f2ab3 Phil Davis
			print(htmlspecialchars($ph1ent['descr']));
412
			print("</td>\n");
413
			print("<td>\n");
414
			list ($myid_type, $myid_data) = ipsec_find_id($ph1ent, "local");
415 4260c32a Stephen Beaver
416 4b5f2ab3 Phil Davis
			if (empty($myid_data)) {
417
				print(gettext("Unknown"));
418
			} else {
419
				print(htmlspecialchars($myid_data));
420
			}
421 4260c32a Stephen Beaver
422 4b5f2ab3 Phil Davis
			print("</td>\n");
423
			print("<td>\n");
424
			$ph1src = ipsec_get_phase1_src($ph1ent);
425 4260c32a Stephen Beaver
426 4b5f2ab3 Phil Davis
			if (empty($ph1src)) {
427
				print(gettext("Unknown"));
428
			} else {
429
				print(htmlspecialchars($ph1src));
430
			}
431 4260c32a Stephen Beaver
432 4b5f2ab3 Phil Davis
			print("</td>\n");
433
			print("<td>\n");
434 0da0d43e Phil Davis
435 4b5f2ab3 Phil Davis
			list ($peerid_type, $peerid_data) = ipsec_find_id($ph1ent, "peer", $rgmap);
436 3795cc0a sbeaver
437 4b5f2ab3 Phil Davis
			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 4b5f2ab3 Phil Davis
			if (empty($ph1src)) {
447
				print(gettext("Unknown"));
448
			} else {
449
				print(htmlspecialchars($ph1src));
450
			}
451 0da0d43e Phil Davis
452 4260c32a 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 4b5f2ab3 Phil Davis
			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 64d53c69 Steve Beaver
				print('<a href="status_ipsec.php?act=connect&amp;ikeid=' . $ph1ent['ikeid'] . '" class="btn btn-xs btn-success" usepost>');
475 4b5f2ab3 Phil Davis
				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 4260c32a Stephen Beaver
		}
483 97242546 Matt Smith
	}
484
485 4260c32a Stephen Beaver
	unset($ipsecconnected, $phase1, $rgmap);
486 86b2861c Matt Smith
}
487 3795cc0a sbeaver
488 4260c32a Stephen Beaver
$pgtitle = array(gettext("Status"), gettext("IPsec"), gettext("Overview"));
489 edcd7535 Phil Davis
$pglinks = array("", "@self", "@self");
490 4260c32a Stephen Beaver
$shortcut_section = "ipsec";
491 0da0d43e Phil Davis
492 4260c32a Stephen Beaver
include("head.inc");
493 0da0d43e Phil Davis
494 4260c32a Stephen Beaver
$tab_array = array();
495
$tab_array[] = array(gettext("Overview"), true, "status_ipsec.php");
496
$tab_array[] = array(gettext("Leases"), false, "status_ipsec_leases.php");
497
$tab_array[] = array(gettext("SADs"), false, "status_ipsec_sad.php");
498
$tab_array[] = array(gettext("SPDs"), false, "status_ipsec_spd.php");
499
display_top_tabs($tab_array);
500 3795cc0a sbeaver
?>
501 0da0d43e Phil Davis
502 4260c32a Stephen Beaver
<div class="panel panel-default">
503
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("IPsec Status");?></h2></div>
504
	<div class="panel-body table-responsive">
505
		<table class="table table-striped table-condensed table-hover sortable-theme-bootstrap" data-sortable>
506
			<thead>
507
				<tr>
508
					<th><?=gettext("Description")?></th>
509
					<th><?=gettext("Local ID")?></th>
510
					<th><?=gettext("Local IP")?></th>
511
					<th><?=gettext("Remote ID")?></th>
512
					<th><?=gettext("Remote IP")?></th>
513
					<th><?=gettext("Role")?></th>
514
					<th><?=gettext("Reauth")?></th>
515
					<th><?=gettext("Algo")?></th>
516
					<th><?=gettext("Status")?></th>
517
					<th></th>
518
				</tr>
519
			</thead>
520
			<tbody id="ipsec-body">
521
				<tr>
522 fc48da17 NOYB
					<td colspan="10">
523 499adf73 Phil Davis
						<?=print_info_box(gettext("Collecting IPsec status information."), "warning", "")?>
524 3795cc0a sbeaver
					</td>
525
				</tr>
526
			</tbody>
527 c7fbdd6c Ermal
		</table>
528
	</div>
529 3795cc0a sbeaver
</div>
530
531
<?php
532
unset($status);
533 4260c32a Stephen Beaver
534 d2c1089f Phil Davis
if (ipsec_enabled()) {
535 4260c32a Stephen Beaver
	print('<div class="infoblock">');
536 d2c1089f Phil Davis
} else {
537 4260c32a Stephen Beaver
	print('<div class="infoblock blockopen">');
538 d2c1089f Phil Davis
}
539 4260c32a Stephen Beaver
540 530c7ccf NOYB
print_info_box(sprintf(gettext('IPsec can be configured %1$shere%2$s.'), '<a href="vpn_ipsec.php">', '</a>'), 'info', false);
541 d2c1089f Phil Davis
?>
542
</div>
543 4260c32a Stephen Beaver
544
<script type="text/javascript">
545
//<![CDATA[
546
547
events.push(function() {
548 067551a4 Stephen Beaver
	ajax_lock = false;		// Mutex so we don't make a call until the previous call is finished
549
	sa_open = new Array();	// Array in which to keep the child SA show/hide state
550 29c1ecb8 Stephen Jones
	tryCount = 3;
551 4260c32a Stephen Beaver
	// Fetch the tbody contents from the server
552
	function update_table() {
553
		if (ajax_lock) {
554
			return;
555
		}
556
557
		ajax_lock = true;
558
559
		ajaxRequest = $.ajax(
560
			{
561
				url: "/status_ipsec.php",
562
				type: "post",
563
				data: {
564
					ajax: 	"ajax"
565 1144e24c Steve Beaver
				},
566
				error: function(xhr, textStatus, errorThrown){
567
					//alert("error.... retrying");
568 29c1ecb8 Stephen Jones
					if (tryCount > 0){
569
						tryCount --;
570 1144e24c Steve Beaver
						ajax_lock = false;
571
						update_table();
572
					}
573
					return;
574 4260c32a Stephen Beaver
				}
575
			}
576
		);
577
578
		// Deal with the results of the above ajax call
579
		ajaxRequest.done(function (response, textStatus, jqXHR) {
580 29c1ecb8 Stephen Jones
			if(textStatus === "success"){
581
				tryCount =3;
582
			}
583 fc48da17 NOYB
			if (!response) {
584 2807660f Stephen Jones
				response = '<tr><td colspan="10"><?=print_info_box(addslashes(gettext("No IPsec status information available.")), "warning", "")?></td></tr>';
585 fc48da17 NOYB
			}
586
587 4260c32a Stephen Beaver
			$('#ipsec-body').html(response);
588
			ajax_lock = false;
589
590 067551a4 Stephen Beaver
			// Update "Show child SA" handlers
591
			$('[id^=btnchildsa-]').click(function () {
592
				show_childsa($(this).prop("id").replace( /^\D+/g, ''));
593
			});
594
595
			// Check the sa_open array for child SAs that have been opened
596 4260c32a Stephen Beaver
			$('[id^=childsa-con]').each(function(idx) {
597 067551a4 Stephen Beaver
				sa_idx = $(this).prop("id").replace( /^\D+/g, '');
598 4260c32a Stephen Beaver
599
				if (sa_open[sa_idx]) {
600 067551a4 Stephen Beaver
					show_childsa(sa_idx);
601 4260c32a Stephen Beaver
				}
602
			});
603
604 64d53c69 Steve Beaver
			// re-attached the GET to POST handler
605
			interceptGET();
606
607 4260c32a Stephen Beaver
			// and do it again
608
			setTimeout(update_table, 5000);
609
		});
610
	}
611
612 067551a4 Stephen Beaver
	function show_childsa(said) {
613
		sa_open[said] = true;
614
		$('#childsa-con' + said).show();
615
		$('#btnchildsa-con' + said).hide();
616
	}
617
618 4260c32a Stephen Beaver
	// Populate the tbody on page load
619
	update_table();
620
});
621
//]]>
622
</script>
623
624 d2c1089f Phil Davis
<?php
625 3795cc0a sbeaver
include("foot.inc"); ?>