--JAVAscriptで呼び出すカウンタスクリプト --Tanaka's OSAX 2.01が必要です。 --ver0.11b 2006/9/27 --・IPリストの照合を変更。最期にリターンをつけて「xx.xx.xx.3」と「xx.xx.xx.32」の区別が付くようになった。 --ver0.1b 2006/9/25 --・高速化のため、IPをファイルに保存せず、propertyに(つまりメモリ上に)保存するようにした。 --・カウントファイルも、書き出すだけで、読み込みは起動時のみにした。 --・IPリストの有効/無効の判定、IPアドレス有無の判定を高速化。 --================================ -- 設定 --================================ property countFile : "jscount2.dat" --カウントファイル名 --================================ -- 設定はここまで --================================ property lastCount : "" -- カウントを覚えておく変数 property accessIPs : "" -- IPを覚えておく変数 property accessIPsDate : "" -- 最後にIPを覚えた日付を覚えておく変数 property today : "" -- 今日を覚えておく変数 property thisDir : "" --スクリプトのあるディレクトリが入る変数 property crlf : (ASCII character 13) & (ASCII character 10) on run --起動時の処理 set thisDir to (":" as alias) as string --パス取得 --カウントファイルの読み込み。なければ作成 try set lastCount to (MT Read File (thisDir & countFile)) --カウントファイルを読み込み on error errorNum --カウントファイルがなかったら set lastCount to "0" MT Write File lastCount to file (thisDir & countFile) --ファイル作成 end try end run on handle CGI request urlPath searching for getData with posted data postData from client IP address ipAddress if ipAddress is not "" then --IPアドレスが取得できていたら set ipAddress to (ipAddress as text) & return --例えばxx.xx.xx.3とxx.xx.xx.32の区別を付けるため、リターンも含ませる --IPリストが今日のものかチェック set today to current date set time of today to 0 -- 今日の0時丁度に設定 if accessIPsDate < today then --昨日以前だ。つまり本日最初のアクセス。 set accessIPsDate to current date --IPリストの日付を今日にセット set accessIPs to "" & ipAddress ----IPリストをクリアしてこのIPのみにする my countUp(1) --カウントアップと表示 else -- >=の場合。今日だ --IPチェックを行う if (offset in accessIPs of ipAddress) is not 0 then --IPがあった my countUp(0) --表示のみ else --IPがなかった set accessIPs to accessIPs & ipAddress --IPアドレスを覚えておく。リターン付き my countUp(1) --カウントアップと表示 end if end if else --IPアドレスがわからなかった my countUp(1) --カウントアップと表示 end if end handle CGI request --カウントアップ処理。mode0なら表示だけ。1ならカウントアップする on countUp(mode) if mode = 1 then --カウントアップなら set lastCount to lastCount + 1 MT Write File lastCount to file (thisDir & countFile) --カウンタファイルに上書き else --カウントアップしないなら --なにもしない。lastCountはそのまま。 end if --表示処理 --MT Write File accessIPs to file (thisDir & "_iplist") --デバッグ。リスト書きだし set retJava to "document.write('" & lastCount & "');" & crlf --JAVAscriptをセット return retJava --JAVAscript吐き出し end countUp