/*
* SARG Squid Analysis Report Generator http://sarg.sourceforge.net
- * 1998, 2013
+ * 1998, 2015
*
* SARG donations:
* please look at http://sarg.sourceforge.net/donations.php
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(_("Write error in %s: %s\n"),tusr,strerror(errno));
+ debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),tusr,strerror(errno));
exit(EXIT_FAILURE);
}
globstat.totuser=totuser;
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);
}
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);
}
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') {
ttnoucache+=tnoucache;
}
if (fclose(fp_top2)==EOF) {
- debuga(_("Write error in %s: %s\n"),top2,strerror(errno));
+ 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
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_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);
}
if ((ReportType & REPORT_TYPE_TOPUSERS) == 0) {
fputs("</body>\n</html>\n",fp_top3);
if (fclose (fp_top3)==EOF) {
- debuga(_("Write error in %s: %s\n"),top3,strerror(errno));
+ debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),top3,strerror(errno));
exit(EXIT_FAILURE);
}
- if (debugz) debugaz(_("No top users report because it is not configured in report_type\n"));
+ if (debugz>=LogLevel_Process) debugaz(__FILE__,__LINE__,_("No top users report because it is not configured in report_type\n"));
return;
}
if (SortTableJs[0]) fputs(" sorttable_alpha",fp_top3);
fprintf(fp_top3,"\">%s</th>",_("USERID"));
}
+ if((TopUserFields & TOPUSERFIELDS_USERIP) != 0) {
+ fputs("<th class=\"header_l",fp_top3);
+ if (SortTableJs[0]) fputs(" sorttable_alpha",fp_top3);
+ fprintf(fp_top3,"\">%s</th>",_("USERIP"));
+ }
if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0)
fprintf(fp_top3,"<th class=\"header_l\">%s</th>",_("CONNECT"));
if((TopUserFields & TOPUSERFIELDS_BYTES) != 0)
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)
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;
else
fprintf(fp_top3,"<td class=\"data2\"><a href=\"%s/%s.html\">%s</a></td>",uinfo->filename,uinfo->filename,uinfo->label);
}
+ if((TopUserFields & TOPUSERFIELDS_USERIP) != 0) {
+ fprintf(fp_top3,"<td class=\"data2\">%s</td>",uinfo->ip);
+ }
if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0) {
fputs("<td class=\"data\"",fp_top3);
if (SortTableJs[0]) fprintf(fp_top3," sorttable_customkey=\"%"PRId64"\"",(int64_t)nacc);
fprintf(fp_top3,"<td class=\"data\">%3.2lf%%</td><td class=\"data\">%3.2lf%%</td>",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
}
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);
fputs("<td></td>",fp_top3);
if((TopUserFields & TOPUSERFIELDS_DATE_TIME) !=0 && (ReportType & REPORT_TYPE_DATE_TIME) != 0 && !indexonly)
fputs("<td></td>",fp_top3);
- fprintf(fp_top3,"<th class=\"header_l\">%s</th>",_("TOTAL"));
+ if((TopUserFields & TOPUSERFIELDS_USERIP) != 0)
+ fprintf(fp_top3,"<th class=\"header_l\" colspan=\"2\">%s</th>",_("TOTAL"));
+ else
+ fprintf(fp_top3,"<th class=\"header_l\">%s</th>",_("TOTAL"));
if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0)
fprintf(fp_top3,"<th class=\"header_r\">%s</th>",fixnum(ttnacc,1));
fprintf(fp_top3,"<th class=\"header_r\">%3.2lf%%</th><th class=\"header_r\">%3.2lf%%</th>",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
}
fputs("<td></td>",fp_top3);
if((TopUserFields & TOPUSERFIELDS_DATE_TIME) !=0 && (ReportType & REPORT_TYPE_DATE_TIME) != 0 && !indexonly)
fputs("<td></td>",fp_top3);
- fprintf(fp_top3,"<th class=\"header_l\">%s</th>",_("AVERAGE"));
+ if((TopUserFields & TOPUSERFIELDS_USERIP) != 0)
+ fprintf(fp_top3,"<th class=\"header_l\" colspan=\"2\">%s</th>",_("AVERAGE"));
+ else
+ fprintf(fp_top3,"<th class=\"header_l\">%s</th>",_("AVERAGE"));
if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0)
fprintf(fp_top3,"<th class=\"header_r\">%s</th>",fixnum(ttnacc/totuser,1));
}
fputs("</table></div>\n",fp_top3);
- if (write_html_trailer(fp_top3)<0)
- debuga(_("Write error in top user list %s\n"),top3);
+ write_html_trailer(fp_top3);
if (fclose(fp_top3)==EOF) {
- debuga(_("Write error in %s: %s\n"),top3,strerror(errno));
+ debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),top3,strerror(errno));
exit(EXIT_FAILURE);
}