From: Frederic Marchal Date: Wed, 10 Dec 2014 20:28:17 +0000 (+0100) Subject: Display a column with the user's IP address in the top user report X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8e134f1a19331166548929fe8135d4cf24bdb4b6;p=thirdparty%2Fsarg.git Display a column with the user's IP address in the top user report 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. --- diff --git a/getconf.c b/getconf.c index 8f35ae5..c0e22e5 100644 --- 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}, diff --git a/include/conf.h b/include/conf.h index e5617e6..f888d13 100755 --- a/include/conf.h +++ b/include/conf.h @@ -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 diff --git a/readlog.c b/readlog.c index 6b009b0..f977a17 100644 --- 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++; diff --git a/topuser.c b/topuser.c index 83b3ef7..c9c2164 100644 --- 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",_("USERID")); } + if((TopUserFields & TOPUSERFIELDS_USERIP) != 0) { + fputs("%s",_("USERIP")); + } if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0) fprintf(fp_top3,"%s",_("CONNECT")); if((TopUserFields & TOPUSERFIELDS_BYTES) != 0) @@ -370,6 +375,9 @@ void topuser(void) else fprintf(fp_top3,"%s",uinfo->filename,uinfo->filename,uinfo->label); } + if((TopUserFields & TOPUSERFIELDS_USERIP) != 0) { + fprintf(fp_top3,"%s",uinfo->ip); + } if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0) { fputs("",fp_top3); if((TopUserFields & TOPUSERFIELDS_DATE_TIME) !=0 && (ReportType & REPORT_TYPE_DATE_TIME) != 0 && !indexonly) fputs("",fp_top3); - fprintf(fp_top3,"%s",_("TOTAL")); + if((TopUserFields & TOPUSERFIELDS_USERIP) != 0) + fprintf(fp_top3,"%s",_("TOTAL")); + else + fprintf(fp_top3,"%s",_("TOTAL")); if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0) fprintf(fp_top3,"%s",fixnum(ttnacc,1)); @@ -460,7 +471,10 @@ void topuser(void) fputs("",fp_top3); if((TopUserFields & TOPUSERFIELDS_DATE_TIME) !=0 && (ReportType & REPORT_TYPE_DATE_TIME) != 0 && !indexonly) fputs("",fp_top3); - fprintf(fp_top3,"%s",_("AVERAGE")); + 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));