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