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.dhcp-start.cgi.z / Tasks.dhcp-start.cgi
Encoding:
Text File  |  1997-07-30  |  6.0 KB  |  205 lines

  1. #!/usr/bin/perl5
  2. #
  3. # Tasks.dhcp-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.dhcp-start.cgi,v 1.8 1997/04/17 23:44:51 shotes Exp $
  21.  
  22. require "/usr/OnRamp/lib/OnRamp.pm";
  23. require "/usr/OnRamp/lib/java.pm";
  24.  
  25. $myname = "Tasks.dhcp-start.cgi";
  26. $def_config_dir = "/var/dhcp/config";
  27. $temp = "task.tmp";
  28. $data = "task.dummy";
  29. $action = "Tasks.dhcp-start.cgi?loop";
  30.  
  31. $it = "<td align=right>";
  32. $ni = "</td>";
  33. $bo = "<td><font size=5><i>";
  34. $nb = "</i></font></td>";
  35.  
  36. @find_vals = ('status','leases');
  37.  
  38. &get_fields;
  39. &getLeases;
  40.  
  41. # clear temporary file for initial call
  42. if (!$ARGV[0]) {
  43.     open(OUT,"> $temp");
  44.     close(OUT);
  45.  
  46. } elsif ($ARGV[0] eq 'loop') { %vals = %fld;  }
  47. else { &readValues; }
  48.  
  49. if ($ARGV[0] eq loop) {
  50.     &errorCheck;
  51.     &writeFile;
  52.  
  53.     $go = "/tasks/dhcp-end.cgi?st";
  54.     # printf("Location: %s%c%c",$go,10,10);
  55.     print "Content-type: text/html\n\n";
  56.     print "<HTML><HEAD>";
  57.     print "<META HTTP-EQUIV=\"refresh\" CONTENT=\"0; URL=$go\">";
  58.     print "</HEAD><BODY></BODY></HTML>";
  59.     exit 0;
  60. }
  61.  
  62. &generic;
  63.  
  64. sub readValues {
  65.     open(IN,"< $temp");
  66.     while(<IN>) {
  67.         @items = split(/=/);
  68.         foreach $arg (@find_vals) {
  69.             if ($arg eq $items[0]) {
  70.                 if ($items[1] ne "\n") {
  71.                     $vals{$arg} = $items[1];
  72.                     chop $vals{$arg};
  73.                 }
  74.             }
  75.         }
  76.     }
  77.     close(IN);
  78. }
  79.  
  80. sub errorCheck {
  81. }
  82.  
  83. sub error {
  84.     $error = $_[0];
  85.     &generic;
  86.     exit 0;
  87. }
  88.  
  89. sub writeFile {
  90.     undef %terms;
  91.     open(IN,"< $temp");
  92.     while(<IN>) {
  93.         @items = split(/=/);
  94.         chop $items[1];
  95.         $terms{$items[0]} = $items[1];
  96.     }
  97.     close(IN);
  98.     foreach $arg (@find_vals) {
  99.     $fld{$arg} =~ s/\r\n/&&/g;
  100.         $terms{$arg} = $fld{$arg};
  101.     }
  102.     open(OUT,"> $temp");
  103.     foreach $arg (keys(%terms)) {
  104.         print OUT "$arg=$terms{$arg}\n";
  105.     }
  106.     close(OUT);
  107. }
  108.  
  109. sub getLeases {
  110.     undef @lst;
  111.     opendir(CONFIG, $def_config_dir) ||
  112.         &error("Unable to open directory $def_config_dir");
  113.     while ($name = readdir(CONFIG) ) {
  114.         if ($name =~ /^config\./) {
  115.             $ipa = $name;
  116.             $ipa =~ s/^config\.//;
  117.             if ($ipa ne "Default") { push(@lst,$ipa); }
  118.         }
  119.     }
  120.     closedir(CONFIG);
  121. }
  122.  
  123. sub generic {
  124.     print "Content-type: text/html\n\n";
  125.     print "<html><head><title>DHCP Setup</title>\n";
  126.     print "<script language=\"JavaScript\">\n<!--\n";
  127.  
  128.     # JavaScript
  129. print "
  130. $js_error_box
  131. $js_ip
  132. $js_iplist
  133. function Next()  {
  134.     form = document.page1;
  135.     if (!testIPList(form.leases, \"lease address\")) return;
  136.     setTimeout('form.submit()',0);
  137.     return;
  138. }\n";
  139.  
  140.     print "//-->\n";
  141.     print "</script></head>\n\n";
  142.  
  143.     print "<body bgcolor=\'ddc4b2\' background=/tasks/dhcp-task.bg.gif>\n";
  144.     if ($error) {
  145.         print "<font size=4 color=ff0000><b>Error: </b>$error<br></font>";
  146.     }
  147.     print "<i>$message</i>";
  148.  
  149.     print "<table width=100%>",
  150.           "<tr><th align=left><h1>DHCP Setup</h1></th>\n",
  151.           "<th align=right><a href=\"/newsplash.shtml\">",
  152.           "<img height=55 width=57 border=0 src=/tasks/home.gif></a>\n",
  153.           "  <a href=\"Tasks.shtml\">",
  154.           "<img height=55 width=57 border=0 src=/tasks/back.gif></a>",
  155.           "</tr></table>\n";
  156.  
  157.     printf("\n<form name=\"page1\" action=\"%s\" method=post>\n", $action);
  158.    
  159.     print "<center><table width=620>\n";
  160.  
  161.     print "    <tr><td colspan=2>
  162.     Dynamic Host Configuration Protocol (DHCP) automatically configures
  163.     new hosts for membership in a network. When DHCP is enabled, new hosts
  164.     request network configuration information from the DHCP server as soon
  165.     as they are connected to the network. The server responds by sending a
  166.     hostname and an IP address, which is based on the address of the network
  167.     where the new host is connecting. Because the name and address may be 
  168.     surrendered or allowed to expire, it is considered a lease.
  169.     <br><br></td></tr>\n";
  170.  
  171.     print "<tr>$bo Enable the DHCP server: $nb\n$it", 
  172.           "<font size=5>", &radio("status","Yes","Yes","No"), "</font>",
  173.           "$ni </tr>\n";
  174.     print "    <tr><td colspan=2>
  175.     If you select <I>Yes</I>, the Internet Gateway will act as a DHCP
  176.     server, automatically supplying network configuration information 
  177.     to new hosts connecting to the network. If you select <I>No</I>, 
  178.     you will need to assign new hosts a name and address by some other 
  179.     method, such as the DHCP pages that are available in the Internet 
  180.     Gateway Administration tools or (for IRIX workstations) the Network 
  181.     Setup tools that are part of the IRIX Desktop toolchest. 
  182.     <br><br></td></tr>\n";
  183.  
  184.     print "<tr>$bo Subnets for this DHCP server: $nb\n$it",
  185.       "<font size=5><textarea name='leases' rows=5 cols=15>";
  186.     foreach (@lst) {
  187.     print "$_\r\n";
  188.     }
  189.     print "</textarea>$ni </tr>\n";
  190.     print "<tr><td colspan=2>Add, edit or delete addresses of the networks
  191.     where the DHCP server will supply name and address information to 
  192.     new hosts.<br><br></td></tr>\n"; 
  193.     print "</td></tr><tr><td> </td></tr>\n\n";
  194.  
  195.     print "</table></center>\n";
  196.  
  197.     print '<MAP NAME="js_map">',
  198.     '<AREA SHAPE="rect" COORDS="0,0,59,52" HREF="javascript:Next()">',
  199.     '</MAP>';
  200.     print "\n";
  201.     print '<IMG SRC="/tasks/rightarrow.gif" BORDER=0 USEMAP="#js_map" align="right">';
  202.  
  203.     print "\n</form></body></html>";
  204. }
  205.