2 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
6 * please look at http://sarg.sourceforge.net/donations.php
8 * http://sourceforge.net/projects/sarg/forums/forum/363374
9 * ---------------------------------------------------------------------
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
27 #include "include/conf.h"
28 #include "include/defs.h"
29 #include "include/filelist.h"
31 //! The global statistics of the whole log read.
32 struct globalstatstruct globstat
;
33 //! \c True to enable the smart filter.
34 bool smartfilter
=false;
36 extern FileListObject UserAgentLog
;
38 //! The file to store the HTML page where the time of access is reported for one site and one user.
39 static FILE *fp_tt
=NULL
;
40 //! The name of the file containing the access time of the site/user.
41 static char arqtt
[4096]="";
43 static FILE *maketmp(const char *user
, const char *dirname
, int debug
);
44 static void gravatmp(FILE *fp_ou
, const char *oldurl
, long long int nacc
, long long int nbytes
, const char *oldmsg
, long long int nelap
, long long int incache
, long long int oucache
);
45 static void closett(void);
46 static void gravaporuser(const struct userinfostruct
*uinfo
, const char *dirname
, const char *url
, const char *ip
, const char *data
, const char *hora
, long long int tam
, long long int elap
);
47 static void gravager(FILE *fp_gen
,const char *filename
, const struct userinfostruct
*uinfo
, long long int nacc
, const char *url
, long long int nbytes
, const char *ip
, const char *hora
, const char *dia
, long long int nelap
, long long int incache
, long long int oucache
);
48 static void grava_SmartFilter(const char *dirname
, const char *user
, const char *ip
, const char *data
, const char *hora
, const char *url
, const char *smart
);
57 char accdia
[11], acchora
[9], accip
[256], *accurl
;
58 char oldaccdia
[11], oldacchora
[9], oldaccip
[256];
60 char wdirname
[MAXLEN
];
63 char acccode
[MAXLEN
/2 - 1], oldacccode
[MAXLEN
/2 - 1];
64 char ipantes
[256], nameantes
[MAXLEN
];
65 char accsmart
[MAXLEN
];
66 char crc2
[MAXLEN
/2 -1];
67 char siteind
[MAX_TRUNCATED_URL
];
69 char oldaccdiatt
[11],oldacchoratt
[9];
71 char u2
[MAX_USER_LEN
];
72 char userlabel
[MAX_USER_LEN
];
73 long long int nbytes
=0;
74 long long int nelap
=0;
76 long long int incache
=0;
77 long long int oucache
=0;
78 long long int accbytes
, accelap
;
81 const char *sort_field
;
82 const char *sort_order
;
89 struct getwordstruct gwarea
;
91 struct userinfostruct
*uinfo
;
96 memset(&globstat
,0,sizeof(globstat
));
99 if (vrfydir(&period
, addr
, site
, us
)<0) {
100 debuga(__FILE__
,__LINE__
,_("Cannot create the output directory name containing the period as part of the name\n"));
104 if (snprintf(outdirname
,sizeof(outdirname
),"%s/emailrep",tmp
)>=sizeof(outdirname
)) {
105 debuga(__FILE__
,__LINE__
,_("Path too long: "));
106 debuga_more("%s/emailrep\n",tmp
);
109 my_mkdir(outdirname
);
112 if(debugz
>=LogLevel_Process
){
113 debugaz(__FILE__
,__LINE__
,_("outdirname=%s\n"),outdirname
);
116 if (email
[0] == '\0' && !FileList_IsEmpty(UserAgentLog
))
120 init_usertab(UserTabFile
);
122 snprintf(wdirname
,sizeof(wdirname
),"%s/sarg-general",outdirname
);
123 if((fp_gen
=MY_FOPEN(wdirname
,"w"))==NULL
){
124 debuga(__FILE__
,__LINE__
,_("Cannot open file \"%s\": %s\n"),wdirname
,strerror(errno
));
129 sort_labels(&sort_field
,&sort_order
);
131 if (indexonly
|| datetimeby
==0)
134 daystat
=day_prepare();
136 uscan
=userinfo_startscan();
138 debuga(__FILE__
,__LINE__
,_("Cannot enumerate the user list\n"));
141 while ((uinfo
= userinfo_advancescan(uscan
)) != NULL
) {
142 sort_users_log(tmp
,debug
,uinfo
);
143 if (snprintf(tmp3
,sizeof(tmp3
),"%s/%s.user_log",tmp
,uinfo
->filename
)>=sizeof(tmp3
)) {
144 debuga(__FILE__
,__LINE__
,_("Path too long: "));
145 debuga_more("%s/%s.user_log\n",tmp
,uinfo
->filename
);
148 if((fp_in
=FileObject_Open(tmp3
))==NULL
){
149 debuga(__FILE__
,__LINE__
,_("Cannot open file \"%s\": %s\n"),tmp3
,FileObject_GetLastOpenError());
152 user
=uinfo
->filename
;
153 day_newuser(daystat
);
155 strcpy(u2
,uinfo
->id
);
156 if(Ip2Name
&& uinfo
->id_is_ip
) {
157 safe_strcpy(ipantes
,u2
,sizeof(ipantes
));
158 ip2name(u2
,sizeof(u2
));
159 strcpy(nameantes
,u2
);
161 user_find(userlabel
,MAX_USER_LEN
, u2
);
162 userinfo_label(uinfo
,userlabel
);
165 fp_tmp
=maketmp(user
,tmp
,debug
);
172 memset(oldaccdiatt
,0,sizeof(oldaccdiatt
));
173 memset(oldacchoratt
,0,sizeof(oldacchoratt
));
174 memset(oldacciptt
,0,sizeof(oldacciptt
));
182 if ((line
=longline_create())==NULL
) {
183 debuga(__FILE__
,__LINE__
,_("Not enough memory to read file \"%s\"\n"),tmp3
);
187 while((buf
=longline_read(fp_in
,line
))!=NULL
) {
188 getword_start(&gwarea
,buf
);
189 if (getword(accdia
,sizeof(accdia
),&gwarea
,'\t')<0 || getword(acchora
,sizeof(acchora
),&gwarea
,'\t')<0 ||
190 getword(accip
,sizeof(accip
),&gwarea
,'\t')<0 ||
191 getword_ptr(buf
,&accurl
,&gwarea
,'\t')<0 || getword_atoll(&accbytes
,&gwarea
,'\t')<0 ||
192 getword(acccode
,sizeof(acccode
),&gwarea
,'\t')<0) {
193 debuga(__FILE__
,__LINE__
,_("Invalid record in file \"%s\"\n"),tmp3
);
196 if(strncmp(acccode
,"TCP_DENIED/407",14) == 0) continue;
197 if (getword_atoll(&accelap
,&gwarea
,'\t')<0) {
198 debuga(__FILE__
,__LINE__
,_("Invalid elapsed time in file \"%s\"\n"),tmp3
);
201 if (getword_skip(20000,&gwarea
,'"')<0 || getword(accsmart
,sizeof(accsmart
),&gwarea
,'"')<0) {
202 debuga(__FILE__
,__LINE__
,_("Invalid smart info in file \"%s\"\n"),tmp3
);
206 if(accsmart
[0] != '\0') {
208 grava_SmartFilter(tmp
,uinfo
->id
,accip
,accdia
,acchora
,accurl
,accsmart
);
212 if(strcmp(accip
,ipantes
) != 0) {
213 strcpy(ipantes
,accip
);
214 ip2name(accip
,sizeof(accip
));
215 strcpy(nameantes
,accip
);
216 } else safe_strcpy(accip
,nameantes
,sizeof(accip
));
220 day_addpoint(daystat
,accdia
,acchora
,accelap
,accbytes
);
221 if (iprel
) gravaporuser(uinfo
,outdirname
,accurl
,accip
,accdia
,acchora
,accbytes
,accelap
);
225 url_len
=strlen(accurl
);
226 if (!oldurl
|| url_len
>=ourl_size
) {
228 oldurl
=realloc(oldurl
,ourl_size
);
230 debuga(__FILE__
,__LINE__
,_("Not enough memory to store the url\n"));
234 strcpy(oldurl
,accurl
);
235 strcpy(oldacccode
,acccode
);
236 strcpy(oldaccip
,accip
);
237 strcpy(oldaccdia
,accdia
);
238 strcpy(oldacchora
,acchora
);
241 same_url
=(strcmp(oldurl
,accurl
) == 0);
243 if(site
[0] == '\0') {
245 if(strstr(oldacccode
,"DENIED") != 0)
249 if (fp_tmp
) gravatmp(fp_tmp
,oldurl
,nacc
,nbytes
,oldmsg
,nelap
,incache
,oucache
);
250 gravager(fp_gen
,wdirname
,uinfo
,nacc
,oldurl
,nbytes
,oldaccip
,oldacchora
,oldaccdia
,nelap
,incache
,oucache
);
262 if ((ReportType
& REPORT_TYPE_SITE_USER_TIME_DATE
) != 0 && !indexonly
&&
263 (!oldurltt
|| strcmp(oldurltt
,accurl
) || strcmp(oldaccdiatt
,accdia
) || strcmp(oldacchoratt
,acchora
) ||
264 strcmp(oldacciptt
,accip
))) {
267 snprintf(arqtt
,sizeof(arqtt
),"%s/%s",outdirname
,uinfo
->filename
);
268 if(access(arqtt
, R_OK
) != 0)
270 snprintf(arqtt
,sizeof(arqtt
),"%s/%s/tt.html",outdirname
,uinfo
->filename
);
271 if ((fp_tt
= fopen(arqtt
, "w")) == 0) {
272 debuga(__FILE__
,__LINE__
,_("Cannot open file \"%s\": %s\n"),arqtt
,strerror(errno
));
279 sprintf(httplink,"<font size=%s color=%s><href=http://%s>%s",FontSize,PrivacyStringColor,PrivacyString,PrivacyString);
281 sprintf(httplink,"<font size=%s><a href=\"http://%s\">%s</a>",FontSize,accurl,accurl);
284 write_html_header(fp_tt
,(IndexTree
== INDEX_TREE_DATE
) ? 4 : 2,_("Site access report"),HTML_JS_NONE
);
285 fprintf(fp_tt
,"<tr><td class=\"header_c\">%s: %s</td></tr>\n",_("Period"),period
.html
);
286 fprintf(fp_tt
,"<tr><td class=\"header_c\">%s: %s</td></tr>\n",_("User"),uinfo
->label
);
287 fputs("<tr><td class=\"header_c\">",fp_tt
);
288 fprintf(fp_tt
,_("Sort: %s, %s"),sort_field
,sort_order
);
289 fputs("</td></tr>\n",fp_tt
);
290 fprintf(fp_tt
,"<tr><th class=\"header_c\">%s</th></tr>\n",_("User"));
291 close_html_header(fp_tt
);
293 fputs("<div class=\"report\"><table cellpadding=\"0\" cellspacing=\"2\">\n",fp_tt
);
295 if (!oldurltt
|| strcmp(oldurltt
,accurl
)) {
296 const char *url
=accurl
;
297 if (*url
==ALIAS_PREFIX
) url
++;
298 url_to_anchor(accurl
,siteind
,sizeof(siteind
));
299 fprintf(fp_tt
,"<tr class=\"tt\"><td colspan=\"3\"><a name=\"%s\">",siteind
);
300 fprintf(fp_tt
,"<b>%s</b>",_("Accessed site: "));
301 output_html_string(fp_tt
,url
,100);
302 fputs("</a></td></tr>\n",fp_tt
);
303 fprintf(fp_tt
,"<tr><th class=\"header_l\">%s</th>",_("IP"));
304 fprintf(fp_tt
,"<th class=\"header_l\">%s</th><th class=\"header_l\">%s</th></tr>\n",_("DATE"),pgettext("wall clock","TIME"));
307 fprintf(fp_tt
,"<tr><td class=\"data2\">%s</td>",accip
);
308 fprintf(fp_tt
,"<td class=\"data\">%s</td><td class=\"data\">%s</td></tr>\n",accdia
,acchora
);
310 url_len
=strlen(accurl
);
311 if (!oldurltt
|| url_len
>=ourltt_size
) {
312 ourltt_size
=url_len
+1;
313 oldurltt
=realloc(oldurltt
,ourltt_size
);
315 debuga(__FILE__
,__LINE__
,_("Not enough memory to store the url\n"));
319 strcpy(oldurltt
,accurl
);
320 strcpy(oldaccdiatt
,accdia
);
321 strcpy(oldacchoratt
,acchora
);
322 strcpy(oldacciptt
,accip
);
325 strcpy(crc2
,acccode
);
326 str
=strchr(crc2
,'/');
328 if(strstr(crc2
,"MISS") != 0)
333 strcpy(oldacccode
,acccode
);
334 strcpy(oldaccip
,accip
);
336 url_len
=strlen(accurl
);
337 if (url_len
>=ourl_size
) {
339 oldurl
=realloc(oldurl
,ourl_size
);
341 debuga(__FILE__
,__LINE__
,_("Not enough memory to store the url\n"));
345 strcpy(oldurl
,accurl
);
347 strcpy(oldaccdia
,accdia
);
348 strcpy(oldacchora
,acchora
);
350 if (FileObject_Close(fp_in
)) {
351 debuga(__FILE__
,__LINE__
,_("Read error in \"%s\": %s\n"),tmp3
,FileObject_GetLastCloseError());
354 longline_destroy(&line
);
355 if (oldurltt
) free(oldurltt
);
357 if(strstr(oldacccode
,"DENIED") != 0)
361 if (fp_tmp
) gravatmp(fp_tmp
,oldurl
,nacc
,nbytes
,oldmsg
,nelap
,incache
,oucache
);
363 gravager(fp_gen
,wdirname
,uinfo
,nacc
,oldurl
,nbytes
,oldaccip
,oldacchora
,oldaccdia
,nelap
,incache
,oucache
);
368 day_totalize(daystat
,tmp
,uinfo
);
371 if (fclose(fp_tmp
)==EOF
) {
372 debuga(__FILE__
,__LINE__
,_("Write error in \"%s\": %s\n"),uinfo
->filename
,strerror(errno
));
377 if (!KeepTempLog
&& unlink(tmp3
)) {
378 debuga(__FILE__
,__LINE__
,_("Cannot delete \"%s\": %s\n"),tmp3
,strerror(errno
));
382 userinfo_stopscan(uscan
);
383 day_cleanup(daystat
);
385 totalger(fp_gen
,wdirname
);
386 if (fclose(fp_gen
)==EOF
) {
387 debuga(__FILE__
,__LINE__
,_("Write error in \"%s\": %s\n"),wdirname
,strerror(errno
));
391 if(email
[0] == '\0') {
393 if(DansGuardianConf
[0] != '\0')
395 else if (debugz
>=LogLevel_Process
)
396 debugaz(__FILE__
,__LINE__
,_("Dansguardian report not produced because no dansguardian configuration file was provided\n"));
404 if((ReportType
& REPORT_TYPE_DOWNLOADS
) != 0)
406 else if (debugz
>=LogLevel_Process
)
407 debugaz(__FILE__
,__LINE__
,_("Downloaded files report not requested in report_type\n"));
409 if((ReportType
& REPORT_TYPE_TOPSITES
) != 0)
411 else if (debugz
>=LogLevel_Process
)
412 debugaz(__FILE__
,__LINE__
,_("Top sites report not requested in report_type\n"));
414 if((ReportType
& REPORT_TYPE_SITES_USERS
) != 0)
416 else if (debugz
>=LogLevel_Process
)
417 debugaz(__FILE__
,__LINE__
,_("Sites & users report not requested in report_type\n"));
419 if ((ReportType
& REPORT_TYPE_DENIED
) != 0)
421 else if (debugz
>=LogLevel_Process
)
422 debugaz(__FILE__
,__LINE__
,_("Denied accesses report not requested in report_type\n"));
424 if ((ReportType
& REPORT_TYPE_AUTH_FAILURES
) != 0)
426 else if (debugz
>=LogLevel_Process
)
427 debugaz(__FILE__
,__LINE__
,_("Authentication failures report not requested in report_type\n"));
429 if(smartfilter
) smartfilter_report();
431 if(DansGuardianConf
[0] != '\0')
432 dansguardian_report();
436 if((ReportType
& REPORT_TYPE_USERS_SITES
) != 0)
438 else if (debugz
>=LogLevel_Process
)
439 debugaz(__FILE__
,__LINE__
,_("User's detailed report not requested in report_type\n"));
444 if(SuccessfulMsg
) debuga(__FILE__
,__LINE__
,_("Successful report generated on %s\n"),outdirname
);
448 if((strcmp(email
,"stdout") != 0) && SuccessfulMsg
)
449 debuga(__FILE__
,__LINE__
,_("Successful report generated and sent to %s\n"),email
);
452 if(indexonly
) index_only(outdirname
, debug
);
454 removetmp(outdirname
);
458 static FILE *maketmp(const char *user
, const char *dirname
, int debug
)
461 char wdirname
[MAXLEN
];
463 if((ReportType
& REPORT_TYPE_USERS_SITES
) == 0) return(NULL
);
464 if((ReportType
& REPORT_TYPE_TOPUSERS
) == 0) return(NULL
);
466 if(debug
) debuga(__FILE__
,__LINE__
,_("Making file %s/%s\n"),tmp
,user
);
467 if (snprintf(wdirname
,sizeof(wdirname
),"%s/%s.utmp",tmp
,user
)>=sizeof(wdirname
)) {
468 debuga(__FILE__
,__LINE__
,_("Path too long: "));
469 debuga_more("%s/%s.utmp\n",tmp
,user
);
473 if((fp_ou
=fopen(wdirname
,"w"))==NULL
){
474 debuga(__FILE__
,__LINE__
,_("Cannot open file \"%s\": %s\n"),wdirname
,strerror(errno
));
482 static void gravatmp(FILE *fp_ou
, const char *oldurl
, long long int nacc
, long long int nbytes
, const char *oldmsg
, long long int nelap
, long long int incache
, long long int oucache
)
485 This complicated printf is due to Microsoft's inability to comply with any standard. Msvcrt is unable
486 to print a long long int unless it is exactly 64-bits long.
488 fprintf(fp_ou
,"%"PRIu64
"\t%"PRIu64
"\t%s\t%s\t%"PRIu64
"\t%"PRIu64
"\t%"PRIu64
"\n",(uint64_t)nacc
,(uint64_t)nbytes
,oldurl
,oldmsg
,(uint64_t)nelap
,(uint64_t)incache
,(uint64_t)oucache
);
493 static void closett(void)
498 fputs("</table>\n</div>\n",fp_tt
);
499 fputs("</body>\n</html>\n",fp_tt
);
500 if (fclose(fp_tt
)==EOF
) {
501 debuga(__FILE__
,__LINE__
,_("Write error in \"%s\": %s\n"),arqtt
,strerror(errno
));
508 static void gravaporuser(const struct userinfostruct
*uinfo
, const char *dirname
, const char *url
, const char *ip
, const char *data
, const char *hora
, long long int tam
, long long int elap
)
511 char wdirname
[MAXLEN
];
513 if((ReportType
& REPORT_TYPE_USERS_SITES
) == 0) return;
515 if (snprintf(wdirname
,sizeof(wdirname
),"%s/%s.ip",tmp
,uinfo
->filename
)>=sizeof(wdirname
)) {
516 debuga(__FILE__
,__LINE__
,_("Path too long: "));
517 debuga_more("%s/%s.ip\n",tmp
,uinfo
->filename
);
521 if((fp_ou
=MY_FOPEN(wdirname
,"a"))==NULL
){
522 debuga(__FILE__
,__LINE__
,_("Cannot open file \"%s\": %s\n"),wdirname
,strerror(errno
));
527 This complicated printf is due to Microsoft's inability to comply with any standard. Msvcrt is unable
528 to print a long long int unless it is exactly 64-bits long.
530 fprintf(fp_ou
,"%s\t%s\t%s\t%s\t%"PRIu64
"\t%"PRIu64
"\n",ip
,url
,data
,hora
,(uint64_t)tam
,(uint64_t)elap
);
532 if (fclose(fp_ou
)==EOF
) {
533 debuga(__FILE__
,__LINE__
,_("Write error in \"%s\": %s\n"),wdirname
,strerror(errno
));
541 static void gravager(FILE *fp_gen
,const char *filename
, const struct userinfostruct
*uinfo
, long long int nacc
, const char *url
, long long int nbytes
, const char *ip
, const char *hora
, const char *dia
, long long int nelap
, long long int incache
, long long int oucache
)
544 This complicated printf is due to Microsoft's inability to comply with any standard. Msvcrt is unable
545 to print a long long int unless it is exactly 64-bits long.
547 if (fprintf(fp_gen
,"%s\t%"PRIu64
"\t%"PRIu64
"\t%s\t%s\t%s\t%s\t%"PRIu64
"\t%"PRIu64
"\t%"PRIu64
"\n",uinfo
->id
,(uint64_t)nacc
,(uint64_t)nbytes
,url
,ip
,hora
,dia
,(uint64_t)nelap
,(uint64_t)incache
,(uint64_t)oucache
)<0) {
548 debuga(__FILE__
,__LINE__
,_("Write error in file \"%s\": %s\n"),filename
,strerror(errno
));
553 globstat
.nbytes
+=nbytes
;
554 globstat
.elap
+=nelap
;
555 globstat
.incache
+=incache
;
556 globstat
.oucache
+=oucache
;
561 Write the total line at the end of the general file.
563 void totalger(FILE *fp_gen
,const char *filename
)
566 This complicated printf is due to Microsoft's inability to comply with any standard. Msvcrt is unable
567 to print a long long int unless it is exactly 64-bits long.
569 if (fprintf(fp_gen
,"TOTAL\t%"PRIu64
"\t%"PRIu64
"\t%"PRIu64
"\t%"PRIu64
"\t%"PRIu64
"\n",(uint64_t)globstat
.nacc
,(uint64_t)globstat
.nbytes
,(uint64_t)globstat
.elap
,(uint64_t)globstat
.incache
,(uint64_t)globstat
.oucache
)<0) {
570 debuga(__FILE__
,__LINE__
,_("Failed to write the total line in %s\n"),filename
);
575 int ger_read(char *buffer
,struct generalitemstruct
*item
,const char *filename
)
579 long long int number
;
581 if (strncmp(buffer
,"TOTAL\t",6)==0) {
586 if (*buffer
== '-') {
589 } else if (*buffer
== '+') {
593 while (isdigit(*buffer
))
594 number
=(number
* 10) + (*buffer
++)-'0';
596 debuga(__FILE__
,__LINE__
,_("Invalid total number of accesses in file \"%s\"\n"),filename
);
600 item
->nacc
=number
*sign
;
603 if (*buffer
== '-') {
606 } else if (*buffer
== '+') {
610 while (isdigit(*buffer
))
611 number
=(number
* 10) + (*buffer
++)-'0';
613 debuga(__FILE__
,__LINE__
,_("Invalid total size in file \"%s\"\n"),filename
);
617 item
->nbytes
=number
*sign
;
620 if (*buffer
== '-') {
623 } else if (*buffer
== '+') {
627 while (isdigit(*buffer
))
628 number
=(number
* 10) + (*buffer
++)-'0';
630 debuga(__FILE__
,__LINE__
,_("Invalid total elapsed time in file \"%s\"\n"),filename
);
634 item
->nelap
=number
*sign
;
637 if (*buffer
== '-') {
640 } else if (*buffer
== '+') {
644 while (isdigit(*buffer
))
645 number
=(number
* 10) + (*buffer
++)-'0';
647 debuga(__FILE__
,__LINE__
,_("Invalid total cache hit in file \"%s\"\n"),filename
);
651 item
->incache
=number
*sign
;
654 if (*buffer
== '-') {
657 } else if (*buffer
== '+') {
661 while (isdigit(*buffer
))
662 number
=(number
* 10) + (*buffer
++)-'0';
664 debuga(__FILE__
,__LINE__
,_("Invalid total cache miss in file \"%s\"\n"),filename
);
667 item
->oucache
=number
*sign
;
672 for (i
=0 ; i
<MAX_USER_LEN
-1 && (unsigned char)*buffer
>=' ' ; i
++) buffer
++;
674 debuga(__FILE__
,__LINE__
,_("User name too long or invalid in file \"%s\"\n"),filename
);
680 if (*buffer
== '-') {
683 } else if (*buffer
== '+') {
687 while (isdigit(*buffer
))
688 number
=(number
* 10) + (*buffer
++)-'0';
690 debuga(__FILE__
,__LINE__
,_("Invalid number of accesses in file \"%s\"\n"),filename
);
694 item
->nacc
=number
*sign
;
697 if (*buffer
== '-') {
700 } else if (*buffer
== '+') {
704 while (isdigit(*buffer
))
705 number
=(number
* 10) + (*buffer
++)-'0';
707 debuga(__FILE__
,__LINE__
,_("Invalid number of bytes in file \"%s\"\n"),filename
);
711 item
->nbytes
=number
*sign
;
714 while ((unsigned char)*buffer
>=' ') buffer
++;
716 debuga(__FILE__
,__LINE__
,_("URL too long or invalid in file \"%s\"\n"),filename
);
722 for (i
=0 ; i
<MAX_IP_LEN
-1 && (unsigned char)*buffer
>=' ' ; i
++) buffer
++;
724 debuga(__FILE__
,__LINE__
,_("IP address too long or invalid in file \"%s\"\n"),filename
);
730 for (i
=0 ; i
<MAX_DATETIME_LEN
-1 && (unsigned char)*buffer
>=' ' ; i
++) buffer
++;
732 debuga(__FILE__
,__LINE__
,_("Time too long or invalid in file \"%s\"\n"),filename
);
738 for (i
=0 ; i
<MAX_DATETIME_LEN
-1 && (unsigned char)*buffer
>=' ' ; i
++) buffer
++;
740 debuga(__FILE__
,__LINE__
,_("Date too long or invalid in file \"%s\"\n"),filename
);
746 if (*buffer
== '-') {
749 } else if (*buffer
== '+') {
753 while (isdigit(*buffer
))
754 number
=(number
* 10) + (*buffer
++)-'0';
756 debuga(__FILE__
,__LINE__
,_("Invalid elapsed time in file \"%s\"\n"),filename
);
760 item
->nelap
=number
*sign
;
763 if (*buffer
== '-') {
766 } else if (*buffer
== '+') {
770 while (isdigit(*buffer
))
771 number
=(number
* 10) + (*buffer
++)-'0';
773 debuga(__FILE__
,__LINE__
,_("Invalid cache hit size in file \"%s\"\n"),filename
);
777 item
->incache
=number
*sign
;
780 if (*buffer
== '-') {
783 } else if (*buffer
== '+') {
787 while (isdigit(*buffer
))
788 number
=(number
* 10) + (*buffer
++)-'0';
790 debuga(__FILE__
,__LINE__
,_("Invalid cache miss size in file \"%s\"\n"),filename
);
793 item
->oucache
=number
*sign
;
798 static void grava_SmartFilter(const char *dirname
, const char *user
, const char *ip
, const char *data
, const char *hora
, const char *url
, const char *smart
)
801 char wdirname
[MAXLEN
];
803 if (snprintf(wdirname
,sizeof(wdirname
),"%s/smartfilter.int_unsort",dirname
)>=sizeof(wdirname
)) {
804 debuga(__FILE__
,__LINE__
,_("Path too long: "));
805 debuga_more("%s/smartfilter.int_unsort\n",dirname
);
809 if((fp_ou
=MY_FOPEN(wdirname
,"a"))==NULL
){
810 debuga(__FILE__
,__LINE__
,_("Cannot open file \"%s\": %s\n"),wdirname
,strerror(errno
));
814 fprintf(fp_ou
,"%s\t%s\t%s\t%s\t%s\t%s\n",user
,data
,hora
,ip
,url
,smart
);
815 fputs("</body>\n</html>\n",fp_tt
);
817 if (fclose(fp_ou
)==EOF
) {
818 debuga(__FILE__
,__LINE__
,_("Write error in \"%s\": %s\n"),wdirname
,strerror(errno
));