X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=topuser.c;h=f272fa529afa9528fb03d8e42eeae2d46ba13e80;hb=ffc9b006b8358644c054c5e4c2929791efec7475;hp=52c08cc27b71e2677cc00b665e9b5a5cbdc29fc2;hpb=2240dcea42dc19e969132876a5cfc12688b7356e;p=thirdparty%2Fsarg.git diff --git a/topuser.c b/topuser.c index 52c08cc..f272fa5 100644 --- a/topuser.c +++ b/topuser.c @@ -1,6 +1,6 @@ /* * SARG Squid Analysis Report Generator http://sarg.sourceforge.net - * 1998, 2010 + * 1998, 2015 * * SARG donations: * please look at http://sarg.sourceforge.net/donations.php @@ -27,405 +27,486 @@ #include "include/conf.h" #include "include/defs.h" +extern struct globalstatstruct globstat; +extern bool smartfilter; + +/*! +Save the total number of users. The number is written in sarg-users and set +in a global variable for further reference. + +\param totuser The total number of users. +*/ +static void set_total_users(int totuser) +{ + char tusr[1024]; + FILE *fp_ou; + + snprintf(tusr,sizeof(tusr),"%s/sarg-users",outdirname); + if((fp_ou=fopen(tusr,"w"))==NULL) { + debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),tusr,strerror(errno)); + exit(EXIT_FAILURE); + } + fprintf(fp_ou,"%d\n",totuser); + if (fclose(fp_ou)==EOF) { + debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),tusr,strerror(errno)); + exit(EXIT_FAILURE); + } + globstat.totuser=totuser; +} + void topuser(void) { + FILE *fp_in = NULL, *fp_top1 = NULL, *fp_top2 = NULL, *fp_top3 = NULL; + long long int ttnbytes=0, ttnacc=0, tnacc=0; + long long int tnbytes=0, ttnelap=0, tnelap=0; + long long int tnincache=0, tnoucache=0, ttnincache=0, ttnoucache=0; + long long int nbytes; + long long int nacc; + long long int elap, incac, oucac; + double perc=0.00; + double perc2=0.00; + double inperc=0.00, ouperc=0.00; + int posicao=0; + char olduser[MAX_USER_LEN], csort[MAXLEN]; + char wger[MAXLEN], top1[MAXLEN], top2[MAXLEN], top3[MAXLEN]; + char user[MAX_USER_LEN]; + const char *sfield="-n -k 2,2"; + const char *order; + const char *sort_field; + const char *sort_order; + char title[80]; + char *warea; + int totuser=0; + int topcount=0; + int cstatus; + struct getwordstruct gwarea; + longline line; + struct generalitemstruct item; + struct userinfostruct *uinfo; + + if (debugz>=LogLevel_Process) + debuga(__FILE__,__LINE__,_("Creating top users report...\n")); + ntopuser = 0; + snprintf(wger,sizeof(wger),"%s/sarg-general",outdirname); + if((fp_in=fopen(wger,"r"))==NULL) { + debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),wger,strerror(errno)); + exit(EXIT_FAILURE); + } + + snprintf(top2,sizeof(top2),"%s/top.tmp",outdirname); + if((fp_top2=fopen(top2,"w"))==NULL) { + debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),top2,strerror(errno)); + exit(EXIT_FAILURE); + } + + olduser[0]='\0'; + totuser=0; + + if ((line=longline_create())==NULL) { + debuga(__FILE__,__LINE__,_("Not enough memory to read file \"%s\"\n"),wger); + exit(EXIT_FAILURE); + } + + while((warea=longline_read(fp_in,line))!=NULL) { + ger_read(warea,&item,wger); + if(item.total) continue; + if(strcmp(olduser,item.user) != 0) { + totuser++; + + if (olduser[0] != '\0') { + /* + This complicated printf is due to Microsoft's inability to comply with any standard. Msvcrt is unable + to print a long long int unless it is exactly 64-bits long. + */ + fprintf(fp_top2,"%s\t%"PRIu64"\t%"PRIu64"\t%"PRIu64"\t%"PRIu64"\t%"PRIu64"\n",olduser,(uint64_t)tnbytes,(uint64_t)tnacc,(uint64_t)tnelap,(uint64_t)tnincache,(uint64_t)tnoucache); + + ttnbytes+=tnbytes; + ttnacc+=tnacc; + ttnelap+=tnelap; + ttnincache+=tnincache; + ttnoucache+=tnoucache; + } + strcpy(olduser,item.user); + tnbytes=0; + tnacc=0; + tnelap=0; + tnincache=0; + tnoucache=0; + } + + tnbytes+=item.nbytes; + tnacc+=item.nacc; + tnelap+=item.nelap; + tnincache+=item.incache; + tnoucache+=item.oucache; + } + if (fclose(fp_in)==EOF) { + debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),wger,strerror(errno)); + exit(EXIT_FAILURE); + } + longline_destroy(&line); + + if (olduser[0] != '\0') { + /* + This complicated printf is due to Microsoft's inability to comply with any standard. Msvcrt is unable + to print a long long int unless it is exactly 64-bits long. + */ + fprintf(fp_top2,"%s\t%"PRIu64"\t%"PRIu64"\t%"PRIu64"\t%"PRIu64"\t%"PRIu64"\n",olduser,(uint64_t)tnbytes,(uint64_t)tnacc,(uint64_t)tnelap,(uint64_t)tnincache,(uint64_t)tnoucache); + + ttnbytes+=tnbytes; + ttnacc+=tnacc; + ttnelap+=tnelap; + ttnincache+=tnincache; + ttnoucache+=tnoucache; + } + if (fclose(fp_top2)==EOF) { + debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),top2,strerror(errno)); + exit(EXIT_FAILURE); + } + +#ifdef ENABLE_DOUBLE_CHECK_DATA + if (ttnacc!=globstat.nacc || ttnbytes!=globstat.nbytes || ttnelap!=globstat.elap || + ttnincache!=globstat.incache || ttnoucache!=globstat.oucache) { + debuga(__FILE__,__LINE__,_("Total statistics mismatch when reading \"%s\" to produce the top users\n"),wger); + exit(EXIT_FAILURE); + } +#endif - FILE *fp_in = NULL, *fp_ou = NULL, *fp_top1 = NULL, *fp_top2 = NULL, *fp_top3 = NULL; - long long int ttnbytes=0, ttnacc=0, tnacc=0; - long long int tnbytes=0, ttnelap=0, tnelap=0; - long long int tnincache=0, tnoucache=0, ttnincache=0, ttnoucache=0; - long long int nbytes; - long long int nacc; - long long int elap, incac, oucac; - double perc=0.00; - double perc2=0.00; - double inperc=0.00, ouperc=0.00; - int posicao=0; - char olduser[MAX_USER_LEN], csort[MAXLEN], period[MAXLEN], arqper[MAXLEN]; - char wger[MAXLEN], top1[MAXLEN], top2[MAXLEN], top3[MAXLEN]; - char user[MAX_USER_LEN], tusr[MAXLEN]; - char ipantes[MAXLEN], nameantes[MAXLEN]; - char sfield[10]="2,2"; - char order[255]="-r"; - char title[80]; - char *warea; - char user2[MAXLEN]; - char name[MAXLEN]; - char ltext110[100]; - int totuser=0; - int topcount=0; - int i; - char *s; - int cstatus; - struct getwordstruct gwarea; - struct longlinestruct line; - struct generalitemstruct item; - - ipantes[0]='\0'; - nameantes[0]='\0'; - - /* - * get period - */ - strcpy(arqper,dirname); - strcat(arqper,"/sarg-period"); - if ((fp_in = fopen(arqper, "r")) == 0) { - fprintf(stderr, "SARG: (topuser) %s: %s\n",text[45],arqper); - exit(1); - } - if (!fgets(period,sizeof(period),fp_in)) { - fprintf(stderr,"SARG: (topuser) Read error in %s\n",arqper); - exit(1); - } - fclose(fp_in); - - strcpy(wger,dirname); - strcpy(top1,dirname); - strcpy(top2,dirname); - strcpy(top3,dirname); - strcpy(tusr,dirname); - strcat(wger,"/sarg-general"); - strcat(top1,"/top"); - strcat(top2,"/top.tmp"); - strcat(tusr,"/sarg-users"); - strcat(top3,"/index.html"); - - ntopuser = 0; - if((fp_in=fopen(wger,"r"))==NULL) { - fprintf(stderr, "SARG: (topuser) %s: %s\n",text[45],wger); - exit(1); - } - - if((fp_top2=fopen(top2,"w"))==NULL) { - fprintf(stderr, "SARG: (topuser) %s: %s\n",text[45],top2); - exit(1); - } - - olduser[0]='\0'; - totuser=0; - - if (longline_prepare(&line)<0) { - debuga(_("Not enough memory to read the file %s"),wger); - exit(1); - } - - while((warea=longline_read(fp_in,&line))!=NULL) { - ger_read(warea,&item,wger); - if(item.total) continue; - if(strcmp(olduser,item.user) != 0) { - totuser++; - - if (olduser[0] != '\0') { - 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; - ttnelap+=tnelap; - ttnincache+=tnincache; - ttnoucache+=tnoucache; - } - strcpy(olduser,item.user); - tnbytes=0; - tnacc=0; - tnelap=0; - tnincache=0; - tnoucache=0; - } - - tnbytes+=item.nbytes; - tnacc+=item.nacc; - tnelap+=item.nelap; - tnincache+=item.incache; - tnoucache+=item.oucache; - } - fclose(fp_in); - longline_free(&line); - - if (olduser[0] != '\0') { - 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; - ttnelap+=tnelap; - ttnincache+=tnincache; - ttnoucache+=tnoucache; - } - fclose(fp_top2); - - strup(TopuserSortField); - strlow(TopuserSortOrder); - - if(strcmp(TopuserSortField,"USER") == 0) - strcpy(sfield,"1,1"); - - if(strcmp(TopuserSortField,"CONNECT") == 0) - strcpy(sfield,"3,3"); - - if(strcmp(TopuserSortField,"TIME") == 0) - strcpy(sfield,"4,4"); - - if(strcmp(TopuserSortOrder,"normal") == 0) - order[0]='\0'; - - sprintf(csort,"sort -n -T \"%s\" %s -k %s -o \"%s\" \"%s\"", TempDir, order, sfield, top1, top2); - cstatus=system(csort); - if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { - fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus)); - fprintf(stderr, "SARG: sort command: %s\n",csort); - exit(1); - } - - if((fp_top1=fopen(top1,"r"))==NULL) { - fprintf(stderr, "SARG: (topuser) %s: %s\n",text[45],top1); - exit(1); - } - - unlink(top2); - - if((fp_top3=fopen(top3,"w"))==NULL) { - fprintf(stderr, "SARG: (topuser) %s: %s\n",text[45],top3); - exit(1); - } - - snprintf(title,sizeof(title),_("SARG report for %s"),period); - write_html_header(fp_top3,(IndexTree == INDEX_TREE_DATE) ? 3 : 1,title); - fprintf(fp_top3,"%s: %s\n",text[89],period); - fprintf(fp_top3,"%s: %s, %s\n",text[104],TopuserSortField,TopuserSortOrder); - fprintf(fp_top3,"%s\n",text[137]); - close_html_header(fp_top3); - - fputs("
\n",fp_top3); - fputs("\n",fp_top3); - - if((ReportType & REPORT_TYPE_TOPSITES) != 0 && !Privacy) fprintf(fp_top3,"\n",text[119]); - if((ReportType & REPORT_TYPE_SITES_USERS) != 0 && !Privacy) fprintf(fp_top3,"\n",text[85]); - if(dansguardian_count) fprintf(fp_top3,"\n",text[128]); - if(squidguard_count) fprintf(fp_top3,"\n",text[122]); - if ((ReportType & REPORT_TYPE_DOWNLOADS) != 0 && download_count && !Privacy && ndownload) fprintf(fp_top3,"\n",text[125]); - if ((ReportType & REPORT_TYPE_DENIED) != 0 && denied_count && !Privacy) fprintf(fp_top3,"\n",text[118]); - if ((ReportType & REPORT_TYPE_AUTH_FAILURES) != 0 && authfail_count && !Privacy) fprintf(fp_top3,"\n",text[117]); - if(smartfilter) fprintf(fp_top3,"\n",text[116]); - if(UserAgentLog[0] != '\0' && useragent_count) fprintf(fp_top3,"\n",_("Useragent")); - fputs("\n
  
%s
%s
%s
%s
%s
%s
%s
%s
%s
\n",fp_top3); - - if ((ReportType & REPORT_TYPE_TOPUSERS) == 0) { - fputs("\n\n",fp_top3); - fclose (fp_top3); - return; - } - - fputs("
\n",fp_top3); - fputs("",fp_top3); - - if((TopUserFields & TOPUSERFIELDS_NUM) != 0) - fprintf(fp_top3,"",text[100]); - if((TopUserFields & TOPUSERFIELDS_DATE_TIME) !=0 && (ReportType & REPORT_TYPE_DATE_TIME) != 0) - fputs("",fp_top3); - if((TopUserFields & TOPUSERFIELDS_USERID) != 0) - fprintf(fp_top3,"",text[98]); - if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0) - fprintf(fp_top3,"",text[92]); - if((TopUserFields & TOPUSERFIELDS_BYTES) != 0) - fprintf(fp_top3,"",text[93]); - if((TopUserFields & TOPUSERFIELDS_SETYB) != 0) - fprintf(fp_top3,"",text[93]); - if((TopUserFields & TOPUSERFIELDS_IN_CACHE_OUT) != 0) - fprintf(fp_top3,"",text[113],text[114],text[112]); - if((TopUserFields & TOPUSERFIELDS_USED_TIME) != 0) - fprintf(fp_top3,"",text[94]); - if((TopUserFields & TOPUSERFIELDS_MILISEC) != 0) - fprintf(fp_top3,"",text[95]); - if((TopUserFields & TOPUSERFIELDS_PTIME) != 0) - fprintf(fp_top3,"",text[99]); - - fputs("\n",fp_top3); - - ntopuser = 0; - - if (longline_prepare(&line)<0) { - debuga(_("Not enough memory to read the downloaded files")); - exit(1); - } - - while((warea=longline_read(fp_top1,&line))!=NULL) { - getword_start(&gwarea,warea); - if (getword(user,sizeof(user),&gwarea,'\t')<0) { - printf("SARG: Maybe you have a broken user in your %s file.\n",top1); - exit(1); - } - if (getword_atoll(&nbytes,&gwarea,'\t')<0) { - printf("SARG: Maybe you have a broken number of bytes in your %s file.\n",top1); - exit(1); - } - if (getword_atoll(&nacc,&gwarea,'\t')<0) { - printf("SARG: Maybe you have a broken number of access in your %s file.\n",top1); - exit(1); - } - if (getword_atoll(&elap,&gwarea,'\t')<0) { - printf("SARG: Maybe you have a broken elpased time in your %s file.\n",top1); - exit(1); - } - if (getword_atoll(&incac,&gwarea,'\t')<0) { - printf("SARG: Maybe you have a broken in-cache size in your %s file.\n",top1); - exit(1); - } - if (getword_atoll(&oucac,&gwarea,'\n')<0) { - printf("SARG: Maybe you have a broken out-of-cache size in your %s file.\n",top1); - exit(1); - } - if(nacc < 1) - continue; - ntopuser = 1; - if(TopUsersNum > 0 && topcount >= TopUsersNum) break; - tnbytes=nbytes; - tnelap=elap; - - strcpy(user2,user); - if(userip) { - fixip(user2); - if(Ip2Name) { - if(strcmp(user2,ipantes) != 0) { - strcpy(ipantes,user2); - ip2name(user2,sizeof(user2)); - strcpy(nameantes,user2); - } else strcpy(user2,nameantes); - } - } - - fputs("",fp_top3); - - posicao++; - if((TopUserFields & TOPUSERFIELDS_NUM) != 0) - fprintf(fp_top3,"",posicao); - - user_find(name, sizeof(name), user2); - if(Ip2Name && - ((str=(char *) strstr(name, ".")) != (char *) NULL) && - ((str=(char *) strstr(str+1, ".")) != (char *) NULL)) - ip2name(name,sizeof(name)); - if(dotinuser && strchr(name,'_')) { - subs(name,sizeof(name),"_","."); - } - - if((TopUserFields & TOPUSERFIELDS_DATE_TIME) !=0 && (ReportType & REPORT_TYPE_DATE_TIME) != 0) { - s=text[110]; - for(i=0 ; i",fp_top3); + set_total_users(totuser); + + if((TopuserSort & TOPUSER_SORT_USER) != 0) { + sfield="-k 1,1"; + sort_field=_("user"); + } else if((TopuserSort & TOPUSER_SORT_CONNECT) != 0) { + sfield="-n -k 3,3"; + sort_field=_("connect"); + } else if((TopuserSort & TOPUSER_SORT_TIME) != 0) { + sfield="-n -k 4,4"; + sort_field=pgettext("duration","time"); + } else { + sort_field=_("bytes"); + } + + if((TopuserSort & TOPUSER_SORT_REVERSE) == 0) { + order=""; + sort_order=_("normal"); + } else { + order="-r"; + sort_order=_("reverse"); + } + + snprintf(top1,sizeof(top1),"%s/top",outdirname); + if (snprintf(csort,sizeof(csort),"sort -T \"%s\" -t \"\t\" %s %s -o \"%s\" \"%s\"", tmp, order, sfield, top1, top2)>=sizeof(csort)) { + debuga(__FILE__,__LINE__,_("Sort command too long when sorting file \"%s\" to \"%s\"\n"),top2,top1); + exit(EXIT_FAILURE); + } + cstatus=system(csort); + if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { + debuga(__FILE__,__LINE__,_("sort command return status %d\n"),WEXITSTATUS(cstatus)); + debuga(__FILE__,__LINE__,_("sort command: %s\n"),csort); + exit(EXIT_FAILURE); + } + + if((fp_top1=fopen(top1,"r"))==NULL) { + debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),top1,strerror(errno)); + exit(EXIT_FAILURE); + } + + if (!KeepTempLog && unlink(top2)) { + debuga(__FILE__,__LINE__,_("Cannot delete \"%s\": %s\n"),top2,strerror(errno)); + exit(EXIT_FAILURE); + } + + snprintf(top3,sizeof(top3),"%s/"INDEX_HTML_FILE,outdirname); + if((fp_top3=fopen(top3,"w"))==NULL) { + debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),top3,strerror(errno)); + exit(EXIT_FAILURE); + } + + snprintf(title,sizeof(title),_("SARG report for %s"),period.text); + write_html_header(fp_top3,(IndexTree == INDEX_TREE_DATE) ? 3 : 1,title,HTML_JS_SORTTABLE); + fputs("\n",fp_top3); + if ((ReportType & REPORT_TYPE_TOPUSERS) != 0) { + fputs("\n",fp_top3); + fprintf(fp_top3,"\n",_("Top users")); + } else { + /* TRANSLATORS: This is the title of the main report page when no + * top users list are requested. + */ + fprintf(fp_top3,"\n",_("Table of content")); + } + close_html_header(fp_top3); + + if (!indexonly) { + fputs("
%s%s%s%s%%%s%s-%s-%s%s%s%%%s
%d
",fp_top3); + fprintf(fp_top3,_("Period: %s"),period.html); + fputs("
",fp_top3); + fprintf(fp_top3,_("Sort: %s, %s"),sort_field,sort_order); + fputs("
%s
%s
\n",fp_top3); + if((ReportType & REPORT_TYPE_TOPSITES) != 0 && !Privacy) fprintf(fp_top3,"\n",_("Top sites")); + if((ReportType & REPORT_TYPE_SITES_USERS) != 0 && !Privacy) fprintf(fp_top3,"\n",_("Sites & Users")); + if(dansguardian_count) fprintf(fp_top3,"\n",_("DansGuardian")); + if(redirector_count) fprintf(fp_top3,"\n",_("Redirector")); + if (is_download()) fprintf(fp_top3,"\n",_("Downloads")); + if (is_denied()) fprintf(fp_top3,"\n",_("Denied accesses")); + if (is_authfail()) fprintf(fp_top3,"\n",_("Authentication Failures")); + if(smartfilter) fprintf(fp_top3,"\n",_("SmartFilter")); + if(UserAgentLog[0] != '\0' && useragent_count) fprintf(fp_top3,"\n",_("Useragent")); + fputs("\n
%s
%s
%s
%s
%s
%s
%s
%s
%s
\n",fp_top3); + } + + if ((ReportType & REPORT_TYPE_TOPUSERS) == 0) { + fputs("\n\n",fp_top3); + if (fclose (fp_top3)==EOF) { + debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),top3,strerror(errno)); + exit(EXIT_FAILURE); + } + if (debugz>=LogLevel_Process) debugaz(__FILE__,__LINE__,_("No top users report because it is not configured in report_type\n")); + return; + } + + fputs("
\n",fp_top3); + + if((TopUserFields & TOPUSERFIELDS_NUM) != 0) + fprintf(fp_top3,"",_("NUM")); + if((TopUserFields & TOPUSERFIELDS_DATE_TIME) !=0 && (ReportType & REPORT_TYPE_DATE_TIME) != 0 && !indexonly) { + fputs("",fp_top3); + } + if((TopUserFields & TOPUSERFIELDS_USERID) != 0) { + fputs("",_("USERID")); + } + if((TopUserFields & TOPUSERFIELDS_USERIP) != 0) { + fputs("",_("USERIP")); + } + if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0) + fprintf(fp_top3,"",_("CONNECT")); + if((TopUserFields & TOPUSERFIELDS_BYTES) != 0) + fprintf(fp_top3,"",_("BYTES")); + if((TopUserFields & TOPUSERFIELDS_SETYB) != 0) + fprintf(fp_top3,"",_("BYTES")); + if((TopUserFields & TOPUSERFIELDS_IN_CACHE_OUT) != 0) + fprintf(fp_top3,"",_("IN-CACHE-OUT")); + if((TopUserFields & TOPUSERFIELDS_USED_TIME) != 0) + fprintf(fp_top3,"",_("ELAPSED TIME")); + if((TopUserFields & TOPUSERFIELDS_MILISEC) != 0) + fprintf(fp_top3,"",_("MILLISEC")); + if((TopUserFields & TOPUSERFIELDS_PTIME) != 0) + fprintf(fp_top3,"",pgettext("duration","TIME")); + + fputs("\n",fp_top3); + + greport_prepare(); + + ntopuser = 0; + + if ((line=longline_create())==NULL) { + debuga(__FILE__,__LINE__,_("Not enough memory to read file \"%s\"\n"),top1); + exit(EXIT_FAILURE); + } + + while((warea=longline_read(fp_top1,line))!=NULL) { + getword_start(&gwarea,warea); + if (getword(user,sizeof(user),&gwarea,'\t')<0) { + debuga(__FILE__,__LINE__,_("Invalid user in file \"%s\"\n"),top1); + exit(EXIT_FAILURE); + } + if (getword_atoll(&nbytes,&gwarea,'\t')<0) { + debuga(__FILE__,__LINE__,_("Invalid number of bytes in file \"%s\"\n"),top1); + exit(EXIT_FAILURE); + } + if (getword_atoll(&nacc,&gwarea,'\t')<0) { + debuga(__FILE__,__LINE__,_("Invalid number of accesses in file \"%s\"\n"),top1); + exit(EXIT_FAILURE); + } + if (getword_atoll(&elap,&gwarea,'\t')<0) { + debuga(__FILE__,__LINE__,_("Invalid elapsed time in file \"%s\"\n"),top1); + exit(EXIT_FAILURE); + } + if (getword_atoll(&incac,&gwarea,'\t')<0) { + debuga(__FILE__,__LINE__,_("Invalid in-cache size in file \"%s\"\n"),top1); + exit(EXIT_FAILURE); + } + if (getword_atoll(&oucac,&gwarea,'\n')<0) { + debuga(__FILE__,__LINE__,_("Invalid out-of-cache size in file \"%s\"\n"),top1); + exit(EXIT_FAILURE); + } + if(nacc < 1) + continue; + ntopuser = 1; + if(TopUsersNum > 0 && topcount >= TopUsersNum) break; + tnbytes=nbytes; + tnelap=elap; + + uinfo=userinfo_find_from_id(user); + if (!uinfo) { + debuga(__FILE__,__LINE__,_("Unknown user ID %s in file \"%s\"\n"),user,top1); + exit(EXIT_FAILURE); + } + uinfo->topuser=1; + + fputs("",fp_top3); + + posicao++; + if((TopUserFields & TOPUSERFIELDS_NUM) != 0) + fprintf(fp_top3,"",posicao); + + if (!indexonly) { + if((TopUserFields & TOPUSERFIELDS_DATE_TIME) !=0 && (ReportType & REPORT_TYPE_DATE_TIME) != 0) { + fputs("",uinfo->filename,uinfo->filename,ImageFile,_("date/time report")); + day_deletefile(uinfo); + } + } + if((TopUserFields & TOPUSERFIELDS_USERID) != 0) { + if((ReportType & REPORT_TYPE_USERS_SITES) == 0 || indexonly) + fprintf(fp_top3,"",uinfo->label); + else + fprintf(fp_top3,"",uinfo->filename,uinfo->filename,uinfo->label); + } + if((TopUserFields & TOPUSERFIELDS_USERIP) != 0) { + fprintf(fp_top3,"",uinfo->ip); + } + if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0) { + fputs("",fixnum(nacc,1)); + } + if((TopUserFields & TOPUSERFIELDS_BYTES) != 0) { + fputs("",fixnum(tnbytes,1)); + } + if((TopUserFields & TOPUSERFIELDS_SETYB) != 0) { + perc=(ttnbytes) ? tnbytes * 100. / ttnbytes : 0.; + fprintf(fp_top3,"",perc); + } + if((TopUserFields & TOPUSERFIELDS_IN_CACHE_OUT) != 0) { + inperc=(tnbytes) ? incac * 100. / tnbytes : 0.; + ouperc=(tnbytes) ? oucac * 100. / tnbytes : 0.; + fprintf(fp_top3,"",inperc,ouperc); +#ifdef ENABLE_DOUBLE_CHECK_DATA + if ((inperc!=0. || ouperc!=0.) && fabs(inperc+ouperc-100.)>=0.01) { + debuga(__FILE__,__LINE__,_("The total of the in-cache and cache-miss is not 100%% at position %d (user %s)\n"),posicao,uinfo->label); + } +#endif + } + if((TopUserFields & TOPUSERFIELDS_USED_TIME) != 0) { + fputs("",buildtime(tnelap)); + } + if((TopUserFields & TOPUSERFIELDS_MILISEC) != 0) { + fputs("",fixnum2(tnelap,1)); + } + if((TopUserFields & TOPUSERFIELDS_PTIME) != 0) { + perc2=(ttnelap) ? elap * 100. / ttnelap : 0.; + fprintf(fp_top3,"",perc2); + } + + fputs("\n",fp_top3); + + topcount++; + } + if (fclose(fp_top1)==EOF) { + debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),top1,strerror(errno)); + exit(EXIT_FAILURE); + } + if (!KeepTempLog && unlink(top1)) { + debuga(__FILE__,__LINE__,_("Cannot delete \"%s\": %s\n"),top1,strerror(errno)); + exit(EXIT_FAILURE); + } + longline_destroy(&line); + + if((TopUserFields & TOPUSERFIELDS_TOTAL) != 0) { + fputs("",fp_top3); + if((TopUserFields & TOPUSERFIELDS_NUM) != 0) + fputs("",fp_top3); + if((TopUserFields & TOPUSERFIELDS_DATE_TIME) !=0 && (ReportType & REPORT_TYPE_DATE_TIME) != 0 && !indexonly) + fputs("",fp_top3); + if((TopUserFields & TOPUSERFIELDS_USERIP) != 0) + fprintf(fp_top3,"",_("TOTAL")); + else + fprintf(fp_top3,"",_("TOTAL")); + + if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0) + fprintf(fp_top3,"",fixnum(ttnacc,1)); + if((TopUserFields & TOPUSERFIELDS_BYTES) != 0) + fprintf(fp_top3,"",fixnum(ttnbytes,1)); + if((TopUserFields & TOPUSERFIELDS_SETYB) != 0) + fputs("",fp_top3); + if((TopUserFields & TOPUSERFIELDS_IN_CACHE_OUT) != 0) + { + inperc=(ttnbytes) ? ttnincache * 100. / ttnbytes : 0.; + ouperc=(ttnbytes) ? ttnoucache *100. / ttnbytes : 0.; + fprintf(fp_top3,"",inperc,ouperc); +#ifdef ENABLE_DOUBLE_CHECK_DATA + if (fabs(inperc+ouperc-100.)>=0.01) { + debuga(__FILE__,__LINE__,_("The total of the in-cache and cache-miss is not 100%%\n")); + } #endif - fputs("\" alt=\"T\">",fp_top3); - } else { - sprintf(val1,"%s/d%s.html",dirname,user); - unlink(val1); - } - if((TopUserFields & TOPUSERFIELDS_USERID) != 0) { - if((ReportType & REPORT_TYPE_USERS_SITES) == 0) - fprintf(fp_top3,"",name); - else - fprintf(fp_top3,"",user,user,name); - } - if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0) - fprintf(fp_top3,"",fixnum(nacc,1)); - if((TopUserFields & TOPUSERFIELDS_BYTES) != 0) - fprintf(fp_top3,"",fixnum(tnbytes,1)); - if((TopUserFields & TOPUSERFIELDS_SETYB) != 0) { - perc=(ttnbytes) ? tnbytes * 100. / ttnbytes : 0.; - fprintf(fp_top3,"",perc); - } - if((TopUserFields & TOPUSERFIELDS_IN_CACHE_OUT) != 0) { - inperc=(tnbytes) ? incac * 100. / tnbytes : 0.; - ouperc=(tnbytes) ? oucac * 100. / tnbytes : 0.; - fprintf(fp_top3,"",inperc,ouperc); - } - if((TopUserFields & TOPUSERFIELDS_USED_TIME) != 0) - fprintf(fp_top3,"",buildtime(tnelap)); - if((TopUserFields & TOPUSERFIELDS_MILISEC) != 0) - fprintf(fp_top3,"",fixnum2(tnelap,1)); - if((TopUserFields & TOPUSERFIELDS_PTIME) != 0) { - perc2=(ttnelap) ? elap * 100. / ttnelap : 0.; - fprintf(fp_top3,"",perc2); - } - - fputs("\n",fp_top3); - - topcount++; - } - fclose(fp_top1); - unlink(top1); - longline_free(&line); - - if((TopUserFields & TOPUSERFIELDS_TOTAL) != 0) { - fputs("",fp_top3); - if((TopUserFields & TOPUSERFIELDS_NUM) != 0) - fputs("",fp_top3); - if((TopUserFields & TOPUSERFIELDS_DATE_TIME) !=0 && (ReportType & REPORT_TYPE_DATE_TIME) != 0) - fputs("",fp_top3); - fprintf(fp_top3,"",text[107]); - - if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0) - fprintf(fp_top3,"",fixnum(ttnacc,1)); - if((TopUserFields & TOPUSERFIELDS_BYTES) != 0) - fprintf(fp_top3,"",fixnum(ttnbytes,1)); - if((TopUserFields & TOPUSERFIELDS_SETYB) != 0) - fputs("",fp_top3); - if((TopUserFields & TOPUSERFIELDS_IN_CACHE_OUT) != 0) - { - inperc=(ttnbytes) ? ttnincache * 100. / ttnbytes : 0.; - ouperc=(ttnbytes) ? ttnoucache *100. / ttnbytes : 0.; - fprintf(fp_top3,"",inperc,ouperc); - } - if((TopUserFields & TOPUSERFIELDS_USED_TIME) != 0) - fprintf(fp_top3,"",buildtime(ttnelap)); - if((TopUserFields & TOPUSERFIELDS_MILISEC) != 0) - fprintf(fp_top3,"",fixnum2(ttnelap,1)); - - fputs("\n",fp_top3); - } - - if(ntopuser && (TopUserFields & TOPUSERFIELDS_AVERAGE) != 0) { - fputs("",fp_top3); - if((TopUserFields & TOPUSERFIELDS_NUM) != 0) - fputs("",fp_top3); - if((TopUserFields & TOPUSERFIELDS_DATE_TIME) !=0 && (ReportType & REPORT_TYPE_DATE_TIME) != 0) - fputs("",fp_top3); - fprintf(fp_top3,"",text[96]); - - if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0) - fprintf(fp_top3,"",fixnum(ttnacc/totuser,1)); - if((TopUserFields & TOPUSERFIELDS_BYTES) != 0) { - tnbytes=(totuser) ? ttnbytes / totuser : 0; - fprintf(fp_top3,"",fixnum(tnbytes,1)); - } - if((TopUserFields & TOPUSERFIELDS_SETYB) != 0) - fputs("",fp_top3); - if((TopUserFields & TOPUSERFIELDS_IN_CACHE_OUT) != 0) - fputs("",fp_top3); - if((TopUserFields & TOPUSERFIELDS_USED_TIME) != 0) - fprintf(fp_top3,"",buildtime(ttnelap/totuser)); - if((TopUserFields & TOPUSERFIELDS_MILISEC) != 0) - fprintf(fp_top3,"",fixnum2(ttnelap/totuser,1)); - fputs("\n",fp_top3); - } - - fputs("
%s%s%s%s%s%%%s%s%s%s%%%s
%d",fp_top3); #ifdef HAVE_GD - if(Graphs && GraphFont[0]!='\0') { - fprintf(fp_top3,"\"G\" ",user,ImageFile,text[126]); - } + if(Graphs && GraphFont[0]!='\0') { + greport_day(uinfo); + //fprintf(fp_top3,"\"G\" ",uinfo->filename,ImageFile,_("Graphic")); + fprintf(fp_top3,"\"G\" ",uinfo->filename,ImageFile,_("Graphic")); + } #endif - fprintf(fp_top3,"\"T\"%s%s%s%s%s%3.2lf%%%3.2lf%%%3.2lf%%%s%s%3.2lf%%
%s%s%s%15s%3.2lf%%%3.2lf%%%s%s%s%s%3.2lf%%%3.2lf%%%3.2lf%%%s%s%3.2lf%%
%s%s%15s%3.2lf%%%3.2lf%%%s%s
%s%s%15s%s%s
\n",fp_top3); - write_html_trailer(fp_top3); - fclose(fp_top3); - - if((fp_ou=fopen(tusr,"w"))==NULL) { - fprintf(stderr, "SARG: (topuser) %s: %s\n",text[45],tusr); - exit(1); - } - fprintf(fp_ou,"%d\n",totuser); - fclose(fp_ou); - - return; + } + if((TopUserFields & TOPUSERFIELDS_USED_TIME) != 0) + fprintf(fp_top3,"%s",buildtime(ttnelap)); + if((TopUserFields & TOPUSERFIELDS_MILISEC) != 0) + fprintf(fp_top3,"%s",fixnum2(ttnelap,1)); + + fputs("\n",fp_top3); + } + greport_cleanup(); + + if(ntopuser && (TopUserFields & TOPUSERFIELDS_AVERAGE) != 0) { + fputs("",fp_top3); + if((TopUserFields & TOPUSERFIELDS_NUM) != 0) + fputs("",fp_top3); + if((TopUserFields & TOPUSERFIELDS_DATE_TIME) !=0 && (ReportType & REPORT_TYPE_DATE_TIME) != 0 && !indexonly) + fputs("",fp_top3); + if((TopUserFields & TOPUSERFIELDS_USERIP) != 0) + fprintf(fp_top3,"%s",_("AVERAGE")); + else + fprintf(fp_top3,"%s",_("AVERAGE")); + + if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0) + fprintf(fp_top3,"%s",fixnum(ttnacc/totuser,1)); + if((TopUserFields & TOPUSERFIELDS_BYTES) != 0) { + tnbytes=(totuser) ? ttnbytes / totuser : 0; + fprintf(fp_top3,"%15s",fixnum(tnbytes,1)); + } + if((TopUserFields & TOPUSERFIELDS_SETYB) != 0) + fputs("",fp_top3); + if((TopUserFields & TOPUSERFIELDS_IN_CACHE_OUT) != 0) + fputs("",fp_top3); + if((TopUserFields & TOPUSERFIELDS_USED_TIME) != 0) + fprintf(fp_top3,"%s",buildtime(ttnelap/totuser)); + if((TopUserFields & TOPUSERFIELDS_MILISEC) != 0) + fprintf(fp_top3,"%s",fixnum2(ttnelap/totuser,1)); + fputs("\n",fp_top3); + } + + fputs("\n",fp_top3); + write_html_trailer(fp_top3); + if (fclose(fp_top3)==EOF) { + debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),top3,strerror(errno)); + exit(EXIT_FAILURE); + } + + return; }