#!/usr/bin/perl -w #//===================================================================== #// w_s3rdct.cgi リダイレクトカウント #//===================================================================== #//【バージョン】 #// version 1.11 #//【著作権】 #// Copyright (C) 2001-2002 Y.SAK #//【連絡先】 #// e-mail : SAK #// homepage: http://homepage2.nifty.com/sak/ #//===================================================================== #// 準備 $syslog = '../w_sys'; *data = GetPara(); $log = $data{'log'}; $fnm = $data{'fnm'}; $url = $data{'url'}; $path = $ENV{'PATH_INFO'}; $ip = $ENV{'REMOTE_ADDR'}; $blws = $ENV{'HTTP_USER_AGENT'}; #// 動作環境セット if (($i = index($path, '/w_test/')) != -1) { $j = index($path, '/', $i += length('/w_test/')); $syslog = 'w_test/' . substr($syslog, 3); } #// パラメタチェック if ($url eq '') { exit(0); } #// カウント開始 if ($log ne '') { if ($fnm eq '') { $fnm = 'sakcm'; } #// アクセス回数加算 $ct = 0; $ctold = 0; $ctmmold = 0; $err = 0; open(CNT, "$syslog/acc_$fnm.dat") or $err = 1; if ($err == 0) { chomp ($ct = ); chomp ($dttmold = ); chomp ($ctnow = ); chomp ($ctold = ); chomp ($ctmmnow = ); chomp ($ctmmold = ); close(CNT); } if ($ct eq '' or length($dttmold) < 19 or $ct < 1) { if (-e "$syslog/acc_$fnm.dat") { print "Location: $url\n\n"; exit(0); } } ($ss, $mn, $hh, $dd, $mm, $yy) = localtime(time); $yy += 1900; $mm++; $dttm = sprintf("%04d.%02d.%02d %02d:%02d:%02d", $yy, $mm, $dd, $hh, $mn, $ss); $err = 0; open(CNT, ">$syslog/acc_$fnm.dat") or $err = 1; if ($err == 0) { if (length($dttmold) == 19) { if (substr($dttmold, 0, 10) ne substr($dttm, 0, 10) and $ctnow > 0) { $ctold = $ctnow; $ctnow = 0; if (substr($dttmold, 0, 7) ne substr($dttm, 0, 7) and $ctmmnow > 0) { $ctmmold = $ctmmnow; $ctmmnow = 0; } } } $ct++; if ($ct eq '' or $ct < 1) { print "Location: $url\n\n"; exit(0); } $ctnow++; $ctmmnow++; print CNT $ct, "\n", $dttm, "\n", $ctnow, "\n", $ctold, "\n", $ctmmnow, "\n", $ctmmold, "\n"; close(CNT); } #// カウント終了 } #// リダイレクト if ($log ne '9') { print "Location: $url\n\n"; } else { print "Content-type: text/html\n\n"; print "$url"; } #// 終了 exit(0); #//===================================================================== #// パラメタ取得 #//===================================================================== sub GetPara { my($encoding) = @_; my($method) = $ENV{'REQUEST_METHOD'}; local($query, @in, $key, $val); #// 日本語コード変換 jcode.pl 読み込み require 'jcode.pl' if $encoding; #// パラメタ取得 if ($method eq 'GET') { $query = $ENV{'QUERY_STRING'}; } elsif ($method eq 'POST') { read(STDIN, $query, $ENV{'CONTENT_LENGTH'}); } local(@query) = split(/&/, $query); foreach (@query) { tr/+/ /; ($key, $val) = split(/=/); $key =~ s/%([A-Fa-f0-9][A-Fa-f0-9])/pack("c", hex($1))/ge; $val =~ s/%([A-Fa-f0-9][A-Fa-f0-9])/pack("c", hex($1))/ge; $val =~ s/\r\n/\n/g; jcode'convert(*key, $encoding) if ($encoding); jcode'convert(*val, $encoding) if ($encoding); $in{$key} = $val; } #// 戻り値セット return *in; }