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