home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2003 March / DPPCPRO0303.ISO / Netfusion / data1.cab / Components / FormHandlerComp / Forms / cgi-bin-Unix / Forms-Handler.cgi
Encoding:
Text File  |  1998-12-10  |  4.7 KB  |  162 lines

  1.  
  2. #The database separator token is -- 
  3.  
  4. $TOKEN ="    ";
  5. ###################
  6. ###################
  7. ###################
  8.  
  9. #This will allow error to pump directly to to client, instead of crashing the server.
  10. select STDOUT;
  11. print "Content-type: text/html\n\n";
  12.  
  13.  
  14. #
  15. # This reads in the information sent when the user pressed Submit
  16. #
  17. if ($ENV{'REQUEST_METHOD'} eq "GET") { $buffer = $ENV{'QUERY_STRING'}; }
  18. else { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); }
  19.  
  20. #
  21. # Now, using a little loop, we'll split up the data into name/value
  22. # pairs, which makes them easier to work with. 
  23. #
  24. $buffer =~ s/([;<>\*\|`&\$!\#\(\)\[\]\{\}:'"])/\\$1/g; 
  25. $buffer =~ tr/\n//d; 
  26. $buffer = "$buffer ";
  27.  
  28. @pairs = split(/&/, $buffer);
  29. foreach $pair (@pairs)
  30. {
  31.     ($name, $value) = split(/=/, $pair);
  32.     $value =~ tr/+/ /;
  33.     $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  34.     chop($value);
  35.     if ($FORM{$name} eq '') {$FORM{$name} = $value;}
  36.         else {$FORM{$name} = "$FORM{$name} $value";}
  37. }
  38.  
  39.  
  40. # Once the name/value pairs have been created, you can work with
  41. # them by referring to the variable names you set up in the 
  42. # original HTML, using $FORM{"varname"}.
  43.  
  44. # First, we make sure that they actually gave an email address
  45. #
  46. #check for error -- REQUIRE on selective basis $FORM{'na'}
  47.  
  48. ¬completeinternal unless $FORM{'fields'} && $FORM{'filename'} && $FORM{'error'} && $FORM{'success'};
  49.  
  50. $STORAGEFILE = $FORM{'filename'};
  51. $NUMBERARG = $FORM{'fields'};
  52.  
  53. $COUNTER = 1;
  54.  
  55.  
  56. #### Auto #####
  57. $ERRORRESPONSE=$FORM{'error'};
  58. $SUCCESSRESPONSE=$FORM{'success'};
  59. $STORAGE = $STORAGEDIR.$STORAGEFILE;
  60. $ENV{'HTTP_REFERER'} =~ s/\/[^\/]*$/\//g; 
  61.  
  62. while($COUNTER <= $NUMBERARG){ 
  63.    $CONFIG = $COUNTER.a;
  64.    ¬complete if (($FORM{$COUNTER} eq '') && ($FORM{$CONFIG} eq "TRUE"));
  65.    $COUNTER = $COUNTER + 1;
  66. }
  67.  
  68. &makedat;
  69. &success;
  70. exit;
  71.  
  72.  
  73. ######################################################################
  74. ############################  Make .dat file    ######################
  75. ######################################################################
  76. sub makedat {
  77.     open(NEW,">> $STORAGE") || &permissionfail;
  78.     select(NEW);
  79.     $COUNTER = 1;
  80.     $DATA = $FORM{$COUNTER};
  81.     $DATA =~ s/\r\n/" "/eg;
  82.     print NEW "$DATA";
  83.     $COUNTER = 2;
  84.     while($COUNTER <= $NUMBERARG){
  85.       $DATA = $FORM{$COUNTER};
  86.       $DATA =~ s/\r\n/" "/eg;
  87.         print NEW "$TOKEN$DATA";
  88.         $COUNTER = $COUNTER + 1;
  89.     }
  90.     print NEW "\n";
  91.     close(NEW);
  92. }
  93. ###############################################################################
  94. ############################  Complete/Success  ###############################
  95. ###############################################################################
  96. sub success{
  97.     select(STDOUT);
  98.     print "<html>";
  99.     print "<head>";
  100.     print "<meta http-equiv=\"Refresh\" content=\"0; URL=$SUCCESSRESPONSE\">";
  101.     print "</head>";
  102.     print "</html>";
  103.  
  104. }
  105.  
  106. ###############################################################################
  107. ############################  Incomplete Error  ###############################
  108. ###############################################################################
  109. sub notcomplete {
  110.    select(STDOUT);
  111.    print "<html>";
  112.    print "<head>";
  113.    print "<meta http-equiv=\"Refresh\" content=\"0; URL=$ERRORRESPONSE\">";
  114.    print "</head>";
  115.    print "</html>";
  116.     exit;
  117.  
  118. ###############################################################################
  119. ############################  Incomplete Error  ###############################
  120. ###############################################################################
  121. sub notcompleteinternal {
  122.     select(STDOUT);
  123.     print "<html>";
  124.     print "<h3>This is a internal error (without configuration variable)</h3>";
  125.     print "the following variable are escape out for perl script protection:";
  126.     print "<UL>";
  127.     print "\;<>\*\|\`\&\$\!\#()[]{}\:\'\"\/ (return character deleted)<br>";
  128.     print "</UL>";
  129.     print "or one of the following file is not declare in the field:";
  130.     print "<UL>";
  131.     print "filename (date file name)<br>";
  132.     print "fields (# of field)<br>";
  133.     print "success(success respond file) <br> "; 
  134.     print "error(error respond file) <br>";
  135.     print "</UL>";
  136.     print "</html>";
  137.     exit;
  138.  
  139. sub permissionfail {
  140.     select(STDOUT);
  141.     print "<html>";
  142.     print "<h3>Error writing to data file.</h3>";
  143.     print "There was an error trying to access the data file.<br>";
  144.     print "This CGI may not have permission to write to this file.<br>";
  145.     print "Please contact the system administrator.<br>";
  146.     print "The data entered in the form was not recorded due to this problem.<br>";
  147.     print "</html>";
  148.     exit;
  149. }
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.