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