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