]> git.ipfire.org Git - thirdparty/sarg.git/blob - report.c
Append \n at the end of every debuga
[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(dirname, "%s%s", outdir, period);
87 vrfydir(period, addr, site, us, email);
88
89 if(debugz){
90 debugaz("dirname",dirname);
91 }
92
93 gperiod(dirname,period);
94
95 if(UserAgentLog[0] != '\0' && email[0] == '\0') useragent();
96
97 sprintf(wdirname,"%s/sarg-general",dirname);
98 if((fp_gen=MY_FOPEN(wdirname,"w"))==NULL){
99 fprintf(stderr, "SARG: (report) %s: %s\n",_("Cannot open file"),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 strcpy(wdirname,dirname);
147 maketmp(user,tmp,debug,indexonly);
148 maketmp_hour(user,tmp,indexonly);
149
150 ttopen=0;
151 oldurltt=NULL;
152 ourltt_size=0;
153 memset(oldaccdiatt,0,sizeof(oldaccdiatt));
154 memset(oldacchoratt,0,sizeof(oldacchoratt));
155 new_user=1;
156
157 if (longline_prepare(&line)<0) {
158 debuga(_("Not enough memory to read the downloaded files\n"));
159 exit(1);
160 }
161
162 while((buf=longline_read(fp_in,&line))!=NULL) {
163 getword_start(&gwarea,buf);
164 if (getword(accdia,sizeof(accdia),&gwarea,'\t')<0 || getword(acchora,sizeof(acchora),&gwarea,'\t')<0 ||
165 getword(accip,sizeof(accip),&gwarea,'\t')<0 ||
166 getword_ptr(buf,&accurl,&gwarea,'\t')<0 || getword_atoll(&accbytes,&gwarea,'\t')<0 ||
167 getword(acccode,sizeof(acccode),&gwarea,'\t')<0) {
168 debuga(_("There is a broken record or garbage in file %s\n"),tmp3);
169 exit(1);
170 }
171 if(strncmp(acccode,"TCP_DENIED/407",14) == 0) continue;
172 if (getword_atoll(&accelap,&gwarea,'\t')<0) {
173 debuga(_("There is a broken elapsed time in file %s\n"),tmp3);
174 exit(1);
175 }
176 if (getword_skip(20000,&gwarea,'"')<0 || getword(accsmart,sizeof(accsmart),&gwarea,'"')<0) {
177 debuga(_("There is a broken smart info in file %s\n"),tmp3);
178 exit(1);
179 }
180
181 if(accsmart[0] != '\0') {
182 smartfilter++;
183 strcpy(wdirname,dirname);
184 grava_SmartFilter(wdirname,uinfo->id,accip,accdia,acchora,accurl,accsmart);
185 }
186
187 if(Ip2Name) {
188 if(strcmp(accip,ipantes) != 0) {
189 strcpy(ipantes,accip);
190 ip2name(accip,sizeof(accip));
191 strcpy(nameantes,accip);
192 } else strcpy(accip,nameantes);
193 }
194
195 strcpy(wdirname,dirname);
196 gravatmp_hora(wdirname,uinfo,accdia,acchora,accelap,accbytes,indexonly);
197
198 if(iprel){
199 strcpy(wdirname,dirname);
200 gravaporuser(uinfo,wdirname,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(1);
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 strcpy(oldmsg,"OK");
227 if(strstr(oldacccode,"DENIED") != 0)
228 sprintf(oldmsg,"%s",_("DENIED"));
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 url_to_file(accurl,siteind,sizeof(siteind));
261 snprintf(arqtt,sizeof(arqtt),"%s/%s",dirname,uinfo->filename);
262 if(access(arqtt, R_OK) != 0)
263 my_mkdir(arqtt);
264 snprintf(arqtt,sizeof(arqtt),"%s/%s/tt%s-%s.html",dirname,uinfo->filename,uinfo->filename,siteind);
265 if ((fp_tt = fopen(arqtt, "w")) == 0) {
266 fprintf(stderr, "SARG: (report) %s: %s\n",_("Cannot open file"),arqtt);
267 exit(1);
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_l\">%s:&nbsp;%s</td></tr>\n",_("Period"),period);
281 fprintf(fp_tt,"<tr><td class=\"header_l\">%s:&nbsp;%s</td></tr>\n",_("User"),uinfo->label);
282 fprintf(fp_tt,"<tr><td class=\"header_l\">%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 fputs("<tr><td></td><td></td></tr>",fp_tt);
288 strncpy(tmp4,_("DATE/TIME"),4);
289 tmp4[4]='\0';
290 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);
291 }
292
293 fputs("<tr><td class=\"data\">",fp_tt);
294 output_html_string(fp_tt,accurl,100);
295 fprintf(fp_tt,"</td><td class=\"data\">%s</td><td class=\"data\">%s</td></tr>\n",accdia,acchora);
296
297 url_len=strlen(accurl);
298 if (!oldurltt || url_len>=ourltt_size) {
299 ourltt_size=url_len+1;
300 oldurltt=realloc(oldurltt,ourltt_size);
301 if (!oldurltt) {
302 debuga(_("Not enough memory to store the url\n"));
303 exit(1);
304 }
305 }
306 strcpy(oldurltt,accurl);
307 strcpy(oldaccdiatt,accdia);
308 strcpy(oldacchoratt,acchora);
309 }
310
311 strcpy(crc2,acccode);
312 str=strchr(crc2,'/');
313 if (str) *str='\0';
314 if(strstr(crc2,"MISS") != 0)
315 oucache+=accbytes;
316 else incache+=accbytes;
317
318 if(new_user) {
319 new_user=0;
320 strcpy(wdirname,dirname);
321 day_totalize(tmp,puinfo,indexonly);
322 }
323
324 puinfo=uinfo;
325 strcpy(oldacccode,acccode);
326 strcpy(oldaccip,accip);
327 if (!same_url) {
328 url_len=strlen(accurl);
329 if (url_len>=ourl_size) {
330 ourl_size=url_len+1;
331 oldurl=realloc(oldurl,ourl_size);
332 if (!oldurl) {
333 debuga(_("Not enough memory to store the url\n"));
334 exit(1);
335 }
336 }
337 strcpy(oldurl,accurl);
338 }
339 strcpy(oldaccdia,accdia);
340 strcpy(oldacchora,acchora);
341
342 }
343 fclose(fp_in);
344 longline_free(&line);
345 if (oldurltt) free(oldurltt);
346 unlink(tmp3);
347 }
348 closedir(dirp);
349
350 if (oldurl) {
351 if(strstr(oldacccode,"DENIED") != 0)
352 strcpy(oldmsg,_("DENIED"));
353 else
354 strcpy(oldmsg,"OK");
355 strcpy(wdirname,dirname);
356 gravatmpf(puinfo,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache);
357 strcpy(wdirname,dirname);
358 gravager(fp_gen,puinfo,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache);
359 free(oldurl);
360 }
361 fclose(fp_gen);
362 if (puinfo) day_totalize(tmp,puinfo,indexonly);
363
364 tmpsort();
365
366 strcpy(wdirname,dirname);
367 totalger(wdirname, debug, outdir);
368
369 if(email[0] == '\0') {
370 if((ReportType & REPORT_TYPE_DOWNLOADS) != 0) download_report();
371
372 if(DansGuardianConf[0] != '\0') {
373 strcpy(wdirname,dirname);
374 dansguardian_log();
375 }
376
377 strcpy(wdirname,dirname);
378 squidguard_log();
379
380 strcpy(wdirname,dirname);
381 topuser();
382
383 if((ReportType & REPORT_TYPE_TOPSITES) != 0) topsites();
384
385 if((ReportType & REPORT_TYPE_SITES_USERS) != 0) siteuser();
386 gen_denied_report();
387
388 strcpy(wdirname,dirname);
389 authfail_report();
390
391 if(smartfilter) smartfilter_report();
392
393 if(DansGuardianConf[0] != '\0') dansguardian_report();
394
395 squidguard_report();
396
397 if((ReportType & REPORT_TYPE_USERS_SITES) != 0) htmlrel();
398
399 make_index();
400
401 if(SuccessfulMsg) fprintf(stderr, "SARG: %s %s\n",_("Successful report generated on"),dirname);
402 } else {
403 strcpy(wdirname,dirname);
404 geramail(wdirname, debug, outdir, userip, email, TempDir);
405
406 if((strcmp(email,"stdout") != 0) && SuccessfulMsg)
407 fprintf(stderr, "SARG: %s %s\n",_("Successful report generated and sent to"),email);
408 }
409
410 if(indexonly) {
411 strcpy(wdirname,dirname);
412 index_only(wdirname, debug);
413 }
414
415 /*
416 2009-10-13(Frederic) This piece of code is never called so it is commented out for good.
417 if(strlen(email) < 0)
418 removetmp(dirname);
419 */
420
421 return;
422 }
423
424 static void maketmp(const char *user, const char *dirname, int debug, int indexonly)
425 {
426
427 FILE *fp_ou;
428
429 char wdirname[MAXLEN];
430
431 if(indexonly) return;
432 if((ReportType & REPORT_TYPE_USERS_SITES) == 0) return;
433
434 if(debug) debuga(_("Making file: %s/%s\n"),tmp,user);
435 if (snprintf(wdirname,sizeof(wdirname),"%s/%s.utmp",tmp,user)>=sizeof(wdirname)) {
436 debuga(_("Temporary file name too long: %s/%s.utmp\n"),tmp,user);
437 exit(1);
438 }
439
440 if((fp_ou=fopen(wdirname,"w"))==NULL){
441 fprintf(stderr, "SARG: (report) %s: %s\n",_("Cannot open file"),wdirname);
442 exit(1);
443 }
444
445 fclose(fp_ou);
446 return;
447 }
448
449
450 static void maketmp_hour(const char *user, const char *dirname, int indexonly)
451 {
452
453 FILE *fp_ou;
454
455 char wdirname[MAXLEN];
456
457 if(indexonly) return;
458 if((ReportType & REPORT_TYPE_USERS_SITES) == 0) return;
459
460 if (snprintf(wdirname,sizeof(wdirname),"%s/%s.htmp",tmp,user)>=sizeof(wdirname)) {
461 debuga(_("Temporary file name too long: %s/%s.htmp\n"),tmp,user);
462 exit(1);
463 }
464
465 if((fp_ou=fopen(wdirname,"w"))==NULL){
466 fprintf(stderr, "SARG: (report-1) %s: %s - %s\n",_("Cannot open file"),wdirname,strerror(errno));
467 exit(1);
468 }
469
470 fclose(fp_ou);
471 return;
472 }
473
474
475 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)
476 {
477 FILE *fp_ou;
478 char wdirname[MAXLEN];
479
480 if(indexonly) return;
481 if((ReportType & REPORT_TYPE_USERS_SITES) == 0) return;
482
483 if (snprintf(wdirname,sizeof(wdirname),"%s/%s.utmp",tmp,uinfo->filename)>=sizeof(wdirname)) {
484 debuga(_("Temporary file name too long: %s/%s.utmp\n"),tmp,uinfo->filename);
485 exit(1);
486 }
487
488 if((fp_ou=MY_FOPEN(wdirname,"a"))==NULL){
489 fprintf(stderr, "SARG: (report) %s: %s\n",_("Cannot open file"),wdirname);
490 exit(1);
491 }
492
493 fprintf(fp_ou,"%lld\t%lld\t%s\t%s\t%lld\t%lld\t%lld\n",nacc,nbytes,oldurl,oldmsg,nelap,incache,oucache);
494
495 fclose(fp_ou);
496 ttopen=0;
497
498 if(fp_tt) {
499 fputs("</table>\n</div>\n",fp_tt);
500 fputs("</body>\n</html>\n",fp_tt);
501 fclose(fp_tt);
502 fp_tt=NULL;
503 }
504
505 return;
506 }
507
508 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)
509 {
510 FILE *fp_ou;
511 char wdirname[MAXLEN];
512
513 if(indexonly || (ReportType & REPORT_TYPE_USERS_SITES) == 0) return;
514
515 if (snprintf(wdirname,sizeof(wdirname),"%s/%s.utmp",tmp,uinfo->filename)>=sizeof(wdirname)) {
516 debuga(_("Path too long %s/%s.utmp\n"),tmp,uinfo->filename);
517 exit(1);
518 }
519
520 if((fp_ou=MY_FOPEN(wdirname,"a"))==NULL){
521 fprintf(stderr, "SARG: (report) %s: %s\n",_("Cannot open file"),wdirname);
522 exit(1);
523 }
524
525 fprintf(fp_ou,"%lld\t%lld\t%s\t%s\t%lld\t%lld\t%lld\n",nacc,nbytes,oldurl,oldmsg,nelap,incache,oucache);
526
527 fclose(fp_ou);
528 ttopen=0;
529
530 if(fp_tt) {
531 fputs("</table>\n",fp_tt);
532 fputs("</body>\n</html>\n",fp_tt);
533 fclose(fp_tt);
534 fp_tt=NULL;
535 }
536
537 return;
538 }
539
540
541 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)
542 {
543
544 FILE *fp_ou;
545 char wdirname[MAXLEN];
546
547 if(indexonly || ((ReportType & REPORT_TYPE_USERS_SITES) == 0)) return;
548
549 if (snprintf(wdirname,sizeof(wdirname),"%s/%s.htmp",tmp,uinfo->filename)>=sizeof(wdirname)) {
550 debuga(_("Path too long %s/%s.htmp\n"),tmp,uinfo->filename);
551 exit(1);
552 }
553
554 if((fp_ou=MY_FOPEN(wdirname,"a"))==NULL){
555 debuga(_("(report-2) Cannot open file: %s - %s\n"),wdirname,strerror(errno));
556 exit(1);
557 }
558
559 if(strcmp(datetimeby,"bytes") == 0) fprintf(fp_ou,"%s\t%s\t%lld\n",data,hora,bytes);
560 else fprintf(fp_ou,"%s\t%s\t%lld\n",data,hora,elap);
561
562 fclose(fp_ou);
563
564 return;
565 }
566
567
568 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)
569 {
570
571 FILE *fp_ou;
572 char wdirname[MAXLEN];
573
574 if(indexonly || ((ReportType & REPORT_TYPE_USERS_SITES) == 0)) return;
575
576 if (snprintf(wdirname,sizeof(wdirname),"%s/%s.ip",tmp,uinfo->filename)>=sizeof(wdirname)) {
577 debuga(_("Path too long %s/%s.ip\n"),tmp,uinfo->filename);
578 exit(1);
579 }
580
581 if((fp_ou=MY_FOPEN(wdirname,"a"))==NULL){
582 fprintf(stderr, "SARG: (report) %s: %s\n",_("Cannot open file"),wdirname);
583 exit(1);
584 }
585
586 fprintf(fp_ou,"%s\t%s\t%s\t%s\t%lld\t%lld\n",ip,url,data,hora,tam,elap);
587
588 fclose(fp_ou);
589
590 return;
591
592 }
593
594
595 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)
596 {
597 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);
598 return;
599 }
600
601 int ger_read(char *buffer,struct generalitemstruct *item,const char *filename)
602 {
603 int i;
604 int sign;
605 long long int number;
606
607 if (strncmp(buffer,"TOTAL\t",6)==0) {
608 item->total=1;
609 buffer+=6;
610
611 sign=+1;
612 if (*buffer == '-') {
613 buffer++;
614 sign=-1;
615 } else if (*buffer == '+') {
616 buffer++;
617 }
618 number=0LL;
619 while (isdigit(*buffer))
620 number=(number * 10) + (*buffer++)-'0';
621 if (*buffer!='\t') {
622 debuga(_("Invalid total number of accesses in %s\n"),filename);
623 exit(1);
624 }
625 buffer++;
626 item->nacc=number*sign;
627
628 sign=+1;
629 if (*buffer == '-') {
630 buffer++;
631 sign=-1;
632 } else if (*buffer == '+') {
633 buffer++;
634 }
635 number=0LL;
636 while (isdigit(*buffer))
637 number=(number * 10) + (*buffer++)-'0';
638 if (*buffer!='\t') {
639 debuga(_("Invalid total size in %s\n"),filename);
640 exit(1);
641 }
642 buffer++;
643 item->nbytes=number*sign;
644
645 sign=+1;
646 if (*buffer == '-') {
647 buffer++;
648 sign=-1;
649 } else if (*buffer == '+') {
650 buffer++;
651 }
652 number=0LL;
653 while (isdigit(*buffer))
654 number=(number * 10) + (*buffer++)-'0';
655 if (*buffer!='\t') {
656 debuga(_("Invalid total elapsed time in %s\n"),filename);
657 exit(1);
658 }
659 buffer++;
660 item->nelap=number*sign;
661
662 sign=+1;
663 if (*buffer == '-') {
664 buffer++;
665 sign=-1;
666 } else if (*buffer == '+') {
667 buffer++;
668 }
669 number=0LL;
670 while (isdigit(*buffer))
671 number=(number * 10) + (*buffer++)-'0';
672 if (*buffer!='\t') {
673 debuga(_("Invalid total cache hit in %s\n"),filename);
674 exit(1);
675 }
676 buffer++;
677 item->incache=number*sign;
678
679 sign=+1;
680 if (*buffer == '-') {
681 buffer++;
682 sign=-1;
683 } else if (*buffer == '+') {
684 buffer++;
685 }
686 number=0LL;
687 while (isdigit(*buffer))
688 number=(number * 10) + (*buffer++)-'0';
689 if (*buffer!='\0') {
690 debuga(_("Invalid total cache miss in %s\n"),filename);
691 exit(1);
692 }
693 item->oucache=number*sign;
694 } else {
695 item->total=0;
696
697 item->user=buffer;
698 for (i=0 ; i<MAX_USER_LEN-1 && (unsigned char)*buffer>=' ' ; i++) buffer++;
699 if (*buffer!='\t') {
700 debuga(_("User name too long or invalid in %s\n"),filename);
701 exit(1);
702 }
703 *buffer++='\0';
704
705 sign=+1;
706 if (*buffer == '-') {
707 buffer++;
708 sign=-1;
709 } else if (*buffer == '+') {
710 buffer++;
711 }
712 number=0LL;
713 while (isdigit(*buffer))
714 number=(number * 10) + (*buffer++)-'0';
715 if (*buffer!='\t') {
716 debuga(_("Invalid number of accesses in %s\n"),filename);
717 exit(1);
718 }
719 buffer++;
720 item->nacc=number*sign;
721
722 sign=+1;
723 if (*buffer == '-') {
724 buffer++;
725 sign=-1;
726 } else if (*buffer == '+') {
727 buffer++;
728 }
729 number=0LL;
730 while (isdigit(*buffer))
731 number=(number * 10) + (*buffer++)-'0';
732 if (*buffer!='\t') {
733 debuga(_("Invalid number of bytes in %s\n"),filename);
734 exit(1);
735 }
736 buffer++;
737 item->nbytes=number*sign;
738
739 item->url=buffer;
740 while ((unsigned char)*buffer>=' ') buffer++;
741 if (*buffer!='\t') {
742 debuga(_("URL too long or invalid in %s\n"),filename);
743 exit(1);
744 }
745 *buffer++='\0';
746
747 item->ip=buffer;
748 for (i=0 ; i<MAX_IP_LEN-1 && (unsigned char)*buffer>=' ' ; i++) buffer++;
749 if (*buffer!='\t') {
750 debuga(_("IP address too long or invalid in %s\n"),filename);
751 exit(1);
752 }
753 *buffer++='\0';
754
755 item->time=buffer;
756 for (i=0 ; i<MAX_DATETIME_LEN-1 && (unsigned char)*buffer>=' ' ; i++) buffer++;
757 if (*buffer!='\t') {
758 debuga(_("Time too long or invalid in %s\n"),filename);
759 exit(1);
760 }
761 *buffer++='\0';
762
763 item->date=buffer;
764 for (i=0 ; i<MAX_DATETIME_LEN-1 && (unsigned char)*buffer>=' ' ; i++) buffer++;
765 if (*buffer!='\t') {
766 debuga(_("Date too long or invalid in %s\n"),filename);
767 exit(1);
768 }
769 *buffer++='\0';
770
771 sign=+1;
772 if (*buffer == '-') {
773 buffer++;
774 sign=-1;
775 } else if (*buffer == '+') {
776 buffer++;
777 }
778 number=0LL;
779 while (isdigit(*buffer))
780 number=(number * 10) + (*buffer++)-'0';
781 if (*buffer!='\t') {
782 debuga(_("Invalid elapsed time in %s\n"),filename);
783 exit(1);
784 }
785 buffer++;
786 item->nelap=number*sign;
787
788 sign=+1;
789 if (*buffer == '-') {
790 buffer++;
791 sign=-1;
792 } else if (*buffer == '+') {
793 buffer++;
794 }
795 number=0LL;
796 while (isdigit(*buffer))
797 number=(number * 10) + (*buffer++)-'0';
798 if (*buffer!='\t') {
799 debuga(_("Invalid cache hit size in %s\n"),filename);
800 exit(1);
801 }
802 buffer++;
803 item->incache=number*sign;
804
805 sign=+1;
806 if (*buffer == '-') {
807 buffer++;
808 sign=-1;
809 } else if (*buffer == '+') {
810 buffer++;
811 }
812 number=0LL;
813 while (isdigit(*buffer))
814 number=(number * 10) + (*buffer++)-'0';
815 if (*buffer!='\0') {
816 debuga(_("Invalid cache miss size in %s\n"),filename);
817 exit(1);
818 }
819 item->oucache=number*sign;
820 }
821 return(0);
822 }
823
824 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)
825 {
826
827 FILE *fp_ou;
828 char wdirname[MAXLEN];
829
830 sprintf(wdirname,"%s/smartfilter.unsort",dirname);
831
832 if((fp_ou=MY_FOPEN(wdirname,"a"))==NULL){
833 fprintf(stderr, "SARG: (report) %s: %s\n",_("Cannot open file"),wdirname);
834 exit(1);
835 }
836
837 fprintf(fp_ou,"%s\t%s\t%s\t%s\t%s\t%s\n",user,data,hora,ip,url,smart);
838 fputs("</body>\n</html>\n",fp_tt);
839
840 fclose(fp_ou);
841
842 return;
843
844 }