fixing error messages in MySQL and Mem

This commit is contained in:
Benjamin Sonntag 2012-10-18 07:36:37 +00:00
parent a7a43f6bee
commit e865f4e906
2 changed files with 35 additions and 39 deletions

View File

@ -357,7 +357,7 @@ class m_mem {
return false; return false;
} }
if ($newpass!=$newpass2) { if ($newpass!=$newpass2) {
$err->raise("mem",_("The new passwords are differents, please retry.")); $err->raise("mem",_("The new passwords are differents, please retry"));
return false; return false;
} }
$db->query("SELECT login FROM membres WHERE uid='$cuid';"); $db->query("SELECT login FROM membres WHERE uid='$cuid';");

View File

@ -148,7 +148,7 @@ class m_mysql {
$err->log("mysql","php_myadmin_connect"); $err->log("mysql","php_myadmin_connect");
$db->query("SELECT name,password FROM dbusers WHERE uid='$cuid' and enable='ADMIN';"); $db->query("SELECT name,password FROM dbusers WHERE uid='$cuid' and enable='ADMIN';");
if (!$db->num_rows()) { if (!$db->num_rows()) {
$err->raise("mysql",_("Cannot connect to PhpMyadmin")); $err->raise("mysql",_("Cannot connect to PhpMyAdmin"));
return false; return false;
} }
$db->next_record(); $db->next_record();
@ -189,7 +189,7 @@ class m_mysql {
$size=$this->get_db_size($dbname); $size=$this->get_db_size($dbname);
$db->query("SELECT login,pass,db, bck_mode, bck_gzip, bck_dir, bck_history FROM db WHERE uid='$cuid' AND db='$dbname';"); $db->query("SELECT login,pass,db, bck_mode, bck_gzip, bck_dir, bck_history FROM db WHERE uid='$cuid' AND db='$dbname';");
if (!$db->num_rows()) { if (!$db->num_rows()) {
$err->raise("mysql",_("The database %s not found"),$dbn); $err->raise("mysql",_("Database %s not found"),$dbn);
return array("enabled"=>false); return array("enabled"=>false);
} }
$c=array(); $c=array();
@ -216,7 +216,7 @@ class m_mysql {
$err->log("mysql","add_db",$dbn); $err->log("mysql","add_db",$dbn);
$password_user=""; $password_user="";
if (!$quota->cancreate("mysql")) { if (!$quota->cancreate("mysql")) {
$err->raise("mysql",_("Your databases quota is over. You cannot create more databases.")); $err->raise("mysql",_("Your databases quota is over. You cannot create more databases"));
return false; return false;
} }
$pos=strpos($dbn,'_'); $pos=strpos($dbn,'_');
@ -228,18 +228,18 @@ class m_mysql {
$dbn=$dbncomp[1]; $dbn=$dbncomp[1];
} }
if (!preg_match("#^[0-9a-z]*$#",$dbn)) { if (!preg_match("#^[0-9a-z]*$#",$dbn)) {
$err->raise("mysql",_("Database name can only only letters and numbers.")); $err->raise("mysql",_("Database name can contain only letters and numbers"));
return false; return false;
} }
if (strlen($dbname) > 64) { if (strlen($dbname) > 64) {
$err->raise("mysql",_("Database name cannot exceed 64 characters.")); $err->raise("mysql",_("Database name cannot exceed 64 characters"));
return false; return false;
} }
$db->query("SELECT * FROM db WHERE db='$dbname';"); $db->query("SELECT * FROM db WHERE db='$dbname';");
if ($db->num_rows()) { if ($db->num_rows()) {
$err->raise("mysql",_("Database %s already exists."),$dbn); $err->raise("mysql",_("Database %s already exists"),$dbn);
return false; return false;
} }
@ -257,7 +257,7 @@ class m_mysql {
$myadm=$db->f("name"); $myadm=$db->f("name");
$password=$db->f("password"); $password=$db->f("password");
}else{ }else{
$err->raise("mysql",_("There is a problem with the special PhpMyadmin user. Contact the administrator."));//FIXME error code $err->raise("mysql",_("There is a problem with the special PhpMyAdmin user. Contact the administrator"));
return false; return false;
} }
@ -276,7 +276,7 @@ class m_mysql {
return true; return true;
} else { } else {
$err->log("mysql","add_db",$dbn); $err->log("mysql","add_db",$dbn);
$err->raise("mysql",_("An error occured. The database could not be created.")); $err->raise("mysql",_("An error occured. The database could not be created"));
return false; return false;
} }
} }
@ -294,7 +294,7 @@ class m_mysql {
$dbname=addslashes($dbn); $dbname=addslashes($dbn);
$db->query("SELECT uid FROM db WHERE db='$dbname';"); $db->query("SELECT uid FROM db WHERE db='$dbname';");
if (!$db->num_rows()) { if (!$db->num_rows()) {
$err->raise("mysql",_("The database was not found. Suppression failed.")); $err->raise("mysql",_("The database was not found. I can't delete it"));
return false; return false;
} }
$db->next_record(); $db->next_record();
@ -336,13 +336,13 @@ class m_mysql {
$dbn=$dbncomp[1]; $dbn=$dbncomp[1];
} }
if (!preg_match("#^[0-9a-z]*$#",$dbn)) { if (!preg_match("#^[0-9a-z]*$#",$dbn)) {
$err->raise("mysql",_("Database name can contain only letters and numbers.")); $err->raise("mysql",_("Database name can contain only letters and numbers"));
return false; return false;
} }
printvar("SELECT * FROM db WHERE uid='$cuid' AND db='$dbname';"); printvar("SELECT * FROM db WHERE uid='$cuid' AND db='$dbname';");
$db->query("SELECT * FROM db WHERE uid='$cuid' AND db='$dbname';"); $db->query("SELECT * FROM db WHERE uid='$cuid' AND db='$dbname';");
if (!$db->num_rows()) { if (!$db->num_rows()) {
$err->raise("mysql",_("Database %s not found."),$dbn); $err->raise("mysql",_("Database %s not found"),$dbn);
return false; return false;
} }
$db->next_record(); $db->next_record();
@ -355,11 +355,11 @@ class m_mysql {
if (!$bck_mode) if (!$bck_mode)
$bck_mode="0"; $bck_mode="0";
if (!$bck_history) { if (!$bck_history) {
$err->raise("mysql",_("You have to choose how many backups you want to keep.")); $err->raise("mysql",_("You have to choose how many backups you want to keep"));
return false; return false;
} }
if (($bck_dir=$bro->convertabsolute($bck_dir,0))===false) { // return a full path or FALSE if (($bck_dir=$bro->convertabsolute($bck_dir,0))===false) { // return a full path or FALSE
$err->raise("mysql",_("Directory does not exists.")); $err->raise("mysql",_("Directory does not exist"));
return false; return false;
} }
$db->query("UPDATE db SET bck_mode='$bck_mode', bck_history='$bck_history', bck_gzip='$bck_gzip', bck_dir='$bck_dir' WHERE uid='$cuid' AND db='$dbname';"); $db->query("UPDATE db SET bck_mode='$bck_mode', bck_history='$bck_history', bck_gzip='$bck_gzip', bck_dir='$bck_dir' WHERE uid='$cuid' AND db='$dbname';");
@ -377,19 +377,19 @@ class m_mysql {
$err->log("mysql","put_mysql_details"); $err->log("mysql","put_mysql_details");
$db->query("SELECT * FROM db WHERE uid='$cuid';"); $db->query("SELECT * FROM db WHERE uid='$cuid';");
if (!$db->num_rows()) { if (!$db->num_rows()) {
$err->raise("mysql",_("Database not found.")); $err->raise("mysql",_("Database not found"));
return false; return false;
} }
$db->next_record(); $db->next_record();
$login=$db->f("login"); $login=$db->f("login");
if (!$password) { if (!$password) {
$err->raise("mysql",_("You have to set a new password.")); $err->raise("mysql",_("The password is mandatory"));
return false; return false;
} }
if (strlen($password)>16) { if (strlen($password)>16) {
$err->raise("mysql",_("Mysql password cannot exceed 16 characters.")); $err->raise("mysql",_("MySQL password cannot exceed 16 characters"));
return false; return false;
} }
@ -419,28 +419,28 @@ class m_mysql {
$err->log("mysql","grant",$base."-".$user); $err->log("mysql","grant",$base."-".$user);
if(!preg_match("#^[0-9a-z_\\*\\\\]*$#",$base)){ if(!preg_match("#^[0-9a-z_\\*\\\\]*$#",$base)){
$err->raise("mysql",_("Database name can only contain letters and numbers.")); $err->raise("mysql",_("Database name can contain only letters and numbers"));
return false; return false;
}elseif(!$db->query("select db from db where db='$base';")){ } elseif (!$db->query("select db from db where db='$base';")){
$err->raise("mysql","query base fail"); $err->raise("mysql","Database not found");
return false; return false;
} }
if($rights==null){ if($rights==null){
$rights='ALL PRIVILEGES'; $rights='ALL PRIVILEGES';
}elseif(!preg_match("#^[a-zA-Z,\s]*$#",$rights)){ }elseif(!preg_match("#^[a-zA-Z,\s]*$#",$rights)){
$err->raise("mysql",_("Databases rights are not correct.")); $err->raise("mysql",_("Databases rights are not correct"));
return false; return false;
} }
if(!preg_match("#^[0-9a-z_-]*$#",$user)) { if (!preg_match("#^[0-9a-z]#",$user)) {
$err->raise("mysql",_("Database username can contain only letters numbers hyphen and underscores")); $err->raise("mysql",_("The username can contain only letters and numbers."));
return false; return false;
} }
$db->query("select name from dbusers where name='".$user."' ;"); $db->query("select name from dbusers where name='".$user."' ;");
if(!$db->num_rows()){ if(!$db->num_rows()){
$err->raise("mysql","Database user not found."); $err->raise("mysql","Database user not found");
return false; return false;
} }
if($rights == "FILE"){ if($rights == "FILE"){
@ -455,7 +455,7 @@ class m_mysql {
$grant .= ";"; $grant .= ";";
} }
if(!$this->dbus->query($grant)){ if(!$this->dbus->query($grant)){
$err->raise("mysql",_("Could not grant rights.")); $err->raise("mysql",_("Could not grant rights"));
return false; return false;
} }
return true; return true;
@ -477,7 +477,7 @@ class m_mysql {
return false; return false;
} }
if (!($fi=$bro->convertabsolute($file,0))) { if (!($fi=$bro->convertabsolute($file,0))) {
$err->raise("mysql",_("File not found.")); $err->raise("mysql",_("File not found"));
return false; return false;
} }
if (substr($fi,-3)==".gz") { if (substr($fi,-3)==".gz") {
@ -655,31 +655,31 @@ class m_mysql {
$pass=addslashes($password); $pass=addslashes($password);
if (!$usern) { if (!$usern) {
$err->raise("mysql",_("You have to input a username.")); $err->raise("mysql",_("The username is mandatory"));
return false; return false;
} }
if (!$pass) { if (!$pass) {
$err->raise("mysql",_("You have to input a password.")); $err->raise("mysql",_("The password is mandatory"));
return false; return false;
} }
if (!preg_match("#^[0-9a-z]#",$usern)) { if (!preg_match("#^[0-9a-z]#",$usern)) {
$err->raise("mysql",_("The username can contain only letters and numbers.")); $err->raise("mysql",_("The username can contain only letters and numbers"));
return false; return false;
} }
// We check the length of the COMPLETE username, not only the part after _ // We check the length of the COMPLETE username, not only the part after _
if (strlen($user) > 16) { if (strlen($user) > 16) {
$err->raise("mysql",_("Mysql username cannot exceed 16 characters.")); $err->raise("mysql",_("MySQL username cannot exceed 16 characters"));
return false; return false;
} }
$db->query("SELECT * FROM dbusers WHERE name='$user';"); $db->query("SELECT * FROM dbusers WHERE name='$user';");
if ($db->num_rows()) { if ($db->num_rows()) {
$err->raise("mysql",_("The database user was not found.")); $err->raise("mysql",_("The database user was not found"));
return false; return false;
} }
if ($password != $passconf || !$password) { if ($password != $passconf || !$password) {
$err->raise("mysql",_("The passwords do not match.")); $err->raise("mysql",_("The passwords do not match"));
return false; return false;
} }
@ -711,13 +711,9 @@ class m_mysql {
$usern=trim($usern); $usern=trim($usern);
$user=addslashes($usern); $user=addslashes($usern);
if(!preg_match("#^[0-9a-zA-Z_]*$#",$password)) {
$err->raise("mysql",_("Database password can contain only letters numbers and underscore."));
return false;
}
$pass=addslashes($password); $pass=addslashes($password);
if ($password != $passconf || !$password) { if ($password != $passconf || !$password) {
$err->raise("mysql",_("The passwords do not match.")); $err->raise("mysql",_("The passwords do not match"));
return false; return false;
} }
@ -744,12 +740,12 @@ class m_mysql {
global $db,$err,$mem,$cuid,$L_MYSQL_DATABASE; global $db,$err,$mem,$cuid,$L_MYSQL_DATABASE;
$err->log("mysql","del_user",$user); $err->log("mysql","del_user",$user);
if (!preg_match("#^[0-9a-z]#",$user)) { if (!preg_match("#^[0-9a-z]#",$user)) {
$err->raise("mysql",_("The username can contain only letters and numbers.")); $err->raise("mysql",_("The username can contain only letters and numbers"));
return false; return false;
} }
$db->query("SELECT name FROM dbusers WHERE name='".$user."' and enable not in ('ADMIN','HIDDEN');"); $db->query("SELECT name FROM dbusers WHERE name='".$user."' and enable not in ('ADMIN','HIDDEN');");
if (!$db->num_rows()) { if (!$db->num_rows()) {
$err->raise("mysql",_("The username was not found.")); $err->raise("mysql",_("The username was not found"));
return false; return false;
} }
$db->next_record(); $db->next_record();