#!/usr/local/bin/perl # ###################################################################### ### ### ### CGI不正リンク防止&ダウンロード数集計 T-FileSafe Ver.1.00 ### [2/2] ログ閲覧 (tflog.cgi) ### (c) 1996-2002 Takahiro Nishida ### http://www.mytools.net/ ### ### ###################################################################### # ### 変数設定部 (詳細は上記ページをご覧下さい) ###################### # データファイルの入っているディレクトリ $basedir = "."; # データファイルのURL $baseurl = "."; # 戻り先URL $backurl = "http://your.homepage/"; ###(変数設定部)ここまで######################################### # この秒数以内に同IPから同Fileへのリクエストが来ていたらカウントしない $DEFAULT_DOUGHT_TIME = 60; # エラーログの位置 $errorlog = "$basedir/errors.txt"; # アクセスログの位置 $accesslog = "$basedir/access.txt"; # このファイルの名前 $cginame = "tflog.cgi"; $verno = '1.00'; &main; sub main{ &init_variables; &check_input; &open_datafile; &show_html; } ##### 変数の初期化 sub init_variables{ $status_access = "Good."; $status_errors = "Good."; } ##### 入力のチェック sub check_input{ if ($ENV{'REQUEST_METHOD'} eq "POST"){ read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); } else{ $buffer = $ENV{'QUERY_STRING'}; } @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($vn, $value) = split(/=/, $pair); $F{$vn} .= $value; } $m_match = $F{'match'}; $m_dtime = $F{'dtime'}; ($m_dtime =~ /^\d+$/) || ($m_dtime = $DEFAULT_DOUGHT_TIME); } ##### データファイルのオープン sub open_datafile{ open(FILE, "$accesslog") || ($status_access = "Can't Open!!"); @accesses = ; close(FILE); } ##### 表示 sub show_html{ local($htmlbuf); $htmlbuf = &html_header; $htmlbuf .= &html_log; $htmlbuf .= &html_footer; print "Content-type: text/html\n"; print "\n"; print $htmlbuf; } ##### ヘッダ sub html_header{ " T-FileSafe Ver.$verno Log Page

T-FileSafe Log Page

Powered by T-FileSafe Ver.$verno   [Back]

生ログ: access.txt(Status: $status_access) / errors.txt(Status: $status_errors) ]

検索: 連続アクセス排除: 秒以内/ [Reset]


"; } ##### フッタ sub html_footer{ "
"; } ##### ログの表示 sub html_log{ local($b_date, $b_sec, $b_file, $b_host, $b_ref); local($p_file, $p_host, $p_sec); local($valid); local(%DAY_FILE, %ALL_FILE, %BR); local($html_log, $html_all, $html_day); ### 分析 foreach(@accesses){ ### 値の取得 (/^\[(\d{4}\/\d{2}\/\d{2})\s(\d{2}):(\d{2}):(\d{2})\]\sGET\s\(([^\)]+)\)\sHost:(.+)\sRef:(.+)/) || next; $b_date = $1; $b_sec = $2 * 3600 + $3 * 60 + $4; $b_file = $5; $b_host = $6; $b_ref = $7; ### ファイル名のマッチング ($m_match) && ($b_file !~ /$m_match/) && next; ### 連続アクセスのチェック $valid = 1; ($b_file eq $p_file) && ($b_host eq $p_host) && ($b_sec - $p_sec <= $m_dtime) && ($valid = 0); ### 比較用に保存 $p_file = $b_file; $p_host = $b_host; $p_sec = $b_sec; ### 連続アクセスなら次へ ($valid) || next; ### 計算 $DAY_FILE{$b_date}{$b_file}++; $ALL_FILE{$b_file}++; } ### ソート用 sub sortbydesc{ $BR{$b}<=>$BR{$a} }; ### 日別 foreach $k_date(sort keys %DAY_FILE){ $c_total = 0; $html_tmp = ""; %BR = %{ $DAY_FILE{$k_date} }; foreach $k_file(sort sortbydesc keys %BR){ $html_tmp .= "[$DAY_FILE{$k_date}{$k_file}] $k_file
\n"; $c_total += $DAY_FILE{$k_date}{$k_file}; } $html_day = "$k_date: total $c_total accesses.
\n"; $html_day .= $html_tmp; $html_day .= "
\n"; $html_log = $html_day . $html_log; } ### 総合 $c_total = 0; $html_tmp = ""; %BR = %ALL_FILE; foreach $k_file(sort sortbydesc keys %BR){ $html_tmp .= "[$ALL_FILE{$k_file}] $k_file
\n"; $c_total += $ALL_FILE{$k_file}; } $html_all .= "ALL: ... total $c_total accesses.
\n"; $html_all .= $html_tmp; $html_all .= "
\n"; $html_log = $html_all . $html_log; $html_log; }