Changeset 3197


Ignore:
Timestamp:
08/14/12 11:44:43 (10 months ago)
Author:
squidly
Message:

Continuing on sql modification for consistency + Bugfixes

Location:
alternc/trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • alternc/trunk/bureau/admin/sql_bck.php

    r2724 r3197  
    5050<br /> 
    5151<?php 
    52         if ($error) { 
     52        if (isset($error) && $error) { 
    5353                echo "<p class=\"error\">$error</p><p>&nbsp;</p>"; 
    5454        } 
  • alternc/trunk/bureau/admin/sql_restore.php

    r2719 r3197  
    4545<br /> 
    4646<?php 
    47         if ($error) { 
     47        if (isset($error) && $error) { 
    4848                echo "<p class=\"error\">$error</p><p>&nbsp;</p>"; 
    4949        } 
  • alternc/trunk/bureau/admin/sql_users_add.php

    r3149 r3197  
    5050        if (isset($error) && $error) { 
    5151                echo "<p class=\"error\">$error</p>"; 
    52                 if ($fatal) { 
     52                if (isset($fatal) && $fatal) { 
    5353?> 
    5454<?php include_once("foot.php"); ?> 
  • alternc/trunk/bureau/admin/sql_users_rights.php

    r3135 r3197  
    4949if ($r) { 
    5050 
    51 echo "<p>"._("help_sql_users_rights_ok")."</p>"; 
    5251?> 
    5352 
  • alternc/trunk/bureau/class/m_mysql.php

    r3196 r3197  
    132132   *  "db" => database name "bck" => backup mode for this db  
    133133   *  "dir" => Backup folder. 
    134    *  Returns FALSE if the user has no database. 
     134   *  Returns an array (empty) if no databases 
    135135   */ 
    136136  function get_dblist() { 
    137137    global $db,$err,$bro,$cuid; 
    138138    $err->log("mysql","get_dblist"); 
     139    $db->free(); 
    139140    $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     } 
    144141    $c=array(); 
    145142    while ($db->next_record()) { 
     
    248245      // Ok, database does not exist, quota is ok and dbname is compliant. Let's proceed 
    249246      $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); 
    254249      $this->dbus->query("FLUSH PRIVILEGES;"); 
    255250      return true; 
     
    370365  } 
    371366 
    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  } 
    373416 
    374417 
     
    510553 
    511554    // 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); 
    513556    // We add him to the user table  
    514557    $db->query("INSERT INTO dbusers (uid,name,enable) VALUES($cuid,'$user','ACTIVATED');"); 
     
    526569  function change_user_password($usern,$password,$passconf) { 
    527570    global $db,$err,$quota,$mem,$cuid,$admin; 
    528     $err->log("mysql","add_user",$usern); 
     571    $err->log("mysql","change_user_pass",$usern); 
    529572 
    530573    $usern=trim($usern); 
     
    542585      } 
    543586    } 
    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."')"); 
    545588    return true; 
    546589  } 
     
    590633 
    591634    $r=array(); 
     635    $db->free(); 
    592636    $dblist=$this->get_dblist(); 
    593  
    594637    for ( $i=0 ; $i<count($dblist) ; $i++ ) { 
    595638      $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"]."';"); 
     
    663706    if( $strrights ){ 
    664707      $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); 
    666709    } 
    667710    $this->dbus->query("FLUSH PRIVILEGES"); 
     
    696739    } else return false; 
    697740  } 
    698    
     741 
    699742  /* ----------------------------------------------------------------- */ 
    700743  /** Hook function called when a user is created. 
     
    712755    }else{ 
    713756      $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      }  
    715764      $db->query("INSERT INTO dbusers (uid,name,password,enable) VALUES ('$cuid','$myadm','$password','ADMIN');"); 
    716765    } 
    717766    return true; 
    718767  } 
     768 
     769 
     770 
    719771   
    720772  /* ----------------------------------------------------------------- */ 
  • alternc/trunk/debian/alternc.config

    r3191 r3197  
    9595        db_input critical alternc/quotauninstalled || true 
    9696        db_go 
    97     db_reset alternc/puotauninstalled || true 
     97    db_reset alternc/quotauninstalled || true 
    9898    db_fset alternc/quotauninstalled "seen" "false" || true 
    9999fi 
  • alternc/trunk/debian/changelog

    r3144 r3197  
     1alternc (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 
    113alternc (1.1+nmu3) stable; urgency=low 
    214 
  • alternc/trunk/install/mysql.sql

    r3196 r3197  
    107107  bck_gzip tinyint(3) unsigned NOT NULL default '0',    # Faut-il compresser les backups ? 
    108108  bck_dir varchar(255) NOT NULL default '',             # O stocke-t-on les backups sql ? 
    109   PRIMARY KEY uid (uid) 
     109  PRIMARY KEY id (id) 
    110110) TYPE=MyISAM COMMENT='Bases MySQL des membres'; 
    111111 
Note: See TracChangeset for help on using the changeset viewer.