示例#1
0
文件: options.c 项目: 0-T-0/goaccess
void
read_option_args (int argc, char **argv)
{
  int o, idx = 0;

#ifdef HAVE_LIBGEOIP
  conf.geo_db = GEOIP_MEMORY_CACHE;
#endif

  while ((o = getopt_long (argc, argv, short_options, long_opts, &idx)) >= 0) {
    if (-1 == o || EOF == o)
      break;
    switch (o) {
    case 'f':
      conf.ifile = optarg;
      break;
    case 'p':
      /* ignore it */
      break;
#ifdef HAVE_LIBGEOIP
    case 'g':
      conf.geo_db = GEOIP_STANDARD;
      break;
#endif
    case 'e':
      if (conf.ignore_ip_idx < MAX_IGNORE_IPS)
        conf.ignore_ips[conf.ignore_ip_idx++] = optarg;
      break;
    case 'a':
      conf.list_agents = 1;
      break;
    case 'c':
      conf.load_conf_dlg = 1;
      break;
    case 'i':
      conf.hl_header = 1;
      break;
    case 'q':
      conf.ignore_qstr = 1;
      break;
    case 'o':
      conf.output_format = optarg;
      break;
    case 'l':
      conf.debug_log = optarg;
      dbg_log_open (conf.debug_log);
      break;
    case 'r':
      conf.skip_term_resolver = 1;
      break;
    case 'd':
      conf.enable_html_resolver = 1;
      break;
    case 'm':
      conf.mouse_support = 1;
      break;
    case 'M':
      conf.append_method = 1;
      break;
    case 'h':
      cmd_help ();
      break;
    case 'H':
      conf.append_protocol = 1;
      break;
    case 'V':
      display_version ();
      exit (EXIT_SUCCESS);
      break;
    case 0:

      if (!strcmp ("no-global-config", long_opts[idx].name))
        break;  /* ignore it */

      /* colors */
      if (!strcmp ("color", long_opts[idx].name) &&
          conf.color_idx < MAX_CUSTOM_COLORS)
        conf.colors[conf.color_idx++] = optarg;

      /* color scheme */
      if (!strcmp ("color-scheme", long_opts[idx].name))
        conf.color_scheme = atoi (optarg);

      /* log format */
      if (!strcmp ("log-format", long_opts[idx].name) && !conf.log_format)
        conf.log_format = unescape_str (optarg);

      /* time format */
      if (!strcmp ("time-format", long_opts[idx].name) && !conf.time_format)
        conf.time_format = unescape_str (optarg);

      /* date format */
      if (!strcmp ("date-format", long_opts[idx].name) && !conf.date_format)
        conf.date_format = unescape_str (optarg);

      /* invalid requests */
      if (!strcmp ("invalid-requests", long_opts[idx].name)) {
        conf.invalid_requests_log = optarg;
        invalid_log_open (conf.invalid_requests_log);
      }

      /* static file */
      if (!strcmp ("static-file", long_opts[idx].name) &&
          conf.static_file_idx < MAX_EXTENSIONS) {
        if (conf.static_file_max_len < strlen (optarg))
          conf.static_file_max_len = strlen (optarg);
        conf.static_files[conf.static_file_idx++] = optarg;
      }
      /* 4xx to unique count */
      if (!strcmp ("4xx-to-unique-count", long_opts[idx].name))
        conf.client_err_to_unique_count = 1;

      /* html report title */
      if (!strcmp ("html-report-title", long_opts[idx].name))
        conf.html_report_title = optarg;

      /* 444 as 404 */
      if (!strcmp ("444-as-404", long_opts[idx].name))
        conf.code444_as_404 = 1;

      /* all static files */
      if (!strcmp ("all-static-files", long_opts[idx].name))
        conf.all_static_files = 1;

      /* ignore crawlers */
      if (!strcmp ("ignore-crawlers", long_opts[idx].name))
        conf.ignore_crawlers = 1;

      /* ignore status code */
      if (!strcmp ("ignore-status", long_opts[idx].name) &&
          conf.ignore_status_idx < MAX_IGNORE_STATUS) {
        if (!str_inarray (optarg, conf.ignore_status, conf.ignore_status_idx))
          conf.ignore_status[conf.ignore_status_idx++] = optarg;
      }

      /* ignore panel */
      if (!strcmp ("ignore-panel", long_opts[idx].name) &&
          conf.ignore_panel_idx < TOTAL_MODULES) {
        if (!str_inarray (optarg, conf.ignore_panels, conf.ignore_panel_idx))
          conf.ignore_panels[conf.ignore_panel_idx++] = optarg;
      }

      /* ignore referer */
      if (!strcmp ("ignore-referer", long_opts[idx].name) &&
          conf.ignore_referer_idx < MAX_IGNORE_REF)
        conf.ignore_referers[conf.ignore_referer_idx++] = optarg;

      /* sort view */
      if (!strcmp ("sort-panel", long_opts[idx].name) &&
          conf.sort_panel_idx < TOTAL_MODULES)
        conf.sort_panels[conf.sort_panel_idx++] = optarg;

      /* real os */
      if (!strcmp ("real-os", long_opts[idx].name))
        conf.real_os = 1;

      /* double decode */
      if (!strcmp ("double-decode", long_opts[idx].name))
        conf.double_decode = 1;

      /* no color */
      if (!strcmp ("no-color", long_opts[idx].name))
        conf.no_color = 1;

      /* no columns */
      if (!strcmp ("no-column-names", long_opts[idx].name))
        conf.no_column_names = 1;

      /* no csv summary */
      if (!strcmp ("no-csv-summary", long_opts[idx].name))
        conf.no_csv_summary = 1;

      /* json pretty print */
      if (!strcmp ("json-pretty-print", long_opts[idx].name))
        conf.json_pretty_print = 1;

      /* no progress */
      if (!strcmp ("no-progress", long_opts[idx].name))
        conf.no_progress = 1;

      /* specifies the path of the GeoIP City database file */
      if (!strcmp ("geoip-city-data", long_opts[idx].name) ||
          !strcmp ("geoip-database", long_opts[idx].name))
        conf.geoip_database = optarg;

      /* load data from disk */
      if (!strcmp ("load-from-disk", long_opts[idx].name))
        conf.load_from_disk = 1;

      /* keep database files */
      if (!strcmp ("keep-db-files", long_opts[idx].name))
        conf.keep_db_files = 1;

      /* specifies the path of the database file */
      if (!strcmp ("db-path", long_opts[idx].name))
        conf.db_path = optarg;

      /* set the size in bytes of the extra mapped memory */
      if (!strcmp ("xmmap", long_opts[idx].name))
        conf.xmmap = atoi (optarg);

      /* specifies the maximum number of leaf nodes to be cached */
      if (!strcmp ("cache-lcnum", long_opts[idx].name))
        conf.cache_lcnum = atoi (optarg);

      /* specifies the maximum number of non-leaf nodes to be cached */
      if (!strcmp ("cache-ncnum", long_opts[idx].name))
        conf.cache_ncnum = atoi (optarg);

      /* number of members in each leaf page */
      if (!strcmp ("tune-lmemb", long_opts[idx].name))
        conf.tune_lmemb = atoi (optarg);

      /* number of members in each non-leaf page */
      if (!strcmp ("tune-nmemb", long_opts[idx].name))
        conf.tune_nmemb = atoi (optarg);

      /* number of elements of the bucket array */
      if (!strcmp ("tune-bnum", long_opts[idx].name))
        conf.tune_bnum = atoi (optarg);

      /* specifies that each page is compressed with X encoding */
      if (!strcmp ("compression", long_opts[idx].name)) {
#ifdef HAVE_ZLIB
        if (!strcmp ("zlib", optarg))
          conf.compression = TC_ZLIB;
#endif
#ifdef HAVE_BZ2
        if (!strcmp ("bz2", optarg))
          conf.compression = TC_BZ2;
#endif
      }

      /* default config file --dwf */
      if (!strcmp ("dcf", long_opts[idx].name)) {
        display_default_config_file ();
        exit (EXIT_SUCCESS);
      }

      break;
    case 's':
      display_storage ();
      exit (EXIT_SUCCESS);
    case '?':
      exit (EXIT_FAILURE);
    default:
      exit (EXIT_FAILURE);
    }
  }

  for (idx = optind; idx < argc; idx++)
    cmd_help ();
}
示例#2
0
文件: options.c 项目: Seravo/goaccess
/* Parse command line long options. */
static void
parse_long_opt (const char *name, const char *oarg)
{
  if (!strcmp ("no-global-config", name))
    return;

  /* == LOG & DATE FORMAT OPTIONS == */

  /* log format */
  if (!strcmp ("log-format", name) && !conf.log_format)
    set_log_format_str (oarg);

  /* time format */
  if (!strcmp ("time-format", name))
    set_time_format_str (oarg);

  /* date format */
  if (!strcmp ("date-format", name))
    set_date_format_str (oarg);

  /* == USER INTERFACE OPTIONS == */

  /* colors */
  if (!strcmp ("color", name) && conf.color_idx < MAX_CUSTOM_COLORS)
    conf.colors[conf.color_idx++] = oarg;

  /* color scheme */
  if (!strcmp ("color-scheme", name))
    conf.color_scheme = atoi (oarg);

  /* html custom CSS */
  if (!strcmp ("html-custom-css", name))
    conf.html_custom_css = oarg;

  /* html custom JS */
  if (!strcmp ("html-custom-js", name))
    conf.html_custom_js = oarg;

  /* html JSON object containing default preferences */
  if (!strcmp ("html-prefs", name))
    conf.html_prefs = oarg;

  /* html report title */
  if (!strcmp ("html-report-title", name))
    conf.html_report_title = oarg;

  /* json pretty print */
  if (!strcmp ("json-pretty-print", name))
    conf.json_pretty_print = 1;

  /* max items */
  if (!strcmp ("max-items", name)) {
    char *sEnd;
    int max = strtol (oarg, &sEnd, 10);
    if (oarg == sEnd || *sEnd != '\0' || errno == ERANGE)
      conf.max_items = 1;
    else
      conf.max_items = max;
  }

  /* no color */
  if (!strcmp ("no-color", name))
    conf.no_color = 1;

  /* no columns */
  if (!strcmp ("no-column-names", name))
    conf.no_column_names = 1;

  /* no csv summary */
  if (!strcmp ("no-csv-summary", name))
    conf.no_csv_summary = 1;

  /* no progress */
  if (!strcmp ("no-progress", name))
    conf.no_progress = 1;

  /* no tab scroll */
  if (!strcmp ("no-tab-scroll", name))
    conf.no_tab_scroll = 1;

  /* no html last updated field */
  if (!strcmp ("no-html-last-updated", name))
    conf.no_html_last_updated = 1;

  /* == SERVER OPTIONS == */

  /* address to bind to */
  if (!strcmp ("addr", name))
    conf.addr = oarg;

  /* FIFO in (read) */
  if (!strcmp ("fifo-in", name))
    conf.fifo_in = oarg;

  /* FIFO out (write) */
  if (!strcmp ("fifo-out", name))
    conf.fifo_out = oarg;

  /* WebSocket origin */
  if (!strcmp ("origin", name))
    conf.origin = oarg;

  /* port to use */
  if (!strcmp ("port", name)) {
    int port = strtol (oarg, NULL, 10);
    if (port < 0 || port > 65535)
      LOG_DEBUG (("Invalid port."));
    else
      conf.port = oarg;
  }

  /* real time HTML */
  if (!strcmp ("real-time-html", name))
    conf.real_time_html = 1;

  /* TLS/SSL certificate */
  if (!strcmp ("ssl-cert", name))
    conf.sslcert = oarg;

  /* TLS/SSL private key */
  if (!strcmp ("ssl-key", name))
    conf.sslkey = oarg;

  /* URL to which the WebSocket server responds. */
  if (!strcmp ("ws-url", name))
    conf.ws_url = oarg;

  /* == FILE OPTIONS == */

  /* invalid requests */
  if (!strcmp ("invalid-requests", name)) {
    conf.invalid_requests_log = oarg;
    invalid_log_open (conf.invalid_requests_log);
  }

  /* output file */
  if (!strcmp ("output", name) && conf.output_format_idx < MAX_OUTFORMATS)
    conf.output_formats[conf.output_format_idx++] = optarg;

  /* == PARSE OPTIONS == */

  /* 444 as 404 */
  if (!strcmp ("444-as-404", name))
    conf.code444_as_404 = 1;

  /* 4xx to unique count */
  if (!strcmp ("4xx-to-unique-count", name))
    conf.client_err_to_unique_count = 1;

  /* all static files */
  if (!strcmp ("all-static-files", name))
    conf.all_static_files = 1;

  /* crawlers only */
  if (!strcmp ("crawlers-only", name))
    conf.crawlers_only = 1;

  /* date specificity */
  if (!strcmp ("date-spec", name) && !strcmp (oarg, "hr"))
    conf.date_spec_hr = 1;

  /* double decode */
  if (!strcmp ("double-decode", name))
    conf.double_decode = 1;

  /* enable panel */
  if (!strcmp ("enable-panel", name) && conf.enable_panel_idx < TOTAL_MODULES) {
    if (!str_inarray (oarg, conf.enable_panels, conf.enable_panel_idx))
      conf.enable_panels[conf.enable_panel_idx++] = oarg;
  }

  /* hour specificity */
  if (!strcmp ("hour-spec", name) && !strcmp (oarg, "min"))
    conf.hour_spec_min = 1;

  /* ignore crawlers */
  if (!strcmp ("ignore-crawlers", name))
    conf.ignore_crawlers = 1;

  /* ignore panel */
  if (!strcmp ("ignore-panel", name) && conf.ignore_panel_idx < TOTAL_MODULES) {
    if (!str_inarray (oarg, conf.ignore_panels, conf.ignore_panel_idx))
      conf.ignore_panels[conf.ignore_panel_idx++] = oarg;
  }

  /* ignore referer */
  if (!strcmp ("ignore-referer", name) &&
      conf.ignore_referer_idx < MAX_IGNORE_REF)
    conf.ignore_referers[conf.ignore_referer_idx++] = oarg;

  /* ignore status code */
  if (!strcmp ("ignore-status", name) &&
      conf.ignore_status_idx < MAX_IGNORE_STATUS) {
    if (!str_inarray (oarg, conf.ignore_status, conf.ignore_status_idx))
      conf.ignore_status[conf.ignore_status_idx++] = oarg;
  }

  /* number of line tests */
  if (!strcmp ("num-tests", name)) {
    char *sEnd;
    int tests = strtol (oarg, &sEnd, 10);
    if (oarg == sEnd || *sEnd != '\0' || errno == ERANGE)
      return;
    conf.num_tests = tests;
  }

  /* real os */
  if (!strcmp ("real-os", name))
    conf.real_os = 1;

  /* sort view */
  if (!strcmp ("sort-panel", name) && conf.sort_panel_idx < TOTAL_MODULES)
    conf.sort_panels[conf.sort_panel_idx++] = oarg;

  /* static file */
  if (!strcmp ("static-file", name) && conf.static_file_idx < MAX_EXTENSIONS) {
    if (conf.static_file_max_len < strlen (oarg))
      conf.static_file_max_len = strlen (oarg);
    conf.static_files[conf.static_file_idx++] = oarg;
  }

  /* == GEOIP OPTIONS == */

  /* specifies the path of the GeoIP City database file */
  if (!strcmp ("geoip-city-data", name) || !strcmp ("geoip-database", name))
    conf.geoip_database = oarg;

  /* == BTREE OPTIONS == */

  /* keep database files */
  if (!strcmp ("keep-db-files", name))
    conf.keep_db_files = 1;

  /* load data from disk */
  if (!strcmp ("load-from-disk", name))
    conf.load_from_disk = 1;

  /* specifies the path of the database file */
  if (!strcmp ("db-path", name))
    conf.db_path = oarg;

  /* specifies the maximum number of leaf nodes to be cached */
  if (!strcmp ("cache-lcnum", name))
    conf.cache_lcnum = atoi (oarg);

  /* specifies the maximum number of non-leaf nodes to be cached */
  if (!strcmp ("cache-ncnum", name))
    conf.cache_ncnum = atoi (oarg);

  /* number of elements of the bucket array */
  if (!strcmp ("tune-bnum", name))
    conf.tune_bnum = atoi (oarg);

  /* number of members in each non-leaf page */
  if (!strcmp ("tune-nmemb", name))
    conf.tune_nmemb = atoi (oarg);

  /* number of members in each leaf page */
  if (!strcmp ("tune-lmemb", name))
    conf.tune_lmemb = atoi (oarg);

  /* set the size in bytes of the extra mapped memory */
  if (!strcmp ("xmmap", name))
    conf.xmmap = atoi (oarg);

  /* specifies that each page is compressed with X encoding */
  if (!strcmp ("compression", name)) {
#ifdef HAVE_ZLIB
    if (!strcmp ("zlib", oarg))
      conf.compression = TC_ZLIB;
#endif
#ifdef HAVE_BZ2
    if (!strcmp ("bz2", oarg))
      conf.compression = TC_BZ2;
#endif
  }

  /* default config file --dwf */
  if (!strcmp ("dcf", name)) {
    display_default_config_file ();
    exit (EXIT_SUCCESS);
  }
}