-
Notifications
You must be signed in to change notification settings - Fork 4
/
topsites.cgi
executable file
·177 lines (141 loc) · 4.59 KB
/
topsites.cgi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/usr/bin/perl
#
# LightSquid Project (c) 2004-2005 Sergey Erokhin aka ESL
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# detail see in gnugpl.txt
print "Content-Type: text/html\n\n";
use File::Basename;
push (@INC,(fileparse($0))[1]);
use CGI;
require "lightsquid.cfg";
require "common.pl";
$co=new CGI;
$year =$co->param('year');
$month =$co->param('month');
$day =$co->param('day');
$sortorder =$co->param('order');
$sortorder ||='size';
InitTPL("topsites",$co->param('tpl'));
$mode =$co->param('mode');
if ($mode eq "month") {
$workperiod="##MSG_WHOLE## ##MSG_MONTH## - $year $MonthName[$month]";
$mask = "$year$month*";
} elsif ($mode eq "year") {
$workperiod="##MSG_WHOLE## ##MSG_YEAR## - $year";
$mask = "$year*";
} else {
$mode="day";
$workperiod="$day $MonthName[$month] $year";
$mask = "$year$month$day";
}
$n=1;
$printdotflag=0;
#$workperiod="$day $MonthName[$month] $year";
$sorturl ="topsites.cgi?year=$year&month=$month&day=$day";
$sorturl .="&mode=$mode" if ($mode ne "day");
$sorturl .="&order";
$sortconnecturl_L = "$sorturl=hits";
$sortconnecturl_B = "##MSG_CONNECT##";
$sortbytesurl_L = "$sorturl=size";
$sortbytesurl_B = "##MSG_BYTES##";
$sortconnectattr = ($sortorder eq "hits")?"$hTPLVARIABLE{selectedattr}":"";
$sortbytesattr = ($sortorder eq "size")?"$hTPLVARIABLE{selectedattr}":"";
@days=sort glob("$reportpath/$mask/*");
@days=reverse @days;
foreach $userpath (@days) {
next if ($userpath =~ m/^\./);
$userpath =~ m/\d\/(.*)$/;
$user=$1;
open FF,"<$userpath";
$totalsize=<FF>;chomp $totalsize;$totalsize=~s/total: //;
$total+=$totalsize;
while (<FF>) {
($site,$size,$hit)=split;
$hash{hits}{$site}+=$hit;
$hash{size}{$site}+=$size;
}
close FF;
}
$whourl = "whousesite.cgi?year=$year&month=$month&day=$day";
$whourl .="&mode=$mode" if ($mode ne "day");
$whourl .="&usersite";
$N=0;
foreach $site (sort {$hash{$sortorder}{$b} <=> $hash{$sortorder}{$a}} keys %{$hash{$sortorder}}) {
$percent =sprintf("%2.1f",int($hash{size}{$site}*1000/$total)/10);
# $percent ="0.0";
$printhit =FineDec($hash{hits}{$site});
$printsize=FineDec($hash{size}{$site});
$siteurlwho_L = "$whourl=$site";
$siteurlwho_B = "##MSG_WHO##";
$siteurl_L = "http://$site";
$siteurl_B = "$site";
$N++;
if ($N > $topsiteslimit) {
unless ($printdotflag) {
$printdotflag=1;
$rowattr = ($N & 1)?$hTPLVARIABLE{oddattr}:$hTPLVARIABLE{evenattr};
$dotN=$N; #for color flipper
$tmp=$hTPL{site};
$tmp=~s/##SITENUM##//;
$tmp=~s/##SITEURLWHO_L##//;
$tmp=~s/##SITEURLWHO_B##/\.\.\./;
$tmp=~s/##SITEURL_L##//;
$tmp=~s/##SITEURL_B##/\.\.\./;
$tmp=~s/##SITECONNECT##/\.\.\./;
$tmp=~s/##SITEBYTES##/\.\.\./;
$tmp=~s/##SITEPERCENT##//;
$tmp=~s/##ROWATTR##/$rowattr/;
$tpl{site} .= $tmp;
}
next;
}
$rowattr = ($N & 1)?$hTPLVARIABLE{oddattr}:$hTPLVARIABLE{evenattr};
$tmp=$hTPL{site};
$tmp=~s/##SITENUM##/$N/;
$tmp=~s/##SITEURLWHO_L##/$siteurlwho_L/;
$tmp=~s/##SITEURLWHO_B##/$siteurlwho_B/;
$tmp=~s/##SITEURL_L##/$siteurl_L/;
$tmp=~s/##SITEURL_B##/$siteurl_B/;
$tmp=~s/##SITECONNECT##/$printhit/;
$tmp=~s/##SITEBYTES##/$printsize/;
$tmp=~s/##SITEPERCENT##/$percent/;
$tmp=~s/##ROWATTR##/$rowattr/;
$tpl{site} .= $tmp;
}
close FF;
if ($printdotflag) {
$rowattr = (($dotN+1) & 1)?$hTPLVARIABLE{oddattr}:$hTPLVARIABLE{evenattr};
$tmp=$hTPL{site};
$tmp=~s/##SITENUM##/$N/;
$tmp=~s/##SITEURLWHO_L##/$siteurlwho_L/;
$tmp=~s/##SITEURLWHO_B##/$siteurlwho_B/;
$tmp=~s/##SITEURL_L##/$siteurl_L/;
$tmp=~s/##SITEURL_B##/$siteurl_B/;
$tmp=~s/##SITECONNECT##/$printhit/;
$tmp=~s/##SITEBYTES##/$printsize/;
$tmp=~s/##SITEPERCENT##/$percent/;
$tmp=~s/##ROWATTR##/$rowattr/;
$tpl{site} .= $tmp;
}
$totalprint=FineDec($total);
ReplaceTPL(TOTAL,$totalprint);
ReplaceTPL_URL(SORTCONNECTURL,$sortconnecturl_L,$sortconnecturl_B);
ReplaceTPL(SORTCONNECTATTR,$sortconnectattr);
ReplaceTPL_URL(SORTBYTESURL,$sortbytesurl_L,$sortbytesurl_B);
ReplaceTPL(SORTBYTESATTR,$sortbytesattr);
ReplaceTPL(DATE,$workperiod);
ApplyTPL();
PrintTPL();
__END__
2004-09-09 :: ADD skip all files starting with .
2005-04-09 :: ADD show $topsiteslimit records in log (see lightsquid.cfg)
2005-04-17 :: ADD TemplateEngine
2005-05-01 :: ADD month & year mode report
2005-08-30 :: ADD color flipper
2005-09-06 :: ADD colorselected now defined in TPL file
2005-10-02 :: ADD _L,_B