#!/usr/mesh/bin/perl # Forum.pl is freeware: (c)GOMASUKE # Dept. of Computer Science, Faculty of Engineering, # Shizuoka Univ., Hamamatsu, Japan # Ver.1.0 1998/05/23 # # The following DENY BLOCK: write permission denied domain(0) require './jcode.pl'; $base = 'http://www.hogehoge.(or|ne).jp/~foo/'; $pg = 'forum.cgi'; $cfile = 'xcnt.txt'; $ifile = 'xidx.txt'; $dfile = 'bbs/'; $max = 12; @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'} = 'd'; $itm{'pos'} = 1; $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\n/g; $itm{$var} = $value; } $act = $itm{'act'}; $pos = $itm{'pos'}; $no = $itm{'no'}; if ($ref eq '') { $act = 'i'; $pos = 1; $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 < hogeフォーラム $act EOF if ($act eq 'i') { &act_i; } if ($act eq 'n') { &act_n; } if ($act eq 'o') { &act_o; } if ($act eq 'w') { &act_w; } if ($act eq 's') { &act_s; } if ($act eq 'd') { &act_d; } if ($act eq 'f') { &act_f; } if ($act eq 'p') { &act_p; } print "\n\n"; exit; sub act_i { print "
\n";
$i = 0; $c = 0; @d = (); $nx = 0;
if (-e $ifile) {
  open(IN,"<$ifile");
  foreach $a () {
    chop($a);
    ($lv,$no,$rt) = split('<',$a);
    if ($lv == 0) {
      $c++;
      if ($pos > $c) { next; }
      $i++;
      if ($i > $max) { $nx = 1; last; }
    }
    if ($pos <= $c) { push(@d,$a); }
  }
  close(IN);
}
foreach (@d) {
  ($lv,$no,$rt) = split('<',$_);
  $cno = substr("000$no",-3);
  $pfile = "$dfile$cno\.txt";
  if (-e $pfile) {
    open(IN,"<$pfile");
    chop($a = );
    close(IN);

    ($tt,$dt,$nm,$ml,$re,$rt,$ri) = split('<',$a);
    ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdat) = localtime($dt);
    $mon++;
    $dt = sprintf("%02d/%02d %02d:%02d", $mon,$mday,$hour,$min);

    if ($lv == 0) {
        print "";
    } else {
        print "";
    }
    $sp = ' ' x $lv;
    print "$sp$tt\n";
    print "$sp   $nm $dt\n";
  }
}

print "
\n"; if ($nx == 1) { $pos += $max; print "

次の親スレッド

\n"; } print < cgi script (c)GOMASUKE<forum.pl> EOF } sub act_n { if (-e $cfile) { if ($no == 0) { open(IN,"<$cfile"); chop($no = ); close(IN); } $c = 1; while($no > 0 && $c <= $max) { &det; $no--; $c++; } if ($no != 0) { print "

次の記事

\n"; } } } sub act_o { if (-e $cfile) { open(IN,"<$cfile"); chop($ct = ); close(IN); if ($no == 0) { $no = 1; } $c = 1; while($no <= $ct && $c <= $max) { &det; $no++; $c++; } if ($no <= $ct) { print "

次の記事

\n"; } } } sub act_w { print <新規記事を書く
投稿者:
Email(任意):
タイトル:
内容: タグは無視されます。

 

EOF } sub act_s { $f = 0; @d = (); if (-e $ifile) { open(IN,"<$ifile"); foreach $a () { chop($a); ($lv,$fn,$rt) = split('<',$a); if ($f == 0 && $no != $fn) { next; } if ($f == 1 && $lv == 0) { last; } push(@d,$a); $f = 1; } close(IN); } foreach (@d) { ($lv,$no,$rt) = split('<',$_); &det; } } sub det { $cno = substr("000$no",-3); $pfile = "$dfile$cno\.txt"; if (-e $pfile) { open(IN,"<$pfile"); chop($a = ); ($tt,$dt,$nm,$ml,$re,$rt,$ri) = 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); print "

フォローする』"; if ($re != 0) { print "『元記事』"; } if ($re != 0 && $re != $rt) { print "『親記事』"; } print "

\n"; print "

$tt

"; if ($ml ne '') { $nm = "$nm"; } print "

$nm $dt [$no]

\n"; while() { $_ =~ s/\n/
/g; print "$_\n"; } close(IN); print "
\n"; } } sub act_d { &det; } sub act_f { print "フォロー記事を書く
\n"; $cno = substr("000$no",-3); $pfile = "$dfile$cno\.txt"; if (-e $pfile) { open(IN,"<$pfile"); chop($a = ); ($tt,$dt,$nm,$ml,$re,$rt,$ri) = split('<',$a); $dat = ""; while() { $dat = $dat . "> $_"; } close(IN); print < 投稿者:
Email(任意):
タイトル:
内容: タグは無視されます。できるだけ引用を削って下さい。

 
EOF } } sub act_p { $nm = $nm2 = $itm{'nm'}; $ml = $itm{'ml'}; if (!($ml =~ "\@")) { $ml = ""; } $tt = $tt2 = $itm{'tt'}; $mg = $mg2 = $itm{'mg'}; $nm2 =~ s/\n//g; $nm2 =~ s/ / /g; $nm2 =~ s/ //g; if ($nm2 eq '') { print "

『投稿者』がありません

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

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

$user"; return; } $mg2 =~ s/\n//g; $mg2 =~ s/ / /g; $mg2 =~ s/ //g; if ($mg2 eq '') { print "

『内容』がありません

$user"; return; } if (-e $cfile) { open(IN,"+<$cfile"); flock(IN,2); $ct = ; $ct++; seek(IN,0,0); print IN "$ct\n"; close(IN); } @d = (); if (-e $ifile) { open(IN,"+<$ifile"); flock(IN,2); if ($no == 0) { chop(@d = ); unshift(@d,"0<$ct<$ct"); $re = 0; $rt = $ct; } else { foreach $a () { chop($a); push(@d,$a); ($lv,$fn,$rot) = split('<',$a); if ($no == $fn) { $lv++; push(@d,"$lv<$ct<$rot"); $re = $no; $rt = $rot; } } } seek(IN,0,0); foreach (@d) { print IN "$_\n"; } close(IN); } $dt = time; $hd = "$tt<$dt<$nm<$ml<$re<$rt<$user"; $cno = substr("000$ct",-3); $pfile = "$dfile$cno\.txt"; open(IN,">$pfile"); print IN "$hd\n"; print IN "$mg\n"; close(IN); print <

投稿完了

記事一覧を再読み込みして下さい

記事を確認する』 EOF }