home *** CD-ROM | disk | FTP | other *** search
- #!/usr/bin/perl5
- #
- # summary.cgi
- #
- # Copyright 1988-1996 Silicon Graphics, Inc.
- # All rights reserved.
- #
- # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- # the contents of this file may not be disclosed to third parties, copied or
- # duplicated in any form, in whole or in part, without the prior written
- # permission of Silicon Graphics, Inc.
- #
- # RESTRICTED RIGHTS LEGEND:
- # Use, duplication or disclosure by the Government is subject to restrictions
- # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- # rights reserved under the Copyright Laws of the United States.
- #
- # $Id: summary.cgi,v 1.4 1998/01/31 02:14:11 jrw Exp $
-
- #################################################################
- # #
- # LIMITATIONS: If the protocol order of a particular map is #
- # changed, protocol attributes and control pairs will be lost. #
- # A future version of Internet Gateway may correct this. #
- # #
- #################################################################
-
- BEGIN { require "/usr/WebFace/lib/CGI.pm"; import CGI; }
- require "/usr/OnRamp/lib/OnRamp.pm";
- require "/usr/OnRamp/lib/java.pm";
-
- $query = new CGI;
-
- $nsswitch_cf = "/etc/nsswitch.conf";
- $dummy = "/etc/nsswitch.conf.tmp";
- $title = "Unified Name Service";
- $myname = "summary.cgi";
- $help_page = "nsd-config-help.html";
- $conf_page = "/admin/nsd-config.cgi";
-
-
- $js =
- "$js_standard
- $js_help
- $js_error_box
- function checkForm(form) {
- return (true);
- }";
-
- if ($query->param('doit')) {
-
- $instructions = "<blockquote>
- You have made changes to the following UNS maps. If this looks
- correct, use the \"Accept\" button to make the changes. If not,
- use the \"Cancel\" button to go back and edit your configuration.
- </blockquote><p>\n";
-
- @names = $query->param;
- foreach $key (@names) {
- $show_summary = 'true'
- if ($key ne 'doit' && $query->param($key) ne 'delete');
- }
- if ($show_summary) {
- print $query->header;
- &generic;
- } else {
- # Delete maps
- open(NSSWITCH, $nsswitch_cf);
- open(TEMP, ">$dummy");
- while ($line = <NSSWITCH>) {
- if ($line =~ /^\s*[#\n]/) {
- print TEMP "$line";
- next;
- }
- @entlist = split(/\s+/, $line);
- chop ($entlist[0]);
- $entlist[0] =~ s/(\S+)\s*(\(\S+\)*)$/\1/g;
-
- undef $found;
- foreach $key (@names) {
- next if ($key eq 'doit');
- if ($key eq $entlist[0]) {
- # We have a match
- print TEMP "# $line";
- $found = 'true';
- }
- }
- print TEMP "$line" unless $found;
- }
- close(NSSWITCH);
- close(TEMP);
- rename($dummy, $nsswitch_cf);
- system("/etc/killall", "-HUP", "nsd");
- &redirect("$conf_page?done");
- exit;
- }
-
- } elsif ($query->param('accept')) {
-
- rename($dummy, $nsswitch_cf);
- system("/etc/killall", "-HUP", "nsd");
- &redirect("$conf_page?done");
- exit;
-
- } else {
- &redirect($conf_page);
- exit;
- }
-
- sub confirm_nsswitch {
-
- foreach $map (@names) { # Find maps to be edited
- if ($map =~ /_1$/) {
- $newmap = $map;
- if ($map =~ /new\d+/) {
- $newmap =~ s/_\d+$//g;
- $name = $newmap . "_name";
- $name = $query->param($name);
- if ($name) {
- push (@newlist, $name);
- $indices{$name} = $newmap;
- }
-
- } elsif ($map !~ /^old_/) {
- # Weed out if no changes were made
- $newmap =~ s/_\d+$//g;
- undef $changed;
- for ($i = 1; $i < 4; $i++) {
- $new = $newmap . "_" . $i;
- $old = "old_" . $newmap . "_" . $i;
- $changed = 'true'
- unless ($query->param($new) eq $query->param($old));
- }
- push (@maplist, $newmap) if $changed;
- }
- } elsif ($query->param($map) eq 'delete') {
- push (@deletelist, $map);
- }
- }
-
- open(NSSWITCH, $nsswitch_cf); # Comment out old maps
- open(TEMP, ">$dummy");
- while ($line = <NSSWITCH>) {
- if ($line =~ /^\s*[#\n]/) {
- print TEMP "$line";
- next;
- }
- @entlist = split(/\s+/, $line);
- chop ($entlist[0]);
- @found = ($entlist[0] =~ /(\(\S+\)*)$/);
- $entlist[0] =~ s/(\S+)\s*(\(\S+\)*)$/\1/g;
- if($2 && @found) {
- $map_attr{$entlist[0]} = $2;
- }
-
- undef $found;
- foreach $map (@maplist) {
- if ($map eq $entlist[0]) {
- # We have a match
- print TEMP "# $line";
- $found = 'true';
- }
- }
- if (! $found) {
- foreach $map (@deletelist) {
- if ($map eq $entlist[0]) {
- # We have a match
- print TEMP "# $line";
- $found = 'true';
- }
- }
- }
- print TEMP "$line" unless $found;
- }
- close(NSSWITCH);
-
- foreach $map (@maplist,@newlist) { # Add new maps
- print "<tr>";
- print "<td><b>$map:</b>\n";
-
- print TEMP "$map$map_attr{$map}: ";
- for ($i = length("$map$map_attr{$map}:"); $i < 24; $i += 8) {
- print TEMP "\t";
- }
-
- $map = $indices{$map} if (grep(/$map/,@newlist));
- @values = ($query->param($map."_1"),
- $query->param($map."_2"),
- $query->param($map."_3"));
- &check_values;
- print "<td>$values[0]";
- print "<td>$values[1]" if ($values[1] ne "none");
- print "<td>$values[2]" if ($values[2] ne "none");
- print "\n";
- if ($error) {
- print $error;
- undef $error;
- }
- print TEMP "$values[0]";
- print TEMP " $values[1]" if ($values[1] ne "none");
- print TEMP " $values[2]" if ($values[2] ne "none");
- print TEMP "\n";
- }
- foreach $map (@deletelist) {
- print "<tr>";
- print "<td><b>$map:</b>\n";
- print "<td colspan=3><i>will be deleted</i>\n";
- }
- close(TEMP);
- }
-
- sub check_values
- {
- if ($values[0] eq "none") {
- $values[0] = $values[1];
- $values[1] = $values[2];
- $values[2] = "none";
- }
- if ($values[0] eq "none") {
- $values[0] = $values[1];
- $values[1] = "none";
- }
- if ($values[0] eq "none") {
- $values[0] = "files";
- $error = "<tr><td colspan=4><i>Note:
- No service specified for \"$map\".
- Defaulting to \"files\".</i>\n";
- }
- for ($i = 0; $i < 2; $i++) {
- if ($values[0] eq $values[1]) {
- $values[1] = $values[2];
- $values[2] = "none";
- }
- }
- }
-
- sub generic {
- &js_title_block($title,$js);
- &header_block($title);
-
- print $query->startform("POST", "$myname?accept", "", "NAME=StandardForm",
- "onSubmit=\"return runSubmit()\"");
-
- print $instructions;
-
- print qq|<font size="+1"><center><table>\n|;
- &confirm_nsswitch;
- print "</tr></table></center>";
- print "<p>\n";
-
- print qq|<center><table border=2 cellspacing=0 cellpadding=0 width=300>
- <tr><th align=center>
- <input type="submit" name="accept" value="Accept" onClick="markOther()">
- <th align=center>
- <input type="button" name="back" value="Cancel"
- onClick="markOther(); history.back()"></tr></table></center></font>|;
-
- print $query->endform;
- }
-