#!/usr/bin/perl
# Simple web report generation harness.
#
# Written by David MacKenzie <djm@web.us.uu.net>
# Please send comments and bug reports to fastresolve-bugs@web.us.uu.net.

##############################################################################
#   Copyright 1999 UUNET, an MCI WorldCom company.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.
##############################################################################

use Getopt::Std;

use vars qw($opt_c $opt_o);

main();
exit(0);

sub usage
{
    die "Usage: $0 [-c analog.cfg] [-o report.html] logfile...\n";
}

sub main
{
    my($prefix, $exec_prefix, $cfg, $report, $logfile, $cat);

    $prefix="/usr/local";
    $exec_prefix="${prefix}";
    $ENV{PATH}="${exec_prefix}/bin:$ENV{PATH}";

    getopts("c:o:") || usage();
    @ARGV || usage();

    $cfg = $opt_c || "${prefix}/share/fastresolve/analog.cfg";
    $report = $opt_o || "report.html";

    $cat = "cat";
    foreach $logfile (@ARGV) {
	if (! -f $logfile) {
	    die "$logfile: $!\n";
	}
	if ($logfile =~ m/\.gz$/) {
	    $cat = "gzcat";
	}
    }

    warn "Resolving IP addresses\n";
    system "$cat @ARGV | dns-terror -m100";

    warn "Getting domain owners\n";
    system "getdominfo -a -m10";

    warn "Creating Analog config files\n";
    system "convert-ip-db > dns.cache";
    system "convert-dom-db > subdomains.cfg";

    warn "Producing report $report\n";
    system "$cat @ARGV | analog -G +g$cfg > $report";
}
