Cleaning Out the Attic

Cleaning out the attic
    Photo by timsamoff

Don’t you get a kick out of looking at old scripts that you’ve built? I’ve been going through some fossils. I’m pretty sure that some Carbon-14 (14C) testing is needed to date some of these scripts. While some scripts will never be used again, some are still relevant and useful.

I remember that 
Adam and I were asked to report (via Tivoli Inventory) which computers had CAC (or SmartCard) Readers. This information wasn’t available “out of the box” in Tivoli so we wrote a custom Inventory scanner. I’ve kept the MIF creation logic (see, doesn’t MIF take you back?) for giggles. I still use Devcon.exe(which is referenced in the script).

#!/usr/bin/perl

############################################################################
#
# This script will scan and collect information about SmartCard Readers
# This script depends on devcon.exe (which is freely available)
#
# SPC – 25 March 2005 – Original Script written
############################################################################

use Win32;

$dev=’device’;
$status=’status’;

sub main {
chkver();
wrtmif();
rundevcon();
closemif();
}

sub chkver {
#Devcon cannot run on NT 4.0 systems. Exclude all NT 4.0 from executing.
($string, $major, $minor, $build, $id) = Win32::GetOSVersion();
print “Major = $major\n”;
if ($major == 4) {
print “This script will not run on Windows NT Version $major\n”;
exit
}
}

sub wrtmif {
#write scardrdr.mif file
$cMif=”scardrdr.mif”;
open(FILE,”>$cMif”) || die “Could not open MIF file”;

print (FILE “START COMPONENT\n”);
print (FILE “\tNAME = \”SCARDRDR.MIF\”\n”);
print (FILE “\tDESCRIPTION = \”Smart Card Readers installed on System\”\n”);
print (FILE “\tSTART GROUP\n”);
print (FILE “\t\tNAME = \”ESM_SMART_CARD_READERS\”\n”);
print (FILE “\t\tID = 1\n”);
print (FILE “\t\tCLASS = \”ESM_SMART_CARD_READERS|1\”\n”);
print (FILE “\t\tSTART ATTRIBUTE\n”);
print (FILE “\t\t\tNAME = \”HWID\”\n”);
print (FILE “\t\t\tID = 1\n”);
print (FILE “\t\t\tACCESS = READ-ONLY\n”);
print (FILE “\t\t\tTYPE = STRING(255)\n”);
print (FILE “\t\t\tVALUE = \”\”\n”);
print (FILE “\t\tEND ATTRIBUTE\n”);
print (FILE “\t\tSTART ATTRIBUTE\n”);
print (FILE “\t\t\tNAME = \”Device\”\n”);
print (FILE “\t\t\tID = 2\n”);
print (FILE “\t\t\tACCESS = READ-ONLY\n”);
print (FILE “\t\t\tTYPE = STRING(255)\n”);
print (FILE “\t\t\tVALUE = \”\”\n”);
print (FILE “\t\tEND ATTRIBUTE\n”);
print (FILE “\t\tSTART ATTRIBUTE\n”);
print (FILE “\t\t\tNAME = \”STATUS\”\n”);
print (FILE “\t\t\tID = 3\n”);
print (FILE “\t\t\tACCESS = READ-ONLY\n”);
print (FILE “\t\t\tTYPE = STRING(512)\n”);
print (FILE “\t\t\tVALUE = \”\”\n”);
print (FILE “\t\tEND ATTRIBUTE\n”);
print (FILE “\t\tKEY = 1\n”);
print (FILE “\tEND GROUP\n”);
print (FILE “\tSTART TABLE\n”);
print (FILE “\t\tNAME = \”SCARDRDR.MIF\”\n”);
print (FILE “\t\tID = 1\n”);
print (FILE “\t\tCLASS = \”ESM_SMART_CARD_READERS|1\”\n”);

}

sub rundevcon {
#run Devcon and grab all info regarding CAC Readers
@dev = `devcon.exe status =SmartCardReader`;
$grabDev = 1;
$readName = 0;
$noDev = 1;
foreach $line (@dev) {

$line =~ s/^\s+//;
$line =~ s/\s+$//;
if ($grabDev) {
chomp $line;
$hwid=$line;
print “HW ID = $hwid\n”;
$grabDev=”;
}
if ($readName) {
print ‘readname is running’;
chomp $line;
$status=$line;
add2mif();
$readName=”;
$noDev=0;
$grabDev = 1;
}

if ($line =~ /^Name: (.+)/) {
$dev=$1;
print “Device Name is: $dev\n”;
$readName = 1;
}

}

if ($noDev) {
$hwid=’0000′;
$dev=’No Devices Found’;
$status=’DISABLED’;
add2mif();
}
}

sub add2mif {
#add data content to scardrdr.mif file
print (FILE “\t\t\t{\”$hwid\”,\”$dev\”,\”$status\”}\n”);
}

sub closemif {
#finish writing mif file
print (FILE “\tEND TABLE\n”);
print (FILE “END COMPONENT\n”);
close (FILE);
}

main();

I guess Mom was wrong when she said “if you haven’t used it in six months, throw it away”.  I always did hate cleaning out the attic.