#!/usr/local/bin/perl ############################################### # click3.cgi # V1.2 (2003.1.21) # Copyright(C) CGI-design ############################################### $base = './clickdata'; $day_file = "$base/day.txt"; #本日 $menu_file = "$base/menu.txt"; #メニュー $opfile = "$base/option.txt"; #オプション $lockfile = "$base/lock"; #ロック $mday = (localtime)[3]; open IN,"$day_file"; $data = ; close IN; if (!$data) {chmod(0666,$day_file); open OUT,">$day_file"; print OUT $mday; close OUT;} open IN,"$opfile"; ($lockmode,$pass) = split(/<>/,); close IN; ### 日替り・月替り処理 ### open IN,"$day_file"; $pre_day = ; close IN; if ($pre_day != $mday) { open OUT,">$day_file"; print OUT $mday; close OUT; &lock; open IN,"$menu_file"; while () { ($file_name,$dsp_name) = split(/<>/); $cntfile = "$base/$file_name"; open INC, "$cntfile"; ($cnt,$cnt_pre,$cnt_day,$cnt_mon) = split(/,/,); close INC; if ($pre_day > $mday) {$data = "$cnt,$cnt_pre,$cnt,$cnt";} else {$data = "$cnt,$cnt_pre,$cnt,$cnt_mon";} open OUT, ">$cntfile"; print OUT $data; close OUT; } close IN; &unlock; } ### メイン処理 ### $in = $ENV{'QUERY_STRING'}; ($w,$in_url) = split(/&url=/,$in); ($n,$file) = split(/=/,$w); if ($file) { $cntfile = "$base/$file"; if (-e $cntfile) { &lock; open IN,"$cntfile"; ($cnt,$cnt_pre,$cnt_day,$cnt_mon) = split(/,/,); close IN; $cnt++; open OUT,">$cntfile"; print OUT "$cnt,$cnt_pre,$cnt_day,$cnt_mon"; close OUT; &unlock; } else { open OUT,">$cntfile"; print OUT "1,0,0,0"; close OUT; chmod(0666,$cntfile); open OUT,">>$menu_file"; print OUT "$file<><>$in_url<><><><>\n"; close OUT; } } print "Location: $in_url\n\n"; exit; ### sub lock { if (!$lockmode) {return;} $retry = 3; if (-e $lockfile) { $locktime = (stat($lockfile))[9]; if ($locktime < time - 60) {&unlock;} } while (!mkdir($lockfile,0755)) { if (--$retry < 0) {&error("busy!");} sleep(1); } } ### sub unlock {if ($lockmode) {rmdir($lockfile);}}