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