Example #1
0
static void
expand_on_mouse_click (void)
{
  int ok_mouse;
  MEVENT event;

  ok_mouse = getmouse (&event);
  if (!conf.mouse_support || ok_mouse != OK)
    return;

  if (event.bstate & BUTTON1_CLICKED) {
    /* ignore header/footer clicks */
    if (event.y < MAX_HEIGHT_HEADER || event.y == LINES - 1)
      return;

    if (set_module_from_mouse_event (&gscroll, dash, event.y))
      return;

    reset_scroll_offsets (&gscroll);
    gscroll.expanded = 1;

    free_holder_by_module (&holder, gscroll.current);
    free_dashboard (dash);
    allocate_holder_by_module (gscroll.current);
    allocate_data ();

    render_screens ();
  }
}
Example #2
0
static void
set_module_to (GScrolling * scrll, GModule module)
{
  /* reset expanded module */
  collapse_current_module ();
  scrll->current = module;
  render_screens ();
}
Example #3
0
/* collapse the current expanded module */
static void
collapse_current_module (void)
{
  if (scrolling.expanded) {
    scrolling.expanded = 0;
    reset_scroll_offsets (&scrolling);
    free_dashboard (dash);
    allocate_data ();
    render_screens ();
  }
}
Example #4
0
static void
window_resize (void)
{
  endwin ();
  refresh ();
  werase (header_win);
  werase (main_win);
  werase (stdscr);
  term_size (main_win);
  refresh ();
  render_screens ();
}
Example #5
0
static void
set_module_to (GScroll * scrll, GModule module)
{
  if (ignore_panel (module)) {
    disabled_panel_msg (module);
    return;
  }
  /* reset expanded module */
  collapse_current_module ();
  scrll->current = module;
  render_screens ();
}
Example #6
0
/* collapse the current expanded module */
static void
collapse_current_module (void)
{
  if (!gscroll.expanded)
    return;

  gscroll.expanded = 0;
  reset_scroll_offsets (&gscroll);
  free_dashboard (dash);
  allocate_data ();
  render_screens ();
}
Example #7
0
static void
render_sort_dialog (void)
{
  load_sort_win (main_win, gscroll.current, &module_sort[gscroll.current]);
  pthread_mutex_lock (&gdns_thread.mutex);
  free_holder (&holder);
  pthread_cond_broadcast (&gdns_thread.not_empty);
  pthread_mutex_unlock (&gdns_thread.mutex);
  free_dashboard (dash);
  allocate_holder ();
  allocate_data ();
  render_screens ();
}
Example #8
0
static void
search_next_match (int search)
{
  pthread_mutex_lock (&gdns_thread.mutex);
  search = perform_next_find (holder, &gscroll);
  pthread_mutex_unlock (&gdns_thread.mutex);
  if (search != 0)
    return;

  free_dashboard (dash);
  allocate_data ();
  render_screens ();
}
Example #9
0
static void
curses_output (void)
{
  allocate_data ();
  if (!conf.skip_term_resolver)
    gdns_thread_create ();

  render_screens ();
  get_keys ();

  /* restore tty modes and reset
   * terminal into non-visual mode */
  endwin ();
}
Example #10
0
static void
render_search_dialog (int search)
{
  if (render_find_dialog (main_win, &gscroll))
    return;

  pthread_mutex_lock (&gdns_thread.mutex);
  search = perform_next_find (holder, &gscroll);
  pthread_mutex_unlock (&gdns_thread.mutex);
  if (search != 0)
    return;

  free_dashboard (dash);
  allocate_data ();
  render_screens ();
}
Example #11
0
static void
perform_tail_follow (uint64_t * size1)
{
  uint64_t size2 = 0;
  char buf[LINE_BUFFER];
  FILE *fp = NULL;

  if (logger->piping)
    return;

  size2 = file_size (conf.ifile);

  /* file hasn't changed */
  if (size2 == *size1)
    return;

  if (!(fp = fopen (conf.ifile, "r")))
    FATAL ("Unable to read log file %s.", strerror (errno));
  if (!fseeko (fp, *size1, SEEK_SET))
    while (fgets (buf, LINE_BUFFER, fp) != NULL)
      parse_log (&logger, buf, -1);
  fclose (fp);

  *size1 = size2;
  pthread_mutex_lock (&gdns_thread.mutex);
  free_holder (&holder);
  pthread_cond_broadcast (&gdns_thread.not_empty);
  pthread_mutex_unlock (&gdns_thread.mutex);

  free_dashboard (dash);
  allocate_holder ();
  allocate_data ();

  term_size (main_win);
  render_screens ();
  usleep (200000);      /* 0.2 seconds */
}
Example #12
0
static void
get_keys (void)
{
  int search = 0;
  int c, quit = 1;
  uint64_t size1 = 0;

  if (!logger->piping)
    size1 = file_size (conf.ifile);

  while (quit) {
    c = wgetch (stdscr);
    switch (c) {
    case 'q':  /* quit */
      if (!gscroll.expanded) {
        quit = 0;
        break;
      }
      collapse_current_module ();
      break;
    case KEY_F (1):
    case '?':
    case 'h':
      load_help_popup (main_win);
      render_screens ();
      break;
    case 49:   /* 1 */
      /* reset expanded module */
      set_module_to (&gscroll, VISITORS);
      break;
    case 50:   /* 2 */
      /* reset expanded module */
      set_module_to (&gscroll, REQUESTS);
      break;
    case 51:   /* 3 */
      /* reset expanded module */
      set_module_to (&gscroll, REQUESTS_STATIC);
      break;
    case 52:   /* 4 */
      /* reset expanded module */
      set_module_to (&gscroll, NOT_FOUND);
      break;
    case 53:   /* 5 */
      /* reset expanded module */
      set_module_to (&gscroll, HOSTS);
      break;
    case 54:   /* 6 */
      /* reset expanded module */
      set_module_to (&gscroll, OS);
      break;
    case 55:   /* 7 */
      /* reset expanded module */
      set_module_to (&gscroll, BROWSERS);
      break;
    case 56:   /* 8 */
      /* reset expanded module */
      set_module_to (&gscroll, VISIT_TIMES);
      break;
    case 57:   /* 9 */
      /* reset expanded module */
      set_module_to (&gscroll, REFERRERS);
      break;
    case 48:   /* 0 */
      /* reset expanded module */
      set_module_to (&gscroll, REFERRING_SITES);
      break;
    case 33:   /* shift + 1 */
      /* reset expanded module */
      set_module_to (&gscroll, KEYPHRASES);
      break;
    case 34:   /* Shift + 2 */
      /* reset expanded module */
#ifdef HAVE_LIBGEOIP
      set_module_to (&gscroll, GEO_LOCATION);
#else
      set_module_to (&gscroll, STATUS_CODES);
#endif
      break;
#ifdef HAVE_LIBGEOIP
    case 35:   /* Shift + 3 */
      /* reset expanded module */
      set_module_to (&gscroll, STATUS_CODES);
      break;
#endif
    case 9:    /* TAB */
      /* reset expanded module */
      collapse_current_module ();
      if (next_module () == 0)
        render_screens ();
      break;
    case 353:  /* Shift TAB */
      /* reset expanded module */
      collapse_current_module ();
      if (previous_module () == 0)
        render_screens ();
      break;
    case 'g':  /* g = top */
      scroll_to_first_line ();
      display_content (main_win, logger, dash, &gscroll);
      break;
    case 'G':  /* G = down */
      scroll_to_last_line ();
      display_content (main_win, logger, dash, &gscroll);
      break;
      /* expand dashboard module */
    case KEY_RIGHT:
    case 0x0a:
    case 0x0d:
    case 32:   /* ENTER */
    case 79:   /* o */
    case 111:  /* O */
    case KEY_ENTER:
      expand_current_module ();
      display_content (main_win, logger, dash, &gscroll);
      break;
    case KEY_DOWN:     /* scroll main dashboard */
      if ((gscroll.dash + real_size_y) < (unsigned) dash->total_alloc) {
        gscroll.dash++;
        display_content (main_win, logger, dash, &gscroll);
      }
      break;
    case KEY_MOUSE:    /* handles mouse events */
      expand_on_mouse_click ();
      break;
    case 106:  /* j - DOWN expanded module */
      scroll_down_expanded_module ();
      display_content (main_win, logger, dash, &gscroll);
      break;
      /* scroll up main_win */
    case KEY_UP:
      if (gscroll.dash > 0) {
        scroll_up_dashboard ();
        display_content (main_win, logger, dash, &gscroll);
      }
      break;
    case 2:    /* ^ b - page up */
    case 339:  /* ^ PG UP */
      page_up_module ();
      display_content (main_win, logger, dash, &gscroll);
      break;
    case 6:    /* ^ f - page down */
    case 338:  /* ^ PG DOWN */
      page_down_module ();
      display_content (main_win, logger, dash, &gscroll);
      break;
    case 107:  /* k - UP expanded module */
      scroll_up_expanded_module ();
      display_content (main_win, logger, dash, &gscroll);
      break;
    case 'n':
      search_next_match (search);
      break;
    case '/':
      render_search_dialog (search);
      break;
    case 99:   /* c */
      if (conf.no_color)
        break;
      load_schemes_win (main_win);
      free_dashboard (dash);
      allocate_data ();
      render_screens ();
      break;
    case 115:  /* s */
      render_sort_dialog ();
      break;
    case 269:
    case KEY_RESIZE:
      window_resize ();
      break;
    default:
      perform_tail_follow (&size1);
      break;
    }
  }
}
Example #13
0
int
main (int argc, char **argv)
{
  int quit = 0;

#if defined(__GLIBC__)
  setup_signal_handlers ();
#endif

  /* command line/config options */
  verify_global_config (argc, argv);
  parse_conf_file (&argc, &argv);
  parse_cmd_line (argc, argv);

  /* initialize storage */
  init_storage ();
  /* setup to use the current locale */
  set_locale ();

#ifdef HAVE_LIBGEOIP
  init_geoip ();
#endif

  /* init logger */
  logger = init_log ();
  /* init parsing spinner */
  parsing_spinner = new_gspinner ();
  parsing_spinner->process = &logger->process;

  /* outputting to stdout */
  if (conf.output_html) {
    ui_spinner_create (parsing_spinner);
    goto out;
  }

  /* init curses */
  set_input_opts ();
  if (conf.no_color || has_colors () == FALSE) {
    conf.color_scheme = NO_COLOR;
    conf.no_color = 1;
  } else {
    start_color ();
  }
  init_colors ();
  init_windows (&header_win, &main_win);
  set_curses_spinner (parsing_spinner);

  /* configuration dialog */
  if (isatty (STDIN_FILENO) && (conf.log_format == NULL || conf.load_conf_dlg)) {
    refresh ();
    quit = verify_format (logger, parsing_spinner);
  }
  /* straight parsing */
  else {
    ui_spinner_create (parsing_spinner);
  }

out:

  /* main processing event */
  time (&start_proc);
  if (conf.load_from_disk)
    set_general_stats ();
  else if (!quit && parse_log (&logger, NULL, -1))
    FATAL ("Error while processing file");

  logger->offset = logger->process;

  /* no valid entries to process from the log */
  if ((logger->process == 0) || (logger->process == logger->invalid))
    FATAL ("Nothing valid to process.");

  /* init reverse lookup thread */
  gdns_init ();
  parse_initial_sort ();
  allocate_holder ();

  end_spinner ();
  time (&end_proc);

  /* stdout */
  if (conf.output_html) {
    /* CSV */
    if (conf.output_format && strcmp ("csv", conf.output_format) == 0)
      output_csv (logger, holder);
    /* JSON */
    else if (conf.output_format && strcmp ("json", conf.output_format) == 0)
      output_json (logger, holder);
    /* HTML */
    else
      output_html (logger, holder);
  }
  /* curses */
  else {
    allocate_data ();
    if (!conf.skip_term_resolver)
      gdns_thread_create ();

    render_screens ();
    get_keys ();

    attroff (COLOR_PAIR (COL_WHITE));
    /* restore tty modes and reset
     * terminal into non-visual mode */
    endwin ();
  }
  /* clean */
  house_keeping ();

  return EXIT_SUCCESS;
}
Example #14
0
static void
get_keys (void)
{
  int search;
  int c, quit = 1, scrll, offset, ok_mouse;
  int *scroll_ptr, *offset_ptr;
  int exp_size = DASH_EXPANDED - DASH_NON_DATA;
  MEVENT event;

  char buf[LINE_BUFFER];
  FILE *fp = NULL;
  unsigned long long size1 = 0, size2 = 0;

  if (!logger->piping)
    size1 = file_size (conf.ifile);
  while (quit) {
    c = wgetch (stdscr);
    switch (c) {
    case 'q':  /* quit */
      if (!scrolling.expanded) {
        quit = 0;
        break;
      }
      collapse_current_module ();
      break;
    case KEY_F (1):
    case '?':
    case 'h':
      load_help_popup (main_win);
      render_screens ();
      break;
    case 49:   /* 1 */
      /* reset expanded module */
      set_module_to (&scrolling, VISITORS);
      break;
    case 50:   /* 2 */
      /* reset expanded module */
      set_module_to (&scrolling, REQUESTS);
      break;
    case 51:   /* 3 */
      /* reset expanded module */
      set_module_to (&scrolling, REQUESTS_STATIC);
      break;
    case 52:   /* 4 */
      /* reset expanded module */
      set_module_to (&scrolling, NOT_FOUND);
      break;
    case 53:   /* 5 */
      /* reset expanded module */
      set_module_to (&scrolling, HOSTS);
      break;
    case 54:   /* 6 */
      /* reset expanded module */
      set_module_to (&scrolling, OS);
      break;
    case 55:   /* 7 */
      /* reset expanded module */
      set_module_to (&scrolling, BROWSERS);
      break;
    case 56:   /* 8 */
      /* reset expanded module */
      set_module_to (&scrolling, REFERRERS);
      break;
    case 57:   /* 9 */
      /* reset expanded module */
      set_module_to (&scrolling, REFERRING_SITES);
      break;
    case 48:   /* 0 */
      /* reset expanded module */
      set_module_to (&scrolling, KEYPHRASES);
      break;
    case 33:   /* Shift+1 */
      /* reset expanded module */
#ifdef HAVE_LIBGEOIP
      set_module_to (&scrolling, GEO_LOCATION);
#else
      set_module_to (&scrolling, STATUS_CODES);
#endif
      break;
#ifdef HAVE_LIBGEOIP
    case 64:   /* Shift+2 */
      /* reset expanded module */
      set_module_to (&scrolling, STATUS_CODES);
      break;
#endif
    case 9:    /* TAB */
      /* reset expanded module */
      collapse_current_module ();
      scrolling.current++;
      if (scrolling.current == TOTAL_MODULES)
        scrolling.current = 0;
      render_screens ();
      break;
    case 353:  /* Shift TAB */
      /* reset expanded module */
      collapse_current_module ();
      if (scrolling.current == 0)
        scrolling.current = TOTAL_MODULES - 1;
      else
        scrolling.current--;
      render_screens ();
      break;
    case 'g':  /* g = top */
      if (!scrolling.expanded)
        scrolling.dash = 0;
      else {
        scrolling.module[scrolling.current].scroll = 0;
        scrolling.module[scrolling.current].offset = 0;
      }
      display_content (main_win, logger, dash, &scrolling);
      break;
    case 'G':  /* G = down */
      if (!scrolling.expanded)
        scrolling.dash = dash->total_alloc - real_size_y;
      else {
        scrll = offset = 0;
        scrll = dash->module[scrolling.current].idx_data - 1;
        if (scrll >= exp_size && scrll >= offset + exp_size)
          offset = scrll < exp_size - 1 ? 0 : scrll - exp_size + 1;
        scrolling.module[scrolling.current].scroll = scrll;
        scrolling.module[scrolling.current].offset = offset;
      }
      display_content (main_win, logger, dash, &scrolling);
      break;
      /* expand dashboard module */
    case KEY_RIGHT:
    case 0x0a:
    case 0x0d:
    case 32:   /* ENTER */
    case 79:   /* o */
    case 111:  /* O */
    case KEY_ENTER:
      if (scrolling.expanded && scrolling.current == HOSTS) {
        /* make sure we have a valid IP */
        int sel = scrolling.module[scrolling.current].scroll;
        if (!invalid_ipaddr (dash->module[HOSTS].data[sel].data))
          load_agent_list (main_win, dash->module[HOSTS].data[sel].data);
        break;
      }
      if (scrolling.expanded)
        break;
      reset_scroll_offsets (&scrolling);
      scrolling.expanded = 1;

      free_holder_by_module (&holder, scrolling.current);
      free_dashboard (dash);
      allocate_holder_by_module (scrolling.current);
      allocate_data ();

      display_content (main_win, logger, dash, &scrolling);
      break;
    case KEY_DOWN:     /* scroll main dashboard */
      if ((scrolling.dash + real_size_y) < (unsigned) dash->total_alloc) {
        scrolling.dash++;
        display_content (main_win, logger, dash, &scrolling);
      }
      break;
    case KEY_MOUSE:    /* handles mouse events */
      ok_mouse = getmouse (&event);
      if (conf.mouse_support && ok_mouse == OK) {
        if (event.bstate & BUTTON1_CLICKED) {
          /* ignore header/footer clicks */
          if (event.y < MAX_HEIGHT_HEADER || event.y == LINES - 1)
            break;

          if (set_module_from_mouse_event (&scrolling, dash, event.y))
            break;
          reset_scroll_offsets (&scrolling);
          scrolling.expanded = 1;

          free_holder_by_module (&holder, scrolling.current);
          free_dashboard (dash);
          allocate_holder_by_module (scrolling.current);
          allocate_data ();

          render_screens ();
        }
      }
      break;
    case 106:  /* j - DOWN expanded module */
      scroll_ptr = &scrolling.module[scrolling.current].scroll;
      offset_ptr = &scrolling.module[scrolling.current].offset;

      if (!scrolling.expanded)
        break;
      if (*scroll_ptr >= dash->module[scrolling.current].idx_data - 1)
        break;
      ++(*scroll_ptr);
      if (*scroll_ptr >= exp_size && *scroll_ptr >= *offset_ptr + exp_size)
        ++(*offset_ptr);
      display_content (main_win, logger, dash, &scrolling);
      break;
      /* scroll up main_win */
    case KEY_UP:
      if (scrolling.dash > 0) {
        scrolling.dash--;
        display_content (main_win, logger, dash, &scrolling);
      }
      break;
    case 2:    /* ^ b - page up */
    case 339:  /* ^ PG UP */
      scroll_ptr = &scrolling.module[scrolling.current].scroll;
      offset_ptr = &scrolling.module[scrolling.current].offset;

      if (!scrolling.expanded)
        break;
      /* decrease scroll and offset by exp_size */
      *scroll_ptr -= exp_size;
      if (*scroll_ptr < 0)
        *scroll_ptr = 0;

      if (*scroll_ptr < *offset_ptr)
        *offset_ptr -= exp_size;
      if (*offset_ptr <= 0)
        *offset_ptr = 0;
      display_content (main_win, logger, dash, &scrolling);
      break;
    case 6:    /* ^ f - page down */
    case 338:  /* ^ PG DOWN */
      scroll_ptr = &scrolling.module[scrolling.current].scroll;
      offset_ptr = &scrolling.module[scrolling.current].offset;

      if (!scrolling.expanded)
        break;

      *scroll_ptr += exp_size;
      if (*scroll_ptr >= dash->module[scrolling.current].idx_data - 1)
        *scroll_ptr = dash->module[scrolling.current].idx_data - 1;
      if (*scroll_ptr >= exp_size && *scroll_ptr >= *offset_ptr + exp_size)
        *offset_ptr += exp_size;
      if (*offset_ptr + exp_size >=
          dash->module[scrolling.current].idx_data - 1)
        *offset_ptr = dash->module[scrolling.current].idx_data - exp_size;
      if (*scroll_ptr < exp_size - 1)
        *offset_ptr = 0;

      display_content (main_win, logger, dash, &scrolling);
      break;
    case 107:  /* k - UP expanded module */
      scroll_ptr = &scrolling.module[scrolling.current].scroll;
      offset_ptr = &scrolling.module[scrolling.current].offset;

      if (!scrolling.expanded)
        break;
      if (*scroll_ptr <= 0)
        break;
      --(*scroll_ptr);
      if (*scroll_ptr < *offset_ptr)
        --(*offset_ptr);
      display_content (main_win, logger, dash, &scrolling);
      break;
    case 'n':
      pthread_mutex_lock (&gdns_thread.mutex);
      search = perform_next_find (holder, &scrolling);
      pthread_mutex_unlock (&gdns_thread.mutex);
      if (search == 0) {
        free_dashboard (dash);
        allocate_data ();
        render_screens ();
      }
      break;
    case '/':
      if (render_find_dialog (main_win, &scrolling))
        break;
      pthread_mutex_lock (&gdns_thread.mutex);
      search = perform_next_find (holder, &scrolling);
      pthread_mutex_unlock (&gdns_thread.mutex);
      if (search == 0) {
        free_dashboard (dash);
        allocate_data ();
        render_screens ();
      }
      break;
    case 99:   /* c */
      if (conf.no_color)
        break;
      load_schemes_win (main_win);
      free_dashboard (dash);
      allocate_data ();
      render_screens ();
      break;
    case 115:  /* s */
      load_sort_win (main_win, scrolling.current,
                     &module_sort[scrolling.current]);
      pthread_mutex_lock (&gdns_thread.mutex);
      free_holder (&holder);
      pthread_cond_broadcast (&gdns_thread.not_empty);
      pthread_mutex_unlock (&gdns_thread.mutex);
      free_dashboard (dash);
      allocate_holder ();
      allocate_data ();
      render_screens ();
      break;
    case 269:
    case KEY_RESIZE:
      endwin ();
      refresh ();
      werase (header_win);
      werase (main_win);
      werase (stdscr);
      term_size (main_win);
      refresh ();
      render_screens ();
      break;
    default:
      if (logger->piping)
        break;
      size2 = file_size (conf.ifile);

      /* file has changed */
      if (size2 != size1) {
        if (!(fp = fopen (conf.ifile, "r")))
          FATAL ("Unable to read log file %s.", strerror (errno));
        if (!fseeko (fp, size1, SEEK_SET))
          while (fgets (buf, LINE_BUFFER, fp) != NULL)
            parse_log (&logger, buf, -1);
        fclose (fp);

        size1 = size2;
        pthread_mutex_lock (&gdns_thread.mutex);
        free_holder (&holder);
        pthread_cond_broadcast (&gdns_thread.not_empty);
        pthread_mutex_unlock (&gdns_thread.mutex);

        free_dashboard (dash);
        allocate_holder ();
        allocate_data ();

        term_size (main_win);
        render_screens ();
        usleep (200000);        /* 0.2 seconds */
      }
      break;
    }
  }
}