int action_list_move_item_up_level() { Pw* curpw; PWList *curpwl, *iter; int i; char str[STRING_LONG]; char answer[STRING_MEDIUM]; switch(uilist_get_highlighted_type()){ case PW_ITEM: curpw = uilist_get_highlighted_item(); if(curpw && current_pw_sublist->parent){ pwlist_detach_pw(current_pw_sublist, curpw); pwlist_add_ptr(current_pw_sublist->parent, curpw); uilist_refresh(); } break; case PW_SUBLIST: curpwl = uilist_get_highlighted_sublist(); if(curpwl && current_pw_sublist->parent){ pwlist_detach_sublist(current_pw_sublist, curpwl); pwlist_add_sublist(current_pw_sublist->parent, curpwl); uilist_refresh(); } break; case PW_UPLEVEL: case PW_NULL: default: /* do nothing */ break; } }
int action_list_select_item() { Pw* curpw; PWList* curpwl; PWSearchResult* cursearch; // Are they searching, or in normal mode? if(search_results != NULL) { cursearch = uilist_get_highlighted_searchresult(); curpwl = cursearch->sublist; curpw = cursearch->entry; if(curpw){ action_edit_pw(curpw); } else if(curpwl){ // Quite out of searching search_remove(); // Now display the selected sublist current_pw_sublist = curpwl; uilist_refresh(); } } else { switch(uilist_get_highlighted_type()){ case PW_ITEM: curpw = uilist_get_highlighted_item(); if(curpw){ action_edit_pw(curpw); } break; case PW_SUBLIST: curpwl = uilist_get_highlighted_sublist(); if(curpwl){ current_pw_sublist = curpwl; uilist_refresh(); } break; case PW_UPLEVEL: action_list_up_one_level(); break; case PW_NULL: default: /* do nothing */ break; } } }
int action_list_select_item() { Pw* curpw; PWList* curpwl; switch(uilist_get_highlighted_type()){ case PW_ITEM: curpw = uilist_get_highlighted_item(); if(curpw){ action_edit_pw(curpw); } break; case PW_SUBLIST: curpwl = uilist_get_highlighted_sublist(); if(curpwl){ current_pw_sublist = curpwl; uilist_refresh(); } break; case PW_UPLEVEL: action_list_up_one_level(); break; case PW_NULL: default: /* do nothing */ break; } }
int action_yes_no_dialog(InputField *fields, int num_fields, char *title, char *question) { int ch, i; char *ret; WINDOW *dialog_win; /* * initialize the info window */ if(title){ disp_h = ((num_fields+2) * 2) + 3; } else { disp_h = ((num_fields+1) * 2) + 3; } dialog_win = newwin(disp_h, disp_w, (LINES - disp_h)/2, (COLS - disp_w)/2); keypad(dialog_win, TRUE); action_input_dialog_draw_items(dialog_win, fields, num_fields, title, NULL); i = ui_statusline_yes_no(question, 1); /* * clean up */ delwin(dialog_win); uilist_refresh(); return i; }
static void ui_display_help() { int i, l = 0; WINDOW *helpwin; int width = 65; helpwin = newwin(LINES - 5, width, 3, (COLS - width) / 2); box(helpwin, 0, 0); uilist_clear(); for (i = 0; help[i] != NULL; i++) { mvwaddstr(helpwin, l + 1, 1, help[i]); l++; if (!((i + 1) % (LINES - 8)) || (help[i + 1] == NULL)) { wrefresh(helpwin); ui_statusline_msg("Press any key to continue..."); getch(); wclear(helpwin); box(helpwin, 0, 0); l = 0; } } uilist_refresh(); ui_statusline_clear(); delwin(helpwin); }
int action_input_gpgid_dialog(InputField *fields, int num_fields, char *title) { int i, valid_id; int ch = '1', first_time = 1; char *ret; WINDOW *dialog_win; char msg[] = "(press 'q' when export recipient list is complete)"; char msg2[80]; /* * initialize the info window */ disp_h = ((num_fields+2) * 2) + 3; dialog_win = newwin(disp_h, disp_w, (LINES - disp_h)/2, (COLS - disp_w)/2); keypad(dialog_win, TRUE); action_input_dialog_draw_items(dialog_win, fields, num_fields, title, msg); /* * actions loop - ignore read only as not changing main state */ while(first_time || ((ch = wgetch(dialog_win)) != 'q')){ // On first loop, drop straight into recipient 1 first_time = 0; if( (ch >= '1') && (ch <= NUM_TO_CHAR(num_fields)) ){ i = CHAR_TO_NUM(ch); fields[i].value = (char*)ui_statusline_ask_str(fields[i].name, (char*)fields[i].value, fields[i].max_length); // Now verify it's a valid recipient if(strlen(fields[i].value)) { valid_id = gnupg_check_id(fields[i].value); if(valid_id == 0) { // Good, valid id } else { // Invalid id. Warn and blank if(valid_id == -2) { snprintf(msg2, 80, "Key expired for '%s'", (char*)fields[i].value); } else { snprintf(msg2, 80, "Invalid recipient '%s'", (char*)fields[i].value); } ui_statusline_msg(msg2); snprintf(fields[i].value, STRING_LONG, ""); } // Redraw display action_input_dialog_draw_items(dialog_win, fields, num_fields, title, msg); } } } /* * clean up */ delwin(dialog_win); uilist_refresh(); }
void ui_refresh_windows() { ui_draw_top(); ui_draw_bottom(); uilist_refresh(); refresh(); }
int action_list_up_one_level() { /* move up one sublist */ if(current_pw_sublist->parent){ current_pw_sublist = current_pw_sublist->parent; uilist_refresh(); } }
int action_input_dialog(InputField *fields, int num_fields, char *title) { int ch, i; char *ret; WINDOW *dialog_win; char msg[] = "(press 'q' to return to list)"; char msg2[80]; /* * initialize the info window */ if(title){ disp_h = ((num_fields+2) * 2) + 3; } else { disp_h = ((num_fields+1) * 2) + 3; } dialog_win = newwin(disp_h, disp_w, (LINES - disp_h)/2, (COLS - disp_w)/2); keypad(dialog_win, TRUE); action_input_dialog_draw_items(dialog_win, fields, num_fields, title, msg); /* * actions loop */ while((ch = wgetch(dialog_win)) != 'q'){ if(!options->readonly) { if( (ch >= '1') && (ch <= NUM_TO_CHAR(num_fields)) ){ i = CHAR_TO_NUM(ch); if(fields[i].autogen != NULL){ fields[i].value = (char*)ui_statusline_ask_str_with_autogen( fields[i].name, (char*)fields[i].value, fields[i].max_length, fields[i].autogen, 0x07); } else if(fields[i].type == STRING){ fields[i].value = (char*)ui_statusline_ask_str(fields[i].name, (char*)fields[i].value, fields[i].max_length); } else if(fields[i].type == INT){ ui_statusline_ask_num(fields[i].name, (int*)fields[i].value); } else if(fields[i].type == INFORMATION){ // Easy, do nothing! } action_input_dialog_draw_items(dialog_win, fields, num_fields, title, msg); } else if(ch == 'l'){ delwin(dialog_win); action_list_launch(); break; } } else { statusline_readonly(); } } /* * clean up */ delwin(dialog_win); uilist_refresh(); }
int action_list_read_file() { pwlist_free_all(); if(pwlist_read_file() != 0){ pwlist = pwlist_new("Main"); current_pw_sublist = pwlist; } uilist_refresh(); return -1; }
int action_list_at_top_level() { if(current_pw_sublist->parent){ action_list_up_one_level(); uilist_refresh(); return 0; } else { return 1; } }
int action_list_delete_item() { Pw* curpw; PWList* curpwl; int i; char str[STRING_LONG]; switch(uilist_get_highlighted_type()){ case PW_ITEM: curpw = uilist_get_highlighted_item(); if(curpw){ snprintf(str, STRING_LONG, "Really delete \"%s\"", curpw->name); i = ui_statusline_yes_no(str, 0); if(i){ pwlist_delete_pw(current_pw_sublist, curpw); ui_statusline_msg("Password deleted"); } else { ui_statusline_msg("Password not deleted"); } } break; case PW_SUBLIST: curpwl = uilist_get_highlighted_sublist(); if(curpwl){ snprintf(str, STRING_LONG, "Really delete Sublist \"%s\"", curpwl->name); i = ui_statusline_yes_no(str, 0); if(i){ pwlist_delete_sublist(curpwl->parent, curpwl); ui_statusline_msg("Password Sublist deleted"); } else { ui_statusline_msg("Password not deleted"); } } break; case PW_UPLEVEL: case PW_NULL: default: /* do nothing */ break; } uilist_refresh(); }
int action_list_add_sublist() { char *name; PWList *sublist, *iter; name = malloc(STRING_MEDIUM); ui_statusline_ask_str("Sublist Name:", name, STRING_MEDIUM); for(iter = current_pw_sublist->sublists; iter != NULL; iter = iter->next){ if( strcmp(iter->name, name) == 0){ free(name); return -1; } } sublist = pwlist_new(name); pwlist_add_sublist(current_pw_sublist, sublist); uilist_refresh(); }
int ui_display_help() { int i; WINDOW *helpwin; helpwin = newwin(LINES - 5, COLS - 6, 3, 3); uilist_clear(); for(i = 0; help[i] != NULL; i++){ waddstr(helpwin, help[i]); if( !((i+1) % (LINES - 9)) || (help[i+1] == NULL) ){ /* refresh();*/ wrefresh(helpwin); ui_statusline_msg("Press any key to continue..."); getch(); wclear(helpwin); } } uilist_refresh(); ui_statusline_clear(); delwin(helpwin); }
int action_list_rename() { Pw* curpw; PWList* curpwl; char *new_name; new_name = malloc(STRING_MEDIUM); switch(uilist_get_highlighted_type()){ case PW_ITEM: curpw = uilist_get_highlighted_item(); if(curpw){ ui_statusline_ask_str("New Name", new_name, STRING_MEDIUM); if(strlen(new_name) > 0) { pwlist_rename_item(curpw, new_name); } } break; case PW_SUBLIST: curpwl = uilist_get_highlighted_sublist(); if(curpwl){ ui_statusline_ask_str("New Sublist Name", new_name, STRING_MEDIUM); if(strlen(new_name) > 0) { pwlist_rename_sublist(curpwl, new_name); } } break; case PW_UPLEVEL: case PW_NULL: default: /* do nothing */ break; } uilist_refresh(); }
int ui_run() { int ch; int load_worked = 0; #ifdef DEBUG int debug_i = 0; #endif time_base = time(NULL); while (1) { can_resize = TRUE; if (should_resize) { ui_resize(); } ch = getch(); ui_statusline_clear(); can_resize = FALSE; if ((time_base < (time(NULL) - (options->passphrase_timeout * 60))) && options->passphrase_timeout != 0 && tolower(ch) != 'q') { folder_write_file(); folder_free_all(); ui_statusline_msg("Passphrase has timed out and you must enter it again."); getch(); load_worked = folder_read_file(); if (load_worked != 0) { ui_statusline_msg("Error - unable to re-load the password file!"); break; } if (search_results != NULL) search_remove(); time_base = time(NULL); continue; } switch (ch) { case 'Q': case 'q': if (search_results != NULL) search_remove(); else if (action_list_at_top_level()) return 0; break; case '?': ui_display_help(); break; case KEY_PPAGE: uilist_page_up(); break; case KEY_NPAGE: uilist_page_down(); break; case KEY_UP: case 'k': uilist_up(); break; case KEY_DOWN: case 'j': uilist_down(); break; case 'A': if (!options->readonly) action_list_add_sublist(); else statusline_readonly(); break; case 'U': action_list_up_one_level(); break; case 'r': if (!options->readonly) { action_list_rename(); folder_write_file(); } else { statusline_readonly(); } break; case 'a': if (!options->readonly) { action_list_add_pw(); folder_write_file(); } else { statusline_readonly(); } break; case 'e': case ' ': case 13: /* return/enter key */ action_list_select_item(); break; case 'x': action_list_mark(); break; case 'B': action_list_copy_username(); break; case 'C': action_list_copy_pw(); break; case 'd': case 0x14A: /* DEL key */ if (!options->readonly) action_list_delete_item(); else statusline_readonly(); break; case 'm': if (!options->readonly) action_list_move_item(); else statusline_readonly(); break; case 'o': action_edit_options(); break; case 0x17: /* control-w */ if (!options->readonly) folder_write_file(); else statusline_readonly(); break; case 0x12: /* control-r */ action_list_read_file(); break; case 0x07: /* control-g */ pwgen_indep(); break; case 0x06: /* control-f */ gnupg_forget_passphrase(); break; case 0x0C: /* control-l */ ui_refresh_windows(); break; case '/': case 'F': search_get(); break; case 'f': filter_get(); break; case 'E': action_list_export(); break; case 'I': if (!options->readonly) { folder_import_passwd(); uilist_refresh(); } else { statusline_readonly(); } break; case 'L': action_list_locate(); break; case 'l': action_list_launch(); break; case 0x0B: /* control-k (up) */ case '[': action_list_move_item_up(); break; case 0x0A: /* control-j (down) */ case ']': action_list_move_item_down(); break; #ifdef DEBUG case '$': debug_i++; snprintf(msg, 80, "Name %d", debug_i); folder_add(current_pw_sublist, msg, "myhost", "myuser", "mypasswd", "mylaucnh"); uilist_refresh(); break; #endif default: break; } } return 0; }
int action_list_move_item() { Pw* curpw; PWList *curpwl, *iter; int i; char str[STRING_LONG]; char answer[STRING_MEDIUM]; switch(uilist_get_highlighted_type()){ case PW_ITEM: curpw = uilist_get_highlighted_item(); if(curpw){ while(1){ snprintf(str, STRING_LONG, "Move \"%s\" to where?", curpw->name); ui_statusline_ask_str(str, answer, STRING_MEDIUM); /* if user just enters nothing do nothing */ if(answer[0] == 0){ return 0; } for(iter = current_pw_sublist->sublists; iter != NULL; iter = iter->next){ if( strcmp(iter->name, answer) == 0 ){ pwlist_detach_pw(current_pw_sublist, curpw); pwlist_add_ptr(iter, curpw); uilist_refresh(); return 0; } } ui_statusline_msg("Sublist does not exist, try again"); getch(); } } break; case PW_SUBLIST: curpwl = uilist_get_highlighted_sublist(); if(curpwl){ while(1){ snprintf(str, STRING_LONG, "Move sublist \"%s\" to where?", curpwl->name); ui_statusline_ask_str(str, answer, STRING_MEDIUM); /* if user just enters nothing, do nothing */ if(answer[0] == 0){ return 0; } if( strcmp(answer, curpwl->name) == 0 ){ return 0; } for(iter = current_pw_sublist->sublists; iter != NULL; iter = iter->next){ if( strcmp(iter->name, answer) == 0 ){ pwlist_detach_sublist(current_pw_sublist, curpwl); pwlist_add_sublist(iter, curpwl); uilist_refresh(); return 0; } } ui_statusline_msg("Sublist does not exist, try again"); getch(); } } break; case PW_UPLEVEL: case PW_NULL: default: /* do nothing */ break; } }
int action_list_add_pw() { Pw *pw; InputField fields[] = { {"Name:\t", NULL, STRING_MEDIUM, STRING}, {"Host:\t", NULL, STRING_MEDIUM, STRING}, {"User:\t", NULL, STRING_MEDIUM, STRING}, {"Password:\t", NULL, STRING_SHORT, STRING, pwgen_ask}, {"Launch Command:\t", NULL, STRING_LONG, STRING} }; int i, x; pw = pwlist_new_pw(); ui_statusline_ask_str(fields[0].name, pw->name, STRING_MEDIUM); ui_statusline_ask_str(fields[1].name, pw->host, STRING_MEDIUM); ui_statusline_ask_str(fields[2].name, pw->user, STRING_MEDIUM); /* int x = strlen(msg) + 5; if(input == NULL){ input = malloc(len); } statusline_clear(); statusline_msg(msg); echo(); show_cursor(); mvwgetnstr(bottom, 1, x, input, len); noecho(); hide_cursor(); statusline_clear();*/ ui_statusline_ask_str_with_autogen(fields[3].name, pw->passwd, STRING_SHORT, fields[3].autogen, 0x07); /* statusline_msg(fields[3].name); x = strlen(fields[3].name) + 5; if((i = getch()) == 0x07){ pw->passwd = fields[3].autogen(); } else { echo(); show_cursor(); mvwgetnstr(bottom, 1, x, pw->passwd, PASS_LEN); mvwaddch(bottom, 1, x, i); wmove(bottom, 1, x+1); noecho(); hide_cursor(); statusline_clear(); }*/ ui_statusline_ask_str(fields[4].name, pw->launch, STRING_LONG); fields[0].value = pw->name; fields[1].value = pw->host; fields[2].value = pw->user; fields[3].value = pw->passwd; fields[4].value = pw->launch; i = action_yes_no_dialog(fields, (sizeof(fields)/sizeof(InputField)), NULL, "Add this entry"); if(i){ pwlist_add_ptr(current_pw_sublist, pw); ui_statusline_msg("New password added"); } else { pwlist_free_pw(pw); ui_statusline_msg("New password cancelled"); } uilist_refresh(); }