#!/usr/local/bin/perl
# カウンター表示CGIスクリプト Ver.2.10(03/12/27)
# byすらむどらごん(isobe@cx.airnet.ne.jp)
# http://www4.airnet.ne.jp/isobe/soft/counter2.pl
#HTMLファイルの方で、インラインイメージとして呼び出すと、
#幅96ドット、高さ16ドットの、x-bitmap形式の
#6桁の数字の画像ファイルを返すPerlスクリプト。
#その際、アクセスログを、通し番号、
#日時、相手のホスト名(不明のときはIPアドレス)、
#ブラウザの種類とリンク元についてとることができる。
#さらに、呼び出すときの引き数で(「count.cgi?num=1」の様に)、
#ログファイルの添え字を指定できるので、
#このスクリプトで、何カ所かのカウンタを一度に処理できる。
#リンク元については、このカウンタを呼び出すHTMLファイルの
#方で、JavaScriptを用いて、
#
#のようにして参照できるようにしてください。
#あ、リンク元自体にに「&hoge=」って文字列があった場合うまくいかないかも
#しれないけど、あきらめてください(←いいかげんな)。
#まあ、どうしてもって場合は、HTMLファイルの上記にあたるところの「hoge」を
#下に2ヶ所ある「hoge」とあわせて別の文字列に変えればOKです。
#「#!/usr/local/bin/perl」のところと、カウンタファイル、
#ログファイルの指定の所は、環境にあわせて変えてください。
#パラメータとして渡された添え字
@temp = split(/=/,$ENV{'QUERY_STRING'});
$num = $temp[1];
$num =~ s/&hoge//;
#カウンターファイルとログファイルの指定
#$0はこのファイルがおいてあるディレクトリ
#$numは上の添え字に置き換えられる。
$0 =~ s/(.*)\/([^\/]*)$/${1}/;
$COUNT_FILE = "$0/../soft/count$num.txt";
$LOG_FILE = "$0/../soft/log$num.txt";
#カウンターファイルの書き替え
open(COUNT_FILE, "+< $COUNT_FILE") || die;
flock(COUNT_FILE,2);
$count = ;
$count++;
seek(COUNT_FILE,0,0);
print COUNT_FILE "$count\n";
close(COUNT_FILE);
#日時と相手のホスト名(不明のときはIPアドレス)を調べる
$dateStr = `date`;
chop($dateStr);
if ($ENV{'REMOTE_HOST'}) {
$address = $ENV{'REMOTE_HOST'};
} else {
$address = $ENV{'REMOTE_ADDR'};
}
#リンク元を調べる
@temp = split(/&hoge=/,$ENV{'QUERY_STRING'});
$refer = $temp[1];
#ログファイルへの書き込み
open(LOG_FILE, ">>$LOG_FILE") || die;
flock(LOG_FILE,2);
seek(LOG_FILE,0,2);
printf(LOG_FILE "%6d %s %s %s %s\n",$count,$dateStr,$address,$ENV{'HTTP_USER_AGENT'},$refer);
close(LOG_FILE);
#$zeroから$fiveに,$countの値の十万,一万,千,百,十,一の位の数字を
#16倍したものが入っている
$zero = ($count % 10) * 16;
$count /= 10;
$one = ($count % 10) * 16;
$count /= 10;
$two = ($count % 10) * 16;
$count /= 10;
$three = ($count % 10) * 16;
$count /= 10;
$four = ($count % 10) * 16;
$count /= 10;
$five = ($count % 10) * 16;
#イメージデータ
#「0」の文字
$xbm[0]="0x00, 0x00";
$xbm[1]="0xfe, 0xff";
$xbm[2]="0xfe, 0xff";
$xbm[3]="0xfe, 0xff";
$xbm[4]="0x0e, 0xe0";
$xbm[5]="0x0e, 0xe0";
$xbm[6]="0x0e, 0xe0";
$xbm[7]="0x0e, 0xe0";
$xbm[8]="0x0e, 0xe0";
$xbm[9]="0x0e, 0xe0";
$xbm[10]="0x0e, 0xe0";
$xbm[11]="0x0e, 0xe0";
$xbm[12]="0x0e, 0xe0";
$xbm[13]="0xfe, 0xff";
$xbm[14]="0xfe, 0xff";
$xbm[15]="0xfe, 0xff";
#「1」の文字
$xbm[16]="0x00, 0x00";
$xbm[17]="0x00, 0xe0";
$xbm[18]="0x00, 0xe0";
$xbm[19]="0x00, 0xe0";
$xbm[20]="0x00, 0xe0";
$xbm[21]="0x00, 0xe0";
$xbm[22]="0x00, 0xe0";
$xbm[23]="0x00, 0xe0";
$xbm[24]="0x00, 0xe0";
$xbm[25]="0x00, 0xe0";
$xbm[26]="0x00, 0xe0";
$xbm[27]="0x00, 0xe0";
$xbm[28]="0x00, 0xe0";
$xbm[29]="0x00, 0xe0";
$xbm[30]="0x00, 0xe0";
$xbm[31]="0x00, 0xe0";
#「2」の文字
$xbm[32]="0x00, 0x00";
$xbm[33]="0xfe, 0xff";
$xbm[34]="0xfe, 0xff";
$xbm[35]="0xfe, 0xff";
$xbm[36]="0x00, 0xe0";
$xbm[37]="0x00, 0xe0";
$xbm[38]="0x00, 0xe0";
$xbm[39]="0xfe, 0xff";
$xbm[40]="0xfe, 0xff";
$xbm[41]="0xfe, 0xff";
$xbm[42]="0x0e, 0x00";
$xbm[43]="0x0e, 0x00";
$xbm[44]="0x0e, 0x00";
$xbm[45]="0xfe, 0xff";
$xbm[46]="0xfe, 0xff";
$xbm[47]="0xfe, 0xff";
#「3」の文字
$xbm[48]="0x00, 0x00";
$xbm[49]="0xfe, 0xff";
$xbm[50]="0xfe, 0xff";
$xbm[51]="0xfe, 0xff";
$xbm[52]="0x00, 0xe0";
$xbm[53]="0x00, 0xe0";
$xbm[54]="0x00, 0xe0";
$xbm[55]="0xfe, 0xff";
$xbm[56]="0xfe, 0xff";
$xbm[57]="0xfe, 0xff";
$xbm[58]="0x00, 0xe0";
$xbm[59]="0x00, 0xe0";
$xbm[60]="0x00, 0xe0";
$xbm[61]="0xfe, 0xff";
$xbm[62]="0xfe, 0xff";
$xbm[63]="0xfe, 0xff";
#「4」の文字
$xbm[64]="0x00, 0x00";
$xbm[65]="0x0e, 0xe0";
$xbm[66]="0x0e, 0xe0";
$xbm[67]="0x0e, 0xe0";
$xbm[68]="0x0e, 0xe0";
$xbm[69]="0x0e, 0xe0";
$xbm[70]="0x0e, 0xe0";
$xbm[71]="0xfe, 0xff";
$xbm[72]="0xfe, 0xff";
$xbm[73]="0xfe, 0xff";
$xbm[74]="0x00, 0xe0";
$xbm[75]="0x00, 0xe0";
$xbm[76]="0x00, 0xe0";
$xbm[77]="0x00, 0xe0";
$xbm[78]="0x00, 0xe0";
$xbm[79]="0x00, 0xe0";
#「5」の文字
$xbm[80]="0x00, 0x00";
$xbm[81]="0xfe, 0xff";
$xbm[82]="0xfe, 0xff";
$xbm[83]="0xfe, 0xff";
$xbm[84]="0x0e, 0x00";
$xbm[85]="0x0e, 0x00";
$xbm[86]="0x0e, 0x00";
$xbm[87]="0xfe, 0xff";
$xbm[88]="0xfe, 0xff";
$xbm[89]="0xfe, 0xff";
$xbm[90]="0x00, 0xe0";
$xbm[91]="0x00, 0xe0";
$xbm[92]="0x00, 0xe0";
$xbm[93]="0xfe, 0xff";
$xbm[94]="0xfe, 0xff";
$xbm[95]="0xfe, 0xff";
#「6」の文字
$xbm[96]="0x00, 0x00";
$xbm[97]="0xfe, 0xff";
$xbm[98]="0xfe, 0xff";
$xbm[99]="0xfe, 0xff";
$xbm[100]="0x0e, 0x00";
$xbm[101]="0x0e, 0x00";
$xbm[102]="0x0e, 0x00";
$xbm[103]="0xfe, 0xff";
$xbm[104]="0xfe, 0xff";
$xbm[105]="0xfe, 0xff";
$xbm[106]="0x0e, 0xe0";
$xbm[107]="0x0e, 0xe0";
$xbm[108]="0x0e, 0xe0";
$xbm[109]="0xfe, 0xff";
$xbm[110]="0xfe, 0xff";
$xbm[111]="0xfe, 0xff";
#「7」の文字
$xbm[112]="0x00, 0x00";
$xbm[113]="0xfe, 0xff";
$xbm[114]="0xfe, 0xff";
$xbm[115]="0xfe, 0xff";
$xbm[116]="0x0e, 0xe0";
$xbm[117]="0x0e, 0xe0";
$xbm[118]="0x0e, 0xe0";
$xbm[119]="0x0e, 0xe0";
$xbm[120]="0x0e, 0xe0";
$xbm[121]="0x0e, 0xe0";
$xbm[122]="0x00, 0xe0";
$xbm[123]="0x00, 0xe0";
$xbm[124]="0x00, 0xe0";
$xbm[125]="0x00, 0xe0";
$xbm[126]="0x00, 0xe0";
$xbm[127]="0x00, 0xe0";
#「8」の文字
$xbm[128]="0x00, 0x00";
$xbm[129]="0xfe, 0xff";
$xbm[130]="0xfe, 0xff";
$xbm[131]="0xfe, 0xff";
$xbm[132]="0x0e, 0xe0";
$xbm[133]="0x0e, 0xe0";
$xbm[134]="0x0e, 0xe0";
$xbm[135]="0xfe, 0xff";
$xbm[136]="0xfe, 0xff";
$xbm[137]="0xfe, 0xff";
$xbm[138]="0x0e, 0xe0";
$xbm[139]="0x0e, 0xe0";
$xbm[140]="0x0e, 0xe0";
$xbm[141]="0xfe, 0xff";
$xbm[142]="0xfe, 0xff";
$xbm[143]="0xfe, 0xff";
#「9」の文字
$xbm[144]="0x00, 0x00";
$xbm[145]="0xfe, 0xff";
$xbm[146]="0xfe, 0xff";
$xbm[147]="0xfe, 0xff";
$xbm[148]="0x0e, 0xe0";
$xbm[149]="0x0e, 0xe0";
$xbm[150]="0x0e, 0xe0";
$xbm[151]="0xfe, 0xff";
$xbm[152]="0xfe, 0xff";
$xbm[153]="0xfe, 0xff";
$xbm[154]="0x00, 0xe0";
$xbm[155]="0x00, 0xe0";
$xbm[156]="0x00, 0xe0";
$xbm[157]="0xfe, 0xff";
$xbm[158]="0xfe, 0xff";
$xbm[159]="0xfe, 0xff";
#ヘッダの表示
print "Content-Type:image/x-xbitmap\n\n";
#ビットマップファイルの生成
print "#define access2_width 96\n";
print "#define access2_height 16\n";
print "static char access2_bits[] = {\n";
print" 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n";
for($j = 1; $j < 15; $j++){
print" $xbm[$five+$j], ";
print"$xbm[$four+$j], ";
print"$xbm[$three+$j], ";
print"$xbm[$two+$j], ";
print"$xbm[$one+$j], ";
print"$xbm[$zero+$j],\n";
}
print" ";
print" $xbm[$five+15], ";
print"$xbm[$four+15], ";
print"$xbm[$three+15], ";
print"$xbm[$two+15], ";
print"$xbm[$one+15], ";
print"$xbm[$zero+15]};\n";