X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=topuser.c;h=f272fa529afa9528fb03d8e42eeae2d46ba13e80;hb=ffc9b006b8358644c054c5e4c2929791efec7475;hp=2fa4c0578c70f58c206bb53de7c440c4d1b3ede6;hpb=d6f0349d3dc994a07fdc514433032f88e24c4588;p=thirdparty%2Fsarg.git diff --git a/topuser.c b/topuser.c index 2fa4c05..f272fa5 100644 --- a/topuser.c +++ b/topuser.c @@ -1,6 +1,6 @@ /* * SARG Squid Analysis Report Generator http://sarg.sourceforge.net - * 1998, 2012 + * 1998, 2015 * * SARG donations: * please look at http://sarg.sourceforge.net/donations.php @@ -43,12 +43,14 @@ static void set_total_users(int totuser) snprintf(tusr,sizeof(tusr),"%s/sarg-users",outdirname); if((fp_ou=fopen(tusr,"w"))==NULL) { - debuga(_("(topuser) Cannot open file %s: %s\n"),tusr,strerror(errno)); + debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),tusr,strerror(errno)); exit(EXIT_FAILURE); } fprintf(fp_ou,"%d\n",totuser); - if (fclose(fp_ou)==EOF) - debuga(_("Failed to close file %s - %s\n"),tusr,strerror(errno)); + if (fclose(fp_ou)==EOF) { + debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),tusr,strerror(errno)); + exit(EXIT_FAILURE); + } globstat.totuser=totuser; } @@ -82,16 +84,18 @@ void topuser(void) struct generalitemstruct item; struct userinfostruct *uinfo; + if (debugz>=LogLevel_Process) + debuga(__FILE__,__LINE__,_("Creating top users report...\n")); ntopuser = 0; snprintf(wger,sizeof(wger),"%s/sarg-general",outdirname); if((fp_in=fopen(wger,"r"))==NULL) { - debuga(_("(topuser) Cannot open file %s: %s\n"),wger,strerror(errno)); + debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),wger,strerror(errno)); exit(EXIT_FAILURE); } snprintf(top2,sizeof(top2),"%s/top.tmp",outdirname); if((fp_top2=fopen(top2,"w"))==NULL) { - debuga(_("(topuser) Cannot open file %s: %s\n"),top2,strerror(errno)); + debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),top2,strerror(errno)); exit(EXIT_FAILURE); } @@ -99,7 +103,7 @@ void topuser(void) totuser=0; if ((line=longline_create())==NULL) { - debuga(_("Not enough memory to read the file %s\n"),wger); + debuga(__FILE__,__LINE__,_("Not enough memory to read file \"%s\"\n"),wger); exit(EXIT_FAILURE); } @@ -136,7 +140,10 @@ void topuser(void) tnincache+=item.incache; tnoucache+=item.oucache; } - fclose(fp_in); + if (fclose(fp_in)==EOF) { + debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),wger,strerror(errno)); + exit(EXIT_FAILURE); + } longline_destroy(&line); if (olduser[0] != '\0') { @@ -152,12 +159,15 @@ void topuser(void) ttnincache+=tnincache; ttnoucache+=tnoucache; } - fclose(fp_top2); + if (fclose(fp_top2)==EOF) { + debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),top2,strerror(errno)); + exit(EXIT_FAILURE); + } #ifdef ENABLE_DOUBLE_CHECK_DATA if (ttnacc!=globstat.nacc || ttnbytes!=globstat.nbytes || ttnelap!=globstat.elap || ttnincache!=globstat.incache || ttnoucache!=globstat.oucache) { - debuga(_("Total statistics mismatch when reading %s to produce the top users\n"),wger); + debuga(__FILE__,__LINE__,_("Total statistics mismatch when reading \"%s\" to produce the top users\n"),wger); exit(EXIT_FAILURE); } #endif @@ -172,7 +182,7 @@ void topuser(void) sort_field=_("connect"); } else if((TopuserSort & TOPUSER_SORT_TIME) != 0) { sfield="-n -k 4,4"; - sort_field=_("time"); + sort_field=pgettext("duration","time"); } else { sort_field=_("bytes"); } @@ -187,29 +197,29 @@ void topuser(void) snprintf(top1,sizeof(top1),"%s/top",outdirname); if (snprintf(csort,sizeof(csort),"sort -T \"%s\" -t \"\t\" %s %s -o \"%s\" \"%s\"", tmp, order, sfield, top1, top2)>=sizeof(csort)) { - debuga(_("Sort command too long when sorting file \"%s\" to \"%s\"\n"),top2,top1); + debuga(__FILE__,__LINE__,_("Sort command too long when sorting file \"%s\" to \"%s\"\n"),top2,top1); exit(EXIT_FAILURE); } cstatus=system(csort); if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { - debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus)); - debuga(_("sort command: %s\n"),csort); + debuga(__FILE__,__LINE__,_("sort command return status %d\n"),WEXITSTATUS(cstatus)); + debuga(__FILE__,__LINE__,_("sort command: %s\n"),csort); exit(EXIT_FAILURE); } if((fp_top1=fopen(top1,"r"))==NULL) { - debuga(_("(topuser) Cannot open file %s: %s\n"),top1,strerror(errno)); + debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),top1,strerror(errno)); exit(EXIT_FAILURE); } if (!KeepTempLog && unlink(top2)) { - debuga(_("Cannot delete \"%s\": %s\n"),top2,strerror(errno)); + debuga(__FILE__,__LINE__,_("Cannot delete \"%s\": %s\n"),top2,strerror(errno)); exit(EXIT_FAILURE); } - snprintf(top3,sizeof(top3),"%s/index.html",outdirname); + snprintf(top3,sizeof(top3),"%s/"INDEX_HTML_FILE,outdirname); if((fp_top3=fopen(top3,"w"))==NULL) { - debuga(_("(topuser) Cannot open file %s: %s\n"),top3,strerror(errno)); + debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),top3,strerror(errno)); exit(EXIT_FAILURE); } @@ -247,8 +257,11 @@ void topuser(void) if ((ReportType & REPORT_TYPE_TOPUSERS) == 0) { fputs("\n\n",fp_top3); - fclose (fp_top3); - if (debugz) debugaz(_("No top users report because it is not configured in report_type\n")); + if (fclose (fp_top3)==EOF) { + debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),top3,strerror(errno)); + exit(EXIT_FAILURE); + } + if (debugz>=LogLevel_Process) debugaz(__FILE__,__LINE__,_("No top users report because it is not configured in report_type\n")); return; } @@ -269,6 +282,11 @@ void topuser(void) if (SortTableJs[0]) fputs(" sorttable_alpha",fp_top3); fprintf(fp_top3,"\">%s",_("USERID")); } + if((TopUserFields & TOPUSERFIELDS_USERIP) != 0) { + fputs("%s",_("USERIP")); + } if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0) fprintf(fp_top3,"%s",_("CONNECT")); if((TopUserFields & TOPUSERFIELDS_BYTES) != 0) @@ -282,7 +300,7 @@ void topuser(void) if((TopUserFields & TOPUSERFIELDS_MILISEC) != 0) fprintf(fp_top3,"%s",_("MILLISEC")); if((TopUserFields & TOPUSERFIELDS_PTIME) != 0) - fprintf(fp_top3,"%%%s",_("TIME")); + fprintf(fp_top3,"%%%s",pgettext("duration","TIME")); fputs("\n",fp_top3); @@ -291,34 +309,34 @@ void topuser(void) ntopuser = 0; if ((line=longline_create())==NULL) { - debuga(_("Not enough memory to read the downloaded files\n")); + debuga(__FILE__,__LINE__,_("Not enough memory to read file \"%s\"\n"),top1); exit(EXIT_FAILURE); } while((warea=longline_read(fp_top1,line))!=NULL) { getword_start(&gwarea,warea); if (getword(user,sizeof(user),&gwarea,'\t')<0) { - debuga(_("There is a broken user in file %s\n"),top1); + debuga(__FILE__,__LINE__,_("Invalid user in file \"%s\"\n"),top1); exit(EXIT_FAILURE); } if (getword_atoll(&nbytes,&gwarea,'\t')<0) { - debuga(_("There is a broken number of bytes in file %s\n"),top1); + debuga(__FILE__,__LINE__,_("Invalid number of bytes in file \"%s\"\n"),top1); exit(EXIT_FAILURE); } if (getword_atoll(&nacc,&gwarea,'\t')<0) { - debuga(_("There is a broken number of access in file %s\n"),top1); + debuga(__FILE__,__LINE__,_("Invalid number of accesses in file \"%s\"\n"),top1); exit(EXIT_FAILURE); } if (getword_atoll(&elap,&gwarea,'\t')<0) { - debuga(_("There is a broken elpased time in file %s\n"),top1); + debuga(__FILE__,__LINE__,_("Invalid elapsed time in file \"%s\"\n"),top1); exit(EXIT_FAILURE); } if (getword_atoll(&incac,&gwarea,'\t')<0) { - debuga(_("There is a broken in-cache size in file %s\n"),top1); + debuga(__FILE__,__LINE__,_("Invalid in-cache size in file \"%s\"\n"),top1); exit(EXIT_FAILURE); } if (getword_atoll(&oucac,&gwarea,'\n')<0) { - debuga(_("There is a broken out-of-cache size in file %s\n"),top1); + debuga(__FILE__,__LINE__,_("Invalid out-of-cache size in file \"%s\"\n"),top1); exit(EXIT_FAILURE); } if(nacc < 1) @@ -330,14 +348,11 @@ void topuser(void) uinfo=userinfo_find_from_id(user); if (!uinfo) { - debuga(_("Unknown user ID %s in file %s\n"),user,top1); + debuga(__FILE__,__LINE__,_("Unknown user ID %s in file \"%s\"\n"),user,top1); exit(EXIT_FAILURE); } uinfo->topuser=1; - report_day(uinfo); - greport_day(uinfo); - fputs("",fp_top3); posicao++; @@ -349,17 +364,14 @@ void topuser(void) fputs("",fp_top3); #ifdef HAVE_GD if(Graphs && GraphFont[0]!='\0') { + greport_day(uinfo); //fprintf(fp_top3,"\"G\" ",uinfo->filename,ImageFile,_("Graphic")); fprintf(fp_top3,"\"G\" ",uinfo->filename,ImageFile,_("Graphic")); } #endif + report_day(uinfo); fprintf(fp_top3,"\"T\"",uinfo->filename,uinfo->filename,ImageFile,_("date/time report")); - } else { - sprintf(val1,"%s/d%s.html",outdirname,uinfo->filename); - if (unlink(val1)) { - debuga(_("Cannot delete \"%s\": %s\n"),val1,strerror(errno)); - exit(EXIT_FAILURE); - } + day_deletefile(uinfo); } } if((TopUserFields & TOPUSERFIELDS_USERID) != 0) { @@ -368,6 +380,9 @@ void topuser(void) else fprintf(fp_top3,"%s",uinfo->filename,uinfo->filename,uinfo->label); } + if((TopUserFields & TOPUSERFIELDS_USERIP) != 0) { + fprintf(fp_top3,"%s",uinfo->ip); + } if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0) { fputs("%3.2lf%%%3.2lf%%",inperc,ouperc); #ifdef ENABLE_DOUBLE_CHECK_DATA if ((inperc!=0. || ouperc!=0.) && fabs(inperc+ouperc-100.)>=0.01) { - debuga(_("The total of the in-cache and cache-miss is not 100%% at position %d (user %s)\n"),posicao,uinfo->label); + debuga(__FILE__,__LINE__,_("The total of the in-cache and cache-miss is not 100%% at position %d (user %s)\n"),posicao,uinfo->label); } #endif } @@ -411,9 +426,12 @@ void topuser(void) topcount++; } - fclose(fp_top1); + if (fclose(fp_top1)==EOF) { + debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),top1,strerror(errno)); + exit(EXIT_FAILURE); + } if (!KeepTempLog && unlink(top1)) { - debuga(_("Cannot delete \"%s\": %s\n"),top1,strerror(errno)); + debuga(__FILE__,__LINE__,_("Cannot delete \"%s\": %s\n"),top1,strerror(errno)); exit(EXIT_FAILURE); } longline_destroy(&line); @@ -424,7 +442,10 @@ void topuser(void) fputs("",fp_top3); if((TopUserFields & TOPUSERFIELDS_DATE_TIME) !=0 && (ReportType & REPORT_TYPE_DATE_TIME) != 0 && !indexonly) fputs("",fp_top3); - fprintf(fp_top3,"%s",_("TOTAL")); + if((TopUserFields & TOPUSERFIELDS_USERIP) != 0) + fprintf(fp_top3,"%s",_("TOTAL")); + else + fprintf(fp_top3,"%s",_("TOTAL")); if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0) fprintf(fp_top3,"%s",fixnum(ttnacc,1)); @@ -439,7 +460,7 @@ void topuser(void) fprintf(fp_top3,"%3.2lf%%%3.2lf%%",inperc,ouperc); #ifdef ENABLE_DOUBLE_CHECK_DATA if (fabs(inperc+ouperc-100.)>=0.01) { - debuga(_("The total of the in-cache and cache-miss is not 100%%\n")); + debuga(__FILE__,__LINE__,_("The total of the in-cache and cache-miss is not 100%%\n")); } #endif } @@ -458,7 +479,10 @@ void topuser(void) fputs("",fp_top3); if((TopUserFields & TOPUSERFIELDS_DATE_TIME) !=0 && (ReportType & REPORT_TYPE_DATE_TIME) != 0 && !indexonly) fputs("",fp_top3); - fprintf(fp_top3,"%s",_("AVERAGE")); + if((TopUserFields & TOPUSERFIELDS_USERIP) != 0) + fprintf(fp_top3,"%s",_("AVERAGE")); + else + fprintf(fp_top3,"%s",_("AVERAGE")); if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0) fprintf(fp_top3,"%s",fixnum(ttnacc/totuser,1)); @@ -478,10 +502,11 @@ void topuser(void) } fputs("\n",fp_top3); - if (write_html_trailer(fp_top3)<0) - debuga(_("Write error in top user list %s\n"),top3); - if (fclose(fp_top3)==EOF) - debuga(_("Failed to close the top user list %s - %s\n"),top3,strerror(errno)); + write_html_trailer(fp_top3); + if (fclose(fp_top3)==EOF) { + debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),top3,strerror(errno)); + exit(EXIT_FAILURE); + } return; }