/*
- * AUTHOR: Pedro Lineu Orso pedro.orso@gmail.com
- * 1998, 2010
* SARG Squid Analysis Report Generator http://sarg.sourceforge.net
+ * 1998, 2010
*
* SARG donations:
* please look at http://sarg.sourceforge.net/donations.php
+ * Support:
+ * http://sourceforge.net/projects/sarg/forums/forum/363374
* ---------------------------------------------------------------------
*
* This program is free software; you can redistribute it and/or modify
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[10], hour[15];
+ 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,text[7]);
- if (getword(urly,sizeof(urly),&gwarea,' ')<0 || getword(href,sizeof(href),&gwarea,' ')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s string.\n",text[7]);
- exit(1);
- }
- debuga("%s squidGuard %s: %s",urly,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",text[8],wentp);
- exit(1);
+ debuga(_("(squidguard) Cannot open log file %s\n"),wentp);
+ exit(EXIT_FAILURE);
}
while (fgets(buf,sizeof(buf),fp_in) != NULL) {
getword_start(&gwarea1,SquidGuardLogFormat);
leks[0]='\0';
if (getword(leks,sizeof(leks),&gwarea1,'#')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wentp);
- exit(1);
+ debuga(_("There is a broken record or garbage in your %s file\n"),wentp);
+ exit(EXIT_FAILURE);
}
while(strcmp(leks,"end") != 0) {
if (getword(leks,sizeof(leks),&gwarea1,'#')<0 || getword(sep,sizeof(sep),&gwarea1,'#')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wentp);
- exit(1);
+ debuga(_("Maybe you have a broken record or garbage in your %s file\n"),wentp);
+ exit(EXIT_FAILURE);
}
if(strcmp(leks,"end") != 0) {
if (getword(res,sizeof(res),&gwarea,sep[0])<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wentp);
- exit(1);
+ debuga(_("Maybe you have a broken record or garbage in your %s file\n"),wentp);
+ exit(EXIT_FAILURE);
}
- if(strcmp(leks,"year") == 0)
+ if(strcmp(leks,"year") == 0) {
+ if (strlen(res)>=sizeof(year)) {
+ debuga(_("Year string too long in squidGuard log file %s\n"),wentp);
+ exit(EXIT_FAILURE);
+ }
strcpy(year,res);
- else if(strcmp(leks,"year") == 0)
- strcpy(year,res);
- else if(strcmp(leks,"mon") == 0)
+ } else if(strcmp(leks,"mon") == 0) {
+ if (strlen(res)>=sizeof(mon)) {
+ debuga(_("Month string too long in squidGuard log file %s\n"),wentp);
+ exit(EXIT_FAILURE);
+ }
strcpy(mon,res);
- else if(strcmp(leks,"day") == 0)
+ } else if(strcmp(leks,"day") == 0) {
+ if (strlen(res)>=sizeof(day)) {
+ debuga(_("Day string too long in squidGuard log file %s\n"),wentp);
+ exit(EXIT_FAILURE);
+ }
strcpy(day,res);
- else if(strcmp(leks,"hour") == 0)
+ } else if(strcmp(leks,"hour") == 0) {
+ if (strlen(res)>=sizeof(hour)) {
+ debuga(_("Hour string too long in squidGuard log file %s\n"),wentp);
+ exit(EXIT_FAILURE);
+ }
strcpy(hour,res);
- else if(strcmp(leks,"list") == 0)
+ } 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(EXIT_FAILURE);
+ }
strcpy(list,res);
- else if(strcmp(leks,"ip") == 0)
+ } else if(strcmp(leks,"ip") == 0) {
+ if (strlen(res)>=sizeof(ip)) {
+ debuga(_("IP address too long in squidGuard log file %s\n"),wentp);
+ exit(EXIT_FAILURE);
+ }
strcpy(ip,res);
- else if(strcmp(leks,"user") == 0)
+ } else if(strcmp(leks,"user") == 0) {
+ if (strlen(res)>=sizeof(user)) {
+ debuga(_("User ID too long in squidGuard log file %s\n"),wentp);
+ exit(EXIT_FAILURE);
+ }
strcpy(user,res);
- else if(strcmp(leks,"url") == 0)
+ } else if(strcmp(leks,"url") == 0) {
+ if (strlen(res)>=sizeof(url)) {
+ debuga(_("URL too long in squidGuard log file %s\n"),wentp);
+ exit(EXIT_FAILURE);
+ }
strcpy(url,res);
+ }
}
}
} else {
getword_skip(MAXLEN,&gwarea,' ')<0 || getword(url,sizeof(url),&gwarea,' ')<0 ||
getword(ip,sizeof(ip),&gwarea,'/')<0 || getword_skip(MAXLEN,&gwarea,' ')<0 ||
getword(user,sizeof(user),&gwarea,' ')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wentp);
- exit(1);
+ debuga(_("There is a broken record or garbage in your %s file\n"),wentp);
+ 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];
char year[10], day[10], mon[10];
char user[MAXLEN];
+ char tmp6[MAXLEN];
int y;
int cstatus;
char *str;
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",text[8],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",SquidGuardConf);
- exit(1);
+ debuga(_("Cannot open squidGuard config file: %s\n"),SquidGuardConf);
+ exit(EXIT_FAILURE);
}
if((fp_guard=fopen(SquidGuardConf,"r"))==NULL) {
- fprintf(stderr, "SARG: (squidguard) %s: %s\n",text[8],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);
}
}
if(debug) {
- debuga("%s: %s",text[54],guard_ou);
+ debuga(_("Sorting file: %s\n"),guard_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);