package access; #┌───────────────────────────────── #│ アクセス解析システム v1.0 (2002/04) #│ Copyright(C) Kent Web 2002 #│ webmaster@kent-web.com #│ http://www.kent-web.com/ #└───────────────────────────────── # # 【使用法】 # # カウンタのログ更新の直後に以下の2行を付け加える # require './access.pl'; # &access'analyze; #============# # 基本設定 # #============# # 記録ファイル $datfile= './access.dat'; # 最大ログ保持数(これ以上大きくしない方が無難です) $max = 1000; #============# # 設定完了 # #============# sub analyze { # ブラウザ情報を取得 $agent2 = $agent = $ENV{'HTTP_USER_AGENT'}; if ($agent =~ /AOL/) { $agent = 'AOL'; } elsif ($agent =~ /Opera/i) { $agent = 'Opera'; } elsif ($agent =~ /MSIE 3/i) { $agent = 'MSIE 3'; } elsif ($agent =~ /MSIE 4/i) { $agent = 'MSIE 4'; } elsif ($agent =~ /MSIE 5/i) { $agent = 'MSIE 5'; } elsif ($agent =~ /MSIE 6/i) { $agent = 'MSIE 6'; } elsif ($agent =~ /Mozilla\/2/i) { $agent = 'Netscape 2'; } elsif ($agent =~ /Mozilla\/3/i) { $agent = 'Netscape 3'; } elsif ($agent =~ /Mozilla\/4/i) { $agent = 'Netscape 4'; } elsif ($agent =~ /Netscape ?6/i) { $agent = 'Netscape 6'; } elsif ($agent =~ /Mozilla\/5/i) { $agent = 'Mozilla'; } elsif ($agent =~ /Netscape/i && $agent =~ /Gecko/i) { $agent = 'Mozilla'; } elsif ($agent =~ /Lynx/i) { $agent = 'Lynx'; } elsif ($agent =~ /Cuam/i) { $agent = 'Cuam'; } elsif ($agent =~ /DoCoMo/i) { $agent = 'i-mode'; } elsif ($agent =~ /Internet Ninja/i) { $agent = 'Internet Ninja'; } if ($agent2 =~ /win[dows ]*95/i) { $os = 'Win95'; } elsif ($agent2 =~ /win[dows ]*9x/i) { $os = 'WinMe'; } elsif ($agent2 =~ /win[dows ]*98/i) { $os = 'Win98'; } elsif ($agent2 =~ /win[dows ]*XP/i) { $os = 'WinXP'; } elsif ($agent2 =~ /win[dows ]*NT ?5\.1/i) { $os = 'WinXP'; } elsif ($agent2 =~ /Win[dows ]*NT ?5/i) { $os = 'Win2000'; } elsif ($agent2 =~ /win[dows ]*2000/i) { $os = 'Win2000'; } elsif ($agent2 =~ /Win[dows ]*NT/i) { $os = 'WinNT'; } elsif ($agent2 =~ /Win[dows ]*CE/i) { $os = 'WinCE'; } elsif ($agent2 =~ /shap pda browser/i) { $os = 'ZAURUS'; } elsif ($agent2 =~ /Mac/i) { $os = 'Mac'; } elsif ($agent2 =~ /X11/ || $agent2 =~ /SunOS/i || $agent2 =~ /Linux/i || $agent2 =~ /HP-UX/i || $agent2 =~ /FreeBSD/i || $agent2 =~ /NetBSD/i || $agent2 =~ /OSF1/i || $agent2 =~ /IRIX/i) { $os = 'UNIX'; } else { $os = 'unknown'; } # ホスト名を取得 $host = $ENV{'REMOTE_HOST'}; $addr = $ENV{'REMOTE_ADDR'}; if ($host eq "" || $host eq $addr) { $host = gethostbyaddr(pack("C4",split(/\./,$addr)),2) || $addr; } if ($host eq "") { $host = $addr; } if ($host =~ /(.*)\.(\d+)$/) { ; } elsif ($host =~ /(.*)\.(.*)\.(.*)\.(.*)$/) { $host = "\*\.$2\.$3\.$4"; } elsif ($host =~ /(.*)\.(.*)\.(.*)$/) { $host = "\*\.$2\.$3"; } # 時間を取得 $ENV{'TZ'} = "JST-9"; ($sec,$min,$hour,$mday,$mon,$year,$wday) = localtime(time); # ログ読み込み open(IN,"$datfile") || &error; @lines = ; close(IN); # 記事数を調整し、新規ログをフォーマット while ($max-1 < @lines) { pop(@lines); } unshift(@lines,"$agent<>$os<>$host<>$wday<>$hour<>\n"); # 更新 open(OUT,">$datfile") || &error; print OUT @lines; close(OUT); }