void eingabe_hinzuf_anzeigen(void) { char vname[25], nname[25], tag[3], monat[3], jahr[5]; curs_set(1); wclear(seingabe); mvwaddstr(seingabe, 2, 2, "* Eintrag hinzufügen"); mvwaddstr(seingabe, 2+2, 2, "+ Vorname: "); wrefresh(seingabe); wgetnstr(seingabe, vname, 24); mvwaddstr(seingabe, 2+3, 2, "+ Nachname: "); wrefresh(seingabe); wgetnstr(seingabe, nname, 24); mvwaddstr(seingabe, 2+4, 2, "+ Datum: - - "); mvwgetnstr(seingabe, 2+4, 11, tag, 2); mvwgetnstr(seingabe, 2+4, 14, monat, 2); mvwgetnstr(seingabe, 2+4, 17, jahr, 4); if (strlen(vname) > 0 && strlen(nname) > 0 && strlen(tag) > 0 && strlen(monat) > 0 && strlen(jahr) > 0) { strcpy(aenderungs_eintrag.vname, vname); strcpy(aenderungs_eintrag.nname, nname); aenderungs_eintrag.sdatum.tag = atoi(tag); aenderungs_eintrag.sdatum.monat = atoi(monat); aenderungs_eintrag.sdatum.jahr = atoi(jahr); } curs_set(0); }
int channel_input(WINDOW *win, int c) { char buf[6]; int x; switch (c) { case 'a': case 'A': conf.do_change_channel = conf.do_change_channel ? 0 : 1; break; case 'd': case 'D': echo(); curs_set(1); mvwgetnstr(win, 3, 25, buf, 6); curs_set(0); noecho(); sscanf(buf, "%d", &x); conf.channel_time = x*1000; break; case 'u': case 'U': echo(); curs_set(1); mvwgetnstr(win, 4, 26, buf, 6); curs_set(0); noecho(); sscanf(buf, "%d", &x); conf.channel_max = x; break; case 'm': case 'M': conf.do_change_channel = 0; echo(); curs_set(1); mvwgetnstr(win, 6, 30, buf, 2); curs_set(0); noecho(); sscanf(buf, "%d", &x); x = channel_find_index_from_chan(x); if (x >= 0) { if (!conf.serveraddr) channel_change(x); else conf.channel_idx = x; } break; default: return 0; /* didn't handle input */ } net_send_channel_config(); update_channel_win(win); return 1; }
void display_input_add_event(int is_single) { char text[PHRASES_CHARS_LENGTH], day[3], month[3], year[5], hour[3], minute[3], repeat_cycle[5]; curs_set(1); wclear(wsinput); if (is_single == 1) { mvwaddstr(wsinput, 0, 0, "* "); waddstr(wsinput, phrases_data.input_single_event); } else { mvwaddstr(wsinput, 0, 0, "* "); waddstr(wsinput, phrases_data.input_repeating_event); } mvwaddstr(wsinput, 2, 0, "+ "); waddstr(wsinput, phrases_data.input_text); waddstr(wsinput, ": "); wrefresh(wsinput); wgetnstr(wsinput, text, PHRASES_CHARS_LENGTH-1); mvwaddstr(wsinput, 4, 0, "+ "); waddstr(wsinput, phrases_data.input_date); waddstr(wsinput, ": - - "); mvwgetnstr(wsinput, 4, strlen(phrases_data.input_date)+4, day, 2); mvwgetnstr(wsinput, 4, strlen(phrases_data.input_date)+7, month, 2); mvwgetnstr(wsinput, 4, strlen(phrases_data.input_date)+10, year, 4); mvwaddstr(wsinput, 5, 0, "+ "); waddstr(wsinput, phrases_data.input_time); waddstr(wsinput, ": - "); mvwgetnstr(wsinput, 5, strlen(phrases_data.input_time)+4, hour, 2); mvwgetnstr(wsinput, 5, strlen(phrases_data.input_time)+7, minute, 2); if (is_single == 0) { mvwaddstr(wsinput, 7, 0, "+ "); waddstr(wsinput, phrases_data.input_repeat_cycle); waddstr(wsinput, ": "); wgetnstr(wsinput, repeat_cycle, 4); } if (strlen(text) > 0 && strlen(day) > 0 && strlen(month) > 0 && strlen(year) > 0) { strcpy(entry_to_change.text, text); entry_to_change.date.day = atoi(day); entry_to_change.date.month = atoi(month); entry_to_change.date.year = atoi(year); entry_to_change.time.hour = atoi(hour); entry_to_change.time.minute = atoi(minute); entry_to_change.is_birthday = 0; entry_to_change.repeat_cycle = atoi(repeat_cycle); } curs_set(0); }
int32_t get_num (NOTUSED AppData * a) { WINDOW *menu_win, *menu_sub; int maxx; const int BUFSZ = 32; char buf[BUFSZ]; maxx = getmaxx (stdscr); menu_win = newwin (5, maxx - 1, 0, 1); menu_sub = derwin (menu_win, 1, maxx - 1 - 2, 3, 1); mvwprintw (menu_win, 1, 2, "%s", "Enter a number, please"); box (menu_win, 0, 0); wrefresh (menu_win); nl (); nodelay (menu_sub, FALSE); echo (); nocbreak (); keypad (menu_sub, FALSE); mvwgetnstr (menu_sub, 0, 0, buf, BUFSZ); buf[BUFSZ - 1] = '\0'; nonl (); noecho (); raw (); keypad (menu_sub, TRUE); return atoi (buf); }
std::string StringBox(WINDOW* parent, string title, string message, int maxLength) { int nColumns = (message.size() > maxLength ? message.size() : maxLength) + 4; int nLines = maxLength / MAX_MESSAGEBOX_COLS + 6; WINDOW* stringBox = 0; WINDOW* textArea = 0; std::string result; if (nColumns < MIN_MESSAGEBOX_COLS) nColumns = MIN_MESSAGEBOX_COLS; else if (nColumns > MAX_MESSAGEBOX_COLS) nColumns = MAX_MESSAGEBOX_COLS; stringBox = subwin(parent, nLines, nColumns, (LINES - nLines)/2, (COLS - nColumns)/2); if (stringBox == 0) { Log::getInstance().write("Failed to intialize stringBox window."); return result; } textArea = subwin(stringBox, nLines - 4, nColumns - 4, (LINES - nLines)/2 + 4, (COLS - nColumns)/2 + 2); if (textArea == 0) { delwin(stringBox); Log::getInstance().write("Failed to intialize textArea window."); return result; } wclear(parent); wbkgd(stringBox, COLOR_PAIR(ColorPairManager::getInstance().getColorPair(COLOR_WHITE, COLOR_BLUE))); wborder(stringBox, 0, 0, 0, 0, 0, 0, 0, 0); mvwaddstr(stringBox, 0, 5, title.c_str()); mvwaddstr(stringBox, 2, (nColumns - message.size())/2, message.c_str()); echo(); char buffer[maxLength + 1]; wrefresh(stringBox); mvwgetnstr(textArea, 0, 0, buffer, maxLength); noecho(); result = buffer; wclear(parent); wrefresh(parent); delwin(textArea); delwin(stringBox); return result; }
void get_string(WINDOW *my_win){ memset(&input, 0, sizeof(input)); mvwgetnstr(my_win, 0, 7, input, sizeof(input)-1); // The -1 insures a null. // mvwscanw(my_win, 0, 7, "%25c", &input); wdeleteln(my_win); mvwprintw(my_win, 0, 0, "Input: "); update_panels(); doupdate(); }
void window_error(void) { WINDOW *win; int x,y; initscr(); /* init ncurses mode */ start_color(); init_pair(1, COLOR_BLACK, COLOR_WHITE); init_pair(2, COLOR_YELLOW, COLOR_BLUE); init_pair(3, COLOR_YELLOW, COLOR_RED); getmaxyx(stdscr, y, x); y = (y - 8) / 2.0; x = (x - 27) / 2.0; win = newwin(8, 27, y, x); wbkgd(win, COLOR_PAIR(3)); box(win, 0, 0); // wbkgdset(win, COLOR_PAIR(1)); mvwprintw(win, 2, 6, "!!!! ERROR !!!!"); mvwprintw(win, 4, 6, "Enter For Quit."); wrefresh(win); #if 0 mvwprintw(win, 2, 2, "User:"******"Pass:"******" "); mvwprintw(win, 4, 8, " "); wrefresh(win); mvwgetnstr(win, 2, 8, buff->pwd_name, USERNAME_LEN); noecho(); mvwgetnstr(win, 4, 8, buff->pwd_passwd, PASSWORD_LEN); overwrite(win, stdscr); echo(); #endif getchar(); delwin(win); touchwin(stdscr); endwin(); /* leave ncurses mode */ }
void display_input_add_birthday_event(void) { char first_name[PHRASES_CHARS_LENGTH/2], last_name[128], day[3], month[3], year[5]; curs_set(1); wclear(wsinput); mvwaddstr(wsinput, 0, 0, "* "); waddstr(wsinput, phrases_data.input_birthday_event); mvwaddstr(wsinput, 2, 0, "+ "); waddstr(wsinput, phrases_data.input_first_name); waddstr(wsinput, ": "); wrefresh(wsinput); wgetnstr(wsinput, first_name, 127); mvwaddstr(wsinput, 4, 0, "+ "); waddstr(wsinput, phrases_data.input_last_name); waddstr(wsinput, ": "); wrefresh(wsinput); wgetnstr(wsinput, last_name, 127); mvwaddstr(wsinput, 6, 0, "+ "); waddstr(wsinput, phrases_data.input_date); waddstr(wsinput, ": - - "); mvwgetnstr(wsinput, 6, strlen(phrases_data.input_date)+4, day, 2); mvwgetnstr(wsinput, 6, strlen(phrases_data.input_date)+7, month, 2); mvwgetnstr(wsinput, 6, strlen(phrases_data.input_date)+10, year, 4); if (strlen(first_name) > 0 && strlen(last_name) > 0 && strlen(day) > 0 && strlen(month) > 0 && strlen(year) > 0) { strcpy(entry_to_change.text, first_name); strcat(entry_to_change.text, " "); strcat(entry_to_change.text, last_name); entry_to_change.date.day = atoi(day); entry_to_change.date.month = atoi(month); entry_to_change.date.year = atoi(year); entry_to_change.time.hour = 0; entry_to_change.time.minute = 0; entry_to_change.is_birthday = 1; entry_to_change.repeat_cycle = 0; } curs_set(0); }
void window_login(WindowPasswd_t *buff) { WINDOW *win; int x,y; initscr(); /* init ncurses mode */ start_color(); init_pair(1, COLOR_BLACK, COLOR_WHITE); init_pair(2, COLOR_YELLOW, COLOR_BLUE); getmaxyx(stdscr, y, x); y = (y - 8) / 2.0; x = (x - 27) / 2.0; win = newwin(8, 27, y, x); wbkgd(win, COLOR_PAIR(2)); box(win, 0, 0); mvwprintw(win, 2, 2, "User:"******"Pass:"******" "); mvwprintw(win, 4, 8, " "); wrefresh(win); mvwgetnstr(win, 2, 8, buff->pwd_name, USERNAME_LEN); noecho(); mvwgetnstr(win, 4, 8, buff->pwd_passwd, PASSWORD_LEN); overwrite(win, stdscr); echo(); delwin(win); touchwin(stdscr); endwin(); /* leave ncurses mode */ }
void ui_statusline_ask_num(char *msg, int *i) { int x = strlen(msg) + 5; char input[STRING_SHORT]; ui_statusline_clear(); ui_statusline_msg(msg); echo(); show_cursor(); mvwgetnstr(bottom, 1, x, input, STRING_SHORT); *i = atoi(input); noecho(); hide_cursor(); ui_statusline_clear(); }
// // Affiche une fenêtre de demande de texte. // Ex: demande du pseudo. // void displayTextPromptMenu(char title[], char fieldTitle[], char result[], int n, int yPos, int xPos) { if(result == NULL || n < 0) return; do { //variables pour l'affichage du menu WINDOW *win = getMenuWindowNoLogo(1, title, yPos, xPos); mvwprintw(win, 4, 2, "%s", fieldTitle); wrefresh(win); refresh(); //on demande un string à l'utilisateur mvwgetnstr(win, 4, (int) strlen(fieldTitle) + 3, result, n); wclear(win); wrefresh(win); delwin(win); } while(strlen(result) < 1 || strpbrk(result, ",")); //on ne veut pas de virgule, ça peut interférer avec le stockage des meilleurs scores }
int set_itf (SwitchPos * sp, AppData * a) { WINDOW *menu_win, *menu_sub; int maxx; const int BUFSZ = 1024; char *newitf; maxx = getmaxx (stdscr); menu_win = newwin (5, maxx, 0, 0); menu_sub = derwin (menu_win, 1, maxx - 2, 3, 1); mvwprintw (menu_win, 1, 2, "%s", "Enter a filename to use, please"); box (menu_win, 0, 0); wrefresh (menu_win); // sp->initial_tuning_file newitf = utlCalloc (BUFSZ, sizeof (char)); if (NULL == newitf) { errMsg ("allocation failed\n"); return 1; } // def_prog_mode(); // setsyx(4,20+2); nl (); nodelay (menu_sub, FALSE); echo (); nocbreak (); keypad (menu_sub, FALSE); mvwgetnstr (menu_sub, 0, 0, newitf, BUFSZ); newitf[BUFSZ - 1] = '\0'; newitf = utlRealloc (newitf, strlen (newitf) + 1); nonl (); noecho (); raw (); keypad (menu_sub, TRUE); // reset_prog_mode(); message (a, "Using file: %s, thanks.\n", newitf); if (sp->initial_tuning_file) utlFAN (sp->initial_tuning_file); sp->initial_tuning_file = newitf; return 0; }
void DrawUMountUI() { MNTEdit = newwin(8, 52, 4, 20); keypad(MNTEdit, TRUE); box(MNTEdit, ACS_VLINE, ACS_HLINE); wattron(MNTEdit, A_BOLD); mvwprintw(MNTEdit,1, 15, "Unmount a filesystem"); mvwaddstr(MNTEdit,3, 2, "Type a mount point or device to umount "); wattroff(MNTEdit, A_BOLD); mvwaddstr(MNTEdit,5, 2, "[_____________________________________]"); /* Window Refresh */ wrefresh(MNTEdit); echo(); wattron(MNTEdit, A_REVERSE); mvwaddstr(MNTEdit,5, 2, "[_____________________________________]"); mvwgetnstr(MNTEdit, 5,3, Umountbuf, 30); wattroff(MNTEdit, A_REVERSE); noecho(); }
/** * dest should have enough space (at least len) to hold the string. */ void get_text_string_from_centered_panel(char const *const prompt, char *dest, int len) { WINDOW *panel_win; PANEL *the_panel; int panel_height=6,panel_width; /* char *dest = malloc(100); */ int promptlen = strlen(prompt); panel_width = MAX(30, promptlen+5); /* Create the window to hold the panel */ panel_win = newwin(panel_height, panel_width, (LINES-panel_height)/2, (COLS-panel_width)/2); box(panel_win, 0, 0); print_in_middle(panel_win, 1, 0, panel_width, prompt, COLOR_PAIR(6)); wattron(panel_win, COLOR_PAIR(5)); mvwhline(panel_win, 3, 2, ' ', panel_width-4); curs_set(1); // make cursor visible echo(); mvwgetnstr(panel_win, 3, 2, dest, len); noecho(); curs_set(0); // make cursor invisible wattroff(panel_win, COLOR_PAIR(5)); /* create the panel from our window */ the_panel = new_panel(panel_win); top_panel(the_panel); update_panels(); doupdate(); del_panel(the_panel); update_panels(); delwin(panel_win); doupdate(); }
bool channel_input(WINDOW *win, int c) { char buf[6]; int x; int new_idx = -1; switch (c) { case 's': case 'S': conf.intf.channel_scan = conf.intf.channel_scan ? 0 : 1; break; case 'd': case 'D': echo(); curs_set(1); mvwgetnstr(win, 19, 12, buf, 6); curs_set(0); noecho(); sscanf(buf, "%d", &x); conf.intf.channel_time = x*1000; break; case 'u': case 'U': echo(); curs_set(1); mvwgetnstr(win, 20, 18, buf, 6); curs_set(0); noecho(); sscanf(buf, "%d", &x); conf.intf.channel_max = x; break; case 'm': case 'M': echo(); curs_set(1); mvwgetnstr(win, 22, 18, buf, 3); curs_set(0); noecho(); sscanf(buf, "%d", &x); conf.intf.channel_set.freq = wlan_chan2freq(x); break; case '1': conf.intf.channel_set.width = CHAN_WIDTH_20_NOHT; break; case '2': conf.intf.channel_set.width = CHAN_WIDTH_20; break; case '4': conf.intf.channel_set.width = CHAN_WIDTH_40; set_ht40plus = false; break; case '5': conf.intf.channel_set.width = CHAN_WIDTH_40; set_ht40plus = true; break; case '8': conf.intf.channel_set.width = CHAN_WIDTH_80; break; case '6': conf.intf.channel_set.width = CHAN_WIDTH_160; break; case '\r': case KEY_ENTER: /* used to close win, too */ new_idx = uwifi_channel_idx_from_freq(&conf.intf.channels, conf.intf.channel_set.freq); if ((new_idx >= 0 && new_idx != conf.intf.channel_idx) || conf.intf.channel_set.width != conf.intf.channel.width || set_ht40plus != uwifi_channel_is_ht40plus(&conf.intf.channel)) { uwifi_channel_fix_center_freq(&conf.intf.channel_set, set_ht40plus); /* some setting changed */ if (conf.serveraddr[0] == '\0') { /* server */ if (!uwifi_channel_change(&conf.intf, &conf.intf.channel_set)) { /* reset UI */ conf.intf.channel_set = conf.intf.channel; } else { net_send_channel_config(); } } else { /* client */ conf.intf.channel_idx = new_idx; conf.intf.channel = conf.intf.channel_set; LOG_INF("Sending channel config to server"); net_send_channel_config(); } } return false; default: return false; /* didn't handle input */ } update_channel_win(win); return true; }
int Mountafs() { int MNTEditKey; while(1) { DrawMountUI(); MNTEditKey = wgetch(MNTEdit); switch(MNTEditKey) { /* Help */ case KEY_F(1): //help_func("addtofstab"); break; /* Edit Keys */ case KEY_F(2): // Device echo(); wattron(MNTEdit,A_REVERSE); mvwprintw(MNTEdit, 3, 22,"[_________________________]"); mvwgetnstr(MNTEdit, 3,23, fsmgrbuf, 25); strcpy(mountfields.Device, fsmgrbuf); wattroff(MNTEdit,A_REVERSE); noecho(); break; case KEY_F(3): // Mount Point echo(); wattron(MNTEdit,A_REVERSE); mvwprintw(MNTEdit, 4, 22,"[_________________________]"); mvwgetnstr(MNTEdit, 4,23, fsmgrbuf, 25); strcpy(mountfields.MntDir, fsmgrbuf); wattroff(MNTEdit,A_REVERSE); noecho(); break; case KEY_F(4): // Fstype echo(); wattron(MNTEdit,A_REVERSE); mvwprintw(MNTEdit, 5, 22,"[_________________________]"); mvwgetnstr(MNTEdit, 5,23, fsmgrbuf, 25); strcpy(mountfields.Fstyp, fsmgrbuf); wattroff(MNTEdit,A_REVERSE); noecho(); break; case KEY_F(5): // Options echo(); wattron(MNTEdit,A_REVERSE); mvwprintw(MNTEdit, 6, 22,"[_________________________]"); mvwgetnstr(MNTEdit, 6,23, fsmgrbuf, 25); strcpy(mountfields.Option, fsmgrbuf); wattroff(MNTEdit,A_REVERSE); noecho(); break; case KEY_F(9): CommenceMount(); return 0; break; /* Quit */ case KEY_F(10): return 0; break; } } return 0; }
int adduser(void) { /* Declarations */ getmaxyx(stdscr, y,x); /* Screen Sizes */ int key; while(true) { drawauscreen(); /* Draw the Screen */ refresh(); do { key = getch(); switch(key) { /* Field Edit Keys which are number keys */ case '1': echo(); if((loginname = malloc(sizeof(char) * USER_BUFFER + 1)) == NULL) return(1); attron(A_REVERSE); mvprintw(7, 35, "_________________"); mvwgetnstr(stdscr, 7,35, loginname, 15); attroff(A_REVERSE); noecho(); break; case '2': echo(); if((usergecos = malloc(sizeof(char) * USER_BUFFER + 1)) == NULL) return(1); attron(A_REVERSE); mvprintw(8, 35, "_________________"); mvwgetnstr(stdscr, 8,35, usergecos, 15); attroff(A_REVERSE); noecho(); break; case '3': echo(); if((userid = malloc(sizeof(char) * USER_BUFFER + 1)) == NULL) return(1); attron(A_REVERSE); mvprintw(9, 35, "_________________"); mvwgetnstr(stdscr, 9,35, userid, 5); attroff(A_REVERSE); noecho(); break; case '4': echo(); if((groupid = malloc(sizeof(char) * USER_BUFFER + 1)) == NULL) return(1); attron(A_REVERSE); mvprintw(10, 35, "_________________"); mvwgetnstr(stdscr, 10,35, groupid, 5); attroff(A_REVERSE); noecho(); break; case '5': echo(); if((usershell = malloc(sizeof(char) * USER_BUFFER + 1)) == NULL) return(1); attron(A_REVERSE); mvprintw(11, 35, "_________________"); mvwgetnstr(stdscr, 11,35, usershell, 15); attroff(A_REVERSE); noecho(); break; case '6': echo(); if((homedir = malloc(sizeof(char) * USER_BUFFER + 1)) == NULL) return(1); attron(A_REVERSE); mvprintw(12, 35, "_________________"); mvwgetnstr(stdscr, 12,35, homedir, 15); attroff(A_REVERSE); noecho(); break; /* Function Key Controls */ case KEY_F(1): /* Help */ break; case KEY_F(2): /* Refresh */ refresh(); break; case KEY_F(3): /* Cancel Key */ break; case KEY_F(4): /* Reset Fields if statements to prevent crashing if pressed more than once. strcmp does cause segmentation fault */ if(loginname != "(cleared)") free(loginname); if(usergecos != "(cleared)") free(usergecos); if(usershell != "(cleared)") free(usershell); if(homedir != "(cleared)") free(homedir); if(userid != "(cleared)") free(userid); if(groupid != "(cleared)") free(groupid); loginname = "(cleared)"; usergecos = "(cleared)"; usershell = "(cleared)"; homedir = "(cleared)"; userid = "(cleared)"; groupid = "(cleared)"; break; case KEY_F(5): /* Run Command */ //executecmd(command); /* Execute command */ break; case KEY_F(6): /* Add User */ verifyadd(); /* Confirms then Add or quits */ break; case KEY_F(9): /* Run Default Shell */ clear(); endwin(); system(DEFAULT_SHELL); break; case KEY_F(10): /* Quits Dialog */ return(0); break; } drawauscreen(); refresh(); } while(key != '\n'); /* Other Statments goes here */ }; /* Finish up */ free(loginname); free(usergecos); free(usershell); free(homedir); return 0; }
int useradd() { noecho(); keypad(stdscr, TRUE); while(1) { DrawAddUserScreen(); AddUserKey = getch(); switch(AddUserKey) { /* Help */ case KEY_F(1): break; /* Reset Fields */ case KEY_F(2): sprintf(ui.username, "_"); sprintf(ui.gecos, "_"); sprintf(ui.user_id, "_"); sprintf(ui.group_id, "_"); sprintf(ui.shell, "_"); sprintf(ui.homedir, "_"); break; /* Username */ case KEY_F(3): echo(); attron(A_REVERSE); mvprintw(8,35, "[_______________________]"); mvwgetnstr(stdscr, 8,36, userinfobuf, 15); strcpy(ui.username, userinfobuf); attroff(A_REVERSE); noecho(); unamefield = 1; break; /* User Comment/Gecos */ case KEY_F(4): echo(); attron(A_REVERSE); mvprintw(9,35, "[_______________________]"); mvwgetnstr(stdscr, 9,36, userinfobuf, 20); strcpy(ui.gecos, userinfobuf); attroff(A_REVERSE); noecho(); break; /* User ID*/ case KEY_F(5): echo(); attron(A_REVERSE); mvprintw(10,35, "[_______________________]"); mvwgetnstr(stdscr, 10,36, userinfobuf, 20); strcpy(ui.user_id, userinfobuf); attroff(A_REVERSE); noecho(); uidfield = 1; break; /* Group ID*/ case KEY_F(6): echo(); attron(A_REVERSE); mvprintw(11,35, "[_______________________]"); mvwgetnstr(stdscr, 11,36, userinfobuf, 20); strcpy(ui.group_id, userinfobuf); attroff(A_REVERSE); noecho(); gidfield = 1; break; /* Login Shell */ case KEY_F(7): echo(); attron(A_REVERSE); mvprintw(12,35, "[_______________________]"); mvwgetnstr(stdscr, 12,36, userinfobuf, 23); strcpy(ui.shell, userinfobuf); attroff(A_REVERSE); noecho(); break; /* Home Dir */ case KEY_F(8): echo(); attron(A_REVERSE); mvprintw(13,35, "[_______________________]"); mvwgetnstr(stdscr, 13,36, userinfobuf, 23); strcpy(ui.homedir, userinfobuf); attroff(A_REVERSE); noecho(); break; case KEY_F(9): execute_default_shell(); break; /* Quit */ case KEY_F(10): return 0; break; /* Commence Add */ case KEY_F(11): add_user(); break; }; }; return 0; }
int filter_input(WINDOW *win, int c) { char buf[18]; int i; switch (c) { case 'm': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_MGMT); if (conf.filter_pkt & PKT_TYPE_MGMT) conf.filter_pkt |= PKT_TYPE_ALL_MGMT; else conf.filter_pkt &= ~PKT_TYPE_ALL_MGMT; break; case 'b': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_BEACON); break; case 'p': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_PROBE); break; case 'a': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_ASSOC); break; case 'u': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_AUTH); break; case 'c': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_CTRL); if (conf.filter_pkt & PKT_TYPE_CTRL) conf.filter_pkt |= PKT_TYPE_ALL_CTRL; else conf.filter_pkt &= ~PKT_TYPE_ALL_CTRL; break; case 'r': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_CTS | PKT_TYPE_RTS); break; case 'k': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_ACK); break; case 'd': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_DATA); if (conf.filter_pkt & PKT_TYPE_DATA) conf.filter_pkt |= PKT_TYPE_ALL_DATA; else conf.filter_pkt &= ~PKT_TYPE_ALL_DATA; break; case 'q': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_QDATA); break; case 'n': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_NULL); break; case 'R': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_ARP); break; case 'P': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_ICMP); break; case 'I': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_IP); break; case 'U': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_UDP); break; case 'T': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_TCP); break; case 'O': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_OLSR|PKT_TYPE_OLSR_LQ|PKT_TYPE_OLSR_GW); break; case 'B': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_BATMAN); break; case 'M': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_MESHZ); break; case 's': echo(); print_centered(win, FILTER_MAX, 57, "[ Enter new BSSID and ENTER ]"); mvwprintw(win, 5, MAC_COL + 4, ">"); mvwgetnstr(win, 5, MAC_COL + 7, buf, 17); noecho(); convert_string_to_mac(buf, conf.filterbssid); break; case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': i = c - '1'; if (MAC_NOT_EMPTY(conf.filtermac[i]) && conf.filtermac_enabled[i]) { conf.filtermac_enabled[i] = 0; } else { echo(); print_centered(win, FILTER_MAX, 57, "[ Enter new MAC %d and ENTER ]", i+1); mvwprintw(win, 9 + i, MAC_COL + 4, ">"); mvwgetnstr(win, 9 + i, MAC_COL + 7, buf, 17); noecho(); /* just enable old MAC if user pressed return only */ if (*buf == '\0' && MAC_NOT_EMPTY(conf.filtermac[i])) conf.filtermac_enabled[i] = 1; else { convert_string_to_mac(buf, conf.filtermac[i]); if (MAC_NOT_EMPTY(conf.filtermac[i])) conf.filtermac_enabled[i] = true; } } break; case 'o': conf.filter_off = conf.filter_off ? 0 : 1; break; default: return 0; } /* convenience: */ /* if one of the individual mgmt frames is deselected we dont want to see all mgmt frames */ if ((conf.filter_pkt & PKT_TYPE_ALL_MGMT) != PKT_TYPE_ALL_MGMT) conf.filter_pkt = conf.filter_pkt & ~PKT_TYPE_MGMT; /* same for ctl */ if ((conf.filter_pkt & PKT_TYPE_ALL_CTRL) != PKT_TYPE_ALL_CTRL) conf.filter_pkt = conf.filter_pkt & ~PKT_TYPE_CTRL; /* same for data */ if ((conf.filter_pkt & PKT_TYPE_ALL_DATA) != PKT_TYPE_ALL_DATA) conf.filter_pkt = conf.filter_pkt & ~PKT_TYPE_DATA; /* recalculate filter flag */ conf.do_macfilter = 0; for (i = 0; i < MAX_FILTERMAC; i++) { if (conf.filtermac_enabled[i]) conf.do_macfilter = 1; } net_send_filter_config(); update_filter_win(win); return 1; }
bool channel_input(WINDOW *win, int c) { char buf[6]; int x; switch (c) { case 's': case 'S': conf.do_change_channel = conf.do_change_channel ? 0 : 1; break; case 'd': case 'D': echo(); curs_set(1); mvwgetnstr(win, 18, 12, buf, 6); curs_set(0); noecho(); sscanf(buf, "%d", &x); conf.channel_time = x*1000; break; case 'u': case 'U': echo(); curs_set(1); mvwgetnstr(win, 19, 18, buf, 6); curs_set(0); noecho(); sscanf(buf, "%d", &x); conf.channel_max = x; break; case 'm': case 'M': echo(); curs_set(1); mvwgetnstr(win, 21, 18, buf, 3); curs_set(0); noecho(); sscanf(buf, "%d", &x); int i = channel_find_index_from_chan(x); if (i >= 0) { if (!conf.serveraddr[0] != '\0') { if (!channel_change(i, conf.channel_set_width, conf.channel_set_ht40plus)) printlog("Channel %d %s is not available/allowed", x, channel_width_string(conf.channel_set_width, conf.channel_set_ht40plus)); } else conf.channel_idx = i; } break; case '1': conf.channel_set_width = CHAN_WIDTH_20_NOHT; break; case '2': conf.channel_set_width = CHAN_WIDTH_20; break; case '4': conf.channel_set_width = CHAN_WIDTH_40; conf.channel_set_ht40plus = false; break; case '5': conf.channel_set_width = CHAN_WIDTH_40; conf.channel_set_ht40plus = true; break; case '8': conf.channel_set_width = CHAN_WIDTH_80; break; case '6': conf.channel_set_width = CHAN_WIDTH_160; break; default: return false; /* didn't handle input */ } // TODO: net client has not set channel_width and ht40p yet: net_send_channel_config(); update_channel_win(win); return true; }
bool filter_input(WINDOW *win, int c) { char buf[18]; int i, t; switch (c) { case 'm': TOGGLE_BITSET(conf.filter_stype[WLAN_FRAME_TYPE_MGMT], 0xffff, uint16_t); break; case 'c': TOGGLE_BITSET(conf.filter_stype[WLAN_FRAME_TYPE_CTRL], 0xffff, uint16_t); break; case 'd': TOGGLE_BITSET(conf.filter_stype[WLAN_FRAME_TYPE_DATA], 0xffff, uint16_t); break; case 'r': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_ARP); break; case 'M': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_ICMP); break; case 'i': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_IP); break; case 'V': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_UDP); break; case 'W': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_TCP); break; case 'I': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_OLSR); break; case 'K': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_BATMAN); break; case 'Z': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_MESHZ); break; case '!': TOGGLE_BIT(conf.filter_mode, WLAN_MODE_AP); break; case '@': TOGGLE_BIT(conf.filter_mode, WLAN_MODE_STA); break; case '#': TOGGLE_BIT(conf.filter_mode, WLAN_MODE_IBSS); break; case '%': TOGGLE_BIT(conf.filter_mode, WLAN_MODE_4ADDR); break; case '^': TOGGLE_BIT(conf.filter_mode, WLAN_MODE_UNKNOWN); break; case '_': echo(); print_centered(win, FILTER_WIN_HEIGHT-1, FILTER_WIN_WIDTH, "[ Enter new BSSID and ENTER ]"); mvwprintw(win, THIRD_ROW + 1, MODE_COL + 4, ">"); mvwgetnstr(win, THIRD_ROW + 1, MODE_COL + 7, buf, 17); noecho(); convert_string_to_mac(buf, conf.filterbssid); break; case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': i = c - '1'; if (MAC_NOT_EMPTY(conf.filtermac[i]) && conf.filtermac_enabled[i]) { conf.filtermac_enabled[i] = 0; } else { echo(); print_centered(win, FILTER_WIN_HEIGHT-1, FILTER_WIN_WIDTH, "[ Enter new MAC %d and ENTER ]", i+1); mvwprintw(win, THIRD_ROW + 1 + i, MAC_COL + 4, ">"); mvwgetnstr(win, THIRD_ROW + 1 + i, MAC_COL + 7, buf, 17); noecho(); /* just enable old MAC if user pressed return only */ if (*buf == '\0' && MAC_NOT_EMPTY(conf.filtermac[i])) conf.filtermac_enabled[i] = 1; else { convert_string_to_mac(buf, conf.filtermac[i]); if (MAC_NOT_EMPTY(conf.filtermac[i])) conf.filtermac_enabled[i] = true; } } break; case '0': conf.filter_off = conf.filter_off ? 0 : 1; break; case '*': conf.filter_badfcs = conf.filter_badfcs ? 0 : 1; break; default: for (t = 0; t < WLAN_NUM_TYPES; t++) { for (i = 0; i < WLAN_NUM_STYPES; i++) { if (stype_names[t][i].c == c) { TOGGLE_BIT(conf.filter_stype[t], BIT(i)); goto out; } } } return false; // not found } out: /* recalculate filter flag */ conf.do_macfilter = 0; for (i = 0; i < MAX_FILTERMAC; i++) { if (conf.filtermac_enabled[i]) conf.do_macfilter = 1; } net_send_filter_config(); update_filter_win(win); return true; }
/* * mvgetnstr -- * Get a string (of maximum n) characters from stdscr starting at (y, x). */ int mvgetnstr(int y, int x, char *str, int n) { return mvwgetnstr(stdscr, y, x, str, n); }
int main(int argc, char *argv[]) { WINDOW *send_win, *people_win; win_s send, people; int ch; int port, i = 0; char *host, *name; pthread_t read_pid; pt_s pt; if (argc != 4) { fprintf(stderr, "usage: %s <host> <port> <nickname>\n", argv[0]); return 0; } host = argv[1]; port = atoi(argv[2]); for (i = 0; i < strlen(argv[3]); i++) { pt.wbuf[i] = argv[3][i]; } fprintf(stdout, "OK in 46\n"); // setlocale(LC_ALL, "zh_CN.UTF-8"); initscr(); raw(); echo(); keypad(stdscr, TRUE); if(has_colors() == FALSE) { endwin(); printf("Your terminal does not support color\n"); return 1; } start_color(); init_pair(1, COLOR_GREEN, COLOR_BLACK); init_pair(2, COLOR_YELLOW, COLOR_BLACK); init_pair(3, COLOR_BLUE, COLOR_BLACK); init_pair(4, COLOR_CYAN, COLOR_BLACK); send.height = 5; send.width = COLS - 20; send.startx = 0; send.starty = LINES - 5; refresh(); send_win = create_newwin(send, "SEND"); refresh(); pt.clientfd = open_clientfd(host, port); Rio_readinitb(&(pt.rio), pt.clientfd); pt.wbuf[strlen(argv[3])] = '\n'; Rio_writen(pt.clientfd, pt.wbuf, strlen(pt.wbuf)); pt.wbuf[strlen(argv[3])] = ':'; pthread_create(&read_pid, NULL, read_thread, &pt); int name_len = strlen(argv[3]) + 1; while (mvwgetnstr(send_win, 0, 0, pt.wbuf + name_len, MAXLINE - name_len) != ERR) { pt.wbuf[strlen(pt.wbuf)] = '\n'; Rio_writen(pt.clientfd, pt.wbuf, strlen(pt.wbuf)); bzero(pt.wbuf + name_len, MAXLINE - name_len); werase(send_win); } endwin(); return 0; }
/* save results */ static void save_results_table(void) { int rows,cols,n=40,length,c; WINDOW *mywin; FILE *outfile; DIR *mydir; struct dirent *mydirent; char fname[n+1]; rows = (LINES - 3) / 2; length = strlen(save_table_str) + n + 2; cols = (COLS - length) / 2; /* create input window */ mywin = subwin(stdscr,3,length,rows,cols); keypad(mywin,TRUE); wattrset(mywin,COLOR_PAIR(BG_PAIR)); /* setup colors */ wbkgdset(mywin,COLOR_PAIR(BG_PAIR)); werase(mywin); /* erase and color window */ mvwaddstr(mywin,1,1,save_table_str); length = strlen(save_table_str) + 1; box(mywin,0,0); wrefresh(mywin); echo(); mvwgetnstr(mywin,1,length,fname,n); noecho(); /* open current directory */ mydir = opendir("."); if (mydir == NULL ) { werase(mywin); mvwaddstr(mywin,1,1,opendir_err); box(mywin,0,0); wrefresh(mywin); while ( (c = mvwgetch(mywin,1,strlen(save_file_exists)+1)) ) { if(c == 'n' || c == 'N') { delwin(mywin); return; } } } /* check existing files */ while( (mydirent = readdir(mydir)) != NULL ) { if( strcmp(fname,mydirent->d_name) == 0 ) { werase(mywin); mvwaddstr(mywin,1,1,save_file_exists); box(mywin,0,0); wrefresh(mywin); while ( (c = mvwgetch(mywin,1,strlen(save_file_exists)+1)) ) { if(c == 'n' || c == 'N') { delwin(mywin); closedir(mydir); return; } else if (c == 'y' || c == 'Y') break; } break; } } closedir(mydir); /* open output file */ errno = 0; outfile = fopen(fname,"w"); if (errno) { werase(mywin); mvwaddstr(mywin,1,1,save_table_err); box(mywin,0,0); wrefresh(mywin); while( (c = mvwgetch(mywin,1,strlen(save_table_err+1))) ) { if( c == 13 ) { delwin(mywin); return; } } } /* write results */ write_results(outfile); fclose(outfile); delwin(mywin); return; }
int userinfo(void) { /* Declarations */ getmaxyx(stdscr, y,x); /* Screen Sizes */ uid_t uid; gid_t gid; struct passwd *pw; uid = getuid(); gid = getgid(); WINDOW *uidlg; /* Prompt Username Window */ /* Draw to screen */ clear(); box(stdscr, ACS_VLINE, ACS_HLINE); /* y x - Screens */ uidlg = newwin(6,61,6,8); /* User name input dialog */ box(uidlg, ACS_VLINE, ACS_HLINE); wattron(uidlg, A_UNDERLINE); mvwprintw(uidlg, 1, 20, "User Information"); wattroff(uidlg, A_UNDERLINE); /* Buffer control */ if((loginname = malloc(sizeof(char) * USER_BUFFER + 1)) == NULL) return(1); echo(); /* Turns on Echo to see the text typed */ /* Username Prompt */ mvwprintw(uidlg, 3, 1, "Please type in username to look up:"); mvwprintw(uidlg, 3, 37, "______________"); wrefresh(uidlg); /* Now We need to gain strings that is typed in */ /* Show a highlighted Field */ wattron(uidlg, A_REVERSE); mvwprintw(uidlg, 3, 37, "______________"); wrefresh(uidlg); mvwgetnstr(uidlg, 3,37, loginname, 15); wattroff(uidlg, A_REVERSE); noecho(); /* Removes Echo */ werase(uidlg); /* Shows User Information */ refresh(); attron(A_UNDERLINE); mvprintw(1, 25, "%s User Information", PROG_NAME); /* Title */ attroff(A_UNDERLINE); refresh(); /* Process User Info now has error handling */ if (pw = getpwnam(loginname) == NULL) { progerror(); free(loginname); return 1; } else { pw = getpwnam(loginname); } mvprintw(4, 10, "Username: "******"%s", pw->pw_name); mvprintw(5, 10, "User ID: "); mvprintw(5, 25, "%d", pw->pw_uid); mvprintw(6, 10, "Group ID: "); mvprintw(6, 25, "%d", pw->pw_gid); mvprintw(7, 10, "Shell: "); mvprintw(7, 25, "%s", pw->pw_shell); mvprintw(8, 10, "Home dir: "); mvprintw(8, 25, "%s", pw->pw_dir); mvprintw(9, 10, "Comment: "); mvprintw(9, 25, "%s", pw->pw_gecos); mvprintw(15,20, "Press Enter to return after viewing"); getch(); free(loginname); return 0; }
char * ui_statusline_ask_str(char *msg, char *input, int len) { char *tmp; char *tmp2; char *tmp3; int x = strlen(msg) + 5; if(input == NULL){ input = malloc(len); } ui_statusline_clear(); ui_statusline_msg(msg); echo(); show_cursor(); mvwgetnstr(bottom, 1, x, input, len); noecho(); hide_cursor(); ui_statusline_clear(); // Tabs don't play nicely with ncurses or xml // So, swap any for (a single) space tmp = input; while(*tmp != 0) { if(*tmp == 9) *tmp = ' '; tmp++; } // In some cases (eg when inside screen), the backspace // comes through to us. Handle it here if needed tmp = input; while(*tmp != 0) { if(*tmp == 8) { // tmp2 is where to copy to, tmp3 is where to copy from tmp3 = tmp + 1; if(tmp == input) { tmp2 = tmp; } else { tmp2 = tmp - 1; } // When we're done, start from the character // we copied in to tmp = tmp2; // Process forward while(*tmp3 != 0) { *tmp2 = *tmp3; tmp2++; tmp3++; } *tmp2 = 0; } else { tmp++; } } // All done return input; }
int removeuser(void) { /* Declarations */ WINDOW *rmudlg; /* Prompt Username Window */ rmudlg = newwin(6,61,6,10); /* User name input dialog */ box(rmudlg, ACS_VLINE, ACS_HLINE); wattron(rmudlg, A_UNDERLINE); mvwprintw(rmudlg, 1, 20, "Remove user from system"); wattroff(rmudlg, A_UNDERLINE); echo(); /* Turns on Echo to see the text typed */ /* Username Prompt */ mvwprintw(rmudlg, 3, 1, "Please type in username to remove:"); mvwprintw(rmudlg, 3, 37, "[______________]"); wrefresh(rmudlg); /* Show a highlighted Field */ wattron(rmudlg, A_REVERSE); mvwprintw(rmudlg, 3, 37, "[______________]"); wrefresh(rmudlg); mvwgetnstr(rmudlg, 3,38, loginname, 15); wattroff(rmudlg, A_REVERSE); noecho(); /* Removes Echo */ werase(rmudlg); while(1) { rmudlg = newwin(10,61,6,10); box(rmudlg, ACS_VLINE, ACS_HLINE); wattron(rmudlg, A_UNDERLINE); mvwprintw(rmudlg, 1, 20, "Are you sure"); wattroff(rmudlg, A_UNDERLINE); mvwprintw(rmudlg, 3, 7, "Are you sure you want to delete"); mvwprintw(rmudlg, 4, 7, "user %s from the system", loginname); wattron(rmudlg,A_BOLD); mvwprintw(rmudlg, 6, 7, "Y=Yes N=No F10=Cancel"); wattroff(rmudlg,A_BOLD); wrefresh(rmudlg); key = getch(); switch(key) { case KEY_F(10): return 0; break; case 'n': return 0; break; case 'N': return 0; break; case 'y': delUser(); return 0; break; case 'Y': delUser(); return 0; break; } }; return 0; }