Apache Includes Parser

Wrote this script to read and parse all included files in httpd.conf or any file specified when calling the PHP script. Will output content from httpd.conf(or any file specified) and all included files found and output to stdout. I used this to pipe the output to grep when searching for various Apache directives. Useful to find directives that are in a included file that are overwriting your directives set in httpd.conf.


<?php
error_reporting
(0);
if (
$argc != 2) {
echo <<<FILE
#################################################

Reads all ”Included files” in specified file and outputs to stdout.

Usage: php $argv[0] file
Example: php $argv
[0] httpd.conf
#####################################

FILE;
}
else
{
$file = file($argv[1]);
$content = “”;
try {
foreach (
$file as $line) {
$line = str_replace(“\n”,“”,$line);
if (
stristr($line,‘Include’) && !stristr($line,‘#’)) {
if (
preg_match(‘/^.*\*\.conf$/’,$line)) {
$str = str_replace(“Include ”,“”,$line);
$str = str_replace(“*.conf”,“”,$str);
$dirFiles = @scandir($str);
foreach (
$dirFiles as $dirFile) {
if (
stristr($dirFile,“.conf”)) {
$content .= file_get_contents($str.$dirFile);
}
}
}
elseif (
preg_match(‘/^.*[a-zA-z0-9]\.conf$/’,$line)) {
$content .= file_get_contents(substr($line, 8));
}
else
{
$str = str_replace(“Include ”,“”,$line);
$dirFiles = @scandir($str);
foreach (
$dirFiles as $dirFile) {
if (
stristr($dirFile,“.conf”)) {
$content .= file_get_contents($str.$dirFile);
}
}
}
}
print_r($content);
}
} catch (
Exception $e) {
echo
$e->getMessage();
}
}