void print_about(const int debuglvl) { int max_height = 0, max_width = 0, height = 0, width = 0, startx = 0, starty = 0; struct vrmr_list about_list; /* top menu */ char *key_choices[] = { "F10" }; int key_choices_n = 1; char *cmd_choices[] = { gettext("back") }; int cmd_choices_n = 1; char about_version_string[sizeof(version_string)]; /* create the about version string */ snprintf(about_version_string, sizeof(about_version_string), "Version: %s\n", version_string); /* get screensize */ getmaxyx(stdscr, max_height, max_width); width = 72; height = max_height - 8; startx = (max_width - width) / 2; starty = 4; vrmr_list_setup(debuglvl, &about_list, free_helpword); (void)read_helpline(debuglvl, &about_list, "Vuurmuur_conf\n"); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, "=============\n"); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, about_version_string); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, "Copyright 2003-2007 (c) Victor Julien <victor(at)vuurmuur(dot)org>.\n"); (void)read_helpline(debuglvl, &about_list, "This program is distributed under the terms of the GPL.\n"); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, "Support\n"); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, "=======\n"); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, "Website: http://www.vuurmuur.org/\n"); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, "Mailinglist: http://sourceforge.net/mail/?group_id=114382\n"); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, "Forum: http://sourceforge.net/forum/?group_id=114382\n"); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, "IRC: irc://irc.freenode.net/vuurmuur\n"); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, "Thanks to\n"); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, "=========\n"); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, "Philippe Baumgart (documentation).\n"); (void)read_helpline(debuglvl, &about_list, "Michiel Bodewes (website development).\n"); (void)read_helpline(debuglvl, &about_list, "Nicolas Dejardin <zephura(at)free(dot)fr> (French translation).\n"); (void)read_helpline(debuglvl, &about_list, "Adi Kriegisch (coding, documentation, Debian packages).\n"); (void)read_helpline(debuglvl, &about_list, "Sebastian Marten (documentation).\n"); (void)read_helpline(debuglvl, &about_list, "Holger Ohmacht (German translation).\n"); (void)read_helpline(debuglvl, &about_list, "Hugo Ribeiro (Brazilian Portuguese translation).\n"); (void)read_helpline(debuglvl, &about_list, "Aleksandr Shubnik <alshu(at)tut(dot)by> (rpm development, Russian translation).\n"); (void)read_helpline(debuglvl, &about_list, "Per Olav Siggerud (Norwegian translation).\n"); (void)read_helpline(debuglvl, &about_list, "Alexandre Simon (coding).\n"); (void)read_helpline(debuglvl, &about_list, "Stefan Ubbink (Gentoo ebuilds, coding).\n"); (void)read_helpline(debuglvl, &about_list, "Rob de Wit (wiki hosting).\n"); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, "See: http://www.vuurmuur.org/trac/wiki/Credits for the latest information.\n"); (void)read_helpline(debuglvl, &about_list, "\n"); set_lines(debuglvl, &about_list, (size_t)(width - 4)); draw_top_menu(debuglvl, top_win, gettext("About"), key_choices_n, key_choices, cmd_choices_n, cmd_choices); /* print the status list */ print_list(debuglvl, &about_list, gettext("About"), height, width, starty, startx, UTF8_FALSE); vrmr_list_cleanup(debuglvl, &about_list); }
/* Display the menu that allows the user to act on a connection. */ static void statevent_interactivemenu_log( const int debuglvl, struct vuurmuur_config *cnf, StatEventCtl *ctl, Conntrack *ct, VR_ConntrackRequest *connreqnull, Zones *zones, BlockList *blocklist, Interfaces *interfaces, Services *services, StatEventGen *gen_ptr) { VrWin *win = NULL; VrMenu *menu = NULL; int ch = 0; int menu_items = 10; char *str = NULL; const int width = 70; /* top menu */ char *key_choices[] = { "F12", "F10"}; int key_choices_n = 2; char *cmd_choices[] = { gettext("help"), gettext("back")}; int cmd_choices_n = 2; StatEventLog *log = (StatEventLog *)gen_ptr; Conntrack *ctr = NULL; VR_ConntrackRequest connreq; char *title = gettext("Manage Log"); /* number labels */ char *nums[9] = { "1", "2", "3", "4", "5", "6", "7", "8", NULL }; int n = 0; int action = 0; VrBusyWinShow(); /* init filter */ VR_connreq_setup(debuglvl, &connreq); connreq.group_conns = TRUE; connreq.unknown_ip_as_net = TRUE; /* sorting, relevant for grouping */ connreq.sort_in_out_fwd = FALSE; connreq.sort_conn_status = FALSE; /* drawing */ connreq.draw_acc_data = TRUE; connreq.draw_details = TRUE; /* get the connections for killing them later if the user chooses to */ ctr = conn_init_ct(debuglvl, zones, interfaces, services, blocklist); conn_ct_get_connections(debuglvl, cnf, ctr, &connreq); action = rules_actiontoi(log->action); if(action == AT_DROP || action == AT_REJECT) menu_items--; /* create the window and put it in the middle of the screen */ win = VrNewWin(menu_items + 2,width,0,0,vccnf.color_win); if(win == NULL) { (void)vrprint.error(-1, VR_ERR, "VrNewWin failed"); return; } VrWinSetTitle(win, title); menu = VrNewMenu(menu_items, width - 2, 1,1, menu_items,vccnf.color_win,vccnf.color_win); if(menu == NULL) { (void)vrprint.error(-1, VR_ERR, "VrNewMenu failed"); return; } VrMenuSetDescFreeFunc(menu, free); VrMenuSetupNameList(debuglvl, menu); VrMenuSetupDescList(debuglvl, menu); if(action != AT_DROP && action != AT_REJECT) { /* setup menu items */ str = VrGetString(gettext("Kill this connection")); VrMenuAddItem(debuglvl, menu, nums[n], str); n++; } str = VrGetString("--- %s ---", gettext("Kill options")); VrMenuAddSepItem(debuglvl, menu, str); str = VrGetString(gettext("Kill all connections with source %s"), log->src_ip); VrMenuAddItem(debuglvl, menu, nums[n++], str); str = VrGetString(gettext("Kill all connections with destination %s"), log->dst_ip); VrMenuAddItem(debuglvl, menu, nums[n++], str); str = VrGetString(gettext("Kill all connections of %s"), log->src_ip); VrMenuAddItem(debuglvl, menu, nums[n++], str); str = VrGetString(gettext("Kill all connections of %s"), log->dst_ip); VrMenuAddItem(debuglvl, menu, nums[n++], str); str = VrGetString("--- %s ---", gettext("BlockList options")); VrMenuAddSepItem(debuglvl, menu, str); str = VrGetString(gettext("Add source %s to BlockList"), log->src_ip); VrMenuAddItem(debuglvl, menu, nums[n++], str); str = VrGetString(gettext("Add destination %s to BlockList"), log->dst_ip); VrMenuAddItem(debuglvl, menu, nums[n++], str); str = VrGetString(gettext("Add both source and destination to BlockList")); VrMenuAddItem(debuglvl, menu, nums[n], str); /* n != n++ */ VrMenuConnectToWin(debuglvl, menu, win); VrMenuPost(debuglvl, menu); draw_top_menu(debuglvl, top_win, title, key_choices_n, key_choices, cmd_choices_n, cmd_choices); update_panels(); doupdate(); VrBusyWinHide(); /* user input */ char quit = FALSE; while(quit == FALSE) { ch = VrWinGetch(win); switch(ch) { case 27: case 'q': case 'Q': case KEY_F(10): quit = TRUE; break; case 10: { ITEM *cur = current_item(menu->m); if(cur != NULL) { int act = atoi((char *)item_name(cur)); switch(act) { case 1: /* kill */ { /* check if the conntrack tool is set */ if(conf.conntrack_location[0] == '\0') { (void)vrprint.error(-1, VR_ERR, STR_CONNTRACK_LOC_NOT_SET); } else { if(confirm(gettext("Kill connections"),gettext("Are you sure?"), vccnf.color_win_note, vccnf.color_win_note_rev|A_BOLD, 1) == 1) { kill_connections_by_ip(debuglvl, &conf, ctr, log->src_ip, log->dst_ip, log->ser, CONN_UNUSED); } } break; } case 2: /* kill all src ip */ /* check if the conntrack tool is set */ if(conf.conntrack_location[0] == '\0') { (void)vrprint.error(-1, VR_ERR, STR_CONNTRACK_LOC_NOT_SET); } else if(confirm(gettext("Kill connections"),gettext("Are you sure?"), vccnf.color_win_note, vccnf.color_win_note_rev|A_BOLD, 1) == 1) { kill_connections_by_ip(debuglvl, &conf, ctr, log->src_ip, NULL, NULL, CONN_UNUSED); } break; case 3: /* kill all dst ip */ /* check if the conntrack tool is set */ if(conf.conntrack_location[0] == '\0') { (void)vrprint.error(-1, VR_ERR, STR_CONNTRACK_LOC_NOT_SET); } else if(confirm(gettext("Kill connections"),gettext("Are you sure?"), vccnf.color_win_note, vccnf.color_win_note_rev|A_BOLD, 1) == 1) { kill_connections_by_ip(debuglvl, &conf, ctr, NULL, log->dst_ip, NULL, CONN_UNUSED); } break; case 4: /* check if the conntrack tool is set */ if(conf.conntrack_location[0] == '\0') { (void)vrprint.error(-1, VR_ERR, STR_CONNTRACK_LOC_NOT_SET); } else if(confirm(gettext("Kill connections"),gettext("Are you sure?"), vccnf.color_win_note, vccnf.color_win_note_rev|A_BOLD, 1) == 1) { kill_connections_by_ip(debuglvl, &conf, ctr, NULL, log->src_ip, NULL, CONN_UNUSED); kill_connections_by_ip(debuglvl, &conf, ctr, log->src_ip, NULL, NULL, CONN_UNUSED); } break; case 5: /* check if the conntrack tool is set */ if(conf.conntrack_location[0] == '\0') { (void)vrprint.error(-1, VR_ERR, STR_CONNTRACK_LOC_NOT_SET); } else if(confirm(gettext("Kill connections"),gettext("Are you sure?"), vccnf.color_win_note, vccnf.color_win_note_rev|A_BOLD, 1) == 1) { kill_connections_by_ip(debuglvl, &conf, ctr, NULL, log->dst_ip, NULL, CONN_UNUSED); kill_connections_by_ip(debuglvl, &conf, ctr, log->dst_ip, NULL, NULL, CONN_UNUSED); } break; case 6: if(confirm(gettext("Add to BlockList and Apply Changes"),gettext("Are you sure?"), vccnf.color_win_note, vccnf.color_win_note_rev|A_BOLD, 1) == 1) { block_and_kill(debuglvl, ctr, zones, blocklist, interfaces, log->src_ip); } break; case 7: if(confirm(gettext("Add to BlockList and Apply Changes"),gettext("Are you sure?"), vccnf.color_win_note, vccnf.color_win_note_rev|A_BOLD, 1) == 1) { block_and_kill(debuglvl, ctr, zones, blocklist, interfaces, log->dst_ip); } break; case 8: if(confirm(gettext("Add to BlockList and Apply Changes"),gettext("Are you sure?"), vccnf.color_win_note, vccnf.color_win_note_rev|A_BOLD, 1) == 1) { block_and_kill(debuglvl, ctr, zones, blocklist, interfaces, log->src_ip); block_and_kill(debuglvl, ctr, zones, blocklist, interfaces, log->dst_ip); } break; default: break; } } break; } case KEY_F(12): case 'h': case 'H': case '?': print_help(debuglvl, ctl->help_actions); break; default: (void)VrMenuDefaultNavigation(debuglvl, menu, ch); break; } } conn_ct_clear_connections(debuglvl, ctr); conn_free_ct(debuglvl, &ctr, zones); VrDelMenu(debuglvl, menu); VrDelWin(win); update_panels(); doupdate(); return; }
int statevent_menu(const int debuglvl, struct vuurmuur_config *cnf, int type, StatEventCtl *ctl, Conntrack *ct, VR_ConntrackRequest *connreq, Zones *zones, BlockList *blocklist, Interfaces *interfaces, Services *services) { VrWin *win = NULL; VrMenu *menu = NULL; int ch = 0; d_list_node *d_node = NULL; StatEventGen *gen_ptr = NULL; /* top menu */ char *key_choices[] = { "F12", "enter", "F10"}; int key_choices_n = 3; char *cmd_choices[] = { gettext("help"), ctl->options_str, gettext("back")}; int cmd_choices_n = 3; /* print a warning if we have no data */ if(ctl->list.len == 0) { (void)vrprint.warning(VR_WARN, ctl->warn_no_data_str); return(0); } win = VrNewWin(LINES - 6,COLS - 2,3,1,vccnf.color_win); if(win == NULL) { (void)vrprint.error(-1, VR_ERR, "VrNewWin failed"); return(-1); } VrWinSetTitle(win, ctl->title_str); draw_top_menu(debuglvl, top_win, ctl->title_str, key_choices_n, key_choices, cmd_choices_n, cmd_choices); menu = VrNewMenu(LINES - 8,COLS - 4,1,1,ctl->list.len, vccnf.color_win,vccnf.color_win_rev); if(menu == NULL) { (void)vrprint.error(-1, VR_ERR, "VrNewMenu failed"); return(-1); } VrMenuSetNameFreeFunc(menu, free); VrMenuSetDescFreeFunc(menu, free); VrMenuSetupNameList(debuglvl, menu); VrMenuSetupDescList(debuglvl, menu); unsigned int num = 1; for(d_node = ctl->list.top; d_node; d_node = d_node->next) { gen_ptr = d_node->data; if(debuglvl >= MEDIUM) (void)vrprint.debug(__FUNC__, "gen_ptr->filtered %d", gen_ptr->filtered); if(gen_ptr->filtered == 0) { char *desc_str = NULL; char *name_str = NULL; char strtmp[512] = ""; size_t name_len = 0, desc_len = 0; if(ctl->list.len <= 9) snprintf(strtmp, sizeof(strtmp), "%u", num); else if(ctl->list.len <= 99) snprintf(strtmp, sizeof(strtmp), "%2u", num); else if(ctl->list.len <= 999) snprintf(strtmp, sizeof(strtmp), "%3u", num); else if(ctl->list.len <= 9999) snprintf(strtmp, sizeof(strtmp), "%4u", num); else if(ctl->list.len <= 99999) snprintf(strtmp, sizeof(strtmp), "%5u", num); else if(ctl->list.len <= 999999) snprintf(strtmp, sizeof(strtmp), "%6u", num); else snprintf(strtmp, sizeof(strtmp), "%10u", num); name_len = strlen(strtmp) + 1; name_str = malloc(name_len); strlcpy(name_str, strtmp, name_len); /* get the str that will form the desc */ desc_len = win->width - 2 - name_len; desc_str = ctl->print2str(debuglvl, gen_ptr, desc_len); num++; /* add the item to the menu */ VrMenuAddItem(debuglvl, menu, name_str, desc_str); } } /* check if we didn't add any item (if all was filtered) */ if(num == 1) { (void)vrprint.warning(VR_WARN, ctl->warn_no_data_str); VrDelMenu(debuglvl, menu); VrDelWin(win); update_panels(); doupdate(); return(0); } VrMenuConnectToWin(debuglvl, menu, win); VrMenuPost(debuglvl, menu); VrBusyWinHide(); update_panels(); doupdate(); /* user input */ char quit = FALSE; while(quit == FALSE) { ch = VrWinGetch(win); switch(ch) { case 27: case 'q': case 'Q': case KEY_F(10): quit = TRUE; break; case 10: { ITEM *cur = current_item(menu->m); if(cur != NULL) { int i = atoi((char *)item_name(cur)); unsigned int u = 1; gen_ptr = NULL; /* get the current event: handle * filtered events as well */ for(d_node = ctl->list.top; d_node; d_node = d_node->next, u++) { gen_ptr = d_node->data; if(!gen_ptr->filtered) { if(u == (unsigned int)i) break; } else { u--; } gen_ptr = NULL; } if(gen_ptr == NULL) { // error return(-1); } else { /* call the interactive menu function */ ctl->menu(debuglvl, cnf, ctl, ct, connreq, zones, blocklist, interfaces, services, gen_ptr); /* when done, restore the title and options */ draw_top_menu(debuglvl, top_win, ctl->title_str, key_choices_n, key_choices, cmd_choices_n, cmd_choices); } } break; } case KEY_F(12): case 'h': case 'H': case '?': print_help(debuglvl, ctl->help_overview); break; default: (void)VrMenuDefaultNavigation(debuglvl, menu, ch); break; } } VrDelMenu(debuglvl, menu); VrDelWin(win); update_panels(); doupdate(); return(0); }
/* Display the menu that allows the user to act on a connection. */ static void statevent_interactivemenu_conn( const int debuglvl, struct vuurmuur_config *cnf, StatEventCtl *ctl, Conntrack *ct, VR_ConntrackRequest *connreq, Zones *zones, BlockList *blocklist, Interfaces *interfaces, Services *services, StatEventGen *gen_ptr) { VrWin *win = NULL; VrMenu *menu = NULL; int ch = 0; int menu_items = 10; char *str = NULL; const int width = 70; /* top menu */ char *key_choices[] = { "F12", "F10"}; int key_choices_n = 2; char *cmd_choices[] = { gettext("help"), gettext("back")}; int cmd_choices_n = 2; StatEventConn *con = (StatEventConn *)gen_ptr; Conntrack *privct = NULL; char ungroup_conns = FALSE; char *title = gettext("Manage Connection"); /* if needed get our own private ungrouped ct */ if(connreq->group_conns == TRUE) { ungroup_conns = TRUE; /* we are ungrouping the list */ connreq->group_conns = FALSE; privct = conn_init_ct(debuglvl, zones, interfaces, services, blocklist); if(privct == NULL) return; conn_ct_get_connections(debuglvl, cnf, privct, connreq); ct = privct; } /* create the window and put it in the middle of the screen */ win = VrNewWin(menu_items + 2,width,0,0,vccnf.color_win); if(win == NULL) { (void)vrprint.error(-1, VR_ERR, "VrNewWin failed"); return; } VrWinSetTitle(win, title); menu = VrNewMenu(menu_items, width - 2, 1,1, menu_items,vccnf.color_win,vccnf.color_win_rev); if(menu == NULL) { (void)vrprint.error(-1, VR_ERR, "VrNewMenu failed"); return; } VrMenuSetDescFreeFunc(menu, free); VrMenuSetupNameList(debuglvl, menu); VrMenuSetupDescList(debuglvl, menu); /* setup menu items */ if(con->cnt == 1) str = VrGetString(gettext("Kill this connection")); else str = VrGetString(gettext("Kill all connections with this service/source/destination"),con->cnt); VrMenuAddItem(debuglvl, menu, "1", str); str = VrGetString("--- %s ---", gettext("Kill options")); VrMenuAddSepItem(debuglvl, menu, str); str = VrGetString(gettext("Kill all connections with source %s"), con->src_ip); VrMenuAddItem(debuglvl, menu, "2", str); str = VrGetString(gettext("Kill all connections with destination %s"), con->dst_ip); VrMenuAddItem(debuglvl, menu, "3", str); str = VrGetString(gettext("Kill all connections of %s"), con->src_ip); VrMenuAddItem(debuglvl, menu, "4", str); str = VrGetString(gettext("Kill all connections of %s"), con->dst_ip); VrMenuAddItem(debuglvl, menu, "5", str); str = VrGetString("--- %s ---", gettext("BlockList options")); VrMenuAddSepItem(debuglvl, menu, str); str = VrGetString(gettext("Add source %s to BlockList"), con->src_ip); VrMenuAddItem(debuglvl, menu, "6", str); str = VrGetString(gettext("Add destination %s to BlockList"), con->dst_ip); VrMenuAddItem(debuglvl, menu, "7", str); str = VrGetString(gettext("Add both source and destination to BlockList")); VrMenuAddItem(debuglvl, menu, "8", str); VrMenuConnectToWin(debuglvl, menu, win); VrMenuPost(debuglvl, menu); draw_top_menu(debuglvl, top_win, title, key_choices_n, key_choices, cmd_choices_n, cmd_choices); update_panels(); doupdate(); /* user input */ char quit = FALSE; while(quit == FALSE) { ch = VrWinGetch(win); switch(ch) { case 27: case 'q': case 'Q': case KEY_F(10): quit = TRUE; break; case 10: { ITEM *cur = current_item(menu->m); if(cur != NULL) { int act = atoi((char *)item_name(cur)); switch(act) { case 1: /* kill */ { /* check if the conntrack tool is set */ if(conf.conntrack_location[0] == '\0') { (void)vrprint.error(-1, VR_ERR, STR_CONNTRACK_LOC_NOT_SET); } else if(con->cnt == 1) { if(confirm(gettext("Kill connection"),gettext("Are you sure?"), vccnf.color_win_note, vccnf.color_win_note_rev|A_BOLD, 1) == 1) { kill_connection(debuglvl, conf.conntrack_location, con->src_ip, con->dst_ip, con->protocol, con->src_port, con->dst_port); } } else { vrprint.debug(__FUNC__, "cnt %u, src %s srcip %s dst %s dstip %s ser %s", con->cnt, con->src, con->src_ip, con->dst, con->dst_ip, con->ser); if(confirm(gettext("Kill connections"),gettext("Are you sure?"), vccnf.color_win_note, vccnf.color_win_note_rev|A_BOLD, 1) == 1) { kill_connections(debuglvl, &conf, connreq, ct, con); } } break; } case 2: /* kill all src ip */ /* check if the conntrack tool is set */ if(conf.conntrack_location[0] == '\0') { (void)vrprint.error(-1, VR_ERR, STR_CONNTRACK_LOC_NOT_SET); } else if(confirm(gettext("Kill connections"),gettext("Are you sure?"), vccnf.color_win_note, vccnf.color_win_note_rev|A_BOLD, 1) == 1) { kill_connections_by_ip(debuglvl, &conf, ct, con->src_ip, NULL, NULL, CONN_UNUSED); } break; case 3: /* kill all dst ip */ /* check if the conntrack tool is set */ if(conf.conntrack_location[0] == '\0') { (void)vrprint.error(-1, VR_ERR, STR_CONNTRACK_LOC_NOT_SET); } else if(confirm(gettext("Kill connections"),gettext("Are you sure?"), vccnf.color_win_note, vccnf.color_win_note_rev|A_BOLD, 1) == 1) { kill_connections_by_ip(debuglvl, &conf, ct, NULL, con->dst_ip, NULL, CONN_UNUSED); } break; case 4: /* check if the conntrack tool is set */ if(conf.conntrack_location[0] == '\0') { (void)vrprint.error(-1, VR_ERR, STR_CONNTRACK_LOC_NOT_SET); } else if(confirm(gettext("Kill connections"),gettext("Are you sure?"), vccnf.color_win_note, vccnf.color_win_note_rev|A_BOLD, 1) == 1) { kill_connections_by_ip(debuglvl, &conf, ct, NULL, con->src_ip, NULL, CONN_UNUSED); kill_connections_by_ip(debuglvl, &conf, ct, con->src_ip, NULL, NULL, CONN_UNUSED); } break; case 5: /* check if the conntrack tool is set */ if(conf.conntrack_location[0] == '\0') { (void)vrprint.error(-1, VR_ERR, STR_CONNTRACK_LOC_NOT_SET); } else if(confirm(gettext("Kill connections"),gettext("Are you sure?"), vccnf.color_win_note, vccnf.color_win_note_rev|A_BOLD, 1) == 1) { kill_connections_by_ip(debuglvl, &conf, ct, NULL, con->dst_ip, NULL, CONN_UNUSED); kill_connections_by_ip(debuglvl, &conf, ct, con->dst_ip, NULL, NULL, CONN_UNUSED); } break; case 6: if(confirm(gettext("Add to BlockList and Apply Changes"),gettext("Are you sure?"), vccnf.color_win_note, vccnf.color_win_note_rev|A_BOLD, 1) == 1) { block_and_kill(debuglvl, ct, zones, blocklist, interfaces, con->src_ip); } break; case 7: if(confirm(gettext("Add to BlockList and Apply Changes"),gettext("Are you sure?"), vccnf.color_win_note, vccnf.color_win_note_rev|A_BOLD, 1) == 1) { block_and_kill(debuglvl, ct, zones, blocklist, interfaces, con->dst_ip); } break; case 8: if(confirm(gettext("Add to BlockList and Apply Changes"),gettext("Are you sure?"), vccnf.color_win_note, vccnf.color_win_note_rev|A_BOLD, 1) == 1) { block_and_kill(debuglvl, ct, zones, blocklist, interfaces, con->src_ip); block_and_kill(debuglvl, ct, zones, blocklist, interfaces, con->dst_ip); } break; default: break; } } break; } case KEY_F(12): case 'h': case 'H': case '?': print_help(debuglvl, ctl->help_actions); break; default: (void)VrMenuDefaultNavigation(debuglvl, menu, ch); break; } } VrDelMenu(debuglvl, menu); VrDelWin(win); update_panels(); doupdate(); /* we have ungrouped the list, clean up here. */ if(ungroup_conns == TRUE) { connreq->group_conns = TRUE; conn_ct_clear_connections(debuglvl, privct); conn_free_ct(debuglvl, &privct, NULL); } return; }
/* trafvol_section This section shows bandwidth usage of the system. Returncodes: 0: ok -1: error */ int trafvol_section(const int debuglvl, Zones *zones, Interfaces *interfaces, Services *services) { int retval = 0; int quit = 0, ch; int max_onscreen = 0, max_height = 0, max_width = 0; unsigned int i = 0; unsigned int ifac_num = 0; struct InterfaceData_ *iface_ptr=NULL; d_list_node *d_node = NULL, *bw_d_node = NULL; struct TrafVol_ *bw_ptr = NULL; d_list bw_list; int year = 0, month = 0; time_t cur_time, yesterday_time, lastweek_time; struct tm cur_tm, yesterday_tm, lastweek_tm; char bw_str[6] = ""; int result=0; int update_interval = 10000000; /* weird, in pratice this seems to be twenty sec */ int slept_so_far = 10000000; /* time slept since last update */ /* top menu */ char *key_choices[] = { "F12", "F10"}; int key_choices_n = 2; char *cmd_choices[] = { gettext("help"), gettext("back")}; int cmd_choices_n = 2; if(interfaces->list.len == 0) { (void)vrprint.warning(VR_WARN, gettext("no interfaces found. Please define an interface first.")); return(0); } if(strcmp(vccnf.iptrafvol_location, "") == 0) { (void)vrprint.error(-1, VR_ERR, gettext("please set the location of the iptrafvol.pl command in the Settings.")); return(-1); } getmaxyx(stdscr, max_height, max_width); max_onscreen = max_height - 6 - 6; /* count the number of non virtual interfaces */ for(ifac_num = 0, d_node = interfaces->list.top; d_node; d_node = d_node->next) { if(!(iface_ptr = d_node->data)) { (void)vrprint.error(-1, VR_INTERR, "NULL pointer (in: %s:%d).", __FUNC__, __LINE__); return(-1); } if(iface_ptr->device_virtual == FALSE) { ifac_num++; } } if(ifac_num > (unsigned int)max_onscreen) ifac_num = (unsigned int)max_onscreen; /* init */ if(trafvol_section_init(debuglvl, max_height - 6, 78, 3, 1, ifac_num) < 0) return(-1); /* make sure wgetch doesn't block */ nodelay(TrafVolSection.win, TRUE); keypad(TrafVolSection.win, TRUE); draw_top_menu(debuglvl, top_win, gettext("Traffic Volume"), key_choices_n, key_choices, cmd_choices_n, cmd_choices); update_panels(); doupdate(); /* the main loop */ while(quit == 0 && retval == 0) { if(debuglvl >= LOW) (void)vrprint.debug(__FUNC__, "slept_so_far: %d, update_interval: %d.", slept_so_far, update_interval); /* check if we have slept long enough */ if(slept_so_far >= update_interval) { if(debuglvl >= HIGH) (void)vrprint.debug(__FUNC__, "slept_so_far: %d -> now print.", slept_so_far); slept_so_far = 0; /* get the time */ cur_time = time(NULL); if(cur_time == -1) { (void)vrprint.error(-1, VR_INTERR, "getting current time failed (in: %s:%d).", __FUNC__, __LINE__); return(-1); } yesterday_time = cur_time - 86400; lastweek_time = cur_time - (86400 * 7); if(localtime_r(&cur_time, &cur_tm) == NULL) { (void)vrprint.error(-1, VR_INTERR, "converting current time failed (in: %s:%d).", __FUNC__, __LINE__); return(-1); } if(localtime_r(&yesterday_time, &yesterday_tm) == NULL) { (void)vrprint.error(-1, VR_INTERR, "converting yesterday's time failed (in: %s:%d).", __FUNC__, __LINE__); return(-1); } if(localtime_r(&lastweek_time, &lastweek_tm) == NULL) { (void)vrprint.error(-1, VR_INTERR, "converting lastweeks's time failed (in: %s:%d).", __FUNC__, __LINE__); return(-1); } /* update data here */ for(d_node = interfaces->list.top, i = 0; d_node && i < ifac_num; d_node = d_node->next) { if(!(iface_ptr = d_node->data)) { (void)vrprint.error(-1, VR_INTERR, "NULL pointer (in: %s:%d).", __FUNC__, __LINE__); return(-1); } if(iface_ptr->device_virtual == FALSE) { /* interface name */ set_field_buffer_wrap(debuglvl, TrafVolSection.fields[11 * i], 0, iface_ptr->name); /* get the bw for today */ result = bandwidth_get_iface(debuglvl, iface_ptr->device, cur_tm.tm_year + 1900, cur_tm.tm_mon + 1, cur_tm.tm_mday, 1, 1, &bw_list); if(result == 1) { for(bw_d_node = bw_list.top; bw_d_node; bw_d_node = bw_d_node->next) { if(!(bw_ptr = bw_d_node->data)) { (void)vrprint.error(-1, VR_INTERR, "NULL pointer (in: %s:%d).", __FUNC__, __LINE__); return(-1); } //printf("%2d/%2d/%4d: in: %u, out: %u %s\n", bw_ptr->day, bw_ptr->month, bw_ptr->year, bw_ptr->recv_mb, bw_ptr->send_mb, bw_ptr->total ? "(total)" : ""); create_bw_string(debuglvl, bw_ptr->recv_mb, bw_str, sizeof(bw_str)); set_field_buffer_wrap(debuglvl, TrafVolSection.fields[1 + (11 * i)], 0, bw_str); create_bw_string(debuglvl, bw_ptr->send_mb, bw_str, sizeof(bw_str)); set_field_buffer_wrap(debuglvl, TrafVolSection.fields[2 + (11 * i)], 0, bw_str); } d_list_cleanup(debuglvl, &bw_list); } else if(result == 0) { set_field_buffer_wrap(debuglvl, TrafVolSection.fields[1 + (11 * i)], 0, " - "); set_field_buffer_wrap(debuglvl, TrafVolSection.fields[2 + (11 * i)], 0, " - "); } else { set_field_buffer_wrap(debuglvl, TrafVolSection.fields[1 + (11 * i)], 0, gettext("error")); set_field_buffer_wrap(debuglvl, TrafVolSection.fields[2 + (11 * i)], 0, gettext("error")); } /* get the bw for yesterday */ result = bandwidth_get_iface(debuglvl, iface_ptr->device, yesterday_tm.tm_year + 1900, yesterday_tm.tm_mon + 1, yesterday_tm.tm_mday, 1, 1, &bw_list); if(result == 1) { for(bw_d_node = bw_list.top; bw_d_node; bw_d_node = bw_d_node->next) { if(!(bw_ptr = bw_d_node->data)) { (void)vrprint.error(-1, VR_INTERR, "NULL pointer (in: %s:%d).", __FUNC__, __LINE__); return(-1); } //printf("%2d/%2d/%4d: in: %u, out: %u %s\n", bw_ptr->day, bw_ptr->month, bw_ptr->year, bw_ptr->recv_mb, bw_ptr->send_mb, bw_ptr->total ? "(total)" : ""); create_bw_string(debuglvl, bw_ptr->recv_mb, bw_str, sizeof(bw_str)); set_field_buffer_wrap(debuglvl, TrafVolSection.fields[3 + (11 * i)], 0, bw_str); create_bw_string(debuglvl, bw_ptr->send_mb, bw_str, sizeof(bw_str)); set_field_buffer_wrap(debuglvl, TrafVolSection.fields[4 + (11 * i)], 0, bw_str); } d_list_cleanup(debuglvl, &bw_list); } else if(result == 0) { set_field_buffer_wrap(debuglvl, TrafVolSection.fields[3 + (11 * i)], 0, " - "); set_field_buffer_wrap(debuglvl, TrafVolSection.fields[4 + (11 * i)], 0, " - "); } else { set_field_buffer_wrap(debuglvl, TrafVolSection.fields[3 + (11 * i)], 0, gettext("error")); set_field_buffer_wrap(debuglvl, TrafVolSection.fields[4 + (11 * i)], 0, gettext("error")); } /* get the bw for past 7 days */ result = bandwidth_get_iface(debuglvl, iface_ptr->device, lastweek_tm.tm_year + 1900, lastweek_tm.tm_mon + 1, lastweek_tm.tm_mday, 7, 1, &bw_list); if(result == 1) { for(bw_d_node = bw_list.top; bw_d_node; bw_d_node = bw_d_node->next) { if(!(bw_ptr = bw_d_node->data)) { (void)vrprint.error(-1, VR_INTERR, "NULL pointer (in: %s:%d).", __FUNC__, __LINE__); return(-1); } //printf("%2d/%2d/%4d: in: %u, out: %u %s\n", bw_ptr->day, bw_ptr->month, bw_ptr->year, bw_ptr->recv_mb, bw_ptr->send_mb, bw_ptr->total ? "(total)" : ""); create_bw_string(debuglvl, bw_ptr->recv_mb, bw_str, sizeof(bw_str)); set_field_buffer_wrap(debuglvl, TrafVolSection.fields[5 + (11 * i)], 0, bw_str); create_bw_string(debuglvl, bw_ptr->send_mb, bw_str, sizeof(bw_str)); set_field_buffer_wrap(debuglvl, TrafVolSection.fields[6 + (11 * i)], 0, bw_str); } d_list_cleanup(debuglvl, &bw_list); } else if(result == 0) { set_field_buffer_wrap(debuglvl, TrafVolSection.fields[5 + (11 * i)], 0, " - "); set_field_buffer_wrap(debuglvl, TrafVolSection.fields[6 + (11 * i)], 0, " - "); } else { set_field_buffer_wrap(debuglvl, TrafVolSection.fields[5 + (11 * i)], 0, gettext("error")); set_field_buffer_wrap(debuglvl, TrafVolSection.fields[6 + (11 * i)], 0, gettext("error")); } /* get the bw for the current month */ result = bandwidth_get_iface(debuglvl, iface_ptr->device, cur_tm.tm_year + 1900, cur_tm.tm_mon + 1, 1, 0, 1, &bw_list); if(result == 1) { for(bw_d_node = bw_list.top; bw_d_node; bw_d_node = bw_d_node->next) { if(!(bw_ptr = bw_d_node->data)) { (void)vrprint.error(-1, VR_INTERR, "NULL pointer (in: %s:%d).", __FUNC__, __LINE__); return(-1); } //printf("%2d/%2d/%4d: in: %u, out: %u %s\n", bw_ptr->day, bw_ptr->month, bw_ptr->year, bw_ptr->recv_mb, bw_ptr->send_mb, bw_ptr->total ? "(total)" : ""); create_bw_string(debuglvl, bw_ptr->recv_mb, bw_str, sizeof(bw_str)); set_field_buffer_wrap(debuglvl, TrafVolSection.fields[7 + (11 * i)], 0, bw_str); create_bw_string(debuglvl, bw_ptr->send_mb, bw_str, sizeof(bw_str)); set_field_buffer_wrap(debuglvl, TrafVolSection.fields[8 + (11 * i)], 0, bw_str); } d_list_cleanup(debuglvl, &bw_list); } else if(result == 0) { set_field_buffer_wrap(debuglvl, TrafVolSection.fields[7 + (11 * i)], 0, " - "); set_field_buffer_wrap(debuglvl, TrafVolSection.fields[8 + (11 * i)], 0, " - "); } else { set_field_buffer_wrap(debuglvl, TrafVolSection.fields[7 + (11 * i)], 0, gettext("error")); set_field_buffer_wrap(debuglvl, TrafVolSection.fields[8 + (11 * i)], 0, gettext("error")); } /* get the bw for the last month */ year = cur_tm.tm_year + 1900; /* get prev month (by not adding +1) */ month = cur_tm.tm_mon; /* if month = 0 (Jan), set it to 12 (Dec) and subtract one of the year. */ if(month == 0) { month = 12; year = year - 1; } result = bandwidth_get_iface(debuglvl, iface_ptr->device, year, month, 1, 0, 1, &bw_list); if(result == 1) { for(bw_d_node = bw_list.top; bw_d_node; bw_d_node = bw_d_node->next) { if(!(bw_ptr = bw_d_node->data)) { (void)vrprint.error(-1, VR_INTERR, "NULL pointer (in: %s:%d).", __FUNC__, __LINE__); return(-1); } //printf("%2d/%2d/%4d: in: %u, out: %u %s\n", bw_ptr->day, bw_ptr->month, bw_ptr->year, bw_ptr->recv_mb, bw_ptr->send_mb, bw_ptr->total ? "(total)" : ""); create_bw_string(debuglvl, bw_ptr->recv_mb, bw_str, sizeof(bw_str)); set_field_buffer_wrap(debuglvl, TrafVolSection.fields[9 + (11 * i)], 0, bw_str); create_bw_string(debuglvl, bw_ptr->send_mb, bw_str, sizeof(bw_str)); set_field_buffer_wrap(debuglvl, TrafVolSection.fields[10 + (11 * i)], 0, bw_str); } d_list_cleanup(debuglvl, &bw_list); } else if(result == 0) { set_field_buffer_wrap(debuglvl, TrafVolSection.fields[9 + (11 * i)], 0, " - "); set_field_buffer_wrap(debuglvl, TrafVolSection.fields[10 + (11 * i)], 0, " - "); } else { set_field_buffer_wrap(debuglvl, TrafVolSection.fields[9 + (11 * i)], 0, gettext("error")); set_field_buffer_wrap(debuglvl, TrafVolSection.fields[10 + (11 * i)], 0, gettext("error")); } /* finally draw the screen */ wrefresh(TrafVolSection.win); /* update the line */ i++; } } } /* finally draw the screen */ wrefresh(TrafVolSection.win); /* process the keyboard input */ ch = wgetch(TrafVolSection.win); switch(ch) { /* quit */ case 27: case 'q': case 'Q': case KEY_F(10): quit = 1; break; case KEY_F(12): case 'h': case 'H': case '?': print_help(debuglvl, ":[VUURMUUR:TRAFVOL]:"); break; } if(quit == 0) { usleep(10000); slept_so_far = slept_so_far + 10000; if(debuglvl >= HIGH) (void)vrprint.debug(__FUNC__, "just slept: slept_so_far '%d'.", slept_so_far); } } /* EXIT: cleanup */ nodelay(TrafVolSection.win, FALSE); /* destroy the window and form */ trafvol_section_destroy(); update_panels(); doupdate(); return(retval); }