#!/usr/bin/perl # Vote.pl is freeware: (c)GOMASUKE # Ver.1.0 1999/12/14 # # The following DENY BLOCK: write permission denied domain(0) require './jcode.pl'; $base = 'http://www.hogehoge.ne.jp/~foo/'; $pg = 'vote.cgi'; $cfile1 = '../bbs/vcnt1.txt'; $cfile2 = '../bbs/vcnt2.txt'; $ifile1 = '../bbs/vidx1.txt'; $ifile2 = '../bbs/vidx2.txt'; $dfile = '../bbs/'; $pwd = 'xyz'; $max = 12; $mmax = 400; $cmax = 20; @week = ("Sun","Mon","Tue","Wed","Thu","Fri","Sat"); $rh = $ENV{'REMOTE_HOST'}; $ra = $ENV{'REMOTE_ADDR'}; $rf = $ENV{'HTTP_X_FORWARDED_FOR'}; $ref = $ENV{'HTTP_REFERER'}; $ref =~ s/%7E/~/gi; $itm{'act'} = 'i'; $itm{'no'} = 0; $ENV{'REQUEST_METHOD'} =~ tr/a-z/A-Z/; if ($ENV{'REQUEST_METHOD'} eq "GET") { $dat = $ENV{'QUERY_STRING'}; } else { read(STDIN, $dat, $ENV{'CONTENT_LENGTH'}); } @buf = split('&',$dat); foreach $item (@buf) { ($var,$value) = split('=',$item); $value =~ tr/+/ /; $value =~ s/%([0-9a-fA-F][0-9a-fA-F])/pack("C", hex($1))/eg; &jcode'convert(*value,'sjis'); $value =~ s//>/g; $value =~ s/\r\n/\n/g; $value =~ s/\r/\n/g; #Win,Mac $value =~ s/\n{2,}/\n/g; $itm{$var} = $value; } $act = $itm{'act'}; $no = $itm{'no'}; $nm = $itm{'nm'}; if ($ref eq '') { $act = 'i'; $ref = $base; } if ($ref =~ /^$base/) { $acl = 1; if ($act eq "p") { if ($rh eq $ra) { $rh = gethostbyaddr(pack("C4", split('\.',$rh)),2) || $ra; } $user = "$rh\/$ra"; if ($rf ne '') { $rff = gethostbyaddr(pack("C4", split('\.',$rf)),2) || $rf; $user = "$user\/$rff\/$rf"; } } DENY: { # if ($rh =~ /\.zzz\.(or|ne)\.jp/i) { $acl = 2; last DENY; } # if ($rh =~ /\.interq\.(or|ne)\.jp/i) { $acl = 2; last DENY; } # if ($rh =~ /\.eznet\.(or|ne)\.jp/i) { $acl = 2; last DENY; } # if ($rh =~ /\.interwave\.(or|ne)\.jp/i) { $acl = 2; last DENY; } # if ($ra =~ /^xxx\.xxx\.xxx\./) { $acl = 2; last DENY; } } } else { $acl = 3; } print "Content-type: text/html\n\n"; if ($acl == 2) { print "

Forbidden

Your client is not allowed to access the requested object.\n"; exit; } if ($acl == 3) { print "

Forbidden

Your client is not allowed to access the requested object.
$ref\n"; exit; } print < ●● $act EOF if ($act eq 'i') { &act_i; } if ($act eq 'd') { &act_d; } if ($act eq 'p') { &act_p; } if ($act eq 'n') { &act_n; } if ($act eq 'e') { &act_e; } print <
管理用

cgi script (c)GOMASUKE<vote.pl>
http://www.orange.ne.jp/~kibita/n88/index.html

EOF exit; sub act_i { @c = (); @t = (); @k = (); if (-e $ifile1) { open(IN,"<$ifile1"); foreach $a () { chop($a); ($no,$tt,$ct) = split('<',$a); $h_key = sprintf("%04d%04d", $ct,$no); $c{$no} = $ct; $t{$no} = $tt; $k{$no} = $h_key; } close(IN); } &act_w; print <
タイトルをクリックするとコメントが\表\示されます
EOF $i= 0; $rk = 99999; foreach $key (sort { $k{$b} <=> $k{$a} } keys %k) { $i++; $ct = $c{$key}; if ($ct < $rk) { $rk = $ct; $no = $i; } if ($no > $max) { last; } if ($ct != 0) { print "\n"; } else { last; } } print "
ランクタイトル投票数
No\.$no$t{$key}$ct

\n"; } sub act_w { print <

●●

[再読込]

あなたの印象に残った●●を投票してください

タイトル
あらかじめ、タイトルが幾つか用意されています
投票者(必須)
Email(任意)
内容についての感想など(必須) 半角換算400文字まで タグは無視されます

 
EOF } sub act_d { if (-e $ifile1) { open(IN,"<$ifile1"); foreach $a () { ($nn,$tt,$ct) = split('<',$a); if ($no == $nn) { last; } } close(IN); } print <【$tt】についてのコメントです

[戻る]


EOF if (-e $ifile2) { open(IN,"<$ifile2"); while($a = ) { chop($a); ($nn,$ct) = split('<',$a); if ($no == $nn) { &det; } } close(IN); } print "
投票者コメント

[戻る]\n"; } sub err_1 { print "[戻る]\n"; } sub det { $f = 0; $cno = substr("000$ct",-3); $pfile = "$dfile$cno\.txt"; if (-e $pfile) { $f = 1; $mg = ""; open(OUT,"<$pfile"); chop($a = ); while() { $mg = $mg . $_; } close(OUT); ($nn,$dt,$nm,$ml,$ra0,$user) = split('<',$a); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdat) = localtime($dt); $mon++; $dt = sprintf("%02d/%02d<%3s>%02d:%02d", $mon,$mday,$week[$wday],$hour,$min); if ($ml ne '') { $nm = "$nm"; } if ($act eq 'n') { print "$t{$nn}"; } else { print ""; } print "$nm"; $mg =~ s/\n$//g; $mg =~ s/\n/
/g; ($ip1,$ip2,$ip3,$ip4) = split('\.',$ra0); $ra0 = "\*\.$ip2\.\*\.$ip4"; print "$mg($dt [$ct] $ra0)\n"; } } sub act_n { @t = (); if (-e $ifile1) { open(IN,"<$ifile1"); foreach $a () { chop($a); ($nn,$tt,$ct) = split('<',$a); $t{$nn} = $tt; } close(IN); } print <【最新$cmax件】についてのコメントです

[一覧へ戻る]


EOF if (-e $cfile2 && -e $ifile2) { if ($no == 0) { open(IN,"<$cfile2"); chop($no = ); close(IN); } $c = 1; open(IN,"<$ifile2"); while($no > 0 && $c <= $cmax) { $ct = $no; &det; $no--; if ($f == 1) { $c++; } } close(IN); } print "
タイトル投票者コメント
\n"; if ($no != 0) { print "

次の記事

\n"; } print "
[一覧へ戻る]\n"; } sub act_p { $it = $itm{'it'}; $tt = $tt2 = $itm{'tt'}; $tp = $itm{'tp'}; $nm = $nm2 = $itm{'nm'}; $ml = $itm{'ml'}; if (!($ml =~ "\@")) { $ml = ""; } $mg = $mg2 = $itm{'mg'}; $nm2 =~ s/\n//g; $nm2 =~ s/ / /g; $nm2 =~ s/ //g; if ($nm2 eq '') { print "

『投票者』がありません

"; &err_1; return; } $tt2 =~ s/\n//g; $tt2 =~ s/ / /g; $tt2 =~ s/ //g; if ($it == 0 && $tt2 eq '') { print "

『追加タイトル』がありません

"; &err_1; return; } $tt = $tt . '(' . $tp . ')'; $mg2 =~ s/\n//g; $mg2 =~ s/ / /g; $mg2 =~ s/ //g; if ($mg2 eq '') { print "

『内容』がありません

"; &err_1; return; } $ln = length($mg2); if ($ln > $mmax) { print "

文字数を減らして下さい($ln char)

"; &err_1; return; } @d = (); if ($it != 0) { $no = $it; } if (-e $cfile1 && -e $ifile1) { open(IN,"+<$cfile1"); flock(IN,2); if ($it == 0) { $no = ; $no++; seek(IN,0,0); print IN "$no\n"; open(OUT,">>$ifile1"); print OUT "$no<$tt<1\n"; } else { open(OUT,"+<$ifile1"); chop(@d = ); seek(OUT,0,0); foreach (@d) { ($nn,$tt,$cn) = split('<',$_); if ($nn == $no) { $cn++; } print OUT "$nn<$tt<$cn\n"; } } close(OUT); close(IN); } if (-e $cfile2 && -e $ifile2) { open(IN,"+<$cfile2"); flock(IN,2); $ct = ; $ct++; seek(IN,0,0); print IN "$ct\n"; @d = (); open(OUT,"+<$ifile2"); chop(@d = ); unshift(@d,"$no<$ct"); seek(OUT,0,0); foreach (@d) { print OUT "$_\n"; } close(OUT); close(IN); } $dt = time; $hd = "$no<$dt<$nm<$ml<$ra<$user"; $mg =~ s/\n$//g; $cno = substr("000$ct",-3); $pfile = "$dfile$cno\.txt"; open(IN,">$pfile"); print IN "$hd\n"; print IN "$mg\n"; close(IN); &act_i; } sub act_e { @d = (); $pw = $itm{'pw'}; $cno = substr("000$no",-3); $pfile = "$dfile$cno\.txt"; $nfile = "$dfile$cno" . "x\.txt"; if (-e $pfile && -e $ifile1 && $pw eq $pwd) { open(IN,"<$pfile"); chop($a = ); close(IN); ($no,$dt,$nm,$ml,$ra,$user) = split('<',$a); open(IN,"+<$ifile1"); flock(IN,2); chop(@d = ); seek(IN,0,0); foreach (@d) { ($nn,$tt,$ct) = split('<',$_); if ($nn == $no) { $ct--; } print IN "$nn<$tt<$ct\n"; } close(IN); rename($pfile, $nfile); } &act_i; }