]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Don't process the details of the users that are not listed
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Sun, 30 Oct 2011 19:04:54 +0000 (19:04 +0000)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Sun, 30 Oct 2011 19:04:54 +0000 (19:04 +0000)
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.

html.c
include/defs.h
report.c
sort.c
topuser.c

diff --git a/html.c b/html.c
index e77669e16450760da49e23fb2cb3252b32beb9ca..af073490b28f8af70e2678c81cd82bc56004a2f2 100644 (file)
--- 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){
index f276c45e60523a5d16d720a61fb1d8ca3949bce9..d24238de00e626de3d00cdd8fbade2d48b5d2cd8 100755 (executable)
@@ -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
index b39335940fa141ad3100024468fcea0f72023dbc..69dc8c29d2077ce3ce8382fe1fc2162a72a8cfd7 100644 (file)
--- 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 56b6a0d3d133f22f649be52aa79d0e802d633ad6..83e190f467674815f1288ce68a99479ad0757349 100644 (file)
--- a/sort.c
+++ b/sort.c
 #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;
 }
 
index b58de859c9793d0a2c49b0b90ae856a0f75bc966..9ebf5199506b5c5df587590170bdccf36cf0d1cb 100644 (file)
--- 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;
 }