/* render find dialog */ int render_find_dialog (WINDOW * main_win, GScroll * gscroll) { int y, x, valid = 1; int w = FIND_DLG_WIDTH; int h = FIND_DLG_HEIGHT; char *query = NULL; WINDOW *win; getmaxyx (stdscr, y, x); win = newwin (h, w, (y - h) / 2, (x - w) / 2); keypad (win, TRUE); wborder (win, '|', '|', '-', '-', '+', '+', '+', '+'); draw_header (win, FIND_HEAD, " %s", 1, 1, w - 2, 1, 0); draw_header (win, FIND_DESC, " %s", 2, 1, w - 2, 2, 0); find_t.icase = 0; query = input_string (win, 4, 2, w - 3, "", 1, &find_t.icase); if (query != NULL && *query != '\0') { reset_scroll_offsets (gscroll); reset_find (); find_t.pattern = xstrdup (query); valid = 0; } if (query != NULL) free (query); touchwin (main_win); close_win (win); wrefresh (main_win); return valid; }
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 (); } }
/* 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 (); } }
/* 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 (); }
static void expand_current_module (void) { if (gscroll.expanded && gscroll.current == HOSTS) { load_ip_agent_list (); return; } if (gscroll.expanded) 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 (); }
/* set search gscroll */ static void perform_find_dash_scroll (GScroll * gscroll, GModule module) { int *scrll, *offset; int exp_size = get_num_expanded_data_rows (); /* reset gscroll offsets if we are changing module */ if (gscroll->current != module) reset_scroll_offsets (gscroll); scrll = &gscroll->module[module].scroll; offset = &gscroll->module[module].offset; (*scrll) = find_t.next_idx; if (*scrll >= exp_size && *scrll >= *offset + exp_size) (*offset) = (*scrll) < exp_size - 1 ? 0 : (*scrll) - exp_size + 1; gscroll->current = module; gscroll->dash = module * DASH_COLLAPSED; gscroll->expanded = 1; find_t.module = module; }
/* set search scrolling */ void perform_find_dash_scroll (GScrolling * scrolling, GModule module) { int *scroll, *offset; int exp_size = DASH_EXPANDED - DASH_NON_DATA; /* reset scrolling offsets if we are changing module */ if (scrolling->current != module) reset_scroll_offsets (scrolling); scroll = &scrolling->module[module].scroll; offset = &scrolling->module[module].offset; (*scroll) = find_t.next_idx; if (*scroll >= exp_size && *scroll >= *offset + exp_size) (*offset) = (*scroll) < exp_size - 1 ? 0 : (*scroll) - exp_size + 1; scrolling->current = module; scrolling->dash = module * DASH_COLLAPSED; scrolling->expanded = 1; find_t.module = module; }
/* perform a forward search across all modules */ int perform_next_find (GHolder * h, GScroll * gscroll) { int y, x, j, n, rc; char buf[REGEX_ERROR]; char *data; regex_t regex; GModule module; GSubList *sub_list; getmaxyx (stdscr, y, x); if (find_t.pattern == NULL || *find_t.pattern == '\0') return 1; /* compile and initialize regexp */ if (regexp_init (®ex, find_t.pattern)) return 1; /* use last find_t.module and start search */ for (module = find_t.module; module < TOTAL_MODULES; module++) { n = h[module].idx; for (j = find_t.next_parent_idx; j < n; j++, find_t.next_idx++) { data = h[module].items[j].metrics->data; rc = regexec (®ex, data, 0, NULL, 0); if (rc != 0 && rc != REG_NOMATCH) { regerror (rc, ®ex, buf, sizeof (buf)); draw_header (stdscr, buf, "%s", y - 1, 0, x, WHITE_RED, 0); refresh (); regfree (®ex); return 1; } else if (rc == 0 && !find_t.look_in_sub) { find_t.look_in_sub = 1; goto found; } else { sub_list = h[module].items[j].sub_list; if (find_next_sub_item (sub_list, ®ex) == 0) goto found; } } /* reset find */ find_t.next_idx = 0; find_t.next_parent_idx = 0; find_t.next_sub_idx = 0; if (find_t.module != module) { reset_scroll_offsets (gscroll); gscroll->expanded = 0; } if (module == TOTAL_MODULES - 1) { find_t.module = 0; goto out; } } found: perform_find_dash_scroll (gscroll, module); out: regfree (®ex); return 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; } } }