0 && $pos < strlen($c)) { if ($c[$pos] === '{') $depth++; elseif ($c[$pos] === '}') $depth--; $pos++; } $block = substr($c, $start, $pos - $start); preg_match('/\broot\s+([^;]+);/', $block, $rm); $root = isset($rm[1]) ? trim(trim($rm[1]), "\"'") : ''; preg_match('/\bserver_name\s+([^;]+);/', $block, $sm); if (isset($sm[1])) { $names = preg_split('/\s+/', trim($sm[1]), -1, PREG_SPLIT_NO_EMPTY); foreach ($names as $name) { $d = is_valid_domain($name); if ($d && !in_array($d, $existed, true)) { $out_path = $root ?: dirname($path); $out_path = str_replace('\\', '/', $out_path); echo "{$out_path}@@@{$d}@@@nginx@@@{$path}\n"; } } } $offset = $pos; } } function scan_apache_file($path, $existed) { $c = @file_get_contents($path); if (!$c) return; $vhosts = preg_split('/]*>/i', $c, -1, PREG_SPLIT_NO_EMPTY); array_shift($vhosts); $parts = preg_split('/]*>/i', $c); for ($i = 1; $i < count($parts); $i++) { $block = $parts[$i]; $end = strpos($block, ''); if ($end !== false) $block = substr($block, 0, $end); preg_match('/DocumentRoot\s+["\']?([^"\'\\s]+)["\']?/', $block, $dm); $root = isset($dm[1]) ? trim($dm[1], "\"'") : ''; $names = []; if (preg_match('/ServerName\s+([^\\n#]+)/', $block, $m)) $names[] = trim($m[1]); if (preg_match_all('/ServerAlias\s+([^\\n#]+)/', $block, $aliases)) { foreach ($aliases[1] as $a) $names = array_merge($names, preg_split('/\s+/', trim($a), -1, PREG_SPLIT_NO_EMPTY)); } foreach ($names as $name) { $d = is_valid_domain($name); if ($d && !in_array($d, $existed, true)) { $out_path = $root ?: dirname($path); $out_path = str_replace('\\', '/', $out_path); echo "{$out_path}@@@{$d}@@@apache@@@{$path}\n"; } } } } function scan_conf_dir($dir, $existed) { if (!@is_dir($dir)) return; $files = @scandir($dir); if (!$files) return; foreach ($files as $f) { if ($f === '.' || $f === '..') continue; $p = $dir . '/' . $f; if (@is_dir($p)) continue; if ((substr($f, -5) === '.conf' || substr($f, -6) === '.vhost' || strpos($f, '.') === false) && @is_readable($p)) { if (strpos($p, 'nginx') !== false) scan_nginx_file($p, $existed); elseif (strpos($p, 'apache') !== false || strpos($p, 'httpd') !== false) scan_apache_file($p, $existed); } } } $dirs = [ '/etc/nginx/sites-enabled', '/etc/nginx/sites-available', '/etc/nginx/conf.d', '/etc/nginx/vhosts.d', '/etc/apache2/sites-enabled', '/etc/apache2/sites-available', '/etc/apache2/conf.d', '/etc/httpd/conf.d', '/etc/httpd/vhosts.d', ]; foreach ($dirs as $d) { scan_conf_dir($d, $existed); } die('!ended!');