#!/usr/bin/perl ###### /usr/local/bin/perl5 is an unusal name for the perl interpreter. ###### on many systems, perl is located in /usr/bin/perl, and rarely ###### carries a numeric suffix. ###### ###### You can try executing "which perl" or "locate /perl" ###### to try and locate perl, if you don't know it's location ###### ###### NT systems do not use this facility, but instead rely entirely ###### on the extension of the file (hence the need to name the file ###### with a .pl extension on most NT web servers) ############################################ # Library Search 1.1.0 release 1 # # (c) copyright 1998-2000 NCP Technologies, # At Connex Global Communication Systems Inc, # Jaywil Software Dev. Inc. 1-800-815-8370 # # Derived from Library Search 1.0.1 release 1, 7-Feb-2002 # by CCj/Clearline. # # Updates were many and various -- more complete # abstraction of config variables, generalization of # path handling, rewriting of date code to # use internal time functions, removal of all # file system operations during search, and # and a compelete reimplementation of the search # function (mostly to remove OS dependances, # but also to fix a some minor searching bugs). # # The cprstrx function was removed. # The CountEntries function was no longer # used, and was removed. # # The number of code lines has been reduced in # many places. All lines have been # modified to conform to 80 column format. # # The level of generalization is now approximately # suitable to allow for compilation of the code # for platforms where perl interpreters are not # available, should the need arise. # # # This program is distributed WITHOUT ANY WARRANTY; # without even the implied warranty of MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. # ############################################################################# # Main Program Section # *NOTE* no changes are required in this file whatsoever.. view lib.conf ############################################################################# # Programming # Comments ############################################################################# &GetQueryData; # $loggedin = 0; # User Not Logged in initially. $version = "1.1.0"; # ###### $virtual and $logoImage are used to describe web content on the forms ###### generated by this script. They may be overridden by the config ###### variables VIRTUAL and LOGO_IMAGE respectively. Note the trailing ###### slash for virtual. $virtual = "http://www.google.com/search/"; $logoImage = "logo.gif"; ###### These two variables are new -- NT requires that certain types of ###### executables have certain exteinsions, and it also requires ###### backslashes as directory separators. These variables here are the UNIX ###### defaults. The config file variables CGISCRIPT, and DIRSEP ###### will override these defaults on any platform, and must be defined on NT. $script = "libsearch.cgi"; $dirsep = "/"; ###### $countpath defines the path to your count directory. Reads value of ###### "x1" to assign the correct count -- each new library created will have ###### a unique value, and this script will automatically generate a count data ###### file if it doesn't exist. Define COUNTPATH in the config file to ###### override this default. Note that on UNIX this may be a relative ###### pathname. On NT it must be a fully qualified pathname. $countpath = "tmp"; ###### Similarly these are defaults for the mail program, the organisation ###### name, and a URL to associate with the organisation's name. They ###### may be overriden by the MAILPROG, ORG_NAME, and ORG_URL config ###### vars respectively. $mailProg = "/usr/sbin/sendmail -t"; $orgName = "Our Favourite Org, Inc."; $orgUrl = "http://www.google.com/"; # # Set up name arrays for weekdays and month names. # @weekdays=( "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"); @months=( "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"); # # Translate timezone-localised 'time' into a "struct tm" array. # ($sec, $min, $hour, $mday, $month, $year, $wday, $yday, $ds) = localtime(time); # # Save the year for use in the copyright message. # $cpr_year=1900+$year; # # Generate a datestring for use when generating mail. # $mailheader_date="$weekdays[$wday], $mday $months[$month] $cpr_year " . "$hour:$min:$sec"; # # Find the configuration file. If we are on NT, then likely the current # directory is *NOT* the script directory and the first test will fail. # $libConf = "lib.conf"; ($libConf = $ENV{PATH_TRANSLATED}) =~ s/[^\\]*$/lib.conf/ unless ( -e $libConf); &ReadConf; # Read the configuration file. &PrintHeader; # Print The Header Information > WWW #print ("
\$libConf: $libConf
"); #print ("
\$mailProg: $mailProg
"); #print ("
generated date: $mailheader_date
"); #print ("
done reading config
"); &PrintCommands; # Print The Commands > WWW #print ("
done printcommands
"); # &PreformAction; # Preform the specified action. or default. #print ("
done preformaction
"); &PrintFooter; # Print The Footer Information > WWW #print ("
done printfooter
"); exit; ############################################################################# ############################################################################# # Sub Procedures ############################################################ ############################################################################# #This Software is (c) 1998-1999 NCP Technologies and At Connex Global Communication Systems Inc #This Software is (c) 1998-1999 NCP Technologies and At Connex Global Communication Systems Inc ############################################ # PrintFooter # Purpose: To Print The footer info to the # WWW ############################################ sub PrintFooter { print <

(c) copyright $cpr_year $orgName.
NCP } ############################################ # ListDatabases # Purpose: To list the available databases # ############################################ #This Software is (c) 1998-1999 NCP Technologies and At Connex Global Communication Systems Inc sub ListDatabases { print "
Visitor number " .&getCounterValue("count-list-libs.txt") ."

\n"; print "Total Library Databases : $databases
"; for ($a=1;$a<=$databases;$a++) { if (($databasedata[($a*10)+2] eq "*") || ($databasedata[($a*10)+2] eq "")) { print "

$databasedata[($a*10)+0] - ("; } else { print "

$databasedata[($a*10)+0] - ("; } if (($databasedata[($a*10)+2] ne "*") && ($databasedata[($a*10)+2] ne "")) { print "Password Required"; } else { print "No Password"; } print ")"; print " [ $databasedata[($a*10)+6] item(s) ]"; } } ############################################ # PreformAction # Purpose: To preform the action requested # ############################################ #This Software is (c) 1998-1999 NCP Technologies and At Connex Global Communication Systems Inc sub PreformAction { $carryon=0; if ($qstring[2] eq '') { $qstring[2] = 1; } # 1 = list databases for login # print "$ENV{'QUERY_STRING'}
"; # print "$in{'name'}|$in{'email'}"; if ($qstring[2] eq 1) { &ListDatabases } else { if (($loggedin eq 1)&&($qstring[2] ne 2)) { if ($qstring[2] eq 3) { &SearchForm; } if ($qstring[2] eq 4) { &Search; } if ($qstring[2] eq 5) { if ($in{'prev'} eq "Prev") { $carryon=1; &Search; } if ($in{'next'} eq "Next") { $carryon=1; &Search; } else { if (($in{'next'} eq '') && ($in{'prev'} eq '')) { &makeRequest; } } } } else { if ($qstring[2] eq 2) { if (($qstring[0] ne '') && ($qstring[0] > 0) && ($qstring[0] <= $databases)){ &PrintLoginForm; } } else { print "
Invalid Password"; } } } } ############################################ # FSearch # Purpose: Does The actual Search # ############################################ # This functin based on code written by # NCP Technologies and # At Connex Global Communication Systems Inc # sub FSearch { # # Bail if all the match strings are empty. # foreach $pattern (@qstring[3..9]) { push (@patterns, $pattern) unless ($pattern eq ''); } print "no search", &PrintFooter, halt unless (@patterns); # # Assign the match strings to search criteria. # $title = $qstring[3]; $author = $qstring[4]; $category = $qstring[5]; $subject = $qstring[6]; $dewey = $qstring[7]; $isbn = $qstring[8]; $publisher = $qstring[9]; # # Set the book counter and an initial twenty-element empty slot of # the @bookdata array. The rest of the code elsewhere in this script # doesn't seem to BELIEVE in zero-based perl arrays. # $validbooks=0; push(@bookdata, "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""); # # Open the database file and read it line by line. Try to match every # criteria against each line. If all criteria match a line, push() that # line into the @bookdata array. # open(SEARCH, $databasedata[($qstring[0]*10)+5]); while () { @line = split(/\t/, $_); next if ( $title ne '' && $line[0] !~ m/$title/i && $line[1] !~ m/$title/i && $line[2] !~ m/$title/i); next if ( $author ne '' && $line[3] !~ m/$author/i && $line[4] !~ m/$author/i && $line[5] !~ m/$author/i); next if ( $subject ne '' && $line[10] !~ m/$subject/i && $line[11] !~ m/$subject/i && $line[12] !~ m/$subject/i && $line[13] !~ m/$subject/i); next if ($publisher ne '' && $line[6] !~ m/$publisher/i); next if ($category ne '' && $line[7] !~ m/$category/i); next if ($dewey ne '' && $line[8] !~ m/$dewey/i); next if ($isbn ne '' && $line[9] !~ m/$isbn/i); # # If we get to this point we have a match. # $validbooks++; # # Trim the double quotes from each field of the current line. # foreach (@line) { s/^"(.*)"$/\1/; } # # Push @line into a twenty-slot wide chunk of the @bookdata array. # unshift(@line, ""); push(@line, "", "", "", "", ""); push(@bookdata, @line); } close(SEARCH); } ############################################ # makeRequest # Purpose: Request Item(s) # ############################################ #This Software is (c) 1998-1999 NCP Technologies and # At Connex Global Communication Systems Inc sub makeRequest { if (($qstring[11] eq '') || ($qstring[12] eq '')) { $errMsg = " Missing Email/Phone or Name
\n" } $selected = 0; for($a=1;$a<=100;$a++) { if ($qstring[12+$a] eq "on") { $selected++; } } if ($selected eq 0) { $errMsg = " No Items Selected!
\n"; } if (defined $errMsg) { print $errMsg; print "Please hit the back button on your browser and make the\n"; print "necessary corrections\n"; return; } &FSearch; $recipient = "$databasedata[($qstring[0]*10)+4]"; open (MAIL, "|$mailProg") || die "Can't create pipe to $mailProg!\n"; print MAIL "Date: $mailheader_date -0500\n"; print MAIL "From: $adminName <$adminEmail>\n"; print MAIL "Organization: $orgName\n"; print MAIL "To: Library Admin <$recipient>\n"; print MAIL "Subject: Borrow Request\n\n"; print MAIL "***********************************\n"; print MAIL "* Borrow Request Form *\n"; print MAIL "* from Library Search 1.0.1 *\n"; print MAIL "***********************************\n"; print MAIL "Library :$databasedata[($qstring[0]*10)+0]\n"; print MAIL "Name Of Requestor :$in{'name'}\n"; print MAIL "Phone/Email :$in{'email'}\n"; print MAIL "Date/Time :$mailheader_date\n"; print MAIL "From :$ENV{'REMOTE_ADDR'}\n"; print MAIL "***********************************\n"; print MAIL "COMMENTS:$in{'comm'}\n"; print MAIL "\n"; for($a=1;$a<=100;$a++) { if ($qstring[12+$a] eq "on") { $cool=$lqstring[12+$a]; print MAIL "***************** Requested Item *****************\n"; print MAIL "Name :$bookdata[(($cool)*20)+1]\n"; print MAIL "Author :$bookdata[(($cool)*20)+4]\n"; print MAIL "Dewey :$bookdata[(($cool)*20)+9]\n"; print MAIL "ISBN :$bookdata[(($cool)*20)+10]\n\n"; } } print MAIL "\n\n(c) copyright $cpr_year $orgName.\n"; close (MAIL); print "$databasedata[($qstring[0]*10)+0]
"; print "Requesting Item(s):
"; for($a=1;$a<=100;$a++) { if ($qstring[12+$a] eq "on") { $cool=$lqstring[12+$a]; print " $bookdata[(($cool)*20)+1]
"; } } print "
Your Items Have Been Requested, Thank You"; } ############################################ # Search # Purpose: To find entries.. # ############################################ #This Software is (c) 1998-1999 NCP Technologies and # At Connex Global Communication Systems Inc sub Search { if ($in{'next'} eq "Next") { $qstring[10]=$qstring[10]+10; } if ($in{'prev'} eq "Prev") { $qstring[10]=$qstring[10]-10; } &FSearch; print "$databasedata[($qstring[0]*10)+0]
"; print "Your Search Found $validbooks Match(es)

"; if ($validbooks eq 0) { &PrintFooter; exit(0); } if (($qstring[10] > $validbooks)) { $qstring[10] = $validbooks; } if (($qstring[10] - 10) > 0) { $newfirst = $qstring[10]-10; } else { $newfirst = 1; } if (($qstring[10]) <= 0) { $qstring[10] = 1; } $last = $qstring[10] + 9; if ($last <= $validbooks) { print "$qstring[10]-$last of "; print "$validbooks "; } else { $last = $validbooks; print "$qstring[10]-$last of "; print "$validbooks "; } $newlast = $last +1; print "

"; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print <
Name : NCP if ($in{'name'} eq '') { print "
"; } else { print "
"; } print <
Phone Number/Email Address : NCP if ($in{'email'} eq '') { print "
"; } else { print "
"; } print <
Comments : NCP if ($in{'comm'} eq '') { print "

"; } else { print "

"; } print <

NCP if ($carryon eq 1) { print "$in{'$a'}"; for ($a=10;$a<100;$a++) { if ($qstring[$a] eq "on") { print "
  • Checked: $bookdata[($lqstring[$a]*20)+1]"; print ""; } } } print "

    "; print "
  • "; print ""; for ($a=$qstring[10];$a<=$last;$a++) { print < Title $bookdata[($a*20)+1] NCP if ($bookdata[($a*20)+2] ne '') { print " : $bookdata[($a*20)+2]"; } if ($bookdata[($a*20)+3] ne '') { #This Software is (c) 1998-1999 NCP Technologies and At Connex Global Communication Systems Inc print" ($bookdata[($a*20)+3])"; } print < Author $bookdata[($a*20)+4] NCP if ($bookdata[($a*20)+5] ne '') { print ", $bookdata[($a*20)+5]"; } if ($bookdata[($a*20)+6] ne '') { print ", $bookdata[($a*20)+6]"; } print < Category $bookdata[($a*20)+8] Subject $bookdata[($a*20)+11]
    $bookdata[($a*20)+12]
    $bookdata[($a*20)+13]
    $bookdata[($a*20)+14] Dewey $bookdata[($a*20)+9] ISBN $bookdata[($a*20)+10] Publisher $bookdata[($a*20)+7]
    NCP } # $ofirst=$qstring[10]; # print "["; # if ($ofirst ne 1) { # print ""; # } # print "Prev 10"; # if ($ofirst ne 1) { #This Software is (c) 1998-1999 NCP Technologies and At Connex Global Communication Systems Inc# # print ""; # } # print "] "; # print "["; # if ($newlast <= $validbooks) { # print ""; # } # print "Next 10"; # if ($newlast <= $validbooks) { # print ""; # } # print "]"; print ""; print ""; print ""; print ""; } #f # getCounterValue("filename") # # Increment and return the counter in "filename" in the counter directory. # sub getCounterValue { local $count = 0; open (COUNTER, "+>>".$countpath.$dirsep.$_[0]); flock(COUNTER, $LOCK_EX); seek(COUNTER, 0, 0); $count = unless (eof(COUNTER)); truncate(COUNTER, 0); print COUNTER (++$count); close(COUNTER); return $count; } ############################################ # SearchForm # Purpose: To Get Database Searching info # from the viewer. ############################################ #This Software is (c) 1998-1999 NCP Technologies and At Connex Global Communication Systems Inc sub SearchForm { print "Visitor number " .&getCounterValue("count-lib-$databasedata[$qstring[0]*10].txt") ."

    "; print <
    Enter Field(s) to search:

    Title:
    Author:
    Category:
    Subject:
    Dewey:
    ISBN:
    Publisher:

    NCP } ############################################ # PrintLoginForm # Purpose: To Print The Login Form # ############################################ #This Software is (c) 1998-1999 NCP Technologies and # At Connex Global Communication Systems Inc sub PrintLoginForm { print < Login To $databasedata[($qstring[0]*10)+0]
    Password:
    NCP } ############################################ # GetQueryData # Purpose: To Get Information From The Query # String passed from The WWW ############################################ #This Software is (c) 1998-1999 NCP Technologies and # At Connex Global Communication Systems Inc sub GetQueryData { local $qString = $ENV{'QUERY_STRING'}; # # Replace '+' chars with spaces and de%hex the query string. # $qString =~ s/\+/ /g; $qString =~ s/%([A-Fa-f0-9]{2})/pack("c",hex($1))/ge; $x=0; foreach $stream (split(/\&/, $qString)) { ($lqstring[$x], $qstring[$x]) = split(/\=/, $stream); if ($lqstring[$x] eq "login") { $in{'login'} = $qstring[$x]; } if ($lqstring[$x] eq "next") { $in{'next'} = $qstring[$x]; } if ($lqstring[$x] eq "prev") { $in{'prev'} = $qstring[$x]; } if ($lqstring[$x] eq "name") { $in{'name'} = $qstring[$x]; } if ($lqstring[$x] eq "email") { $in{'email'} = $qstring[$x]; } if ($lqstring[$x] eq "comm") { $in{'comm'} = $qstring[$x]; } $x++; } } ############################################ # ReadConf # Purpose: To Get information from the # configuration file ############################################ #This Software is (c) 1998-1999 NCP Technologies and # At Connex Global Communication Systems Inc ###### In the config file, elements are ":" separated -- this makes ###### it hard to enter a dos/windows style fully qualified pathname ###### because such paths require a drive specification with a colon, ###### eg: d:\srv\http\netutils.ccjclearline.com\cgi. The below code ###### handles such pathnames gracefully. sub ReadConf { $databases = 0; open (NCP, $libConf) || print ("can't open lib.conf"); @data = ; close(NCP); foreach $stream (@data) { chop($stream); @config = split(/:/, $stream); $confvar = shift (@config); # # Parse out the DATABASE spec. # if ($confvar eq "DATABASE") { $databases++; $a = $databases*10; $b = 0; $databasedata[$a++] = $config[$b++]; #name of library $databasedata[$a++] = $config[$b++]; #location of library $databasedata[$a++] = $config[$b++]; #library password $databasedata[$a++] = $config[$b++]; #email one - maintainer? $databasedata[$a++] = $config[$b++]; #email two # # The next element is the path and filename that contains the library # data. If it is a fully qualified dos pathname, then this is just # the drive letter, and the following element is the rest of the dos # path. We need to combine these two elements into one @databasedata # array element, reinserting the colon that we split upon when # we parsed the line. # if ( $config[$b] =~ /^[A-Za-z]$/ ) { $databasedata[$a++] = $config[$b++].":".$config[$b++]; # # Not a fully qualified DOS pathname. Treat it normaly. # } else { $databasedata[$a++] = $config[$b++]; } #DEBUG: prints the database path. #print $databasedata[$a-1]; $databasedata[$a] = $config[$b]; # number of records } # # Handle normal config vars. # $virtual = $config[0] if ($confvar eq "VIRTUAL"); $logoImage = $config[0] if ($confvar eq "LOGO_IMAGE"); $adminEmail = $config[0] if ($confvar eq "ADMINEMAIL"); $aboutpage = $config[0] if ($confvar eq "ABOUTPAGE"); $adminName = $config[0] if ($confvar eq "ADMINNAME"); $dirsep = $config[0] if ($confvar eq "DIRSEP"); $script = $config[0] if ($confvar eq "CGISCRIPT"); $orgName = $config[0] if ($confvar eq "ORG_NAME"); # # Handle config vars that night have colons in them. # This is harmless if the value had no colons in it. # $countpath = join(":", @config) if ($confvar eq "COUNTPATH"); $virtual = join(":", @config) if ($confvar eq "VIRTUAL"); $orgUrl = join(":", @config) if ($confvar eq "ORG_URL"); $mailProg = join(":", @config) if ($confvar eq "MAILPROG"); } } ############################################ # PrintCommands # Purpose: To Print the available commands # to the screen. ############################################ #This Software is (c) 1998-1999 NCP Technologies and # At Connex Global Communication Systems Inc sub PrintCommands { print "[About]"; print " [List Libraries] ["; print "Contact Admin] "; if (($qstring[0] ne '') && ($qstring[1] ne '')) { if (($qstring[0] <= $databases) && ($qstring[0] > 0)) { $valid=0; for($a=1;$a<=$databases;$a++) { if ($databasedata[($a*10)+2] eq $qstring[1]) { print "[Search] "; $loggedin = 1; } } } } print "
    "; } ############################################ # PrintHeader # Purpose: To print the initial html code # at the top of the page. ############################################ #This Software is (c) 1998-1999 NCP Technologies and # At Connex Global Communication Systems Inc sub PrintHeader { print "Content-type: text/html\n\n"; print < Library Search $version

    NCP }