Changeset 3197
- Timestamp:
- 08/14/12 11:44:43 (10 months ago)
- Location:
- alternc/trunk
- Files:
-
- 8 edited
-
bureau/admin/sql_bck.php (modified) (1 diff)
-
bureau/admin/sql_restore.php (modified) (1 diff)
-
bureau/admin/sql_users_add.php (modified) (1 diff)
-
bureau/admin/sql_users_rights.php (modified) (1 diff)
-
bureau/class/m_mysql.php (modified) (10 diffs)
-
debian/alternc.config (modified) (1 diff)
-
debian/changelog (modified) (1 diff)
-
install/mysql.sql (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
alternc/trunk/bureau/admin/sql_bck.php
r2724 r3197 50 50 <br /> 51 51 <?php 52 if ( $error) {52 if (isset($error) && $error) { 53 53 echo "<p class=\"error\">$error</p><p> </p>"; 54 54 } -
alternc/trunk/bureau/admin/sql_restore.php
r2719 r3197 45 45 <br /> 46 46 <?php 47 if ( $error) {47 if (isset($error) && $error) { 48 48 echo "<p class=\"error\">$error</p><p> </p>"; 49 49 } -
alternc/trunk/bureau/admin/sql_users_add.php
r3149 r3197 50 50 if (isset($error) && $error) { 51 51 echo "<p class=\"error\">$error</p>"; 52 if ( $fatal) {52 if (isset($fatal) && $fatal) { 53 53 ?> 54 54 <?php include_once("foot.php"); ?> -
alternc/trunk/bureau/admin/sql_users_rights.php
r3135 r3197 49 49 if ($r) { 50 50 51 echo "<p>"._("help_sql_users_rights_ok")."</p>";52 51 ?> 53 52 -
alternc/trunk/bureau/class/m_mysql.php
r3196 r3197 132 132 * "db" => database name "bck" => backup mode for this db 133 133 * "dir" => Backup folder. 134 * Returns FALSE if the user has no database.134 * Returns an array (empty) if no databases 135 135 */ 136 136 function get_dblist() { 137 137 global $db,$err,$bro,$cuid; 138 138 $err->log("mysql","get_dblist"); 139 $db->free(); 139 140 $db->query("SELECT login,pass,db, bck_mode, bck_dir FROM db WHERE uid='$cuid' ORDER BY db;"); 140 if (!$db->num_rows()) {141 $err->raise("mysql",11);142 return false;143 }144 141 $c=array(); 145 142 while ($db->next_record()) { … … 248 245 // Ok, database does not exist, quota is ok and dbname is compliant. Let's proceed 249 246 $db->query("INSERT INTO db (uid,login,pass,db,bck_mode) VALUES ('$cuid','$myadm','$password','$dbname',0);"); 250 #TODO escape dbname to avoid wildcard '_' 251 die(); 252 print_r("GRANT ALL PRIVILEGES ON `".$dbname."`.* TO '".$myadm."'@".$this->dbus->Host." IDENTIFIED BY '".addslashes($password)."'"); 253 $this->dbus->query("GRANT ALL PRIVILEGES ON `".addslashes($dbname)."`.* TO '".$myadm."'@".$this->dbus->Host." IDENTIFIED BY '".addslashes($password)."'"); 247 $dbname=str_replace('_','\_',$dbname); 248 $this->grant($dbname,$myadm,"ALL PRIVILEGES",$password); 254 249 $this->dbus->query("FLUSH PRIVILEGES;"); 255 250 return true; … … 370 365 } 371 366 372 367 /** 368 * Function used to grant SQL rights to users: 369 * @base :database 370 * @user : database user 371 * @rights : rights to apply ( optional, every rights apply given if missing 372 * @pass : user password ( optional, if not given the pass stays the same, else it takes the new value ) 373 * @table : sql tables to apply rights 374 **/ 375 function grant($base,$user,$rights=null,$pass=null,$table='*'){ 376 global $err,$db; 377 $err->log("mysql","grant"); 378 if(!preg_match("#^[0-9a-z\_]*$#",$base)){ 379 $err->raise("mysql",2); 380 return false; 381 }elseif(!$db->query("select db from db where db='$base';")){ 382 $err->raise("mysql",10); 383 return false; 384 } 385 386 if($rights==null){ 387 $rights='ALL PRIVILEGES'; 388 }elseif(!preg_match("#^[a-zA-Z\,]*$#",$rights)){ 389 $err->raise("mysql",3); 390 return false; 391 } 392 393 if(!preg_match("#^[0-9a-z\_]*$#",$user)) { 394 $err->raise("mysql",5); 395 return false; 396 } 397 if(!$db->query("select name from dbusers where name='".$user."' ;")){ 398 $err->raise("mysql",6); 399 return false; 400 } 401 402 $grant="grant ".$rights." on `".$base."`.".$table." to '".$user."'@'".$this->dbus->Host."'" ; 403 404 if($pass){ 405 $grant .= " identified by '".$pass."';"; 406 }else{ 407 $grant .= ";"; 408 } 409 if(!$this->dbus->query($grant)){ 410 $err->raise("mysql",6); 411 return false; 412 } 413 return true; 414 415 } 373 416 374 417 … … 510 553 511 554 // We create the user account (the "file" right is the only one we need globally to be able to use load data into outfile) 512 $this-> dbus->query("GRANT file ON *.* TO '$user'@".$this->dbus->Host." IDENTIFIED BY '$pass';");555 $this->grant("*",$user,"FILE",$pass); 513 556 // We add him to the user table 514 557 $db->query("INSERT INTO dbusers (uid,name,enable) VALUES($cuid,'$user','ACTIVATED');"); … … 526 569 function change_user_password($usern,$password,$passconf) { 527 570 global $db,$err,$quota,$mem,$cuid,$admin; 528 $err->log("mysql"," add_user",$usern);571 $err->log("mysql","change_user_pass",$usern); 529 572 530 573 $usern=trim($usern); … … 542 585 } 543 586 } 544 $this->dbus->query("SET PASSWORD FOR ".$user."@".$this->dbus->Host." = PASSWORD( ".$pass.")");587 $this->dbus->query("SET PASSWORD FOR ".$user."@".$this->dbus->Host." = PASSWORD('".$pass."')"); 545 588 return true; 546 589 } … … 590 633 591 634 $r=array(); 635 $db->free(); 592 636 $dblist=$this->get_dblist(); 593 594 637 for ( $i=0 ; $i<count($dblist) ; $i++ ) { 595 638 $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"]."';"); … … 663 706 if( $strrights ){ 664 707 $strrights=substr($strrights,0,strlen($strrights)-1); 665 $this-> dbus->query("GRANT $strrights ON $dbname.* TO '$usern'@'".$this->dbus->Host."';");708 $this->grant($dbname,$usern,$strrights); 666 709 } 667 710 $this->dbus->query("FLUSH PRIVILEGES"); … … 696 739 } else return false; 697 740 } 698 741 699 742 /* ----------------------------------------------------------------- */ 700 743 /** Hook function called when a user is created. … … 712 755 }else{ 713 756 $myadm=$mem->user["login"]."_myadm"; 714 $password="kikoulol"; 757 $chars = "234567890abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; 758 $i = 0; 759 $password = ""; 760 while ($i <= 8) { 761 $password .= $chars{mt_rand(0,strlen($chars))}; 762 $i++; 763 } 715 764 $db->query("INSERT INTO dbusers (uid,name,password,enable) VALUES ('$cuid','$myadm','$password','ADMIN');"); 716 765 } 717 766 return true; 718 767 } 768 769 770 719 771 720 772 /* ----------------------------------------------------------------- */ -
alternc/trunk/debian/alternc.config
r3191 r3197 95 95 db_input critical alternc/quotauninstalled || true 96 96 db_go 97 db_reset alternc/ puotauninstalled || true97 db_reset alternc/quotauninstalled || true 98 98 db_fset alternc/quotauninstalled "seen" "false" || true 99 99 fi -
alternc/trunk/debian/changelog
r3144 r3197 1 alternc (1.1+nmu4) stable; urgency=low 2 3 * SQL Modification 4 * MySQL tables used for Alternc users databases modified (mysql.sql) 5 * Adding a special phpmyadmin user. 6 * Users can now create databases en databases users independently 7 ( no need to create a first database to create a user anymore) 8 * Bugfixes in installation process 9 10 11 -- squidly <squidly@nnx.com> Tue, 14 Aug 2012 11:21:14 +0200 12 1 13 alternc (1.1+nmu3) stable; urgency=low 2 14 -
alternc/trunk/install/mysql.sql
r3196 r3197 107 107 bck_gzip tinyint(3) unsigned NOT NULL default '0', # Faut-il compresser les backups ? 108 108 bck_dir varchar(255) NOT NULL default '', # O stocke-t-on les backups sql ? 109 PRIMARY KEY uid (uid)109 PRIMARY KEY id (id) 110 110 ) TYPE=MyISAM COMMENT='Bases MySQL des membres'; 111 111
Note: See TracChangeset
for help on using the changeset viewer.
