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