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