Project

General

Profile

Download (17.7 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 4a762cf0 Steve Beaver
 * Copyright (c) 2004-2019 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 ea0dd417 jim-p
init_config_arr(array('ipsec', 'phase1'));
39 4b5f2ab3 Phil Davis
40 4260c32a Stephen Beaver
// If this is just an AJAX call to update the table body, just generate the body and quit
41
if ($_REQUEST['ajax']) {
42
	print_ipsec_body();
43
	exit;
44
}
45 a93e56c5 Matthew Grooms
46 64d53c69 Steve Beaver
if ($_POST['act'] == 'connect') {
47
	if (ctype_digit($_POST['ikeid'])) {
48
		$ph1ent = ipsec_get_phase1($_POST['ikeid']);
49 483c3b5b Ermal LUÇI
		if (!empty($ph1ent)) {
50 9d51fcde Chris Buechler
			if (empty($ph1ent['iketype']) || $ph1ent['iketype'] == 'ikev1' || isset($ph1ent['splitconn'])) {
51 64d53c69 Steve Beaver
				$ph2entries = ipsec_get_number_of_phase2($_POST['ikeid']);
52 483c3b5b Ermal LUÇI
				for ($i = 0; $i < $ph2entries; $i++) {
53 64d53c69 Steve Beaver
					$connid = escapeshellarg("con{$_POST['ikeid']}00{$i}");
54 c5d8cbe0 Chris Buechler
					mwexec_bg("/usr/local/sbin/ipsec down {$connid}");
55 b866103e Chris Buechler
					mwexec_bg("/usr/local/sbin/ipsec up {$connid}");
56 483c3b5b Ermal LUÇI
				}
57
			} else {
58 62caa87a jim-p
				mwexec_bg("/usr/local/sbin/ipsec down con" . escapeshellarg($_POST['ikeid'] . '000'));
59
				mwexec_bg("/usr/local/sbin/ipsec up con" . escapeshellarg($_POST['ikeid'] . '000'));
60 483c3b5b Ermal LUÇI
			}
61
		}
62 6e8b0ec3 jim-p
	}
63 64d53c69 Steve Beaver
} else if ($_POST['act'] == 'ikedisconnect') {
64 130f3c92 Stephen Jones
65 3c5f4441 Stephen Jones
	if (!empty($_POST['ikesaid']) && ctype_digit($_POST['ikesaid'])) {
66
		mwexec_bg("/usr/local/sbin/ipsec down " ."'" . escapeshellarg($_POST['ikeid']) . "[" . escapeshellarg($_POST['ikesaid']) . "]" . "'");
67
	} else {
68
		mwexec_bg("/usr/local/sbin/ipsec down " . escapeshellarg($_POST['ikeid']));
69 614be051 bcyrill
	}
70 64d53c69 Steve Beaver
} else if ($_POST['act'] == 'childdisconnect') {
71 130f3c92 Stephen Jones
	//pull out number from id
72 64d53c69 Steve Beaver
		if (!empty($_POST['ikesaid']) && ctype_digit($_POST['ikesaid'])) {
73 3c5f4441 Stephen Jones
			mwexec_bg("/usr/local/sbin/ipsec down " . escapeshellarg($_POST['ikeid']) . "{" . escapeshellarg($_POST['ikesaid']) . "}");
74 5f601060 Phil Davis
		}
75 6e0b68bf jim-p
}
76
77 4260c32a Stephen Beaver
// Table body is composed here so that it can be more easily updated via AJAX
78
function print_ipsec_body() {
79
	global $config;
80
	$a_phase1 = &$config['ipsec']['phase1'];
81
	$status = ipsec_list_sa();
82
	$ipsecconnected = array();
83
	if (is_array($status)) {
84
		foreach ($status as $ikeid => $ikesa) {
85 130f3c92 Stephen Jones
			//check which array format
86
			if(isset($ikesa['con-id'])){
87
				$con_id = substr($ikesa['con-id'],3);
88
			}else{
89
				$con_id = filter_var($ikeid, FILTER_SANITIZE_NUMBER_INT);
90
			}
91 4260c32a Stephen Beaver
			if ($ikesa['version'] == 1) {
92
				$ph1idx = substr($con_id, 0, strrpos(substr($con_id, 0, -1), '00'));
93
				$ipsecconnected[$ph1idx] = $ph1idx;
94
			} else {
95 109a304e Graham Collinson
				if (!ipsec_ikeid_used($con_id)) {
96
					// probably a v2 with split connection then
97
					$ph1idx = substr($con_id, 0, strrpos(substr($con_id, 0, -1), '00'));
98
					$ipsecconnected[$ph1idx] = $ph1idx;
99
				} else {
100
					$ipsecconnected[$con_id] = $ph1idx = $con_id;
101
				}
102 4260c32a Stephen Beaver
			}
103 3795cc0a sbeaver
104 4260c32a Stephen Beaver
			print("<tr>\n");
105 3c5f4441 Stephen Jones
106
			print("<td>\n");
107
			print(htmlspecialchars($ikesa['con-id'])) . ":\n";
108
			print('#' . htmlspecialchars($ikesa['uniqueid']));
109
			print("</td>\n");
110
111 4260c32a Stephen Beaver
			print("<td>\n");
112 80392e01 Stephen Jones
			if (is_array($a_phase1) && htmlspecialchars(ipsec_get_descr($ph1idx)) == "") {
113 29c1ecb8 Stephen Jones
				foreach ($a_phase1 as $ph1) {
114 80392e01 Stephen Jones
					if($con_id == $ph1['ikeid'] && isset($ph1['mobile']) ){
115
						print(htmlspecialchars($ph1['descr']));
116 29c1ecb8 Stephen Jones
						break;
117
					}
118
				}
119
			}
120 4260c32a Stephen Beaver
			print(htmlspecialchars(ipsec_get_descr($ph1idx)));
121
			print("</td>\n");
122 3c5f4441 Stephen Jones
123 4260c32a Stephen Beaver
			print("<td>\n");
124 0da0d43e Phil Davis
125 4260c32a Stephen Beaver
			if (!empty($ikesa['local-id'])) {
126
				if ($ikesa['local-id'] == '%any') {
127
					print(gettext('Any identifier'));
128
				} else {
129
					print(htmlspecialchars($ikesa['local-id']));
130
				}
131 5f601060 Phil Davis
			} else {
132 4260c32a Stephen Beaver
				print(gettext("Unknown"));
133 5f601060 Phil Davis
			}
134 86b2861c Matt Smith
135 4260c32a Stephen Beaver
			print("</td>\n");
136
			print("<td>\n");
137
138
			if (!empty($ikesa['local-host'])) {
139
				print(htmlspecialchars($ikesa['local-host']));
140 86b2861c Matt Smith
			} else {
141 4260c32a Stephen Beaver
				print(gettext("Unknown"));
142 86b2861c Matt Smith
			}
143 4260c32a Stephen Beaver
144
			/*
145
			 * XXX: local-nat-t was defined by pfSense
146
			 * When strongswan team accepted the change, they changed it to
147
			 * nat-local. Keep both for a while and remove local-nat-t in
148
			 * the future
149
			 */
150
			if (isset($ikesa['local-nat-t']) || isset($ikesa['nat-local'])) {
151 e96b20f6 Jose Luis Duran
				print(" NAT-T");
152 4260c32a Stephen Beaver
			}
153
154
			print("</td>\n");
155
			print("<td>\n");
156
157
			$identity = "";
158
			if (!empty($ikesa['remote-id'])) {
159
				if ($ikesa['remote-id'] == '%any') {
160
					$identity = htmlspecialchars(gettext('Any identifier'));
161
				} else {
162
					$identity = htmlspecialchars($ikesa['remote-id']);
163
				}
164
			}
165
166
			if (!empty($ikesa['remote-xauth-id'])) {
167
				echo htmlspecialchars($ikesa['remote-xauth-id']);
168
				echo "<br/>{$identity}";
169
			} elseif (!empty($ikesa['remote-eap-id'])) {
170
				echo htmlspecialchars($ikesa['remote-eap-id']);
171
				echo "<br/>{$identity}";
172
			} else {
173
				if (empty($identity)) {
174
					print(gettext("Unknown"));
175
				} else {
176
					print($identity);
177
				}
178
			}
179
180
			print("</td>\n");
181
			print("<td>\n");
182
183
			if (!empty($ikesa['remote-host'])) {
184
				print(htmlspecialchars($ikesa['remote-host']));
185
			} else {
186 3795cc0a sbeaver
				print(gettext("Unknown"));
187 4260c32a Stephen Beaver
			}
188
			/*
189
			 * XXX: remote-nat-t was defined by pfSense
190
			 * When strongswan team accepted the change, they changed it to
191
			 * nat-remote. Keep both for a while and remove remote-nat-t in
192
			 * the future
193
			 */
194
			if (isset($ikesa['remote-nat-t']) || isset($ikesa['nat-remote'])) {
195
				print(" NAT-T");
196
			}
197
198
			print("</td>\n");
199
			print("<td>\n");
200
			print("IKEv" . htmlspecialchars($ikesa['version']));
201
			print("<br/>\n");
202
203
			if ($ikesa['initiator'] == 'yes') {
204
				print("initiator");
205
			} else {
206
				print("responder");
207
			}
208
209
			print("</td>\n");
210
			print("<td>\n");
211 c57e936a stilez
			print(htmlspecialchars($ikesa['reauth-time']) . gettext(" seconds (") . convert_seconds_to_dhms($ikesa['reauth-time']) . ")");
212 4260c32a Stephen Beaver
			print("</td>\n");
213
			print("<td>\n");
214
			print(htmlspecialchars($ikesa['encr-alg']));
215
			print("<br/>");
216
			print(htmlspecialchars($ikesa['integ-alg']));
217
			print("<br/>");
218
			print(htmlspecialchars($ikesa['prf-alg']));
219
			print("<br/>\n");
220
			print(htmlspecialchars($ikesa['dh-group']));
221
			print("</td>\n");
222
			print("<td>\n");
223
224
			if ($ikesa['state'] == 'ESTABLISHED') {
225
				print('<span class="text-success">');
226
			} else {
227
				print('<span>');
228
			}
229
230
			print(ucfirst(htmlspecialchars($ikesa['state'])));
231 9e820b59 Phil Davis
232
			if ($ikesa['state'] == 'ESTABLISHED') {
233 7f0d6ccf Phil Davis
				print("<br/>");
234
				printf(gettext('%1$s seconds (%2$s) ago'), htmlspecialchars($ikesa['established']), convert_seconds_to_dhms($ikesa['established']));
235 9e820b59 Phil Davis
			}
236
237 3c5f4441 Stephen Jones
			print("</span><br /><br />");
238 4260c32a Stephen Beaver
239
			if ($ikesa['state'] != 'ESTABLISHED') {
240
241 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>');
242 9e820b59 Phil Davis
				print('<i class="fa fa-sign-in icon-embed-btn"></i>');
243
				print(gettext("Connect VPN"));
244
				print("</a>\n");
245 4260c32a Stephen Beaver
246 86b2861c Matt Smith
			} else {
247 4260c32a Stephen Beaver
248 3c5f4441 Stephen Jones
				print('<a href="status_ipsec.php?act=ikedisconnect&amp;ikeid=' . $ikesa['con-id']. '&amp;ikesaid=' .$ikesa['uniqueid'] . '"class="btn btn-xs btn-danger" data-toggle="tooltip" title="' . gettext("Disconnect VPN") . '" usepost>');
249 4260c32a Stephen Beaver
				print('<i class="fa fa-trash icon-embed-btn"></i>');
250
				print(gettext("Disconnect"));
251
				print("</a><br />\n");
252
253
			}
254
255
			print("</td>\n");
256
			print("</tr>\n");
257
			print("<tr>\n");
258
			print("<td colspan = 10>\n");
259
260
			if (is_array($ikesa['child-sas']) && (count($ikesa['child-sas']) > 0)) {
261 130f3c92 Stephen Jones
				$child_key = "";
262
				foreach ($ikesa['child-sas'] as $key => $val){
263
					$child_key = $key;
264
					break;
265
				}
266 4260c32a Stephen Beaver
267 067551a4 Stephen Beaver
				print('<div>');
268 130f3c92 Stephen Jones
				print('<a type="button" id="btnchildsa-'. $child_key .  '" class="btn btn-sm btn-info">');
269 4260c32a Stephen Beaver
				print('<i class="fa fa-plus-circle icon-embed-btn"></i>');
270
				print(gettext('Show child SA entries'));
271
				print("</a>\n");
272
				print("	</div>\n");
273
274 130f3c92 Stephen Jones
				print('<table class="table table-hover table-condensed" id="childsa-'.$child_key . '" style="display:none">');
275 4260c32a Stephen Beaver
				print("<thead>\n");
276
				print('<tr class="bg-info">');
277 3c5f4441 Stephen Jones
				print('<th>' . gettext("IPsec ID") . '</th>');
278
				print('<th>' . gettext("Local subnets") . '</th>');
279
				print('<th>' . gettext("Local SPI(s)") . '</th>');
280
				print('<th>' . gettext("Remote subnets") . '</th>');
281
				print('<th>' . gettext("Times") . '</th>');
282
				print('<th>' . gettext("Algo") . '</th>');
283
				print('<th>' . gettext("Stats") . '</th>');
284 4260c32a Stephen Beaver
				print('<th><!-- Buttons --></th>');
285
				print("</tr\n");
286
				print("</thead>\n");
287
				print("<tbody>\n");
288
289
				foreach ($ikesa['child-sas'] as $childid => $childsa) {
290
					print("<tr>");
291
					print("<td>\n");
292 3c5f4441 Stephen Jones
					print($childsa['name'] . ":<br />");
293
					print("#" . $childsa['uniqueid']);
294
					print("</td>\n");
295
					print("<td>\n");
296 4260c32a Stephen Beaver
297
					if (is_array($childsa['local-ts'])) {
298
						foreach ($childsa['local-ts'] as $lnets) {
299
							print(htmlspecialchars(ipsec_fixup_network($lnets)) . "<br />");
300
						}
301
					} else {
302
						print(gettext("Unknown"));
303
					}
304
305
					print("</td>\n");
306
					print("<td>\n");
307
308
					if (isset($childsa['spi-in'])) {
309
						print(gettext("Local: ") . htmlspecialchars($childsa['spi-in']));
310
					}
311
312
					if (isset($childsa['spi-out'])) {
313
						print('<br/>' . gettext('Remote: ') . htmlspecialchars($childsa['spi-out']));
314
					}
315
316
					print("</td>\n");
317
					print("<td>\n");
318
319
					if (is_array($childsa['remote-ts'])) {
320
						foreach ($childsa['remote-ts'] as $rnets) {
321
							print(htmlspecialchars(ipsec_fixup_network($rnets)) . '<br />');
322
						}
323
					} else {
324
						print(gettext("Unknown"));
325
					}
326
327
					print("</td>\n");
328
					print("<td>\n");
329
330 7f0d6ccf Phil Davis
					printf(gettext('Rekey: %1$s seconds (%2$s)'), htmlspecialchars($childsa['rekey-time']), convert_seconds_to_dhms($childsa['rekey-time']));
331
					print('<br/>');
332
					printf(gettext('Life: %1$s seconds (%2$s)'), htmlspecialchars($childsa['life-time']), convert_seconds_to_dhms($childsa['life-time']));
333
					print('<br/>');
334
					printf(gettext('Install: %1$s seconds (%2$s)'), htmlspecialchars($childsa['install-time']), convert_seconds_to_dhms($childsa['install-time']));
335 4260c32a Stephen Beaver
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 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>');
373 4260c32a Stephen Beaver
					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 9723b525 Stephen Beaver
				print("</tr>\n");
385 4260c32a Stephen Beaver
386 3795cc0a sbeaver
			}
387 4260c32a Stephen Beaver
388
			unset($con_id);
389 86b2861c Matt Smith
		}
390 4260c32a Stephen Beaver
391
	}
392
393
	$rgmap = array();
394 4b5f2ab3 Phil Davis
	if (is_array($a_phase1)) {
395
		foreach ($a_phase1 as $ph1ent) {
396
			if (isset($ph1ent['disabled'])) {
397
				continue;
398
			}
399 4260c32a Stephen Beaver
400 4b5f2ab3 Phil Davis
			$rgmap[$ph1ent['remote-gateway']] = $ph1ent['remote-gateway'];
401 4260c32a Stephen Beaver
402 4b5f2ab3 Phil Davis
			if ($ipsecconnected[$ph1ent['ikeid']]) {
403
				continue;
404
			}
405 4260c32a Stephen Beaver
406 4b5f2ab3 Phil Davis
			print("<tr>\n");
407 437263f2 Stephen Jones
			print("<td></td>\n");
408 360e7711 Stephen Jones
			print("<td>\n");
409 4b5f2ab3 Phil Davis
			print(htmlspecialchars($ph1ent['descr']));
410
			print("</td>\n");
411
			print("<td>\n");
412
			list ($myid_type, $myid_data) = ipsec_find_id($ph1ent, "local");
413 4260c32a Stephen Beaver
414 4b5f2ab3 Phil Davis
			if (empty($myid_data)) {
415
				print(gettext("Unknown"));
416
			} else {
417
				print(htmlspecialchars($myid_data));
418
			}
419 4260c32a Stephen Beaver
420 4b5f2ab3 Phil Davis
			print("</td>\n");
421
			print("<td>\n");
422
			$ph1src = ipsec_get_phase1_src($ph1ent);
423 4260c32a Stephen Beaver
424 4b5f2ab3 Phil Davis
			if (empty($ph1src)) {
425
				print(gettext("Unknown"));
426
			} else {
427
				print(htmlspecialchars($ph1src));
428
			}
429 4260c32a Stephen Beaver
430 4b5f2ab3 Phil Davis
			print("</td>\n");
431
			print("<td>\n");
432 0da0d43e Phil Davis
433 4b5f2ab3 Phil Davis
			list ($peerid_type, $peerid_data) = ipsec_find_id($ph1ent, "peer", $rgmap);
434 3795cc0a sbeaver
435 4b5f2ab3 Phil Davis
			if (empty($peerid_data)) {
436
				print(gettext("Unknown"));
437
			} else {
438
				print(htmlspecialchars($peerid_data));
439
			}
440
			print("			</td>\n");
441
			print("			<td>\n");
442
			$ph1src = ipsec_get_phase1_dst($ph1ent);
443 0da0d43e Phil Davis
444 4b5f2ab3 Phil Davis
			if (empty($ph1src)) {
445
				print(gettext("Unknown"));
446
			} else {
447
				print(htmlspecialchars($ph1src));
448
			}
449 0da0d43e Phil Davis
450 4260c32a Stephen Beaver
			print("</td>\n");
451
			print("<td>\n");
452
			print("</td>\n");
453
			print("<td>\n");
454
			print("</td>\n");
455
			print("<td>\n");
456
			print("</td>\n");
457 3795cc0a sbeaver
458 4b5f2ab3 Phil Davis
			if (isset($ph1ent['mobile'])) {
459
460
				print("<td>\n");
461
				print(gettext("Awaiting connections"));
462
				print("</td>\n");
463
				print("<td>\n");
464
				print("</td>\n");
465
				print("</td>\n");
466
			} else {
467
468
				print("<td>\n");
469
				print(gettext("Disconnected"));
470
				print("</td>\n");
471
				print("<td>\n");
472 64d53c69 Steve Beaver
				print('<a href="status_ipsec.php?act=connect&amp;ikeid=' . $ph1ent['ikeid'] . '" class="btn btn-xs btn-success" usepost>');
473 4b5f2ab3 Phil Davis
				print('<i class="fa fa-sign-in icon-embed-btn"></i>');
474
				print(gettext("Connect VPN"));
475
				print("</a>\n");
476
				print("</td>\n");
477
478
			}
479
			print("</tr>\n");
480 4260c32a Stephen Beaver
		}
481 97242546 Matt Smith
	}
482
483 4260c32a Stephen Beaver
	unset($ipsecconnected, $phase1, $rgmap);
484 86b2861c Matt Smith
}
485 3795cc0a sbeaver
486 4260c32a Stephen Beaver
$pgtitle = array(gettext("Status"), gettext("IPsec"), gettext("Overview"));
487 edcd7535 Phil Davis
$pglinks = array("", "@self", "@self");
488 4260c32a Stephen Beaver
$shortcut_section = "ipsec";
489 0da0d43e Phil Davis
490 4260c32a Stephen Beaver
include("head.inc");
491 0da0d43e Phil Davis
492 4260c32a Stephen Beaver
$tab_array = array();
493
$tab_array[] = array(gettext("Overview"), true, "status_ipsec.php");
494
$tab_array[] = array(gettext("Leases"), false, "status_ipsec_leases.php");
495
$tab_array[] = array(gettext("SADs"), false, "status_ipsec_sad.php");
496
$tab_array[] = array(gettext("SPDs"), false, "status_ipsec_spd.php");
497
display_top_tabs($tab_array);
498 3795cc0a sbeaver
?>
499 0da0d43e Phil Davis
500 4260c32a Stephen Beaver
<div class="panel panel-default">
501
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("IPsec Status");?></h2></div>
502
	<div class="panel-body table-responsive">
503
		<table class="table table-striped table-condensed table-hover sortable-theme-bootstrap" data-sortable>
504
			<thead>
505
				<tr>
506 3c5f4441 Stephen Jones
					<th><?=gettext("IPsec ID")?></th>
507 4260c32a Stephen Beaver
					<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 fc48da17 NOYB
					<td colspan="10">
522 499adf73 Phil Davis
						<?=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 4260c32a Stephen Beaver
533 d2c1089f Phil Davis
if (ipsec_enabled()) {
534 4260c32a Stephen Beaver
	print('<div class="infoblock">');
535 d2c1089f Phil Davis
} else {
536 4260c32a Stephen Beaver
	print('<div class="infoblock blockopen">');
537 d2c1089f Phil Davis
}
538 4260c32a Stephen Beaver
539 530c7ccf NOYB
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 4260c32a Stephen Beaver
543
<script type="text/javascript">
544
//<![CDATA[
545
546
events.push(function() {
547 067551a4 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 29c1ecb8 Stephen Jones
	tryCount = 3;
550 4260c32a Stephen Beaver
	// 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 1144e24c Steve Beaver
				},
565
				error: function(xhr, textStatus, errorThrown){
566
					//alert("error.... retrying");
567 29c1ecb8 Stephen Jones
					if (tryCount > 0){
568
						tryCount --;
569 1144e24c Steve Beaver
						ajax_lock = false;
570
						update_table();
571
					}
572
					return;
573 4260c32a Stephen Beaver
				}
574
			}
575
		);
576
577
		// Deal with the results of the above ajax call
578
		ajaxRequest.done(function (response, textStatus, jqXHR) {
579 29c1ecb8 Stephen Jones
			if(textStatus === "success"){
580
				tryCount =3;
581
			}
582 fc48da17 NOYB
			if (!response) {
583 2807660f Stephen Jones
				response = '<tr><td colspan="10"><?=print_info_box(addslashes(gettext("No IPsec status information available.")), "warning", "")?></td></tr>';
584 fc48da17 NOYB
			}
585
586 4260c32a Stephen Beaver
			$('#ipsec-body').html(response);
587
			ajax_lock = false;
588
589 067551a4 Stephen Beaver
			// Update "Show child SA" handlers
590
			$('[id^=btnchildsa-]').click(function () {
591 3c5f4441 Stephen Jones
				show_childsa($(this).prop("id").replace( 'btnchildsa-', ''));
592 067551a4 Stephen Beaver
			});
593
594
			// Check the sa_open array for child SAs that have been opened
595 3c5f4441 Stephen Jones
			$('[id^=childsa-]').each(function(idx) {
596
				sa_idx = $(this).prop("id").replace( 'childsa-', '');
597 4260c32a Stephen Beaver
598
				if (sa_open[sa_idx]) {
599 067551a4 Stephen Beaver
					show_childsa(sa_idx);
600 4260c32a Stephen Beaver
				}
601
			});
602
603 64d53c69 Steve Beaver
			// re-attached the GET to POST handler
604
			interceptGET();
605
606 4260c32a Stephen Beaver
			// and do it again
607
			setTimeout(update_table, 5000);
608
		});
609
	}
610
611 067551a4 Stephen Beaver
	function show_childsa(said) {
612
		sa_open[said] = true;
613 3c5f4441 Stephen Jones
		$('#childsa-' + said).show();
614 067551a4 Stephen Beaver
		$('#btnchildsa-con' + said).hide();
615
	}
616
617 4260c32a Stephen Beaver
	// Populate the tbody on page load
618
	update_table();
619
});
620
//]]>
621
</script>
622
623 d2c1089f Phil Davis
<?php
624 3795cc0a sbeaver
include("foot.inc"); ?>