Continuing on sql modification for consistency + Bugfixes
This commit is contained in:
parent
5bf955c998
commit
391bb4a50d
|
@ -49,7 +49,7 @@ if (!$r=$mysql->get_mysql_details($id)) {
|
||||||
<hr id="topbar"/>
|
<hr id="topbar"/>
|
||||||
<br />
|
<br />
|
||||||
<?php
|
<?php
|
||||||
if ($error) {
|
if (isset($error) && $error) {
|
||||||
echo "<p class=\"error\">$error</p><p> </p>";
|
echo "<p class=\"error\">$error</p><p> </p>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ if (!$r=$mysql->get_mysql_details($id)) {
|
||||||
<hr id="topbar"/>
|
<hr id="topbar"/>
|
||||||
<br />
|
<br />
|
||||||
<?php
|
<?php
|
||||||
if ($error) {
|
if (isset($error) && $error) {
|
||||||
echo "<p class=\"error\">$error</p><p> </p>";
|
echo "<p class=\"error\">$error</p><p> </p>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ if (!$quota->cancreate("mysql_users")) {
|
||||||
<?php
|
<?php
|
||||||
if (isset($error) && $error) {
|
if (isset($error) && $error) {
|
||||||
echo "<p class=\"error\">$error</p>";
|
echo "<p class=\"error\">$error</p>";
|
||||||
if ($fatal) {
|
if (isset($fatal) && $fatal) {
|
||||||
?>
|
?>
|
||||||
<?php include_once("foot.php"); ?>
|
<?php include_once("foot.php"); ?>
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,6 @@ if (isset($error) && $error) {
|
||||||
|
|
||||||
if ($r) {
|
if ($r) {
|
||||||
|
|
||||||
echo "<p>"._("help_sql_users_rights_ok")."</p>";
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<form method="post" action="sql_users_dorights.php">
|
<form method="post" action="sql_users_dorights.php">
|
||||||
|
|
|
@ -131,16 +131,13 @@ class m_mysql {
|
||||||
* @return array returns an associative array as follow : <br>
|
* @return array returns an associative array as follow : <br>
|
||||||
* "db" => database name "bck" => backup mode for this db
|
* "db" => database name "bck" => backup mode for this db
|
||||||
* "dir" => Backup folder.
|
* "dir" => Backup folder.
|
||||||
* Returns FALSE if the user has no database.
|
* Returns an array (empty) if no databases
|
||||||
*/
|
*/
|
||||||
function get_dblist() {
|
function get_dblist() {
|
||||||
global $db,$err,$bro,$cuid;
|
global $db,$err,$bro,$cuid;
|
||||||
$err->log("mysql","get_dblist");
|
$err->log("mysql","get_dblist");
|
||||||
|
$db->free();
|
||||||
$db->query("SELECT login,pass,db, bck_mode, bck_dir FROM db WHERE uid='$cuid' ORDER BY db;");
|
$db->query("SELECT login,pass,db, bck_mode, bck_dir FROM db WHERE uid='$cuid' ORDER BY db;");
|
||||||
if (!$db->num_rows()) {
|
|
||||||
$err->raise("mysql",11);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$c=array();
|
$c=array();
|
||||||
while ($db->next_record()) {
|
while ($db->next_record()) {
|
||||||
list($dbu,$dbn)=split_mysql_database_name($db->f("db"));
|
list($dbu,$dbn)=split_mysql_database_name($db->f("db"));
|
||||||
|
@ -247,10 +244,8 @@ class m_mysql {
|
||||||
$err->log("mysql","add_db_succes",$dbn);
|
$err->log("mysql","add_db_succes",$dbn);
|
||||||
// Ok, database does not exist, quota is ok and dbname is compliant. Let's proceed
|
// Ok, database does not exist, quota is ok and dbname is compliant. Let's proceed
|
||||||
$db->query("INSERT INTO db (uid,login,pass,db,bck_mode) VALUES ('$cuid','$myadm','$password','$dbname',0);");
|
$db->query("INSERT INTO db (uid,login,pass,db,bck_mode) VALUES ('$cuid','$myadm','$password','$dbname',0);");
|
||||||
#TODO escape dbname to avoid wildcard '_'
|
$dbname=str_replace('_','\_',$dbname);
|
||||||
die();
|
$this->grant($dbname,$myadm,"ALL PRIVILEGES",$password);
|
||||||
print_r("GRANT ALL PRIVILEGES ON `".$dbname."`.* TO '".$myadm."'@".$this->dbus->Host." IDENTIFIED BY '".addslashes($password)."'");
|
|
||||||
$this->dbus->query("GRANT ALL PRIVILEGES ON `".addslashes($dbname)."`.* TO '".$myadm."'@".$this->dbus->Host." IDENTIFIED BY '".addslashes($password)."'");
|
|
||||||
$this->dbus->query("FLUSH PRIVILEGES;");
|
$this->dbus->query("FLUSH PRIVILEGES;");
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -369,7 +364,55 @@ die();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function used to grant SQL rights to users:
|
||||||
|
* @base :database
|
||||||
|
* @user : database user
|
||||||
|
* @rights : rights to apply ( optional, every rights apply given if missing
|
||||||
|
* @pass : user password ( optional, if not given the pass stays the same, else it takes the new value )
|
||||||
|
* @table : sql tables to apply rights
|
||||||
|
**/
|
||||||
|
function grant($base,$user,$rights=null,$pass=null,$table='*'){
|
||||||
|
global $err,$db;
|
||||||
|
$err->log("mysql","grant");
|
||||||
|
if(!preg_match("#^[0-9a-z\_]*$#",$base)){
|
||||||
|
$err->raise("mysql",2);
|
||||||
|
return false;
|
||||||
|
}elseif(!$db->query("select db from db where db='$base';")){
|
||||||
|
$err->raise("mysql",10);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($rights==null){
|
||||||
|
$rights='ALL PRIVILEGES';
|
||||||
|
}elseif(!preg_match("#^[a-zA-Z\,]*$#",$rights)){
|
||||||
|
$err->raise("mysql",3);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!preg_match("#^[0-9a-z\_]*$#",$user)) {
|
||||||
|
$err->raise("mysql",5);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(!$db->query("select name from dbusers where name='".$user."' ;")){
|
||||||
|
$err->raise("mysql",6);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$grant="grant ".$rights." on `".$base."`.".$table." to '".$user."'@'".$this->dbus->Host."'" ;
|
||||||
|
|
||||||
|
if($pass){
|
||||||
|
$grant .= " identified by '".$pass."';";
|
||||||
|
}else{
|
||||||
|
$grant .= ";";
|
||||||
|
}
|
||||||
|
if(!$this->dbus->query($grant)){
|
||||||
|
$err->raise("mysql",6);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
|
@ -509,7 +552,7 @@ die();
|
||||||
}
|
}
|
||||||
|
|
||||||
// We create the user account (the "file" right is the only one we need globally to be able to use load data into outfile)
|
// 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->dbus->Host." IDENTIFIED BY '$pass';");
|
$this->grant("*",$user,"FILE",$pass);
|
||||||
// We add him to the user table
|
// We add him to the user table
|
||||||
$db->query("INSERT INTO dbusers (uid,name,enable) VALUES($cuid,'$user','ACTIVATED');");
|
$db->query("INSERT INTO dbusers (uid,name,enable) VALUES($cuid,'$user','ACTIVATED');");
|
||||||
return true;
|
return true;
|
||||||
|
@ -525,7 +568,7 @@ die();
|
||||||
**/
|
**/
|
||||||
function change_user_password($usern,$password,$passconf) {
|
function change_user_password($usern,$password,$passconf) {
|
||||||
global $db,$err,$quota,$mem,$cuid,$admin;
|
global $db,$err,$quota,$mem,$cuid,$admin;
|
||||||
$err->log("mysql","add_user",$usern);
|
$err->log("mysql","change_user_pass",$usern);
|
||||||
|
|
||||||
$usern=trim($usern);
|
$usern=trim($usern);
|
||||||
$user=addslashes($mem->user["login"]."_".$usern);
|
$user=addslashes($mem->user["login"]."_".$usern);
|
||||||
|
@ -541,7 +584,7 @@ die();
|
||||||
return false; // The error has been raised by checkPolicy()
|
return false; // The error has been raised by checkPolicy()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->dbus->query("SET PASSWORD FOR ".$user."@".$this->dbus->Host." = PASSWORD(".$pass.")");
|
$this->dbus->query("SET PASSWORD FOR ".$user."@".$this->dbus->Host." = PASSWORD('".$pass."')");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -589,8 +632,8 @@ die();
|
||||||
$err->log("mysql","get_user_dblist");
|
$err->log("mysql","get_user_dblist");
|
||||||
|
|
||||||
$r=array();
|
$r=array();
|
||||||
|
$db->free();
|
||||||
$dblist=$this->get_dblist();
|
$dblist=$this->get_dblist();
|
||||||
|
|
||||||
for ( $i=0 ; $i<count($dblist) ; $i++ ) {
|
for ( $i=0 ; $i<count($dblist) ; $i++ ) {
|
||||||
$this->dbus->query("SELECT Db, Select_priv, Insert_priv, Update_priv, Delete_priv, Create_priv, Drop_priv, References_priv, Index_priv, Alter_priv, Create_tmp_table_priv, Lock_tables_priv FROM mysql.db WHERE User='".$mem->user["login"].($user?"_":"").$user."' AND Host='".$this->dbus->Host."' AND Db='".$dblist[$i]["db"]."';");
|
$this->dbus->query("SELECT Db, Select_priv, Insert_priv, Update_priv, Delete_priv, Create_priv, Drop_priv, References_priv, Index_priv, Alter_priv, Create_tmp_table_priv, Lock_tables_priv FROM mysql.db WHERE User='".$mem->user["login"].($user?"_":"").$user."' AND Host='".$this->dbus->Host."' AND Db='".$dblist[$i]["db"]."';");
|
||||||
if ($this->dbus->next_record())
|
if ($this->dbus->next_record())
|
||||||
|
@ -662,7 +705,7 @@ die();
|
||||||
$this->dbus->query("REVOKE ALL PRIVILEGES ON $dbname.* FROM '$usern'@'".$this->dbus->Host."';");
|
$this->dbus->query("REVOKE ALL PRIVILEGES ON $dbname.* FROM '$usern'@'".$this->dbus->Host."';");
|
||||||
if( $strrights ){
|
if( $strrights ){
|
||||||
$strrights=substr($strrights,0,strlen($strrights)-1);
|
$strrights=substr($strrights,0,strlen($strrights)-1);
|
||||||
$this->dbus->query("GRANT $strrights ON $dbname.* TO '$usern'@'".$this->dbus->Host."';");
|
$this->grant($dbname,$usern,$strrights);
|
||||||
}
|
}
|
||||||
$this->dbus->query("FLUSH PRIVILEGES");
|
$this->dbus->query("FLUSH PRIVILEGES");
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@ -711,12 +754,21 @@ die();
|
||||||
$password=$db->f("password");
|
$password=$db->f("password");
|
||||||
}else{
|
}else{
|
||||||
$myadm=$mem->user["login"]."_myadm";
|
$myadm=$mem->user["login"]."_myadm";
|
||||||
$password="kikoulol";
|
$chars = "234567890abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
|
$i = 0;
|
||||||
|
$password = "";
|
||||||
|
while ($i <= 8) {
|
||||||
|
$password .= $chars{mt_rand(0,strlen($chars))};
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
$db->query("INSERT INTO dbusers (uid,name,password,enable) VALUES ('$cuid','$myadm','$password','ADMIN');");
|
$db->query("INSERT INTO dbusers (uid,name,password,enable) VALUES ('$cuid','$myadm','$password','ADMIN');");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
/** Hook function called when a user is deleted.
|
/** Hook function called when a user is deleted.
|
||||||
* AlternC's standard function that delete a member
|
* AlternC's standard function that delete a member
|
||||||
|
|
|
@ -94,7 +94,7 @@ if [ "$mount_point" != "$quota_activation" ]
|
||||||
then
|
then
|
||||||
db_input critical alternc/quotauninstalled || true
|
db_input critical alternc/quotauninstalled || true
|
||||||
db_go
|
db_go
|
||||||
db_reset alternc/puotauninstalled || true
|
db_reset alternc/quotauninstalled || true
|
||||||
db_fset alternc/quotauninstalled "seen" "false" || true
|
db_fset alternc/quotauninstalled "seen" "false" || true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,15 @@
|
||||||
|
alternc (1.1+nmu4) stable; urgency=low
|
||||||
|
|
||||||
|
* SQL Modification
|
||||||
|
* MySQL tables used for Alternc users databases modified (mysql.sql)
|
||||||
|
* Adding a special phpmyadmin user.
|
||||||
|
* Users can now create databases en databases users independently
|
||||||
|
( no need to create a first database to create a user anymore)
|
||||||
|
* Bugfixes in installation process
|
||||||
|
|
||||||
|
|
||||||
|
-- squidly <squidly@nnx.com> Tue, 14 Aug 2012 11:21:14 +0200
|
||||||
|
|
||||||
alternc (1.1+nmu3) stable; urgency=low
|
alternc (1.1+nmu3) stable; urgency=low
|
||||||
|
|
||||||
* Templating full configuration of postfix & dovecot
|
* Templating full configuration of postfix & dovecot
|
||||||
|
|
|
@ -106,7 +106,7 @@ CREATE TABLE IF NOT EXISTS db (
|
||||||
bck_history tinyint(3) unsigned NOT NULL default '0', # Nombre de backup conserver ?
|
bck_history tinyint(3) unsigned NOT NULL default '0', # Nombre de backup conserver ?
|
||||||
bck_gzip tinyint(3) unsigned NOT NULL default '0', # Faut-il compresser les backups ?
|
bck_gzip tinyint(3) unsigned NOT NULL default '0', # Faut-il compresser les backups ?
|
||||||
bck_dir varchar(255) NOT NULL default '', # O stocke-t-on les backups sql ?
|
bck_dir varchar(255) NOT NULL default '', # O stocke-t-on les backups sql ?
|
||||||
PRIMARY KEY uid (uid)
|
PRIMARY KEY id (id)
|
||||||
) TYPE=MyISAM COMMENT='Bases MySQL des membres';
|
) TYPE=MyISAM COMMENT='Bases MySQL des membres';
|
||||||
|
|
||||||
--
|
--
|
||||||
|
|
Loading…
Reference in New Issue