]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Add links on the Sites & Users page to the user's page
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Sun, 30 Oct 2011 19:04:33 +0000 (19:04 +0000)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Sun, 30 Oct 2011 19:04:33 +0000 (19:04 +0000)
The page listing the links visited and who visited them contains links to
jump directly to the page of each user provided they are on the top
users page.

ChangeLog
include/conf.h
include/defs.h
siteuser.c
topuser.c
userinfo.c

index 674b8476b7ec8481211820a5e0dc85461dccb080..d621462a9baabafc22fe7a816bcecd041a75e6bf 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -19,6 +19,7 @@ Oct-30-2011 Version 2.3.2-pre2
                - Discriminate between users whose name produce the same mangled temporary file name.
                - Write a note about the number of entries ignored in the reports (thanks to Iain Lopata).
                - Command line option -z output some messages to explain why the reports are not generated due to the configuration.
+               - The Sites & Users report page links to the user's page if the user is listed in the Top Users page.
 
 Sep-18-2010 Version 2.3.1
                - Remove the distinct printf for the alpha architecture as it doesn't work anymore and is not necessary anyway.
index 3e8582c70b5a4b9d210ba5f6d44c61c303f8ba0a..c939c29c2f7c3adaf0c818a6fb297781e31a0581 100755 (executable)
@@ -468,7 +468,6 @@ int  realtime_refresh;
 int  realtime_access_log_lines;
 int  rc;
 int  ntopsites;
-int  nsitesusers;
 int  nrepday;
 int  ndownload;
 int  ntopuser;
index d11346873204d753c146a0d3ed563918c557702c..f276c45e60523a5d16d720a61fb1d8ca3949bce9 100755 (executable)
@@ -51,6 +51,10 @@ struct userinfostruct
        char label[MAX_USER_LEN];
        //! The mangled name to use in file names of that user.
        char filename[MAX_USER_FNAME_LEN];
+       //! \c True if this user is in the topuser list.
+       int topuser;
+       //! A general purpose flag that can be set when scanning the user's list.
+       int flag;
 };
 
 //! Scan through the known users.
@@ -208,6 +212,7 @@ void userinfo_free(void);
 userscan userinfo_startscan(void);
 void userinfo_stopscan(userscan uscan);
 struct userinfostruct *userinfo_advancescan(userscan uscan);
+void userinfo_clearflag(void);
 
 // usertab.c
 void init_usertab(const char *UserTabFile);
index 02df1f6095e121f9245567c2369871ce3375543a..997b27193567efcb6c3dd3fa32c73c79c6ec5769 100644 (file)
@@ -32,7 +32,6 @@ void siteuser(void)
        FILE *fp_in, *fp_ou;
 
        char *buf;
-       char wuser[MAXLEN];
        char *ourl;
        char csort[255];
        char general[MAXLEN];
@@ -40,15 +39,14 @@ void siteuser(void)
        char sites[MAXLEN];
        char report[MAXLEN];
        int regs=0;
-       int ucount=0;
        int ourl_size;
        int url_len;
-       char *users;
-       long long int obytes;
+       int topuser_link;
+       int nsitesusers;
        int cstatus;
        longline line;
        struct generalitemstruct item;
-       const struct userinfostruct *uinfo;
+       struct userinfostruct *uinfo;
 
        if(Privacy) {
                if (debugz) debugaz(_("Sites and users report not generated because privacy option is on\n"));
@@ -103,13 +101,9 @@ void siteuser(void)
 
        ourl=NULL;
        ourl_size=0;
-       obytes=0;
 
-       if((users=(char *) malloc(204800))==NULL){
-               debuga(_("ERROR: Cannot load. Memory fault\n"));
-               exit(EXIT_FAILURE);
-       }
-       strcpy(users," ");
+       userinfo_clearflag();
+       topuser_link=((ReportType & REPORT_TYPE_USERS_SITES) != 0 && !indexonly);
 
        if ((line=longline_create())==NULL) {
                debuga(_("Not enough memory to read file %s\n"),general2);
@@ -126,9 +120,18 @@ void siteuser(void)
                }
 
                if (item.nacc > 0) nsitesusers = 1;
-               if(!regs) {
+               if (!nsitesusers) continue;
+
+               if (ourl==NULL || strcmp(item.url,ourl) != 0) {
+                       if (regs>0) fputs("</td></tr>\n",fp_ou);
+
+                       regs++;
+                       if (SiteUsersReportLimit && regs >= SiteUsersReportLimit)
+                               break;
+                       fprintf(fp_ou,"<tr><td class=\"data\">%d</td><td class=\"data2\">",regs);
+
                        url_len=strlen(item.url);
-                       if (!ourl || url_len>=ourl_size) {
+                       if (url_len>=ourl_size) {
                                ourl_size=url_len+1;
                                ourl=realloc(ourl,ourl_size);
                                if (!ourl) {
@@ -137,28 +140,7 @@ void siteuser(void)
                                }
                        }
                        strcpy(ourl,item.url);
-                       obytes=item.nbytes;
-                       regs++;
-               }
-
-               sprintf(wuser," %s ",uinfo->label);
-               if(strstr(users,wuser) == 0 && strcmp(item.url,ourl) == 0) {
-                       strcat(users,uinfo->label);
-                       strcat(users," ");
-                       ucount++;
-                       if(ucount>4) {
-                               strcat(users,"<br>");
-                               ucount=0;
-                       }
-               }
-
-               if(SiteUsersReportLimit) {
-                       if(regs >= SiteUsersReportLimit)
-                               continue;
-               }
-
-               if(strcmp(item.url,ourl) != 0 && nsitesusers) {
-                       fprintf(fp_ou,"<tr><td class=\"data\">%d</td><td class=\"data2\">",regs);
+                       
                        if(BlockIt[0]!='\0' && ourl[0]!=ALIAS_PREFIX) {
                                fprintf(fp_ou,"<a href=\"%s%s?url=",wwwDocumentRoot,BlockIt);
                                output_html_url(fp_ou,ourl);
@@ -169,46 +151,32 @@ void siteuser(void)
 
                        if (BytesInSitesUsersReport) {
                                fputs("<td class=\"data\"",fp_ou);
-                               if (SortTableJs[0]) fprintf(fp_ou," sorttable_customkey=\"%"PRId64"\"",(int64_t)obytes);
-                               fprintf(fp_ou,">%s</td>",fixnum(obytes,1));
+                               if (SortTableJs[0]) fprintf(fp_ou," sorttable_customkey=\"%"PRId64"\"",(int64_t)item.nbytes);
+                               fprintf(fp_ou,">%s</td>",fixnum(item.nbytes,1));
                        }
-                       fprintf(fp_ou,"<td class=\"data2\">%s</td></tr>\n",users);
-
-                       regs++;
-                       ucount=0;
-                       strcpy(users,uinfo->label);
-                       strcat(users," ");
-                       url_len=strlen(item.url);
-                       if (url_len>=ourl_size) {
-                               ourl_size=url_len+1;
-                               ourl=realloc(ourl,ourl_size);
-                               if (!ourl) {
-                                       debuga(_("Not enough memory to store the url\n"));
-                                       exit(EXIT_FAILURE);
-                               }
-                       }
-                       strcpy(ourl,item.url);
-                       obytes=item.nbytes;
+                       fputs("<td class=\"data2\">",fp_ou);
+
+                       userinfo_clearflag();
+                       if (topuser_link && uinfo->topuser)
+                               fprintf(fp_ou,"<a href=\"%s/%s.html\">%s</a>",uinfo->filename,uinfo->filename,uinfo->label);
+                       else
+                               fprintf(fp_ou,"%s",uinfo->label);
+                       uinfo->flag=1;
+               }
+               else if (uinfo->flag==0) {
+                       if (topuser_link && uinfo->topuser)
+                               fprintf(fp_ou," <a href=\"%s/%s.html\">%s</a>",uinfo->filename,uinfo->filename,uinfo->label);
+                       else
+                               fprintf(fp_ou," %s",uinfo->label);
+                       uinfo->flag=1;
                }
+
        }
        fclose(fp_in);
        longline_destroy(&line);
 
-       if(nsitesusers) {
-               fprintf(fp_ou,"<tr><td class=\"data\">%d</td><td class=\"data2\">",regs);
-               if(BlockIt[0]!='\0' && ourl[0]!=ALIAS_PREFIX) {
-                       fprintf(fp_ou,"<a href=\"%s%s?url=",wwwDocumentRoot,BlockIt);
-                       output_html_url(fp_ou,ourl);
-                       fputs("\"><img src=\"../images/sarg-squidguard-block.png\"></a>&nbsp;",fp_ou);
-               }
-               output_html_link(fp_ou,ourl,100);
-               fputs("</td>",fp_ou);
-               if (BytesInSitesUsersReport) {
-                       fputs("<td class=\"data\"",fp_ou);
-                       if (SortTableJs[0]) fprintf(fp_ou," sorttable_customkey=\"%"PRId64"\"",(int64_t)obytes);
-                       fprintf(fp_ou,">%s</td>",fixnum(obytes,1));
-               }
-               fprintf(fp_ou,"<td class=\"data2\">%s</td></tr>\n",users);
+       if(regs>0) {
+               fputs("</td></tr>\n",fp_ou);
        }
        if (ourl) free(ourl);
 
@@ -223,8 +191,5 @@ void siteuser(void)
        if (fclose(fp_ou)==EOF)
                debuga(_("Failed to close file %s - %s\n"),report,strerror(errno));
 
-       if(users)
-               free(users);
-
        return;
 }
index 2148c8508624ed26274223b18d14fb5eb7a38157..b58de859c9793d0a2c49b0b90ae856a0f75bc966 100644 (file)
--- a/topuser.c
+++ b/topuser.c
@@ -60,7 +60,7 @@ void topuser(void)
        struct getwordstruct gwarea;
        longline line;
        struct generalitemstruct item;
-       const struct userinfostruct *uinfo;
+       struct userinfostruct *uinfo;
 
        ipantes[0]='\0';
        nameantes[0]='\0';
@@ -305,6 +305,7 @@ void topuser(void)
                        debuga(_("Unknown user ID %s in file %s\n"),user,top1);
                        exit(EXIT_FAILURE);
                }
+               uinfo->topuser=1;
 
                fputs("<tr>",fp_top3);
 
index 4339ba6ad816d4b11e30de8e16732d669847b163..8cdabc071976e20ab96c5c822ce35782f224af37 100644 (file)
@@ -218,3 +218,18 @@ struct userinfostruct *userinfo_advancescan(userscan uscan)
        }
        return(uinfo);
 }
+
+/*!
+Clear the general purpose flag from all the user's info.
+*/
+void userinfo_clearflag(void)
+{
+       struct usergroupstruct *group;
+       int i;
+
+       for (group=first_user_group ; group ; group=group->next) {
+               for (i=0 ; i<group->nusers ; i++)
+                       group->list[i].flag=0;
+       }
+}
+