" ;
if ($stdout) {
passthru($exe,$ret);
} else {
exec ($exe,$ret);
}
echo "
" ;
if ($ret != 0) {
return false ;
} else {
return true ;
}
}
/* ----------------------------------------------------------------- */
/** Get the size of a database
* @param $dbname name of the database
* @return integer database size
* @access private
*/
function get_db_size($dbname) {
global $db,$err;
$this->dbus->query("SHOW TABLE STATUS FROM `$dbname`;");
$size = 0;
while ($db->next_record()) {
$size += $db->f('Data_length') + $db->f('Index_length') + $db->f('Data_free');
}
return $size;
}
/* ------------------------------------------------------------ */
/**
* Returns the list of database users of an account
**/
function get_userslist() {
global $db,$err,$bro,$cuid;
$err->log("mysql","get_userslist");
$db->query("SELECT name FROM dbusers WHERE uid='$cuid' ORDER BY name;");
if (!$db->num_rows()) {
$err->raise("mysql",19);
return false;
}
$c=array();
while ($db->next_record()) {
$c[]=array("name"=>substr($db->f("name"),strpos($db->f("name"),"_")+1));
}
return $c;
}
/* ------------------------------------------------------------ */
/**
* Create a new user in MySQL rights tables
* @param $usern the username (we will add _[alternc-account] to it)
* @param $password The password for this username
* @param $passconf The password confirmation
* @return TRUE if the user has been created in MySQL or FALSE if an error occurred
**/
function add_user($usern,$password,$passconf) {
global $db,$err,$quota,$mem,$cuid,$admin;
$err->log("mysql","add_user",$usern);
$usern=trim($usern);
$user=addslashes($mem->user["login"]."_".$usern);
$pass=addslashes($password);
if (!$usern) {
$err->raise("mysql",21);
return false;
}
if (!$pass) {
$err->raise("mysql",20);
return false;
}
if (!$quota->cancreate("mysql_users")) {
$err->raise("mysql",13);
return false;
}
if (!ereg("^[0-9a-z]",$usern)) {
$err->raise("mysql",14);
return false;
}
// We check the length of the COMPLETE username, not only the part after _
if (strlen($user) > 16) {
$err->raise("mysql",15);
return false;
}
$db->query("SELECT * FROM dbusers WHERE name='$user';");
if ($db->num_rows()) {
$err->raise("mysql",16);
return false;
}
if ($password != $passconf || !$password) {
$err->raise("mysql",17);
return false;
}
// Check this password against the password policy using common API :
if (is_callable(array($admin,"checkPolicy"))) {
if (!$admin->checkPolicy("mysql",$user,$password)) {
return false; // The error has been raised by checkPolicy()
}
}
// We create the user account (the "file" right is the only one we need globally to be able to use load data into outfile)
$this->dbus->query("GRANT file ON *.* TO '$user'@'$this->client' IDENTIFIED BY '$pass';");
// We add him to the user table
$db->query("INSERT INTO dbusers (uid,name) VALUES($cuid,'$user');");
return true;
}
/* ------------------------------------------------------------ */
/**
* Change a user's MySQL password
* @param $usern the username
* @param $password The password for this username
* @param $passconf The password confirmation
* @return TRUE if the password has been changed in MySQL or FALSE if an error occurred
**/
function change_user_password($usern,$password,$passconf) {
global $db,$err,$quota,$mem,$cuid,$admin;
$err->log("mysql","add_user",$usern);
$usern=trim($usern);
$user=addslashes($mem->user["login"]."_".$usern);
$pass=addslashes($password);
if ($password != $passconf || !$password) {
$err->raise("mysql",17);
return false;
}
// Check this password against the password policy using common API :
if (is_callable(array($admin,"checkPolicy"))) {
if (!$admin->checkPolicy("mysql",$user,$password)) {
return false; // The error has been raised by checkPolicy()
}
}
$this->dbus->query("SET PASSWORD FOR '$user'@'$this->client' = PASSWORD('$pass')");
return true;
}
/* ------------------------------------------------------------ */
/**
* Delete a user in MySQL rights tables
* @param $user the username (we will add "[alternc-account]_" to it) to delete
* @return TRUE if the user has been deleted in MySQL or FALSE if an error occurred
**/
function del_user($user) {
global $db,$err,$mem,$cuid,$L_MYSQL_DATABASE;
$err->log("mysql","del_user",$user);
if (!ereg("^[0-9a-z]",$user)) {
$err->raise("mysql",14);
return false;
}
$db->query("SELECT name FROM dbusers WHERE name='".$mem->user["login"]."_$user';");
if (!$db->num_rows()) {
$err->raise("mysql",18);
return false;
}
$db->next_record();
$login=$db->f("name");
// Ok, database exists and dbname is compliant. Let's proceed
$this->dbus->query("REVOKE ALL PRIVILEGES ON *.* FROM '".$mem->user["login"]."_$user'@'$this->client';");
$this->dbus->query("DELETE FROM mysql.db WHERE User='".$mem->user["login"]."_$user' AND Host='$this->client';");
$this->dbus->query("DELETE FROM mysql.user WHERE User='".$mem->user["login"]."_$user' AND Host='$this->client';");
$this->dbus->query("FLUSH PRIVILEGES");
$this->dbus->query("DELETE FROM dbusers WHERE uid='$cuid' AND name='".$mem->user["login"]."_$user';");
return true;
}
/* ------------------------------------------------------------ */
/**
* Return the list of the database rights of user $user
* @param $user the username
* @return array An array of database name and rights
**/
function get_user_dblist($user) {
global $db,$err,$mem,$cuid,$L_MYSQL_DATABASE;
$err->log("mysql","get_user_dblist");
$r=array();
$dblist=$this->get_dblist();
for ( $i=0 ; $i