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