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