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