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