numlist hours = { { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 }, 24 };
//! Domain suffix to strip from the user name.
char StripUserSuffix[MAX_USER_LEN]="";
+//! Length of the suffix to strip from the user name.
+int StripSuffixLen=0;
-extern char *userfile;
extern FileListObject AccessLog;
extern const struct ReadLogProcessStruct ReadSquidLog;
char *str;
char hora[30];
char dia[128]="";
- char wuser[MAXLEN];
char tmp3[MAXLEN]="";
char download_url[MAXLEN];
char smartfilter[MAXLEN];
const char *url;
- const char *user;
- const char *UserPtr;
int OutputNonZero = REPORT_EVERY_X_LINES ;
int idata=0;
int x;
int hmr;
int nopen;
- int StripSuffixLen;
int maxopenfiles=MAX_OPEN_USER_FILES;
unsigned long int recs1=0UL;
unsigned long int recs2=0UL;
bool download_flag=false;
bool id_is_ip;
enum ReadLogReturnCodeEnum log_entry_status;
+ enum UserProcessError PUser;
struct stat logstat;
struct getwordstruct gwarea;
struct userfilestruct *prev_ufile;
struct userfilestruct *ufile1;
struct ReadLogStruct log_entry;
struct LogLineStruct log_line;
+ FILE *UseragentLog=NULL;
LogLine_Init(&log_line);
LogLine_File(&log_line,arq);
recs1=0UL;
recs2=0UL;
- StripSuffixLen=strlen(StripUserSuffix);
// pre-read the file only if we have to show stats
if (ShowReadStatistics && ShowReadPercent && fp_in->Rewind) {
continue;
}
- if (StripSuffixLen>0)
+ PUser=process_user(&log_entry.User,log_entry.Ip,&id_is_ip);
+ switch (PUser)
{
- x=strlen(log_entry.User);
- if (x>StripSuffixLen && strcasecmp(log_entry.User+(x-StripSuffixLen),StripUserSuffix)==0)
- log_entry.User[x-StripSuffixLen]='\0';
- }
- if(strlen(log_entry.User) > MAX_USER_LEN) {
- if (debugz>=LogLevel_Process) debuga(__FILE__,__LINE__,_("User ID too long: %s\n"),log_entry.User);
- excluded_count[ER_UserNameTooLong]++;
- totregsx++;
- continue;
- }
-
- // include_users
- if(IncludeUsers[0] != '\0') {
- snprintf(val1,sizeof(val1),":%s:",log_entry.User);
- if((str=(char *) strstr(IncludeUsers,val1)) == (char *) NULL ) {
+ case USERERR_NoError:
+ break;
+ case USERERR_NameTooLong:
+ if (debugz>=LogLevel_Process) debuga(__FILE__,__LINE__,_("User ID too long: %s\n"),log_entry.User);
+ excluded_count[ER_UserNameTooLong]++;
+ totregsx++;
+ continue;
+ case USERERR_Excluded:
excluded_count[ER_User]++;
continue;
- }
+ case USERERR_InvalidChar:
+ excluded_count[ER_InvalidUserChar]++;
+ continue;
+ case USERERR_EmptyUser:
+ excluded_count[ER_NoUser]++;
+ continue;
+ case USERERR_SysUser:
+ excluded_count[ER_SysUser]++;
+ continue;
+ case USERERR_Ignored:
+ excluded_count[ER_IgnoredUser]++;
+ totregsx++;
+ continue;
+ case USERERR_Untracked:
+ excluded_count[ER_UntrackedUser]++;
+ continue;
}
if(vercode(log_entry.HttpCode)) {
continue;
}
- if(testvaliduserchar(log_entry.User)) {
- excluded_count[ER_InvalidUserChar]++;
- continue;
- }
-
// replace any tab by a single space
for (str=log_entry.Url ; *str ; str++)
if (*str=='\t') *str=' ';
}
}
- if(UserIp) {
- UserPtr=log_entry.Ip;
- id_is_ip=true;
- } else {
- UserPtr=log_entry.User;
- id_is_ip=false;
- if ((UserPtr[0]=='\0') || (UserPtr[1]=='\0' && (UserPtr[0]=='-' || UserPtr[0]==' '))) {
- if(RecordsWithoutUser == RECORDWITHOUTUSER_IP) {
- UserPtr=log_entry.Ip;
- id_is_ip=true;
- }
- if(RecordsWithoutUser == RECORDWITHOUTUSER_IGNORE) {
- excluded_count[ER_NoUser]++;
- continue;
- }
- if(RecordsWithoutUser == RECORDWITHOUTUSER_EVERYBODY)
- UserPtr="everybody";
- } else {
- if(NtlmUserFormat == NTLMUSERFORMAT_USER) {
- if ((str=strchr(UserPtr,'+'))!=NULL || (str=strchr(UserPtr,'\\'))!=NULL || (str=strchr(UserPtr,'_'))!=NULL) {
- UserPtr=str+1;
- }
- }
- }
- }
-
- if(us[0] != '\0'){
- if(strcmp(UserPtr,us)!=0) {
- excluded_count[ER_UntrackedUser]++;
- continue;
- }
- }
-
- if(Filter->SysUsers) {
- snprintf(wuser,sizeof(wuser),":%s:",UserPtr);
- if(strstr(userfile, wuser) == 0) {
- excluded_count[ER_SysUser]++;
- continue;
- }
- }
-
- if(Filter->UserFilter) {
- if(!vuexclude(UserPtr)) {
- if (debugz>=LogLevel_Process) debuga(__FILE__,__LINE__,_("Excluded user: %s\n"),UserPtr);
- excluded_count[ER_IgnoredUser]++;
- totregsx++;
- continue;
- }
- }
-
- user=process_user(UserPtr);
- if (UserPtr!=user)
- {
- UserPtr=user;
- id_is_ip=false;
- }
- if (UserPtr[0]=='\0' || (UserPtr[1]=='\0' && (UserPtr[0]=='-' || UserPtr[0]==' ' || UserPtr[0]==':'))) {
- excluded_count[ER_NoUser]++;
- continue;
- }
-
if (log_entry.DataSize<0) log_entry.DataSize=0;
if (log_entry.ElapsedTime<0) log_entry.ElapsedTime=0;
nopen=0;
prev_ufile=NULL;
- for (ufile=first_user_file ; ufile && strcmp(UserPtr,ufile->user->id)!=0 ; ufile=ufile->next) {
+ for (ufile=first_user_file ; ufile && strcmp(log_entry.User,ufile->user->id)!=0 ; ufile=ufile->next) {
prev_ufile=ufile;
if (ufile->file) nopen++;
}
if (!ufile) {
ufile=malloc(sizeof(*ufile));
if (!ufile) {
- debuga(__FILE__,__LINE__,_("Not enough memory to store the user %s\n"),UserPtr);
+ debuga(__FILE__,__LINE__,_("Not enough memory to store the user %s\n"),log_entry.User);
exit(EXIT_FAILURE);
}
memset(ufile,0,sizeof(*ufile));
* This id_is_ip stuff is just to store the string only once if the user is
* identified by its IP address instead of a distinct ID and IP address.
*/
- uinfo=userinfo_create(UserPtr,(id_is_ip) ? NULL : log_entry.Ip);
+ uinfo=userinfo_create(log_entry.User,(id_is_ip) ? NULL : log_entry.Ip);
ufile->user=uinfo;
nusers++;
} else {
}
if ((ufile->file = MY_FOPEN (tmp3, "a")) == NULL) {
debuga(__FILE__,__LINE__,_("(log) Cannot open temporary file %s: %s\n"), tmp3, strerror(errno));
- exit (1);
+ exit(EXIT_FAILURE);
}
}
if (fprintf(ufile->file, "%s\t%s\t%s\t%s\t%"PRIu64"\t%s\t%ld\t%s\n",dia,hora,
log_entry.Ip,url,(uint64_t)log_entry.DataSize,
log_entry.HttpCode,log_entry.ElapsedTime,smartfilter)<=0) {
- debuga(__FILE__,__LINE__,_("Write error in the log file of user %s\n"),UserPtr);
+ debuga(__FILE__,__LINE__,_("Write error in the log file of user %s\n"),log_entry.User);
exit(EXIT_FAILURE);
}
records_kept++;
if (fp_log && log_line.current_format!=&ReadSargLog) {
fprintf(fp_log, "%s\t%s\t%s\t%s\t%s\t%"PRIu64"\t%s\t%ld\t%s\n",dia,hora,
- UserPtr,log_entry.Ip,url,(uint64_t)log_entry.DataSize,
+ log_entry.User,log_entry.Ip,url,(uint64_t)log_entry.DataSize,
log_entry.HttpCode,log_entry.ElapsedTime,smartfilter);
}
denied_write(&log_entry);
authfail_write(&log_entry);
if (download_flag) download_write(&log_entry,download_url);
+ if (log_entry.UserAgent)
+ {
+ if (!UseragentLog)
+ UseragentLog=UserAgent_Open();
+ UserAgent_Write(UseragentLog,&log_entry.EntryTime,log_entry.Ip,log_entry.User,log_entry.UserAgent);
+ }
if (log_line.current_format!=&ReadSargLog) {
if (period.start.tm_year==0 || idata<mindate || compare_date(&period.start,&log_entry.EntryTime)>0){
if (debugz>=LogLevel_Data){
printf("IP=\t%s\n",log_entry.Ip);
- printf("USER=\t%s\n",UserPtr);
+ printf("USER=\t%s\n",log_entry.User);
printf("ELAP=\t%ld\n",log_entry.ElapsedTime);
printf("DATE=\t%s\n",dia);
printf("TIME=\t%s\n",hora);
debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),arq,FileObject_GetLastCloseError());
exit(EXIT_FAILURE);
}
+ if (UseragentLog) fclose(UseragentLog);
if (ShowReadStatistics) {
if (ShowReadPercent)
printf(_("SARG: Records in file: %lu, reading: %3.2f%%\n"),recs2, (float) 100 );