From 9d473cb2687eb9b37092f85f576178d59e19fcbe Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Sun, 17 Oct 2010 13:38:32 +0000 Subject: [PATCH] use meta HTML classes --- lam/templates/tests/index.php | 21 +-- lam/templates/tests/lamdaemonTest.php | 192 ++++++++++++++------------ lam/templates/tests/schemaTest.php | 58 ++++---- 3 files changed, 148 insertions(+), 123 deletions(-) diff --git a/lam/templates/tests/index.php b/lam/templates/tests/index.php index 31e92261..f7827a49 100644 --- a/lam/templates/tests/index.php +++ b/lam/templates/tests/index.php @@ -42,20 +42,25 @@ if (!checkIfWriteAccessIsAllowed()) die(); setlanguage(); include '../main_header.php'; +echo "
\n"; -echo "

" . _("LAM tests") . "

\n"; +$container = new htmlTable(); +$container->addElement(new htmlSubTitle(_("LAM tests")), true); -echo "\n"; +$container->addElement(new htmlLink(_("Lamdaemon test"), 'lamdaemonTest.php')); +$container->addElement(new htmlSpacer('20px', null)); +$container->addElement(new htmlOutputText(_("Check if quotas and homedirectories can be managed.")), true); -echo ""; -echo ""; +$container->addElement(new htmlSpacer(null, '20px'), true); -echo ""; -echo ""; - -echo "
" . _("Lamdaemon test") . "  " . _("Check if quotas and homedirectories can be managed.") . "
" . _("Schema test") . "  " . _("Check if the LDAP schema fits the requirements of the selected account modules.") . "
\n"; +$container->addElement(new htmlLink(_("Schema test"), 'schemaTest.php')); +$container->addElement(new htmlSpacer('20px', null)); +$container->addElement(new htmlOutputText(_("Check if the LDAP schema fits the requirements of the selected account modules.")), true); +$tabindex = 1; +parseHtml(null, $container, array(), true, $tabindex, 'user'); +echo "
\n"; include '../main_footer.php'; ?> diff --git a/lam/templates/tests/lamdaemonTest.php b/lam/templates/tests/lamdaemonTest.php index 71dcd420..e5a517d3 100644 --- a/lam/templates/tests/lamdaemonTest.php +++ b/lam/templates/tests/lamdaemonTest.php @@ -43,8 +43,11 @@ if (!checkIfWriteAccessIsAllowed()) die(); setlanguage(); include '../main_header.php'; +echo "
\n"; +echo "
\n"; -echo "

" . _("Lamdaemon test") . "

\n"; +$container = new htmlTable(); +$container->addElement(new htmlTitle(_("Lamdaemon test")), true); $servers = explode(";", $_SESSION['config']->get_scriptServers()); $serverIDs = array(); @@ -61,51 +64,42 @@ for ($i = 0; $i < sizeof($servers); $i++) { } if (isset($_POST['runTest'])) { - lamRunLamdaemonTestSuite($_POST['server'], $serverTitles[$_POST['server']] , isset($_POST['checkQuotas'])); + lamRunLamdaemonTestSuite($_POST['server'], $serverTitles[$_POST['server']] , isset($_POST['checkQuotas']), $container); } 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"; + $container->addElement(new htmlOutputText(_("Server"))); + $serverOptions = array(); + for ($i = 0; $i < sizeof($servers); $i++) { + $servers[$i] = explode(":", $servers[$i]); + $serverName = $servers[$i][0]; + $title = $serverName; + if (isset($servers[$i][1])) { + $title = $servers[$i][1] . " (" . $serverName . ")"; + } + $serverOptions[$title] = $serverName; + } + $serverSelect = new htmlSelect('server', $serverOptions); + $serverSelect->setHasDescriptiveElements(true); + $container->addElement($serverSelect, true); - echo "
"; + $container->addElement(new htmlOutputText(_("Check quotas"))); + $container->addElement(new htmlInputCheckbox('checkQuotas', false), true); - echo "\n"; - echo "
\n"; - echo "
\n"; + $container->addElement(new htmlSpacer(null, '10px'), true); + + $okButton = new htmlButton('runTest', _("Ok")); + $okButton->colspan = 2; + $container->addElement($okButton); } else { - StatusMessage("ERROR", _('No lamdaemon server set, please update your LAM configuration settings.')); + $container->addElement(new htmlStatusMessage("ERROR", _('No lamdaemon server set, please update your LAM configuration settings.'))); } +$tabindex = 1; +parseHtml(null, $container, array(), false, $tabindex, 'user'); +echo "\n"; +echo "
\n"; include '../main_footer.php'; @@ -116,14 +110,17 @@ include '../main_footer.php'; * @param boolean $stopTest specifies if test should be run * @param connection $handle SSH connection * @param string $testText describing text + * @param htmlTable $container container for HTML output * @return boolean true, if errors occured */ -function lamTestLamdaemon($command, $stopTest, $handle, $testText) { - $okImage = "\"\"\n"; - $failImage = "\"\"\n"; +function lamTestLamdaemon($command, $stopTest, $handle, $testText, $container) { + $okImage = "../../graphics/pass.png"; + $failImage = "../../graphics/fail.png"; + $spacer = new htmlSpacer('10px', null); // run lamdaemon and get user quotas if (!$stopTest) { - echo "\n" . $testText . "  \n"; + $container->addElement(new htmlOutputText($testText)); + $container->addElement($spacer); flush(); $lamdaemonOk = false; $output = $handle->exec("sudo " . $_SESSION['config']->get_scriptPath() . ' ' . escapeshellarg($command)); @@ -131,24 +128,32 @@ function lamTestLamdaemon($command, $stopTest, $handle, $testText) { $lamdaemonOk = true; } if ($lamdaemonOk) { - echo "" . $okImage . "  "; - echo "" . _("Lamdaemon successfully run.") . ""; + $container->addElement(new htmlImage($okImage)); + $container->addElement($spacer); + $container->addElement(new htmlOutputText(_("Lamdaemon successfully run.")), true); } else { - echo "" . $failImage . "  \n"; - echo "\n"; + $container->addElement(new htmlImage($failImage)); + $container->addElement($spacer); if (!(strpos($output, 'ERROR,') === 0) && !(strpos($output, 'WARN,') === 0)) { // error messages from console (e.g. sudo) - StatusMessage('ERROR', $output); + $container->addElement(new htmlStatusMessage('ERROR', $output), true); } else { // error messages from lamdaemon - call_user_func_array('StatusMessage', explode(",", $output)); + $parts = explode(",", $output); + if (sizeof($parts) == 2) { + $container->addElement(new htmlStatusMessage($parts[0], $parts[1]), true); + } + elseif (sizeof($parts) == 3) { + $container->addElement(new htmlStatusMessage($parts[0], $parts[1], $parts[2]), true); + } + else { + $container->addElement(new htmlOutputText($output), true); + } } - echo "\n"; $stopTest = true; } - echo "\n"; } flush(); return $stopTest; @@ -160,41 +165,45 @@ function lamTestLamdaemon($command, $stopTest, $handle, $testText) { * @param String $serverName server ID * @param String $serverTitle server name * @param boolean $testQuota true, if Quotas should be checked + * @param htmlTable $container container for HTML output */ -function lamRunLamdaemonTestSuite($serverName, $serverTitle, $testQuota) { +function lamRunLamdaemonTestSuite($serverName, $serverTitle, $testQuota, $container) { $SPLIT_DELIMITER = "###x##y##x###"; - $okImage = "\"\"\n"; - $failImage = "\"\"\n"; + $okImage = "../../graphics/pass.png"; + $failImage = "../../graphics/fail.png"; - echo "\n"; - flush(); $stopTest = false; + $spacer = new htmlSpacer('10px', null); - echo "\n\n"; + $container->addElement(new htmlSubTitle($serverTitle), true); // check script server and path - echo "\n\n"; + $container->addElement(new htmlOutputText(_("Lamdaemon server and path"))); + $container->addElement(new htmlSpacer('10px', null)); if (!isset($serverName) || (strlen($serverName) < 3)) { - echo "\n"; - echo ""; + $container->addElement(new htmlImage($failImage)); + $container->addElement($spacer); + $container->addElement(new htmlOutputText(_("No lamdaemon server set, please update your LAM configuration settings.")), true); } elseif (($_SESSION['config']->get_scriptPath() == null) || (strlen($_SESSION['config']->get_scriptPath()) < 10)) { - echo "\n"; - echo ""; + $container->addElement(new htmlImage($failImage)); + $container->addElement($spacer); + $container->addElement(new htmlOutputText(_("No lamdaemon path set, please update your LAM configuration settings.")), true); $stopTest = true; } else { - echo "\n"; - echo ""; + $container->addElement(new htmlImage($okImage)); + $container->addElement($spacer); + $container->addElement(new htmlOutputText(sprintf(_("Using %s as lamdaemon remote server."), $serverName)), true); } - echo "\n"; flush(); // check Unix account of LAM admin if (!$stopTest) { - echo "\n\n"; + $container->addElement(new htmlOutputText(_("Unix account"))); + $container->addElement($spacer); $credentials = $_SESSION['ldap']->decrypt_login(); $unixOk = false; $sr = @ldap_read($_SESSION['ldap']->server(), $credentials[0], "objectClass=posixAccount", array('uid')); @@ -206,22 +215,24 @@ function lamRunLamdaemonTestSuite($serverName, $serverTitle, $testQuota) { } } if ($unixOk) { - echo "\n"; - echo ""; + $container->addElement(new htmlImage($okImage)); + $container->addElement($spacer); + $container->addElement(new htmlOutputText(sprintf(_("Using %s to connect to remote server."), $userName)), true); } else { - echo "\n"; - echo ""; + $container->addElement(new htmlImage($failImage)); + $container->addElement($spacer); + $container->addElement(new htmlOutputText(sprintf(_("Your LAM admin user (%s) must be a valid Unix account to work with lamdaemon!"), $credentials[0])), true); $stopTest = true; } - echo "\n"; } flush(); // check SSH login if (!$stopTest) { - echo "\n\n"; + $container->addElement(new htmlOutputText(_("SSH connection"))); + $container->addElement($spacer); flush(); $sshOk = false; $handle = lamTestConnectSSH($serverName); @@ -231,35 +242,42 @@ function lamRunLamdaemonTestSuite($serverName, $serverTitle, $testQuota) { } } if ($sshOk) { - echo ""; - echo ""; + $container->addElement(new htmlImage($okImage)); + $container->addElement($spacer); + $container->addElement(new htmlOutputText(_("SSH connection could be established.")), true); } else { - echo "\n"; - echo ""; + $container->addElement(new htmlImage($failImage)); + $container->addElement($spacer); + $container->addElement(new htmlOutputText(_("Unable to connect to remote server!")), true); $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) { + if (!$stopTest) { + $stopTest = lamTestLamdaemon("+" . $SPLIT_DELIMITER . "test" . $SPLIT_DELIMITER . "basic", $stopTest, $handle, _("Execute lamdaemon"), $container); + } + + if (!$stopTest) { $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")); + $stopTest = lamTestLamdaemon("+" . $SPLIT_DELIMITER . "test" . $SPLIT_DELIMITER . "nss" . $SPLIT_DELIMITER . "$userName", $stopTest, $handle, _("Lamdaemon: check NSS LDAP"), $container); + if (!$stopTest && $testQuota) { + $handle = lamTestConnectSSH($serverName); + @$handle->login($userName, $credentials[1]); + $stopTest = lamTestLamdaemon("+" . $SPLIT_DELIMITER . "test" . $SPLIT_DELIMITER . "quota", $stopTest, $handle, _("Lamdaemon: Quota module installed"), $container); + $handle = lamTestConnectSSH($serverName); + @$handle->login($userName, $credentials[1]); + $stopTest = lamTestLamdaemon("+" . $SPLIT_DELIMITER . "quota" . $SPLIT_DELIMITER . "get" . $SPLIT_DELIMITER . "user", $stopTest, $handle, _("Lamdaemon: read quotas"), $container); + } } - 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"; + $container->addElement(new htmlSpacer(null, '10px'), true); + $endMessage = new htmlOutputText(_("Lamdaemon test finished.")); + $endMessage->colspan = 5; + $container->addElement($endMessage); } /** diff --git a/lam/templates/tests/schemaTest.php b/lam/templates/tests/schemaTest.php index 1a77bf56..0ac8d837 100644 --- a/lam/templates/tests/schemaTest.php +++ b/lam/templates/tests/schemaTest.php @@ -46,45 +46,47 @@ if (!checkIfWriteAccessIsAllowed()) die(); setlanguage(); include '../main_header.php'; +echo "
\n"; -echo "

" . _("Schema test") . "

\n"; +$container = new htmlTable(); + +$container->addElement(new htmlTitle(_("Schema test")), true); get_schema_objectclasses(); $classes = get_cached_schema('objectclasses'); if (!is_array($classes)) { - StatusMessage('ERROR', _('Unable to retrieve schema!'), _('You do not have the required access rights or the LDAP schema is not published by your server.')); - include '../main_footer.php'; - die(); + $container->addElement(new htmlStatusMessage('ERROR', _('Unable to retrieve schema!'), _('You do not have the required access rights or the LDAP schema is not published by your server.'))); } - -// loop for active account types -for ($t = 0; $t < sizeof($types); $t++) { - $modules = $_SESSION['config']->get_AccountModules($types[$t]); - echo "

" . getTypeAlias($types[$t]) . "

\n"; - echo "\n"; - - for ($m = 0; $m < sizeof($modules); $m++) { - $error = checkSchemaForModule($modules[$m], $types[$t]); - $message = _("No problems found."); - $icon = '../../graphics/pass.png'; - if ($error != null) { - $icon = '../../graphics/fail.png'; - $message = $error; +else { + // loop for active account types + for ($t = 0; $t < sizeof($types); $t++) { + $modules = $_SESSION['config']->get_AccountModules($types[$t]); + $container->addElement(new htmlSubTitle(getTypeAlias($types[$t])), true); + for ($m = 0; $m < sizeof($modules); $m++) { + $error = checkSchemaForModule($modules[$m], $types[$t]); + $message = _("No problems found."); + $icon = '../../graphics/pass.png'; + if ($error != null) { + $icon = '../../graphics/fail.png'; + $message = $error; + } + // module name + $container->addElement(new htmlOutputText(getModuleAlias($modules[$m], $types[$t]))); + $container->addElement(new htmlSpacer('10px', null)); + // icon + $container->addElement(new htmlImage($icon)); + $container->addElement(new htmlSpacer('10px', null)); + // text + $container->addElement(new htmlOutputText($message), true); } - // module name - echo "\n"; - echo "\n"; - // icon - echo "\n"; - // text - echo "\n"; - echo "\n"; } - - echo "
" . getModuleAlias($modules[$m], $types[$t]) . "\"\"" . $message . "
\n
"; } +$tabindex = 1; +parseHtml(null, $container, array(), true, $tabindex, 'user'); + +echo "
\n"; include '../main_footer.php'; /**