home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume25 / policy / part01 / scripts / policy.pl < prev    next >
Encoding:
Perl Script  |  1992-02-28  |  3.3 KB  |  124 lines

  1. #!/usr/local/bin/perl
  2. # $Id: policy.pl,v 5.3.2.5 91/09/03 09:56:01 policy USENET $
  3. #
  4. # Ported to perl by Andy Linton <Andy.Linton@comp.vuw.ac.nz>
  5. # Based on a shell script by Bud Hovell <bud@mtek.com>
  6. #
  7. # Copyright (c) 1991 Andy Linton
  8. # All rights reserved.
  9. #
  10. # Redistribution and use in source and binary forms are permitted provided
  11. # that: (1) source distributions retain this entire copyright notice and
  12. # comment, and (2) distributions including binaries display the following
  13. # acknowledgement:  ``This product includes software developed by the
  14. # Victoria University of Wellington, New Zealand and its contributors''
  15. # in the documentation or other materials provided with the distribution
  16. # and in all advertising materials mentioning features or use of this
  17. # software.
  18. # Neither the name of the University nor the names of its contributors may
  19. # be used to endorse or promote products derived from this software without
  20. # specific prior written permission.
  21. # THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  22. # WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  23. # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  24. #################### edit these in the Makefile! ###########################
  25. $poldir='';
  26. $pager='';
  27. $myname='';
  28. ############################################################################
  29. # Note: any policy file must be named identically to the first word of the
  30. #     first line in the file itself. Consider the file "logins", with
  31. #    this as line one:
  32. #
  33. #    logins  - responsibilities of users
  34. #
  35. #    .....where the word "logins" begins at character one of line
  36. #       one of the file named "logins". This first line will then be
  37. #       extracted to the ad-hoc menu file to provide the menu id for
  38. #       the user to select the "logins" policy file.
  39.  
  40. $| = 1;        # Force a flush after each write or print
  41.  
  42. $clear='';
  43. # Do we have a "clear" function?
  44. if (-x '/bin/clear')
  45. {
  46.     $clear='/bin/clear';
  47. }
  48. elsif (-x '/usr/bin/clear')
  49. {
  50.     $clear='/usr/bin/clear';
  51. }
  52. elsif (-x '/usr/ucb/clear')
  53. {
  54.     $clear='/usr/ucb/clear';
  55. }
  56. # ....or curses?
  57. elsif (-x '/usr/bin/tput')
  58. {
  59.     $clear='/usr/bin/tput clear';
  60. }
  61.  
  62. # Build a menu from the files in the $poldir directory
  63. chdir ($poldir);
  64. opendir (POLDIR, $poldir) || die "Can't opendir $poldir, stopped";
  65. while ($filename = readdir (POLDIR))
  66. {
  67.   if (-f $filename)
  68.   {
  69.     open (FILENAME, $filename) || die  "Can't opendir $filename, stopped";
  70.     $_ = <FILENAME>;
  71.     close (FILENAME);
  72.     ($menu_entry, $junk) = split(/\$/);
  73.     $menu{$filename} = $menu_entry;
  74.   }
  75. }
  76.  
  77. $hostname = `$myname`;
  78. $hostname =~ tr/a-z/A-Z/;
  79.  
  80. # Re-run the menu until 'quit' from user:
  81. while(1)
  82. {
  83.   system ("$clear");
  84.  
  85.   print "\nDIRECTORY OF LOCAL POLICY FOR $hostname\n";
  86.   
  87.   while (($key, $value) = each(%menu))
  88.   {
  89.     print "\n\t$value\n";
  90.   }
  91.  
  92.   print "\n\tor 'q'uit";
  93.   print "\n\nTo review a policy, type in subject: > ";
  94.   $_ = <STDIN>;
  95.   if (/^[qQ]$/)
  96.   {
  97.     # Wants to quit
  98.     print "\nPolicy review concluded. Thank you for your interest.\n";
  99.     last;
  100.   }
  101.   elsif (/^$/)
  102.   {
  103.     # No entry
  104.     print "\nYou must provide a name or 'q'uit.\007";
  105.     sleep (2);
  106.     next;
  107.   }
  108.   else
  109.   {
  110.     # Wants another
  111.     chop;
  112.     if (-r "$poldir/$_")
  113.     {
  114.       system ("$clear");
  115.       system ("$pager $poldir/$_");
  116.     }
  117.     else
  118.     {
  119.       print "\nYou must provide a name or 'q'uit.\007";
  120.       sleep (2);
  121.     }
  122.   }
  123. }
  124.