char template2[255]="/var/tmp/sargtpl2.XXXXXX";
char cmd[512];
char *buf;
- int fd1;
+ int fd1,fd2;
int cstatus;
longline line;
init_usertab(UserTabFile);
#ifdef HAVE_MKSTEMP
+ fd2 = mkstemp(template2);
+ if (fd2 == -1) {
+ debuga(_("Cannot create a temporary file name to produce the report: %s\n"),strerror(errno));
+ exit(EXIT_FAILURE);
+ }
fd1 = mkstemp(template1);
#else
- fd1=open(mktemp(template1),O_RDWR);
+ buf = mktemp(template2);
+ if (buf[0]=='\0') {
+ debuga(_("Cannot create a temporary file name to produce the report: %s\n"),strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+ fd2 = -1;
+ fd1 = open(mktemp(template1),O_RDWR);
#endif
- mktemp(template2);
if((fd1 == -1 ) || ((tmp = fdopen (fd1, "w+" )) == NULL) ) { /* failure, bail out */
debuga(_("(realtime) mkstemp error - %s\n"),strerror(errno));
fclose(tmp);
longline_destroy(&line);
- if (snprintf(cmd,sizeof(cmd),"sort -t \"\t\" -r -k 1,1 -k 2,2 -o \"%s\" \"%s\"",template2,template1)>=sizeof(cmd)) {
+ if (fd2!=-1) close(fd2);//not safe at all but good enough for now.
+ if (snprintf(cmd,sizeof(cmd),"sort -t \"\t\" -r -n -k 1,1 -o \"%s\" \"%s\"",template2,template1)>=sizeof(cmd)) {
debuga(_("Sort command too long when sorting file \"%s\" to \"%s\"\n"),template1,template2);
exit(EXIT_FAILURE);
}
static int getdata(char *rec, FILE *ftmp)
{
- time_t tt;
- struct tm *t;
- char dat[128];
- char tbuf[128];
+ int dat;
char typ[128];
char warea[MAXLEN];
char user[MAX_USER_LEN];
struct getwordstruct gwarea;
getword_start(&gwarea,rec);
- if (getword(dat,sizeof(dat),&gwarea,' ')<0) {
+ if (getword_atoi(&dat,&gwarea,'.')<0) {
debuga(_("The time stamp at column 1 is too long\n"));
return(-1);
}
+ if (getword_skip(10,&gwarea,' ')<0) {
+ debuga(_("The time stamp decimal part at column 1 is too long\n"));
+ return(-1);
+ }
if (getword(warea,sizeof(warea),&gwarea,' ')<0) {
debuga(_("The connection duration at column 2 is too long\n"));
return(-1);
if(strncmp(user,"-",1) == 0 && RealtimeUnauthRec==REALTIME_UNAUTH_REC_IGNORE)
return(0);
- tt=atoi(dat);
- t=localtime(&tt);
- if(strncmp(DateFormat,"u",1) == 0)
- strftime(tbuf, sizeof(tbuf), "%Y-%m-%d\t%H:%M", t);
- else if(strncmp(DateFormat,"e",1) == 0)
- strftime(tbuf, sizeof(tbuf), "%d-%m-%Y\t%H:%M", t);
-
- fprintf(ftmp,"%s\t%s\t%s\t%s\t%s\n",tbuf,ip,user,url,typ);
+ fprintf(ftmp,"%d\t%s\t%s\t%s\t%s\n",dat,ip,user,url,typ);
return(0);
}
static void datashow(const char *tmp)
{
FILE *fin;
- char dat[128];
- char tim[128];
+ time_t tt;
+ struct tm *t;
+ char tbuf[128];
+ int dat;
char *buf;
char *url;
char *ourl=NULL;
while((buf=longline_read(fin,line))!=NULL) {
fixendofline(buf);
getword_start(&gwarea,buf);
- if (getword(dat,sizeof(dat),&gwarea,'\t')<0) {
- debuga(_("Maybe you have a broken record or garbage in your %s file\n"),tmp);
- exit(EXIT_FAILURE);
- }
- if (getword(tim,sizeof(tim),&gwarea,'\t')<0) {
- debuga(_("Maybe you have a broken record or garbage in your %s file\n"),tmp);
+ if (getword_atoi(&dat,&gwarea,'\t')<0) {
+ debuga(_("Invalid time column in file %s\n"),tmp);
exit(EXIT_FAILURE);
}
if (getword(ip,sizeof(ip),&gwarea,'\t')<0) {
- debuga(_("Maybe you have a broken record or garbage in your %s file\n"),tmp);
+ debuga(_("Invalid IP address in file %s\n"),tmp);
exit(EXIT_FAILURE);
}
if (getword(user,sizeof(user),&gwarea,'\t')<0) {
- debuga(_("Maybe you have a broken record or garbage in your %s file\n"),tmp);
+ debuga(_("Invalid user name in file %s\n"),tmp);
exit(EXIT_FAILURE);
}
- if(strlen(dat) < 3 || strlen(user) < 1) continue;
+ if (strlen(user) < 1) continue;
if (getword_ptr(buf,&url,&gwarea,'\t')<0) {
- debuga(_("Maybe you have a broken url in your %s file\n"),tmp);
+ debuga(_("Invalid URL in file %s\n"),tmp);
exit(EXIT_FAILURE);
}
if (getword(typ,sizeof(typ),&gwarea,'\t')<0) {
- debuga(_("Maybe you have a broken record or garbage in your %s file\n"),tmp);
+ debuga(_("Invalid access type in file %s\n"),tmp);
exit(EXIT_FAILURE);
}
if(strstr(RealtimeTypes,typ) == 0)
ip2name(u2,sizeof(u2));
user_find(name, sizeof(name), u2);
- printf("<tr><td class=\"data\">%s %s</td><td class=\"data3\">%s</td><td class=\"data3\">%s</td><td class=\"data3\">%s</td><td class=\"data2\"><a href=\"http://%s\">%s</td></tr>\n",dat,tim,ip,name,typ,url,url);
+ tt=(time_t)dat;
+ t=localtime(&tt);
+ if(DateFormat[0]=='u')
+ strftime(tbuf, sizeof(tbuf), "%Y-%m-%d %H:%M", t);
+ else if(DateFormat[0]=='e')
+ strftime(tbuf, sizeof(tbuf), "%d-%m-%Y %H:%M", t);
+
+ printf("<tr><td class=\"data\">%s</td><td class=\"data3\">%s</td><td class=\"data3\">%s</td><td class=\"data3\">%s</td><td class=\"data2\"><a href=\"http://%s\">%s</td></tr>\n",tbuf,ip,name,typ,url,url);
strcpy(ouser,user);
url_len=strlen(url);