]>
git.ipfire.org Git - thirdparty/sarg.git/blob - topsites.c
2 * AUTHOR: Pedro Lineu Orso orso@penguintech.com.br
4 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
7 * please look at http://sarg.sourceforge.net/donations.php
8 * ---------------------------------------------------------------------
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
26 #include "include/conf.h"
53 long long int tnacc
=0;
54 long long int tnbytes
=0;
55 long long int tntime
=0;
56 long long int twork1
=0, twork2
=0, twork3
=0;
60 sprintf(geral
,"%s/geral",dirname
);
61 sprintf(sites
,"%s/sites",dirname
);
62 sprintf(geral2
,"%s/geral2",dirname
);
63 sprintf(geral3
,"%s/geral3",dirname
);
64 sprintf(per
,"%s/periodo",dirname
);
66 if (strstr(ReportType
,"topusers") == 0)
67 sprintf(report
,"%s/index.html",dirname
);
69 sprintf(report
,"%s/topsites.html",dirname
);
71 if ((fp_in
= fopen(per
, "r")) == 0) {
72 fprintf(stderr
, "SARG: (topuser) %s: %s\n",text
[45],per
);
76 fgets(periodo
,sizeof(periodo
),fp_in
);
79 sprintf(csort
,"sort -k 4,4 -o '%s' '%s'",geral2
,geral
);
82 if((fp_in
=fopen(geral2
,"r"))==NULL
) {
83 fprintf(stderr
, "SARG: (topsite) %s: %s\n",text
[8],geral2
);
87 if((fp_ou
=fopen(geral3
,"w"))==NULL
) {
88 fprintf(stderr
, "SARG: (topsite) %s: %s\n",text
[8],geral3
);
92 while(fgets(buf
,sizeof(buf
),fp_in
)!=NULL
) {
94 if(strcmp(url
,"TOTAL") == 0) {
95 getword(ttnacc
,buf
,' ');
96 getword(ttnbytes
,buf
,' ');
97 getword(ttntime
,buf
,' ');
100 getword(nacc
,buf
,' ');
101 getword(nbytes
,buf
,' ');
102 getword(url
,buf
,' ');
103 getword(ntemp
,buf
,' ');
104 getword(ntemp
,buf
,' ');
105 getword(ntemp
,buf
,' ');
106 getword(ntime
,buf
,' ');
113 if(strcmp(url
,ourl
) != 0) {
114 my_lltoa(tnacc
,val1
,15);
115 my_lltoa(tnbytes
,val2
,15);
116 my_lltoa(tntime
,val3
,15);
117 sprintf(buf
,"%s %s %s %s\n",val1
,val2
,val3
,ourl
);
125 tnacc
+=my_atoll(nacc
);
126 tnbytes
+=my_atoll(nbytes
);
127 tntime
+=my_atoll(ntime
);
130 my_lltoa(tnacc
,val1
,15);
131 my_lltoa(tnbytes
,val2
,15);
132 my_lltoa(tntime
,val3
,15);
133 sprintf(buf
,"%s %s %s %s\n",val1
,val2
,val3
,ourl
);
140 strlow(TopsitesSortField
);
141 strlow(TopsitesSortType
);
143 if(strcmp(TopsitesSortField
,"connect") == 0)
145 if(strcmp(TopsitesSortField
,"bytes") == 0)
147 if(strcmp(TopsitesSortType
,"a") == 0)
149 if(strcmp(TopsitesSortType
,"d") == 0)
152 sprintf(csort
,"sort %s -k %s -o '%s' '%s'",sortt
,sortf
,sites
,geral3
);
158 if((fp_in
=fopen(sites
,"r"))==NULL
) {
159 fprintf(stderr
, "SARG: (topsite) %s: %s\n",text
[8],sites
);
163 if((fp_ou
=fopen(report
,"w"))==NULL
) {
164 fprintf(stderr
, "SARG: (topsite) %s: %s\n",text
[8],report
);
170 fputs("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"",fp_ou
);
171 fputs(" \"http://www.w3.org/TR/html4/loose.dtd\">\n",fp_ou
);
172 fputs("<html>\n",fp_ou
);
173 fputs("<head>\n",fp_ou
);
174 sprintf(html
," <meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">\n",CharSet
);
177 fputs("</head>\n",fp_ou
);
179 sprintf(url
,"<body bgcolor=%s text=%s background='%s'>\n",BgColor
,TxColor
,BgImage
);
182 if(strlen(LogoImage
) > 0) {
183 fputs("<center><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_ou
);
184 sprintf(url
,"<tr><th class=\"logo\"><img src='%s' border=0 align=absmiddle width=%s height=%s> %s</th></tr>\n",LogoImage
,Width
,Height
,LogoText
);
186 fputs("<tr><td height=\"5\"></td></tr>\n",fp_ou
);
187 fputs("</table>\n",fp_ou
);
190 if(strcmp(IndexTree
,"date") == 0)
191 show_sarg(fp_ou
,"../../..");
193 show_sarg(fp_ou
, "..");
195 fputs("<center><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_ou
);
196 sprintf(url
,"<tr><th class=\"title\">%s</th></tr>\n",Title
);
199 sprintf(url
,"<tr><td class=\"header3\">%s: %s</td></tr>\n",text
[89],periodo
);
201 sprintf(url
,"<tr><td class=\"header3\">%s %s %s</td></tr>\n",text
[83],TopSitesNum
,text
[84]);
203 fputs("</table></center>\n",fp_ou
);
205 fputs("<center><table cellpadding=\"1\" cellspacing=\"2\">\n",fp_ou
);
206 fputs("<tr><td></td></tr>\n",fp_ou
);
207 sprintf(url
,"<tr><td class=\"header\">%s</td><th class=\"header\">%s</th> \
208 <th class=\"header\">%s</th><th class=\"header\">%s</th> \
209 <th class=\"header\">%s</th></tr>\n", \
210 text
[100],text
[91],text
[92],text
[93],text
[99]);
215 while(fgets(buf
,sizeof(buf
),fp_in
)!=NULL
) {
216 if(regs
>atoi(TopSitesNum
))
218 getword(nacc
,buf
,' ');
219 getword(nbytes
,buf
,' ');
220 getword(ntime
,buf
,' ');
221 getword(url
,buf
,' ');
223 twork1
=my_atoll(nacc
);
224 twork2
=my_atoll(nbytes
);
225 twork3
=my_atoll(ntime
);
227 sprintf(wwork1
,"%s",fixnum(twork1
,1));
228 sprintf(wwork2
,"%s",fixnum(twork2
,1));
229 sprintf(wwork3
,"%s",fixnum(twork3
,1));
231 if(strlen(BlockIt
) > 0)
232 sprintf(BlockImage
,"<a href=\"%s%s?url=%s\"><img src=\"../images/sarg-squidguard-block.png\" border=\"0\"></a> ",wwwDocumentRoot
,BlockIt
,url
);
233 else BlockImage
[0]='\0';
236 sprintf(ourl
,"<tr><td class=\"data\">%d</td><td class=\"data2\">%s<a href=\"http://%s\"><font class=\"link\">%s</font></td><td class=\"data\">%s</td><td class=\"data\">%s</td><td class=\"data\">%s</td></tr>\n",regs
,BlockImage
,url
,url
,wwork1
,wwork2
,wwork3
);
242 fputs("</table></center>\n",fp_ou
);
246 fputs("</body>\n</html>\n",fp_ou
);