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