From 8f22c32dd778e20d5df1eaf7bf6a81412ac493b7 Mon Sep 17 00:00:00 2001 From: cajus Date: Wed, 31 May 2006 13:35:17 +0000 Subject: [PATCH] Cleaned error messages during login git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@3586 594d385d-05f5-0310-b6e9-bd551577e9d8 --- TODO | 2 - html/index.php | 134 ++++++++++++++++----------------- html/main.php | 10 +-- ihtml/themes/default/login.tpl | 2 +- include/class_config.inc | 6 +- include/functions.inc | 14 ++-- 6 files changed, 79 insertions(+), 89 deletions(-) diff --git a/TODO b/TODO index 27bf74f60..8ddb47225 100644 --- a/TODO +++ b/TODO @@ -17,8 +17,6 @@ Target for 2.5: * Change FAIstate when triggering actions (install, sysinfo, softupdate) -* Fix error messages on login - * Fix DNS plugin * Zones are not creatable, currently * Error messages are partly wrong diff --git a/html/index.php b/html/index.php index 63fb9db91..16e0c94be 100644 --- a/html/index.php +++ b/html/index.php @@ -23,6 +23,65 @@ require_once ("../include/php_setup.inc"); require_once ("functions.inc"); header("Content-type: text/html; charset=UTF-8"); +function displayLogin() +{ + global $smarty,$message,$config,$ssl,$error_collector; + error_reporting(E_ALL); + /* Fill template with required values */ + $username = ""; + if(isset($_POST["username"])){ + $username= $_POST["username"]; + } + $smarty->assign ('date', gmdate("D, d M Y H:i:s")); + $smarty->assign ('username', $username); + $smarty->assign ('personal_img', get_template_path('images/personal.png')); + $smarty->assign ('password_img', get_template_path('images/password.png')); + $smarty->assign ('directory_img', get_template_path('images/ldapserver.png')); + + /* Some error to display? */ + if (!isset($message)){ + $message= ""; + } + $smarty->assign ("message", $message); + + /* Displasy SSL mode warning? */ + if ($ssl != "" && $config->data['MAIN']['WARNSSL'] == 'true'){ + $smarty->assign ("ssl", ""._("Warning").": "._("Session will not be encrypted.")." "._("Enter SSL session")."!"); + } else { + $smarty->assign ("ssl", ""); + } + + /* Generate server list */ + $servers= array(); + if (isset($_POST['server'])){ + $selected= validate($_POST['server']); + } else { + $selected= $config->data['MAIN']['DEFAULT']; + } + foreach ($config->data['LOCATIONS'] as $key => $ignored){ + $servers[$key]= $key; + } + $smarty->assign ("server_options", $servers); + $smarty->assign ("server_id", $selected); + + /* show login screen */ + $smarty->assign ("PHPSESSID", session_id()); + if (isset($_SESSION['errors'])){ + $smarty->assign("errors", $_SESSION['errors']); + } + if ($error_collector != ""){ + $smarty->assign("php_errors", $error_collector.""); + } else { + $smarty->assign("php_errors", ""); + } + + $smarty->display (get_template_path('headers.tpl')); + $smarty->display(get_template_path('login.tpl')); + exit(); +} + + + /* Set error handler to own one, initialize time calculation and start session. */ session_start (); @@ -142,8 +201,7 @@ if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['login'])){ $ldap = $config->get_ldap_link(); if (is_null($ldap) || (is_int($ldap) && $ldap == 0)){ print_red (_("Can't bind to LDAP. Please contact the system administrator.")); - echo $_SESSION['errors']; - $smarty->display(get_template_path('login.tpl')); + displayLogin(); exit(); } @@ -155,7 +213,8 @@ if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['login'])){ require_once("functions_setup.inc"); if(!is_schema_readable($config->current['SERVER'],$config->current['ADMIN'],$config->current['PASSWORD'])){ print_red(_("GOsa cannot retrieve information about the installed schema files. Please make sure, that this is possible.")); - echo $_SESSION['errors']; + $smarty->display(get_template_path('headers.tpl')); + echo "".$_SESSION['errors'].""; exit(); }else{ $str = (schema_check($config->current['SERVER'],$config->current['ADMIN'],$config->current['PASSWORD'],0,TRUE)); @@ -163,7 +222,8 @@ if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['login'])){ foreach($str as $tr){ if(isset($tr['needonstartup'])){ print_red($tr['msg']."
"._("Your ldap setup contains old schema definitions. Please re-run the setup.")); - print $_SESSION['errors']; + $smarty->display(get_template_path('headers.tpl')); + echo "".$_SESSION['errors'].""; exit(); } } @@ -301,71 +361,7 @@ if ($error_collector != ""){ } else { $smarty->assign("php_errors", ""); } -$smarty->display (get_template_path('login.tpl')); - - - - - - - -function displayLogin() -{ - global $smarty,$message,$config,$ssl,$error_collector; - error_reporting(E_ALL); - /* Fill template with required values */ - $username = ""; - if(isset($_POST["username"])){ - $username= $_POST["username"]; - } - $smarty->assign ('date', gmdate("D, d M Y H:i:s")); - $smarty->assign ('username', $username); - $smarty->assign ('personal_img', get_template_path('images/personal.png')); - $smarty->assign ('password_img', get_template_path('images/password.png')); - $smarty->assign ('directory_img', get_template_path('images/ldapserver.png')); - - /* Some error to display? */ - if (!isset($message)){ - $message= ""; - } - $smarty->assign ("message", $message); - - /* Displasy SSL mode warning? */ - if ($ssl != "" && $config->data['MAIN']['WARNSSL'] == 'true'){ - $smarty->assign ("ssl", ""._("Warning").": "._("Session will not be encrypted.")." "._("Enter SSL session")."!"); - } else { - $smarty->assign ("ssl", ""); - } - - /* Generate server list */ - $servers= array(); - if (isset($_POST['server'])){ - $selected= validate($_POST['server']); - } else { - $selected= $config->data['MAIN']['DEFAULT']; - } - foreach ($config->data['LOCATIONS'] as $key => $ignored){ - $servers[$key]= $key; - } - $smarty->assign ("server_options", $servers); - $smarty->assign ("server_id", $selected); - - /* show login screen */ - $smarty->display (get_template_path('headers.tpl')); - $smarty->assign ("PHPSESSID", session_id()); - if (isset($_SESSION['errors'])){ - $smarty->assign("errors", $_SESSION['errors']); - } - if ($error_collector != ""){ - $smarty->assign("php_errors", $error_collector.""); - } else { - $smarty->assign("php_errors", ""); - } - - $smarty->display(get_template_path('login.tpl')); - exit(); -} - +displayLogin(); // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: diff --git a/html/main.php b/html/main.php index 212707878..e43f2aaeb 100644 --- a/html/main.php +++ b/html/main.php @@ -100,7 +100,6 @@ if(empty($_SESSION['_LAST_PAGE_REQUEST'])){ header ("Location: logout.php"); exit; } -// echo "Session was ".$request_time." s inactive"; $_SESSION['_LAST_PAGE_REQUEST'] = time(); } @@ -157,8 +156,7 @@ $plist= $_SESSION['plist']; /* Check for register globals */ if (isset($global_check) && $config->data['MAIN']['FORCEGLOBALS'] == 'true'){ - print_red (_("Register globals is on. GOsa will refuse to login unless this is fixed by an administrator.")); - echo $_SESSION['errors']; + echo _("FATAL: Register globals is on. GOsa will refuse to login unless this is fixed by an administrator."); gosa_log ("Register globals is on. For security reasons, this should be turned off."); session_destroy (); exit (); @@ -335,8 +333,7 @@ if (isset ($_SESSION['post_cnt'])){ if (is_file("$plugin_dir/main.inc")){ require_once ("$plugin_dir/main.inc"); } else { - print_red(sprintf(_("Can't find any plugin definitions for plugin '%s'!"), $plug)); - echo $_SESSION['errors']; + echo sprintf(_("FATAL: Can't find any plugin definitions for plugin '%s'!"), $plug); exit(); } @@ -355,8 +352,7 @@ if (is_file("$plugin_dir/main.inc")){ } } -/* Print_out last ErrorMessage repeated string. - */ +/* Print_out last ErrorMessage repeated string. */ print_red(NULL); $smarty->assign("contents", $display); diff --git a/ihtml/themes/default/login.tpl b/ihtml/themes/default/login.tpl index 7c771cb1d..2f8c0dbf6 100644 --- a/ihtml/themes/default/login.tpl +++ b/ihtml/themes/default/login.tpl @@ -1,7 +1,6 @@ {* GOsa login - smarty template *} {$php_errors} -{$errors}
@@ -22,6 +21,7 @@
+ {$errors}
diff --git a/include/class_config.inc b/include/class_config.inc index 6d028a11b..88754e069 100644 --- a/include/class_config.inc +++ b/include/class_config.inc @@ -193,9 +193,11 @@ class config { /* Check for connection */ if (is_null($this->ldap) || (is_int($this->ldap) && $this->ldap == 0)){ + $smarty= get_smarty(); print_red (_("Can't bind to LDAP. Please contact the system administrator.")); - echo $_SESSION['errors']; - exit; + $smarty->display (get_template_path('headers.tpl')); + echo ''.$_SESSION['errors'].''; + exit(); } if (!isset($_SESSION['size_limit'])){ diff --git a/include/functions.inc b/include/functions.inc index 8588391b8..d6518ba90 100644 --- a/include/functions.inc +++ b/include/functions.inc @@ -295,12 +295,8 @@ function ldap_init ($server, $base, $binddn='', $pass='') /* Sadly we've no proper return values here. Use the error message instead. */ if (!preg_match("/Success/i", $ldap->error)){ - print_red(sprintf(_("Error when connecting the LDAP. Server said '%s'."), - $ldap->get_error())); - echo $_SESSION['errors']; - - /* Hard error. We'd like to use the LDAP, anyway... */ - exit; + echo sprintf(_("FATAL: Error when connecting the LDAP. Server said '%s'."), $ldap->get_error())); + exit(); } /* Preset connection base to $base and return to caller */ @@ -317,8 +313,10 @@ function ldap_login_user ($username, $password) $ldap = $config->get_ldap_link(); if (!preg_match("/Success/i", $ldap->error)){ print_red(sprintf(_("User login failed. LDAP server said '%s'."), $ldap->get_error())); - echo $_SESSION['errors']; - exit; + $smarty= get_smarty(); + $smarty->display(get_template_path('headers.tpl')); + echo "".$_SESSION['errors'].""; + exit(); } $ldap->cd($config->current['BASE']); $ldap->search("(&(uid=$username)(objectClass=gosaAccount))", array("uid")); -- 2.30.2