" . _("Lamdaemon test") . "\n"; $servers = explode(";", $_SESSION['config']->get_scriptServers()); $serverIDs = array(); $serverTitles = array(); for ($i = 0; $i < sizeof($servers); $i++) { $serverParts = explode(":", $servers[$i]); $serverName = $serverParts[0]; $title = $serverName; if (isset($serverParts[1])) { $title = $serverParts[1] . " (" . $serverName . ")"; } $serverIDs[] = $serverName; $serverTitles[$serverName] = $title; } if (isset($_POST['runTest'])) { lamRunLamdaemonTestSuite($_POST['server'], $serverTitles[$_POST['server']] , isset($_POST['checkQuotas'])); } else if ((sizeof($servers) > 0) && isset($servers[0]) && ($servers[0] != '')) { echo "
\n"; echo "
" . _("Lamdaemon test") . "
\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "
\n"; echo _("Server"); echo "\n"; echo "\n"; echo "
\n"; echo _("Check quotas"); echo "\n"; echo "\n"; echo "
\n"; echo "
"; echo "\n"; echo "
\n"; echo "
\n"; } else { StatusMessage("ERROR", _('No lamdaemon server set, please update your LAM configuration settings.')); } include '../main_footer.php'; /** * 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) { $okImage = "\"\"\n"; $failImage = "\"\"\n"; // run lamdaemon and get user quotas if (!$stopTest) { echo "\n" . $testText . "  \n"; flush(); $lamdaemonOk = false; $output = $handle->exec("sudo " . $_SESSION['config']->get_scriptPath() . ' ' . escapeshellarg($command)); if ((stripos(strtolower($output), "error") === false) && ((strpos($output, 'INFO,') === 0) || (strpos($output, 'QUOTA_ENTRY') === 0))) { $lamdaemonOk = true; } if ($lamdaemonOk) { echo "" . $okImage . "  "; echo "" . _("Lamdaemon successfully run.") . ""; } else { echo "" . $failImage . "  \n"; echo "\n"; if (!(strpos($output, 'ERROR,') === 0) && !(strpos($output, 'WARN,') === 0)) { // error messages from console (e.g. sudo) StatusMessage('ERROR', $output); } else { // error messages from lamdaemon call_user_func_array('StatusMessage', explode(",", $output)); } echo "\n"; $stopTest = true; } echo "\n"; } flush(); return $stopTest; } /** * Runs all tests for a given server. * * @param String $serverName server ID * @param String $serverTitle server name * @param boolean $testQuota true, if Quotas should be checked */ function lamRunLamdaemonTestSuite($serverName, $serverTitle, $testQuota) { $SPLIT_DELIMITER = "###x##y##x###"; $okImage = "\"\"\n"; $failImage = "\"\"\n"; 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 (($_SESSION['config']->get_scriptPath() == null) || (strlen($_SESSION['config']->get_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 SSH login if (!$stopTest) { echo "\n\n"; flush(); $sshOk = false; $handle = lamTestConnectSSH($serverName); if ($handle) { if ($handle->login($userName, $credentials[1])) { $sshOk = true; } } if ($sshOk) { echo ""; echo ""; } else { echo "\n"; echo ""; $stopTest = true; } echo "\n"; } flush(); $stopTest = lamTestLamdaemon("+" . $SPLIT_DELIMITER . "test" . $SPLIT_DELIMITER . "basic", $stopTest, $handle, _("Execute lamdaemon")); $handle = lamTestConnectSSH($serverName); @$handle->login($userName, $credentials[1]); $stopTest = lamTestLamdaemon("+" . $SPLIT_DELIMITER . "test" . $SPLIT_DELIMITER . "nss" . $SPLIT_DELIMITER . "$userName", $stopTest, $handle, _("Lamdaemon: check NSS LDAP")); if ($testQuota) { $handle = lamTestConnectSSH($serverName); @$handle->login($userName, $credentials[1]); $stopTest = lamTestLamdaemon("+" . $SPLIT_DELIMITER . "test" . $SPLIT_DELIMITER . "quota", $stopTest, $handle, _("Lamdaemon: Quota module installed")); $handle = lamTestConnectSSH($serverName); @$handle->login($userName, $credentials[1]); $stopTest = lamTestLamdaemon("+" . $SPLIT_DELIMITER . "quota" . $SPLIT_DELIMITER . "get" . $SPLIT_DELIMITER . "user", $stopTest, $handle, _("Lamdaemon: read quotas")); } echo "
$serverTitle\n
" . _("Lamdaemon server and path") . "  " . $failImage . "" . _("No lamdaemon server set, please update your LAM configuration settings.") . "" . $failImage . "  " . _("No lamdaemon path set, please update your LAM configuration settings.") . "" . $okImage . "  " . sprintf(_("Using %s as lamdaemon remote server."), $serverName) . "
" . _("Unix account") . "  " . $okImage . "  " . sprintf(_("Using %s to connect to remote server."), $userName) . "" . $failImage . "  " . sprintf(_("Your LAM admin user (%s) must be a valid Unix account to work with lamdaemon!"), $credentials[0]) . "
" . _("SSH connection") . "  " . $okImage . "  " . _("SSH connection could be established.") . "" . $failImage . "  " . _("Unable to connect to remote server!") . "

\n"; echo "

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

\n"; } /** * Connects to the given SSH server. * * @param String $server server name (e.g. localhost or localhost,1234) * @return object handle */ function lamTestConnectSSH($server) { // add phpseclib to include path set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/../../lib/3rdParty/phpseclib'); include_once('Net/SSH2.php'); $serverNameParts = explode(",", $server); if (sizeof($serverNameParts) > 1) { return @new Net_SSH2($serverNameParts[0], $serverNameParts[1]); } else { return @new Net_SSH2($server); } } ?>