FILE *fp_in = NULL, *fp_ou = NULL;
char *buf;
- char url[MAX_URL_LEN];
+ char *url;
char authfail_in[MAXLEN];
char per[MAXLEN];
char report[MAXLEN];
if(DataFile[0] != '\0') return;
ouser[0]='\0';
+ ouser2[0]='\0';
sprintf(tmp4,"%s/sarg/authfail.log.unsort",TempDir);
while((buf=longline_read(fp_in,&line))!=NULL) {
getword_start(&gwarea,buf);
if (getword(data,sizeof(data),&gwarea,'\t')<0 || getword(hora,sizeof(hora),&gwarea,'\t')<0 ||
- getword(user,sizeof(user),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0 ||
- getword(url,sizeof(url),&gwarea,'\t')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",authfail_in);
+ getword(user,sizeof(user),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0) {
+ debuga(_("Maybe you have a broken record or garbage in your %s file"),authfail_in);
+ exit(1);
+ }
+ if (getword_ptr(buf,&url,&gwarea,'\t')<0) {
+ debuga(_("Maybe you have a broken url in your %s file"),authfail_in);
exit(1);
}
char user[MAXLEN], code1[255], code2[255];
char ip[30];
char wdata[127];
- char url[MAX_URL_LEN];
+ char *url;
int idata=0;
int cstatus;
struct getwordstruct gwarea;
}
if(debug) {
+ char short_url[1024];
getword_start(&gwarea,text[7]);
- if (getword(url,sizeof(url),&gwarea,' ')<0 || getword(href,sizeof(href),&gwarea,' ')<0) {
+ if (getword_limit(short_url,sizeof(short_url),&gwarea,' ')<0 || getword(href,sizeof(href),&gwarea,' ')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s entry.\n",text[7]);
exit(1);
}
- debuga("%s DansGuardian %s: %s",url,gwarea.current,loglocation);
+ debuga("%s DansGuardian %s: %s",short_url,gwarea.current,loglocation);
}
if((fp_in=MY_FOPEN(loglocation,"r"))==NULL) {
if (getword(year,sizeof(year),&gwarea,'.')<0 || getword(mon,sizeof(mon),&gwarea,'.')<0 ||
getword(day,sizeof(day),&gwarea,' ')<0 || getword(hour,sizeof(hour),&gwarea,' ')<0 ||
getword(user,sizeof(user),&gwarea,' ')<0 || getword(ip,sizeof(ip),&gwarea,' ')<0 ||
- getword_skip(MAXLEN,&gwarea,'/')<0 || getword_skip(MAXLEN,&gwarea,'/')<0 ||
- getword(url,sizeof(url),&gwarea,' ')<0 || getword_skip(255,&gwarea,' ')<0 ||
+ getword_skip(MAXLEN,&gwarea,'/')<0 || getword_skip(MAXLEN,&gwarea,'/')<0) {
+ debuga(_("Maybe you have a broken record or garbage in your %s file"),loglocation);
+ exit(1);
+ }
+ if (getword_ptr(buf,&url,&gwarea,' ')<0) {
+ debuga(_("Maybe you have a broken url in your %s file"),loglocation);
+ exit(1);
+ }
+ if (getword_skip(255,&gwarea,' ')<0 ||
getword(code1,sizeof(code1),&gwarea,' ')<0 || getword(code2,sizeof(code2),&gwarea,' ')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",loglocation);
+ debuga(_("Maybe you have a broken record or garbage in your %s file"),loglocation);
exit(1);
}
sprintf(wdata,"%s%02d%s",year,atoi(mon),day);
FILE *fp_in = NULL, *fp_ou = NULL;
- char url[MAXLEN];
+ char *url;
char dansguardian_in[MAXLEN];
char per[MAXLEN];
char report[MAXLEN];
while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
getword_start(&gwarea,buf);
if (getword(user,sizeof(user),&gwarea,'\t')<0 || getword(date2,sizeof(date2),&gwarea,'\t')<0 ||
- getword(hour,sizeof(hour),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0 ||
- getword(url,sizeof(url),&gwarea,'\t')<0 || getword(rule,sizeof(rule),&gwarea,'\n')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",dansguardian_in);
+ getword(hour,sizeof(hour),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0) {
+ debuga(_("Maybe you have a broken record or garbage in your %s file"),dansguardian_in);
+ exit(1);
+ }
+ if (getword_ptr(buf,&url,&gwarea,'\t')<0) {
+ debuga(_("Maybe you have a broken url in your %s file"),dansguardian_in);
+ exit(1);
+ }
+ if (getword(rule,sizeof(rule),&gwarea,'\n')<0) {
+ debuga(_("Maybe you have a broken rule in your %s file"),dansguardian_in);
exit(1);
}
continue;
}
- fprintf(fp_ou,"<tr><td class=\"data2\" nospaw>%s</td><td class=\"data2\" nospaw>%s</td><td class=\"data2\" nospaw>%s-%s</td><td class=\"data2\" nospaw><a href=\"http://%s\">%s</a></td><td class=\"data2\" nospaw>%s</td></tr>\n",name,ip,date,hour,url,url,rule);
+ fprintf(fp_ou,"<tr><td class=\"data2\" nospaw>%s</td><td class=\"data2\" nospaw>%s</td><td class=\"data2\" nospaw>%s-%s</td><td class=\"data2\" nospaw><a href=\"http://",name,ip,date,hour);
+ output_html_url(fp_ou,url);
+ fputs("\">",fp_ou);
+ output_html_string(fp_ou,url,100);
+ fprintf(fp_ou,"</a></td><td class=\"data2\" nospaw>%s</td></tr>\n",rule);
}
fclose(fp_in);
{
FILE *fp_ou;
char reg[MAXLEN];
+ char val[20];
if((fp_ou=MY_FOPEN(DataFile,"a"))==NULL){
fprintf(stderr, "SARG: (datafile) %s: %s\n",text[45],DataFile);
exit(1);
}
- my_lltoa(nacc,val1,0);
- my_lltoa(nbytes,val2,0);
- my_lltoa(nelap,val3,0);
- my_lltoa(incache,val4,0);
- my_lltoa(oucache,val5,0);
-
if((DataFileFields & DATA_FIELD_USER) != 0) {
strcpy(reg,user);
strncat(reg,DataFileDelimiter,1);
strncat(reg,DataFileDelimiter,1);
}
if((DataFileFields & DATA_FIELD_CONNECT) != 0) {
- strncat(reg,val1,strlen(val1));
+ my_lltoa(nacc,val,sizeof(val),0);
+ strcat(reg,val);
strncat(reg,DataFileDelimiter,1);
}
if((DataFileFields & DATA_FIELD_BYTES) != 0) {
- strncat(reg,val2,strlen(val2));
+ my_lltoa(nbytes,val,sizeof(val),0);
+ strcat(reg,val);
strncat(reg,DataFileDelimiter,1);
}
if((DataFileFields & DATA_FIELD_IN_CACHE) != 0) {
- strncat(reg,val4,strlen(val4));
+ my_lltoa(incache,val,sizeof(val),0);
+ strcat(reg,val);
strncat(reg,DataFileDelimiter,1);
}
if((DataFileFields & DATA_FIELD_OUT_CACHE) != 0) {
- strncat(reg,val5,strlen(val5));
+ my_lltoa(oucache,val,sizeof(val),0);
+ strcat(reg,val);
strncat(reg,DataFileDelimiter,1);
}
if((DataFileFields & DATA_FIELD_ELAPSED) != 0) {
- strncat(reg,val3,strlen(val3));
+ my_lltoa(nelap,val,sizeof(val),0);
+ strcat(reg,val);
strncat(reg,DataFileDelimiter,1);
}
FILE *fp_in = NULL, *fp_ou = NULL;
char *buf;
- char url[MAX_URL_LEN];
+ char *url;
char denied_in[MAXLEN];
char per[MAXLEN];
char report[MAXLEN];
while((buf=longline_read(fp_in,&line))!=NULL) {
getword_start(&gwarea,buf);
if (getword(data,sizeof(data),&gwarea,'\t')<0 || getword(hora,sizeof(hora),&gwarea,'\t')<0 ||
- getword(user,sizeof(user),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0 ||
- getword(url,sizeof(url),&gwarea,'\t')<0) {
+ getword(user,sizeof(user),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",denied_in);
exit(1);
}
+ if (getword_ptr(buf,&url,&gwarea,'\t')<0) {
+ debuga(_("Maybe you have a broken url in your %s file"),denied_in);
+ exit(1);
+ }
if((str=(char *) strstr(user, "_")) != (char *) NULL ) {
if((str=(char *) strstr(str+1, "_")) != (char *) NULL )
-/*! \fn void getword_start(struct getwordstruct *gwarea, const char *line)
+/*! \fn void getword_start(struct getwordstruct *gwarea, char *line)
Initialize the getword buffer with the given text line.
\param gwarea The getword buffer to initialize.
+/*! \fn int getword_limit(char *word, int limit, struct getwordstruct *gwarea, int stop)
+Extract one word with a maximum size and skip any supernumerary bytes until the stop bytes is
+found.
+
+\param word The buffer to store the extracted word.
+\param limit The size of the buffer.
+\param gwarea The getword buffer initialized by getword_start().
+\param stop The character indicating the end of the word.
+
+\retval 0 The word is extracted.
+*/
+
+
+
+
+
/*! \fn int getword_multisep(char *word, int limit, struct getwordstruct *gwarea, int stop)
Extract one "word" from the text line and remove it from the text line. The word's boundary is defined
\param gwarea The getword buffer initialized by getword_start().
\param stop The character indicating the end of the word.
-\retval 0 The number is skipped.
+\retval 0 The number is extracted.
\retval -1 The stop character was not found after the number.
*/
+/*! \fn int getword_ptr(char *orig_line,char **word, struct getwordstruct *gwarea, int stop)
+Return a pointer to a null terminated string starting at the current position and ending
+and the stop character.
+
+\param orig_line The line that is being parsed.
+\param word A pointer to set to the beginning of the string.
+\param gwarea The getword buffer initialized by getword_start().
+\param stop The character indicating the end of the word.
+
+\retval 0 The word is skipped.
+\retval -1 Invalid \a orig_line passed to the function.
+*/
+
+
+
+
/*! \fn long long int my_atoll (const char *nptr)
Convert a string into a long long.
-/*! \fn void my_lltoa(unsigned long long int n, char s[], int len)
+/*! \fn void my_lltoa(unsigned long long int n, char *s, int ssize, int len)
Format a long long into a string.
\param n The number to format.
\param s The buffer to write the number.
+\param ssize The size of the output buffer.
\param len The minimum number of digits to format in the output. If the formatted
number is less than this length, it is padded with zeros.
+/*! \fn void url_to_file(const char *url,char *file,int filesize)
+Mangle an URL to produce a part that can be included in a file.
+
+\param url The URL to mangle.
+\param file The buffer to write the mangled URL.
+\param filesize The size of the buffer.
+*/
+
+
+
+
+
/*! \fn void write_html_trailer(FILE *fp_ou)
End the HTML file by closing the centered table that was opened by write_html_header(), writting
the informations of show_info() and closing the body and html tag. After this function returns, the
FILE *fp_in = NULL, *fp_ou = NULL;
char *buf;
- char url[MAX_URL_LEN];
+ char *url;
char report_in[MAXLEN];
char wdirname[MAXLEN];
char report[MAXLEN];
while((buf=longline_read(fp_in,&line))!=NULL) {
getword_start(&gwarea,buf);
if (getword(data,sizeof(data),&gwarea,'\t')<0 || getword(hora,sizeof(hora),&gwarea,'\t')<0 ||
- getword(user,sizeof(user),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0 ||
- getword(url,sizeof(url),&gwarea,'\t')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",report_in);
+ getword(user,sizeof(user),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0) {
+ debuga(_("Maybe you have a broken record or garbage in your %s file"),report_in);
+ exit(1);
+ }
+ if (getword_ptr(buf,&url,&gwarea,'\t')<0) {
+ debuga(_("Maybe you have a broken url in your %s file"),report_in);
exit(1);
}
output_html_url(fp_ou,url);
fprintf(fp_ou,"\"><img src=\"%s/sarg-squidguard-block.png\"></a> ",ImageFile);
}
- fputs("<a href=\"",fp_ou);
+ fputs("<a href=\"html://",fp_ou);
output_html_url(fp_ou,url);
fputs("\">",fp_ou);
output_html_string(fp_ou,url,100);
long long int ltemp;
long long int ntotuser;
long long int userbytes, userelap;
- char *linebuf;
+ char *buf;
char arqin[MAXLEN], arqou[MAXLEN], arqper[MAXLEN], arqip[MAXLEN];
- char url[MAX_URL_LEN], tmsg[50], csort[MAXLEN];
+ char *url, tmsg[50], csort[MAXLEN];
char period[MAXLEN], usuario[MAXLEN], wusuario[MAXLEN], u2[MAXLEN], duser[MAXLEN];
- char userurl[1024], userhora[9], userdia[9];
+ char userhora[9], userdia[9];
char user_ip[MAXLEN], olduserip[MAXLEN], tmp2[MAXLEN], tmp3[MAXLEN];
char denied_report[255], name2[MAXLEN];
char *str;
int cstatus;
const char txtext[]=".txt";
int dlen;
- char urly[MAX_URL_LEN];
- char siteind[MAX_URL_LEN];
+ char siteind[MAX_TRUNCATED_URL];
struct getwordstruct gwarea;
- struct longlinestruct line;
+ struct longlinestruct line,line1;
if((ReportType & REPORT_TYPE_USERS_SITES) == 0) return;
fprintf(stderr, "SARG: (html2) %s: %s\n",text[45],arqper);
exit(1);
}
+ if (longline_prepare(&line)<0) {
+ debuga(_("Not enough memory to read file %s"),arqper);
+ exit(1);
+ }
ttnacc=0;
totbytes=0;
totelap=0;
- while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
+ while((buf=longline_read(fp_in,&line))!=NULL) {
if(strncmp(buf,"TOTAL\t",6) == 0) {
getword_start(&gwarea,buf);
if (getword_skip(MAXLEN,&gwarea,'\t')<0 || getword_atoll(<emp,&gwarea,'\t')<0) {
}
}
fclose(fp_in);
+ longline_free(&line);
strcpy(arqper,dirname);
strcat(arqper,"/sarg-users");
tnelap=0;
tnincache=0;
tnoucache=0;
- while((linebuf=longline_read(fp_in,&line))!=NULL) {
- getword_start(&gwarea,linebuf);
+ while((buf=longline_read(fp_in,&line))!=NULL) {
+ getword_start(&gwarea,buf);
if (getword_atoll(<emp,&gwarea,'\t')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin);
+ printf("SARG: Maybe you have a broken number of access in your %s file.\n",arqin);
exit(1);
}
tnacc+=ltemp;
if (getword_atoll(<emp,&gwarea,'\t')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin);
+ printf("SARG: Maybe you have a broken downloaded size in your %s file.\n",arqin);
exit(1);
}
tnbytes+=ltemp;
- if (getword_skip(MAX_URL_LEN,&gwarea,'\t')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin);
+ if (getword_ptr(NULL,NULL,&gwarea,'\t')<0) {
+ debuga(_("Maybe you have a broken url in your %s file"),arqin);
exit(1);
}
if (getword_skip(MAXLEN,&gwarea,'\t')<0) {
exit(1);
}
if (getword_atoll(<emp,&gwarea,'\t')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin);
+ printf("SARG: Maybe you have a broken elapsed time in your %s file.\n",arqin);
exit(1);
}
tnelap+=ltemp;
if (getword_atoll(<emp,&gwarea,'\t')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin);
+ printf("SARG: Maybe you have a broken in-cache volume in your %s file.\n",arqin);
exit(1);
}
tnincache+=ltemp;
if (getword_atoll(<emp,&gwarea,'\n')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file (%d).\n",arqin,__LINE__);
+ printf("SARG: Maybe you have a broken out-cache volume in your %s file (%d).\n",arqin,__LINE__);
exit(1);
}
tnoucache+=ltemp;
debuga("%s: %s",text[61],usuario);
}
- while((linebuf=longline_read(fp_in,&line))!=NULL) {
- getword_start(&gwarea,linebuf);
+ while((buf=longline_read(fp_in,&line))!=NULL) {
+ getword_start(&gwarea,buf);
if (getword_atoll(&twork,&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken number of access in your %s file.\n",arqin);
exit(1);
printf("SARG: Maybe you have a broken number of bytes in your %s file.\n",arqin);
exit(1);
}
- if (getword(url,sizeof(url),&gwarea,'\t')<0) {
- printf("SARG: Maybe you have a broken url in your %s file.\n",arqin);
+ if (getword_ptr(buf,&url,&gwarea,'\t')<0) {
+ debuga(_("Maybe you have a broken url in your %s file"),arqin);
exit(1);
}
if (getword(tmsg,sizeof(tmsg),&gwarea,'\t')<0) {
else
strcpy(tmp6,"../../images");
- if(!LongUrl) {
- char *endofhost=strchr(url,'/');
- if (endofhost) *endofhost='\0';
- strcpy(urly,url);
- } else {
- strcpy(urly,url);
- url_module(url, module);
- str=strchr(url,'/');
- if (str){
- *str='\0';
- strcat(url,"…");
- strcat(url,module);
- }
- }
-
if((ReportType & REPORT_TYPE_SITE_USER_TIME_DATE) != 0) {
s=text[110];
for(z1=0 ; z1<sizeof(ltext110)-1 && s[z1] ; z1++)
ltext110[z1]=tolower(s[z1]);
ltext110[z1]='\0';
- for(z1=0; urly[z1]; z1++) {
- if(urly[z1]=='?' || urly[z1]=='-' || urly[z1]=='.' || urly[z1]==':' || urly[z1]=='/' || urly[z1]=='\\' ||
- urly[z1]=='*' || urly[z1]=='\'' || urly[z1]=='\"' || urly[z1]=='$')
- siteind[z1]='_';
- else
- siteind[z1]=urly[z1];
- }
- siteind[z1]='\0';
+ url_to_file(url,siteind,sizeof(siteind));
fprintf(fp_ou,"<td class=\"data\"><a href=\"tt%s-%s.html\"><img src=\"%s/datetime.png\" title=\"%s %s\" alt=\"T\"></a></td>",usuario,siteind,tmp6,ltext110,text[55]);
} else {
fprintf(fp_ou,"<td class=\"data\"></td>");
if(Privacy)
fprintf(fp_ou,"<td class=\"data2\"><span style=\"color:%s;\">%s</span></td>",PrivacyStringColor,PrivacyString);
else {
+ fputs("<td class=\"data2\">",fp_ou);
if(BlockIt[0]!='\0') {
- fprintf(fp_ou,"<td class=\"data2\"><a href=\"%s%s?url=%s\"><img src=\"%s/sarg-squidguard-block.png\"></a><a href=\"http://%s\"> %s</a></td>",wwwDocumentRoot,BlockIt,urly,tmp6,urly,urly);
- } else
- fprintf(fp_ou,"<td class=\"data2\"><a href=\"http://%s\" title=\"%s\">%s</a></td>",urly,urly,url);
+ fprintf(fp_ou,"<a href=\"%s%s?url=",wwwDocumentRoot,BlockIt);
+ output_html_url(fp_ou,url);
+ fprintf(fp_ou,"\"><img src=\"%s/sarg-squidguard-block.png\"></a> ",tmp6);
+ }
+ fputs("<a href=\"http://",fp_ou);
+ output_html_url(fp_ou,url);
+ fputs("\">%s",fp_ou);
+ output_html_string(fp_ou,url,100);
+ fputs("</a></td>",fp_ou);
}
if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0)
exit(1);
}
- while(fgets(buf,sizeof(buf),fp_ip)!=NULL) {
+ if (longline_prepare(&line1)<0) {
+ debuga(_("Not enough memory to read file %s"),arqip);
+ exit(1);
+ }
+ while((buf=longline_read(fp_ip,&line1))!=NULL) {
if(strstr(buf,url) != 0)
fputs(buf,fp_ip2);
}
+ longline_free(&line1);
fclose(fp_ip);
fclose(fp_ip2);
olduserip[0]='\0';
- while(fgets(buf,sizeof(buf),fp_ip)) {
+ if (longline_prepare(&line1)<0) {
+ debuga(_("Not enough memory to read file %s"),arqip);
+ exit(1);
+ }
+ while((buf=longline_read(fp_ip,&line1))!=NULL) {
getword_start(&gwarea,buf);
if (getword(user_ip,sizeof(user_ip),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken user IP in your %s file.\n",tmp3);
exit(1);
}
- if (getword(userurl,sizeof(userurl),&gwarea,'\t')<0) {
- printf("SARG: Maybe you have a broken user URL in your %s file.\n",tmp3);
+ if (getword_ptr(NULL,NULL,&gwarea,'\t')<0) {
+ debuga(_("Maybe you have a broken user url in your %s file"),tmp3);
exit(1);
}
if (getword(userdia,sizeof(userdia),&gwarea,'\t')<0) {
exit(1);
}
if(strcmp(user_ip,olduserip) != 0) {
- my_lltoa(unelap,val2,0);
sprintf(wwork1,"%s",fixnum(unbytes,1));
- fprintf(fp_ou,"<tr><td></td><td class=\"data\">%s</td><td></td><td class=\"data\">%s</td><td></td><td></td><td></td><td class=\"data\">%s</td><td class=\"data\">%s</td></tr>\n",olduserip,wwork1,buildtime(unelap),val2);
+ fprintf(fp_ou,"<tr><td></td><td class=\"data\">%s</td><td></td><td class=\"data\">%s</td><td></td><td></td><td></td><td class=\"data\">%s</td><td class=\"data\">%lld</td></tr>\n",olduserip,wwork1,buildtime(unelap),unelap);
strcpy(olduserip,user_ip);
unacc=0;
}
fclose(fp_ip);
+ longline_free(&line1);
unlink(tmp2);
unlink(tmp3);
- my_lltoa(unelap,val3,0);
sprintf(wwork1,"%s",fixnum(unbytes,1));
- fprintf(fp_ou,"<tr><td></td><td class=\"data\">%s</td><td></td><td class=\"data\">%s</td><td></td><td></td><td></td><td class=\"data\">%s</td><td class=\"data\">%s</td></tr>\n",olduserip,wwork1,buildtime(unelap),val3);
+ fprintf(fp_ou,"<tr><td></td><td class=\"data\">%s</td><td></td><td class=\"data\">%s</td><td></td><td></td><td></td><td class=\"data\">%s</td><td class=\"data\">%lld</td></tr>\n",olduserip,wwork1,buildtime(unelap),unelap);
}
unacc=0;
#define MAXLEN 20000
#define MAX_URL_LEN 40000
+#define MAX_TRUNCATED_URL 512
#define MAXLOGS 255
#define REPORT_TYPE_USERS_SITES 0x0001UL
#define INDEX_TREE_DATE 0x0001UL
#define INDEX_TREE_FILE 0x0002UL
-FILE *fp_tt;
-
char outdir[MAXLEN];
char dirname[MAXLEN];
char buf[MAXLEN];
{
const char *current;
const char *beginning;
+ int modified;
};
struct longlinestruct
void getword_start(struct getwordstruct *gwarea, const char *line);
void getword_restart(struct getwordstruct *gwarea);
int getword(char *word, int limit, struct getwordstruct *gwarea, int stop);
+int getword_limit(char *word, int limit, struct getwordstruct *gwarea, int stop);
int getword_multisep(char *word, int limit, struct getwordstruct *gwarea, int stop);
int getword_skip(int limit, struct getwordstruct *gwarea, int stop);
int getword_atoll(long long int *number, struct getwordstruct *gwarea, int stop);
+int getword_ptr(char *orig_line,char **word, struct getwordstruct *gwarea, int stop);
long long int my_atoll (const char *nptr);
int is_absolute(const char *path);
int getnumlist(char *, numlist *, const int, const int);
void conv_month(char *month);
void debuga(const char *msg,...);
void debugaz(const char *head, const char *msg);
-void my_lltoa(unsigned long long int n, char s[], int len);
+void my_lltoa(unsigned long long int n, char *s, int ssize, int len);
char *get_size(const char *path, const char *file);
void url_module(const char *url, char *w2);
+void url_to_file(const char *url,char *file,int filesize);
void strip_latin(char *line);
char *buildtime(long long int elap);
void obtdate(const char *dirname, const char *name, char *data);
*/
getword_start(&gwarea,data);
if (getword_skip(16,&gwarea,' ')<0) {
- printf("SARG: Maybe you have a broken week day in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
+ debuga(_("Maybe you have a broken week day in your %s%s/sarg-date file"),outdir,direntp->d_name);
exit(1);
}
if (getword_multisep(mon,sizeof(mon),&gwarea,' ')<0) {
- printf("SARG: Maybe you have a broken month in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
+ debuga(_("Maybe you have a broken month in your %s%s/sarg-date file"),outdir,direntp->d_name);
exit(1);
}
if (getword_multisep(day,sizeof(day),&gwarea,' ')<0) {
- printf("SARG: Maybe you have a broken day in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
+ debuga(_("Maybe you have a broken day in your %s%s/sarg-date file"),outdir,direntp->d_name);
exit(1);
}
if (getword_multisep(hour,sizeof(hour),&gwarea,' ')<0) {
- printf("SARG: Maybe you have a broken time in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
+ debuga(_("Maybe you have a broken time in your %s%s/sarg-date file"),outdir,direntp->d_name);
exit(1);
}
do {
if (getword_multisep(year,sizeof(year),&gwarea,' ')<0) {
- printf("SARG: Maybe you have a broken year in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
+ debuga(_("Maybe you have a broken year in your %s%s/sarg-date file"),outdir,direntp->d_name);
exit(1);
}
} while (year[0] && !isdigit(year[0])); //skip time zone information with spaces until the year is found
if (sscanf(hour,"%d:%d:%d",&ihour,&iminute,&isecond)!=3) {
- printf("SARG: Maybe you have a broken time in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
+ debuga(_("Maybe you have a broken time in your %s%s/sarg-date file"),outdir,direntp->d_name);
exit(1);
}
buildymd(day,mon,year,ftime);
char start_hour[128];
char end_hour[128];
char *linebuf;
- char url[MAX_URL_LEN];
- char urly[MAX_URL_LEN];
+ char hostname[512];
+ char *url;
+ char *urly;
enum InputLogFormat ilf;
int ilf_count[ILF_Last];
int ch;
unsigned long recs2=0UL;
int OutputNonZero = REPORT_EVERY_X_LINES ;
int download_flag=0;
- char download_url[MAX_URL_LEN];
+ char *download_url;
char sz_Last_User[MAXLEN]="";
struct getwordstruct gwarea;
struct longlinestruct line;
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) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+ if (getword_ptr(linebuf,&url,&gwarea,' ')<0) {
+ debuga(_("Maybe you have a broken url in your %s file"),arq);
exit(1);
}
if (getword_skip(MAXLEN,&gwarea,' ')<0 || getword(code2,sizeof(code2),&gwarea,' ')<0 ||
printf("SARG: Maybe you have a broken request method in your %s file.\n",arq);
exit(1);
}
- if (getword(url,sizeof(url),&gwarea,' ')<0){
- printf("SARG: Maybe you have a broken URI in your %s file.\n",arq);
+ if (getword_ptr(linebuf,&url,&gwarea,' ')<0){
+ debuga(_("Maybe you have a broken url in your %s file"),arq);
exit(1);
}
if (getword(user,sizeof(user),&gwarea,' ')<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,'\t')<0){
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+ if (getword_ptr(linebuf,&url,&gwarea,'\t')<0){
+ debuga(_("Maybe you have a broken record or garbage in your %s file"),arq);
exit(1);
}
if (getword(tam,sizeof(tam),&gwarea,'\t')<0){
if (!isa_ncols) continue;
getword_start(&gwarea,linebuf);
for (x=0 ; x<isa_ncols ; x++) {
- if (getword(val1,sizeof(val1),&gwarea,'\t')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+ if (getword_ptr(linebuf,&str,&gwarea,'\t')<0) {
+ debuga(_("Maybe you have a broken record or garbage in your %s file"),arq);
exit(1);
}
if (x==isa_cols[ISACOL_Ip]) {
- if (strlen(val1)>=sizeof(ip)) {
+ if (strlen(str)>=sizeof(ip)) {
printf("SARG: Maybe you have a broken IP in your %s file.\n",arq);
exit(1);
}
- strcpy(ip,val1);
+ strcpy(ip,str);
} else if (x==isa_cols[ISACOL_UserName]) {
- if (strlen(val1)>=sizeof(user)) {
+ if (strlen(str)>=sizeof(user)) {
printf("SARG: Maybe you have a broken user in your %s file.\n",arq);
exit(1);
}
- strcpy(user,val1);
+ strcpy(user,str);
} else if (x==isa_cols[ISACOL_Date]) {
- if (strlen(val1)>=sizeof(data)) {
+ if (strlen(str)>=sizeof(data)) {
printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
exit(1);
}
- strcpy(data,val1);
+ strcpy(data,str);
} else if (x==isa_cols[ISACOL_Time]) {
- if (strlen(val1)>=sizeof(hora)) {
+ if (strlen(str)>=sizeof(hora)) {
printf("SARG: Maybe you have a broken time in your %s file.\n",arq);
exit(1);
}
- strcpy(hora,val1);
+ strcpy(hora,str);
} else if (x==isa_cols[ISACOL_TimeTaken]) {
- if (strlen(val1)>=sizeof(elap)) {
+ if (strlen(str)>=sizeof(elap)) {
printf("SARG: Maybe you have a broken download duration in your %s file.\n",arq);
exit(1);
}
- strcpy(elap,val1);
+ strcpy(elap,str);
} else if (x==isa_cols[ISACOL_Bytes]) {
- if (strlen(val1)>=sizeof(tam)) {
+ if (strlen(str)>=sizeof(tam)) {
printf("SARG: Maybe you have a broken download size in your %s file.\n",arq);
exit(1);
}
- strcpy(tam,val1);
+ strcpy(tam,str);
} else if (x==isa_cols[ISACOL_Uri]) {
- if (strlen(val1)>=sizeof(url)) {
- printf("SARG: Maybe you have a broken URL in your %s file.\n",arq);
- exit(1);
- }
- strcpy(url,val1);
+ url=str;
} else if (x==isa_cols[ISACOL_Status]) {
- if (strlen(val1)>=sizeof(code)) {
+ if (strlen(str)>=sizeof(code)) {
printf("SARG: Maybe you have a broken access code in your %s file.\n",arq);
exit(1);
}
- strcpy(code,val1);
+ strcpy(code,str);
}
}
}
}
- if((ReportType & REPORT_TYPE_DENIED) != 0)
- strcpy(urly,url);
+ urly=url;
if(ilf!=ILF_Sarg) {
/*
*/
download_flag=is_download_suffix(url);
if (download_flag) {
- strcpy(download_url,url);
+ download_url=url;
download_count++;
}
}
}
if(!LongUrl) {
- char *endofhost=strchr(url,'/');
- if (endofhost)
- *endofhost='\0';
- if(strlen(url) > 512 && (endofhost=strchr(url,'%')) != NULL) {
- *endofhost='\0';
- }
+ int i;
+
+ for (i=0 ; i<sizeof(hostname)-1 && url[i] && url[i]!='/' ; i++)
+ hostname[i]=url[i];
+ hostname[i]='\0';
+ url=hostname;
}
if(ilf==ILF_Squid) {
static void getlog(void);
static void header(void);
-char typ[128];
-char ouser[MAXLEN]="";
-char ourl[MAXLEN]="";
-
void realtime(void)
{
struct tm *t;
char dat[128];
char tbuf[128];
+ char typ[128];
char warea[MAXLEN];
- char url[MAX_URL_LEN];
+ char *url;
struct getwordstruct gwarea;
getword_start(&gwarea,rec);
return(-1);
}
if(strncmp(typ,"CONNECT",7) == 0) {
- if (getword(url,sizeof(url),&gwarea,' ')<0) {
+ if (getword_ptr(rec,&url,&gwarea,' ')<0) {
return(-1);
}
if (getword(user,sizeof(user),&gwarea,' ')<0) {
fprintf(stderr,"SARG: The URL at column 7 is too long.\n");
return(-1);
}
- if (getword(url,sizeof(url),&gwarea,'/')<0) {
- fprintf(stderr,"SARG: The URL at column 7 is too long.\n");
+ if (getword_ptr(rec,&url,&gwarea,'/')<0) {
+ debuga(_("The URL at column 7 is too long"));
return(-1);
}
if (getword_skip(MAXLEN,&gwarea,' ')<0) {
- fprintf(stderr,"SARG: The data at column 8 is too long.\n");
+ debuga(_("The data at column 8 is too long"));
return(-1);
}
if (getword(user,sizeof(user),&gwarea,' ')<0) {
- fprintf(stderr,"SARG: The user at column 9 is too long.\n");
+ debuga(_("The user at column 9 is too long"));
return(-1);
}
}
FILE *fin;
char dat[128];
char tim[128];
- char buf[MAXLEN];
- char url[MAX_URL_LEN];
+ char *buf;
+ char *url;
+ char *ourl=NULL;
+ char ouser[MAXLEN]="";
+ char typ[128];
+ int url_len;
+ int ourl_size=0;
struct getwordstruct gwarea;
+ struct longlinestruct line;
if((fin=fopen(tmp,"r"))==NULL) {
fprintf(stderr, "SARG: (realtime) open error %s - %s\n",tmp,strerror(errno));
header();
- while(fgets(buf, sizeof(buf), fin)) {
+ if (longline_prepare(&line)<0) {
+ debuga(_("Not enough memory to read the log file"));
+ exit(1);
+ }
+
+ while((buf=longline_read(fin,&line))!=NULL) {
fixendofline(buf);
getword_start(&gwarea,buf);
if (getword(dat,sizeof(dat),&gwarea,'\t')<0) {
exit(1);
}
if(strlen(dat) < 3 || strlen(user) < 1) continue;
- if (getword(url,sizeof(url),&gwarea,'\t')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp);
+ if (getword_ptr(buf,&url,&gwarea,'\t')<0) {
+ debuga(_("Maybe you have a broken url in your %s file"),tmp);
exit(1);
}
if (getword(typ,sizeof(typ),&gwarea,'\t')<0) {
if(strstr(RealtimeTypes,typ) == 0)
continue;
- if(strcmp(ouser,user) == 0 && strcmp(ourl,url) == 0)
+ if(strcmp(ouser,user) == 0 && ourl && strcmp(ourl,url) == 0)
continue;
if(userip)
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);
strcpy(ouser,user);
+
+ url_len=strlen(url);
+ if (!ourl || url_len>=ourl_size) {
+ ourl_size=url_len+1;
+ ourl=realloc(ourl,ourl_size);
+ if (!ourl) {
+ debuga(_("Not enough memory to store the url"));
+ exit(1);
+ }
+ }
strcpy(ourl,url);
}
+ longline_free(&line);
+ if (ourl) free(ourl);
puts("</table>\n</div>\n</body>\n</html>\n");
fclose(fin);
printf(" <meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">\n",CharSet);
css(stdout);
puts("</head>\n");
- printf(buf,"<body style=\"font-family:%s;font-size:%s;background-color:%s;background-image:url(%s)\">\n",FontFace,TitleFontSize,BgColor,BgImage);
+ printf("<body style=\"font-family:%s;font-size:%s;background-color:%s;background-image:url(%s)\">\n",FontFace,TitleFontSize,BgColor,BgImage);
puts("<div align=\"center\"><table cellpadding=\"1\" cellspacing=\"1\">\n");
printf("<tr><th class=\"title_l\" colspan=\"10\">SARG %s</th></tr>\n",text[134]);
printf("<tr><th class=\"text\" colspan=\"10\">%s: %d s</th></tr>\n",text[136],realtime_refresh);
#include "include/conf.h"
#include "include/defs.h"
+static FILE *fp_tt=NULL;
+
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(const char *dirname, const char *user, const char *data, const char *hora, long long int elap, long long int accbytes, int indexonly);
FILE *fp_gen;
char *buf;
- char accdia[11], acchora[9], accuser[MAXLEN], accip[MAXLEN], accurl[MAX_URL_LEN];
+ char accdia[11], acchora[9], accuser[MAXLEN], accip[MAXLEN], *accurl;
char oldaccdia[11], oldacchora[9], oldaccip[MAXLEN];
- char wdirname[MAXLEN], oldurl[MAX_URL_LEN], oldaccuser[MAXLEN];
+ char wdirname[MAXLEN], oldaccuser[MAXLEN];
+ char *oldurl=NULL;
char olduser[MAXLEN], oldmsg[50], acccode[MAXLEN/2 - 1], oldacccode[MAXLEN/2 - 1], user[MAXLEN];
char ipantes[MAXLEN], nameantes[MAXLEN];
char accsmart[MAXLEN];
char crc2[MAXLEN/2 -1];
- char siteind[MAX_URL_LEN];
+ char siteind[MAX_TRUNCATED_URL];
char arqtt[256];
- char oldurltt[MAX_URL_LEN],oldaccdiatt[11],oldacchoratt[9];
+ char *oldurltt=NULL;
+ char oldaccdiatt[11],oldacchoratt[9];
long long int nbytes=0;
long long int nelap=0;
long long int nacc=0;
struct dirent *direntp;
const char logext[]=".log";
int dlen;
+ int url_len;
+ int ourl_size=0;
+ int ourltt_size=0;
struct getwordstruct gwarea;
struct longlinestruct line;
olduser[0]='\0';
strncat(tmp,"/sarg",5);
+ fp_tt=NULL;
dirp = opendir(tmp);
while ((direntp = readdir( dirp )) != NULL ) {
}
ttopen=0;
- memset(oldurltt,0,sizeof(oldurltt));
+ oldurltt=NULL;
+ ourltt_size=0;
memset(oldaccdiatt,0,sizeof(oldaccdiatt));
memset(oldacchoratt,0,sizeof(oldacchoratt));
getword_start(&gwarea,buf);
if (getword(accdia,sizeof(accdia),&gwarea,'\t')<0 || getword(acchora,sizeof(acchora),&gwarea,'\t')<0 ||
getword(accuser,sizeof(accuser),&gwarea,'\t')<0 || getword(accip,sizeof(accip),&gwarea,'\t')<0 ||
- getword(accurl,sizeof(accurl),&gwarea,'\t')<0 || getword_atoll(&accbytes,&gwarea,'\t')<0 ||
+ getword_ptr(buf,&accurl,&gwarea,'\t')<0 || getword_atoll(&accbytes,&gwarea,'\t')<0 ||
getword(acccode,sizeof(acccode),&gwarea,'\t')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file (%d).\n",tmp3,__LINE__);
+ debuga(_("Maybe you have a broken record or garbage in your %s file (%d)"),tmp3,__LINE__);
exit(1);
}
if(strncmp(acccode,"TCP_DENIED/407",14) == 0) continue;
}
if(!rtotal){
+ url_len=strlen(accurl);
+ if (!oldurl || url_len>=ourl_size) {
+ ourl_size=url_len+1;
+ oldurl=realloc(oldurl,ourl_size);
+ if (!oldurl) {
+ debuga(_("Not enough memory to store the url"));
+ exit(1);
+ }
+ }
strcpy(oldurl,accurl);
strcpy(oldacccode,acccode);
strcpy(oldaccuser,accuser);
nelap+=accelap;
if ((ReportType & REPORT_TYPE_SITE_USER_TIME_DATE) != 0 &&
- (strcmp(oldurltt,accurl) || strcmp(oldaccdiatt,accdia) || strcmp(oldacchoratt,acchora))) {
+ (!oldurltt || strcmp(oldurltt,accurl) || strcmp(oldaccdiatt,accdia) || strcmp(oldacchoratt,acchora))) {
if(!ttopen) {
ind2++;
- strcpy(siteind,accurl);
- for(str=siteind; *str; str++) {
- if(*str=='?' || *str=='-' || *str=='.' || *str==':' || *str=='/' || *str=='\\' || *str=='*' ||
- *str=='\'' || *str=='\"' || *str=='$' || *str=='@')
- *str='_';
- }
+ url_to_file(accurl,siteind,sizeof(siteind));
snprintf(arqtt,sizeof(arqtt),"%s/%s",dirname,accuser);
if(access(arqtt, R_OK) != 0)
my_mkdir(arqtt);
fprintf(fp_tt,"<tr><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th></tr>\n",text[91],tmp4,text[110]+5);
}
- fprintf(fp_tt,"<tr><td class=\"data\">%s</td><td class=\"data\">%s</td><td class=\"data\">%s</td></tr>\n",accurl,accdia,acchora);
+ fputs("<tr><td class=\"data\">",fp_tt);
+ output_html_string(fp_tt,accurl,100);
+ fprintf(fp_tt,"</td><td class=\"data\">%s</td><td class=\"data\">%s</td></tr>\n",accdia,acchora);
+ url_len=strlen(accurl);
+ if (!oldurltt || url_len>=ourltt_size) {
+ ourltt_size=url_len+1;
+ oldurltt=realloc(oldurltt,ourltt_size);
+ if (!oldurltt) {
+ debuga(_("Not enough memory to store the url"));
+ exit(1);
+ }
+ }
strcpy(oldurltt,accurl);
strcpy(oldaccdiatt,accdia);
strcpy(oldacchoratt,acchora);
strcpy(oldacccode,acccode);
strcpy(oldaccip,accip);
+ url_len=strlen(accurl);
+ if (url_len>=ourl_size) {
+ ourl_size=url_len+1;
+ oldurl=realloc(oldurl,ourl_size);
+ if (!oldurl) {
+ debuga(_("Not enough memory to store the url"));
+ exit(1);
+ }
+ }
strcpy(oldurl,accurl);
strcpy(oldaccdia,accdia);
strcpy(oldacchora,acchora);
fclose(fp_in);
unlink(tmp3);
longline_free(&line);
+ if (oldurltt) free(oldurltt);
}
closedir(dirp);
- if(strstr(oldacccode,"DENIED") != 0)
- strcpy(oldmsg,text[46]);
- else
- strcpy(oldmsg,"OK");
- strcpy(wdirname,dirname);
- if(oldaccuser[0] == '\0')
- strcpy(oldaccuser,accuser);
- gravatmpf(oldaccuser,wdirname,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache);
- strcpy(wdirname,dirname);
- gravager(fp_gen,oldaccuser,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache);
+ if (oldurl) {
+ if(strstr(oldacccode,"DENIED") != 0)
+ strcpy(oldmsg,text[46]);
+ else
+ strcpy(oldmsg,"OK");
+ strcpy(wdirname,dirname);
+ if(oldaccuser[0] == '\0')
+ strcpy(oldaccuser,accuser);
+ gravatmpf(oldaccuser,wdirname,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache);
+ strcpy(wdirname,dirname);
+ gravager(fp_gen,oldaccuser,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache);
+ free(oldurl);
+ }
fclose(fp_gen);
day_totalize(tmp,oldaccuser,indexonly);
{
FILE *fp_ou;
- char val1[16];
- char val2[16];
- char val3[16];
- char val4[16];
- char val5[16];
char wdirname[MAXLEN];
if(indexonly) return;
if((ReportType & REPORT_TYPE_USERS_SITES) == 0) return;
if (snprintf(wdirname,sizeof(wdirname),"%s/%s.utmp",tmp,oldaccuser)>=sizeof(wdirname)) {
- fprintf(stderr,"SARG: Path too long %s/%s.utmp\n",tmp,oldaccuser);
+ debuga(_("Path too long %s/%s.utmp"),tmp,oldaccuser);
exit(1);
}
exit(1);
}
- my_lltoa(nacc,val1,0);
- my_lltoa(nbytes,val2,0);
- my_lltoa(nelap,val3,0);
- my_lltoa(incache,val4,0);
- my_lltoa(oucache,val5,0);
- fprintf(fp_ou,"%s\t%s\t%s\t%s\t%s\t%s\t%s\n",val1,val2,oldurl,oldmsg,val3,val4,val5);
+ fprintf(fp_ou,"%lld\t%lld\t%s\t%s\t%lld\t%lld\t%lld\n",nacc,nbytes,oldurl,oldmsg,nelap,incache,oucache);
fclose(fp_ou);
ttopen=0;
fputs("</table>\n</div>\n",fp_tt);
fputs("</body>\n</html>\n",fp_tt);
fclose(fp_tt);
+ fp_tt=NULL;
}
return;
exit(1);
}
- my_lltoa(nacc,val1,0);
- my_lltoa(nbytes,val2,0);
- my_lltoa(nelap,val3,0);
- my_lltoa(incache,val4,0);
- my_lltoa(oucache,val5,0);
- fprintf(fp_ou,"%s\t%s\t%s\t%s\t%s\t%s\t%s\n",val1,val2,oldurl,oldmsg,val3,val4,val5);
+ fprintf(fp_ou,"%lld\t%lld\t%s\t%s\t%lld\t%lld\t%lld\n",nacc,nbytes,oldurl,oldmsg,nelap,incache,oucache);
fclose(fp_ou);
ttopen=0;
fputs("</table>\n",fp_tt);
fputs("</body>\n</html>\n",fp_tt);
fclose(fp_tt);
+ fp_tt=NULL;
}
return;
static void gravager(FILE *fp_gen, const char *user, long long int nacc, const char *url, long long int nbytes, const char *ip, const char *hora, const char *dia, long long int nelap, long long int incache, long long int oucache)
{
- my_lltoa(nacc,val1,0);
- my_lltoa(nbytes,val2,0);
- my_lltoa(nelap,val3,0);
- my_lltoa(incache,val4,0);
- my_lltoa(oucache,val5,0);
- fprintf(fp_gen,"%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",user,val1,val2,url,ip,hora,dia,val3,val4,val5);
+ fprintf(fp_gen,"%s\t%lld\t%lld\t%s\t%s\t%s\t%s\t%lld\t%lld\t%lld\n",user,nacc,nbytes,url,ip,hora,dia,nelap,incache,oucache);
return;
}
char *buf;
char user[MAXLEN];
- char url[MAX_URL_LEN];
+ char *url;
char wuser[MAXLEN];
- char ourl[MAX_URL_LEN];
+ char *ourl;
char csort[255];
char general[MAXLEN];
char general2[MAXLEN];
char period[100];
int regs=0;
int ucount=0;
+ int ourl_size;
+ int url_len;
char *users;
long long int nbytes;
long long int obytes;
fprintf(fp_ou,"<tr><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th></tr>\n",text[100],text[91],text[103]);
user[0]='\0';
- ourl[0]='\0';
+ ourl=NULL;
+ ourl_size=0;
obytes=0;
if((users=(char *) malloc(204800))==NULL){
printf("SARG: Maybe you have an invalid number of bytes in your %s file of the siteuser.\n",general2);
exit(1);
}
- if (getword(url,sizeof(url),&gwarea,'\t')<0) {
- printf("SARG: Maybe you have an invalid url in your %s file of the siteuser.\n",general2);
+ if (getword_ptr(buf,&url,&gwarea,'\t')<0) {
+ debuga(_("Maybe you have an invalid url in your %s file of the siteuser"),general2);
exit(1);
}
if(!regs) {
+ url_len=strlen(url);
+ if (!ourl || url_len>=ourl_size) {
+ ourl_size=url_len+1;
+ ourl=realloc(ourl,ourl_size);
+ if (!ourl) {
+ debuga(_("Not enough memory to store the url"));
+ exit(1);
+ }
+ }
strcpy(ourl,url);
obytes=nbytes;
regs++;
ucount=0;
strcpy(users,name);
strcat(users," ");
+ url_len=strlen(url);
+ if (url_len>=ourl_size) {
+ ourl_size=url_len+1;
+ ourl=realloc(ourl,ourl_size);
+ if (!ourl) {
+ debuga(_("Not enough memory to store the url"));
+ exit(1);
+ }
+ }
strcpy(ourl,url);
obytes=nbytes;
}
output_html_string(fp_ou,ourl,100);
fprintf(fp_ou,"</a></td><td class=\"data2\">%s</td></tr>\n",users);
}
+ if (ourl) free(ourl);
unlink(general2);
}
if(strcmp(leks,"year") == 0)
strcpy(year,res);
- else if(strcmp(leks,"year") == 0)
- strcpy(year,res);
else if(strcmp(leks,"mon") == 0)
strcpy(mon,res);
else if(strcmp(leks,"day") == 0)
FILE *fp_in = NULL, *fp_ou = NULL;
- char url[MAXLEN];
+ char *url;
char squidguard_in[MAXLEN];
char per[MAXLEN];
char report[MAXLEN];
while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
getword_start(&gwarea,buf);
if (getword(user,sizeof(user),&gwarea,'\t')<0 || getword(data2,sizeof(data2),&gwarea,'\t')<0 ||
- getword(hora,sizeof(hora),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0 ||
- getword(url,sizeof(url),&gwarea,'\t')<0 || getword(rule,sizeof(rule),&gwarea,'\n')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",squidguard_in);
+ getword(hora,sizeof(hora),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0) {
+ debuga(_("Maybe you have a broken record or garbage in your %s file"),squidguard_in);
+ exit(1);
+ }
+ if (getword_ptr(buf,&url,&gwarea,'\t')<0) {
+ debuga(_("Maybe you have a broken url in your %s file"),squidguard_in);
+ exit(1);
+ }
+ if (getword(rule,sizeof(rule),&gwarea,'\n')<0) {
+ debuga(_("Maybe you have a broken rule in your %s file"),squidguard_in);
exit(1);
}
continue;
}
- fprintf(fp_ou,"<tr><td class=\"data2\">%s</td><td class=\"data2\">%s</td><td class=\"data2\">%s-%s</td><td class=\"data2\"><a href=\"http://%s\">%s</a></td><td class=\"data2\">%s</td></th>\n",name,ip,data,hora,url,url,rule);
+ fprintf(fp_ou,"<tr><td class=\"data2\">%s</td><td class=\"data2\">%s</td><td class=\"data2\">%s-%s</td><td class=\"data2\"><a href=\"http://",name,ip,data,hora);
+ output_html_url(fp_ou,url);
+ fputs("\">",fp_ou);
+ output_html_string(fp_ou,url,100);
+ fprintf(fp_ou,"</a></td><td class=\"data2\">%s</td></th>\n",rule);
}
fclose(fp_in);
FILE *fp_in, *fp_ou;
char *buf;
- char url[MAX_URL_LEN];
- char ourl[MAX_URL_LEN];
+ char user[MAXLEN];
+ char *url;
+ char *ourl=NULL;
char ntemp[255];
char ttnacc[20];
char ttnbytes[20];
long long int twork1=0, twork2=0, twork3=0;
int regs=0;
int cstatus;
+ int url_len;
+ int ourl_size=0;
struct getwordstruct gwarea;
struct longlinestruct line;
while((buf=longline_read(fp_in,&line))!=NULL) {
getword_start(&gwarea,buf);
- if (getword(url,sizeof(url),&gwarea,'\t')<0) {
+ if (getword(user,sizeof(user),&gwarea,'\t')<0) {
printf("SARG: Maybe you have an invalid user in your %s file of the topsites.\n",general2);
exit(1);
}
- if(strcmp(url,"TOTAL") == 0) {
+ if(strcmp(user,"TOTAL") == 0) {
if (getword(ttnacc,sizeof(ttnacc),&gwarea,'\t')<0) {
printf("SARG: Maybe you have an invalid total number of access in your %s file of the topsites.\n",general2);
exit(1);
printf("SARG: Maybe you have an invalid number of bytes in your %s file of the topsites.\n",general2);
exit(1);
}
- if (getword(url,sizeof(url),&gwarea,'\t')<0) {
- printf("SARG: Maybe you have an invalid url in your %s file of the topsites.\n",general2);
+ if (getword_ptr(buf,&url,&gwarea,'\t')<0) {
+ debuga(_("Maybe you have an invalid url in your %s file of the topsites"),general2);
exit(1);
}
if (getword(ntemp,sizeof(ntemp),&gwarea,'\t')<0) {
}
if(!regs) {
+ url_len=strlen(url);
+ if (!ourl || url_len>=ourl_size) {
+ ourl_size=url_len+1;
+ ourl=realloc(ourl,ourl_size);
+ if (!ourl) {
+ debuga(_("Not enough memory to store the url"));
+ exit(1);
+ }
+ }
strcpy(ourl,url);
regs++;
}
if(strcmp(url,ourl) != 0) {
- my_lltoa(tnacc,val1,15);
- my_lltoa(tnbytes,val2,15);
- my_lltoa(tntime,val3,15);
- fprintf(fp_ou,"%s\t%s\t%s\t%s\n",val1,val2,val3,ourl);
+ fprintf(fp_ou,"%015lld\t%015lld\t%015lld\t%s\n",tnacc,tnbytes,tntime,ourl);
+ url_len=strlen(url);
+ if (url_len>=ourl_size) {
+ ourl_size=url_len+1;
+ ourl=realloc(ourl,ourl_size);
+ if (!ourl) {
+ debuga(_("Not enough memory to store the url"));
+ exit(1);
+ }
+ }
strcpy(ourl,url);
tnacc=0;
tnbytes=0;
unlink(general2);
longline_free(&line);
- my_lltoa(tnacc,val1,15);
- my_lltoa(tnbytes,val2,15);
- my_lltoa(tntime,val3,15);
- fprintf(fp_ou,"%s\t%s\t%s\t%s\n",val1,val2,val3,ourl);
+ if (ourl) {
+ fprintf(fp_ou,"%015lld\t%015lld\t%015lld\t%s\n",tnacc,tnbytes,tntime,ourl);
+ free(ourl);
+ }
fclose(fp_ou);
exit(1);
}
if (nacc == 0) continue;
- if (getword_atoll(&nbytes,&gwarea,'\t')<0 ||
- getword_atoll(&ntime,&gwarea,'\t')<0 || getword(url,sizeof(url),&gwarea,'\t')<0) {
+ if (getword_atoll(&nbytes,&gwarea,'\t')<0 || getword_atoll(&ntime,&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",sites);
exit(1);
}
+ if (getword_ptr(buf,&url,&gwarea,'\t')<0) {
+ debuga(_("Maybe you have a broken url in your %s file"),sites);
+ exit(1);
+ }
twork1=nacc;
twork2=nbytes;
strcpy(wwork2,fixnum(twork2,1));
strcpy(wwork3,fixtime(twork3));
- fprintf(fp_ou,"<tr><td class=\"data\">%d</td><td class=\"data2 link\">",regs);
+ fprintf(fp_ou,"<tr><td class=\"data\">%d</td><td class=\"data2 link\">",++regs);
if(BlockIt[0] != '\0') {
fprintf(fp_ou,"<a href=\"%s%s?url=\"",wwwDocumentRoot,BlockIt);
fputs("\">",fp_ou);
output_html_string(fp_ou,url,100);
fprintf(fp_ou,"</a></td><td class=\"data\">%s</td><td class=\"data\">%s</td><td class=\"data\">%s</td></tr>\n",wwork1,wwork2,wwork3);
- regs++;
}
fclose(fp_in);
longline_free(&line);
printf("SARG: Maybe you have a broken number of bytes in your %s file.\n",wger);
exit(1);
}
- if (getword_skip(MAX_URL_LEN,&gwarea,'\t')<0) {
- printf("SARG: Maybe you have a broken url in your %s file.\n",wger);
+ if (getword_ptr(NULL,NULL,&gwarea,'\t')<0) {
+ debuga(_("Maybe you have a broken url in your %s file"),wger);
exit(1);
}
if (getword(ip,sizeof(ip),&gwarea,'\t')<0) {
totuser++;
if (olduser[0] != '\0') {
- my_lltoa(tnbytes,val1,15);
- my_lltoa(tnacc,val2,15);
- my_lltoa(tnelap,val3,15);
- my_lltoa(tnincache,val4,15);
- my_lltoa(tnoucache,val5,15);
- fprintf(fp_top2,"%s\t%s\t%s\t%s\t%s\t%s\n",olduser,val1,val2,val3,val4,val5);
+ fprintf(fp_top2,"%s\t%015lld\t%015lld\t%015lld\t%015lld\t%015lld\n",olduser,tnbytes,tnacc,tnelap,tnincache,tnoucache);
ttnbytes+=tnbytes;
ttnacc+=tnacc;
longline_free(&line);
if (olduser[0] != '\0') {
- my_lltoa(tnbytes,val1,15);
- my_lltoa(tnacc,val2,15);
- my_lltoa(tnelap,val3,15);
- my_lltoa(tnincache,val4,15);
- my_lltoa(tnoucache,val5,15);
- fprintf(fp_top2,"%s\t%s\t%s\t%s\t%s\t%s\n",olduser,val1,val2,val3,val4,val5);
+ fprintf(fp_top2,"%s\t%015lld\t%015lld\t%015lld\t%015lld\t%015lld\n",olduser,tnbytes,tnacc,tnelap,tnincache,tnoucache);
ttnbytes+=tnbytes;
ttnacc+=tnacc;
}
if(strcmp(hora,ohora) != 0 || strcmp(data,odata) != 0) {
- my_lltoa(telap,val1,15);
- fprintf(fp_ou,"%s\t%s\t%s\n",odata,ohora,val1);
+ fprintf(fp_ou,"%s\t%s\t%015lld\n",odata,ohora,telap);
strcpy(odata,data);
strcpy(ohora,hora);
telap=0;
telap+=my_atoll(elap);
}
- my_lltoa(telap,val1,15);
- fprintf(fp_ou,"%s\t%s\t%s\n",data,hora,val1);
+ fprintf(fp_ou,"%s\t%s\t%015lld\n",data,hora,telap);
fclose(fp_in);
fclose(fp_ou);
long long int nacc, nbytes;
long long int elap;
long long int incac, oucac;
- char wger[MAXLEN], user[MAXLEN], url[MAX_URL_LEN];
+ char wger[MAXLEN], user[MAXLEN];
char ip[MAXLEN], hora[9], data[15];
char *warea;
struct getwordstruct gwarea;
printf("SARG: Maybe you have a broken number of bytes in your %s file.\n",wger);
exit(1);
}
- if (getword(url,sizeof(url),&gwarea,'\t')<0) {
- printf("SARG: Maybe you have a broken url in your %s file.\n",wger);
+ if (getword_ptr(NULL,NULL,&gwarea,'\t')<0) {
+ debuga(_("Maybe you have a broken url in your %s file"),wger);
exit(1);
}
if (getword(ip,sizeof(ip),&gwarea,'\t')<0) {
exit(1);
}
- url[0]='\0';
-
- my_lltoa(tnacc,val1,15);
- my_lltoa(tnbytes,val2,15);
- my_lltoa(telap,val3,15);
- my_lltoa(tincache,val4,15);
- my_lltoa(toucache,val5,15);
- fprintf(fp_ou,"TOTAL\t%s\t%s\t%s\t%s\t%s\n",val1,val2,val3,val4,val5);
+ fprintf(fp_ou,"TOTAL\t%015lld\t%015lld\t%015lld\t%015lld\t%015lld\n",tnacc,tnbytes,telap,tincache,toucache);
fclose(fp_ou);
return (0);
{
gwarea->beginning=line;
gwarea->current=line;
+ gwarea->modified=0;
}
void getword_restart(struct getwordstruct *gwarea)
{
+ if (gwarea->modified) {
+ debuga(_("Cannot parse again the line as it was modified"));
+ exit(1);
+ }
gwarea->current=gwarea->beginning;
}
return(0);
}
+int getword_limit(char *word, int limit, struct getwordstruct *gwarea, int stop)
+{
+ int x;
+
+ limit--;
+ for(x=0; x<limit && gwarea->current[x] && gwarea->current[x] != stop ;x++) {
+ word[x] = gwarea->current[x];
+ }
+ word[x] = '\0';
+ gwarea->current+=x;
+ while (*gwarea->current && *gwarea->current != stop) gwarea->current++;
+ if (*gwarea->current) ++gwarea->current;
+ return(0);
+}
+
int getword_multisep(char *word, int limit, struct getwordstruct *gwarea, int stop)
{
int x;
}
+int getword_ptr(char *orig_line,char **word, struct getwordstruct *gwarea, int stop)
+{
+ /*!
+ \note Why pass the original buffer to the function ? Because we must modify it to
+ insert the terminating ASCII zero for the word we return and that's not compatible
+ with getword_restart(). Moreover, getword_start() sometime works on constant strings
+ so this function require the original buffer to detect any missuse.
+ */
+ int x;
+ int sep;
+ int start;
+
+ if (orig_line && orig_line!=gwarea->beginning) {
+ debuga(_("Invalid buffer passed to getword_ptr"));
+ return(-1);
+ }
+
+ start=(gwarea->current-gwarea->beginning);
+ if (word && orig_line) *word=orig_line+start;
+ for(x=0;((gwarea->current[x]) && (gwarea->current[x] != stop ));x++);
+ sep=(gwarea->current[x]!='\0');
+ if (word && orig_line) orig_line[start+x] = '\0';
+ if (sep) ++x;
+ gwarea->current+=x;
+ gwarea->modified=1;
+ return(0);
+}
+
#define MAXLLL 30 //!< Maximum number of digits in long long (a guess).
long long int my_atoll (const char *nptr)
{
}
-void my_lltoa(unsigned long long int n, char s[], int len)
+void my_lltoa(unsigned long long int n, char *s, int ssize, int len)
{
int i;
int slen = 0;
int j;
char c;
+ ssize--;
+ if (len>ssize) {
+ debuga(_("The requested number length passed to my_lltoa (%d) is bigger than the output buffer size (%d)"),len,ssize);
+ abort();
+ }
+
do {
s[slen++] = (n % 10) + '0';
- } while ((n /= 10) > 0);
+ } while ((n /= 10) > 0 && slen<ssize);
s[slen] = '\0';
for (i = 0, j = slen-1; i<j; i++, j--) {
int numlen;
static char abbrev[30];
- my_lltoa(value, num, 0);
+ my_lltoa(value, num, sizeof(num), 0);
if(strcmp(DisplayedValues,"abbreviation") == 0) {
numlen = strlen(num);
char *pret;
register int i, j, k;
- my_lltoa(value, num, 0);
+ my_lltoa(value, num, sizeof(num), 0);
bzero(buf, MAXLEN_FIXNUM2*2);
pbuf = buf;
w2[x]='\0';
}
+void url_to_file(const char *url,char *file,int filesize)
+{
+ int i,skip;
+
+ filesize--;
+ skip=0;
+ for(i=0; i<filesize && *url; url++) {
+ if(*url=='?' || *url=='-' || *url=='.' || *url==':' || *url=='/' || *url=='\\' ||
+ *url=='*' || *url=='\'' || *url=='\"' || *url=='$') {
+ if (!skip) file[i++]='_';
+ skip=1;
+ } else {
+ file[i++]=*url;
+ skip=0;
+ }
+ }
+ file[i]='\0';
+}
void version(void)
{
size_t nread;
if (!line->buffer) return(NULL);
- if (feof(fp_in)) return(NULL);
line->start=line->end;
skipcr=1;
- while (skipcr || (line->buffer[line->end]!='\n' && line->buffer[line->end]!='\r')) {
+ while (skipcr || line->end>=line->length || (line->buffer[line->end]!='\n' && line->buffer[line->end]!='\r')) {
if (line->end>=line->length) {
if (line->start>0) {
for (i=line->start ; i<line->end ; i++)