#!/usr/bin/perl ## ## ↑Perlのパスです。分からない方はサーバ管理者へお訪ね下さい。 #──【システム設定ここから】──────────────────────────# ## ## 下記の項目は変更しない方が無難です。 ## 通常は変更無しをお勧めします。 ## $use_flc = '1'; # flock関数('0'使わない / '1'使う#標準 / '2'ロックしない) $lock_dir = 'lock/'; # ロックディレクトリ $data_dir = 'data/'; # データ記録ディレクトリ $lib_dir = 'lib/'; # ライブラリディレクトリ $http_ref = ''; # アクセス制限用URL $ck_name = 'txtcntdx'; # クッキーネーム $ck_path = ''; # クッキー発行元パス $ck_days = '0'; # クッキー有効日数 $use_cookie = '1'; # クッキー再カウント防止機能('0'使わない#標準 / '1'使う) #──【システム設定ここまで】──────────────────────────# #──【プログラム開始】─────────────────────────────# ## ## ★これ以下は変更の必要はありません。 ## ★不用意に改造してしまいますと、動作しなくなる場合があります。 ## #クラス $util = util->new(); $count_up = 1; #クッキー(オプション) if($use_cookie) { require($lib_dir.'p_cookie.cgi'); } #HTTP_REFERERと照合 if(!$util->check_http_ref) { &error('');} #日付け取得 @date = gmtime(time + (60 * 60 * 9)); $date[4] += 1; $date[5] += 1900; if($date[3] < 10) {$date[3] = '0'.$date[3]; } if($date[4] < 10) {$date[4] = '0'.$date[4]; } $t_date = "cnt_$date[5]_$date[4]_$date[3]_"; undef @date; #カウント処理 $util->lock($lock_dir,'EX',$use_flc) or &error('B'); if(open(CNT,"<$data_dir$t_date".'.cgi')){ chomp(($fig,$Tdes,$Ydes,$Ades,$t_cnt,$y_cnt,$total) = ); close(CNT); $t_cnt += $count_up; open(CNT,">$data_dir$t_date".'.cgi'); print CNT "$fig\n$Tdes\n$Ydes\n$Ades\n$t_cnt\n$y_cnt\n$total\n"; close(CNT); } else { #更新処理 require($lib_dir.'p_update.cgi'); require($lib_dir.'p_des.cgi'); &update(); } $util->unlock($lock_dir,'EX',$use_flc); #出力 $total += $t_cnt; while(length($t_cnt) < $fig) { $t_cnt = '0'.$t_cnt; } while(length($y_cnt) < $fig) { $y_cnt = '0'.$y_cnt; } while(length($total) < $fig) { $total = '0'.$total; } #クッキー(オプション) if($use_cookie) { &print_cookie(); } print "Content-Type: text/plain\n\n"; if($Tdes){ print "document.write('$Tdes$t_cnt');"; } if($Ydes){ print "document.write('$Ydes$y_cnt');"; } if($Ades){ print "document.write('$Ades$total');"; } #終了 exit(0); #──【プログラム終了】─────────────────────────────# ## in('エラーメッセージ') Bは混雑,Fはファイルエラー ## out(なし) sub error { my($er_msg) = $_[0]; $util->unlock($lock_dir,'',$use_flc); #$util->unlock($lock_dir,'EX',$use_flc);#←開発用 print "Content-Type: text/plain\n\n"; print "document.write('----');"; exit(0); } package util; ## ブレス sub new { return bless {}; } ##--------------------------------------## ## in(なし) ## out('真or偽') ##--------------------------------------## sub check_http_ref { if(!$main::http_ref){ return 1; } if($main::ENV{'HTTP_REFERER'} =~ /^$main::http_ref/) { return 1; } return undef; } ##--------------------------------------## ## in('ロックディレクトリ','ロックID','flock方法') ## out('真or偽') ##--------------------------------------## sub lock { my(undef,$l_dir,$l_id,$u_fl) = @_; if($u_fl eq 2) { return 1; } my($retry) = 100; my($time_out) = 600;#ロック制限時間 my(@sta,$n_t); if($u_fl){ open($l_id,">>$l_dir$l_id.cgi") or return undef; flock($l_id,2) or return undef; $L{$l_ic} = 1; return 1; } while (-d "$l_dir$l_id") { select(undef, undef, undef, 0.1); if (--$retry <= 0) { $n_t = time;@sta = stat("$l_dir$l_id"); if(($sta[9] + $time_out) < $n_t) { rmdir("$l_dir$l_id");last; } return undef; } } if((mkdir "$l_dir$l_id",'0755')){ $L{$l_id} = 1; return 1; } return undef; } ##--------------------------------------## ## in('ロックディレクトリ','ロックID','flock方法') ## out(なし) ## ロックIDを省略すると%Lに記録されたロック全解除 ##--------------------------------------## sub unlock { my(undef,$l_dir,$l_id,$u_fl) = @_; if($u_fl eq 2) { return; } if($l_id){ if($u_fl){flock($l_id,8);close($l_id);return 1;} if (rmdir("$l_dir$l_id")) { return 1; } } else{ while(($key,$val) = each %L) { if($u_fl){ flock($key,8);close($key);} else{ rmdir("$l_dir$key"); } } } } 0;