From: Frédéric Marchal Date: Thu, 30 Jul 2009 20:21:28 +0000 (+0000) Subject: Fixed bug #1847374 X-Git-Tag: v2_2_6~49 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4157aa09582bbfcce405719e42d7e5873123067c;p=thirdparty%2Fsarg.git Fixed bug #1847374 --- diff --git a/download.c b/download.c index d8b86b6..3a66196 100644 --- a/download.c +++ b/download.c @@ -30,7 +30,7 @@ void download_report(void) { FILE *fp_in = NULL, *fp_ou = NULL; - + char url[MAXLEN]; char report_in[MAXLEN]; char wdirname[MAXLEN]; @@ -49,6 +49,7 @@ void download_report(void) int i; ouser[0]='\0'; + ouser2[0]='\0'; sprintf(report_in,"%s/sarg/download.log",TempDir); if(access(report_in, R_OK) != 0) @@ -114,7 +115,7 @@ void download_report(void) fixip(user); } - if(strcmp(Ip2Name,"yes") == 0) + if(strcmp(Ip2Name,"yes") == 0) ip2name(ip,sizeof(ip)); if(!z) { @@ -126,7 +127,7 @@ void download_report(void) user[0]='\0'; if(user[0] != '\0') strcpy(ouser,user); - if(strcmp(oip,ip) == 0) + if(strcmp(oip,ip) == 0) ip[0]='\0'; if(ip[0] != '\0') strcpy(oip,ip); @@ -140,7 +141,7 @@ void download_report(void) if(DownloadReportLimit) { if(strcmp(ouser2,name) == 0) { - count++; + count++; } else { count=1; strcpy(ouser2,name); diff --git a/html.c b/html.c index fd9b893..3431706 100644 --- a/html.c +++ b/html.c @@ -36,7 +36,7 @@ void htmlrel(void) long long int totelap=0, totelap2=0, nnelap=0, unelap=0, tnelap=0; long long int incache=0, oucache=0, tnincache=0, tnoucache=0, twork=0, twork2=0; char arqin[MAXLEN], arqou[MAXLEN], arqper[MAXLEN], arqip[MAXLEN]; - char nacc[20], nbytes[20], url[1024], tmsg[50], nelap[20], csort[MAXLEN]; + char nacc[20], nbytes[20], url[MAXLEN], tmsg[50], nelap[20], csort[MAXLEN]; char period[MAXLEN], usuario[MAXLEN], wusuario[MAXLEN], u2[MAXLEN], duser[MAXLEN]; char userbytes[20], userelap[20], userurl[1024], userhora[9], userdia[9]; char user_ip[MAXLEN], olduserip[MAXLEN], tmp2[MAXLEN], tmp3[MAXLEN], incac[20], oucac[20]; @@ -53,6 +53,8 @@ void htmlrel(void) const char txtext[]=".txt"; int dlen; char href2[MAXLEN]; + char urly[MAXLEN]; + char siteind[MAXLEN]; if(strstr(ReportType,"users_sites") == 0) return; @@ -144,7 +146,7 @@ void htmlrel(void) strcpy(duser,arqin); strcat(duser,"denied_"); strcat(arqin,direntp->d_name); - + if((str=(char *) strstr(denied_report, "_")) != (char *) NULL ) { if((str=(char *) strstr(str+1, "_")) != (char *) NULL ) fixip(denied_report); @@ -241,7 +243,7 @@ void htmlrel(void) fputs("\n",fp_ou); fputs("
\n",fp_ou); - if(strlen(denied_report) > 0) { + if(denied_report[0]!='\0') { fprintf(fp_ou,"\n",denied_report,text[116],text[55]); } @@ -284,15 +286,36 @@ void htmlrel(void) debuga("%s: %s",text[61],usuario); } - fscanf(fp_in,"%s",nacc); - fscanf(fp_in,"%s",nbytes); - fscanf(fp_in,"%s",url); - fscanf(fp_in,"%s",tmsg); - fscanf(fp_in,"%s",nelap); - fscanf(fp_in,"%s",incac); - fscanf(fp_in,"%s",oucac); + while(fgets(buf,sizeof(buf),fp_in)!=NULL) { + if (getword(nacc,sizeof(nacc),buf,' ')<0) { + printf("SARG: Maybe you have a broken number of access in your %s file.\n",arqin); + exit(1); + } + if (getword(nbytes,sizeof(nbytes),buf,' ')<0) { + printf("SARG: Maybe you have a broken number of bytes in your %s file.\n",arqin); + exit(1); + } + if (getword(url,sizeof(url),buf,' ')<0) { + printf("SARG: Maybe you have a broken url in your %s file.\n",arqin); + exit(1); + } + if (getword(tmsg,sizeof(tmsg),buf,' ')<0) { + printf("SARG: Maybe you have a broken status in your %s file.\n",arqin); + exit(1); + } + if (getword(nelap,sizeof(nelap),buf,' ')<0) { + printf("SARG: Maybe you have a broken elapsed time in your %s file.\n",arqin); + exit(1); + } + if (getword(incac,sizeof(incac),buf,' ')<0) { + printf("SARG: Maybe you have a broken in cache column in your %s file.\n",arqin); + exit(1); + } + if (getword(oucac,sizeof(oucac),buf,' ')<0) { + printf("SARG: Maybe you have a broken not in cache column in your %s file.\n",arqin); + exit(1); + } - while(!feof(fp_in)) { if(strncmp(tmsg,"OK",2) != 0) sprintf(tmsg,"",text[46]); else bzero(tmsg, 50); @@ -314,7 +337,7 @@ void htmlrel(void) perc2=nnelap * 100; perc2=perc2 / tnelap; } else perc2=0; - + if(incache) { inperc=incache * 100; inperc=inperc / nnbytes; @@ -331,11 +354,8 @@ void htmlrel(void) strcpy(wwork3,fixnum2(nnelap,1)); if(strcmp(LongUrl,"yes") != 0) { - if (getword(warea,sizeof(warea),url,'/')<0) { - printf("SARG: Maybe you have a broken record or garbage in the url of the %s file.\n",arqin); - exit(1); - } - sprintf(url,"%s",warea); + char *endofhost=strchr(url,'/'); + if (endofhost) *endofhost='\0'; strcpy(urly,url); } else { strcpy(urly,url); @@ -375,7 +395,7 @@ void htmlrel(void) } else { bzero(href2, MAXLEN); bzero(ltext110, 50); - } + } sprintf(val2,"%s",href2); sprintf(val3,"%3.2f%%",perc); @@ -417,7 +437,7 @@ void htmlrel(void) if(strncmp(tmsg," ",1) == 0) bzero(hbc9, 30); - + if(UserReportLimit<=0 || count<=UserReportLimit) { fprintf(fp_ou,"%s\n",val2,httplink,wwork1,wwork2,val3,val4,val5,val6,wwork3,val7,tmsg); count++; @@ -507,15 +527,6 @@ void htmlrel(void) unbytes=0; unelap=0; - fscanf(fp_in,"%s",nacc); - fscanf(fp_in,"%s",nbytes); - fscanf(fp_in,"%s",url); - fscanf(fp_in,"%s",tmsg); - fscanf(fp_in,"%s",nelap); - fscanf(fp_in,"%s",incac); - fscanf(fp_in,"%s",oucac); -// fscanf(fp_in,"%s",datestimes); - } if(iprel) @@ -601,7 +612,7 @@ void htmlrel(void) } fclose(fp_in); - + if(atoi(PerUserLimit) > 0) { if(tnbytes > (atoi(PerUserLimit)*1000000)) { limit_flag=0; @@ -673,7 +684,7 @@ void htmlrel(void) strcpy(wwork3,fixnum2(totelap2,1)); sprintf(val6,"%s",buildtime(totelap2)); - sprintf(val7,"%3.2f%%",perc2); + sprintf(val7,"%3.2f%%",perc2); strcpy(hbc1,"class=\"header2\""); strcpy(hbc2,"class=\"header2\""); @@ -694,7 +705,7 @@ void htmlrel(void) bzero(wwork3, 255); bzero(hbc3, 30); } - if(strstr(UserReportFields,"USED_TIME") == 0) { + if(strstr(UserReportFields,"USED_TIME") == 0) { bzero(val6, 255); bzero(hbc4, 30); } @@ -702,7 +713,7 @@ void htmlrel(void) bzero(val7, 255); bzero(hbc5, 30); } - + if(strstr(UserReportFields,"AVERAGE") != 0) { fprintf(fp_ou,"\n",hbc6,text[96],hbc1,wwork1,hbc2,wwork2,hbc4,val6,hbc3,wwork3,hbc5,val7); } diff --git a/include/conf.h b/include/conf.h index a17b502..c7afeaf 100755 --- a/include/conf.h +++ b/include/conf.h @@ -266,7 +266,6 @@ char ftime[128]; char mask[MAXLEN]; char httplink[MAXLEN]; char html_old[MAXLEN]; -char siteind[MAXLEN]; char site[MAXLEN]; char us[50]; char email[MAXLEN]; diff --git a/include/defs.h b/include/defs.h index 5431fbf..9ecba63 100755 --- a/include/defs.h +++ b/include/defs.h @@ -71,7 +71,7 @@ void realtime(void); void report_day(const char *user); // report.c -void gravatmp(char *oldaccuser, char *dirname, char *oldurl, long long int nacc, long long int nbytes, char *oldmsg, long long int nelap, int indexonly, long long int incache, long long int oucache); +void gravatmp(const char *oldaccuser, const char *dirname, const char *oldurl, long long int nacc, long long int nbytes, const char *oldmsg, long long int nelap, int indexonly, long long int incache, long long int oucache); void gerarel(void); // siteuser.c diff --git a/index.c b/index.c index 579fc58..24b1f78 100644 --- a/index.c +++ b/index.c @@ -133,7 +133,7 @@ void make_index(void) strcpy(warea,direntp2->d_name); if(strstr(warea,"-") != 0) { if (getword_multisep(m1,sizeof(m1),warea,'-')<0) { - printf("SARG: Maybe you have a broken record or garbage in your %s directory.\n",val2); + printf("SARG: Maybe you have a broken record or garbage in your %s directory.\n",val2); exit(1); } strcpy(m2,warea); @@ -147,7 +147,7 @@ void make_index(void) strcpy(warea,direntp3->d_name); if(strstr(warea,"-") != 0) { if (getword_multisep(d1,sizeof(d1),warea,'-')<0) { - printf("SARG: Maybe you have a broken record or garbage in your %s directory.\n",val2); + printf("SARG: Maybe you have a broken record or garbage in your %s directory.\n",val2); exit(1); } strcpy(d2,warea); @@ -207,36 +207,36 @@ void make_index(void) obttotal(outdir,direntp->d_name,tbytes,tuser,media); strcpy(html,data); if (getword_multisep(mon,sizeof(mon),html,' ')<0) { - printf("SARG: Maybe you have a broken week day in your %s%s/sarg-date file.\n",outdir,direntp->d_name); + printf("SARG: Maybe you have a broken week day in your %s%s/sarg-date file.\n",outdir,direntp->d_name); exit(1); } if (getword_multisep(mon,sizeof(mon),html,' ')<0) { - printf("SARG: Maybe you have a broken month in your %s%s/sarg-date file.\n",outdir,direntp->d_name); + printf("SARG: Maybe you have a broken month in your %s%s/sarg-date file.\n",outdir,direntp->d_name); exit(1); } if (getword_multisep(day,sizeof(day),html,' ')<0) { - printf("SARG: Maybe you have a broken day in your %s%s/sarg-date file.\n",outdir,direntp->d_name); + printf("SARG: Maybe you have a broken day in your %s%s/sarg-date file.\n",outdir,direntp->d_name); exit(1); } if (getword_multisep(hour,sizeof(hour),html,' ')<0) { - printf("SARG: Maybe you have a broken time in your %s%s/sarg-date file.\n",outdir,direntp->d_name); + printf("SARG: Maybe you have a broken time in your %s%s/sarg-date file.\n",outdir,direntp->d_name); exit(1); } if (getword_multisep(year,sizeof(year),html,' ')<0) { - printf("SARG: Maybe you have a broken year in your %s%s/sarg-date file.\n",outdir,direntp->d_name); + printf("SARG: Maybe you have a broken year in your %s%s/sarg-date file.\n",outdir,direntp->d_name); exit(1); } strcpy(html,hour); if (getword_multisep(h,sizeof(h),html,':')<0) { - printf("SARG: Maybe you have a broken hour in your %s%s/sarg-date file.\n",outdir,direntp->d_name); + printf("SARG: Maybe you have a broken hour in your %s%s/sarg-date file.\n",outdir,direntp->d_name); exit(1); } if (getword_multisep(m,sizeof(m),html,':')<0) { - printf("SARG: Maybe you have a broken minute in your %s%s/sarg-date file.\n",outdir,direntp->d_name); + printf("SARG: Maybe you have a broken minute in your %s%s/sarg-date file.\n",outdir,direntp->d_name); exit(1); } if (getword_multisep(s,sizeof(s),html,0)<0) { - printf("SARG: Maybe you have a broken second in your %s%s/sarg-date file.\n",outdir,direntp->d_name); + printf("SARG: Maybe you have a broken second in your %s%s/sarg-date file.\n",outdir,direntp->d_name); exit(1); } buildymd(day,mon,year,ftime); @@ -272,9 +272,9 @@ void make_index(void) } write_html_header(fp_ou, "."); fprintf(fp_ou,"\n",hbc1,text[130],hbc1,text[132]); - while(fgets(wwork1,MAXLEN,fp_tmp)!=NULL) { + while(fgets(wwork1,sizeof(wwork1),fp_tmp)!=NULL) { if (getword_multisep(tmp4,sizeof(tmp4),wwork1,' ')<0) { - printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir_tmp2); + printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir_tmp2); exit(1); } fprintf(fp_ou,"\n",tmp4,tmp4,wwork1); @@ -315,11 +315,11 @@ void make_index(void) write_html_header(fp_ou2,".."); fprintf(fp_ou2,"\n",hbc1,text[130],text[131]); while(fgets(wwork1,MAXLEN,fp_tmp2)!=NULL) { - wwork1[strlen(wwork1)-1]='\0'; + wwork1[strlen(wwork1)-1]='\0'; strcpy(tmp5,wwork1); if(strstr(tmp5,"-") != 0) { if (getword_multisep(warea,sizeof(warea),tmp5,'-')<0) { - printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir_tmp3); + printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir_tmp3); exit(1); } name_month(warea,sizeof(warea)); @@ -331,7 +331,7 @@ void make_index(void) name_month(nmonth,sizeof(nmonth)); } fprintf(fp_ou2,"\n",wwork1,tmp4,nmonth); - + sprintf(val1,"%s%s/%s",outdir,tmp4,wwork1); sprintf(tmp5,"%s%s/%s/index.unsort",outdir,tmp4,wwork1); if((fp_ou3=fopen(tmp5,"w"))==NULL) { @@ -411,27 +411,27 @@ void make_index(void) fprintf(fp_ou,"\n",hbc1,text[101],hbc1,text[102],hbc1,text[103],hbc1,text[93],hbc1,text[96]); while(fgets(buf,MAXLEN,fp_tmp2)!=NULL) { if (getword_multisep(period,sizeof(period),buf,';')<0) { - printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir_tmp2); + printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir_tmp2); exit(1); } if (getword_multisep(period,sizeof(period),buf,';')<0) { - printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir_tmp2); + printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir_tmp2); exit(1); } if (getword_multisep(data,sizeof(data),buf,';')<0) { - printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir_tmp2); + printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir_tmp2); exit(1); } if (getword_multisep(tuser,sizeof(tuser),buf,';')<0) { - printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir_tmp2); + printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir_tmp2); exit(1); } if (getword_multisep(tbytes,sizeof(tbytes),buf,';')<0) { - printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir_tmp2); + printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir_tmp2); exit(1); } if (getword_multisep(media,sizeof(media),buf,';')<0) { - printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir_tmp2); + printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir_tmp2); exit(1); } fprintf(fp_ou,"\n",period,ReplaceIndex,period,data,tuser,tbytes,media); @@ -439,7 +439,7 @@ void make_index(void) if(fp_tmp2) fclose(fp_tmp2); unlink(wdir_tmp2); } - + write_html_trailer(fp_ou); if(fp_ou) fclose(fp_ou); } diff --git a/log.c b/log.c index f5a180c..52b5da9 100644 --- a/log.c +++ b/log.c @@ -1102,17 +1102,11 @@ int main(int argc,char *argv[]) } 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 && strchr(url,'%') != NULL) { - 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); + char *endofhost=strchr(url,'/'); + if (endofhost) + *endofhost='\0'; + if(strlen(url) > 512 && (endofhost=strchr(url,'%')) != NULL) { + *endofhost='\0'; } } @@ -1504,7 +1498,7 @@ int main(int argc,char *argv[]) sort_users_log(tmp, debug); - if(strlen(DataFile) > 0) + if(DataFile[0] != '\0') data_file(tmp); else gerarel(); diff --git a/report.c b/report.c index 83c1082..8b720f6 100644 --- a/report.c +++ b/report.c @@ -28,7 +28,7 @@ static void maketmp(const char *user, const char *dirname, int debug, int indexonly); static void maketmp_hour(const char *user, const char *dirname, int indexonly); -static void gravatmp_hora(char *dirname, char *user, char *data, char *hora, char *elap, char *accbytes, int indexonly); +static void gravatmp_hora(const char *dirname, const char *user, const char *data, const char *hora, const char *elap, const char *accbytes, int indexonly); static void gravatmpf(char *oldaccuser, char *dirname, char *oldurl, long long int nacc, long long int nbytes, char *oldmsg, long long int nelap, int indexonly, long long int incache, long long int oucache); static void gravaporuser(char *user, char *dirname, char *url, char *ip, char *data, char *hora, char *tam, char *elap, int indexonly); static void gravager(char *dirname, char *user, long long int nacc, char *url, long long int nbytes, char *ip, char *hora, char *dia, long long int nelap, long long int incache, long long int oucache); @@ -43,12 +43,12 @@ void gerarel(void) char oldaccdia[11], oldacchora[9], oldaccip[MAXLEN], wdir[MAXLEN], per1[MAXLEN]; char wdirname[MAXLEN], oldurl[MAXLEN], oldaccuser[MAXLEN]; char olduser[MAXLEN], oldmsg[50], acccode[MAXLEN/2 - 1], oldaccelap[10], oldacccode[MAXLEN/2 - 1], user[MAXLEN]; - char ipantes[MAXLEN], nameantes[MAXLEN]; + char ipantes[MAXLEN], nameantes[MAXLEN]; char accsmart[MAXLEN]; char wcrc[MAXLEN/2 -1]; char crc2[MAXLEN/2 -1]; - long long int nbytes=0; - long long int nelap=0; + long long int nbytes=0; + long long int nelap=0; long long int nacc=0; long long int rtotal=0; long long int incache=0; @@ -58,6 +58,7 @@ void gerarel(void) struct dirent *direntp; const char logext[]=".log"; int dlen; + char siteind[MAXLEN]; ipantes[0]='\0'; nameantes[0]='\0'; @@ -75,7 +76,7 @@ void gerarel(void) gperiod(dirname,period); - if(strlen(UserAgentLog) > 0 && email[0] == '\0') useragent(); + if(UserAgentLog[0] != '\0' && email[0] == '\0') useragent(); olduser[0]='\0'; strncat(tmp,"/sarg",5); @@ -137,7 +138,7 @@ void gerarel(void) exit(1); } - if(strlen(accsmart) > 0) { + if(accsmart[0] != '\0') { smartfilter++; strcpy(wdirname,dirname); grava_SmartFilter(wdirname,accuser,accip,accdia,acchora,accurl,accsmart); @@ -209,11 +210,10 @@ void gerarel(void) if(!ttopen) { ind2++; strcpy(siteind,accurl); - str=siteind; - for(z1=0; str[z1]; z1++) { - if(str[z1]=='?' || str[z1]=='-' || str[z1]=='.' || str[z1]==':' || str[z1]=='/' || str[z1]=='\\' || str[z1]=='*' || - str[z1]=='\'' || str[z1]=='\"' || str[z1]=='$') - str[z1]='_'; + for(str=siteind; *str; str++) { + if(*str=='?' || *str=='-' || *str=='.' || *str==':' || *str=='/' || *str=='\\' || *str=='*' || + *str=='\'' || *str=='\"' || *str=='$') + *str='_'; } sprintf(arqtt,"%s/%s",dirname,accuser); if(access(arqtt, R_OK) != 0) @@ -234,7 +234,7 @@ void gerarel(void) sprintf(httplink,"%s", \ FontSize,PrivacyStringColor,PrivacyString,PrivacyString); else - sprintf(httplink,"%s",FontSize,accurl,accurl); + sprintf(httplink,"%s",FontSize,accurl,accurl); sprintf(ltext110,"%s",text[110]); for(s=ltext110; *s; ++s) @@ -257,7 +257,7 @@ void gerarel(void) fprintf(fp_tt,"\n",text[89],period); fprintf(fp_tt,"\n",text[90],name); fprintf(fp_tt,"\n",text[104],UserSortField,UserSortOrder); - fprintf(fp_tt,"\n",text[32]); + fprintf(fp_tt,"\n",text[32]); fputs("
%s %s
%s
%s%s%s%s%s%s%s%s%s%s
%s%s%s%s%s%s
%s%s
%s%s
%s/%s
%s %s
%s%s%s%s%s
%s%s%s%s%s
%s: %s
%s: %s
%s: %s, %s
%s
%s
\n",fp_tt); fputs("
\n",fp_tt); @@ -427,10 +427,15 @@ static void maketmp_hour(const char *user, const char *dirname, int indexonly) } -void gravatmp(char *oldaccuser, char *dirname, char *oldurl, long long int nacc, long long int nbytes, char *oldmsg, long long int nelap, int indexonly, long long int incache, long long int oucache) +void gravatmp(const char *oldaccuser, const char *dirname, const char *oldurl, long long int nacc, long long int nbytes, const char *oldmsg, long long int nelap, int indexonly, long long int incache, long long int oucache) { FILE *fp_ou; + char val1[16]; + char val2[16]; + char val3[16]; + char val4[16]; + char val5[16]; char wdirname[MAXLEN]; @@ -445,7 +450,7 @@ void gravatmp(char *oldaccuser, char *dirname, char *oldurl, long long int nacc, if((fp_ou=fopen(wdirname,"a"))==NULL){ fprintf(stderr, "SARG: (report) %s: %s\n",text[45],wdirname); exit(1); - } + } my_lltoa(nacc,val1,15); my_lltoa(nbytes,val2,15); @@ -468,11 +473,10 @@ void gravatmp(char *oldaccuser, char *dirname, char *oldurl, long long int nacc, } -static void gravatmp_hora(char *dirname, char *user, char *data, char *hora, char *elap, char *bytes, int indexonly) +static void gravatmp_hora(const char *dirname, const char *user, const char *data, const char *hora, const char *elap, const char *bytes, int indexonly) { FILE *fp_ou; - char wdirname[MAXLEN]; if(indexonly || (strstr(ReportType,"users_sites") == 0)) return; @@ -513,7 +517,7 @@ static void gravaporuser(char *user, char *dirname, char *url, char *ip, char *d if((fp_ou=fopen(wdirname,"a"))==NULL){ fprintf(stderr, "SARG: (report) %s: %s\n",text[45],wdirname); exit(1); - } + } fprintf(fp_ou,"%s %s %s %s %s %s\n",ip,url,data,hora,tam,elap); @@ -561,7 +565,7 @@ static void gravatmpf(char *oldaccuser, char *dirname, char *oldurl, long long i } return; - + } @@ -572,7 +576,7 @@ static void gravager(char *dirname, char *user, long long int nacc, char *url, l strcat(dirname,"/"); strcat(dirname,"sarg-general"); - + if((fp_ou=fopen(dirname,"a"))==NULL){ fprintf(stderr, "SARG: (report) %s: %s\n",text[45],dirname); exit(1); diff --git a/topuser.c b/topuser.c index f5fd988..c41bf4b 100644 --- a/topuser.c +++ b/topuser.c @@ -51,7 +51,7 @@ void topuser(void) int topcount=0; char *s; int cstatus; - char warea[1500]; + char warea[MAXLEN]; char user2[MAXLEN]; char name[MAXLEN]; char href1[MAXLEN]; @@ -89,7 +89,7 @@ void topuser(void) //fscanf(fp_in,"%s%s%s%s%s%s%s%s%s%s",user,nacc,nbytes,url,ip,time,date,elap,incac,oucac); fgets(warea,sizeof(warea),fp_in); if (getword(user,sizeof(user),warea,' ')<0) { - printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wger); + printf("SARG: Maybe you have a broken user in your %s file.\n",wger); exit(1); } @@ -98,39 +98,39 @@ void topuser(void) while(!feof(fp_in)) { if (getword(nacc,sizeof(nacc),warea,' ')<0) { - printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wger); + printf("SARG: Maybe you have a broken number of access in your %s file.\n",wger); exit(1); } if (getword(nbytes,sizeof(nbytes),warea,' ')<0) { - printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wger); + printf("SARG: Maybe you have a broken number of bytes in your %s file.\n",wger); exit(1); } if (getword(url,sizeof(url),warea,' ')<0) { - printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wger); + printf("SARG: Maybe you have a broken url in your %s file.\n",wger); exit(1); } if (getword(ip,sizeof(ip),warea,' ')<0) { - printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wger); + printf("SARG: Maybe you have a broken user's IP in your %s file.\n",wger); exit(1); } if (getword(time,sizeof(time),warea,' ')<0) { - printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wger); + printf("SARG: Maybe you have a broken time in your %s file.\n",wger); exit(1); } if (getword(date,sizeof(date),warea,' ')<0) { - printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wger); + printf("SARG: Maybe you have a broken date in your %s file.\n",wger); exit(1); } if (getword(elap,sizeof(elap),warea,' ')<0) { - printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wger); + printf("SARG: Maybe you have a broken download duration in your %s file.\n",wger); exit(1); } if (getword(incac,sizeof(incac),warea,' ')<0) { - printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wger); + printf("SARG: Maybe you have a broken in cache download in your %s file.\n",wger); exit(1); } if (getword(oucac,sizeof(oucac),warea,' ')<0) { - printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wger); + printf("SARG: Maybe you have a broken not in cache download in your %s file.\n",wger); exit(1); } if(strcmp(olduser,user) != 0) { @@ -152,7 +152,7 @@ void topuser(void) ttnoucache+=tnoucache; tnbytes=0; tnacc=0; - tnelap=0; + tnelap=0; tnincache=0; tnoucache=0; } @@ -304,7 +304,7 @@ void topuser(void) sprintf(val8,"%%%s",text[99]); strcpy(val9,"colspan=2"); bzero(val10, 255); - + strcpy(hbc1,"class=\"header\""); strcpy(hbc2,"class=\"header\""); strcpy(hbc3,"class=\"header\""); @@ -346,7 +346,7 @@ void topuser(void) bzero(val6, 255); bzero(hbc6, 30); } - if(strstr(TopUserFields,"MILISEC") == 0) { + if(strstr(TopUserFields,"MILISEC") == 0) { bzero(val7, 255); bzero(hbc7, 30); } @@ -441,14 +441,16 @@ void topuser(void) unlink(val1); } -// if(UserTabFile[0] != '\0' && strstr(user2,".") != 0) { - if(strcmp(user2,"TOTAL") != 0) + if(strcmp(user2,"TOTAL") != 0) { get_usertab_name(user2,name,sizeof(name)); - if((strcmp(Ip2Name,"yes") == 0) && - ((str=(char *) strstr(name, ".")) != (char *) NULL) && - ((str=(char *) strstr(str+1, ".")) != (char *) NULL)) - ip2name(name,sizeof(name)); + if((strcmp(Ip2Name,"yes") == 0) && + ((str=(char *) strstr(name, ".")) != (char *) NULL) && + ((str=(char *) strstr(str+1, ".")) != (char *) NULL)) + ip2name(name,sizeof(name)); + } else { + name[0]='\0'; + } twork=my_atoll(nacc); my_lltoa(twork,nacc,0); @@ -492,7 +494,7 @@ void topuser(void) bzero(wwork1, 255); bzero(hbc3, 30); } - if(strstr(TopUserFields,"BYTES") == 0) { + if(strstr(TopUserFields,"BYTES") == 0) { bzero(wwork2, 255); bzero(hbc4, 30); } @@ -554,7 +556,7 @@ void topuser(void) strcpy(hbc3,"class=\"header2\""); strcpy(hbc4,"class=\"header2\""); strcpy(hbc5,"class=\"header2\""); - strcpy(hbc6,"class=\"header2\""); + strcpy(hbc6,"class=\"header2\""); strcpy(hbc7,"class=\"header2\""); strcpy(hbc8,"class=\"header2\""); strcpy(hbc9,"class=\"header2\""); @@ -635,11 +637,13 @@ void topuser(void) } if(ntopuser) { - if((strstr(ReportType,"date_time") != 0 && strstr(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) fprintf(fp_top3,"\n",hbc10,text[96],hbc1,wwork1,hbc2,wwork2,hbc3,buildtime(ttnelap/totuser),hbc4,wwork3); + if((strstr(ReportType,"date_time") != 0 && strstr(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) + fprintf(fp_top3,"\n",hbc10,text[96],hbc1,wwork1,hbc2,wwork2,hbc3,buildtime(ttnelap/totuser),hbc4,wwork3); } - if(strlen(UserAgentLog) > 0) { + if(UserAgentLog[0] != '\0') { fputs("\n",fp_top3); fputs("\n",fp_top3); fputs("\n",fp_top3); diff --git a/totger.c b/totger.c index 1c0104d..42badb6 100644 --- a/totger.c +++ b/totger.c @@ -33,10 +33,10 @@ int totalger(const char *dirname, int debug, const char *outdir) long long int tnbytes=0; long long int telap=0; long long int tincache=0, toucache=0; - char wger[MAXLEN], user[MAXLEN], nacc[16], nbytes[16], url[2048]; + char wger[MAXLEN], user[MAXLEN], nacc[16], nbytes[16], url[MAXLEN]; char ip[MAXLEN], hora[9], data[11], elap[16]; char incac[16], oucac[16]; - char warea[1500]; + char warea[MAXLEN]; strcpy(wger,dirname); strcat(wger,"/sarg-general"); @@ -46,49 +46,47 @@ int totalger(const char *dirname, int debug, const char *outdir) exit(1); } - //fscanf(fp_in,"%s%s%s%s%s%s%s%s%s%s",user,nacc,nbytes,url,ip,hora,data,elap,incac,oucac); - fgets(warea,sizeof(warea),fp_in); - - while(!feof(fp_in)) + while(fgets(warea,sizeof(warea),fp_in)) { + //printf("%s\n",warea); if (getword(user,sizeof(user),warea,' ')<0) { - printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wger); + printf("SARG: Maybe you have a broken user in your %s file.\n",wger); exit(1); } if (getword(nacc,sizeof(nacc),warea,' ')<0) { - printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wger); + printf("SARG: Maybe you have a broken number of access in your %s file.\n",wger); exit(1); } if (getword(nbytes,sizeof(nbytes),warea,' ')<0) { - printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wger); + printf("SARG: Maybe you have a broken number of bytes in your %s file.\n",wger); exit(1); } if (getword(url,sizeof(url),warea,' ')<0) { - printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wger); + printf("SARG: Maybe you have a broken url in your %s file.\n",wger); exit(1); } if (getword(ip,sizeof(ip),warea,' ')<0) { - printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wger); + printf("SARG: Maybe you have a broken source IP address in your %s file.\n",wger); exit(1); } if (getword(hora,sizeof(hora),warea,' ')<0) { - printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wger); + printf("SARG: Maybe you have a broken time in your %s file.\n",wger); exit(1); } if (getword(data,sizeof(data),warea,' ')<0) { - printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wger); + printf("SARG: Maybe you have a broken date in your %s file.\n",wger); exit(1); } if (getword(elap,sizeof(elap),warea,' ')<0) { - printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wger); + printf("SARG: Maybe you have a broken elapsed time in your %s file.\n",wger); exit(1); } if (getword(incac,sizeof(incac),warea,' ')<0) { - printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wger); + printf("SARG: Maybe you have a broken in cache column in your %s file.\n",wger); exit(1); } if (getword(oucac,sizeof(oucac),warea,0)<0) { - printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wger); + printf("SARG: Maybe you have a broken not in cache column in your %s file.\n",wger); exit(1); } tnacc+=my_atoll(nacc); @@ -96,9 +94,6 @@ int totalger(const char *dirname, int debug, const char *outdir) telap+=my_atoll(elap); tincache+=my_atoll(incac); toucache+=my_atoll(oucac); - - //fscanf(fp_in,"%s%s%s%s%s%s%s%s%s%s",user,nacc,nbytes,url,ip,hora,data,elap,incac,oucac); - fgets(warea,sizeof(warea),fp_in); } fclose(fp_in); diff --git a/util.c b/util.c index 2755256..4afb020 100644 --- a/util.c +++ b/util.c @@ -1395,12 +1395,16 @@ void url_module(const char *url, char *w2) if(url[x] == '/' || y>=sizeof(w)-1) break; w[y++]=url[x]; } + if (x<0) { + w2[0]='\0'; + return; + } x=0; for(y=y-1; y>=0; y--) { w2[x++]=w[y]; } - w2[x]=0; + w2[x]='\0'; }
%s%s%15s%s%s
%s%s%15s%s%s
%s%s%15s%s%s
%s%s%15s%s%s
Useragent Report