]>
Commit | Line | Data |
---|---|---|
25697a35 | 1 | /* |
c37945ed FM |
2 | * AUTHOR: Pedro Lineu Orso pedro.orso@gmail.com |
3 | * 1998, 2008 | |
94ff9470 | 4 | * SARG Squid Analysis Report Generator http://sarg.sourceforge.net |
25697a35 GS |
5 | * |
6 | * SARG donations: | |
7 | * please look at http://sarg.sourceforge.net/donations.php | |
8 | * --------------------------------------------------------------------- | |
9 | * | |
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. | |
14 | * | |
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. | |
19 | * | |
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. | |
23 | * | |
24 | */ | |
25 | ||
26 | #include "include/conf.h" | |
27 | ||
32e71fa4 | 28 | void topuser(void) |
25697a35 GS |
29 | { |
30 | ||
491b862f | 31 | FILE *fp_in = NULL, *fp_ou = NULL, *fp_top1 = NULL, *fp_top2 = NULL, *fp_top3 = NULL; |
25697a35 GS |
32 | long long int ttnbytes=0, ttnacc=0, tnacc=0; |
33 | long long int tnbytes=0, ttnelap=0, tnelap=0; | |
34 | long long int tnincache=0, tnoucache=0, ttnincache=0, ttnoucache=0; | |
35 | float perc=0.00; | |
36 | float perc2=0.00; | |
37 | float inperc=0.00, ouperc=0.00; | |
38 | int posicao=0; | |
d6e703cc | 39 | char olduser[MAXLEN], csort[MAXLEN], period[MAXLEN], arqper[MAXLEN]; |
25697a35 GS |
40 | char wger[MAXLEN], top1[MAXLEN], top2[MAXLEN], top3[MAXLEN]; |
41 | char user[MAXLEN], nacc[20], nbytes[20], preg[MAXLEN], tusr[MAXLEN]; | |
d6e703cc | 42 | char ip[MAXLEN], time[30], date[30], elap[30], incac[30], oucac[30]; |
25697a35 GS |
43 | char ipantes[MAXLEN], nameantes[MAXLEN]; |
44 | char sfield[10]="2,2"; | |
94ff9470 | 45 | char order[255]="-r"; |
491b862f | 46 | char wheader[512]=""; |
25697a35 GS |
47 | int totuser=0; |
48 | int topcount=0; | |
49 | char *s; | |
456d78a5 | 50 | int cstatus; |
7ebe75af FM |
51 | char warea[1500]; |
52 | char user2[MAXLEN]; | |
53 | char name[MAXLEN]; | |
25697a35 GS |
54 | |
55 | ipantes[0]='\0'; | |
56 | nameantes[0]='\0'; | |
57 | ||
58 | strcpy(wger,dirname); | |
59 | strcpy(top1,dirname); | |
60 | strcpy(top2,dirname); | |
61 | strcpy(top3,dirname); | |
62 | strcpy(tusr,dirname); | |
d6e703cc | 63 | strcat(wger,"/sarg-general"); |
25697a35 GS |
64 | strcat(top1,"/top"); |
65 | strcat(top2,"/top.tmp"); | |
d6e703cc | 66 | strcat(tusr,"/sarg-users"); |
25697a35 GS |
67 | strcat(top3,"/index.html"); |
68 | ||
d6e703cc | 69 | ntopuser = 0; |
25697a35 GS |
70 | if((fp_in=fopen(wger,"r"))==NULL) { |
71 | fprintf(stderr, "SARG: (topuser) %s: %s\n",text[45],wger); | |
72 | exit(1); | |
73 | } | |
74 | ||
75 | if((fp_top2=fopen(top2,"w"))==NULL) { | |
76 | fprintf(stderr, "SARG: (topuser) %s: %s\n",text[45],top2); | |
77 | exit(1); | |
78 | } | |
79 | ||
7ebe75af FM |
80 | //fscanf(fp_in,"%s%s%s%s%s%s%s%s%s%s",user,nacc,nbytes,url,ip,time,date,elap,incac,oucac); |
81 | fgets(warea,sizeof(warea),fp_in); | |
82 | if (getword(user,sizeof(user),warea,' ')<0) { | |
83 | printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wger); | |
84 | exit(1); | |
85 | } | |
25697a35 GS |
86 | |
87 | strcpy(olduser,user); | |
88 | totuser=1; | |
89 | ||
90 | while(!feof(fp_in)) { | |
7ebe75af FM |
91 | if (getword(nacc,sizeof(nacc),warea,' ')<0) { |
92 | printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wger); | |
93 | exit(1); | |
94 | } | |
95 | if (getword(nbytes,sizeof(nbytes),warea,' ')<0) { | |
96 | printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wger); | |
97 | exit(1); | |
98 | } | |
99 | if (getword(url,sizeof(url),warea,' ')<0) { | |
100 | printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wger); | |
101 | exit(1); | |
102 | } | |
103 | if (getword(ip,sizeof(ip),warea,' ')<0) { | |
104 | printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wger); | |
105 | exit(1); | |
106 | } | |
107 | if (getword(time,sizeof(time),warea,' ')<0) { | |
108 | printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wger); | |
109 | exit(1); | |
110 | } | |
111 | if (getword(date,sizeof(date),warea,' ')<0) { | |
112 | printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wger); | |
113 | exit(1); | |
114 | } | |
115 | if (getword(elap,sizeof(elap),warea,' ')<0) { | |
116 | printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wger); | |
117 | exit(1); | |
118 | } | |
119 | if (getword(incac,sizeof(incac),warea,' ')<0) { | |
120 | printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wger); | |
121 | exit(1); | |
122 | } | |
123 | if (getword(oucac,sizeof(oucac),warea,' ')<0) { | |
124 | printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wger); | |
125 | exit(1); | |
126 | } | |
25697a35 GS |
127 | if(strcmp(olduser,user) != 0) { |
128 | if(strcmp(user,"TOTAL") != 0) | |
129 | totuser++; | |
130 | ||
131 | my_lltoa(tnbytes,val1,15); | |
132 | my_lltoa(tnacc,val2,15); | |
133 | my_lltoa(tnelap,val3,15); | |
134 | my_lltoa(tnincache,val4,15); | |
135 | my_lltoa(tnoucache,val5,15); | |
7ebe75af | 136 | fprintf(fp_top2,"%s %s %s %s %s %s\n",olduser,val1,val2,val3,val4,val5); |
25697a35 GS |
137 | |
138 | strcpy(olduser,user); | |
139 | ttnbytes+=tnbytes; | |
140 | ttnacc+=tnacc; | |
141 | ttnelap+=tnelap; | |
142 | ttnincache+=tnincache; | |
143 | ttnoucache+=tnoucache; | |
144 | tnbytes=0; | |
145 | tnacc=0; | |
146 | tnelap=0; | |
147 | tnincache=0; | |
148 | tnoucache=0; | |
149 | } | |
150 | ||
151 | tnbytes+=my_atoll(nbytes); | |
152 | tnacc+=my_atoll(nacc); | |
153 | tnelap+=my_atoll(elap); | |
154 | tnincache+=my_atoll(incac); | |
155 | tnoucache+=my_atoll(oucac); | |
156 | ||
7ebe75af FM |
157 | //fscanf(fp_in,"%s%s%s%s%s%s%s%s%s%s",user,nacc,nbytes,url,ip,time,date,elap,incac,oucac); |
158 | fgets(warea,sizeof(warea),fp_in); | |
159 | if (getword(user,sizeof(user),warea,' ')<0) { | |
160 | printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wger); | |
161 | exit(1); | |
162 | } | |
25697a35 GS |
163 | |
164 | if(strcmp(user,"TOTAL") == 0) | |
165 | continue; | |
166 | } | |
167 | ||
168 | my_lltoa(tnbytes,val1,15); | |
169 | my_lltoa(tnacc,val2,15); | |
170 | my_lltoa(tnelap,val3,15); | |
171 | my_lltoa(tnincache,val4,15); | |
172 | my_lltoa(tnoucache,val5,15); | |
7ebe75af | 173 | fprintf(fp_top2,"%s %s %s %s %s %s\n",olduser,val1,val2,val3,val4,val5); |
25697a35 GS |
174 | |
175 | ttnbytes+=tnbytes; | |
176 | ttnacc+=tnacc; | |
177 | ttnelap+=tnelap; | |
178 | ttnincache+=tnincache; | |
179 | ttnoucache+=tnoucache; | |
180 | ||
181 | my_lltoa(ttnbytes,val1,15); | |
182 | my_lltoa(ttnacc,val2,15); | |
183 | my_lltoa(ttnelap,val3,15); | |
184 | my_lltoa(ttnincache,val4,15); | |
185 | my_lltoa(ttnoucache,val5,15); | |
186 | sprintf(preg,"TOTAL %s %s %s %s %s\n",val1,val2,val3,val4,val5); | |
491b862f GS |
187 | if (fp_in) fclose(fp_in); |
188 | if (fp_top2) fclose(fp_top2); | |
25697a35 GS |
189 | |
190 | strup(TopuserSortField); | |
191 | strlow(TopuserSortOrder); | |
192 | ||
193 | if(strcmp(TopuserSortField,"USER") == 0) | |
194 | strcpy(sfield,"1,1"); | |
195 | ||
196 | if(strcmp(TopuserSortField,"CONNECT") == 0) | |
197 | strcpy(sfield,"3,3"); | |
198 | ||
199 | if(strcmp(TopuserSortField,"TIME") == 0) | |
200 | strcpy(sfield,"4,4"); | |
201 | ||
202 | if(strcmp(TopuserSortOrder,"normal") == 0) | |
203 | order[0]='\0'; | |
204 | ||
94ff9470 | 205 | sprintf(csort,"sort -n -T %s %s -k %s -o '%s' '%s'", TempDir, order, sfield, top1, top2); |
456d78a5 FM |
206 | cstatus=system(csort); |
207 | if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { | |
208 | fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus)); | |
209 | fprintf(stderr, "SARG: sort command: %s\n",csort); | |
210 | exit(1); | |
211 | } | |
212 | if((fp_top1=fopen(top1,"a"))==NULL) { | |
213 | fprintf(stderr, "SARG: (topuser) %s: %s\n",text[45],top1); | |
214 | fprintf(stderr, "SARG: sort command: %s\n",csort); | |
215 | exit(1); | |
216 | } | |
25697a35 GS |
217 | |
218 | unlink(top2); | |
219 | ||
25697a35 GS |
220 | fputs(preg,fp_top1); |
221 | fclose(fp_top1); | |
222 | ||
223 | if((fp_top1=fopen(top1,"r"))==NULL) { | |
224 | fprintf(stderr, "SARG: (topuser) %s: %s\n",text[45],top1); | |
225 | exit(1); | |
226 | } | |
227 | ||
228 | if((fp_top3=fopen(top3,"w"))==NULL) { | |
229 | fprintf(stderr, "SARG: (topuser) %s: %s\n",text[45],top3); | |
230 | exit(1); | |
231 | } | |
232 | ||
233 | /* | |
234 | * get period | |
235 | */ | |
236 | ||
237 | strcpy(arqper,dirname); | |
d6e703cc | 238 | strcat(arqper,"/sarg-period"); |
25697a35 GS |
239 | |
240 | if ((fp_in = fopen(arqper, "r")) == 0) { | |
241 | fprintf(stderr, "SARG: (topuser) %s: %s\n",text[45],arqper); | |
242 | exit(1); | |
243 | } | |
244 | ||
d6e703cc | 245 | fgets(period,sizeof(period),fp_in); |
25697a35 GS |
246 | fclose(fp_in); |
247 | ||
d6e703cc | 248 | fprintf(fp_top3, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<html>\n<head>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">\n",CharSet); |
25697a35 | 249 | fputs("</head>\n",fp_top3); |
25697a35 | 250 | css(fp_top3); |
d6e703cc FM |
251 | fprintf(fp_top3,"<body class=\"body\">"); |
252 | if(strlen(LogoImage) > 0) fprintf(fp_top3, "<center><table cellpadding=\"0\" cellspacing=\"0\">\n<tr><th class=\"logo\"><img src='%s' border=0 align=absmiddle width=%s height=%s> %s</th></tr>\n<tr><td height=\"5\"></td></tr>\n</table>\n",LogoImage,Width,Height,LogoText); | |
25697a35 | 253 | |
491b862f GS |
254 | if(strcmp(IndexTree,"date") == 0) |
255 | show_sarg(fp_top3, "../../.."); | |
256 | else | |
257 | show_sarg(fp_top3, ".."); | |
25697a35 | 258 | fputs("<center><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_top3); |
d6e703cc | 259 | fprintf(fp_top3,"<tr><th align=\"center\" class=\"title\">%s</th></tr>\n",Title); |
25697a35 | 260 | |
d6e703cc | 261 | fprintf(fp_top3,"<tr><td class=\"header3\">%s: %s</td></tr>\n",text[89],period); |
25697a35 GS |
262 | strcat(wheader,(char *)text[104]); |
263 | strcat(wheader,": "); | |
264 | strcat(wheader,TopuserSortField); | |
265 | strcat(wheader,", "); | |
266 | strcat(wheader,TopuserSortOrder); | |
d6e703cc FM |
267 | fprintf(fp_top3,"<tr><td class=\"header3\">%s</td></tr>\n",wheader); |
268 | fprintf(fp_top3,"<tr><th class=\"header3\">%s</th></tr>\n",text[137]); | |
25697a35 GS |
269 | |
270 | fputs("</table></center>\n",fp_top3); | |
271 | fputs("<center><table cellpadding=\"1\" cellspacing=\"2\">\n",fp_top3); | |
272 | fputs("<tr><td><br></td><td></td></tr>\n",fp_top3); | |
273 | ||
d6e703cc FM |
274 | if(strstr(ReportType,"topsites") != 0 && strcmp(Privacy,"yes") != 0) fprintf(fp_top3,"<tr><td class=\"link\" colspan=11><a href=\"topsites.html\"><font class=\"link\">%s</font></a><font class=\"text\"></font></td></tr>\n",text[119]); |
275 | if(strstr(ReportType,"sites_users") != 0 && strcmp(Privacy,"yes") != 0) fprintf(fp_top3,"<tr><td class=\"link\" colspan=11><a href=\"siteuser.html\"><font class=\"link\">%s</font></a><font class=\"text\"></font></td></tr>\n",text[85]); | |
276 | if(dansguardian_count) fprintf(fp_top3,"<tr><td class=\"link\" colspan=11><a href=\"dansguardian.html\"><font class=\"link\">%s</font></a><font class=\"text\"></font></td></tr>\n",text[128]); | |
277 | if(squidguard_count) fprintf(fp_top3,"<tr><td class=\"link\" colspan=11><a href=\"squidguard.html\"><font class=\"link\">%s</font></a><font class=\"text\"></font></td></tr>\n",text[122]); | |
278 | if (strstr(ReportType,"downloads") != 0 && download_count && strcmp(Privacy,"yes") != 0 && ndownload) fprintf(fp_top3,"<tr><td class=\"link\" colspan=11><a href=\"download.html\"><font class=\"link\">%s</font></a><font class=\"text\"></font></td></tr>\n",text[125]); | |
279 | if (strstr(ReportType,"denied") != 0 && denied_count && strcmp(Privacy,"yes") != 0) fprintf(fp_top3,"<tr><td class=\"link\" colspan=11><a href=\"denied.html\"><font class=\"link\">%s</font></a><font class=\"text\"></font></td></tr>\n",text[118]); | |
280 | if (strstr(ReportType,"auth_failures") != 0 && authfail_count && strcmp(Privacy,"yes") != 0) fprintf(fp_top3,"<tr><td class=\"link\" colspan=11><a href=\"authfail.html\"><font class=\"link\">%s</font></a><font class=\"text\"></font></td></tr>\n",text[117]); | |
281 | if(smartfilter) fprintf(fp_top3,"<tr><td class=\"link\" colspan=11><a href=\"smartfilter.html\"><font class=\"link\">%s</font></a><font class=\"text\"></font></td></tr>\n",text[116]); | |
282 | fputs("<tr><td></td></tr>\n",fp_top3); | |
25697a35 | 283 | |
491b862f GS |
284 | if (strstr(ReportType,"topuser") == 0) { |
285 | fputs("</body>\n</html>\n",fp_top3); | |
d6e703cc | 286 | if (fp_top3) fclose (fp_top3); |
491b862f GS |
287 | return; |
288 | } | |
25697a35 GS |
289 | strcpy(val1,text[100]); |
290 | strcpy(val2,text[98]); | |
291 | strcpy(val3,text[92]); | |
292 | strcpy(val4,text[93]); | |
293 | sprintf(val11,"%%%s",text[93]); | |
294 | sprintf(val5,"%s-%s-%s",text[113],text[114],text[112]); | |
295 | strcpy(val6,text[94]); | |
296 | strcpy(val7,text[95]); | |
297 | sprintf(val8,"%%%s",text[99]); | |
298 | strcpy(val9,"colspan=2"); | |
299 | bzero(val10, 255); | |
300 | ||
301 | strcpy(hbc1,"class=\"header\""); | |
302 | strcpy(hbc2,"class=\"header\""); | |
303 | strcpy(hbc3,"class=\"header\""); | |
304 | strcpy(hbc4,"class=\"header\""); | |
305 | strcpy(hbc5,"class=\"header3\""); | |
306 | strcpy(hbc6,"class=\"header\""); | |
307 | strcpy(hbc7,"class=\"header\""); | |
308 | strcpy(hbc8,"class=\"header\""); | |
309 | strcpy(hbc9,"class=\"header\""); | |
310 | strcpy(hbc10,"class=\"header\""); | |
311 | ||
312 | if(strstr(TopUserFields,"NUM") == 0) { | |
313 | bzero(val1, 255); | |
314 | bzero(hbc1, 30); | |
315 | } | |
316 | if(strstr(TopUserFields,"USERID") == 0) { | |
317 | bzero(val2, 255); | |
318 | bzero(hbc2, 30); | |
319 | } | |
320 | if(strstr(TopUserFields,"CONNECT") == 0) { | |
321 | bzero(val3, 255); | |
322 | bzero(hbc3, 30); | |
323 | } | |
324 | if(strstr(TopUserFields,"BYTES") == 0) { | |
325 | bzero(val4, 255); | |
326 | bzero(hbc4, 30); | |
327 | } | |
328 | if(strstr(TopUserFields,"SETYB") == 0) { | |
329 | bzero(val11, 255); | |
330 | bzero(hbc9, 30); | |
331 | } | |
332 | if(strstr(TopUserFields,"IN-CACHE-OUT") == 0) { | |
333 | bzero(val5, 255); | |
334 | bzero(hbc5, 30); | |
335 | bzero(val9, 255); | |
336 | strcpy(val10,"<td></td>"); | |
337 | } | |
338 | if(strstr(TopUserFields,"USED_TIME") == 0) { | |
339 | bzero(val6, 255); | |
340 | bzero(hbc6, 30); | |
341 | } | |
342 | if(strstr(TopUserFields,"MILISEC") == 0) { | |
343 | bzero(val7, 255); | |
344 | bzero(hbc7, 30); | |
345 | } | |
346 | if(strstr(TopUserFields,"%TIME") == 0) { | |
347 | bzero(val8, 255); | |
348 | bzero(hbc8, 30); | |
349 | } | |
350 | ||
d6e703cc | 351 | fprintf(fp_top3,"<tr><th %s>%s</th><th %s></th><th %s>%s</th><th %s>%s</th><th %s>%s</th><th %s>%s</th><th %s %s>%s%s</th><th %s>%s</th><th %s>%s</th><th %s>%s</th></tr>\n",hbc1,val1,hbc1,hbc2,val2,hbc3,val3,hbc4,val4,hbc9,val11,hbc5,val9,val5,val10,hbc6,val6,hbc7,val7,hbc8,val8); |
25697a35 | 352 | |
d6e703cc | 353 | ntopuser = 0; |
25697a35 | 354 | |
d6e703cc | 355 | fscanf(fp_top1,"%s%s%s%s%s%s",user,nbytes,nacc,elap,incac,oucac); |
25697a35 | 356 | while(!feof(fp_top1)) { |
d6e703cc FM |
357 | if(atoi(nacc) < 1) { |
358 | fscanf(fp_top1,"%s%s%s%s%s%s",user,nbytes,nacc,elap,incac,oucac); | |
359 | continue; | |
360 | } else ntopuser = 1; | |
25697a35 GS |
361 | if(atoi(TopUsersNum) > 0 && topcount >= atoi(TopUsersNum)) goto final; |
362 | strcpy(user2,user); | |
363 | tnbytes=my_atoll(nbytes); | |
364 | ||
365 | if(tnbytes) { | |
366 | perc=tnbytes * 100; | |
367 | perc=perc / ttnbytes; | |
368 | } else perc = 0; | |
369 | ||
370 | if(atol(elap)) { | |
371 | perc2=atol(elap); | |
372 | perc2=((perc2 * 100) / ttnelap); | |
373 | } else perc2 = 0; | |
374 | ||
375 | if(atol(incac)) { | |
376 | inperc=atol(incac); | |
377 | inperc=((inperc * 100) / tnbytes); | |
378 | } else inperc = 0; | |
379 | ||
380 | if(atol(oucac)) { | |
381 | ouperc=atol(oucac); | |
382 | ouperc=((ouperc * 100) / tnbytes); | |
383 | } else ouperc = 0; | |
384 | ||
385 | strcpy(href," "); | |
386 | strcpy(href2," "); | |
387 | strcpy(href3," "); | |
388 | ||
389 | if(strcmp(user,"TOTAL") != 0){ | |
390 | sprintf(href,"<a href='%s/",user); | |
391 | sprintf(href2,"<a href='%s/d",user); | |
392 | sprintf(href3,"<a href='%s/graph_day.png'>",user); | |
393 | strcat(href,user); | |
394 | strcat(href2,user); | |
395 | strcat(href,".html'>"); | |
396 | strcat(href2,".html'>"); | |
397 | } | |
398 | ||
399 | if(strcmp(Graphs,"yes") != 0) | |
400 | bzero(href3,MAXLEN); | |
401 | ||
402 | posicao++; | |
403 | ||
404 | tnelap=my_atoll(elap); | |
405 | ||
406 | if(userip) { | |
407 | fixip(user2); | |
408 | if(strcmp(Ip2Name,"yes") == 0) { | |
409 | if(strcmp(user2,ipantes) != 0) { | |
410 | strcpy(ipantes,user2); | |
a1c55d8c | 411 | ip2name(user2,sizeof(user2)); |
25697a35 GS |
412 | strcpy(nameantes,user2); |
413 | } else strcpy(user2,nameantes); | |
414 | } | |
415 | } | |
416 | ||
417 | if(strstr(ReportType,"date_time") != 0) { | |
418 | sprintf(ltext110,"%s",text[110]); | |
32e71fa4 FM |
419 | for(s=ltext110; *s; ++s) |
420 | *s=tolower(*s); | |
25697a35 GS |
421 | } else { |
422 | bzero(href2, MAXLEN); | |
423 | bzero(ltext110, 50); | |
424 | sprintf(val1,"%s/d%s.html",dirname,user); | |
32e71fa4 | 425 | unlink(val1); |
25697a35 GS |
426 | } |
427 | ||
d6e703cc FM |
428 | // if(UserTabFile[0] != '\0' && strstr(user2,".") != 0) { |
429 | if(UserTabFile[0] != '\0' && strcmp(user2,"TOTAL") != 0) { | |
25697a35 GS |
430 | sprintf(warea,":%s:",user2); |
431 | if((str=(char *) strstr(userfile,warea)) != (char *) NULL ) { | |
432 | z1=0; | |
433 | str2=(char *) strstr(str+1,":"); | |
434 | str2++; | |
435 | bzero(name, MAXLEN); | |
436 | while(str2[z1] != ':') { | |
437 | name[z1]=str2[z1]; | |
438 | z1++; | |
439 | } | |
440 | } else strcpy(name,user2); | |
441 | } else strcpy(name,user2); | |
442 | ||
d6e703cc FM |
443 | if((strcmp(Ip2Name,"yes") == 0) && |
444 | ((str=(char *) strstr(name, ".")) != (char *) NULL) && | |
445 | ((str=(char *) strstr(str+1, ".")) != (char *) NULL)) | |
a1c55d8c | 446 | ip2name(name,sizeof(name)); |
25697a35 GS |
447 | |
448 | twork=my_atoll(nacc); | |
449 | my_lltoa(twork,nacc,0); | |
450 | sprintf(wwork1,"%s",fixnum(twork,1)); | |
451 | sprintf(wwork2,"%s",fixnum(tnbytes,1)); | |
d6e703cc | 452 | sprintf(wwork3,"%s",fixnum2(tnelap,1)); |
25697a35 GS |
453 | |
454 | sprintf(val1,"%d",posicao); | |
455 | #ifdef HAVE_GD | |
d6e703cc | 456 | sprintf(val2,"%s<img src=\"%s/graph.png\" border=\"0\" title=\"%s\"></a> %s<img src=\"%s/datetime.png\" border=\"0\" title=\"%s %s\">\n",href3,ImageFile,text[126],href2,ImageFile,ltext110,text[55]); |
25697a35 | 457 | #else |
d6e703cc | 458 | sprintf(val2,"%s<img src=\"%s/datetime.png\" border=\"0\" title=\"%s\">\n",href2,ImageFile,ltext110); |
25697a35 GS |
459 | #endif |
460 | ||
461 | sprintf(val3,"%3.2f%%",perc); | |
462 | sprintf(val4,"%3.2f%%",inperc); | |
463 | sprintf(val5,"%3.2f%%",ouperc); | |
464 | sprintf(val6,"%s",buildtime(tnelap)); | |
465 | sprintf(val7,"%3.2f%%",perc2); | |
466 | ||
467 | strcpy(hbc1,"class=\"data\""); | |
468 | strcpy(hbc2,"class=\"data2\""); | |
469 | strcpy(hbc3,"class=\"data\""); | |
470 | strcpy(hbc4,"class=\"data\""); | |
471 | strcpy(hbc5,"class=\"data\""); | |
472 | strcpy(hbc6,"class=\"data\""); | |
473 | strcpy(hbc7,"class=\"data\""); | |
474 | strcpy(hbc8,"class=\"data\""); | |
475 | strcpy(hbc9,"class=\"data\""); | |
476 | strcpy(hbc10,"class=\"data\""); | |
477 | ||
478 | if(strstr(TopUserFields,"NUM") == 0) { | |
479 | bzero(val1, 255); | |
480 | bzero(hbc1, 30); | |
481 | } | |
482 | if(strstr(TopUserFields,"USERID") == 0) { | |
483 | bzero(val2, 255); | |
484 | bzero(hbc2, 30); | |
485 | } | |
486 | if(strstr(TopUserFields,"CONNECT") == 0) { | |
487 | bzero(wwork1, 255); | |
488 | bzero(hbc3, 30); | |
489 | } | |
490 | if(strstr(TopUserFields,"BYTES") == 0) { | |
491 | bzero(wwork2, 255); | |
492 | bzero(hbc4, 30); | |
493 | } | |
494 | if(strstr(TopUserFields,"SETYB") == 0) { | |
495 | bzero(val3, 255); | |
496 | bzero(hbc5, 30); | |
497 | } | |
d6e703cc | 498 | |
25697a35 GS |
499 | if(strstr(TopUserFields,"IN-CACHE-OUT") == 0) { |
500 | bzero(val4, 255); | |
501 | bzero(hbc6, 30); | |
502 | } | |
503 | if(strstr(TopUserFields,"IN-CACHE-OUT") == 0) { | |
504 | bzero(val5, 255); | |
505 | bzero(hbc7, 30); | |
506 | } | |
507 | if(strstr(TopUserFields,"USED_TIME") == 0) { | |
508 | bzero(val6, 255); | |
509 | bzero(hbc8, 30); | |
510 | } | |
511 | if(strstr(TopUserFields,"MILISEC") == 0) { | |
512 | bzero(wwork3, 255); | |
513 | bzero(hbc9, 30); | |
514 | } | |
515 | if(strstr(TopUserFields,"%TIME") == 0) { | |
516 | bzero(val7, 255); | |
517 | bzero(hbc10, 30); | |
518 | } | |
519 | ||
520 | if(strstr(ReportType,"users_sites") == 0) | |
521 | href[0]='\0'; | |
522 | ||
94ff9470 GS |
523 | if(dotinuser && strstr(name,"_")) { |
524 | str2=(char *)subs(name,"_","."); | |
525 | strcpy(name,str2); | |
491b862f | 526 | free(str2); |
94ff9470 GS |
527 | } |
528 | ||
25697a35 GS |
529 | sprintf(preg,"<tr><td %s>%s</td><td %s>%s</td><td %s>%s%s</td><td %s>%s</td><td %s>%s</td><td %s>%s</td><td %s>%s</td><td %s>%s</td><td %s>%s</td><td %s>%s<td %s>%s</td></tr>\n",hbc1,val1,hbc2,val2,hbc2,href,name,hbc3,wwork1,hbc4,wwork2,hbc5,val3,hbc6,val4,hbc7,val5,hbc8,val6,hbc9,wwork3,hbc10,val7); |
530 | ||
531 | if(strstr(user,"TOTAL") != 0) { | |
532 | ||
533 | if(atol(incac)) { | |
534 | inperc=ttnbytes / 100; | |
535 | inperc=atol(incac) / inperc; | |
536 | } else inperc = 0; | |
537 | ||
538 | if(atol(oucac)) { | |
539 | ouperc=ttnbytes / 100; | |
540 | ouperc=atol(oucac) / ouperc; | |
541 | } else ouperc = 0; | |
542 | ||
543 | sprintf(wwork1,"%s",fixnum(ttnacc,1)); | |
544 | sprintf(wwork2,"%s",fixnum(ttnbytes,1)); | |
d6e703cc | 545 | sprintf(wwork3,"%s",fixnum2(ttnelap,1)); |
25697a35 GS |
546 | |
547 | strcpy(hbc1,"class=\"header2\""); | |
548 | strcpy(hbc2,"class=\"header2\""); | |
549 | strcpy(hbc3,"class=\"header2\""); | |
550 | strcpy(hbc4,"class=\"header2\""); | |
551 | strcpy(hbc5,"class=\"header2\""); | |
552 | strcpy(hbc6,"class=\"header2\""); | |
553 | strcpy(hbc7,"class=\"header2\""); | |
554 | strcpy(hbc8,"class=\"header2\""); | |
555 | strcpy(hbc9,"class=\"header2\""); | |
556 | strcpy(hbc10,"class=\"header\""); | |
557 | ||
558 | sprintf(val4,"%3.2f%%",inperc); | |
559 | sprintf(val5,"%3.2f%%",ouperc); | |
560 | sprintf(val6,"%s",buildtime(ttnelap)); | |
561 | sprintf(val7,"%3.2f%%",perc2); | |
562 | ||
563 | if(strstr(TopUserFields,"CONNECT") == 0) { | |
564 | bzero(wwork1, 255); | |
565 | bzero(hbc1, 30); | |
566 | } | |
567 | if(strstr(TopUserFields,"BYTES") == 0) { | |
568 | bzero(wwork2, 255); | |
569 | bzero(hbc2, 30); | |
570 | } | |
571 | if(strstr(TopUserFields,"IN-CACHE-OUT") == 0) { | |
572 | bzero(val4, 255); | |
573 | bzero(val5, 255); | |
574 | bzero(hbc3, 30); | |
575 | bzero(hbc4, 30); | |
576 | } | |
577 | if(strstr(TopUserFields,"USED_TIME") == 0) { | |
578 | bzero(val6, 255); | |
579 | bzero(hbc5, 30); | |
580 | } | |
581 | if(strstr(TopUserFields,"MILISEC") == 0) { | |
582 | bzero(wwork3, 255); | |
583 | bzero(hbc6, 30); | |
584 | } | |
585 | ||
586 | if(strstr(ReportType,"date_time") != 0) { | |
587 | if(strstr(TopUserFields,"TOTAL") != 0) | |
588 | sprintf(preg,"<tr><td></td><td></td><th %s>%s</th><th %s>%s</th><th %s>%15s</th><td></td><th %s>%s</th><th %s>%s</th><th %s>%s</th><th %s>%s</th></tr>\n",hbc10,text[107],hbc1,wwork1,hbc2,wwork2,hbc3,val4,hbc4,val5,hbc5,val6,hbc6,wwork3); | |
589 | } else if(strstr(TopUserFields,"TOTAL") != 0) | |
590 | sprintf(preg,"<tr><td></td><td></td><th %s>%s</th><th %s>%s</th><th %s>%15s</th><td></td><th %s>%s</th><th %s>%s</th><th %s>%s</th><th %s>%s</th></tr>\n",hbc10,text[107],hbc1,wwork1,hbc2,wwork2,hbc3,val4,hbc4,val5,hbc5,val6,hbc6,wwork3); | |
591 | } | |
592 | ||
593 | fputs(preg,fp_top3); | |
594 | ||
595 | topcount++; | |
596 | ||
d6e703cc | 597 | fscanf(fp_top1,"%s%s%s%s%s%s",user,nbytes,nacc,elap,incac,oucac); |
25697a35 GS |
598 | } |
599 | ||
d6e703cc FM |
600 | if(ttnbytes) tnbytes=ttnbytes / totuser; |
601 | else tnbytes=0; | |
25697a35 GS |
602 | |
603 | twork=ttnacc/totuser; | |
604 | twork2=ttnelap/totuser; | |
605 | sprintf(wwork1,"%s",fixnum(twork,1)); | |
606 | sprintf(wwork2,"%s",fixnum(tnbytes,1)); | |
d6e703cc | 607 | sprintf(wwork3,"%s",fixnum2(twork2,1)); |
25697a35 GS |
608 | |
609 | if(strstr(TopUserFields,"CONNECT") == 0) { | |
610 | bzero(wwork1, 255); | |
611 | bzero(hbc1, 30); | |
612 | } | |
613 | if(strstr(TopUserFields,"BYTES") == 0) { | |
614 | bzero(wwork2, 255); | |
615 | bzero(hbc2, 30); | |
616 | } | |
617 | if(strstr(TopUserFields,"IN-CACHE-OUT") == 0) { | |
618 | bzero(val4, 255); | |
619 | bzero(val5, 255); | |
620 | bzero(hbc3, 30); | |
621 | bzero(hbc4, 30); | |
622 | } | |
623 | if(strstr(TopUserFields,"USED_TIME") == 0) { | |
624 | bzero(val6, 255); | |
625 | bzero(hbc5, 30); | |
626 | } | |
627 | if(strstr(TopUserFields,"MILISEC") == 0) { | |
628 | bzero(wwork3, 255); | |
629 | bzero(hbc6, 30); | |
630 | } | |
631 | ||
d6e703cc FM |
632 | if(ntopuser) { |
633 | if((strstr(ReportType,"date_time") != 0 && strstr(TopUserFields,"AVERAGE") != 0)) fprintf(fp_top3,"<tr><td></td><th></th><th %s>%s</th><th %s>%s</th><th %s>%15s</th><td></td><td></td><td></td><th %s>%s</th><th %s>%s</th></tr>\n",hbc10,text[96],hbc1,wwork1,hbc2,wwork2,hbc3,buildtime(ttnelap/totuser),hbc4,wwork3); | |
634 | else if(strstr(TopUserFields,"AVERAGE") != 0) fprintf(fp_top3,"<tr><td></td><th></th><td></td><th %s>%s</th><th %s>%s</th><th %s>%15s</th><td></td><td></td><td></td><th %s>%s</th><th %s>%s</th></tr>\n",hbc10,text[96],hbc1,wwork1,hbc2,wwork2,hbc3,buildtime(ttnelap/totuser),hbc4,wwork3); | |
25697a35 GS |
635 | } |
636 | ||
637 | if(strlen(UserAgentLog) > 0) { | |
638 | fputs("<tr><td></td></tr>\n",fp_top3); | |
639 | fputs("<tr><td></td></tr>\n",fp_top3); | |
640 | fputs("<td align=\"left\" colspan=8><font size=-1><a href='useragent.html'>Useragent</a> Report</td>\n",fp_top3); | |
641 | } | |
642 | ||
d6e703cc | 643 | fputs("</table></center>",fp_top3); |
25697a35 GS |
644 | |
645 | show_info(fp_top3); | |
646 | ||
647 | final: | |
648 | fclose(fp_top1); | |
649 | unlink(top1); | |
650 | ||
651 | if((fp_ou=fopen(tusr,"w"))==NULL) { | |
652 | fprintf(stderr, "SARG: (topuser) %s: %s\n",text[45],tusr); | |
653 | exit(1); | |
654 | } | |
655 | ||
d6e703cc | 656 | fprintf(fp_ou,"%d\n",totuser); |
25697a35 GS |
657 | |
658 | fputs("</body>\n</html>\n",fp_top3); | |
659 | fclose(fp_top3); | |
660 | fclose(fp_ou); | |
661 | ||
662 | return; | |
663 | } |