//! List of the input log files to process.
FileListObject AccessLog=NULL;
-
-
//! Selected locale set through the environment variable.
char *CurrentLocale=NULL;
+//! Set to \c true if a useragent log is provided on the command line.
+bool UserAgentFromCmdLine=false;
+
+extern FileListObject UserAgentLog;
static void getusers(const char *pwdfile, int debug);
extern char *optarg;
char hm_str[15];
- char uagent[MAXLEN];
char hexclude[MAXLEN];
char splitprefix[MAXLEN];
int ch;
LogoText[0]='\0';
PasswdFile[0]='\0';
OutputEmail[0]='\0';
- UserAgentLog[0]='\0';
ExcludeHosts[0]='\0';
ExcludeUsers[0]='\0';
ConfigFile[0]='\0';
us[0]='\0';
ReadFilter.DateRange[0]='\0';
df='\0';
- uagent[0]='\0';
hexclude[0]='\0';
addr[0]='\0';
ReadFilter.StartTime=-1;
safe_strcpy(addr,optarg,sizeof(addr));
break;
case 'b': //unused option
- safe_strcpy(uagent,optarg,sizeof(uagent));
+ UserAgentFromCmdLine=true;
+ if (!UserAgentLog)
+ UserAgentLog=FileList_Create();
+ if (!FileList_AddFile(UserAgentLog,optarg)) {
+ debuga(__FILE__,__LINE__,_("Not enough memory to store a user agent file name\n"));
+ exit(EXIT_FAILURE);
+ }
break;
case 'c':
safe_strcpy(hexclude,optarg,sizeof(hexclude));
else
ReadFilter.max_elapsed=0;
- if(uagent[0] != '\0') strcpy(UserAgentLog,uagent);
-
if(tmp[0] == '\0') strcpy(tmp,TempDir);
else strcpy(TempDir,tmp);
/*
debuga(__FILE__,__LINE__,_("Parameters:\n"));
debuga(__FILE__,__LINE__,_(" Hostname or IP address (-a) = %s\n"),addr);
- debuga(__FILE__,__LINE__,_(" Useragent log (-b) = %s\n"),uagent);
+ FIter=FileListIter_Open(UserAgentLog);
+ while ((file=FileListIter_NextWithMask(FIter))!=NULL)
+ debuga(__FILE__,__LINE__,_(" Useragent log (-b) = %s\n"),file);
+ FileListIter_Close(FIter);
debuga(__FILE__,__LINE__,_(" Exclude file (-c) = %s\n"),hexclude);
debuga(__FILE__,__LINE__,_(" Date from-until (-d) = %s\n"),ReadFilter.DateRange);
debuga(__FILE__,__LINE__,_(" Email address to send reports (-e) = %s\n"),email);
if(userfile)
free(userfile);
close_usertab();
+ FileList_Destroy(&UserAgentLog);
end_time=time(NULL);
#include "include/conf.h"
#include "include/defs.h"
+#include "include/filelist.h"
+
+FileListObject UserAgentLog=NULL;
void useragent(void)
{
char tmp3[MAXLEN];
char day[4],month[5],year[5], wdate[20];
char csort[MAXLEN];
+ const char *FileName;
int agentot=0, agentot2=0, agentdif=0, cont=0, nagent;
unsigned long totregsl=0;
int cstatus;
int ndate;
double perc;
struct getwordstruct gwarea, gwarea1;
+ FileListIterator FIter;
ip[0]='\0';
data[0]='\0';
sprintf(tmp3,"%s/squagent.int_unsort",tmp);
sprintf(tmp2,"%s/squagent.int_log",tmp);
- if((fp_in=fopen(UserAgentLog,"r"))==NULL) {
- debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),UserAgentLog,strerror(errno));
- exit(EXIT_FAILURE);
- }
if((fp_ou=fopen(tmp3,"w"))==NULL) {
debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),tmp3,strerror(errno));
exit(EXIT_FAILURE);
}
- if(debug) {
- debuga(__FILE__,__LINE__,_("Reading useragent log \"%s\"\n"),UserAgentLog);
- }
-
- while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
- totregsl++;
- getword_start(&gwarea,buf);
- if (getword(ip,sizeof(ip),&gwarea,' ')<0 || getword_skip(MAXLEN,&gwarea,'[')<0 ||
- getword(data,sizeof(data),&gwarea,' ')<0) {
- debuga(__FILE__,__LINE__,_("Invalid record in file \"%s\"\n"),UserAgentLog);
- exit(EXIT_FAILURE);
- }
- getword_start(&gwarea1,data);
- if (getword(day,sizeof(day),&gwarea1,'/')<0 || getword(month,sizeof(month),&gwarea1,'/')<0 ||
- getword(year,sizeof(year),&gwarea1,':')<0) {
- debuga(__FILE__,__LINE__,_("Invalid date in file \"%s\"\n"),UserAgentLog);
+ FIter=FileListIter_Open(UserAgentLog);
+ while ((FileName=FileListIter_Next(FIter))!=NULL)
+ {
+ if((fp_in=fopen(FileName,"r"))==NULL) {
+ debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),FileName,strerror(errno));
exit(EXIT_FAILURE);
}
- if (dfrom!=0 || duntil!=0){
- buildymd(day,month,year,wdate,sizeof(wdate));
- ndate=atoi(wdate);
- if (ndate<dfrom) continue;
- if (ndate>duntil) break;
- }
- if(totregsl == 1)
- strcpy(idate,data);
- strcpy(fdate,data);
- if (getword_skip(MAXLEN,&gwarea,'"')<0 || getword(agent,sizeof(agent),&gwarea,'"')<0) {
- debuga(__FILE__,__LINE__,_("Invalid useragent in file \"%s\"\n"),UserAgentLog);
- exit(EXIT_FAILURE);
+
+ if(debug) {
+ debuga(__FILE__,__LINE__,_("Reading useragent log \"%s\"\n"),FileName);
}
- if(gwarea.current[0]!='\0') {
- if (getword_skip(MAXLEN,&gwarea,' ')<0 || getword(user,sizeof(user),&gwarea,'\n')<0) {
- debuga(__FILE__,__LINE__,_("Invalid record in file \"%s\"\n"),UserAgentLog);
+ while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
+ totregsl++;
+ getword_start(&gwarea,buf);
+ if (getword(ip,sizeof(ip),&gwarea,' ')<0 || getword_skip(MAXLEN,&gwarea,'[')<0 ||
+ getword(data,sizeof(data),&gwarea,' ')<0) {
+ debuga(__FILE__,__LINE__,_("Invalid record in file \"%s\"\n"),FileName);
exit(EXIT_FAILURE);
}
- if(user[0] == '-')
- strcpy(user,ip);
- if(user[0] == '\0')
+ getword_start(&gwarea1,data);
+ if (getword(day,sizeof(day),&gwarea1,'/')<0 || getword(month,sizeof(month),&gwarea1,'/')<0 ||
+ getword(year,sizeof(year),&gwarea1,':')<0) {
+ debuga(__FILE__,__LINE__,_("Invalid date in file \"%s\"\n"),FileName);
+ exit(EXIT_FAILURE);
+ }
+ if (dfrom!=0 || duntil!=0){
+ buildymd(day,month,year,wdate,sizeof(wdate));
+ ndate=atoi(wdate);
+ if (ndate<dfrom) continue;
+ if (ndate>duntil) break;
+ }
+ if(totregsl == 1)
+ strcpy(idate,data);
+ strcpy(fdate,data);
+ if (getword_skip(MAXLEN,&gwarea,'"')<0 || getword(agent,sizeof(agent),&gwarea,'"')<0) {
+ debuga(__FILE__,__LINE__,_("Invalid useragent in file \"%s\"\n"),FileName);
+ exit(EXIT_FAILURE);
+ }
+
+ if(gwarea.current[0]!='\0') {
+ if (getword_skip(MAXLEN,&gwarea,' ')<0 || getword(user,sizeof(user),&gwarea,'\n')<0) {
+ debuga(__FILE__,__LINE__,_("Invalid record in file \"%s\"\n"),FileName);
+ exit(EXIT_FAILURE);
+ }
+ if(user[0] == '-')
+ strcpy(user,ip);
+ if(user[0] == '\0')
+ strcpy(user,ip);
+ } else {
strcpy(user,ip);
- } else {
- strcpy(user,ip);
+ }
+
+ fprintf(fp_ou,"%s\t%s\t%s\n",ip,agent,user);
+ useragent_count++;
}
- fprintf(fp_ou,"%s\t%s\t%s\n",ip,agent,user);
- useragent_count++;
+ if (fclose(fp_in)==EOF) {
+ debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),FileName,strerror(errno));
+ exit(EXIT_FAILURE);
+ }
}
+ FileListIter_Close(FIter);
if(debug) {
debuga(__FILE__,__LINE__,_(" Records read: %ld\n"),totregsl);
debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),tmp3,strerror(errno));
exit(EXIT_FAILURE);
}
- if (fclose(fp_in)==EOF) {
- debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),UserAgentLog,strerror(errno));
- exit(EXIT_FAILURE);
- }
-
if(debug) {
debuga(__FILE__,__LINE__,_("Sorting file \"%s\"\n"),tmp2);
}