<commit_before>/**
 * goaccess.c -- main log analyzer
 * Copyright (C) 2009-2013 by <NAME> <<EMAIL>>
 * GoAccess - An Ncurses apache weblog analyzer & interactive viewer
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * A copy of the GNU General Public License is attached to this
 * source distribution for its full text.
 *
 * Visit http://goaccess.prosoftcorp.com for new releases.
 */

#define _LARGEFILE_SOURCE
#define _LARGEFILE64_SOURCE
#define _FILE_OFFSET_BITS    64

#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <glib.h>
#include <locale.h>

#if HAVE_CONFIG_H
#include <config.h>
#endif

#include <pthread.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

#include "commons.h"
#include "csv.h"
#include "error.h"
#include "gdashboard.h"
#include "gdns.h"
#include "json.h"
#include "output.h"
#include "parser.h"
#include "settings.h"
#include "ui.h"
#include "util.h"

static WINDOW *header_win, *main_win;
#ifdef HAVE_LIBGEOIP
static char short_options[] = "f:e:p:o:acrmghq";
#else
static char short_options[] = "f:e:p:o:acrmhq";
#endif

GConf conf = { 0 };

int active_gdns = 0;
static GDash *dash;
static GHolder *holder;
static GLog *logger;
static GSpinner *parsing_spinner;

/* *INDENT-OFF* */
static GSort sort[TOTAL_MODULES] = {
   {VISITORS        , SORT_BY_DATA, SORT_DESC},
   {REQUESTS        , SORT_BY_HITS, SORT_DESC},
   {REQUESTS_STATIC , SORT_BY_HITS, SORT_DESC},
   {NOT_FOUND       , SORT_BY_HITS, SORT_DESC},
   {HOSTS           , SORT_BY_HITS, SORT_DESC},
   {OS              , SORT_BY_HITS, SORT_DESC},
   {BROWSERS        , SORT_BY_HITS, SORT_DESC},
   {REFERRERS       , SORT_BY_HITS, SORT_DESC},
   {REFERRING_SITES , SORT_BY_HITS, SORT_DESC},
   {KEYPHRASES      , SORT_BY_HITS, SORT_DESC},
#ifdef HAVE_LIBGEOIP
   {GEO_LOCATION    , SORT_BY_HITS, SORT_DESC},
#endif
   {STATUS_CODES    , SORT_BY_HITS, SORT_DESC},
};

static GScrolling scrolling = {
   {
      {0, 0}, /* visitors    {scroll, offset} */
      {0, 0}, /* requests    {scroll, offset} */
      {0, 0}, /* req static  {scroll, offset} */
      {0, 0}, /* not found   {scroll, offset} */
      {0, 0}, /* hosts       {scroll, offset} */
      {0, 0}, /* os          {scroll, offset} */
      {0, 0}, /* browsers    {scroll, offset} */
      {0, 0}, /* referrers   {scroll, offset} */
      {0, 0}, /* ref sites   {scroll, offset} */
      {0, 0}, /* keywords    {scroll, offset} */
#ifdef HAVE_LIBGEOIP
      {0, 0}, /* geolocation {scroll, offset} */
#endif
      {0, 0}, /* status      {scroll, offset} */
   },
   0,         /* current module */
   0,         /* main dashboard scroll */
   0,         /* expanded flag */
};
/* *INDENT-ON* */

#ifdef HAVE_LIBGEOIP
static void
free_countries (GO_UNUSED gpointer old_key, gpointer old_value,
                GO_UNUSED gpointer user_data)
{
   GLocation *loc = old_value;
   free (loc);
}
#endif

/* free memory allocated by g_hash_table_new_full() function */
static void
free_key_value (gpointer old_key, GO_UNUSED gpointer old_value,
                GO_UNUSED gpointer user_data)
{
   g_free (old_key);
}

static void
cmd_help (void)
{
   printf ("\nGoAccess - %s\n\n", GO_VERSION);
   printf ("Usage: ");
   printf ("goaccess -f log_file [-c][-r][-m][-h][-q]");
#ifdef HAVE_LIBGEOIP
   printf ("[-g]");
#endif
   printf ("[-a][-o csv|json][-e IP_ADDRESS][-p CONFFILE]\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 (" -m            - Enable mouse support on main dashboard.\n");
   printf (" -q            - Ignore request's query string.\n");
#ifdef HAVE_LIBGEOIP
   printf (" -g            - Standard GeoIP database for less memory usage.\n");
#endif
   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");
   printf (" -o <argument> - Output format:\n");<commit_msg>Updated command help format.<commit_after>/**
 * goaccess.c -- main log analyzer
 * Copyright (C) 2009-2013 by <NAME> <<EMAIL>>
 * GoAccess - An Ncurses apache weblog analyzer & interactive viewer
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * A copy of the GNU General Public License is attached to this
 * source distribution for its full text.
 *
 * Visit http://goaccess.prosoftcorp.com for new releases.
 */

#define _LARGEFILE_SOURCE
#define _LARGEFILE64_SOURCE
#define _FILE_OFFSET_BITS    64

#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <glib.h>
#include <locale.h>

#if HAVE_CONFIG_H
#include <config.h>
#endif

#include <pthread.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

#include "commons.h"
#include "csv.h"
#include "error.h"
#include "gdashboard.h"
#include "gdns.h"
#include "json.h"
#include "output.h"
#include "parser.h"
#include "settings.h"
#include "ui.h"
#include "util.h"

static WINDOW *header_win, *main_win;
#ifdef HAVE_LIBGEOIP
static char short_options[] = "f:e:p:o:acrmghq";
#else
static char short_options[] = "f:e:p:o:acrmhq";
#endif

GConf conf = { 0 };

int active_gdns = 0;
static GDash *dash;
static GHolder *holder;
static GLog *logger;
static GSpinner *parsing_spinner;

/* *INDENT-OFF* */
static GSort sort[TOTAL_MODULES] = {
   {VISITORS        , SORT_BY_DATA, SORT_DESC},
   {REQUESTS        , SORT_BY_HITS, SORT_DESC},
   {REQUESTS_STATIC , SORT_BY_HITS, SORT_DESC},
   {NOT_FOUND       , SORT_BY_HITS, SORT_DESC},
   {HOSTS           , SORT_BY_HITS, SORT_DESC},
   {OS              , SORT_BY_HITS, SORT_DESC},
   {BROWSERS        , SORT_BY_HITS, SORT_DESC},
   {REFERRERS       , SORT_BY_HITS, SORT_DESC},
   {REFERRING_SITES , SORT_BY_HITS, SORT_DESC},
   {KEYPHRASES      , SORT_BY_HITS, SORT_DESC},
#ifdef HAVE_LIBGEOIP
   {GEO_LOCATION    , SORT_BY_HITS, SORT_DESC},
#endif
   {STATUS_CODES    , SORT_BY_HITS, SORT_DESC},
};

static GScrolling scrolling = {
   {
      {0, 0}, /* visitors    {scroll, offset} */
      {0, 0}, /* requests    {scroll, offset} */
      {0, 0}, /* req static  {scroll, offset} */
      {0, 0}, /* not found   {scroll, offset} */
      {0, 0}, /* hosts       {scroll, offset} */
      {0, 0}, /* os          {scroll, offset} */
      {0, 0}, /* browsers    {scroll, offset} */
      {0, 0}, /* referrers   {scroll, offset} */
      {0, 0}, /* ref sites   {scroll, offset} */
      {0, 0}, /* keywords    {scroll, offset} */
#ifdef HAVE_LIBGEOIP
      {0, 0}, /* geolocation {scroll, offset} */
#endif
      {0, 0}, /* status      {scroll, offset} */
   },
   0,         /* current module */
   0,         /* main dashboard scroll */
   0,         /* expanded flag */
};
/* *INDENT-ON* */

#ifdef HAVE_LIBGEOIP
static void
free_countries (GO_UNUSED gpointer old_key, gpointer old_value,
                GO_UNUSED gpointer user_data)
{
   GLocation *loc = old_value;
   free (loc);
}
#endif

/* free memory allocated by g_hash_table_new_full() function */
static void
free_key_value (gpointer old_key, GO_UNUSED gpointer old_value,
                GO_UNUSED gpointer user_data)
{
   g_free (old_key);
}

static void
cmd_help (void)
{
   printf ("\nGoAccess - %s\n\n", GO_VERSION);
   printf ("Usage: ");
   printf ("goaccess -f log_file [-c][-r][-m][-h][-q]");
#ifdef HAVE_LIBGEOIP
   printf ("[-g]");
#endif
   printf ("\n\t\t");
   printf ("[-a][-o csv|json][-e IP_ADDRESS][-p CONFFILE]\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 (" -m            - Enable mouse support on main dashboard.\n");
   printf (" -q            - Ignore request's query string.\n");
#ifdef HAVE_LIBGEOIP
   printf (" -g            - Standard GeoIP database for less memory usage.\n");
#endif
   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");
   printf (" -o <argument> - Output format:\n");
{'fraction_non_alphanumeric': 0.13828116821940753, 'fraction_numerical': 0.008793049303883596, 'mean_word_length': 2.8790093382054405, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4568597', 'n_tokens_mistral': 3311, 'n_tokens_neox': 3278, 'n_words': 992}