]> git.ipfire.org Git - thirdparty/sarg.git/blame - topuser.c
Don't show empty colums in top users report when columns are not requested in sarg...
[thirdparty/sarg.git] / topuser.c
CommitLineData
25697a35 1/*
c37945ed 2 * AUTHOR: Pedro Lineu Orso pedro.orso@gmail.com
a6e5c172 3 * 1998, 2010
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"
5f3cfd1d 27#include "include/defs.h"
25697a35 28
32e71fa4 29void topuser(void)
25697a35
GS
30{
31
491b862f 32 FILE *fp_in = NULL, *fp_ou = NULL, *fp_top1 = NULL, *fp_top2 = NULL, *fp_top3 = NULL;
25697a35
GS
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;
6e792ade
FM
36 long long int nbytes;
37 long long int nacc;
38 long long int elap, incac, oucac;
9f20cdae
FM
39 double perc=0.00;
40 double perc2=0.00;
41 double inperc=0.00, ouperc=0.00;
25697a35 42 int posicao=0;
d6e703cc 43 char olduser[MAXLEN], csort[MAXLEN], period[MAXLEN], arqper[MAXLEN];
25697a35 44 char wger[MAXLEN], top1[MAXLEN], top2[MAXLEN], top3[MAXLEN];
9f20cdae 45 char user[MAXLEN], tusr[MAXLEN];
6e792ade 46 char ip[MAXLEN], time[30], date[30];
25697a35
GS
47 char ipantes[MAXLEN], nameantes[MAXLEN];
48 char sfield[10]="2,2";
94ff9470 49 char order[255]="-r";
25697a35
GS
50 int totuser=0;
51 int topcount=0;
52 char *s;
456d78a5 53 int cstatus;
4157aa09 54 char warea[MAXLEN];
7ebe75af
FM
55 char user2[MAXLEN];
56 char name[MAXLEN];
9c7c6346 57 struct getwordstruct gwarea;
25697a35
GS
58
59 ipantes[0]='\0';
60 nameantes[0]='\0';
61
9f20cdae
FM
62 /*
63 * get period
64 */
65 strcpy(arqper,dirname);
66 strcat(arqper,"/sarg-period");
67 if ((fp_in = fopen(arqper, "r")) == 0) {
68 fprintf(stderr, "SARG: (topuser) %s: %s\n",text[45],arqper);
69 exit(1);
70 }
71 if (!fgets(period,sizeof(period),fp_in)) {
72 fprintf(stderr,"SARG: (topuser) Read error in %s\n",arqper);
73 exit(1);
74 }
75 fclose(fp_in);
76
25697a35
GS
77 strcpy(wger,dirname);
78 strcpy(top1,dirname);
79 strcpy(top2,dirname);
80 strcpy(top3,dirname);
81 strcpy(tusr,dirname);
d6e703cc 82 strcat(wger,"/sarg-general");
25697a35
GS
83 strcat(top1,"/top");
84 strcat(top2,"/top.tmp");
d6e703cc 85 strcat(tusr,"/sarg-users");
25697a35
GS
86 strcat(top3,"/index.html");
87
d6e703cc 88 ntopuser = 0;
25697a35 89 if((fp_in=fopen(wger,"r"))==NULL) {
936c9905
FM
90 fprintf(stderr, "SARG: (topuser) %s: %s\n",text[45],wger);
91 exit(1);
25697a35
GS
92 }
93
94 if((fp_top2=fopen(top2,"w"))==NULL) {
936c9905
FM
95 fprintf(stderr, "SARG: (topuser) %s: %s\n",text[45],top2);
96 exit(1);
25697a35
GS
97 }
98
fb7c5f27
FM
99 olduser[0]='\0';
100 totuser=0;
25697a35 101
fb7c5f27 102 while(fgets(warea,sizeof(warea),fp_in)) {
9c7c6346
FM
103 getword_start(&gwarea,warea);
104 if (getword(user,sizeof(user),&gwarea,'\t')<0) {
fb7c5f27
FM
105 printf("SARG: Maybe you have a broken user in your %s file.\n",wger);
106 exit(1);
107 }
108 if(strcmp(user,"TOTAL") == 0) {
109 continue;
110 }
6e792ade 111 if (getword_atoll(&nacc,&gwarea,'\t')<0) {
4157aa09 112 printf("SARG: Maybe you have a broken number of access in your %s file.\n",wger);
7ebe75af
FM
113 exit(1);
114 }
6e792ade 115 if (getword_atoll(&nbytes,&gwarea,'\t')<0) {
4157aa09 116 printf("SARG: Maybe you have a broken number of bytes in your %s file.\n",wger);
7ebe75af
FM
117 exit(1);
118 }
9c7c6346 119 if (getword(url,sizeof(url),&gwarea,'\t')<0) {
4157aa09 120 printf("SARG: Maybe you have a broken url in your %s file.\n",wger);
7ebe75af
FM
121 exit(1);
122 }
9c7c6346 123 if (getword(ip,sizeof(ip),&gwarea,'\t')<0) {
4157aa09 124 printf("SARG: Maybe you have a broken user's IP in your %s file.\n",wger);
7ebe75af
FM
125 exit(1);
126 }
9c7c6346 127 if (getword(time,sizeof(time),&gwarea,'\t')<0) {
4157aa09 128 printf("SARG: Maybe you have a broken time in your %s file.\n",wger);
7ebe75af
FM
129 exit(1);
130 }
9c7c6346 131 if (getword(date,sizeof(date),&gwarea,'\t')<0) {
4157aa09 132 printf("SARG: Maybe you have a broken date in your %s file.\n",wger);
7ebe75af
FM
133 exit(1);
134 }
6e792ade 135 if (getword_atoll(&elap,&gwarea,'\t')<0) {
4157aa09 136 printf("SARG: Maybe you have a broken download duration in your %s file.\n",wger);
7ebe75af
FM
137 exit(1);
138 }
6e792ade 139 if (getword_atoll(&incac,&gwarea,'\t')<0) {
4157aa09 140 printf("SARG: Maybe you have a broken in cache download in your %s file.\n",wger);
7ebe75af
FM
141 exit(1);
142 }
6e792ade 143 if (getword_atoll(&oucac,&gwarea,'\n')<0) {
4157aa09 144 printf("SARG: Maybe you have a broken not in cache download in your %s file.\n",wger);
7ebe75af
FM
145 exit(1);
146 }
25697a35 147 if(strcmp(olduser,user) != 0) {
fb7c5f27
FM
148 totuser++;
149
150 if (olduser[0] != '\0') {
151 my_lltoa(tnbytes,val1,15);
152 my_lltoa(tnacc,val2,15);
153 my_lltoa(tnelap,val3,15);
154 my_lltoa(tnincache,val4,15);
155 my_lltoa(tnoucache,val5,15);
120d768c 156 fprintf(fp_top2,"%s\t%s\t%s\t%s\t%s\t%s\n",olduser,val1,val2,val3,val4,val5);
fb7c5f27
FM
157
158 ttnbytes+=tnbytes;
159 ttnacc+=tnacc;
160 ttnelap+=tnelap;
161 ttnincache+=tnincache;
162 ttnoucache+=tnoucache;
163 }
354c1a68 164 strcpy(olduser,user);
25697a35
GS
165 tnbytes=0;
166 tnacc=0;
4157aa09 167 tnelap=0;
25697a35
GS
168 tnincache=0;
169 tnoucache=0;
170 }
171
6e792ade
FM
172 tnbytes+=nbytes;
173 tnacc+=nacc;
174 tnelap+=elap;
175 tnincache+=incac;
176 tnoucache+=oucac;
25697a35 177 }
9f20cdae 178 fclose(fp_in);
25697a35 179
fb7c5f27
FM
180 if (olduser[0] != '\0') {
181 my_lltoa(tnbytes,val1,15);
182 my_lltoa(tnacc,val2,15);
183 my_lltoa(tnelap,val3,15);
184 my_lltoa(tnincache,val4,15);
185 my_lltoa(tnoucache,val5,15);
120d768c 186 fprintf(fp_top2,"%s\t%s\t%s\t%s\t%s\t%s\n",olduser,val1,val2,val3,val4,val5);
fb7c5f27
FM
187
188 ttnbytes+=tnbytes;
189 ttnacc+=tnacc;
190 ttnelap+=tnelap;
191 ttnincache+=tnincache;
192 ttnoucache+=tnoucache;
fb7c5f27 193 }
9f20cdae 194 fclose(fp_top2);
25697a35
GS
195
196 strup(TopuserSortField);
197 strlow(TopuserSortOrder);
198
199 if(strcmp(TopuserSortField,"USER") == 0)
200 strcpy(sfield,"1,1");
201
202 if(strcmp(TopuserSortField,"CONNECT") == 0)
203 strcpy(sfield,"3,3");
204
205 if(strcmp(TopuserSortField,"TIME") == 0)
206 strcpy(sfield,"4,4");
207
208 if(strcmp(TopuserSortOrder,"normal") == 0)
209 order[0]='\0';
210
9a2efbd0 211 sprintf(csort,"sort -n -T \"%s\" %s -k %s -o \"%s\" \"%s\"", TempDir, order, sfield, top1, top2);
456d78a5
FM
212 cstatus=system(csort);
213 if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
214 fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus));
215 fprintf(stderr, "SARG: sort command: %s\n",csort);
216 exit(1);
217 }
25697a35 218
fb7c5f27
FM
219 if((fp_top1=fopen(top1,"r"))==NULL) {
220 fprintf(stderr, "SARG: (topuser) %s: %s\n",text[45],top1);
221 exit(1);
222 }
223
9f20cdae
FM
224 unlink(top2);
225
fb7c5f27
FM
226 if((fp_top3=fopen(top3,"w"))==NULL) {
227 fprintf(stderr, "SARG: (topuser) %s: %s\n",text[45],top3);
228 exit(1);
229 }
230
d6e703cc 231 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 232 css(fp_top3);
dfb337be
FM
233 fprintf(fp_top3,"</head>\n<body class=\"body\">");
234 write_logo_image(fp_top3);
25697a35 235
0349fa24 236 if(IndexTree == INDEX_TREE_DATE)
491b862f
GS
237 show_sarg(fp_top3, "../../..");
238 else
239 show_sarg(fp_top3, "..");
dfb337be 240 fputs("<div align=\"center\"><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_top3);
d6e703cc 241 fprintf(fp_top3,"<tr><th align=\"center\" class=\"title\">%s</th></tr>\n",Title);
d6e703cc 242 fprintf(fp_top3,"<tr><td class=\"header3\">%s: %s</td></tr>\n",text[89],period);
9f20cdae 243 fprintf(fp_top3,"<tr><td class=\"header3\">%s: %s, %s</td></tr>\n",text[104],TopuserSortField,TopuserSortOrder);
d6e703cc 244 fprintf(fp_top3,"<tr><th class=\"header3\">%s</th></tr>\n",text[137]);
dfb337be 245 fputs("</table></div>\n",fp_top3);
9f20cdae 246
dfb337be 247 fputs("<div align=\"center\"><table cellpadding=\"1\" cellspacing=\"2\">\n",fp_top3);
9f20cdae 248 fputs("<tr><td>&nbsp;</td><td>&nbsp;</td></tr>\n",fp_top3);
25697a35 249
085c1e1f
FM
250 if((ReportType & REPORT_TYPE_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]);
251 if((ReportType & REPORT_TYPE_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]);
dfb337be 252 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]);
d6e703cc 253 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]);
085c1e1f
FM
254 if ((ReportType & REPORT_TYPE_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]);
255 if ((ReportType & REPORT_TYPE_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]);
256 if ((ReportType & REPORT_TYPE_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]);
dfb337be 257 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]);
d6e703cc 258 fputs("<tr><td></td></tr>\n",fp_top3);
25697a35 259
085c1e1f 260 if ((ReportType & REPORT_TYPE_TOPUSERS) == 0) {
491b862f 261 fputs("</body>\n</html>\n",fp_top3);
9f20cdae 262 fclose (fp_top3);
491b862f
GS
263 return;
264 }
fb7c5f27 265
9f20cdae
FM
266 fputs("<tr>",fp_top3);
267
268 if((TopUserFields & TOPUSERFIELDS_NUM) != 0)
269 fprintf(fp_top3,"<th class=\"header\">%s</th>",text[100]);
270 if((TopUserFields & TOPUSERFIELDS_DATE_TIME) !=0 && (ReportType & REPORT_TYPE_DATE_TIME) != 0)
271 fputs("<th class=\"header\"></th>",fp_top3);
272 if((TopUserFields & TOPUSERFIELDS_USERID) != 0)
273 fprintf(fp_top3,"<th class=\"header\">%s</th>",text[98]);
274 if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0)
275 fprintf(fp_top3,"<th class=\"header\">%s</th>",text[92]);
276 if((TopUserFields & TOPUSERFIELDS_BYTES) != 0)
277 fprintf(fp_top3,"<th class=\"header\">%s</th>",text[93]);
278 if((TopUserFields & TOPUSERFIELDS_SETYB) != 0)
279 fprintf(fp_top3,"<th class=\"header\">%%%s</th>",text[93]);
280 if((TopUserFields & TOPUSERFIELDS_IN_CACHE_OUT) != 0)
281 fprintf(fp_top3,"<th class=\"header3\" colspan=\"2\">%s-%s-%s</th>",text[113],text[114],text[112]);
282 if((TopUserFields & TOPUSERFIELDS_USED_TIME) != 0)
283 fprintf(fp_top3,"<th class=\"header\">%s</th>",text[94]);
284 if((TopUserFields & TOPUSERFIELDS_MILISEC) != 0)
285 fprintf(fp_top3,"<th class=\"header\">%s</th>",text[95]);
286 if((TopUserFields & TOPUSERFIELDS_PTIME) != 0)
287 fprintf(fp_top3,"<th class=\"header\">%%%s</th>",text[99]);
288
289 fputs("</tr>\n",fp_top3);
25697a35 290
d6e703cc 291 ntopuser = 0;
25697a35 292
05b90947 293 while(fgets(warea,sizeof(warea),fp_top1)) {
9c7c6346
FM
294 getword_start(&gwarea,warea);
295 if (getword(user,sizeof(user),&gwarea,'\t')<0) {
05b90947
FM
296 printf("SARG: Maybe you have a broken user in your %s file.\n",top1);
297 exit(1);
298 }
6e792ade 299 if (getword_atoll(&nbytes,&gwarea,'\t')<0) {
05b90947
FM
300 printf("SARG: Maybe you have a broken number of bytes in your %s file.\n",top1);
301 exit(1);
302 }
6e792ade 303 if (getword_atoll(&nacc,&gwarea,'\t')<0) {
05b90947
FM
304 printf("SARG: Maybe you have a broken number of access in your %s file.\n",top1);
305 exit(1);
306 }
6e792ade 307 if (getword_atoll(&elap,&gwarea,'\t')<0) {
9f20cdae 308 printf("SARG: Maybe you have a broken elpased time in your %s file.\n",top1);
05b90947
FM
309 exit(1);
310 }
6e792ade 311 if (getword_atoll(&incac,&gwarea,'\t')<0) {
9f20cdae 312 printf("SARG: Maybe you have a broken in-cache size in your %s file.\n",top1);
05b90947
FM
313 exit(1);
314 }
6e792ade 315 if (getword_atoll(&oucac,&gwarea,'\n')<0) {
9f20cdae 316 printf("SARG: Maybe you have a broken out-of-cache size in your %s file.\n",top1);
05b90947
FM
317 exit(1);
318 }
9f20cdae 319 if(nacc < 1)
d6e703cc 320 continue;
05b90947 321 ntopuser = 1;
fb7c5f27 322 if(TopUsersNum > 0 && topcount >= TopUsersNum) goto final;
6e792ade 323 tnbytes=nbytes;
6e792ade 324 tnelap=elap;
25697a35 325
9f20cdae 326 strcpy(user2,user);
25697a35
GS
327 if(userip) {
328 fixip(user2);
246c8489 329 if(Ip2Name) {
25697a35
GS
330 if(strcmp(user2,ipantes) != 0) {
331 strcpy(ipantes,user2);
a1c55d8c 332 ip2name(user2,sizeof(user2));
25697a35
GS
333 strcpy(nameantes,user2);
334 } else strcpy(user2,nameantes);
335 }
336 }
dfb337be 337
9f20cdae 338 fputs("<tr>",fp_top3);
25697a35 339
9f20cdae
FM
340 posicao++;
341 if((TopUserFields & TOPUSERFIELDS_NUM) != 0)
342 fprintf(fp_top3,"<td class=\"data\">%d</td>",posicao);
25697a35 343
9f20cdae
FM
344 user_find(name, sizeof(name), user2);
345 if(Ip2Name &&
346 ((str=(char *) strstr(name, ".")) != (char *) NULL) &&
347 ((str=(char *) strstr(str+1, ".")) != (char *) NULL))
348 ip2name(name,sizeof(name));
349 if(dotinuser && strchr(name,'_')) {
350 subs(name,sizeof(name),"_",".");
4157aa09 351 }
25697a35 352
9f20cdae
FM
353 if((TopUserFields & TOPUSERFIELDS_DATE_TIME) !=0 && (ReportType & REPORT_TYPE_DATE_TIME) != 0) {
354 sprintf(ltext110,"%s",text[110]);
355 for(s=ltext110; *s; ++s)
356 *s=tolower(*s);
357 fputs("<td class=\"data2\">",fp_top3);
25697a35 358#ifdef HAVE_GD
9f20cdae
FM
359 if(Graphs) {
360 fprintf(fp_top3,"<a href=\"%s/graph_day.png\"><img src=\"%s/graph.png\" border=\"0\" title=\"%s\" alt=\"G\"></a>&nbsp;",user,ImageFile,text[126]);
361 }
25697a35 362#endif
9f20cdae
FM
363 fprintf(fp_top3,"<a href=\"%s/d%s.html\"><img src=\"%s/datetime.png\" border=\"0\" title=\"%s",user,user,ImageFile,ltext110);
364#ifdef HAVE_GD
365 fprintf(fp_top3," %s",text[55]);
366#endif
367 fputs("\" alt=\"T\"></a></td>",fp_top3);
368 } else {
369 sprintf(val1,"%s/d%s.html",dirname,user);
370 unlink(val1);
25697a35 371 }
9f20cdae
FM
372 if((TopUserFields & TOPUSERFIELDS_USERID) != 0) {
373 if((ReportType & REPORT_TYPE_USERS_SITES) == 0)
374 fprintf(fp_top3,"<td class=\"data2\">%s</td>",name);
375 else
376 fprintf(fp_top3,"<td class=\"data2\"><a href=\"%s/%s.html\">%s</a></td>",user,user,name);
25697a35 377 }
9f20cdae
FM
378 if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0)
379 fprintf(fp_top3,"<td class=\"data\">%s</td>",fixnum(nacc,1));
380 if((TopUserFields & TOPUSERFIELDS_BYTES) != 0)
381 fprintf(fp_top3,"<td class=\"data\">%s</td>",fixnum(tnbytes,1));
382 if((TopUserFields & TOPUSERFIELDS_SETYB) != 0) {
383 perc=(ttnbytes) ? tnbytes * 100. / ttnbytes : 0.;
384 fprintf(fp_top3,"<td class=\"data\">%3.2lf%%</td>",perc);
25697a35 385 }
9f20cdae
FM
386 if((TopUserFields & TOPUSERFIELDS_IN_CACHE_OUT) != 0) {
387 inperc=(tnbytes) ? incac * 100. / tnbytes : 0.;
388 ouperc=(tnbytes) ? oucac * 100. / tnbytes : 0.;
389 fprintf(fp_top3,"<td class=\"data\">%3.2lf%%</td><td class=\"data\">%3.2lf%%</td>",inperc,ouperc);
25697a35 390 }
9f20cdae
FM
391 if((TopUserFields & TOPUSERFIELDS_USED_TIME) != 0)
392 fprintf(fp_top3,"<td class=\"data\">%s</td>",buildtime(tnelap));
393 if((TopUserFields & TOPUSERFIELDS_MILISEC) != 0)
394 fprintf(fp_top3,"<td class=\"data\">%s</td>",fixnum2(tnelap,1));
395 if((TopUserFields & TOPUSERFIELDS_PTIME) != 0) {
396 perc2=(ttnelap) ? elap * 100. / ttnelap : 0.;
397 fprintf(fp_top3,"<td class=\"data\">%3.2lf%%</td>",perc2);
dfb337be 398 }
25697a35 399
9f20cdae 400 fputs("</tr>\n",fp_top3);
25697a35
GS
401
402 topcount++;
25697a35
GS
403 }
404
9f20cdae
FM
405 if((TopUserFields & TOPUSERFIELDS_TOTAL) != 0) {
406
407 fputs("<tr>",fp_top3);
408 if((TopUserFields & TOPUSERFIELDS_NUM) != 0)
409 fputs("<td></td>",fp_top3);
410 if((TopUserFields & TOPUSERFIELDS_DATE_TIME) !=0 && (ReportType & REPORT_TYPE_DATE_TIME) != 0)
411 fputs("<td></td>",fp_top3);
412 fprintf(fp_top3,"<th class=\"header\">%s</th>",text[107]);
413
414 if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0)
415 fprintf(fp_top3,"<th class=\"header2\">%s</th>",fixnum(ttnacc,1));
416 if((TopUserFields & TOPUSERFIELDS_BYTES) != 0)
417 fprintf(fp_top3,"<th class=\"header2\">%15s</th>",fixnum(ttnbytes,1));
418 if((TopUserFields & TOPUSERFIELDS_SETYB) != 0)
419 fputs("<td></td>",fp_top3);
420 if((TopUserFields & TOPUSERFIELDS_IN_CACHE_OUT) != 0)
421 {
422 inperc=(ttnbytes) ? ttnincache * 100. / ttnbytes : 0.;
423 ouperc=(ttnbytes) ? ttnoucache *100. / ttnbytes : 0.;
424 fprintf(fp_top3,"<th class=\"header2\">%3.2lf%%</th><th class=\"header2\">%3.2lf%%</th>",inperc,ouperc);
425 }
426 if((TopUserFields & TOPUSERFIELDS_USED_TIME) != 0)
427 fprintf(fp_top3,"<th class=\"header2\">%s</th>",buildtime(ttnelap));
428 if((TopUserFields & TOPUSERFIELDS_MILISEC) != 0)
429 fprintf(fp_top3,"<th class=\"header2\">%s</th>",fixnum2(ttnelap,1));
430
431 fputs("</tr>\n",fp_top3);
25697a35
GS
432 }
433
9f20cdae
FM
434 if(ntopuser && (TopUserFields & TOPUSERFIELDS_AVERAGE) != 0) {
435 fputs("<tr>",fp_top3);
436 if((TopUserFields & TOPUSERFIELDS_NUM) != 0)
437 fputs("<td></td>",fp_top3);
438 if((TopUserFields & TOPUSERFIELDS_DATE_TIME) !=0 && (ReportType & REPORT_TYPE_DATE_TIME) != 0)
439 fputs("<td></td>",fp_top3);
440 fprintf(fp_top3,"<th class=\"header\">%s</th>",text[96]);
441
442 if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0)
443 fprintf(fp_top3,"<th class=\"header2\">%s</th>",fixnum(ttnacc/totuser,1));
444 if((TopUserFields & TOPUSERFIELDS_BYTES) != 0) {
445 tnbytes=(totuser) ? ttnbytes / totuser : 0;
446 fprintf(fp_top3,"<th class=\"header2\">%15s</th>",fixnum(tnbytes,1));
447 }
448 if((TopUserFields & TOPUSERFIELDS_SETYB) != 0)
449 fputs("<td></td>",fp_top3);
450 if((TopUserFields & TOPUSERFIELDS_IN_CACHE_OUT) != 0)
451 fputs("<td></td><td></td>",fp_top3);
452 if((TopUserFields & TOPUSERFIELDS_USED_TIME) != 0)
453 fprintf(fp_top3,"<th class=\"header2\">%s</th>",buildtime(ttnelap/totuser));
454 if((TopUserFields & TOPUSERFIELDS_MILISEC) != 0)
455 fprintf(fp_top3,"<th class=\"header2\">%s</th>",fixnum2(ttnelap/totuser,1));
456 fputs("</tr>\n",fp_top3);
25697a35
GS
457 }
458
4157aa09 459 if(UserAgentLog[0] != '\0') {
25697a35
GS
460 fputs("<tr><td></td></tr>\n",fp_top3);
461 fputs("<tr><td></td></tr>\n",fp_top3);
fb7c5f27 462 fputs("<td align=\"left\" colspan=\"8\"><font size=-1><a href=\"useragent.html\">Useragent</a> Report</td>\n",fp_top3);
25697a35
GS
463 }
464
dfb337be 465 fputs("</table></div>",fp_top3);
25697a35
GS
466
467 show_info(fp_top3);
468
469final:
470 fclose(fp_top1);
471 unlink(top1);
472
473 if((fp_ou=fopen(tusr,"w"))==NULL) {
474 fprintf(stderr, "SARG: (topuser) %s: %s\n",text[45],tusr);
475 exit(1);
476 }
477
d6e703cc 478 fprintf(fp_ou,"%d\n",totuser);
25697a35
GS
479
480 fputs("</body>\n</html>\n",fp_top3);
481 fclose(fp_top3);
482 fclose(fp_ou);
483
484 return;
485}