vps_docroot.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. ///////////////////////////////////////////////////////////////////////////
  3. // Created and developed by Greg Zemskov, Revisium Company
  4. // Email: ai@revisium.com, http://revisium.com/ai/, skype: greg_zemskov
  5. // For non-commercial usage only
  6. ///////////////////////////////////////////////////////////////////////////
  7. $found_dirs = array();
  8. // exclude from scan list
  9. $exclude_dirs = array(
  10. '/usr/share',
  11. '/var/www',
  12. '/usr'
  13. );
  14. // add extra dirs to scan list
  15. $include_dirs = array(
  16. '/tmp',
  17. '/home/bitrix',
  18. '/var/www/bitrix',
  19. '/var/tmp'
  20. );
  21. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  22. function scan_configs($path, $recurs) {
  23. global $found_dirs;
  24. if (!file_exists($path)) {
  25. return;
  26. }
  27. if ($dir = opendir($path)) {
  28. while($file = readdir($dir)) {
  29. if (($file == '.') or ($file == '..'))
  30. continue;
  31. $name = $file;
  32. $file = $path . '/' . $file;
  33. if (is_dir($file) && $recurs) {
  34. scan_configs($file, true);
  35. }
  36. if (is_file($file) && filesize($file) < 5000000) {
  37. $content = file_get_contents($file);
  38. if ((preg_match_all('~DocumentRoot\s+[\'"]?(/[^\s\'"]+)~mi', $content, $out, PREG_PATTERN_ORDER)) ||
  39. (preg_match_all('~DocumentRoot\s+(/.+)~mi', $content, $out, PREG_PATTERN_ORDER)) ||
  40. (preg_match_all('~root_path\s+(/.+);~mi', $content, $out, PREG_PATTERN_ORDER)) ||
  41. (preg_match_all('~root\s+(/.+);$~mi', $content, $out, PREG_PATTERN_ORDER))) {
  42. foreach ($out[1] as $index => $docroot) {
  43. $docroot = "/" . trim(trim($docroot), "/");
  44. $found_dirs[$docroot] = 1;
  45. }
  46. }
  47. }
  48. }
  49. closedir($dir);
  50. }
  51. }
  52. scan_configs('/etc/apache2', true);
  53. scan_configs('/etc/httpd', true);
  54. scan_configs('/usr/local/nginx/conf', true);
  55. scan_configs('/etc/nginx', true);
  56. scan_configs('/usr/local/etc/nginx', true);
  57. scan_configs('/usr/local/directadmin/data', true);
  58. scan_configs('/home/admin/conf/', true);
  59. $result_list = array_merge(array_diff(array_keys($found_dirs), $exclude_dirs), $include_dirs);
  60. sort($result_list);
  61. foreach ($result_list as $dir) {
  62. if (file_exists($dir)) {
  63. echo $dir . "\n";
  64. }
  65. }