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-admin.cgi < prev    next >
Encoding:
Text File  |  1995-11-10  |  14.3 KB  |  476 lines

  1. #!/bin/sh
  2. perl=/usr/local/etc/architext/perl
  3. eval "exec $perl -x $0 $*"
  4. #!perl
  5. ## Copyright Arhitext Software, 1995 (c)
  6. ##
  7. ## This CGI script is intended as a first stop for
  8. ## administrators of Architext's web site search engine.
  9. ##
  10. ## This script will appear a several different web pages,
  11. ## and will check to make sure that the user has
  12. ## registered with Architext before providing access
  13. ## to the full range of functionality.
  14. $| = 1;
  15.  
  16. $root = "/usr/local/etc/architext";
  17.  
  18. die "Invalid root directory '$root'\n" unless -d $root;
  19.  
  20. unshift(@INC, "$root/perllib");
  21. require 'architext.pl';
  22. require 'architextConf.pl';
  23.  
  24. %form = &Architext'readFormArgs;
  25. %attr = &ArchitextConf'readConfig("$root/Architext.conf", $form{'db'});
  26.  
  27. if (&Architext'remoteMode($root)) {
  28.     $helppath = &Architext'helpPath();
  29. } else {
  30.     $helppath = $attr{'ArchitextURL'};
  31. }
  32.  
  33. $news_url = &Architext'newsURL();
  34. $scriptname = "AT-admin.cgi";
  35.  
  36. if ($form{'register'} eq 'yes') {
  37.     ## given the presence of the register attribute
  38.     ## we can assume that the user has registered with
  39.     ## architext and is visiting this page for the
  40.     ## first time, so we need to update Architext.conf
  41.     ## to mark the user as registered.
  42.     $cmd = "echo register yes >> $attr{'ArchitextRoot'}/Architext.conf";
  43.     $exit = system($cmd) unless ($attr{'register'} eq 'yes');
  44.     &Architext'exitError($attr{'ArchitextURL'},
  45.                  "Unable to update configuration file with registation information. $!") if $exit;
  46.     if ($form{'remote'} eq 'yes') {
  47.         $cmd = "touch $attr{'ArchitextRoot'}/.remote";
  48.         $exit = system($cmd) unless (-e "$attr{'ArchitextRoot'}/.remote");
  49.         &Architext'exitError($attr{'ArchitextURL'},
  50.                  "Unable to create .remote file - $!") 
  51.         if $exit;
  52.     }
  53.     if ($form{'at_email'}) {
  54.         $cmd = "echo AdminMail $form{'at_email'} >> $attr{'ArchitextRoot'}/Architext.conf";
  55.         $exit = system($cmd) unless ($attr{'AdminMail'});
  56.         &Architext'exitError($attr{'ArchitextURL'},
  57.                  "Unable to update configuration file with admin mail address. $!") if $exit;
  58.     }
  59.     ## create index.html file with some interesting stuff in it
  60.     %attr = &ArchitextConf'readConfig("$root/Architext.conf");    
  61.     &createIndex($attr{'ConfigRoot'});
  62. }
  63.  
  64. ## check for password, if one is specified in Architext.conf
  65. ## if it doesn't appear as a form arg, present password page
  66.  
  67. if ($attr{'register'} eq 'yes') {
  68.     ## they are registered, so present them with the options
  69.     ## and check for an admin password
  70.     &Architext'password($attr{'ArchitextURL'},
  71.             $scriptname,
  72.             $attr{'Password'}, 
  73.             $form{'password'});
  74.     
  75.     $attr{'Password'} =~ tr/a-zA-Z/n-za-mN-ZA-M/;
  76.     $postpass = 
  77.     "<INPUT TYPE=\"hidden\" NAME=\"password\" VALUE=\"$attr{'Password'}\">"
  78.         if ($attr{'Password'});
  79.     $getpass = "?password=$attr{'Password'}" if $postpass;
  80.  
  81.     if ($form{'db'}) {
  82.     ## db specific admin page
  83.     &Architext'printHeader($attr{'ArchitextURL'}, 
  84.                    "Collection Administration: $form{'db'}");
  85.     print "<hr><b>Collection Status</b><ul>";
  86.     &Architext'printStatus($form{'db'}, $root, $attr{'ConfigRoot'},
  87.                    $attr{'ArchitextURL'}, $attr{'CollectionRoot'});
  88.     print <<EOF;
  89. <p><FORM ACTION="AT-admin.cgi" METHOD=POST>
  90. <INPUT TYPE="submit" VALUE="Update Status">
  91. Check status information again, in case it has changed.
  92. <INPUT TYPE="hidden" NAME="db" VALUE="$form{'db'}">
  93. $postpass
  94. </FORM>
  95. EOF
  96.     ;
  97.     print "</ul><hr>";
  98.     print <<EOF;
  99. <b>Possible Actions</b><ul>
  100.  
  101. <FORM ACTION="AT-config.cgi" METHOD="POST">
  102. <INPUT TYPE="submit" VALUE="Configure"> 
  103. <INPUT TYPE="hidden" NAME="db" VALUE="$form{'db'}">
  104. Configure the characteristics of this document collection.  
  105. $postpass
  106. </FORM>
  107. EOF
  108.     ;
  109.     ## show index or stop index button appropriately
  110.     if (-e "$root/collections/$form{'db'}.pid") {
  111.         print <<EOF;
  112. <FORM ACTION="AT-index.cgi" METHOD=POST>
  113. <INPUT TYPE="submit" NAME="Stop" VALUE="Stop Indexing">
  114. Stop the indexing process that is currently running on this collection.
  115. <INPUT TYPE="hidden" NAME="db" VALUE="$form{'db'}">
  116. $postpass
  117. </FORM>
  118. EOF
  119.     ;
  120.     } else {
  121.         print <<EOF;
  122. <FORM ACTION="AT-index.cgi" METHOD="POST">
  123. <INPUT TYPE="hidden" NAME="db" VALUE="$form{'db'}">
  124. <INPUT TYPE="submit" VALUE="Index"> 
  125. Create an index for this collection.
  126. $postpass
  127. </FORM>
  128. EOF
  129.     ;
  130.     }
  131.  
  132.     print <<EOF;
  133.  
  134. <FORM ACTION="AT-generate.cgi" METHOD="POST">
  135. <INPUT TYPE="hidden" NAME="db" VALUE="$form{'db'}">
  136. <INPUT TYPE="submit" VALUE="Generate"> Generate the pages
  137. needed to search on this collection.
  138. $postpass
  139. </FORM>
  140. EOF
  141.     ;
  142.     if (-e "$attr{'ConfigRoot'}/AT-$form{'db'}query.html") {
  143.         print <<EOF;    
  144. <FORM ACTION="$attr{'ArchitextURL'}AT-$form{'db'}query.html" METHOD="GET">
  145. <INPUT TYPE="submit" VALUE="Search">
  146. Make a query on this collection.
  147. </FORM>
  148.  
  149. EOF
  150.     ;
  151.     }            
  152.     if ((-e "$root/collections/$form{'db'}.pid") ||
  153.     (-e "$root/collections/$form{'db'}.last") ||
  154.     (-e "$root/collections/new/$form{'db'}.err")) {
  155.     print <<EOF;
  156. <p> <FORM ACTION="AT-generate.cgi" METHOD=POST>
  157. <INPUT TYPE="submit" NAME="Status" VALUE="View Logs">
  158. View the log files from the most recent indexing process.
  159. <INPUT TYPE="hidden" NAME="db" VALUE="$form{'db'}">
  160. $postpass
  161. </FORM>
  162. EOF
  163.     ;
  164.  
  165.     }
  166.     print <<EOF;
  167. <FORM ACTION="AT-admin.cgi" METHOD="POST">
  168. <INPUT TYPE="hidden" NAME="dbname" VALUE="$form{'db'}">
  169. <INPUT TYPE="hidden" NAME="Remove" VALUE="Remove">
  170. <INPUT TYPE="submit" VALUE="Remove">
  171. Remove this collection and all files associated with it.
  172. $postpass
  173. </FORM>
  174.  
  175. <FORM ACTION="AT-admin.cgi" METHOD="POST">
  176. <INPUT TYPE="submit" VALUE="Main Admin Page">
  177. Go back to the main administration page.
  178. $postpass
  179. </FORM>
  180.  
  181. EOF
  182. ;
  183.     print "</ul>";
  184.     print "<hr><b>Collection Characteristics</b>\n";
  185.     &printForm($form{'db'}); 
  186.     } elsif ($form{'Support'}) {
  187.     ## send support information to Architext
  188.     open(STDERR, ">/dev/null");
  189.     @commands = ('ls -ld HTML', 'ls -l HTML',
  190.              'ls -ld ROOT', 'ls -ld ROOT/collections',
  191.              'ls -ld ROOT/collections/new',
  192.              'ls -lR ROOT', 'cat ROOT/Architext.conf',
  193.              'cat ROOT/collections/*.conf');
  194.  
  195.     opendir(LOGS, "$attr{'ConfigRoot'}");
  196.     @outfiles = grep(/\.log|err|prog$/, readdir(LOGS));
  197.     for (@outfiles) {
  198.         push(@commands, "tail HTML/$_");
  199.     }
  200.     
  201.     &Architext'printHeader($attr{'ArchitextURL'}, 
  202.                    "Create Support Information");
  203.  
  204.  
  205.     open(SUPPORT, ">$root/support.out");
  206.     open(MAIL, "| mail support@atext.com") if $form{'email'};
  207.     print MAIL "To: support@atext.com\n" if $form{'email'};
  208.     print MAIL "Subject: Architext Support Information\n" if $form{'email'};
  209.     for (@commands) {
  210.         $_ =~ s/ROOT/$root/;
  211.         $_ =~ s/HTML/$attr{'ConfigRoot'}/;
  212.         print SUPPORT "$_\n";
  213.         print MAIL "$_\n" if $form{'email'};
  214.         print SUPPORT `$_`;
  215.         print MAIL `$_` if $form{'email'};
  216.         print MAIL "\n" if $form{'email'};
  217.         print SUPPORT "\n";
  218.         
  219.     }
  220.     
  221.     close(MAIL) if $form{'email'};
  222.     close(SUPPORT);
  223.  
  224.     if ($form{'email'}) {
  225.         $email = 
  226.         ", and has been sent via email to <b>support@atext.com</b>,";
  227.     } else {
  228.         $email = ".";
  229.     }            
  230.  
  231.     print <<EOF;
  232.  
  233. <p> Your support information has been recorded in the file
  234. <b>$root/support.out</b>$email  If your system is not configured to send email
  235. to outside locations, please send the contents of the above file
  236. to support@atext.com.  Thank you.
  237. <p>
  238. <FORM ACTION="AT-admin.cgi" METHOD=POST>
  239. $postpass
  240. <INPUT TYPE="submit" NAME="GoBack" VALUE="Back To Main Admin Page">
  241. </FORM>
  242. EOF
  243.     ;
  244.     &Architext'Copyright($attr{'ArchitextURL'});
  245.     exit 0;
  246.     } elsif ($form{'Remove'}) {
  247.     ## remove collection verb
  248.     &Architext'printHeader($attr{'ArchitextURL'},
  249.                    "Remove Collection: $form{'dbname'}");
  250.     if ($form{'verify'}) {
  251.         if (-e "$root/collections/$form{'dbname'}.pid") {
  252.         print "<p><b>Sorry, you cannot remove a collection while an index process is running for that collection</b>";
  253.         } else {
  254.         ## no index process is running, so it is safe to
  255.         ## remove the collection and all associated files
  256.         %attr = &ArchitextConf'readConfig("$root/Architext.conf", 
  257.                           $form{'dbname'});
  258.         open(STDERR, ">/dev/null");
  259.         push(@commands, 
  260.              "rm -f $root/collections/new/$form{'dbname'}*");
  261.         push(@commands, 
  262.              "rm -f $root/collections/$form{'dbname'}*");
  263.         push(@commands, "rm -f $attr{'CollectionRoot'}*");
  264.         push(@commands, 
  265.              "rm -f $attr{'ConfigRoot'}/AT-$form{'dbname'}query.html");
  266.         push(@commands, 
  267.              "rm -f $attr{'ConfigRoot'}/AT-$form{'dbname'}.log");
  268.         push(@commands, 
  269.              "rm -f $attr{'ConfigRoot'}/AT-$form{'dbname'}.prog");
  270.         push(@commands, 
  271.              "rm -f $attr{'ConfigRoot'}/AT-$form{'dbname'}.err");
  272.         push(@commands,
  273.              "rm -f $attr{'CgiBin'}AT-$form{'dbname'}search.cgi");
  274.         push(@commands,
  275.              "rm -f $attr{'CgiBin'}AT-$form{'dbname'}gather.cgi");
  276.         push(@commands,
  277.              "rm -f $attr{'ConfigRoot'}/AT-$form{'dbname'}search.cgi");
  278.         push(@commands,
  279.              "rm -f $attr{'ConfigRoot'}/AT-$form{'dbname'}gather.cgi");
  280.         for (@commands) {
  281.             system($_);
  282.         }
  283.         print "<p><b>The collection '$form{'dbname'}' has been removed</b>.";
  284.         }
  285.         print <<EOF;
  286. <p>
  287. <FORM ACTION="AT-admin.cgi" METHOD=POST>
  288. $postpass
  289. <INPUT TYPE="submit" VALUE="Admin">
  290. Go back to the main administration page.
  291. </FORM>
  292. EOF
  293.     ;
  294.  
  295.     } else {
  296.         print <<EOF;
  297. Do you really want to remove the configure files, index files, and 
  298. query scripts associated with this collection?
  299. <p>
  300. <FORM ACTION="AT-admin.cgi" METHOD=POST>
  301. <INPUT TYPE="hidden" NAME="verify" VALUE="yes">
  302. <INPUT TYPE="hidden" NAME="Remove" VALUE="Remove">
  303. <INPUT TYPE="hidden" NAME="dbname" VALUE="$form{'dbname'}">
  304. $postpass
  305. <INPUT TYPE="submit" VALUE="Remove">
  306. Remove all files associated with this collection.
  307. </FORM>
  308.  
  309. <p>
  310. <FORM ACTION="AT-admin.cgi" METHOD=POST>
  311. <INPUT TYPE="hidden" NAME="db" VALUE="$form{'dbname'}">
  312. $postpass
  313. <INPUT TYPE="submit" VALUE="Admin">
  314. Don't remove files, go back to the administration page for this collection.
  315. </FORM>
  316. EOF
  317.     ;
  318.  
  319.     }
  320.     &Architext'Copyright($attr{'ArchitextURL'});
  321.     exit(0);
  322.     } else {
  323.     ## main admin page
  324.     &Architext'printHeader($attr{'ArchitextURL'}, 
  325.                    "On Target Administration");
  326.     opendir(CONF, "$root/collections");
  327.     @dbconf = grep(/\.conf$/, readdir(CONF));
  328.     print "<hr><b>Exisiting Collections</b><ul>";
  329.     
  330.     if ($#dbconf > -1) {
  331.         for (@dbconf) {
  332.         s|\.conf$||;
  333.         if ($getpass) {
  334.             $getdb = "&db=$_";
  335.         } else {
  336.             $getdb = "?db=$_";
  337.         }
  338.         print qq(<br> <a href="AT-admin.cgi$getpass$getdb">$_</a>\n);
  339.         $status = &Architext'getStatusString($root, $_, 
  340.                              $attr{'ConfigRoot'},
  341.                              $attr{'ArchitextURL'});
  342.         print " -- $status\n";
  343.         }
  344.     } else {
  345.         print "<p>(No document collections found)<p>\n";
  346.     }
  347.  
  348.     print "</ul><hr>";
  349.     
  350.     print "<b> New Collection</b><ul>";
  351.     print <<EOF;
  352. <p><FORM ACTION="AT-config.cgi" METHOD=POST>
  353. Enter a name for a new collection:
  354. <INPUT NAME="new" SIZE=20><br>
  355. <INPUT TYPE="submit" NAME="NewCollection" VALUE="Create New Collection">
  356. $postpass
  357. </FORM>
  358. EOF
  359.     ;
  360.  
  361.     print "</ul><hr>";
  362.  
  363.     print "<b> Support Information</b>"; 
  364.     print "<ul>";
  365. print <<EOF;
  366. <p><FORM ACTION="AT-admin.cgi" METHOD=POST>
  367. $postpass
  368. <INPUT TYPE="checkbox" NAME="email" VALUE="email" CHECKED>
  369. Send support information to <b>support@atext.com</b>.  If you do not
  370. want the information automatically emailed to Architext, uncheck this
  371. box, and a file containing the support information will be created, but
  372. not emailed.<br>
  373. <INPUT TYPE="submit" NAME="Support" VALUE="Support">
  374. EOF
  375.     ;
  376.        
  377.     print "</ul>";
  378.     print <<EOF;        
  379. <hr>
  380. <a href="$news_url">
  381. News</a> Check here for up-to-the-minute information about OnTarget.
  382. <hr>
  383. <a href="$attr{'ArchitextURL'}AT-admininfo.html">
  384. Admin Info Page.</a>  This page is simply
  385. a list of the options you chose at install time; you
  386. can check here to find out where certain files are located in
  387. case you have forgotten. 
  388. EOF
  389.     ;
  390.     &Architext'Copyright($attr{'ArchitextURL'});
  391.     exit 0;
  392.     }
  393.  
  394.  
  395.  
  396. } else {
  397.     ## not yet registered, so print out screen to send user
  398.     ## back to AT-starthere.html to get them registered and
  399.     ## happy before they start using the admin tools
  400.     &Architext'printHeader($attr{'ArchitextURL'}, "Architext Administration");
  401.     print <<EOF;
  402. <p><h1> Not yet registered. </h1>
  403. <p>  Apparently, you have not yet registered your copy of
  404. this software with Architext.  To do this, please go to the
  405. <a href="AT-start.cgi">getting started</a>
  406. page and follow the instructions presented there. <br>
  407. Thanks!<br>
  408. EOF
  409. ;
  410. }
  411.  
  412. &Architext'Copyright($attr{'ArchitextURL'});
  413.  
  414.  
  415. ## show the attributes for a particular collection
  416. sub printForm {
  417.     local($db) = shift;
  418.     local($url) = $attr{'ArchitextURL'};
  419.     print "<UL>\n";
  420.     &Architext'printLineItem($url,'IndexExecutable',
  421.                  $attr{'IndexExecutable'})
  422.     if &Architext'debugMode();
  423.     &Architext'printLineItem($url,'SearchExecutable',
  424.                  $attr{'SearchExecutable'})
  425.     if &Architext'debugMode();
  426.     &Architext'printLineItem($url,'StemTable',$attr{'StemTable'})
  427.     if &Architext'debugMode();
  428.     &Architext'printLineItem($url,'StopTable',$attr{'StopTable'})
  429.     if &Architext'debugMode();
  430.     &Architext'printLineItem($url,'CollectionInfo', $attr{'CollectionInfo'})
  431.     if &Architext'debugMode();
  432.     &Architext'printLineItem($url,'CollectionIndex',
  433.                  $attr{'CollectionIndex'});
  434.     if ($attr{'CollectionContents'} =~ /^\+/) {
  435.     $attr{'CollectionContents'} =~ s/^\+//;
  436.     print <<EOF;
  437. <li> <a href="${helppath}AT-helpdoc.html#CollectionContents">
  438. CollectionContents:</a> Index the files listed in 
  439. '$attr{'CollectionContents'}'.
  440. EOF
  441.     ;
  442.     } else {
  443.     $files = join(", ", split(/[:,;\s]+/, $attr{'CollectionContents'}));
  444.     print <<EOF;
  445. <li> <a href="${helppath}AT-helpdoc.html#CollectionContents">
  446. CollectionContents:</a> Index the files '$files' using these rules:<ul>
  447. EOF
  448.     ;
  449.     &Architext'printLineItem($url,'IndexFilter',
  450.                  $attr{'IndexFilter'});
  451.     &Architext'printLineItem($url,'ExclusionRules',
  452.                  $attr{'ExclusionRules'});
  453.     print "</ul>";
  454.     }
  455.     &Architext'printLineItem($url,'AdminMail',
  456.                  $attr{'AdminMail'});
  457.     print "</UL>\n";
  458.  
  459. }
  460.  
  461. sub createIndex {
  462.     local($location) = @_;
  463.     open(INDEX, ">$location/index.html");
  464.     print INDEX qq(<html><head><title>On Target Administration</title></head>);
  465.     print INDEX qq(<body><h1><img src="pictures/AT-Block-logo.gif">);
  466.     print INDEX qq(<p>Architext On Target</h1>);
  467.     print INDEX qq(<p> Welcome to the OnTarget administration directory.\n);
  468.     print INDEX qq(From here, you can:); 
  469.     print INDEX qq(<p> Go to the <a href="$ENV{'SCRIPT_NAME'}"> main\n);
  470.     print INDEX qq(administration page</a>.<br>\n);
  471.     print INDEX qq(Go to <a href="http://www.atext.com">Architext Software's);
  472.     print INDEX qq(</a> home page);
  473.     print INDEX qq(<p><p><b>TIP:</b> Make a bookmark for this page, so you can easily get back to the administration page.);
  474.     close(INDEX);
  475. }
  476.