/*
* AUTHOR: Pedro Lineu Orso pedro.orso@gmail.com
- * 1998, 2008
+ * 1998, 2010
* SARG Squid Analysis Report Generator http://sarg.sourceforge.net
*
* SARG donations:
char url[MAXLEN];
char wuser[MAXLEN];
char ourl[MAXLEN];
- char nacc[20];
- char nbytes[20];
- char obytes[20];
char csort[255];
char general[MAXLEN];
char general2[MAXLEN];
int regs=0;
int ucount=0;
char *users;
- long long int llbytes=0;
+ long long int nbytes;
+ long long int obytes;
+ long long int nacc;
int cstatus;
+ struct getwordstruct gwarea;
- if(strcmp(Privacy,"yes") == 0)
+ if(Privacy)
return;
nsitesusers = 0;
sprintf(report,"%s/siteuser.html",dirname);
if ((fp_in = fopen(per, "r")) == 0) {
- fprintf(stderr, "SARG: (topuser) %s: %s\n",text[45],per);
+ fprintf(stderr, "SARG: (siteuser) %s: %s\n",text[45],per);
exit(1);
}
- fgets(period,sizeof(period),fp_in);
+ if (!fgets(period,sizeof(period),fp_in)) {
+ fprintf(stderr,"SARG: (siteuser) read error in %s\n",per);
+ exit(1);
+ }
fclose(fp_in);
- sprintf(csort,"sort -k 4,4 -k 1,1 -o '%s' '%s'",general2,general);
+ sprintf(csort,"sort -k 4,4 -k 1,1 -o \"%s\" \"%s\"",general2,general);
cstatus=system(csort);
if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus));
fputs("<div align=\"center\"><table cellpadding=\"0\" cellspacing=\"2\">\n",fp_ou);
fputs("<tr><td></td></tr>\n",fp_ou);
- if(strncmp(strlow(BytesInSitesUsersReport),"yes",3) == 0)
+ if(BytesInSitesUsersReport)
fprintf(fp_ou,"<tr><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th></tr>\n",text[100],text[91],text[93],text[103]);
else
fprintf(fp_ou,"<tr><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th></tr>\n",text[100],text[91],text[103]);
user[0]='\0';
ourl[0]='\0';
- obytes[0]='\0';
+ obytes=0;
if((users=(char *) malloc(204800))==NULL){
fprintf(stderr, "SARG: ERROR: %s",text[87]);
strcpy(users," ");
while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
- if (getword(user,sizeof(user),buf,' ')<0) {
+ getword_start(&gwarea,buf);
+ if (getword(user,sizeof(user),&gwarea,'\t')<0) {
printf("SARG: Maybe you have an invalid user in the %s file of the siteuser.\n",general2);
exit(1);
}
/*
In fact, even the first call is unecessary as the resolved user variable is never used.
- if(strcmp(Ip2Name,"yes") == 0)
+ if(Ip2Name)
ip2name(user,sizeof(user));
*/
if the first ip2name succeed because it will try to resolve a name which is not an IP but if
the first ip2name failed, the second attempt may find the expected address which was resolved
in the mean time by the DNS server.
- if(strcmp(Ip2Name,"yes") == 0)
+ if(Ip2Name)
ip2name(user,sizeof(user));
*/
- if (getword(nacc,sizeof(nacc),buf,' ')<0){
+ if (getword_atoll(&nacc,&gwarea,'\t')<0){
printf("SARG: Maybe you have an invalid number of access in your %s file of the siteuser.\n",general2);
exit(1);
}
- if (atoi(nacc) > 0) nsitesusers = 1;
- if (getword(nbytes,sizeof(nbytes),buf,' ')<0){
+ if (nacc > 0) nsitesusers = 1;
+ if (getword_atoll(&nbytes,&gwarea,'\t')<0){
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),buf,' ')<0) {
+ 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);
exit(1);
}
if(!regs) {
strcpy(ourl,url);
- strcpy(obytes,nbytes);
+ obytes=nbytes;
regs++;
}
else BlockImage[0]='\0';
if(strcmp(url,ourl) != 0 && nsitesusers) {
- if(strncmp(strlow(BytesInSitesUsersReport),"yes",3) == 0) {
- llbytes=my_atoll(obytes);
- sprintf(wwork2,"%s",fixnum(llbytes,1));
+ if(BytesInSitesUsersReport) {
+ sprintf(wwork2,"%s",fixnum(obytes,1));
fprintf(fp_ou,"<tr><td class=\"data\">%d</td><td class=\"data2\">%s<a href=\"http://%s\">%s</a></td><td class=\"data\">%s</td><td class=\"data2\">%s</td></tr>\n",regs,BlockImage,ourl,ourl,wwork2,users);
} else
fprintf(fp_ou,"<tr><td class=\"data\">%d</td><td class=\"data2\">%s<a href=\"http://%s\">%s</a></td><td class=\"data2\">%s</td></tr>\n",regs,BlockImage,ourl,ourl,users);
strcpy(users,name);
strcat(users," ");
strcpy(ourl,url);
- strcpy(obytes,nbytes);
+ obytes=nbytes;
}
}