home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 12 / Silicon_Graphics_Developer_Magic_Soft_Dev_812-8101-012.iso / .all / httpd_ncsa / cgi-bin / AT-index.cgi < prev    next >
Encoding:
Text File  |  1995-11-10  |  11.0 KB  |  358 lines

  1. #!/bin/sh
  2. perl=/usr/local/etc/architext/perl
  3. eval "exec $perl -x $0 $*"
  4. #!perl
  5.  
  6. ## Copyright Architext Software, 1994 (c)
  7. ##
  8. ## This CGI script allows users to index Architext databases
  9. ## through a WWW interface. Naturally, there are plenty of security
  10. ## concerns associated with this scheme.
  11. ##
  12. ## This script appears as several different web pages, depending on
  13. ## its invocation. If invoked with a 'db=<database>' argument, the
  14. ## script prints out the configuration information for a particular
  15. ## database and then allows the user to change it. If
  16. ## invoked with 'Index=Index' and 'dbname=<database>', it will ininitialize 
  17. ## a database which has an existing database configuration file. 
  18. ## Without any of these arguments, it displays a list of currently 
  19. ## existing database.conf files, and allows the user to choose a database 
  20. ## to index.
  21. $| = 1;  ## don't buffer output
  22.  
  23. $root = "/usr/local/etc/architext";
  24.  
  25. die "Invalid root directory '$root'\n" unless -d $root;
  26.  
  27. unshift(@INC, "$root/perllib");
  28. require 'architext.pl';
  29. require 'architextConf.pl';
  30.  
  31. %form = &Architext'readFormArgs;
  32. %attr = &ArchitextConf'readConfig("$root/Architext.conf", $form{'db'});
  33.  
  34. if (&Architext'remoteMode($root)) {
  35.     $helppath = &Architext'helpPath();
  36. } else {
  37.     $helppath = $attr{'ArchitextURL'};
  38. }
  39.  
  40. $scriptname = "AT-index.cgi";
  41.  
  42. ## check for password, if one is specified in Architext.conf
  43. ## if it doesn't appear as a form arg, present password page
  44. &Architext'password($attr{'ArchitextURL'},
  45.             $scriptname,
  46.             $attr{'Password'}, 
  47.             $form{'password'});
  48.  
  49. $attr{'Password'} =~ tr/a-zA-Z/n-za-mN-ZA-M/;
  50. $postpass = 
  51.     "<INPUT TYPE=\"hidden\" NAME=\"password\" VALUE=\"$attr{'Password'}\">" if
  52.     ($attr{'Password'});
  53. $getpass = "?password=$attr{'Password'}" if $postpass;
  54.  
  55. if ($form{'Stop'}) {
  56.    &Architext'printHeader($attr{'ArchitextURL'},
  57.                "Stop Indexing: $form{'db'}");
  58.    $pidfile = "$root/collections/$form{'db'}.pid";
  59.    if (! -e $pidfile) {
  60.        &Architext'exitError($attr{'ArchitextURL'}, 
  61.                 "<b>You tried to stop an indexing process that wasn't running</b>");
  62.    }
  63.    open(PID, "$pidfile");
  64.    while (<PID>) {
  65.        $pid = $_;
  66.    }
  67.    close(PID);
  68.    kill 'TERM', $pid;
  69.    unlink($pidfile);
  70.    open(TERM, ">$root/collections/$form{'db'}.term");
  71.    close(TERM);
  72.    print "<p> <b>Indexing process number $pid has been terminated.</b>\n";
  73.    print <<EOF;
  74. <p> 
  75. <FORM ACTION="AT-admin.cgi" METHOD=POST>
  76. <INPUT TYPE="hidden" NAME="db" VALUE="$form{'db'}">
  77. <INPUT TYPE="submit" NAME="Admin" VALUE="Admin">
  78. Go back to the admin page for this collection.
  79. $postpass
  80. </FORM>
  81. EOF
  82.     ;
  83.    &Architext'Copyright($attr{'ArchitextURL'});
  84.    exit(0);
  85. }
  86.  
  87. if ($form{'db'}) {
  88.     ## Print out configuration options for an already-existing
  89.     ## database so the user knows what will happen upon indexing
  90.  
  91.     ## Dump our standard header
  92.     &Architext'printHeader($attr{'ArchitextURL'},
  93.                "Collection Indexing: $form{'db'}");
  94.  
  95.     ## Check for the desired database.conf file.
  96.     $dbconfig = $root . "/collections/" . $form{'db'} . ".conf";
  97.     if (! -r $dbconfig) { 
  98.     &Architext'exitFileError($attr{'ArchitextURL'},
  99.                  $dbconfig, "does not exist"); }
  100.  
  101.     ## Read all the configuration information.
  102.     ##%attr = &ArchitextConf'readConfig("$root/Architext.conf", $form{'db'});
  103.  
  104.     print "<p> The collection you have chosen has the ";
  105.     print "following characteristics:\n";
  106.     ## Print the form.
  107.  
  108.     ## This form is just a little list of the options.
  109.     &printForm($form{'db'});    
  110.     &Architext'Copyright($attr{'ArchitextURL'});
  111.  
  112. }  elsif ($form{'Index'}) {
  113.     ## Assuming all the relevant configuration options are specified
  114.     ## as form arguments, this mode actually starts the indexing .
  115.  
  116.     ## Header again
  117.     &Architext'printHeader($attr{'ArchitextURL'},
  118.                "Collection Indexing: $form{'dbname'}");
  119.  
  120.     if (!$form{'dbname'}) { 
  121.     &Architext'exitError($attr{'ArchitextURL'},
  122.                  "Index specified with no dbname."); }
  123.  
  124.     ## Can we read the db.conf file?
  125.     $dbconfig = $root . "/collections/" . $form{'dbname'} . ".conf";
  126.     if (! -e $dbconfig && ! -r $dbconfig) {
  127.     &Architext'exitFileError($attr{'ArchitextURL'},
  128.                  $dbconfig, 
  129.                  "does not exist or is not readable.");
  130.     }
  131.  
  132.     if (-e "$root/collections/$form{'dbname'}.pid") {
  133.     print <<EOF;
  134. <p><b>An indexing process is already in progress for this collection.</b>
  135. <FORM ACTION="AT-index.cgi" METHOD=POST>
  136. <INPUT TYPE="submit" NAME="Stop" VALUE="Stop Indexing">
  137. Stop the indexing process that is currently running on this collection.
  138. <INPUT TYPE="hidden" NAME="db" VALUE="$form{'dbname'}">
  139. $postpass
  140. </FORM>
  141. EOF
  142.     ;
  143.     &Architext'Copyright($attr{'ArchitextURL'});
  144.     exit(0);
  145.     }
  146.  
  147.     ## tell the user it started the process.
  148.     ## variables below tell user how to access log file and prog
  149.     ## progress file from browser, and tell indexer exactly where
  150.     ## to put them.
  151.     $logname = "AT-$form{'dbname'}.log";
  152.     $progname = "AT-$form{'dbname'}.prog";
  153.     $errname = "AT-$form{'dbname'}.err";
  154.     $realpath = "$root/collections";
  155.     $urlpath = $attr{'ArchitextURL'};
  156.     print "<H2>Indexing initiated.</H2>\n";
  157.     print "<p><hr>\n";
  158.     if ($getpass) {
  159.     $getpass .= "&";
  160.     } else {
  161.     $getpass = "?";
  162.     }
  163.     $getpass .= "db=$form{'dbname'}";
  164.     print <<EOF;
  165. <b>Next steps:</b>
  166. <p>While you are waiting for the indexing process to complete, you can: 
  167. <p> <FORM ACTION="AT-generate.cgi" METHOD=POST>
  168. <INPUT TYPE="submit" NAME="Status" VALUE="View Logs">
  169. View the log files created by the indexing process.  
  170. <INPUT TYPE="hidden" NAME="db" VALUE="$form{'dbname'}">
  171. $postpass
  172. </FORM>
  173. <p>
  174. <FORM ACTION="AT-index.cgi" METHOD=POST>
  175. <INPUT TYPE="submit" NAME="Stop" VALUE="Stop Indexing">
  176. Stop the indexing process that was just initiated.
  177. <INPUT TYPE="hidden" NAME="db" VALUE="$form{'dbname'}">
  178. $postpass
  179. </FORM>
  180. <p> <FORM ACTION="AT-generate.cgi" METHOD=POST>
  181. <INPUT TYPE="submit" NAME="Generating" VALUE="Generate">
  182. Generate a search page for this collection.
  183. $postpass
  184. <INPUT TYPE="hidden" NAME="db" VALUE="$form{'dbname'}">
  185. </FORM>
  186. <p> 
  187. <FORM ACTION="AT-admin.cgi" METHOD=POST>
  188. <INPUT TYPE="hidden" NAME="db" VALUE="$form{'dbname'}">
  189. <INPUT TYPE="submit" NAME="Admin" VALUE="Admin">
  190. Go back to the admin page for this collection.
  191. $postpass
  192. </FORM>
  193.  
  194. <p><b>Note:</b>Unless you have
  195. configured this collection to send email when the indexing process 
  196. is done, you will need to view the log files or visit the admin page
  197. for this collection if you want to know when indexing has finished.
  198. EOF
  199.     ;
  200.     ## Kick off the indexing process here.
  201.     $aindex = $root . "/aindex.pl";
  202.     $!="";
  203.     unless (fork) { # this is the child
  204.         unless (fork) {        # child's child
  205.             sleep 1 until getppid == 1;
  206.         ## &Closer closes file descriptors before execing to workaround
  207.         ## NCSA bug in httpd version 1.3
  208.         &Closer();
  209.             ## third and fourth args make indexer build progress and log files
  210.         exec($aindex, $form{'dbname'}, "$realpath/$logname", 
  211.          "$realpath/$progname", "$realpath/$errname");            
  212.         }             
  213.     ##first child exits quickly
  214.     exit 0;             
  215.     }
  216.     
  217.     wait; ## parent reaps first child quickly
  218.     &Architext'Copyright($attr{'ArchitextURL'});
  219. } else {
  220.     ## Print out the top-level screen: scan the root directory for
  221.     ## db.conf files, and allow the user to select a db.conf
  222.     ## file.
  223.  
  224.     opendir(CONF, "$root/collections");
  225.     @dbconf = grep(/\.conf$/, readdir(CONF));
  226.  
  227.     &Architext'printHeader($attr{'ArchitextURL'},"Collection Indexing");
  228.  
  229.     if ($#dbconf > -1) {
  230.     print <<EOF;
  231. <FORM ACTION="http:AT-index.cgi" METHOD=POST>
  232. Choose a document collection to index.<P>
  233. <DL>
  234. <DT> 
  235. Existing <a href="${helppath}AT-helpdoc.html#Document Collections">
  236. document collections:</a> <DD>
  237. <SELECT NAME="db" SIZE=5>
  238. EOF
  239.     ;
  240.     for (@dbconf) {
  241.     s|\.conf$||;
  242.     next if $_ eq 'Architext';
  243.     print "<OPTION> $_\n";
  244.     }
  245.     print <<EOF;
  246. </SELECT>
  247. </DL>
  248. <INPUT TYPE="submit" NAME="Select" VALUE="Select">
  249. $postpass
  250. </FORM>
  251. EOF
  252.     ;
  253. } else {
  254.     print <<EOF;
  255. <p> There are no document collections currently defined.  Please
  256. click on the configure button to go to the collection configuration
  257. screen.
  258. <FORM ACTION="http:AT-config.cgi" METHOD=POST>
  259. <INPUT TYPE="submit" VALUE="Configure">
  260. $postpass
  261. </FORM>
  262. EOF
  263.     ;
  264. }
  265.     &Architext'Copyright($attr{'ArchitextURL'});
  266. }
  267.  
  268. sub printForm {
  269.     local($db) = shift;
  270.     local($url) = $attr{'ArchitextURL'};
  271.     print "<UL>\n";
  272.     &Architext'printLineItem($url,'IndexExecutable',
  273.                  $attr{'IndexExecutable'})
  274.     if &Architext'debugMode();
  275.     &Architext'printLineItem($url,'SearchExecutable',
  276.                  $attr{'SearchExecutable'})
  277.     if &Architext'debugMode();
  278.     &Architext'printLineItem($url,'StemTable',$attr{'StemTable'})
  279.     if &Architext'debugMode();
  280.     &Architext'printLineItem($url,'StopTable',$attr{'StopTable'})
  281.     if &Architext'debugMode();
  282.     &Architext'printLineItem($url,'CollectionInfo', $attr{'CollectionInfo'})
  283.     if &Architext'debugMode();
  284.     &Architext'printLineItem($url,'CollectionIndex',
  285.                  $attr{'CollectionIndex'});
  286.     if ($attr{'CollectionContents'} =~ /^\+/) {
  287.     $attr{'CollectionContents'} =~ s/^\+//;
  288.     print <<EOF;
  289. <li> <a href="${helppath}AT-helpdoc.html#CollectionContents">
  290. CollectionContents:</a> Index the files listed in 
  291. '$attr{'CollectionContents'}'.
  292. EOF
  293.     ;
  294.     } else {
  295.     $files = join(", ", split(/[:,;\s]+/, $attr{'CollectionContents'}));
  296.     print <<EOF;
  297. <li> <a href="${helppath}AT-helpdoc.html#CollectionContents">
  298. CollectionContents:</a> Index the files '$files' using these rules:<ul>
  299. EOF
  300.     ;
  301.     &Architext'printLineItem($url,'IndexFilter',
  302.                  $attr{'IndexFilter'});
  303.     &Architext'printLineItem($url,'ExclusionRules',
  304.                  $attr{'ExclusionRules'});
  305.     print "</ul>";
  306.     }
  307.     &Architext'printLineItem($url,'AdminMail',
  308.                  $attr{'AdminMail'});
  309.     print "</UL>\n";
  310.     
  311.     print <<EOF;
  312. <p> Click on the <b>Index</b> button to start indexing.
  313. Depending on the size of your collection, this may take
  314. anywhere from a few moments to a few hours.
  315. After you initiate the indexing process you will be given links
  316. to several log files that you can reload periodically to monitor the
  317. progress of the indexing process.  If you specified an admin email address
  318. for this collection, you will also be notified via email
  319. when the indexing process finishes.
  320. <p><FORM ACTION="http:AT-index.cgi" METHOD=POST>
  321. <INPUT TYPE="submit" NAME="index" VALUE="Index">
  322. Start an indexing process for this collection.
  323. <INPUT TYPE="hidden" NAME="Index" VALUE="Index">
  324. <INPUT TYPE="hidden" NAME="dbname" VALUE="$db">
  325. $postpass
  326. </FORM>
  327.  
  328. <p> 
  329. <FORM ACTION="AT-admin.cgi" METHOD=POST>
  330. <INPUT TYPE="hidden" NAME="db" VALUE="$db">
  331. <INPUT TYPE="submit" NAME="Admin" VALUE="Admin">
  332. Go back to the admin page for this collection.
  333. $postpass
  334. </FORM>
  335. EOF
  336.     ;
  337. }
  338.  
  339. ## closes the first 20 filehandles to kill unclosed socket
  340. ## from NCSA httpd 1.3, which is a bug that prevents
  341. ## indexing process from being able to background.
  342. sub Closer {
  343.     if (`uname -s` =~ /irix/i) {
  344. # /usr/include/sys.s.
  345.     $SYS_close = 1006;
  346.     }
  347.     else {
  348.         $SYS_close = 6;
  349.     }
  350.     die "Must define \$SYS_close" unless defined($SYS_close);
  351.     for ($i=0; $i<20; $i++) {
  352.     syscall($SYS_close, $i+0);
  353.     }
  354. }
  355.  
  356.  
  357.  
  358.