home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / SATAN11.ZIP / PERL / RECONFIG.PL < prev    next >
Perl Script  |  1995-04-11  |  4KB  |  144 lines

  1. #!/usr/local/bin/perl
  2.  
  3. #  Usage: reconfig [file]
  4. #
  5. #   This replaces the program paths (e.g. /bin/awk) in SATAN with an
  6. # alternate path that is found in the file "file.paths".  It also finds
  7. # perl5 (or at least tries!) and changes the path in all the stand-alone
  8. # perl programs.
  9. #
  10.  
  11. # all the HTML browsers we know about, IN ORDER OF PREFERENCE!
  12. @all_www= ("netscape", "Mosaic", "xmosaic", "lynx");
  13.  
  14. #
  15. #  Potential directories to find commands; first, find the user's path...
  16. $PATH = $ENV{"PATH"};
  17.  
  18. # additional dirs; *COLON* separated!
  19. $other_dirs="/usr/ccs/bin:/bin:/usr/bin:/usr/ucb:/usr/bsd:/usr/ucb/bin:/usr/sbin:/usr/etc:/usr/local/bin:/usr/bin/X11:/usr/X11/bin";
  20.  
  21. #
  22. # split into a more reasonable format:
  23. @all_dirs = split(/:/, $PATH . ":" . $other_dirs);
  24.  
  25. #
  26. #  Target shell scripts in question:
  27. @shell_scripts=("paths.pl", "rex.satan", "rsh.satan", "tftp.satan");
  28. @perl5_src = <get_targets faux_fping *satan* html.pl>;
  29.  
  30. #
  31. #  Target shell commands in question
  32. @all_commands=("cc", "cat", "chmod", "cmp", "comm", "cp", "date", "diff",
  33.     "egrep", "expr", "find", "grep", "ls", "mail", "mkdir", "mv", "rm",
  34.     "sed", "sh", "sort", "tftp", "touch", "uniq", "uudecode", "ypcat",
  35.     "strings", "finger", "ftp", "rpcinfo", "rusers", "showmount",
  36.     "ypwhich", "nslookup", "xhost", "su", "awk", "sed", "test");
  37.  
  38. print "checking to make sure all the target(s) are here...\n";
  39.  
  40. for (@shell_scripts) {
  41.     die "ERROR -- $_ not found!\n" unless -f $_;
  42.     }
  43.  
  44. # find perl5!
  45. print "Ok, trying to find perl5 now... hang on a bit...\n";
  46. for $dir (@all_dirs) {
  47.     # first, find where it might be; oftentimes you'll see perl,
  48.     # perl4, perl5, etc. in the same dir
  49.     while (<$dir/perl5* $dir/perl*>) {
  50.         if (-x $_) {
  51.             $perl_version=`($_ -v 2> /dev/null) |
  52.                 awk '/This is perl, version 5/ { print $NF }'`;
  53.             if ($perl_version) {
  54.                 $PERL=$_;
  55.                 $pflag="1";
  56.                 last;
  57.                 }
  58.             }
  59.             last if $pflag;
  60.         }
  61.     last if $pflag;
  62.     }
  63.  
  64. die "\nCan't find perl5!  Bailing out...\n" unless $PERL;
  65. print "\nPerl5 is in $PERL\n";
  66.  
  67. for (@perl5_src) { $perl5_src .= "$_ "; }
  68. print "\nchanging the perl source in: $perl5_src\n";
  69. system "$PERL -pi -e \"s@/usr/local/bin/perl.*@$PERL@;\" $perl5_src";
  70.  
  71. # make sure things are executable...
  72. system("chmod u+x $perl5_src");
  73.  
  74. # find the most preferred www viewer first.
  75. for $www (@all_www) {
  76.     for $dir (@all_dirs) {
  77.         if (!$MOSAIC) {
  78.             if (-x "$dir/$www") {
  79.                 $MOSAIC="$dir/$www";
  80.                 next;
  81.                 }
  82.             }
  83.         }
  84.     }
  85. if ($MOSAIC) {
  86.     print "\nHTML/WWW Browser is $MOSAIC\n";
  87.     $upper{"MOSAIC"} = $MOSAIC;
  88.     }
  89. else { print "Cannot find a web browser!  SATAN cannot be run except in CLI"; }
  90.  
  91. print "\nSo far so good...\nLooking for all the commands now...\n";
  92.  
  93. for $command (@all_commands) {
  94.     $found="false";
  95.     for $dir (@all_dirs) {
  96.         # if find the command in one of the directories, print string
  97.         if (-f "$dir/$command") {
  98.             # this converts to upper case
  99.             ($upper = $command) =~ y/[a-z]/[A-Z]/;
  100.             $found="true";
  101.             $upper{$upper} = "$dir/$command";
  102.             # print "found ($upper) $dir/$command\n";
  103.             last;
  104.             }
  105.         }
  106.     print "can't find $command\n" unless $found eq "true";
  107.     }
  108.  
  109. print "\nOk, now doing substitutions on the shell scripts...\n";
  110. for $shell (@shell_scripts) {
  111.      print "Changing paths in $shell...\n";
  112.     die "Can't open $shell\n" unless open(SCRIPT, $shell);
  113.     rename($shell, $shell . '.old');
  114.     die "Can't open $shell\n" unless open(OUT, ">$shell");
  115.  
  116.     #
  117.     #  Open up the script, search for lines beginning with
  118.     # stuff like "TEST", "AWK", etc.  If the file ends in "pl",
  119.     # assume it's a perl script and change it accordingly
  120.     while (<SCRIPT>) {
  121.         $found = 0;
  122.         for $command (keys %upper) {
  123.             if(/^\$?$command=/) {
  124.                 # shell script
  125.                 if ($shell !~ /.pl$/) {
  126.                     print OUT "$command=$upper{$command}\n";
  127.                     }
  128.                 # perl script
  129.                 else {
  130.                     print OUT "\$" . "$command=\"$upper{$command}\";\n";
  131.                     }
  132.                 $found = 1;
  133.                 }
  134.             }
  135.         print OUT $_ if !$found;
  136.         }
  137.     close(SCRIPT);
  138.     close(OUT);
  139.     # finally, make sure everything is back to executable status
  140.     system ("chmod u+x $shell");
  141.     }
  142.  
  143. # done...
  144.