#!/usr/bin/perl -w

use strict;
use vars qw( $BASE_PATH );
use Cwd 'abs_path';
use File::Basename;

$BASE_PATH = dirname(dirname(abs_path($0)));

# read in sites.txt
open(SITES, "$BASE_PATH/sites.txt") 
	|| die("Error: could not read sites.txt file $!\n");

while (<SITES>) {
	# FIXME: handle comments, blank lines!
	chomp(my $path = $_);
	my @parts = split('/', $path);
	my $site_name = $parts[-2];
	my $cmd = "$BASE_PATH/bin/vhost-audit.pl $path > $BASE_PATH/json/$site_name.json";
#	print("$cmd\n");
	# FIXME: would be better if we wrote out these files ourselves.
	open(AUDIT, "$cmd |")
		|| die("Error: could sudit site ($site_name) $!\n");
	close(AUDIT);
}

close(SITES);
