Skip to content
Snippets Groups Projects
Commit 3a669678 authored by Andreas Åkre Solberg's avatar Andreas Åkre Solberg
Browse files

added counters on ldapstatus page, only loading 20 seconds for not timeout

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1227 44740490-163a-0410-bde0-09ae8108e29a
parent 01d85e26
No related branches found
No related tags found
No related merge requests found
<?php <?php
$this->data['header'] = 'LDAP status page'; $this->data['header'] = 'LDAP status page';
$this->data['head'] = '<style>
table.statustable td {
border-bottom: 1px solid #eee;
}
</style>';
$this->includeAtTemplateBase('includes/header.php'); $this->includeAtTemplateBase('includes/header.php');
?> ?>
...@@ -18,6 +24,7 @@ $this->includeAtTemplateBase('includes/header.php'); ...@@ -18,6 +24,7 @@ $this->includeAtTemplateBase('includes/header.php');
<th>test bind()</th> <th>test bind()</th>
<th>attributes</th> <th>attributes</th>
<th>Meta</th> <th>Meta</th>
<th>Time</th>
</tr> </tr>
<?php <?php
...@@ -70,8 +77,39 @@ foreach($this->data['sortedOrgIndex'] as $orgkey) { ...@@ -70,8 +77,39 @@ foreach($this->data['sortedOrgIndex'] as $orgkey) {
showRes('ldapBindTestUser', $res, $this); showRes('ldapBindTestUser', $res, $this);
showRes('ldapGetAttributesTestUser', $res, $this); showRes('ldapGetAttributesTestUser', $res, $this);
showRes('configMeta', $res, $this); showRes('configMeta', $res, $this);
echo('<td style="text-align: right">' . ceil($res['time']*1000) . ' ms</td>');
echo('</tr>'); echo('</tr>');
} }
?> ?>
</table> </table>
<?php
echo('<p>Loaded ' . $this->data['completeNo'] . ' of ' . $this->data['completeOf'] . ' organizations</p>');
$sum = $this->data['lightCounter'][0] + $this->data['lightCounter'][1] + $this->data['lightCounter'][2];
if ($sum > 0) {
echo('<table class="statustable" style="border: 1px solid #ccc; width: 400px">');
echo('<tr><th>Type</th><th>Counter</th><th>Percentage</th></tr>');
echo('<tr><td><img src="/' . $this->data['baseurlpath'] . 'resources/icons/accept.png" /></td><td>' . $this->data['lightCounter'][0] . '</td><td>' .
number_format(100 * $this->data['lightCounter'][0] / $sum, 1) . ' %</td></tr>');
echo('<tr><td><img src="/' . $this->data['baseurlpath'] . 'resources/icons/delete.png" /></td><td>' . $this->data['lightCounter'][2] . '</td><td>' .
number_format(100 * $this->data['lightCounter'][2] / $sum, 1) . ' %</td></tr>');
echo('<tr><td><span style="color: #b4b4b4; font-size: x-small">NA</span></td><td>' . $this->data['lightCounter'][1] . '</td><td>' .
number_format(100 * $this->data['lightCounter'][1] / $sum, 1) . ' %</td></tr>');
echo('<tr><th>Sum</th><th>' . $sum . '</th><th>100 %</th></tr>');
echo('</table>');
}
if ($this->data['completeOf'] > $this->data['completeNo']) {
echo('<p>[ <a href="?reload=1">load more entries</a> | <a href="?reset=1">reset all entries</a> ]');
} else {
echo('<p>[ <a href="?reset=1">reset all entries</a> ]');
}
?>
<?php $this->includeAtTemplateBase('includes/footer.php'); ?> <?php $this->includeAtTemplateBase('includes/footer.php'); ?>
...@@ -23,6 +23,7 @@ $orgs = $ldapconfig->getValue('orgldapconfig'); ...@@ -23,6 +23,7 @@ $orgs = $ldapconfig->getValue('orgldapconfig');
#echo '<pre>'; print_r($orgs); exit; #echo '<pre>'; print_r($orgs); exit;
function phpping($host, $port) { function phpping($host, $port) {
SimpleSAML_Logger::debug('ldapstatus phpping(): ping [' . $host . ':' . $port . ']' ); SimpleSAML_Logger::debug('ldapstatus phpping(): ping [' . $host . ':' . $port . ']' );
...@@ -37,13 +38,20 @@ function phpping($host, $port) { ...@@ -37,13 +38,20 @@ function phpping($host, $port) {
} }
} }
function is_in_array($needles, $haystack) {
$needles = SimpleSAML_Utilities::arrayize($needles);
foreach($needles AS $needle) {
if (array_key_exists($needle, $haystack) && !empty($haystack[$needle])) return TRUE;
}
return FALSE;
}
function checkConfig($conf, $req) { function checkConfig($conf, $req) {
$err = array(); $err = array();
foreach($req AS $r) { foreach($req AS $r) {
if (!array_key_exists($r, $conf)) {
$err[] = $r; if (!is_in_array($r, $conf)) {
} elseif (empty($conf[$r]) && $conf[$r] !== FALSE) { $err[] = 'missing or empty: ' . join(', ', SimpleSAML_Utilities::arrayize($r));
$err[] = 'empty:' . $r;
} }
} }
if (count($err) > 0) { if (count($err) > 0) {
...@@ -52,18 +60,54 @@ function checkConfig($conf, $req) { ...@@ -52,18 +60,54 @@ function checkConfig($conf, $req) {
return array(TRUE, NULL); return array(TRUE, NULL);
} }
$results = array(); $results = NULL;
if (array_key_exists('reset', $_GET) && $_GET['reset'] === '1') {
$results = array();
} else {
if (array_key_exists('_ldapstatus_results', $_SESSION)) {
$results = $_SESSION['_ldapstatus_results'];
} else {
$results = array();
}
}
#echo('<pre>'); print_r($results); exit;
$start = microtime(TRUE);
$previous = microtime(TRUE);
$maxtime = $ldapStatusConfig->getValue('maxExecutionTime', 15);
foreach ($orgs AS $orgkey => $orgconfig) { foreach ($orgs AS $orgkey => $orgconfig) {
$previous = microtime(TRUE);
if ((microtime(TRUE) - $start) > $maxtime) {
SimpleSAML_Logger::debug('ldapstatus: Completing execution after maxtime [' .(microtime(TRUE) - $start) . ' of maxtime ' . $maxtime . ']');
break;
}
if (array_key_exists($orgkey, $_SESSION['_ldapstatus_results'])) {
SimpleSAML_Logger::debug('ldapstatus: Skipping org already tested [' .$orgkey. ']');
continue;
} else {
SimpleSAML_Logger::debug('ldapstatus: Not Skipping org: [' .$orgkey. ']');
}
SimpleSAML_Logger::debug('ldapstatus: Executing test on [' .$orgkey . ']');
$results[$orgkey] = array(); $results[$orgkey] = array();
$results[$orgkey]['config'] = checkConfig($orgconfig, array('description', 'searchbase', 'hostname')); $results[$orgkey]['config'] = checkConfig($orgconfig, array('description', 'searchbase', 'hostname'));
$results[$orgkey]['configMeta'] = checkConfig($orgconfig, array('enable_tls', 'contactMail', 'contactURL')); $results[$orgkey]['configMeta'] = checkConfig($orgconfig, array(array('contactMail', 'contactURL')));
$results[$orgkey]['configTest'] = checkConfig($orgconfig, array('testUser', 'testPassword')); $results[$orgkey]['configTest'] = checkConfig($orgconfig, array('testUser', 'testPassword'));
if (!$results[$orgkey]['config'][0]) continue; if (!$results[$orgkey]['config'][0]) {
$results[$orgkey]['time'] = microtime(TRUE) - $previous;
continue;
}
$urldef = explode(' ', $orgconfig['hostname']); $urldef = explode(' ', $orgconfig['hostname']);
$url = parse_url($urldef[0]); $url = parse_url($urldef[0]);
...@@ -73,20 +117,13 @@ foreach ($orgs AS $orgkey => $orgconfig) { ...@@ -73,20 +117,13 @@ foreach ($orgs AS $orgkey => $orgconfig) {
SimpleSAML_Logger::debug('ldapstatus Url parse [' . $orgconfig['hostname'] . '] => [' . $url['host'] . ']:[' . $port . ']' ); SimpleSAML_Logger::debug('ldapstatus Url parse [' . $orgconfig['hostname'] . '] => [' . $url['host'] . ']:[' . $port . ']' );
// $pingreturn = NULL;
// $pingoutput = NULL;
// exec($pingcommand . ' ' . escapeshellcmd($url['host']), $pingoutput, $pingreturn);
// if ($pingreturn == '0') {
// $results[$orgkey]['ping'] = array(TRUE,join("\r\n", $pingoutput));
// } else {
// $results[$orgkey]['ping'] = array(FALSE,join("\r\n", $pingoutput));
// continue;
// }
$results[$orgkey]['ping'] = phpping($url['host'], $port); $results[$orgkey]['ping'] = phpping($url['host'], $port);
if (!$results[$orgkey]['ping'][0]) continue; if (!$results[$orgkey]['ping'][0]) {
$results[$orgkey]['time'] = microtime(TRUE) - $previous;
continue;
}
// LDAP Connect // LDAP Connect
try { try {
...@@ -94,6 +131,7 @@ foreach ($orgs AS $orgkey => $orgconfig) { ...@@ -94,6 +131,7 @@ foreach ($orgs AS $orgkey => $orgconfig) {
$results[$orgkey]['connect'] = array(TRUE,NULL); $results[$orgkey]['connect'] = array(TRUE,NULL);
} catch (Exception $e) { } catch (Exception $e) {
$results[$orgkey]['connect'] = array(FALSE,$e->getMessage()); $results[$orgkey]['connect'] = array(FALSE,$e->getMessage());
$results[$orgkey]['time'] = microtime(TRUE) - $previous;
continue; continue;
} }
...@@ -108,6 +146,7 @@ foreach ($orgs AS $orgkey => $orgconfig) { ...@@ -108,6 +146,7 @@ foreach ($orgs AS $orgkey => $orgconfig) {
} }
} catch (Exception $e) { } catch (Exception $e) {
$results[$orgkey]['adminBind'] = array(FALSE,$e->getMessage()); $results[$orgkey]['adminBind'] = array(FALSE,$e->getMessage());
$results[$orgkey]['time'] = microtime(TRUE) - $previous;
continue; continue;
} }
} }
...@@ -120,6 +159,7 @@ foreach ($orgs AS $orgkey => $orgconfig) { ...@@ -120,6 +159,7 @@ foreach ($orgs AS $orgkey => $orgconfig) {
$results[$orgkey]['ldapSearchBogus'] = array(TRUE,NULL); $results[$orgkey]['ldapSearchBogus'] = array(TRUE,NULL);
} catch (Exception $e) { } catch (Exception $e) {
$results[$orgkey]['ldapSearchBogus'] = array(FALSE,$e->getMessage()); $results[$orgkey]['ldapSearchBogus'] = array(FALSE,$e->getMessage());
$results[$orgkey]['time'] = microtime(TRUE) - $previous;
continue; continue;
} }
...@@ -133,6 +173,7 @@ foreach ($orgs AS $orgkey => $orgconfig) { ...@@ -133,6 +173,7 @@ foreach ($orgs AS $orgkey => $orgconfig) {
$results[$orgkey]['ldapSearchTestUser'] = array(TRUE,NULL); $results[$orgkey]['ldapSearchTestUser'] = array(TRUE,NULL);
} catch (Exception $e) { } catch (Exception $e) {
$results[$orgkey]['ldapSearchTestUser'] = array(FALSE,$e->getMessage()); $results[$orgkey]['ldapSearchTestUser'] = array(FALSE,$e->getMessage());
$results[$orgkey]['time'] = microtime(TRUE) - $previous;
continue; continue;
} }
...@@ -141,6 +182,7 @@ foreach ($orgs AS $orgkey => $orgconfig) { ...@@ -141,6 +182,7 @@ foreach ($orgs AS $orgkey => $orgconfig) {
} else { } else {
$results[$orgkey]['ldapBindTestUser'] = array(FALSE,NULL); $results[$orgkey]['ldapBindTestUser'] = array(FALSE,NULL);
$results[$orgkey]['time'] = microtime(TRUE) - $previous;
continue; continue;
} }
...@@ -151,22 +193,39 @@ foreach ($orgs AS $orgkey => $orgconfig) { ...@@ -151,22 +193,39 @@ foreach ($orgs AS $orgkey => $orgconfig) {
$results[$orgkey]['ldapGetAttributesTestUser'] = array(FALSE,$e->getMessage()); $results[$orgkey]['ldapGetAttributesTestUser'] = array(FALSE,$e->getMessage());
} }
} }
$results[$orgkey]['time'] = microtime(TRUE) - $previous;
} }
$_SESSION['_ldapstatus_results'] = $results;
#echo '<pre>'; print_r($results); exit; #echo '<pre>'; print_r($results); exit;
$lightCounter = array(0,0,0);
function resultCode($res) { function resultCode($res) {
global $lightCounter;
$code = ''; $code = '';
$columns = array('config', 'ping', 'adminBind', 'ldapSearchBogus', 'configTest', 'ldapSearchTestUser', 'ldapBindTestUser', 'ldapGetAttributesTestUser', 'configMeta'); $columns = array('config', 'ping', 'adminBind', 'ldapSearchBogus', 'configTest', 'ldapSearchTestUser', 'ldapBindTestUser', 'ldapGetAttributesTestUser', 'configMeta');
foreach ($columns AS $c) { foreach ($columns AS $c) {
if (array_key_exists($c, $res)) { if (array_key_exists($c, $res)) {
$code .= ($res[$c][0] ? '0' : '2'); if ($res[$c][0]) {
$code .= '0';
$lightCounter[0]++;
} else {
$code .= '2';
$lightCounter[2]++;
}
} else { } else {
$code .= '1'; $code .= '1';
$lightCounter[1]++;
} }
} }
return $code; return $code;
} }
$ressortable = array(); $ressortable = array();
...@@ -178,8 +237,12 @@ asort($ressortable); ...@@ -178,8 +237,12 @@ asort($ressortable);
$t = new SimpleSAML_XHTML_Template($config, 'ldapstatus:ldapstatus.php'); $t = new SimpleSAML_XHTML_Template($config, 'ldapstatus:ldapstatus.php');
$t->data['completeNo'] = count($results);
$t->data['completeOf'] = count($orgs);
$t->data['results'] = $results; $t->data['results'] = $results;
$t->data['orgconfig'] = $orgs; $t->data['orgconfig'] = $orgs;
$t->data['lightCounter'] = $lightCounter;
$t->data['sortedOrgIndex'] = array_keys($ressortable); $t->data['sortedOrgIndex'] = array_keys($ressortable);
$t->show(); $t->show();
exit; exit;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment