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