home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2005 June / PCpro_2005_06.ISO / files / opensource / xamp / xampp-win32.exe / xampp / securefunctions.php < prev    next >
Encoding:
PHP Script  |  2004-12-18  |  5.6 KB  |  229 lines

  1. <?php
  2.  
  3. function mysqlrootupdate($currentpass, $newpass, $renewpass)
  4. {
  5.     $curdir = getcwd();
  6.     list ($partwampp, $directorwampp) = spliti ('\\\htdocs', $curdir);
  7.     $mypasswdtxt="mysqlrootpasswd.txt";
  8.     $mypasswdtxtdir=$partwampp."\security\\".$mypasswdtxt;
  9.     $dir=$partwampp."\security\\";
  10.     // if ($currentpass=="")
  11.     global $rootpasswdupdate;
  12.     global $update;
  13.     if (@mysql_connect("localhost","root","$currentpass"))
  14.     {
  15.     mysql_select_db("mysql");
  16.     $update="yes";
  17. mysql_query("UPDATE `user` SET `Select_priv` = 'Y',
  18. `Insert_priv` = 'Y',
  19. `Update_priv` = 'Y',
  20. `Delete_priv` = 'Y',
  21. `Create_priv` = 'Y',
  22. `Drop_priv` = 'Y',
  23. `Reload_priv` = 'Y',
  24. `Shutdown_priv` = 'Y',
  25. `Process_priv` = 'Y',
  26. `File_priv` = 'Y',
  27. `Grant_priv` = 'Y',
  28. `References_priv` = 'Y',
  29. `Index_priv` = 'Y',
  30. `Alter_priv` = 'Y',
  31. `Show_db_priv` = 'Y',
  32. `Super_priv` = 'Y',
  33. `Create_tmp_table_priv` = 'Y',
  34. `Lock_tables_priv` = 'Y',
  35. `Execute_priv` = 'Y',
  36. `Repl_slave_priv` = 'Y',
  37. `Repl_client_priv` = 'Y',
  38. `ssl_cipher` = '',
  39. `x509_issuer` = '',
  40. `x509_subject` = '' WHERE CONVERT( `Host` USING utf8 ) = '%' AND CONVERT( `User` USING utf8 ) = 'root' LIMIT 1");
  41. mysql_query("UPDATE user SET password = PASSWORD( '$newpass' ) WHERE `User` = 'root'");
  42.     // UPDATE `user` SET `User` = 'testuser', `password` = PASSWORD( 'birdbird' ) WHERE `Host` = 'localhost' AND `User` = 'tefstuser' LIMIT 1 ;
  43.     mysql_close;
  44.     
  45.     $dh = @opendir($dir);
  46.     if ($dh)
  47.     { } else { system("md $dir"); } 
  48.  
  49.  
  50.     $datei = fopen($mypasswdtxtdir,'w+');
  51.     $put="mysql user = root\r\nmysql password = $newpass";
  52.     fputs($datei, $put);
  53.     fclose($datei);
  54.     $rootpasswdupdate="yes";                
  55.     }
  56.     else
  57.     {
  58.     $rootpasswdupdate="no";
  59.     } 
  60. }
  61.  
  62.  
  63. function phpmyadminstatus()
  64. {
  65. global $currentstatus;
  66. global $authzeile;
  67. global $notfind;
  68.  
  69. $curdir = getcwd();
  70. list ($partwampp, $directorwampp) = spliti ('\\\htdocs', $curdir);
  71. $configinc="config.inc.php";
  72. $phpmyadminconf=$partwampp."\phpmyadmin\\".$configinc;
  73.  
  74. if (file_exists($phpmyadminconf)) 
  75. {
  76.     $datei = fopen($phpmyadminconf,'r');
  77.     $i=0;
  78.     while(!feof($datei)) 
  79.     {
  80.     $zeile = fgets($datei,255);
  81.     $oldzeile[]=$zeile; 
  82.     list ($left, $right) = split ('=', $zeile);
  83.     if (preg_match("/'auth_type'/i", $left))
  84.         { 
  85.         if (preg_match("/'http'/i", $right))
  86.             { $currentstatus[]="http"; $authzeile[]=$i; } 
  87.         elseif (preg_match("/'cookie'/i", $right))
  88.             { $currentstatus[]="cookie"; $authzeile[]=$i; } 
  89.         else { $currentstatus[]="null"; $authzeile[]=$i; }
  90.     
  91.         }    
  92.     $i++;
  93.     }
  94.     fclose($datei); 
  95. }
  96. else
  97.     {
  98.     $notfind=1;
  99.     }
  100. }
  101.  
  102.  
  103.  
  104. function changephpadminauth($phpmyadminauth, $myupdate)
  105. {
  106. global $phpmyadminconfsafe;
  107. $curdir = getcwd();
  108. list ($partwampp, $directorwampp) = spliti ('\\\htdocs', $curdir);
  109. $configinc="config.inc.php";
  110. $phpmyadminconf=$partwampp."\phpmyadmin\\".$configinc;
  111.  
  112. if (file_exists($phpmyadminconf)) 
  113. {
  114.     $datei = fopen($phpmyadminconf,'r');
  115.     $i=0;
  116.     while(!feof($datei)) 
  117.     {
  118.     $zeile = fgets($datei,255);
  119.     $oldzeile[]=$zeile; 
  120.     list ($left, $right) = split ('=', $zeile);
  121.     if (preg_match("/'auth_type'/i", $left))
  122.         { 
  123.         if (preg_match("/'http'/i", $right))
  124.             { $currentstatus[]="http"; $authzeile[]=$i; } 
  125.         elseif (preg_match("/'cookie'/i", $right))
  126.             { $currentstatus[]="cookie"; $authzeile[]=$i; } 
  127.         else { $currentstatus[]="null"; $authzeile[]=$i; }
  128.     
  129.         }    
  130.     $i++;
  131.     }
  132.     fclose($datei); 
  133.     }
  134.     else
  135.     {
  136.     $notfind=1;
  137.     }
  138.  
  139. $mynewzeile="\$cfg['Servers'][\$i]['auth_type']     = '$phpmyadminauth';      // Authentication method (config, http or cookie based)\n";
  140.  
  141.  
  142.     if (file_exists($phpmyadminconf)) 
  143.     {
  144.         If ($currentstatus[0]=="null" || $myupdate=="1")
  145.         {
  146.         copy($phpmyadminconf, $phpmyadminconf.'.safe');
  147.         $phpmyadminconfsafe=$partwampp."\phpmyadmin\\".$configinc.".safe";
  148.         $phpmyadminauth="http";
  149.         $datei = fopen($phpmyadminconf,'w+');             
  150.             if($datei) 
  151.             {
  152.             for($z=0;$z<$i+1;$z++) 
  153.                 {
  154.                 if ($authzeile[0]==$z)
  155.                     {
  156.                     fputs($datei,$mynewzeile);
  157.                     }
  158.                     else
  159.                     {
  160.                     fputs($datei,$oldzeile[$z]);
  161.                     }
  162.                 }
  163.             }
  164.         }
  165.     }    
  166. }
  167.  
  168.  
  169. function htaccess($xauser, $xapasswd)
  170. {    
  171.     global $xamppdirconfig;
  172.     global $xapasswdtxtdir;
  173.     global $htpasswddir;
  174.     global $htpasswddirectory;
  175.     global $htxampp;
  176.     $curdir = getcwd();
  177.     list ($partwampp, $directorwampp) = spliti ('\\\htdocs', $curdir);
  178.     $htaccess=".htaccess";
  179.     $xapasswdtxt="xamppdirpasswd.txt";
  180.     $htpasswd="xampp.users";
  181.     $xapasswdtxtdir=$partwampp."\security\\".$xapasswdtxt;
  182.     $curspcript=$_SERVER["SCRIPT_FILENAME"];
  183.     // list ($left, $right) = split ('url', $curspcript);
  184.     // if ($left=="")
  185.     // {
  186.     $htxampp=$partwampp."\htdocs\\xampp\\".$htaccess;
  187.     // }
  188.     // else
  189.     // {
  190.     // $htxampp=$left.$htaccess;
  191.     // }
  192.     $htpasswdexe=$partwampp."\apache\\bin\\htpasswd.exe";
  193.     if (file_exists($htpasswdexe))
  194.     {
  195.     // $htpasswdexe="\"".$htpasswdexe."\"";
  196.     $htpasswddir="\"".$partwampp."\security\\".$htpasswd."\"";
  197.     $htpasswddirectory=$partwampp."\security\\".$htpasswd;    
  198.     $dir=$partwampp."\security\\";
  199.     $dh = @opendir($dir);
  200.     if ($dh)
  201.     { } else { system("md $dir"); } 
  202.     
  203.     $datei = fopen($htxampp,'w+');
  204.     $insert="AuthName \"xampp user\"\r\nAuthType Basic\r\nAuthUserFile $htpasswddir\r\nrequire valid-user"; 
  205.     fputs($datei,$insert); 
  206.     fclose($datei);
  207.     $htpassrealm = "\"$htpasswdexe\" -c -m -b c:\\xampp.users $xauser $xapasswd";
  208.     shell_exec("$htpassrealm");
  209.     
  210.     /// Better this way agains problems with "c:\program files" directories \\\\
  211.     if (@copy("c:\\xampp.users", $htpasswddirectory)) 
  212.         {
  213.         unlink ("c:\\xampp.users");
  214.         }
  215.         
  216.     $datei = fopen($xapasswdtxtdir,'w+');
  217.     $put="XAMPP user = $xauser\r\nXAMPP password = $xapasswd";
  218.     fputs($datei, $put);
  219.     fclose($datei);
  220.         $xamppdirconfig="ok";
  221.     
  222.     }
  223.     else
  224.     {
  225.         
  226.         $xamppdirconfig="notok";
  227.     }
  228. }
  229. ?>