diff --git a/lam/templates/tests/lamdaemonTest.php b/lam/templates/tests/lamdaemonTest.php index a16c306f..3fb2d844 100644 --- a/lam/templates/tests/lamdaemonTest.php +++ b/lam/templates/tests/lamdaemonTest.php @@ -3,7 +3,7 @@ $Id$ This code is part of LDAP Account Manager (http://www.sourceforge.net/projects/lam) - Copyright (C) 2006 Roland Gruber + Copyright (C) 2006 - 2007 Roland Gruber This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -25,6 +25,7 @@ $Id$ * Tests the lamdaemon script. * * @author Roland Gruber +* @author Thomas Manninger * @package tools */ @@ -50,103 +51,6 @@ echo "\n"; echo "

" . _("Lamdaemon test") . "

\n"; -echo "\n"; - -flush(); -$stopTest = false; - -// check script server and path -echo "\n\n"; -if (!isset($_SESSION['config']->scriptServer) || (strlen($_SESSION['config']->scriptServer) < 3)) { - echo "\n"; - echo ""; -} -elseif (!isset($_SESSION['config']->scriptPath) || (strlen($_SESSION['config']->scriptPath) < 10)) { - echo "\n"; - echo ""; - $stopTest = true; -} -else { - echo "\n"; - echo ""; -} -echo "\n"; - -flush(); - -// check Unix account of LAM admin -if (!$stopTest) { - echo "\n\n"; - $credentials = $_SESSION['ldap']->decrypt_login(); - $unixOk = false; - $sr = @ldap_read($_SESSION['ldap']->server(), $credentials[0], "objectClass=posixAccount", array('uid')); - if ($sr) { - $entry = @ldap_get_entries($_SESSION['ldap']->server(), $sr); - $userName = $entry[0]['uid'][0]; - if ($userName) { - $unixOk = true; - } - } - if ($unixOk) { - echo "\n"; - echo ""; - } - else { - echo "\n"; - echo ""; - $stopTest = true; - } - echo "\n"; -} - -flush(); - -// check SSH2 function -if (!$stopTest) { - echo "\n\n"; - if (function_exists("ssh2_connect")) { - echo ""; - echo ""; - } - else { - echo "\n"; - echo ""; - $stopTest = true; - } - echo "\n"; -} - -flush(); - -// check SSH login -if (!$stopTest) { - echo "\n\n"; - flush(); - $sshOk = false; - $handle = @ssh2_connect($_SESSION['config']->scriptServer); - if ($handle) { - if (@ssh2_auth_password($handle, $userName, $credentials[1])) { - $sshOk = true; - } - } - if ($sshOk) { - echo ""; - echo ""; - } - else { - echo "\n"; - echo ""; - $stopTest = true; - } - echo "\n"; -} - -flush(); - -$stopTest = lamTestLamdaemon("+ test basic\n", $stopTest, $handle, _("Execute lamdaemon")); -$stopTest = lamTestLamdaemon("+ test quota\n", $stopTest, $handle, _("Lamdaemon: Quota module installed")); -$stopTest = lamTestLamdaemon("+ quota get user\n", $stopTest, $handle, _("Lamdaemon: read quotas")); - /** * Runs a test case of lamdaemon. * @@ -199,7 +103,7 @@ function lamTestLamdaemon($command, $stopTest, $handle, $testText) { call_user_func_array('StatusMessage', split(",", $return[$i])); } echo "\n"; - $stopTest = true; + $stopTest = true; } echo "\n"; } @@ -207,7 +111,120 @@ function lamTestLamdaemon($command, $stopTest, $handle, $testText) { return $stopTest; } -echo "
" . _("Lamdaemon server and path") . "  " . _("Error") . "" . _("No lamdaemon server set, please update your LAM configuration settings.") . "" . _("Error") . "  " . _("No lamdaemon path set, please update your LAM configuration settings.") . "" . _("Ok") . "  " . sprintf(_("Using %s as lamdaemon remote server."), $_SESSION['config']->scriptServer) . "
" . _("Unix account") . "  " . _("Ok") . "" . sprintf(_("Using %s to connect to remote server."), $userName) . "" . _("Error") . "  " . sprintf(_("Your LAM admin user (%s) must be a valid Unix account to work with lamdaemon!"), $credentials[0]) . "
" . _("SSH2 module") . "  " . _("Ok") . "" . _("SSH2 module is installed.") . "" . _("Error") . "  " . _("Please install the SSH2 module for PHP and activate it in your php.ini!") . "
" . _("SSH connection") . "  " . _("Ok") . "" . _("SSH connection could be established.") . "" . _("Error") . "  " . _("Unable to connect to remote server!") . "
\n"; +$servers = explode(";", $_SESSION['config']->get_scriptServers()); +for ($i = 0; $i < sizeof($servers); $i++) { + $servers[$i] = explode(":", $servers[$i]); + $serverName = $servers[$i][0]; + $title = $serverName; + $serverDisplayName = $servers[$i][0]; + if (isset($servers[$i][1])) { + $serverDisplayName = $servers[$i][1]; + $title = $serverDisplayName . " (" . $serverName . ")"; + } + + echo "\n"; + + flush(); + $stopTest = false; + + echo "\n\n"; + + // check script server and path + echo "\n\n"; + if (!isset($serverName) || (strlen($serverName) < 3)) { + echo "\n"; + echo ""; + } + elseif (!isset($_SESSION['config']->scriptPath) || (strlen($_SESSION['config']->scriptPath) < 10)) { + echo "\n"; + echo ""; + $stopTest = true; + } + else { + echo "\n"; + echo ""; + } + echo "\n"; + + flush(); + + // check Unix account of LAM admin + if (!$stopTest) { + echo "\n\n"; + $credentials = $_SESSION['ldap']->decrypt_login(); + $unixOk = false; + $sr = @ldap_read($_SESSION['ldap']->server(), $credentials[0], "objectClass=posixAccount", array('uid')); + if ($sr) { + $entry = @ldap_get_entries($_SESSION['ldap']->server(), $sr); + $userName = $entry[0]['uid'][0]; + if ($userName) { + $unixOk = true; + } + } + if ($unixOk) { + echo "\n"; + echo ""; + } + else { + echo "\n"; + echo ""; + $stopTest = true; + } + echo "\n"; + } + + flush(); + + // check SSH2 function + if (!$stopTest) { + echo "\n\n"; + if (function_exists("ssh2_connect")) { + echo ""; + echo ""; + } + else { + echo "\n"; + echo ""; + $stopTest = true; + } + echo "\n"; + } + + flush(); + + // check SSH login + if (!$stopTest) { + echo "\n\n"; + flush(); + $sshOk = false; + $handle = @ssh2_connect($serverName); + if ($handle) { + if (@ssh2_auth_password($handle, $userName, $credentials[1])) { + $sshOk = true; + } + } + if ($sshOk) { + echo ""; + echo ""; + } + else { + echo "\n"; + echo ""; + $stopTest = true; + } + echo "\n"; + } + + flush(); + + $stopTest = lamTestLamdaemon("+ test basic\n", $stopTest, $handle, _("Execute lamdaemon")); + $stopTest = lamTestLamdaemon("+ test quota\n", $stopTest, $handle, _("Lamdaemon: Quota module installed")); + $stopTest = lamTestLamdaemon("+ quota get user\n", $stopTest, $handle, _("Lamdaemon: read quotas")); + + echo "
"; + + echo "
$title\n
" . _("Lamdaemon server and path") . "  " . _("Error") . "" . _("No lamdaemon server set, please update your LAM configuration settings.") . "" . _("Error") . "  " . _("No lamdaemon path set, please update your LAM configuration settings.") . "" . _("Ok") . "  " . sprintf(_("Using %s as lamdaemon remote server."), $serverName) . "
" . _("Unix account") . "  " . _("Ok") . "" . sprintf(_("Using %s to connect to remote server."), $userName) . "" . _("Error") . "  " . sprintf(_("Your LAM admin user (%s) must be a valid Unix account to work with lamdaemon!"), $credentials[0]) . "
" . _("SSH2 module") . "  " . _("Ok") . "" . _("SSH2 module is installed.") . "" . _("Error") . "  " . _("Please install the SSH2 module for PHP and activate it in your php.ini!") . "
" . _("SSH connection") . "  " . _("Ok") . "" . _("SSH connection could be established.") . "" . _("Error") . "  " . _("Unable to connect to remote server!") . "
\n"; +} echo "

" . _("Lamdaemon test finished.") . "

\n";