\n"; echo "\n"; echo "\n"; echo ""; echo "\n"; echo "

" . _("Lamdaemon test") . "

\n"; /** * Runs a test case of lamdaemon. * * @param string $command test command * @param boolean $stopTest specifies if test should be run * @param connection $handle SSH connection * @param string $testText describing text * @return boolean true, if errors occured */ function lamTestLamdaemon($command, $stopTest, $handle, $testText) { // run lamdaemon and get user quotas if (!$stopTest) { echo "\n" . $testText . "  \n"; flush(); $lamdaemonOk = false; $errorMessage = ""; $shell = ssh2_exec($handle, "sudo " . $_SESSION['config']->scriptPath); $stderr = ssh2_fetch_stream($shell, SSH2_STREAM_STDERR); fwrite($shell, $command); $return = array(); $time = time() + 20; while (sizeof($return) < 1) { if ($time < time()) { $lamdaemonOk = false; $return[] = "ERROR," . _("Timeout while executing lamdaemon commands!"); break; } usleep(100); $read = split("\n", trim(fread($shell, 100000))); if ((sizeof($read) == 1) && (!isset($read[0]) || ($read[0] == ""))) continue; for ($i = 0; $i < sizeof($read); $i++) { $return[] = $read[$i]; } } $errOut = @fread($stderr, 100000); if ((strpos(strtolower($errOut), "sudoers") !== false) || (strpos(strtolower($errOut), "sorry") !== false)) { $return[] = "ERROR," . _("Sudo is not setup correctly!") . "," . str_replace(",", " ", $errOut); } if ((sizeof($return) == 1) && (strpos(strtolower($return[0]), "error") === false)) { $lamdaemonOk = true; } if ($lamdaemonOk) { echo "" . _("Ok") . ""; echo "" . _("Lamdaemon successfully run.") . ""; } else { echo "" . _("Error") . "  \n"; echo "\n"; for ($i = 0; $i < sizeof($return); $i++) { call_user_func_array('StatusMessage', split(",", $return[$i])); } echo "\n"; $stopTest = true; } echo "\n"; } flush(); return $stopTest; } $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"; echo "\n"; echo "\n"; ?>