]> git.ipfire.org Git - thirdparty/sarg.git/blob - report.c
56edff97d0a218cba301023279572bf96466f147
[thirdparty/sarg.git] / report.c
1 /*
2 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
3 * 1998, 2015
4 *
5 * SARG donations:
6 * please look at http://sarg.sourceforge.net/donations.php
7 * Support:
8 * http://sourceforge.net/projects/sarg/forums/forum/363374
9 * ---------------------------------------------------------------------
10 *
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.
15 *
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.
20 *
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.
24 *
25 */
26
27 #include "include/conf.h"
28 #include "include/defs.h"
29
30 //! The global statistics of the whole log read.
31 struct globalstatstruct globstat;
32 //! \c True to enable the smart filter.
33 bool smartfilter=false;
34
35 //! The file to store the HTML page where the time of access is reported for one site and one user.
36 static FILE *fp_tt=NULL;
37 //! The name of the file containing the access time of the site/user.
38 static char arqtt[4096]="";
39
40 static FILE *maketmp(const char *user, const char *dirname, int debug);
41 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);
42 static void closett(void);
43 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);
44 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);
45 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);
46
47 void gerarel(void)
48 {
49 FILE *fp_in;
50 FILE *fp_gen;
51 FILE *fp_tmp=NULL;
52
53 char *buf;
54 char accdia[11], acchora[9], accip[256], *accurl;
55 char oldaccdia[11], oldacchora[9], oldaccip[256];
56 char oldacciptt[256];
57 char wdirname[MAXLEN];
58 char *oldurl=NULL;
59 char oldmsg[50], acccode[MAXLEN/2 - 1], oldacccode[MAXLEN/2 - 1];
60 char ipantes[256], nameantes[MAXLEN];
61 char accsmart[MAXLEN];
62 char crc2[MAXLEN/2 -1];
63 char siteind[MAX_TRUNCATED_URL];
64 char *oldurltt=NULL;
65 char oldaccdiatt[11],oldacchoratt[9];
66 char tmp3[MAXLEN];
67 char u2[MAX_USER_LEN];
68 char userlabel[MAX_USER_LEN];
69 long long int nbytes=0;
70 long long int nelap=0;
71 long long int nacc=0;
72 long long int incache=0;
73 long long int oucache=0;
74 long long int accbytes, accelap;
75 char *str;
76 userscan uscan;
77 const char *sort_field;
78 const char *sort_order;
79 const char *user;
80 int url_len;
81 int ourl_size=0;
82 int ourltt_size=0;
83 int same_url;
84 bool new_user;
85 struct getwordstruct gwarea;
86 longline line;
87 struct userinfostruct *uinfo;
88 DayObject daystat;
89
90 ipantes[0]='\0';
91 smartfilter=false;
92 memset(&globstat,0,sizeof(globstat));
93
94 if (vrfydir(&period, addr, site, us, email)<0) {
95 debuga(_("Cannot create the output directory name containing the period as part of the name\n"));
96 exit(EXIT_FAILURE);
97 }
98
99 if(debugz>=LogLevel_Process){
100 debugaz(_("outdirname=%s\n"),outdirname);
101 }
102
103 if(UserAgentLog[0] != '\0' && email[0] == '\0') useragent();
104
105 snprintf(wdirname,sizeof(wdirname),"%s/sarg-general",outdirname);
106 if((fp_gen=MY_FOPEN(wdirname,"w"))==NULL){
107 debuga(_("Cannot open file \"%s\": %s\n"),wdirname,strerror(errno));
108 exit(EXIT_FAILURE);
109 }
110
111 fp_tt=NULL;
112 sort_labels(&sort_field,&sort_order);
113
114 if (indexonly || datetimeby==0)
115 daystat=NULL;
116 else
117 daystat=day_prepare();
118
119 uscan=userinfo_startscan();
120 if (uscan == NULL) {
121 debuga(_("Cannot enumerate the user list\n"));
122 exit(EXIT_FAILURE);
123 }
124 while ((uinfo = userinfo_advancescan(uscan)) != NULL ) {
125 sort_users_log(tmp,debug,uinfo);
126 if (snprintf(tmp3,sizeof(tmp3),"%s/%s.user_log",tmp,uinfo->filename)>=sizeof(tmp3)) {
127 debuga(_("Path too long: "));
128 debuga_more("%s/%s.user_log\n",tmp,uinfo->filename);
129 exit(EXIT_FAILURE);
130 }
131 if((fp_in=MY_FOPEN(tmp3,"r"))==NULL){
132 debuga(_("Cannot open file \"%s\": %s\n"),tmp3,strerror(errno));
133 exit(EXIT_FAILURE);
134 }
135 user=uinfo->filename;
136 day_newuser(daystat);
137
138 strcpy(u2,uinfo->id);
139 if(Ip2Name && uinfo->id_is_ip) {
140 safe_strcpy(ipantes,u2,sizeof(ipantes));
141 ip2name(u2,sizeof(u2));
142 strcpy(nameantes,u2);
143 }
144 user_find(userlabel,MAX_USER_LEN, u2);
145 userinfo_label(uinfo,userlabel);
146
147 if (!indexonly) {
148 fp_tmp=maketmp(user,tmp,debug);
149 }
150
151 ttopen=0;
152 oldurl=NULL;
153 oldurltt=NULL;
154 ourltt_size=0;
155 memset(oldaccdiatt,0,sizeof(oldaccdiatt));
156 memset(oldacchoratt,0,sizeof(oldacchoratt));
157 memset(oldacciptt,0,sizeof(oldacciptt));
158 new_user=true;
159 nacc=0;
160 nbytes=0;
161 nelap=0;
162 incache=0;
163 oucache=0;
164
165 if ((line=longline_create())==NULL) {
166 debuga(_("Not enough memory to read file \"%s\"\n"),tmp3);
167 exit(EXIT_FAILURE);
168 }
169
170 while((buf=longline_read(fp_in,line))!=NULL) {
171 getword_start(&gwarea,buf);
172 if (getword(accdia,sizeof(accdia),&gwarea,'\t')<0 || getword(acchora,sizeof(acchora),&gwarea,'\t')<0 ||
173 getword(accip,sizeof(accip),&gwarea,'\t')<0 ||
174 getword_ptr(buf,&accurl,&gwarea,'\t')<0 || getword_atoll(&accbytes,&gwarea,'\t')<0 ||
175 getword(acccode,sizeof(acccode),&gwarea,'\t')<0) {
176 debuga(_("Invalid record in file \"%s\"\n"),tmp3);
177 exit(EXIT_FAILURE);
178 }
179 if(strncmp(acccode,"TCP_DENIED/407",14) == 0) continue;
180 if (getword_atoll(&accelap,&gwarea,'\t')<0) {
181 debuga(_("Invalid elapsed time in file \"%s\"\n"),tmp3);
182 exit(EXIT_FAILURE);
183 }
184 if (getword_skip(20000,&gwarea,'"')<0 || getword(accsmart,sizeof(accsmart),&gwarea,'"')<0) {
185 debuga(_("Invalid smart info in file \"%s\"\n"),tmp3);
186 exit(EXIT_FAILURE);
187 }
188
189 if(accsmart[0] != '\0') {
190 smartfilter=true;
191 grava_SmartFilter(tmp,uinfo->id,accip,accdia,acchora,accurl,accsmart);
192 }
193
194 if(Ip2Name) {
195 if(strcmp(accip,ipantes) != 0) {
196 strcpy(ipantes,accip);
197 ip2name(accip,sizeof(accip));
198 strcpy(nameantes,accip);
199 } else safe_strcpy(accip,nameantes,sizeof(accip));
200 }
201
202 if (!indexonly) {
203 day_addpoint(daystat,accdia,acchora,accelap,accbytes);
204 if (iprel) gravaporuser(uinfo,outdirname,accurl,accip,accdia,acchora,accbytes,accelap);
205 }
206
207 if(new_user){
208 url_len=strlen(accurl);
209 if (!oldurl || url_len>=ourl_size) {
210 ourl_size=url_len+1;
211 oldurl=realloc(oldurl,ourl_size);
212 if (!oldurl) {
213 debuga(_("Not enough memory to store the url\n"));
214 exit(EXIT_FAILURE);
215 }
216 }
217 strcpy(oldurl,accurl);
218 strcpy(oldacccode,acccode);
219 strcpy(oldaccip,accip);
220 strcpy(oldaccdia,accdia);
221 strcpy(oldacchora,acchora);
222 new_user=false;
223 }
224 same_url=(strcmp(oldurl,accurl) == 0);
225
226 if(site[0] == '\0') {
227 if(!same_url){
228 if(strstr(oldacccode,"DENIED") != 0)
229 strcpy(oldmsg,"DENIED");
230 else
231 strcpy(oldmsg,"OK");
232 if (fp_tmp) gravatmp(fp_tmp,oldurl,nacc,nbytes,oldmsg,nelap,incache,oucache);
233 gravager(fp_gen,wdirname,uinfo,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache);
234 nacc=0;
235 nbytes=0;
236 nelap=0;
237 incache=0;
238 oucache=0;
239 }
240 }
241 nacc++;
242 nbytes+=accbytes;
243 nelap+=accelap;
244
245 if ((ReportType & REPORT_TYPE_SITE_USER_TIME_DATE) != 0 && !indexonly &&
246 (!oldurltt || strcmp(oldurltt,accurl) || strcmp(oldaccdiatt,accdia) || strcmp(oldacchoratt,acchora) ||
247 strcmp(oldacciptt,accip))) {
248
249 if(!ttopen) {
250 snprintf(arqtt,sizeof(arqtt),"%s/%s",outdirname,uinfo->filename);
251 if(access(arqtt, R_OK) != 0)
252 my_mkdir(arqtt);
253 snprintf(arqtt,sizeof(arqtt),"%s/%s/tt.html",outdirname,uinfo->filename);
254 if ((fp_tt = fopen(arqtt, "w")) == 0) {
255 debuga(_("Cannot open file \"%s\": %s\n"),arqtt,strerror(errno));
256 exit(EXIT_FAILURE);
257 }
258 ttopen=1;
259
260 /*
261 if(Privacy)
262 sprintf(httplink,"<font size=%s color=%s><href=http://%s>%s",FontSize,PrivacyStringColor,PrivacyString,PrivacyString);
263 else
264 sprintf(httplink,"<font size=%s><a href=\"http://%s\">%s</a>",FontSize,accurl,accurl);
265 */
266
267 write_html_header(fp_tt,(IndexTree == INDEX_TREE_DATE) ? 4 : 2,_("Site access report"),HTML_JS_NONE);
268 fprintf(fp_tt,"<tr><td class=\"header_c\">%s:&nbsp;%s</td></tr>\n",_("Period"),period.html);
269 fprintf(fp_tt,"<tr><td class=\"header_c\">%s:&nbsp;%s</td></tr>\n",_("User"),uinfo->label);
270 fputs("<tr><td class=\"header_c\">",fp_tt);
271 fprintf(fp_tt,_("Sort:&nbsp;%s, %s"),sort_field,sort_order);
272 fputs("</td></tr>\n",fp_tt);
273 fprintf(fp_tt,"<tr><th class=\"header_c\">%s</th></tr>\n",_("User"));
274 close_html_header(fp_tt);
275
276 fputs("<div class=\"report\"><table cellpadding=\"0\" cellspacing=\"2\">\n",fp_tt);
277 }
278 if (!oldurltt || strcmp(oldurltt,accurl)) {
279 const char *url=accurl;
280 if (*url==ALIAS_PREFIX) url++;
281 url_to_anchor(accurl,siteind,sizeof(siteind));
282 fprintf(fp_tt,"<tr class=\"tt\"><td colspan=\"3\"><a name=\"%s\">",siteind);
283 fprintf(fp_tt,"<b>%s</b>",_("Accessed site: "));
284 output_html_string(fp_tt,url,100);
285 fputs("</a></td></tr>\n",fp_tt);
286 fprintf(fp_tt,"<tr><th class=\"header_l\">%s</th>",_("IP"));
287 fprintf(fp_tt,"<th class=\"header_l\">%s</th><th class=\"header_l\">%s</th></tr>\n",_("DATE"),pgettext("wall clock","TIME"));
288 }
289
290 fprintf(fp_tt,"<tr><td class=\"data2\">%s</td>",accip);
291 fprintf(fp_tt,"<td class=\"data\">%s</td><td class=\"data\">%s</td></tr>\n",accdia,acchora);
292
293 url_len=strlen(accurl);
294 if (!oldurltt || url_len>=ourltt_size) {
295 ourltt_size=url_len+1;
296 oldurltt=realloc(oldurltt,ourltt_size);
297 if (!oldurltt) {
298 debuga(_("Not enough memory to store the url\n"));
299 exit(EXIT_FAILURE);
300 }
301 }
302 strcpy(oldurltt,accurl);
303 strcpy(oldaccdiatt,accdia);
304 strcpy(oldacchoratt,acchora);
305 strcpy(oldacciptt,accip);
306 }
307
308 strcpy(crc2,acccode);
309 str=strchr(crc2,'/');
310 if (str) *str='\0';
311 if(strstr(crc2,"MISS") != 0)
312 oucache+=accbytes;
313 else
314 incache+=accbytes;
315
316 strcpy(oldacccode,acccode);
317 strcpy(oldaccip,accip);
318 if (!same_url) {
319 url_len=strlen(accurl);
320 if (url_len>=ourl_size) {
321 ourl_size=url_len+1;
322 oldurl=realloc(oldurl,ourl_size);
323 if (!oldurl) {
324 debuga(_("Not enough memory to store the url\n"));
325 exit(EXIT_FAILURE);
326 }
327 }
328 strcpy(oldurl,accurl);
329 }
330 strcpy(oldaccdia,accdia);
331 strcpy(oldacchora,acchora);
332 }
333 if (fclose(fp_in)==EOF) {
334 debuga(_("Read error in \"%s\": %s\n"),tmp3,strerror(errno));
335 exit(EXIT_FAILURE);
336 }
337 longline_destroy(&line);
338 if (oldurltt) free(oldurltt);
339 if (oldurl) {
340 if(strstr(oldacccode,"DENIED") != 0)
341 strcpy(oldmsg,"DENIED");
342 else
343 strcpy(oldmsg,"OK");
344 if (fp_tmp) gravatmp(fp_tmp,oldurl,nacc,nbytes,oldmsg,nelap,incache,oucache);
345 closett();
346 gravager(fp_gen,wdirname,uinfo,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache);
347 free(oldurl);
348 oldurl=NULL;
349 }
350 if(!new_user) {
351 day_totalize(daystat,tmp,uinfo);
352 }
353 if (fp_tmp) {
354 if (fclose(fp_tmp)==EOF) {
355 debuga(_("Write error in \"%s\": %s\n"),uinfo->filename,strerror(errno));
356 exit(EXIT_FAILURE);
357 }
358 fp_tmp=NULL;
359 }
360 if (!KeepTempLog && unlink(tmp3)) {
361 debuga(_("Cannot delete \"%s\": %s\n"),tmp3,strerror(errno));
362 exit(EXIT_FAILURE);
363 }
364 }
365 userinfo_stopscan(uscan);
366 day_cleanup(daystat);
367
368 totalger(fp_gen,wdirname);
369 if (fclose(fp_gen)==EOF) {
370 debuga(_("Write error in \"%s\": %s\n"),wdirname,strerror(errno));
371 exit(EXIT_FAILURE);
372 }
373
374 if(email[0] == '\0') {
375 if (!indexonly) {
376 if(DansGuardianConf[0] != '\0')
377 dansguardian_log();
378 else if (debugz>=LogLevel_Process)
379 debugaz(_("Dansguardian report not produced because no dansguardian configuration file was provided\n"));
380
381 redirector_log();
382 }
383
384 topuser();
385
386 if (!indexonly) {
387 if((ReportType & REPORT_TYPE_DOWNLOADS) != 0)
388 download_report();
389 else if (debugz>=LogLevel_Process)
390 debugaz(_("Downloaded files report not requested in report_type\n"));
391
392 if((ReportType & REPORT_TYPE_TOPSITES) != 0)
393 topsites();
394 else if (debugz>=LogLevel_Process)
395 debugaz(_("Top sites report not requested in report_type\n"));
396
397 if((ReportType & REPORT_TYPE_SITES_USERS) != 0)
398 siteuser();
399 else if (debugz>=LogLevel_Process)
400 debugaz(_("Sites & users report not requested in report_type\n"));
401
402 if ((ReportType & REPORT_TYPE_DENIED) != 0)
403 gen_denied_report();
404 else if (debugz>=LogLevel_Process)
405 debugaz(_("Denied accesses report not requested in report_type\n"));
406
407 if ((ReportType & REPORT_TYPE_AUTH_FAILURES) != 0)
408 authfail_report();
409 else if (debugz>=LogLevel_Process)
410 debugaz(_("Authentication failures report not requested in report_type\n"));
411
412 if(smartfilter) smartfilter_report();
413
414 if(DansGuardianConf[0] != '\0')
415 dansguardian_report();
416
417 redirector_report();
418
419 if((ReportType & REPORT_TYPE_USERS_SITES) != 0)
420 htmlrel();
421 else if (debugz>=LogLevel_Process)
422 debugaz(_("User's detailed report not requested in report_type\n"));
423 }
424
425 make_index();
426
427 if(SuccessfulMsg) debuga(_("Successful report generated on %s\n"),outdirname);
428 } else {
429 geramail(outdirname, debug, outdir, email, tmp);
430
431 if((strcmp(email,"stdout") != 0) && SuccessfulMsg)
432 debuga(_("Successful report generated and sent to %s\n"),email);
433 }
434
435 if(indexonly) index_only(outdirname, debug);
436
437 removetmp(outdirname);
438 return;
439 }
440
441 static FILE *maketmp(const char *user, const char *dirname, int debug)
442 {
443 FILE *fp_ou;
444 char wdirname[MAXLEN];
445
446 if((ReportType & REPORT_TYPE_USERS_SITES) == 0) return(NULL);
447 if((ReportType & REPORT_TYPE_TOPUSERS) == 0) return(NULL);
448
449 if(debug) debuga(_("Making file %s/%s\n"),tmp,user);
450 if (snprintf(wdirname,sizeof(wdirname),"%s/%s.utmp",tmp,user)>=sizeof(wdirname)) {
451 debuga(_("Path too long: "));
452 debuga_more("%s/%s.utmp\n",tmp,user);
453 exit(EXIT_FAILURE);
454 }
455
456 if((fp_ou=fopen(wdirname,"w"))==NULL){
457 debuga(_("Cannot open file \"%s\": %s\n"),wdirname,strerror(errno));
458 exit(EXIT_FAILURE);
459 }
460
461 return(fp_ou);
462 }
463
464
465 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)
466 {
467 /*
468 This complicated printf is due to Microsoft's inability to comply with any standard. Msvcrt is unable
469 to print a long long int unless it is exactly 64-bits long.
470 */
471 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);
472
473 return;
474 }
475
476 static void closett(void)
477 {
478 ttopen=0;
479
480 if(fp_tt) {
481 fputs("</table>\n</div>\n",fp_tt);
482 fputs("</body>\n</html>\n",fp_tt);
483 if (fclose(fp_tt)==EOF) {
484 debuga(_("Write error in \"%s\": %s\n"),arqtt,strerror(errno));
485 exit(EXIT_FAILURE);
486 }
487 fp_tt=NULL;
488 }
489 }
490
491 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)
492 {
493 FILE *fp_ou;
494 char wdirname[MAXLEN];
495
496 if((ReportType & REPORT_TYPE_USERS_SITES) == 0) return;
497
498 if (snprintf(wdirname,sizeof(wdirname),"%s/%s.ip",tmp,uinfo->filename)>=sizeof(wdirname)) {
499 debuga(_("Path too long: "));
500 debuga_more("%s/%s.ip\n",tmp,uinfo->filename);
501 exit(EXIT_FAILURE);
502 }
503
504 if((fp_ou=MY_FOPEN(wdirname,"a"))==NULL){
505 debuga(_("Cannot open file \"%s\": %s\n"),wdirname,strerror(errno));
506 exit(EXIT_FAILURE);
507 }
508
509 /*
510 This complicated printf is due to Microsoft's inability to comply with any standard. Msvcrt is unable
511 to print a long long int unless it is exactly 64-bits long.
512 */
513 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);
514
515 if (fclose(fp_ou)==EOF) {
516 debuga(_("Write error in \"%s\": %s\n"),wdirname,strerror(errno));
517 exit(EXIT_FAILURE);
518 }
519
520 return;
521 }
522
523
524 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)
525 {
526 /*
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.
529 */
530 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) {
531 debuga(_("Write error in file \"%s\": %s\n"),filename,strerror(errno));
532 exit(EXIT_FAILURE);
533 }
534
535 globstat.nacc+=nacc;
536 globstat.nbytes+=nbytes;
537 globstat.elap+=nelap;
538 globstat.incache+=incache;
539 globstat.oucache+=oucache;
540 return;
541 }
542
543 /*!
544 Write the total line at the end of the general file.
545 */
546 void totalger(FILE *fp_gen,const char *filename)
547 {
548 /*
549 This complicated printf is due to Microsoft's inability to comply with any standard. Msvcrt is unable
550 to print a long long int unless it is exactly 64-bits long.
551 */
552 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) {
553 debuga(_("Failed to write the total line in %s\n"),filename);
554 exit(EXIT_FAILURE);
555 }
556 }
557
558 int ger_read(char *buffer,struct generalitemstruct *item,const char *filename)
559 {
560 int i;
561 int sign;
562 long long int number;
563
564 if (strncmp(buffer,"TOTAL\t",6)==0) {
565 item->total=1;
566 buffer+=6;
567
568 sign=+1;
569 if (*buffer == '-') {
570 buffer++;
571 sign=-1;
572 } else if (*buffer == '+') {
573 buffer++;
574 }
575 number=0LL;
576 while (isdigit(*buffer))
577 number=(number * 10) + (*buffer++)-'0';
578 if (*buffer!='\t') {
579 debuga(_("Invalid total number of accesses in file \"%s\"\n"),filename);
580 exit(EXIT_FAILURE);
581 }
582 buffer++;
583 item->nacc=number*sign;
584
585 sign=+1;
586 if (*buffer == '-') {
587 buffer++;
588 sign=-1;
589 } else if (*buffer == '+') {
590 buffer++;
591 }
592 number=0LL;
593 while (isdigit(*buffer))
594 number=(number * 10) + (*buffer++)-'0';
595 if (*buffer!='\t') {
596 debuga(_("Invalid total size in file \"%s\"\n"),filename);
597 exit(EXIT_FAILURE);
598 }
599 buffer++;
600 item->nbytes=number*sign;
601
602 sign=+1;
603 if (*buffer == '-') {
604 buffer++;
605 sign=-1;
606 } else if (*buffer == '+') {
607 buffer++;
608 }
609 number=0LL;
610 while (isdigit(*buffer))
611 number=(number * 10) + (*buffer++)-'0';
612 if (*buffer!='\t') {
613 debuga(_("Invalid total elapsed time in file \"%s\"\n"),filename);
614 exit(EXIT_FAILURE);
615 }
616 buffer++;
617 item->nelap=number*sign;
618
619 sign=+1;
620 if (*buffer == '-') {
621 buffer++;
622 sign=-1;
623 } else if (*buffer == '+') {
624 buffer++;
625 }
626 number=0LL;
627 while (isdigit(*buffer))
628 number=(number * 10) + (*buffer++)-'0';
629 if (*buffer!='\t') {
630 debuga(_("Invalid total cache hit in file \"%s\"\n"),filename);
631 exit(EXIT_FAILURE);
632 }
633 buffer++;
634 item->incache=number*sign;
635
636 sign=+1;
637 if (*buffer == '-') {
638 buffer++;
639 sign=-1;
640 } else if (*buffer == '+') {
641 buffer++;
642 }
643 number=0LL;
644 while (isdigit(*buffer))
645 number=(number * 10) + (*buffer++)-'0';
646 if (*buffer!='\0') {
647 debuga(_("Invalid total cache miss in file \"%s\"\n"),filename);
648 exit(EXIT_FAILURE);
649 }
650 item->oucache=number*sign;
651 } else {
652 item->total=0;
653
654 item->user=buffer;
655 for (i=0 ; i<MAX_USER_LEN-1 && (unsigned char)*buffer>=' ' ; i++) buffer++;
656 if (*buffer!='\t') {
657 debuga(_("User name too long or invalid in file \"%s\"\n"),filename);
658 exit(EXIT_FAILURE);
659 }
660 *buffer++='\0';
661
662 sign=+1;
663 if (*buffer == '-') {
664 buffer++;
665 sign=-1;
666 } else if (*buffer == '+') {
667 buffer++;
668 }
669 number=0LL;
670 while (isdigit(*buffer))
671 number=(number * 10) + (*buffer++)-'0';
672 if (*buffer!='\t') {
673 debuga(_("Invalid number of accesses in file \"%s\"\n"),filename);
674 exit(EXIT_FAILURE);
675 }
676 buffer++;
677 item->nacc=number*sign;
678
679 sign=+1;
680 if (*buffer == '-') {
681 buffer++;
682 sign=-1;
683 } else if (*buffer == '+') {
684 buffer++;
685 }
686 number=0LL;
687 while (isdigit(*buffer))
688 number=(number * 10) + (*buffer++)-'0';
689 if (*buffer!='\t') {
690 debuga(_("Invalid number of bytes in file \"%s\"\n"),filename);
691 exit(EXIT_FAILURE);
692 }
693 buffer++;
694 item->nbytes=number*sign;
695
696 item->url=buffer;
697 while ((unsigned char)*buffer>=' ') buffer++;
698 if (*buffer!='\t') {
699 debuga(_("URL too long or invalid in file \"%s\"\n"),filename);
700 exit(EXIT_FAILURE);
701 }
702 *buffer++='\0';
703
704 item->ip=buffer;
705 for (i=0 ; i<MAX_IP_LEN-1 && (unsigned char)*buffer>=' ' ; i++) buffer++;
706 if (*buffer!='\t') {
707 debuga(_("IP address too long or invalid in file \"%s\"\n"),filename);
708 exit(EXIT_FAILURE);
709 }
710 *buffer++='\0';
711
712 item->time=buffer;
713 for (i=0 ; i<MAX_DATETIME_LEN-1 && (unsigned char)*buffer>=' ' ; i++) buffer++;
714 if (*buffer!='\t') {
715 debuga(_("Time too long or invalid in file \"%s\"\n"),filename);
716 exit(EXIT_FAILURE);
717 }
718 *buffer++='\0';
719
720 item->date=buffer;
721 for (i=0 ; i<MAX_DATETIME_LEN-1 && (unsigned char)*buffer>=' ' ; i++) buffer++;
722 if (*buffer!='\t') {
723 debuga(_("Date too long or invalid in file \"%s\"\n"),filename);
724 exit(EXIT_FAILURE);
725 }
726 *buffer++='\0';
727
728 sign=+1;
729 if (*buffer == '-') {
730 buffer++;
731 sign=-1;
732 } else if (*buffer == '+') {
733 buffer++;
734 }
735 number=0LL;
736 while (isdigit(*buffer))
737 number=(number * 10) + (*buffer++)-'0';
738 if (*buffer!='\t') {
739 debuga(_("Invalid elapsed time in file \"%s\"\n"),filename);
740 exit(EXIT_FAILURE);
741 }
742 buffer++;
743 item->nelap=number*sign;
744
745 sign=+1;
746 if (*buffer == '-') {
747 buffer++;
748 sign=-1;
749 } else if (*buffer == '+') {
750 buffer++;
751 }
752 number=0LL;
753 while (isdigit(*buffer))
754 number=(number * 10) + (*buffer++)-'0';
755 if (*buffer!='\t') {
756 debuga(_("Invalid cache hit size in file \"%s\"\n"),filename);
757 exit(EXIT_FAILURE);
758 }
759 buffer++;
760 item->incache=number*sign;
761
762 sign=+1;
763 if (*buffer == '-') {
764 buffer++;
765 sign=-1;
766 } else if (*buffer == '+') {
767 buffer++;
768 }
769 number=0LL;
770 while (isdigit(*buffer))
771 number=(number * 10) + (*buffer++)-'0';
772 if (*buffer!='\0') {
773 debuga(_("Invalid cache miss size in file \"%s\"\n"),filename);
774 exit(EXIT_FAILURE);
775 }
776 item->oucache=number*sign;
777 }
778 return(0);
779 }
780
781 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)
782 {
783 FILE *fp_ou;
784 char wdirname[MAXLEN];
785
786 if (snprintf(wdirname,sizeof(wdirname),"%s/smartfilter.int_unsort",dirname)>=sizeof(wdirname)) {
787 debuga(_("Path too long: "));
788 debuga_more("%s/smartfilter.int_unsort\n",dirname);
789 exit(EXIT_FAILURE);
790 }
791
792 if((fp_ou=MY_FOPEN(wdirname,"a"))==NULL){
793 debuga(_("Cannot open file \"%s\": %s\n"),wdirname,strerror(errno));
794 exit(EXIT_FAILURE);
795 }
796
797 fprintf(fp_ou,"%s\t%s\t%s\t%s\t%s\t%s\n",user,data,hora,ip,url,smart);
798 fputs("</body>\n</html>\n",fp_tt);
799
800 if (fclose(fp_ou)==EOF) {
801 debuga(_("Write error in \"%s\": %s\n"),wdirname,strerror(errno));
802 exit(EXIT_FAILURE);
803 }
804
805 return;
806 }