#
require 'config/xml.cf';
require 'config/version.pl';
require 'perl/misc.pl';
require 'perllib/getopts.pl';
require 'config/htm.cf';
sub save_htm {
local($path) = @_;
$xml         = "results/$sara_data/$report_xml";
@level       = "";
@level_num   = 0;
$htm_cnt     = 0;
%host_data   = ();
%vuln_data   = ();
%green_data  = ();
%class_data  = ();
%subnet_data = ();
open (XML,$xml);
while (<XML>) {
#
# Find next start tag
# 
   if (/<[a-zA-Z0-9\_\-\=\"\? ][a-zA-Z0-9\_\-\=\"\/\.\? ]+>/) {
    $class = "";
    ($dum,$tag_start) = split(/</);
    ($tag_start,$dum) = split(/>/,$tag_start);
    if ($tag_start =~ /class\=/) {
      ($tag_start,$class) = split(/\s+/,$tag_start);
      ($dum,$class) = split(/\=/,$class);
      $class  =~ s/\"//g;
      $class .= "=";
    } elsif ($tag_start =~ /xmlns\=/) {
      ($tag_start,$dum) = split(/\s+/,$tag_start);
    }
    $_ =~ s/<[a-zA-Z0-9\_\-\=\" ][a-zA-Z0-9\_\-\=\"\/\. ]+>/%$class/;
    next if ($tag_start =~ /xml version/);
    $level[$level_num] = $tag_start;    
    if ($tag_start eq "$tag_host") {
      $_htm  = 0;
      $_data = 0;
    }
    $level_num++;
  }
#
#  Find next stop tag
#
   if (/<\/[a-zA-Z0-9\_\-\=\" ]+>/) {
    ($_data,$tag_stop) = split(/</);
    $_data =~ s/^\s+%//;
    $_data =~ s/\s+$//;
    $_data =~ s/\n//g;
    ($tag_stop,$dum) = split(/>/,$tag_stop);
    ($dum,$tag_stop) = split(/\//,$tag_stop);
    $level_num--;
    if ($tag_start eq $tag_stop) {
        $$tag_start = $_data;   
# Load Host Data
        if ($tag_start eq $tag_id) {
          $scan_data{$tag_id}                       = $$tag_id;
        } elsif ($tag_start eq $tag_date) {
          $scan_data{$tag_date}                     = $$tag_date; 
        } elsif ($tag_start eq $tag_version) {
          $scan_data{$tag_version}                  = $$tag_version;
        } elsif ($tag_start eq $tag_level) {
          $scan_data{$tag_level}                    = $$tag_level;
        } elsif ($tag_start eq $tag_vul_cnt) {
          ($title,$value) = split(/\=/, $$tag_start);
          $summary_data{$title} = $value;
        } elsif ($tag_start eq $tag_host_IP) {
          $host_data{$$tag_host_IP}{$tag_sub_info}    = $$tag_sub_info;
          $subnet_data{$$tag_sub_info}{$tag_host_IP} .= "$$tag_host_IP;";
        } elsif ($tag_stop eq $tag_host_name) {
          $host_data{$$tag_host_IP}{$tag_host_name}   = $$tag_host_name;
        } elsif ($tag_stop eq $tag_host_mac) {
           $host_data{$$tag_host_IP}{$tag_host_mac}   = $$tag_host_mac;
        } elsif ($tag_stop eq $tag_host_fw) {
           $host_data{$$tag_host_IP}{$tag_host_fw}    = $$tag_host_fw;
        } elsif ($tag_stop eq $tag_host_os) {
          $host_data{$$tag_host_IP}{$tag_host_os}     = $$tag_host_os;
        } elsif ($tag_stop eq $tag_host_nb) {
          $host_data{$$tag_host_IP}{$tag_host_nb}     = $$tag_host_nb;
        } elsif ($tag_stop eq $tag_host_domain) {
          $host_data{$$tag_host_IP}{$tag_host_domain} = $$tag_host_domain;
        } elsif ($tag_stop eq $tag_host_green) {
          $host_data{$$tag_host_IP}{$tag_host_green}  = $$tag_host_green;
        } elsif ($tag_stop eq $tag_host_red) {
          $host_data{$$tag_host_IP}{$tag_host_red}    = $$tag_host_red;
        } elsif ($tag_stop eq $tag_host_yellow) {
          $host_data{$$tag_host_IP}{$tag_host_yellow} = $$tag_host_yellow;
        } elsif ($tag_stop eq $tag_host_brown) {
          $host_data{$$tag_host_IP}{$tag_host_brown}  = $$tag_host_brown;
        } elsif ($tag_stop eq $tag_host_gray) {
          $host_data{$$tag_host_IP}{$tag_host_gray}   = $$tag_host_gray;
        } elsif ($tag_start eq $tag_data) {
          $vuln_data{$$tag_data}{$tag_class}          = $$tag_class;
          $vuln_data{$$tag_data}{$tag_host_IP}       .= "x $$tag_host_IP x";
          $vuln_data{$$tag_data}{$tag_severity}       = $$tag_severity;
          $host_data{$$tag_host_IP}{'Vulnerable'}     = "YES";
        } elsif ($tag_start eq $tag_cve) {
          $cve_data{$$tag_cve}{$$tag_data}             = "$$tag_data";
        } elsif ($tag_start eq $tag_sans) {
          $cve_data{$$tag_cve}{$tag_sans}            .= "$$tag_sans;";
        } elsif ($tag_start eq $tag_fp) {
          $fp_data{$$tag_data}{$$tag_host_IP}         = $$tag_fp;
        } elsif (($tag_start eq $tag_svc_port) && 
          $$tag_severity eq "GREEN") {
          $green_data{$$tag_svc_name}{$tag_host_IP}  .= "x $$tag_host_IP x";
          $green_data{$$tag_svc_name}{$tag_svc_port}  = $$tag_svc_port;
        }
    } 
    if ($level[$level_num] eq $tag_stop) {
    } else {
       die "error: start tag $level[$level_num] and stop tag ($tag_stop) mismatch\n";
  } 
 }
}
close(XML);
open(HTM, ">$path") || die "cannot save htm to $path: $!";
&htm_write(%host_data, %green_data, %vuln_data);
close(HTM);
}
sub htm_bar_chart {
  $total_bar = $summary_data{'Total'};
  if ($total_bar >= 1) {
    $green_per = int(((450 * $summary_data{'Green'}) / $total_bar) +.5);
    $black_per = int(((450 * $summary_data{'Gray'}) / $total_bar) +.5);
    $red_per =   int(((450 * $summary_data{'Red'}) / $total_bar) +.5);
    $yellow_per= int(((450 * $summary_data{'Yellow'}) / $total_bar) +.5);
    $brown_per = int(((450 * $summary_data{'Brown'}) / $total_bar) +.5);
    $return  = "<UL><UL><UL>\n";
    $return .= "<TABLE BORDER=0><TR><TD width=\"75\"><Font size=2>Green ($summary_data{'Green'})</Font></TD>\n";
    $return .= "<TD width=\"$green_per\" BGCOLOR=\"Green\"><Font Size=2>&nbsp;</Font></TD>\n";
    $return .= "<TD><Font size=2>$green_bar</Font></TD></TR></TABLE>\n";

    $return .= "<TABLE BORDER=0><TR><TD width=\"75\"><Font size=2>Grey ($summary_data{'Gray'})</Font></TD>\n";
    $return .= "<TD width=\"$black_per\" BGCOLOR=\"#808080\"><Font size=2>&nbsp;</Font></TD>\n";
    $return .= "<TD><Font size=2>$black_bar</Font></TD></TR></TABLE>\n";

    $return .= "<TABLE BORDER=0><TR><TD width=\"75\"><Font size=2>Red ($summary_data{'Red'})</Font></TD>\n";
    $return .= "<TD width=\"$red_per\" BGCOLOR=\"RED\"><Font size=2>&nbsp;</Font></TD>\n";
    $return .= "<TD><Font size=2>$red_bar</Font></TD></TR></TABLE>\n";

    $return .= "<TABLE BORDER=0><TR><TD width=\"75\"><Font size=2>Yellow ($summary_data{'Yellow'})</Font></TD>\n";
    $return .= "<TD width=\"$yellow_per\" BGCOLOR=\"YELLOW\"><Font size=2>&nbsp;</Font></TD>\n";
    $return .= "<TD><Font size=2>$yellow_bar</Font></TD></TR></TABLE>\n";

    $return .= "<TABLE BORDER=0><TR><TD width=\"75\"><Font size=2>Brown ($summary_data{'Brown'})</Font></TD>\n";
    $return .= "<TD width=\"$brown_per\" BGCOLOR=\"#800000\"><Font size=2>&nbsp;</Font></TD>\n";
    $return .= "<TD><Font size=2>$brown_bar</Font size=2></TD></TR></TABLE>\n";
    $return .= "<P> <B>Figure 1  Host Summary by Color</B> </UL></UL></UL>\n";
  }
  return $return;
}
sub htm_table {
    local (@args)      = @_;
   local $test         = 0;
   local $cnt          = 0;
   local $null         = '&lt;None&gt;<BR>';
   local $width        = "";
   local $twidth       = "630";
   local $face         = "Face\=$font_face" if $font_face;
   $twidth             = "570" if ($htm_border == 0);
   $width              = "width=350" if ($htm_type eq "Vul");
   $return  = "<TABLE BGCOLOR=\"#DFDFDF\" BORDER = \"$htm_border\" width = $twidth>\n";
   for (@args) {
     $null = "" if (/[a-zA-Z0-9]+/);
     if ($test == 0) {
        $return .= "<TR>";
        $_width  = $width;
     } else {
        $_width  = "";
     } 
     $return .= "<TD $_width valign=top><Font size=2 $face>$args[$cnt]</Font></TD>\n"; 
     $cnt++;
     $test++;
     $test = 0 if ($test ==  $htm_columns);
     $return .= "</TR>\n" if ($test == 0);
   }
   if ($null) {
     $return = $null;
   } else {
     $return .= "</TR>\n" if ($test != 0);
     $return .= "</TABLE>\n";
   }
   if ($caption) {
     $return .= "<TABLE border=0 width=640><TR><TD>";
     $return .= "<Center><Font size=2 $face><B>$caption</B></Font></Center></TD></TR></TABLE\n";
   }
   return $return;
}
sub get_subnet_data {
  local @args = @_;
  local $_net = $args[0];
    (@net_ip) = split(/\;/,$subnet_data{$_net}{$tag_host_IP});
    @table_host = "";
    $host_cnt   = 0;
     $table_host[$host_cnt++]  = "<Center><B>Host Name</B></Center>";
     $table_host[$host_cnt++]  = "<Center><B>Host IP</B></Center>";
     $table_host[$host_cnt++]  = "<Center><B>NetBios Name</B></Center>";
     $table_host[$host_cnt++]  = "<Center><B>Operating System</B></Center>";
     $table_host[$host_cnt++]  = "<B>Grn</B>";
     $table_host[$host_cnt++]  = "<B>Red</B>";
     $table_host[$host_cnt++]  = "<B>Yel</B>";
     $table_host[$host_cnt++]  = "<B>Brn</B>";
     $table_host[$host_cnt++]  = "<B>FP</B>";

    for $_host (sort @net_ip) {
       $name_ip =  "N_$_host";
       $name_ip =~ s/\./_/g;
       if (($host_data{$_host}{'Vulnerable'} ne "YES") && ($novul eq "on") && ($option ne "default")){
         $table_host[$host_cnt++] = "$host_data{$_host}{$tag_host_name}";
       } else {
         $table_host[$host_cnt++] = "<A HREF=\"\#$name_ip\">$host_data{$_host}{$tag_host_name}</a>";
       }
       $table_host[$host_cnt++] = "$_host";
       $table_host[$host_cnt++] = "$host_data{$_host}{$tag_host_nb}";
       $table_host[$host_cnt++] = "$host_data{$_host}{$tag_host_os}";
       $table_host[$host_cnt++] = "$host_data{$_host}{$tag_host_green}";
       $table_host[$host_cnt++] = "$host_data{$_host}{$tag_host_red}";
       $table_host[$host_cnt++] = "$host_data{$_host}{$tag_host_yellow}";
       $table_host[$host_cnt++] = "$host_data{$_host}{$tag_host_brown}";
       $table_host[$host_cnt++] = "$host_data{$_host}{$tag_host_gray}";
    }
       $htm_columns = 9;
       $htm_border  = 1;
       $font_size   = 2;
       $font_face   = "arial";
       $htm_type    = "";
       $host_table = &htm_table(@table_host);
}

sub get_host_data {
local @args = @_;
local $_host = $args[0];
$fw_note = $host_data{$_host}{$tag_host_fw};
if ($fw_note !~ /none/ && $fw_note) {
   $fw_note = "Note: Host may be protected by a firewall ($fw_note)";
   $fw_star = '*';
} else {
   $fw_note = "";
   $fw_star = "";
}

$vuln_cnt     = $host_data{$_host}{$tag_host_red}+$host_data{$_host}{$tag_host_yellow}+$host_data{$_host}{$tag_host_brown};
@table_hosts  = ("<Center><B>Name</B></Center>","<Center><B>IP</B></Center>",
                 "<Center><B>NetBios</B></Center>",
                 "<Center><B>Netbios Domain</B></Center>",,
                 "<Center><B>Operating System</B></Center>",
                 "$host_data{$_host}{$tag_host_name}",
                 "$_host",
                 "$host_data{$_host}{$tag_host_nb}",
                 "$host_data{$_host}{$tag_host_domain}",
                 "$host_data{$_host}{$tag_host_os}");

   $htm_columns = 5;
   $htm_border  = 1;
   $htm_type    = "";
   $caption     = "";
   $name_ip     = "N_$_host";
   $name_ip     =~ s/\./_/g;
   $host_output = "<A NAME=\"$name_ip\">";
   $host_output .= &htm_table(@table_hosts);
   $host_output .= "<P><B>$fw_star $fw_note</B><P>\n";
   return $host_output;
}
sub get_host_svc($_host) {
  my @args = @_;
  my $_host = $args[0];
  $table_cnt   = 0;
  @table_hosts  = "";
  for $_service (sort keys %green_data) {
    if ( "$green_data{$_service}{$tag_host_IP}" =~ /x $_host x/) {
      if ($table_cnt  == 0) {
        $table_hosts[$table_cnt++] .= "&nbsp;&nbsp; $_service ($green_data{$_service}{$tag_svc_port})<BR>\n";
      }elsif ($table_cnt == 1) {
        $table_hosts[$table_cnt++] .= "&nbsp;&nbsp; $_service ($green_data{$_service}{$tag_svc_port})<BR>\n";
      }elsif ($table_cnt == 2) {
        $table_hosts[$table_cnt++] .= "&nbsp;&nbsp; $_service ($green_data{$_service}{$tag_svc_port})<BR>\n";
      }elsif ($table_cnt == 3) {
        $table_hosts[$table_cnt]   .= "&nbsp;&nbsp; $_service ($green_data{$_service}{$tag_svc_port})<BR>\n";
        $table_cnt = 0;
      }
    }
  }
  $htm_columns = 4;
  $htm_border  = 0;
  $font_size   = 2;
  $font_face   = "arial";
  $htm_type    = "";
  $caption     = 0;
  $host_table  = &htm_table(@table_hosts);
  return $host_table;
}
sub get_host_vulns($_host) {
  local @args  = @_;
  local $_host = $args[0];
      $list_cnt   = 0;
      $red_cnt    = 0;
      $yellow_cnt = 0;
      $brown_cnt  = 0;
      $gray_cnt   = 0;
      @list_vulns = "";
      @red_vulns  = "";
      @yellow_vulns = "";
      @brown_vulns  = "";
      @gray_vulns   = "";
      $list_vulns[$list_cnt++]    = "&lt;None&gt;<BR>";
      $list_vulns[$list_cnt++]    = "";
      $list_vulns[$list_cnt++]    = "";
      $list_vulns[$list_cnt++]    = "";
      $vuln_found = 0;
      for $_data (keys %vuln_data) {
        $cve_cnt    = 0;
        $sans_cnt   = 0;
        $_sans_cnt  = 0;
        @list_cves  = "";
        @list_sans  = "";
        @_list_sans = "";
        if ( "$vuln_data{$_data}{$tag_host_IP}" =~ /x $_host x/) {
          if ($vuln_found == 0) {
            $vuln_found = 1;
            $list_cnt = $list_cnt - 4;
            $list_vulns[$list_cnt++]    = "<Center><B>Vulnerability Class/Data</B></Center>";
            $list_vulns[$list_cnt++]    = "<B>Severity</B>";
            $list_vulns[$list_cnt++]    = "<B>CVE No.</B>";
            $list_vulns[$list_cnt++]    = "<B>Top20</B>"
          }
          for $_cve (sort {$b cmp $a} keys %cve_data) {
           if ( "$cve_data{$_cve}{$_data}" eq "$_data") {
             if ($cve_data{$_cve}{$tag_sans}) {
               (@sans20)  = split(/;/,$cve_data{$_cve}{$tag_sans});
               for (@sans20) {
                  $_list_sans[$_sans_cnt++]  = "$_";
               }
             }
             if ($cve_cnt <= 1) {
               $list_cves[$cve_cnt++]    = "$_cve";
             } elsif ($cve_cnt == 2) {
               $list_cves[$cve_cnt -1]  .= "\+";
               $cve_cnt++;
             }
           }
         }
         for (@_list_sans) {
           $dup = "";
           $_sans = $_;
           for (@list_sans) {
             $dup = "YES" if ($_sans eq $_);
           }
           if (!$dup) {
             if ($sans_cnt <= 1) {
               $list_sans[$sans_cnt++]    = $_sans;
             } elsif ($sans_cnt ==2) {
               $list_sans[$sans_cnt - 1] .="\+";
               $sans_cnt++;
             }
           }
         }
         if ($fp_data{$_data}{$_host} eq "FP") {
           $_severity  = "gray";
         } else {
           $_severity                  =lc($vuln_data{$_data}{$tag_severity});
         }
         $_class = $class = "$vuln_data{$_data}{$tag_class}";
         $_class =~ s/\s/_/g;
         if ($_class =~ /\[/) {
           ($dum, $_class) = split(/\[/,$_class);
           ($_class,$dum)  = split(/\]/,$_class);
         }
         if ($list_sans[0]) {
             $sans_string = "<A HREF=\"http://www.sans.org/top20\">$list_sans[0]</A><BR>\n";
         } else {
             $sans_string =" ";
         }
         if ($_severity eq "red") {
           $red_vulns[$red_cnt++]    = "&nbsp;&nbsp;$class<BR>\n&nbsp;&nbsp;<A HREF=\"#$list_cves[0]\">$_data</A>";
           $red_vulns[$red_cnt++]    = "&nbsp;$_severity";
           $red_vulns[$red_cnt++]    = "$list_cves[0]<BR>\n$list_cves[1]";
           $red_vulns[$red_cnt++]    = "$sans_string";
         } elsif ($_severity eq "yellow") {
           $yellow_vulns[$yellow_cnt++]    = "&nbsp;&nbsp;$class<BR>\n&nbsp;&nbsp;<A HREF=\"#$list_cves[0]\">$_data</A>";
           $yellow_vulns[$yellow_cnt++]    = "&nbsp;$_severity";
           $yellow_vulns[$yellow_cnt++]    = "$list_cves[0]<BR>\n$list_cves[1]";
           $yellow_vulns[$yellow_cnt++]    = "$sans_string";
         } elsif ($_severity eq "brown") {
           $brown_vulns[$brown_cnt++]    = "&nbsp;&nbsp;$class<BR>\n&nbsp;&nbsp;<A HREF=\"#$list_cves[0]\">$_data</A>";
           $brown_vulns[$brown_cnt++]    = "&nbsp;$_severity";
           $brown_vulns[$brown_cnt++]    = "$list_cves[0]<BR>\n$list_cves[1]";
           $brown_vulns[$brown_cnt++]    = "$sans_string";
         } elsif ($_severity eq "gray") {
           $gray_vulns[$gray_cnt++]    = "&nbsp;&nbsp;$class<BR>\n&nbsp;&nbsp;<A HREF=\"#$list_cves[0]\">$_data</A>";
           $gray_vulns[$gray_cnt++]    = "&nbsp;$_severity";
           $gray_vulns[$gray_cnt++]    = "$list_cves[0]<BR>\n$list_cves[1]";
           $gray_vulns[$gray_cnt++]    = "$sans_string";
         }
       }
      }

      for (@red_vulns) {
        $list_vulns[$list_cnt++] = $_ if ($_);
      }
      for (@yellow_vulns) {
        $list_vulns[$list_cnt++] = $_ if ($_);
      }
      for (@brown_vulns) {
        $list_vulns[$list_cnt++] = $_ if ($_);;
      }
#      for (@gray_vulns) {
#        $list_vulns[$list_cnt++] = $_;
#      }
      $htm_columns = 4;
      $htm_border  = 0;
      $font_size   = 2;
      $font_face   = "arial";
      $htm_type    = "Vul";
      $caption     = "";
      $vulns       = &htm_table(@list_vulns);
      $vulns      .= "</UL><P><Font Face=Arial><B>False Positives</B></Font><UL><P>\n";
      $greys       = &htm_table(@gray_vulns);
      $vulns      .= $greys;
      if ($vuln_found == 1) {
         return $vulns;
      } else {
         return '&lt;None&gt;<BR>';
      }
}

sub get_vulns() {
  my $_host;
  $red_cnt    = 0;
  $yellow_cnt = 0;
  $brown_cnt  = 0;
  $gray_cnt   = 0;
  @red_vulns  = "";
  @yellow_vulns = "";
  @brown_vulns  = "";
  @gray_vulns   = "";
  $font         = "<Font Face=\"Arial\" Size=\"1\">";
  $font1        = "<Font Face=\"Arial\" Size=\"2\">";
    for $_host (sort keys %host_data) {
      $host_name = "$host_data{$_host}{$tag_host_name}";
      $name_ip     = "N_$_host";
      $name_ip     =~ s/\./_/g;
      for $_data (keys %vuln_data) {
        if ( "$vuln_data{$_data}{$tag_host_IP}" =~ /x $_host x/) {
         if ($fp_data{$_data}{$_host} eq "FP") {
           $_severity  = "gray";
         } else {
           $_severity                  =lc($vuln_data{$_data}{$tag_severity});
         }
         $_class = $class = "$vuln_data{$_data}{$tag_class}";
         $_class =~ s/\s/_/g;
         if ($_class =~ /\[/) {
           ($dum, $_class) = split(/\[/,$_class);
           ($_class,$dum)  = split(/\]/,$_class);
         }
# New Stuff
         $cve_cnt = 0;
         for $_cve (sort {$b cmp $a} keys %cve_data) {
           if ( "$cve_data{$_cve}{$_data}" eq "$_data") {
             if ($cve_data{$_cve}{$tag_sans}) {
               (@sans20)  = split(/;/,$cve_data{$_cve}{$tag_sans});
               for (@sans20) {
                  $_list_sans[$_sans_cnt++]  = "$_";
               }
             }
             if ($cve_cnt <= 1) {
               $list_cves[$cve_cnt++]    = "$_cve";
             } elsif ($cve_cnt == 2) {
               $list_cves[$cve_cnt -1]  .= "\+";
               $cve_cnt++;
             }
           }
         }
# New Stuff
         $class_data{$_class} = $_class;
         if ($_severity eq "red") {
           $red_vulns[$red_cnt++]       = "<TR><TD valign=top>$font&nbsp;<A HREF=\"\#$name_ip\">$host_name</A></Font></TD>";
           $red_vulns[$red_cnt++]       = "<TD>$font&nbsp;<A HREF=\"#$list_cves[0]\">$_data</Font></TD></TR>\n";
         } elsif ($_severity eq "yellow") {
           $yellow_vulns[$yellow_cnt++] = "<TR><TD valign=top>$font&nbsp;<A HREF=\"\#$name_ip\">$host_name</A></Font></TD>";
           $yellow_vulns[$yellow_cnt++] = "<TD>$font&nbsp;<A HREF=\"#$list_cves[0]\">$_data</Font></TD></TR>\n";
         } elsif ($_severity eq "brown") {
           $brown_vulns[$brown_cnt++]   = "<TR><TD valign=top>$font&nbsp;<A HREF=\"\#$name_ip\">$host_name</A></Font></TD>";
           $brown_vulns[$brown_cnt++]   = "<TD>$font&nbsp;<A HREF=\"#$list_cves[0]\">$_data</Font></TD></TR>\n";
         } elsif ($_severity eq "gray") {
           $gray_vulns[$gray_cnt++]     = "<TR><TD valign=top>$font&nbsp;<A HREF=\"\#$name_ip\">$host_name</A></Font></TD>";
           $gray_vulns[$gray_cnt++]     = "<TD>$font&nbsp;<A HREF=\"#$list_cves[0]\">$_data</Font></TD></TR>\n";
         }
       }
      }
    }
    $return      = "<P>$font1<B>Critical Vulnerabilities (RED)</B></Font><P>\n"; 
    $return     .= "<UL><TABLE BGCOLOR=\"#DFDFDF\" width=570 BORDER = 0>";
    for (@red_vulns) {
      $return   .= $_;
    }
    $return     .= "</TABLE></UL>\n";
    $return     .= "<P>$font1<B>Probable Vulnerabilities (YELLOW)</B></Font><P>\n";
    $return     .= "<UL><TABLE BGCOLOR=\"#DFDFDF\" width=570 BORDER = 0>\n";
    for (@yellow_vulns) {
      $return   .= $_;
    }
    $return     .= "</TABLE></UL>\n";
    $return     .= "<P>$font1<B>Possible Vulnerabilities (BROWN)</B></Font><P>\n";
    $return     .= "<UL><TABLE BGCOLOR=\"#DFDFDF\" width=570 BORDER = 0>\n";
    for (@brown_vulns) {
      $return   .= $_;
    }
    $return     .= "</TABLE></UL>\n";
    $return     .= "<P>$font1<B>Labeled as False Positive (GRAY)</B></Font><P>\n";
    $return     .= "<UL><TABLE BGCOLOR=\"#DFDFDF\" width=570 BORDER = 0>\n";
    for (@gray_vulns) {
      $return   .= $_;
    }
    $return     .= "</TABLE></UL>";
    return $return;
}
sub get_tutorials {
  my $BASE    = "html/nvd/";
  my $_data   = "";
  my $_class  = "";
  my @_cves   = "";
  my @_sorted = "";
  my $cve_cnt = 0;

  for $_data (keys %vuln_data) {
     $_class = $class = "$vuln_data{$_data}{$tag_class}";
     $_cve = &get_cve($_class, $_data);
     $_cve = "NOCVE" if (!$_cve);
     if ("@_cves" !~ /$_cve/) {
       $_cves[$cve_cnt++] = $_cve;
     }
  }
  @sorted = sort(@_cves);
  for (@sorted) {
     print HTM "<A NAME=$_>\n";
     open (CVE, "$BASE$_.html");
     while(<CVE>) {
       next if /$\<HTML\>/;
       next if /$\<\/HTML\>/;
       next if /$\<HEAD\>/;
       next if /$\<\/HEAD\>/;
       next if /$\<TITLE\>/;
       next if /$\<BODY\>/;
       next if /$\<\/BODY\>/;
       print HTM "$_";
     }
  }
}

sub get_todays_date {
  my ($mday,$mon,$year,$dum,@month);
  @month    =  ('January', 'February', 'March', 'April', 'May', 'June',
                'July', 'August', 'September', 'October', 'November','December'); 
  ($dum,$dum,$dum,$mday,$mon,$year,$dum,$dum,$dum) = localtime();
  $year += 1900;
  $mon   = $month[$mon];
  $return = "$mday $mon $year";
  return $return
}
1;
