home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Applications 2002 November / SGI IRIX 6.5 Applications 2002 November.iso / dist / gateway.idb / usr / WebFace / Source / 20-NetworkServices / nsd / summary.cgi.z / summary.cgi
Encoding:
Text File  |  2002-06-12  |  7.8 KB  |  262 lines

  1. #!/usr/bin/perl5
  2. #
  3. # summary.cgi
  4. #
  5. # Copyright 1988-1996 Silicon Graphics, Inc.
  6. # All rights reserved.
  7. #
  8. # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  9. # the contents of this file may not be disclosed to third parties, copied or
  10. # duplicated in any form, in whole or in part, without the prior written
  11. # permission of Silicon Graphics, Inc.
  12. #
  13. # RESTRICTED RIGHTS LEGEND:
  14. # Use, duplication or disclosure by the Government is subject to restrictions
  15. # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  16. # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  17. # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  18. # rights reserved under the Copyright Laws of the United States.
  19. #
  20. # $Id: summary.cgi,v 1.4 1998/01/31 02:14:11 jrw Exp $
  21.  
  22. #################################################################
  23. #                                                               #
  24. # LIMITATIONS: If the protocol order of a particular map is     #
  25. # changed, protocol attributes and control pairs will be lost.  #
  26. # A future version of Internet Gateway may correct this.        # 
  27. #                                                               #
  28. #################################################################
  29.  
  30. BEGIN { require "/usr/WebFace/lib/CGI.pm"; import CGI; }
  31. require "/usr/OnRamp/lib/OnRamp.pm";
  32. require "/usr/OnRamp/lib/java.pm";
  33.  
  34. $query = new CGI;
  35.  
  36. $nsswitch_cf  = "/etc/nsswitch.conf";
  37. $dummy        = "/etc/nsswitch.conf.tmp";
  38. $title        = "Unified Name Service";
  39. $myname       = "summary.cgi";
  40. $help_page    = "nsd-config-help.html";
  41. $conf_page    = "/admin/nsd-config.cgi";
  42.  
  43.  
  44. $js =
  45. "$js_standard
  46. $js_help
  47. $js_error_box
  48. function checkForm(form) {
  49.         return (true);
  50. }";
  51.  
  52. if ($query->param('doit')) {
  53.  
  54.     $instructions = "<blockquote>
  55.         You have made changes to the following UNS maps.  If this looks 
  56.         correct, use the \"Accept\" button to make the changes.  If not, 
  57.         use the \"Cancel\" button to go back and edit your configuration.  
  58.         </blockquote><p>\n";
  59.  
  60.     @names = $query->param;
  61.     foreach $key (@names) {
  62.         $show_summary = 'true' 
  63.             if ($key ne 'doit' && $query->param($key) ne 'delete');
  64.     }
  65.     if ($show_summary) {
  66.         print $query->header;
  67.         &generic;
  68.     } else {
  69.         # Delete maps
  70.         open(NSSWITCH, $nsswitch_cf);
  71.         open(TEMP, ">$dummy");
  72.         while ($line = <NSSWITCH>) {
  73.             if ($line =~ /^\s*[#\n]/) {
  74.                 print TEMP "$line";
  75.                 next;
  76.             }
  77.             @entlist = split(/\s+/, $line);
  78.             chop ($entlist[0]);
  79.             $entlist[0] =~ s/(\S+)\s*(\(\S+\)*)$/\1/g;
  80.  
  81.             undef $found;
  82.             foreach $key (@names) {
  83.                 next if ($key eq 'doit');
  84.                 if ($key eq $entlist[0]) {
  85.                     # We have a match
  86.                     print TEMP "# $line";
  87.                     $found = 'true';
  88.                 }
  89.             }
  90.             print TEMP "$line" unless $found;
  91.         }
  92.         close(NSSWITCH);
  93.         close(TEMP);
  94.         rename($dummy, $nsswitch_cf);
  95.         system("/etc/killall", "-HUP", "nsd");
  96.         &redirect("$conf_page?done"); 
  97.         exit; 
  98.     }
  99.  
  100. } elsif ($query->param('accept')) {
  101.  
  102.     rename($dummy, $nsswitch_cf);
  103.     system("/etc/killall", "-HUP", "nsd");
  104.     &redirect("$conf_page?done"); 
  105.     exit; 
  106.  
  107. } else {
  108.     &redirect($conf_page);
  109.     exit;
  110. }
  111.  
  112. sub confirm_nsswitch {
  113.  
  114.     foreach $map (@names) {               # Find maps to be edited
  115.         if ($map =~ /_1$/) {
  116.             $newmap = $map;
  117.             if ($map =~ /new\d+/) {
  118.                 $newmap =~ s/_\d+$//g;
  119.                 $name = $newmap . "_name";
  120.                 $name = $query->param($name);
  121.                 if ($name) {
  122.                     push (@newlist, $name);
  123.                     $indices{$name} = $newmap;
  124.                 }
  125.  
  126.             } elsif ($map !~ /^old_/) {
  127.                 # Weed out if no changes were made
  128.                 $newmap =~ s/_\d+$//g;
  129.                 undef $changed;
  130.                 for ($i = 1; $i < 4; $i++) {
  131.                     $new = $newmap . "_" . $i;
  132.                     $old = "old_" . $newmap . "_" . $i;
  133.                     $changed = 'true'
  134.                         unless ($query->param($new) eq $query->param($old));
  135.                 }
  136.                 push (@maplist, $newmap) if $changed; 
  137.             }
  138.         } elsif ($query->param($map) eq 'delete') {
  139.             push (@deletelist, $map);
  140.         }
  141.     }
  142.  
  143.     open(NSSWITCH, $nsswitch_cf);          # Comment out old maps
  144.     open(TEMP, ">$dummy");
  145.     while ($line = <NSSWITCH>) {
  146.         if ($line =~ /^\s*[#\n]/) {
  147.             print TEMP "$line";
  148.             next;
  149.         }
  150.         @entlist = split(/\s+/, $line);
  151.         chop ($entlist[0]);
  152.         @found = ($entlist[0] =~ /(\(\S+\)*)$/);
  153.         $entlist[0] =~ s/(\S+)\s*(\(\S+\)*)$/\1/g;
  154.         if($2 && @found) {
  155.             $map_attr{$entlist[0]} = $2;
  156.         }
  157.  
  158.         undef $found;
  159.         foreach $map (@maplist) {
  160.             if ($map eq $entlist[0]) {
  161.                 # We have a match
  162.                 print TEMP "# $line";
  163.                 $found = 'true';
  164.             }
  165.         }
  166.         if (! $found) {
  167.             foreach $map (@deletelist) {
  168.                 if ($map eq $entlist[0]) {
  169.                     # We have a match
  170.                     print TEMP "# $line";
  171.                     $found = 'true';
  172.                 }
  173.             }
  174.         }
  175.         print TEMP "$line" unless $found;
  176.     }
  177.     close(NSSWITCH);
  178.  
  179.     foreach $map (@maplist,@newlist) {      # Add new maps
  180.         print "<tr>";
  181.         print "<td><b>$map:</b>\n";
  182.  
  183.         print TEMP "$map$map_attr{$map}: ";
  184.         for ($i = length("$map$map_attr{$map}:"); $i < 24; $i += 8) {
  185.                 print TEMP "\t";
  186.         }
  187.         
  188.         $map = $indices{$map} if (grep(/$map/,@newlist));
  189.         @values = ($query->param($map."_1"),
  190.                    $query->param($map."_2"),
  191.                    $query->param($map."_3"));
  192.         &check_values;
  193.         print "<td>$values[0]";
  194.         print "<td>$values[1]" if ($values[1] ne "none");
  195.         print "<td>$values[2]" if ($values[2] ne "none");
  196.         print "\n";
  197.         if ($error) {
  198.             print $error;
  199.             undef $error;
  200.         }
  201.         print TEMP "$values[0]";
  202.         print TEMP " $values[1]" if ($values[1] ne "none");
  203.         print TEMP " $values[2]" if ($values[2] ne "none");
  204.         print TEMP "\n";
  205.     }
  206.     foreach $map (@deletelist) {
  207.         print "<tr>";
  208.         print "<td><b>$map:</b>\n";
  209.         print "<td colspan=3><i>will be deleted</i>\n";
  210.     }
  211.     close(TEMP);
  212. }
  213.  
  214. sub check_values
  215. {
  216.     if ($values[0] eq "none") {
  217.         $values[0] = $values[1];
  218.         $values[1] = $values[2];
  219.         $values[2] = "none";
  220.     }
  221.     if ($values[0] eq "none") {
  222.         $values[0] = $values[1];
  223.         $values[1] = "none";
  224.     }
  225.     if ($values[0] eq "none") {
  226.         $values[0] = "files";
  227.         $error = "<tr><td colspan=4><i>Note:
  228.                   No service specified for \"$map\".
  229.                   Defaulting to \"files\".</i>\n";
  230.     }
  231.     for ($i = 0; $i < 2; $i++) {
  232.         if ($values[0] eq $values[1]) {
  233.             $values[1] = $values[2];
  234.             $values[2] = "none";
  235.         }
  236.     }
  237. }
  238.  
  239. sub generic {
  240.     &js_title_block($title,$js);
  241.     &header_block($title);
  242.  
  243.     print $query->startform("POST", "$myname?accept", "", "NAME=StandardForm", 
  244.         "onSubmit=\"return runSubmit()\"");
  245.  
  246.     print $instructions;
  247.  
  248.     print qq|<font size="+1"><center><table>\n|;
  249.     &confirm_nsswitch; 
  250.     print "</tr></table></center>";
  251.     print "<p>\n";
  252.  
  253.     print qq|<center><table border=2 cellspacing=0 cellpadding=0 width=300>
  254.     <tr><th align=center>
  255.     <input type="submit" name="accept" value="Accept" onClick="markOther()">
  256.     <th align=center>
  257.     <input type="button" name="back" value="Cancel"
  258.     onClick="markOther(); history.back()"></tr></table></center></font>|;
  259.  
  260.     print $query->endform;
  261. }
  262.