Skip to content

Commit

Permalink
Added "Remote User" panel to capture HTTP authentication requests.
Browse files Browse the repository at this point in the history
Use %e within the log-format variable to enable this panel.
  • Loading branch information
allinurl committed Nov 4, 2016
1 parent 95f9925 commit 1c2750b
Show file tree
Hide file tree
Showing 14 changed files with 85 additions and 3 deletions.
3 changes: 3 additions & 0 deletions config/goaccess.conf
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ double-decode false
#enable-panel REFERRING_SITES
#enable-panel KEYPHRASES
#enable-panel STATUS_CODES
#enable-panel REMOTE_USER
#enable-panel GEO_LOCATION

# Hour specificity. Possible values: `hr` (default), or `min` (tenth
Expand Down Expand Up @@ -425,6 +426,7 @@ ignore-panel REFERRERS
#ignore-panel REFERRING_SITES
ignore-panel KEYPHRASES
#ignore-panel STATUS_CODES
#ignore-panel REMOTE_USER
#ignore-panel GEO_LOCATION

# Ignore referers from being counted.
Expand Down Expand Up @@ -482,6 +484,7 @@ real-os true
#sort-panel REFERRING_SITES,BY_HITS,ASC
#sort-panel KEYPHRASES,BY_HITS,ASC
#sort-panel STATUS_CODES,BY_HITS,ASC
#sort-panel REMOTE_USER,BY_HITS,ASC
#sort-panel GEO_LOCATION,BY_HITS,ASC

# Consider the following extensions as static files
Expand Down
9 changes: 9 additions & 0 deletions goaccess.1
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ down by continent and country. It needs to be compiled with GeoLocation
support.
.IP "HTTP Status Codes"
The values of the numeric status code to HTTP requests.
.IP "Remote User (HTTP authentication)"
This is the userid of the person requesting the document as determined by HTTP
authentication. If the document is not password protected, this part will be
"-" just like the previous one. This panel is not enabled unless
.I %e
is given within the log-format variable.

.P
.I NOTE:
Expand Down Expand Up @@ -697,6 +703,9 @@ date field matching the
variable.
.IP %v
The canonical Server Name of the server serving the request (Virtual Host).
.IP %e
This is the userid of the person requesting the document as determined by HTTP
authentication.
.IP %h
host (the client IP address, either IPv4 or IPv6)
.IP %r
Expand Down
5 changes: 5 additions & 0 deletions src/commons.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ get_module_enum (const char *str)
{"REFERRING_SITES" , REFERRING_SITES} ,
{"KEYPHRASES" , KEYPHRASES} ,
{"STATUS_CODES" , STATUS_CODES} ,
{"REMOTE_USER" , REMOTE_USER} ,
#ifdef HAVE_LIBGEOIP
{"GEO_LOCATION" , GEO_LOCATION} ,
#endif
Expand Down Expand Up @@ -384,6 +385,10 @@ verify_panels (void)
if (!str_inarray ("VIRTUAL_HOSTS", conf.ignore_panels, ignore_panel_idx))
remove_module (VIRTUAL_HOSTS);
}
if (!strstr (conf.log_format, "%e") && ignore_panel_idx < TOTAL_MODULES) {
if (!str_inarray ("REMOTE_USER", conf.ignore_panels, ignore_panel_idx))
remove_module (REMOTE_USER);
}
}

/* Build an array of available modules (ignores listed panels).
Expand Down
5 changes: 3 additions & 2 deletions src/commons.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ struct tm *now_tm;

/* total number of modules */
#ifdef HAVE_LIBGEOIP
#define TOTAL_MODULES 14
#define TOTAL_MODULES 15
#else
#define TOTAL_MODULES 13
#define TOTAL_MODULES 14
#endif

/* maximum number of items within a panel */
Expand Down Expand Up @@ -102,6 +102,7 @@ typedef enum MODULES
REFERRING_SITES,
KEYPHRASES,
STATUS_CODES,
REMOTE_USER,
#ifdef HAVE_LIBGEOIP
GEO_LOCATION,
#endif
Expand Down
1 change: 1 addition & 0 deletions src/csv.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ static GPanel paneling[] = {
{REFERRING_SITES , print_csv_data} ,
{KEYPHRASES , print_csv_data} ,
{STATUS_CODES , print_csv_data} ,
{REMOTE_USER , print_csv_data} ,
#ifdef HAVE_LIBGEOIP
{GEO_LOCATION , print_csv_data} ,
#endif
Expand Down
1 change: 1 addition & 0 deletions src/gholder.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ static GPanel paneling[] = {
{REFERRING_SITES , add_data_to_holder, NULL} ,
{KEYPHRASES , add_data_to_holder, NULL} ,
{STATUS_CODES , add_root_to_holder, NULL} ,
{REMOTE_USER , add_data_to_holder, NULL} ,
#ifdef HAVE_LIBGEOIP
{GEO_LOCATION , add_root_to_holder, NULL} ,
#endif
Expand Down
6 changes: 5 additions & 1 deletion src/goaccess.c
Original file line number Diff line number Diff line change
Expand Up @@ -906,8 +906,12 @@ get_keys (void)
/* reset expanded module */
set_module_to (&gscroll, STATUS_CODES);
break;
case 36: /* Shift + 3 */
/* reset expanded module */
set_module_to (&gscroll, REMOTE_USER);
break;
#ifdef HAVE_LIBGEOIP
case 36: /* Shift + 4 */
case 37: /* Shift + 4 */
/* reset expanded module */
set_module_to (&gscroll, GEO_LOCATION);
break;
Expand Down
1 change: 1 addition & 0 deletions src/json.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ static GPanel paneling[] = {
{REFERRING_SITES , print_json_data , NULL } ,
{KEYPHRASES , print_json_data , NULL } ,
{STATUS_CODES , print_json_data , print_json_sub_items } ,
{REMOTE_USER , print_json_data , NULL } ,
#ifdef HAVE_LIBGEOIP
{GEO_LOCATION , print_json_data , print_json_sub_items } ,
#endif
Expand Down
1 change: 1 addition & 0 deletions src/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ static GHTML htmldef[] = {
{CHART_VBAR, hits_visitors_plot, 0, 1},
{CHART_VBAR, hits_bw_plot, 0, 1},
}},
{REMOTE_USER , 1, print_metrics } ,
#ifdef HAVE_LIBGEOIP
{GEO_LOCATION , 1, print_metrics, {
{CHART_VBAR, hits_visitors_plot, 0, 1},
Expand Down
42 changes: 42 additions & 0 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ static int gen_host_key (GKeyData * kdata, GLogItem * logitem);
static int gen_keyphrase_key (GKeyData * kdata, GLogItem * logitem);
static int gen_os_key (GKeyData * kdata, GLogItem * logitem);
static int gen_vhost_key (GKeyData * kdata, GLogItem * logitem);
static int gen_remote_user_key (GKeyData * kdata, GLogItem * logitem);
static int gen_referer_key (GKeyData * kdata, GLogItem * logitem);
static int gen_ref_site_key (GKeyData * kdata, GLogItem * logitem);
static int gen_request_key (GKeyData * kdata, GLogItem * logitem);
Expand Down Expand Up @@ -296,6 +297,19 @@ static GParse paneling[] = {
NULL,
NULL,
NULL,
}, {
REMOTE_USER,
gen_remote_user_key,
insert_data,
NULL,
insert_hit,
insert_visitor,
insert_bw,
insert_cumts,
insert_maxts,
NULL,
NULL,
NULL,
},
};
/* *INDENT-ON* */
Expand Down Expand Up @@ -440,6 +454,7 @@ init_log_item (GLog * glog)
logitem->time = NULL;
logitem->uniq_key = NULL;
logitem->vhost = NULL;
logitem->userid = NULL;

memset (logitem->site, 0, sizeof (logitem->site));

Expand Down Expand Up @@ -490,6 +505,8 @@ free_glog (GLogItem * logitem)
free (logitem->time);
if (logitem->uniq_key != NULL)
free (logitem->uniq_key);
if (logitem->userid != NULL)
free (logitem->userid);
if (logitem->vhost != NULL)
free (logitem->vhost);

Expand Down Expand Up @@ -1048,6 +1065,15 @@ parse_specifier (GLogItem * logitem, char **str, const char *p, const char *end)
return spec_err (logitem, SPEC_TOKN_NUL, *p, NULL);
logitem->vhost = tkn;
break;
/* remote user */
case 'e':
if (logitem->userid)
return spec_err (logitem, SPEC_TOKN_SET, *p, NULL);
tkn = parse_string (&(*str), end, 1);
if (tkn == NULL)
return spec_err (logitem, SPEC_TOKN_NUL, *p, NULL);
logitem->userid = tkn;
break;
/* remote hostname (IP only) */
case 'h':
if (logitem->host)
Expand Down Expand Up @@ -1932,6 +1958,22 @@ gen_vhost_key (GKeyData * kdata, GLogItem * logitem)
return 0;
}

/* A wrapper to generate a unique key for the virtual host panel.
*
* On error, 1 is returned.
* On success, the generated userid key is assigned to our key data
* structure. */
static int
gen_remote_user_key (GKeyData * kdata, GLogItem * logitem)
{
if (!logitem->userid)
return 1;

get_kdata (kdata, logitem->userid, logitem->userid);

return 0;
}

/* A wrapper to generate a unique key for the hosts panel.
*
* On error, 1 is returned.
Expand Down
1 change: 1 addition & 0 deletions src/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ typedef struct GLogItem_
char *time;
char *uniq_key;
char *vhost;
char *userid;

char site[REF_SITE_LEN + 1];

Expand Down
3 changes: 3 additions & 0 deletions src/sort.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ const int sort_choices[][SORT_MAX_OPTS] = {
{SORT_BY_HITS, SORT_BY_VISITORS, SORT_BY_DATA, SORT_BY_BW, SORT_BY_AVGTS, SORT_BY_CUMTS, SORT_BY_MAXTS, -1},
/* STATUS_CODES */
{SORT_BY_HITS, SORT_BY_VISITORS, SORT_BY_DATA, SORT_BY_BW, SORT_BY_AVGTS, SORT_BY_CUMTS, SORT_BY_MAXTS, -1},
/* REMOTE_USER */
{SORT_BY_HITS, SORT_BY_VISITORS, SORT_BY_DATA, SORT_BY_BW, SORT_BY_AVGTS, SORT_BY_CUMTS, SORT_BY_MAXTS, -1},
#ifdef HAVE_LIBGEOIP
/* GEO_LOCATION */
{SORT_BY_HITS, SORT_BY_VISITORS, SORT_BY_DATA, SORT_BY_BW, SORT_BY_AVGTS, SORT_BY_CUMTS, SORT_BY_MAXTS, -1},
Expand Down Expand Up @@ -109,6 +111,7 @@ GSort module_sort[TOTAL_MODULES] = {
{REFERRING_SITES , SORT_BY_HITS , SORT_DESC } ,
{KEYPHRASES , SORT_BY_HITS , SORT_DESC } ,
{STATUS_CODES , SORT_BY_HITS , SORT_DESC } ,
{REMOTE_USER , SORT_BY_HITS , SORT_DESC } ,
#ifdef HAVE_LIBGEOIP
{GEO_LOCATION , SORT_BY_HITS , SORT_DESC } ,
#endif
Expand Down
5 changes: 5 additions & 0 deletions src/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ static GOutput outputting[] = {
{REFERRING_SITES , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 0 , 1 , 0 , 0} ,
{KEYPHRASES , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 0 , 1 , 0 , 0} ,
{STATUS_CODES , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 0 , 1 , 0 , 0} ,
{REMOTE_USER , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 0 , 1 , 0 , 0} ,
#ifdef HAVE_LIBGEOIP
{GEO_LOCATION , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 0 , 1 , 0 , 0} ,
#endif
Expand Down Expand Up @@ -273,6 +274,7 @@ module_to_label (GModule module)
SITES_LABEL,
KEYPH_LABEL,
CODES_LABEL,
RUSER_LABEL,
#ifdef HAVE_LIBGEOIP
GEOLO_LABEL,
#endif
Expand Down Expand Up @@ -301,6 +303,7 @@ module_to_id (GModule module)
SITES_ID,
KEYPH_ID,
CODES_ID,
RUSER_ID,
#ifdef HAVE_LIBGEOIP
GEOLO_ID,
#endif
Expand Down Expand Up @@ -329,6 +332,7 @@ module_to_head (GModule module)
SITES_HEAD,
KEYPH_HEAD,
CODES_HEAD,
RUSER_HEAD,
#ifdef HAVE_LIBGEOIP
GEOLO_HEAD,
#endif
Expand Down Expand Up @@ -361,6 +365,7 @@ module_to_desc (GModule module)
SITES_DESC,
KEYPH_DESC,
CODES_DESC,
RUSER_DESC,
#ifdef HAVE_LIBGEOIP
GEOLO_DESC,
#endif
Expand Down
5 changes: 5 additions & 0 deletions src/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@
#define VHOST_ID "vhosts"
#define VHOST_LABEL "Virtual Hosts"

#define RUSER_HEAD "Remote User (HTTP authentication)"
#define RUSER_DESC "Data sorted by hits [, avgts, cumts, maxts]"
#define RUSER_ID "remote_user"
#define RUSER_LABEL "Remote User"

#define FOUND_HEAD "Not Found URLs (404s)"
#define FOUND_DESC "Top not found URLs sorted by hits [, avgts, cumts, maxts, mthd, proto]"
#define FOUND_ID "not_found"
Expand Down

0 comments on commit 1c2750b

Please sign in to comment.