#!/usr/mesh/bin/perl # # program name : addmsg.cgi(Add Message to $title_html and $message_html) # # function : Show input data to user and reconfirm to submit the message. # # programmer : makoto takenaka (takesoft@mxs.meshnet.or.jp) # # copyright : (c) 1996, 1997 by Takesoft # # version(date) : # 1.0 (Dec 7, 1996) # 1.1 (Jan 13, 1997) Change layout. # 1.2 (Jan 23, 1997) Change $msg_url to $full_msg_url and # use $title_url and $msg_url for mutual link # at title string. # 1.3 (Feb 15, 1997) Change to "$year += 1900;", this works well until # 2038/01/19. # 1.4 (June 28,1997) Insert unless statement at the end of (3). # 1.5 (July 5,1997) Change &message to $message in the unless # statement at the end of (3). # 1.6 (Nov 23, 1998) Insert header print line in sub error_message. # #(1) Prepare jcode.pl. # require 'jcode.pl'; # #(2) Prepare constants, date and files. # #(2.1) Set constants. # # For $t_order and $m_order, "comment_link" or "new_first" or "new_last" # is available. # $limit_tfile = 60000; # limit of title file(byte) $limit_mfile = 60000; # limit of message file(byte) $t_order = "comment_link"; # order of titles $m_order = "comment_link"; # order of messages $web_code = "euc"; # "euc", "sjis" or "jis" $san = 'san'; # san in $web_code $nrank = 10; # number of ranks in comments $base_dir = "./"; # base directory of CLWB $base_url = "./"; # url of CLWB $m_count_file = "${base_dir}m_count.txt"; # message counter file $title_f = "title001.html"; # current title file name $title_html = "${base_dir}$title_f"; # message title file $titlewk_html = "${base_dir}titlewk.html"; # message title work file $title_url = $base_url.$title_f; # url of title page $msg_f = "msg001.html"; # message file name(last name) $msg_html = "${base_dir}$msg_f"; # message file name $msg_url = $base_url.$msg_f; # url of message page # full url of current message file $full_msg_url = "http://www2a.meshnet.or.jp/~user-id/clwb/$msg_f"; $msgwk_html = "${base_dir}msgwk.html"; # message work file $commsg_cgi = "./commsg.cgi"; # url of commsg.cgi # #(2.2) Get date and time. # ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); $year += 1900; # Add 1900, which is valid until 2038/01/19. $mon++; $thisday = (Sun,Mon,Tue,Wed,Thu,Fri,Sat)[$wday]; if ($sec < 10) {$sec = "0$sec";} if ($min < 10) {$min = "0$min";} if ($hour < 10) {$hour = "0$hour";} if ($mday < 10) {$mday = "0$mday";} if ($mon < 10) {$mon = "0$mon";} # $date = "$year/$mon/$mday $thisday $hour:$min:$sec"; # #(2.3) Check file sizes. # if(-e $title_html) { $title_html_byte = (-s $title_html); # Get size of title file. if($title_html_byte > $limit_tfile) {&error_message("(2.3): Title file is greater than $limit_tfile (bytes).");} } else {&error_message("(2.3): File $title_html is not found.");} # if(-e $msg_html) { $msg_html_byte = (-s $msg_html); # Get size of message file. if($msg_html_byte > $limit_mfile) {&error_message("(2.3): Message file is greater than $limit_mfile (bytes).");} } else {&error_message("(2.3): File $msg_html is not found.");} # #(3) get parameters from sent data. # if ($ENV{'REQUEST_METHOD'} eq "POST") { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); } else { $buffer = $ENV{'QUERY_STRING'}; } # @pairs = split(/&/, $buffer); # foreach $pair (@pairs) { ($pname, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([0-9a-fA-F][0-9a-fA-F])/pack("C", hex($1))/eg; $icode = &jcode'convert(*value, $web_code); # Convert to one code $value =~ s/&/&/go; # Change & to & $value =~ s/\x22/"/g; # Change " to " $value =~ s//>/g; # Change > to > $value =~ s/\x0D\x0A/\x0A/g; # Change CR LF to LF $value =~ s/\x0D/\x0A/g; # Change CR to LF $parameters{$pname} = $value; } # $owner_mode = $parameters{'owner_mode'}; $to = $parameters{'to'}; $name = $parameters{'name'}; $url = $parameters{'url'}; $mail = $parameters{'mail'}; $title = $parameters{'title'}; $message = $parameters{'message'}; $new_message = 0; unless($to) {$new_message = 1;} if($to eq '0'){$new_message = 1;} if($new_message){$to = '0';} unless($icode){$icode = 'undef';} unless($title) {$title = 'No Title';} if($owner_mode){$san2 = "";} else {$san2 = $san;} unless($name && $message){exit 1;} # #(4) Set message number. # open(COUNTFILE, "$m_count_file") || &error_message("(4.1):Unable to open $m_count_file"); $m_count = ; $m_count = $m_count + 1; close(COUNTFILE); # #(5) Add comment title to $title_html. # #(5.1) Open $title_html file. # open(TITLE_FILE, "+<$title_html") || &error_message("(5.1):Unable to open $title_html"); flock(TITLE_FILE, 2); open(TITLEWK_FILE, "+<$titlewk_html") || &error_message("(5.1):Unable to open $titlewk_html"); flock(TITLEWK_FILE, 2); # #(5.2) Search end of target message title range and write comment # message title. # $notwritten = 1; $tnew_message = $new_message; if($t_order eq 'new_last'){$tnew_message = $new_message + 1;} if($t_order eq 'new_first'){$tnew_first = 1;} else {$tnew_first = 0;} # while() { if((($notwritten > 0) && /\\n"; print TITLEWK_FILE ''; print TITLEWK_FILE "$m_count"; $colspan = $nrank - $rankc + 1; print TITLEWK_FILE "$name $date $title\n"; print TITLEWK_FILE "\n"; $notwritten = 0; next if $tnew_first; } elsif((($tnew_message == 0) && ($notwritten > 0)) && /\\n"; print TITLEWK_FILE ''; for($irank = 1; $irank <= $nrank; $irank++) { $pitem = $items[$irank - 1];#item of same rank in privious line $pitem =~ s///; if($irank < $rankc - 2) { print TITLEWK_FILE $pitem.''; } elsif($irank == $rankc - 2) { if($pitem eq '*' || $pitem eq '|') {print TITLEWK_FILE '|';} else {print TITLEWK_FILE '
';} } elsif($irank == $rankc - 1) { if($rank == $nrank) { if($pitem eq '*' || $pitem eq '|') {print TITLEWK_FILE '|';} else {print TITLEWK_FILE '
';} } else {print TITLEWK_FILE '+';} } elsif($irank == $rankc) { print TITLEWK_FILE "$m_count"; last; } } $colspan = $nrank - $rankc + 1; print TITLEWK_FILE "$name $date $title\n"; print TITLEWK_FILE "\n"; $notwritten = 0; } print TITLEWK_FILE $_; } truncate(TITLEWK_FILE, tell(TITLEWK_FILE)); # #(5.3) Reset file pointer and copy TITLEWK_FILE to LDC1. # seek(TITLE_FILE, 0, 0); seek(TITLEWK_FILE, 0, 0); # while() {print TITLE_FILE $_;} # flock(TITLEWK_FILE, 8); close(TITLEWK_FILE); flock(TITLE_FILE, 8); close(TITLE_FILE); # #(6) Add comment to $msg_html. # #(6.1) Open $msg_html file. # open(MSG_FILE, "+<$msg_html") || &error_message("(6.1):Unable to open $msg_html"); flock(MSG_FILE, 2); open(MSGWK_FILE, "+<$msgwk_html") || &error_message("(6.1):Unable to open $msgwk_html"); flock(MSGWK_FILE, 2); # #(6.2) Search end of target message range and write comment # message. # $notwritten = 1; $mnew_message = $new_message; if($m_order eq 'new_last'){$mnew_message = $new_message + 1;} if($m_order eq 'new_first'){$mnew_first = 1;} else {$mnew_first = 0;} # while() { if($notwritten == 0) {;} # Do nothing. elsif(((($mnew_message == 0) && /\\n"; # print MSGWK_FILE "[$m_count]"; if(($url) && ($url ne "http://")) {print MSGWK_FILE "$name $san2";} else {print MSGWK_FILE "$name $san2";} if($mail) { print MSGWK_FILE "($mail) $date "; } else { print MSGWK_FILE " $date "; } if($to > 0){print MSGWK_FILE "(TO #$to) ";} print MSGWK_FILE "$title\n"; # print MSGWK_FILE < $message
EOF # print MSGWK_FILE "\n"; $notwritten = 0; next if $mnew_first; } print MSGWK_FILE $_; } truncate(MSGWK_FILE, tell(MSGWK_FILE)); # #(6.3) Reset file pointer and copy MSGWK_FILE to LDC1. # seek(MSG_FILE, 0, 0); seek(MSGWK_FILE, 0, 0); # while() {print MSG_FILE $_;} # flock(MSGWK_FILE, 8); close(MSGWK_FILE); flock(MSG_FILE, 8); close(MSG_FILE); # #(7) Incremet $m_count on $m_count_file. # No increment for error between (5)-(6) # Increment to written $m_count because another process may # increment $m_count during (5)-(6). # open(COUNTFILE, "+< $m_count_file") || &error_message("(9):Unable to open $m_count_file"); flock(COUNTFILE, 2); $m_count = ; $m_count = $m_count + 1; seek(COUNTFILE, 0, 0); print COUNTFILE $m_count; flock(COUNTFILE, 8); close(COUNTFILE); # #(8) Show added message. # print "Pragma: no-cache\n"; print "Location: ${full_msg_url}#$m_count\n\n"; # exit 0; # sub error_message { local($message) = @_; print "Content-type: text/html\n\n"; print "Error Message from addmsg.cgi of Web page: \n"; print "$message\n"; exit 1; }