]> git.ipfire.org Git - thirdparty/sarg.git/blob - html.c
Replaced the ifdef FOPEN64 by a single call to MY_FOPEN for code clarity.
[thirdparty/sarg.git] / html.c
1 /*
2 * AUTHOR: Pedro Lineu Orso orso@penguintech.com.br
3 * 1998, 2005
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 htmlrel(void)
30 {
31 DIR *dirp;
32 FILE *fp_in, *fp_ou, *fp_ip, *fp_ip2, *fp_usr;
33
34 struct dirent *direntp;
35 long long int nnbytes=0, unbytes=0, tnbytes=0, totbytes=0, totbytes2=0;
36 long long int totelap=0, totelap2=0, nnelap=0, unelap=0, tnelap=0;
37 long long int incache=0, oucache=0, tnincache=0, tnoucache=0, twork=0, twork2=0;
38 char arqin[MAXLEN], arqou[MAXLEN], arqper[MAXLEN], arqip[MAXLEN];
39 char nacc[20], nbytes[20], url[1024], tmsg[50], nelap[20], csort[MAXLEN];
40 char period[MAXLEN], usuario[MAXLEN], wusuario[MAXLEN], u2[MAXLEN], duser[MAXLEN];
41 char userbytes[20], userelap[20], userurl[1024], userhora[9], userdia[9];
42 char user_ip[MAXLEN], olduserip[MAXLEN], tmp2[MAXLEN], tmp3[MAXLEN], incac[20], oucac[20];
43 char denied_report[255], name2[MAXLEN];
44 //char ttd1[3], ttd2[3], ttd3[5], ttt1[3], ttt2[3], ttt3[3];
45 char *str;
46 char warea[MAXLEN];
47 char wtemp[MAXLEN], totuser[8];
48 long long int tnacc=0, ttnacc=0, unacc=0;
49 float perc=0, perc2=0, ouperc=0, inperc=0;
50 char *s;
51 int count;
52 int cstatus;
53 const char txtext[]=".txt";
54 int dlen;
55
56 if(strstr(ReportType,"users_sites") == 0) return;
57
58 strcpy(tmp2,TempDir);
59 strcat(tmp2,"/sargtmp.unsort");
60
61 strcpy(tmp3,TempDir);
62 strcat(tmp3,"/sargtmp.log");
63
64 strcpy(arqper,dirname);
65 strcat(arqper,"/sarg-period");
66
67 if ((fp_in = fopen(arqper, "r")) == 0){
68 fprintf(stderr, "SARG: (html1) %s: %s\n",text[45],arqper);
69 exit(1);
70 }
71
72 fgets(period,sizeof(period),fp_in);
73 fclose(fp_in);
74
75 strcpy(arqper,dirname);
76 strcat(arqper,"/sarg-general");
77
78 if ((fp_in = fopen(arqper, "r")) == 0){
79 fprintf(stderr, "SARG: (html2) %s: %s\n",text[45],arqper);
80 exit(1);
81 }
82
83 while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
84 if(strstr(buf,"TOTAL") == 0) {
85 if (getword(wtemp,sizeof(wtemp),buf,' ')<0) {
86 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqper);
87 exit(1);
88 }
89 ttnacc+=my_atoll(buf);
90 if (getword(wtemp,sizeof(wtemp),buf,' ')<0 || getword(wtemp,sizeof(wtemp),buf,' ')<0) {
91 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqper);
92 exit(1);
93 }
94 totbytes+=my_atoll(wtemp);
95 if (getword(wtemp,sizeof(wtemp),buf,' ')<0 || getword(wtemp,sizeof(wtemp),buf,' ')<0 ||
96 getword(wtemp,sizeof(wtemp),buf,' ')<0 || getword(wtemp,sizeof(wtemp),buf,' ')<0 ||
97 getword(wtemp,sizeof(wtemp),buf,' ')<0) {
98 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqper);
99 exit(1);
100 }
101 totelap+=my_atoll(wtemp);
102 }
103 }
104
105 fclose(fp_in);
106
107 dirp = opendir(tmp);
108 while ( (direntp = readdir( dirp )) != NULL ) {
109 dlen=strlen(direntp->d_name)-(sizeof(txtext)-1);
110 if (dlen<0) continue;
111 if(strcmp(direntp->d_name+dlen,txtext) != 0)
112 continue;
113
114 count=1;
115 if (dlen>0) {
116 if (dlen>=sizeof(wusuario)) continue;
117 strncpy(wusuario,direntp->d_name,dlen);
118 wusuario[dlen]=0;
119 } else {
120 wusuario[0]=0;
121 }
122 str=strrchr(wusuario,'.');
123 if (str)
124 strcpy(denied_report,str+1);
125 else
126 strcpy(denied_report,wusuario);
127
128 sprintf(warea,"%s/%s",dirname,wusuario);
129 mkdir(warea,0755);
130
131 report_day(wusuario);
132 greport_day(wusuario);
133
134 strcpy(usuario,wusuario);
135 strcpy(arqin,tmp);
136 strcat(arqin,"/");
137 strcpy(arqou,dirname);
138 strcat(arqou,"/");
139 strcat(arqou,usuario);
140 strcat(arqou,"/");
141 strcat(arqou,usuario);
142 strcat(arqou,".html");
143 strcpy(duser,arqin);
144 strcat(duser,"denied_");
145 strcat(arqin,direntp->d_name);
146
147 if((str=(char *) strstr(denied_report, "_")) != (char *) NULL ) {
148 if((str=(char *) strstr(str+1, "_")) != (char *) NULL )
149 fixip(denied_report);
150 }
151 strcat(duser,denied_report);
152 strcat(duser,".html");
153 if(access(duser, R_OK) != 0)
154 denied_report[0]='\0';
155
156 strcpy(u2,usuario);
157 if(userip)
158 fixip(u2);
159 if(strcmp(Ip2Name,"yes") == 0)
160 ip2name(u2,sizeof(u2));
161
162 get_usertab_name(u2,name2,sizeof(name2));
163
164 if(dotinuser && strstr(name2,"_")) {
165 str2=(char *)subs(name2,"_",".");
166 strcpy(name2,str2);
167 }
168
169 if ((fp_in = fopen(arqin, "r")) == 0){
170 fprintf(stderr, "SARG: (html3) %s: %s\n",text[45],arqin);
171 exit(1);
172 }
173
174 while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
175 if (getword(wtemp,sizeof(wtemp),buf,' ')<0) {
176 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin);
177 exit(1);
178 }
179 tnacc+=my_atoll(wtemp);
180 if (getword(wtemp,sizeof(wtemp),buf,' ')<0) {
181 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin);
182 exit(1);
183 }
184 tnbytes+=my_atoll(wtemp);
185 if (getword(wtemp,sizeof(wtemp),buf,' ')<0 || getword(wtemp,sizeof(wtemp),buf,' ')<0 ||
186 getword(wtemp,sizeof(wtemp),buf,' ')<0) {
187 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin);
188 exit(1);
189 }
190 tnelap+=my_atoll(wtemp);
191 if (getword(wtemp,sizeof(wtemp),buf,' ')<0) {
192 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin);
193 exit(1);
194 }
195 tnincache+=my_atoll(wtemp);
196 if (getword(wtemp,sizeof(wtemp),buf,' ')<0) {
197 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin);
198 exit(1);
199 }
200 tnoucache+=my_atoll(wtemp);
201 }
202
203 fclose(fp_in);
204
205 if ((fp_in = fopen(arqin, "r")) == 0){
206 fprintf(stderr, "SARG: (html4) %s: %s\n",text[45],arqin);
207 exit(1);
208 }
209
210 if ((fp_ou = fopen(arqou, "w")) == 0){
211 fprintf(stderr, "SARG: (html5) %s: %s\n",text[45],arqou);
212 exit(1);
213 }
214
215 fputs("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"",fp_ou);
216 fputs(" \"http://www.w3.org/TR/html4/loose.dtd\">\n",fp_ou);
217 fputs("<html>\n",fp_ou);
218 fputs("<head>\n",fp_ou);
219 fprintf(fp_ou," <meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">\n",CharSet);
220 css(fp_ou);
221 fputs("</head>\n",fp_ou);
222
223 fprintf(fp_ou,"<body style=\"font-family:%s;font-size:%s;background-color:%s; \
224 background-image:url(%s)\">\n",FontFace,TitleFontSize,BgColor,BgImage);
225
226 if(strlen(LogoImage) > 0) {
227 fputs("<center><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_ou);
228 fprintf(fp_ou,"<tr><th class=\"logo\"><img src='%s' border=0 align=absmiddle width=%s height=%s>&nbsp;%s</th></tr>\n",LogoImage,Width,Height,LogoText);
229 fputs("<tr><td height=\"5\"></td></tr>\n",fp_ou);
230 fputs("</table>\n",fp_ou);
231 }
232
233 if(strcmp(IndexTree,"date") == 0)
234 show_sarg(fp_ou, "../../../..");
235 else
236 show_sarg(fp_ou, "../..");
237
238 fputs("<center><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_ou);
239 fprintf(fp_ou,"<tr><th class=\"title\" colspan=\"2\">%s</th></tr>\n",Title);
240
241 fprintf(fp_ou,"<tr><td class=\"header\" colspan=\"2\">%s:&nbsp;%s</td></tr>\n",text[89],period);
242 fprintf(fp_ou,"<tr><td class=\"header\" colspan=\"2\">%s:&nbsp;%s</td></tr>\n",text[90],name2);
243 fprintf(fp_ou,"<tr><td class=\"header\" colspan=\"2\">%s:&nbsp;%s, %s</td></tr>\n",text[104],UserSortField,UserSortOrder);
244 fprintf(fp_ou,"<tr><td class=\"header3\" colspan=2>%s %s</td></tr>\n",text[32],text[55]);
245 fputs("<tr><td></td></tr>\n",fp_ou);
246
247 fputs("</table></center>\n",fp_ou);
248 fputs("<center><table cellpadding=\"2\" cellspacing=\"1\">\n",fp_ou);
249
250 if(strlen(denied_report) > 0) {
251 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]);
252 }
253
254 strcpy(val3,text[92]);
255 strcpy(val4,text[93]);
256 sprintf(val11,"%%%s",text[93]);
257 sprintf(val5,"%s-%s-%s",text[113],text[114],text[112]);
258 strcpy(val6,text[94]);
259 strcpy(val7,text[95]);
260 sprintf(val8,"%%%s",text[99]);
261 strcpy(val9,"colspan=2");
262 bzero(val10, 255);
263
264 if(strstr(UserReportFields,"CONNECT") == 0)
265 bzero(val3, 255);
266 if(strstr(UserReportFields,"BYTES") == 0)
267 bzero(val4, 255);
268 if(strstr(UserReportFields,"SETYB") == 0)
269 bzero(val11, 255);
270 if(strstr(UserReportFields,"IN-CACHE-OUT") == 0) {
271 bzero(val5, 255);
272 bzero(val9, 255);
273 strcpy(val10,"<td></td>");
274 }
275 if(strstr(UserReportFields,"USED_TIME") == 0)
276 bzero(val6, 255);
277 if(strstr(UserReportFields,"MILISEC") == 0)
278 bzero(val7, 255);
279 if(strstr(UserReportFields,"%TIME") == 0)
280 bzero(val8, 255);
281
282 fprintf(fp_ou,"<tr><th></th><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header3\" %s>%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th></tr>\n",text[91],val3,val4,val11,val9,val5,val6,val7,val8);
283
284 if(debug) {
285 if(userip) {
286 strcpy(u2,usuario);
287 fixip(u2);
288 sprintf(msg, "%s: %s",text[61],u2);
289 } else
290 sprintf(msg, "%s: %s",text[61],usuario);
291 debuga(msg);
292 }
293
294 fscanf(fp_in,"%s",nacc);
295 fscanf(fp_in,"%s",nbytes);
296 fscanf(fp_in,"%s",url);
297 fscanf(fp_in,"%s",tmsg);
298 fscanf(fp_in,"%s",nelap);
299 fscanf(fp_in,"%s",incac);
300 fscanf(fp_in,"%s",oucac);
301
302 while(!feof(fp_in)) {
303 if(strncmp(tmsg,"OK",2) != 0)
304 sprintf(tmsg,"<td class=\"data\">%s</td>",text[46]);
305 else bzero(tmsg, 50);
306
307 nnbytes=my_atoll(nbytes);
308 nnelap=my_atoll(nelap);
309 incache=my_atoll(incac);
310 oucache=my_atoll(oucac);
311
312 if(nnbytes) {
313 perc=nnbytes * 100;
314 perc=perc / tnbytes;
315 } else {
316 perc=0;
317 ouperc=0;
318 }
319
320 if(nnelap) {
321 perc2=nnelap * 100;
322 perc2=perc2 / tnelap;
323 } else perc2=0;
324
325 if(incache) {
326 inperc=incache * 100;
327 inperc=inperc / nnbytes;
328 } else inperc=0;
329
330 if(oucache) {
331 ouperc=oucache * 100;
332 ouperc=ouperc / nnbytes;
333 } else ouperc=0;
334
335 twork=my_atoll(nacc);
336 strcpy(wwork1,fixnum(twork,1));
337 strcpy(wwork2,fixnum(nnbytes,1));
338 strcpy(wwork3,fixnum2(nnelap,1));
339
340 if(strcmp(LongUrl,"yes") != 0) {
341 if (getword(warea,sizeof(warea),url,'/')<0) {
342 printf("SARG: Maybe you have a broken record or garbage in the url of the %s file.\n",arqin);
343 exit(1);
344 }
345 sprintf(url,"%s",warea);
346 strcpy(urly,url);
347 } else {
348 strcpy(urly,url);
349 url_module(url, module);
350 if (getword(warea,sizeof(warea),url,'/')<0) {
351 printf("SARG: Maybe you have a broken record or garbage in the url of the %s file.\n",arqin);
352 exit(1);
353 }
354 sprintf(url,"%s...%s",warea,module);
355 }
356
357 if(strcmp(Privacy,"yes") == 0)
358 sprintf(httplink,"<font color=%s><href=http://%s>%s", \
359 PrivacyStringColor,PrivacyString,PrivacyString);
360 else
361 strcpy(tmp6,"../../images");
362 if(strcmp(IndexTree,"date") == 0)
363 sprintf(tmp6,"../%s",ImageFile);
364 if(strlen(BlockIt) > 0)
365 sprintf(httplink,"<a href=\"%s%s?url=%s\"><img src=\"%s/sarg-squidguard-block.png\" border=\"0\"></a><a href=http://%s>&nbsp;%s</a>",wwwDocumentRoot,BlockIt,urly,tmp6,urly,urly);
366 else
367 sprintf(httplink,"<a href=http://%s title=\"%s\">%s</a>",urly,urly,url);
368
369 if(strstr(ReportType,"site_user_time_date") != 0) {
370 strcpy(ltext110,text[110]);
371 for(s=ltext110; *s; ++s)
372 *s=tolower(*s);
373 strcpy(siteind,urly);
374 str=siteind;
375 for(z1=0; str[z1]; z1++) {
376 if(str[z1]=='?' || str[z1]=='-' || str[z1]=='.' || str[z1]==':' || str[z1]=='/' || str[z1]=='\\' || str[z1]=='*' ||
377 str[z1]=='\'' || str[z1]=='\"' || str[z1]=='$')
378 str[z1]='_';
379 }
380 sprintf(href2,"<a href=\"tt%s-%s.html\"><img src=\"%s/datetime.png\" border=\"0\" title=\"%s %s\"></a>",usuario,siteind,tmp6,ltext110,text[55]);
381 } else {
382 bzero(href2, MAXLEN);
383 bzero(ltext110, 50);
384 }
385
386 sprintf(val2,"%s",href2);
387 sprintf(val3,"%3.2f%%",perc);
388 sprintf(val4,"%3.2f%%",inperc);
389 sprintf(val5,"%3.2f%%",ouperc);
390 sprintf(val6,"%s",buildtime(nnelap));
391 sprintf(val7,"%3.2f%%",perc2);
392
393 if(strstr(UserReportFields,"CONNECT") == 0) {
394 bzero(wwork1, 255);
395 bzero(hbc1, 30);
396 }
397 if(strstr(UserReportFields,"BYTES") == 0) {
398 bzero(wwork2, 255);
399 bzero(hbc2, 30);
400 }
401 if(strstr(UserReportFields,"MILISEC") == 0) {
402 bzero(wwork3, 255);
403 bzero(hbc3, 30);
404 }
405 if(strstr(UserReportFields,"SETYB") == 0) {
406 bzero(val3, 255);
407 bzero(hbc4, 30);
408 }
409 if(strstr(UserReportFields,"IN-CACHE-OUT") == 0) {
410 bzero(val4, 255);
411 bzero(val5, 255);
412 bzero(hbc5, 30);
413 bzero(hbc6, 30);
414 }
415 if(strstr(UserReportFields,"USED_TIME") == 0) {
416 bzero(val6, 255);
417 bzero(hbc7, 30);
418 }
419 if(strstr(UserReportFields,"%TIME") == 0) {
420 bzero(val7, 255);
421 bzero(hbc8, 30);
422 }
423 if(strncmp(tmsg," ",1) == 0)
424 bzero(hbc9, 30);
425
426
427 if(UserReportLimit<=0 || count<=UserReportLimit) {
428 fprintf(fp_ou,"<tr><td class=\"data\">%s</td><td class=\"data2\">%s</td><td class=\"data\">%s</td><td class=\"data\">%s</td><td class=\"data\">%s</td><td class=\"data\">%s</td><td class=\"data\">%s</td><td class=\"data\">%s</td><td class=\"data\">%s</td><td class=\"data\">%s</td>%s</tr>\n",val2,httplink,wwork1,wwork2,val3,val4,val5,val6,wwork3,val7,tmsg);
429 count++;
430 }
431
432 if(iprel) {
433 strcpy(arqip,tmp);
434 strcat(arqip,"/");
435 strcat(arqip,usuario);
436 strcat(arqip,".ip");
437
438 if ((fp_ip = fopen(arqip, "r")) == 0){
439 fprintf(stderr, "SARG: (html6) %s: %s\n",text[45],arqip);
440 exit(1);
441 }
442
443 if ((fp_ip2 = MY_FOPEN(tmp2, "a")) == 0){
444 fprintf(stderr, "SARG: (html7) %s: %s\n",text[45],tmp2);
445 exit(1);
446 }
447
448 while(fgets(buf,sizeof(buf),fp_ip)!=NULL) {
449 if(strstr(buf,url) != 0)
450 fputs(buf,fp_ip2);
451 }
452
453 fclose(fp_ip);
454 fclose(fp_ip2);
455
456 sprintf(csort,"sort -n -T %s -k 1,1 -k 5,5 -o '%s' '%s'",TempDir,tmp3,tmp2);
457 cstatus=system(csort);
458 if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
459 fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus));
460 fprintf(stderr, "SARG: sort command: %s\n",csort);
461 exit(1);
462 }
463
464 if ((fp_ip = MY_FOPEN(tmp3, "r")) == 0) {
465 fprintf(stderr, "SARG: (html8) %s: %s\n",text[45],tmp3);
466 exit(1);
467 }
468
469 fscanf(fp_ip,"%s",user_ip);
470 fscanf(fp_ip,"%s",userurl);
471 fscanf(fp_ip,"%s",userdia);
472 fscanf(fp_ip,"%s",userhora);
473 fscanf(fp_ip,"%s",userbytes);
474 fscanf(fp_ip,"%s",userelap);
475
476 strcpy(olduserip,user_ip);
477
478 while(!feof(fp_ip)) {
479 if(strcmp(user_ip,olduserip) != 0) {
480 my_lltoa(unelap,val2,0);
481 sprintf(wwork1,"%s",fixnum(unbytes,1));
482 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);
483
484 strcpy(olduserip,user_ip);
485 unacc=0;
486 unbytes=0;
487 unelap=0;
488 }
489
490 unbytes=unbytes+my_atoll(userbytes);
491 unelap=unelap+my_atoll(userelap);
492
493 fscanf(fp_ip,"%s",user_ip);
494 fscanf(fp_ip,"%s",userurl);
495 fscanf(fp_ip,"%s",userdia);
496 fscanf(fp_ip,"%s",userhora);
497 fscanf(fp_ip,"%s",userbytes);
498 fscanf(fp_ip,"%s",userelap);
499
500 }
501
502 fclose(fp_ip);
503
504 unlink(tmp2);
505 unlink(tmp3);
506
507 my_lltoa(unelap,val3,0);
508 sprintf(wwork1,"%s",fixnum(unbytes,1));
509 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</font></td></tr>\n",olduserip,wwork1,buildtime(unelap),val3);
510 }
511
512 unacc=0;
513 unbytes=0;
514 unelap=0;
515
516 fscanf(fp_in,"%s",nacc);
517 fscanf(fp_in,"%s",nbytes);
518 fscanf(fp_in,"%s",url);
519 fscanf(fp_in,"%s",tmsg);
520 fscanf(fp_in,"%s",nelap);
521 fscanf(fp_in,"%s",incac);
522 fscanf(fp_in,"%s",oucac);
523 // fscanf(fp_in,"%s",datestimes);
524
525 }
526
527 if(iprel)
528 unlink(arqip);
529 unlink(arqin);
530
531 if(tnbytes) {
532 perc=totbytes / 100;
533 perc=tnbytes / perc;
534 } else perc=0;
535
536 if(tnelap) {
537 perc2=totelap / 100;
538 perc2=tnelap / perc2;
539 } else perc2=0;
540
541 if(tnoucache) {
542 ouperc=tnoucache * 100;
543 ouperc=ouperc / tnbytes;
544 } else ouperc=0;
545
546 if(tnincache) {
547 inperc=tnincache * 100;
548 inperc=inperc / tnbytes;
549 } else inperc=0;
550
551 sprintf(wwork1,"%s",fixnum(tnacc,1));
552 sprintf(wwork2,"%s",fixnum(tnbytes,1));
553 sprintf(wwork3,"%s",fixnum2(tnelap,1));
554
555 sprintf(val2,"%s%s",href2,ltext110);
556 sprintf(val3,"%3.2f%%",perc);
557 sprintf(val4,"%3.2f%%",inperc);
558 sprintf(val5,"%3.2f%%",ouperc);
559 sprintf(val6,"%s",buildtime(tnelap));
560 sprintf(val7,"%3.2f%%",perc2);
561
562 strcpy(hbc1,"class=\"header2\"");
563 strcpy(hbc2,"class=\"header2\"");
564 strcpy(hbc3,"class=\"header2\"");
565 strcpy(hbc4,"class=\"header2\"");
566 strcpy(hbc5,"class=\"header2\"");
567 strcpy(hbc6,"class=\"header2\"");
568 strcpy(hbc7,"class=\"header2\"");
569 strcpy(hbc8,"class=\"header2\"");
570 strcpy(hbc9,"class=\"header\"");
571
572 if(strstr(UserReportFields,"CONNECT") == 0) {
573 bzero(wwork1, 255);
574 bzero(hbc1, 30);
575 }
576 if(strstr(UserReportFields,"BYTES") == 0) {
577 bzero(wwork2, 255);
578 bzero(hbc2, 30);
579 }
580 if(strstr(UserReportFields,"MILISEC") == 0) {
581 bzero(wwork3, 255);
582 bzero(hbc3, 30);
583 }
584 if(strstr(UserReportFields,"SETYB") == 0) {
585 bzero(val3, 255);
586 bzero(hbc4, 30);
587 }
588 if(strstr(UserReportFields,"IN-CACHE-OUT") == 0) {
589 bzero(val4, 255);
590 bzero(hbc5, 30);
591 }
592 if(strstr(UserReportFields,"IN-CACHE-OUT") == 0) {
593 bzero(val5, 255);
594 bzero(hbc6, 30);
595 }
596 if(strstr(UserReportFields,"USED_TIME") == 0) {
597 bzero(val6, 255);
598 bzero(hbc7, 30);
599 }
600 if(strstr(UserReportFields,"%TIME") == 0) {
601 bzero(val7, 255);
602 bzero(hbc8, 30);
603 }
604
605 if(strstr(UserReportFields,"TOTAL") != 0) {
606 fprintf(fp_ou,"<tr><th></th><th %s>%s</th><th %s>%s</th><th %s>%s</th><th %s>%s</th><th %s>%s</th><th %s>%s</th><th %s>%s</th><th %s>%s</font></th><th %s>%s</font></th></tr>\n",hbc9,text[107],hbc1,wwork1,hbc2,wwork2,hbc4,val3,hbc5,val4,hbc6,val5,hbc7,val6,hbc3,wwork3,hbc8,val7);
607 }
608
609 fclose(fp_in);
610
611 if(atoi(PerUserLimit) > 0) {
612 if(tnbytes > (atoi(PerUserLimit)*1000000)) {
613 limit_flag=0;
614 if(access(PerUserLimitFile, R_OK) == 0) {
615 if((fp_usr = fopen(PerUserLimitFile, "r")) == 0) {
616 fprintf(stderr, "SARG: (html9) %s: %s\n",text[45],PerUserLimitFile);
617 exit(1);
618 }
619 while(fgets(tmp6,sizeof(tmp6),fp_usr)!=NULL) {
620 if(strstr(tmp6,"\n") != 0)
621 tmp6[strlen(tmp6)-1]='\0';
622 if(strcmp(tmp6,u2) == 0) {
623 limit_flag=1;
624 break;
625 }
626 }
627 fclose(fp_usr);
628 }
629
630 if(!limit_flag) {
631 if((fp_usr = fopen(PerUserLimitFile, "a")) == 0) {
632 fprintf(stderr, "SARG: (html10) %s: %s\n",text[45],PerUserLimitFile);
633 exit(1);
634 }
635 fprintf(fp_usr,"%s\n",u2);
636 fclose(fp_usr);
637
638 if(debug) {
639 sprintf(msg, "%s %s %s (%s MB). %s %s",text[32],u2,text[74],PerUserLimit,text[75],PerUserLimitFile);
640 debuga(msg);
641 }
642 }
643 }
644 }
645
646 // if(indexonly) {
647 // unlink(arqou);
648 // continue;
649 // }
650
651 if (strstr(ReportType,"topuser") != 0) {
652 strcpy(arqper,dirname);
653 strcat(arqper,"/sarg-users");
654
655 if ((fp_in = fopen(arqper, "r")) == 0){
656 fprintf(stderr, "SARG: (html11) %s: %s\n",text[45],arqper);
657 exit(1);
658 }
659
660 fgets(totuser,8,fp_in);
661 fclose(fp_in);
662
663 totbytes2=totbytes/my_atoll(totuser);
664 totelap2=totelap/my_atoll(totuser);
665
666 if(totbytes2) {
667 perc = totbytes / 100;
668 perc = totbytes2 / perc;
669 } else perc=0;
670
671 if(totelap2) {
672 perc2 = totelap / 100;
673 perc2 = totelap2 / perc2;
674 } else perc2=0;
675
676 twork2=my_atoll(totuser);
677 twork=ttnacc/twork2;
678
679 sprintf(wwork1,"%s",fixnum(twork,1));
680 sprintf(wwork2,"%s",fixnum(totbytes2,1));
681 sprintf(wwork3,"%s",fixnum2(totelap2,1));
682
683 sprintf(val6,"%s",buildtime(totelap2));
684 sprintf(val7,"%3.2f%%",perc2);
685
686 strcpy(hbc1,"class=\"header2\"");
687 strcpy(hbc2,"class=\"header2\"");
688 strcpy(hbc3,"class=\"header2\"");
689 strcpy(hbc4,"class=\"header2\"");
690 strcpy(hbc5,"class=\"header2\"");
691 strcpy(hbc6,"class=\"header\"");
692
693 if(strstr(UserReportFields,"CONNECT") == 0) {
694 bzero(wwork1, 255);
695 bzero(hbc1, 30);
696 }
697 if(strstr(UserReportFields,"BYTES") == 0) {
698 bzero(wwork2, 255);
699 bzero(hbc2, 30);
700 }
701 if(strstr(UserReportFields,"MILISEC") == 0) {
702 bzero(wwork3, 255);
703 bzero(hbc3, 30);
704 }
705 if(strstr(UserReportFields,"USED_TIME") == 0) {
706 bzero(val6, 255);
707 bzero(hbc4, 30);
708 }
709 if(strstr(UserReportFields,"%TIME") == 0) {
710 bzero(val7, 255);
711 bzero(hbc5, 30);
712 }
713
714 if(strstr(UserReportFields,"AVERAGE") != 0) {
715 fprintf(fp_ou,"<tr><th></th><th %s>%s</th><th %s>%s</th><th %s>%s</th><th></th><th></th><th></th><th %s>%s</th><th %s>%s</font></th><th %s>%s</th></tr>\n",hbc6,text[96],hbc1,wwork1,hbc2,wwork2,hbc4,val6,hbc3,wwork3,hbc5,val7);
716 }
717 } /* added */
718 tnacc=0;
719 tnbytes=0;
720 tnelap=0;
721 tnincache=0;
722 tnoucache=0;
723
724 fputs("</center></table>\n",fp_ou);
725
726 show_info(fp_ou);
727
728 fputs("</body>\n</html>\n",fp_ou);
729
730 fclose(fp_ou);
731
732 htaccess(wusuario);
733
734 }
735
736 (void)rewinddir(dirp);
737 (void)closedir(dirp);
738
739 return;
740 }