SET(sarg_VERSION 2)
SET(sarg_REVISION "3rc1")
SET(sarg_BUILD "")
-SET(sarg_BUILDDATE "Feb-10-2010")
+SET(sarg_BUILDDATE "Mar-02-2010")
INCLUDE(AddFileDependencies)
INCLUDE(CheckIncludeFile)
SET_TARGET_PROPERTIES(sarg PROPERTIES VERSION "${sarg_VERSION}.${sarg_REVISION}.${sarg_BUILD}")
-SET_TARGET_PROPERTIES(sarg PROPERTIES COMPILE_FLAGS "$ENV{CFLAGS} -Wall -Wextra -Wno-sign-compare -Wno-unused-parameter")
+SET_TARGET_PROPERTIES(sarg PROPERTIES COMPILE_FLAGS "$ENV{CFLAGS} -Wall -Wno-sign-compare")
SET_TARGET_PROPERTIES(sarg PROPERTIES LINK_FLAGS "$ENV{LDFLAGS}")
+CHECK_C_COMPILER_FLAG("-Wextra" HAVE_WEXTRA)
+IF(HAVE_WEXTRA)
+ # Not supported by gcc 3.3
+ GET_TARGET_PROPERTY(TMPCFLAGS sarg COMPILE_FLAGS)
+ SET_TARGET_PROPERTIES(sarg PROPERTIES COMPILE_FLAGS "${TMPCFLAGS} -Wextra -Wno-unused-parameter")
+ENDIF(HAVE_WEXTRA)
+
CHECK_C_COMPILER_FLAG("-Werror=implicit-function-declaration" HAVE_WERROR_IMPLICIT_FUNCTION)
IF(HAVE_WERROR_IMPLICIT_FUNCTION)
GET_TARGET_PROPERTY(TMPCFLAGS sarg COMPILE_FLAGS)
# Gettext and friends
IF(NOT HAVE_LC_MESSAGES)
- UNSET(FILES)
+ SET(FILES)
IF(HAVE_LOCALE_H)
LIST(APPEND FILES "locale.h")
ENDIF(HAVE_LOCALE_H)
#include "include/conf.h"
#include "include/defs.h"
-void htaccess(const char *name)
+void htaccess(const struct userinfostruct *uinfo)
{
char htname[MAXLEN];
FILE *fp_auth;
if(!UserAuthentication)
return;
- sprintf(htname,"%s/%s/.htaccess",dirname,name);
+ if (snprintf(htname,sizeof(htname),"%s/%s/.htaccess",dirname,uinfo->filename)>=sizeof(htname)) {
+ debuga(_("File name too long: %s/%s/.htaccess"),dirname,uinfo->filename);
+ exit(1);
+ }
if((fp_auth=fopen(htname,"w"))==NULL) {
fprintf(stderr, "SARG: (auth) %s: %s - %s\n",text[45],htname,strerror(errno));
exit(1);
fputs("<Limit GET POST>\nRequire ",fp_auth);
for (i=0 ; Require[i] ; i++)
if (Require[i]=='%' && Require[i+1]=='u') {
- fputs(name,fp_auth);
+ fputs(uinfo->id,fp_auth);
i++;
} else {
fputc(Require[i],fp_auth);
int z=0;
int count=0;
int cstatus;
+ int new_user;
struct getwordstruct gwarea;
struct longlinestruct line;
struct userinfostruct *uinfo;
exit(1);
}
+ new_user=0;
if(!z) {
strcpy(ouser,user);
strcpy(oip,ip);
z++;
+ new_user=1;
} else {
- if(strcmp(ouser,user) == 0)
- user[0]='\0';
- if(user[0] != '\0')
+ if(strcmp(ouser,user) != 0) {
strcpy(ouser,user);
- if(strcmp(oip,ip) == 0)
- ip[0]='\0';
- if(ip[0] != '\0')
+ new_user=1;
+ }
+ if(strcmp(oip,ip) != 0) {
strcpy(oip,ip);
+ new_user=1;
+ }
}
if(AuthfailReportLimit) {
continue;
}
- fprintf(fp_ou,"<tr><td class=\"data2\">%s</td><td class=\"data2\">%s</td><td class=\"data2\">%s-%s</td><td class=\"data2\">",uinfo->label,ip,data,hora);
+ fputs("<tr>",fp_ou);
+ if (new_user)
+ fprintf(fp_ou,"<td class=\"data2\">%s</td><td class=\"data2\">%s</td>",uinfo->label,ip);
+ else
+ fputs("<td class=\"data2\"></td><td class=\"data2\"></td>",fp_ou);
+ fprintf(fp_ou,"<td class=\"data2\">%s-%s</td><td class=\"data2\">",data,hora);
if(BlockIt[0]!='\0') {
fprintf(fp_ou,"<a href=\"%s%s?url=",wwwDocumentRoot,BlockIt);
output_html_url(fp_ou,url);
-/*! \fn void obtuser(const char *dirname, const char *name, char *tuser)
-Get the number of entries stored in a connection data directory. The number is read from
-the <tt>sarg-users</tt> file of the connection data's directory.
+/*! \fn int obtuser(const char *dirname, const char *name)
+Get the number of entries stored in a report data directory. The number is read from
+the <tt>sarg-users</tt> file of the report data's directory.
-\param dirname The directory to look for the connection directory.
-\param name The name of the connection directory whose <tt>sarg-users</tt> file must be read.
-\param tuser The buffer to store the content of the file. It must be more than 20
-bytes long.
+\param dirname The directory containing the reports.
+\param name The name of the report directory whose <tt>sarg-users</tt> file must be read.
+
+\return The number of entries in the report or zero if the file doesn't exists.
*/
-/*! \fn void obttotal(const char *dirname, const char *name, char *tbytes, const char *tuser, char *media)
-Count the total size transfered in a connection directory and compute the average number of bytes
+/*! \fn void obttotal(const char *dirname, const char *name, char *tbytes, int nuser, char *media)
+Count the total size transfered in a report directory and compute the average number of bytes
per entry.
-\param dirname The directory to look for the connection directory.
-\param name The name of the connection directory whose <tt>sarg-general</tt> file must be read.
-\param tbytes A buffer to store the total number of bytes from this connection.
-\param tuser The number of entries in the connection directory.
+\param dirname The directory containing the reports.
+\param name The name of the report directory whose <tt>sarg-general</tt> file must be read.
+\param tbytes A buffer to store the total number of bytes from this report.
+\param nuser The number of entries in the report directory.
\param media A buffer to store the average number of bytes per entry.
*/
-/*! \fn void subs(char *str, int size, char *from, char *to)
-Replace one occurence of the string \a from by \a to in the string \a str.
-
-\param str The string in which to replace the text.
-\param size The size of the string buffer to detect a buffer overflow if \a to is longer than \a from.
-\param from The fragment of text to replace.
-\param to The text to replace instead of \a from.
-*/
-
-
-
-
-
/*! \fn void removetmp(const char *outdir)
Remove the file <tt>sarg-period</tt> from the output directory and purge the file <tt>sarg-general</tt> from
all the lines but the total.
char *buf;
char arqin[MAXLEN], arqou[MAXLEN], arqper[MAXLEN], arqip[MAXLEN];
char *url, tmsg[50], csort[MAXLEN];
- char period[MAXLEN], usuario[MAXLEN], wusuario[MAXLEN], duser[MAXLEN];
+ char period[MAXLEN], user[MAXLEN], duser[MAXLEN];
char userhora[9], userdia[9];
char user_ip[MAXLEN], olduserip[MAXLEN], tmp2[MAXLEN], tmp3[MAXLEN];
char denied_report[255];
count=1;
if (dlen>0) {
- if (dlen>=sizeof(wusuario)) continue;
- strncpy(wusuario,direntp->d_name,dlen);
- wusuario[dlen]=0;
+ if (dlen>=sizeof(user)) continue;
+ strncpy(user,direntp->d_name,dlen);
+ user[dlen]=0;
} else {
- wusuario[0]=0;
+ user[0]=0;
}
- uinfo=userinfo_find_from_file(wusuario);
+ uinfo=userinfo_find_from_file(user);
if (!uinfo) {
- debuga(_("Unknown user ID %s in directory %s"),wusuario,tmp);
+ debuga(_("Unknown user ID %s in directory %s"),user,tmp);
exit(1);
}
- str=strrchr(wusuario,'.');
+ str=strrchr(user,'.');
if (str)
strcpy(denied_report,str+1);
else
- strcpy(denied_report,wusuario);
+ strcpy(denied_report,user);
- if (snprintf(warea,sizeof(warea),"%s/%s",dirname,wusuario)>=sizeof(warea)) {
- debuga(_("Destination directory too long: %s/%s"),dirname,wusuario);
+ if (snprintf(warea,sizeof(warea),"%s/%s",dirname,user)>=sizeof(warea)) {
+ debuga(_("Destination directory too long: %s/%s"),dirname,user);
exit(1);
}
mkdir(warea,0755);
report_day(uinfo);
greport_day(uinfo);
- strcpy(usuario,wusuario);
if (snprintf(arqin,sizeof(arqin),"%s/%s",tmp,direntp->d_name)>=sizeof(arqin)) {
debuga(_("Input file name too long: %s/%s"),tmp,direntp->d_name);
exit(1);
fputs("</tr>\n",fp_ou);
if(debug) {
- debuga("%s: %s",text[61],usuario);
+ debuga("%s: %s",text[61],uinfo->id);
}
while((buf=longline_read(fp_in,&line))!=NULL) {
ltext110[z1]=tolower(s[z1]);
ltext110[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]);
+ fprintf(fp_ou,"<td class=\"data\"><a href=\"tt%s-%s.html\"><img src=\"%s/datetime.png\" title=\"%s %s\" alt=\"T\"></a></td>",uinfo->filename,siteind,tmp6,ltext110,text[55]);
} else {
fprintf(fp_ou,"<td class=\"data\"></td>");
}
}
if(iprel) {
- strcpy(arqip,tmp);
- strcat(arqip,"/");
- strcat(arqip,usuario);
- strcat(arqip,".ip");
+ if (snprintf(arqip,sizeof(arqip),"%s/%s.ip",tmp,uinfo->filename)>=sizeof(arqip)) {
+ debuga(_("File name too long: %s/%s.ip"),tmp,uinfo->filename);
+ exit(1);
+ }
if ((fp_ip = fopen(arqip, "r")) == 0){
fprintf(stderr, "SARG: (html6) %s: %s\n",text[45],arqip);
write_html_trailer(fp_ou);
fclose(fp_ou);
- htaccess(wusuario);
+ htaccess(uinfo);
}
(void)closedir(dirp);
};
// auth.c
-void htaccess(const char *name);
+void htaccess(const struct userinfostruct *uinfo);
// authfail.c
void authfail_report(void);
void write_html_trailer(FILE *fp_ou);
void output_html_string(FILE *fp_ou,const char *str,int maxlen);
void output_html_url(FILE *fp_ou,const char *url);
-void subs(char *str, int size, char *from, char *to);
void conv_month(char *month);
void debuga(const char *msg,...);
void debugaz(const char *head, const char *msg);
char *buildtime(long long int elap);
void obtdate(const char *dirname, const char *name, char *data);
void formatdate(char *date,int date_size,int year,int month,int day,int hour,int minute,int second,int dst);
-void obtuser(const char *dirname, const char *name, char *tuser);
-void obttotal(const char *dirname, const char *name, char *tbytes, const char *tuser, char *media);
+int obtuser(const char *dirname, const char *name);
+void obttotal(const char *dirname, const char *name, char *tbytes, int nuser, char *media);
void version(void);
int vercode(const char *code);
void load_excludecodes(const char *ExcludeCodes);
-#define VERSION PACKAGE_VERSION" Feb-10-2010"
+#define VERSION PACKAGE_VERSION" Mar-02-2010"
#define PGM PACKAGE_NAME
#define URL "http://sarg.sourceforge.net"
char wdir[MAXLEN];
char month[4];
char data[80];
- char tuser[20];
char tbytes[20];
char media[20];
char ftime[128];
int order;
int i;
int cmp;
+ int tuser;
struct getwordstruct gwarea;
struct sortstruct
{
item=sortlist[i];
else
item=sortlist[nsort-i-1];
- obtuser(outdir,item->dirname,tuser);
+ tuser=obtuser(outdir,item->dirname);
obttotal(outdir,item->dirname,tbytes,tuser,media);
- fprintf(fp_ou,"<tr><td class=\"data2\"><a href='%s/%s'>%s</a></td><td class=\"data2\">%s</td><td class=\"data\">%s</td><td class=\"data\">%s</td><td class=\"data\">%s</td></tr>\n",item->dirname,ReplaceIndex,item->dirname,item->date,tuser,tbytes,media);
+ fprintf(fp_ou,"<tr><td class=\"data2\"><a href='%s/%s'>%s</a></td><td class=\"data2\">%s</td><td class=\"data\">%d</td><td class=\"data\">%s</td><td class=\"data\">%s</td></tr>\n",item->dirname,ReplaceIndex,item->dirname,item->date,tuser,tbytes,media);
}
fputs("</table></div>\n",fp_ou);
write_html_trailer(fp_ou);
while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
getword_start(&gwarea,buf);
if (getword(data,sizeof(data),&gwarea,' ')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+ debuga(_("Maybe you have a broken record or garbage in your %s file"),arq);
exit(1);
}
tt=atoi(data);
fputs("<div class=\"report\"><table cellpadding=\"1\" cellspacing=\"2\">\n",fp_ou);
fputs("<tr><td></td></tr>\n",fp_ou);
- fprintf(fp_ou,"<tr><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th> \
- <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[92],text[93],text[99]);
+ fprintf(fp_ou,"<tr><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th><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[92],text[93],text[99]);
regs=0;
ntopsites = 0;
}
-void obtuser(const char *dirname, const char *name, char *tuser)
+int obtuser(const char *dirname, const char *name)
{
FILE *fp_in;
char wdir[MAXLEN];
+ char tuser[20];
+ int nuser;
sprintf(wdir,"%s%s/sarg-users",dirname,name);
if((fp_in=fopen(wdir,"r"))==NULL) {
sprintf(wdir,"%s%s/users",dirname,name);
if((fp_in=fopen(wdir,"r"))==NULL) {
- tuser[0]='\0';
- return;
+ return(0);
}
}
- if (!fgets(tuser,20,fp_in)) {
- fprintf(stderr,"Failed to read the user in %s\n",wdir);
+ if (!fgets(tuser,sizeof(tuser),fp_in)) {
+ debuga(_("Failed to read the number of users in %s"),wdir);
exit(1);
}
fclose(fp_in);
- fixendofline(tuser);
-
- return;
+ nuser=atoi(tuser);
+ return(nuser);
}
-void obttotal(const char *dirname, const char *name, char *tbytes, const char *tuser, char *media)
+void obttotal(const char *dirname, const char *name, char *tbytes, int nuser, char *media)
{
FILE *fp_in;
char *buf;
char user[MAX_USER_LEN];
char sep;
long long int med=0;
- long long int wtuser=0;
long long int twork=0;
struct getwordstruct gwarea;
struct longlinestruct line;
continue;
getword_start(&gwarea,buf);
if (getword(user,sizeof(user),&gwarea,sep)<0) {
- debuga(_("Maybe you have a invalid user in your %s file"),wdir);
+ debuga(_("There is a invalid user in file %s"),wdir);
exit(1);
}
if(strcmp(warea,"TOTAL") != 0)
continue;
if (getword_skip(MAXLEN,&gwarea,sep)<0) {
- debuga(_("Maybe you have a broken record or garbage in your %s file"),wdir);
+ debuga(_("There a broken total number of access in file %s"),wdir);
exit(1);
}
if (getword_atoll(&twork,&gwarea,sep)<0) {
- debuga(_("Maybe you have a broken record or garbage in your %s file"),wdir);
+ debuga(_("There is a broken number of bytes in file %s"),wdir);
exit(1);
}
strcpy(tbytes,fixnum(twork,1));
fclose(fp_in);
longline_free(&line);
- wtuser=my_atoll(tuser);
- if(wtuser <= 0) {
+ if(nuser <= 0) {
strcpy(media,"0");
return;
}
- med=twork / wtuser;
+ med=twork / nuser;
strcpy(media,fixnum(med,1));
return;
struct stat info;
if (snprintf(images,sizeof(images),"%simages",outdir)>=sizeof(images)) {
- fprintf(stderr,"SARG: Cannot copy images to target directory %simages\n",outdir);
+ debuga(_("Cannot copy images to target directory %simages"),outdir);
exit(1);
}
if (access(images,R_OK)!=0) {
strcpy(imgdir,IMAGEDIR);
dirp = opendir(imgdir);
if(dirp==NULL) {
- fprintf(stderr, "SARG: (util) %s %s: %s\n","Can't open directory", imgdir,strerror(errno));
+ debuga(_("(util) Can't open directory %s: %s"),imgdir,strerror(errno));
return;
}
while ((direntp = readdir( dirp )) != NULL ){
continue;
sprintf(srcfile,"%s/%s",imgdir,direntp->d_name);
if (stat(srcfile,&info)) {
- fprintf(stderr,"SARG: Cannot stat \"%s\" - %s\n",srcfile,strerror(errno));
+ debuga(_("Cannot stat \"%s\" - %s"),srcfile,strerror(errno));
continue;
}
if (S_ISREG(info.st_mode)) {
if(img_ou!=NULL) {
while ((nread = fread(buffer,1,sizeof(buffer),img_in))>0) {
if (fwrite(buffer,1,nread,img_ou)!=nread) {
- fprintf(stderr,"SARG: Failed to copy image %s to %s\n",srcfile,dstfile);
+ debuga(_("Failed to copy image %s to %s"),srcfile,dstfile);
break;
}
}
wdate[sizeof(wdate)-1]='\0';
if(strchr(wdate,'-') == NULL) {
if (strlen(wdate)*2+1>=sizeof(wdate)) {
- fprintf(stderr,"SARG: Invalid date range passed as argument.\n");
+ debuga(_("Invalid date range passed as argument"));
exit(1);
}
strcat(wdate,"-");
}
if (sscanf(wdate,"%d/%d/%d-%d/%d/%d",&diaf,&mesf,&anof,&diau,&mesu,&anou)!=6) {
- fprintf(stderr,"SARG: The date range passed as argument is not formated as dd/mm/yyyy-dd/mm/yyyy.\n");
+ debuga(_("The date range passed as argument is not formated as dd/mm/yyyy-dd/mm/yyyy"));
exit(1);
}
}
-void subs(char *str, int size, char *from, char *to)
-{
- char *tmp;
- int i;
- int ss, st, sf;
- int len;
- int shift;
-
- tmp = strstr(str, from);
- if(tmp == NULL)
- return;
-
- ss = strlen(str);
- sf = strlen(from);
- st = strlen(to);
- shift=st-sf;
-
- if (shift>0) {
- if (ss+shift>=size){
- fprintf(stderr,"SARG: Cannot replace %s by %s in %s and fit within %d bytes\n",from,to,str,size);
- exit(1);
- }
- for (i=strlen(tmp) ; i>=sf ; i--)
- tmp[i+shift]=tmp[i];
- } else if (shift<0) {
- len=strlen(tmp);
- for (i=sf ; i<=len ; i++)
- tmp[i+shift]=tmp[i];
- }
- memcpy(tmp, to, st);
- return;
-}
-
-
void removetmp(const char *outdir)
{
debuga("%s: sarg-general, sarg-period",text[82]);
}
if (snprintf(warea,sizeof(warea),"%s/sarg-general",outdir)>=sizeof(warea)) {
- fprintf(stderr, "SARG: (removetmp) directory too long to remove: %s/sarg-period\n",outdir);
+ debuga(_("(removetmp) directory too long to remove: %s/sarg-period"),outdir);
exit(1);
}
if((fp_in=fopen(warea,"r"))==NULL){
fputs(buf,fp_in);
fclose(fp_in);
if (snprintf(warea,sizeof(warea),"%s/sarg-period",outdir)>=sizeof(warea)) {
- fprintf(stderr, "SARG: (removetmp) directory too long to remove: %s/sarg-period\n",outdir);
+ debuga(_("(removetmp) directory too long to remove: %s/sarg-period"),outdir);
exit(1);
}
unlink(warea);
bzero(excludecode,1024);
if((fp_in=fopen(ExcludeCodes,"r"))==NULL) {
- fprintf(stderr, "SARG: (util) Cannot open file: %s (exclude_codes)\n",ExcludeCodes);
+ debuga(_("(util) Cannot open file: %s (exclude_codes)"),ExcludeCodes);
exit(1);
}
char *ptr;
if (snprintf(cmd,sizeof(cmd),"du -skh %s%s",path,file)>=sizeof(cmd)) {
- printf("SARG: Cannot get disk space because the path %s%s is too long.\n",path,file);
+ debuga(_("Cannot get disk space because the path %s%s is too long"),path,file);
exit(1);
}
fp = popen(cmd, "r");
if (!fgets(response, sizeof(response), fp)) {
- fprintf(stderr,"SARG: Cannot get disk size with command %s",cmd);
+ debuga(_("Cannot get disk size with command %s"),cmd);
exit(1);
}
ptr=strchr(response,'\t');
if (ptr==NULL) {
- fprintf(stderr,"SARG: The command %s failed.\n",cmd);
+ debuga(_("The command %s failed"),cmd);
exit(1);
}
pclose(fp);
printf("SARG: ------------------------------------------------------------------------------\n");
if (snprintf(dir,sizeof(dir),"%s/sarg",tmp)>=sizeof(dir)) {
- fprintf(stderr,"SARG: temporary directory too long: %s/sarg\n",tmp);
+ debuga(_("temporary directory too long: %s/sarg"),tmp);
exit(1);
}
unlinkdir(dir,0);
void version(void)
{
- printf("SARG Version: %s\n",VERSION);
+ printf(_("SARG Version: %s\n"),VERSION);
exit(0);
}
(direntp->d_name[1] == '.' && direntp->d_name[2] == '\0')))
continue;
if (snprintf(dname,sizeof(dname),"%s/%s",dir,direntp->d_name)>=sizeof(dname)) {
- fprintf(stderr,"SARG: directory name to delete too long: %s/%s\n",dir,direntp->d_name);
+ debuga(_("directory name to delete too long: %s/%s"),dir,direntp->d_name);
exit(1);
}
#ifdef HAVE_LSTAT
}
if (S_ISREG(st.st_mode)) {
if (unlink(dname)) {
- fprintf(stderr,"SARG: cannot delete %s - %s\n",dname,strerror(errno));
+ debuga(_("cannot delete %s - %s"),dname,strerror(errno));
exit(1);
}
} else if (S_ISDIR(st.st_mode)) {
unlinkdir(dname,0);
} else {
- fprintf(stderr,"SARG: unknown path type %s\n",dname);
+ debuga(_("unknown path type %s"),dname);
}
}
closedir(dirp);
if (!contentonly) {
if (rmdir(dir)) {
- fprintf(stderr,"SARG: cannot delete %s - %s\n",dir,strerror(errno));
+ debuga(_("cannot delete %s - %s"),dir,strerror(errno));
exit(1);
}
}