From: Frédéric Marchal Date: Sun, 26 Aug 2012 13:56:55 +0000 (+0200) Subject: Purge the old log file decoding code X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ef09faf6a1297527255b67b3bf23a4bb85052a5a;p=thirdparty%2Fsarg.git Purge the old log file decoding code The legacy code to read the log files is gone for good. --- diff --git a/readlog.c b/readlog.c index 3165830..39f9c70 100644 --- a/readlog.c +++ b/readlog.c @@ -71,13 +71,8 @@ int ReadLogFile(struct ReadLogDataStruct *Filter) char *linebuf; char *str; char arq_log[255]; - //char fun[MAXLEN]; - //char elap[255]; char user[MAX_USER_LEN]; - //char data[255]; - //char ip[60]; char hora[30]; - //char mes[30]; char tbuf2[128]; char dia[128]=""; char wuser[MAXLEN]; @@ -92,7 +87,6 @@ int ReadLogFile(struct ReadLogDataStruct *Filter) int blen; int OutputNonZero = REPORT_EVERY_X_LINES ; int idata=0; - //int isa_ncols=0,isa_cols[ISACOL_Last]; int x; int hmr; int nopen; @@ -107,7 +101,6 @@ int ReadLogFile(struct ReadLogDataStruct *Filter) long int totregsl=0; long int totregsg=0; long int totregsx=0; - //long long int iyear, imonth, iday; FILE *fp_in=NULL; FILE *fp_log=NULL; FILE *fp_Download_Unsort=NULL; @@ -119,7 +112,6 @@ int ReadLogFile(struct ReadLogDataStruct *Filter) enum ReadLogReturnCodeEnum log_entry_status; struct stat logstat; struct getwordstruct gwarea; - //struct tm tt; struct userfilestruct *prev_ufile; struct userinfostruct *uinfo; struct userfilestruct *first_user_file=NULL; @@ -127,7 +119,6 @@ int ReadLogFile(struct ReadLogDataStruct *Filter) struct userfilestruct *ufile1; struct ReadLogStruct log_entry; const struct ReadLogProcessStruct *current_format=NULL; - //time_t tnum; for (x=0 ; x0) { @@ -343,335 +310,6 @@ int ReadLogFile(struct ReadLogDataStruct *Filter) fputs("*** SARG Log ***\n",fp_log); } -#if 0 - if (ilf==ILF_Squid || ilf==ILF_Common || ilf==ILF_Unknown) { - getword_start(&gwarea,linebuf); - if (getword(data,sizeof(data),&gwarea,' ')<0) { - debuga(_("Maybe you have a broken time in your access.log file\n")); - exit(EXIT_FAILURE); - } - if((str=(char *) strchr(data, '.')) != (char *) NULL && (str=(char *) strchr(str+1, '.')) != (char *) NULL ) { - strcpy(ip,data); - log_entry.Ip=ip; - if(squid24) { - if (getword(user,sizeof(user),&gwarea,' ')<0 || getword_skip(255,&gwarea,' ')<0) { - debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq); - exit(EXIT_FAILURE); - } - } else { - if (getword_skip(255,&gwarea,' ')<0 || getword(user,sizeof(user),&gwarea,' ')<0) { - debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq); - exit(EXIT_FAILURE); - } - } - log_entry.User=user; - if (getword(data,sizeof(data),&gwarea,']')<0 || getword_skip(MAXLEN,&gwarea,'"')<0 || - getword(fun,sizeof(fun),&gwarea,' ')<0) { - debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq); - exit(EXIT_FAILURE); - } - if (getword_ptr(linebuf,&log_entry.Url,&gwarea,' ')<0) { - debuga(_("Maybe you have a broken url in your %s file\n"),arq); - exit(EXIT_FAILURE); - } - if (getword_skip(MAXLEN,&gwarea,' ')<0) { - debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq); - exit(EXIT_FAILURE); - } - if (getword(code2,sizeof(code2),&gwarea,' ')<0) { - debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq); - exit(EXIT_FAILURE); - } - if (getword_atoll(&log_entry.DataSize,&gwarea,' ')<0) { - debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq); - exit(EXIT_FAILURE); - } - if((str=(char *) strchr(gwarea.current, ' ')) != (char *) NULL ) { - if (getword(code,sizeof(code),&gwarea,' ')<0) { - debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq); - exit(EXIT_FAILURE); - } - } else { - if (getword(code,sizeof(code),&gwarea,'\0')<0) { - debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq); - exit(EXIT_FAILURE); - } - } - - if ((str = strchr(code, ':')) != NULL) - *str = '/'; - log_entry.HttpCode=code; - - ilf=ILF_Common; - ilf_count[ilf]++; - - getword_start(&gwarea,data+1); - if (getword_multisep(data,sizeof(data),&gwarea,':')<0){ - debuga(_("Maybe you have a broken date in your %s file\n"),arq); - exit(EXIT_FAILURE); - } - if (getword_multisep(hora,sizeof(hora),&gwarea,' ')<0){ - debuga(_("Maybe you have a broken date in your %s file\n"),arq); - exit(EXIT_FAILURE); - } - getword_start(&gwarea,data); - if (getword_atoll(&iday,&gwarea,'/')<0){ - debuga(_("Maybe you have a broken date in your %s file\n"),arq); - exit(EXIT_FAILURE); - } - if (getword(mes,sizeof(mes),&gwarea,'/')<0){ - debuga(_("Maybe you have a broken date in your %s file\n"),arq); - exit(EXIT_FAILURE); - } - if (getword_atoll(&iyear,&gwarea,'/')<0){ - debuga(_("Maybe you have a broken date in your %s file\n"),arq); - exit(EXIT_FAILURE); - } - - imonth=month2num(mes)+1; - idata=builddia(iday,imonth,iyear); - computedate(iyear,imonth,iday,&tt); - if (sscanf(hora,"%d:%d:%d",&tt.tm_hour,&tt.tm_min,&tt.tm_sec)!=3 || tt.tm_hour<0 || tt.tm_hour>=24 || - tt.tm_min<0 || tt.tm_min>=60 || tt.tm_sec<0 || tt.tm_sec>=60) { - debuga(_("Invalid time found in %s\n"),arq); - exit(EXIT_FAILURE); - } - log_entry.EntryTime=&tt; - } - - if(ilf==ILF_Unknown || ilf==ILF_Squid) { - if (getword(elap,sizeof(elap),&gwarea,' ')<0) { - debuga(_("Maybe you have a broken elapsed time in your %s file\n"),arq); - exit(EXIT_FAILURE); - } - while(strcmp(elap,"") == 0 && gwarea.current[0] != '\0') - if (getword(elap,sizeof(elap),&gwarea,' ')<0) { - debuga(_("Maybe you have a broken elapsed time in your %s file\n"),arq); - exit(EXIT_FAILURE); - } - if(strlen(elap) < 1) continue; - log_entry.ElapsedTime=atol(elap); - if (getword(ip,sizeof(ip),&gwarea,' ')<0){ - debuga(_("Maybe you have a broken client IP address in your %s file\n"),arq); - exit(EXIT_FAILURE); - } - log_entry.Ip=ip; - if (getword(code,sizeof(code),&gwarea,' ')<0){ - debuga(_("Maybe you have a broken result code in your %s file\n"),arq); - exit(EXIT_FAILURE); - } - log_entry.HttpCode=code; - if (getword_atoll(&log_entry.DataSize,&gwarea,' ')<0){ - debuga(_("Maybe you have a broken amount of data in your %s file\n"),arq); - exit(EXIT_FAILURE); - } - if (getword(fun,sizeof(fun),&gwarea,' ')<0){ - debuga(_("Maybe you have a broken request method in your %s file\n"),arq); - exit(EXIT_FAILURE); - } - if (getword_ptr(linebuf,&log_entry.Url,&gwarea,' ')<0){ - debuga(_("Maybe you have a broken url in your %s file\n"),arq); - exit(EXIT_FAILURE); - } - if (getword(user,sizeof(user),&gwarea,' ')<0){ - debuga(_("Maybe you have a broken user ID in your %s file\n"),arq); - exit(EXIT_FAILURE); - } - log_entry.User=user; - ilf=ILF_Squid; - ilf_count[ilf]++; - - tnum=atoi(data); - log_entry.EntryTime=localtime(&tnum); - if (log_entry.EntryTime == NULL) { - debuga(_("Cannot convert the timestamp from the squid log file\n")); - exit(EXIT_FAILURE); - } - - strftime(tbuf2, sizeof(tbuf2), "%H%M", log_entry.EntryTime); - - idata=(log_entry.EntryTime->tm_year+1900)*10000+(log_entry.EntryTime->tm_mon+1)*100+log_entry.EntryTime->tm_mday; - } - } - if (ilf==ILF_Sarg) { - getword_start(&gwarea,linebuf); - if (getword(data,sizeof(data),&gwarea,'\t')<0){ - debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq); - exit(EXIT_FAILURE); - } - if (getword(hora,sizeof(hora),&gwarea,'\t')<0) { - debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq); - exit(EXIT_FAILURE); - } - if (getword(user,sizeof(user),&gwarea,'\t')<0) { - debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq); - exit(EXIT_FAILURE); - } - log_entry.User=user; - if (getword(ip,sizeof(ip),&gwarea,'\t')<0) { - debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq); - exit(EXIT_FAILURE); - } - log_entry.Ip=ip; - if (getword_ptr(linebuf,&log_entry.Url,&gwarea,'\t')<0){ - debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq); - exit(EXIT_FAILURE); - } - if (getword_atoll(&log_entry.DataSize,&gwarea,'\t')<0){ - debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq); - exit(EXIT_FAILURE); - } - if (getword(code,sizeof(code),&gwarea,'\t')<0){ - debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq); - exit(EXIT_FAILURE); - } - log_entry.HttpCode=code; - if (getword_atol(&log_entry.ElapsedTime,&gwarea,'\t')<0){ - debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq); - exit(EXIT_FAILURE); - } - if (getword(smartfilter,sizeof(smartfilter),&gwarea,'\0')<0){ - debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq); - exit(EXIT_FAILURE); - } - getword_start(&gwarea,data); - if (getword_atoll(&iday,&gwarea,'/')<0 || iday<1 || iday>31){ - debuga(_("Maybe you have a broken date in your %s file\n"),arq); - exit(EXIT_FAILURE); - } - if (getword_atoll(&imonth,&gwarea,'/')<0 || imonth<1 || imonth>12){ - debuga(_("Maybe you have a broken date in your %s file\n"),arq); - exit(EXIT_FAILURE); - } - if (getword_atoll(&iyear,&gwarea,'\0')<0){ - debuga(_("Maybe you have a broken date in your %s file\n"),arq); - exit(EXIT_FAILURE); - } - idata=builddia(iday,imonth,iyear); - computedate(iyear,imonth,iday,&tt); - if (sscanf(hora,"%d:%d:%d",&tt.tm_hour,&tt.tm_min,&tt.tm_sec)!=3 || tt.tm_hour<0 || tt.tm_hour>=24 || - tt.tm_min<0 || tt.tm_min>=60 || tt.tm_sec<0 || tt.tm_sec>=60) { - debuga(_("Invalid time found in %s\n"),arq); - exit(EXIT_FAILURE); - } - log_entry.EntryTime=&tt; - } - if (ilf==ILF_Isa) { - if (linebuf[0] == '#') { - int ncols,cols[ISACOL_Last]; - - fixendofline(linebuf); - getword_start(&gwarea,linebuf); - // remove the #Fields: column at the beginning of the line - if (getword_skip(1000,&gwarea,' ')<0){ - debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq); - exit(EXIT_FAILURE); - } - for (ncols=0 ; ncols=0) { - isa_ncols=ncols; - for (ncols=0 ; ncols=sizeof(ip)) { - debuga(_("Maybe you have a broken IP in your %s file\n"),arq); - exit(EXIT_FAILURE); - } - strcpy(ip,str); - log_entry.Ip=ip; - } else if (x==isa_cols[ISACOL_UserName]) { - if (strlen(str)>=sizeof(user)) { - debuga(_("Maybe you have a broken user ID in your %s file\n"),arq); - exit(EXIT_FAILURE); - } - strcpy(user,str); - log_entry.User=user; - } else if (x==isa_cols[ISACOL_Date]) { - if (strlen(str)>=sizeof(data)) { - debuga(_("Maybe you have a broken date in your %s file\n"),arq); - exit(EXIT_FAILURE); - } - strcpy(data,str); - } else if (x==isa_cols[ISACOL_Time]) { - if (strlen(str)>=sizeof(hora)) { - debuga(_("Maybe you have a broken time in your %s file\n"),arq); - exit(EXIT_FAILURE); - } - strcpy(hora,str); - } else if (x==isa_cols[ISACOL_TimeTaken]) { - log_entry.ElapsedTime=atol(str); - } else if (x==isa_cols[ISACOL_Bytes]) { - log_entry.DataSize=atoll(str); - } else if (x==isa_cols[ISACOL_Uri]) { - log_entry.Url=str; - } else if (x==isa_cols[ISACOL_Status]) { - if (strlen(str)>=sizeof(code)) { - debuga(_("Maybe you have a broken access code in your %s file\n"),arq); - exit(EXIT_FAILURE); - } - strcpy(code,str); - } - } - - if(strcmp(code,"401") == 0 || strcmp(code,"403") == 0 || strcmp(code,"407") == 0) { - static char valcode[12]; - sprintf(valcode,"DENIED/%s",code); - log_entry.HttpCode=valcode; - } else { - log_entry.HttpCode=code; - } - getword_start(&gwarea,data); - if (getword_atoll(&iyear,&gwarea,'-')<0){ - debuga(_("Maybe you have a broken year in your %s file\n"),arq); - exit(EXIT_FAILURE); - } - if (getword_atoll(&imonth,&gwarea,'-')<0){ - debuga(_("Maybe you have a broken month in your %s file\n"),arq); - exit(EXIT_FAILURE); - } - if (getword_atoll(&iday,&gwarea,'\0')<0){ - debuga(_("Maybe you have a broken day in your %s file\n"),arq); - exit(EXIT_FAILURE); - } - - idata=builddia(iday,imonth,iyear); - computedate(iyear,imonth,iday,&tt); - if (isa_cols[ISACOL_Time]>=0) { - if (sscanf(hora,"%d:%d:%d",&tt.tm_hour,&tt.tm_min,&tt.tm_sec)!=3 || tt.tm_hour<0 || tt.tm_hour>=24 || - tt.tm_min<0 || tt.tm_min>=60 || tt.tm_sec<0 || tt.tm_sec>=60) { - debuga(_("Invalid time found in %s\n"),arq); - exit(EXIT_FAILURE); - } - } - log_entry.EntryTime=&tt; - } -#endif if (log_entry.Ip==NULL) { debuga(_("Unknown input log file format: no IP addresses\n")); break;