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