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
));
98 if (vrfydir(&period
, addr
, site
, us
)<0) {
99 debuga(__FILE__
,__LINE__
,_("Cannot create the output directory name containing the period as part of the name\n"));
103 if (snprintf(outdirname
,sizeof(outdirname
),"%s/emailrep",tmp
)>=sizeof(outdirname
)) {
104 debuga(__FILE__
,__LINE__
,_("Path too long: "));
105 debuga_more("%s/emailrep\n",tmp
);
108 my_mkdir(outdirname
);
111 if(debugz
>=LogLevel_Process
){
112 debugaz(__FILE__
,__LINE__
,_("outdirname=%s\n"),outdirname
);
115 if (!FileList_IsEmpty(UserAgentLog
) && email
[0] == '\0') useragent();
117 snprintf(wdirname
,sizeof(wdirname
),"%s/sarg-general",outdirname
);
118 if((fp_gen
=MY_FOPEN(wdirname
,"w"))==NULL
){
119 debuga(__FILE__
,__LINE__
,_("Cannot open file \"%s\": %s\n"),wdirname
,strerror(errno
));
124 sort_labels(&sort_field
,&sort_order
);
126 if (indexonly
|| datetimeby
==0)
129 daystat
=day_prepare();
131 uscan
=userinfo_startscan();
133 debuga(__FILE__
,__LINE__
,_("Cannot enumerate the user list\n"));
136 while ((uinfo
= userinfo_advancescan(uscan
)) != NULL
) {
137 sort_users_log(tmp
,debug
,uinfo
);
138 if (snprintf(tmp3
,sizeof(tmp3
),"%s/%s.user_log",tmp
,uinfo
->filename
)>=sizeof(tmp3
)) {
139 debuga(__FILE__
,__LINE__
,_("Path too long: "));
140 debuga_more("%s/%s.user_log\n",tmp
,uinfo
->filename
);
143 if((fp_in
=FileObject_Open(tmp3
))==NULL
){
144 debuga(__FILE__
,__LINE__
,_("Cannot open file \"%s\": %s\n"),tmp3
,FileObject_GetLastOpenError());
147 user
=uinfo
->filename
;
148 day_newuser(daystat
);
150 strcpy(u2
,uinfo
->id
);
151 if(Ip2Name
&& uinfo
->id_is_ip
) {
152 safe_strcpy(ipantes
,u2
,sizeof(ipantes
));
153 ip2name(u2
,sizeof(u2
));
154 strcpy(nameantes
,u2
);
156 user_find(userlabel
,MAX_USER_LEN
, u2
);
157 userinfo_label(uinfo
,userlabel
);
160 fp_tmp
=maketmp(user
,tmp
,debug
);
167 memset(oldaccdiatt
,0,sizeof(oldaccdiatt
));
168 memset(oldacchoratt
,0,sizeof(oldacchoratt
));
169 memset(oldacciptt
,0,sizeof(oldacciptt
));
177 if ((line
=longline_create())==NULL
) {
178 debuga(__FILE__
,__LINE__
,_("Not enough memory to read file \"%s\"\n"),tmp3
);
182 while((buf
=longline_read(fp_in
,line
))!=NULL
) {
183 getword_start(&gwarea
,buf
);
184 if (getword(accdia
,sizeof(accdia
),&gwarea
,'\t')<0 || getword(acchora
,sizeof(acchora
),&gwarea
,'\t')<0 ||
185 getword(accip
,sizeof(accip
),&gwarea
,'\t')<0 ||
186 getword_ptr(buf
,&accurl
,&gwarea
,'\t')<0 || getword_atoll(&accbytes
,&gwarea
,'\t')<0 ||
187 getword(acccode
,sizeof(acccode
),&gwarea
,'\t')<0) {
188 debuga(__FILE__
,__LINE__
,_("Invalid record in file \"%s\"\n"),tmp3
);
191 if(strncmp(acccode
,"TCP_DENIED/407",14) == 0) continue;
192 if (getword_atoll(&accelap
,&gwarea
,'\t')<0) {
193 debuga(__FILE__
,__LINE__
,_("Invalid elapsed time in file \"%s\"\n"),tmp3
);
196 if (getword_skip(20000,&gwarea
,'"')<0 || getword(accsmart
,sizeof(accsmart
),&gwarea
,'"')<0) {
197 debuga(__FILE__
,__LINE__
,_("Invalid smart info in file \"%s\"\n"),tmp3
);
201 if(accsmart
[0] != '\0') {
203 grava_SmartFilter(tmp
,uinfo
->id
,accip
,accdia
,acchora
,accurl
,accsmart
);
207 if(strcmp(accip
,ipantes
) != 0) {
208 strcpy(ipantes
,accip
);
209 ip2name(accip
,sizeof(accip
));
210 strcpy(nameantes
,accip
);
211 } else safe_strcpy(accip
,nameantes
,sizeof(accip
));
215 day_addpoint(daystat
,accdia
,acchora
,accelap
,accbytes
);
216 if (iprel
) gravaporuser(uinfo
,outdirname
,accurl
,accip
,accdia
,acchora
,accbytes
,accelap
);
220 url_len
=strlen(accurl
);
221 if (!oldurl
|| url_len
>=ourl_size
) {
223 oldurl
=realloc(oldurl
,ourl_size
);
225 debuga(__FILE__
,__LINE__
,_("Not enough memory to store the url\n"));
229 strcpy(oldurl
,accurl
);
230 strcpy(oldacccode
,acccode
);
231 strcpy(oldaccip
,accip
);
232 strcpy(oldaccdia
,accdia
);
233 strcpy(oldacchora
,acchora
);
236 same_url
=(strcmp(oldurl
,accurl
) == 0);
238 if(site
[0] == '\0') {
240 if(strstr(oldacccode
,"DENIED") != 0)
241 strcpy(oldmsg
,"DENIED");
244 if (fp_tmp
) gravatmp(fp_tmp
,oldurl
,nacc
,nbytes
,oldmsg
,nelap
,incache
,oucache
);
245 gravager(fp_gen
,wdirname
,uinfo
,nacc
,oldurl
,nbytes
,oldaccip
,oldacchora
,oldaccdia
,nelap
,incache
,oucache
);
257 if ((ReportType
& REPORT_TYPE_SITE_USER_TIME_DATE
) != 0 && !indexonly
&&
258 (!oldurltt
|| strcmp(oldurltt
,accurl
) || strcmp(oldaccdiatt
,accdia
) || strcmp(oldacchoratt
,acchora
) ||
259 strcmp(oldacciptt
,accip
))) {
262 snprintf(arqtt
,sizeof(arqtt
),"%s/%s",outdirname
,uinfo
->filename
);
263 if(access(arqtt
, R_OK
) != 0)
265 snprintf(arqtt
,sizeof(arqtt
),"%s/%s/tt.html",outdirname
,uinfo
->filename
);
266 if ((fp_tt
= fopen(arqtt
, "w")) == 0) {
267 debuga(__FILE__
,__LINE__
,_("Cannot open file \"%s\": %s\n"),arqtt
,strerror(errno
));
274 sprintf(httplink,"<font size=%s color=%s><href=http://%s>%s",FontSize,PrivacyStringColor,PrivacyString,PrivacyString);
276 sprintf(httplink,"<font size=%s><a href=\"http://%s\">%s</a>",FontSize,accurl,accurl);
279 write_html_header(fp_tt
,(IndexTree
== INDEX_TREE_DATE
) ? 4 : 2,_("Site access report"),HTML_JS_NONE
);
280 fprintf(fp_tt
,"<tr><td class=\"header_c\">%s: %s</td></tr>\n",_("Period"),period
.html
);
281 fprintf(fp_tt
,"<tr><td class=\"header_c\">%s: %s</td></tr>\n",_("User"),uinfo
->label
);
282 fputs("<tr><td class=\"header_c\">",fp_tt
);
283 fprintf(fp_tt
,_("Sort: %s, %s"),sort_field
,sort_order
);
284 fputs("</td></tr>\n",fp_tt
);
285 fprintf(fp_tt
,"<tr><th class=\"header_c\">%s</th></tr>\n",_("User"));
286 close_html_header(fp_tt
);
288 fputs("<div class=\"report\"><table cellpadding=\"0\" cellspacing=\"2\">\n",fp_tt
);
290 if (!oldurltt
|| strcmp(oldurltt
,accurl
)) {
291 const char *url
=accurl
;
292 if (*url
==ALIAS_PREFIX
) url
++;
293 url_to_anchor(accurl
,siteind
,sizeof(siteind
));
294 fprintf(fp_tt
,"<tr class=\"tt\"><td colspan=\"3\"><a name=\"%s\">",siteind
);
295 fprintf(fp_tt
,"<b>%s</b>",_("Accessed site: "));
296 output_html_string(fp_tt
,url
,100);
297 fputs("</a></td></tr>\n",fp_tt
);
298 fprintf(fp_tt
,"<tr><th class=\"header_l\">%s</th>",_("IP"));
299 fprintf(fp_tt
,"<th class=\"header_l\">%s</th><th class=\"header_l\">%s</th></tr>\n",_("DATE"),pgettext("wall clock","TIME"));
302 fprintf(fp_tt
,"<tr><td class=\"data2\">%s</td>",accip
);
303 fprintf(fp_tt
,"<td class=\"data\">%s</td><td class=\"data\">%s</td></tr>\n",accdia
,acchora
);
305 url_len
=strlen(accurl
);
306 if (!oldurltt
|| url_len
>=ourltt_size
) {
307 ourltt_size
=url_len
+1;
308 oldurltt
=realloc(oldurltt
,ourltt_size
);
310 debuga(__FILE__
,__LINE__
,_("Not enough memory to store the url\n"));
314 strcpy(oldurltt
,accurl
);
315 strcpy(oldaccdiatt
,accdia
);
316 strcpy(oldacchoratt
,acchora
);
317 strcpy(oldacciptt
,accip
);
320 strcpy(crc2
,acccode
);
321 str
=strchr(crc2
,'/');
323 if(strstr(crc2
,"MISS") != 0)
328 strcpy(oldacccode
,acccode
);
329 strcpy(oldaccip
,accip
);
331 url_len
=strlen(accurl
);
332 if (url_len
>=ourl_size
) {
334 oldurl
=realloc(oldurl
,ourl_size
);
336 debuga(__FILE__
,__LINE__
,_("Not enough memory to store the url\n"));
340 strcpy(oldurl
,accurl
);
342 strcpy(oldaccdia
,accdia
);
343 strcpy(oldacchora
,acchora
);
345 if (FileObject_Close(fp_in
)) {
346 debuga(__FILE__
,__LINE__
,_("Read error in \"%s\": %s\n"),tmp3
,FileObject_GetLastCloseError());
349 longline_destroy(&line
);
350 if (oldurltt
) free(oldurltt
);
352 if(strstr(oldacccode
,"DENIED") != 0)
353 strcpy(oldmsg
,"DENIED");
356 if (fp_tmp
) gravatmp(fp_tmp
,oldurl
,nacc
,nbytes
,oldmsg
,nelap
,incache
,oucache
);
358 gravager(fp_gen
,wdirname
,uinfo
,nacc
,oldurl
,nbytes
,oldaccip
,oldacchora
,oldaccdia
,nelap
,incache
,oucache
);
363 day_totalize(daystat
,tmp
,uinfo
);
366 if (fclose(fp_tmp
)==EOF
) {
367 debuga(__FILE__
,__LINE__
,_("Write error in \"%s\": %s\n"),uinfo
->filename
,strerror(errno
));
372 if (!KeepTempLog
&& unlink(tmp3
)) {
373 debuga(__FILE__
,__LINE__
,_("Cannot delete \"%s\": %s\n"),tmp3
,strerror(errno
));
377 userinfo_stopscan(uscan
);
378 day_cleanup(daystat
);
380 totalger(fp_gen
,wdirname
);
381 if (fclose(fp_gen
)==EOF
) {
382 debuga(__FILE__
,__LINE__
,_("Write error in \"%s\": %s\n"),wdirname
,strerror(errno
));
386 if(email
[0] == '\0') {
388 if(DansGuardianConf
[0] != '\0')
390 else if (debugz
>=LogLevel_Process
)
391 debugaz(__FILE__
,__LINE__
,_("Dansguardian report not produced because no dansguardian configuration file was provided\n"));
399 if((ReportType
& REPORT_TYPE_DOWNLOADS
) != 0)
401 else if (debugz
>=LogLevel_Process
)
402 debugaz(__FILE__
,__LINE__
,_("Downloaded files report not requested in report_type\n"));
404 if((ReportType
& REPORT_TYPE_TOPSITES
) != 0)
406 else if (debugz
>=LogLevel_Process
)
407 debugaz(__FILE__
,__LINE__
,_("Top sites report not requested in report_type\n"));
409 if((ReportType
& REPORT_TYPE_SITES_USERS
) != 0)
411 else if (debugz
>=LogLevel_Process
)
412 debugaz(__FILE__
,__LINE__
,_("Sites & users report not requested in report_type\n"));
414 if ((ReportType
& REPORT_TYPE_DENIED
) != 0)
416 else if (debugz
>=LogLevel_Process
)
417 debugaz(__FILE__
,__LINE__
,_("Denied accesses report not requested in report_type\n"));
419 if ((ReportType
& REPORT_TYPE_AUTH_FAILURES
) != 0)
421 else if (debugz
>=LogLevel_Process
)
422 debugaz(__FILE__
,__LINE__
,_("Authentication failures report not requested in report_type\n"));
424 if(smartfilter
) smartfilter_report();
426 if(DansGuardianConf
[0] != '\0')
427 dansguardian_report();
431 if((ReportType
& REPORT_TYPE_USERS_SITES
) != 0)
433 else if (debugz
>=LogLevel_Process
)
434 debugaz(__FILE__
,__LINE__
,_("User's detailed report not requested in report_type\n"));
439 if(SuccessfulMsg
) debuga(__FILE__
,__LINE__
,_("Successful report generated on %s\n"),outdirname
);
443 if((strcmp(email
,"stdout") != 0) && SuccessfulMsg
)
444 debuga(__FILE__
,__LINE__
,_("Successful report generated and sent to %s\n"),email
);
447 if(indexonly
) index_only(outdirname
, debug
);
449 removetmp(outdirname
);
453 static FILE *maketmp(const char *user
, const char *dirname
, int debug
)
456 char wdirname
[MAXLEN
];
458 if((ReportType
& REPORT_TYPE_USERS_SITES
) == 0) return(NULL
);
459 if((ReportType
& REPORT_TYPE_TOPUSERS
) == 0) return(NULL
);
461 if(debug
) debuga(__FILE__
,__LINE__
,_("Making file %s/%s\n"),tmp
,user
);
462 if (snprintf(wdirname
,sizeof(wdirname
),"%s/%s.utmp",tmp
,user
)>=sizeof(wdirname
)) {
463 debuga(__FILE__
,__LINE__
,_("Path too long: "));
464 debuga_more("%s/%s.utmp\n",tmp
,user
);
468 if((fp_ou
=fopen(wdirname
,"w"))==NULL
){
469 debuga(__FILE__
,__LINE__
,_("Cannot open file \"%s\": %s\n"),wdirname
,strerror(errno
));
477 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
)
480 This complicated printf is due to Microsoft's inability to comply with any standard. Msvcrt is unable
481 to print a long long int unless it is exactly 64-bits long.
483 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
);
488 static void closett(void)
493 fputs("</table>\n</div>\n",fp_tt
);
494 fputs("</body>\n</html>\n",fp_tt
);
495 if (fclose(fp_tt
)==EOF
) {
496 debuga(__FILE__
,__LINE__
,_("Write error in \"%s\": %s\n"),arqtt
,strerror(errno
));
503 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
)
506 char wdirname
[MAXLEN
];
508 if((ReportType
& REPORT_TYPE_USERS_SITES
) == 0) return;
510 if (snprintf(wdirname
,sizeof(wdirname
),"%s/%s.ip",tmp
,uinfo
->filename
)>=sizeof(wdirname
)) {
511 debuga(__FILE__
,__LINE__
,_("Path too long: "));
512 debuga_more("%s/%s.ip\n",tmp
,uinfo
->filename
);
516 if((fp_ou
=MY_FOPEN(wdirname
,"a"))==NULL
){
517 debuga(__FILE__
,__LINE__
,_("Cannot open file \"%s\": %s\n"),wdirname
,strerror(errno
));
522 This complicated printf is due to Microsoft's inability to comply with any standard. Msvcrt is unable
523 to print a long long int unless it is exactly 64-bits long.
525 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
);
527 if (fclose(fp_ou
)==EOF
) {
528 debuga(__FILE__
,__LINE__
,_("Write error in \"%s\": %s\n"),wdirname
,strerror(errno
));
536 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
)
539 This complicated printf is due to Microsoft's inability to comply with any standard. Msvcrt is unable
540 to print a long long int unless it is exactly 64-bits long.
542 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) {
543 debuga(__FILE__
,__LINE__
,_("Write error in file \"%s\": %s\n"),filename
,strerror(errno
));
548 globstat
.nbytes
+=nbytes
;
549 globstat
.elap
+=nelap
;
550 globstat
.incache
+=incache
;
551 globstat
.oucache
+=oucache
;
556 Write the total line at the end of the general file.
558 void totalger(FILE *fp_gen
,const char *filename
)
561 This complicated printf is due to Microsoft's inability to comply with any standard. Msvcrt is unable
562 to print a long long int unless it is exactly 64-bits long.
564 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) {
565 debuga(__FILE__
,__LINE__
,_("Failed to write the total line in %s\n"),filename
);
570 int ger_read(char *buffer
,struct generalitemstruct
*item
,const char *filename
)
574 long long int number
;
576 if (strncmp(buffer
,"TOTAL\t",6)==0) {
581 if (*buffer
== '-') {
584 } else if (*buffer
== '+') {
588 while (isdigit(*buffer
))
589 number
=(number
* 10) + (*buffer
++)-'0';
591 debuga(__FILE__
,__LINE__
,_("Invalid total number of accesses in file \"%s\"\n"),filename
);
595 item
->nacc
=number
*sign
;
598 if (*buffer
== '-') {
601 } else if (*buffer
== '+') {
605 while (isdigit(*buffer
))
606 number
=(number
* 10) + (*buffer
++)-'0';
608 debuga(__FILE__
,__LINE__
,_("Invalid total size in file \"%s\"\n"),filename
);
612 item
->nbytes
=number
*sign
;
615 if (*buffer
== '-') {
618 } else if (*buffer
== '+') {
622 while (isdigit(*buffer
))
623 number
=(number
* 10) + (*buffer
++)-'0';
625 debuga(__FILE__
,__LINE__
,_("Invalid total elapsed time in file \"%s\"\n"),filename
);
629 item
->nelap
=number
*sign
;
632 if (*buffer
== '-') {
635 } else if (*buffer
== '+') {
639 while (isdigit(*buffer
))
640 number
=(number
* 10) + (*buffer
++)-'0';
642 debuga(__FILE__
,__LINE__
,_("Invalid total cache hit in file \"%s\"\n"),filename
);
646 item
->incache
=number
*sign
;
649 if (*buffer
== '-') {
652 } else if (*buffer
== '+') {
656 while (isdigit(*buffer
))
657 number
=(number
* 10) + (*buffer
++)-'0';
659 debuga(__FILE__
,__LINE__
,_("Invalid total cache miss in file \"%s\"\n"),filename
);
662 item
->oucache
=number
*sign
;
667 for (i
=0 ; i
<MAX_USER_LEN
-1 && (unsigned char)*buffer
>=' ' ; i
++) buffer
++;
669 debuga(__FILE__
,__LINE__
,_("User name too long or invalid in file \"%s\"\n"),filename
);
675 if (*buffer
== '-') {
678 } else if (*buffer
== '+') {
682 while (isdigit(*buffer
))
683 number
=(number
* 10) + (*buffer
++)-'0';
685 debuga(__FILE__
,__LINE__
,_("Invalid number of accesses in file \"%s\"\n"),filename
);
689 item
->nacc
=number
*sign
;
692 if (*buffer
== '-') {
695 } else if (*buffer
== '+') {
699 while (isdigit(*buffer
))
700 number
=(number
* 10) + (*buffer
++)-'0';
702 debuga(__FILE__
,__LINE__
,_("Invalid number of bytes in file \"%s\"\n"),filename
);
706 item
->nbytes
=number
*sign
;
709 while ((unsigned char)*buffer
>=' ') buffer
++;
711 debuga(__FILE__
,__LINE__
,_("URL too long or invalid in file \"%s\"\n"),filename
);
717 for (i
=0 ; i
<MAX_IP_LEN
-1 && (unsigned char)*buffer
>=' ' ; i
++) buffer
++;
719 debuga(__FILE__
,__LINE__
,_("IP address too long or invalid in file \"%s\"\n"),filename
);
725 for (i
=0 ; i
<MAX_DATETIME_LEN
-1 && (unsigned char)*buffer
>=' ' ; i
++) buffer
++;
727 debuga(__FILE__
,__LINE__
,_("Time too long or invalid in file \"%s\"\n"),filename
);
733 for (i
=0 ; i
<MAX_DATETIME_LEN
-1 && (unsigned char)*buffer
>=' ' ; i
++) buffer
++;
735 debuga(__FILE__
,__LINE__
,_("Date too long or invalid in file \"%s\"\n"),filename
);
741 if (*buffer
== '-') {
744 } else if (*buffer
== '+') {
748 while (isdigit(*buffer
))
749 number
=(number
* 10) + (*buffer
++)-'0';
751 debuga(__FILE__
,__LINE__
,_("Invalid elapsed time in file \"%s\"\n"),filename
);
755 item
->nelap
=number
*sign
;
758 if (*buffer
== '-') {
761 } else if (*buffer
== '+') {
765 while (isdigit(*buffer
))
766 number
=(number
* 10) + (*buffer
++)-'0';
768 debuga(__FILE__
,__LINE__
,_("Invalid cache hit size in file \"%s\"\n"),filename
);
772 item
->incache
=number
*sign
;
775 if (*buffer
== '-') {
778 } else if (*buffer
== '+') {
782 while (isdigit(*buffer
))
783 number
=(number
* 10) + (*buffer
++)-'0';
785 debuga(__FILE__
,__LINE__
,_("Invalid cache miss size in file \"%s\"\n"),filename
);
788 item
->oucache
=number
*sign
;
793 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
)
796 char wdirname
[MAXLEN
];
798 if (snprintf(wdirname
,sizeof(wdirname
),"%s/smartfilter.int_unsort",dirname
)>=sizeof(wdirname
)) {
799 debuga(__FILE__
,__LINE__
,_("Path too long: "));
800 debuga_more("%s/smartfilter.int_unsort\n",dirname
);
804 if((fp_ou
=MY_FOPEN(wdirname
,"a"))==NULL
){
805 debuga(__FILE__
,__LINE__
,_("Cannot open file \"%s\": %s\n"),wdirname
,strerror(errno
));
809 fprintf(fp_ou
,"%s\t%s\t%s\t%s\t%s\t%s\n",user
,data
,hora
,ip
,url
,smart
);
810 fputs("</body>\n</html>\n",fp_tt
);
812 if (fclose(fp_ou
)==EOF
) {
813 debuga(__FILE__
,__LINE__
,_("Write error in \"%s\": %s\n"),wdirname
,strerror(errno
));