#!/sw/bin/perl -w #################################################################### # # ff.pl Version 1.0: Check system files at Sunsolve # # (c) 2001, Thomas Bader # # License: BSD #################################################################### # ---------------- # Modules # ---------------- require 5.002; use strict; use vars('$opt_v', '$opt_h'); use Socket; use Getopt::Std; # ---------------- # Declare vars # ---------------- my $basename; my $line; my $filetocheck; my $found = 0; my $remote = "sunsolve.sun.com"; # Sunsolves webserver my $port = 80; # Port of the webserver my $url = "/pub-cgi/fileFingerprints.pl"; # URL of the cgi script my $iaddr = inet_aton($remote) || die "no such host: $remote"; my $paddr = sockaddr_in($port, $iaddr); my $proto = getprotobyname('tcp'); # ---------------- # Parse command line options # --------------- # -v verbose / -h help getopts('vh'); if( defined($opt_h) || ! $ARGV[0] ) { ($basename = $0) =~ s/.*\///; # strip away the path print "Usage: $basename [-v] [-h] \\n"; exit(1); } # ---------------- # Get MD5SUM # ---------------- $filetocheck = qx#md5sum $ARGV[0] 2>/dev/null#; $filetocheck =~ s/ /%22/g; # HTTP-encoding # ---------------- # Open Socket # ---------------- socket(SOCK, PF_INET, SOCK_STREAM, $proto) || die "socket: $!"; connect(SOCK, $paddr) || die "connect: $!"; # ---------------- # Send Request # ---------------- send(SOCK, "GET $url?md5list=$filetocheck\r\n\r\n", 0); # ---------------- # Extract the Infos # ---------------- while(chomp($line=)) { if($line =~ /Results of Last Search/ && $found == 0) { print "File found; file is OK\n"; $found = 1; if( defined($opt_v) ) { print "\n"; } } if($line =~ /canonical-path:\s\(.*?)\<\/TT\>/ && defined($opt_v) ) { print "Canonical-Path: $1\n"; } if($line =~ /package:\s\(.*?)\<\/TT\>/ && defined($opt_v) ) { print "Package: $1\n"; } if($line =~ /version:\s\(.*?)\<\/TT\>/ && defined($opt_v) ) { print "Version: $1\n"; } if($line =~ /architecture:\s\(.*?)\<\/TT\>/ && defined($opt_v) ) { print "Architecture: $1\n"; } if($line =~ /source:\s\(.*?)\<\/TT\>/ && defined($opt_v) ) { print "Source: $1\n"; } if($line =~ /patch:\s\(.*?)\<\/TT\>/ && defined($opt_v) ) { print "Patch: $1\n"; } } # ---------------- # Warn about corrupt files # ---------------- if($found != 1) { print "Warning: File was not found in database or it is corrupt!\n"; } # ---------------- # Clean up # ---------------- close(SOCK);