static const char * set_formats (char *date_format, char *log_format, char *time_format) { /* display status bar error messages */ if (!time_format && !conf.time_format) return "Select a time format."; if (!date_format && !conf.date_format) return "Select a date format."; if (!log_format && !conf.log_format) return "Select a log format."; if (time_format) { free (conf.time_format); conf.time_format = unescape_str (time_format); } if (date_format) { free (conf.date_format); conf.date_format = unescape_str (date_format); } if (log_format) { free (conf.log_format); conf.log_format = unescape_str (log_format); } set_spec_date_format (); return NULL; }
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 (); }
/* render config log date/format dialog */ int verify_format (GLog * logger, GSpinner * spinner) { GMenu *menu; WINDOW *win; char *cstm_log, *cstm_date; int c, quit = 1; int invalid = 1; int y, x, h = CONF_WIN_H, w = CONF_WIN_W; int w2 = w - 2; size_t i, n, sel; /* conf dialog menu options */ const char *choices[] = { "Common Log Format (CLF)", "Common Log Format (CLF) with Virtual Host", "NCSA Combined Log Format", "NCSA Combined Log Format with Virtual Host", "W3C", "CloudFront (Download Distribution)" }; n = ARRAY_SIZE (choices); getmaxyx (stdscr, y, x); win = newwin (h, w, (y - h) / 2, (x - w) / 2); keypad (win, TRUE); wborder (win, '|', '|', '-', '-', '+', '+', '+', '+'); /* create a new instance of GMenu and make it selectable */ menu = new_gmenu (win, CONF_MENU_H, CONF_MENU_W, CONF_MENU_Y, CONF_MENU_X); menu->size = n; menu->selectable = 1; /* add items to GMenu */ menu->items = (GItem *) xcalloc (n, sizeof (GItem)); for (i = 0; i < n; ++i) { menu->items[i].name = alloc_string (choices[i]); sel = get_selected_format_idx (); menu->items[i].checked = sel == i ? 1 : 0; } post_gmenu (menu); draw_header (win, "Log Format Configuration", " %s", 1, 1, w2, 1, 0); mvwprintw (win, 2, 2, "[SPACE] to toggle - [ENTER] to proceed"); /* set log format from goaccessrc if available */ draw_header (win, "Log Format - [c] to add/edit format", " %s", 11, 1, w2, 1, 0); if (conf.log_format) { log_format = escape_str (conf.log_format); mvwprintw (win, 12, 2, "%.*s", CONF_MENU_W, log_format); if (conf.log_format) free (conf.log_format); } /* set date format from goaccessrc if available */ draw_header (win, "Date Format - [d] to add/edit format", " %s", 14, 1, w2, 1, 0); if (conf.date_format) { date_format = escape_str (conf.date_format); mvwprintw (win, 15, 2, "%.*s", CONF_MENU_W, date_format); if (conf.date_format) free (conf.date_format); } wrefresh (win); while (quit) { c = wgetch (stdscr); switch (c) { case KEY_DOWN: gmenu_driver (menu, REQ_DOWN); draw_header (win, "", "%s", 3, 2, CONF_MENU_W, 0, 0); break; case KEY_UP: gmenu_driver (menu, REQ_UP); draw_header (win, "", "%s", 3, 2, CONF_MENU_W, 0, 0); break; case 32: /* space */ gmenu_driver (menu, REQ_SEL); if (date_format) free (date_format); if (log_format) free (log_format); for (i = 0; i < n; ++i) { if (menu->items[i].checked != 1) continue; date_format = get_selected_date_str (i); log_format = get_selected_format_str (i); draw_header (win, date_format, " %s", 15, 1, CONF_MENU_W, 0, 0); draw_header (win, log_format, " %s", 12, 1, CONF_MENU_W, 0, 0); break; } break; case 99: /* c */ /* clear top status bar */ draw_header (win, "", "%s", 3, 2, CONF_MENU_W, 0, 0); wmove (win, 12, 2); /* get input string */ cstm_log = input_string (win, 12, 2, 70, log_format, 0, 0); if (cstm_log != NULL && *cstm_log != '\0') { if (log_format) free (log_format); log_format = alloc_string (cstm_log); free (cstm_log); } /* did not set an input string */ else { if (cstm_log) free (cstm_log); if (log_format) { free (log_format); log_format = NULL; } } break; case 100: /* d */ /* clear top status bar */ draw_header (win, "", "%s", 3, 2, CONF_MENU_W, 0, 0); wmove (win, 15, 0); /* get input string */ cstm_date = input_string (win, 15, 2, 14, date_format, 0, 0); if (cstm_date != NULL && *cstm_date != '\0') { if (date_format) free (date_format); date_format = alloc_string (cstm_date); free (cstm_date); } /* did not set an input string */ else { if (cstm_date) free (cstm_date); if (date_format) { free (date_format); date_format = NULL; } } break; case 274: /* F10 */ case 0x0a: case 0x0d: case KEY_ENTER: /* display status bar error messages */ if (date_format == NULL) draw_header (win, "Select a date format.", "%s", 3, 2, CONF_MENU_W, WHITE_RED, 0); if (log_format == NULL) draw_header (win, "Select a log format.", "%s", 3, 2, CONF_MENU_W, WHITE_RED, 0); if (date_format && log_format) { conf.date_format = unescape_str (date_format); conf.log_format = unescape_str (log_format); /* test log against selected settings */ if (test_format (logger)) { invalid = 1; draw_header (win, "No valid hits.", "%s", 3, 2, CONF_MENU_W, WHITE_RED, 0); free (conf.log_format); free (conf.date_format); } /* valid data, reset logger & start parsing */ else { reset_struct (logger); /* start spinner thread */ spinner->win = win; spinner->y = 3; spinner->x = 2; spinner->spin_x = CONF_MENU_W; spinner->w = CONF_MENU_W; spinner->color = BLACK_CYAN; ui_spinner_create (spinner); invalid = 0; quit = 0; } } break; case KEY_RESIZE: case 'q': quit = 0; break; } pthread_mutex_lock (&spinner->mutex); wrefresh (win); pthread_mutex_unlock (&spinner->mutex); } /* clean stuff up */ for (i = 0; i < n; ++i) free (menu->items[i].name); free (menu->items); free (menu); return invalid ? 1 : 0; }
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': conf.ignore_host = optarg; break; case 'a': conf.list_agents = 1; break; case 'c': conf.load_conf_dlg = 1; break; case 'q': conf.ignore_qstr = 1; break; case 'o': conf.output_format = optarg; 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 */ if (!strcmp ("color-scheme", long_opts[idx].name)) conf.color_scheme = atoi (optarg); if (!strcmp ("log-format", long_opts[idx].name)) conf.log_format = unescape_str (optarg); if (!strcmp ("date-format", long_opts[idx].name)) conf.date_format = unescape_str (optarg); if (!strcmp ("static-file", long_opts[idx].name)) { if (conf.static_file_max_len < strlen (optarg)) conf.static_file_max_len = strlen (optarg); conf.static_files[conf.static_file_idx++] = optarg; } if (!strcmp ("real-os", long_opts[idx].name)) conf.real_os = 1; if (!strcmp ("no-color", long_opts[idx].name)) conf.no_color = 1; 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)) conf.geoip_city_data = 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 } break; case 's': display_storage (); exit (EXIT_SUCCESS); case '?': exit (EXIT_FAILURE); default: exit (EXIT_FAILURE); } } for (idx = optind; idx < argc; idx++) cmd_help (); }