From: Frédéric Marchal Date: Sun, 30 Oct 2011 19:04:54 +0000 (+0000) Subject: Don't process the details of the users that are not listed X-Git-Tag: v2.3.2~13 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e5b3a1295b50f80015655fafa26c9d77e721e987;p=thirdparty%2Fsarg.git Don't process the details of the users that are not listed When the topusers list is limited to some users, the details of those users are not processed and the corresponding files are not generated. Some files are still generated but the changes needed to remove those files are too intrusives for this release. --- diff --git a/html.c b/html.c index e77669e..af07349 100644 --- a/html.c +++ b/html.c @@ -37,15 +37,14 @@ void htmlrel(void) long long int totelap=0, totelap2=0, nnelap=0, unelap=0, tnelap=0; long long int incache=0, oucache=0, tnincache=0, tnoucache=0, twork=0; long long int ltemp; - long long int ntotuser=1; + long long int ntotuser; long long int userbytes, userelap; char *buf; - char arqin[MAXLEN], arqou[MAXLEN], arqper[MAXLEN], arqip[MAXLEN]; + char arqin[MAXLEN], arqou[MAXLEN], arqip[MAXLEN]; char *url, tmsg[50], csort[MAXLEN]; char duser[MAXLEN]; char user_ip[MAXLEN], olduserip[MAXLEN], tmp2[MAXLEN], tmp3[MAXLEN]; char warea[MAXLEN]; - char totuser[8]; char tmp6[MAXLEN]; char *user_url; long long int tnacc=0, ttnacc=0, unacc=0; @@ -55,7 +54,6 @@ void htmlrel(void) int have_denied_report; const char *sort_field; const char *sort_order; - const char *user; char siteind[MAX_TRUNCATED_URL]; struct getwordstruct gwarea; longline line,line1; @@ -75,21 +73,7 @@ void htmlrel(void) tnacc=globstat.nacc; totbytes=globstat.nbytes; totelap=globstat.elap; - - if ((ReportType & REPORT_TYPE_TOPUSERS) != 0) { - snprintf(arqper,sizeof(arqper),"%s/sarg-users",outdirname); - if ((fp_in = fopen(arqper, "r")) == 0){ - debuga(_("(html11) Cannot open file %s - %s\n"),arqper,strerror(errno)); - exit(EXIT_FAILURE); - } - if (!fgets(totuser,sizeof(totuser),fp_in)) { - debuga(_("(html11) read error in %s\n"),arqper); - exit(EXIT_FAILURE); - } - fclose(fp_in); - ntotuser=my_atoll(totuser); - if (ntotuser<=0) ntotuser=1; - } + ntotuser=globstat.totuser; greport_prepare(); @@ -101,10 +85,13 @@ void htmlrel(void) exit(EXIT_FAILURE); } while ( (uinfo = userinfo_advancescan(uscan)) != NULL ) { - user=uinfo->filename; + if (!uinfo->topuser) { + continue; + } + tmpsort(uinfo); - if (snprintf(warea,sizeof(warea),"%s/%s",outdirname,user)>=sizeof(warea)) { - debuga(_("Destination directory too long: %s/%s\n"),outdirname,user); + if (snprintf(warea,sizeof(warea),"%s/%s",outdirname,uinfo->filename)>=sizeof(warea)) { + debuga(_("Destination directory too long: %s/%s\n"),outdirname,uinfo->filename); exit(EXIT_FAILURE); } if (access(warea, R_OK) != 0) { @@ -117,8 +104,8 @@ void htmlrel(void) report_day(uinfo); greport_day(uinfo); - if (snprintf(arqin,sizeof(arqin),"%s/%s.txt",tmp,uinfo->filename)>=sizeof(arqin)) { - debuga(_("Input file name too long: %s/%s.txt\n"),tmp,uinfo->filename); + if (snprintf(arqin,sizeof(arqin),"%s/htmlrel.txt",tmp)>=sizeof(arqin)) { + debuga(_("Input file name too long: %s/htmlrel.txt\n"),tmp); exit(EXIT_FAILURE); } if ((fp_in = fopen(arqin, "r")) == 0){ diff --git a/include/defs.h b/include/defs.h index f276c45..d24238d 100755 --- a/include/defs.h +++ b/include/defs.h @@ -74,6 +74,8 @@ struct globalstatstruct long long int incache; //! Amount of data not fetched from the cache. long long int oucache; + //! The number of users in the topuser list. + int totuser; }; // auth.c @@ -177,7 +179,7 @@ void smartfilter_report(void); // sort.c void sort_users_log(const char *tmp, int debug); -void tmpsort(void); +void tmpsort(const struct userinfostruct *uinfo); void sort_labels(const char **label,const char **order); // splitlog.c diff --git a/report.c b/report.c index b393359..69dc8c2 100644 --- a/report.c +++ b/report.c @@ -346,11 +346,6 @@ void gerarel(void) fclose(fp_gen); if (puinfo && !indexonly) day_totalize(tmp,puinfo); - if (!indexonly) - tmpsort(); - else if (debugz) - debugaz(_("Only the index is generated as requested\n")); - if(email[0] == '\0') { if (!indexonly) { if((ReportType & REPORT_TYPE_DOWNLOADS) != 0) diff --git a/sort.c b/sort.c index 56b6a0d..83e190f 100644 --- a/sort.c +++ b/sort.c @@ -27,10 +27,8 @@ #include "include/conf.h" #include "include/defs.h" -void tmpsort(void) +void tmpsort(const struct userinfostruct *uinfo) { - userscan uscan; - struct userinfostruct *uinfo; int cstatus; char csort[MAXLEN]; char arqou[MAXLEN], arqin[MAXLEN]; @@ -39,8 +37,6 @@ void tmpsort(void) const char *field3="3,3"; const char *order; - if((ReportType & REPORT_TYPE_USERS_SITES) == 0) return; - if((UserSort & USER_SORT_CONNECT) != 0) { field1="1,1"; field2="2,2"; @@ -60,42 +56,34 @@ void tmpsort(void) else order="-r"; - uscan=userinfo_startscan(); - if (uscan == NULL) { - debuga(_("Cannot enumerate the user list\n")); + if (snprintf(arqin,sizeof(arqin),"%s/%s.utmp",tmp,uinfo->filename)>=sizeof(arqin)) { + debuga(_("file name too long: %s/%s.utmp\n"),tmp,uinfo->filename); + exit(EXIT_FAILURE); + } + if (snprintf(arqou,sizeof(arqou),"%s/htmlrel.txt",tmp)>=sizeof(arqou)) { + debuga(_("file name too long: %s/htmlrel.txt\n"),tmp); exit(EXIT_FAILURE); } - while ((uinfo = userinfo_advancescan(uscan)) != NULL ){ - if (snprintf(arqin,sizeof(arqin),"%s/%s.utmp",tmp,uinfo->filename)>=sizeof(arqin)) { - debuga(_("file name too long: %s/%s.utmp\n"),tmp,uinfo->filename); - exit(EXIT_FAILURE); - } - if (snprintf(arqou,sizeof(arqou),"%s/%s.txt",tmp,uinfo->filename)>=sizeof(arqou)) { - debuga(_("file name too long: %s/%s.utmp\n"),tmp,uinfo->filename); - exit(EXIT_FAILURE); - } - if(debug) { - debuga(_("Sorting file: %s\n"),arqou); - } + if(debug) { + debuga(_("Sorting file: %s\n"),arqin); + } - if (snprintf(csort,sizeof(csort),"sort -n -T \"%s\" -t \"\t\" %s -k %s -k %s -k %s -o \"%s\" \"%s\"",tmp,order,field1,field2,field3,arqou,arqin)>=sizeof(csort)) { - debuga(_("Sort command too long when sorting file \"%s\" to \"%s\"\n"),arqin,arqou); - exit(EXIT_FAILURE); - } - cstatus=system(csort); - if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { - debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus)); - debuga(_("sort command: %s\n"),csort); - exit(EXIT_FAILURE); - } - if (unlink(arqin)) { - debuga(_("Cannot delete %s - %s\n"),arqin,strerror(errno)); - exit(EXIT_FAILURE); - } + if (snprintf(csort,sizeof(csort),"sort -n -T \"%s\" -t \"\t\" %s -k %s -k %s -k %s -o \"%s\" \"%s\"",tmp,order,field1,field2,field3,arqou,arqin)>=sizeof(csort)) { + debuga(_("Sort command too long when sorting file \"%s\" to \"%s\"\n"),arqin,arqou); + exit(EXIT_FAILURE); + } + cstatus=system(csort); + if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { + debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus)); + debuga(_("sort command: %s\n"),csort); + exit(EXIT_FAILURE); + } + if (unlink(arqin)) { + debuga(_("Cannot delete %s - %s\n"),arqin,strerror(errno)); + exit(EXIT_FAILURE); } - userinfo_stopscan(uscan); return; } diff --git a/topuser.c b/topuser.c index b58de85..9ebf519 100644 --- a/topuser.c +++ b/topuser.c @@ -27,9 +27,7 @@ #include "include/conf.h" #include "include/defs.h" -#ifdef ENABLE_DOUBLE_CHECK_DATA extern struct globalstatstruct globstat; -#endif void topuser(void) { @@ -459,6 +457,7 @@ void topuser(void) fprintf(fp_ou,"%d\n",totuser); if (fclose(fp_ou)==EOF) debuga(_("Failed to close file %s - %s\n"),tusr,strerror(errno)); + globstat.totuser=totuser; return; }