Changeset 2944
- Timestamp:
- 05/18/11 22:39:42 (2 years ago)
- File:
-
- 1 edited
-
alternc/trunk/bureau/class/m_mysql.php (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
alternc/trunk/bureau/class/m_mysql.php
r2943 r2944 89 89 // TODO BUG BUG BUG 90 90 // c'est pas étanche : $db se retrouve avec Database de $sql->dbu . Danger, faut comprendre pourquoi 91 $this->Database = "alternc"; 91 // Si on veux que ca marche, il faut Database=alternc. 92 $this->Database = "mysql"; 92 93 $this->HumanHostname = $human_hostname; 93 94 … … 97 98 98 99 class m_mysql { 99 var $dbu ;100 var $dbus; 100 101 101 102 /*---------------------------------------------------------------------------*/ … … 104 105 */ 105 106 function m_mysql() { 106 $this->dbu = new DBU_mysql();107 $this->dbus = new DBU_mysql(); 107 108 } 108 109 … … 218 219 $pa=addslashes($db->f("pass")); 219 220 } 220 if ($this->dbu ->query("CREATE DATABASE `$dbname`;")) {221 if ($this->dbus->query("CREATE DATABASE `$dbname`;")) { 221 222 // Ok, database does not exist, quota is ok and dbname is compliant. Let's proceed 222 223 $db->query("INSERT INTO db (uid,login,pass,db,bck_mode) VALUES ('$cuid','$lo','$pa','$dbname',0);"); 223 224 // give everything but GRANT on db.* 224 225 // we assume there's already a user 225 $this->dbu ->query("GRANT ALL PRIVILEGES ON `".$dbname."`.* TO '".$lo."'@'$this->client'");226 $this->dbus->query("GRANT ALL PRIVILEGES ON `".$dbname."`.* TO '".$lo."'@'$this->client'"); 226 227 return true; 227 228 } else { … … 253 254 // Ok, database exists and dbname is compliant. Let's proceed 254 255 $db->query("DELETE FROM db WHERE uid='$cuid' AND db='$dbname';"); 255 $this->dbu ->query("DROP DATABASE `$dbname`;");256 $this->dbus->query("DROP DATABASE `$dbname`;"); 256 257 $db->query("SELECT COUNT(*) AS cnt FROM db WHERE uid='$cuid';"); 257 258 $db->next_record(); 258 $this->dbu ->query("REVOKE ALL PRIVILEGES ON `".$dbname."`.* FROM '".$login."'@'$this->client'");259 if ($this->dbu ->f("cnt")==0) {260 $this->dbu ->query("DELETE FROM mysql.user WHERE User='".$login."';");261 $this->dbu ->query("FLUSH PRIVILEGES;");259 $this->dbus->query("REVOKE ALL PRIVILEGES ON `".$dbname."`.* FROM '".$login."'@'$this->client'"); 260 if ($this->dbus->f("cnt")==0) { 261 $this->dbus->query("DELETE FROM mysql.user WHERE User='".$login."';"); 262 $this->dbus->query("FLUSH PRIVILEGES;"); 262 263 } 263 264 return true; … … 343 344 // Update all the "pass" fields for this user : 344 345 $db->query("UPDATE db SET pass='$password' WHERE uid='$cuid';"); 345 $this->dbu ->query("SET PASSWORD FOR '$login'@'$this->client' = PASSWORD('$password')");346 $this->dbus->query("SET PASSWORD FOR '$login'@'$this->client' = PASSWORD('$password')"); 346 347 return true; 347 348 } … … 388 389 $db->query("INSERT INTO db (uid,login,pass,db) VALUES ('$cuid','".$login."','$password','".$dbname."');"); 389 390 // give everything but GRANT on $user.* 390 $this->dbu ->query("GRANT ALL PRIVILEGES ON `".$dbname."`.* TO '".$login."'@'$this->client' IDENTIFIED BY '".addslashes($password)."'");391 $this->dbu ->query("CREATE DATABASE `".$dbname."`;");391 $this->dbus->query("GRANT ALL PRIVILEGES ON `".$dbname."`.* TO '".$login."'@'$this->client' IDENTIFIED BY '".addslashes($password)."'"); 392 $this->dbus->query("CREATE DATABASE `".$dbname."`;"); 392 393 return true; 393 394 } … … 444 445 global $db,$err; 445 446 446 $this->dbu ->query("SHOW TABLE STATUS FROM `$dbname`;");447 $this->dbus->query("SHOW TABLE STATUS FROM `$dbname`;"); 447 448 $size = 0; 448 449 while ($db->next_record()) { … … 530 531 531 532 // We create the user account (the "file" right is the only one we need globally to be able to use load data into outfile) 532 $this->dbu ->query("GRANT file ON *.* TO '$user'@'$this->client' IDENTIFIED BY '$pass';");533 $this->dbus->query("GRANT file ON *.* TO '$user'@'$this->client' IDENTIFIED BY '$pass';"); 533 534 // We add him to the user table 534 535 $db->query("INSERT INTO dbusers (uid,name) VALUES($cuid,'$user');"); … … 563 564 } 564 565 565 $this->dbu ->query("SET PASSWORD FOR '$user'@'$this->client' = PASSWORD('$pass')");566 $this->dbus->query("SET PASSWORD FOR '$user'@'$this->client' = PASSWORD('$pass')"); 566 567 return true; 567 568 } … … 591 592 592 593 // Ok, database exists and dbname is compliant. Let's proceed 593 $this->dbu ->query("REVOKE ALL PRIVILEGES ON *.* FROM '".$mem->user["login"]."_$user'@'$this->client';");594 $this->dbu ->query("DELETE FROM mysql.db WHERE User='".$mem->user["login"]."_$user' AND Host='$this->client';");595 $this->dbu ->query("DELETE FROM mysql.user WHERE User='".$mem->user["login"]."_$user' AND Host='$this->client';");596 $this->dbu ->query("FLUSH PRIVILEGES");597 $this->dbu ->query("DELETE FROM dbusers WHERE uid='$cuid' AND name='".$mem->user["login"]."_$user';");594 $this->dbus->query("REVOKE ALL PRIVILEGES ON *.* FROM '".$mem->user["login"]."_$user'@'$this->client';"); 595 $this->dbus->query("DELETE FROM mysql.db WHERE User='".$mem->user["login"]."_$user' AND Host='$this->client';"); 596 $this->dbus->query("DELETE FROM mysql.user WHERE User='".$mem->user["login"]."_$user' AND Host='$this->client';"); 597 $this->dbus->query("FLUSH PRIVILEGES"); 598 $this->dbus->query("DELETE FROM dbusers WHERE uid='$cuid' AND name='".$mem->user["login"]."_$user';"); 598 599 return true; 599 600 } … … 614 615 615 616 for ( $i=0 ; $i<count($dblist) ; $i++ ) { 616 $this->dbu ->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->client' AND Db='".$dblist[$i]["db"]."';");617 if ($this->dbu ->next_record())618 $r[]=array("db"=>$dblist[$i]["name"], "select"=>$this->dbu ->f("Select_priv"), "insert"=>$this->dbu->f("Insert_priv"), "update"=>$this->dbu->f("Update_priv"), "delete"=>$this->dbu->f("Delete_priv"), "create"=>$this->dbu->f("Create_priv"), "drop"=>$this->dbu->f("Drop_priv"), "references"=>$this->dbu->f("References_priv"), "index"=>$this->dbu->f("Index_priv"), "alter"=>$this->dbu->f("Alter_priv"), "create_tmp"=>$this->dbu->f("Create_tmp_table_priv"), "lock"=>$this->dbu->f("Lock_tables_priv"));617 $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->client' AND Db='".$dblist[$i]["db"]."';"); 618 if ($this->dbus->next_record()) 619 $r[]=array("db"=>$dblist[$i]["name"], "select"=>$this->dbus->f("Select_priv"), "insert"=>$this->dbus->f("Insert_priv"), "update"=>$this->dbus->f("Update_priv"), "delete"=>$this->dbus->f("Delete_priv"), "create"=>$this->dbus->f("Create_priv"), "drop"=>$this->dbus->f("Drop_priv"), "references"=>$this->dbus->f("References_priv"), "index"=>$this->dbus->f("Index_priv"), "alter"=>$this->dbus->f("Alter_priv"), "create_tmp"=>$this->dbus->f("Create_tmp_table_priv"), "lock"=>$this->dbus->f("Lock_tables_priv")); 619 620 else 620 621 $r[]=array("db"=>$dblist[$i]["name"], "select"=>"N", "insert"=>"N", "update"=>"N", "delete"=>"N", "create"=>"N", "drop"=>"N", "references"=>"N", "index"=>"N", "alter"=>"N", "Create_tmp"=>"N", "lock"=>"N" ); … … 678 679 679 680 // We reset all user rights on this DB : 680 $this->dbu ->query("SELECT * FROM mysql.db WHERE User = '$usern' AND Db = '$dbname';");681 if($this->dbu ->num_rows())682 $this->dbu ->query("REVOKE ALL PRIVILEGES ON $dbname.* FROM '$usern'@'$this->client';");681 $this->dbus->query("SELECT * FROM mysql.db WHERE User = '$usern' AND Db = '$dbname';"); 682 if($this->dbus->num_rows()) 683 $this->dbus->query("REVOKE ALL PRIVILEGES ON $dbname.* FROM '$usern'@'$this->client';"); 683 684 if( $strrights ){ 684 685 $strrights=substr($strrights,0,strlen($strrights)-1); 685 $this->dbu ->query("GRANT $strrights ON $dbname.* TO '$usern'@'$this->client';");686 } 687 $this->dbu ->query("FLUSH PRIVILEGES");686 $this->dbus->query("GRANT $strrights ON $dbname.* TO '$usern'@'$this->client';"); 687 } 688 $this->dbus->query("FLUSH PRIVILEGES"); 688 689 return TRUE; 689 690 }
Note: See TracChangeset
for help on using the changeset viewer.
