#!/usr/bin/perl

use strict;
use lib ('../lib');
use warnings;

my $mmm;

if ( defined( $ENV{SERVER_NAME} ) ) {

    # we are in cgi mode
    require CGI;
    if ( CGI::path_info() =~ m@/*lists.xml$@ ) {
        require MMM;
        print CGI::header( -type => 'text/xml' );
        $mmm = MMM->new( configfile => $ENV{MMM_CONFIG} ) or do {
            print "Please setup MMM_CONFIG in apache config";
            exit(0);
        };
        $mmm->load_queue();
        $mmm->build_list();
        exit(0);
    }
    else {
        print CGI::header();
        require MMM::Report::Html;
        $mmm = MMM::Report::Html->new( configfile => $ENV{MMM_CONFIG} ) or do {
            print "Please setup MMM_CONFIG in apache config";
            exit(0);
        };
    }
}
else {
    require MMM::Report::Console;
    $mmm =
      MMM::Report::Console->new( configfile => $ARGV[0] || $ENV{MMM_CONFIG} );
}

$mmm->load_queue();
$mmm->report();

