]> git.ipfire.org Git - thirdparty/sarg.git/blame - html.c
Patch #2657320 applied.
[thirdparty/sarg.git] / html.c
CommitLineData
25697a35 1/*
94ff9470 2 * AUTHOR: Pedro Lineu Orso orso@penguintech.com.br
25697a35 3 * 1998, 2005
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"
27
28void htmlrel()
29{
30 DIR *dirp;
31 FILE *fp_in, *fp_ou, *fp_ip, *fp_ip2, *fp_usr, *fp_tt;
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];
491b862f 38 char nacc[20], nbytes[20], url[1024], purl[1024], tmsg[50], tmsg2[50], nelap[20], csort[MAXLEN];
d6e703cc 39 char period[MAXLEN], usuario[MAXLEN], wusuario[MAXLEN], u2[MAXLEN], duser[MAXLEN];
25697a35
GS
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];
94ff9470 42 char denied_report[255], name2[MAXLEN];
25697a35
GS
43 char ttd1[3], ttd2[3], ttd3[5], ttt1[3], ttt2[3], ttt3[3];
44 char *str;
45 char ftime[128], 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 x, count;
456d78a5 51 int cstatus;
25697a35 52
25697a35
GS
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);
d6e703cc 62 strcat(arqper,"/sarg-period");
25697a35
GS
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
d6e703cc 69 fgets(period,sizeof(period),fp_in);
25697a35
GS
70 fclose(fp_in);
71
72 strcpy(arqper,dirname);
d6e703cc 73 strcat(arqper,"/sarg-general");
25697a35
GS
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) {
4bcb77cf
FM
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 }
25697a35 86 ttnacc+=my_atoll(buf);
4bcb77cf
FM
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 }
25697a35 91 totbytes+=my_atoll(wtemp);
4bcb77cf
FM
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 }
25697a35
GS
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:
4bcb77cf
FM
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 }
25697a35
GS
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, iprel, userip);
130 greport_day(wusuario, iprel, userip);
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) {
4bcb77cf
FM
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 }
25697a35 164 tnacc+=my_atoll(wtemp);
4bcb77cf
FM
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 }
25697a35 169 tnbytes+=my_atoll(wtemp);
4bcb77cf
FM
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 }
25697a35 175 tnelap+=my_atoll(wtemp);
4bcb77cf
FM
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 }
25697a35 180 tnincache+=my_atoll(wtemp);
4bcb77cf
FM
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 }
25697a35
GS
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 sprintf(html," <meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">\n",CharSet);
205 fputs(html,fp_ou);
206 css(fp_ou);
207 fputs("</head>\n",fp_ou);
208
209 sprintf(buf,"<body style=\"font-family:%s;font-size:%s;background-color:%s; \
210 background-image:url(%s)\">\n",FontFace,TitleFontSize,BgColor,BgImage);
211 fputs(buf,fp_ou);
212
94ff9470
GS
213 if(strlen(LogoImage) > 0) {
214 fputs("<center><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_ou);
215 sprintf(html,"<tr><th class=\"logo\"><img src='%s' border=0 align=absmiddle width=%s height=%s>&nbsp;%s</th></tr>\n",LogoImage,Width,Height,LogoText);
216 fputs(html,fp_ou);
217 fputs("<tr><td height=\"5\"></td></tr>\n",fp_ou);
218 fputs("</table>\n",fp_ou);
219 }
25697a35 220
491b862f
GS
221 if(strcmp(IndexTree,"date") == 0)
222 show_sarg(fp_ou, "../../../..");
223 else
224 show_sarg(fp_ou, "../..");
225
25697a35
GS
226 fputs("<center><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_ou);
227 sprintf(html,"<tr><th class=\"title\" colspan=\"2\">%s</th></tr>\n",Title);
228 fputs(html,fp_ou);
229
230 strcpy(u2,usuario);
231 if(userip){
232 strcpy(u2,usuario);
233 fixip(u2);
234 }
235 if(strcmp(Ip2Name,"yes") == 0)
a1c55d8c 236 ip2name(u2,sizeof(u2));
25697a35
GS
237
238 if(UserTabFile[0] != '\0') {
239 sprintf(warea,":%s:",u2);
240 if((str=(char *) strstr(userfile,warea)) != (char *) NULL ) {
241 z1=0;
242 str2=(char *) strstr(str+1,":");
243 str2++;
244 bzero(name, MAXLEN);
245 while(str2[z1] != ':') {
246 name[z1]=str2[z1];
247 z1++;
248 }
249 } else strcpy(name,u2);
250 } else strcpy(name,u2);
94ff9470
GS
251
252 strcpy(name2,name);
253 if(dotinuser && strstr(name2,"_")) {
254 str2=(char *)subs(name2,"_",".");
255 strcpy(name2,str2);
256 }
25697a35 257
d6e703cc 258 sprintf(html,"<tr><td class=\"header\" colspan=\"2\">%s:&nbsp;%s</td></tr>\n",text[89],period);
25697a35 259 fputs(html,fp_ou);
94ff9470 260 sprintf(html,"<tr><td class=\"header\" colspan=\"2\">%s:&nbsp;%s</td></tr>\n",text[90],name2);
25697a35
GS
261 fputs(html,fp_ou);
262 sprintf(html,"<tr><td class=\"header\" colspan=\"2\">%s:&nbsp;%s, %s</td></tr>\n",text[104],UserSortField,UserSortOrder);
263 fputs(html,fp_ou);
264 sprintf(html,"<tr><td class=\"header3\" colspan=2>%s %s</td></tr>\n",text[32],text[55]);
265 fputs(html,fp_ou);
266 fputs("<tr><td></td></tr>\n",fp_ou);
267
268 fputs("</table></center>\n",fp_ou);
d6e703cc 269 fputs("<center><table cellpadding=\"2\" cellspacing=\"1\">\n",fp_ou);
25697a35
GS
270
271 if(strlen(denied_report) > 0) {
272 sprintf(html,"<tr><td class=\"header\" colspan=11><a href=\"denied_%s.html\">%s</a> %s</td></tr>\n",denied_report,text[116],text[55]);
273 fputs(html,fp_ou);
274 }
275
276 strcpy(val3,text[92]);
277 strcpy(val4,text[93]);
278 sprintf(val11,"%%%s",text[93]);
279 sprintf(val5,"%s-%s-%s",text[113],text[114],text[112]);
280 strcpy(val6,text[94]);
281 strcpy(val7,text[95]);
282 sprintf(val8,"%%%s",text[99]);
283 strcpy(val9,"colspan=2");
284 bzero(val10, 255);
285
286 if(strstr(UserReportFields,"CONNECT") == 0)
287 bzero(val3, 255);
288 if(strstr(UserReportFields,"BYTES") == 0)
289 bzero(val4, 255);
290 if(strstr(UserReportFields,"SETYB") == 0)
291 bzero(val11, 255);
292 if(strstr(UserReportFields,"IN-CACHE-OUT") == 0) {
293 bzero(val5, 255);
294 bzero(val9, 255);
295 strcpy(val10,"<td></td>");
296 }
297 if(strstr(UserReportFields,"USED_TIME") == 0)
298 bzero(val6, 255);
299 if(strstr(UserReportFields,"MILISEC") == 0)
300 bzero(val7, 255);
301 if(strstr(UserReportFields,"%TIME") == 0)
302 bzero(val8, 255);
303
304 sprintf(html,"<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);
305 fputs(html,fp_ou);
306
307 if(debug) {
308 if(userip) {
309 strcpy(u2,usuario);
310 fixip(u2);
311 sprintf(msg, "%s: %s",text[61],u2);
312 } else
313 sprintf(msg, "%s: %s",text[61],usuario);
314 debuga(msg);
315 }
316
317 fscanf(fp_in,"%s",nacc);
318 fscanf(fp_in,"%s",nbytes);
319 fscanf(fp_in,"%s",url);
320 fscanf(fp_in,"%s",tmsg);
321 fscanf(fp_in,"%s",nelap);
322 fscanf(fp_in,"%s",incac);
323 fscanf(fp_in,"%s",oucac);
324
325 while(!feof(fp_in)) {
326 if(strncmp(tmsg,"OK",2) != 0)
327 sprintf(tmsg,"<td class=\"data\">%s</td>",text[46]);
328 else bzero(tmsg, 50);
329
330 nnbytes=my_atoll(nbytes);
331 nnelap=my_atoll(nelap);
332 incache=my_atoll(incac);
333 oucache=my_atoll(oucac);
334
335 if(nnbytes) {
336 perc=nnbytes * 100;
337 perc=perc / tnbytes;
338 } else {
339 perc=0;
340 ouperc=0;
341 }
342
343 if(nnelap) {
344 perc2=nnelap * 100;
345 perc2=perc2 / tnelap;
346 } else perc2=0;
347
348 if(incache) {
349 inperc=incache * 100;
350 inperc=inperc / nnbytes;
351 } else inperc=0;
352
353 if(oucache) {
354 ouperc=oucache * 100;
355 ouperc=ouperc / nnbytes;
356 } else ouperc=0;
357
358 twork=my_atoll(nacc);
359 sprintf(wwork1,"%s",fixnum(twork,1));
360 sprintf(wwork2,"%s",fixnum(nnbytes,1));
d6e703cc 361 sprintf(wwork3,"%s",fixnum2(nnelap,1));
25697a35
GS
362
363 if(strcmp(LongUrl,"yes") != 0) {
4bcb77cf
FM
364 if (getword(warea,sizeof(warea),url,'/')<0) {
365 printf("SARG: Maybe you have a broken record or garbage in the url of the %s file.\n",arqin);
366 exit(1);
367 }
25697a35
GS
368 sprintf(url,"%s",warea);
369 strcpy(urly,url);
370 } else {
371 strcpy(urly,url);
372 url_module(url, module);
4bcb77cf
FM
373 if (getword(warea,sizeof(warea),url,'/')<0) {
374 printf("SARG: Maybe you have a broken record or garbage in the url of the %s file.\n",arqin);
375 exit(1);
376 }
25697a35
GS
377 sprintf(url,"%s...%s",warea,module);
378 }
379
380 if(strcmp(Privacy,"yes") == 0)
381 sprintf(httplink,"<font color=%s><href=http://%s>%s", \
382 PrivacyStringColor,PrivacyString,PrivacyString);
383 else
491b862f
GS
384 strcpy(tmp6,"../../images");
385 if(strcmp(IndexTree,"date") == 0)
386 sprintf(tmp6,"../%s",ImageFile);
25697a35 387 if(strlen(BlockIt) > 0)
491b862f 388 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);
25697a35
GS
389 else
390 sprintf(httplink,"<a href=http://%s title=\"%s\">%s</a>",urly,urly,url);
391
392 if(strstr(ReportType,"site_user_time_date") != 0) {
393 sprintf(ltext110,"%s",text[110]);
394 if(ltext110){
395 for(s=ltext110; *s; ++s)
396 *s=tolower(*s);
397 }
398 strcpy(siteind,urly);
399 str=siteind;
a1c55d8c
FM
400 for(z1=0; str[z1]; z1++) {
401 if(str[z1]=='?' || str[z1]=='-' || str[z1]=='.' || str[z1]==':' || str[z1]=='/' || str[z1]=='\\' || str[z1]=='*' ||
402 str[z1]=='\'' || str[z1]=='\"' || str[z1]=='$')
25697a35
GS
403 str[z1]='_';
404 }
491b862f 405 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]);
25697a35
GS
406 } else {
407 bzero(href2, MAXLEN);
408 bzero(ltext110, 50);
409 }
410
411 sprintf(val2,"%s",href2);
412 sprintf(val3,"%3.2f%%",perc);
413 sprintf(val4,"%3.2f%%",inperc);
414 sprintf(val5,"%3.2f%%",ouperc);
415 sprintf(val6,"%s",buildtime(nnelap));
416 sprintf(val7,"%3.2f%%",perc2);
417
418 if(strstr(UserReportFields,"CONNECT") == 0) {
419 bzero(wwork1, 255);
420 bzero(hbc1, 30);
421 }
422 if(strstr(UserReportFields,"BYTES") == 0) {
423 bzero(wwork2, 255);
424 bzero(hbc2, 30);
425 }
426 if(strstr(UserReportFields,"MILISEC") == 0) {
427 bzero(wwork3, 255);
428 bzero(hbc3, 30);
429 }
430 if(strstr(UserReportFields,"SETYB") == 0) {
431 bzero(val3, 255);
432 bzero(hbc4, 30);
433 }
434 if(strstr(UserReportFields,"IN-CACHE-OUT") == 0) {
435 bzero(val4, 255);
436 bzero(val5, 255);
437 bzero(hbc5, 30);
438 bzero(hbc6, 30);
439 }
440 if(strstr(UserReportFields,"USED_TIME") == 0) {
441 bzero(val6, 255);
442 bzero(hbc7, 30);
443 }
444 if(strstr(UserReportFields,"%TIME") == 0) {
445 bzero(val7, 255);
446 bzero(hbc8, 30);
447 }
448 if(strncmp(tmsg," ",1) == 0)
449 bzero(hbc9, 30);
450
451 sprintf(html,"<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);
452
453 if(UserReportLimit) {
454 if(count <= UserReportLimit) {
455 fputs(html,fp_ou);
456 count++;
457 }
458 } else fputs(html,fp_ou);
459
460 if(iprel) {
461 strcpy(arqip,tmp);
462 strcat(arqip,"/");
463 strcat(arqip,usuario);
464 strcat(arqip,".ip");
465
466 if ((fp_ip = fopen(arqip, "r")) == 0){
467 fprintf(stderr, "SARG: (html6) %s: %s\n",text[45],arqip);
468 exit(1);
469 }
0dda06bf
FM
470
471#if defined(HAVE_FOPEN64)
472 if ((fp_ip2 = (long)fopen64(tmp2, "a")) == 0){
473#else
25697a35 474 if ((fp_ip2 = fopen(tmp2, "a")) == 0){
0dda06bf 475#endif
25697a35
GS
476 fprintf(stderr, "SARG: (html7) %s: %s\n",text[45],tmp2);
477 exit(1);
478 }
479
480 while(fgets(buf,sizeof(buf),fp_ip)!=NULL) {
481 if(strstr(buf,url) != 0)
482 fputs(buf,fp_ip2);
483 }
484
485 fclose(fp_ip);
486 fclose(fp_ip2);
487
94ff9470 488 sprintf(csort,"sort -n -T %s -k 1,1 -k 5,5 -o '%s' '%s'",TempDir,tmp3,tmp2);
456d78a5
FM
489 cstatus=system(csort);
490 if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
491 fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus));
492 fprintf(stderr, "SARG: sort command: %s\n",csort);
493 exit(1);
494 }
25697a35 495
0dda06bf
FM
496#if defined(HAVE_FOPEN64)
497 if ((fp_ip = (long)fopen64(tmp3, "r")) == 0) {
498#else
25697a35 499 if ((fp_ip = fopen(tmp3, "r")) == 0) {
0dda06bf 500#endif
25697a35
GS
501 fprintf(stderr, "SARG: (html8) %s: %s\n",text[45],tmp3);
502 exit(1);
503 }
504
505 fscanf(fp_ip,"%s",user_ip);
506 fscanf(fp_ip,"%s",userurl);
507 fscanf(fp_ip,"%s",userdia);
508 fscanf(fp_ip,"%s",userhora);
509 fscanf(fp_ip,"%s",userbytes);
510 fscanf(fp_ip,"%s",userelap);
511
512 strcpy(olduserip,user_ip);
513
514 while(!feof(fp_ip)) {
515 if(strcmp(user_ip,olduserip) != 0) {
516 my_lltoa(unelap,val2,0);
517 sprintf(wwork1,"%s",fixnum(unbytes,1));
518 sprintf(html,"<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);
519 fputs(html,fp_ou);
520
521 strcpy(olduserip,user_ip);
522 unacc=0;
523 unbytes=0;
524 unelap=0;
525 }
526
527 unbytes=unbytes+my_atoll(userbytes);
528 unelap=unelap+my_atoll(userelap);
529
530 fscanf(fp_ip,"%s",user_ip);
531 fscanf(fp_ip,"%s",userurl);
532 fscanf(fp_ip,"%s",userdia);
533 fscanf(fp_ip,"%s",userhora);
534 fscanf(fp_ip,"%s",userbytes);
535 fscanf(fp_ip,"%s",userelap);
536
537 }
538
539 fclose(fp_ip);
540
541 unlink(tmp2);
542 unlink(tmp3);
543
544 my_lltoa(unelap,val3,0);
545 sprintf(wwork1,"%s",fixnum(unbytes,1));
546 sprintf(html,"<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);
547 fputs(html,fp_ou);
548 }
549
550 unacc=0;
551 unbytes=0;
552 unelap=0;
553
554 fscanf(fp_in,"%s",nacc);
555 fscanf(fp_in,"%s",nbytes);
556 fscanf(fp_in,"%s",url);
557 fscanf(fp_in,"%s",tmsg);
558 fscanf(fp_in,"%s",nelap);
559 fscanf(fp_in,"%s",incac);
560 fscanf(fp_in,"%s",oucac);
561// fscanf(fp_in,"%s",datestimes);
562
563 }
564
565 if(iprel)
566 unlink(arqip);
567 unlink(arqin);
568
569 if(tnbytes) {
570 perc=totbytes / 100;
571 perc=tnbytes / perc;
572 } else perc=0;
573
574 if(tnelap) {
575 perc2=totelap / 100;
576 perc2=tnelap / perc2;
577 } else perc2=0;
578
579 if(tnoucache) {
580 ouperc=tnoucache * 100;
581 ouperc=ouperc / tnbytes;
582 } else ouperc=0;
583
584 if(tnincache) {
585 inperc=tnincache * 100;
586 inperc=inperc / tnbytes;
587 } else inperc=0;
588
589 sprintf(wwork1,"%s",fixnum(tnacc,1));
590 sprintf(wwork2,"%s",fixnum(tnbytes,1));
d6e703cc 591 sprintf(wwork3,"%s",fixnum2(tnelap,1));
25697a35
GS
592
593 sprintf(val2,"%s%s",href2,ltext110);
594 sprintf(val3,"%3.2f%%",perc);
595 sprintf(val4,"%3.2f%%",inperc);
596 sprintf(val5,"%3.2f%%",ouperc);
597 sprintf(val6,"%s",buildtime(tnelap));
598 sprintf(val7,"%3.2f%%",perc2);
599
600 strcpy(hbc1,"class=\"header2\"");
601 strcpy(hbc2,"class=\"header2\"");
602 strcpy(hbc3,"class=\"header2\"");
603 strcpy(hbc4,"class=\"header2\"");
604 strcpy(hbc5,"class=\"header2\"");
605 strcpy(hbc6,"class=\"header2\"");
606 strcpy(hbc7,"class=\"header2\"");
607 strcpy(hbc8,"class=\"header2\"");
608 strcpy(hbc9,"class=\"header\"");
609
610 if(strstr(UserReportFields,"CONNECT") == 0) {
611 bzero(wwork1, 255);
612 bzero(hbc1, 30);
613 }
614 if(strstr(UserReportFields,"BYTES") == 0) {
615 bzero(wwork2, 255);
616 bzero(hbc2, 30);
617 }
618 if(strstr(UserReportFields,"MILISEC") == 0) {
619 bzero(wwork3, 255);
620 bzero(hbc3, 30);
621 }
622 if(strstr(UserReportFields,"SETYB") == 0) {
623 bzero(val3, 255);
624 bzero(hbc4, 30);
625 }
626 if(strstr(UserReportFields,"IN-CACHE-OUT") == 0) {
627 bzero(val4, 255);
628 bzero(hbc5, 30);
629 }
630 if(strstr(UserReportFields,"IN-CACHE-OUT") == 0) {
631 bzero(val5, 255);
632 bzero(hbc6, 30);
633 }
634 if(strstr(UserReportFields,"USED_TIME") == 0) {
635 bzero(val6, 255);
636 bzero(hbc7, 30);
637 }
638 if(strstr(UserReportFields,"%TIME") == 0) {
639 bzero(val7, 255);
640 bzero(hbc8, 30);
641 }
642
643 if(strstr(UserReportFields,"TOTAL") != 0) {
644 sprintf(html,"<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);
645 fputs(html,fp_ou);
646 }
647
648 fclose(fp_in);
649
650 if(atoi(PerUserLimit) > 0) {
651 if(tnbytes > (atoi(PerUserLimit)*1000000)) {
652 limit_flag=0;
653 if(access(PerUserLimitFile, R_OK) == 0) {
654 if((fp_usr = fopen(PerUserLimitFile, "r")) == 0) {
655 fprintf(stderr, "SARG: (html9) %s: %s\n",text[45],PerUserLimitFile);
656 exit(1);
657 }
491b862f
GS
658 while(fgets(tmp6,sizeof(tmp6),fp_usr)!=NULL) {
659 if(strstr(tmp6,"\n") != 0)
660 tmp6[strlen(tmp6)-1]='\0';
661 if(strcmp(tmp6,u2) == 0) {
25697a35
GS
662 limit_flag=1;
663 break;
664 }
665 }
666 fclose(fp_usr);
667 }
668
669 if(!limit_flag) {
670 if((fp_usr = fopen(PerUserLimitFile, "a")) == 0) {
671 fprintf(stderr, "SARG: (html10) %s: %s\n",text[45],PerUserLimitFile);
672 exit(1);
673 }
674 sprintf(html,"%s\n",u2);
675 fputs(html,fp_usr);
676 fclose(fp_usr);
677
678 if(debug) {
679 sprintf(msg, "%s %s %s (%s MB). %s %s",text[32],u2,text[74],PerUserLimit,text[75],PerUserLimitFile);
680 debuga(msg);
681 }
682 }
683 }
684 }
685
d6e703cc
FM
686// if(indexonly) {
687// unlink(arqou);
688// continue;
689// }
690
691 if (strstr(ReportType,"topuser") != 0) {
25697a35 692 strcpy(arqper,dirname);
d6e703cc 693 strcat(arqper,"/sarg-users");
491b862f 694
25697a35
GS
695 if ((fp_in = fopen(arqper, "r")) == 0){
696 fprintf(stderr, "SARG: (html11) %s: %s\n",text[45],arqper);
697 exit(1);
698 }
699
700 fgets(totuser,8,fp_in);
701 fclose(fp_in);
702
703 totbytes2=totbytes/my_atoll(totuser);
704 totelap2=totelap/my_atoll(totuser);
705
706 if(totbytes2) {
707 perc = totbytes / 100;
708 perc = totbytes2 / perc;
709 } else perc=0;
710
711 if(totelap2) {
712 perc2 = totelap / 100;
713 perc2 = totelap2 / perc2;
714 } else perc2=0;
715
716 twork2=my_atoll(totuser);
717 twork=ttnacc/twork2;
718
719 sprintf(wwork1,"%s",fixnum(twork,1));
720 sprintf(wwork2,"%s",fixnum(totbytes2,1));
d6e703cc 721 sprintf(wwork3,"%s",fixnum2(totelap2,1));
25697a35
GS
722
723 sprintf(val6,"%s",buildtime(totelap2));
724 sprintf(val7,"%3.2f%%",perc2);
725
726 strcpy(hbc1,"class=\"header2\"");
727 strcpy(hbc2,"class=\"header2\"");
728 strcpy(hbc3,"class=\"header2\"");
729 strcpy(hbc4,"class=\"header2\"");
730 strcpy(hbc5,"class=\"header2\"");
731 strcpy(hbc6,"class=\"header\"");
732
733 if(strstr(UserReportFields,"CONNECT") == 0) {
734 bzero(wwork1, 255);
735 bzero(hbc1, 30);
736 }
737 if(strstr(UserReportFields,"BYTES") == 0) {
738 bzero(wwork2, 255);
739 bzero(hbc2, 30);
740 }
741 if(strstr(UserReportFields,"MILISEC") == 0) {
742 bzero(wwork3, 255);
743 bzero(hbc3, 30);
744 }
745 if(strstr(UserReportFields,"USED_TIME") == 0) {
746 bzero(val6, 255);
747 bzero(hbc4, 30);
748 }
749 if(strstr(UserReportFields,"%TIME") == 0) {
750 bzero(val7, 255);
751 bzero(hbc5, 30);
752 }
753
754 if(strstr(UserReportFields,"AVERAGE") != 0) {
755 sprintf(html,"<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);
756 fputs(html,fp_ou);
757 }
d6e703cc 758} /* added */
25697a35
GS
759 tnacc=0;
760 tnbytes=0;
761 tnelap=0;
762 tnincache=0;
763 tnoucache=0;
764
765 fputs("</center></table>\n",fp_ou);
766
767 show_info(fp_ou);
768
769 fputs("</body>\n</html>\n",fp_ou);
770
771 fclose(fp_ou);
772
491b862f 773 htaccess(wusuario);
25697a35
GS
774
775 }
776
777 (void)rewinddir(dirp);
778 (void)closedir(dirp);
779
780 return;
781}