/*
* SARG Squid Analysis Report Generator http://sarg.sourceforge.net
- * 1998, 2013
+ * 1998, 2015
*
* SARG donations:
* please look at http://sarg.sourceforge.net/donations.php
void denied_open(void)
{
if ((ReportType & REPORT_TYPE_DENIED) == 0) {
- if (debugz>=LogLevel_Process) debugaz(_("Denied report not produced as it is not requested\n"));
+ if (debugz>=LogLevel_Process) debugaz(__FILE__,__LINE__,_("Denied report not produced as it is not requested\n"));
return;
}
if (Privacy) {
- if (debugz>=LogLevel_Process) debugaz(_("Denied report not produced because privacy option is active\n"));
+ if (debugz>=LogLevel_Process) debugaz(__FILE__,__LINE__,_("Denied report not produced because privacy option is active\n"));
return;
}
snprintf(denied_unsort,sizeof(denied_unsort),"%s/denied.int_unsort",tmp);
if ((fp_denied=MY_FOPEN(denied_unsort,"w"))==NULL) {
- debuga(_("(log) Cannot open file %s: %s\n"),denied_unsort,strerror(errno));
+ debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),denied_unsort,strerror(errno));
exit(EXIT_FAILURE);
}
return;
{
if (fp_denied) {
if (fclose(fp_denied)==EOF) {
- debuga(_("Write error in %s: %s\n"),denied_unsort,strerror(errno));
+ debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),denied_unsort,strerror(errno));
exit(EXIT_FAILURE);
}
fp_denied=NULL;
if (!denied_exists) {
if (!KeepTempLog && denied_unsort[0]!='\0' && unlink(denied_unsort))
- debuga(_("Cannot delete \"%s\": %s\n"),denied_unsort,strerror(errno));
+ debuga(__FILE__,__LINE__,_("Cannot delete \"%s\": %s\n"),denied_unsort,strerror(errno));
denied_unsort[0]='\0';
- if (debugz>=LogLevel_Process) debugaz(_("Denied report not produced because it is empty\n"));
+ if (debugz>=LogLevel_Process) debugaz(__FILE__,__LINE__,_("Denied report not produced because it is empty\n"));
return;
}
if (debugz>=LogLevel_Process)
- debuga(_("Creating denied accesses report...\n"));
+ debuga(__FILE__,__LINE__,_("Creating denied accesses report...\n"));
if (snprintf(denied_sort,sizeof(denied_sort),"%s/denied.int_log",tmp)>=sizeof(denied_sort)) {
- debuga(_("Temporary directory path too long to sort the denied accesses\n"));
+ debuga(__FILE__,__LINE__,_("Temporary directory path too long to sort the denied accesses\n"));
exit(EXIT_FAILURE);
}
if (snprintf(csort,sizeof(csort),"sort -T \"%s\" -t \"\t\" -k 3,3 -k 5,5 -o \"%s\" \"%s\"",tmp,denied_sort,denied_unsort)>=sizeof(csort)) {
- debuga(_("Sort command too long when sorting file \"%s\" to \"%s\"\n"),denied_unsort,denied_sort);
+ debuga(__FILE__,__LINE__,_("Sort command too long when sorting file \"%s\" to \"%s\"\n"),denied_unsort,denied_sort);
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 (unlink(denied_unsort)) {
- debuga(_("Cannot delete %s - %s\n"),denied_unsort,strerror(errno));
+ debuga(__FILE__,__LINE__,_("Cannot delete \"%s\": %s\n"),denied_unsort,strerror(errno));
exit(EXIT_FAILURE);
}
denied_unsort[0]='\0';
sprintf(report,"%s/denied.html",outdirname);
if((fp_in=MY_FOPEN(denied_sort,"r"))==NULL) {
- debuga(_("(denied) Cannot open log file %s: %s\n"),denied_sort,strerror(errno));
+ debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),denied_sort,strerror(errno));
exit(EXIT_FAILURE);
}
if((fp_ou=MY_FOPEN(report,"w"))==NULL) {
- debuga(_("(denied) Cannot open log file %s: %s\n"),report,strerror(errno));
+ debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),report,strerror(errno));
exit(EXIT_FAILURE);
}
fprintf(fp_ou,"<tr><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th></tr>\n",_("USERID"),_("IP/NAME"),_("DATE/TIME"),_("ACCESSED SITE"));
if ((line=longline_create())==NULL) {
- debuga(_("Not enough memory to read the denied accesses\n"));
+ debuga(__FILE__,__LINE__,_("Not enough memory to read file \"%s\"\n"),denied_sort);
exit(EXIT_FAILURE);
}
getword_start(&gwarea,buf);
if (getword(data,sizeof(data),&gwarea,'\t')<0 || getword(hora,sizeof(hora),&gwarea,'\t')<0 ||
getword(user,sizeof(user),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0) {
- debuga(_("There is a broken record or garbage in file %s\n"),denied_sort);
+ debuga(__FILE__,__LINE__,_("Invalid record in file \"%s\"\n"),denied_sort);
exit(EXIT_FAILURE);
}
if (getword_ptr(buf,&url,&gwarea,'\t')<0) {
- debuga(_("There is a broken url in file %s\n"),denied_sort);
+ debuga(__FILE__,__LINE__,_("Invalid url in file \"%s\"\n"),denied_sort);
exit(EXIT_FAILURE);
}
if (sscanf(data,"%d/%d/%d",&day,&month,&year)!=3) continue;
uinfo=userinfo_find_from_id(user);
if (!uinfo) {
- debuga(_("Unknown user ID %s in file %s\n"),user,denied_sort);
+ debuga(__FILE__,__LINE__,_("Unknown user ID %s in file \"%s\"\n"),user,denied_sort);
exit(EXIT_FAILURE);
}
output_html_link(fp_ou,url,100);
fputs("</td></tr>\n",fp_ou);
}
- fclose(fp_in);
+ if (fclose(fp_in)==EOF) {
+ debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),denied_sort,strerror(errno));
+ exit(EXIT_FAILURE);
+ }
longline_destroy(&line);
if(count>DeniedReportLimit && DeniedReportLimit>0)
show_ignored_denied(fp_ou,count-DeniedReportLimit);
fputs("</table></div>\n",fp_ou);
- if (write_html_trailer(fp_ou)<0)
- debuga(_("Write error in file %s\n"),report);
+ write_html_trailer(fp_ou);
if (fclose(fp_ou)==EOF) {
- debuga(_("Write error in %s: %s\n"),report,strerror(errno));
+ debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),report,strerror(errno));
exit(EXIT_FAILURE);
}
if (!KeepTempLog && unlink(denied_sort)==-1)
- debuga(_("Cannot delete \"%s\": %s\n"),denied_sort,strerror(errno));
+ debuga(__FILE__,__LINE__,_("Cannot delete \"%s\": %s\n"),denied_sort,strerror(errno));
return;
}
{
if (fp_denied){
if (fclose(fp_denied)==EOF) {
- debuga(_("Write error in %s: %s\n"),denied_unsort,strerror(errno));
+ debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),denied_unsort,strerror(errno));
exit(EXIT_FAILURE);
}
fp_denied=NULL;
}
if (!KeepTempLog && denied_unsort[0]) {
if (unlink(denied_unsort)==-1)
- debuga(_("Failed to delete %s: %s\n"),denied_unsort,strerror(errno));
+ debuga(__FILE__,__LINE__,_("Failed to delete \"%s\": %s\n"),denied_unsort,strerror(errno));
}
}