For those of you who saw the earlier request for help, and offered
suggestions, thank you.  Here is the current implementation.

Using a static directory structure, I have incorporated a script that was
written by another member of this mailing list, Jason Scott Gessner, to
generate a results report based on the aggregate information produced by the
HFNetCheck utility published by www.shavlik.com for Microsoft.  The
following is the complete version of my patches.pl script with a link to the
site maintained by Jason Gessner for his hfnetchk_to_html.pl script:
http://www.multiply.org/software/hfnetchk/index.html.  One change has been
made to this script by Jason which alters its functionality, it now accepts
the option of CVS format instead of tab (simply changed the switch, and the
required matching parameter to reflect the record seperator in use for the
aggregate output).  I hope that the code is commented sufficiently to
explain what is going on, but if not, please feel free to ask, and I will
respond as quickly as possible.

#!/usr/bin/perl
#---------------------------------------------------------------------------
---#

# script name:  patches.pl

# version history
# -----------------------------
# version 0.0.1
# date:         May 9, 2002
# author:       Joshua R. Sidwell
#                   [EMAIL PROTECTED]
# comments: This script is designed to leverage HFNetChk.exe from
#           www.shavlik.com by creating a completely automated compliance
#           check for Servers and Workstations running Microsoft Windows
2000.
#           There are no command line options required for running this
script,
#           you do however need to ensure that you have the appropriate
#           directory structure in place as well as all of the required
files.
#           Some of these files are a part of Jason Scott Gessners
#           hfnetchk_to_html.pl script.  See his site for the most current
#           version of his script.  In the future, the command line and it's
#           options may change, so you need to review his documentation and
#           verify that it is setup appropriately.  Currently, you need to
#           maintain a folder named images in the Results directory to use
his
#           images.  The directory structure is as follows:
#           
#           C:\AutoSec
#               hfnetchk.exe
#               patches.pl
#               servers.txt
#               t_results.csv
#           C:\AutoSec\Results (This folder is populated by the patches.pl
#                               script at runtime.  It will have one file
per
#                               IP Address that you scan, a results.csv
#                               file, and a results.html file [generated by
#                               hfnetchk_to_html.pl by Jason Scott Gessner])
#           C:\AutoSec\Results\images
#                       alert.gif
#                       Curve_Aid.gif
#                       exclamation.gif
#                       info.gif
#                       LeftCurve_Top.gif
#                       RightCurve_Top.gif
#           C:\AutoSec\html
#                   html_CSV.pl (renamed hfnetchk_to_html.pl script) 
#                   style-msie.css
#
#           If you have any questions/comments regarding the patches.pl
script
#           please contact the author at the e-mail address provided above.
#
#           In the future, I will be trying to reduce the number of files,
and
#           provide this in a small executable file.
#
# --------------------------------CORP
SECTION-------------------------------- #
# This section has been removed for simplicity sake
# since it is merely a banner with my company inform-
# ation and a tag line for Jason Scott Gessner.
# --------------------------------CORP
SECTION-------------------------------- #


# --------------------------------PROG
SECTION-------------------------------- #
#  Create an anonymous hash to hold the values from the
C:\AutoSec\servers.txt
#  file.  This file has the following format:
#
#  IPAddress,Domain\UserName,Password
#  --OR--
#  IPAddress,UserName,Password (for servers that are not part of a Domain)

        %hash = (
                IP => "",
                UN => "",
                PW => ""
        );

#  Here we setup all of the files that we will be using throughout this
script.
#  Each one is relative to the $root folder, so it should be trivial to
change
#  the location where you place this.  The subdirectories, and files on the
#  other hand are "hardcoded" relative to the root directory, so you will
need
#  to follow the layout given above, or alter the script to suit your fancy.

        $root = "c:\\AutoSec";
        $html = "$root\\html";
        $folder = "$root\\Results";
        $output = "$folder\\results.csv";
        $sourcefile = "$root\\t_results.csv";
        $style = "$html\\style-msie.css";
        $outstyle = "$folder\\style-msie.css";

#  Here we are copying the t_results.csv  and the style-msie.css
#  files to the results subdirectory to make sure that they are present.
#  The advantage of this is that you can delete the entire contents of the
#  results directory when you are done running your report, and simply move
the
#  results.html file to your prefered location.
#  Thanks to [EMAIL PROTECTED] for the following code snippet.  It did
the
#  trick and solved one of my frustrations.

#  print "Path is $root\nSource is $sourcefile\nDestination is $output\n"; #
Debug Info
        if (-e $sourcefile) {
                `copy $sourcefile $output`;
        }
        if (! -e $output) { die "file copy failed\n"; }

        if (-e $style) {
                `copy $style $outstyle`;
        }
        if (! -e $outstyle) { die "file copy failed\n";}

#  Now we are getting to the meat of the program.  Here we are opening the
#  servers.txt file that we use to determine what hosts we are going to
check.
open(SERVERS, "<c:\\AutoSec\\servers.txt");
#  While we have a line in the servers.txt file, we will execute the
following
#  block of code....
while (<SERVERS>) {
#  Basic housekeeping, move the current line into the $line variable.
        $line = $_;
#  Here we are populating the hash that we created earlier with the
IPAddress,
#  UserName, and Password.
        ($hash->{IP},$hash->{UN},$hash->{PW}) = split(/,/, $line) or die
"Could not split the imput line from servers.txt";
#  Basic housekeeping, copy the IPAddress from the hash to the $ip variable.
        $ip = $hash->{IP};
#  Create the variable $imput, and give it the following value (this file is
#  used for the individual scans, and can be used individually with the
#  original version of hfnetchk_to_html.pl from Jason Scott Gessner.
        $imput = "$folder\\$ip.txt";
#  Here we are calling the external hfnetchk.exe program with the
information
#  from the servers.txt file that we pulled into the hash.  You may wish to
#  change some of these settings to fit your environment.  See the relevant
#  documentation on the Microsoft site or by typing hfnetchk.exe /?
        `hfnetchk.exe -i $hash->{IP} -z -v -t 128 -o tab -b -f $imput -u
$hash->{UN} -p $hash->{PW}`;
#  We now use the output file $ip.txt that we just created as our imput file
#  for another hash.  This one is designed to convert the standard tab
delimited
#  output of hfnetchk.exe to a comma seperated file (*.csv)
        open(SOURCE,"<$imput");
#  The hash receives the split information representing the
MachineName,Product,
#  Bulletin,Q Number, and Reason
        my %info = (
                MN => "",
                P => "",
                B => "",
                QN => "",
                R => ""
                );
#  While we have a line of text to process from our output file, we take
each
#  line and place it into the $text variable to do something with it.
        while (<SOURCE>) {
                $text = $_;
#  If the line begins with "Machine Name," we want to skip it since it is
#  redundant.
                if (m/Machine Name/g) {
                        next;
                } else {
#  If it does not match with "Machine Name" we want to split the line into
its
#  different parts.  So, to capture this, we open the $output filehandle and
#  print the hash with commas seperating the now split fields.
                open(OUTPUT,">>$output");
                ($info->{MN},$info->{P},$info->{B},$info->{QN},$info->{R}) =
split(/ /, $text);
                printf OUTPUT "$info->{MN}" . "," . "$info->{PB}" . "," .
"$info->{QN}" . "," . "$info->{R}" . "," . "$info->{S}" . "\n";
                close(OUTPUT);
                }
        }
        close SOURCE;
}
close SERVERS;
# --------------------------------PROG
SECTION-------------------------------- #


# --------------------------------HTML
FORMAT-------------------------------- #
#  This is a call to an external perl script that parses the results.csv
file
#  and outputs it to a formatted HTML file with all the relevant links to
the
#  Microsoft.com site.  Thanks to Jason Scott Gessner for writing this
script.
        `$html\\html_CSV.pl $folder\\results.csv $folder\\results.html cvs
yes`;
# --------------------------------HTML
FORMAT-------------------------------- #

Joshua Sidwell
Network Engineer, CISSP
1400 S. Grand Ave
Santa Ana, CA 92705
(714) 796-8383
[EMAIL PROTECTED]

--------- Email Confidentiality Notice -------
The information in this email may be confidential, proprietary and/or
sensitive and is intended only for use by the entity or individual to whom
it is addressed.  If you, the reader of this email and/or its attachments,
are not the intended recipient, you are hereby notified that any
dissemination, distribution, publishing, modification, storage or copying of
this email or any of its attachments is strictly prohibited.  If you have
received this communication in error, please immediately notify the
[EMAIL PROTECTED] and destroy all copies of this message along with any
attachments.

_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to