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

LDAP status module implements Ping in php. several other improvements...

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1167 44740490-163a-0410-bde0-09ae8108e29a
parent bf4bf34a
No related branches found
No related tags found
No related merge requests found
...@@ -11,6 +11,7 @@ $this->includeAtTemplateBase('includes/header.php'); ...@@ -11,6 +11,7 @@ $this->includeAtTemplateBase('includes/header.php');
<table class="attributes" style="width: 100%; border: 1px solid #aaa"> <table class="attributes" style="width: 100%; border: 1px solid #aaa">
<tr> <tr>
<th>Name of institusion</th> <th>Name of institusion</th>
<!-- th>Identifier</th -->
<th>Conf</th> <th>Conf</th>
<th>Meta</th> <th>Meta</th>
<th>Ping</th> <th>Ping</th>
...@@ -44,15 +45,21 @@ function showRes($key, $res, $template) { ...@@ -44,15 +45,21 @@ function showRes($key, $res, $template) {
} }
$i = 0; $i = 0;
$classes = array('odd', 'even'); $classes = array('odd', 'even');
foreach($this->data['results'] as $orgkey => $res) {
# $this->data['results']
foreach($this->data['sortedOrgIndex'] as $orgkey) {
$res = $this->data['results'][$orgkey];
echo('<tr class="' . ($classes[($i++ % 2)]) . '">'); echo('<tr class="' . ($classes[($i++ % 2)]) . '">');
echo('<td>' . htmlspecialchars($this->getTranslation($this->data['orgconfig'][$orgkey]['description'])) . '</td>'); echo('<td>' . htmlspecialchars($this->getTranslation($this->data['orgconfig'][$orgkey]['description'])) . '</td>');
# echo('<td><tt>' . htmlspecialchars($orgkey) . '</tt></td>');
showRes('config', $res, $this); showRes('config', $res, $this);
showRes('configMeta', $res, $this); showRes('configMeta', $res, $this);
showRes('ping', $res, $this); showRes('ping', $res, $this);
showRes('adminUser', $res, $this); showRes('adminBind', $res, $this);
showRes('ldapSearchBogus', $res, $this); showRes('ldapSearchBogus', $res, $this);
showRes('ldapSearchTestUser', $res, $this); showRes('ldapSearchTestUser', $res, $this);
showRes('ldapBindTestUser', $res, $this); showRes('ldapBindTestUser', $res, $this);
......
...@@ -21,10 +21,29 @@ $orgs = $ldapconfig->getValue('orgldapconfig'); ...@@ -21,10 +21,29 @@ $orgs = $ldapconfig->getValue('orgldapconfig');
#echo '<pre>'; print_r($orgs); exit; #echo '<pre>'; print_r($orgs); exit;
function phpping($host, $port) {
SimpleSAML_Logger::debug('ldapstatus phpping(): ping [' . $host . ':' . $port . ']' );
$timeout = 1.0;
$socket = @fsockopen($host, $port, $errno, $errstr, $timeout);
@fclose($socket);
if ($errno) {
return array(FALSE, $errno . ':' . $errstr);
} else {
return array(TRUE,NULL);
}
}
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 (!array_key_exists($r, $conf)) {
$err[] = $r;
} elseif (empty($conf[$r])) {
$err[] = 'empty:' . $r;
}
} }
if (count($err) > 0) { if (count($err) > 0) {
return array(FALSE, 'Missing: ' . join(', ', $err)); return array(FALSE, 'Missing: ' . join(', ', $err));
...@@ -39,28 +58,32 @@ foreach ($orgs AS $orgkey => $orgconfig) { ...@@ -39,28 +58,32 @@ foreach ($orgs AS $orgkey => $orgconfig) {
$results[$orgkey] = array(); $results[$orgkey] = array();
$results[$orgkey]['config'] = checkConfig($orgconfig, array('description', 'searchbase', 'hostname', 'attributes')); $results[$orgkey]['config'] = checkConfig($orgconfig, array('description', 'searchbase', 'hostname'));
$results[$orgkey]['configMeta'] = checkConfig($orgconfig, array('enable_tls', 'testUser', 'testPassword', 'contactMail', 'contactURL')); $results[$orgkey]['configMeta'] = checkConfig($orgconfig, array('enable_tls', 'testUser', 'testPassword', 'contactMail', 'contactURL'));
$url = parse_url($orgconfig['hostname']);
$pingreturn = NULL; if (!$results[$orgkey]['config'][0]) continue;
$pingoutput = NULL;
$urldef = explode(' ', $orgconfig['hostname']);
# echo 'Ping command: ' . $pingcommand; exit; $url = parse_url($urldef[0]);
$port = 389;
if (!empty($url['port'])) $port = $url['port'];
exec($pingcommand . ' ' . escapeshellcmd($url['host']), $pingoutput, $pingreturn); SimpleSAML_Logger::debug('ldapstatus Url parse [' . $orgconfig['hostname'] . '] => [' . $url['host'] . ']:[' . $port . ']' );
# echo $pingreturn; exit; // $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);
if (!$results[$orgkey]['ping'][0]) continue;
if ($pingreturn == '0') {
$results[$orgkey]['ping'] = array(TRUE,join("\r\n", $pingoutput));
} else {
$results[$orgkey]['ping'] = array(FALSE,join("\r\n", $pingoutput));
continue;
}
#continue;
// LDAP Connect // LDAP Connect
try { try {
...@@ -106,7 +129,7 @@ foreach ($orgs AS $orgkey => $orgconfig) { ...@@ -106,7 +129,7 @@ foreach ($orgs AS $orgkey => $orgconfig) {
continue; continue;
} }
if ($ldap->bind($orgconfig['testUser'], $orgconfig['testPassword'])) { if ($ldap->bind($dn, $orgconfig['testPassword'])) {
$results[$orgkey]['ldapBindTestUser'] = array(TRUE,NULL); $results[$orgkey]['ldapBindTestUser'] = array(TRUE,NULL);
} else { } else {
...@@ -124,9 +147,33 @@ foreach ($orgs AS $orgkey => $orgconfig) { ...@@ -124,9 +147,33 @@ foreach ($orgs AS $orgkey => $orgconfig) {
} }
#echo '<pre>'; print_r($results); exit; #echo '<pre>'; print_r($results); exit;
function resultCode($res) {
$code = '';
$columns = array('config', 'configMeta', 'ping', 'adminUser', 'ldapSearchBogus', 'ldapSearchTestUser', 'ldapBindTestUser', 'ldapGetAttributesTestUser');
foreach ($columns AS $c) {
if (array_key_exists($c, $res)) {
$code .= ($res[$c][0] ? '0' : '2');
} else {
$code .= '1';
}
}
return $code;
}
$ressortable = array();
foreach ($results AS $key => $res) {
$ressortable[$key] = resultCode($res);
}
asort($ressortable);
#echo '<pre>'; print_r($ressortable); exit;
$t = new SimpleSAML_XHTML_Template($config, 'ldapstatus:ldapstatus.php'); $t = new SimpleSAML_XHTML_Template($config, 'ldapstatus:ldapstatus.php');
$t->data['results'] = $results; $t->data['results'] = $results;
$t->data['orgconfig'] = $orgs; $t->data['orgconfig'] = $orgs;
$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