2022-10-28 15:34:35 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cli/cli.h>
|
2022-11-23 22:19:19 +00:00
|
|
|
#include "../types/plugin_state.h"
|
2022-10-28 15:34:35 +00:00
|
|
|
|
|
|
|
#define TOTP_CLI_COMMAND_NAME "totp"
|
|
|
|
|
|
|
|
#define DOCOPT_ARGUMENT(arg) "<" arg ">"
|
2022-11-23 22:19:19 +00:00
|
|
|
#define DOCOPT_MULTIPLE(arg) arg "..."
|
2022-10-28 15:34:35 +00:00
|
|
|
#define DOCOPT_OPTIONAL(param) "[" param "]"
|
|
|
|
#define DOCOPT_REQUIRED(param) "(" param ")"
|
|
|
|
#define DOCOPT_OPTION(option, value) option " " value
|
|
|
|
#define DOCOPT_SWITCH(option) option
|
|
|
|
#define DOCOPT_OPTIONS "[options]"
|
|
|
|
#define DOCOPT_DEFAULT(val) "[default: " val "]"
|
|
|
|
|
2023-04-26 20:50:37 +00:00
|
|
|
extern const char* TOTP_CLI_COLOR_ERROR;
|
|
|
|
extern const char* TOTP_CLI_COLOR_WARNING;
|
|
|
|
extern const char* TOTP_CLI_COLOR_SUCCESS;
|
|
|
|
extern const char* TOTP_CLI_COLOR_INFO;
|
|
|
|
|
2023-04-05 19:45:27 +00:00
|
|
|
#define TOTP_CLI_PRINTF(format, ...) printf(format, ##__VA_ARGS__)
|
|
|
|
|
|
|
|
#define TOTP_CLI_PRINTF_COLORFUL(color, format, ...) \
|
2023-07-24 10:47:44 +00:00
|
|
|
TOTP_CLI_PRINTF("\e[%s" format "\e[0m", color, ##__VA_ARGS__)
|
2023-03-09 15:40:09 +00:00
|
|
|
|
|
|
|
#define TOTP_CLI_PRINTF_ERROR(format, ...) \
|
|
|
|
TOTP_CLI_PRINTF_COLORFUL(TOTP_CLI_COLOR_ERROR, format, ##__VA_ARGS__)
|
|
|
|
#define TOTP_CLI_PRINTF_WARNING(format, ...) \
|
|
|
|
TOTP_CLI_PRINTF_COLORFUL(TOTP_CLI_COLOR_WARNING, format, ##__VA_ARGS__)
|
|
|
|
#define TOTP_CLI_PRINTF_SUCCESS(format, ...) \
|
|
|
|
TOTP_CLI_PRINTF_COLORFUL(TOTP_CLI_COLOR_SUCCESS, format, ##__VA_ARGS__)
|
|
|
|
#define TOTP_CLI_PRINTF_INFO(format, ...) \
|
|
|
|
TOTP_CLI_PRINTF_COLORFUL(TOTP_CLI_COLOR_INFO, format, ##__VA_ARGS__)
|
|
|
|
|
2023-04-26 20:50:37 +00:00
|
|
|
#define TOTP_CLI_LOCK_UI(plugin_state) \
|
|
|
|
Scene __previous_scene = plugin_state->current_scene; \
|
|
|
|
totp_scene_director_activate_scene(plugin_state, TotpSceneStandby)
|
2022-10-28 15:34:35 +00:00
|
|
|
|
2023-04-26 20:50:37 +00:00
|
|
|
#define TOTP_CLI_UNLOCK_UI(plugin_state) \
|
|
|
|
totp_scene_director_activate_scene(plugin_state, __previous_scene)
|
2022-12-26 20:31:38 +00:00
|
|
|
|
2022-11-23 22:19:19 +00:00
|
|
|
/**
|
|
|
|
* @brief Checks whether user is authenticated and entered correct PIN.
|
|
|
|
* If user is not authenticated it prompts user to enter correct PIN to authenticate.
|
|
|
|
* @param plugin_state application state
|
2023-01-06 23:07:26 +00:00
|
|
|
* @param cli pointer to the firmware CLI subsystem
|
2022-11-23 22:19:19 +00:00
|
|
|
* @return \c true if user is already authenticated or successfully authenticated; \c false otherwise
|
|
|
|
*/
|
2022-11-10 05:32:21 +00:00
|
|
|
bool totp_cli_ensure_authenticated(const PluginState* plugin_state, Cli* cli);
|
2023-01-06 23:07:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Forces application to be instantly closed
|
|
|
|
* @param event_queue main app queue
|
|
|
|
*/
|
|
|
|
void totp_cli_force_close_app(FuriMessageQueue* event_queue);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Reads line of characters from console
|
|
|
|
* @param cli pointer to the firmware CLI subsystem
|
|
|
|
* @param out_str pointer to an output string to put read line to
|
|
|
|
* @param mask_user_input whether to mask input characters in console or not
|
|
|
|
* @return \c true if line successfully read and confirmed; \c false otherwise
|
|
|
|
*/
|
|
|
|
bool totp_cli_read_line(Cli* cli, FuriString* out_str, bool mask_user_input);
|
2023-04-01 14:45:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Extracts \c uint8_t value and trims arguments string
|
|
|
|
* @param args arguments string
|
|
|
|
* @param[out] value parsed value
|
|
|
|
* @return \c true if value successfully read and parsed as \c uint8_t ; \c false otherwise
|
|
|
|
*/
|
|
|
|
bool args_read_uint8_and_trim(FuriString* args, uint8_t* value);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Free \c FuriString instance in a secure manner by clearing it first
|
|
|
|
* @param str instance to free
|
|
|
|
*/
|
|
|
|
void furi_string_secure_free(FuriString* str);
|
2023-04-26 20:50:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Deletes last printed line in console
|
|
|
|
*/
|
|
|
|
void totp_cli_delete_last_line();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Deletes current printed line in console
|
|
|
|
*/
|
|
|
|
void totp_cli_delete_current_line();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Deletes last printed char in console
|
|
|
|
*/
|
|
|
|
void totp_cli_delete_last_char();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Prints error message about invalid command arguments
|
|
|
|
*/
|
|
|
|
void totp_cli_print_invalid_arguments();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Prints error message about config file update error
|
|
|
|
*/
|
|
|
|
void totp_cli_print_error_updating_config_file();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Prints error message about config file loading error
|
|
|
|
*/
|
|
|
|
void totp_cli_print_error_loading_token_info();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Prints message to let user knwo that command is processing now
|
|
|
|
*/
|
|
|
|
void totp_cli_print_processing();
|