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