home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / FAQ / cgi-bin / guest.pl < prev    next >
Perl Script  |  2009-11-06  |  13KB  |  405 lines

  1. #!/usr/bin/perl
  2. #  ^
  3. # / \
  4. #  |   Modify the line the arrow is pointing to, to the correct
  5. #  |   location of Perl v5 or better.
  6. #Uninet######################################################################
  7. #   w  w  w  .  u  n  i  n  e  t  s  o  l  u  t  i  o  n  s  .  c  o   m    #
  8. # UNINET PERL COMPANY(TM) PRESENTS                                          #
  9. # GuestCall 2000 SR1 (2.1.0)                                                #
  10. # Compact, Powerful, GuestCall.                                             #
  11. # ------------------------------------------------------------------------- #
  12. # (C)1997-2001 Universal Networks, All Rights Reserved.                     #
  13. #                                                                           #
  14. # This program is free software; you can redistribute it and/or             #
  15. # modify it under the terms of the GNU General Public License               #
  16. # as published by the Free Software Foundation; either version 2            #
  17. # of the License, or (at your option) any later version.                    #
  18. #                                                                           #
  19. # This program is distributed in the hope that it will be useful,           #
  20. # but WITHOUT ANY WARRANTY; without even the implied warranty of            #
  21. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             #
  22. # GNU General Public License for more details.                              # 
  23. #                                                                           #
  24. # You should have received a copy of the GNU General Public License         #
  25. # along with this program; if not, write to the                             #
  26. #                Free Software Foundation, Inc.                             #
  27. #                59 Temple Place - Suite 330                                #
  28. #                Boston, MA  02111-1307, USA.                               #
  29. #                                                                           #
  30. # -->A full copy of the GNU General Public License is included in LICENSE   #
  31. # ------------------------------------------------------------------------- #
  32. # Need Support? We offer FREE technical support!                            #
  33. # Email us at support@uninetsolutions.com for quick, free support today!    # 
  34. # ------------------------------------------------------------------------- #
  35. # Modification History:                                                     #
  36. # 1.0.0: 5/5/1997  GuestCall Released.                                      #
  37. #   SR1: 5/6/1997  HTML Creation Error Fixed.                               #
  38. #   SR2: 3/1/2000  Newly discovered Netscape incompatiblity fixed.          #
  39. # 2.0.0: 6/6/2000  Overhaul of most GuestCall functions - details in README #
  40. # 2.1.0: 4/21/2000 Fixed minor bug, added line length limiter.              #
  41. #######################################################################Uninet 
  42.  
  43. #Settings (see README for more information)
  44. #1. What is your site's name?
  45. $bookname = "RTSI Guestbook \(powered by GuestCall\)";
  46.  
  47. #2.What color background do you want?
  48. # NOTE: You can use English names
  49. # of colors or a color's HEX number.
  50. # EXAMPLE: To have a white background,
  51. # you can type "white" or "#FFFFFF."
  52. $color = "#FFFFFF";
  53.  
  54. #3. Where is the data file?
  55. $gdatl = "/home/ftp/OS9/FAQ/data/gbook.txt";
  56.  
  57. #4. Enter words you would like
  58. # filtered from you guest book
  59. # REMEMBER: it is case sensitive,
  60. # so word is different from Word
  61. # and WORD.
  62. @badwords = ("shit");
  63.  
  64. #5. You can enter a custom header
  65. # on the lines between the two
  66. # EOT's.
  67. $header = <<"EOT";
  68.  
  69. <i>Real-Time Services guestbook for people to post in!</i>
  70.  
  71.  
  72. EOT
  73.  
  74. #6. You can enter a custom footer
  75. # on the lines between the two
  76. # EOT's.
  77. $footer = <<"EOT";
  78.  
  79. <HR>
  80.  
  81.  
  82. EOT
  83.  
  84. #7. Password for clearing Guest-
  85. # Call messages.
  86. $password = "GC2k";
  87.  
  88. #8. Are you using Win32?
  89. $win32 = "0";
  90.  
  91. #9. How many postings should be
  92. # displayed on one page?
  93. $displaynum = "10";
  94.  
  95. #10. What should be the maximum
  96. # length that length of a line?
  97. # Anything over the number you
  98. # select will be wrapped to the
  99. # next line.
  100. $wrap = "70";
  101.  
  102.  
  103. ##################################
  104. #your done! your done! your done!#
  105. ##################################
  106.  
  107. $passok = "${password}ok";
  108. $displaynum--;
  109.  
  110. @months = ('Jan','Feb','Mar','Apr','May','June','July','Aug','Sept','Oct','Nov','Dec');
  111.  
  112. @days = ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
  113.  
  114. ($sec,$min,$hour,$mday,$mon,$year,$wday) = (localtime(time))[0,1,2,3,4,5,6];
  115.  
  116. $year += 1900;
  117.  
  118. if ($min < 10){
  119.    $min = "0$min";
  120. }
  121.  
  122.  
  123. if ($hour < 12){
  124.    
  125.    $ampm = "A.M.";
  126.    
  127. }
  128. else{
  129.  
  130.    $ampm = "P.M.";
  131.    
  132. }
  133.  
  134. if ($hour > 12) {
  135.    
  136.    $hour -= 12;
  137.    
  138. }
  139.  
  140. if ($hour < 1){
  141.  
  142.    $hour = 12;
  143.    
  144. }
  145.  
  146.  
  147.     
  148.  
  149. $date = "$days[$wday], $months[$mon] $mday, $year at $hour:$min $ampm";
  150.  
  151. open (data,"$gdatl");
  152.    @rawdat = <data>;
  153. close (data);
  154.  
  155. foreach $dat (@rawdat){
  156.    $dat =~ s/\r\n//g;
  157.    $dat =~ s/\r//g;
  158.    $dat =~ s/\n//g;     
  159.    $dat_wo_lf .= $dat;
  160. }
  161.    
  162. @gdat = split (/\&\t\&/, $dat_wo_lf);
  163.    
  164.  
  165. if (@gdat eq ""){
  166.  
  167.    $gdatnum = 0;
  168.    
  169. }
  170. else{
  171.  
  172.    $gdatnum = $#gdat + 1;
  173.  
  174. }
  175.  
  176. read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
  177.  
  178. @pairs = split(/&/, $buffer);
  179.  
  180. foreach $pair (@pairs){
  181.     ($name, $value) = split(/=/, $pair);
  182.     $value =~ tr/+/ /;
  183.     $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  184.     $value =~ s/~!/ ~!/g; 
  185.     $FORM{$name} = $value;
  186. }
  187.  
  188.  
  189. if ($FORM{'snd'} eq ""){
  190.  
  191.    if ($ENV{'QUERY_STRING'} eq "log") {
  192.       
  193.       #User wants to see logs.
  194.        
  195.       print ("Content-type: text/html\n\n");
  196.       print "<html><head><title>Log file</title></head><body bgcolor = '$color'>You currently have $gdatnum messages.<BR>";
  197.       print "<tr><table border=\"0\" width = \"100%\"><td>Message No.</td><td>User's Name</td><td>User's Client</td><td>Date written</td></tr>";
  198.       print "<tr><td colspan = 5><HR></td></tr>";
  199.       
  200.       for $i (0...$#gdat){
  201.          ($name, $email, $pdate, $comments, $useragent) = split (":\t:", $gdat[$i]);
  202.          $pnum = $i + 1;
  203.          print "<tr><td>$pnum</td><td>$name ($email)</td><td>$useragent</td><td>$pdate</td></tr>";
  204.       }
  205.       
  206.       print "</table><BR>(C)1997-2000 <a href=\"http://www.uninetsolutions.com/guest\">Universal Networks</a>. Processed on $date.</body></html>";
  207.  
  208.    }
  209.    elsif ($ENV{'QUERY_STRING'} eq $password){
  210.       print ("Content-type: text/html\n\n");
  211.       print "<html><head><title>Erase Messages?</title></head>";
  212.       print "<body bgcolor=\"#FFFFFF\"><h2>Erase Messages?</h2>";
  213.       print "Are you sure you want to erase all of your ";
  214.       print "GuestCall Messages?<HR><a href=\"$ENV{'SCRIPT_NAME'}\?$passok\">OK</a></body></html>";
  215.    }
  216.    elsif ($ENV{'QUERY_STRING'} eq $passok){
  217.       
  218.       open (mordat, ">$gdatl");
  219.       
  220.          unless ($win32){
  221.             flock mordat, 2;
  222.             flock mordat, 8;
  223.          }
  224.          
  225.       close(mordat);
  226.  
  227.       print ("Content-type: text/html\n\n");
  228.       print "<html><head><title>Messages Erased</title></head>";
  229.       print "<body bgcolor=\"#FFFFFF\"><h2>Messages Erased</h2>";
  230.       print "GuestCall has deleted all of the postings in your ";
  231.       print "guest book.</body></html>";
  232.  
  233.    }
  234.    else{
  235.  
  236.       #User wants to see guest book.
  237.  
  238.       for $i (0...$#gdat){
  239.          $gdat[$i] =~ s/\</\<\;/g;
  240.          $gdat[$i] =~ s/\>/\>\;/g;
  241.          $gdat[$i] =~ s/\:ctrln\:/\<BR\>/g;
  242.          (@pairs) = split (/ /, $gdat[$i]);
  243.          $number = 0;
  244.          foreach $pair (@pairs) {
  245.             @pairs2 = split(//, $pair);
  246.             if ($#pairs2 >= $wrap) {
  247.                $num = 0;
  248.                $num2 = 0;
  249.                foreach $num2 (0...$#pairs2){
  250.                   if ($num == $wrap) {
  251.                      $pairs2[$num2] .= " ";
  252.                      $num = "0";
  253.                   }
  254.                   else{
  255.                      $num++;
  256.                   }
  257.  
  258.                }
  259.             }
  260.             $entrydat ="";
  261.             foreach $pair2 (@pairs2){
  262.                $entrydat .= $pair2;
  263.             }
  264.             $pairs[$number] = "$entrydat ";
  265.             $number++;
  266.          }
  267.          $gdat[$i] = "@pairs";
  268.  
  269.          for $ii (0...$#badwords){
  270.             $gdat[$i] =~ s/$badwords[$ii]/\(censored\)/g;
  271.          }
  272.  
  273.       }
  274.    
  275.    
  276.       if ($FORM{'displaynum'}) {
  277.          $startnum = $FORM{'displaynum'};
  278.          $stopnum = $FORM{'displaynum'} + $displaynum;
  279.       }
  280.       else{
  281.          $FORM{'displaynum'} = 0;
  282.          $startnum = "0";
  283.          $stopnum = $displaynum;
  284.  
  285.          
  286.       }
  287.       
  288.       if ($displaynum < $#gdat) {
  289.          
  290.          $prenum = $startnum - ($displaynum + 1);
  291.          $nextnum = $stopnum + 1;
  292.          
  293.          if ($FORM{'displaynum'} > 0){
  294.             $previous="<center><form action=\"$ENV{'SCRIPT_NAME'}\" method=\"post\"><input type=\"hidden\" name=\"displaynum\" value=\"$prenum\"><input type=\"submit\" value=\"Next\"></form></center>";
  295.          }
  296.          
  297.          if (($FORM{'displaynum'} + 10) < $#gdat){
  298.             $next="<center><form action=\"$ENV{'SCRIPT_NAME'}\" method=\"post\"><input type=\"hidden\" name=\"displaynum\" value=\"$nextnum\"><input type=\"submit\" value=\"Previous\"></form></center>";
  299.          }  
  300.       
  301.       }
  302.       
  303.       for $i ($startnum...$stopnum){
  304.          $selectgdat[$i] = $gdat[$i];
  305.       }
  306.    
  307.       print ("Content-type: text/html\n\n");
  308.       print "<head><title>$bookname</title></head><body bgcolor = '$color'>$header";
  309.       print "${dataaaa}Currently there are $gdatnum postings in $bookname<BR><BR>$previous";
  310.       
  311.  
  312.      foreach $dat (@selectgdat) {
  313.          if ($dat){
  314.             ($name, $email, $pdate, $comments, $useragent) = split (":\t:", $dat);
  315.             print "<HR width=\"75%\"><b>On $pdate, <a href=\"mailto:$email\">$name</a> said:</b><BR>$comments<BR>";
  316.          }
  317.       }
  318.    
  319.       print "$next<BR><HR width=\"75%\"><FORM ACTION='$ENV{'SCRIPT_NAME'}' METHOD=POST>Your Name:<Input type = 'text' name = 'name' SIZE='45'><BR>Email Address:<Input type = 'text' name = 'email' SIZE='45'><BR>Comments:<BR> <TEXTAREA width = 100% height = 100% name='comment' wrap='soft' cols=60 rows=15></TEXTAREA> <Input type = 'Hidden' name = 'snd' value='2444211'><BR><center><input type='submit' name='submit' value='Submit'> <input type='reset'  name='reset'  value='Clear Form'></center><BR></form><BR>$footer<font size=\"1\">Powered by <a href = \"http://www.uninetsolutions.com/guest/\">GuestCall 2000 \(2.0.1\)</a>, (C) 1997-2001 Universal Networks.</font></body></html>";
  320.    }
  321. }
  322. else{
  323.  
  324.    #Add message.
  325.    $i = $i + 1;
  326.    open (mordat, "$gdatl");
  327.       @current_messages = <mordat>;
  328.    close(mordat);
  329.    
  330.    open (mordat, ">$gdatl");
  331.    
  332.       unless ($win32){
  333.          flock mordat, 2;
  334.       
  335.          #Check for change made during locking process.
  336.          seek mordat, 0, 2;
  337.       }
  338.         
  339.       $FORM{'comment'} =~ s/\r\n/\:ctrln\:/g;
  340.       $FORM{'comment'} =~ s/\r/\:ctrln\:/g;
  341.       $FORM{'comment'} =~ s/\n/\:ctrln\:/g;
  342.    
  343.       print mordat "$FORM{'name'}:\t:$FORM{'email'}:\t:$date:\t:$FORM{'comment'}:\t:$ENV{'useragent'}&\t&";
  344.       
  345.       if (@current_messages){
  346.          print mordat "\n@current_messages";
  347.       }
  348.       
  349.       unless ($win32){
  350.          flock mordat, 8;
  351.       }
  352.       
  353.    close(mordat);
  354.    
  355.    $form_filt[0] = $FORM{'name'};
  356.    $form_filt[1] = $FORM{'email'};
  357.    $form_filt[2] = $FORM{'comment'};
  358.  
  359.  
  360.       for $i (0...$#form_filt){
  361.          $form_filt[$i] =~ s/\</\<\;/g;
  362.          $form_filt[$i] =~ s/\>/\>\;/g;
  363.          $form_filt[$i] =~ s/\:ctrln\:/\<BR\>/g;
  364.          (@pairs) = split (/ /, $form_filt[$i]);
  365.          $number = 0;
  366.          foreach $pair (@pairs) {
  367.             @pairs2 = split(//, $pair);
  368.             if ($#pairs2 >= $wrap) {
  369.                $num = 0;
  370.                $num2 = 0;
  371.                foreach $num2 (0...$#pairs2){
  372.                   if ($num == $wrap) {
  373.                      $pairs2[$num2] .= " ";
  374.                      $num = "0";
  375.                   }
  376.                   else{
  377.                      $num++;
  378.                   }
  379.  
  380.                }
  381.             }
  382.             $entrydat ="";
  383.             foreach $pair2 (@pairs2){
  384.                $entrydat .= $pair2;
  385.             }
  386.             $pairs[$number] = "$entrydat ";
  387.             $number++;
  388.          }
  389.          $form_filt[$i] = "@pairs";
  390.  
  391.          for $ii (0...$#badwords){
  392.             $form_filt[$i] =~ s/$badwords[$ii]/\(censored\)/g;
  393.          }
  394.  
  395.       }
  396.  
  397.    $FORM{'name'} = $form_filt[0];
  398.    $FORM{'email'} = $form_filt[1];
  399.    $FORM{'comment'} = $form_filt[2];
  400.  
  401.    print ("Content-type: text/html\n\n");
  402.    print "<html><head><title>Message Posted to $bookname</title></head><body bgcolor = '$color'>$header<font size=\"4\">Message Posted</font><BR>Here is what you added:<BR><B>Name:</B>$FORM{'name'}<BR><B>Email Address:</B>$FORM{'email'}<BR><B>Comments:</B><BR>$FORM{'comment'}<BR><a href = \"$ENV{'HTTP_REFERER'}\">Back to $bookname</a><HR>Powered by <a href=\"http://www.uninetsolutions.com/guest\">Universal Networks</a>.$footer</body></html>";
  403. }
  404.  
  405.