home *** CD-ROM | disk | FTP | other *** search
/ Internet 1996 World Exposition / park.org.s3.amazonaws.com.7z / park.org.s3.amazonaws.com / cgi-bin / Japan / KDD / guestbook.pl < prev    next >
Perl Script  |  2017-09-21  |  5KB  |  178 lines

  1. #!/usr/local/bin/perl
  2.  
  3. # posts guest comment to web page
  4.  
  5. require 'cgi-lib.pl';
  6. # require 'jcode.pl';
  7.  
  8. # grab values passed from form:
  9. &ReadParse(*in);
  10.  
  11. print "Content-type: text/html\n";
  12. print "Pragma: no-cache\n\n";
  13.  
  14. # print the top part of the response
  15. print "<HTML><HEAD>\n";
  16. print "<TITLE>Post Results</TITLE>\n";
  17. print "</HEAD><BODY>\n";
  18.  
  19. # resolve return directory
  20. $year_day = (localtime)[7];    # days of year
  21. $first_day = 94;        # first day of seimei (April 4)
  22. $moon_day = $year_day - $first_day + 1;    # day of sekki
  23. @sekki = ('seimei','koku-u','rikka','shouman','boushu','geshi','shousho',
  24.       'taisho','risshu','shosho','hakuro','shubun','kanro','soukou',
  25.       'rittou','shousetsu','taisetsu','touji');
  26. @dsekki = (16,15,16,15,16,16,15,16,16,15,16,15,15,15,15,15,14,10);
  27. $csekki = 0;            # sekki counter
  28. $cmoon_day = $moon_day;        # moon day counter
  29. while ($cmoon_day > 0) {
  30.     $cmoon_day = $cmoon_day - $dsekki[$csekki];
  31.     $csekki = $csekki + 1;
  32. }
  33. $ddir = $sekki[$csekki - 1];
  34. $month_html = join('',"SEKKI/",$ddir,"/renga_home.html");
  35.  
  36. # change to your favorite date format:
  37. $date = `date`;
  38. chop($date); # remove "\n"
  39.  
  40. # Grab the HTML file and make a file name for the temp file.
  41. $file = "$ENV{'PATH_TRANSLATED'}browse_renga.html";
  42. $tmp = "$ENV{'PATH_TRANSLATED'}browse_renga.html.tmp";
  43. $tmp =~ s/\//@/g; # make a unique tmp file name from the path
  44. $tmp = "/tmp/$tmp";
  45. $file2 ="$ENV{'PATH_TRANSLATED'}browse_renga2.html"; 
  46. $tmp2 = "$ENV{'PATH_TRANSLATED'}browse_renga2.html.tmp";
  47. $tmp2 =~ s/\//@/g; # make a unique tmp2 file name from the path
  48. $tmp2 = "/tmp/$tmp2";
  49.  
  50. # if any fields are blank, then skip the post and inform user:
  51. if ( !$in{'name'} || !$in{'email'} || !$in{'renga'} ) {
  52.   &err("╢τñ╚ñ¬╠╛┴░ñ╚E-mailÑóÑ╔Ñ∞Ñ╣ñ╦ñ┤╡¡╞■╧│ñ∞ñ¼ñóñΩñ▐ñ╣ñ╚┼╨╧┐ñ╟ñ¡ñ▐ñ╗ñ≤íú<BR>ñΓñª░∞┼┘ñ¬│╬ñ½ñßñ╬╛σíóñ┤┼╨╧┐ñ»ñ└ñ╡ññíú");
  53. }
  54.  
  55. # get an exclusive open on the tmp file, so
  56. # two posts at the same time don't clobber each other.
  57. for ($count = 0; -f "$tmp"; $count++) {
  58. # oh no. someone else is trying to update the message file.  so we wait.
  59.   sleep(1);
  60.   &err("┬╛ñ╬┐═ñ¼╜±ñ¡╣■ñ▀├µñ╟ñ╣íúñ╖ñ╨ñΘñ»ñ¬┬╘ñ┴▓╝ñ╡ññíú(1)") if ($count > 4);  # but not for long
  61. }
  62. # open temp file
  63. open(TMP,">$tmp") || &err("║ε╢╚Ñ╒ÑíÑñÑδñ¼│½ñ▒ñ▐ñ╗ñ≤íú(1)");
  64. # open the HTML file
  65. open(FILE,"<$file") || &err("$fileñ¼│½ñ▒ñ▐ñ╗ñ≤íú(1)");
  66. # an HTMLBBS file.  look through it for the HTML comments
  67. # that denote stuff we want to change:
  68.  
  69. $guestbook = 0;
  70. while(<FILE>) {
  71.   if (/<!--GUESTBOOK-->/) {
  72.     print TMP "<!--GUESTBOOK-->\n";
  73.     $guestbook = 1;
  74.   }
  75.   elsif (/<!--POINTER-->/) {
  76.     # add this post
  77.     print TMP "<HR>\n";
  78.     print TMP "<P>\n";
  79.     print TMP "$in{'renga'}<BR>\n";
  80.     if ($in{'disp'} =~ /on/ ) {
  81.       print TMP "í╩$in{'name'}íí$in{'email'}í╦\n";    #email display : on
  82.     }
  83.     else {
  84.       print TMP "í╩$in{'name'}í╦\n";    #email display : off
  85.     }
  86.     print TMP "</P>\n";
  87.     print TMP "<!--POINTER-->\n";
  88.   }
  89.   else { print TMP $_; }  # copy lines
  90. }
  91. if ($guestbook == 0) {
  92. ## print "$guestbook\n";
  93.   &err("╧ó▓╬Ñ╬í╝Ñ╚ñ╟ñ╧ñóñΩñ▐ñ╗ñ≤íú(1)"); 
  94.  
  95. # move the new file over the old:
  96. open(TMP,"<$tmp") || &err("║ε╢╚Ñ╒ÑíÑñÑδñ¼│½ñ▒ñ▐ñ╗ñ≤íú(1)");
  97. # open the HTML file
  98. open(FILE,">$file") || &err("$fileñ¼│½ñ▒ñ▐ñ╗ñ≤íú(1)");
  99. while(<TMP>) {
  100.   print FILE $_;
  101. }
  102. close(FILE);
  103. close(TMP);
  104.  
  105. # get an exclusive open on the tmp file, so
  106. # two posts at the same time don't clobber each other.
  107. for($count = 0; -f "$tmp2"; $count++) {
  108. # oh no. someone else is trying to update the message file.  so we wait.
  109.   sleep(1);
  110.   &err("┬╛ñ╬┐═ñ¼╜±ñ¡╣■ñ▀├µñ╟ñ╣íúñ╖ñ╨ñΘñ»ñ¬┬╘ñ┴▓╝ñ╡ññíú(2)") if ($count > 4);  # but not for long
  111. }
  112. # open temp file
  113. open(TMP2,">$tmp2") || &err("║ε╢╚Ñ╒ÑíÑñÑδñ¼│½ñ▒ñ▐ñ╗ñ≤íú(2)");
  114. # open the HTML file
  115. open(FILE2,"<$file2") || &err("$file2ñ¼│½ñ▒ñ▐ñ╗ñ≤íú(2)");
  116. # an HTMLBBS file.  look through it for the HTML comments
  117. # that denote stuff we want to change:
  118.  
  119. $guestbook = 0;
  120. while(<FILE2>) {
  121.   if (/<!--LASTDATE-->/)  { print TMP2 "<!--LASTDATE--> $date \n"; }
  122.   elsif (/<!--GUESTBOOK-->/) {
  123.     print TMP2 "<!--GUESTBOOK-->\n";
  124.     $guestbook = 1;
  125.   }
  126.   elsif (/<!--POINTER-->/) {
  127.     # add this post
  128.     print TMP2 "<HR>\n";
  129.     print TMP2 "<P>\n";
  130.     print TMP2 "$in{'renga'}<BR>\n";
  131.     print TMP2 "í╩$in{'name'}íí$in{'email'}í╦<BR>\n";
  132.     print TMP2 "í╬$in{'comment'}í╧\n";
  133.     print TMP2 "</P>\n";
  134.     print TMP2 "<!--POINTER-->\n";
  135.   }
  136.   else { print TMP2 $_; }  # copy lines
  137. }
  138. if ($guestbook == 0) {
  139.   &err("╧ó▓╬Ñ╬í╝Ñ╚ñ╟ñ╧ñóñΩñ▐ñ╗ñ≤íú(2)");
  140.  
  141. # move the new file over the old:
  142. open(TMP2,"<$tmp2") || &err("║ε╢╚Ñ╒ÑíÑñÑδñ¼│½ñ▒ñ▐ñ╗ñ≤íú(2)");
  143. # open the HTML file
  144. open(FILE2,">$file2") || &err("$file2ñ¼│½ñ▒ñ▐ñ╗ñ≤íú(2)");
  145. while(<TMP2>) {
  146.   print FILE2 $_;
  147. }
  148. close(FILE2);
  149. close(TMP2);
  150.  
  151. unlink "$tmp";
  152. unlink "$tmp2";
  153.  
  154. # print the rest of the response HTML
  155. print "<P><H2>┼╨╧┐ñ╖ñ▐ñ╖ñ┐íú</H2></P>\n";
  156. print "<A HREF=\"$ENV{'PATH_INFO'}$month_html\" TARGET=\"_top\"><B>╔╜╝¿ñ╣ñδ</B></A>\n";
  157. print "<P><FONT size=-1>╔╜╝¿ñ╡ñ∞ñ╩ññ╛∞╣τñ╧íóNetscapeñ╬ReloadÑ▄Ñ┐Ñ≤ñ≥Ñ»ÑΩÑ├Ñ»ñ╖ñ╞▓╝ñ╡ññíú</FONT>\n";
  158. print "</BODY></HTML>\n";
  159. exit;
  160.  
  161. #
  162. # if we got an error, print message, close & clean up
  163. #
  164. sub err {
  165.   local($msg) = @_;
  166.   print "<P>$msg</P>\n";
  167.   close FILE;
  168.   close FILE2;
  169.   close TMP;
  170.   close TMP2;
  171.   unlink "$tmp";
  172.   unlink "$tmp2";
  173.   print "<A HREF=\"$ENV{'PATH_INFO'}reg_renga.html\"><B>╠ßñδ</B></A>\n";
  174.   print "</BODY></HTML>\n";
  175.   exit;
  176. }