2022-10-28 18:34:35 +03:00
|
|
|
#include "list.h"
|
|
|
|
#include <stdlib.h>
|
2022-11-24 01:19:19 +03:00
|
|
|
#include "../../../types/token_info.h"
|
|
|
|
#include "../../../services/config/constants.h"
|
2023-04-26 23:50:37 +03:00
|
|
|
#include "../../../services/config/config.h"
|
|
|
|
#include "../../../ui/scene_director.h"
|
2022-10-28 18:34:35 +03:00
|
|
|
#include "../../cli_helpers.h"
|
|
|
|
|
|
|
|
void totp_cli_command_list_docopt_commands() {
|
|
|
|
TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_LIST ", " TOTP_CLI_COMMAND_LIST_ALT
|
|
|
|
" List all available tokens\r\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void totp_cli_command_list_docopt_usage() {
|
|
|
|
TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_NAME " " DOCOPT_REQUIRED(
|
|
|
|
TOTP_CLI_COMMAND_LIST " | " TOTP_CLI_COMMAND_LIST_ALT) "\r\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void totp_cli_command_list_handle(PluginState* plugin_state, Cli* cli) {
|
|
|
|
if(!totp_cli_ensure_authenticated(plugin_state, cli)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-04-26 23:50:37 +03:00
|
|
|
TokenInfoIteratorContext* iterator_context =
|
|
|
|
totp_config_get_token_iterator_context(plugin_state);
|
|
|
|
size_t total_count = totp_token_info_iterator_get_total_count(iterator_context);
|
|
|
|
if(total_count <= 0) {
|
2022-10-28 18:34:35 +03:00
|
|
|
TOTP_CLI_PRINTF("There are no tokens");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-04-26 23:50:37 +03:00
|
|
|
TOTP_CLI_LOCK_UI(plugin_state);
|
|
|
|
|
|
|
|
size_t original_index = totp_token_info_iterator_get_current_token_index(iterator_context);
|
|
|
|
|
2023-01-18 19:52:33 +03:00
|
|
|
TOTP_CLI_PRINTF("+-----+---------------------------+--------+----+-----+\r\n");
|
2023-04-01 17:45:52 +03:00
|
|
|
TOTP_CLI_PRINTF("| %-3s | %-25s | %-6s | %-s | %-s |\r\n", "#", "Name", "Algo", "Ln", "Dur");
|
2023-01-18 19:52:33 +03:00
|
|
|
TOTP_CLI_PRINTF("+-----+---------------------------+--------+----+-----+\r\n");
|
2023-04-26 23:50:37 +03:00
|
|
|
for(size_t i = 0; i < total_count; i++) {
|
|
|
|
totp_token_info_iterator_go_to(iterator_context, i);
|
|
|
|
const TokenInfo* token_info = totp_token_info_iterator_get_current_token(iterator_context);
|
2022-10-28 18:34:35 +03:00
|
|
|
TOTP_CLI_PRINTF(
|
2023-01-18 19:52:33 +03:00
|
|
|
"| %-3" PRIu16 " | %-25.25s | %-6s | %-2" PRIu8 " | %-3" PRIu8 " |\r\n",
|
2023-04-26 23:50:37 +03:00
|
|
|
i + 1,
|
|
|
|
furi_string_get_cstr(token_info->name),
|
2023-04-01 17:45:52 +03:00
|
|
|
token_info_get_algo_as_cstr(token_info),
|
2023-01-18 19:52:33 +03:00
|
|
|
token_info->digits,
|
|
|
|
token_info->duration);
|
2023-04-26 23:50:37 +03:00
|
|
|
}
|
|
|
|
|
2023-01-18 19:52:33 +03:00
|
|
|
TOTP_CLI_PRINTF("+-----+---------------------------+--------+----+-----+\r\n");
|
2023-04-26 23:50:37 +03:00
|
|
|
|
|
|
|
totp_token_info_iterator_go_to(iterator_context, original_index);
|
|
|
|
|
|
|
|
TOTP_CLI_UNLOCK_UI(plugin_state);
|
2022-10-28 18:34:35 +03:00
|
|
|
}
|