]> git.ipfire.org Git - thirdparty/sarg.git/blob - topuser.c
Imported Sarg 2.1.0
[thirdparty/sarg.git] / topuser.c
1 /*
2 * AUTHOR: Pedro Lineu Orso orso@penguintech.com.br
3 * 1998, 2005
4 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
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 = NULL, *fp_ou = NULL, *fp_top1 = NULL, *fp_top2 = NULL, *fp_top3 = NULL;
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";
45 char order[255]="-r";
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,"/users");
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 if (fp_in) fclose(fp_in);
158 if (fp_top2) 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
175 sprintf(csort,"sort -n -T %s %s -k %s -o '%s' '%s'", TempDir, order, sfield, top1, top2);
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);
227 sprintf(preg,"<tr><th class=\"logo\"><img src='%s' border=0 align=absmiddle width=%s height=%s>&nbsp;%s</th></tr>\n",LogoImage,Width,Height,LogoText);
228 fputs(preg,fp_top3);
229 fputs("<tr><td height=\"5\"></td></tr>\n",fp_top3);
230 fputs("</table>\n",fp_top3);
231 }
232
233 if(strcmp(IndexTree,"date") == 0)
234 show_sarg(fp_top3, "../../..");
235 else
236 show_sarg(fp_top3, "..");
237 fputs("<center><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_top3);
238 sprintf(preg,"<tr><th align=\"center\" class=\"title\">%s</th></tr>\n",Title);
239 fputs(preg,fp_top3);
240
241 sprintf(preg,"<tr><td class=\"header3\">%s: %s</td></tr>\n",text[89],periodo);
242 fputs(preg,fp_top3);
243 strcat(wheader,(char *)text[104]);
244 strcat(wheader,": ");
245 strcat(wheader,TopuserSortField);
246 strcat(wheader,", ");
247 strcat(wheader,TopuserSortOrder);
248 sprintf(preg,"<tr><td class=\"header3\">%s</td></tr>\n",wheader);
249 fputs(preg,fp_top3);
250 sprintf(preg,"<tr><td class=\"header3\">Topuser %s</td></tr>\n",text[55]);
251 fputs(preg,fp_top3);
252
253 fputs("</table></center>\n",fp_top3);
254 fputs("<center><table cellpadding=\"1\" cellspacing=\"2\">\n",fp_top3);
255 fputs("<tr><td><br></td><td></td></tr>\n",fp_top3);
256
257 if(strstr(ReportType,"topsites") != 0) {
258 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]);
259 fputs(preg,fp_top3);
260 }
261
262 if(strstr(ReportType,"sites_users") != 0) {
263 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]);
264 fputs(preg,fp_top3);
265 }
266
267 if(dansguardian_count) {
268 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]);
269 fputs(preg,fp_top3);
270 }
271
272 if(squidguard_count) {
273 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]);
274 fputs(preg,fp_top3);
275 }
276
277 if (strstr(ReportType,"downloads") != 0 && download_count) {
278 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]);
279 fputs(preg,fp_top3);
280 }
281
282 if (strstr(ReportType,"denied") != 0 && denied_count) {
283 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]);
284 fputs(preg,fp_top3);
285 }
286
287 if (strstr(ReportType,"auth_failures") != 0 && authfail_count) {
288 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]);
289 fputs(preg,fp_top3);
290 }
291
292 if(smartfilter) {
293 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]);
294 fputs(preg,fp_top3);
295 }
296 strcpy(preg,"<tr><td></td></tr>\n");
297 fputs(preg,fp_top3);
298
299 if (strstr(ReportType,"topuser") == 0) {
300 fputs("</body>\n</html>\n",fp_top3);
301 if (fp_top3)
302 fclose (fp_top3);
303 return;
304 }
305 strcpy(val1,text[100]);
306 strcpy(val2,text[98]);
307 strcpy(val3,text[92]);
308 strcpy(val4,text[93]);
309 sprintf(val11,"%%%s",text[93]);
310 sprintf(val5,"%s-%s-%s",text[113],text[114],text[112]);
311 strcpy(val6,text[94]);
312 strcpy(val7,text[95]);
313 sprintf(val8,"%%%s",text[99]);
314 strcpy(val9,"colspan=2");
315 bzero(val10, 255);
316
317 strcpy(hbc1,"class=\"header\"");
318 strcpy(hbc2,"class=\"header\"");
319 strcpy(hbc3,"class=\"header\"");
320 strcpy(hbc4,"class=\"header\"");
321 strcpy(hbc5,"class=\"header3\"");
322 strcpy(hbc6,"class=\"header\"");
323 strcpy(hbc7,"class=\"header\"");
324 strcpy(hbc8,"class=\"header\"");
325 strcpy(hbc9,"class=\"header\"");
326 strcpy(hbc10,"class=\"header\"");
327
328 if(strstr(TopUserFields,"NUM") == 0) {
329 bzero(val1, 255);
330 bzero(hbc1, 30);
331 }
332 if(strstr(TopUserFields,"USERID") == 0) {
333 bzero(val2, 255);
334 bzero(hbc2, 30);
335 }
336 if(strstr(TopUserFields,"CONNECT") == 0) {
337 bzero(val3, 255);
338 bzero(hbc3, 30);
339 }
340 if(strstr(TopUserFields,"BYTES") == 0) {
341 bzero(val4, 255);
342 bzero(hbc4, 30);
343 }
344 if(strstr(TopUserFields,"SETYB") == 0) {
345 bzero(val11, 255);
346 bzero(hbc9, 30);
347 }
348 if(strstr(TopUserFields,"IN-CACHE-OUT") == 0) {
349 bzero(val5, 255);
350 bzero(hbc5, 30);
351 bzero(val9, 255);
352 strcpy(val10,"<td></td>");
353 }
354 if(strstr(TopUserFields,"USED_TIME") == 0) {
355 bzero(val6, 255);
356 bzero(hbc6, 30);
357 }
358 if(strstr(TopUserFields,"MILISEC") == 0) {
359 bzero(val7, 255);
360 bzero(hbc7, 30);
361 }
362 if(strstr(TopUserFields,"%TIME") == 0) {
363 bzero(val8, 255);
364 bzero(hbc8, 30);
365 }
366
367 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);
368
369 fputs(preg,fp_top3);
370
371 fscanf(fp_top1,"%s",user);
372 fscanf(fp_top1,"%s",nbytes);
373 fscanf(fp_top1,"%s",nacc);
374 fscanf(fp_top1,"%s",elap);
375 fscanf(fp_top1,"%s",incac);
376 fscanf(fp_top1,"%s",oucac);
377
378 while(!feof(fp_top1)) {
379 if(atoi(TopUsersNum) > 0 && topcount >= atoi(TopUsersNum)) goto final;
380 strcpy(user2,user);
381 tnbytes=my_atoll(nbytes);
382
383 if(tnbytes) {
384 perc=tnbytes * 100;
385 perc=perc / ttnbytes;
386 } else perc = 0;
387
388 if(atol(elap)) {
389 perc2=atol(elap);
390 perc2=((perc2 * 100) / ttnelap);
391 } else perc2 = 0;
392
393 if(atol(incac)) {
394 inperc=atol(incac);
395 inperc=((inperc * 100) / tnbytes);
396 } else inperc = 0;
397
398 if(atol(oucac)) {
399 ouperc=atol(oucac);
400 ouperc=((ouperc * 100) / tnbytes);
401 } else ouperc = 0;
402
403 strcpy(href," ");
404 strcpy(href2," ");
405 strcpy(href3," ");
406
407 if(strcmp(user,"TOTAL") != 0){
408 sprintf(href,"<a href='%s/",user);
409 sprintf(href2,"<a href='%s/d",user);
410 sprintf(href3,"<a href='%s/graph_day.png'>",user);
411 strcat(href,user);
412 strcat(href2,user);
413 strcat(href,".html'>");
414 strcat(href2,".html'>");
415 }
416
417 if(strcmp(Graphs,"yes") != 0)
418 bzero(href3,MAXLEN);
419
420 posicao++;
421
422 tnelap=my_atoll(elap);
423
424 if(userip) {
425 fixip(user2);
426 if(strcmp(Ip2Name,"yes") == 0) {
427 if(strcmp(user2,ipantes) != 0) {
428 strcpy(ipantes,user2);
429 ip2name(user2);
430 strcpy(nameantes,user2);
431 } else strcpy(user2,nameantes);
432 }
433 }
434
435 if(strstr(ReportType,"date_time") != 0) {
436 sprintf(ltext110,"%s",text[110]);
437 if(ltext110){
438 for(s=ltext110; *s; ++s)
439 *s=tolower(*s);
440 }
441 } else {
442 bzero(href2, MAXLEN);
443 bzero(ltext110, 50);
444 sprintf(val1,"%s/d%s.html",dirname,user);
445 unlink(val1);
446 }
447
448 if(UserTabFile[0] != '\0' && strstr(user2,".") != 0) {
449 sprintf(warea,":%s:",user2);
450 if((str=(char *) strstr(userfile,warea)) != (char *) NULL ) {
451 z1=0;
452 str2=(char *) strstr(str+1,":");
453 str2++;
454 bzero(name, MAXLEN);
455 while(str2[z1] != ':') {
456 name[z1]=str2[z1];
457 z1++;
458 }
459 } else strcpy(name,user2);
460 } else strcpy(name,user2);
461
462 if(strcmp(Ip2Name,"yes") == 0) {
463 if((str=(char *) strstr(name, ".")) != (char *) NULL) {
464 if((str=(char *) strstr(str+1, ".")) != (char *) NULL)
465 ip2name(name);
466 }
467 }
468
469 twork=my_atoll(nacc);
470 my_lltoa(twork,nacc,0);
471 sprintf(wwork1,"%s",fixnum(twork,1));
472 sprintf(wwork2,"%s",fixnum(tnbytes,1));
473 sprintf(wwork3,"%s",fixnum(tnelap,1));
474
475 sprintf(val1,"%d",posicao);
476 #ifdef HAVE_GD
477 sprintf(val2,"%s<img src=\"%s/graph.png\" border=\"0\" title=\"%s %s\"></a>&nbsp;%s<img src=\"%s/datetime.png\" border=\"0\" title=\"%s %s\">\n",href3,ImageFile,text[126],text[55],href2,ImageFile,ltext110,text[55]);
478 #else
479 sprintf(val2,"%s<img src=\"%s/datetime.png\" border=\"0\" title=\"%s %s\">\n",href2,ImageFile,ltext110,text[55]);
480 #endif
481
482 sprintf(val3,"%3.2f%%",perc);
483 sprintf(val4,"%3.2f%%",inperc);
484 sprintf(val5,"%3.2f%%",ouperc);
485 sprintf(val6,"%s",buildtime(tnelap));
486 sprintf(val7,"%3.2f%%",perc2);
487
488 strcpy(hbc1,"class=\"data\"");
489 strcpy(hbc2,"class=\"data2\"");
490 strcpy(hbc3,"class=\"data\"");
491 strcpy(hbc4,"class=\"data\"");
492 strcpy(hbc5,"class=\"data\"");
493 strcpy(hbc6,"class=\"data\"");
494 strcpy(hbc7,"class=\"data\"");
495 strcpy(hbc8,"class=\"data\"");
496 strcpy(hbc9,"class=\"data\"");
497 strcpy(hbc10,"class=\"data\"");
498
499 if(strstr(TopUserFields,"NUM") == 0) {
500 bzero(val1, 255);
501 bzero(hbc1, 30);
502 }
503 if(strstr(TopUserFields,"USERID") == 0) {
504 bzero(val2, 255);
505 bzero(hbc2, 30);
506 }
507 if(strstr(TopUserFields,"CONNECT") == 0) {
508 bzero(wwork1, 255);
509 bzero(hbc3, 30);
510 }
511 if(strstr(TopUserFields,"BYTES") == 0) {
512 bzero(wwork2, 255);
513 bzero(hbc4, 30);
514 }
515 if(strstr(TopUserFields,"SETYB") == 0) {
516 bzero(val3, 255);
517 bzero(hbc5, 30);
518 }
519 if(strstr(TopUserFields,"IN-CACHE-OUT") == 0) {
520 bzero(val4, 255);
521 bzero(hbc6, 30);
522 }
523 if(strstr(TopUserFields,"IN-CACHE-OUT") == 0) {
524 bzero(val5, 255);
525 bzero(hbc7, 30);
526 }
527 if(strstr(TopUserFields,"USED_TIME") == 0) {
528 bzero(val6, 255);
529 bzero(hbc8, 30);
530 }
531 if(strstr(TopUserFields,"MILISEC") == 0) {
532 bzero(wwork3, 255);
533 bzero(hbc9, 30);
534 }
535 if(strstr(TopUserFields,"%TIME") == 0) {
536 bzero(val7, 255);
537 bzero(hbc10, 30);
538 }
539
540 if(strstr(ReportType,"users_sites") == 0)
541 href[0]='\0';
542
543 if(dotinuser && strstr(name,"_")) {
544 str2=(char *)subs(name,"_",".");
545 strcpy(name,str2);
546 free(str2);
547 }
548
549 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);
550
551 if(strstr(user,"TOTAL") != 0) {
552
553 if(atol(incac)) {
554 inperc=ttnbytes / 100;
555 inperc=atol(incac) / inperc;
556 } else inperc = 0;
557
558 if(atol(oucac)) {
559 ouperc=ttnbytes / 100;
560 ouperc=atol(oucac) / ouperc;
561 } else ouperc = 0;
562
563 sprintf(wwork1,"%s",fixnum(ttnacc,1));
564 sprintf(wwork2,"%s",fixnum(ttnbytes,1));
565 sprintf(wwork3,"%s",fixnum(ttnelap,1));
566
567 strcpy(hbc1,"class=\"header2\"");
568 strcpy(hbc2,"class=\"header2\"");
569 strcpy(hbc3,"class=\"header2\"");
570 strcpy(hbc4,"class=\"header2\"");
571 strcpy(hbc5,"class=\"header2\"");
572 strcpy(hbc6,"class=\"header2\"");
573 strcpy(hbc7,"class=\"header2\"");
574 strcpy(hbc8,"class=\"header2\"");
575 strcpy(hbc9,"class=\"header2\"");
576 strcpy(hbc10,"class=\"header\"");
577
578 sprintf(val4,"%3.2f%%",inperc);
579 sprintf(val5,"%3.2f%%",ouperc);
580 sprintf(val6,"%s",buildtime(ttnelap));
581 sprintf(val7,"%3.2f%%",perc2);
582
583 if(strstr(TopUserFields,"CONNECT") == 0) {
584 bzero(wwork1, 255);
585 bzero(hbc1, 30);
586 }
587 if(strstr(TopUserFields,"BYTES") == 0) {
588 bzero(wwork2, 255);
589 bzero(hbc2, 30);
590 }
591 if(strstr(TopUserFields,"IN-CACHE-OUT") == 0) {
592 bzero(val4, 255);
593 bzero(val5, 255);
594 bzero(hbc3, 30);
595 bzero(hbc4, 30);
596 }
597 if(strstr(TopUserFields,"USED_TIME") == 0) {
598 bzero(val6, 255);
599 bzero(hbc5, 30);
600 }
601 if(strstr(TopUserFields,"MILISEC") == 0) {
602 bzero(wwork3, 255);
603 bzero(hbc6, 30);
604 }
605
606 if(strstr(ReportType,"date_time") != 0) {
607 if(strstr(TopUserFields,"TOTAL") != 0)
608 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);
609 } else if(strstr(TopUserFields,"TOTAL") != 0)
610 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);
611 }
612
613 fputs(preg,fp_top3);
614
615 topcount++;
616
617 fscanf(fp_top1,"%s",user);
618 fscanf(fp_top1,"%s",nbytes);
619 fscanf(fp_top1,"%s",nacc);
620 fscanf(fp_top1,"%s",elap);
621 fscanf(fp_top1,"%s",incac);
622 fscanf(fp_top1,"%s",oucac);
623 }
624
625 if(ttnbytes) {
626 tnbytes=ttnbytes / totuser;
627 } else tnbytes=0;
628
629 twork=ttnacc/totuser;
630 twork2=ttnelap/totuser;
631 sprintf(wwork1,"%s",fixnum(twork,1));
632 sprintf(wwork2,"%s",fixnum(tnbytes,1));
633 sprintf(wwork3,"%s",fixnum(twork2,1));
634
635 if(strstr(TopUserFields,"CONNECT") == 0) {
636 bzero(wwork1, 255);
637 bzero(hbc1, 30);
638 }
639 if(strstr(TopUserFields,"BYTES") == 0) {
640 bzero(wwork2, 255);
641 bzero(hbc2, 30);
642 }
643 if(strstr(TopUserFields,"IN-CACHE-OUT") == 0) {
644 bzero(val4, 255);
645 bzero(val5, 255);
646 bzero(hbc3, 30);
647 bzero(hbc4, 30);
648 }
649 if(strstr(TopUserFields,"USED_TIME") == 0) {
650 bzero(val6, 255);
651 bzero(hbc5, 30);
652 }
653 if(strstr(TopUserFields,"MILISEC") == 0) {
654 bzero(wwork3, 255);
655 bzero(hbc6, 30);
656 }
657
658 if((strstr(ReportType,"date_time") != 0 && strstr(TopUserFields,"AVERAGE") != 0)) {
659 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);
660 fputs(preg,fp_top3);
661 } else if(strstr(TopUserFields,"AVERAGE") != 0) {
662 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);
663 fputs(preg,fp_top3);
664 }
665
666 if(strlen(UserAgentLog) > 0) {
667 fputs("<tr><td></td></tr>\n",fp_top3);
668 fputs("<tr><td></td></tr>\n",fp_top3);
669 fputs("<td align=\"left\" colspan=8><font size=-1><a href='useragent.html'>Useragent</a> Report</td>\n",fp_top3);
670 }
671
672 strcpy(preg,"</table></center>");
673 fputs(preg,fp_top3);
674
675 show_info(fp_top3);
676
677 final:
678 fclose(fp_top1);
679 unlink(top1);
680
681 if((fp_ou=fopen(tusr,"w"))==NULL) {
682 fprintf(stderr, "SARG: (topuser) %s: %s\n",text[45],tusr);
683 exit(1);
684 }
685
686 sprintf(preg,"%d\n",totuser);
687 fputs(preg,fp_ou);
688
689 fputs("</body>\n</html>\n",fp_top3);
690 fclose(fp_top3);
691 fclose(fp_ou);
692
693 return;
694 }