]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Display a column with the user's IP address in the top user report
authorFrederic Marchal <fmarchal@users.sourceforge.net>
Wed, 10 Dec 2014 20:28:17 +0000 (21:28 +0100)
committerFrederic Marchal <fmarchal@users.sourceforge.net>
Wed, 10 Dec 2014 20:28:17 +0000 (21:28 +0100)
In sarg.conf, topuser_fields accept the new USERIP parameter to display
a new column with the user's IP address. It is only useful if the IP
address is replaced by a name or resolved to a host name.

getconf.c
include/conf.h
readlog.c
topuser.c

index 8f35ae5a79aa03f35c72f9de064155bb7ba97080..c0e22e56ba7392e5fa81638bd9c1719f7e6eeef1 100644 (file)
--- a/getconf.c
+++ b/getconf.c
@@ -93,6 +93,7 @@ static struct param_list topuserfields_values[]=
        {"NUM",TOPUSERFIELDS_NUM,0},
        {"DATE_TIME",TOPUSERFIELDS_DATE_TIME,0},
        {"USERID",TOPUSERFIELDS_USERID,0},
+       {"USERIP",TOPUSERFIELDS_USERIP,0},
        {"CONNECT",TOPUSERFIELDS_CONNECT,0},
        {"BYTES",TOPUSERFIELDS_BYTES,0},
        {"%BYTES",TOPUSERFIELDS_SETYB,0},
index e5617e6b1ee10334215078236ba2492a20f9cc80..f888d13e5d60abdc0ef1f1ba3696b02c7a4089d6 100755 (executable)
@@ -212,6 +212,7 @@ Sarg will complain that there are too many days in the files if this limit is ov
 #define TOPUSERFIELDS_PTIME        0x0200UL
 #define TOPUSERFIELDS_TOTAL        0x0400UL
 #define TOPUSERFIELDS_AVERAGE      0x0800UL
+#define TOPUSERFIELDS_USERIP       0x1000UL
 
 #define USERREPORTFIELDS_CONNECT      0x0001UL
 #define USERREPORTFIELDS_BYTES        0x0002UL
index 6b009b0661dcfc9133f315713c90a5345ab5bb45..f977a17084431edb79b46e80ce15053a274ee12d 100644 (file)
--- a/readlog.c
+++ b/readlog.c
@@ -582,6 +582,10 @@ static void ReadOneLogFile(struct ReadLogDataStruct *Filter,const char *arq)
                        memset(ufile,0,sizeof(*ufile));
                        ufile->next=first_user_file;
                        first_user_file=ufile;
+                       /*
+                        * This id_is_ip stuff is just to store the string only once if the user is
+                        * identified by its IP address instead of a distinct ID and IP address.
+                        */
                        uinfo=userinfo_create(log_entry.User,(id_is_ip) ? NULL : log_entry.Ip);
                        ufile->user=uinfo;
                        nusers++;
index 83b3ef765ecc5db434dc0f860c7c2e84664ea51b..c9c21646b35016bc1c8c0591a6bac94d34a2a8f4 100644 (file)
--- a/topuser.c
+++ b/topuser.c
@@ -277,6 +277,11 @@ void topuser(void)
                if (SortTableJs[0]) fputs(" sorttable_alpha",fp_top3);
                fprintf(fp_top3,"\">%s</th>",_("USERID"));
        }
+       if((TopUserFields & TOPUSERFIELDS_USERIP) != 0) {
+               fputs("<th class=\"header_l",fp_top3);
+               if (SortTableJs[0]) fputs(" sorttable_alpha",fp_top3);
+               fprintf(fp_top3,"\">%s</th>",_("USERIP"));
+       }
        if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0)
                fprintf(fp_top3,"<th class=\"header_l\">%s</th>",_("CONNECT"));
        if((TopUserFields & TOPUSERFIELDS_BYTES) != 0)
@@ -370,6 +375,9 @@ void topuser(void)
                        else
                                fprintf(fp_top3,"<td class=\"data2\"><a href=\"%s/%s.html\">%s</a></td>",uinfo->filename,uinfo->filename,uinfo->label);
                }
+               if((TopUserFields & TOPUSERFIELDS_USERIP) != 0) {
+                       fprintf(fp_top3,"<td class=\"data2\">%s</td>",uinfo->ip);
+               }
                if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0) {
                        fputs("<td class=\"data\"",fp_top3);
                        if (SortTableJs[0]) fprintf(fp_top3," sorttable_customkey=\"%"PRId64"\"",(int64_t)nacc);
@@ -426,7 +434,10 @@ void topuser(void)
                        fputs("<td></td>",fp_top3);
                if((TopUserFields & TOPUSERFIELDS_DATE_TIME) !=0 && (ReportType & REPORT_TYPE_DATE_TIME) != 0 && !indexonly)
                        fputs("<td></td>",fp_top3);
-               fprintf(fp_top3,"<th class=\"header_l\">%s</th>",_("TOTAL"));
+               if((TopUserFields & TOPUSERFIELDS_USERIP) != 0)
+                       fprintf(fp_top3,"<th class=\"header_l\" colspan=\"2\">%s</th>",_("TOTAL"));
+               else
+                       fprintf(fp_top3,"<th class=\"header_l\">%s</th>",_("TOTAL"));
 
                if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0)
                        fprintf(fp_top3,"<th class=\"header_r\">%s</th>",fixnum(ttnacc,1));
@@ -460,7 +471,10 @@ void topuser(void)
                        fputs("<td></td>",fp_top3);
                if((TopUserFields & TOPUSERFIELDS_DATE_TIME) !=0 && (ReportType & REPORT_TYPE_DATE_TIME) != 0 && !indexonly)
                        fputs("<td></td>",fp_top3);
-               fprintf(fp_top3,"<th class=\"header_l\">%s</th>",_("AVERAGE"));
+               if((TopUserFields & TOPUSERFIELDS_USERIP) != 0)
+                       fprintf(fp_top3,"<th class=\"header_l\" colspan=\"2\">%s</th>",_("AVERAGE"));
+               else
+                       fprintf(fp_top3,"<th class=\"header_l\">%s</th>",_("AVERAGE"));
 
                if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0)
                        fprintf(fp_top3,"<th class=\"header_r\">%s</th>",fixnum(ttnacc/totuser,1));