diff --git a/lam/docs/README.lamdaemon.txt b/lam/docs/README.lamdaemon.txt index 6b9df61b..c3c66cc5 100644 --- a/lam/docs/README.lamdaemon.txt +++ b/lam/docs/README.lamdaemon.txt @@ -73,6 +73,9 @@ to point to lamdaemonOld.pl. If you want to compile it yourself, get the sources here: http://pecl.php.net/package/ssh2 + After installing the PHP module please add this line to your php.ini: + extension=ssh2.so + 5. Set up SSH ============= @@ -89,6 +92,9 @@ Now everything should work fine. 6. Debugging lamdaemon ====================== + - There is a test page for lamdaemon: + Login to LAM and open Tools -> Tests -> Lamdaemon test + - Check /var/log/auth.log or the equivalent on your system This file contains messages about all logins. If the ssh login failed then you will find a description about the reason here. diff --git a/lam/templates/tests/index.php b/lam/templates/tests/index.php new file mode 100644 index 00000000..a160ec80 --- /dev/null +++ b/lam/templates/tests/index.php @@ -0,0 +1,63 @@ +\n"; +echo "\n"; +echo "\n"; +echo ""; + +echo "\n"; + +echo "

" . _("LAM tests") . "

\n"; + +echo "\n"; + +echo ""; +echo ""; + +echo "
" . _("Lamdaemon test") . "  " . _("Check if quotas and homedirectories can be managed.") . "
\n"; + +echo "\n"; +echo "\n"; + +?> diff --git a/lam/templates/tests/lamdaemonTest.php b/lam/templates/tests/lamdaemonTest.php new file mode 100644 index 00000000..a799ffdd --- /dev/null +++ b/lam/templates/tests/lamdaemonTest.php @@ -0,0 +1,200 @@ +\n"; +echo "\n"; +echo "\n"; +echo ""; + +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(); + +// run lamdaemon and get user quotas +if (!$stopTest) { + echo "\n\n"; + flush(); + $lamdaemonOk = false; + $errorMessage = ""; + $shell = ssh2_exec($handle, "sudo " . $_SESSION['config']->scriptPath); + $stderr = ssh2_fetch_stream($shell, SSH2_STREAM_STDERR); + fwrite($shell, "+ quota get user\n"); + $return = array(); + $time = time() + 20; + while (sizeof($return) < 1) { + if ($time < time()) { + $lamdaemonOk = false; + $errorMessage = _("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 ((stripos($errOut, "sudoers") !== false) || (stripos($errOut, "sorry") !== false)) { + $return[] = "ERROR," . _("Sudo is not setup correctly!") . "," . str_replace(",", " ", $errOut); + } + if ((sizeof($return) == 1) && (stripos($return[0], "error") === false)) { + $lamdaemonOk = true; + } + if ($lamdaemonOk) { + echo ""; + echo ""; + } + else { + echo "\n"; + echo "\n"; + $stopTest = true; + } + echo "\n"; +} + +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") . "  " . _("Your LAM admin user must be a valid Unix account to work with lamdaemon!") . "
" . _("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!") . "
" . _("Execute lamdaemon") . "  " . _("Ok") . "" . _("Lamdaemon successfully run.") . "" . _("Error") . "  \n"; + for ($i = 0; $i < sizeof($return); $i++) { + call_user_func_array('StatusMessage', split(",", $return[$i])); + } + echo "
\n"; + +echo "

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

\n"; + +echo "\n"; +echo "\n"; + +?> diff --git a/lam/templates/tools.php b/lam/templates/tools.php index dfa923f6..1d52c0fc 100644 --- a/lam/templates/tools.php +++ b/lam/templates/tools.php @@ -85,6 +85,13 @@ $tools[] = array( "link" => "schema/schema.php" ); +// tests +$tools[] = array( + "name" => _("Tests"), + "description" => _("Here you can test if certain LAM features work on your installation."), + "link" => "tests/index.php" + ); + echo "

 

\n"; // print tools table