Apache "Include" directive with wildcards

Published by cybso on
This is a post from my original site, which was hosted by the former blog service of the University of Osnabrück. I have moved it to the new site for archiving. Pages linked in this article may no longer work today, and the blog comments under the article no longer exist. Opinions expressed in this article reflect the point of view of the time of publication and do not necessarily reflect my opinion today.

Apache's include directive does not accept wildcards, so something like this won't be allowed:

Include /srv/www/vhosts/*/conf/vhost.conf

You can use mod_perl to realize this. Additionally, the following example does a simple permission check to ensure that the included file has not been modified by an ordinary user:

<perl>
    use File::stat;
    foreach $file (glob '/srv/www/vhosts/*/conf/vhost.conf') {
        my $stat = stat($file);
        if ($stat->uid != 0 || $stat->gid != 0) {
            warn "$file is not owned by root:root, skipping!\n";
            next;
        }
        if ($stat->mode & 0002) {
            warn "$file is world-writable, skipping!\n";
            next;
        }
        push @Include, $file;
    }
</perl>