From: Frédéric Marchal Date: Fri, 22 Jan 2010 09:59:25 +0000 (+0000) Subject: Fixed regressions in creation and reading of a sarg parsed log (thanks to Joao Alves) X-Git-Tag: v2_2_7~14 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ff8d5836af52911b4a356c85001c471ec6a2dd51;p=thirdparty%2Fsarg.git Fixed regressions in creation and reading of a sarg parsed log (thanks to Joao Alves) --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 01affbf..bcd3f7f 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ PROJECT(sarg C) SET(sarg_VERSION 2) SET(sarg_REVISION 2) SET(sarg_BUILD "7rc1") -SET(sarg_BUILDDATE "Jan-20-2010") +SET(sarg_BUILDDATE "Jan-22-2010") INCLUDE(AddFileDependencies) INCLUDE(CheckIncludeFile) diff --git a/ChangeLog b/ChangeLog index 74c6acb..0136d27 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,6 @@ SARG ChangeLog -Jan-20-2010 Version 2.2.7 +Jan-22-2010 Version 2.2.7 - Extra compile and run time protection (FORTIFY_SOURCE) fixed in configure. - Use tabulations as columns separator in intermediary files to avoid problems when a field of the log contains a space. - Input log file type detection partly rewritten to clearly distinguish which type is processed where. @@ -21,6 +21,8 @@ Jan-20-2010 Version 2.2.7 - Replace --enable-htmldir by --enable-sargphp to avoid confusion on the name. - Installation of sarg-php can be disabled with --disable-sargphp. - Fixed empty entries in squidGuard log when the URL doesn't start with protocol://. + - Fixed regressions in creation and reading of a sarg parsed log (thanks to Joao Alves). + - Does not report URLs consisting of only a host name ending with .com as a downloaded file. Jan-06-2010 Version 2.2.6.1 - Remove unnecessary dependency on off_t. diff --git a/include/conf.h b/include/conf.h index efa0caa..54be925 100755 --- a/include/conf.h +++ b/include/conf.h @@ -143,7 +143,6 @@ char urly[MAXLEN]; char user[MAXLEN]; char period[MAXLEN]; char msg[1024]; -char per_hour[128]; char code[MAXLEN]; char code2[MAXLEN]; char tmp[MAXLEN]; @@ -254,7 +253,7 @@ int ShowSargInfo; int BytesInSitesUsersReport; int ShowSargLogo; char ParsedOutputLog[MAXLEN]; -char ParsedOutputLogCompress[255]; +char ParsedOutputLogCompress[512]; char DisplayedValues[20]; char HeaderFontSize[5]; char TitleFontSize[5]; diff --git a/include/info.h b/include/info.h index a9ee4ce..45a38c8 100755 --- a/include/info.h +++ b/include/info.h @@ -1,3 +1,3 @@ -#define VERSION PACKAGE_VERSION" Jan-20-2010" +#define VERSION PACKAGE_VERSION" Jan-22-2010" #define PGM PACKAGE_NAME #define URL "http://sarg.sourceforge.net" diff --git a/log.c b/log.c index f45dc1c..841f3c9 100644 --- a/log.c +++ b/log.c @@ -100,6 +100,8 @@ int main(int argc,char *argv[]) char bufz[MAXLEN]; char bufy[MAXLEN]; char tmp2[MAXLEN]; + char start_hour[128]; + char end_hour[128]; enum InputLogFormat ilf; int ilf_count[ILF_Last]; int ch; @@ -125,7 +127,7 @@ int main(int argc,char *argv[]) unsigned long recs1=0UL; unsigned long recs2=0UL; int OutputNonZero = REPORT_EVERY_X_LINES ; - int download_flag; + int download_flag=0; char download_url[MAXLEN]; char sz_Last_User[MAXLEN]=""; struct getwordstruct gwarea; @@ -200,7 +202,7 @@ int main(int argc,char *argv[]) ShowSargInfo=1; ShowSargLogo=1; strcpy(ParsedOutputLog,"no"); - strcpy(ParsedOutputLogCompress,"/bin/gzip"); + strcpy(ParsedOutputLogCompress,"/bin/gzip -f"); strcpy(DisplayedValues,"abbreviation"); strcpy(HeaderFontSize,"9px"); strcpy(TitleFontSize,"11px"); @@ -248,6 +250,8 @@ int main(int argc,char *argv[]) DataFile[0]='\0'; SquidGuardConf[0]='\0'; DansGuardianConf[0]='\0'; + start_hour[0]='\0'; + end_hour[0]='\0'; denied_count=0; download_count=0; @@ -712,6 +716,7 @@ int main(int argc,char *argv[]) from_stdin=0; } ilf=ILF_Unknown; + download_flag=0; // pre-Read the file only if I have to show stats if(ShowReadStatistics && !from_stdin) { rewind(fp_in); @@ -738,9 +743,9 @@ int main(int argc,char *argv[]) if(strncmp(bufz,"*** SARG Log ***",16) == 0) { getword_start(&gwarea,arqtt); - if (getword(val2,sizeof(val2),&gwarea,'-')<0 || getword(val2,sizeof(val2),&gwarea,'_')<0 || - getword(val3,sizeof(val3),&gwarea,'-')<0 || getword(val3,sizeof(val3),&gwarea,'_')<0) { - printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq); + if (getword_skip(2000,&gwarea,'-')<0 || getword(val2,sizeof(val2),&gwarea,'_')<0 || + getword_skip(10,&gwarea,'-')<0 || getword(val3,sizeof(val3),&gwarea,'_')<0) { + printf("SARG: The name of the file is invalid: %s\n",arq); exit(1); } sprintf(period,"%s-%s",val2,val3); @@ -750,10 +755,9 @@ int main(int argc,char *argv[]) } } - if(strcmp(ParsedOutputLog, "no") != 0 && ilf!=ILF_Sarg) { + if(!fp_log && strcmp(ParsedOutputLog, "no") != 0 && ilf!=ILF_Sarg) { if(access(ParsedOutputLog,R_OK) != 0) { - sprintf(csort,"%s",ParsedOutputLog); - my_mkdir(csort); + my_mkdir(ParsedOutputLog); } sprintf(arq_log,"%s/sarg_temp.log",ParsedOutputLog); if((fp_log=MY_FOPEN(arq_log,"w"))==NULL) { @@ -912,39 +916,39 @@ int main(int argc,char *argv[]) } if (ilf==ILF_Sarg) { getword_start(&gwarea,bufz); - if (getword(data,sizeof(data),&gwarea,' ')<0){ + if (getword(data,sizeof(data),&gwarea,'\t')<0){ printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq); exit(1); } - if (getword(hora,sizeof(hora),&gwarea,' ')<0) { + if (getword(hora,sizeof(hora),&gwarea,'\t')<0) { printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq); exit(1); } - if (getword(user,sizeof(user),&gwarea,' ')<0) { + if (getword(user,sizeof(user),&gwarea,'\t')<0) { printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq); exit(1); } - if (getword(ip,sizeof(ip),&gwarea,' ')<0) { + if (getword(ip,sizeof(ip),&gwarea,'\t')<0) { printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq); exit(1); } - if (getword(url,sizeof(url),&gwarea,' ')<0){ + if (getword(url,sizeof(url),&gwarea,'\t')<0){ printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq); exit(1); } - if (getword(tam,sizeof(tam),&gwarea,' ')<0){ + if (getword(tam,sizeof(tam),&gwarea,'\t')<0){ printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq); exit(1); } - if (getword(code,sizeof(code),&gwarea,' ')<0){ + if (getword(code,sizeof(code),&gwarea,'\t')<0){ printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq); exit(1); } - if (getword(elap,sizeof(elap),&gwarea,' ')<0){ + if (getword(elap,sizeof(elap),&gwarea,'\t')<0){ printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq); exit(1); } - if (getword(smartfilter,sizeof(smartfilter),&gwarea,' ')<0){ + if (getword(smartfilter,sizeof(smartfilter),&gwarea,'\0')<0){ printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq); exit(1); } @@ -1132,10 +1136,16 @@ int main(int argc,char *argv[]) if(strstr(ReportType,"denied") != 0) strcpy(urly,url); - download_flag=is_download_suffix(url); - if (download_flag) { - strcpy(download_url,url); - download_count++; + if(ilf!=ILF_Sarg) { + /* + The full URL is not saved in sarg log. There is no point in testing the URL to detect + a downloaded file. + */ + download_flag=is_download_suffix(url); + if (download_flag) { + strcpy(download_url,url); + download_count++; + } } // remove any protocol:// at the beginning of the URL @@ -1192,15 +1202,15 @@ int main(int argc,char *argv[]) exit(1); } getword_start(&gwarea,data); - if (getword_multisep(dia,sizeof(dia),&gwarea,'/')<0){ + if (getword(dia,sizeof(dia),&gwarea,'/')<0){ printf("SARG: Maybe you have a broken date in your %s file.\n",arq); exit(1); } - if (getword_multisep(mes,sizeof(mes),&gwarea,'/')<0){ + if (getword(mes,sizeof(mes),&gwarea,'/')<0){ printf("SARG: Maybe you have a broken date in your %s file.\n",arq); exit(1); } - if (getword_multisep(ano,sizeof(ano),&gwarea,'/')<0){ + if (getword(ano,sizeof(ano),&gwarea,'/')<0){ printf("SARG: Maybe you have a broken date in your %s file.\n",arq); exit(1); } @@ -1213,18 +1223,31 @@ int main(int argc,char *argv[]) idata=atoi(wdata); } else if (ilf==ILF_Sarg) { getword_start(&gwarea,data); - if (getword_multisep(mes,sizeof(mes),&gwarea,'/')<0){ - printf("SARG: Maybe you have a broken date in your %s file.\n",arq); - exit(1); - } - if (getword_multisep(dia,sizeof(dia),&gwarea,'/')<0){ - printf("SARG: Maybe you have a broken date in your %s file.\n",arq); - exit(1); + if(strcmp(df,"u") == 0) { + if (getword(mes,sizeof(mes),&gwarea,'/')<0){ + printf("SARG: Maybe you have a broken date in your %s file.\n",arq); + exit(1); + } + if (getword(dia,sizeof(dia),&gwarea,'/')<0){ + printf("SARG: Maybe you have a broken date in your %s file.\n",arq); + exit(1); + } + } else { + if (getword(dia,sizeof(dia),&gwarea,'/')<0){ + printf("SARG: Maybe you have a broken date in your %s file.\n",arq); + exit(1); + } + if (getword(mes,sizeof(mes),&gwarea,'/')<0){ + printf("SARG: Maybe you have a broken date in your %s file.\n",arq); + exit(1); + } } - if (getword_multisep(ano,sizeof(ano),&gwarea,0)<0){ + if (getword(ano,sizeof(ano),&gwarea,0)<0){ printf("SARG: Maybe you have a broken date in your %s file.\n",arq); exit(1); } + snprintf(wdata,9,"%s%s%s",ano,mes,dia); + idata=atoi(wdata); } if(debugm) @@ -1351,8 +1374,7 @@ int main(int argc,char *argv[]) } fputs (bufz, fp_Write_User); - if(strcmp(ParsedOutputLog, "no") != 0 && ilf!=ILF_Sarg) - fputs(bufz,fp_log); + if(fp_log && ilf!=ILF_Sarg) fputs(bufz,fp_log); totregsg++; @@ -1384,7 +1406,7 @@ int main(int argc,char *argv[]) totper++; mindate=idata; sprintf(period,"%s-",tbuf); - sprintf(per_hour,"%s-",tbuf2); + strcpy(start_hour,tbuf2); if(date[0] != '\0') fixper(tbuf, period, cduntil); if(debugz){ @@ -1477,7 +1499,6 @@ int main(int argc,char *argv[]) if(date[0] == '\0' && ilf_count[ILF_Sarg]==0) { strcat(period,tbuf); - strcat(per_hour,tbuf2); } if(debugz){ @@ -1497,34 +1518,36 @@ int main(int argc,char *argv[]) if(fp_log != NULL) { fclose(fp_log); + strcpy(end_hour,tbuf2); getword_start(&gwarea,period); - if (getword_multisep(val2,sizeof(val2),&gwarea,'-')<0){ + if (getword(val2,sizeof(val2),&gwarea,'-')<0){ printf("SARG: Maybe you have a broken date range definition.\n"); exit(1); } - if (getword_multisep(val1,sizeof(val1),&gwarea,'\0')<0){ + if (getword(val1,sizeof(val1),&gwarea,'\0')<0){ printf("SARG: Maybe you have a broken date range definition.\n"); exit(1); } - getword_start(&gwarea,per_hour); - if (getword_multisep(val3,sizeof(val3),&gwarea,'-')<0){ - printf("SARG: Maybe you have a broken date range definition.\n"); - exit(1); - } - sprintf(val4,"%s/sarg-%s_%s-%s_%s.log",ParsedOutputLog,val2,val3,val1,gwarea.current); - rename(arq_log,val4); - strcpy(arq_log,val4); - - if(strcmp(ParsedOutputLogCompress,"nocompress") != 0) { - sprintf(val1,"\"%s\" \"%s\"",ParsedOutputLogCompress,arq_log); - cstatus=system(val1); - if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { - fprintf(stderr, "SARG: command return status %d\n",WEXITSTATUS(cstatus)); - fprintf(stderr, "SARG: command: %s\n",val1); - exit(1); + sprintf(val4,"%s/sarg-%s_%s-%s_%s.log",ParsedOutputLog,val2,start_hour,val1,end_hour); + if (rename(arq_log,val4)) { + fprintf(stderr,"SARG: failed to rename %s to %s - %s\n",arq_log,val4,strerror(errno)); + } else { + strcpy(arq_log,val4); + + if(strcmp(ParsedOutputLogCompress,"nocompress") != 0 && ParsedOutputLogCompress[0] != '\0') { + /* + No double quotes around ParsedOutputLogCompress because it may contain command line options. If double quotes are + necessary around the command name, put them in the configuration file. + */ + sprintf(val1,"%s \"%s\"",ParsedOutputLogCompress,arq_log); + cstatus=system(val1); + if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { + fprintf(stderr, "SARG: command return status %d\n",WEXITSTATUS(cstatus)); + fprintf(stderr, "SARG: command: %s\n",val1); + exit(1); + } } } - if(debug) debuga("%s %s",text[123],arq_log); } diff --git a/sarg.conf b/sarg.conf index 7d7d696..3f16aec 100644 --- a/sarg.conf +++ b/sarg.conf @@ -498,7 +498,10 @@ #parsed_output_log none # TAG: parsed_output_log_compress /bin/gzip|/usr/bin/bzip2|nocompress -# sarg logs compress util +# Command to run to compress sarg parsed output log. It may contain +# options (such as -f to overwrite existing target file). The name of +# the file to compresse is provided at the end of this +# command line. Don't forget to quote things appropriately. # #parsed_output_log_compress /bin/gzip