static void read_log(const char *wentp, FILE *fp_ou)
{
FILE *fp_in = NULL;
+ char buf[MAXLEN];
char leks[5], sep[2], res[MAXLEN];
char mon[20], day[3], year[5], hour[15];
char list[MAXLEN];
char wdata[127];
char url[MAX_URL_LEN];
char user[MAX_USER_LEN];
+ char ip[25];
int idata=0;
int i;
char *str;
struct getwordstruct gwarea1;
if(debug) {
- getword_start(&gwarea,_("Reading access log file"));
- if (getword(url,sizeof(url),&gwarea,' ')<0 || getword_skip(MAXLEN,&gwarea,' ')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s string.\n",_("Reading access log file"));
- exit(1);
- }
- debuga("%s squidGuard %s: %s\n",url,gwarea.current,wentp);
+ debuga(_("Reading squidGuard 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) {
- perror("parse squidGuard - realloc");
- exit(EXIT_FAILURE);
+ debuga(_("Not enough memory to store the name of the new squidGuard log to be read - %s\n"),strerror(errno));
+ exit(EXIT_FAILURE);
}
files_done[nfiles_done-1] = strdup(wentp);
if (!files_done[nfiles_done-1]) {
- perror("parse squidGuard - strdup");
- exit(EXIT_FAILURE);
+ debuga(_("Not enough memory to store the name of the new squidGuard log to be read - %s\n"),strerror(errno));
+ exit(EXIT_FAILURE);
}
if ((fp_in=fopen(wentp,"r"))==NULL) {
- fprintf(stderr, "SARG: (squidguard) %s: %s\n",_("Cannot open log file"),wentp);
- exit(1);
+ debuga(_("(squidguard) Cannot open log file %s\n"),wentp);
+ exit(EXIT_FAILURE);
}
while (fgets(buf,sizeof(buf),fp_in) != NULL) {
leks[0]='\0';
if (getword(leks,sizeof(leks),&gwarea1,'#')<0) {
debuga(_("There is a broken record or garbage in your %s file\n"),wentp);
- exit(1);
+ exit(EXIT_FAILURE);
}
while(strcmp(leks,"end") != 0) {
if (getword(leks,sizeof(leks),&gwarea1,'#')<0 || getword(sep,sizeof(sep),&gwarea1,'#')<0) {
debuga(_("Maybe you have a broken record or garbage in your %s file\n"),wentp);
- exit(1);
+ exit(EXIT_FAILURE);
}
if(strcmp(leks,"end") != 0) {
if (getword(res,sizeof(res),&gwarea,sep[0])<0) {
debuga(_("Maybe you have a broken record or garbage in your %s file\n"),wentp);
- exit(1);
+ exit(EXIT_FAILURE);
}
if(strcmp(leks,"year") == 0) {
if (strlen(res)>=sizeof(year)) {
debuga(_("Year string too long in squidGuard log file %s\n"),wentp);
- exit(1);
+ exit(EXIT_FAILURE);
}
strcpy(year,res);
} else if(strcmp(leks,"mon") == 0) {
if (strlen(res)>=sizeof(mon)) {
debuga(_("Month string too long in squidGuard log file %s\n"),wentp);
- exit(1);
+ exit(EXIT_FAILURE);
}
strcpy(mon,res);
} else if(strcmp(leks,"day") == 0) {
if (strlen(res)>=sizeof(day)) {
debuga(_("Day string too long in squidGuard log file %s\n"),wentp);
- exit(1);
+ exit(EXIT_FAILURE);
}
strcpy(day,res);
} else if(strcmp(leks,"hour") == 0) {
if (strlen(res)>=sizeof(hour)) {
debuga(_("Hour string too long in squidGuard log file %s\n"),wentp);
- exit(1);
+ exit(EXIT_FAILURE);
}
strcpy(hour,res);
} else if(strcmp(leks,"list") == 0) {
if (strlen(res)>=sizeof(list)) {
debuga(_("Banning list name too long in squidGuard log file %s\n"),wentp);
- exit(1);
+ exit(EXIT_FAILURE);
}
strcpy(list,res);
} else if(strcmp(leks,"ip") == 0) {
if (strlen(res)>=sizeof(ip)) {
debuga(_("IP address too long in squidGuard log file %s\n"),wentp);
- exit(1);
+ exit(EXIT_FAILURE);
}
strcpy(ip,res);
} else if(strcmp(leks,"user") == 0) {
if (strlen(res)>=sizeof(user)) {
debuga(_("User ID too long in squidGuard log file %s\n"),wentp);
- exit(1);
+ exit(EXIT_FAILURE);
}
strcpy(user,res);
} else if(strcmp(leks,"url") == 0) {
if (strlen(res)>=sizeof(url)) {
debuga(_("URL too long in squidGuard log file %s\n"),wentp);
- exit(1);
+ exit(EXIT_FAILURE);
}
strcpy(url,res);
}
getword(ip,sizeof(ip),&gwarea,'/')<0 || getword_skip(MAXLEN,&gwarea,' ')<0 ||
getword(user,sizeof(user),&gwarea,' ')<0) {
debuga(_("There is a broken record or garbage in your %s file\n"),wentp);
- exit(1);
+ exit(EXIT_FAILURE);
}
/*
The URL may be "http://url:port/data" if the method is GET or simply "url:port/" if the method is CONNECT.
void squidguard_log(void)
{
FILE *fp_ou = NULL, *fp_guard = NULL;
+ char buf[MAXLEN];
char guard_in[MAXLEN];
char guard_ou[MAXLEN];
char logdir[MAXLEN];
sprintf(guard_in,"%s/squidguard.unsort",tmp);
sprintf(guard_ou,"%s/squidguard.log",tmp);
if((fp_ou=fopen(guard_in,"a"))==NULL) {
- fprintf(stderr, "SARG: (squidguard) %s: %s\n",_("Cannot open log file"),guard_in);
- exit(1);
+ debuga(_("(squidguard) Cannot open log file %s\n"),guard_in);
+ exit(EXIT_FAILURE);
}
bzero(day, 3);
if(SquidGuardConf[0] != 0) {
if(access(SquidGuardConf, R_OK) != 0) {
debuga(_("Cannot open squidGuard config file: %s\n"),SquidGuardConf);
- exit(1);
+ exit(EXIT_FAILURE);
}
if((fp_guard=fopen(SquidGuardConf,"r"))==NULL) {
- fprintf(stderr, "SARG: (squidguard) %s: %s\n",_("Cannot open log file"),SquidGuardConf);
- exit(1);
+ debuga(_("(squidguard) Cannot open log file %s\n"),SquidGuardConf);
+ exit(EXIT_FAILURE);
}
logdir[0]=0;
}
}
} else {
- sprintf(wentp,"%s",SquidGuardLogAlternate);
+ strcpy(wentp,SquidGuardLogAlternate);
read_log(wentp,fp_ou);
}
sprintf(tmp6,"sort -k 1,1 -k 2,2 -k 4,4 \"%s\" -o \"%s\"",guard_in, guard_ou);
cstatus=system(tmp6);
if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
- fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus));
- fprintf(stderr, "SARG: sort command: %s\n",tmp6);
- exit(1);
+ debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus));
+ debuga(_("sort command: %s\n"),tmp6);
+ exit(EXIT_FAILURE);
}
unlink(guard_in);