/*
* SARG Squid Analysis Report Generator http://sarg.sourceforge.net
- * 1998, 2013
+ * 1998, 2015
*
* SARG donations:
* please look at http://sarg.sourceforge.net/donations.php
getword_start(&gwarea1,RedirectorLogFormat);
leks[0]='\0';
if (getword(leks,sizeof(leks),&gwarea1,'#')<0) {
- debuga(_("Invalid \"redirector_log_format\" option in your sarg.conf (too many characters before first tag)\n"));
+ debuga(__FILE__,__LINE__,_("Invalid \"redirector_log_format\" option in your sarg.conf (too many characters before first tag)\n"));
exit(EXIT_FAILURE);
}
year=0;
full_url[0]='\0';
while(strcmp(leks,"end") != 0) {
if (getword(leks,sizeof(leks),&gwarea1,'#')<0) {
- debuga(_("Invalid \"redirector_log_format\" option in your sarg.conf (missing # at end of tag)\n"));
+ debuga(__FILE__,__LINE__,_("Invalid \"redirector_log_format\" option in your sarg.conf (missing # at end of tag)\n"));
exit(EXIT_FAILURE);
}
if (getword(sep,sizeof(sep),&gwarea1,'#')<0) {
- debuga(_("Invalid \"redirector_log_format\" option in your sarg.conf (too many characters in column separator)\n"));
+ debuga(__FILE__,__LINE__,_("Invalid \"redirector_log_format\" option in your sarg.conf (too many characters in column separator)\n"));
exit(EXIT_FAILURE);
}
if(strcmp(leks,"end") != 0) {
if (getword_limit(res,sizeof(res),&gwarea,sep[0])<0) {
- debuga(_("Parsing of tag \"%s\" in redirector log %s returned no result\n"),leks,wentp);
+ debuga(__FILE__,__LINE__,_("Parsing of tag \"%s\" in redirector log \"%s\" returned no result\n"),leks,wentp);
RedirectorErrors++;
return;
}
day=atoi(res);
} else if(strcmp(leks,"hour") == 0) {
if (strlen(res)>=sizeof(hour)) {
- debuga(_("Hour string too long in redirector log file %s\n"),wentp);
+ debuga(__FILE__,__LINE__,_("Hour string too long in redirector log file \"%s\"\n"),wentp);
RedirectorErrors++;
return;
}
strcpy(hour,res);
} else if(strcmp(leks,"source") == 0) {
if (strlen(res)>=sizeof(source)) {
- debuga(_("Banning source name too long in redirector log file %s\n"),wentp);
+ debuga(__FILE__,__LINE__,_("Banning source name too long in redirector log file \"%s\"\n"),wentp);
RedirectorErrors++;
return;
}
strcpy(source,res);
} else if(strcmp(leks,"list") == 0) {
if (strlen(res)>=sizeof(list)) {
- debuga(_("Banning list name too long in redirector log file %s\n"),wentp);
+ debuga(__FILE__,__LINE__,_("Banning list name too long in redirector log file \"%s\"\n"),wentp);
RedirectorErrors++;
return;
}
strcpy(list,res);
} else if(strcmp(leks,"ip") == 0) {
if (strlen(res)>=sizeof(ip)) {
- debuga(_("IP address too long in redirector log file %s\n"),wentp);
+ debuga(__FILE__,__LINE__,_("IP address too long in redirector log file \"%s\"\n"),wentp);
RedirectorErrors++;
return;
}
strcpy(ip,res);
} else if(strcmp(leks,"user") == 0) {
if (strlen(res)>=sizeof(user)) {
- debuga(_("User ID too long in redirector log file %s\n"),wentp);
+ debuga(__FILE__,__LINE__,_("User ID too long in redirector log file \"%s\"\n"),wentp);
RedirectorErrors++;
return;
}
} else {
if (getword_atoll(&lyear,&gwarea,'-')<0 || getword_atoll(&lmon,&gwarea,'-')<0 ||
getword_atoll(&lday,&gwarea,' ')<0) {
- debuga(_("Invalid date found in file %s\n"),wentp);
+ debuga(__FILE__,__LINE__,_("Invalid date in file \"%s\"\n"),wentp);
RedirectorErrors++;
return;
}
mon=(int)lmon;
day=(int)lday;
if (getword(hour,sizeof(hour),&gwarea,' ')<0) {
- debuga(_("Invalid time found in file %s\n"),wentp);
+ debuga(__FILE__,__LINE__,_("Invalid time in file \"%s\"\n"),wentp);
RedirectorErrors++;
return;
}
if (getword_skip(MAXLEN,&gwarea,'(')<0 || getword(source,sizeof(source),&gwarea,'/')<0) {
- debuga(_("Invalid redirected source in file %s\n"),wentp);
+ debuga(__FILE__,__LINE__,_("Invalid redirected source in file \"%s\"\n"),wentp);
RedirectorErrors++;
return;
}
if (getword(list,sizeof(list),&gwarea,'/')<0) {
- debuga(_("Invalid redirected list in file %s\n"),wentp);
+ debuga(__FILE__,__LINE__,_("Invalid redirected list in file \"%s\"\n"),wentp);
RedirectorErrors++;
return;
}
if (getword_skip(MAXLEN,&gwarea,' ')<0 || getword_limit(full_url,sizeof(full_url),&gwarea,' ')<0) {
- debuga(_("Invalid URL in file %s\n"),wentp);
+ debuga(__FILE__,__LINE__,_("Invalid url in file \"%s\"\n"),wentp);
RedirectorErrors++;
return;
}
if (getword(ip,sizeof(ip),&gwarea,'/')<0) {
- debuga(_("Invalid source IP in file %s\n"),wentp);
+ debuga(__FILE__,__LINE__,_("Invalid source IP in file \"%s\"\n"),wentp);
RedirectorErrors++;
return;
}
if (getword_skip(MAXLEN,&gwarea,' ')<0 || getword(user,sizeof(user),&gwarea,' ')<0) {
- debuga(_("Invalid user in file %s\n"),wentp);
+ debuga(__FILE__,__LINE__,_("Invalid user in file \"%s\"\n"),wentp);
RedirectorErrors++;
return;
}
static void read_log(const char *wentp, FILE *fp_ou,int dfrom,int duntil)
{
- FILE *fp_in = NULL;
+ FileObject *fp_in = NULL;
char *buf;
int i;
longline line;
if(debug) {
- debuga(_("Reading redirector log file %s\n"),wentp);
+ debuga(__FILE__,__LINE__,_("Reading redirector log file \"%s\"\n"),wentp);
}
/* With squidGuard, you can log groups in only one log file.
nfiles_done++;
files_done = realloc(files_done, nfiles_done*sizeof(char *));
if (!files_done) {
- debuga(_("Not enough memory to store the name of the new redirector log to be read - %s\n"),strerror(errno));
+ debuga(__FILE__,__LINE__,_("Not enough memory to store the name of the new redirector log to be read - %s\n"),strerror(errno));
exit(EXIT_FAILURE);
}
files_done[nfiles_done-1] = strdup(wentp);
if (!files_done[nfiles_done-1]) {
- debuga(_("Not enough memory to store the name of the new redirector log to be read - %s\n"),strerror(errno));
+ debuga(__FILE__,__LINE__,_("Not enough memory to store the name of the new redirector log to be read - %s\n"),strerror(errno));
exit(EXIT_FAILURE);
}
- if ((fp_in=fopen(wentp,"r"))==NULL) {
- debuga(_("(squidguard) Cannot open log file %s: %s\n"),wentp,strerror(errno));
+ if ((fp_in=FileObject_Open(wentp))==NULL) {
+ debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),wentp,FileObject_GetLastOpenError());
exit(EXIT_FAILURE);
}
if ((line=longline_create())==NULL) {
- debuga(_("Not enough memory to read the redirector log\n"));
+ debuga(__FILE__,__LINE__,_("Not enough memory to read file \"%s\"\n"),wentp);
exit(EXIT_FAILURE);
}
while ((buf=longline_read(fp_in,line)) != NULL) {
parse_log(fp_ou,buf);
}
- fclose(fp_in);
+ if (FileObject_Close(fp_in)) {
+ debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),wentp,FileObject_GetLastCloseError());
+ exit(EXIT_FAILURE);
+ }
longline_destroy(&line);
return;
}
str2 = user;
if(SquidGuardConf[0] == '\0' && NRedirectorLogs == 0) {
- if (debugz>=LogLevel_Process) debugaz(_("No redirector logs provided to produce that kind of report\n"));
+ if (debugz>=LogLevel_Process) debugaz(__FILE__,__LINE__,_("No redirector logs provided to produce that kind of report\n"));
return;
}
snprintf(guard_in,sizeof(guard_in),"%s/redirector.int_unsort",tmp);
if((fp_ou=fopen(guard_in,"w"))==NULL) {
- debuga(_("(squidguard) Cannot open log file %s: %s\n"),guard_in,strerror(errno));
+ debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),guard_in,strerror(errno));
exit(EXIT_FAILURE);
}
read_log(RedirectorLogs[i],fp_ou,dfrom,duntil);
} else {
if(access(SquidGuardConf, R_OK) != 0) {
- debuga(_("Cannot open squidGuard config file: %s\n"),SquidGuardConf);
+ debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),SquidGuardConf,strerror(errno));
exit(EXIT_FAILURE);
}
if((fp_guard=fopen(SquidGuardConf,"r"))==NULL) {
- debuga(_("(squidguard) Cannot open log file %s: %s\n"),SquidGuardConf,strerror(errno));
+ debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),SquidGuardConf,strerror(errno));
exit(EXIT_FAILURE);
}
read_log(wentp,fp_ou,dfrom,duntil);
}
}
+ if (fclose(fp_guard)==EOF) {
+ debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),SquidGuardConf,strerror(errno));
+ exit(EXIT_FAILURE);
+ }
}
- if (fp_guard) fclose(fp_guard);
if (fp_ou && fclose(fp_ou)==EOF) {
- debuga(_("Write error in %s: %s\n"),guard_in,strerror(errno));
+ debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),guard_in,strerror(errno));
exit(EXIT_FAILURE);
}
if (redirector_count) {
snprintf(redirector_sorted,sizeof(redirector_sorted),"%s/redirector.int_log",tmp);
if(debug) {
- debuga(_("Sorting file: %s\n"),redirector_sorted);
+ debuga(__FILE__,__LINE__,_("Sorting file \"%s\"\n"),redirector_sorted);
}
if (snprintf(tmp6,sizeof(tmp6),"sort -t \"\t\" -k 1,1 -k 2,2 -k 4,4 \"%s\" -o \"%s\"",guard_in, redirector_sorted)>=sizeof(tmp6)) {
- debuga(_("Sort command too long when sorting file \"%s\" to \"%s\"\n"),guard_in,redirector_sorted);
+ debuga(__FILE__,__LINE__,_("Sort command too long when sorting file \"%s\" to \"%s\"\n"),guard_in,redirector_sorted);
exit(EXIT_FAILURE);
}
cstatus=system(tmp6);
if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
- debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus));
- debuga(_("sort command: %s\n"),tmp6);
+ debuga(__FILE__,__LINE__,_("sort command return status %d\n"),WEXITSTATUS(cstatus));
+ debuga(__FILE__,__LINE__,_("sort command: %s\n"),tmp6);
exit(EXIT_FAILURE);
}
}
if (!KeepTempLog && unlink(guard_in)) {
- debuga(_("Cannot delete \"%s\": %s\n"),guard_in,strerror(errno));
+ debuga(__FILE__,__LINE__,_("Cannot delete \"%s\": %s\n"),guard_in,strerror(errno));
exit(EXIT_FAILURE);
}
return;
void redirector_report(void)
{
- FILE *fp_in = NULL, *fp_ou = NULL;
+ FileObject *fp_in = NULL;
+ FILE *fp_ou = NULL;
char *buf;
char *url;
if(!redirector_count) {
if (debugz>=LogLevel_Process) {
if (redirector_sorted[0])
- debugaz(_("Redirector report not generated because it is empty\n"));
+ debugaz(__FILE__,__LINE__,_("Redirector report not generated because it is empty\n"));
}
return;
}
snprintf(report,sizeof(report),"%s/redirector.html",outdirname);
- if((fp_in=fopen(redirector_sorted,"r"))==NULL) {
- debuga(_("(squidguard) Cannot open log file %s: %s\n"),redirector_sorted,strerror(errno));
+ if((fp_in=FileObject_Open(redirector_sorted))==NULL) {
+ debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),redirector_sorted,FileObject_GetLastOpenError());
exit(EXIT_FAILURE);
}
if((fp_ou=fopen(report,"w"))==NULL) {
- debuga(_("(squidguard) 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);
}
if ((line=longline_create())==NULL) {
- debuga(_("Not enough memory to read the processed redirector log\n"));
+ debuga(__FILE__,__LINE__,_("Not enough memory to read file \"%s\"\n"),redirector_sorted);
exit(EXIT_FAILURE);
}
while((buf=longline_read(fp_in,line))!=NULL) {
getword_start(&gwarea,buf);
if (getword(user,sizeof(user),&gwarea,'\t')<0) {
- debuga(_("Invalid user in file %s\n"),redirector_sorted);
+ debuga(__FILE__,__LINE__,_("Invalid user in file \"%s\"\n"),redirector_sorted);
exit(EXIT_FAILURE);
}
if (getword_atoll(&data2,&gwarea,'\t')<0) {
- debuga(_("Invalid date in file %s\n"),redirector_sorted);
+ debuga(__FILE__,__LINE__,_("Invalid date in file \"%s\"\n"),redirector_sorted);
exit(EXIT_FAILURE);
}
if (getword(hora,sizeof(hora),&gwarea,'\t')<0) {
- debuga(_("Invalid time in file %s\n"),redirector_sorted);
+ debuga(__FILE__,__LINE__,_("Invalid time in file \"%s\"\n"),redirector_sorted);
exit(EXIT_FAILURE);
}
if (getword(ip,sizeof(ip),&gwarea,'\t')<0) {
- debuga(_("Invalid IP address in file %s\n"),redirector_sorted);
+ debuga(__FILE__,__LINE__,_("Invalid IP address in file \"%s\"\n"),redirector_sorted);
exit(EXIT_FAILURE);
}
if (getword_ptr(buf,&url,&gwarea,'\t')<0) {
- debuga(_("Invalid URL in file %s\n"),redirector_sorted);
+ debuga(__FILE__,__LINE__,_("Invalid url in file \"%s\"\n"),redirector_sorted);
exit(EXIT_FAILURE);
}
if (getword(rule,sizeof(rule),&gwarea,'\n')<0) {
- debuga(_("Invalid rule in file %s\n"),redirector_sorted);
+ debuga(__FILE__,__LINE__,_("Invalid rule in file \"%s\"\n"),redirector_sorted);
exit(EXIT_FAILURE);
}
uinfo=userinfo_find_from_id(user);
if (!uinfo) {
- debuga(_("Unknown user ID %s in file %s\n"),user,redirector_sorted);
+ debuga(__FILE__,__LINE__,_("Unknown user ID %s in file \"%s\"\n"),user,redirector_sorted);
exit(EXIT_FAILURE);
}
output_html_link(fp_ou,url,100);
fprintf(fp_ou,"</td><td class=\"data2\">%s</td></tr>\n",rule);
}
- fclose(fp_in);
+ if (FileObject_Close(fp_in)) {
+ debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),redirector_sorted,FileObject_GetLastCloseError());
+ exit(EXIT_FAILURE);
+ }
longline_destroy(&line);
if(count>SquidGuardReportLimit && SquidGuardReportLimit>0)
}
fputs("</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(redirector_sorted)) {
- debuga(_("Cannot delete \"%s\": %s\n"),redirector_sorted,strerror(errno));
+ debuga(__FILE__,__LINE__,_("Cannot delete \"%s\": %s\n"),redirector_sorted,strerror(errno));
exit(EXIT_FAILURE);
}