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