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