#!/usr/bin/perl -w
# -*- perl -*-
#
## (C) 1998 Michael Jastremski <mike@westphila.net>
##   for the Nessus project (http://www.nessus.org)
#
#  Usage:  nsr2html [--resolve] < report.nsr > report.html
#                   ^^^^^^^^^^ 
#                            ^ DNS lookups are turned off by default
#   


use strict;
use Socket;
use Getopt::Long;

no strict 'vars';
GetOptions("resolve!");

$|=1;

printf STDERR " Resolving hostnames, please be patient.\n" if $opt_resolve;



print << "HEADER";
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<HTML><HEAD><TITLE>nsr2html output</TITLE></HEAD><BODY BGCOLOR=#FFFFFF><BR><BR>
HEADER


	my %seen;
	my $n_nodes=1;


while(<STDIN>)
{
    my ($node,$port,@stuff) = split(/\s+/);

    if (not defined ($seen{$node}))
	{
		
		my ($n,$ip_info);

		if ($opt_resolve)
		{
            $n = gethostbyname($node);
			$ip_info = sprintf "[%s]",inet_ntoa($n);
		}

		inf("</ul><br><b>$n_nodes.&nbsp;$node $ip_info</b><ul>");
		$n_nodes++;
	}

    $seen{$node} = 1;


    if (grep("INFO|REPORT",@stuff))
	{
		my $info;
		foreach (@stuff)
	    {
			$info  .=  " $_  ";
	    }

		$info =~ s/\;/ /g;
		$info =~ s/(REPORT|INFO|Solution)/<b>$1<\/b>/g; 
		inf("<blockquote><i>$info</i></blockquote>");
	}

    else
	{
		warning("<li>TCP port number $port  is open</li>");
	}


}



#// Here is where you may want to customize the footer

print << "FOOTER";

<br><br><br>
<i>	HTML output created by nsr2html by <a href=http://westphila.net/mike>Michael Jastremski</a> <A href=mailto:mike\@westphila.net&subject=Mail+from+nsr2html+generated+page>&lt;mike\@westphila.net&gt;</a></i></font></body></html>
FOOTER



sub inf
{
    my $msg=shift;
    print "  $msg <br>\n";
    1;
}


sub warning
{
    my $msg=shift;
    print "<font color=#ff0000> $msg </font><br>\n";
    1;

}
