#!/usr/local/bin/perl # ListWebber II 1.0.1b # by Eric Lease Morgan, Infomotions # http://infomotions.com/musings/list-webber/ # Release notes: # 04/23/05 # moved to infomotions.com # 10/24/96 # added a root path so file in particular directories can only be read # 9/14/94 # made sure user entered their name, address, list, and query # 8/3/94 # initial release # declare your host name $hostName = "www.lib.ncsu.edu"; # declare the directory where the lists of lists are saved $listDirectory = "/usr/local/bin/httpd/cgi-bin/lists/"; # what is the URL of your ListWebber perl script? $lw2Location = "http://www.lib.ncsu.edu/cgi-bin/lw2"; # what is location of your error log? $errorLog = "/usr/local/logs/listwebber/lw2-error.log"; # what is the location of your normal, everyday listwebber log? $logFile = "/usr/local/logs/listwebber/lw2.log"; # where is the cgi-lib.pl library so we can read POSTed data require '/usr/local/bin/httpd/cgi-bin/cgi-lib.pl'; # where is sock.pl, a socket binding library necessary for my SMTP communications require '/usr/local/bin/httpd/cgi-bin/sock.pl'; sub printFooter { # you will want to change the 2nd and 3rd print lines of the following footer print "
"; print "This page is maintained by and please report problems to Eric Lease Morgan (eric_morgan\@ncsu.edu). This page was last modified August 3, 1994.

"; print "Go to library's home page. Go to NCSU's home page.

"; print ""; print ""; } # # no configuration should be necessary below this line # # print the begining of every document &printHeader; # make sure a data file is specified if ($ARGV[0] eq "") { # no data file was specified print "Sorry, but you must specify a data file."; &printFooter; &gracefulExit; } # read the data file &readListData; # read the posted data &readPostedData; # display a form or process a query if ($theFunction eq "") {&displayForm;} else { # verify that a username, address, list and query were entered &validateUserName; &validateUserAddress; &validateList; &validateQuery; &processQuery; } # print the footer &printFooter; # exit gracefully &gracefulExit; sub gracefulExit { # quit gracefully exit 0; } sub readPostedData { # get the input &ReadParse; foreach $key (keys(%in)) { if ($key eq "theFunction") {$theFunction = $in{$key};} elsif ($key eq "userName") {$userName = $in{$key};} elsif ($key eq "userAddress") {$userAddress = $in{$key};} elsif ($key eq "theList") { #print "the key: $in{$key}

"; (@theSelectedLists) = split(/\\0/, $in{$key}); } elsif ($key eq "theQuery") {$theQuery = $in{$key};} } # display the input; uncomment the following lines for debuggin' purposes #print "name: $userName

"; #print "address: $userAddress

"; #print "lists: $theSelectedList

"; foreach $list (@theSelectedLists) { print "$list

";} #print "function: $theFunction

"; #print "query: $theQuery

"; #print "


"; } sub readListData { # get ListWebber's list of lists (dataFile) $dataFile = $listDirectory . $ARGV[0]; print "The data file is: $dataFile

"; # open the data file for reading open (DATAFILE, $dataFile) || print "Can't open datafile: $!\n"; # load the data into its arrays $i = 0; while () { ($list, $server, $type) = split(/:/, $_); $list =~ tr/a-z/A-Z/; $server =~ tr/a-z/A-Z/; $type =~ tr/a-z/A-Z/; if (length ($type) > 1) { chop $type; } $theList[$i] = $list; $theServer[$i] = $server; $theType[$i] = $type; # again, uncomment the following line to debug your code #print "list: $theList[$i]\n"; #print "server: $theServer[$i]\n"; #print "type: $theType[$i]\n"; #print "\n"; $i++; } close DATAFILE; } sub displayForm { # create the on-the-fly form # you should not have to edit this unless you want to create your own online help print "

"; print "What is your name? (Explain.)

"; print "

"; print "What is your email address? (Explain.)

"; print "

"; print "What list do you want to query? You may want to consult The Directory of Scholarly Electronic Conferences in order to make your selection. (Explain.)

"; print "

"; print "Do you want to search the list or retrieve messages from the list? (Explain.)

"; print "

    "; print "
  1. Search the list"; print "
  2. Retrieve messages from the list"; print "
"; print "Enter your query. (Explain.)

"; print "

"; print "Press \"Send the query\" to send your query or \"Reset\" to return the form to its original state.

"; print "

"; print "

"; } sub processQuery { # determine the LISTSERV's address $i = 0; $j = 0; foreach $list (@theList) { foreach $selectedList (@theSelectedLists) { ($selectedList) = split(/ /, $selectedList, 0); if ($list eq $selectedList) { $serverAddress[$j] = $theServer[$i]; #print "server address: $serverAddress[$j]

"; $serverType[$j] = $theType[$i]; $j++; } } $i++; } # report to the user what has happened print "$userName ($userAddress), you have opted to"; if ($theFunction eq "search") { print " search the following lists:"; } else { print " print from the following lists:"; } print "

"; print "Your query was '$theQuery', and it has been queued for delivery.

"; print "Replies to your query can take anywhere from a few minutes to more than 24 hours. Be patient."; # display our footer information &printFooter; # become a daemon, and continue processing the request fork && exit 0; # process each list to query for ($i = 0; $i < $j; $i++) { # get our variables $server = $serverAddress[$i]; ($list) = split(/ /, $theSelectedLists[$i]); $type = $serverType[$i]; $smtp = "/tmp/listwebber.smtp-".time; #print "


"; #print "i: $i j: $j

"; #print "server: $server

"; #print "list: $list

"; #print "type: $type

"; #print "temporary file: $smtp

"; # determine the type of query to construct if ($type eq "V") { # write the header to our SMTP file open (SMTP, ">$smtp") || &errorLog; print SMTP "Reply-To: $userAddress\n"; print SMTP "Subject: *** LISTWebber II Query ***\n"; print SMTP "From: $userName <$userAddress>\n"; print SMTP "Return-Path: <$userAddress>\n"; print SMTP "X-Mailer: LISTWebber II \n"; print SMTP "\n"; # begin writing the body of a VM-type query print SMTP "// JOB Echo=No\n"; print SMTP "Database Search DD=Rules\n"; print SMTP "//Rules DD *\n"; # construct the end of the query if ($theFunction eq "search") { print SMTP "S $theQuery in $list\n"; print SMTP "I\n"; print SMTP "/*\n"; } else { print SMTP "search * in $list\n"; print SMTP "print all of $theQuery\n"; print SMTP "/*\n"; } # close the file close (SMTP); # log the transaction &logTransaction; # send our query to the server # replace foo.bar with your email address for debuggin' purposes #$theCommand = "/usr/bin/mail foo.bar < $smtp"; $theCommand = "/usr/lib/sendmail -odq LISTSERV\@$serverAddress[$i] < $smtp"; system $theCommand; # remove our temporary file system "/bin/rm $smtp"; } elsif ($type eq "U") { # declare some more variables $port = "smtp"; $timeout = 1; # open and bind our communications port abort; $SMTP = &sock'open($hostName,$port) || print "Can't open socket: $!"; #$output = <$SMTP>; #print "$output\n"; # send HELO #print "HELO $hostName\n"; print $SMTP "HELO $hostName\n"; #$output = <$SMTP>; #print "$output\n"; # send MAIL #print "MAIL FROM: $userAddress\n"; print $SMTP "MAIL FROM: $userAddress\n"; #$output = <$SMTP>; #print "$output\n"; # send RCPT #print "RCPT TO:\n"; print $SMTP "RCPT TO:\n"; # substitute your address in the next line for debugging purposes #print $SMTP "RCPT TO:\n"; #$output = <$SMTP>; #print "$output\n"; # send DATA #print "DATA\n"; print $SMTP "DATA\n"; #$output = <$SMTP>; #print "$output\n"; # begin writing a Unix query if ($theFunction eq "search") { print $SMTP "search $list $theQuery\n"; } else { print $SMTP "get $list $theQuery\n"; } # end the message print $SMTP ".\n"; #$output = <$SMTP>; #print "$output\n"; # send QUIT #print "QUIT\n"; print $SMTP "QUIT\n"; #$output = <$SMTP>; #print "$output\n"; # log the transaction &logTransaction; } else { print "The type of LISTSERV server is of an unknown type: $serverType. "; print "Call the administrator of this page."; &printFooter; &gracefulExit; } } &gracefulExit; } sub logTransaction { ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); open (LOGFILE, ">>$logFile"); print LOGFILE "$mon/$mday/$year, $hour:$min:$sec, $userName, $userAddress, $list, $serverAddress[$i], $theQuery\n"; close (LOGFILE); } sub errorLog { open (ERRORLOG, ">>$errorLog"); print ERRORLOG "$!\n"; close (ERRORLOG); } sub printHeader { # print the begining of every document $| = 1; print "Content-type: text/html\n\n"; print ""; print ""; print "ListWebber II version 1.0.1b"; print ""; print ""; print "

ListWebber II version 1.0.1b

"; print "About ListWebber II by Eric Lease Morgan, NCSU Libraries."; print "
"; } sub validateUserName { if ($userName eq "") { print "Sorry, but you must enter your name. Please try again.

"; &printFooter; &gracefulExit; } } sub validateUserAddress { if ($userAddress eq "") { print "Sorry, but you must enter your email address. Please try again.

"; &printFooter; &gracefulExit; } } sub validateList { if ($theSelectedLists[0] eq "") { print "Sorry, but you must select at least one list to search. Please try again.

"; &printFooter; &gracefulExit; } } sub validateQuery { if ($theQuery eq "") { print "Sorry, but you must enter some sort of query. Please try again.

"; &printFooter; &gracefulExit; } }