# index.cgi から呼び出される # パソコンから見るためのテストモード $testmode = ""; @user_agent = split(/\//,$ENV{'HTTP_USER_AGENT'}); if ($user_agent[0] eq 'ASTEL') { # ドットi 用の処理 } elsif ($user_agent[0] eq 'UP.Browser') { # EZweb 旧端末用の処理 } elsif ($user_agent[0] =~ /^KDDI/) { # EZweb WAP2.0 対応端末用の処理 } elsif ($user_agent[0] eq 'PDXGW') { # H" 用の処理 } elsif ($user_agent[0] eq 'DoCoMo') { # i-mode 用の処理 } elsif ($user_agent[0] eq 'J-PHONE') { # J-SKY 用の処理 } elsif ($user_agent[0] eq 'L-mode') { # L-mode 用の処理 } else { # それ以外 $id = $ENV{'QUERY_STRING'}; if ($id =~ /test/){ #テストなら許可 } else { print "Content-type: text/html\n\n"; print "携帯からアクセスしてください。"; exit 0; } $testmode = "&test"; } # docomoチェック if($ENV{'REMOTE_ADDR'} =~ /^210\.153\.84\./ || $ENV{'REMOTE_ADDR'} =~ /^210\.136\.161\./ || $ENV{'REMOTE_ADDR'} =~ /^203\.138\.45\./){ # docomoならok } else { $id = $ENV{'QUERY_STRING'}; if ($id =~ /test/){ #テストなら許可 } else { exit 0; # 不正だめぽ } } print "Content-type: text/html\n\n"; # フォルダのurl $folderurl = "folder_url.txt"; open(TP,"$folderurl"); $our_url = ; chop $our_url; close(TP); $id = $ENV{'QUERY_STRING'}; # ファイル指定あり? if ($id =~ /[file|FILE]=([A-Za-z0-9\.]*)/){ $targetfilename = $1; if ($targetfilename =~ /\.cgi/i || $targetfilename =~ /\.csv/i || $targetfilename =~ /\.pl/i) { print "不正なリダイレクト"; exit 0; } } if ($id =~ /[n|N]=([A-Z0-9]*)/){ $id = $1; #id check $length = length $id; $pos = 0; $sum = 0; $sum2 = 0; %Hash1 = ( "I","0","L","1","O","2","V","3","E","4", "H","5","A","6","C","7","K","8","R","9", ); %Hash2 = ( "I",5963,"L",42731,"O",5050,"V",1919,"E",721, "H",50811,"A",6741,"C",156,"K",14142,"R",1356, ); while($length-->=0){ $id5 = substr($id,$pos++,1); $id4 = $id4.$Hash1{$id5}; $sum = $sum + $Hash2{$id5}; } $sum = ($sum * (1+$SMS_encode)) % 999999; if ($id =~ /[A-Z]*([0-9]*)/){ $sum2 = $1; } if (($sum!=$sum2) || ((length $id) <9)){ print "いたずらしちゃダメ!(つд`;)"; exit 0; } # 電番 # print $id4; } else { # n= 専用 print "不正なログインです。"; exit 0; } $host = $ENV{'HTTP_USER_AGENT'}; $adr = $ENV{'REMOTE_ADDR'}; open(TP,"$targetfilename"); foreach $topic (){ # $topic =~ s/(http.*?cgi)(\'|\")/$1\?f=$id$2/; $topic =~ s/__ID__/$id/; $topic =~ s/__URL__/$our_url/; $topic =~ s/__TEST__/$testmode/; print $topic; } close(TP); # ---- ログファイルに書き出し #日付 ($second,$minute,$hour,$dayofmonth,$month,$year,$dayofweek,$dayofyear,$isdst)= localtime(time); #localtimeで配列に時刻を取得 $year+=1900; $month++; # これをlogに書き出し # print "$year/$month/$dayofmonth $hour:$minute,$id2$id3,$host,$adr"; # 排他制御用 $lockdir = "lockdir"; $lockdir2 = "lockdir2"; $retry = 5; # リトライ回数セット while (!mkdir($lockdir, 0777)) { # 作成。出来なければ待つ if (--$retry <= 0) { # 5回ダメなら if (mkdir($lockdir2, 0777)) { # ロックを消すための排他 if ((-M $lockdir) * 86400 > 600) { # 作成時間が10分以上前なら # ロック入れ替え rename($lockdir2, $lockdir) or &error("LOCK ERROR"); last; # 一連の処理へ } else { rmdir($lockdir2); } # 部分ロック削除 } &error("BUSY"); # あきらめる } sleep(1); # 1秒待つ } #存在チェック open(TP,"$datafilename"); foreach $topic (){ if ($topic =~ m/(.*?),(.*?),.*/) { if ($2==$id4){ # めっけ! close(TP); rmdir($lockdir); # 削除 exit 0; } } } close(TP); open(OUT, ">> $datafilename"); # 追加モードで開く flock(OUT, 2); # ロック確認。ロック seek(OUT, 0, 2); # ファイルポインタを末尾にセット # print OUT "$data\n"; # 書き込む print OUT "$year/$month/$dayofmonth $hour:$minute,${id4},$host,$adr\n"; # print "$year/$month/$dayofmonth $hour:$minute,0${id2}0$id3,$host,$adr\n"; close(OUT); # closeすれば自動でロック解除 rmdir($lockdir); # 削除