home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.4 Applications 1997 August / SGI IRIX 6.4 Applications 1997 August.iso / dist / gateway.idb / usr / WebFace / Tasks / Tasks.security-start.cgi.z / Tasks.security-start.cgi
Encoding:
Text File  |  1997-07-30  |  6.4 KB  |  218 lines

  1. #!/usr/bin/perl5
  2. #
  3. # Tasks.security-start.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: Tasks.security-start.cgi,v 1.8 1997/05/01 17:54:45 shotes Exp $
  21.  
  22. require "/usr/OnRamp/lib/OnRamp.pm";
  23.  
  24. $myname = "Tasks.security-start.cgi";
  25. $inet_conf = "/etc/inetd.conf";
  26. $temp = "task.tmp";
  27. $temp2 = "task.tmp2";
  28. $dummy = "task.dummy";
  29. $action = "Tasks.security-start.cgi?loop";
  30.  
  31. $it = "<td><font size=5><i>";
  32. $ni = "</i></font></td>";
  33.  
  34. @find_vals = ('telnet','login','shell','ftp','finger');
  35.  
  36. &get_fields;
  37.  
  38. # clear temporary file for initial call
  39. if (!$ARGV[0]) {
  40.     open(OUT,"> $temp");
  41.     close(OUT);
  42.     open(OUT,"> $temp2");
  43.     close(OUT);
  44. #    &initValues;
  45. } elsif ($ARGV[0] eq 'loop') { %vals = %fld;  }
  46. else { &readValues; }
  47.  
  48. if ($ARGV[0] eq loop) {
  49.     &errorCheck;
  50.     &writeFile;
  51.  
  52.     $go = "/tasks/security-second.cgi?st";
  53.     print "Content-type: text/html\n\n";
  54.     # printf("Location: %s%c%c",$go,10,10);
  55.     print "<HTML><HEAD>";
  56.     print "<META HTTP-EQUIV=\"refresh\" CONTENT=\"0; URL=$go\">";
  57.     print "</HEAD><BODY></BODY></HTML>";
  58.     exit 0;
  59. }
  60.  
  61. &setBoxes;
  62. &generic;
  63.  
  64. sub initValues {
  65.     open(IN,"< $inet_conf");
  66.     while(<IN>) {
  67.         $line = $_;
  68.         if ($line eq "\n") { next; }
  69.         $line =~ /^\s*(\S.*)/;
  70.         @items = split(/\s+/,$1);
  71.         if ($items[0] !~ "#") { $terms{$items[0]} = 1; } 
  72.         else { $terms{$items[0]} = 0; }
  73.     }
  74.     close(IN);
  75.     foreach $arg (@find_vals) {
  76.         if ($arg =~ $_) { $vals{$arg} = $terms{$arg}; }
  77.         else { $vals{$arg} = 0; }
  78.     }
  79. }
  80.  
  81. sub readValues {
  82.     open(IN,"< $temp");
  83.     while(<IN>) {
  84.         chop;
  85.         $terms{$_} = 1;
  86.     }
  87.     close(IN);
  88.     foreach $arg (@find_vals) {
  89.         if ($terms{$arg}) { $vals{$arg} = 1; }
  90.         else { $vals{$arg} = 0; }
  91.     }
  92.     if ($terms{"all_inetd"}) { $vals{"all_inetd"} = 1; }
  93.     else { $vals{"all_inetd"} = 0; }
  94. }
  95.  
  96. sub writeFile {
  97.     undef %terms;
  98.     open(IN,"< $temp");
  99.     while(<IN>) {
  100.         chop;
  101.         $terms{$_} = 1;
  102.     }
  103.     close(IN);
  104.  
  105.     if ($fld{'all_inetd'} == 1) { 
  106.         $terms{'all_inetd'} = 1;
  107.         foreach $arg (@find_vals) { $terms{$arg} = $fld{$arg}; }
  108.     } else {
  109.         $terms{'all_inetd'} = 0;
  110.         foreach $arg (@find_vals) { $terms{$arg} = 0; }
  111.     }
  112.  
  113.     open(OUT,"> $temp");
  114.     foreach $arg (keys(%terms)) {
  115.         print OUT "$arg\n" if ($terms{$arg} == 1);
  116.     }
  117.     close(OUT);
  118. }
  119.  
  120. sub errorCheck {
  121. }
  122.  
  123. sub error {
  124.     $error = $_[0];
  125.     &generic;
  126.     exit 0;
  127. }
  128.  
  129. sub generic {
  130.     print "Content-type: text/html\n\n";
  131.     print "<html><head><title>Security Setup </title>\n";
  132.     print "<script language=\"JavaScript\">\n<!--\n";
  133.  
  134.     # JavaScript
  135. print "function Next()  {
  136.     form = document.page1;
  137.     setTimeout('form.submit()',0);
  138.     return;
  139. }
  140. function errorBox (Ctrl, ErrorMessage) {
  141.     alert (ErrorMessage);  Ctrl.focus();  return;
  142. }\n";
  143.  
  144.     print "//-->\n";
  145.     print "</script></head>\n\n";
  146.  
  147.     print "<body bgcolor=\'a7b4ce\' background=/tasks/security-task.bg.gif>\n";
  148.     if ($error) {
  149.         print "<font size=4 color=ff0000><b>Error: </b>$error<br></font>";
  150.     }
  151.     print "<i>$message</i>";
  152.  
  153.     print "<table width=100%>",
  154.           "<tr><th align=left><h1>Security Setup for Services</h1></th>\n",
  155.           "<th align=right><a href=\"/newsplash.shtml\">",
  156.           "<img height=55 width=57 border=0 src=/tasks/home.gif></a>\n",
  157.           "  <a href=\"Tasks.shtml\">",
  158.           "<img height=55 width=57 border=0 src=/tasks/back.gif></a>",
  159.           "</tr></table>\n";
  160.  
  161.     printf("\n<form name=\"page1\" action=\"%s\" method=post>\n", $action);
  162.     
  163.     print "<center><table width=620>\n";
  164.  
  165.     print "<tr><td colspan=2 align=left>
  166.     Network services started out of inetd are known to pose security risks.
  167.     This page allows you the opportunity of disabling these services.  
  168.     Services disabled include rpc services such as NIS and NFS, 
  169.     internal services such as time, daytime and echo, as well as others.
  170.     For a complete list, see the configuration file \"<i>/etc/inetd.conf</i>\".
  171.     Five important services are singled out, and may separately be left enabled.
  172.     <br><br></td></tr></table>\n\n";
  173.  
  174.     print "<table width=520>\n";
  175.  
  176.     print "<tr><td colspan=2><input type=checkbox name=all_inetd value=1 $chall> ",
  177.           "  <strong>Disable network services started out of inetd</strong><br></td>",
  178.           "</tr><tr><td><br><br></td></tr></table>\n\n";
  179.  
  180.     print "<table width=620>\n";
  181.     print "<tr><td colspan=2>Keep enabled the following services:</td></tr>";
  182.     print "</table><table width=520>\n";
  183.  
  184.     print "<tr><td><input type=checkbox name=ftp value=1 $chftp> "
  185.         ."ftp (File Transfer Protocol.)</td></tr>";
  186.  
  187.     print "<tr><td><input type=checkbox name=telnet value=1 $chtelnet> telnet"
  188.         ." (Internet standard for remote login.)</td></tr>\n";
  189.  
  190.     print "<tr><td><input type=checkbox name=shell value=1 $chshell> shell"
  191.         ." (remote execution of shell commands.)</td></tr>\n";
  192.  
  193.     print "<tr><td><input type=checkbox name=login value=1 $chlogin> "
  194.         ."login (UNIX standard for remote login.)</td></tr>\n";
  195.  
  196.     print "<tr><td><input type=checkbox name=finger value=1 $chfinger> "
  197.         ."finger (remote query of user account information.)</td></tr>\n";
  198.  
  199.     print "</table></center>\n\n";
  200.  
  201.     print '<MAP NAME="js_map">',
  202.     '<AREA SHAPE="rect" COORDS="0,0,59,52" HREF="javascript:Next()">',
  203.     '</MAP>';
  204.     print "\n";
  205.     print '<IMG SRC="/tasks/rightarrow.gif" BORDER=0 USEMAP="#js_map" align="right">';
  206.  
  207.     print "\n</form></body></html>";
  208. }
  209.  
  210. sub setBoxes {
  211.     $chall = $vals{'all_inetd'} ? "checked" : "";
  212.     $chtelnet = $vals{'telnet'} ? "checked" : "";
  213.     $chlogin = $vals{'login'} ? "checked" : "";
  214.     $chshell = $vals{'shell'} ? "checked" : "";
  215.     $chftp = $vals{'ftp'} ? "checked" : "";
  216.     $chfinger = $vals{'finger'} ? "checked" : "";
  217. }
  218.