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;
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;
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");
DataFile[0]='\0';
SquidGuardConf[0]='\0';
DansGuardianConf[0]='\0';
+ start_hour[0]='\0';
+ end_hour[0]='\0';
denied_count=0;
download_count=0;
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);
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);
}
}
- 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) {
}
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);
}
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
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);
}
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)
}
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++;
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){
if(date[0] == '\0' && ilf_count[ILF_Sarg]==0) {
strcat(period,tbuf);
- strcat(per_hour,tbuf2);
}
if(debugz){
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);
}