Webalizer/スクリプト
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
]
開始行:
**スクリプト [#qf377e91]
#contents
----
***URLデコード [#abcd3be1]
暫定版。~
URLデコードした状態で解析すると、どうもURL長いよ警告が出...
Wikiなどの長いURLの解析をスキップしている様子。~
そこで、UTF-8以外の検索文字列を(今のところキメ打ちで)~
UTF-8に直した上でURLエンコードし、再度WebalizerにURLデコ...
ついでにごにょごにょと。
#!/usr/local/bin/php
<?php
$infile = fopen('/tmp/access_log',"r");
$outfile = fopen('/tmp/access_log.tmp',"w");
//検索文字列(Webalizer定義)
//Shift_JISで化けた文字用にチルダ入れる
$query= '/(query|q|keyword|p|MT|search|qr|text)=([\w\d%+...
//リファラ
$ref = '/\[.*?\] ".*?" [0-9]*? [0-9]*? "(.*?)"/';
//クエリ内ハッシュ
$hash = '/[\?&](q=.*#)/';
//Googleキャッシュ
$cache = '/[\?&]q=(cache:[\w\d\-]{12}:.*?\+)/';
if( $infile ) {
while( !feof( $infile ) ) {
$line = fgets( $infile );
if ( !empty($line) ) {
//GoogleSuggest機能?のハッシュ文字対策
if( preg_match($hash, $line, $hash_matches) ...
$line = str_replace($hash_matches[1], ''...
}
//Googleキャッシュの検索文字列
if( preg_match($cache, $line, $cache_matches)...
$line = str_replace($cache_matches[1], ''...
}
//EzWebのSJISのURLエンコードをUTF-8のURLエン...
if( strpos($line, '//ezsch.ezweb.ne.jp/searc...
preg_match($ref, $line, $ref_matches);
preg_match($query, $ref_matches[1], $mat...
$q_str = urlencode( mb_convert_encoding(...
$line = str_replace($matches[2], $q_str,...
}
//InputEncodeがUTF-8以外のURLエンコード文字...
//Googleのケータイ用とLunascapeとgoo用。他に...
if( stripos($line, 'IE=Shift_JIS' ) !== FALS...
stripos($line, 'IE=SJIS' ) !== FALS...
stripos($line, 'IE=EUC-JP' ) !== FALS...
preg_match($ref, $line, $ref_matches);
preg_match( $query, $ref_matches[1], $ma...
$q_str = urlencode( mb_convert_encoding(...
$line = str_replace($matches[2], $q_str,...
}
// fwrite($outfile, mb_convert_encoding( urld...
// print ( mb_convert_encoding( urldecode( $l...
//「%」が二重にエンコードされてる謎を直す
$line = preg_replace('/%25([0-9A-F]{2})/', "...
//全角空白を半角(+)に直す
$line = str_replace('%E3%80%80', '+', $line);
// print $line;
fwrite($outfile, $line);
}
}
}
?>
***GeoIP DB更新 [#of6cfc83]
毎月初に更新されるので対応
#!/bin/bash
cd /tmp
wget http://geolite.maxmind.com/download/geoip/database/...
if [ $? == '0' ]; then
gunzip GeoIP.dat.gz
fi
mv -f GeoIP.dat /usr/local/share/GeoIP/
crontabに登録
0 0 3 * * sh /usr/local/src/GeoIPDBUpdate.sh
マージン取って毎月3日に更新してみる
***URLデコード(旧) [#n77b6c87]
暫定版~
URLエンコードされている検索文字列を~
GoogleCacheでの検索文字列も拾って~
UTF-8に変換する~
変換したあとにwebalizerで解析する
#!/usr/local/bin/php
<?php
$infile = fopen('/tmp/access_log',"r");
$outfile = fopen('/tmp/access_log.tmp',"w");
if( $infile ) {
while( !feof( $infile ) ) {
$line = fgets( $infile );
if ( !empty($line) ) {
if( strpos($line,'search?q=cache:') ) {
$line = preg_replace('/cache:.+?\+/','',...
};
fwrite($outfile, mb_convert_encoding( urldec...
// print ( mb_convert_encoding( urldecode( $l...
}
}
}
?>
終了行:
**スクリプト [#qf377e91]
#contents
----
***URLデコード [#abcd3be1]
暫定版。~
URLデコードした状態で解析すると、どうもURL長いよ警告が出...
Wikiなどの長いURLの解析をスキップしている様子。~
そこで、UTF-8以外の検索文字列を(今のところキメ打ちで)~
UTF-8に直した上でURLエンコードし、再度WebalizerにURLデコ...
ついでにごにょごにょと。
#!/usr/local/bin/php
<?php
$infile = fopen('/tmp/access_log',"r");
$outfile = fopen('/tmp/access_log.tmp',"w");
//検索文字列(Webalizer定義)
//Shift_JISで化けた文字用にチルダ入れる
$query= '/(query|q|keyword|p|MT|search|qr|text)=([\w\d%+...
//リファラ
$ref = '/\[.*?\] ".*?" [0-9]*? [0-9]*? "(.*?)"/';
//クエリ内ハッシュ
$hash = '/[\?&](q=.*#)/';
//Googleキャッシュ
$cache = '/[\?&]q=(cache:[\w\d\-]{12}:.*?\+)/';
if( $infile ) {
while( !feof( $infile ) ) {
$line = fgets( $infile );
if ( !empty($line) ) {
//GoogleSuggest機能?のハッシュ文字対策
if( preg_match($hash, $line, $hash_matches) ...
$line = str_replace($hash_matches[1], ''...
}
//Googleキャッシュの検索文字列
if( preg_match($cache, $line, $cache_matches)...
$line = str_replace($cache_matches[1], ''...
}
//EzWebのSJISのURLエンコードをUTF-8のURLエン...
if( strpos($line, '//ezsch.ezweb.ne.jp/searc...
preg_match($ref, $line, $ref_matches);
preg_match($query, $ref_matches[1], $mat...
$q_str = urlencode( mb_convert_encoding(...
$line = str_replace($matches[2], $q_str,...
}
//InputEncodeがUTF-8以外のURLエンコード文字...
//Googleのケータイ用とLunascapeとgoo用。他に...
if( stripos($line, 'IE=Shift_JIS' ) !== FALS...
stripos($line, 'IE=SJIS' ) !== FALS...
stripos($line, 'IE=EUC-JP' ) !== FALS...
preg_match($ref, $line, $ref_matches);
preg_match( $query, $ref_matches[1], $ma...
$q_str = urlencode( mb_convert_encoding(...
$line = str_replace($matches[2], $q_str,...
}
// fwrite($outfile, mb_convert_encoding( urld...
// print ( mb_convert_encoding( urldecode( $l...
//「%」が二重にエンコードされてる謎を直す
$line = preg_replace('/%25([0-9A-F]{2})/', "...
//全角空白を半角(+)に直す
$line = str_replace('%E3%80%80', '+', $line);
// print $line;
fwrite($outfile, $line);
}
}
}
?>
***GeoIP DB更新 [#of6cfc83]
毎月初に更新されるので対応
#!/bin/bash
cd /tmp
wget http://geolite.maxmind.com/download/geoip/database/...
if [ $? == '0' ]; then
gunzip GeoIP.dat.gz
fi
mv -f GeoIP.dat /usr/local/share/GeoIP/
crontabに登録
0 0 3 * * sh /usr/local/src/GeoIPDBUpdate.sh
マージン取って毎月3日に更新してみる
***URLデコード(旧) [#n77b6c87]
暫定版~
URLエンコードされている検索文字列を~
GoogleCacheでの検索文字列も拾って~
UTF-8に変換する~
変換したあとにwebalizerで解析する
#!/usr/local/bin/php
<?php
$infile = fopen('/tmp/access_log',"r");
$outfile = fopen('/tmp/access_log.tmp',"w");
if( $infile ) {
while( !feof( $infile ) ) {
$line = fgets( $infile );
if ( !empty($line) ) {
if( strpos($line,'search?q=cache:') ) {
$line = preg_replace('/cache:.+?\+/','',...
};
fwrite($outfile, mb_convert_encoding( urldec...
// print ( mb_convert_encoding( urldecode( $l...
}
}
}
?>
ページ名: