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
];
62 char oldmsg
[50], acccode
[MAXLEN
/2 - 1], oldacccode
[MAXLEN
/2 - 1];
63 char ipantes
[256], nameantes
[MAXLEN
];
64 char accsmart
[MAXLEN
];
65 char crc2
[MAXLEN
/2 -1];
66 char siteind
[MAX_TRUNCATED_URL
];
68 char oldaccdiatt
[11],oldacchoratt
[9];
70 char u2
[MAX_USER_LEN
];
71 char userlabel
[MAX_USER_LEN
];
72 long long int nbytes
=0;
73 long long int nelap
=0;
75 long long int incache
=0;
76 long long int oucache
=0;
77 long long int accbytes
, accelap
;
80 const char *sort_field
;
81 const char *sort_order
;
88 struct getwordstruct gwarea
;
90 struct userinfostruct
*uinfo
;
95 memset(&globstat
,0,sizeof(globstat
));
97 if (vrfydir(&period
, addr
, site
, us
, email
)<0) {
98 debuga(__FILE__
,__LINE__
,_("Cannot create the output directory name containing the period as part of the name\n"));
102 if(debugz
>=LogLevel_Process
){
103 debugaz(__FILE__
,__LINE__
,_("outdirname=%s\n"),outdirname
);
106 if (!FileList_IsEmpty(UserAgentLog
) && email
[0] == '\0') useragent();
108 snprintf(wdirname
,sizeof(wdirname
),"%s/sarg-general",outdirname
);
109 if((fp_gen
=MY_FOPEN(wdirname
,"w"))==NULL
){
110 debuga(__FILE__
,__LINE__
,_("Cannot open file \"%s\": %s\n"),wdirname
,strerror(errno
));
115 sort_labels(&sort_field
,&sort_order
);
117 if (indexonly
|| datetimeby
==0)
120 daystat
=day_prepare();
122 uscan
=userinfo_startscan();
124 debuga(__FILE__
,__LINE__
,_("Cannot enumerate the user list\n"));
127 while ((uinfo
= userinfo_advancescan(uscan
)) != NULL
) {
128 sort_users_log(tmp
,debug
,uinfo
);
129 if (snprintf(tmp3
,sizeof(tmp3
),"%s/%s.user_log",tmp
,uinfo
->filename
)>=sizeof(tmp3
)) {
130 debuga(__FILE__
,__LINE__
,_("Path too long: "));
131 debuga_more("%s/%s.user_log\n",tmp
,uinfo
->filename
);
134 if((fp_in
=MY_FOPEN(tmp3
,"r"))==NULL
){
135 debuga(__FILE__
,__LINE__
,_("Cannot open file \"%s\": %s\n"),tmp3
,strerror(errno
));
138 user
=uinfo
->filename
;
139 day_newuser(daystat
);
141 strcpy(u2
,uinfo
->id
);
142 if(Ip2Name
&& uinfo
->id_is_ip
) {
143 safe_strcpy(ipantes
,u2
,sizeof(ipantes
));
144 ip2name(u2
,sizeof(u2
));
145 strcpy(nameantes
,u2
);
147 user_find(userlabel
,MAX_USER_LEN
, u2
);
148 userinfo_label(uinfo
,userlabel
);
151 fp_tmp
=maketmp(user
,tmp
,debug
);
158 memset(oldaccdiatt
,0,sizeof(oldaccdiatt
));
159 memset(oldacchoratt
,0,sizeof(oldacchoratt
));
160 memset(oldacciptt
,0,sizeof(oldacciptt
));
168 if ((line
=longline_create())==NULL
) {
169 debuga(__FILE__
,__LINE__
,_("Not enough memory to read file \"%s\"\n"),tmp3
);
173 while((buf
=longline_read(fp_in
,line
))!=NULL
) {
174 getword_start(&gwarea
,buf
);
175 if (getword(accdia
,sizeof(accdia
),&gwarea
,'\t')<0 || getword(acchora
,sizeof(acchora
),&gwarea
,'\t')<0 ||
176 getword(accip
,sizeof(accip
),&gwarea
,'\t')<0 ||
177 getword_ptr(buf
,&accurl
,&gwarea
,'\t')<0 || getword_atoll(&accbytes
,&gwarea
,'\t')<0 ||
178 getword(acccode
,sizeof(acccode
),&gwarea
,'\t')<0) {
179 debuga(__FILE__
,__LINE__
,_("Invalid record in file \"%s\"\n"),tmp3
);
182 if(strncmp(acccode
,"TCP_DENIED/407",14) == 0) continue;
183 if (getword_atoll(&accelap
,&gwarea
,'\t')<0) {
184 debuga(__FILE__
,__LINE__
,_("Invalid elapsed time in file \"%s\"\n"),tmp3
);
187 if (getword_skip(20000,&gwarea
,'"')<0 || getword(accsmart
,sizeof(accsmart
),&gwarea
,'"')<0) {
188 debuga(__FILE__
,__LINE__
,_("Invalid smart info in file \"%s\"\n"),tmp3
);
192 if(accsmart
[0] != '\0') {
194 grava_SmartFilter(tmp
,uinfo
->id
,accip
,accdia
,acchora
,accurl
,accsmart
);
198 if(strcmp(accip
,ipantes
) != 0) {
199 strcpy(ipantes
,accip
);
200 ip2name(accip
,sizeof(accip
));
201 strcpy(nameantes
,accip
);
202 } else safe_strcpy(accip
,nameantes
,sizeof(accip
));
206 day_addpoint(daystat
,accdia
,acchora
,accelap
,accbytes
);
207 if (iprel
) gravaporuser(uinfo
,outdirname
,accurl
,accip
,accdia
,acchora
,accbytes
,accelap
);
211 url_len
=strlen(accurl
);
212 if (!oldurl
|| url_len
>=ourl_size
) {
214 oldurl
=realloc(oldurl
,ourl_size
);
216 debuga(__FILE__
,__LINE__
,_("Not enough memory to store the url\n"));
220 strcpy(oldurl
,accurl
);
221 strcpy(oldacccode
,acccode
);
222 strcpy(oldaccip
,accip
);
223 strcpy(oldaccdia
,accdia
);
224 strcpy(oldacchora
,acchora
);
227 same_url
=(strcmp(oldurl
,accurl
) == 0);
229 if(site
[0] == '\0') {
231 if(strstr(oldacccode
,"DENIED") != 0)
232 strcpy(oldmsg
,"DENIED");
235 if (fp_tmp
) gravatmp(fp_tmp
,oldurl
,nacc
,nbytes
,oldmsg
,nelap
,incache
,oucache
);
236 gravager(fp_gen
,wdirname
,uinfo
,nacc
,oldurl
,nbytes
,oldaccip
,oldacchora
,oldaccdia
,nelap
,incache
,oucache
);
248 if ((ReportType
& REPORT_TYPE_SITE_USER_TIME_DATE
) != 0 && !indexonly
&&
249 (!oldurltt
|| strcmp(oldurltt
,accurl
) || strcmp(oldaccdiatt
,accdia
) || strcmp(oldacchoratt
,acchora
) ||
250 strcmp(oldacciptt
,accip
))) {
253 snprintf(arqtt
,sizeof(arqtt
),"%s/%s",outdirname
,uinfo
->filename
);
254 if(access(arqtt
, R_OK
) != 0)
256 snprintf(arqtt
,sizeof(arqtt
),"%s/%s/tt.html",outdirname
,uinfo
->filename
);
257 if ((fp_tt
= fopen(arqtt
, "w")) == 0) {
258 debuga(__FILE__
,__LINE__
,_("Cannot open file \"%s\": %s\n"),arqtt
,strerror(errno
));
265 sprintf(httplink,"<font size=%s color=%s><href=http://%s>%s",FontSize,PrivacyStringColor,PrivacyString,PrivacyString);
267 sprintf(httplink,"<font size=%s><a href=\"http://%s\">%s</a>",FontSize,accurl,accurl);
270 write_html_header(fp_tt
,(IndexTree
== INDEX_TREE_DATE
) ? 4 : 2,_("Site access report"),HTML_JS_NONE
);
271 fprintf(fp_tt
,"<tr><td class=\"header_c\">%s: %s</td></tr>\n",_("Period"),period
.html
);
272 fprintf(fp_tt
,"<tr><td class=\"header_c\">%s: %s</td></tr>\n",_("User"),uinfo
->label
);
273 fputs("<tr><td class=\"header_c\">",fp_tt
);
274 fprintf(fp_tt
,_("Sort: %s, %s"),sort_field
,sort_order
);
275 fputs("</td></tr>\n",fp_tt
);
276 fprintf(fp_tt
,"<tr><th class=\"header_c\">%s</th></tr>\n",_("User"));
277 close_html_header(fp_tt
);
279 fputs("<div class=\"report\"><table cellpadding=\"0\" cellspacing=\"2\">\n",fp_tt
);
281 if (!oldurltt
|| strcmp(oldurltt
,accurl
)) {
282 const char *url
=accurl
;
283 if (*url
==ALIAS_PREFIX
) url
++;
284 url_to_anchor(accurl
,siteind
,sizeof(siteind
));
285 fprintf(fp_tt
,"<tr class=\"tt\"><td colspan=\"3\"><a name=\"%s\">",siteind
);
286 fprintf(fp_tt
,"<b>%s</b>",_("Accessed site: "));
287 output_html_string(fp_tt
,url
,100);
288 fputs("</a></td></tr>\n",fp_tt
);
289 fprintf(fp_tt
,"<tr><th class=\"header_l\">%s</th>",_("IP"));
290 fprintf(fp_tt
,"<th class=\"header_l\">%s</th><th class=\"header_l\">%s</th></tr>\n",_("DATE"),pgettext("wall clock","TIME"));
293 fprintf(fp_tt
,"<tr><td class=\"data2\">%s</td>",accip
);
294 fprintf(fp_tt
,"<td class=\"data\">%s</td><td class=\"data\">%s</td></tr>\n",accdia
,acchora
);
296 url_len
=strlen(accurl
);
297 if (!oldurltt
|| url_len
>=ourltt_size
) {
298 ourltt_size
=url_len
+1;
299 oldurltt
=realloc(oldurltt
,ourltt_size
);
301 debuga(__FILE__
,__LINE__
,_("Not enough memory to store the url\n"));
305 strcpy(oldurltt
,accurl
);
306 strcpy(oldaccdiatt
,accdia
);
307 strcpy(oldacchoratt
,acchora
);
308 strcpy(oldacciptt
,accip
);
311 strcpy(crc2
,acccode
);
312 str
=strchr(crc2
,'/');
314 if(strstr(crc2
,"MISS") != 0)
319 strcpy(oldacccode
,acccode
);
320 strcpy(oldaccip
,accip
);
322 url_len
=strlen(accurl
);
323 if (url_len
>=ourl_size
) {
325 oldurl
=realloc(oldurl
,ourl_size
);
327 debuga(__FILE__
,__LINE__
,_("Not enough memory to store the url\n"));
331 strcpy(oldurl
,accurl
);
333 strcpy(oldaccdia
,accdia
);
334 strcpy(oldacchora
,acchora
);
336 if (fclose(fp_in
)==EOF
) {
337 debuga(__FILE__
,__LINE__
,_("Read error in \"%s\": %s\n"),tmp3
,strerror(errno
));
340 longline_destroy(&line
);
341 if (oldurltt
) free(oldurltt
);
343 if(strstr(oldacccode
,"DENIED") != 0)
344 strcpy(oldmsg
,"DENIED");
347 if (fp_tmp
) gravatmp(fp_tmp
,oldurl
,nacc
,nbytes
,oldmsg
,nelap
,incache
,oucache
);
349 gravager(fp_gen
,wdirname
,uinfo
,nacc
,oldurl
,nbytes
,oldaccip
,oldacchora
,oldaccdia
,nelap
,incache
,oucache
);
354 day_totalize(daystat
,tmp
,uinfo
);
357 if (fclose(fp_tmp
)==EOF
) {
358 debuga(__FILE__
,__LINE__
,_("Write error in \"%s\": %s\n"),uinfo
->filename
,strerror(errno
));
363 if (!KeepTempLog
&& unlink(tmp3
)) {
364 debuga(__FILE__
,__LINE__
,_("Cannot delete \"%s\": %s\n"),tmp3
,strerror(errno
));
368 userinfo_stopscan(uscan
);
369 day_cleanup(daystat
);
371 totalger(fp_gen
,wdirname
);
372 if (fclose(fp_gen
)==EOF
) {
373 debuga(__FILE__
,__LINE__
,_("Write error in \"%s\": %s\n"),wdirname
,strerror(errno
));
377 if(email
[0] == '\0') {
379 if(DansGuardianConf
[0] != '\0')
381 else if (debugz
>=LogLevel_Process
)
382 debugaz(__FILE__
,__LINE__
,_("Dansguardian report not produced because no dansguardian configuration file was provided\n"));
390 if((ReportType
& REPORT_TYPE_DOWNLOADS
) != 0)
392 else if (debugz
>=LogLevel_Process
)
393 debugaz(__FILE__
,__LINE__
,_("Downloaded files report not requested in report_type\n"));
395 if((ReportType
& REPORT_TYPE_TOPSITES
) != 0)
397 else if (debugz
>=LogLevel_Process
)
398 debugaz(__FILE__
,__LINE__
,_("Top sites report not requested in report_type\n"));
400 if((ReportType
& REPORT_TYPE_SITES_USERS
) != 0)
402 else if (debugz
>=LogLevel_Process
)
403 debugaz(__FILE__
,__LINE__
,_("Sites & users report not requested in report_type\n"));
405 if ((ReportType
& REPORT_TYPE_DENIED
) != 0)
407 else if (debugz
>=LogLevel_Process
)
408 debugaz(__FILE__
,__LINE__
,_("Denied accesses report not requested in report_type\n"));
410 if ((ReportType
& REPORT_TYPE_AUTH_FAILURES
) != 0)
412 else if (debugz
>=LogLevel_Process
)
413 debugaz(__FILE__
,__LINE__
,_("Authentication failures report not requested in report_type\n"));
415 if(smartfilter
) smartfilter_report();
417 if(DansGuardianConf
[0] != '\0')
418 dansguardian_report();
422 if((ReportType
& REPORT_TYPE_USERS_SITES
) != 0)
424 else if (debugz
>=LogLevel_Process
)
425 debugaz(__FILE__
,__LINE__
,_("User's detailed report not requested in report_type\n"));
430 if(SuccessfulMsg
) debuga(__FILE__
,__LINE__
,_("Successful report generated on %s\n"),outdirname
);
432 geramail(outdirname
, debug
, outdir
, email
, tmp
);
434 if((strcmp(email
,"stdout") != 0) && SuccessfulMsg
)
435 debuga(__FILE__
,__LINE__
,_("Successful report generated and sent to %s\n"),email
);
438 if(indexonly
) index_only(outdirname
, debug
);
440 removetmp(outdirname
);
444 static FILE *maketmp(const char *user
, const char *dirname
, int debug
)
447 char wdirname
[MAXLEN
];
449 if((ReportType
& REPORT_TYPE_USERS_SITES
) == 0) return(NULL
);
450 if((ReportType
& REPORT_TYPE_TOPUSERS
) == 0) return(NULL
);
452 if(debug
) debuga(__FILE__
,__LINE__
,_("Making file %s/%s\n"),tmp
,user
);
453 if (snprintf(wdirname
,sizeof(wdirname
),"%s/%s.utmp",tmp
,user
)>=sizeof(wdirname
)) {
454 debuga(__FILE__
,__LINE__
,_("Path too long: "));
455 debuga_more("%s/%s.utmp\n",tmp
,user
);
459 if((fp_ou
=fopen(wdirname
,"w"))==NULL
){
460 debuga(__FILE__
,__LINE__
,_("Cannot open file \"%s\": %s\n"),wdirname
,strerror(errno
));
468 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
)
471 This complicated printf is due to Microsoft's inability to comply with any standard. Msvcrt is unable
472 to print a long long int unless it is exactly 64-bits long.
474 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
);
479 static void closett(void)
484 fputs("</table>\n</div>\n",fp_tt
);
485 fputs("</body>\n</html>\n",fp_tt
);
486 if (fclose(fp_tt
)==EOF
) {
487 debuga(__FILE__
,__LINE__
,_("Write error in \"%s\": %s\n"),arqtt
,strerror(errno
));
494 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
)
497 char wdirname
[MAXLEN
];
499 if((ReportType
& REPORT_TYPE_USERS_SITES
) == 0) return;
501 if (snprintf(wdirname
,sizeof(wdirname
),"%s/%s.ip",tmp
,uinfo
->filename
)>=sizeof(wdirname
)) {
502 debuga(__FILE__
,__LINE__
,_("Path too long: "));
503 debuga_more("%s/%s.ip\n",tmp
,uinfo
->filename
);
507 if((fp_ou
=MY_FOPEN(wdirname
,"a"))==NULL
){
508 debuga(__FILE__
,__LINE__
,_("Cannot open file \"%s\": %s\n"),wdirname
,strerror(errno
));
513 This complicated printf is due to Microsoft's inability to comply with any standard. Msvcrt is unable
514 to print a long long int unless it is exactly 64-bits long.
516 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
);
518 if (fclose(fp_ou
)==EOF
) {
519 debuga(__FILE__
,__LINE__
,_("Write error in \"%s\": %s\n"),wdirname
,strerror(errno
));
527 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
)
530 This complicated printf is due to Microsoft's inability to comply with any standard. Msvcrt is unable
531 to print a long long int unless it is exactly 64-bits long.
533 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) {
534 debuga(__FILE__
,__LINE__
,_("Write error in file \"%s\": %s\n"),filename
,strerror(errno
));
539 globstat
.nbytes
+=nbytes
;
540 globstat
.elap
+=nelap
;
541 globstat
.incache
+=incache
;
542 globstat
.oucache
+=oucache
;
547 Write the total line at the end of the general file.
549 void totalger(FILE *fp_gen
,const char *filename
)
552 This complicated printf is due to Microsoft's inability to comply with any standard. Msvcrt is unable
553 to print a long long int unless it is exactly 64-bits long.
555 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) {
556 debuga(__FILE__
,__LINE__
,_("Failed to write the total line in %s\n"),filename
);
561 int ger_read(char *buffer
,struct generalitemstruct
*item
,const char *filename
)
565 long long int number
;
567 if (strncmp(buffer
,"TOTAL\t",6)==0) {
572 if (*buffer
== '-') {
575 } else if (*buffer
== '+') {
579 while (isdigit(*buffer
))
580 number
=(number
* 10) + (*buffer
++)-'0';
582 debuga(__FILE__
,__LINE__
,_("Invalid total number of accesses in file \"%s\"\n"),filename
);
586 item
->nacc
=number
*sign
;
589 if (*buffer
== '-') {
592 } else if (*buffer
== '+') {
596 while (isdigit(*buffer
))
597 number
=(number
* 10) + (*buffer
++)-'0';
599 debuga(__FILE__
,__LINE__
,_("Invalid total size in file \"%s\"\n"),filename
);
603 item
->nbytes
=number
*sign
;
606 if (*buffer
== '-') {
609 } else if (*buffer
== '+') {
613 while (isdigit(*buffer
))
614 number
=(number
* 10) + (*buffer
++)-'0';
616 debuga(__FILE__
,__LINE__
,_("Invalid total elapsed time in file \"%s\"\n"),filename
);
620 item
->nelap
=number
*sign
;
623 if (*buffer
== '-') {
626 } else if (*buffer
== '+') {
630 while (isdigit(*buffer
))
631 number
=(number
* 10) + (*buffer
++)-'0';
633 debuga(__FILE__
,__LINE__
,_("Invalid total cache hit in file \"%s\"\n"),filename
);
637 item
->incache
=number
*sign
;
640 if (*buffer
== '-') {
643 } else if (*buffer
== '+') {
647 while (isdigit(*buffer
))
648 number
=(number
* 10) + (*buffer
++)-'0';
650 debuga(__FILE__
,__LINE__
,_("Invalid total cache miss in file \"%s\"\n"),filename
);
653 item
->oucache
=number
*sign
;
658 for (i
=0 ; i
<MAX_USER_LEN
-1 && (unsigned char)*buffer
>=' ' ; i
++) buffer
++;
660 debuga(__FILE__
,__LINE__
,_("User name too long or invalid in file \"%s\"\n"),filename
);
666 if (*buffer
== '-') {
669 } else if (*buffer
== '+') {
673 while (isdigit(*buffer
))
674 number
=(number
* 10) + (*buffer
++)-'0';
676 debuga(__FILE__
,__LINE__
,_("Invalid number of accesses in file \"%s\"\n"),filename
);
680 item
->nacc
=number
*sign
;
683 if (*buffer
== '-') {
686 } else if (*buffer
== '+') {
690 while (isdigit(*buffer
))
691 number
=(number
* 10) + (*buffer
++)-'0';
693 debuga(__FILE__
,__LINE__
,_("Invalid number of bytes in file \"%s\"\n"),filename
);
697 item
->nbytes
=number
*sign
;
700 while ((unsigned char)*buffer
>=' ') buffer
++;
702 debuga(__FILE__
,__LINE__
,_("URL too long or invalid in file \"%s\"\n"),filename
);
708 for (i
=0 ; i
<MAX_IP_LEN
-1 && (unsigned char)*buffer
>=' ' ; i
++) buffer
++;
710 debuga(__FILE__
,__LINE__
,_("IP address too long or invalid in file \"%s\"\n"),filename
);
716 for (i
=0 ; i
<MAX_DATETIME_LEN
-1 && (unsigned char)*buffer
>=' ' ; i
++) buffer
++;
718 debuga(__FILE__
,__LINE__
,_("Time too long or invalid in file \"%s\"\n"),filename
);
724 for (i
=0 ; i
<MAX_DATETIME_LEN
-1 && (unsigned char)*buffer
>=' ' ; i
++) buffer
++;
726 debuga(__FILE__
,__LINE__
,_("Date too long or invalid in file \"%s\"\n"),filename
);
732 if (*buffer
== '-') {
735 } else if (*buffer
== '+') {
739 while (isdigit(*buffer
))
740 number
=(number
* 10) + (*buffer
++)-'0';
742 debuga(__FILE__
,__LINE__
,_("Invalid elapsed time in file \"%s\"\n"),filename
);
746 item
->nelap
=number
*sign
;
749 if (*buffer
== '-') {
752 } else if (*buffer
== '+') {
756 while (isdigit(*buffer
))
757 number
=(number
* 10) + (*buffer
++)-'0';
759 debuga(__FILE__
,__LINE__
,_("Invalid cache hit size in file \"%s\"\n"),filename
);
763 item
->incache
=number
*sign
;
766 if (*buffer
== '-') {
769 } else if (*buffer
== '+') {
773 while (isdigit(*buffer
))
774 number
=(number
* 10) + (*buffer
++)-'0';
776 debuga(__FILE__
,__LINE__
,_("Invalid cache miss size in file \"%s\"\n"),filename
);
779 item
->oucache
=number
*sign
;
784 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
)
787 char wdirname
[MAXLEN
];
789 if (snprintf(wdirname
,sizeof(wdirname
),"%s/smartfilter.int_unsort",dirname
)>=sizeof(wdirname
)) {
790 debuga(__FILE__
,__LINE__
,_("Path too long: "));
791 debuga_more("%s/smartfilter.int_unsort\n",dirname
);
795 if((fp_ou
=MY_FOPEN(wdirname
,"a"))==NULL
){
796 debuga(__FILE__
,__LINE__
,_("Cannot open file \"%s\": %s\n"),wdirname
,strerror(errno
));
800 fprintf(fp_ou
,"%s\t%s\t%s\t%s\t%s\t%s\n",user
,data
,hora
,ip
,url
,smart
);
801 fputs("</body>\n</html>\n",fp_tt
);
803 if (fclose(fp_ou
)==EOF
) {
804 debuga(__FILE__
,__LINE__
,_("Write error in \"%s\": %s\n"),wdirname
,strerror(errno
));