Skip to content

Commit

Permalink
added custom configuration file option
Browse files Browse the repository at this point in the history
  • Loading branch information
abgit authored and allinurl committed Aug 20, 2013
1 parent 56d5b9e commit 4e2809a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
12 changes: 8 additions & 4 deletions goaccess.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
#include "util.h"

static WINDOW *header_win, *main_win;
static char short_options[] = "f:e:acr";
static char short_options[] = "f:e:p:acr";

GConf conf = { 0 };

Expand Down Expand Up @@ -109,15 +109,16 @@ cmd_help (void)
{
printf ("\nGoAccess - %s\n\n", GO_VERSION);
printf ("Usage: ");
printf ("goaccess [ -e IP_ADDRESS][ - a ][ - r][ - c ]< -f log_file >\n\n");
printf ("goaccess [-e IP_ADDRESS][-a][-r][-c][-p CONFIGFILE] -f log_file\n\n");
printf ("The following options can also be supplied to the command:\n\n");
printf (" -f <argument> - Path to input log file.\n");
printf (" -c - Prompt log/date configuration window.\n");
printf (" -r - Disable IP resolver.\n");
printf (" -a - Enable a List of User-Agents by host.\n");
printf (" For faster parsing, don't enable this flag.\n");
printf (" -e <argument> - Exclude an IP from being counted under the\n");
printf (" HOST module. Disabled by default.\n\n");
printf (" HOST module. Disabled by default.\n");
printf (" -p <argument> - Custom configuration file.\n\n");
printf ("Examples can be found by running `man goaccess`.\n\n");
printf ("For more details visit: http://goaccess.prosoftcorp.com\n");
printf ("GoAccess Copyright (C) 2009-2013 GNU GPL'd, by Gerardo Orellana");
Expand Down Expand Up @@ -641,6 +642,9 @@ main (int argc, char *argv[])
case 'f':
conf.ifile = optarg;
break;
case 'p':
realpath( optarg, conf.iconfigfile );
break;
case 'e':
conf.ignore_host = optarg;
break;
Expand All @@ -654,7 +658,7 @@ main (int argc, char *argv[])
conf.skip_resolver = 1;
break;
case '?':
if (optopt == 'f' || optopt == 'e')
if (optopt == 'f' || optopt == 'e' || optopt == 'p')
fprintf (stderr, "Option -%c requires an argument.\n", optopt);
else if (isprint (optopt))
fprintf (stderr, "Unknown option `-%c'.\n", optopt);
Expand Down
18 changes: 11 additions & 7 deletions settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,19 @@ parse_conf_file ()
char *val, *c;
int key = 0;
FILE *file;

if (conf.iconfigfile != NULL){
conf_file = conf.iconfigfile;
}else{
user_home = getenv ("HOME");
if (user_home == NULL)
user_home = "";

user_home = getenv ("HOME");
if (user_home == NULL)
user_home = "";

path = xmalloc (snprintf (NULL, 0, "%s/.goaccessrc", user_home) + 1);
sprintf (path, "%s/.goaccessrc", user_home);
path = xmalloc (snprintf (NULL, 0, "%s/.goaccessrc", user_home) + 1);
sprintf (path, "%s/.goaccessrc", user_home);
conf_file = path;
}

conf_file = path;
file = fopen (conf_file, "r");

if (file == NULL) {
Expand Down
1 change: 1 addition & 0 deletions settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ typedef struct GConfKeyword_
typedef struct GConf_
{
char *ifile;
char iconfigfile[200];
char *ignore_host;
char *date_format;
char *log_format;
Expand Down

0 comments on commit 4e2809a

Please sign in to comment.