̵��
$w3a_option["unwrite"] = 10;
//�ڥ������粽�к���
// �����Ѵ� 1 => ���� , 0 => ���ʤ�
$w3a_option["log_save"] = 1;
//�ڥ����������٤θ����к���
// �ۥ���̾�μ��� 1 => ���� , 0 => ���ʤ�
$w3a_option["ip_ch"] = 1;
/*==========================================================*/
/* ���ꤳ���ޤ� */
/*==========================================================*/
/*======================================*/
/* function */
/*======================================*/
//�ǥХå�
/*
function debug($data){
print "";
print_r($data);
print "";
exit;
}
*/
//�ǡ�������
function mk_data_w3a($str){
$str = str_replace("\t","",$str);
$str = "\t".$str;
return $str;
}
//���ݥꥹ���ɤ߹���
function exclude_read($uri){
if(file_exists($uri)){
if($arr_exclude = file($uri)){
$arr_exclude = array_unique($arr_exclude);
return $arr_exclude;
}
}
}
//�����Ѵ�
function log_save_enc($slist,$sval,$sw_break=0){
if(!$sval) return ;
foreach ($slist as $k => $v) {
if(strstr($sval,$v)){
$sval = str_replace ($v, '!'.$k.'!', $sval);
if(!$sw_break) break;
}
}
return $sval;
}
//����˻����ͤ����뤫�����å�
function inc_array($str,$arr){
$retval = FALSE;
if(is_array($arr)){
foreach($arr as $v){
if(stristr(trim($str), trim($v))){
$retval = TRUE;
break;
}
}
}
return $retval;
}
//�����ȥ����
function get_title($send_title="",$ref_path=""){
if($send_title){
$send_title = trim($send_title);
if(function_exists('mb_convert_encoding')){
$send_title = mb_convert_encoding($send_title, "EUC", "ASCII,JIS,UTF-8,EUC-JP,SJIS");
}
return $send_title;
}
//̵��
if(!$ref_path || !ini_get('allow_url_fopen')) return "";
$url = "http://".$_SERVER["HTTP_HOST"].$ref_path;
if($_SERVER["QUERY_STRING"]){
$url .= "?".$_SERVER["QUERY_STRING"]."&W3A";
}else{
$url .= "?W3A";
}
if($site = @file($url)){
foreach($site as $v){
$v = trim($v);
if(!$v) continue;
$file .= $v;
if(preg_match("/]*>([^<]*)<\/title>/i",$file,$t)){
$title = trim($t[1]);
if(function_exists('mb_convert_encoding')){
$title = mb_convert_encoding($title, "EUC", "ASCII,JIS,UTF-8,EUC-JP,SJIS");
}
return $title;
}
}
}
}
/*======================================*/
/* w3Analyzer�ǥ��쥯�ȥ�ѥ����� */
/*======================================*/
if(!isset($_GET["W3A"]) || isset($w3a_send_title)){
//�ѥ�����
if(isset($_GET["ref"])){
$sn = "";
$acc_path = "";
}else{
if($w3a_option["get_path_type"]){
$sn = substr( $_SERVER["REQUEST_URI"], 1, strlen($_SERVER["REQUEST_URI"]) - strlen(strrchr($_SERVER["REQUEST_URI"], "/")));
$sn = ereg_replace("[^/|~]","",$sn);
if(substr($sn, 0, 2) == '~/') $sn = substr($sn, 2);
$sn = str_replace("/", "../", $sn);
}else{
$sn = $_SERVER['PHP_SELF'];
if(strstr($sn,'~')) $sn = ereg_replace("/~[^/~/]+/","",$sn);
$sn = eregi_replace("^(/|\./)", "", $sn);
$sn = str_replace("/", "../", eregi_replace("[^/]", "", $sn));
}
//w3Analyzer�ǥ��쥯�ȥ�ѥ��Խ�
$acc_path = eregi_replace("^(/|\.\.?/)", "", $acc_path);
$acc_path = $sn.eregi_replace("(/)$", "", $acc_path)."/";
}
unset($sn);
//
if(@include_once($acc_path."inc/config.php")){
//��������̵���ä���Ȥꤢ�������ܻ���
if(!isset($time_diff)) $time_diff = 9;
/*======================================*/
/* ������ɤ߹����� */
/*======================================*/
if($log_type){
$w3a_logfile = $acc_path.$logdir.$logpref.gmdate("Ymd", time()+$time_diff*3600).$logext;
}else{
$w3a_logfdir = $acc_path.$logdir.gmdate("Ym", time()+$time_diff*3600);
if(!is_dir($w3a_logfdir)) mkdir($w3a_logfdir);
$w3a_logfile = $w3a_logfdir."/".$logpref.gmdate("d", time()+$time_diff*3600).$logext;
}
/*======================================*/
/* ���ݥꥹ�Ȥ��ɤ߹��� */
/*======================================*/
unset($exclude);
$exclude_fn = $acc_path.$datadir."exclude_hosts.txt";
if(file_exists($exclude_fn)) $exclude["hosts"] = exclude_read($exclude_fn);
$exclude_fn = $acc_path.$datadir."exclude_urls.txt";
if(file_exists($exclude_fn)) $exclude["urls"] = exclude_read($exclude_fn);
$exclude_fn = $acc_path.$datadir."exclude_uas.txt";
if(file_exists($exclude_fn)) $exclude["uas"] = exclude_read($exclude_fn);
unset($exclude_fn);
/*======================================*/
/* �ᥤ����� */
/*======================================*/
//�Хåե������
$w3a_buf = array();
//HOST������
$w3a_buf["host"] = ($w3a_option["ip_ch"] ? gethostbyaddr($_SERVER["REMOTE_ADDR"]) : $_SERVER["REMOTE_ADDR"]);
$write_flg = true;
//��������
if(inc_array($w3a_buf["host"],$exclude["hosts"])) $write_flg = false;
if(inc_array($_SERVER["REMOTE_ADDR"],$exclude["hosts"])) $write_flg = false;
if(inc_array($_SERVER["HTTP_REFERER"],$exclude["urls"])) $write_flg = false;
if(inc_array($_SERVER["HTTP_USER_AGENT"],$exclude["uas"])) $write_flg = false;
//�ѥ��ȥ�ե��顼������
if(isset($_GET["ref"])){
$w3a_buf["path"] = $_SERVER["HTTP_REFERER"];
$w3a_buf["path"] = ereg_replace("(https?|ftp|news)(://[[:alnum:]\+\$\;\?\.%,!#~*:@&=_-]+)(/.*)","\\3",$w3a_buf["path"]);
//��ե��顼�Խ�
$w3a_buf["ref"] = $_GET["ref"];
if(count($_GET) > 1){
foreach($_GET as $k => $v){
if($k == "ref" || $k == "W3A") continue;
$w3a_buf["ref"] .= '&'.$k;
if($v != "") $w3a_buf["ref"] .= '='.urlencode($v);
}
}
//�ѥ��Խ�
$w3a_buf["path"] = str_replace('?ref','',$w3a_buf["path"]);
}else{
$w3a_buf["path"] = $_SERVER["SCRIPT_NAME"];
$w3a_buf["ref"] = $_SERVER["HTTP_REFERER"];
//������
if($_SERVER["QUERY_STRING"]) $w3a_buf["path"] .= "?".$_SERVER["QUERY_STRING"];
}
//�桼��������������Ȥ�����
$w3a_buf["ua"] = $_SERVER["HTTP_USER_AGENT"];
//title
$w3a_buf["title"] = get_title($w3a_send_title,$w3a_buf["path"]);
//ID
if($_COOKIE["w3a"]["id"]){
$w3a_buf["id"] = $_COOKIE["w3a"]["id"];
}else{
foreach(explode(".",$_SERVER["REMOTE_ADDR"]) as $v){ $w3a_buf["id"] .= dechex($v); }
}
@setcookie("w3a[id]",$w3a_buf["id"],time()+60*60*24*30,'/');
//vc (24���ְ���ϥ�����ȥ��åפ��ʤ�)
if(isset($_COOKIE["w3a"]["date"])){
if($_COOKIE["w3a"]["date"] > time()+60*60*24){
$w3a_buf["vc"] = ($_COOKIE["w3a"]["vc"] ? ++$_COOKIE["w3a"]["vc"] : 1);
@setcookie("w3a[vc]",$w3a_buf["vc"],time()+60*60*24*30,'/');
@setcookie("w3a[date]",time(),time()+60*60*24*30,'/');
}else{
$w3a_buf["vc"] = ($_COOKIE["w3a"]["vc"] ? $_COOKIE["w3a"]["vc"] : 1);
}
}else{
$w3a_buf["vc"] = ($_COOKIE["w3a"]["vc"] ? $_COOKIE["w3a"]["vc"] : 1);
@setcookie("w3a[vc]",$w3a_buf["vc"],time()+60*60*24*30,'/');
@setcookie("w3a[date]",time(),time()+60*60*24*30,'/');
}
// http://���å�
if(strpos($w3a_buf["ref"], 'http://') === 0) $w3a_buf["ref"] = str_replace ('http://', "", $w3a_buf["ref"]);
if(strpos($w3a_buf["ref"], $_SERVER["HTTP_HOST"]) === 0) $w3a_buf["ref"] = "[m]".str_replace ($_SERVER["HTTP_HOST"], "", $w3a_buf["ref"]);
//�����Ѵ�(���粽����)
if($w3a_option["log_save"]){
unset($log_save);
$log_save_fn = $acc_path."inc/save_list.php";
if(file_exists($log_save_fn)){
include_once($log_save_fn);
$w3a_buf["ref"] = log_save_enc($log_save["ref"],$w3a_buf["ref"]);
$w3a_buf["host"] = log_save_enc($log_save["host"],$w3a_buf["host"]);
$w3a_buf["ua"] = log_save_enc($log_save["ua"],$w3a_buf["ua"],1);
}
}
//�ɲå⡼�ɤdz���
if($write_flg && $fn = fopen($w3a_logfile,"a+")){
//��������к�
if($w3a_option["unwrite"]){
rewind($fn);
while (!feof($fn)) {
$str = trim(fgets($fn));
if($str == "") continue;
list($tmp_data[dt],$tmp_data[path],$tmp_data[host],) = explode("\t",$str);
if($tmp_data[dt]) list($tmp_data[day],$tmp_data[week],$tmp_data[hour],$tmp_data[minute],$tmp_data[sec]) = explode(",",$tmp_data[dt]);
//TIME
$write_time = time()-mktime($tmp_data[hour],$tmp_data[minute],$tmp_data[sec]);
//�����ðʾ�ʤ齪λ
if($w3a_option["unwrite"] < $write_time){ unset($tmp_data,$write_time); continue; }
//PATH/HOST�����å�
if($tmp_data[path] == $w3a_buf["path"] && $w3a_buf["host"] == $tmp_data[host]){
$write_flg = false;
unset($tmp_data,$write_time);
break;
}
}
}
//����
if($write_flg){
//���ߥХåե�0�� PHP4.3�ʾ�
if(function_exists('stream_set_write_buffer')) stream_set_write_buffer($fn, 0);
//�ե�������å�
flock($fn,LOCK_EX);
fwrite($fn,gmdate("d,D,H,i,s", time()+$time_diff*3600));
fwrite($fn,mk_data_w3a($w3a_buf["path"]));
fwrite($fn,mk_data_w3a($w3a_buf["host"]));
fwrite($fn,mk_data_w3a($w3a_buf["ref"]));
fwrite($fn,mk_data_w3a($w3a_buf["ua"]));
fwrite($fn,mk_data_w3a($w3a_buf["title"]));
fwrite($fn,mk_data_w3a($w3a_buf["id"]));
fwrite($fn,mk_data_w3a($w3a_buf["vc"]));
fwrite($fn,"\n");
//������
flock($fn,LOCK_UN);
}
fclose($fn);
}
unset($w3a_buf,$w3a_logfile);
}
unset($acc_path,$w3a_option);
}
/*======================================*/
/* HTML��(1X1Ʃ����������) */
/*======================================*/
if(isset($_GET["ref"])){
header("Content-Type: image/gif");
echo base64_decode("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==");
exit;
}
?>