[feladat @ 226]
authorrejo
Tue, 01 Apr 2008 19:12:08 +0000
changeset 123 0aa6b2cf8006
parent 122 2e2cc9cfa115
child 124 7a9d41dbe319
[feladat @ 226] Added a check for a number of database related settings in the configuration. If not set, the interface now will return a clean error message. This closes ticket:28.
docs/i18n-template-php.pot
inc/database.inc.php
inc/error.inc.php
locale/nl_NL/LC_MESSAGES/messages.mo
locale/nl_NL/LC_MESSAGES/nl.po
--- a/docs/i18n-template-php.pot	Mon Mar 31 21:57:24 2008 +0000
+++ b/docs/i18n-template-php.pot	Tue Apr 01 19:12:08 2008 +0000
@@ -673,3 +673,19 @@
 #: inc/users.inc.php:368
 msgid "Password has been changed, please login."
 msgstr ""
+
+msgid "No database name has been set in config.inc.php."
+msgstr ""
+
+msgid "No database host has been set in config.inc.php."
+msgstr ""
+
+msgid "No database username has been set in config.inc.php."
+msgstr ""
+
+msgid "No database password has been set in config.inc.php."
+msgstr ""
+
+msgid "No or unknown database type has been set in config.inc.php."
+msgstr ""
+
--- a/inc/database.inc.php	Mon Mar 31 21:57:24 2008 +0000
+++ b/inc/database.inc.php	Tue Apr 01 19:12:08 2008 +0000
@@ -42,13 +42,47 @@
 	global $dbhost;
 	global $dbdatabase;
 	global $sql_regexp;
-
+	
+	if (!(isset($dbuser) && $dbuser != "")) {
+		include_once("header.inc.php");
+		error(ERR_DB_NO_DB_USER);
+		include_once("footer.inc.php");
+		exit;
+	}
+		
+	if (!(isset($dbpass) && $dbpass != "")) {
+		include_once("header.inc.php");
+		error(ERR_DB_NO_DB_PASS);
+		include_once("footer.inc.php");
+		exit;
+	}
+		
+	if (!(isset($dbhost) && $dbhost != "")) {
+		include_once("header.inc.php");
+		error(ERR_DB_NO_DB_HOST);
+		include_once("footer.inc.php");
+		exit;
+	}
+		
+	if (!(isset($dbdatabase) && $dbdatabase != "")) {
+		include_once("header.inc.php");
+		error(ERR_DB_NO_DB_NAME);
+		include_once("footer.inc.php");
+		exit;
+	}
+		
+	if ((!isset($dbdsntype)) || (!($dbdsntype == "mysql" || $dbdsntype == "pgsql"))) {
+		include_once("header.inc.php");
+		error(ERR_DB_NO_DB_TYPE);
+		include_once("footer.inc.php");
+		exit;
+	}
+		
 	$dsn = "$dbdsntype://$dbuser:$dbpass@$dbhost/$dbdatabase";
 	$db = MDB2::connect($dsn);
 	$db->setOption('portability', MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_EMPTY_TO_NULL);
 
-	if (MDB2::isError($db))
-	{
+	if (MDB2::isError($db)) {
 		// Error handling should be put.
 		error(MYSQL_ERROR_FATAL, $db->getMessage());
 	}
@@ -60,17 +94,12 @@
 	$mysql_pass = $dsn = '';
 
 	// Add support for regular expressions in both MySQL and PostgreSQL
-	if ( $dbdsntype == "mysql" ) 
-	{
+	if ( $dbdsntype == "mysql" ) {
 		$sql_regexp = "REGEXP";
-	} 
-	elseif ( $dbdsntype == "pgsql" ) 
-	{
+	} elseif ( $dbdsntype == "pgsql" ) {
 		$sql_regexp = "~";
-	}
-	else
-	{
-		error(_('Unknown database type in inc/config.inc.php.'));
+	} else {
+		error(ERR_DB_NO_DB_TYPE);
 	};
 	return $db;
 }
--- a/inc/error.inc.php	Mon Mar 31 21:57:24 2008 +0000
+++ b/inc/error.inc.php	Tue Apr 01 19:12:08 2008 +0000
@@ -59,6 +59,13 @@
 define("ERR_UNKNOWN", _('Unknown error.'));
 define("ERR_INV_EMAIL", _('Enter a valid email address.'));
 
+/* DATABASE */
+define("ERR_DB_NO_DB_NAME", _('No database name has been set in config.inc.php.'));
+define("ERR_DB_NO_DB_HOST", _('No database host has been set in config.inc.php.'));
+define("ERR_DB_NO_DB_USER", _('No database username has been set in config.inc.php.'));
+define("ERR_DB_NO_DB_PASS", _('No database password has been set in config.inc.php.'));
+define("ERR_DB_NO_DB_TYPE", _('No or unknown database type has been set in config.inc.php.'));
+
 /* DNS */
 define("ERR_DNS_CONTENT", _('Your content field doesnt have a legit value.'));
 define("ERR_DNS_HOSTNAME", _('Invalid hostname.'));
Binary file locale/nl_NL/LC_MESSAGES/messages.mo has changed
--- a/locale/nl_NL/LC_MESSAGES/nl.po	Mon Mar 31 21:57:24 2008 +0000
+++ b/locale/nl_NL/LC_MESSAGES/nl.po	Tue Apr 01 19:12:08 2008 +0000
@@ -735,3 +735,17 @@
 msgid "User is allowed to edit existing permission templates."
 msgstr "Gebruiker mag permissie templates wijzigen."
 
+msgid "No database name has been set in config.inc.php."
+msgstr "Er is geen database naam opgegeven in config.inc.php."
+
+msgid "No database host has been set in config.inc.php."
+msgstr "Er is geen database hostnaam opgegeven in config.inc.php."
+
+msgid "No database username has been set in config.inc.php."
+msgstr "Er is geen database gebruikersnaam opgegeven in config.inc.php."
+
+msgid "No database password has been set in config.inc.php."
+msgstr "Er is geen database wachtwoord opgegeven in config.inc.php."
+
+msgid "No or unknown database type has been set in config.inc.php."
+msgstr "Er is geen of een onbekend database type opgegeven in config.inc.php."