#! /usr/bin/perl # # joinlist.cgi # # Ver2.023 : 6/15/08 : 削除を修正 # Ver2.022 : 10/2/05 : Copyrightにリンクを追加 # Ver2.021 : 9/11/05 : jcode.plを削除、Copyrightを追加。 # Ver2.02 : 1/22/05 : 名前が記入されないと書き込まないように修正 # Ver2.01 : 3/24/03 : パスワード作成失敗処理を追加 # Ver2.0 : 10/27/02 # パスワード機能を追加 # rdjoin.plとwrjoin.plをjoinlist.cgiの一つに統合 # # $Id: joinlist.cgi,v 1.8 2008/06/14 18:23:20 Hideki Kanayama Exp $ # Copyright(c) 2002-2006, Hideki Kanayama, All rights reserved. $version='2.023'; $lastupdatedyear='2006'; $joindir = "../joinlist"; $cgibin = "../cgi-bin"; $datafile = "$joindir/joinlist.dat"; $eventhtml = "$joindir/event.shtml"; $admindat = "$cgibin/adminpwd.dat"; $thisfile = $0; $thisfile =~ s/^.+[\/\\]([^\\\/]+)$/$1/; $script = "$cgibin/$thisfile"; $tmpfile = "$joindir/tmp.$$"; $lang = 0; if ($ENV{"REQUEST_METHOD"} eq "GET"){ $data=$ENV{"QUERY_STRING"}; $method = 'GET'; } elsif ($ENV{"REQUEST_METHOD"} eq "POST"){ read(STDIN,$data,$ENV{"CONTENT_LENGTH"}); $method = 'POST' } @tmparry=split(/&/,$data); foreach $string (@tmparry){ ($key,$value)=split(/=/,$string); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ s//>/g; if ($value =~ /\r\n/) { $value =~ s/\r\n/
/g; } if ($value =~ /\n/) { $value =~ s/\n/
/g; } if ($value =~ /\r/) { $value =~ s/\r/
/g; } if ($value =~ /,/) { $value =~ s/,/&\#44;/g; } $all{"$key"}=$value; } if (! -e "$admindat"){ if ($all{mode} ne 'adminpwd'){ &setadminpwd; } else { &wradminpwd; print "Location: $eventhtml\n\n"; } } open(ADMIN,"< $admindat"); $adminpwd = ; close(ADMIN); if ($all{mode} eq 'write'){ if (open(DAT,"< $datafile")){ @allline=; close(DAT); ($finnum,@rest) = split(/,/,$allline[$#allline]); } else { $finnum = 0; } if ($all{reg} ne ''){ if ($all{name} ne ''){ open(WR,">> $datafile"); $num = $finnum + 1; if ($all{pwd} ne ''){ $pwd = &makecrypt($all{pwd}); } else { $pwd = ''; } print WR "$num,$all{name},,$all{comment},$pwd\n"; close(WR); } } else { open(DAT,"< $datafile"); open(WR,"> $tmpfile"); while(){ s/[\n\r]*$//; ($num,$name,$join,$comment,$pwd)=split(/,/); $cancel = cancel . $num; $pwdnum = pwd . $num; if($all{$cancel} ne ''){ if ((&checkcrypt($all{$pwdnum},$pwd) && ($pwd ne '')) || &checkcrypt($all{$pwdnum},$adminpwd)){ $join = 'off'; } else { close(DAT); close(WR); print "Content-Type: text/html\n\n"; print "
パスワードが違います。\n"; unlink("$tmpfile"); exit; } } else { print WR "$num,$name,$join,$comment,$pwd\n"; } } close(DAT); close(WR); rename("$tmpfile","$datafile"); } chmod(0666,"$datafile"); print "Location: $eventhtml\n\n"; } else { print "Content-Type: text/html\n\n"; print "
"; print "\n"; print ""; print "\n"; open(DAT,"< $datafile"); while(){ chop; ($num,$name,$join,$comment,$pwd)=split(/,/); $comment =~ s/^$/\ /; if ($join eq 'off'){ next; } print ""; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; } print "\n"; print "\n"; print "
参加者名意気込み/コメントパスワード 
$name$comment
\n"; my $mysite = ('http://www.hidekik.com/','http://www.hidekik.com/en/')[$lang]; print "
joinlist.cgi Ver. $version
\n"; print "
Copyright(C) 2002-$lastupdatedyear, hidekik.com
\n"; close(DAT); } exit; sub makecrypt { my $plain = shift; my $salt = join "", ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]; my $result = crypt($plain,$salt) or crypt($plain,'$1$'.$salt.'$'); return $result; } sub setadminpwd { print "Content-type:text/html\n\n"; print ""; print "
"; print "
管理者用パスワードを設定してください。
"; print ""; print ""; print ""; print "
"; print ""; exit; } sub wradminpwd { $passwd = &makecrypt($all{pwd}); if (open(FILE,"> $admindat")){ print FILE "$passwd"; close(FILE); } else { print "Content-type:text/html\n\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "パスワードファイル作成に失敗しました\n"; print "\n"; print "\n"; print "パスワードファイル作成に失敗しました。"; print "\n"; exit; } } sub checkcrypt { my ($pwd,$encpwd)=@_; return(crypt($pwd,$encpwd) eq "$encpwd"); }