]> git.ipfire.org Git - thirdparty/sarg.git/blob - html.c
5420e708875a366867d661b3b9823d42f2e309a3
[thirdparty/sarg.git] / html.c
1 /*
2 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
3 * 1998, 2010
4 *
5 * SARG donations:
6 * please look at http://sarg.sourceforge.net/donations.php
7 * Support:
8 * http://sourceforge.net/projects/sarg/forums/forum/363374
9 * ---------------------------------------------------------------------
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
24 *
25 */
26
27 #include "include/conf.h"
28 #include "include/defs.h"
29
30 void htmlrel(void)
31 {
32 DIR *dirp;
33 FILE *fp_in, *fp_ou, *fp_ip, *fp_ip2, *fp_usr;
34
35 struct dirent *direntp;
36 long long int nnbytes=0, unbytes=0, tnbytes=0, totbytes=0, totbytes2=0;
37 long long int totelap=0, totelap2=0, nnelap=0, unelap=0, tnelap=0;
38 long long int incache=0, oucache=0, tnincache=0, tnoucache=0, twork=0;
39 long long int ltemp;
40 long long int ntotuser;
41 long long int userbytes, userelap;
42 char arqin[MAXLEN], arqou[MAXLEN], arqper[MAXLEN], arqip[MAXLEN];
43 char url[MAXLEN], tmsg[50], csort[MAXLEN];
44 char period[MAXLEN], usuario[MAXLEN], wusuario[MAXLEN], u2[MAXLEN], duser[MAXLEN];
45 char userurl[1024], userhora[9], userdia[9];
46 char user_ip[MAXLEN], olduserip[MAXLEN], tmp2[MAXLEN], tmp3[MAXLEN];
47 char denied_report[255], name2[MAXLEN];
48 char *str;
49 char warea[MAXLEN];
50 char totuser[8];
51 long long int tnacc=0, ttnacc=0, unacc=0;
52 double perc=0, perc2=0, ouperc=0, inperc=0;
53 char *s;
54 int count;
55 int cstatus;
56 const char txtext[]=".txt";
57 int dlen;
58 char urly[MAXLEN];
59 char siteind[MAXLEN];
60 struct getwordstruct gwarea;
61
62 if((ReportType & REPORT_TYPE_USERS_SITES) == 0) return;
63
64 strcpy(tmp2,TempDir);
65 strcat(tmp2,"/sargtmp.unsort");
66
67 strcpy(tmp3,TempDir);
68 strcat(tmp3,"/sargtmp.log");
69
70 strcpy(arqper,dirname);
71 strcat(arqper,"/sarg-period");
72 if ((fp_in = fopen(arqper, "r")) == 0){
73 fprintf(stderr, "SARG: (html1) %s: %s\n",text[45],arqper);
74 exit(1);
75 }
76 if (!fgets(period,sizeof(period),fp_in)) {
77 fprintf(stderr,"SARG: (html1) read error in %s\n",arqper);
78 exit(1);
79 }
80 fclose(fp_in);
81
82 strcpy(arqper,dirname);
83 strcat(arqper,"/sarg-general");
84 if ((fp_in = fopen(arqper, "r")) == 0){
85 fprintf(stderr, "SARG: (html2) %s: %s\n",text[45],arqper);
86 exit(1);
87 }
88 ttnacc=0;
89 totbytes=0;
90 totelap=0;
91 while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
92 if(strncmp(buf,"TOTAL\t",6) == 0) {
93 getword_start(&gwarea,buf);
94 if (getword_skip(MAXLEN,&gwarea,'\t')<0 || getword_atoll(&ltemp,&gwarea,'\t')<0) {
95 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqper);
96 exit(1);
97 }
98 ttnacc+=ltemp;
99 if (getword_atoll(&ltemp,&gwarea,'\t')<0) {
100 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqper);
101 exit(1);
102 }
103 totbytes+=ltemp;
104 if (getword_atoll(&ltemp,&gwarea,'\t')<0) {
105 printf("SARG: Maybe you have a broken record or garbage in your %s file (%d).\n",arqper,__LINE__);
106 exit(1);
107 }
108 totelap+=ltemp;
109 }
110 }
111 fclose(fp_in);
112
113 strcpy(arqper,dirname);
114 strcat(arqper,"/sarg-users");
115 if ((fp_in = fopen(arqper, "r")) == 0){
116 fprintf(stderr, "SARG: (html11) %s: %s\n",text[45],arqper);
117 exit(1);
118 }
119 if (!fgets(totuser,sizeof(totuser),fp_in)) {
120 fprintf(stderr,"SARG: (html11) read error in %s\n",arqper);
121 exit(1);
122 }
123 fclose(fp_in);
124 ntotuser=my_atoll(totuser);
125 if (ntotuser<=0) ntotuser=1;
126
127 dirp = opendir(tmp);
128 while ( (direntp = readdir( dirp )) != NULL ) {
129 dlen=strlen(direntp->d_name)-(sizeof(txtext)-1);
130 if (dlen<0) continue;
131 if(strcmp(direntp->d_name+dlen,txtext) != 0)
132 continue;
133
134 count=1;
135 if (dlen>0) {
136 if (dlen>=sizeof(wusuario)) continue;
137 strncpy(wusuario,direntp->d_name,dlen);
138 wusuario[dlen]=0;
139 } else {
140 wusuario[0]=0;
141 }
142 str=strrchr(wusuario,'.');
143 if (str)
144 strcpy(denied_report,str+1);
145 else
146 strcpy(denied_report,wusuario);
147
148 if (snprintf(warea,sizeof(warea),"%s/%s",dirname,wusuario)>=sizeof(warea)) {
149 fprintf(stderr,"SARG: destination directory too long: %s/%s\n",dirname,wusuario);
150 exit(1);
151 }
152 mkdir(warea,0755);
153
154 report_day(wusuario);
155 greport_day(wusuario);
156
157 strcpy(usuario,wusuario);
158 strcpy(arqin,tmp);
159 strcat(arqin,"/");
160 strcpy(arqou,dirname);
161 strcat(arqou,"/");
162 strcat(arqou,usuario);
163 strcat(arqou,"/");
164 strcat(arqou,usuario);
165 strcat(arqou,".html");
166 strcpy(duser,arqin);
167 strcat(duser,"denied_");
168 strcat(arqin,direntp->d_name);
169
170 if((str=(char *) strstr(denied_report, "_")) != (char *) NULL ) {
171 if((str=(char *) strstr(str+1, "_")) != (char *) NULL )
172 fixip(denied_report);
173 }
174 strcat(duser,denied_report);
175 strcat(duser,".html");
176 if(access(duser, R_OK) != 0)
177 denied_report[0]='\0';
178
179 strcpy(u2,usuario);
180 if(userip)
181 fixip(u2);
182 if(Ip2Name)
183 ip2name(u2,sizeof(u2));
184
185 user_find(name2, sizeof(name2), u2);
186
187 if(dotinuser && strchr(name2,'_')) {
188 subs(name2,sizeof(name2),"_",".");
189 }
190
191 if ((fp_in = fopen(arqin, "r")) == 0){
192 fprintf(stderr, "SARG: (html3) %s: %s\n",text[45],arqin);
193 exit(1);
194 }
195
196 tnacc=0;
197 tnbytes=0;
198 tnelap=0;
199 tnincache=0;
200 tnoucache=0;
201 while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
202 getword_start(&gwarea,buf);
203 if (getword_atoll(&ltemp,&gwarea,'\t')<0) {
204 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin);
205 exit(1);
206 }
207 tnacc+=ltemp;
208 if (getword_atoll(&ltemp,&gwarea,'\t')<0) {
209 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin);
210 exit(1);
211 }
212 tnbytes+=ltemp;
213 if (getword_skip(MAXLEN,&gwarea,'\t')<0 || getword_skip(MAXLEN,&gwarea,'\t')<0 ||
214 getword_atoll(&ltemp,&gwarea,'\t')<0) {
215 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin);
216 exit(1);
217 }
218 tnelap+=ltemp;
219 if (getword_atoll(&ltemp,&gwarea,'\t')<0) {
220 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin);
221 exit(1);
222 }
223 tnincache+=ltemp;
224 if (getword_atoll(&ltemp,&gwarea,'\n')<0) {
225 printf("SARG: Maybe you have a broken record or garbage in your %s file (%d).\n",arqin,__LINE__);
226 exit(1);
227 }
228 tnoucache+=ltemp;
229 }
230
231 rewind(fp_in);
232
233 if ((fp_ou = fopen(arqou, "w")) == 0){
234 fprintf(stderr, "SARG: (html5) %s: %s\n",text[45],arqou);
235 exit(1);
236 }
237
238 fputs("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n",fp_ou);
239 fputs("<html>\n",fp_ou);
240 fputs("<head>\n",fp_ou);
241 fprintf(fp_ou," <meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">\n",CharSet);
242 css(fp_ou);
243 fputs("</head>\n",fp_ou);
244
245 fprintf(fp_ou,"<body style=\"font-family:%s;font-size:%s;background-color:%s; \
246 background-image:url(%s)\">\n",FontFace,TitleFontSize,BgColor,BgImage);
247
248 write_logo_image(fp_ou);
249
250 if(IndexTree == INDEX_TREE_DATE)
251 show_sarg(fp_ou, "../../../..");
252 else
253 show_sarg(fp_ou, "../..");
254
255 fputs("<div align=\"center\"><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_ou);
256 fprintf(fp_ou,"<tr><th class=\"title\" colspan=\"2\">%s</th></tr>\n",Title);
257
258 fprintf(fp_ou,"<tr><td class=\"header\" colspan=\"2\">%s:&nbsp;%s</td></tr>\n",text[89],period);
259 fprintf(fp_ou,"<tr><td class=\"header\" colspan=\"2\">%s:&nbsp;%s</td></tr>\n",text[90],name2);
260 fprintf(fp_ou,"<tr><td class=\"header\" colspan=\"2\">%s:&nbsp;%s, %s</td></tr>\n",text[104],UserSortField,UserSortOrder);
261 fprintf(fp_ou,"<tr><td class=\"header3\" colspan=\"2\">%s %s</td></tr>\n",text[32],text[55]);
262 fputs("<tr><td></td></tr>\n",fp_ou);
263
264 fputs("</table></div>\n",fp_ou);
265 fputs("<div align=\"center\"><table cellpadding=\"2\" cellspacing=\"1\">\n",fp_ou);
266
267 if(denied_report[0]!='\0') {
268 fprintf(fp_ou,"<tr><td class=\"header\" colspan=\"11\"><a href=\"denied_%s.html\">%s</a> %s</td></tr>\n",denied_report,text[116],text[55]);
269 }
270
271 fprintf(fp_ou,"<tr><th></th><th class=\"header\">%s</th>",text[91]);
272
273 if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0)
274 fprintf(fp_ou,"<th class=\"header\">%s</th>",text[92]);
275 if((UserReportFields & USERREPORTFIELDS_BYTES) != 0)
276 fprintf(fp_ou,"<th class=\"header\">%s</th>",text[93]);
277 if((UserReportFields & USERREPORTFIELDS_SETYB) != 0)
278 fprintf(fp_ou,"<th class=\"header\">%%%s</th>",text[93]);
279 if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) != 0)
280 fprintf(fp_ou,"<th class=\"header3\" colspan=\"2\">%s-%s-%s</th>",text[113],text[114],text[112]);
281 if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0)
282 fprintf(fp_ou,"<th class=\"header\">%s</th>",text[94]);
283 if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0)
284 fprintf(fp_ou,"<th class=\"header\">%s</th>",text[95]);
285 if((UserReportFields & USERREPORTFIELDS_PTIME) != 0)
286 fprintf(fp_ou,"<th class=\"header\">%%%s</th>",text[99]);
287
288 fputs("</tr>\n",fp_ou);
289
290 if(debug) {
291 if(userip) {
292 strcpy(u2,usuario);
293 fixip(u2);
294 debuga("%s: %s",text[61],u2);
295 } else
296 debuga("%s: %s",text[61],usuario);
297 }
298
299 while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
300 getword_start(&gwarea,buf);
301 if (getword_atoll(&twork,&gwarea,'\t')<0) {
302 printf("SARG: Maybe you have a broken number of access in your %s file.\n",arqin);
303 exit(1);
304 }
305 if (getword_atoll(&nnbytes,&gwarea,'\t')<0) {
306 printf("SARG: Maybe you have a broken number of bytes in your %s file.\n",arqin);
307 exit(1);
308 }
309 if (getword(url,sizeof(url),&gwarea,'\t')<0) {
310 printf("SARG: Maybe you have a broken url in your %s file.\n",arqin);
311 exit(1);
312 }
313 if (getword(tmsg,sizeof(tmsg),&gwarea,'\t')<0) {
314 printf("SARG: Maybe you have a broken status in your %s file.\n",arqin);
315 exit(1);
316 }
317 if (getword_atoll(&nnelap,&gwarea,'\t')<0) {
318 printf("SARG: Maybe you have a broken elapsed time in your %s file.\n",arqin);
319 exit(1);
320 }
321 if (getword_atoll(&incache,&gwarea,'\t')<0) {
322 printf("SARG: Maybe you have a broken in cache column in your %s file.\n",arqin);
323 exit(1);
324 }
325 if (getword_atoll(&oucache,&gwarea,'\n')<0) {
326 printf("SARG: Maybe you have a broken not in cache column in your %s file (%d).\n",arqin,__LINE__);
327 exit(1);
328 }
329
330 if(UserReportLimit<=0 || count<=UserReportLimit) {
331 fputs("<tr>",fp_ou);
332
333 if(IndexTree == INDEX_TREE_DATE)
334 sprintf(tmp6,"../%s",ImageFile);
335 else
336 strcpy(tmp6,"../../images");
337
338 if((ReportType & REPORT_TYPE_SITE_USER_TIME_DATE) != 0) {
339 strcpy(ltext110,text[110]);
340 for(s=ltext110; *s; ++s)
341 *s=tolower(*s);
342 strcpy(siteind,urly);
343 str=siteind;
344 for(z1=0; str[z1]; z1++) {
345 if(str[z1]=='?' || str[z1]=='-' || str[z1]=='.' || str[z1]==':' || str[z1]=='/' || str[z1]=='\\' || str[z1]=='*' ||
346 str[z1]=='\'' || str[z1]=='\"' || str[z1]=='$')
347 str[z1]='_';
348 }
349 fprintf(fp_ou,"<td class=\"data\"><a href=\"tt%s-%s.html\"><img src=\"%s/datetime.png\" border=\"0\" title=\"%s %s\" alt=\"T\"></a></td>",usuario,siteind,tmp6,ltext110,text[55]);
350 } else {
351 fprintf(fp_ou,"<td class=\"data\"></td>");
352 }
353
354 if(!LongUrl) {
355 char *endofhost=strchr(url,'/');
356 if (endofhost) *endofhost='\0';
357 strcpy(urly,url);
358 } else {
359 strcpy(urly,url);
360 url_module(url, module);
361 str=strchr(url,'/');
362 if (str){
363 *str='\0';
364 strcat(url,"...");
365 strcat(url,module);
366 }
367 }
368
369 if(Privacy)
370 fprintf(fp_ou,"<td class=\"data2\"><span style=\"color:%s;\">%s</span></td>",PrivacyStringColor,PrivacyString);
371 else {
372 if(BlockIt[0]!='\0') {
373 fprintf(fp_ou,"<td class=\"data2\"><a href=\"%s%s?url=%s\"><img src=\"%s/sarg-squidguard-block.png\" border=\"0\"></a><a href=\"http://%s\">&nbsp;%s</a></td>",wwwDocumentRoot,BlockIt,urly,tmp6,urly,urly);
374 } else
375 fprintf(fp_ou,"<td class=\"data2\"><a href=\"http://%s\" title=\"%s\">%s</a></td>",urly,urly,url);
376 }
377
378 if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0)
379 fprintf(fp_ou,"<td class=\"data\">%s</td>",fixnum(twork,1));
380 if((UserReportFields & USERREPORTFIELDS_BYTES) != 0)
381 fprintf(fp_ou,"<td class=\"data\">%s</td>",fixnum(nnbytes,1));
382 if((UserReportFields & USERREPORTFIELDS_SETYB) != 0) {
383 perc=(tnbytes) ? nnbytes * 100. / tnbytes : 0.;
384 fprintf(fp_ou,"<td class=\"data\">%3.2lf%%</td>",perc);
385 }
386 if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) != 0) {
387 inperc=(nnbytes) ? incache * 100. / nnbytes : 0.;
388 ouperc=(nnbytes) ? oucache * 100. / nnbytes : 0.;
389 fprintf(fp_ou,"<td class=\"data\">%3.2lf%%</td><td class=\"data\">%3.2lf%%</td>",inperc,ouperc);
390 }
391 if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0)
392 fprintf(fp_ou,"<td class=\"data\">%s</td>",buildtime(nnelap));
393 if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0)
394 fprintf(fp_ou,"<td class=\"data\">%s</td>",fixnum2(nnelap,1));
395 if((UserReportFields & USERREPORTFIELDS_PTIME) != 0) {
396 perc2=(tnelap) ? nnelap * 100. / tnelap : 0.;
397 fprintf(fp_ou,"<td class=\"data\">%3.2lf%%</td>",perc2);
398 }
399
400 if(strncmp(tmsg,"OK",2) != 0)
401 fprintf(fp_ou,"<td class=\"data\">%s</td>",text[46]);
402
403 fputs("</tr>\n",fp_ou);
404 count++;
405 }
406
407 if(iprel) {
408 strcpy(arqip,tmp);
409 strcat(arqip,"/");
410 strcat(arqip,usuario);
411 strcat(arqip,".ip");
412
413 if ((fp_ip = fopen(arqip, "r")) == 0){
414 fprintf(stderr, "SARG: (html6) %s: %s\n",text[45],arqip);
415 exit(1);
416 }
417
418 if ((fp_ip2 = MY_FOPEN(tmp2, "a")) == 0){
419 fprintf(stderr, "SARG: (html7) %s: %s\n",text[45],tmp2);
420 exit(1);
421 }
422
423 while(fgets(buf,sizeof(buf),fp_ip)!=NULL) {
424 if(strstr(buf,url) != 0)
425 fputs(buf,fp_ip2);
426 }
427
428 fclose(fp_ip);
429 fclose(fp_ip2);
430
431 sprintf(csort,"sort -n -T \"%s\" -k 1,1 -k 5,5 -o \"%s\" \"%s\"",TempDir,tmp3,tmp2);
432 cstatus=system(csort);
433 if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
434 fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus));
435 fprintf(stderr, "SARG: sort command: %s\n",csort);
436 exit(1);
437 }
438
439 if ((fp_ip = MY_FOPEN(tmp3, "r")) == 0) {
440 fprintf(stderr, "SARG: (html8) %s: %s\n",text[45],tmp3);
441 exit(1);
442 }
443
444 olduserip[0]='\0';
445
446 while(fgets(buf,sizeof(buf),fp_ip)) {
447 getword_start(&gwarea,buf);
448 if (getword(user_ip,sizeof(user_ip),&gwarea,'\t')<0) {
449 printf("SARG: Maybe you have a broken user IP in your %s file.\n",tmp3);
450 exit(1);
451 }
452 if (getword(userurl,sizeof(userurl),&gwarea,'\t')<0) {
453 printf("SARG: Maybe you have a broken user URL in your %s file.\n",tmp3);
454 exit(1);
455 }
456 if (getword(userdia,sizeof(userdia),&gwarea,'\t')<0) {
457 printf("SARG: Maybe you have a broken day in your %s file.\n",tmp3);
458 exit(1);
459 }
460 if (getword(userhora,sizeof(userhora),&gwarea,'\t')<0) {
461 printf("SARG: Maybe you have a broken time in your %s file.\n",tmp3);
462 exit(1);
463 }
464 if (getword_atoll(&userbytes,&gwarea,'\t')<0) {
465 printf("SARG: Maybe you have a broken size in your %s file.\n",tmp3);
466 exit(1);
467 }
468 if (getword_atoll(&userelap,&gwarea,'\t')<0) {
469 printf("SARG: Maybe you have a broken elapsed time in your %s file (%d).\n",tmp3,__LINE__);
470 exit(1);
471 }
472 if(strcmp(user_ip,olduserip) != 0) {
473 my_lltoa(unelap,val2,0);
474 sprintf(wwork1,"%s",fixnum(unbytes,1));
475 fprintf(fp_ou,"<tr><td></td><td class=\"data\">%s</td><td></td><td class=\"data\">%s</td><td></td><td></td><td></td><td class=\"data\">%s</td><td class=\"data\">%s</td></tr>\n",olduserip,wwork1,buildtime(unelap),val2);
476
477 strcpy(olduserip,user_ip);
478 unacc=0;
479 unbytes=0;
480 unelap=0;
481 }
482
483 unbytes=unbytes+userbytes;
484 unelap=unelap+userelap;
485 }
486
487 fclose(fp_ip);
488
489 unlink(tmp2);
490 unlink(tmp3);
491
492 my_lltoa(unelap,val3,0);
493 sprintf(wwork1,"%s",fixnum(unbytes,1));
494 fprintf(fp_ou,"<tr><td></td><td class=\"data\">%s</td><td></td><td class=\"data\">%s</td><td></td><td></td><td></td><td class=\"data\">%s</td><td class=\"data\">%s</td></tr>\n",olduserip,wwork1,buildtime(unelap),val3);
495 }
496
497 unacc=0;
498 unbytes=0;
499 unelap=0;
500 }
501
502 fclose(fp_in);
503
504 if(iprel)
505 unlink(arqip);
506 unlink(arqin);
507
508 if((UserReportFields & USERREPORTFIELDS_TOTAL) != 0) {
509 fprintf(fp_ou,"<tr><th></th><th class=\"header\">%s</th>",text[107]);
510 if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0)
511 fprintf(fp_ou,"<th class=\"header2\">%s</th>",fixnum(tnacc,1));
512 if((UserReportFields & USERREPORTFIELDS_BYTES) != 0)
513 fprintf(fp_ou,"<th class=\"header2\">%s</th>",fixnum(tnbytes,1));
514 if((UserReportFields & USERREPORTFIELDS_SETYB) != 0) {
515 perc=(totbytes) ? tnbytes *100. / totbytes :0.;
516 fprintf(fp_ou,"<th class=\"header2\">%3.2lf%%</th>",perc);
517 }
518 if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) != 0) {
519 inperc=(tnbytes) ? tnincache * 100. / tnbytes : 0.;
520 ouperc=(tnbytes) ? tnoucache * 100. / tnbytes : 0.;
521 fprintf(fp_ou,"<th class=\"header2\">%3.2lf%%</th><th class=\"header2\">%3.2lf%%</th>",inperc,ouperc);
522 }
523 if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0)
524 fprintf(fp_ou,"<th class=\"header2\">%s</th>",buildtime(tnelap));
525 if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0)
526 fprintf(fp_ou,"<th class=\"header2\">%s</th>",fixnum2(tnelap,1));
527 if((UserReportFields & USERREPORTFIELDS_PTIME) != 0) {
528 perc2=(totelap) ? tnelap * 100. / totelap : 0.;
529 fprintf(fp_ou,"<th class=\"header2\">%3.2lf%%</th>",perc2);
530 }
531 fputs("</tr>\n",fp_ou);
532 }
533
534 if(PerUserLimit > 0) {
535 if(tnbytes > (PerUserLimit*1000000)) {
536 limit_flag=0;
537 if(access(PerUserLimitFile, R_OK) == 0) {
538 if((fp_usr = fopen(PerUserLimitFile, "r")) == 0) {
539 fprintf(stderr, "SARG: (html9) %s: %s\n",text[45],PerUserLimitFile);
540 exit(1);
541 }
542 while(fgets(tmp6,sizeof(tmp6),fp_usr)!=NULL) {
543 fixendofline(tmp6);
544 if(strcmp(tmp6,u2) == 0) {
545 limit_flag=1;
546 break;
547 }
548 }
549 fclose(fp_usr);
550 }
551
552 if(!limit_flag) {
553 if((fp_usr = fopen(PerUserLimitFile, "a")) == 0) {
554 fprintf(stderr, "SARG: (html10) %s: %s\n",text[45],PerUserLimitFile);
555 exit(1);
556 }
557 fprintf(fp_usr,"%s\n",u2);
558 fclose(fp_usr);
559
560 if(debug)
561 debuga("%s %s %s (%d MB). %s %s",text[32],u2,text[74],PerUserLimit,text[75],PerUserLimitFile);
562 }
563 }
564 }
565
566 // if(indexonly) {
567 // unlink(arqou);
568 // continue;
569 // }
570
571 if ((ReportType & REPORT_TYPE_TOPUSERS) != 0 && (UserReportFields & USERREPORTFIELDS_AVERAGE) != 0) {
572 totbytes2=totbytes/ntotuser;
573 totelap2=totelap/ntotuser;
574
575 fprintf(fp_ou,"<tr><th></th><th class=\"header\">%s</th>",text[96]);
576 if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0)
577 fprintf(fp_ou,"<th class=\"header2\">%s</th>",fixnum(ttnacc/ntotuser,1));
578 if((UserReportFields & USERREPORTFIELDS_BYTES) != 0)
579 fprintf(fp_ou,"<th class=\"header2\">%s</th>",fixnum(totbytes2,1));
580 fprintf(fp_ou,"<th></th><th></th><th></th>");
581 if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0)
582 fprintf(fp_ou,"<th class=\"header2\">%s</th>",buildtime(totelap2));
583 if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0)
584 fprintf(fp_ou,"<th class=\"header2\">%s</th>",fixnum2(totelap2,1));
585 if((UserReportFields & USERREPORTFIELDS_PTIME) != 0) {
586 perc2 = (totelap) ? totelap2 * 100. / totelap : 0.;
587 fprintf(fp_ou,"<th class=\"header2\">%3.2lf%%</th>",perc2);
588 }
589 fputs("</tr>\n",fp_ou);
590 }
591
592 fputs("</table></div>\n",fp_ou);
593
594 show_info(fp_ou);
595
596 fputs("</body>\n</html>\n",fp_ou);
597
598 fclose(fp_ou);
599
600 htaccess(wusuario);
601 }
602
603 (void)closedir(dirp);
604 greport_cleanup();
605
606 return;
607 }