#!/usr/bin/perl #┌───────────────────────────────── #│ Sun Board v4 #│ sunbbs.cgi - 2007/11/18 #│ Copyright (c) KentWeb #│ webmaster@kent-web.com #│ http://www.kent-web.com/ #└───────────────────────────────── # 外部ファイル require './init.cgi'; require $jcode; &decode; if ($mode eq 'form') { &form; } elsif ($mode eq 'find') { &find; } elsif ($mode eq "past" && $pastkey) { &past; } elsif ($mode eq "check") { ✓ } &location; #------------------------------------------------- # クッキー取得 #------------------------------------------------- sub get_cookie { local($key, $val, *cook); # クッキーを取得 $cook = $ENV{'HTTP_COOKIE'}; # 該当IDを取り出す foreach ( split(/;/, $cook) ) { ($key, $val) = split(/=/); $key =~ s/\s//g; $cook{$key} = $val; } # データをURLデコードして復元 foreach ( split(/<>/, $cook{'SUN_BOARD'}) ) { s/%([0-9A-Fa-f][0-9A-Fa-f])/pack("H2", $1)/eg; push(@cook,$_); } return (@cook); } #------------------------------------------------- # ワード検索 #------------------------------------------------- sub find { print &header; print <<"EOM"; [戻る]
ワード検索
\n"; # ワード検索の実行と結果表示 if ($in{'word'} ne '') { $in{'word'} =~ s/ / /g; my @wd = split(/\s+/, $in{'word'}); my @new; open(IN,"$logfile") || &error("Can't open $logfile"); while () { my $flag; foreach $wd (@wd) { if (index($_,$wd) >= 0) { $flag = 1; if ($in{'cond'} eq 'OR') { last; } } else { if ($in{'cond'} eq 'AND') { $flag = 0; last; } } } if ($flag) { push(@new,$_); } } close(IN); # 検索終了 my $count = @new; print "検索結果:$count
\n"; foreach (@new) { my ($no,$date,$name,$email,$sub,$com,$url,$ho,$pw,$tag) = split(/<>/); $name = "$name" if ($email); if ($url) { if ($url !~ m|https?://|i) { $url = "http://$url"; } $url = "<URL>"; } print "

\n"; if ($whatsnew) { $com = &tagview($com) if ($tag == 1); print "[$no] $sub Date:$date $url

\n"; } else { print "[$no] $sub 投稿者:$name "; print "投稿日:$date $url

\n"; } print "
$com

\n"; } print "

\n"; } print "\n\n"; exit; } #------------------------------------------------- # 過去ログ #------------------------------------------------- sub past { open(IN,"$nofile") || &error("Open Error: $nofile"); my $pastno = ; close(IN); if (!$in{'pastlog'}) { $in{'pastlog'} = $pastno; } $in{'pastlog'} = sprintf("%04d", $in{'pastlog'}); print &header; print <<"EOM"; [戻る]
過去ログ[$in{'pastlog'}]

過去ログ:
キーワード: 条件: EOM if ($in{'view'} eq "") { $in{'view'} = $pagelog; } foreach (5,10,15,20,25,30) { if ($in{'view'} eq $_) { print "
EOM # 表示ログを定義 $in{'pastlog'} =~ s/\D//g; my $file = "$pastdir$in{'pastlog'}\.dat"; # ワード検索処理 if ($in{'word'} ne "") { $in{'word'} =~ s/ / /g; my @wd = split(/\s+/, $in{'word'}); my @new; open(IN,"$file") || &error("Open Error: $file"); while () { my $flag; foreach $wd (@wd) { if (index($_,$wd) >= 0) { $flag = 1; if ($in{'cond'} eq 'OR') { last; } } else { if ($in{'cond'} eq 'AND') { $flag = 0; last; } } } if ($flag) { push(@new,$_); } } close(IN); my $count = @new; print "

検索結果:$count件\n"; if ($in{'page'} eq '') { $in{'page'} = 0; } my $end_data = @new - 1; my $page_end = $in{'page'} + $in{'view'} - 1; if ($page_end >= $end_data) { $page_end = $end_data; } my $next = $page_end + 1; my $back = $in{'page'} - $in{'view'}; my $eword = &url_enc($in{'word'}); if ($back >= 0) { print "[前の$in{'view'}件]\n"; } if ($page_end ne $end_data) { print "[次の$in{'view'}件]\n"; } # 表示開始 foreach ($in{'page'} .. $page_end) { print $new[$_]; } print "


\n\n\n"; exit; } # ページ区切り処理 my $start = $in{'page'} + 1; my $end = $in{'page'} + $pagelog; my $i = 0; open(IN,"$file") || &error("Open Error: $file"); while () { $i++; if ($i < $start) { next; } if ($i > $end) { last; } print $_; } close(IN); print "
\n"; my $next = $in{'page'} + $pagelog; my $back = $in{'page'} - $pagelog; if ($back >= 0 || $next < $i) { print "\n"; } if ($back >= 0) { print qq|\n|; } if ($next < $i) { print qq|\n|; } if ($back >= 0 || $next < $i) { print "
\n|; print qq|\n|; print qq|\n|; print qq|\n|; print qq|
\n|; print qq|\n|; print qq|\n|; print qq|\n|; print qq|
\n"; } print "\n\n"; exit; } #------------------------------------------------- # URLエンコード #------------------------------------------------- sub url_enc { local($_) = @_; s/(\W)/'%' . unpack('H2', $1)/eg; s/\s/+/g; $_; } #------------------------------------------------- # チェックモード #------------------------------------------------- sub check { print &header; print "

Check Mode

\n"; print "
    \n"; # 3ファイルチェック foreach ("$logfile", "$htm_dir$htmfile", "$htm_dir$nexthtm") { # パス if (-e $_) { print "
  • $_ のパス:OK\n"; } else { print "
  • $_ のパス:NG\n"; } # パーミッション if (-r $_ && -w $_) { print "
  • $_ のパーミッション:OK\n"; } else { print "
  • $_ のパーミッション:NG\n"; } } # 過去ログ print "
  • 過去ログ:"; if ($pastkey == 0) { print "設定なし\n"; } else { print "設定あり\n"; # NOファイル if (-e $nofile) { print "
  • NOファイルパス:OK\n"; if (-r $nofile && -w $nofile) { print "
  • NOファイルパーミッション:OK\n"; } else { print "
  • NOファイルパーミッション:NG → $nofile\n"; } } else { print "
  • NOファイルのパス:NG → $nofile\n"; } # ディレクトリ if (-d $pastdir) { print "
  • 過去ログディレクトリパス:OK\n"; if (-r $pastdir && -w $pastdir && -x $pastdir) { print "
  • 過去ログディレクトリパーミッション:OK\n"; } else { print "
  • 過去ログディレクトリパーミッション:NG → $pastdir\n"; } } else { print "
  • 過去ログディレクトリのパス:NG → $pastdir\n"; } } print "
\n\n\n"; exit; }