From: Frédéric Marchal Date: Tue, 3 Jul 2012 10:19:03 +0000 (+0200) Subject: Store the IP address in a structure X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6debcf3d02671a88de69e835243d79e0b79043e7;p=thirdparty%2Fsarg.git Store the IP address in a structure Yet another log variable stored in the structure to be exchanged with the modules to read the input log files. --- diff --git a/readlog.c b/readlog.c index aa14807..99015d8 100644 --- a/readlog.c +++ b/readlog.c @@ -84,7 +84,7 @@ int ReadLogFile(struct ReadLogDataStruct *Filter) char elap[255]; char user[MAX_USER_LEN]; char data[255]; - char ip[MAXLEN]; + char ip[60]; char tam[255]; char hora[30]; char mes[30]; @@ -303,7 +303,7 @@ int ReadLogFile(struct ReadLogDataStruct *Filter) if(debugm) printf("BUF=%s\n",linebuf); - log_entry.EntryTime=NULL; + memset(&log_entry,0,sizeof(log_entry)); if (ilf==ILF_Squid || ilf==ILF_Common || ilf==ILF_Unknown) { getword_start(&gwarea,linebuf); if (getword(data,sizeof(data),&gwarea,' ')<0) { @@ -312,6 +312,7 @@ int ReadLogFile(struct ReadLogDataStruct *Filter) } if((str=(char *) strchr(data, '.')) != (char *) NULL && (str=(char *) strchr(str+1, '.')) != (char *) NULL ) { strcpy(ip,data); + log_entry.Ip=ip; strcpy(elap,"0"); if(squid24) { if (getword(user,sizeof(user),&gwarea,' ')<0 || getword_skip(255,&gwarea,' ')<0) { @@ -415,6 +416,7 @@ int ReadLogFile(struct ReadLogDataStruct *Filter) 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); @@ -468,6 +470,7 @@ int ReadLogFile(struct ReadLogDataStruct *Filter) 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,&full_url,&gwarea,'\t')<0){ debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq); exit(EXIT_FAILURE); @@ -558,6 +561,7 @@ int ReadLogFile(struct ReadLogDataStruct *Filter) 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); @@ -629,7 +633,11 @@ int ReadLogFile(struct ReadLogDataStruct *Filter) log_entry.EntryTime=&tt; } if (log_entry.EntryTime==NULL) { - debuga(_("Unknown input log file format\n")); + debuga(_("Unknown input log file format: no time\n")); + break; + } + if (log_entry.Ip==NULL) { + debuga(_("Unknown input log file format: no IP addresses\n")); break; } @@ -718,7 +726,7 @@ int ReadLogFile(struct ReadLogDataStruct *Filter) if (!url || url[0] == '\0') continue; if(addr[0] != '\0'){ - if(strcmp(addr,ip)!=0) continue; + if(strcmp(addr,log_entry.Ip)!=0) continue; } if(Filter->HostFilter) { if(!vhexclude(url)) { @@ -738,13 +746,13 @@ int ReadLogFile(struct ReadLogDataStruct *Filter) } if(UserIp) { - strcpy(user,ip); + strcpy(user,log_entry.Ip); id_is_ip=true; } else { id_is_ip=false; if(strcmp(user,"-") == 0 || strcmp(user," ") == 0 || strcmp(user,"") == 0) { if(RecordsWithoutUser == RECORDWITHOUTUSER_IP) { - strcpy(user,ip); + strcpy(user,log_entry.Ip); id_is_ip=true; } if(RecordsWithoutUser == RECORDWITHOUTUSER_IGNORE) @@ -871,13 +879,13 @@ int ReadLogFile(struct ReadLogDataStruct *Filter) } strcpy( sz_Last_User , user ) ; }*/ - if (fprintf(ufile->file, "%s\t%s\t%s\t%s\t%ld\t%s\t%ld\t%s\n",dia,hora,ip,url,nbytes,code,elap_time,smartfilter)<=0) { + if (fprintf(ufile->file, "%s\t%s\t%s\t%s\t%ld\t%s\t%ld\t%s\n",dia,hora,log_entry.Ip,url,nbytes,code,elap_time,smartfilter)<=0) { debuga(_("Write error in the log file of user %s\n"),user); exit(EXIT_FAILURE); } if(fp_log && ilf!=ILF_Sarg) - fprintf(fp_log, "%s\t%s\t%s\t%s\t%s\t%ld\t%s\t%ld\t%s\n",dia,hora,user,ip,url,nbytes,code,elap_time,smartfilter); + fprintf(fp_log, "%s\t%s\t%s\t%s\t%s\t%ld\t%s\t%ld\t%s\n",dia,hora,user,log_entry.Ip,url,nbytes,code,elap_time,smartfilter); totregsg++; @@ -890,16 +898,16 @@ int ReadLogFile(struct ReadLogDataStruct *Filter) exit (1); } } - fprintf(fp_Download_Unsort,"%s\t%s\t%s\t%s\t%s\n",dia,hora,user,ip,download_url); + fprintf(fp_Download_Unsort,"%s\t%s\t%s\t%s\t%s\n",dia,hora,user,log_entry.Ip,download_url); } if(fp_denied && strstr(code,"DENIED/403") != 0) { - fprintf(fp_denied, "%s\t%s\t%s\t%s\t%s\n",dia,hora,user,ip,full_url); + fprintf(fp_denied, "%s\t%s\t%s\t%s\t%s\n",dia,hora,user,log_entry.Ip,full_url); denied_count++; } if((ReportType & REPORT_TYPE_AUTH_FAILURES) != 0) { if(fp_authfail && (strstr(code,"DENIED/401") != 0 || strstr(code,"DENIED/407") != 0)) { - fprintf(fp_authfail, "%s\t%s\t%s\t%s\t%s\n",dia,hora,user,ip,full_url); + fprintf(fp_authfail, "%s\t%s\t%s\t%s\t%s\n",dia,hora,user,log_entry.Ip,full_url); authfail_count++; } } @@ -918,7 +926,7 @@ int ReadLogFile(struct ReadLogDataStruct *Filter) } if(debugm){ - printf("IP=\t%s\n",ip); + printf("IP=\t%s\n",log_entry.Ip); printf("USER=\t%s\n",user); printf("ELAP=\t%ld\n",elap_time); printf("DATE=\t%s\n",dia);