Skip to content

Commit

Permalink
Added --ignore-referer-report command line option to hide referers fr…
Browse files Browse the repository at this point in the history
…om output.
  • Loading branch information
allinurl committed May 23, 2017
1 parent e1a1058 commit 5a79990
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ struct option long_opts[] = {
{"ignore-crawlers" , no_argument , 0 , 0 } ,
{"ignore-panel" , required_argument , 0 , 0 } ,
{"ignore-referer" , required_argument , 0 , 0 } ,
{"ignore-referer-report", required_argument , 0 , 0 } ,
{"ignore-status" , required_argument , 0 , 0 } ,
{"invalid-requests" , required_argument , 0 , 0 } ,
{"json-pretty-print" , no_argument , 0 , 0 } ,
Expand Down Expand Up @@ -247,6 +248,7 @@ cmd_help (void)
" --ignore-panel=<PANEL> - Ignore parsing/displaying the given panel.\n"
" --ignore-referer=<NEEDLE> - Ignore a referer from being counted. Wild cards\n"
" are allowed. i.e., *.bing.com\n"
" --ignore-referer-report=<NEEDLE>- Ignore referer's data, e.g. ref. within same site\n"
" --ignore-status=<CODE> - Ignore parsing the given status code.\n"
" --num-tests=<number> - Number of lines to test. >= 0 (10 default)\n"
" --process-and-exit - Parse log and exit without outputting data.\n"
Expand Down Expand Up @@ -522,6 +524,11 @@ parse_long_opt (const char *name, const char *oarg)
set_array_opt (oarg, conf.ignore_referers, &conf.ignore_referer_idx,
MAX_IGNORE_REF);

/* ignore referer report (e.g. within same site) */
if (!strcmp ("ignore-referer-report", name))
set_array_opt (oarg, conf.ignore_referers_report,
&conf.ignore_referer_report_idx, MAX_IGNORE_REF);

/* ignore status code */
if (!strcmp ("ignore-status", name))
set_array_opt (oarg, conf.ignore_status, &conf.ignore_status_idx,
Expand Down
12 changes: 11 additions & 1 deletion src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -1211,7 +1211,17 @@ parse_specifier (GLogItem * logitem, char **str, const char *p, const char *end)
extract_keyphrase (tkn, &logitem->keyphrase);
extract_referer_site (tkn, logitem->site);
}
logitem->ref = tkn;


if (strcmp (tkn, "-") != 0) {
if (!ignore_referer_report (logitem->site)) {
logitem->ref = tkn;
}
if (ignore_referer_report (logitem->site)) {
logitem->site[0] = '\0';
}

}
break;
/* user agent */
case 'u':
Expand Down
2 changes: 2 additions & 0 deletions src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ typedef struct GConf_
const char *ignore_ips[MAX_IGNORE_IPS]; /* array of ips to ignore */
const char *ignore_panels[TOTAL_MODULES]; /* array of panels to ignore */
const char *ignore_referers[MAX_IGNORE_REF]; /* referrers to ignore */
const char *ignore_referers_report[MAX_IGNORE_REF]; /* referrers to count as hit, but ignore referrer data */
const char *ignore_status[MAX_IGNORE_STATUS]; /* status to ignore */
const char *output_formats[MAX_OUTFORMATS]; /* output format, e.g. , HTML */
const char *sort_panels[TOTAL_MODULES]; /* sorting options for each panel */
Expand Down Expand Up @@ -184,6 +185,7 @@ typedef struct GConf_
int ignore_ip_idx; /* ignored ips index */
int ignore_panel_idx; /* ignored panels index */
int ignore_referer_idx; /* ignored referrers index */
int ignore_referer_report_idx; /* ignored referrers index */
int ignore_status_idx; /* ignore status index */
int output_format_idx; /* output format index */
int sort_panel_idx; /* sort panel index */
Expand Down
28 changes: 28 additions & 0 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,34 @@ ignore_referer (const char *host)
return ignore;
}

int
ignore_referer_report (const char *host)
{
char *needle = NULL;
int i, ignore = 0;

if (conf.ignore_referer_report_idx == 0)
return 0;
if (host == NULL || *host == '\0')
return 0;

needle = xstrdup (host);
for (i = 0; i < conf.ignore_referer_report_idx; ++i) {
if (conf.ignore_referers_report[i] == NULL ||
*conf.ignore_referers_report[i] == '\0')
continue;

if (wc_match (conf.ignore_referers_report[i], needle)) {
ignore = 1;
goto out;
}
}
out:
free (needle);

return ignore;
}

/* Determine if the given ip is within a range of IPs.
*
* On error, or not within the range, 0 is returned
Expand Down
1 change: 1 addition & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ int convert_date (char *res, const char *data, const char *from, const char *to,
int count_matches (const char *s1, char c);
int find_output_type (char **filename, const char *ext, int alloc);
int ignore_referer (const char *ref);
int ignore_referer_report (const char *ref);
int intlen (int num);
int invalid_ipaddr (char *str, int *ipvx);
int ip_in_range (const char *ip);
Expand Down

0 comments on commit 5a79990

Please sign in to comment.