From: Frédéric Marchal Date: Wed, 27 Jan 2010 19:03:52 +0000 (+0000) Subject: Parse some of the configuration flags in getconf.c once and use bits mask during... X-Git-Tag: v2.3-pre2~111 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=085c1e1fb8880aa41cd0ec64b080bd8bca6835b8;p=thirdparty%2Fsarg.git Parse some of the configuration flags in getconf.c once and use bits mask during the processing --- diff --git a/ChangeLog b/ChangeLog index 4cb249f..522bfc5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,10 +1,11 @@ SARG ChangeLog -Dec-12-2009 Version 2.3 +Jan-27-2009 Version 2.3 - LDAP usertab added. Now you can have your users in a LDAP Server. Use these tags in sarg.conf: LDAPHost, LDAPPort, LDAPBindDN, LDAPBindPW, LDAPBaseSearch, LDAPFilterSearch + - Parse the string flags from sarg.conf once during the reading of sarg.conf instead of manipulating and duplicating the tests of the strings where they are used. Jan-22-2010 Version 2.2.7 - Extra compile and run time protection (FORTIFY_SOURCE) fixed in configure. diff --git a/datafile.c b/datafile.c index 7c94108..c69066f 100644 --- a/datafile.c +++ b/datafile.c @@ -166,41 +166,41 @@ void saverecs(char *dirname, char *user, long long int nacc, char *url, long lon my_lltoa(incache,val4,0); my_lltoa(oucache,val5,0); - if(strstr(DataFileFields,"user") != 0) { + if((DataFileFields & DATA_FIELD_USER) != 0) { strcpy(reg,user); strncat(reg,DataFileDelimiter,1); } - if(strstr(DataFileFields,"date") != 0) { + if((DataFileFields & DATA_FIELD_DATE) != 0) { strncat(reg,dia,strlen(dia)); strncat(reg,DataFileDelimiter,1); } - if(strstr(DataFileFields,"time") != 0) { + if((DataFileFields & DATA_FIELD_TIME) != 0) { strncat(reg,hora,strlen(hora)); strncat(reg,DataFileDelimiter,1); } - if(strstr(DataFileFields,"url") != 0) { + if((DataFileFields & DATA_FIELD_URL) != 0) { strcpy(name,url); if (strcmp(DataFileUrl,"ip") == 0) name2ip(name); strncat(reg,name,strlen(name)); strncat(reg,DataFileDelimiter,1); } - if(strstr(DataFileFields,"connect") != 0) { + if((DataFileFields & DATA_FIELD_CONNECT) != 0) { strncat(reg,val1,strlen(val1)); strncat(reg,DataFileDelimiter,1); } - if(strstr(DataFileFields,"bytes") != 0) { + if((DataFileFields & DATA_FIELD_BYTES) != 0) { strncat(reg,val2,strlen(val2)); strncat(reg,DataFileDelimiter,1); } - if(strstr(DataFileFields,"in_cache") != 0) { + if((DataFileFields & DATA_FIELD_IN_CACHE) != 0) { strncat(reg,val4,strlen(val4)); strncat(reg,DataFileDelimiter,1); } - if(strstr(DataFileFields,"out_cache") != 0) { + if((DataFileFields & DATA_FIELD_OUT_CACHE) != 0) { strncat(reg,val5,strlen(val5)); strncat(reg,DataFileDelimiter,1); } - if(strstr(DataFileFields,"elapsed") != 0) { + if((DataFileFields & DATA_FIELD_ELAPSED) != 0) { strncat(reg,val3,strlen(val3)); strncat(reg,DataFileDelimiter,1); } diff --git a/getconf.c b/getconf.c index 32e38f4..456c249 100644 --- a/getconf.c +++ b/getconf.c @@ -26,8 +26,77 @@ #include "include/conf.h" #include "include/defs.h" +#define SET_LIST(list) list,sizeof(list)/sizeof(list[0]) + extern numlist hours, weekdays; +struct param_list +{ + //! The name of the value of the parameter. + const char *name; + //! The bit to set if the value is found. + unsigned long int value; + //! The value is invalid if any bit of this mask is set in the parameter. + unsigned long int exclude; +}; + +struct param_list report_type_values[]= +{ + {"users_sites",REPORT_TYPE_USERS_SITES,0}, + {"topusers",REPORT_TYPE_TOPUSERS,0}, + {"topsites",REPORT_TYPE_TOPSITES,0}, + {"sites_users",REPORT_TYPE_SITES_USERS,0}, + {"date_time",REPORT_TYPE_DATE_TIME,0}, + {"denied",REPORT_TYPE_DENIED,0}, + {"auth_failures",REPORT_TYPE_AUTH_FAILURES,0}, + {"site_user_time_date",REPORT_TYPE_SITE_USER_TIME_DATE,0}, + {"downloads",REPORT_TYPE_DOWNLOADS,0}, +}; + +struct param_list data_field_values[]= +{ + {"user",DATA_FIELD_USER,0}, + {"date",DATA_FIELD_DATE,0}, + {"time",DATA_FIELD_TIME,0}, + {"url",DATA_FIELD_URL,0}, + {"connect",DATA_FIELD_CONNECT,0}, + {"bytes",DATA_FIELD_BYTES,0}, + {"in_cache",DATA_FIELD_IN_CACHE,0}, + {"out_cache",DATA_FIELD_OUT_CACHE,0}, + {"elapsed",DATA_FIELD_ELAPSED,0}, +}; + +struct param_list topuserfields_values[]= +{ + {"NUM",TOPUSERFIELDS_NUM,0}, + {"DATE_TIME",TOPUSERFIELDS_DATE_TIME,0}, + {"USERID",TOPUSERFIELDS_USERID,0}, + {"CONNECT",TOPUSERFIELDS_CONNECT,0}, + {"BYTES",TOPUSERFIELDS_BYTES,0}, + {"%BYTES",TOPUSERFIELDS_SETYB,0}, + {"SETYB",TOPUSERFIELDS_SETYB,0}, + {"IN-CACHE-OUT",TOPUSERFIELDS_IN_CACHE_OUT,0}, + {"USED_TIME",TOPUSERFIELDS_USED_TIME,0}, + {"MILISEC",TOPUSERFIELDS_MILISEC,0}, + {"%TIME",TOPUSERFIELDS_PTIME,0}, + {"TOTAL",TOPUSERFIELDS_TOTAL,0}, + {"AVERAGE",TOPUSERFIELDS_AVERAGE,0}, +}; + +struct param_list userreportfields_values[]= +{ + {"CONNECT",USERREPORTFIELDS_CONNECT,0}, + {"BYTES",USERREPORTFIELDS_BYTES,0}, + {"%BYTES",USERREPORTFIELDS_SETYB,0}, + {"SETYB",USERREPORTFIELDS_SETYB,0}, + {"IN-CACHE-OUT",USERREPORTFIELDS_IN_CACHE_OUT,0}, + {"USED_TIME",USERREPORTFIELDS_USED_TIME,0}, + {"MILISEC",USERREPORTFIELDS_MILISEC,0}, + {"%TIME",USERREPORTFIELDS_PTIME,0}, + {"TOTAL",USERREPORTFIELDS_TOTAL,0}, + {"AVERAGE",USERREPORTFIELDS_AVERAGE,0}, +}; + static int is_param(const char *param,const char *buf) { int plen; @@ -172,6 +241,41 @@ static int getparam_bool(const char *param,char *buf,int *value) return(1); } +static int getparam_list(const char *param,struct param_list *options,int noptions,char *buf,unsigned long int *value) +{ + int plen; + char *str; + int i; + + plen=strlen(param); + if (strncmp(buf,param,plen) != 0) return(0); + buf+=plen; + if ((unsigned char)*buf>' ') return(0); + while (*buf && (unsigned char)*buf<=' ') buf++; + + *value=0UL; + while (*buf) { + str=buf; + while (*str && (unsigned char)*str>' ' && *str!=';') str++; + if (*str) { + *str++='\0'; + while (*str && ((unsigned char)*str<=' ' || *str==';')) str++; + } + for (i=0 ; i=noptions) { + fprintf(stderr,"SARG: Unknown value %s for parameter %s\n",buf,param); + exit(1); + } + if ((*value & options[i].exclude)!=0) { + fprintf(stderr,"SARG: Value %s conflicts with other selected values of parameter %s\n",buf,param); + exit(1); + } + *value|=options[i].value; + buf=str; + } + return(1); +} + static void parmtest(char *buf) { char wbuf[50]; @@ -280,7 +384,7 @@ static void parmtest(char *buf) if (getparam_string("temporary_dir",buf,TempDir,sizeof(TempDir))>0) return; - if (getparam_string("report_type",buf,ReportType,sizeof(ReportType))>0) return; + if (getparam_list("report_type",SET_LIST(report_type_values),buf,&ReportType)>0) return; if (getparam_string("output_dir",buf,OutputDir,sizeof(OutputDir))>0) return; @@ -354,17 +458,17 @@ static void parmtest(char *buf) if (getparam_bool("show_read_statistics",buf,&ShowReadStatistics)>0) return; - if (getparam_string("topuser_fields",buf,TopUserFields,sizeof(TopUserFields))>0) return; + if (getparam_list("topuser_fields",SET_LIST(topuserfields_values),buf,&TopUserFields)>0) return; if (getparam_bool("bytes_in_sites_users_report",buf,&BytesInSitesUsersReport)>0) return; - if (getparam_string("user_report_fields",buf,UserReportFields,sizeof(UserReportFields))>0) return; + if (getparam_list("user_report_fields",SET_LIST(userreportfields_values),buf,&UserReportFields)>0) return; if (getparam_string("datafile",buf,DataFile,sizeof(DataFile))>0) return; if (getparam_quoted("datafile_delimiter",buf,DataFileDelimiter,sizeof(DataFileDelimiter))>0) return; - if (getparam_string("datafile_fields",buf,DataFileFields,sizeof(DataFileFields))>0) return; + if (getparam_list("datafile_fields",SET_LIST(data_field_values),buf,&DataFileFields)>0) return; if (getparam_string("datafile_url",buf,DataFileUrl,sizeof(DataFileUrl))>0) return; diff --git a/html.c b/html.c index 79f174d..2e50ad7 100644 --- a/html.c +++ b/html.c @@ -60,7 +60,7 @@ void htmlrel(void) char siteind[MAXLEN]; struct getwordstruct gwarea; - if(strstr(ReportType,"users_sites") == 0) return; + if((ReportType & REPORT_TYPE_USERS_SITES) == 0) return; strcpy(tmp2,TempDir); strcat(tmp2,"/sargtmp.unsort"); @@ -264,22 +264,22 @@ void htmlrel(void) strcpy(val9,"colspan=\"2\""); bzero(val10, 255); - if(strstr(UserReportFields,"CONNECT") == 0) + if((UserReportFields & USERREPORTFIELDS_CONNECT) == 0) bzero(val3, 255); - if(strstr(UserReportFields,"BYTES") == 0) + if((UserReportFields & USERREPORTFIELDS_BYTES) == 0) bzero(val4, 255); - if(strstr(UserReportFields,"SETYB") == 0) + if((UserReportFields & USERREPORTFIELDS_SETYB) == 0) bzero(val11, 255); - if(strstr(UserReportFields,"IN-CACHE-OUT") == 0) { + if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) == 0) { bzero(val5, 255); bzero(val9, 255); strcpy(val10,""); } - if(strstr(UserReportFields,"USED_TIME") == 0) + if((UserReportFields & USERREPORTFIELDS_USED_TIME) == 0) bzero(val6, 255); - if(strstr(UserReportFields,"MILISEC") == 0) + if((UserReportFields & USERREPORTFIELDS_MILISEC) == 0) bzero(val7, 255); - if(strstr(UserReportFields,"%TIME") == 0) + if((UserReportFields & USERREPORTFIELDS_PTIME) == 0) bzero(val8, 255); fprintf(fp_ou,"%s%s%s%s%s%s%s%s\n",text[91],val3,val4,val11,val9,val5,val6,val7,val8); @@ -383,7 +383,7 @@ void htmlrel(void) snprintf(httplink,sizeof(httplink),"%s",urly,urly,url); } - if(strstr(ReportType,"site_user_time_date") != 0) { + if((ReportType & REPORT_TYPE_SITE_USER_TIME_DATE) != 0) { strcpy(ltext110,text[110]); for(s=ltext110; *s; ++s) *s=tolower(*s); @@ -407,33 +407,33 @@ void htmlrel(void) sprintf(val6,"%s",buildtime(nnelap)); sprintf(val7,"%3.2f%%",perc2); - if(strstr(UserReportFields,"CONNECT") == 0) { + if((UserReportFields & USERREPORTFIELDS_CONNECT) == 0) { bzero(wwork1, 255); bzero(hbc1, 30); } - if(strstr(UserReportFields,"BYTES") == 0) { + if((UserReportFields & USERREPORTFIELDS_BYTES) == 0) { bzero(wwork2, 255); bzero(hbc2, 30); } - if(strstr(UserReportFields,"MILISEC") == 0) { + if((UserReportFields & USERREPORTFIELDS_MILISEC) == 0) { bzero(wwork3, 255); bzero(hbc3, 30); } - if(strstr(UserReportFields,"SETYB") == 0) { + if((UserReportFields & USERREPORTFIELDS_SETYB) == 0) { bzero(val3, 255); bzero(hbc4, 30); } - if(strstr(UserReportFields,"IN-CACHE-OUT") == 0) { + if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) == 0) { bzero(val4, 255); bzero(val5, 255); bzero(hbc5, 30); bzero(hbc6, 30); } - if(strstr(UserReportFields,"USED_TIME") == 0) { + if((UserReportFields & USERREPORTFIELDS_USED_TIME) == 0) { bzero(val6, 255); bzero(hbc7, 30); } - if(strstr(UserReportFields,"%TIME") == 0) { + if((UserReportFields & USERREPORTFIELDS_PTIME) == 0) { bzero(val7, 255); bzero(hbc8, 30); } @@ -587,40 +587,38 @@ void htmlrel(void) strcpy(hbc8,"class=\"header2\""); strcpy(hbc9,"class=\"header\""); - if(strstr(UserReportFields,"CONNECT") == 0) { + if((UserReportFields & USERREPORTFIELDS_CONNECT) == 0) { bzero(wwork1, 255); bzero(hbc1, 30); } - if(strstr(UserReportFields,"BYTES") == 0) { + if((UserReportFields & USERREPORTFIELDS_BYTES) == 0) { bzero(wwork2, 255); bzero(hbc2, 30); } - if(strstr(UserReportFields,"MILISEC") == 0) { + if((UserReportFields & USERREPORTFIELDS_MILISEC) == 0) { bzero(wwork3, 255); bzero(hbc3, 30); } - if(strstr(UserReportFields,"SETYB") == 0) { + if((UserReportFields & USERREPORTFIELDS_SETYB) == 0) { bzero(val3, 255); bzero(hbc4, 30); } - if(strstr(UserReportFields,"IN-CACHE-OUT") == 0) { + if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) == 0) { bzero(val4, 255); bzero(hbc5, 30); - } - if(strstr(UserReportFields,"IN-CACHE-OUT") == 0) { bzero(val5, 255); bzero(hbc6, 30); } - if(strstr(UserReportFields,"USED_TIME") == 0) { + if((UserReportFields & USERREPORTFIELDS_USED_TIME) == 0) { bzero(val6, 255); bzero(hbc7, 30); } - if(strstr(UserReportFields,"%TIME") == 0) { + if((UserReportFields & USERREPORTFIELDS_PTIME) == 0) { bzero(val7, 255); bzero(hbc8, 30); } - if(strstr(UserReportFields,"TOTAL") != 0) { + if((UserReportFields & USERREPORTFIELDS_TOTAL) != 0) { fprintf(fp_ou,"%s%s%s%s%s%s%s%s%s\n",hbc9,text[107],hbc1,wwork1,hbc2,wwork2,hbc4,val3,hbc5,val4,hbc6,val5,hbc7,val6,hbc3,wwork3,hbc8,val7); } @@ -664,7 +662,7 @@ void htmlrel(void) // continue; // } - if (strstr(ReportType,"topuser") != 0) { + if ((ReportType & REPORT_TYPE_TOPUSERS) != 0) { strcpy(arqper,dirname); strcat(arqper,"/sarg-users"); @@ -711,28 +709,28 @@ void htmlrel(void) strcpy(hbc5,"class=\"header2\""); strcpy(hbc6,"class=\"header\""); - if(strstr(UserReportFields,"CONNECT") == 0) { + if((UserReportFields & USERREPORTFIELDS_CONNECT) == 0) { bzero(wwork1, 255); bzero(hbc1, 30); } - if(strstr(UserReportFields,"BYTES") == 0) { + if((UserReportFields & USERREPORTFIELDS_BYTES) == 0) { bzero(wwork2, 255); bzero(hbc2, 30); } - if(strstr(UserReportFields,"MILISEC") == 0) { + if((UserReportFields & USERREPORTFIELDS_MILISEC) == 0) { bzero(wwork3, 255); bzero(hbc3, 30); } - if(strstr(UserReportFields,"USED_TIME") == 0) { + if((UserReportFields & USERREPORTFIELDS_USED_TIME) == 0) { bzero(val6, 255); bzero(hbc4, 30); } - if(strstr(UserReportFields,"%TIME") == 0) { + if((UserReportFields & USERREPORTFIELDS_PTIME) == 0) { bzero(val7, 255); bzero(hbc5, 30); } - if(strstr(UserReportFields,"AVERAGE") != 0) { + if((UserReportFields & USERREPORTFIELDS_AVERAGE) != 0) { fprintf(fp_ou,"%s%s%s%s%s%s\n",hbc6,text[96],hbc1,wwork1,hbc2,wwork2,hbc4,val6,hbc3,wwork3,hbc5,val7); } } /* added */ diff --git a/include/conf.h b/include/conf.h index b58a70a..785801d 100755 --- a/include/conf.h +++ b/include/conf.h @@ -137,6 +137,49 @@ int mkstemps(char *template, int suffixlen); #define MAXLEN 20000 #define MAXLOGS 255 +#define REPORT_TYPE_USERS_SITES 0x0001UL +#define REPORT_TYPE_SITE_USER_TIME_DATE 0x0002UL +#define REPORT_TYPE_TOPUSERS 0x0004UL +#define REPORT_TYPE_TOPSITES 0x0008UL +#define REPORT_TYPE_SITES_USERS 0x0010UL +#define REPORT_TYPE_DATE_TIME 0x0020UL +#define REPORT_TYPE_DENIED 0x0040UL +#define REPORT_TYPE_AUTH_FAILURES 0x0080UL +#define REPORT_TYPE_DOWNLOADS 0x0100UL + +#define DATA_FIELD_USER 0x0001UL +#define DATA_FIELD_DATE 0x0002UL +#define DATA_FIELD_TIME 0x0004UL +#define DATA_FIELD_URL 0x0008UL +#define DATA_FIELD_CONNECT 0x0010UL +#define DATA_FIELD_BYTES 0x0020UL +#define DATA_FIELD_IN_CACHE 0x0040UL +#define DATA_FIELD_OUT_CACHE 0x0080UL +#define DATA_FIELD_ELAPSED 0x0100UL + +#define TOPUSERFIELDS_NUM 0x0001UL +#define TOPUSERFIELDS_DATE_TIME 0x0002UL +#define TOPUSERFIELDS_USERID 0x0004UL +#define TOPUSERFIELDS_CONNECT 0x0008UL +#define TOPUSERFIELDS_BYTES 0x0010UL +#define TOPUSERFIELDS_SETYB 0x0020UL +#define TOPUSERFIELDS_IN_CACHE_OUT 0x0040UL +#define TOPUSERFIELDS_USED_TIME 0x0080UL +#define TOPUSERFIELDS_MILISEC 0x0100UL +#define TOPUSERFIELDS_PTIME 0x0200UL +#define TOPUSERFIELDS_TOTAL 0x0400UL +#define TOPUSERFIELDS_AVERAGE 0x0800UL + +#define USERREPORTFIELDS_CONNECT 0x0001UL +#define USERREPORTFIELDS_BYTES 0x0002UL +#define USERREPORTFIELDS_SETYB 0x0004UL +#define USERREPORTFIELDS_IN_CACHE_OUT 0x0008UL +#define USERREPORTFIELDS_USED_TIME 0x0010UL +#define USERREPORTFIELDS_MILISEC 0x0020UL +#define USERREPORTFIELDS_PTIME 0x0040UL +#define USERREPORTFIELDS_TOTAL 0x0080UL +#define USERREPORTFIELDS_AVERAGE 0x0100UL + FILE *fp_tt; char outdir[MAXLEN]; @@ -181,7 +224,7 @@ int TopUsersNum; char ExcludeCodes[256]; char TopsitesSortField[15]; char TopsitesSortType[20]; -char ReportType[255]; +unsigned long int ReportType; char UserTabFile[255]; char warea[MAXLEN]; char name[MAXLEN]; @@ -236,11 +279,11 @@ char PrivacyStringColor[30]; char IncludeUsers[MAXLEN]; char ExcludeString[MAXLEN]; int SuccessfulMsg; -char TopUserFields[255]; -char UserReportFields[255]; +unsigned long int TopUserFields; +unsigned long int UserReportFields; char DataFile[MAXLEN]; char DataFileDelimiter[3]; -char DataFileFields[MAXLEN]; +unsigned long int DataFileFields; char DataFileUrl[20]; char SiteUserTimeDateType[10]; int ShowReadStatistics; diff --git a/log.c b/log.c index 299bc9e..8f4d76c 100644 --- a/log.c +++ b/log.c @@ -142,7 +142,7 @@ int main(int argc,char *argv[]) ConfigFile[0]='\0'; code[0]='\0'; LastLog=0; - ReportType[0]='\0'; + ReportType=0UL; UserTabFile[0]='\0'; BlockIt[0]='\0'; ExternalCSSFile[0]='\0'; @@ -191,10 +191,16 @@ int main(int argc,char *argv[]) strcpy(PrivacyString,"***.***.***.***"); strcpy(PrivacyStringColor,"blue"); SuccessfulMsg=1; - strcpy(TopUserFields,"NUM DATE_TIME USERID CONNECT BYTES %BYTES IN-CACHE-OUT USED_TIME MILISEC %TIME TOTAL AVERAGE"); - strcpy(UserReportFields,"CONNECT BYTES %BYTES IN-CACHE-OUT USED_TIME MILISEC %TIME TOTAL AVERAGE"); + TopUserFields=TOPUSERFIELDS_NUM | TOPUSERFIELDS_DATE_TIME | TOPUSERFIELDS_USERID | TOPUSERFIELDS_CONNECT | + TOPUSERFIELDS_BYTES | TOPUSERFIELDS_SETYB | TOPUSERFIELDS_IN_CACHE_OUT | + TOPUSERFIELDS_USED_TIME | TOPUSERFIELDS_MILISEC | TOPUSERFIELDS_PTIME | + TOPUSERFIELDS_TOTAL | TOPUSERFIELDS_AVERAGE; + UserReportFields=USERREPORTFIELDS_CONNECT | USERREPORTFIELDS_BYTES | USERREPORTFIELDS_SETYB | + USERREPORTFIELDS_IN_CACHE_OUT | USERREPORTFIELDS_USED_TIME | USERREPORTFIELDS_MILISEC | + USERREPORTFIELDS_PTIME | USERREPORTFIELDS_TOTAL | USERREPORTFIELDS_AVERAGE; strcpy(DataFileDelimiter,";"); - strcpy(DataFileFields,"user;date;time;url;connect;bytes;in_cache;out_cache;elapsed"); + DataFileFields=DATA_FIELD_USER | DATA_FIELD_DATE | DATA_FIELD_TIME | DATA_FIELD_URL | DATA_FIELD_CONNECT | + DATA_FIELD_BYTES | DATA_FIELD_IN_CACHE | DATA_FIELD_OUT_CACHE | DATA_FIELD_ELAPSED; strcpy(SiteUserTimeDateType,"table"); ShowReadStatistics=1; strcpy(IndexSortOrder,"D"); @@ -463,10 +469,6 @@ int main(int argc,char *argv[]) if(DataFile[0] != '\0') dataonly++; - subs(TopUserFields,sizeof(TopUserFields),"%BYTES","SETYB"); - - subs(UserReportFields,sizeof(UserReportFields),"%BYTES","SETYB"); - if(!NAccessLog) { strcpy(AccessLog[0],"/var/log/squid/access.log"); NAccessLog++; @@ -496,8 +498,11 @@ int main(int argc,char *argv[]) fhost++; } - if(ReportType[0] == '\0') - strcpy(ReportType,"topusers topsites users_sites sites_users date_time denied auth_failures site_user_time_date downloads"); + if(ReportType == 0) { + ReportType=REPORT_TYPE_TOPUSERS | REPORT_TYPE_TOPSITES | REPORT_TYPE_USERS_SITES | + REPORT_TYPE_SITES_USERS | REPORT_TYPE_DATE_TIME | REPORT_TYPE_DENIED | + REPORT_TYPE_AUTH_FAILURES | REPORT_TYPE_SITE_USER_TIME_DATE | REPORT_TYPE_DOWNLOADS; + } if(access(ExcludeUsers, R_OK) == 0) { getuexclude(ExcludeUsers,debug); @@ -686,7 +691,7 @@ int main(int argc,char *argv[]) sprintf ( sz_Download_Unsort , "%s/sarg/download.unsort", tmp); - if(strstr(ReportType,"denied") != 0) { + if((ReportType & REPORT_TYPE_DENIED) != 0) { if((fp_denied=MY_FOPEN(tmp4,"w"))==NULL) { fprintf(stderr, "%s: (log) %s: %s - %s\n",argv[0],text[45],tmp4,strerror(errno)); exit(1); @@ -694,7 +699,7 @@ int main(int argc,char *argv[]) } if(DataFile[0]=='\0') { - if(strstr(ReportType,"denied") != 0 || strstr(ReportType,"auth_failures") != 0) { + if((ReportType & REPORT_TYPE_DENIED) != 0 || (ReportType & REPORT_TYPE_AUTH_FAILURES) != 0) { if((fp_authfail=MY_FOPEN(tmp6,"w"))==NULL) { fprintf(stderr, "%s: (log) %s: %s - %s\n",argv[0],text[45],tmp6,strerror(errno)); exit(1); @@ -1140,7 +1145,7 @@ int main(int argc,char *argv[]) } } - if(strstr(ReportType,"denied") != 0) + if((ReportType & REPORT_TYPE_DENIED) != 0) strcpy(urly,url); if(ilf!=ILF_Sarg) { @@ -1397,7 +1402,7 @@ int main(int argc,char *argv[]) fprintf(fp_Download_Unsort,"%s\t%s\t%s\t%s\t%s\n",dia,hora,user,ip,download_url); } - if(strstr(ReportType,"denied") != 0 || strstr(ReportType,"auth_failures") != 0) { + if((ReportType & REPORT_TYPE_DENIED) != 0 || (ReportType & REPORT_TYPE_AUTH_FAILURES) != 0) { if(strstr(code,"DENIED/403") != 0) { fprintf(fp_denied, "%s\t%s\t%s\t%s\t%s\n",dia,hora,user,ip,urly); denied_count++; @@ -1558,7 +1563,7 @@ int main(int argc,char *argv[]) debuga("%s %s",text[123],arq_log); } - if(strstr(ReportType,"denied") != 0) { + if((ReportType & REPORT_TYPE_DENIED) != 0) { sprintf(csort,"sort -T \"%s\" -k 3,3 -k 5,5 -o \"%s\" \"%s\"",tmp,tmp5,tmp4); cstatus=system(csort); if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { @@ -1577,7 +1582,7 @@ int main(int argc,char *argv[]) gerarel(); unlink(tmp2); - if(strstr(ReportType,"denied") != 0) + if((ReportType & REPORT_TYPE_DENIED) != 0) unlink(tmp5); if(zip[0] != '\0' && strcmp(zip,"zcat") !=0) { diff --git a/report.c b/report.c index 6c095a0..cdfc35e 100644 --- a/report.c +++ b/report.c @@ -212,7 +212,7 @@ void gerarel(void) nbytes+=accbytes; nelap+=accelap; - if(strstr(ReportType,"site_user_time_date") != 0) { + if((ReportType & REPORT_TYPE_SITE_USER_TIME_DATE) != 0) { if(!ttopen) { ind2++; strcpy(siteind,accurl); @@ -326,7 +326,7 @@ void gerarel(void) totalger(wdirname, debug, outdir); if(email[0] == '\0') { - if(strstr(ReportType,"downloads") != 0) download_report(); + if((ReportType & REPORT_TYPE_DOWNLOADS) != 0) download_report(); if(DansGuardianConf[0] != '\0') { strcpy(wdirname,dirname); @@ -339,9 +339,9 @@ void gerarel(void) strcpy(wdirname,dirname); topuser(); - if(strstr(ReportType,"topsites") != 0) topsites(); + if((ReportType & REPORT_TYPE_TOPSITES) != 0) topsites(); - if(strstr(ReportType,"sites_users") != 0) siteuser(); + if((ReportType & REPORT_TYPE_SITES_USERS) != 0) siteuser(); gen_denied_report(); strcpy(wdirname,dirname); @@ -353,7 +353,7 @@ void gerarel(void) squidguard_report(); - if(strstr(ReportType,"users_sites") != 0) htmlrel(); + if((ReportType & REPORT_TYPE_USERS_SITES) != 0) htmlrel(); make_index(); @@ -388,7 +388,7 @@ static void maketmp(const char *user, const char *dirname, int debug, int indexo char wdirname[MAXLEN]; if(indexonly) return; - if(strstr(ReportType,"users_sites") == 0) return; + if((ReportType & REPORT_TYPE_USERS_SITES) == 0) return; strcpy(wdirname,tmp); strcat(wdirname,"/"); @@ -417,7 +417,7 @@ static void maketmp_hour(const char *user, const char *dirname, int indexonly) char wdirname[MAXLEN]; if(indexonly) return; - if(strstr(ReportType,"users_sites") == 0) return; + if((ReportType & REPORT_TYPE_USERS_SITES) == 0) return; strcpy(wdirname,tmp); strcat(wdirname,"/"); @@ -446,7 +446,7 @@ void gravatmp(const char *oldaccuser, const char *oldurl, long long int nacc, lo char wdirname[MAXLEN]; if(indexonly) return; - if(strstr(ReportType,"users_sites") == 0) return; + if((ReportType & REPORT_TYPE_USERS_SITES) == 0) return; if (snprintf(wdirname,sizeof(wdirname),"%s/%s.utmp",tmp,oldaccuser)>=sizeof(wdirname)) { fprintf(stderr,"SARG: Path too long %s/%s.utmp\n",tmp,oldaccuser); @@ -485,7 +485,7 @@ static void gravatmp_hora(const char *dirname, const char *user, const char *dat FILE *fp_ou; char wdirname[MAXLEN]; - if(indexonly || (strstr(ReportType,"users_sites") == 0)) return; + if(indexonly || ((ReportType & REPORT_TYPE_USERS_SITES) == 0)) return; if (snprintf(wdirname,sizeof(wdirname),"%s/%s.htmp",tmp,user)>=sizeof(wdirname)) { fprintf(stderr,"SARG: Path too long %s/%s.htmp\n",tmp,user); @@ -512,7 +512,7 @@ static void gravaporuser(const char *user, const char *dirname, const char *url, FILE *fp_ou; char wdirname[MAXLEN]; - if(indexonly || (strstr(ReportType,"users_sites") == 0)) return; + if(indexonly || ((ReportType & REPORT_TYPE_USERS_SITES) == 0)) return; if (snprintf(wdirname,sizeof(wdirname),"%s/%s.ip",tmp,user)>=sizeof(wdirname)) { fprintf(stderr,"SARG: Path too long %s/%s.ip\n",tmp,user); @@ -539,7 +539,7 @@ static void gravatmpf(const char *oldaccuser, const char *dirname, const char *o FILE *fp_ou; char wdirname[MAXLEN]; - if(indexonly || (strstr(ReportType,"users_sites") == 0)) return; + if(indexonly || ((ReportType & REPORT_TYPE_USERS_SITES) == 0)) return; if (snprintf(wdirname,sizeof(wdirname),"%s/%s.utmp",tmp,oldaccuser)>=sizeof(wdirname)) { fprintf(stderr,"SARG: Path too long %s/%s.utmp\n",tmp,oldaccuser); diff --git a/sort.c b/sort.c index d3ff056..b8a4547 100644 --- a/sort.c +++ b/sort.c @@ -43,7 +43,7 @@ void tmpsort(void) char order[4]="-r"; if(indexonly) return; - if(strstr(ReportType,"users_sites") == 0) return; + if((ReportType & REPORT_TYPE_USERS_SITES) == 0) return; strup(UserSortField); if(strcmp(UserSortField,"CONNECT") == 0) { diff --git a/topsites.c b/topsites.c index 4a70011..5d84b56 100644 --- a/topsites.c +++ b/topsites.c @@ -67,7 +67,7 @@ void topsites(void) sprintf(general3,"%s/sarg-general3",dirname); sprintf(per,"%s/sarg-period",dirname); - if (strstr(ReportType,"topusers") == 0) + if ((ReportType & REPORT_TYPE_TOPUSERS) == 0) sprintf(report,"%s/index.html",dirname); else sprintf(report,"%s/topsites.html",dirname); diff --git a/topuser.c b/topuser.c index bf98eca..d9ce8bb 100644 --- a/topuser.c +++ b/topuser.c @@ -280,17 +280,17 @@ void topuser(void) fputs("
\n",fp_top3); fputs("\n",fp_top3); - if(strstr(ReportType,"topsites") != 0 && !Privacy) fprintf(fp_top3,"\n",text[119]); - if(strstr(ReportType,"sites_users") != 0 && !Privacy) fprintf(fp_top3,"\n",text[85]); + if((ReportType & REPORT_TYPE_TOPSITES) != 0 && !Privacy) fprintf(fp_top3,"\n",text[119]); + if((ReportType & REPORT_TYPE_SITES_USERS) != 0 && !Privacy) fprintf(fp_top3,"\n",text[85]); if(dansguardian_count) fprintf(fp_top3,"\n",text[128]); if(squidguard_count) fprintf(fp_top3,"\n",text[122]); - if (strstr(ReportType,"downloads") != 0 && download_count && !Privacy && ndownload) fprintf(fp_top3,"\n",text[125]); - if (strstr(ReportType,"denied") != 0 && denied_count && !Privacy) fprintf(fp_top3,"\n",text[118]); - if (strstr(ReportType,"auth_failures") != 0 && authfail_count && !Privacy) fprintf(fp_top3,"\n",text[117]); + if ((ReportType & REPORT_TYPE_DOWNLOADS) != 0 && download_count && !Privacy && ndownload) fprintf(fp_top3,"\n",text[125]); + if ((ReportType & REPORT_TYPE_DENIED) != 0 && denied_count && !Privacy) fprintf(fp_top3,"\n",text[118]); + if ((ReportType & REPORT_TYPE_AUTH_FAILURES) != 0 && authfail_count && !Privacy) fprintf(fp_top3,"\n",text[117]); if(smartfilter) fprintf(fp_top3,"\n",text[116]); fputs("\n",fp_top3); - if (strstr(ReportType,"topuser") == 0) { + if ((ReportType & REPORT_TYPE_TOPUSERS) == 0) { fputs("\n\n",fp_top3); if (fp_top3) fclose (fp_top3); return; @@ -298,42 +298,42 @@ void topuser(void) strcpy(hbc10,"class=\"header\""); - if(strstr(TopUserFields,"NUM") == 0) { + if((TopUserFields & TOPUSERFIELDS_NUM) == 0) { bzero(val1, 255); bzero(hbc1, 30); } else { strcpy(val1,text[100]); strcpy(hbc1,"class=\"header\""); } - if(strstr(TopUserFields,"USERID") == 0) { + if((TopUserFields & TOPUSERFIELDS_USERID) == 0) { bzero(val2, 255); bzero(hbc2, 30); } else { strcpy(val2,text[98]); strcpy(hbc2,"class=\"header\""); } - if(strstr(TopUserFields,"CONNECT") == 0) { + if((TopUserFields & TOPUSERFIELDS_CONNECT) == 0) { bzero(val3, 255); bzero(hbc3, 30); } else { strcpy(val3,text[92]); strcpy(hbc3,"class=\"header\""); } - if(strstr(TopUserFields,"BYTES") == 0) { + if((TopUserFields & TOPUSERFIELDS_BYTES) == 0) { bzero(val4, 255); bzero(hbc4, 30); } else { strcpy(val4,text[93]); strcpy(hbc4,"class=\"header\""); } - if(strstr(TopUserFields,"SETYB") == 0) { + if((TopUserFields & TOPUSERFIELDS_SETYB) == 0) { bzero(val11, 255); bzero(hbc9, 30); } else { sprintf(val11,"%%%s",text[93]); strcpy(hbc9,"class=\"header\""); } - if(strstr(TopUserFields,"IN-CACHE-OUT") == 0) { + if((TopUserFields & TOPUSERFIELDS_IN_CACHE_OUT) == 0) { bzero(val5, 255); bzero(hbc5, 30); bzero(val9, 255); @@ -344,21 +344,21 @@ void topuser(void) strcpy(val9,"colspan=\"2\""); bzero(val10, 255); } - if(strstr(TopUserFields,"USED_TIME") == 0) { + if((TopUserFields & TOPUSERFIELDS_USED_TIME) == 0) { bzero(val6, 255); bzero(hbc6, 30); } else { strcpy(val6,text[94]); strcpy(hbc6,"class=\"header\""); } - if(strstr(TopUserFields,"MILISEC") == 0) { + if((TopUserFields & TOPUSERFIELDS_MILISEC) == 0) { bzero(val7, 255); bzero(hbc7, 30); } else { strcpy(val7,text[95]); strcpy(hbc7,"class=\"header\""); } - if(strstr(TopUserFields,"%TIME") == 0) { + if((TopUserFields & TOPUSERFIELDS_PTIME) == 0) { bzero(val8, 255); bzero(hbc8, 30); } else { @@ -459,7 +459,7 @@ void topuser(void) } } - if(strstr(ReportType,"date_time") != 0) { + if((ReportType & REPORT_TYPE_DATE_TIME) != 0) { sprintf(ltext110,"%s",text[110]); for(s=ltext110; *s; ++s) *s=tolower(*s); @@ -510,49 +510,49 @@ void topuser(void) strcpy(hbc9,"class=\"data\""); strcpy(hbc10,"class=\"data\""); - if(strstr(TopUserFields,"NUM") == 0) { + if((TopUserFields & TOPUSERFIELDS_NUM) == 0) { bzero(val1, 255); bzero(hbc1, 30); } - if(strstr(TopUserFields,"USERID") == 0) { + if((TopUserFields & TOPUSERFIELDS_USERID) == 0) { bzero(val2, 255); bzero(hbc2, 30); } - if(strstr(TopUserFields,"CONNECT") == 0) { + if((TopUserFields & TOPUSERFIELDS_CONNECT) == 0) { bzero(wwork1, 255); bzero(hbc3, 30); } - if(strstr(TopUserFields,"BYTES") == 0) { + if((TopUserFields & TOPUSERFIELDS_BYTES) == 0) { bzero(wwork2, 255); bzero(hbc4, 30); } - if(strstr(TopUserFields,"SETYB") == 0) { + if((TopUserFields & TOPUSERFIELDS_SETYB) == 0) { bzero(val3, 255); bzero(hbc5, 30); } - if(strstr(TopUserFields,"IN-CACHE-OUT") == 0) { + if((TopUserFields & TOPUSERFIELDS_IN_CACHE_OUT) == 0) { bzero(val4, 255); bzero(hbc6, 30); } - if(strstr(TopUserFields,"IN-CACHE-OUT") == 0) { + if((TopUserFields & TOPUSERFIELDS_IN_CACHE_OUT) == 0) { bzero(val5, 255); bzero(hbc7, 30); } - if(strstr(TopUserFields,"USED_TIME") == 0) { + if((TopUserFields & TOPUSERFIELDS_USED_TIME) == 0) { bzero(val6, 255); bzero(hbc8, 30); } - if(strstr(TopUserFields,"MILISEC") == 0) { + if((TopUserFields & TOPUSERFIELDS_MILISEC) == 0) { bzero(wwork3, 255); bzero(hbc9, 30); } - if(strstr(TopUserFields,"%TIME") == 0) { + if((TopUserFields & TOPUSERFIELDS_PTIME) == 0) { bzero(val7, 255); bzero(hbc10, 30); } - if(strstr(ReportType,"users_sites") == 0) { + if((ReportType & REPORT_TYPE_USERS_SITES) == 0) { href1[0]='\0'; href1end[0]='\0'; } @@ -595,33 +595,33 @@ void topuser(void) sprintf(val6,"%s",buildtime(ttnelap)); sprintf(val7,"%3.2f%%",perc2); - if(strstr(TopUserFields,"CONNECT") == 0) { + if((TopUserFields & TOPUSERFIELDS_CONNECT) == 0) { bzero(wwork1, 255); bzero(hbc1, 30); } - if(strstr(TopUserFields,"BYTES") == 0) { + if((TopUserFields & TOPUSERFIELDS_BYTES) == 0) { bzero(wwork2, 255); bzero(hbc2, 30); } - if(strstr(TopUserFields,"IN-CACHE-OUT") == 0) { + if((TopUserFields & TOPUSERFIELDS_IN_CACHE_OUT) == 0) { bzero(val4, 255); bzero(val5, 255); bzero(hbc3, 30); bzero(hbc4, 30); } - if(strstr(TopUserFields,"USED_TIME") == 0) { + if((TopUserFields & TOPUSERFIELDS_USED_TIME) == 0) { bzero(val6, 255); bzero(hbc5, 30); } - if(strstr(TopUserFields,"MILISEC") == 0) { + if((TopUserFields & TOPUSERFIELDS_MILISEC) == 0) { bzero(wwork3, 255); bzero(hbc6, 30); } - if(strstr(ReportType,"date_time") != 0) { - if(strstr(TopUserFields,"TOTAL") != 0) + if((ReportType & REPORT_TYPE_DATE_TIME) != 0) { + if((TopUserFields & TOPUSERFIELDS_TOTAL) != 0) sprintf(preg,"\n",hbc10,text[107],hbc1,wwork1,hbc2,wwork2,hbc3,val4,hbc4,val5,hbc5,val6,hbc6,wwork3); - } else if(strstr(TopUserFields,"TOTAL") != 0) + } else if((TopUserFields & TOPUSERFIELDS_TOTAL) != 0) sprintf(preg,"\n",hbc10,text[107],hbc1,wwork1,hbc2,wwork2,hbc3,val4,hbc4,val5,hbc5,val6,hbc6,wwork3); } @@ -639,33 +639,33 @@ void topuser(void) strcpy(wwork2,fixnum(tnbytes,1)); strcpy(wwork3,fixnum2(twork2,1)); - if(strstr(TopUserFields,"CONNECT") == 0) { + if((TopUserFields & TOPUSERFIELDS_CONNECT) == 0) { bzero(wwork1, 255); bzero(hbc1, 30); } - if(strstr(TopUserFields,"BYTES") == 0) { + if((TopUserFields & TOPUSERFIELDS_BYTES) == 0) { bzero(wwork2, 255); bzero(hbc2, 30); } - if(strstr(TopUserFields,"IN-CACHE-OUT") == 0) { + if((TopUserFields & TOPUSERFIELDS_IN_CACHE_OUT) == 0) { bzero(val4, 255); bzero(val5, 255); bzero(hbc3, 30); bzero(hbc4, 30); } - if(strstr(TopUserFields,"USED_TIME") == 0) { + if((TopUserFields & TOPUSERFIELDS_USED_TIME) == 0) { bzero(val6, 255); bzero(hbc5, 30); } - if(strstr(TopUserFields,"MILISEC") == 0) { + if((TopUserFields & TOPUSERFIELDS_MILISEC) == 0) { bzero(wwork3, 255); bzero(hbc6, 30); } if(ntopuser) { - if((strstr(ReportType,"date_time") != 0 && strstr(TopUserFields,"AVERAGE") != 0)) + if(((ReportType & REPORT_TYPE_DATE_TIME) != 0 && (TopUserFields & TOPUSERFIELDS_AVERAGE) != 0)) fprintf(fp_top3,"\n",hbc10,text[96],hbc1,wwork1,hbc2,wwork2,hbc3,buildtime(ttnelap/totuser),hbc4,wwork3); - else if(strstr(TopUserFields,"AVERAGE") != 0) + else if((TopUserFields & TOPUSERFIELDS_AVERAGE) != 0) fprintf(fp_top3,"\n",hbc10,text[96],hbc1,wwork1,hbc2,wwork2,hbc3,buildtime(ttnelap/totuser),hbc4,wwork3); } diff --git a/totday.c b/totday.c index 9d7b62d..e9e4417 100644 --- a/totday.c +++ b/totday.c @@ -48,7 +48,7 @@ void day_totalize(const char *tmp, const char *user, int indexonly) struct getwordstruct gwarea; if(indexonly) return; - if(strstr(ReportType,"users_sites") == 0) return; + if((ReportType & REPORT_TYPE_USERS_SITES) == 0) return; sprintf(wdirname,"%s/%s.htmp",tmp,user); sprintf(arqout,"%s/%s.day",tmp,user);

%s
%s
%s
%s
%s
%s
%s
%s
%s
%s
%s
%s
%s
%s%s%15s%s%s%s%s
%s%s%15s%s%s%s%s
%s%s%15s%s%s
%s%s%15s%s%s