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 };
-void getusers(char *pwdfile, int debug);
+static void getusers(const char *pwdfile, int debug);
void gethexclude(char *hexfile, int debug);
void getuexclude(char *uexfile, int debug);
void ttx(char *user);
char *argv[];
{
- FILE *fp_in = NULL, *fp_ou = NULL, *fp_denied=NULL, *fp_usr, *fp_authfail=NULL, *fp_log=NULL;
+ FILE *fp_in = NULL, *fp_ou = NULL, *fp_denied=NULL, *fp_authfail=NULL, *fp_log=NULL;
char sz_Download_Unsort[ 20000 ] ;
FILE * fp_Download_Unsort = NULL ;
long int max_elapsed=0;
time_t tt;
struct tm *t;
- unsigned long nreg=0;
off_t recs1=0;
unsigned long recs2=0;
struct rlimit rl;
case 'g':
strcpy(df,optarg);
break;
- case 'h':
- usage(argv[0]);
+ case 'h':
+ usage(argv[0]);
exit(0);
- break;
+ break;
case 'i':
iprel++;
break;
strcpy(hmf,optarg);
}
if(strlen(hm) > 5) {
- printf("SARG: time period must be MM or MM:SS. Exit.\n");
- exit(1);
+ printf("SARG: time period must be MM or MM:SS. Exit.\n");
+ exit(1);
}
bzero(whm,15);
if(strstr(hm,":") != 0) {
debugz++;
break;
case ':':
- fprintf(stderr, "Option -%c require an argument\n",optopt);
- errflg++;
- break;
+ fprintf(stderr, "Option -%c require an argument\n",optopt);
+ errflg++;
+ break;
case '?':
usage(argv[0]);
exit(1);
if(debug) debuga("Init");
if(ConfigFile[0] == '\0') sprintf(ConfigFile,"%s/sarg.conf",SYSCONFDIR);
- else if(access(ConfigFile, R_OK) != 0) {
- sprintf(msg,"Cannot open config file: %s - %s",ConfigFile,strerror(errno));
- debuga(msg);
- exit(1);
- }
-
+ if(access(ConfigFile, R_OK) != 0) {
+ sprintf(msg,"Cannot open config file: %s - %s",ConfigFile,strerror(errno));
+ debuga(msg);
+ exit(1);
+ }
+
if(access(ConfigFile, R_OK) == 0)
getconf();
-
+
if(realt) {
realtime();
exit(0);
dataonly=0;
if(DataFile[0] != '\0');
dataonly++;
-
+
str2=(char *)subs(TopUserFields,"%BYTES","SETYB");
strcpy(TopUserFields,str2);
-
+
str2=(char *)subs(UserReportFields,"%BYTES","SETYB");
strcpy(UserReportFields,str2);
convlog(warq[0], df, dfrom, duntil);
exit(0);
}
-
+
if(strcmp(site,"plit") == 0) {
splitlog(warq[0], df, dfrom, duntil, hexclude);
exit(0);
sprintf(msg,"Cannot open exclude_hosts file: %s - %s",hexclude,strerror(errno));
debuga(msg);
exit(1);
- } else {
- gethexclude(hexclude,debug);
- fhost++;
}
+ gethexclude(hexclude,debug);
+ fhost++;
}
if(ReportType[0] == '\0')
}
}
- if (UserTabFile[0] != '\0') {
- if(debug) {
- sprintf(msg,"%s: %s",text[86],UserTabFile);
- debuga(msg);
- }
- if((fp_usr=fopen(UserTabFile,"r"))==NULL) {
- fprintf(stderr, "%s: (log) %s: %s - %s\n",argv[0],text[45],UserTabFile,strerror(errno));
- exit(1);
- }
- fseek(fp_usr, 0, SEEK_END);
- nreg = ftell(fp_usr);
- fseek(fp_usr, 0, SEEK_SET);
- if((userfile=(char *) malloc(nreg+100))==NULL){
- fprintf(stderr, "%s ERROR: %s",argv[0],text[87]);
- exit(1);
- }
- bzero(userfile,nreg+100);
- strncat(userfile,":",1);
- z1=0;
- z2=1;
- while(fgets(buf,MAXLEN,fp_usr)!=NULL) {
- buf[strlen(buf)-1]='\0';
- if(strstr(buf,"\r") != 0) buf[strlen(buf)-1]='\0';
- if (getword_multisep(bufy,sizeof(bufy),buf,' ')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",UserTabFile);
- exit(1);
- }
- for(z1=0; z1<=strlen(bufy); z1++) {
- userfile[z2]=bufy[z1];
- z2++;
- }
- strncat(userfile,":",1);
- for(z1=0; z1<=strlen(buf); z1++) {
- userfile[z2]=buf[z1];
- z2++;
- }
- strncat(userfile,":",1);
- }
- fclose(fp_usr);
- }
+ read_usertab(UserTabFile);
sprintf ( sz_Download_Unsort , "%s/sarg/download.unsort", tmp);
bool_ShowReadStatistics = ( strcmp(ShowReadStatistics,"yes") == 0 ) ;
while(narq--) {
strcpy(arq,warq[iarq]);
- iarq++;
-
- strcpy(arqtt,arq);
- decomp(arq,zip,tmp);
- if(debug) {
- sprintf(msg, "%s: %s",text[7],arq);
- debuga(msg);
- }
+ iarq++;
-#if defined(HAVE_FOPEN64)
- if((fp_in=fopen64(arq,"r"))==NULL) {
-#else
- if((fp_in=fopen(arq,"r"))==NULL) {
-#endif
- fprintf(stderr, "%s: (log) %s: %s - %s\n",argv[0],text[8],arq,strerror(errno));
- exit(1);
- }
- fgets(bufz,sizeof(bufz),fp_in);
- if(!isalog && strncmp(bufz,"#Software: Mic",14) == 0) isalog++;
+ strcpy(arqtt,arq);
+ decomp(arq,zip,tmp);
+ if(debug) {
+ sprintf(msg, "%s: %s",text[7],arq);
+ debuga(msg);
+ }
- if(strncmp(bufz,"*** SARG Log ***",16) == 0) {
- if (getword(val2,sizeof(val2),arqtt,'-')<0 || getword(val2,sizeof(val2),arqtt,'_')<0 ||
- getword(val3,sizeof(val3),arqtt,'-')<0 || getword(val3,sizeof(val3),arqtt,'_')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+ if((fp_in=MY_FOPEN(arq,"r"))==NULL) {
+ fprintf(stderr, "%s: (log) %s: %s - %s\n",argv[0],text[8],arq,strerror(errno));
exit(1);
}
- sprintf(period,"%s-%s",val2,val3);
- sarglog=1;
- } else fseek(fp_in, 0, SEEK_SET);
+ fgets(bufz,sizeof(bufz),fp_in);
+ if(!isalog && strncmp(bufz,"#Software: Mic",14) == 0) isalog++;
- if(strcmp(ParsedOutputLog, "no") != 0 && !sarglog) {
- if(access(ParsedOutputLog,R_OK) != 0) {
- sprintf(csort,"%s",ParsedOutputLog);
- my_mkdir(csort);
- }
- sprintf(arq_log,"%s/sarg_temp.log",ParsedOutputLog);
-#if defined(HAVE_FOPEN64)
- if((fp_log=fopen64(arq_log,"w"))==NULL) {
-#else
- if((fp_log=fopen(arq_log,"w"))==NULL) {
-#endif
- fprintf(stderr, "%s: (log) %s: %s - %s\n",argv[0],text[8],arq_log,strerror(errno));
- exit(1);
+ if(strncmp(bufz,"*** SARG Log ***",16) == 0) {
+ if (getword(val2,sizeof(val2),arqtt,'-')<0 || getword(val2,sizeof(val2),arqtt,'_')<0 ||
+ getword(val3,sizeof(val3),arqtt,'-')<0 || getword(val3,sizeof(val3),arqtt,'_')<0) {
+ printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+ exit(1);
+ }
+ sprintf(period,"%s-%s",val2,val3);
+ sarglog=1;
+ } else fseek(fp_in, 0, SEEK_SET);
+
+ if(strcmp(ParsedOutputLog, "no") != 0 && !sarglog) {
+ if(access(ParsedOutputLog,R_OK) != 0) {
+ sprintf(csort,"%s",ParsedOutputLog);
+ my_mkdir(csort);
+ }
+ sprintf(arq_log,"%s/sarg_temp.log",ParsedOutputLog);
+ if((fp_log=MY_FOPEN(arq_log,"w"))==NULL) {
+ fprintf(stderr, "%s: (log) %s: %s - %s\n",argv[0],text[8],arq_log,strerror(errno));
+ exit(1);
+ }
+ fputs("*** SARG Log ***\n",fp_log);
}
- fputs("*** SARG Log ***\n",fp_log);
- }
- if(strstr(ReportType,"denied") != 0) {
-#if defined(HAVE_FOPEN64)
- if((fp_denied=fopen64(tmp4,"w"))==NULL) {
-#else
- if((fp_denied=fopen(tmp4,"w"))==NULL) {
-#endif
- fprintf(stderr, "%s: (log) %s: %s - %s\n",argv[0],text[45],tmp4,strerror(errno));
- exit(1);
+ if(strstr(ReportType,"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);
+ }
}
- }
- if(DataFile[0]=='\0') {
- if(strstr(ReportType,"denied") != 0 || strstr(ReportType,"auth_failures") != 0) {
-#if defined(HAVE_FOPEN64)
- if((fp_authfail=fopen64(tmp6,"w"))==NULL) {
-#else
- if((fp_authfail=fopen(tmp6,"w"))==NULL) {
-#endif
- fprintf(stderr, "%s: (log) %s: %s - %s\n",argv[0],text[45],tmp6,strerror(errno));
- exit(1);
+ if(DataFile[0]=='\0') {
+ if(strstr(ReportType,"denied") != 0 || strstr(ReportType,"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);
+ }
}
}
- }
- // pre-Read the file only if I have to show stats
- if(bool_ShowReadStatistics) {
- rewind(fp_in);
- recs1=0;
- recs2=0;
+ // pre-Read the file only if I have to show stats
+ if(bool_ShowReadStatistics) {
+ rewind(fp_in);
+ recs1=0;
+ recs2=0;
- while( fgets(bufz,sizeof(bufz),fp_in) != NULL ) recs1++;
- rewind(fp_in);
- printf("SARG: Records in file: " OFFSET_STRING ", reading: %3.2f%%\r",recs1,(float) 0);
- fflush( stdout ) ;
- }
-
- while(fgets(bufz,sizeof(bufz),fp_in)!=NULL) {
- recs2++;
- if( bool_ShowReadStatistics && ! --OutputNonZero) {
+ while( fgets(bufz,sizeof(bufz),fp_in) != NULL ) recs1++;
+ rewind(fp_in);
+ printf("SARG: Records in file: " OFFSET_STRING ", reading: %3.2f%%\r",recs1,(float) 0);
+ fflush( stdout ) ;
+ }
+
+ while(fgets(bufz,sizeof(bufz),fp_in)!=NULL) {
+ recs2++;
+ if( bool_ShowReadStatistics && ! --OutputNonZero) {
perc = recs2 * 100 ;
perc = perc / recs1 ;
printf("SARG: Records in file: " OFFSET_STRING ", reading: %3.2f%%\r",recs1,perc);
fflush (stdout);
OutputNonZero = REPORT_EVERY_X_LINES ;
- }
- if(strlen(bufz) > MAXLEN-1) continue;
- if(!bufz[0]) continue;
- if(strstr(bufz,"HTTP/0.0") != 0) continue;
- if(strstr(bufz,"logfile turned over") != 0) continue;
- if(bufz[0] == ' ') continue;
- if(strlen(bufz) < 58) continue;
-
- // Record only hours usage which is required
- tt = (time_t) strtoul( bufz, NULL, 10 );
- t = localtime( &tt );
-
- if( bsearch( &( t -> tm_wday ), weekdays.list, weekdays.len,
- sizeof( int ), compar ) == NULL )
- continue;
-
- if( bsearch( &( t -> tm_hour ), hours.list, hours.len,
- sizeof( int ), compar ) == NULL )
- continue;
-
- // exclude_string
- exstring=0;
- if(strlen(ExcludeString) > 0) {
- strcpy(warea,bufz);
- strcpy(html,ExcludeString);
- while(strstr(html,":") != 0) {
- if (getword_multisep(val1,sizeof(val1),html,':')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your exclusion string.\n");
- exit(1);
- }
- if((str=(char *) strstr(warea,val1)) != (char *) NULL )
- exstring++;
- }
- if((str=(char *) strstr(warea,html)) != (char *) NULL )
- exstring++;
- }
- if(exstring) continue;
-
- strcpy(bufy,bufz);
- if ((str = strchr(bufz, '\n')) != NULL)
- *str = '\0'; /* strip \n */
-
- totregsl++;
- common=0;
- if(debugm)
- printf("BUF=%s\n",bufz);
-
- if(!sarglog && !isalog) {
- if (getword(data,sizeof(data),bufz,' ')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your access.log file.\n");
- exit(1);
- }
- if((str=(char *) strstr(data, ".")) != (char *) NULL ) {
- if((str=(char *) strstr(str+1, ".")) != (char *) NULL ) {
- strcpy(ip,data);
- strcpy(elap,"0");
- if(squid24) {
- if (getword(user,sizeof(user),bufz,' ')<0 || getword(none,sizeof(none),bufz,' ')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
- exit(1);
- }
- } else {
- if (getword(none,sizeof(none),bufz,' ')<0 || getword(user,sizeof(user),bufz,' ')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
- exit(1);
- }
- }
- if (getword(data,sizeof(data),bufz,']')<0 || getword(fun,sizeof(fun),bufz,'"')<0 ||
- getword(fun,sizeof(fun),bufz,' ')<0 || getword(url,sizeof(url),bufz,' ')<0 ||
- getword(code2,sizeof(code2),bufz,' ')<0 || getword(code2,sizeof(code2),bufz,' ')<0 ||
- getword(tam,sizeof(tam),bufz,' ')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
- exit(1);
- }
- if((str=(char *) strstr(bufz, " ")) != (char *) NULL ) {
- if (getword(code,sizeof(code),bufz,' ')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
- exit(1);
- }
- }
- else strcpy(code,bufz);
-
- if ((str = strchr(code, ':')) != NULL)
- *str = '/';
-
- if(strcmp(tam,"\0") == 0)
- strcpy(tam,"0");
-
- common++;
- common_log=1;
- }
- }
-
- if(!common) {
- if (getword(elap,sizeof(elap),bufz,' ')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
- exit(1);
- }
- while(strcmp(elap,"") == 0 && strlen(bufz) > 0)
- if (getword(elap,sizeof(elap),bufz,' ')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
- exit(1);
- }
- if(strlen(elap) < 1) continue;
- if (getword(ip,sizeof(ip),bufz,' ')<0){
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
- exit(1);
- }
- if (getword(code,sizeof(code),bufz,' ')<0){
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
- exit(1);
- }
- if (getword(tam,sizeof(tam),bufz,' ')<0){
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
- exit(1);
- }
- if (getword(fun,sizeof(fun),bufz,' ')<0){
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
- exit(1);
- }
- if (getword(url,sizeof(url),bufz,' ')<0){
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
- exit(1);
- }
+ }
+ if(strlen(bufz) > MAXLEN-1) continue;
+ if(!bufz[0]) continue;
+ if(strstr(bufz,"HTTP/0.0") != 0) continue;
+ if(strstr(bufz,"logfile turned over") != 0) continue;
+ if(bufz[0] == ' ') continue;
+ if(strlen(bufz) < 58) continue;
+
+ // Record only hours usage which is required
+ tt = (time_t) strtoul( bufz, NULL, 10 );
+ t = localtime( &tt );
+
+ if( bsearch( &( t -> tm_wday ), weekdays.list, weekdays.len,
+ sizeof( int ), compar ) == NULL )
+ continue;
+
+ if( bsearch( &( t -> tm_hour ), hours.list, hours.len,
+ sizeof( int ), compar ) == NULL )
+ continue;
+
+ // exclude_string
+ exstring=0;
+ if(strlen(ExcludeString) > 0) {
+ strcpy(warea,bufz);
+ strcpy(html,ExcludeString);
+ while(strstr(html,":") != 0) {
+ if (getword_multisep(val1,sizeof(val1),html,':')<0) {
+ printf("SARG: Maybe you have a broken record or garbage in your exclusion string.\n");
+ exit(1);
+ }
+ if((str=(char *) strstr(warea,val1)) != (char *) NULL )
+ exstring++;
+ }
+ if((str=(char *) strstr(warea,html)) != (char *) NULL )
+ exstring++;
+ }
+ if(exstring) continue;
+
+ strcpy(bufy,bufz);
+ if ((str = strchr(bufz, '\n')) != NULL)
+ *str = '\0'; /* strip \n */
+
+ totregsl++;
+ common=0;
+ if(debugm)
+ printf("BUF=%s\n",bufz);
+
+ if(!sarglog && !isalog) {
+ if (getword(data,sizeof(data),bufz,' ')<0) {
+ printf("SARG: Maybe you have a broken record or garbage in your access.log file.\n");
+ exit(1);
+ }
+ if((str=(char *) strstr(data, ".")) != (char *) NULL ) {
+ if((str=(char *) strstr(str+1, ".")) != (char *) NULL ) {
+ strcpy(ip,data);
+ strcpy(elap,"0");
+ if(squid24) {
+ if (getword(user,sizeof(user),bufz,' ')<0 || getword(none,sizeof(none),bufz,' ')<0) {
+ printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+ exit(1);
+ }
+ } else {
+ if (getword(none,sizeof(none),bufz,' ')<0 || getword(user,sizeof(user),bufz,' ')<0) {
+ printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+ exit(1);
+ }
+ }
+ if (getword(data,sizeof(data),bufz,']')<0 || getword(fun,sizeof(fun),bufz,'"')<0 ||
+ getword(fun,sizeof(fun),bufz,' ')<0 || getword(url,sizeof(url),bufz,' ')<0 ||
+ getword(code2,sizeof(code2),bufz,' ')<0 || getword(code2,sizeof(code2),bufz,' ')<0 ||
+ getword(tam,sizeof(tam),bufz,' ')<0) {
+ printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+ exit(1);
+ }
+ if((str=(char *) strstr(bufz, " ")) != (char *) NULL ) {
+ if (getword(code,sizeof(code),bufz,' ')<0) {
+ printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+ exit(1);
+ }
+ }
+ else strcpy(code,bufz);
+
+ if ((str = strchr(code, ':')) != NULL)
+ *str = '/';
+
+ if(strcmp(tam,"\0") == 0)
+ strcpy(tam,"0");
+
+ common++;
+ common_log=1;
+ }
+ }
+
+ if(!common) {
+ if (getword(elap,sizeof(elap),bufz,' ')<0) {
+ printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+ exit(1);
+ }
+ while(strcmp(elap,"") == 0 && strlen(bufz) > 0)
+ if (getword(elap,sizeof(elap),bufz,' ')<0) {
+ printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+ exit(1);
+ }
+ if(strlen(elap) < 1) continue;
+ if (getword(ip,sizeof(ip),bufz,' ')<0){
+ printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+ exit(1);
+ }
+ if (getword(code,sizeof(code),bufz,' ')<0){
+ printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+ exit(1);
+ }
+ if (getword(tam,sizeof(tam),bufz,' ')<0){
+ printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+ exit(1);
+ }
+ if (getword(fun,sizeof(fun),bufz,' ')<0){
+ printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+ exit(1);
+ }
+ if (getword(url,sizeof(url),bufz,' ')<0){
+ printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+ exit(1);
+ }
// while (strstr(bufz,"%20") != 0) {
// getword(warea,bufz,' ');
// strcat(url,warea);
// }
- if (getword(user,sizeof(user),bufz,' ')<0){
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
- exit(1);
- }
- squid_log=1;
- }
- } else if(!isalog) {
- if (getword(data,sizeof(data),bufz,' ')<0){
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
- exit(1);
- }
- if (getword(hora,sizeof(hora),bufz,' ')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
- exit(1);
- }
- if (getword(user,sizeof(user),bufz,' ')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
- exit(1);
- }
- if (getword(ip,sizeof(ip),bufz,' ')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
- exit(1);
- }
- if (getword(url,sizeof(url),bufz,' ')<0){
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
- exit(1);
- }
- if (getword(tam,sizeof(tam),bufz,' ')<0){
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
- exit(1);
- }
- if (getword(code,sizeof(code),bufz,' ')<0){
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
- exit(1);
- }
- if (getword(elap,sizeof(elap),bufz,' ')<0){
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
- exit(1);
- }
- if (getword(smartfilter,sizeof(smartfilter),bufz,' ')<0){
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
- exit(1);
- }
- } else if(isalog) {
- if(!i0) {
- if (getword(val1,sizeof(val1),bufz,' ')<0){
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
- exit(1);
- }
- while(strstr(bufz,"\t") != 0) {
- if (getword(val1,sizeof(val1),bufz,'\t')<0){
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
- exit(1);
- }
- i0++;
- if(strcmp(val1,"c-ip") == 0) i1=i0;
- if(strcmp(val1,"cs-username") == 0) i2=i0;
- if(strcmp(val1,"date") == 0) i3=i0;
- if(strcmp(val1,"time") == 0) i4=i0;
- if(strcmp(val1,"time-taken") == 0) i5=i0;
- if(strcmp(val1,"sc-bytes") == 0) i6=i0;
- if(strcmp(val1,"cs-uri") == 0) i7=i0;
- if(strcmp(val1,"sc-status") == 0) i8=i0;
- }
- }
- fgets(bufz,sizeof(bufz),fp_in);
- strcpy(val1,bufz);
- for(x=0; x<=i1-1; x++) {
- if (getword3(ip,sizeof(ip),val1,'\t')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
- exit(1);
- }
- }
- strcpy(val1,bufz);
- for(x=0; x<=i2-1; x++) {
- if (getword3(user,sizeof(user),val1,'\t')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
- exit(1);
- }
- }
- strcpy(val1,bufz);
- for(x=0; x<=i3-1; x++) {
- if (getword3(data,sizeof(data),val1,'\t')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
- exit(1);
- }
- }
- strcpy(val1,bufz);
- for(x=0; x<=i4-1; x++) {
- if (getword3(hora,sizeof(hora),val1,'\t')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
- exit(1);
- }
- }
- strcpy(val1,bufz);
- for(x=0; x<=i5-1; x++) {
- if (getword3(elap,sizeof(elap),val1,'\t')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
- exit(1);
- }
- }
- strcpy(val1,bufz);
- for(x=0; x<=i6-1; x++) {
- if (getword3(tam,sizeof(tam),val1,'\t')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
- exit(1);
- }
- }
- strcpy(val1,bufz);
- for(x=0; x<=i7-1; x++) {
- if (getword3(url,sizeof(url),val1,'\t')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
- exit(1);
- }
- }
- strcpy(val1,bufz);
- for(x=0; x<=i8-1; x++) {
- if (getword3(code,sizeof(code),val1,'\t')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
- exit(1);
- }
- }
-
- if(strcmp(code,"401") == 0 || strcmp(code,"403") == 0 || strcmp(code,"407") == 0) {
- sprintf(val1,"DENIED/%s",code);
- strcpy(code,val1);
- }
- if (getword(ano,sizeof(ano),data,'-')<0){
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
- exit(1);
- }
- if (getword(mes,sizeof(mes),data,'-')<0){
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
- exit(1);
- }
- strcpy(dia,data);
- conv_month_name(mes);
- sprintf(data," %s/%s/%s:%s",dia,mes,ano,hora);
- }
-
- if(strlen(user) > 150) {
- totregsx++;
- continue;
- }
-
- // include_users
- if(strlen(IncludeUsers) > 0) {
- sprintf(val1,":%s:",user);
- if((str=(char *) strstr(IncludeUsers,val1)) == (char *) NULL )
- continue;
- }
-
- if(excode) {
- if(vercode(code)) {
- totregsx++;
- continue;
- }
- }
-
- if(testvaliduserchar(user))
- continue;
-
- if(strstr(user,"%20") != 0) {
- if (getword(w,sizeof(w),user,'%')<0) {
- printf("SARG: Maybe you have a broken user in your %s file.\n",arq);
- exit(1);
- }
- strcpy(user,w);
- }
-
- while(strstr(user,"%5c") != 0) {
- if (getword_multisep(w,sizeof(w),user,'%')<0){
- printf("SARG: Maybe you have a broken user in your %s file.\n",arq);
- exit(1);
- }
- strcpy(wuser,user+2);
- sprintf(user,"%s.%s",w,wuser);
- }
-
- str=user;
- for(z1=0; str[z1]; z1++) {
- if(isalnum(str[z1]) || ispunct(str[z1])) {
- if(str[z1]=='.') dotinuser++;
- if(str[z1]=='?' || str[z1]=='.' || str[z1]==':' || str[z1]=='/' || str[z1]=='\\')
- str[z1]='_';
- }
- }
-
- strlow(user);
- if(strncmp(NtlmUserFormat,"user",4) == 0) {
- if(strstr(user,"_") != 0)
- if (getword_multisep(warea,sizeof(warea),user,'_')<0){
- printf("SARG: Maybe you have a broken user in your %s file.\n",arq);
- exit(1);
- }
- if(strstr(user,"+") != 0)
- if (getword_multisep(warea,sizeof(warea),user,'+')<0){
- printf("SARG: Maybe you have a broken user in your %s file.\n",arq);
- exit(1);
- }
- }
-
- if(strstr(ReportType,"denied") != 0)
- strcpy(urly,url);
-
- if(strlen(DownloadSuffix)) {
- suffix[0]='\0';
- download_flag=0;
- if(strncmp(url+strlen(url)-4,".",1) == 0)
- strcpy(suffix,url+strlen(url)-3);
- else strcpy(suffix,url+strlen(url)-4);
- if(strstr(DownloadSuffix,suffix) != 0) {
- strcpy(download_url,url);
- download_flag=1;
- download_count++;
- }
- }
-
- if (strchr(url,'/')) {
- if (getword(w,sizeof(w),url,'/')<0){
- printf("SARG: Maybe you have a broken url in your %s file.\n",arq);
- exit(1);
- }
- if (getword(w,sizeof(w),url,'/')<0){
- printf("SARG: Maybe you have a broken url in your %s file.\n",arq);
- exit(1);
- }
- if (!strchr(url,'/')) {
- totregsx++;
- continue;
- }
- }
-
- if(strcmp(LongUrl,"no") == 0) {
- if (getword_multisep(w,sizeof(w),url,'/')<0){
- printf("SARG: Maybe you have a broken url in your %s file.\n",arq);
- exit(1);
- }
- strcpy(url,w);
- if(strlen(url) > 512 && strstr(url,"%") != 0) {
- if (getword_multisep(w,sizeof(w),url,'%')<0){
- printf("SARG: Maybe you have a broken url in your %s file.\n",arq);
- exit(1);
- }
- strcpy(url,w);
- }
- }
-
- if(!sarglog) {
- if(!common && !isalog) {
- tt=atoi(data);
- t=localtime(&tt);
-
- strftime(tbuf2, 127, "%H%M", t);
- if(strncmp(df,"u",1) == 0)
- strftime(tbuf, 127, "%Y%b%d", t);
- if(strncmp(df,"e",1) == 0)
- strftime(tbuf, 127, "%d%b%Y", t);
- if(strncmp(df,"w",1) == 0) {
- strcpy(IndexTree,"file");
- strftime(tbuf, 127, "%Y.%U", t);
- }
-
- strftime(dia, 127, "%d/%m/%Y", t);
- strftime(wdata, 127, "%Y%m%d", t);
-
- idata=atoi(wdata);
-
- if(strncmp(df,"u",1)==0)
- strftime(dia, 127, "%m/%d/%Y", t);
- sprintf(hora,"%02d:%02d:%02d",t->tm_hour,t->tm_min,t->tm_sec);
- } else {
- strcpy(wtemp,data+1);
- if (getword_multisep(data,sizeof(data),wtemp,':')<0){
- printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
- exit(1);
- }
- if (getword_multisep(hora,sizeof(hora),wtemp,' ')<0){
- printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
- exit(1);
- }
- if (getword_multisep(dia,sizeof(dia),data,'/')<0){
- printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
- exit(1);
- }
- if (getword_multisep(mes,sizeof(mes),data,'/')<0){
- printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
- exit(1);
- }
- if (getword_multisep(ano,sizeof(ano),data,'/')<0){
- printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
- exit(1);
- }
-
- if(strcmp(df,"u") == 0)
- sprintf(tbuf,"%s%s%s",ano,mes,dia);
- if(strcmp(df,"e") == 0)
- sprintf(tbuf,"%s%s%s",dia,mes,ano);
- builddia(dia,mes,ano,df,wdata);
- idata=atoi(wdata);
- }
- } else {
- if (getword_multisep(mes,sizeof(mes),data,'/')<0){
- printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
- exit(1);
- }
- if (getword_multisep(dia,sizeof(dia),data,'/')<0){
- printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
- exit(1);
- }
- if (getword_multisep(ano,sizeof(ano),data,0)<0){
- printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
- exit(1);
- }
- }
-
- if(debugm)
- printf("DATE=%s IDATA=%d DFROM=%d DUNTIL=%d\n",date,idata,dfrom,duntil);
-
- l=1;
- if(strlen(us)>0){
- if(strcmp(user,us)==0)
- l=1;else l=0;
- }
-
- if(l){
- if(strlen(addr)>0){
- if(strcmp(addr,ip)==0)
- l=1;else l=0;
- }
- if(fhost) {
+ if (getword(user,sizeof(user),bufz,' ')<0){
+ printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+ exit(1);
+ }
+ squid_log=1;
+ }
+ } else if(!isalog) {
+ if (getword(data,sizeof(data),bufz,' ')<0){
+ printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+ exit(1);
+ }
+ if (getword(hora,sizeof(hora),bufz,' ')<0) {
+ printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+ exit(1);
+ }
+ if (getword(user,sizeof(user),bufz,' ')<0) {
+ printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+ exit(1);
+ }
+ if (getword(ip,sizeof(ip),bufz,' ')<0) {
+ printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+ exit(1);
+ }
+ if (getword(url,sizeof(url),bufz,' ')<0){
+ printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+ exit(1);
+ }
+ if (getword(tam,sizeof(tam),bufz,' ')<0){
+ printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+ exit(1);
+ }
+ if (getword(code,sizeof(code),bufz,' ')<0){
+ printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+ exit(1);
+ }
+ if (getword(elap,sizeof(elap),bufz,' ')<0){
+ printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+ exit(1);
+ }
+ if (getword(smartfilter,sizeof(smartfilter),bufz,' ')<0){
+ printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+ exit(1);
+ }
+ } else if(isalog) {
+ if(!i0) {
+ if (getword(val1,sizeof(val1),bufz,' ')<0){
+ printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+ exit(1);
+ }
+ while(strstr(bufz,"\t") != 0) {
+ if (getword(val1,sizeof(val1),bufz,'\t')<0){
+ printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+ exit(1);
+ }
+ i0++;
+ if(strcmp(val1,"c-ip") == 0) i1=i0;
+ if(strcmp(val1,"cs-username") == 0) i2=i0;
+ if(strcmp(val1,"date") == 0) i3=i0;
+ if(strcmp(val1,"time") == 0) i4=i0;
+ if(strcmp(val1,"time-taken") == 0) i5=i0;
+ if(strcmp(val1,"sc-bytes") == 0) i6=i0;
+ if(strcmp(val1,"cs-uri") == 0) i7=i0;
+ if(strcmp(val1,"sc-status") == 0) i8=i0;
+ }
+ }
+ fgets(bufz,sizeof(bufz),fp_in);
+ strcpy(val1,bufz);
+ for(x=0; x<=i1-1; x++) {
+ if (getword3(ip,sizeof(ip),val1,'\t')<0) {
+ printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+ exit(1);
+ }
+ }
+ strcpy(val1,bufz);
+ for(x=0; x<=i2-1; x++) {
+ if (getword3(user,sizeof(user),val1,'\t')<0) {
+ printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+ exit(1);
+ }
+ }
+ strcpy(val1,bufz);
+ for(x=0; x<=i3-1; x++) {
+ if (getword3(data,sizeof(data),val1,'\t')<0) {
+ printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+ exit(1);
+ }
+ }
+ strcpy(val1,bufz);
+ for(x=0; x<=i4-1; x++) {
+ if (getword3(hora,sizeof(hora),val1,'\t')<0) {
+ printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+ exit(1);
+ }
+ }
+ strcpy(val1,bufz);
+ for(x=0; x<=i5-1; x++) {
+ if (getword3(elap,sizeof(elap),val1,'\t')<0) {
+ printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+ exit(1);
+ }
+ }
+ strcpy(val1,bufz);
+ for(x=0; x<=i6-1; x++) {
+ if (getword3(tam,sizeof(tam),val1,'\t')<0) {
+ printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+ exit(1);
+ }
+ }
+ strcpy(val1,bufz);
+ for(x=0; x<=i7-1; x++) {
+ if (getword3(url,sizeof(url),val1,'\t')<0) {
+ printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+ exit(1);
+ }
+ }
+ strcpy(val1,bufz);
+ for(x=0; x<=i8-1; x++) {
+ if (getword3(code,sizeof(code),val1,'\t')<0) {
+ printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+ exit(1);
+ }
+ }
+
+ if(strcmp(code,"401") == 0 || strcmp(code,"403") == 0 || strcmp(code,"407") == 0) {
+ sprintf(val1,"DENIED/%s",code);
+ strcpy(code,val1);
+ }
+ if (getword(ano,sizeof(ano),data,'-')<0){
+ printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+ exit(1);
+ }
+ if (getword(mes,sizeof(mes),data,'-')<0){
+ printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+ exit(1);
+ }
+ strcpy(dia,data);
+ conv_month_name(mes);
+ sprintf(data," %s/%s/%s:%s",dia,mes,ano,hora);
+ }
+
+ if(strlen(user) > 150) {
+ totregsx++;
+ continue;
+ }
+
+ // include_users
+ if(strlen(IncludeUsers) > 0) {
+ sprintf(val1,":%s:",user);
+ if((str=(char *) strstr(IncludeUsers,val1)) == (char *) NULL )
+ continue;
+ }
+
+ if(excode) {
+ if(vercode(code)) {
+ totregsx++;
+ continue;
+ }
+ }
+
+ if(testvaliduserchar(user))
+ continue;
+
+ if(strstr(user,"%20") != 0) {
+ if (getword(w,sizeof(w),user,'%')<0) {
+ printf("SARG: Maybe you have a broken user in your %s file.\n",arq);
+ exit(1);
+ }
+ strcpy(user,w);
+ }
+
+ while(strstr(user,"%5c") != 0) {
+ if (getword_multisep(w,sizeof(w),user,'%')<0){
+ printf("SARG: Maybe you have a broken user in your %s file.\n",arq);
+ exit(1);
+ }
+ strcpy(wuser,user+2);
+ sprintf(user,"%s.%s",w,wuser);
+ }
+
+ str=user;
+ for(z1=0; str[z1]; z1++) {
+ if(isalnum(str[z1]) || ispunct(str[z1])) {
+ if(str[z1]=='.') dotinuser++;
+ if(str[z1]=='?' || str[z1]=='.' || str[z1]==':' || str[z1]=='/' || str[z1]=='\\')
+ str[z1]='_';
+ }
+ }
+
+ strlow(user);
+ if(strncmp(NtlmUserFormat,"user",4) == 0) {
+ if(strstr(user,"_") != 0)
+ if (getword_multisep(warea,sizeof(warea),user,'_')<0){
+ printf("SARG: Maybe you have a broken user in your %s file.\n",arq);
+ exit(1);
+ }
+ if(strstr(user,"+") != 0)
+ if (getword_multisep(warea,sizeof(warea),user,'+')<0){
+ printf("SARG: Maybe you have a broken user in your %s file.\n",arq);
+ exit(1);
+ }
+ }
+
+ if(strstr(ReportType,"denied") != 0)
+ strcpy(urly,url);
+
+ if(strlen(DownloadSuffix)) {
+ suffix[0]='\0';
+ download_flag=0;
+ if(strncmp(url+strlen(url)-4,".",1) == 0)
+ strcpy(suffix,url+strlen(url)-3);
+ else strcpy(suffix,url+strlen(url)-4);
+ if(strstr(DownloadSuffix,suffix) != 0) {
+ strcpy(download_url,url);
+ download_flag=1;
+ download_count++;
+ }
+ }
+
+ if (strchr(url,'/')) {
+ if (getword(w,sizeof(w),url,'/')<0){
+ printf("SARG: Maybe you have a broken url in your %s file.\n",arq);
+ exit(1);
+ }
+ if (getword(w,sizeof(w),url,'/')<0){
+ printf("SARG: Maybe you have a broken url in your %s file.\n",arq);
+ exit(1);
+ }
+ if (!strchr(url,'/')) {
+ totregsx++;
+ continue;
+ }
+ }
+
+ if(strcmp(LongUrl,"no") == 0) {
+ if (getword_multisep(w,sizeof(w),url,'/')<0){
+ printf("SARG: Maybe you have a broken url in your %s file.\n",arq);
+ exit(1);
+ }
+ strcpy(url,w);
+ if(strlen(url) > 512 && strstr(url,"%") != 0) {
+ if (getword_multisep(w,sizeof(w),url,'%')<0){
+ printf("SARG: Maybe you have a broken url in your %s file.\n",arq);
+ exit(1);
+ }
+ strcpy(url,w);
+ }
+ }
+
+ if(!sarglog) {
+ if(!common && !isalog) {
+ tt=atoi(data);
+ t=localtime(&tt);
+
+ strftime(tbuf2, 127, "%H%M", t);
+ if(strncmp(df,"u",1) == 0)
+ strftime(tbuf, 127, "%Y%b%d", t);
+ if(strncmp(df,"e",1) == 0)
+ strftime(tbuf, 127, "%d%b%Y", t);
+ if(strncmp(df,"w",1) == 0) {
+ strcpy(IndexTree,"file");
+ strftime(tbuf, 127, "%Y.%U", t);
+ }
+
+ strftime(dia, 127, "%d/%m/%Y", t);
+ strftime(wdata, 127, "%Y%m%d", t);
+
+ idata=atoi(wdata);
+
+ if(strncmp(df,"u",1)==0)
+ strftime(dia, 127, "%m/%d/%Y", t);
+ sprintf(hora,"%02d:%02d:%02d",t->tm_hour,t->tm_min,t->tm_sec);
+ } else {
+ strcpy(wtemp,data+1);
+ if (getword_multisep(data,sizeof(data),wtemp,':')<0){
+ printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
+ exit(1);
+ }
+ if (getword_multisep(hora,sizeof(hora),wtemp,' ')<0){
+ printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
+ exit(1);
+ }
+ if (getword_multisep(dia,sizeof(dia),data,'/')<0){
+ printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
+ exit(1);
+ }
+ if (getword_multisep(mes,sizeof(mes),data,'/')<0){
+ printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
+ exit(1);
+ }
+ if (getword_multisep(ano,sizeof(ano),data,'/')<0){
+ printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
+ exit(1);
+ }
+
+ if(strcmp(df,"u") == 0)
+ sprintf(tbuf,"%s%s%s",ano,mes,dia);
+ if(strcmp(df,"e") == 0)
+ sprintf(tbuf,"%s%s%s",dia,mes,ano);
+ builddia(dia,mes,ano,df,wdata);
+ idata=atoi(wdata);
+ }
+ } else {
+ if (getword_multisep(mes,sizeof(mes),data,'/')<0){
+ printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
+ exit(1);
+ }
+ if (getword_multisep(dia,sizeof(dia),data,'/')<0){
+ printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
+ exit(1);
+ }
+ if (getword_multisep(ano,sizeof(ano),data,0)<0){
+ printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
+ exit(1);
+ }
+ }
+
+ if(debugm)
+ printf("DATE=%s IDATA=%d DFROM=%d DUNTIL=%d\n",date,idata,dfrom,duntil);
+
+ l=1;
+ if(strlen(us)>0){
+ if(strcmp(user,us)==0)
+ l=1;
+ else
+ l=0;
+ }
+
+ if(l){
+ if(strlen(addr)>0){
+ if(strcmp(addr,ip)==0)
+ l=1;else l=0;
+ }
+ if(fhost) {
// l=vhexclude(excludefile,ip);
- l=vhexclude(excludefile,url);
- if(!l)
- totregsx++;
- }
- }
-
- if(l){
- if(strlen(date) > 0){
- if(idata >= dfrom && idata <= duntil)
- l=1;else l=0;
- }
- }
- if(l){
- if(strlen(hm)>0) {
- strcpy(whm,hora);
- bzero(hmr,15);
- chm++;
- while(chm) {
- if (getword_multisep(warea,sizeof(warea),whm,':')<0){
- printf("SARG: Maybe you have a broken time in your %s file.\n",arq);
- exit(1);
- }
- strncat(hmr,warea,2);
- chm--;
- }
- strncat(hmr,whm,2);
-
- if(atoi(hmr) >= atoi(hm) && atoi(hmr) <= atoi(hmf))
- l=1;else l=0;
- }
- }
- if(l){
- if(strlen(site)>0){
- if(strstr(url,site)!=0)
- l=1;else l=0;
- }
- }
-
- if(userip)
- strcpy(user,ip);
-
- if(strcmp(user,"-") == 0 || strcmp(user," ") == 0 || strcmp(user,"") == 0) {
- if(strcmp(RecordsWithoutUser,"ip") == 0)
- strcpy(user,ip);
- if(strcmp(RecordsWithoutUser,"ignore") == 0)
- continue;
- if(strcmp(RecordsWithoutUser,"everybody") == 0)
- strcpy(user,"everybody");
- }
-
- if(dotinuser) {
- str2=(char *)subs(user,"_",".");
- strcpy(user,str2);
- dotinuser=0;
- }
-
- if(puser) {
- sprintf(wuser,":%s:",user);
- if(strstr(userfile, wuser) == 0)
- continue;
- }
-
- if(l) {
- if(fuser) {
- l=vuexclude(excludeuser,user);
- if(!l)
- totregsx++;
- }
- }
-
- if(l) {
- if(userip)
- fixip(user);
- }
-
- if(l&&max_elapsed) {
- if(atol(elap)>max_elapsed) {
- elap[0]='0';
- elap[1]='\0';
- }
- }
-
- if(l) {
- if(strcmp(user,"-") !=0 && strlen(url) > 0 && strcmp(user," ") !=0 && strcmp(user,"") !=0 && strcmp(user,":") !=0){
- if((str=(char *) strstr(bufz, "[SmartFilter:")) != (char *) NULL ) {
- str[strlen(str)-1]='\0';
- sprintf(smartfilter,"\"%s\"",str+1);
- } else sprintf(smartfilter,"\"\"");
-
- sprintf(bufz, "%s %s %s %s %s %s %s %s %s\n",dia,hora,user,ip,url,tam,code,elap,smartfilter);
+ l=vhexclude(excludefile,url);
+ if(!l)
+ totregsx++;
+ }
+ }
-#ifdef LEGACY_WRITE_USER
- sprintf(tmp3,"%s/sarg/%s.unsort",tmp,user);
-#if defined(HAVE_FOPEN64)
- if((fp_ou=fopen64(tmp3,"a"))==NULL) {
-#else
- if((fp_ou=fopen(tmp3,"a"))==NULL) {
-#endif
- fprintf(stderr, "%s: (zzzlog) %s: %s - %s\n",argv[0],text[9],tmp3,strerror(errno));
- exit(1);
- }
- fputs(bufz,fp_ou);
+ if(l){
+ if(strlen(date) > 0){
+ if(idata >= dfrom && idata <= duntil)
+ l=1;else l=0;
+ }
+ }
+ if(l){
+ if(strlen(hm)>0) {
+ strcpy(whm,hora);
+ bzero(hmr,15);
+ chm++;
+ while(chm) {
+ if (getword_multisep(warea,sizeof(warea),whm,':')<0){
+ printf("SARG: Maybe you have a broken time in your %s file.\n",arq);
+ exit(1);
+ }
+ strncat(hmr,warea,2);
+ chm--;
+ }
+ strncat(hmr,whm,2);
-#else
- if ( strcmp ( user , sz_Last_User ) != 0 ) {
- if ( fp_Write_User )
- fclose( fp_Write_User ) ;
- sprintf (tmp3, "%s/sarg/%s.unsort", tmp, user);
+ if(atoi(hmr) >= atoi(hm) && atoi(hmr) <= atoi(hmf))
+ l=1;else l=0;
+ }
+ }
+ if(l){
+ if(strlen(site)>0){
+ if(strstr(url,site)!=0)
+ l=1;else l=0;
+ }
+ }
+
+ if(userip)
+ strcpy(user,ip);
+
+ if(strcmp(user,"-") == 0 || strcmp(user," ") == 0 || strcmp(user,"") == 0) {
+ if(strcmp(RecordsWithoutUser,"ip") == 0)
+ strcpy(user,ip);
+ if(strcmp(RecordsWithoutUser,"ignore") == 0)
+ continue;
+ if(strcmp(RecordsWithoutUser,"everybody") == 0)
+ strcpy(user,"everybody");
+ }
+
+ if(dotinuser) {
+ str2=(char *)subs(user,"_",".");
+ strcpy(user,str2);
+ dotinuser=0;
+ }
+
+ if(puser) {
+ sprintf(wuser,":%s:",user);
+ if(strstr(userfile, wuser) == 0)
+ continue;
+ }
+
+ if(l) {
+ if(fuser) {
+ l=vuexclude(excludeuser,user);
+ if(!l)
+ totregsx++;
+ }
+ }
+
+ if(l) {
+ if(userip)
+ fixip(user);
+ }
+
+ if(l&&max_elapsed) {
+ if(atol(elap)>max_elapsed) {
+ elap[0]='0';
+ elap[1]='\0';
+ }
+ }
+
+ if(l) {
+ if(strcmp(user,"-") !=0 && strlen(url) > 0 && strcmp(user," ") !=0 && strcmp(user,"") !=0 && strcmp(user,":") !=0){
+ if((str=(char *) strstr(bufz, "[SmartFilter:")) != (char *) NULL ) {
+ str[strlen(str)-1]='\0';
+ sprintf(smartfilter,"\"%s\"",str+1);
+ } else sprintf(smartfilter,"\"\"");
+
+ sprintf(bufz, "%s %s %s %s %s %s %s %s %s\n",dia,hora,user,ip,url,tam,code,elap,smartfilter);
+
+#ifdef LEGACY_WRITE_USER
+ sprintf(tmp3,"%s/sarg/%s.unsort",tmp,user);
+ if((fp_ou=MY_FOPEN(tmp3,"a"))==NULL) {
+ fprintf(stderr, "%s: (zzzlog) %s: %s - %s\n",argv[0],text[9],tmp3,strerror(errno));
+ exit(1);
+ }
+ fputs(bufz,fp_ou);
-#if defined(HAVE_FOPEN64)
- if ((fp_Write_User = fopen64 (tmp3, "a")) == NULL) {
#else
- if ((fp_Write_User = fopen (tmp3, "a")) == NULL) {
-#endif
- fprintf (stderr, "%s: (log) %s: %s - %s\n", argv[0], text[9], tmp3, strerror(errno));
- exit (1);
- }
- strcpy( sz_Last_User , user ) ;
+ if ( strcmp ( user , sz_Last_User ) != 0 ) {
+ if ( fp_Write_User )
+ fclose( fp_Write_User ) ;
+ sprintf (tmp3, "%s/sarg/%s.unsort", tmp, user);
+
+ if ((fp_Write_User = MY_FOPEN (tmp3, "a")) == NULL) {
+ fprintf (stderr, "%s: (log) %s: %s - %s\n", argv[0], text[9], tmp3, strerror(errno));
+ exit (1);
}
- fputs (bufz, fp_Write_User);
+ strcpy( sz_Last_User , user ) ;
+ }
+ fputs (bufz, fp_Write_User);
#endif
- if(strcmp(ParsedOutputLog, "no") != 0 && !sarglog)
- fputs(bufz,fp_log);
+ if(strcmp(ParsedOutputLog, "no") != 0 && !sarglog)
+ fputs(bufz,fp_log);
#ifdef LEGACY_WRITE_USER
- fclose(fp_ou);
+ fclose(fp_ou);
#endif
- totregsg++;
+ totregsg++;
- if(download_flag && strstr(code,"DENIED") == 0) {
- ndownload = 1;
- sprintf(bufz, "%s %s %s %s %s\n",dia,hora,user,ip,download_url);
+ if(download_flag && strstr(code,"DENIED") == 0) {
+ ndownload = 1;
+ sprintf(bufz, "%s %s %s %s %s\n",dia,hora,user,ip,download_url);
#ifdef LEGACY_WRITE_DOWNLOAD
- sprintf(tmp3,"%s/sarg/download.unsort",tmp);
-#if defined(HAVE_FOPEN64)
- if((fp_ou=fopen64(tmp3,"a"))==NULL) {
-#else
- if((fp_ou=fopen(tmp3,"a"))==NULL) {
-#endif
- fprintf(stderr, "%s: (log) %s: %s - %s\n",argv[0],text[9],tmp3,strerror(errno));
- exit(1);
- }
- fputs(bufz,fp_ou);
- fclose(fp_ou);
-#else
- if ( ! fp_Download_Unsort ) {
-#if defined(HAVE_FOPEN64)
- if ((fp_Download_Unsort = fopen64 ( sz_Download_Unsort, "a")) == NULL) {
+ sprintf(tmp3,"%s/sarg/download.unsort",tmp);
+ if((fp_ou=MY_FOPEN(tmp3,"a"))==NULL) {
+ fprintf(stderr, "%s: (log) %s: %s - %s\n",argv[0],text[9],tmp3,strerror(errno));
+ exit(1);
+ }
+ fputs(bufz,fp_ou);
+ fclose(fp_ou);
#else
- if ((fp_Download_Unsort = fopen (sz_Download_Unsort, "a")) == NULL) {
-#endif
- fprintf (stderr, "%s: (log) %s: %s - %s\n", argv[0], text[9], tmp3, strerror(errno));
- exit (1);
- }
- }
- fputs (bufz, fp_Download_Unsort);
+ if ( ! fp_Download_Unsort ) {
+ if ((fp_Download_Unsort = MY_FOPEN ( sz_Download_Unsort, "a")) == NULL) {
+ fprintf (stderr, "%s: (log) %s: %s - %s\n", argv[0], text[9], tmp3, strerror(errno));
+ exit (1);
+ }
+ }
+ fputs (bufz, fp_Download_Unsort);
#endif
- }
-
- if(strstr(ReportType,"denied") != 0 || strstr(ReportType,"auth_failures") != 0) {
- if(strstr(code,"DENIED/403") != 0) {
- fprintf(fp_denied, "%s %s %s %s %s\n",dia,hora,user,ip,urly);
- denied_count++;
- }
- if(strstr(code,"DENIED/401") != 0 || strstr(code,"DENIED/407") != 0) {
- if(fp_authfail)
- fprintf(fp_authfail, "%s %s %s %s %s\n",dia,hora,user,ip,urly);
- authfail_count++;
- }
- }
-
- if((!totper || idata<mindate) && !sarglog){
- totper++;
- mindate=idata;
- sprintf(period,"%s-",tbuf);
- sprintf(per_hour,"%s-",tbuf2);
- if(strlen(date)>0)
- fixper(tbuf, period, cduntil);
- if(debugz){
- debugaz("tbuf",tbuf);
- debugaz("period",period);
- }
- }
- }
-
- if(debugm){
- printf("IP=\t%s\n",ip);
- printf("USER=\t%s\n",user);
- printf("ELAP=\t%s\n",elap);
- printf("DATE=\t%s\n",dia);
- printf("TIME=\t%s\n",hora);
- printf("FUNC=\t%s\n",fun);
- printf("URL=\t%s\n",url);
- printf("CODE=\t%s\n",code);
- printf("LEN=\t%s\n",tam);
- }
- }
+ }
+
+ if(strstr(ReportType,"denied") != 0 || strstr(ReportType,"auth_failures") != 0) {
+ if(strstr(code,"DENIED/403") != 0) {
+ fprintf(fp_denied, "%s %s %s %s %s\n",dia,hora,user,ip,urly);
+ denied_count++;
+ }
+ if(strstr(code,"DENIED/401") != 0 || strstr(code,"DENIED/407") != 0) {
+ if(fp_authfail)
+ fprintf(fp_authfail, "%s %s %s %s %s\n",dia,hora,user,ip,urly);
+ authfail_count++;
+ }
+ }
+
+ if((!totper || idata<mindate) && !sarglog){
+ totper++;
+ mindate=idata;
+ sprintf(period,"%s-",tbuf);
+ sprintf(per_hour,"%s-",tbuf2);
+ if(strlen(date)>0)
+ fixper(tbuf, period, cduntil);
+ if(debugz){
+ debugaz("tbuf",tbuf);
+ debugaz("period",period);
+ }
+ }
+ }
+
+ if(debugm){
+ printf("IP=\t%s\n",ip);
+ printf("USER=\t%s\n",user);
+ printf("ELAP=\t%s\n",elap);
+ printf("DATE=\t%s\n",dia);
+ printf("TIME=\t%s\n",hora);
+ printf("FUNC=\t%s\n",fun);
+ printf("URL=\t%s\n",url);
+ printf("CODE=\t%s\n",code);
+ printf("LEN=\t%s\n",tam);
+ }
+ }
}
if( bool_ShowReadStatistics )
printf("SARG: Records in file: " OFFSET_STRING ", reading: %3.2f%%\n",recs1, (float) 100 );
if(debug) {
sprintf(msg, " %s: %ld, %s: %ld, %s: %ld",text[10],totregsl,text[11],totregsg,text[68],totregsx);
debuga(msg);
-
+
if((common_log) && (squid_log))
debuga(text[12]);
-
+
if((common_log) && (!squid_log))
debuga(text[13]);
-
+
if((!common_log) && (squid_log))
debuga(text[14]);
if(sarglog)
debuga(text[124]);
-
+
if((!common_log) && (!squid_log) && (!sarglog) && (!isalog)) {
if(!totregsg) {
fprintf(stderr, "SARG: %s\n",text[16]);
fprintf(stderr, "SARG: %s\n",text[21]);
- } else fprintf(stderr, "SARG: %s\n",text[15]);
+ } else fprintf(stderr, "SARG: %s\n",text[15]);
bzero(msg,sizeof(msg));
fclose(fp_in);
// fclose(fp_ou);
exit(0);
}
}
-
+
if(!totregsg){
fprintf(stderr, "SARG: %s\n",text[16]);
fprintf(stderr, "SARG: %s\n",text[21]);
}
unlink(tmp4);
}
-
+
sort_users_log(tmp, debug);
if(strlen(DataFile) > 0)
unlink(tmp2);
if(strstr(ReportType,"denied") != 0)
unlink(tmp5);
-
+
if((strlen(zip) > 0 && strcmp(zip,"zcat") !=0)) {
- recomp(arq, zip); }
+ recomp(arq, zip);
+ }
// else unlink(arq);
if(strcmp(tmp,"/tmp") != 0) {
}
-void getusers(char *pwdfile, int debug)
+static void getusers(const char *pwdfile, int debug)
{
FILE *fp_usr;
char buf[255];
char Msg[255];
- char user[255];
+ char *str;
unsigned long int nreg=0;
if(debug) {
fseek(fp_usr, (off_t)0, SEEK_END);
nreg = ftell(fp_usr);
- nreg = nreg+5000;
+ nreg = nreg+5000;
fseek(fp_usr, (off_t)0, SEEK_SET);
if((userfile=(char *) malloc(nreg))==NULL){
}
bzero(userfile,nreg);
- sprintf(userfile,":");
-
- while(fgets(buf,255,fp_usr)!=NULL) {
- if (getword_multisep(user,sizeof(user),buf,':')<0){
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",pwdfile);
- exit(1);
- }
- strncat(userfile,user,strlen(user));
- strncat(userfile,":",1);
+ strcpy(userfile,":");
+
+ while(fgets(buf,sizeof(buf),fp_usr)!=NULL) {
+ str=strchr(buf,':');
+ if (!str) {
+ printf("SARG: You have an invalid user in your %s file.\n",pwdfile);
+ exit(1);
+ }
+ str[1]=0;
+ strcat(userfile,buf);
}
fclose(fp_usr);