From: Frédéric Marchal Date: Mon, 6 Jul 2009 14:40:44 +0000 (+0000) Subject: Fixed the real time report. X-Git-Tag: v2_2_6~72 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=40d1a88daee05d648302c2dcb8089702d2a38d7f;p=thirdparty%2Fsarg.git Fixed the real time report. --- diff --git a/realtime.c b/realtime.c index deb9eaf..770d52d 100755 --- a/realtime.c +++ b/realtime.c @@ -49,7 +49,7 @@ static void getlog(void) char template1[255]="/var/tmp/sargtpl1.XXXXXX"; char template2[255]="/var/tmp/sargtpl2.XXXXXX"; char cmd[512]; - char buf[512]; + char buf[MAXLEN]; int fd1,fd2,nreg; int cstatus; @@ -72,7 +72,7 @@ static void getlog(void) strncat(userfile,":",1); z1=0; z2=1; - while(fgets(buf,MAXLEN,fp_usr)!=NULL){ + while(fgets(buf,sizeof(buf),fp_usr)!=NULL){ buf[strlen(buf)-1]='\0'; if(strstr(buf,"\r") != 0) buf[strlen(buf)-1]='\0'; if (getword(bufy,sizeof(bufy),buf,' ')<0) { @@ -105,7 +105,7 @@ static void getlog(void) fp = popen(cmd, "r"); while(fgets(buf,sizeof(buf),fp) != NULL ) if (getdata(buf,tmp)<0) { - printf("SARG: Maybe a broken record or garbage was returned by %s.\n",cmd); + fprintf(stderr,"SARG: Maybe a broken record or garbage was returned by %s.\n",cmd); exit(1); } pclose(fp); @@ -128,9 +128,11 @@ int getdata(char *rec, FILE *ftmp) struct tm *t; if (getword3(dat,sizeof(dat),rec,' ')<0) { + fprintf(stderr,"SARG: The time stamp at column 1 is too long.\n"); return(-1); } if (getword3(warea,sizeof(warea),rec,' ')<0) { + fprintf(stderr,"SARG: The connection duration at column 2 is too long.\n"); return(-1); } while(strcmp(warea,"") == 0 && strlen(rec) > 0) @@ -138,15 +140,19 @@ int getdata(char *rec, FILE *ftmp) return(-1); } if (getword3(ip,sizeof(ip),rec,' ')<0) { + fprintf(stderr,"SARG: The IP address at column 3 is too long.\n"); return(-1); } if (getword3(warea,sizeof(warea),rec,' ')<0) { + fprintf(stderr,"SARG: The status at column 4 is too long.\n"); return(-1); } if (getword3(warea,sizeof(warea),rec,' ')<0) { + fprintf(stderr,"SARG: The size at column 5 is too long.\n"); return(-1); } if (getword3(typ,sizeof(typ),rec,' ')<0) { + fprintf(stderr,"SARG: The action at column 6 is too long.\n"); return(-1); } if(strncmp(typ,"CONNECT",7) == 0) { @@ -156,22 +162,27 @@ int getdata(char *rec, FILE *ftmp) if (getword3(user,sizeof(user),rec,' ')<0) { return(-1); } - }else { - if (getword3(url,sizeof(url),rec,'/')<0) { - return(-1); - } - if (getword3(url,sizeof(url),rec,'/')<0) { - return(-1); - } - if (getword3(url,sizeof(url),rec,'/')<0) { - return(-1); - } - if (getword3(user,sizeof(user),rec,' ')<0) { - return(-1); - } - if (getword3(user,sizeof(user),rec,' ')<0) { - return(-1); - } + }else { + if (getword3(url,sizeof(url),rec,'/')<0) { + fprintf(stderr,"SARG: The URL at column 7 is too long.\n"); + return(-1); + } + if (getword3(url,sizeof(url),rec,'/')<0) { + fprintf(stderr,"SARG: The URL at column 7 is too long.\n"); + return(-1); + } + if (getword3(url,sizeof(url),rec,'/')<0) { + fprintf(stderr,"SARG: The URL at column 7 is too long.\n"); + return(-1); + } + if (getword3(user,sizeof(user),rec,' ')<0) { + fprintf(stderr,"SARG: The data at column 8 is too long.\n"); + return(-1); + } + if (getword3(user,sizeof(user),rec,' ')<0) { + fprintf(stderr,"SARG: The user at column 9 is too long.\n"); + return(-1); + } } if(strncmp(user,"-",1) == 0 && strcmp(RealtimeUnauthRec,"ignore") == 0) @@ -184,8 +195,7 @@ int getdata(char *rec, FILE *ftmp) else if(strncmp(DateFormat,"e",1) == 0) strftime(tbuf, 127, "%d-%m-%Y %H:%M", t); - sprintf(warea,"%s %s %s %s %s\n",tbuf,ip,user,url,typ); - fputs(warea,ftmp); + fprintf(ftmp,"%s %s %s %s %s\n",tbuf,ip,user,url,typ); return(0); }