Changeset 2943
- Timestamp:
- 05/18/11 22:26:12 (2 years ago)
- Location:
- alternc/trunk
- Files:
-
- 1 added
- 2 edited
-
bureau/class/m_bro.php (modified) (9 diffs)
-
bureau/class/m_mysql.php (modified) (16 diffs)
-
etc/alternc/dbusers.cnf.sample (added)
Legend:
- Unmodified
- Added
- Removed
-
alternc/trunk/bureau/class/m_bro.php
r2863 r2943 268 268 // Now seek the extension 269 269 if (!$bro_type[$ext]) { 270 return "File";271 } else { 272 return $bro_type[$ext];270 return "File"; 271 } else { 272 return $bro_type[$ext]; 273 273 } 274 274 } … … 307 307 $nextpath = $dir . '/' . $file; 308 308 309 if ($file != '.' && $file != '..' && !is_link($nextpath)) {309 if ($file != '.' && $file != '..' && !is_link($nextpath)) { 310 310 if (is_dir($nextpath)) { 311 311 $totalsize += $this->dirsize($nextpath); … … 406 406 $new[$i]=ssla($new[$i]); 407 407 if (!strpos($old[$i],"/") && !strpos($new[$i],"/")) { // caractère / interdit dans old ET dans new... 408 @rename($absolute."/".$old[$i],$absolute."/".$old[$i].$alea);408 @rename($absolute."/".$old[$i],$absolute."/".$old[$i].$alea); 409 409 } 410 410 } 411 411 for ($i=0;$i<count($old);$i++) { 412 412 if (!strpos($old[$i],"/") && !strpos($new[$i],"/")) { // caractère / interdit dans old ET dans new... 413 @rename($absolute."/".$old[$i].$alea,$absolute."/".$new[$i]);413 @rename($absolute."/".$old[$i].$alea,$absolute."/".$new[$i]); 414 414 } 415 415 } … … 477 477 $d[$i]=ssla($d[$i]); // strip slashes if needed 478 478 if (!strpos($d[$i],"/")) { // caractère / interdit dans le nom du fichier 479 // @rename($absolute."/".$old[$i],$absolute."/".$old[$i].$alea);480 $m = fileperms($absolute."/". $d[$i]);481 482 // pour l'instant on se limite a "write" pour owner, puisque c'est le seul483 // cas interessant compte tenu de la conf de Apache pour AlternC..484 if ($perm[$i]['w']) {485 $m = $m | 128;486 } else {487 $m = $m ^ 128;488 }489 $m = $m | ($perm[$i]['w'] ? 128 : 0); // 0600490 chmod($absolute."/".$d[$i], $m);491 echo "chmod " . sprintf('%o', $m) . " file, was " . sprintf('%o', fileperms($absolute."/". $d[$i])). " -- " . $perm[$i]['w'];479 // @rename($absolute."/".$old[$i],$absolute."/".$old[$i].$alea); 480 $m = fileperms($absolute."/". $d[$i]); 481 482 // pour l'instant on se limite a "write" pour owner, puisque c'est le seul 483 // cas interessant compte tenu de la conf de Apache pour AlternC.. 484 if ($perm[$i]['w']) { 485 $m = $m | 128; 486 } else { 487 $m = $m ^ 128; 488 } 489 $m = $m | ($perm[$i]['w'] ? 128 : 0); // 0600 490 chmod($absolute."/".$d[$i], $m); 491 echo "chmod " . sprintf('%o', $m) . " file, was " . sprintf('%o', fileperms($absolute."/". $d[$i])). " -- " . $perm[$i]['w']; 492 492 } 493 493 } … … 756 756 $end=""; $beg=$dir; $tofind=true; 757 757 while ($tofind) { 758 $db->query("SELECT sub,domaine FROM sub_domaines WHERE compte='$cuid'759 AND type=0 AND (valeur='/$beg/' or valeur='/$beg');");760 $db->next_record();761 if ($db->num_rows()) {762 $tofind=false;763 $this->cacheurl["d".$dir]="http://".$db->f("sub").ife($db->f("sub"),".").$db->f("domaine").$end;764 }765 if (!$beg && $tofind) {766 $tofind=false;767 $this->cacheurl["d".$dir]="-";768 // We did not find it ;(769 }770 if (($tt=strrpos($beg,"/"))!==false) {771 $end=substr($beg,$tt).$end; // = /topdir$end so $end starts AND ends with /772 $beg=substr($beg,0,$tt);773 } else {774 $end="/".$beg.$end;775 $beg="/";776 }758 $db->query("SELECT sub,domaine FROM sub_domaines WHERE compte='$cuid' 759 AND type=0 AND (valeur='/$beg/' or valeur='/$beg');"); 760 $db->next_record(); 761 if ($db->num_rows()) { 762 $tofind=false; 763 $this->cacheurl["d".$dir]="http://".$db->f("sub").ife($db->f("sub"),".").$db->f("domaine").$end; 764 } 765 if (!$beg && $tofind) { 766 $tofind=false; 767 $this->cacheurl["d".$dir]="-"; 768 // We did not find it ;( 769 } 770 if (($tt=strrpos($beg,"/"))!==false) { 771 $end=substr($beg,$tt).$end; // = /topdir$end so $end starts AND ends with / 772 $beg=substr($beg,0,$tt); 773 } else { 774 $end="/".$beg.$end; 775 $beg="/"; 776 } 777 777 } 778 778 } … … 794 794 case "bz": 795 795 case "bz2": 796 $ext = array_pop($parts) . $ext;797 /* FALLTHROUGH */796 $ext = array_pop($parts) . $ext; 797 /* FALLTHROUGH */ 798 798 case "tar.gz": 799 799 case "tar.bz": … … 817 817 $absolute.="/".$file; 818 818 if (file_exists($absolute)) { 819 $content = @file($absolute);820 for($i=0;$i<count($content);$i++) {821 echo stripslashes($content[$i]);822 }819 $content = @file($absolute); 820 for($i=0;$i<count($content);$i++) { 821 echo stripslashes($content[$i]); 822 } 823 823 } 824 824 } else { … … 844 844 $absolute.="/".$file; 845 845 if (file_exists($absolute)) { 846 $f=@fopen($absolute,"wb");847 if ($f) {848 fputs($f,$texte,strlen($texte));849 fclose($f);850 }846 $f=@fopen($absolute,"wb"); 847 if ($f) { 848 fputs($f,$texte,strlen($texte)); 849 fclose($f); 850 } 851 851 } 852 852 } else { … … 940 940 $handle = opendir($file); 941 941 while($filename = readdir($handle)) { 942 if ($filename != "." && $filename != "..") {943 $this->_delete($file."/".$filename);944 }942 if ($filename != "." && $filename != "..") { 943 $this->_delete($file."/".$filename); 944 } 945 945 } 946 946 closedir($handle); -
alternc/trunk/bureau/class/m_mysql.php
r2926 r2943 34 34 * @copyright AlternC-Team 2002-2005 http://alternc.org/ 35 35 */ 36 37 class DBU_mysql extends DB_Sql { 38 var $Host,$HumanHostname,$User,$Password; 39 40 /** 41 * Creator 42 */ 43 function DBU_mysql() { 44 45 # Use the dbusers file if exist, else use default alternc configuration 46 if ( is_readable("/etc/alternc/dbusers.cnf") ) { 47 $mysqlconf=file_get_contents("/etc/alternc/dbusers.cnf"); 48 } else { 49 $mysqlconf=file_get_contents("/etc/alternc/my.cnf"); 50 } 51 $mysqlconf=explode("\n",$mysqlconf); 52 53 # Read the configuration 54 foreach ($mysqlconf as $line) { 55 # First, read the "standard" configuration 56 if (preg_match('/^([A-Za-z0-9_]*) *= *"?(.*?)"?$/', trim($line), $regs)) { 57 switch ($regs[1]) { 58 case "user": 59 $user = $regs[2]; 60 break; 61 case "password": 62 $password = $regs[2]; 63 break; 64 case "host": 65 $host = $regs[2]; 66 break; 67 } 68 } 69 # Then, read specific alternc configuration 70 if (preg_match('/^#alternc_var ([A-Za-z0-9_]*) *= *"?(.*?)"?$/', trim($line), $regs)) { 71 $$regs[1]=$regs[2]; 72 } 73 } 74 75 # Set value of human_host if unset 76 if (! isset($human_hostname) || empty($human_hostname)) { 77 if ( checkip($host) || checkipv6($host) ) { 78 $human_hostname = gethostbyaddr($host); 79 } else { 80 $human_hostname = $host; 81 } 82 } 83 84 85 # Create the object 86 $this->Host = $host; 87 $this->User = $user; 88 $this->Password = $password; 89 // TODO BUG BUG BUG 90 // c'est pas étanche : $db se retrouve avec Database de $sql->dbu . Danger, faut comprendre pourquoi 91 $this->Database = "alternc"; 92 $this->HumanHostname = $human_hostname; 93 94 } 95 } 96 97 36 98 class m_mysql { 37 38 var $server; 39 var $client; 40 99 var $dbu; 41 100 42 101 /*---------------------------------------------------------------------------*/ … … 45 104 */ 46 105 function m_mysql() { 47 $this->server = $GLOBALS['L_MYSQL_HOST']; 48 $this->client = $GLOBALS['L_MYSQL_CLIENT']; 106 $this->dbu = new DBU_mysql(); 49 107 } 50 108 … … 160 218 $pa=addslashes($db->f("pass")); 161 219 } 162 if ($ db->query("CREATE DATABASE `$dbname`;")) {220 if ($this->dbu->query("CREATE DATABASE `$dbname`;")) { 163 221 // Ok, database does not exist, quota is ok and dbname is compliant. Let's proceed 164 222 $db->query("INSERT INTO db (uid,login,pass,db,bck_mode) VALUES ('$cuid','$lo','$pa','$dbname',0);"); 165 223 // give everything but GRANT on db.* 166 224 // we assume there's already a user 167 $ db->query("GRANT ALL PRIVILEGES ON `".$dbname."`.* TO '".$lo."'@'$this->client'");225 $this->dbu->query("GRANT ALL PRIVILEGES ON `".$dbname."`.* TO '".$lo."'@'$this->client'"); 168 226 return true; 169 227 } else { … … 195 253 // Ok, database exists and dbname is compliant. Let's proceed 196 254 $db->query("DELETE FROM db WHERE uid='$cuid' AND db='$dbname';"); 197 $ db->query("DROP DATABASE `$dbname`;");255 $this->dbu->query("DROP DATABASE `$dbname`;"); 198 256 $db->query("SELECT COUNT(*) AS cnt FROM db WHERE uid='$cuid';"); 199 257 $db->next_record(); 200 $ db->query("REVOKE ALL PRIVILEGES ON `".$dbname."`.* FROM '".$login."'@'$this->client'");201 if ($ db->f("cnt")==0) {202 $ db->query("DELETE FROM mysql.user WHERE User='".$login."';");203 $ db->query("FLUSH PRIVILEGES;");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;"); 204 262 } 205 263 return true; … … 279 337 if (is_callable(array($admin,"checkPolicy"))) { 280 338 if (!$admin->checkPolicy("mysql",$login,$password)) { 281 return false; // The error has been raised by checkPolicy()339 return false; // The error has been raised by checkPolicy() 282 340 } 283 341 } … … 285 343 // Update all the "pass" fields for this user : 286 344 $db->query("UPDATE db SET pass='$password' WHERE uid='$cuid';"); 287 $ db->query("SET PASSWORD FOR '$login'@'$this->client' = PASSWORD('$password')");345 $this->dbu->query("SET PASSWORD FOR '$login'@'$this->client' = PASSWORD('$password')"); 288 346 return true; 289 347 } … … 323 381 if (is_callable(array($admin,"checkPolicy"))) { 324 382 if (!$admin->checkPolicy("mysql",$login,$password)) { 325 return false; // The error has been raised by checkPolicy()383 return false; // The error has been raised by checkPolicy() 326 384 } 327 385 } … … 330 388 $db->query("INSERT INTO db (uid,login,pass,db) VALUES ('$cuid','".$login."','$password','".$dbname."');"); 331 389 // give everything but GRANT on $user.* 332 $ db->query("GRANT ALL PRIVILEGES ON `".$dbname."`.* TO '".$login."'@'$this->client' IDENTIFIED BY '".addslashes($password)."'");333 $ db->query("CREATE DATABASE `".$dbname."`;");390 $this->dbu->query("GRANT ALL PRIVILEGES ON `".$dbname."`.* TO '".$login."'@'$this->client' IDENTIFIED BY '".addslashes($password)."'"); 391 $this->dbu->query("CREATE DATABASE `".$dbname."`;"); 334 392 return true; 335 393 } … … 344 402 */ 345 403 function restore($file,$stdout,$id) { 404 // TODO don't work with the separated sql serveur for dbusers 346 405 global $err,$bro,$mem,$L_MYSQL_HOST; 347 406 if (!$r=$this->get_mysql_details($id)) { … … 385 444 global $db,$err; 386 445 387 $ db->query("SHOW TABLE STATUS FROM `$dbname`;");446 $this->dbu->query("SHOW TABLE STATUS FROM `$dbname`;"); 388 447 $size = 0; 389 448 while ($db->next_record()) { 390 $size += $db->f('Data_length') + $db->f('Index_length') 391 + $db->f('Data_free'); 449 $size += $db->f('Data_length') + $db->f('Index_length') + $db->f('Data_free'); 392 450 } 393 451 return $size; … … 467 525 if (is_callable(array($admin,"checkPolicy"))) { 468 526 if (!$admin->checkPolicy("mysql",$user,$password)) { 469 return false; // The error has been raised by checkPolicy()527 return false; // The error has been raised by checkPolicy() 470 528 } 471 529 } 472 530 473 531 // We create the user account (the "file" right is the only one we need globally to be able to use load data into outfile) 474 $ db->query("GRANT file ON *.* TO '$user'@'$this->client' IDENTIFIED BY '$pass';");532 $this->dbu->query("GRANT file ON *.* TO '$user'@'$this->client' IDENTIFIED BY '$pass';"); 475 533 // We add him to the user table 476 534 $db->query("INSERT INTO dbusers (uid,name) VALUES($cuid,'$user');"); … … 505 563 } 506 564 507 $ db->query("SET PASSWORD FOR '$user'@'$this->client' = PASSWORD('$pass')");565 $this->dbu->query("SET PASSWORD FOR '$user'@'$this->client' = PASSWORD('$pass')"); 508 566 return true; 509 567 } … … 533 591 534 592 // Ok, database exists and dbname is compliant. Let's proceed 535 $ db->query("REVOKE ALL PRIVILEGES ON *.* FROM '".$mem->user["login"]."_$user'@'$this->client';");536 $ db->query("DELETE FROM mysql.db WHERE User='".$mem->user["login"]."_$user' AND Host='$this->client';");537 $ db->query("DELETE FROM mysql.user WHERE User='".$mem->user["login"]."_$user' AND Host='$this->client';");538 $ db->query("FLUSH PRIVILEGES");539 $ db->query("DELETE FROM dbusers WHERE uid='$cuid' AND name='".$mem->user["login"]."_$user';");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';"); 540 598 return true; 541 599 } … … 556 614 557 615 for ( $i=0 ; $i<count($dblist) ; $i++ ) { 558 $ db->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"]."';");559 if ($ db->next_record())560 $r[]=array("db"=>$dblist[$i]["name"], "select"=>$ db->f("Select_priv"), "insert"=>$db->f("Insert_priv"), "update"=>$db->f("Update_priv"), "delete"=>$db->f("Delete_priv"), "create"=>$db->f("Create_priv"), "drop"=>$db->f("Drop_priv"), "references"=>$db->f("References_priv"), "index"=>$db->f("Index_priv"), "alter"=>$db->f("Alter_priv"), "create_tmp"=>$db->f("Create_tmp_table_priv"), "lock"=>$db->f("Lock_tables_priv"));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")); 561 619 else 562 620 $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" ); … … 620 678 621 679 // We reset all user rights on this DB : 622 $ db->query("SELECT * FROM mysql.db WHERE User = '$usern' AND Db = '$dbname';");623 if($ db->num_rows())624 $ db->query("REVOKE ALL PRIVILEGES ON $dbname.* FROM '$usern'@'$this->client';");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';"); 625 683 if( $strrights ){ 626 684 $strrights=substr($strrights,0,strlen($strrights)-1); 627 $ db->query("GRANT $strrights ON $dbname.* TO '$usern'@'$this->client';");628 } 629 $ db->query("FLUSH PRIVILEGES");685 $this->dbu->query("GRANT $strrights ON $dbname.* TO '$usern'@'$this->client';"); 686 } 687 $this->dbu->query("FLUSH PRIVILEGES"); 630 688 return TRUE; 631 689 } … … 702 760 */ 703 761 function alternc_export($tmpdir) { 762 //TODO don't work with separated sql server for dbusers 704 763 global $db,$err,$cuid; 705 764 $err->log("mysql","export");
Note: See TracChangeset
for help on using the changeset viewer.
