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