Revision 4b5f2ab3
Added by Phil Davis about 9 years ago
src/usr/local/www/status_ipsec.php | ||
---|---|---|
69 | 69 |
|
70 | 70 |
global $g; |
71 | 71 |
|
72 |
if (!is_array($config['ipsec']['phase1'])) { |
|
73 |
$config['ipsec']['phase1'] = array(); |
|
74 |
} |
|
75 |
|
|
72 | 76 |
// If this is just an AJAX call to update the table body, just generate the body and quit |
73 | 77 |
if ($_REQUEST['ajax']) { |
74 | 78 |
print_ipsec_body(); |
... | ... | |
108 | 112 |
} |
109 | 113 |
} |
110 | 114 |
|
111 |
if (!is_array($config['ipsec']['phase1'])) { |
|
112 |
$config['ipsec']['phase1'] = array(); |
|
113 |
} |
|
114 |
|
|
115 | 115 |
// Table body is composed here so that it can be more easily updated via AJAX |
116 | 116 |
function print_ipsec_body() { |
117 | 117 |
global $config; |
... | ... | |
391 | 391 |
} |
392 | 392 |
|
393 | 393 |
$rgmap = array(); |
394 |
foreach ($a_phase1 as $ph1ent) { |
|
395 |
if (isset($ph1ent['disabled'])) { |
|
396 |
continue; |
|
397 |
} |
|
398 |
|
|
399 |
$rgmap[$ph1ent['remote-gateway']] = $ph1ent['remote-gateway']; |
|
400 |
|
|
401 |
if ($ipsecconnected[$ph1ent['ikeid']]) { |
|
402 |
continue; |
|
403 |
} |
|
394 |
if (is_array($a_phase1)) { |
|
395 |
foreach ($a_phase1 as $ph1ent) { |
|
396 |
if (isset($ph1ent['disabled'])) { |
|
397 |
continue; |
|
398 |
} |
|
404 | 399 |
|
405 |
print("<tr>\n"); |
|
406 |
print("<td>\n"); |
|
400 |
$rgmap[$ph1ent['remote-gateway']] = $ph1ent['remote-gateway']; |
|
407 | 401 |
|
408 |
print(htmlspecialchars($ph1ent['descr'])); |
|
409 |
print("</td>\n"); |
|
410 |
print("<td>\n"); |
|
411 |
list ($myid_type, $myid_data) = ipsec_find_id($ph1ent, "local"); |
|
402 |
if ($ipsecconnected[$ph1ent['ikeid']]) { |
|
403 |
continue; |
|
404 |
} |
|
412 | 405 |
|
413 |
if (empty($myid_data)) { |
|
414 |
print(gettext("Unknown")); |
|
415 |
} else { |
|
416 |
print(htmlspecialchars($myid_data)); |
|
417 |
} |
|
406 |
print("<tr>\n"); |
|
407 |
print("<td>\n"); |
|
418 | 408 |
|
419 |
print("</td>\n"); |
|
420 |
print("<td>\n"); |
|
421 |
$ph1src = ipsec_get_phase1_src($ph1ent); |
|
409 |
print(htmlspecialchars($ph1ent['descr'])); |
|
410 |
print("</td>\n"); |
|
411 |
print("<td>\n"); |
|
412 |
list ($myid_type, $myid_data) = ipsec_find_id($ph1ent, "local"); |
|
422 | 413 |
|
423 |
if (empty($ph1src)) {
|
|
424 |
print(gettext("Unknown")); |
|
425 |
} else { |
|
426 |
print(htmlspecialchars($ph1src));
|
|
427 |
} |
|
414 |
if (empty($myid_data)) {
|
|
415 |
print(gettext("Unknown"));
|
|
416 |
} else {
|
|
417 |
print(htmlspecialchars($myid_data));
|
|
418 |
}
|
|
428 | 419 |
|
429 |
print("</td>\n"); |
|
430 |
print("<td>\n"); |
|
420 |
print("</td>\n"); |
|
421 |
print("<td>\n"); |
|
422 |
$ph1src = ipsec_get_phase1_src($ph1ent); |
|
431 | 423 |
|
432 |
list ($peerid_type, $peerid_data) = ipsec_find_id($ph1ent, "peer", $rgmap); |
|
424 |
if (empty($ph1src)) { |
|
425 |
print(gettext("Unknown")); |
|
426 |
} else { |
|
427 |
print(htmlspecialchars($ph1src)); |
|
428 |
} |
|
433 | 429 |
|
434 |
if (empty($peerid_data)) { |
|
435 |
print(gettext("Unknown")); |
|
436 |
} else { |
|
437 |
print(htmlspecialchars($peerid_data)); |
|
438 |
} |
|
439 |
print(" </td>\n"); |
|
440 |
print(" <td>\n"); |
|
441 |
$ph1src = ipsec_get_phase1_dst($ph1ent); |
|
430 |
print("</td>\n"); |
|
431 |
print("<td>\n"); |
|
442 | 432 |
|
443 |
if (empty($ph1src)) { |
|
444 |
print(gettext("Unknown")); |
|
445 |
} else { |
|
446 |
print(htmlspecialchars($ph1src)); |
|
447 |
} |
|
433 |
list ($peerid_type, $peerid_data) = ipsec_find_id($ph1ent, "peer", $rgmap); |
|
448 | 434 |
|
449 |
print("</td>\n"); |
|
450 |
print("<td>\n"); |
|
451 |
print("</td>\n"); |
|
452 |
print("<td>\n"); |
|
453 |
print("</td>\n"); |
|
454 |
print("<td>\n"); |
|
455 |
print("</td>\n"); |
|
435 |
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); |
|
456 | 443 |
|
457 |
if (isset($ph1ent['mobile'])) { |
|
444 |
if (empty($ph1src)) { |
|
445 |
print(gettext("Unknown")); |
|
446 |
} else { |
|
447 |
print(htmlspecialchars($ph1src)); |
|
448 |
} |
|
458 | 449 |
|
459 |
print("<td>\n"); |
|
460 |
print(gettext("Awaiting connections")); |
|
461 | 450 |
print("</td>\n"); |
462 | 451 |
print("<td>\n"); |
463 | 452 |
print("</td>\n"); |
464 |
print("</td>\n"); |
|
465 |
} else { |
|
466 |
|
|
467 | 453 |
print("<td>\n"); |
468 |
print(gettext("Disconnected")); |
|
469 | 454 |
print("</td>\n"); |
470 | 455 |
print("<td>\n"); |
471 |
print('<a href="status_ipsec.php?act=connect&ikeid=' . $ph1ent['ikeid'] . '" class="btn btn-xs btn-success">'); |
|
472 |
print('<i class="fa fa-sign-in icon-embed-btn"></i>'); |
|
473 |
print(gettext("Connect VPN")); |
|
474 |
print("</a>\n"); |
|
475 | 456 |
print("</td>\n"); |
476 | 457 |
|
458 |
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 |
print('<a href="status_ipsec.php?act=connect&ikeid=' . $ph1ent['ikeid'] . '" class="btn btn-xs btn-success">'); |
|
473 |
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"); |
|
477 | 480 |
} |
478 |
print("</tr>\n"); |
|
479 | 481 |
} |
480 | 482 |
|
481 | 483 |
unset($ipsecconnected, $phase1, $rgmap); |
... | ... | |
539 | 541 |
<script type="text/javascript"> |
540 | 542 |
//<![CDATA[ |
541 | 543 |
|
542 |
// Array in which to keep hte SA show/hide state
|
|
544 |
// Array in which to keep the SA show/hide state
|
|
543 | 545 |
sa_open = new Array(); |
544 | 546 |
|
545 | 547 |
function show_childsa(id, buttonid) { |
Also available in: Unified diff
Prevent foreach crash if no IPsec
On a system with no IPsec defined, this would crash with:
[04-Apr-2016 21:33:24 Etc/UTC] PHP Stack trace:
[04-Apr-2016 21:33:24 Etc/UTC] PHP 1. {main}() /usr/local/www/status_ipsec.php:0
[04-Apr-2016 21:33:24 Etc/UTC] PHP 2. print_ipsec_body() /usr/local/www/status_ipsec.php:74
I did belts-and-braces here - moved the "if" up at line 72 and also added an if(is_array()) at line 394