• R/O
  • SSH
  • HTTPS

wutsecgi: コミット


コミットメタ情報

リビジョン18 (tree)
日時2007-05-13 22:01:12
作者wutse

ログメッセージ

[wifkyplugin]初回チェックイン

変更サマリ

差分

--- trunk/wifkyplugin/analyze/analyze.pl (nonexistent)
+++ trunk/wifkyplugin/analyze/analyze.pl (revision 18)
@@ -0,0 +1,371 @@
1+
2+BEGIN { unshift(@INC, "/cgi-bin/libs"); }
3+
4+use Jcode;
5+use Time::Local;
6+
7+%analyzeLog = ();
8+
9+&logAnalyzer;
10+
11+$useAnalyze;
12+
13+sub logAnalyzer {
14+ ### クッキー読み込み(useAnalyzeが'noAnalyze'の時はカウントしない) ###
15+ foreach(split(/;/, $ENV{'HTTP_COOKIE'})) {
16+ ($key, $val) = split(/=/);
17+ $key =~ s/\s//g;
18+ $cook{$key} = $val;
19+ }
20+
21+ if (exists $cook{useAnalyze} && $cook{useAnalyze} == 'noAnalyze') {
22+ $useAnalyze = 0;
23+ }
24+ else {
25+ $useAnalyze = 1;
26+ }
27+ #####################################################################
28+
29+ my $pageValue = "FrontPage";
30+ my $searchWordValue = "";
31+ if (exists $::form{p}) {
32+ $pageValue = $::form{p};
33+ }
34+ if (exists $ENV{HTTP_REFERER}) {
35+ $refererValue = $ENV{HTTP_REFERER};
36+ my ($refURL, $refParamStr) = split(/\?/, $refererValue);
37+ my @refParamSet = split(/\&/, $refParamStr);
38+ + my %refParam = ();
39+ for $paramSet (@refParamSet) {
40+ my ($key, $value) = split(/=/, $paramSet);
41+ $refParam{$key} = $value;
42+ }
43+ if($refURL =~ /\.google\./) {
44+ my $query = $refParam{'q'};
45+ $query =~ s/\+/ /g;
46+ $query =~ s/%([0-9a-fA-F][0-9a-fA-F])/pack("H2", $1)/eg;
47+ &Jcode::convert(\$query, "euc");
48+ $searchWordValue = $query;
49+ }
50+ elsif($refURL =~ /\.yahoo\./) {
51+ my $query = $refParam{'p'};
52+ $query =~ s/\+/ /g;
53+ $query =~ s/%([0-9a-fA-F][0-9a-fA-F])/pack("H2", $1)/eg;
54+ &Jcode::convert(\$query, "euc");
55+ $searchWordValue = $query;
56+ }
57+ }
58+ else {
59+ $refererValue = 'DIRECT_ACCESS';
60+ }
61+
62+ my $clientValue = $ENV{'REMOTE_ADDR'};
63+
64+ if (exists $ENV{REMOTE_HOST}) {
65+ $clientValue = $ENV{REMOTE_HOST};
66+ }
67+ elsif (exists $ENV{REMOTE_ADDR}) {
68+ $clientValue = $ENV{REMOTE_ADDR};
69+ }
70+
71+ my $userAgentValue = "Undefined";
72+ if (exists $ENV{HTTP_USER_AGENT}) {
73+ $userAgentValue = $ENV{HTTP_USER_AGENT};
74+ }
75+
76+ # wifkyのデフォルトで定義されているアクションとanalyzerアクションは自動的に除外する
77+ my $ignoreActionList = 'index;rindex;older;recent;\?;edt;pwd;ren;del;comment;Delete;Commit;Preview;Upload;tools;preferences;new;analyzer;' . $main::config{'REFERER_IGNORE_ACTION'};
78+ if (exists $::form{a}) {
79+ foreach(split(/;/, $ignoreActionList)) {
80+ my $ignoreAction = $_;
81+ if ($::form{a} =~ /$ignoreAction/) {
82+ $useAnalyze = 0;
83+ }
84+ }
85+ }
86+ # 添付ファイルへのアクセスは除外する
87+ if (exists $::form{f}) {
88+ $useAnalyze = 0;
89+ }
90+
91+ if ($useAnalyze) {
92+ open(LOGFP, "+<access_log.cgi") or open(LOGFP, "+>access_log.cgi") or die("Can't access log File Open.\n"); #'
93+ $| = 1; # FP に対する書き込みバッファリングをしなくする。
94+ flock(LOGFP, 2); # 排他ロック(2)
95+ seek(LOGFP, 0, 0); # ファイルポインタをファイル先頭に
96+ my @logLines = <LOGFP>;
97+ ($no,$pageName,$referer,$datetime,$clientHost,$userAgent,$searchWord) = (split(/<>/, $logLines[0]))[0,1,2,3,4,5,6];
98+ $no++;
99+ $ENV{'TZ'} = "JST-9";
100+ $time = time;
101+ unshift(@logLines, "$no<>$pageValue<>$refererValue<>$time<>$clientValue<>$userAgentValue<>$searchWordValue\n");
102+ seek(LOGFP, 0, 0); # ファイルポインタをファイル先頭に
103+ print(LOGFP @logLines);
104+ flock(LOGFP, 8); # ロック開放(8)
105+ close(LOGFP);
106+ }
107+};
108+
109+$main::action_plugin{analyzer} = \&analyzerAction;
110+
111+sub analyzerAction {
112+ my $category = "Counter";
113+ if (exists $::form{category}) {
114+ $category = $::form{category};
115+ }
116+ &print_header(divclass=>'max',title=>'アクセス解析');
117+ my $bbsEmpty = 0;
118+ open(LOGFP, "access_log.cgi") or $bbsEmpty = 1;
119+ my @logLines = <LOGFP>;
120+ close(LOGFP);
121+ &puts('<h1>アクセス解析</h1>');
122+
123+ my $URL = sprintf('http://%s%s?a=analyzer', $ENV{'HTTP_HOST'}, $ENV{'SCRIPT_NAME'});
124+ &puts(sprintf(qq(<a href="%s&category=Counter">カウンター</a>), $URL));
125+ &puts(sprintf(qq(<a href="%s&category=Referer">リンク元</a>), $URL));
126+ &puts(sprintf(qq(<a href="%s&category=Client">クライアント</a>), $URL));
127+ &puts(sprintf(qq(<a href="%s&category=UserAgent">OS・ブラウザ</a>), $URL));
128+ &puts(sprintf(qq(<a href="%s&category=Search">検索</a>), $URL));
129+ &puts(sprintf(qq(<a href="%s&category=SearchWord">検索(単語)</a>), $URL));
130+
131+ &puts("<br><br>");
132+
133+ ## ページ毎のアクセスカウンター ##
134+ if ($category eq "Counter") {
135+ &viewCounter(@logLines);
136+ }
137+ ## リンク元カウンター ##
138+ elsif ($category eq "Referer") {
139+ &viewReferer(@logLines);
140+ }
141+ ## クライアントホストカウンター ##
142+ elsif ($category eq "Client") {
143+ &viewClient(@logLines);
144+ }
145+ ## ユーザエージェントカウンター ##
146+ elsif ($category eq "UserAgent") {
147+ &viewUserAgent(@logLines);
148+ }
149+ ## サーチワードカウンター(検索条件) ##
150+ elsif ($category eq "Search") {
151+ &viewSearch(@logLines);
152+ }
153+ ## サーチワードカウンター(単語単位) ##
154+ elsif ($category eq "SearchWord") {
155+ &viewSearchWord(@logLines);
156+ }
157+};
158+
159+sub viewCounter {
160+ my (@logLines) = @_;
161+ my ($lastNo,$lastPageName,$lastReferer,$lastDatetime,$lastClientHost,$lastUserAgent,$lastSearchWord) = (split(/<>/, $logLines[0]))[0,1,2,3,4,5,6];
162+ my ($mday,$mon,$year) = (localtime(time))[3..5];
163+ my $today = timelocal(0, 0, 0, $mday, $mon, $year);
164+ my $todayCount = $lastNo;
165+ my %counter = ();
166+ foreach $logItem (@logLines) {
167+ my ($no,$pageName,$referer,$datetime,$clientHost,$userAgent,$searchWord) = (split(/<>/, $logItem))[0..6];
168+ if ($datetime < $today and $todayCount == $lastNo) {
169+ $todayCount = $lastNo - $no;
170+ }
171+ if (exists $counter{$pageName}) {
172+ $counter{$pageName}++;
173+ }
174+ else {
175+ $counter{$pageName} = 1;
176+ }
177+ }
178+ &puts(qq(<table><tr><td align="right">総アクセス数</td><td>${lastNo}</td></tr>
179+<tr><td align="right">本日のアクセス数</td><td>${todayCount}</td></tr></table><br><br>));
180+ &puts("<table>");
181+ foreach $key (sort {$counter{$b} <=> $counter{$a} || $a cmp $b} keys %counter) {
182+ $percent = int($counter{$key} * 100 / $lastNo);
183+ if (&main::object_exists($key)) {
184+ &puts(sprintf(qq(<tr><td><a href="%s">%s</a></td><td>%s(%d)</td>),
185+ &title2url($key), &textOverLength($key, 40), $counter{$key}, ${percent}));
186+ }
187+ else {
188+ &puts(sprintf("<tr><td><blink>%s</blink></td><td>%s(%d%)</td>",
189+ &textOverLength($key, 40), $counter{$key}, ${percent}));
190+ }
191+ &puts(sprintf(qq(<td><table class="counterLine" border="0" height="15"><tr><td width="%s" bgcolor="red"></td></tr></table></td>),
192+ $percent * 6))
193+ &puts("</tr>");
194+ }
195+ &puts("</table>");
196+};
197+
198+sub viewReferer {
199+ my (@logLines) = @_;
200+ my $URL = sprintf('http://%s%s', $ENV{'HTTP_HOST'}, $ENV{'SCRIPT_NAME'});
201+
202+ my ($lastNo,$lastPageName,$lastReferer,$lastDatetime,$lastClientHost,$lastUserAgent,$lastSearchWord) = (split(/<>/, $logLines[0]))[0,1,2,3,4,5,6];
203+ my %refCounter = ();
204+ foreach $logItem (@logLines) {
205+ my ($no,$pageName,$referer,$datetime,$clientHost,$userAgent,$searchWord) = (split(/<>/, $logItem))[0..6];
206+
207+ if (index($referer, $URL) == 0) {
208+ $referer = 'ページ内遷移';
209+ }
210+ if (exists $refCounter{$referer}) {
211+ $refCounter{$referer}++;
212+ }
213+ else {
214+ $refCounter{$referer} = 1;
215+ }
216+ }
217+ &puts("<table>");
218+ foreach $key (sort {$refCounter{$b} <=> $refCounter{$a} || $a cmp $b} keys %refCounter) {
219+ $percent = int($refCounter{$key} * 100 / $lastNo);
220+ if ($key eq 'DIRECT_ACCESS' or $key eq 'ページ内遷移') {
221+ &puts(sprintf(qq(<tr><td>%s</td><td>%s(%d%)</td>),
222+ $key, $refCounter{$key}, $percent));
223+ }
224+ else {
225+ &puts(sprintf(qq(<tr><td><a href="%s">%s</a></td><td>%s(%d%)</td>),
226+ $key, &textOverLength($key, 40), $refCounter{$key}, $percent));
227+ }
228+ &puts(sprintf(qq(<td><table class="counterLine" border="0" height="15"><tr><td width="%s" bgcolor="red"></td></tr></table></td>),
229+ $percent * 6))
230+ &puts("</tr>");
231+ }
232+ &puts("</table>");
233+};
234+
235+sub viewClient {
236+ my (@logLines) = @_;
237+ my ($lastNo,$lastPageName,$lastReferer,$lastDatetime,$lastClientHost,$lastUserAgent,$lastSearchWord) = (split(/<>/, $logLines[0]))[0,1,2,3,4,5,6];
238+ my %clientCounter = ();
239+ foreach $logItem (@logLines) {
240+ my ($no,$pageName,$referer,$datetime,$clientHost,$userAgent,$searchWord) = (split(/<>/, $logItem))[0..6];
241+ if (exists $clientCounter{$clientHost}) {
242+ $clientCounter{$clientHost}++;
243+ }
244+ else {
245+ $clientCounter{$clientHost} = 1;
246+ }
247+ }
248+ &puts("<table>");
249+ foreach $key (sort {$clientCounter{$b} <=> $clientCounter{$a} || $a cmp $b} keys %clientCounter) {
250+ $percent = int($clientCounter{$key} * 100 / $lastNo);
251+ &puts("<tr><td>${key}</td><td>$clientCounter{$key}(${percent}%)</td>");
252+ &puts(sprintf(qq(<td><table class="counterLine" border="0" height="15"><tr><td width="%s" bgcolor="red"></td></tr></table></td>),
253+ $percent * 6))
254+ &puts("</tr>");
255+ }
256+ &puts("</table>");
257+};
258+
259+sub viewUserAgent {
260+ my (@logLines) = @_;
261+ my ($lastNo,$lastPageName,$lastReferer,$lastDatetime,$lastClientHost,$lastUserAgent,$lastSearchWord) = (split(/<>/, $logLines[0]))[0,1,2,3,4,5,6];
262+ my %userAgentCounter = ();
263+ foreach $logItem (@logLines) {
264+ my ($no,$pageName,$referer,$datetime,$clientHost,$userAgent,$searchWord) = (split(/<>/, $logItem))[0..6];
265+ if (exists $userAgentCounter{$userAgent}) {
266+ $userAgentCounter{$userAgent}++;
267+ }
268+ else {
269+ $userAgentCounter{$userAgent} = 1;
270+ }
271+ }
272+ &puts("<table>");
273+ foreach $key (sort {$userAgentCounter{$b} <=> $userAgentCounter{$a} || $a cmp $b} keys %userAgentCounter) {
274+ $percent = int($userAgentCounter{$key} * 100 / $lastNo);
275+ &puts("<tr><td>${key}</td><td>$userAgentCounter{$key}(${percent}%)</td>");
276+ &puts(sprintf(qq(<td><table class="counterLine" border="0" height="15"><tr><td width="%s" bgcolor="red"></td></tr></table></td>),
277+ $percent * 6))
278+ &puts("</tr>");
279+ }
280+ &puts("</table>");
281+};
282+
283+sub viewSearch {
284+ my (@logLines) = @_;
285+ my ($lastNo,$lastPageName,$lastReferer,$lastDatetime,$lastClientHost,$lastUserAgent,$lastSearchWord) = (split(/<>/, $logLines[0]))[0,1,2,3,4,5,6];
286+ my $searchCount = 0;
287+ my %searchCounter = ();
288+ foreach $logItem (@logLines) {
289+ my ($no,$pageName,$referer,$datetime,$clientHost,$userAgent,$searchWord) = (split(/<>|\n/, $logItem))[0..6];
290+ if ($searchWord ne '') {
291+ $searchCount++;
292+ $searchWord = &textSort($searchWord);
293+ if (exists $searchCounter{$searchWord}) {
294+ $searchCounter{$searchWord}++;
295+ }
296+ else {
297+ $searchCounter{$searchWord} = 1;
298+ }
299+ }
300+ }
301+ &puts("<table>");
302+ foreach $key (sort {$searchCounter{$b} <=> $searchCounter{$a} || $a cmp $b} keys %searchCounter) {
303+ if ($searchCount == 0) {
304+ $percent = 0;
305+ }
306+ else {
307+ $percent = int($searchCounter{$key} * 100 / $searchCount);
308+ }
309+ &puts("<tr><td>${key}</td><td>$searchCounter{$key}(${percent}%)</td>");
310+ &puts(sprintf(qq(<td><table class="counterLine" border="0" height="15"><tr><td width="%s" bgcolor="red"></td></tr></table></td>),
311+ $percent * 6))
312+ &puts("</tr>");
313+ }
314+ &puts("</table>");
315+};
316+
317+sub viewSearchWord {
318+ my (@logLines) = @_;
319+ my ($lastNo,$lastPageName,$lastReferer,$lastDatetime,$lastClientHost,$lastUserAgent,$lastSearchWord) = (split(/<>/, $logLines[0]))[0,1,2,3,4,5,6];
320+ my $searchCount = 0;
321+ my %searchCounter = ();
322+ foreach $logItem (@logLines) {
323+ my ($no,$pageName,$referer,$datetime,$clientHost,$userAgent,$searchWord) = (split(/<>|\n/, $logItem))[0..6];
324+ if ($searchWord ne '') {
325+ my @searchWords = split(/\s|\xA1\xA1/, $searchWord);
326+ foreach $word (@searchWords) {
327+ $searchCount++;
328+ if (exists $searchCounter{$word}) {
329+ $searchCounter{$word}++;
330+ }
331+ else {
332+ $searchCounter{$word} = 1;
333+ }
334+ }
335+ }
336+ }
337+ &puts("<table>");
338+ foreach $key (sort {$searchCounter{$b} <=> $searchCounter{$a} || $a cmp $b} keys %searchCounter) {
339+ if ($searchCount == 0) {
340+ $percent = 0;
341+ }
342+ else {
343+ $percent = int($searchCounter{$key} * 100 / $searchCount);
344+ }
345+ &puts("<tr><td>${key}</td><td>$searchCounter{$key}(${percent}%)</td>");
346+ &puts(sprintf(qq(<td><table class="counterLine" border="0" height="15"><tr><td width="%s" bgcolor="red"></td></tr></table></td>),
347+ $percent * 6))
348+ &puts("</tr>");
349+ }
350+ &puts("</table>");
351+};
352+
353+## 文字列をスペース(半角/全角)で切り分け、ソートして半角スペースで繋げる ##
354+sub textSort {
355+ my ($targetText) = @_;
356+ my @targetTexts = split(/\s|\xA1\xA1/, $targetText);
357+ @targetTexts = sort(@targetTexts);
358+ return join(' ', @targetTexts);
359+};
360+
361+## 文字列を指定文字数でカットする(マルチバイト未対応) ##
362+sub textOverLength {
363+ my ($targetText, $targetLength) = @_;
364+ if (length($targetText) > $targetLength) {
365+ $targetText = substr($targetText, 0, $targetLength) . '...';
366+ }
367+ return $targetText;
368+};
369+
370+1;
\ No newline at end of file
--- trunk/wifkyplugin/google/google.pl (nonexistent)
+++ trunk/wifkyplugin/google/google.pl (revision 18)
@@ -0,0 +1,47 @@
1+$inline_plugin{"gmap"} = sub {
2+ my ($session, $width, $height, $keido, $ido, $zoom) = @_;
3+ my $gmapkey = $main::config{'GMAP_KEY'};
4+ if (!$gmapkey) {
5+ return "<blink>GoogleMap KEY undefiend.</blink>";
6+ }
7+ if ($ido) {
8+ if (!$zoom) {
9+ $zoom = 4;
10+ }
11+ &puts(sprintf(qq(<div id="map" style="width: %s; height: %s"></div>), $width, $height));
12+ &puts(qq(<script type="text/javascript"));
13+ &puts(sprintf(qq(src="http://maps.google.co.jp/maps?file=api&amp;v=1&amp;key=%s">), $gmapkey));
14+ &puts(qq(</script>));
15+ &puts(qq(<script type="text/javascript">));
16+ &puts(qq(//<![CDATA[));
17+ &puts(qq(var map = new GMap(document.getElementById("map"));));
18+ &puts(qq(map.addControl(new GSmallMapControl());));
19+ &puts(sprintf(qq(map.centerAndZoom(new GPoint(%s, %s), %s);), $keido, $ido, $zoom));
20+ &puts(qq(//]]>));
21+ &puts(qq(</script>));
22+ }
23+ else {
24+ &puts("<blink>Syntax Error!: ((gmap <i>width height keido ido zoom</i>))</blink>");
25+ }
26+};
27+
28+$inline_plugin{"ganalytics"} = sub {
29+ my ($session, $trackingCode) = @_;
30+ if ($trackingCode) {
31+ &puts(qq(<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">));
32+ &puts(qq(</script>));
33+ &puts(qq(<script type="text/javascript">));
34+ &puts(sprintf(qq( _uacct="%s";), $trackingCode));
35+ &puts(qq( urchinTracker();));
36+ &puts(qq(</script>));
37+ }
38+ else {
39+ &puts("<blink>No TrackingCode: ((ganalytics <i>TrackingCode</i>))</blink>");
40+ }
41+};
42+
43+$main::preferences{'GoogleMapKey'}= [
44+ { desc=>'GoogleMap KEY' , type=>'text' , name=>'GMAP_KEY' , size=>120 },
45+];
46+
47+1;
\ No newline at end of file
旧リポジトリブラウザで表示