2022-11-17 19:33:31 +00:00
|
|
|
#include "move.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <lib/toolbox/args.h>
|
2023-04-05 19:45:27 +00:00
|
|
|
#include <linked_list.h>
|
2022-11-23 22:19:19 +00:00
|
|
|
#include "../../../types/token_info.h"
|
|
|
|
#include "../../../services/config/config.h"
|
2022-11-17 19:33:31 +00:00
|
|
|
#include "../../cli_helpers.h"
|
2022-11-23 22:19:19 +00:00
|
|
|
#include "../../../ui/scene_director.h"
|
2023-04-01 14:45:52 +00:00
|
|
|
#include "../../common_command_arguments.h"
|
2022-11-17 19:33:31 +00:00
|
|
|
|
2023-04-01 14:45:52 +00:00
|
|
|
#define TOTP_CLI_COMMAND_MOVE_ARG_NEW_INDEX "new_index"
|
2022-11-17 19:33:31 +00:00
|
|
|
|
|
|
|
void totp_cli_command_move_docopt_commands() {
|
|
|
|
TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_MOVE ", " TOTP_CLI_COMMAND_MOVE_ALT
|
2023-04-01 14:45:52 +00:00
|
|
|
" Move token\r\n");
|
2022-11-17 19:33:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void totp_cli_command_move_docopt_usage() {
|
|
|
|
TOTP_CLI_PRINTF(
|
|
|
|
" " TOTP_CLI_COMMAND_NAME
|
2023-04-01 14:45:52 +00:00
|
|
|
" " DOCOPT_REQUIRED(TOTP_CLI_COMMAND_MOVE " | " TOTP_CLI_COMMAND_MOVE_ALT) " " DOCOPT_ARGUMENT(
|
|
|
|
TOTP_CLI_COMMAND_ARG_INDEX) " " DOCOPT_ARGUMENT(TOTP_CLI_COMMAND_MOVE_ARG_NEW_INDEX) "\r\n");
|
2022-11-17 19:33:31 +00:00
|
|
|
}
|
|
|
|
|
2023-04-01 14:45:52 +00:00
|
|
|
void totp_cli_command_move_docopt_arguments() {
|
|
|
|
TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_MOVE_ARG_NEW_INDEX
|
|
|
|
" New token index in the list\r\n");
|
2022-11-17 19:33:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void totp_cli_command_move_handle(PluginState* plugin_state, FuriString* args, Cli* cli) {
|
|
|
|
if(!totp_cli_ensure_authenticated(plugin_state, cli)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-04-01 14:45:52 +00:00
|
|
|
int token_index;
|
|
|
|
if(!args_read_int_and_trim(args, &token_index) || token_index < 1 ||
|
|
|
|
token_index > plugin_state->tokens_count) {
|
2022-11-17 19:33:31 +00:00
|
|
|
TOTP_CLI_PRINT_INVALID_ARGUMENTS();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int new_token_index = 0;
|
|
|
|
|
2023-04-01 14:45:52 +00:00
|
|
|
if(!args_read_int_and_trim(args, &new_token_index) || new_token_index < 1 ||
|
|
|
|
new_token_index > plugin_state->tokens_count) {
|
|
|
|
TOTP_CLI_PRINT_INVALID_ARGUMENTS();
|
2022-11-17 19:33:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool activate_generate_token_scene = false;
|
|
|
|
if(plugin_state->current_scene != TotpSceneAuthentication) {
|
|
|
|
totp_scene_director_activate_scene(plugin_state, TotpSceneNone, NULL);
|
|
|
|
activate_generate_token_scene = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
TokenInfo* token_info = NULL;
|
2023-04-01 14:45:52 +00:00
|
|
|
plugin_state->tokens_list =
|
|
|
|
list_remove_at(plugin_state->tokens_list, token_index - 1, (void**)&token_info);
|
|
|
|
furi_check(token_info != NULL);
|
|
|
|
plugin_state->tokens_list =
|
|
|
|
list_insert_at(plugin_state->tokens_list, new_token_index - 1, token_info);
|
|
|
|
|
|
|
|
if(totp_full_save_config_file(plugin_state) == TotpConfigFileUpdateSuccess) {
|
|
|
|
TOTP_CLI_PRINTF_SUCCESS(
|
|
|
|
"Token \"%s\" has been successfully updated\r\n", token_info->name);
|
2022-11-17 19:33:31 +00:00
|
|
|
} else {
|
2023-04-01 14:45:52 +00:00
|
|
|
TOTP_CLI_PRINT_ERROR_UPDATING_CONFIG_FILE();
|
2022-11-17 19:33:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(activate_generate_token_scene) {
|
|
|
|
totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken, NULL);
|
|
|
|
}
|
|
|
|
}
|