Monthly Archives: 9月 2010

Cron muninエラー Pango-WARNING **: Invalid UTF-8 string passed to pango_layout_set

/etc/munin/plugins/hddtemp_smartctlに全角の「゜」が含まれてるらしくこれをDegCへ変更することでエラーを消すことが可能です。

Apache2 mod_geoip CentOS うざい国を弾くモジュール

GEOIPをyumのリポリトジを利用しインストール
# yum install geoip –enablerepo=rpmforge

yumで見当たらないのでmod_geoipをrpmでダウンロードしてインストールする
# wget ftp://ftp.univie.ac.at/systems/linux/fedora/epel/5/i386/mod_geoip-1.2.5-2.el5.i386.rpm
# rpm -ivh mod_geoip-1.2.5-2.el5.i386.rpm

インストールされたか確認する
# ls /usr/lib/httpd/modules/mod_geoip.so

IPのデータベースを更新する
(デフォルトのdatファイルを使ったところ誤認があったので更新することを推薦します)
# wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
# gunzip GeoIP.dat.gz
# mv -f GeoIP.dat /usr/share/GeoIP/GeoIP.dat

1ヶ月ごとに更新されるようなので1ヶ月ごとにデータベースを更新させる
# vi /etc/cron.monthly/geoip

wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
gunzip GeoIP.dat.gz
mv -f GeoIP.dat /usr/share/GeoIP/GeoIP.dat

実行権を追加する
# chmod 755 /etc/cron.monthly/geoip

Apacheの設定ファイルに下記を追記(下のサンプルは日本とアメリカ以外の殆どの国を指定してます)
# vi /etc/httpd/conf.d/mod_geoip.conf

<Location />
Order allow,deny
SetEnvIf GEOIP_COUNTRY_CODE O1 BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE AD BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE AE BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE AF BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE AG BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE AI BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE AL BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE AM BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE AN BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE AO BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE AP BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE AQ BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE AR BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE AS BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE AT BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE AU BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE AW BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE AX BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE AZ BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE BA BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE BB BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE BD BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE BE BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE BF BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE BG BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE BH BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE BI BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE BJ BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE BM BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE BN BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE BO BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE BR BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE BS BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE BT BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE BV BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE BW BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE BY BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE BZ BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE CA BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE CC BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE CD BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE CF BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE CG BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE CH BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE CI BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE CK BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE CL BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE CM BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE CN BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE CO BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE CR BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE CU BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE CV BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE CX BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE CY BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE CZ BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE DE BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE DJ BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE DK BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE DM BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE DO BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE DZ BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE EC BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE EE BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE EG BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE EH BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE ER BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE ES BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE ET BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE EU BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE FI BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE FJ BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE FK BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE FM BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE FO BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE FR BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE GA BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE GB BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE GD BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE GE BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE GF BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE GG BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE GH BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE GI BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE GL BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE GM BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE GN BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE GP BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE GQ BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE GR BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE GS BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE GT BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE GU BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE GW BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE GY BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE HK BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE HM BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE HN BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE HR BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE HT BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE HU BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE ID BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE IE BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE IL BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE IM BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE IN BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE IO BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE IQ BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE IR BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE IS BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE IT BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE JE BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE JM BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE JO BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE KE BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE KG BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE KH BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE KI BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE KM BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE KN BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE KP BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE KR BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE KW BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE KY BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE KZ BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE LA BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE LB BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE LC BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE LI BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE LK BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE LR BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE LS BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE LT BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE LU BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE LV BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE LY BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE MA BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE MC BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE MD BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE ME BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE MG BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE MH BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE MK BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE ML BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE MM BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE MN BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE MO BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE MP BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE MQ BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE MR BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE MS BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE MT BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE MU BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE MV BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE MW BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE MX BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE MY BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE MZ BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE NA BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE NC BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE NE BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE NF BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE NG BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE NI BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE NL BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE NO BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE NP BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE NR BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE NU BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE NZ BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE OM BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE PA BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE PE BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE PF BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE PG BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE PH BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE PK BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE PL BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE PM BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE PN BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE PR BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE PS BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE PT BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE PW BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE PY BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE QA BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE RE BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE RO BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE RS BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE RU BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE RW BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE SA BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE SB BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE SC BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE SD BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE SE BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE SG BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE SH BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE SI BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE SJ BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE SK BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE SL BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE SM BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE SN BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE SO BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE SR BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE ST BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE SV BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE SY BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE SZ BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE TC BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE TD BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE TF BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE TG BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE TH BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE TJ BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE TK BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE TL BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE TM BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE TN BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE TO BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE TR BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE TT BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE TV BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE TW BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE TZ BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE UA BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE UG BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE UM BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE UY BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE UZ BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE VA BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE VC BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE VE BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE VG BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE VI BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE VN BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE VU BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE WF BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE WS BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE YE BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE YT BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE ZA BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE ZM BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE ZW BlockCountry 
Deny from env=BlockCountry
Allow from all
</Location>

規制してる海外のプロキシサーバ経由でアクセスしてページがエラー403になってたら成功です

百度(ボット)を遮断 スパム?の疑惑

ただページを読みに来たのならいいのですが何を考えてるのかユーザの設置したサイト内検索のCGIで大量に”調べ物”をしていた百度のボットがたくさんおりまして頭に来たので全て遮断しました。

#!/usr/bin/perl
#####################################
# 百度ボット遮断
#####################################
# IPを指定(119.63.198.0/24)
$ip = '119.63.198.';
for ($x=1;$x<=254;$x++){
  $baidu_ip = "$ip"."$x";
  # iptablesでパケットを破棄
  $iptables = `iptables -I INPUT -s $baidu_ip -j DROP`;
}

Perlで進行状況(プログレスバー)をモジュールを使わず作る 4

#!/user/bin/perl
$max = '30';
$len = '50';
@arey = ('|', '/', '-', '\', '');
for ($num = 0;$num<=$max;$num++) {
local $| = 1;
$percent = int(($num/$max)*100);
$print = "["."%-"."$len"."s"."] "."%d%%"."r";
$bar = '*' x int(($percent/100)*$len);
if (int(($percent/100)*$len) < $len) {$bar .= @arey[$percent % 4];}
printf ($print,"$bar","$percent");
sleep(1);
}
print "nSuccess!n";

友人より教えていただいたソースを参考に*がクルクルするプログレスバーを作成しました。
※Time::HiResを使うと良いかもしれません。

Perlで進行状況(プログレスバー)をモジュールを使わず作る 3

#!/user/bin/perl
$max = '30';
$len = '50';
for ($num = 0;$num<=$max;$num++) {
local $| = 1;
$percent = int(($num/$max)*100);
$print = "["."%-"."$len"."s"."] "."%d%%"."r";
$bar = '=' x int(($percent/100)*$len);
if (int(($percent/100)*$len) < $len) {$bar .= '>';}
printf ($print,"$bar","$percent");
sleep (1);
}
print "nSuccess!n";

実際に実行すると下記の様になります。
[root@orbit ~]# perl ber.pl
[=================>                                         ] 26%

Perlで進行状況(プログレスバー)をモジュールを使わず作る 2

#!/user/bin/perl
$max = '30';
$len = '50';
for ($num = 0;$num<=$max;$num++) {
local $| = 1;
$percent = int(($num/$max)*100);
$print = "["."%-"."$len"."s"."] "."%d%%"."r";
$bar = '#' x int(($percent/100)*$len);
printf ($print,"$bar","$percent");
sleep (1);
}
print "nSuccess!n";

実際に動かすと下記のようになります。
[root@orbit ~]# perl ber.pl
[####################                                      ] 30%

Perlで進行状況(プログレスバー)をモジュールを使わず作る

yumやcpanのプログレスバーに何故かすごく憧れをいだいていたのでモジュールが無くても使えるものを準備しました^^

#!/user/bin/perl
$max = '30';
$len = '50';
for ($num = 0;$num<=$max;$num++) {
local $| = 1;
$percent = int(($num/$max)*100);
$print = "%-"."$len"."s"."["."%d%%"."]r";
$bar = '#' x int(($percent/100)*$len);
printf ($print,"$bar","$percent");
sleep (1);
}
print "nSuccess!n";

実際に動かすと下記のような感じになります。(多分イメージ的にyumとかと同じ感じになります)
[root@orbit ~]# perl bar.pl
##################################################################[100%]
Success!
[root@orbit ~]#