mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-12 12:28:36 -07:00
Temporarily backport app updates from apps repo
This commit is contained in:
129
applications/external/totp/cli/cli.c
vendored
129
applications/external/totp/cli/cli.c
vendored
@@ -1,23 +1,28 @@
|
||||
// Original idea: https://github.com/br0ziliy
|
||||
|
||||
#include "cli.h"
|
||||
#include <lib/toolbox/args.h>
|
||||
#include <flipper_application/flipper_application.h>
|
||||
#include <flipper_application/plugins/composite_resolver.h>
|
||||
#include <loader/firmware_api/firmware_api.h>
|
||||
#include "cli_helpers.h"
|
||||
#include "commands/list/list.h"
|
||||
#include "commands/add/add.h"
|
||||
#include "commands/update/update.h"
|
||||
#include "commands/delete/delete.h"
|
||||
#include "commands/timezone/timezone.h"
|
||||
#include "commands/help/help.h"
|
||||
#include "commands/move/move.h"
|
||||
#include "commands/pin/pin.h"
|
||||
#include "commands/notification/notification.h"
|
||||
#include "commands/reset/reset.h"
|
||||
#include "commands/automation/automation.h"
|
||||
#include "commands/details/details.h"
|
||||
#include "plugins/timezone/meta.h"
|
||||
#include "plugins/list/meta.h"
|
||||
#include "plugins/modify/add/meta.h"
|
||||
#include "plugins/modify/update/meta.h"
|
||||
#include "plugins/delete/meta.h"
|
||||
#include "plugins/help/meta.h"
|
||||
#include "plugins/move/meta.h"
|
||||
#include "plugins/pin/meta.h"
|
||||
#include "plugins/notification/meta.h"
|
||||
#include "plugins/reset/meta.h"
|
||||
#include "plugins/automation/meta.h"
|
||||
#include "plugins/details/meta.h"
|
||||
#include "plugins/version/meta.h"
|
||||
#include "cli_plugin_interface.h"
|
||||
#include "../app_api_interface.h"
|
||||
|
||||
struct TotpCliContext {
|
||||
PluginState* plugin_state;
|
||||
CompositeApiResolver* plugin_api_resolver;
|
||||
};
|
||||
|
||||
static void totp_cli_print_unknown_command(const FuriString* unknown_command) {
|
||||
@@ -27,57 +32,119 @@ static void totp_cli_print_unknown_command(const FuriString* unknown_command) {
|
||||
furi_string_get_cstr(unknown_command));
|
||||
}
|
||||
|
||||
static void run_external_cli_plugin_handler(
|
||||
const char* handler_name,
|
||||
TotpCliContext* cli_context,
|
||||
FuriString* args,
|
||||
Cli* cli) {
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
FlipperApplication* plugin_app = flipper_application_alloc(
|
||||
storage, composite_api_resolver_get(cli_context->plugin_api_resolver));
|
||||
do {
|
||||
FuriString* full_handler_path =
|
||||
furi_string_alloc_printf(EXT_PATH("apps_data/totp/plugins/%s.fal"), handler_name);
|
||||
FlipperApplicationPreloadStatus preload_res =
|
||||
flipper_application_preload(plugin_app, furi_string_get_cstr(full_handler_path));
|
||||
furi_string_free(full_handler_path);
|
||||
|
||||
if(preload_res != FlipperApplicationPreloadStatusSuccess) {
|
||||
TOTP_CLI_PRINTF_ERROR("Failed to preload plugin. Code: %d\r\n", preload_res);
|
||||
break;
|
||||
}
|
||||
|
||||
if(!flipper_application_is_plugin(plugin_app)) {
|
||||
TOTP_CLI_PRINTF_ERROR("Plugin file is not a library\r\n");
|
||||
break;
|
||||
}
|
||||
|
||||
FlipperApplicationLoadStatus load_status = flipper_application_map_to_memory(plugin_app);
|
||||
if(load_status != FlipperApplicationLoadStatusSuccess) {
|
||||
TOTP_CLI_PRINTF_ERROR("Failed to load plugin file. Code %d\r\n", load_status);
|
||||
break;
|
||||
}
|
||||
|
||||
const FlipperAppPluginDescriptor* app_descriptor =
|
||||
flipper_application_plugin_get_descriptor(plugin_app);
|
||||
|
||||
if(strcmp(app_descriptor->appid, PLUGIN_APP_ID) != 0) {
|
||||
TOTP_CLI_PRINTF_ERROR("Plugin doesn't seems to be a valid TOTP CLI plugin\r\n");
|
||||
break;
|
||||
}
|
||||
|
||||
if(app_descriptor->ep_api_version != PLUGIN_API_VERSION) {
|
||||
TOTP_CLI_PRINTF_ERROR(
|
||||
"Plugin version %" PRIu32 " is not compatible with your app version\r\n",
|
||||
app_descriptor->ep_api_version);
|
||||
break;
|
||||
}
|
||||
|
||||
const CliPlugin* plugin = app_descriptor->entry_point;
|
||||
|
||||
plugin->handle(cli_context->plugin_state, args, cli);
|
||||
} while(false);
|
||||
flipper_application_free(plugin_app);
|
||||
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
}
|
||||
|
||||
static void totp_cli_handler(Cli* cli, FuriString* args, void* context) {
|
||||
TotpCliContext* cli_context = context;
|
||||
PluginState* plugin_state = cli_context->plugin_state;
|
||||
|
||||
FuriString* cmd = furi_string_alloc();
|
||||
|
||||
args_read_string_and_trim(args, cmd);
|
||||
|
||||
const char* external_plugin_name = NULL;
|
||||
|
||||
if(furi_string_cmp_str(cmd, TOTP_CLI_COMMAND_HELP) == 0 ||
|
||||
furi_string_cmp_str(cmd, TOTP_CLI_COMMAND_HELP_ALT) == 0 ||
|
||||
furi_string_cmp_str(cmd, TOTP_CLI_COMMAND_HELP_ALT2) == 0 || furi_string_empty(cmd)) {
|
||||
totp_cli_command_help_handle();
|
||||
external_plugin_name = TOTP_CLI_PLUGIN_HELP_FILE_NAME;
|
||||
} else if(
|
||||
furi_string_cmp_str(cmd, TOTP_CLI_COMMAND_ADD) == 0 ||
|
||||
furi_string_cmp_str(cmd, TOTP_CLI_COMMAND_ADD_ALT) == 0 ||
|
||||
furi_string_cmp_str(cmd, TOTP_CLI_COMMAND_ADD_ALT2) == 0) {
|
||||
totp_cli_command_add_handle(plugin_state, args, cli);
|
||||
external_plugin_name = TOTP_CLI_PLUGIN_ADD_FILE_NAME;
|
||||
} else if(
|
||||
furi_string_cmp_str(cmd, TOTP_CLI_COMMAND_LIST) == 0 ||
|
||||
furi_string_cmp_str(cmd, TOTP_CLI_COMMAND_LIST_ALT) == 0) {
|
||||
totp_cli_command_list_handle(plugin_state, args, cli);
|
||||
external_plugin_name = TOTP_CLI_PLUGIN_LIST_FILE_NAME;
|
||||
} else if(
|
||||
furi_string_cmp_str(cmd, TOTP_CLI_COMMAND_DELETE) == 0 ||
|
||||
furi_string_cmp_str(cmd, TOTP_CLI_COMMAND_DELETE_ALT) == 0) {
|
||||
totp_cli_command_delete_handle(plugin_state, args, cli);
|
||||
external_plugin_name = TOTP_CLI_PLUGIN_DELETE_FILE_NAME;
|
||||
} else if(
|
||||
furi_string_cmp_str(cmd, TOTP_CLI_COMMAND_TIMEZONE) == 0 ||
|
||||
furi_string_cmp_str(cmd, TOTP_CLI_COMMAND_TIMEZONE_ALT) == 0) {
|
||||
totp_cli_command_timezone_handle(plugin_state, args, cli);
|
||||
external_plugin_name = TOTP_CLI_PLUGIN_TIMEZONE_FILE_NAME;
|
||||
} else if(
|
||||
furi_string_cmp_str(cmd, TOTP_CLI_COMMAND_MOVE) == 0 ||
|
||||
furi_string_cmp_str(cmd, TOTP_CLI_COMMAND_MOVE_ALT) == 0) {
|
||||
totp_cli_command_move_handle(plugin_state, args, cli);
|
||||
external_plugin_name = TOTP_CLI_PLUGIN_MOVE_FILE_NAME;
|
||||
} else if(furi_string_cmp_str(cmd, TOTP_CLI_COMMAND_PIN) == 0) {
|
||||
totp_cli_command_pin_handle(plugin_state, args, cli);
|
||||
external_plugin_name = TOTP_CLI_PLUGIN_PIN_FILE_NAME;
|
||||
} else if(furi_string_cmp_str(cmd, TOTP_CLI_COMMAND_NOTIFICATION) == 0) {
|
||||
totp_cli_command_notification_handle(plugin_state, args, cli);
|
||||
external_plugin_name = TOTP_CLI_PLUGIN_NOTIFICATION_FILE_NAME;
|
||||
} else if(furi_string_cmp_str(cmd, TOTP_CLI_COMMAND_AUTOMATION) == 0) {
|
||||
totp_cli_command_automation_handle(plugin_state, args, cli);
|
||||
external_plugin_name = TOTP_CLI_PLUGIN_AUTOMATION_FILE_NAME;
|
||||
} else if(furi_string_cmp_str(cmd, TOTP_CLI_COMMAND_RESET) == 0) {
|
||||
totp_cli_command_reset_handle(plugin_state, cli);
|
||||
external_plugin_name = TOTP_CLI_PLUGIN_RESET_FILE_NAME;
|
||||
} else if(furi_string_cmp_str(cmd, TOTP_CLI_COMMAND_UPDATE) == 0) {
|
||||
totp_cli_command_update_handle(plugin_state, args, cli);
|
||||
external_plugin_name = TOTP_CLI_PLUGIN_UPDATE_FILE_NAME;
|
||||
} else if(
|
||||
furi_string_cmp_str(cmd, TOTP_CLI_COMMAND_DETAILS) == 0 ||
|
||||
furi_string_cmp_str(cmd, TOTP_CLI_COMMAND_DETAILS_ALT) == 0) {
|
||||
totp_cli_command_details_handle(plugin_state, args, cli);
|
||||
external_plugin_name = TOTP_CLI_PLUGIN_DETAILS_FILE_NAME;
|
||||
} else if(furi_string_cmp_str(cmd, TOTP_CLI_COMMAND_VERSION) == 0) {
|
||||
external_plugin_name = TOTP_CLI_PLUGIN_VERSION_FILE_NAME;
|
||||
} else {
|
||||
totp_cli_print_unknown_command(cmd);
|
||||
}
|
||||
|
||||
if(external_plugin_name != NULL) {
|
||||
run_external_cli_plugin_handler(external_plugin_name, cli_context, args, cli);
|
||||
}
|
||||
|
||||
furi_string_free(cmd);
|
||||
}
|
||||
|
||||
@@ -86,6 +153,11 @@ TotpCliContext* totp_cli_register_command_handler(PluginState* plugin_state) {
|
||||
TotpCliContext* context = malloc(sizeof(TotpCliContext));
|
||||
furi_check(context != NULL);
|
||||
context->plugin_state = plugin_state;
|
||||
|
||||
context->plugin_api_resolver = composite_api_resolver_alloc();
|
||||
composite_api_resolver_add(context->plugin_api_resolver, firmware_api_interface);
|
||||
composite_api_resolver_add(context->plugin_api_resolver, application_api_interface);
|
||||
|
||||
cli_add_command(
|
||||
cli, TOTP_CLI_COMMAND_NAME, CliCommandFlagParallelSafe, totp_cli_handler, context);
|
||||
furi_record_close(RECORD_CLI);
|
||||
@@ -95,6 +167,9 @@ TotpCliContext* totp_cli_register_command_handler(PluginState* plugin_state) {
|
||||
void totp_cli_unregister_command_handler(TotpCliContext* context) {
|
||||
Cli* cli = furi_record_open(RECORD_CLI);
|
||||
cli_delete_command(cli, TOTP_CLI_COMMAND_NAME);
|
||||
|
||||
composite_api_resolver_free(context->plugin_api_resolver);
|
||||
|
||||
furi_record_close(RECORD_CLI);
|
||||
free(context);
|
||||
}
|
||||
109
applications/external/totp/cli/cli_helpers.h
vendored
109
applications/external/totp/cli/cli_helpers.h
vendored
@@ -1,23 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <cli/cli.h>
|
||||
#include "../types/plugin_state.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define TOTP_CLI_COMMAND_NAME "totp"
|
||||
|
||||
#define DOCOPT_ARGUMENT(arg) "<" arg ">"
|
||||
#define DOCOPT_MULTIPLE(arg) arg "..."
|
||||
#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 "]"
|
||||
|
||||
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;
|
||||
#define TOTP_CLI_COLOR_ERROR "91m"
|
||||
#define TOTP_CLI_COLOR_WARNING "93m"
|
||||
#define TOTP_CLI_COLOR_SUCCESS "92m"
|
||||
#define TOTP_CLI_COLOR_INFO "96m"
|
||||
|
||||
#define TOTP_CLI_PRINTF(format, ...) printf(format, ##__VA_ARGS__)
|
||||
|
||||
@@ -42,75 +36,30 @@ extern const char* TOTP_CLI_COLOR_INFO;
|
||||
totp_scene_director_activate_scene(plugin_state, __previous_scene); \
|
||||
totp_scene_director_force_redraw(plugin_state)
|
||||
|
||||
/**
|
||||
* @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
|
||||
* @param cli pointer to the firmware CLI subsystem
|
||||
* @return \c true if user is already authenticated or successfully authenticated; \c false otherwise
|
||||
*/
|
||||
bool totp_cli_ensure_authenticated(const PluginState* plugin_state, Cli* cli);
|
||||
#define TOTP_CLI_PRINT_INVALID_ARGUMENTS() \
|
||||
TOTP_CLI_PRINTF_ERROR( \
|
||||
"Invalid command arguments. use \"help\" command to get list of available commands")
|
||||
|
||||
/**
|
||||
* @brief Forces application to be instantly closed
|
||||
* @param event_queue main app queue
|
||||
*/
|
||||
void totp_cli_force_close_app(FuriMessageQueue* event_queue);
|
||||
#define TOTP_CLI_PRINT_ERROR_UPDATING_CONFIG_FILE() \
|
||||
TOTP_CLI_PRINTF_ERROR("An error has occurred during updating config file\r\n")
|
||||
|
||||
/**
|
||||
* @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);
|
||||
#define TOTP_CLI_PRINT_ERROR_LOADING_TOKEN_INFO() \
|
||||
TOTP_CLI_PRINTF_ERROR("An error has occurred during loading token information\r\n")
|
||||
|
||||
/**
|
||||
* @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);
|
||||
#define TOTP_CLI_PRINT_PROCESSING() TOTP_CLI_PRINTF("Processing, please wait...\r\n")
|
||||
|
||||
/**
|
||||
* @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);
|
||||
#define TOTP_CLI_DELETE_LAST_CHAR() \
|
||||
TOTP_CLI_PRINTF("\b \b"); \
|
||||
fflush(stdout)
|
||||
|
||||
/**
|
||||
* @brief Deletes last printed line in console
|
||||
*/
|
||||
void totp_cli_delete_last_line();
|
||||
#define TOTP_CLI_DELETE_CURRENT_LINE() \
|
||||
TOTP_CLI_PRINTF("\33[2K\r"); \
|
||||
fflush(stdout)
|
||||
|
||||
/**
|
||||
* @brief Deletes current printed line in console
|
||||
*/
|
||||
void totp_cli_delete_current_line();
|
||||
#define TOTP_CLI_DELETE_LAST_LINE() \
|
||||
TOTP_CLI_PRINTF("\033[A\33[2K\r"); \
|
||||
fflush(stdout)
|
||||
|
||||
/**
|
||||
* @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 know that command is processing now
|
||||
*/
|
||||
void totp_cli_print_processing();
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
13
applications/external/totp/cli/cli_plugin_interface.h
vendored
Normal file
13
applications/external/totp/cli/cli_plugin_interface.h
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <cli/cli.h>
|
||||
#include <furi/core/string.h>
|
||||
#include "../types/plugin_state.h"
|
||||
|
||||
#define PLUGIN_APP_ID "totp_cli"
|
||||
#define PLUGIN_API_VERSION 1
|
||||
|
||||
typedef struct {
|
||||
const char* name;
|
||||
void (*handle)(PluginState*, FuriString*, Cli*);
|
||||
} CliPlugin;
|
||||
@@ -1,13 +1,9 @@
|
||||
#include "cli_helpers.h"
|
||||
#include "cli_shared_methods.h"
|
||||
#include <cli/cli.h>
|
||||
#include <lib/toolbox/args.h>
|
||||
#include "cli_helpers.h"
|
||||
#include "../types/plugin_event.h"
|
||||
|
||||
const char* TOTP_CLI_COLOR_ERROR = "91m";
|
||||
const char* TOTP_CLI_COLOR_WARNING = "93m";
|
||||
const char* TOTP_CLI_COLOR_SUCCESS = "92m";
|
||||
const char* TOTP_CLI_COLOR_INFO = "96m";
|
||||
|
||||
bool totp_cli_ensure_authenticated(const PluginState* plugin_state, Cli* cli) {
|
||||
if(plugin_state->current_scene == TotpSceneAuthentication) {
|
||||
TOTP_CLI_PRINTF("Pleases enter PIN on your flipper device\r\n");
|
||||
@@ -18,7 +14,7 @@ bool totp_cli_ensure_authenticated(const PluginState* plugin_state, Cli* cli) {
|
||||
furi_delay_ms(100);
|
||||
}
|
||||
|
||||
totp_cli_delete_last_line();
|
||||
TOTP_CLI_DELETE_LAST_LINE();
|
||||
|
||||
if(plugin_state->current_scene == TotpSceneAuthentication || //-V560
|
||||
plugin_state->current_scene == TotpSceneNone) { //-V560
|
||||
@@ -60,7 +56,7 @@ bool totp_cli_read_line(Cli* cli, FuriString* out_str, bool mask_user_input) {
|
||||
} else if(c == CliSymbolAsciiBackspace || c == CliSymbolAsciiDel) {
|
||||
size_t out_str_size = furi_string_size(out_str);
|
||||
if(out_str_size > 0) {
|
||||
totp_cli_delete_last_char();
|
||||
TOTP_CLI_DELETE_LAST_CHAR();
|
||||
furi_string_left(out_str, out_str_size - 1);
|
||||
}
|
||||
} else if(c == CliSymbolAsciiCR) {
|
||||
@@ -90,34 +86,10 @@ void furi_string_secure_free(FuriString* str) {
|
||||
furi_string_free(str);
|
||||
}
|
||||
|
||||
void totp_cli_print_invalid_arguments() {
|
||||
TOTP_CLI_PRINTF_ERROR(
|
||||
"Invalid command arguments. use \"help\" command to get list of available commands");
|
||||
void totp_cli_printf_missed_argument_value(char* arg) {
|
||||
TOTP_CLI_PRINTF_ERROR("Missed or incorrect value for argument \"%s\"\r\n", arg);
|
||||
}
|
||||
|
||||
void totp_cli_print_error_updating_config_file() {
|
||||
TOTP_CLI_PRINTF_ERROR("An error has occurred during updating config file\r\n");
|
||||
}
|
||||
|
||||
void totp_cli_print_error_loading_token_info() {
|
||||
TOTP_CLI_PRINTF_ERROR("An error has occurred during loading token information\r\n");
|
||||
}
|
||||
|
||||
void totp_cli_print_processing() {
|
||||
TOTP_CLI_PRINTF("Processing, please wait...\r\n");
|
||||
}
|
||||
|
||||
void totp_cli_delete_last_char() {
|
||||
TOTP_CLI_PRINTF("\b \b");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
void totp_cli_delete_current_line() {
|
||||
TOTP_CLI_PRINTF("\33[2K\r");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
void totp_cli_delete_last_line() {
|
||||
TOTP_CLI_PRINTF("\033[A\33[2K\r");
|
||||
fflush(stdout);
|
||||
}
|
||||
void totp_cli_printf_unknown_argument(const FuriString* arg) {
|
||||
TOTP_CLI_PRINTF("Unknown argument \"%s\"\r\n", furi_string_get_cstr(arg));
|
||||
}
|
||||
62
applications/external/totp/cli/cli_shared_methods.h
vendored
Normal file
62
applications/external/totp/cli/cli_shared_methods.h
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
#pragma once
|
||||
|
||||
#include <cli/cli.h>
|
||||
#include "../types/plugin_state.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @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
|
||||
* @param cli pointer to the firmware CLI subsystem
|
||||
* @return \c true if user is already authenticated or successfully authenticated; \c false otherwise
|
||||
*/
|
||||
bool totp_cli_ensure_authenticated(const PluginState* plugin_state, Cli* cli);
|
||||
|
||||
/**
|
||||
* @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);
|
||||
|
||||
/**
|
||||
* @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);
|
||||
|
||||
/**
|
||||
* @brief Prints information about unknown argument
|
||||
* @param arg
|
||||
*/
|
||||
void totp_cli_printf_unknown_argument(const FuriString* arg);
|
||||
|
||||
/**
|
||||
* @brief Prints information about missed required argument
|
||||
* @param arg
|
||||
*/
|
||||
void totp_cli_printf_missed_argument_value(char* arg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
192
applications/external/totp/cli/commands/add/add.c
vendored
192
applications/external/totp/cli/commands/add/add.c
vendored
@@ -1,192 +0,0 @@
|
||||
#include "add.h"
|
||||
#include <stdlib.h>
|
||||
#include <lib/toolbox/args.h>
|
||||
#include "../../../types/token_info.h"
|
||||
#include "../../../services/config/config.h"
|
||||
#include "../../../services/convert/convert.h"
|
||||
#include "../../cli_helpers.h"
|
||||
#include "../../../ui/scene_director.h"
|
||||
#include "../../common_command_arguments.h"
|
||||
|
||||
struct TotpAddContext {
|
||||
FuriString* args;
|
||||
Cli* cli;
|
||||
const CryptoSettings* crypto_settings;
|
||||
};
|
||||
|
||||
enum TotpIteratorUpdateTokenResultsEx {
|
||||
TotpIteratorUpdateTokenResultInvalidSecret = 1,
|
||||
TotpIteratorUpdateTokenResultCancelled = 2,
|
||||
TotpIteratorUpdateTokenResultInvalidArguments = 3
|
||||
};
|
||||
|
||||
static TotpIteratorUpdateTokenResult
|
||||
add_token_handler(TokenInfo* token_info, const void* context) {
|
||||
const struct TotpAddContext* context_t = context;
|
||||
|
||||
// Reading token name
|
||||
if(!args_read_probably_quoted_string_and_trim(context_t->args, token_info->name)) {
|
||||
return TotpIteratorUpdateTokenResultInvalidArguments;
|
||||
}
|
||||
|
||||
FuriString* temp_str = furi_string_alloc();
|
||||
|
||||
// Read optional arguments
|
||||
bool mask_user_input = true;
|
||||
PlainTokenSecretEncoding token_secret_encoding = PlainTokenSecretEncodingBase32;
|
||||
while(args_read_string_and_trim(context_t->args, temp_str)) {
|
||||
bool parsed = false;
|
||||
if(!totp_cli_try_read_algo(token_info, temp_str, context_t->args, &parsed) &&
|
||||
!totp_cli_try_read_digits(token_info, temp_str, context_t->args, &parsed) &&
|
||||
!totp_cli_try_read_duration(token_info, temp_str, context_t->args, &parsed) &&
|
||||
!totp_cli_try_read_unsecure_flag(temp_str, &parsed, &mask_user_input) &&
|
||||
!totp_cli_try_read_automation_features(token_info, temp_str, context_t->args, &parsed) &&
|
||||
!totp_cli_try_read_plain_token_secret_encoding(
|
||||
temp_str, context_t->args, &parsed, &token_secret_encoding)) {
|
||||
totp_cli_printf_unknown_argument(temp_str);
|
||||
}
|
||||
|
||||
if(!parsed) {
|
||||
furi_string_free(temp_str);
|
||||
return TotpIteratorUpdateTokenResultInvalidArguments;
|
||||
}
|
||||
}
|
||||
|
||||
// Reading token secret
|
||||
furi_string_reset(temp_str);
|
||||
TOTP_CLI_PRINTF("Enter token secret and confirm with [ENTER]:\r\n");
|
||||
if(!totp_cli_read_line(context_t->cli, temp_str, mask_user_input)) {
|
||||
totp_cli_delete_last_line();
|
||||
furi_string_secure_free(temp_str);
|
||||
return TotpIteratorUpdateTokenResultCancelled;
|
||||
}
|
||||
|
||||
totp_cli_delete_last_line();
|
||||
|
||||
bool secret_set = token_info_set_secret(
|
||||
token_info,
|
||||
furi_string_get_cstr(temp_str),
|
||||
furi_string_size(temp_str),
|
||||
token_secret_encoding,
|
||||
context_t->crypto_settings);
|
||||
|
||||
furi_string_secure_free(temp_str);
|
||||
|
||||
if(!secret_set) {
|
||||
return TotpIteratorUpdateTokenResultInvalidSecret;
|
||||
}
|
||||
|
||||
return TotpIteratorUpdateTokenResultSuccess;
|
||||
}
|
||||
|
||||
#ifdef TOTP_CLI_RICH_HELP_ENABLED
|
||||
void totp_cli_command_add_docopt_commands() {
|
||||
TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_ADD ", " TOTP_CLI_COMMAND_ADD_ALT
|
||||
", " TOTP_CLI_COMMAND_ADD_ALT2 " Add new token\r\n");
|
||||
}
|
||||
|
||||
void totp_cli_command_add_docopt_usage() {
|
||||
TOTP_CLI_PRINTF(
|
||||
" " TOTP_CLI_COMMAND_NAME
|
||||
" " DOCOPT_REQUIRED(TOTP_CLI_COMMAND_ADD " | " TOTP_CLI_COMMAND_ADD_ALT " | " TOTP_CLI_COMMAND_ADD_ALT2) " " DOCOPT_ARGUMENT(TOTP_CLI_COMMAND_ARG_NAME) " " DOCOPT_OPTIONAL(DOCOPT_OPTION(TOTP_CLI_COMMAND_ARG_ALGO_PREFIX, DOCOPT_ARGUMENT(TOTP_CLI_COMMAND_ARG_ALGO))) " " DOCOPT_OPTIONAL(DOCOPT_OPTION(TOTP_CLI_COMMAND_ARG_SECRET_ENCODING_PREFIX, DOCOPT_ARGUMENT(TOTP_CLI_COMMAND_ARG_SECRET_ENCODING))) " " DOCOPT_OPTIONAL(
|
||||
DOCOPT_OPTION(
|
||||
TOTP_CLI_COMMAND_ARG_DIGITS_PREFIX,
|
||||
DOCOPT_ARGUMENT(
|
||||
TOTP_CLI_COMMAND_ARG_DIGITS))) " " DOCOPT_OPTIONAL(DOCOPT_OPTION(TOTP_CLI_COMMAND_ARG_DURATION_PREFIX, DOCOPT_ARGUMENT(TOTP_CLI_COMMAND_ARG_DURATION))) " " DOCOPT_OPTIONAL(DOCOPT_SWITCH(TOTP_CLI_COMMAND_ARG_UNSECURE_PREFIX)) " " DOCOPT_MULTIPLE(DOCOPT_OPTIONAL(DOCOPT_OPTION(TOTP_CLI_COMMAND_ARG_AUTOMATION_FEATURE_PREFIX, DOCOPT_ARGUMENT(TOTP_CLI_COMMAND_ARG_AUTOMATION_FEATURE)))) "\r\n");
|
||||
}
|
||||
|
||||
void totp_cli_command_add_docopt_arguments() {
|
||||
TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_ARG_NAME " Token name\r\n");
|
||||
}
|
||||
|
||||
void totp_cli_command_add_docopt_options() {
|
||||
TOTP_CLI_PRINTF(" " DOCOPT_OPTION(
|
||||
TOTP_CLI_COMMAND_ARG_ALGO_PREFIX,
|
||||
DOCOPT_ARGUMENT(
|
||||
TOTP_CLI_COMMAND_ARG_ALGO)) " Token hashing algorithm. Must be one of: " TOKEN_HASH_ALGO_SHA1_NAME
|
||||
", " TOKEN_HASH_ALGO_SHA256_NAME
|
||||
", " TOKEN_HASH_ALGO_SHA512_NAME
|
||||
", " TOKEN_HASH_ALGO_STEAM_NAME
|
||||
" " DOCOPT_DEFAULT(TOKEN_HASH_ALGO_SHA1_NAME) "\r\n");
|
||||
TOTP_CLI_PRINTF(
|
||||
" " DOCOPT_OPTION(
|
||||
TOTP_CLI_COMMAND_ARG_DIGITS_PREFIX,
|
||||
DOCOPT_ARGUMENT(
|
||||
TOTP_CLI_COMMAND_ARG_DIGITS)) " Number of digits to generate, one of: %" PRIu8
|
||||
", %" PRIu8 ", %" PRIu8
|
||||
" " DOCOPT_DEFAULT("%" PRIu8) "\r\n",
|
||||
TokenDigitsCountFive,
|
||||
TokenDigitsCountSix,
|
||||
TokenDigitsCountEight,
|
||||
TokenDigitsCountSix);
|
||||
|
||||
TOTP_CLI_PRINTF(" " DOCOPT_OPTION(
|
||||
TOTP_CLI_COMMAND_ARG_SECRET_ENCODING_PREFIX,
|
||||
DOCOPT_ARGUMENT(
|
||||
TOTP_CLI_COMMAND_ARG_SECRET_ENCODING)) " Token secret encoding, one of " PLAIN_TOKEN_ENCODING_BASE32_NAME
|
||||
", " PLAIN_TOKEN_ENCODING_BASE64_NAME
|
||||
" " DOCOPT_DEFAULT(
|
||||
PLAIN_TOKEN_ENCODING_BASE32_NAME) "\r\n");
|
||||
|
||||
TOTP_CLI_PRINTF(
|
||||
" " DOCOPT_OPTION(
|
||||
TOTP_CLI_COMMAND_ARG_DURATION_PREFIX,
|
||||
DOCOPT_ARGUMENT(
|
||||
TOTP_CLI_COMMAND_ARG_DURATION)) " Token lifetime duration in seconds, between: %" PRIu8
|
||||
" and %" PRIu8
|
||||
" " DOCOPT_DEFAULT("%" PRIu8) "\r\n",
|
||||
TokenDurationMin,
|
||||
TokenDurationMax,
|
||||
TokenDurationDefault);
|
||||
TOTP_CLI_PRINTF(" " DOCOPT_SWITCH(
|
||||
TOTP_CLI_COMMAND_ARG_UNSECURE_PREFIX) " Show console user input as-is without masking\r\n");
|
||||
TOTP_CLI_PRINTF(" " DOCOPT_OPTION(
|
||||
TOTP_CLI_COMMAND_ARG_AUTOMATION_FEATURE_PREFIX,
|
||||
DOCOPT_ARGUMENT(
|
||||
TOTP_CLI_COMMAND_ARG_AUTOMATION_FEATURE)) " Token automation features to be enabled. Must be one of: " TOKEN_AUTOMATION_FEATURE_NONE_NAME
|
||||
", " TOKEN_AUTOMATION_FEATURE_ENTER_AT_THE_END_NAME
|
||||
", " TOKEN_AUTOMATION_FEATURE_TAB_AT_THE_END_NAME
|
||||
" " DOCOPT_DEFAULT(
|
||||
TOKEN_AUTOMATION_FEATURE_NONE_NAME) "\r\n");
|
||||
TOTP_CLI_PRINTF(" # " TOKEN_AUTOMATION_FEATURE_NONE_NAME " - No features\r\n");
|
||||
TOTP_CLI_PRINTF(" # " TOKEN_AUTOMATION_FEATURE_ENTER_AT_THE_END_NAME
|
||||
" - Type <Enter> key at the end of token input automation\r\n");
|
||||
TOTP_CLI_PRINTF(" # " TOKEN_AUTOMATION_FEATURE_TAB_AT_THE_END_NAME
|
||||
" - Type <Tab> key at the end of token input automation\r\n");
|
||||
TOTP_CLI_PRINTF(" # " TOKEN_AUTOMATION_FEATURE_TYPE_SLOWER_NAME
|
||||
" - Type slower\r\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
void totp_cli_command_add_handle(PluginState* plugin_state, FuriString* args, Cli* cli) {
|
||||
if(!totp_cli_ensure_authenticated(plugin_state, cli)) {
|
||||
return;
|
||||
}
|
||||
|
||||
TokenInfoIteratorContext* iterator_context =
|
||||
totp_config_get_token_iterator_context(plugin_state);
|
||||
|
||||
TOTP_CLI_LOCK_UI(plugin_state);
|
||||
|
||||
struct TotpAddContext add_context = {
|
||||
.args = args, .cli = cli, .crypto_settings = &plugin_state->crypto_settings};
|
||||
TotpIteratorUpdateTokenResult add_result =
|
||||
totp_token_info_iterator_add_new_token(iterator_context, &add_token_handler, &add_context);
|
||||
|
||||
if(add_result == TotpIteratorUpdateTokenResultSuccess) {
|
||||
TOTP_CLI_PRINTF_SUCCESS(
|
||||
"Token \"%s\" has been successfully added\r\n",
|
||||
furi_string_get_cstr(
|
||||
totp_token_info_iterator_get_current_token(iterator_context)->name));
|
||||
} else if(add_result == TotpIteratorUpdateTokenResultCancelled) {
|
||||
TOTP_CLI_PRINTF_INFO("Cancelled by user\r\n");
|
||||
} else if(add_result == TotpIteratorUpdateTokenResultInvalidArguments) {
|
||||
totp_cli_print_invalid_arguments();
|
||||
} else if(add_result == TotpIteratorUpdateTokenResultInvalidSecret) {
|
||||
TOTP_CLI_PRINTF_ERROR("Token secret seems to be invalid and can not be parsed\r\n");
|
||||
} else if(add_result == TotpIteratorUpdateTokenResultFileUpdateFailed) {
|
||||
totp_cli_print_error_updating_config_file();
|
||||
}
|
||||
|
||||
TOTP_CLI_UNLOCK_UI(plugin_state);
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <cli/cli.h>
|
||||
#include "../../../config/app/config.h"
|
||||
#include "../../../types/plugin_state.h"
|
||||
|
||||
#define TOTP_CLI_COMMAND_ADD "add"
|
||||
#define TOTP_CLI_COMMAND_ADD_ALT "mk"
|
||||
#define TOTP_CLI_COMMAND_ADD_ALT2 "new"
|
||||
|
||||
void totp_cli_command_add_handle(PluginState* plugin_state, FuriString* args, Cli* cli);
|
||||
#ifdef TOTP_CLI_RICH_HELP_ENABLED
|
||||
void totp_cli_command_add_docopt_commands();
|
||||
void totp_cli_command_add_docopt_usage();
|
||||
void totp_cli_command_add_docopt_arguments();
|
||||
void totp_cli_command_add_docopt_options();
|
||||
#endif
|
||||
@@ -1,15 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <cli/cli.h>
|
||||
#include "../../../types/plugin_state.h"
|
||||
#include "../../../config/app/config.h"
|
||||
|
||||
#define TOTP_CLI_COMMAND_AUTOMATION "automation"
|
||||
|
||||
void totp_cli_command_automation_handle(PluginState* plugin_state, FuriString* args, Cli* cli);
|
||||
#ifdef TOTP_CLI_RICH_HELP_ENABLED
|
||||
void totp_cli_command_automation_docopt_commands();
|
||||
void totp_cli_command_automation_docopt_usage();
|
||||
void totp_cli_command_automation_docopt_arguments();
|
||||
void totp_cli_command_automation_docopt_options();
|
||||
#endif
|
||||
@@ -1,16 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <cli/cli.h>
|
||||
#include "../../../types/plugin_state.h"
|
||||
#include "../../../config/app/config.h"
|
||||
|
||||
#define TOTP_CLI_COMMAND_DELETE "delete"
|
||||
#define TOTP_CLI_COMMAND_DELETE_ALT "rm"
|
||||
|
||||
void totp_cli_command_delete_handle(PluginState* plugin_state, FuriString* args, Cli* cli);
|
||||
#ifdef TOTP_CLI_RICH_HELP_ENABLED
|
||||
void totp_cli_command_delete_docopt_commands();
|
||||
void totp_cli_command_delete_docopt_usage();
|
||||
void totp_cli_command_delete_docopt_arguments();
|
||||
void totp_cli_command_delete_docopt_options();
|
||||
#endif
|
||||
@@ -1,14 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <cli/cli.h>
|
||||
#include "../../../types/plugin_state.h"
|
||||
#include "../../../config/app/config.h"
|
||||
|
||||
#define TOTP_CLI_COMMAND_DETAILS "lsattr"
|
||||
#define TOTP_CLI_COMMAND_DETAILS_ALT "cat"
|
||||
|
||||
void totp_cli_command_details_handle(PluginState* plugin_state, FuriString* args, Cli* cli);
|
||||
#ifdef TOTP_CLI_RICH_HELP_ENABLED
|
||||
void totp_cli_command_details_docopt_commands();
|
||||
void totp_cli_command_details_docopt_usage();
|
||||
#endif
|
||||
@@ -1,76 +0,0 @@
|
||||
#include "help.h"
|
||||
#include "../../cli_helpers.h"
|
||||
#include "../add/add.h"
|
||||
#include "../update/update.h"
|
||||
#include "../delete/delete.h"
|
||||
#include "../list/list.h"
|
||||
#include "../timezone/timezone.h"
|
||||
#include "../move/move.h"
|
||||
#include "../pin/pin.h"
|
||||
#include "../notification/notification.h"
|
||||
#include "../reset/reset.h"
|
||||
#include "../automation/automation.h"
|
||||
#include "../details/details.h"
|
||||
|
||||
#ifdef TOTP_CLI_RICH_HELP_ENABLED
|
||||
void totp_cli_command_help_docopt_commands() {
|
||||
TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_HELP ", " TOTP_CLI_COMMAND_HELP_ALT
|
||||
", " TOTP_CLI_COMMAND_HELP_ALT2 " Show command usage help\r\n");
|
||||
}
|
||||
|
||||
void totp_cli_command_help_docopt_usage() {
|
||||
TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_NAME " " DOCOPT_REQUIRED(
|
||||
TOTP_CLI_COMMAND_HELP " | " TOTP_CLI_COMMAND_HELP_ALT
|
||||
" | " TOTP_CLI_COMMAND_HELP_ALT2) "\r\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
void totp_cli_command_help_handle() {
|
||||
#ifdef TOTP_CLI_RICH_HELP_ENABLED
|
||||
TOTP_CLI_PRINTF("Usage:\r\n");
|
||||
totp_cli_command_help_docopt_usage();
|
||||
totp_cli_command_list_docopt_usage();
|
||||
totp_cli_command_details_docopt_usage();
|
||||
totp_cli_command_add_docopt_usage();
|
||||
totp_cli_command_update_docopt_usage();
|
||||
totp_cli_command_delete_docopt_usage();
|
||||
totp_cli_command_timezone_docopt_usage();
|
||||
totp_cli_command_move_docopt_usage();
|
||||
totp_cli_command_pin_docopt_usage();
|
||||
totp_cli_command_notification_docopt_usage();
|
||||
totp_cli_command_reset_docopt_usage();
|
||||
totp_cli_command_automation_docopt_usage();
|
||||
cli_nl();
|
||||
TOTP_CLI_PRINTF("Commands:\r\n");
|
||||
totp_cli_command_help_docopt_commands();
|
||||
totp_cli_command_list_docopt_commands();
|
||||
totp_cli_command_details_docopt_commands();
|
||||
totp_cli_command_add_docopt_commands();
|
||||
totp_cli_command_update_docopt_commands();
|
||||
totp_cli_command_delete_docopt_commands();
|
||||
totp_cli_command_timezone_docopt_commands();
|
||||
totp_cli_command_move_docopt_commands();
|
||||
totp_cli_command_pin_docopt_commands();
|
||||
totp_cli_command_notification_docopt_commands();
|
||||
totp_cli_command_reset_docopt_commands();
|
||||
totp_cli_command_automation_docopt_commands();
|
||||
cli_nl();
|
||||
TOTP_CLI_PRINTF("Arguments:\r\n");
|
||||
totp_cli_command_add_docopt_arguments();
|
||||
totp_cli_command_delete_docopt_arguments();
|
||||
totp_cli_command_move_docopt_arguments();
|
||||
totp_cli_command_timezone_docopt_arguments();
|
||||
totp_cli_command_notification_docopt_arguments();
|
||||
totp_cli_command_automation_docopt_arguments();
|
||||
cli_nl();
|
||||
TOTP_CLI_PRINTF("Options:\r\n");
|
||||
totp_cli_command_add_docopt_options();
|
||||
totp_cli_command_update_docopt_options();
|
||||
totp_cli_command_delete_docopt_options();
|
||||
totp_cli_command_pin_docopt_options();
|
||||
totp_cli_command_automation_docopt_options();
|
||||
#else
|
||||
TOTP_CLI_PRINTF(
|
||||
"All the TOTP CLI commands, their arguments, options and usage can be found here https://t.ly/_6pJG");
|
||||
#endif
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../../config/app/config.h"
|
||||
#include <cli/cli.h>
|
||||
|
||||
#define TOTP_CLI_COMMAND_HELP "help"
|
||||
#define TOTP_CLI_COMMAND_HELP_ALT "h"
|
||||
#define TOTP_CLI_COMMAND_HELP_ALT2 "?"
|
||||
|
||||
void totp_cli_command_help_handle();
|
||||
#ifdef TOTP_CLI_RICH_HELP_ENABLED
|
||||
void totp_cli_command_help_docopt_commands();
|
||||
void totp_cli_command_help_docopt_usage();
|
||||
#endif
|
||||
@@ -1,14 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <cli/cli.h>
|
||||
#include "../../../types/plugin_state.h"
|
||||
#include "../../../config/app/config.h"
|
||||
|
||||
#define TOTP_CLI_COMMAND_LIST "list"
|
||||
#define TOTP_CLI_COMMAND_LIST_ALT "ls"
|
||||
|
||||
void totp_cli_command_list_handle(PluginState* plugin_state, FuriString* args, Cli* cli);
|
||||
#ifdef TOTP_CLI_RICH_HELP_ENABLED
|
||||
void totp_cli_command_list_docopt_commands();
|
||||
void totp_cli_command_list_docopt_usage();
|
||||
#endif
|
||||
@@ -1,15 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <cli/cli.h>
|
||||
#include "../../../types/plugin_state.h"
|
||||
#include "../../../config/app/config.h"
|
||||
|
||||
#define TOTP_CLI_COMMAND_MOVE "move"
|
||||
#define TOTP_CLI_COMMAND_MOVE_ALT "mv"
|
||||
|
||||
void totp_cli_command_move_handle(PluginState* plugin_state, FuriString* args, Cli* cli);
|
||||
#ifdef TOTP_CLI_RICH_HELP_ENABLED
|
||||
void totp_cli_command_move_docopt_commands();
|
||||
void totp_cli_command_move_docopt_usage();
|
||||
void totp_cli_command_move_docopt_arguments();
|
||||
#endif
|
||||
@@ -1,14 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <cli/cli.h>
|
||||
#include "../../../types/plugin_state.h"
|
||||
#include "../../../config/app/config.h"
|
||||
|
||||
#define TOTP_CLI_COMMAND_NOTIFICATION "notify"
|
||||
|
||||
void totp_cli_command_notification_handle(PluginState* plugin_state, FuriString* args, Cli* cli);
|
||||
#ifdef TOTP_CLI_RICH_HELP_ENABLED
|
||||
void totp_cli_command_notification_docopt_commands();
|
||||
void totp_cli_command_notification_docopt_usage();
|
||||
void totp_cli_command_notification_docopt_arguments();
|
||||
#endif
|
||||
@@ -1,14 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <cli/cli.h>
|
||||
#include "../../../types/plugin_state.h"
|
||||
#include "../../../config/app/config.h"
|
||||
|
||||
#define TOTP_CLI_COMMAND_PIN "pin"
|
||||
|
||||
void totp_cli_command_pin_handle(PluginState* plugin_state, FuriString* args, Cli* cli);
|
||||
#ifdef TOTP_CLI_RICH_HELP_ENABLED
|
||||
void totp_cli_command_pin_docopt_commands();
|
||||
void totp_cli_command_pin_docopt_usage();
|
||||
void totp_cli_command_pin_docopt_options();
|
||||
#endif
|
||||
@@ -1,13 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <cli/cli.h>
|
||||
#include "../../../types/plugin_state.h"
|
||||
#include "../../../config/app/config.h"
|
||||
|
||||
#define TOTP_CLI_COMMAND_RESET "reset"
|
||||
|
||||
void totp_cli_command_reset_handle(PluginState* plugin_state, Cli* cli);
|
||||
#ifdef TOTP_CLI_RICH_HELP_ENABLED
|
||||
void totp_cli_command_reset_docopt_commands();
|
||||
void totp_cli_command_reset_docopt_usage();
|
||||
#endif
|
||||
@@ -1,15 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <cli/cli.h>
|
||||
#include "../../../types/plugin_state.h"
|
||||
#include "../../../config/app/config.h"
|
||||
|
||||
#define TOTP_CLI_COMMAND_TIMEZONE "timezone"
|
||||
#define TOTP_CLI_COMMAND_TIMEZONE_ALT "tz"
|
||||
|
||||
void totp_cli_command_timezone_handle(PluginState* plugin_state, FuriString* args, Cli* cli);
|
||||
#ifdef TOTP_CLI_RICH_HELP_ENABLED
|
||||
void totp_cli_command_timezone_docopt_commands();
|
||||
void totp_cli_command_timezone_docopt_usage();
|
||||
void totp_cli_command_timezone_docopt_arguments();
|
||||
#endif
|
||||
@@ -1,14 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <cli/cli.h>
|
||||
#include "../../../types/plugin_state.h"
|
||||
#include "../../../config/app/config.h"
|
||||
|
||||
#define TOTP_CLI_COMMAND_UPDATE "update"
|
||||
|
||||
void totp_cli_command_update_handle(PluginState* plugin_state, FuriString* args, Cli* cli);
|
||||
#ifdef TOTP_CLI_RICH_HELP_ENABLED
|
||||
void totp_cli_command_update_docopt_commands();
|
||||
void totp_cli_command_update_docopt_usage();
|
||||
void totp_cli_command_update_docopt_options();
|
||||
#endif
|
||||
@@ -1,8 +1,11 @@
|
||||
#include "automation.h"
|
||||
#include <flipper_application/flipper_application.h>
|
||||
#include <lib/toolbox/args.h>
|
||||
#include "../../cli_helpers.h"
|
||||
#include "../../cli_shared_methods.h"
|
||||
#include "../../cli_plugin_interface.h"
|
||||
#include "../../../services/config/config.h"
|
||||
#include "../../../ui/scene_director.h"
|
||||
#include "../../cli_helpers.h"
|
||||
#include "../../../config/app/config.h"
|
||||
|
||||
#define TOTP_CLI_COMMAND_AUTOMATION_ARG_METHOD "automation"
|
||||
#define TOTP_CLI_COMMAND_AUTOMATION_METHOD_NONE "none"
|
||||
@@ -12,41 +15,8 @@
|
||||
#endif
|
||||
#define TOTP_CLI_COMMAND_AUTOMATION_LAYOUT_QWERTY "QWERTY"
|
||||
#define TOTP_CLI_COMMAND_AUTOMATION_LAYOUT_AZERTY "AZERTY"
|
||||
#define TOTP_CLI_COMMAND_AUTOMATION_LAYOUT_QWERTZ "QWERTZ"
|
||||
#define TOTP_CLI_COMMAND_AUTOMATION_ARG_KB_LAYOUT_PREFIX "-k"
|
||||
#define TOTP_CLI_COMMAND_AUTOMATION_ARG_KB_LAYOUT "layout"
|
||||
|
||||
#ifdef TOTP_CLI_RICH_HELP_ENABLED
|
||||
void totp_cli_command_automation_docopt_commands() {
|
||||
TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_AUTOMATION " Get or set automation settings\r\n");
|
||||
}
|
||||
|
||||
void totp_cli_command_automation_docopt_usage() {
|
||||
TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_NAME " " TOTP_CLI_COMMAND_AUTOMATION " " DOCOPT_OPTIONAL(DOCOPT_OPTION(
|
||||
TOTP_CLI_COMMAND_AUTOMATION_ARG_KB_LAYOUT_PREFIX,
|
||||
DOCOPT_ARGUMENT(
|
||||
TOTP_CLI_COMMAND_AUTOMATION_ARG_KB_LAYOUT))) " " DOCOPT_OPTIONAL(DOCOPT_MULTIPLE(DOCOPT_ARGUMENT(TOTP_CLI_COMMAND_AUTOMATION_ARG_METHOD))) "\r\n");
|
||||
}
|
||||
|
||||
void totp_cli_command_automation_docopt_arguments() {
|
||||
TOTP_CLI_PRINTF(
|
||||
" " TOTP_CLI_COMMAND_AUTOMATION_ARG_METHOD
|
||||
" Automation method to be set. Must be one of: " TOTP_CLI_COMMAND_AUTOMATION_METHOD_NONE
|
||||
", " TOTP_CLI_COMMAND_AUTOMATION_METHOD_USB
|
||||
#ifdef TOTP_BADBT_AUTOMATION_ENABLED
|
||||
", " TOTP_CLI_COMMAND_AUTOMATION_METHOD_BT
|
||||
#endif
|
||||
"\r\n");
|
||||
}
|
||||
|
||||
void totp_cli_command_automation_docopt_options() {
|
||||
TOTP_CLI_PRINTF(" " DOCOPT_OPTION(
|
||||
TOTP_CLI_COMMAND_AUTOMATION_ARG_KB_LAYOUT_PREFIX,
|
||||
DOCOPT_ARGUMENT(
|
||||
TOTP_CLI_COMMAND_AUTOMATION_ARG_KB_LAYOUT)) " Automation keyboard layout. Must be one of: " TOTP_CLI_COMMAND_AUTOMATION_LAYOUT_QWERTY
|
||||
", " TOTP_CLI_COMMAND_AUTOMATION_LAYOUT_AZERTY
|
||||
"\r\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
static void print_method(AutomationMethod method, const char* color) {
|
||||
#ifdef TOTP_BADBT_AUTOMATION_ENABLED
|
||||
@@ -83,6 +53,9 @@ static void print_kb_layout(AutomationKeyboardLayout layout, const char* color)
|
||||
case AutomationKeyboardLayoutAZERTY:
|
||||
layoutToPrint = TOTP_CLI_COMMAND_AUTOMATION_LAYOUT_AZERTY;
|
||||
break;
|
||||
case AutomationKeyboardLayoutQWERTZ:
|
||||
layoutToPrint = TOTP_CLI_COMMAND_AUTOMATION_LAYOUT_QWERTZ;
|
||||
break;
|
||||
default:
|
||||
furi_crash("Unknown automation keyboard layout");
|
||||
break;
|
||||
@@ -98,6 +71,8 @@ static bool
|
||||
*out = AutomationKeyboardLayoutQWERTY;
|
||||
} else if(furi_string_cmpi_str(str, TOTP_CLI_COMMAND_AUTOMATION_LAYOUT_AZERTY) == 0) {
|
||||
*out = AutomationKeyboardLayoutAZERTY;
|
||||
} else if(furi_string_cmpi_str(str, TOTP_CLI_COMMAND_AUTOMATION_LAYOUT_QWERTZ) == 0) {
|
||||
*out = AutomationKeyboardLayoutQWERTZ;
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
@@ -105,7 +80,7 @@ static bool
|
||||
return result;
|
||||
}
|
||||
|
||||
void totp_cli_command_automation_handle(PluginState* plugin_state, FuriString* args, Cli* cli) {
|
||||
static void handle(PluginState* plugin_state, FuriString* args, Cli* cli) {
|
||||
if(!totp_cli_ensure_authenticated(plugin_state, cli)) {
|
||||
return;
|
||||
}
|
||||
@@ -143,7 +118,7 @@ void totp_cli_command_automation_handle(PluginState* plugin_state, FuriString* a
|
||||
|
||||
do {
|
||||
if(!args_valid) {
|
||||
totp_cli_print_invalid_arguments();
|
||||
TOTP_CLI_PRINT_INVALID_ARGUMENTS();
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -160,7 +135,7 @@ void totp_cli_command_automation_handle(PluginState* plugin_state, FuriString* a
|
||||
TOTP_CLI_PRINTF_SUCCESS(")");
|
||||
cli_nl();
|
||||
} else {
|
||||
totp_cli_print_error_updating_config_file();
|
||||
TOTP_CLI_PRINT_ERROR_UPDATING_CONFIG_FILE();
|
||||
}
|
||||
|
||||
#ifdef TOTP_BADBT_AUTOMATION_ENABLED
|
||||
@@ -183,4 +158,16 @@ void totp_cli_command_automation_handle(PluginState* plugin_state, FuriString* a
|
||||
} while(false);
|
||||
|
||||
furi_string_free(temp_str);
|
||||
}
|
||||
|
||||
static const CliPlugin plugin = {.name = "TOTP CLI Plugin: Automation", .handle = &handle};
|
||||
|
||||
static const FlipperAppPluginDescriptor plugin_descriptor = {
|
||||
.appid = PLUGIN_APP_ID,
|
||||
.ep_api_version = PLUGIN_API_VERSION,
|
||||
.entry_point = &plugin,
|
||||
};
|
||||
|
||||
const FlipperAppPluginDescriptor* totp_cli_automation_plugin_ep() {
|
||||
return &plugin_descriptor;
|
||||
}
|
||||
4
applications/external/totp/cli/plugins/automation/meta.h
vendored
Normal file
4
applications/external/totp/cli/plugins/automation/meta.h
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
#define TOTP_CLI_COMMAND_AUTOMATION "automation"
|
||||
#define TOTP_CLI_PLUGIN_AUTOMATION_FILE_NAME "totp_cli_automation_plugin"
|
||||
@@ -1,39 +1,14 @@
|
||||
#include "delete.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <flipper_application/flipper_application.h>
|
||||
#include <lib/toolbox/args.h>
|
||||
#include "../../../services/config/config.h"
|
||||
#include "../../cli_helpers.h"
|
||||
#include "../../cli_shared_methods.h"
|
||||
#include "../../cli_plugin_interface.h"
|
||||
#include "../../../services/config/config.h"
|
||||
#include "../../../ui/scene_director.h"
|
||||
#include "../../common_command_arguments.h"
|
||||
|
||||
#define TOTP_CLI_COMMAND_DELETE_ARG_FORCE_PREFIX "-f"
|
||||
|
||||
#ifdef TOTP_CLI_RICH_HELP_ENABLED
|
||||
void totp_cli_command_delete_docopt_commands() {
|
||||
TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_DELETE ", " TOTP_CLI_COMMAND_DELETE_ALT
|
||||
" Delete existing token\r\n");
|
||||
}
|
||||
|
||||
void totp_cli_command_delete_docopt_usage() {
|
||||
TOTP_CLI_PRINTF(
|
||||
" " TOTP_CLI_COMMAND_NAME
|
||||
" " DOCOPT_REQUIRED(TOTP_CLI_COMMAND_DELETE " | " TOTP_CLI_COMMAND_DELETE_ALT) " " DOCOPT_ARGUMENT(
|
||||
TOTP_CLI_COMMAND_ARG_INDEX) " " DOCOPT_OPTIONAL(DOCOPT_SWITCH(TOTP_CLI_COMMAND_DELETE_ARG_FORCE_PREFIX)) "\r\n");
|
||||
}
|
||||
|
||||
void totp_cli_command_delete_docopt_arguments() {
|
||||
TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_ARG_INDEX " Token index in the list\r\n");
|
||||
}
|
||||
|
||||
void totp_cli_command_delete_docopt_options() {
|
||||
TOTP_CLI_PRINTF(" " DOCOPT_SWITCH(
|
||||
TOTP_CLI_COMMAND_DELETE_ARG_FORCE_PREFIX) " Force command to do not ask user for interactive confirmation\r\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
void totp_cli_command_delete_handle(PluginState* plugin_state, FuriString* args, Cli* cli) {
|
||||
static void handle(PluginState* plugin_state, FuriString* args, Cli* cli) {
|
||||
if(!totp_cli_ensure_authenticated(plugin_state, cli)) {
|
||||
return;
|
||||
}
|
||||
@@ -44,7 +19,7 @@ void totp_cli_command_delete_handle(PluginState* plugin_state, FuriString* args,
|
||||
int token_number;
|
||||
if(!args_read_int_and_trim(args, &token_number) || token_number <= 0 ||
|
||||
(size_t)token_number > totp_token_info_iterator_get_total_count(iterator_context)) {
|
||||
totp_cli_print_invalid_arguments();
|
||||
TOTP_CLI_PRINT_INVALID_ARGUMENTS();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -55,7 +30,7 @@ void totp_cli_command_delete_handle(PluginState* plugin_state, FuriString* args,
|
||||
confirm_needed = false;
|
||||
} else {
|
||||
totp_cli_printf_unknown_argument(temp_str);
|
||||
totp_cli_print_invalid_arguments();
|
||||
TOTP_CLI_PRINT_INVALID_ARGUMENTS();
|
||||
furi_string_free(temp_str);
|
||||
return;
|
||||
}
|
||||
@@ -88,15 +63,15 @@ void totp_cli_command_delete_handle(PluginState* plugin_state, FuriString* args,
|
||||
}
|
||||
|
||||
if(confirmed) {
|
||||
totp_cli_print_processing();
|
||||
TOTP_CLI_PRINT_PROCESSING();
|
||||
if(totp_token_info_iterator_remove_current_token_info(iterator_context)) {
|
||||
totp_cli_delete_last_line();
|
||||
TOTP_CLI_DELETE_LAST_LINE();
|
||||
TOTP_CLI_PRINTF_SUCCESS(
|
||||
"Token \"%s\" has been successfully deleted\r\n", token_info_name);
|
||||
totp_token_info_iterator_go_to(iterator_context, 0);
|
||||
} else {
|
||||
totp_cli_delete_last_line();
|
||||
totp_cli_print_error_updating_config_file();
|
||||
TOTP_CLI_DELETE_LAST_LINE();
|
||||
TOTP_CLI_PRINT_ERROR_UPDATING_CONFIG_FILE();
|
||||
totp_token_info_iterator_go_to(iterator_context, original_token_index);
|
||||
}
|
||||
} else {
|
||||
@@ -105,4 +80,16 @@ void totp_cli_command_delete_handle(PluginState* plugin_state, FuriString* args,
|
||||
}
|
||||
|
||||
TOTP_CLI_UNLOCK_UI(plugin_state);
|
||||
}
|
||||
|
||||
static const CliPlugin plugin = {.name = "TOTP CLI Plugin: Delete", .handle = &handle};
|
||||
|
||||
static const FlipperAppPluginDescriptor plugin_descriptor = {
|
||||
.appid = PLUGIN_APP_ID,
|
||||
.ep_api_version = PLUGIN_API_VERSION,
|
||||
.entry_point = &plugin,
|
||||
};
|
||||
|
||||
const FlipperAppPluginDescriptor* totp_cli_delete_plugin_ep() {
|
||||
return &plugin_descriptor;
|
||||
}
|
||||
5
applications/external/totp/cli/plugins/delete/meta.h
vendored
Normal file
5
applications/external/totp/cli/plugins/delete/meta.h
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#define TOTP_CLI_COMMAND_DELETE "delete"
|
||||
#define TOTP_CLI_COMMAND_DELETE_ALT "rm"
|
||||
#define TOTP_CLI_PLUGIN_DELETE_FILE_NAME "totp_cli_delete_plugin"
|
||||
@@ -1,12 +1,12 @@
|
||||
#include "details.h"
|
||||
#include <stdlib.h>
|
||||
#include <flipper_application/flipper_application.h>
|
||||
#include <lib/toolbox/args.h>
|
||||
#include "../../../types/token_info.h"
|
||||
#include "../../../services/config/constants.h"
|
||||
#include "../../../services/config/config.h"
|
||||
#include "../../../ui/scene_director.h"
|
||||
#include "../../../services/config/constants.h"
|
||||
#include "../../../types/token_info.h"
|
||||
#include "../../cli_helpers.h"
|
||||
#include "../../common_command_arguments.h"
|
||||
#include "../../cli_shared_methods.h"
|
||||
#include "../../cli_plugin_interface.h"
|
||||
#include "../../../ui/scene_director.h"
|
||||
#include "formatters/table/details_output_formatter_table.h"
|
||||
#include "formatters/tsv/details_output_formatter_tsv.h"
|
||||
|
||||
@@ -19,6 +19,7 @@ typedef void (*TOTP_CLI_DETAILS_AUTOMATION_FEATURE_ITEM_FORMATTER)(
|
||||
typedef void (*TOTP_CLI_DETAILS_CSTR_FORMATTER)(const char* key, const char* value);
|
||||
typedef void (*TOTP_CLI_DETAILS_UINT8T_FORMATTER)(const char* key, uint8_t value);
|
||||
typedef void (*TOTP_CLI_DETAILS_SIZET_FORMATTER)(const char* key, size_t value);
|
||||
typedef void (*TOTP_CLI_DETAILS_UINT64T_FORMATTER)(const char* key, uint64_t value);
|
||||
|
||||
typedef struct {
|
||||
const TOTP_CLI_DETAILS_HEADER_FORMATTER header_formatter;
|
||||
@@ -27,6 +28,7 @@ typedef struct {
|
||||
const TOTP_CLI_DETAILS_CSTR_FORMATTER cstr_formatter;
|
||||
const TOTP_CLI_DETAILS_UINT8T_FORMATTER uint8t_formatter;
|
||||
const TOTP_CLI_DETAILS_SIZET_FORMATTER sizet_formatter;
|
||||
const TOTP_CLI_DETAILS_UINT64T_FORMATTER uint64t_formatter;
|
||||
} TotpCliDetailsFormatter;
|
||||
|
||||
static const TotpCliDetailsFormatter available_formatters[] = {
|
||||
@@ -35,14 +37,16 @@ static const TotpCliDetailsFormatter available_formatters[] = {
|
||||
.automation_feature_item_formatter = &details_output_formatter_print_automation_feature_table,
|
||||
.cstr_formatter = &details_output_formatter_print_cstr_table,
|
||||
.uint8t_formatter = &details_output_formatter_print_uint8t_table,
|
||||
.sizet_formatter = &details_output_formatter_print_sizet_table},
|
||||
.sizet_formatter = &details_output_formatter_print_sizet_table,
|
||||
.uint64t_formatter = &details_output_formatter_print_uint64t_table},
|
||||
|
||||
{.header_formatter = &details_output_formatter_print_header_tsv,
|
||||
.footer_formatter = &details_output_formatter_print_footer_tsv,
|
||||
.automation_feature_item_formatter = &details_output_formatter_print_automation_feature_tsv,
|
||||
.cstr_formatter = &details_output_formatter_print_cstr_tsv,
|
||||
.uint8t_formatter = &details_output_formatter_print_uint8t_tsv,
|
||||
.sizet_formatter = &details_output_formatter_print_sizet_tsv},
|
||||
.sizet_formatter = &details_output_formatter_print_sizet_tsv,
|
||||
.uint64t_formatter = &details_output_formatter_print_uint64t_tsv},
|
||||
};
|
||||
|
||||
static void print_automation_features(
|
||||
@@ -72,20 +76,7 @@ static void print_automation_features(
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef TOTP_CLI_RICH_HELP_ENABLED
|
||||
void totp_cli_command_details_docopt_commands() {
|
||||
TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_DETAILS ", " TOTP_CLI_COMMAND_DETAILS_ALT
|
||||
" Displays token details\r\n");
|
||||
}
|
||||
|
||||
void totp_cli_command_details_docopt_usage() {
|
||||
TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_NAME " " DOCOPT_REQUIRED(
|
||||
TOTP_CLI_COMMAND_DETAILS
|
||||
" | " TOTP_CLI_COMMAND_DETAILS_ALT) " " DOCOPT_ARGUMENT(TOTP_CLI_COMMAND_ARG_INDEX) "\r\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
void totp_cli_command_details_handle(PluginState* plugin_state, FuriString* args, Cli* cli) {
|
||||
static void handle(PluginState* plugin_state, FuriString* args, Cli* cli) {
|
||||
if(!totp_cli_ensure_authenticated(plugin_state, cli)) {
|
||||
return;
|
||||
}
|
||||
@@ -95,7 +86,7 @@ void totp_cli_command_details_handle(PluginState* plugin_state, FuriString* args
|
||||
totp_config_get_token_iterator_context(plugin_state);
|
||||
if(!args_read_int_and_trim(args, &token_number) || token_number <= 0 ||
|
||||
(size_t)token_number > totp_token_info_iterator_get_total_count(iterator_context)) {
|
||||
totp_cli_print_invalid_arguments();
|
||||
TOTP_CLI_PRINT_INVALID_ARGUMENTS();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -116,17 +107,34 @@ void totp_cli_command_details_handle(PluginState* plugin_state, FuriString* args
|
||||
|
||||
(*formatter->header_formatter)();
|
||||
(*formatter->sizet_formatter)("Index", token_number);
|
||||
(*formatter->cstr_formatter)("Type", token_info_get_type_as_cstr(token_info));
|
||||
(*formatter->cstr_formatter)("Name", furi_string_get_cstr(token_info->name));
|
||||
(*formatter->cstr_formatter)("Hashing algorithm", token_info_get_algo_as_cstr(token_info));
|
||||
(*formatter->uint8t_formatter)("Number of digits", token_info->digits);
|
||||
(*formatter->uint8t_formatter)("Token lifetime", token_info->duration);
|
||||
if(token_info->type == TokenTypeTOTP) {
|
||||
(*formatter->uint8t_formatter)("Token lifetime", token_info->duration);
|
||||
} else if(token_info->type == TokenTypeHOTP) {
|
||||
(*formatter->uint64t_formatter)("Token counter", token_info->counter);
|
||||
}
|
||||
print_automation_features(token_info, formatter);
|
||||
(*formatter->footer_formatter)();
|
||||
} else {
|
||||
totp_cli_print_error_loading_token_info();
|
||||
TOTP_CLI_PRINT_ERROR_LOADING_TOKEN_INFO();
|
||||
}
|
||||
|
||||
totp_token_info_iterator_go_to(iterator_context, original_token_index);
|
||||
|
||||
TOTP_CLI_UNLOCK_UI(plugin_state);
|
||||
}
|
||||
}
|
||||
|
||||
static const CliPlugin plugin = {.name = "TOTP CLI Plugin: Details", .handle = &handle};
|
||||
|
||||
static const FlipperAppPluginDescriptor plugin_descriptor = {
|
||||
.appid = PLUGIN_APP_ID,
|
||||
.ep_api_version = PLUGIN_API_VERSION,
|
||||
.entry_point = &plugin,
|
||||
};
|
||||
|
||||
const FlipperAppPluginDescriptor* totp_cli_details_plugin_ep() {
|
||||
return &plugin_descriptor;
|
||||
}
|
||||
@@ -1,32 +1,37 @@
|
||||
#include "details_output_formatter_table.h"
|
||||
#include <inttypes.h>
|
||||
#include "../../../../cli_helpers.h"
|
||||
|
||||
void details_output_formatter_print_header_table() {
|
||||
TOTP_CLI_PRINTF("+----------------------+------------------------------+\r\n");
|
||||
TOTP_CLI_PRINTF("| %-20s | %-28s |\r\n", "Property", "Value");
|
||||
TOTP_CLI_PRINTF("+----------------------+------------------------------+\r\n");
|
||||
TOTP_CLI_PRINTF("+----------------------+-------------------------------+\r\n");
|
||||
TOTP_CLI_PRINTF("| %-20s | %-29s |\r\n", "Property", "Value");
|
||||
TOTP_CLI_PRINTF("+----------------------+-------------------------------+\r\n");
|
||||
}
|
||||
|
||||
void details_output_formatter_print_footer_table() {
|
||||
TOTP_CLI_PRINTF("+----------------------+------------------------------+\r\n");
|
||||
TOTP_CLI_PRINTF("+----------------------+-------------------------------+\r\n");
|
||||
}
|
||||
|
||||
void details_output_formatter_print_automation_feature_table(
|
||||
const char* key,
|
||||
const char* feature,
|
||||
bool* header_printed) {
|
||||
TOTP_CLI_PRINTF("| %-20s | %-28.28s |\r\n", *header_printed ? "" : key, feature);
|
||||
TOTP_CLI_PRINTF("| %-20s | %-29.29s |\r\n", *header_printed ? "" : key, feature);
|
||||
*header_printed = true;
|
||||
}
|
||||
|
||||
void details_output_formatter_print_cstr_table(const char* key, const char* value) {
|
||||
TOTP_CLI_PRINTF("| %-20s | %-28.28s |\r\n", key, value);
|
||||
TOTP_CLI_PRINTF("| %-20s | %-29.29s |\r\n", key, value);
|
||||
}
|
||||
|
||||
void details_output_formatter_print_uint8t_table(const char* key, uint8_t value) {
|
||||
TOTP_CLI_PRINTF("| %-20s | %-28" PRIu8 " |\r\n", key, value);
|
||||
TOTP_CLI_PRINTF("| %-20s | %-29" PRIu8 " |\r\n", key, value);
|
||||
}
|
||||
|
||||
void details_output_formatter_print_sizet_table(const char* key, size_t value) {
|
||||
TOTP_CLI_PRINTF("| %-20s | %-28" PRIu16 " |\r\n", key, value);
|
||||
TOTP_CLI_PRINTF("| %-20s | %-29" PRIu16 " |\r\n", key, value);
|
||||
}
|
||||
|
||||
void details_output_formatter_print_uint64t_table(const char* key, uint64_t value) {
|
||||
TOTP_CLI_PRINTF("| %-20s | %-29" PRIu64 " |\r\n", key, value);
|
||||
}
|
||||
@@ -13,3 +13,4 @@ void details_output_formatter_print_automation_feature_table(
|
||||
void details_output_formatter_print_cstr_table(const char* key, const char* value);
|
||||
void details_output_formatter_print_uint8t_table(const char* key, uint8_t value);
|
||||
void details_output_formatter_print_sizet_table(const char* key, size_t value);
|
||||
void details_output_formatter_print_uint64t_table(const char* key, uint64_t value);
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "details_output_formatter_tsv.h"
|
||||
#include <inttypes.h>
|
||||
#include "../../../../cli_helpers.h"
|
||||
|
||||
void details_output_formatter_print_header_tsv() {
|
||||
@@ -27,3 +28,7 @@ void details_output_formatter_print_uint8t_tsv(const char* key, uint8_t value) {
|
||||
void details_output_formatter_print_sizet_tsv(const char* key, size_t value) {
|
||||
TOTP_CLI_PRINTF("%s\t%" PRIu16 "\r\n", key, value);
|
||||
}
|
||||
|
||||
void details_output_formatter_print_uint64t_tsv(const char* key, uint64_t value) {
|
||||
TOTP_CLI_PRINTF("%s\t%" PRIu64 "\r\n", key, value);
|
||||
}
|
||||
@@ -13,3 +13,4 @@ void details_output_formatter_print_automation_feature_tsv(
|
||||
void details_output_formatter_print_cstr_tsv(const char* key, const char* value);
|
||||
void details_output_formatter_print_uint8t_tsv(const char* key, uint8_t value);
|
||||
void details_output_formatter_print_sizet_tsv(const char* key, size_t value);
|
||||
void details_output_formatter_print_uint64t_tsv(const char* key, uint64_t value);
|
||||
5
applications/external/totp/cli/plugins/details/meta.h
vendored
Normal file
5
applications/external/totp/cli/plugins/details/meta.h
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#define TOTP_CLI_COMMAND_DETAILS "lsattr"
|
||||
#define TOTP_CLI_COMMAND_DETAILS_ALT "cat"
|
||||
#define TOTP_CLI_PLUGIN_DETAILS_FILE_NAME "totp_cli_details_plugin"
|
||||
42
applications/external/totp/cli/plugins/help/help.c
vendored
Normal file
42
applications/external/totp/cli/plugins/help/help.c
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
#include <flipper_application/flipper_application.h>
|
||||
#include <storage/storage.h>
|
||||
#include <toolbox/stream/stream.h>
|
||||
#include <toolbox/stream/file_stream.h>
|
||||
#include "../../cli_helpers.h"
|
||||
#include "../../cli_plugin_interface.h"
|
||||
|
||||
static void handle(PluginState* plugin_state, FuriString* args, Cli* cli) {
|
||||
UNUSED(args);
|
||||
UNUSED(cli);
|
||||
UNUSED(plugin_state);
|
||||
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
|
||||
Stream* stream = file_stream_alloc(storage);
|
||||
|
||||
if(file_stream_open(
|
||||
stream, EXT_PATH("apps_assets/totp/cli/cli_help.txt"), FSAM_READ, FSOM_OPEN_EXISTING)) {
|
||||
uint8_t buffer[32U];
|
||||
size_t bytes_read;
|
||||
while((bytes_read = stream_read(stream, &buffer[0], sizeof(buffer))) > 0) {
|
||||
cli_write(cli, &buffer[0], bytes_read);
|
||||
}
|
||||
}
|
||||
|
||||
file_stream_close(stream);
|
||||
stream_free(stream);
|
||||
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
}
|
||||
|
||||
static const CliPlugin plugin = {.name = "TOTP CLI Plugin: Help", .handle = &handle};
|
||||
|
||||
static const FlipperAppPluginDescriptor plugin_descriptor = {
|
||||
.appid = PLUGIN_APP_ID,
|
||||
.ep_api_version = PLUGIN_API_VERSION,
|
||||
.entry_point = &plugin,
|
||||
};
|
||||
|
||||
const FlipperAppPluginDescriptor* totp_cli_help_plugin_ep() {
|
||||
return &plugin_descriptor;
|
||||
}
|
||||
6
applications/external/totp/cli/plugins/help/meta.h
vendored
Normal file
6
applications/external/totp/cli/plugins/help/meta.h
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#define TOTP_CLI_COMMAND_HELP "help"
|
||||
#define TOTP_CLI_COMMAND_HELP_ALT "h"
|
||||
#define TOTP_CLI_COMMAND_HELP_ALT2 "?"
|
||||
#define TOTP_CLI_PLUGIN_HELP_FILE_NAME "totp_cli_help_plugin"
|
||||
@@ -1,22 +1,23 @@
|
||||
#include "list_output_formatter_table.h"
|
||||
#include <inttypes.h>
|
||||
#include "../../../../cli_helpers.h"
|
||||
|
||||
void list_output_formatter_print_header_table() {
|
||||
TOTP_CLI_PRINTF("+-----+---------------------------+--------+----+-----+\r\n");
|
||||
TOTP_CLI_PRINTF("| %-3s | %-25s | %-6s | %-s | %-s |\r\n", "#", "Name", "Algo", "Ln", "Dur");
|
||||
TOTP_CLI_PRINTF("+-----+---------------------------+--------+----+-----+\r\n");
|
||||
TOTP_CLI_PRINTF("+-----+---------------------------+--------+----+------+\r\n");
|
||||
TOTP_CLI_PRINTF("| %-3s | %-25s | %-6s | %-s | %-s |\r\n", "#", "Name", "Algo", "Ln", "Type");
|
||||
TOTP_CLI_PRINTF("+-----+---------------------------+--------+----+------+\r\n");
|
||||
}
|
||||
|
||||
void list_output_formatter_print_body_item_table(size_t index, const TokenInfo* token_info) {
|
||||
TOTP_CLI_PRINTF(
|
||||
"| %-3" PRIu16 " | %-25.25s | %-6s | %-2" PRIu8 " | %-3" PRIu8 " |\r\n",
|
||||
"| %-3" PRIu16 " | %-25.25s | %-6s | %-2" PRIu8 " | %-4s |\r\n",
|
||||
index + 1,
|
||||
furi_string_get_cstr(token_info->name),
|
||||
token_info_get_algo_as_cstr(token_info),
|
||||
token_info->digits,
|
||||
token_info->duration);
|
||||
token_info_get_type_as_cstr(token_info));
|
||||
}
|
||||
|
||||
void list_output_formatter_print_footer_table() {
|
||||
TOTP_CLI_PRINTF("+-----+---------------------------+--------+----+-----+\r\n");
|
||||
}
|
||||
TOTP_CLI_PRINTF("+-----+---------------------------+--------+----+------+\r\n");
|
||||
}
|
||||
@@ -1,19 +1,20 @@
|
||||
#include "list_output_formatter_tsv.h"
|
||||
#include <inttypes.h>
|
||||
#include "../../../../cli_helpers.h"
|
||||
|
||||
void list_output_formatter_print_header_tsv() {
|
||||
TOTP_CLI_PRINTF("%s\t%s\t%s\t%s\t%s\r\n", "#", "Name", "Algo", "Ln", "Dur");
|
||||
TOTP_CLI_PRINTF("%s\t%s\t%s\t%s\t%s\r\n", "#", "Name", "Algo", "Ln", "Type");
|
||||
}
|
||||
|
||||
void list_output_formatter_print_body_item_tsv(size_t index, const TokenInfo* token_info) {
|
||||
TOTP_CLI_PRINTF(
|
||||
"%" PRIu16 "\t%s\t%s\t%" PRIu8 "\t%" PRIu8 "\r\n",
|
||||
"%" PRIu16 "\t%s\t%s\t%" PRIu8 "\t%s\r\n",
|
||||
index + 1,
|
||||
furi_string_get_cstr(token_info->name),
|
||||
token_info_get_algo_as_cstr(token_info),
|
||||
token_info->digits,
|
||||
token_info->duration);
|
||||
token_info_get_type_as_cstr(token_info));
|
||||
}
|
||||
|
||||
void list_output_formatter_print_footer_tsv() {
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,13 @@
|
||||
#include "list.h"
|
||||
#include <stdlib.h>
|
||||
#include <flipper_application/flipper_application.h>
|
||||
#include "../../cli_helpers.h"
|
||||
#include "../../cli_shared_methods.h"
|
||||
#include "../../cli_plugin_interface.h"
|
||||
|
||||
#include <lib/toolbox/args.h>
|
||||
#include "../../../types/token_info.h"
|
||||
#include "../../../services/config/constants.h"
|
||||
#include "../../../services/config/config.h"
|
||||
#include "../../../ui/scene_director.h"
|
||||
#include "../../cli_helpers.h"
|
||||
#include "formatters/table/list_output_formatter_table.h"
|
||||
#include "formatters/tsv/list_output_formatter_tsv.h"
|
||||
|
||||
@@ -28,19 +30,7 @@ static const TotpCliListFormatter available_formatters[] = {
|
||||
.body_item_formatter = &list_output_formatter_print_body_item_tsv,
|
||||
.footer_formatter = &list_output_formatter_print_footer_tsv}};
|
||||
|
||||
#ifdef TOTP_CLI_RICH_HELP_ENABLED
|
||||
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");
|
||||
}
|
||||
#endif
|
||||
|
||||
void totp_cli_command_list_handle(PluginState* plugin_state, FuriString* args, Cli* cli) {
|
||||
static void handle(PluginState* plugin_state, FuriString* args, Cli* cli) {
|
||||
if(!totp_cli_ensure_authenticated(plugin_state, cli)) {
|
||||
return;
|
||||
}
|
||||
@@ -77,4 +67,16 @@ void totp_cli_command_list_handle(PluginState* plugin_state, FuriString* args, C
|
||||
totp_token_info_iterator_go_to(iterator_context, original_index);
|
||||
|
||||
TOTP_CLI_UNLOCK_UI(plugin_state);
|
||||
}
|
||||
|
||||
static const CliPlugin plugin = {.name = "TOTP CLI Plugin: List", .handle = &handle};
|
||||
|
||||
static const FlipperAppPluginDescriptor plugin_descriptor = {
|
||||
.appid = PLUGIN_APP_ID,
|
||||
.ep_api_version = PLUGIN_API_VERSION,
|
||||
.entry_point = &plugin,
|
||||
};
|
||||
|
||||
const FlipperAppPluginDescriptor* totp_cli_list_plugin_ep() {
|
||||
return &plugin_descriptor;
|
||||
}
|
||||
5
applications/external/totp/cli/plugins/list/meta.h
vendored
Normal file
5
applications/external/totp/cli/plugins/list/meta.h
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#define TOTP_CLI_COMMAND_LIST "list"
|
||||
#define TOTP_CLI_COMMAND_LIST_ALT "ls"
|
||||
#define TOTP_CLI_PLUGIN_LIST_FILE_NAME "totp_cli_list_plugin"
|
||||
128
applications/external/totp/cli/plugins/modify/add/add.c
vendored
Normal file
128
applications/external/totp/cli/plugins/modify/add/add.c
vendored
Normal file
@@ -0,0 +1,128 @@
|
||||
#include <flipper_application/flipper_application.h>
|
||||
#include <lib/toolbox/args.h>
|
||||
#include "../../../cli_helpers.h"
|
||||
#include "../../../cli_shared_methods.h"
|
||||
#include "../../../cli_plugin_interface.h"
|
||||
#include "../../../../types/token_info.h"
|
||||
#include "../../../../services/config/config.h"
|
||||
#include "../../../../services/convert/convert.h"
|
||||
#include "../../../../ui/scene_director.h"
|
||||
#include "../common.h"
|
||||
|
||||
struct TotpAddContext {
|
||||
FuriString* args;
|
||||
Cli* cli;
|
||||
const CryptoSettings* crypto_settings;
|
||||
};
|
||||
|
||||
enum TotpIteratorUpdateTokenResultsEx {
|
||||
TotpIteratorUpdateTokenResultInvalidSecret = 1,
|
||||
TotpIteratorUpdateTokenResultCancelled = 2,
|
||||
TotpIteratorUpdateTokenResultInvalidArguments = 3
|
||||
};
|
||||
|
||||
static TotpIteratorUpdateTokenResult
|
||||
add_token_handler(TokenInfo* token_info, const void* context) {
|
||||
const struct TotpAddContext* context_t = context;
|
||||
|
||||
// Reading token name
|
||||
if(!args_read_probably_quoted_string_and_trim(context_t->args, token_info->name)) {
|
||||
return TotpIteratorUpdateTokenResultInvalidArguments;
|
||||
}
|
||||
|
||||
FuriString* temp_str = furi_string_alloc();
|
||||
|
||||
// Read optional arguments
|
||||
bool mask_user_input = true;
|
||||
PlainTokenSecretEncoding token_secret_encoding = PlainTokenSecretEncodingBase32;
|
||||
while(args_read_string_and_trim(context_t->args, temp_str)) {
|
||||
bool parsed = false;
|
||||
if(!totp_cli_try_read_algo(token_info, temp_str, context_t->args, &parsed) &&
|
||||
!totp_cli_try_read_digits(token_info, temp_str, context_t->args, &parsed) &&
|
||||
!totp_cli_try_read_duration(token_info, temp_str, context_t->args, &parsed) &&
|
||||
!totp_cli_try_read_unsecure_flag(temp_str, &parsed, &mask_user_input) &&
|
||||
!totp_cli_try_read_automation_features(token_info, temp_str, context_t->args, &parsed) &&
|
||||
!totp_cli_try_read_plain_token_secret_encoding(
|
||||
temp_str, context_t->args, &parsed, &token_secret_encoding) &&
|
||||
!totp_cli_try_read_token_type(token_info, temp_str, context_t->args, &parsed) &&
|
||||
!totp_cli_try_read_token_counter(token_info, temp_str, context_t->args, &parsed)) {
|
||||
totp_cli_printf_unknown_argument(temp_str);
|
||||
}
|
||||
|
||||
if(!parsed) {
|
||||
furi_string_free(temp_str);
|
||||
return TotpIteratorUpdateTokenResultInvalidArguments;
|
||||
}
|
||||
}
|
||||
|
||||
// Reading token secret
|
||||
furi_string_reset(temp_str);
|
||||
TOTP_CLI_PRINTF("Enter token secret and confirm with [ENTER]:\r\n");
|
||||
if(!totp_cli_read_line(context_t->cli, temp_str, mask_user_input)) {
|
||||
TOTP_CLI_DELETE_LAST_LINE();
|
||||
furi_string_secure_free(temp_str);
|
||||
return TotpIteratorUpdateTokenResultCancelled;
|
||||
}
|
||||
|
||||
TOTP_CLI_DELETE_LAST_LINE();
|
||||
|
||||
bool secret_set = token_info_set_secret(
|
||||
token_info,
|
||||
furi_string_get_cstr(temp_str),
|
||||
furi_string_size(temp_str),
|
||||
token_secret_encoding,
|
||||
context_t->crypto_settings);
|
||||
|
||||
furi_string_secure_free(temp_str);
|
||||
|
||||
if(!secret_set) {
|
||||
return TotpIteratorUpdateTokenResultInvalidSecret;
|
||||
}
|
||||
|
||||
return TotpIteratorUpdateTokenResultSuccess;
|
||||
}
|
||||
|
||||
static void handle(PluginState* plugin_state, FuriString* args, Cli* cli) {
|
||||
if(!totp_cli_ensure_authenticated(plugin_state, cli)) {
|
||||
return;
|
||||
}
|
||||
|
||||
TokenInfoIteratorContext* iterator_context =
|
||||
totp_config_get_token_iterator_context(plugin_state);
|
||||
|
||||
TOTP_CLI_LOCK_UI(plugin_state);
|
||||
|
||||
struct TotpAddContext add_context = {
|
||||
.args = args, .cli = cli, .crypto_settings = &plugin_state->crypto_settings};
|
||||
TotpIteratorUpdateTokenResult add_result =
|
||||
totp_token_info_iterator_add_new_token(iterator_context, &add_token_handler, &add_context);
|
||||
|
||||
if(add_result == TotpIteratorUpdateTokenResultSuccess) {
|
||||
TOTP_CLI_PRINTF_SUCCESS(
|
||||
"Token \"%s\" has been successfully added\r\n",
|
||||
furi_string_get_cstr(
|
||||
totp_token_info_iterator_get_current_token(iterator_context)->name));
|
||||
} else if(add_result == TotpIteratorUpdateTokenResultCancelled) {
|
||||
TOTP_CLI_PRINTF_INFO("Cancelled by user\r\n");
|
||||
} else if(add_result == TotpIteratorUpdateTokenResultInvalidArguments) {
|
||||
TOTP_CLI_PRINT_INVALID_ARGUMENTS();
|
||||
} else if(add_result == TotpIteratorUpdateTokenResultInvalidSecret) {
|
||||
TOTP_CLI_PRINTF_ERROR("Token secret seems to be invalid and can not be parsed\r\n");
|
||||
} else if(add_result == TotpIteratorUpdateTokenResultFileUpdateFailed) {
|
||||
TOTP_CLI_PRINT_ERROR_UPDATING_CONFIG_FILE();
|
||||
}
|
||||
|
||||
TOTP_CLI_UNLOCK_UI(plugin_state);
|
||||
}
|
||||
|
||||
static const CliPlugin plugin = {.name = "TOTP CLI Plugin: Add", .handle = &handle};
|
||||
|
||||
static const FlipperAppPluginDescriptor plugin_descriptor = {
|
||||
.appid = PLUGIN_APP_ID,
|
||||
.ep_api_version = PLUGIN_API_VERSION,
|
||||
.entry_point = &plugin,
|
||||
};
|
||||
|
||||
const FlipperAppPluginDescriptor* totp_cli_add_plugin_ep() {
|
||||
return &plugin_descriptor;
|
||||
}
|
||||
6
applications/external/totp/cli/plugins/modify/add/meta.h
vendored
Normal file
6
applications/external/totp/cli/plugins/modify/add/meta.h
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#define TOTP_CLI_COMMAND_ADD "add"
|
||||
#define TOTP_CLI_COMMAND_ADD_ALT "mk"
|
||||
#define TOTP_CLI_COMMAND_ADD_ALT2 "new"
|
||||
#define TOTP_CLI_PLUGIN_ADD_FILE_NAME "totp_cli_add_plugin"
|
||||
@@ -1,13 +1,8 @@
|
||||
#include "common_command_arguments.h"
|
||||
#include "common.h"
|
||||
#include <lib/toolbox/args.h>
|
||||
|
||||
void totp_cli_printf_missed_argument_value(char* arg) {
|
||||
TOTP_CLI_PRINTF_ERROR("Missed or incorrect value for argument \"%s\"\r\n", arg);
|
||||
}
|
||||
|
||||
void totp_cli_printf_unknown_argument(const FuriString* arg) {
|
||||
TOTP_CLI_PRINTF("Unknown argument \"%s\"\r\n", furi_string_get_cstr(arg));
|
||||
}
|
||||
#include "stdint.h"
|
||||
#include "../../cli_helpers.h"
|
||||
#include "../../cli_shared_methods.h"
|
||||
|
||||
bool totp_cli_try_read_algo(TokenInfo* token_info, FuriString* arg, FuriString* args, bool* parsed) {
|
||||
if(furi_string_cmpi_str(arg, TOTP_CLI_COMMAND_ARG_ALGO_PREFIX) == 0) {
|
||||
@@ -138,4 +133,50 @@ bool totp_cli_try_read_plain_token_secret_encoding(
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool totp_cli_try_read_token_type(
|
||||
TokenInfo* token_info,
|
||||
FuriString* arg,
|
||||
FuriString* args,
|
||||
bool* parsed) {
|
||||
if(furi_string_cmpi_str(arg, TOTP_CLI_COMMAND_ARG_TYPE_PREFIX) == 0) {
|
||||
if(!args_read_string_and_trim(args, arg)) {
|
||||
totp_cli_printf_missed_argument_value(TOTP_CLI_COMMAND_ARG_TYPE_PREFIX);
|
||||
} else if(!token_info_set_token_type_from_str(token_info, arg)) {
|
||||
TOTP_CLI_PRINTF_ERROR(
|
||||
"\"%s\" is incorrect value for argument \"" TOTP_CLI_COMMAND_ARG_TYPE_PREFIX
|
||||
"\"\r\n",
|
||||
furi_string_get_cstr(arg));
|
||||
} else {
|
||||
*parsed = true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool totp_cli_try_read_token_counter(
|
||||
TokenInfo* token_info,
|
||||
FuriString* arg,
|
||||
FuriString* args,
|
||||
bool* parsed) {
|
||||
if(furi_string_cmpi_str(arg, TOTP_CLI_COMMAND_ARG_COUNTER_PREFIX) == 0) {
|
||||
if(!args_read_string_and_trim(args, arg)) {
|
||||
totp_cli_printf_missed_argument_value(TOTP_CLI_COMMAND_ARG_COUNTER_PREFIX);
|
||||
} else if(!token_info_set_token_counter_from_str(token_info, arg)) {
|
||||
TOTP_CLI_PRINTF_ERROR(
|
||||
"\"%s\" is incorrect value for argument \"" TOTP_CLI_COMMAND_ARG_COUNTER_PREFIX
|
||||
"\"\r\n",
|
||||
furi_string_get_cstr(arg));
|
||||
} else {
|
||||
*parsed = true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -1,34 +1,20 @@
|
||||
#pragma once
|
||||
#include <stdlib.h>
|
||||
#include "../types/token_info.h"
|
||||
#include "cli_helpers.h"
|
||||
#include "../../../types/token_info.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define TOTP_CLI_COMMAND_ARG_NAME "name"
|
||||
#define TOTP_CLI_COMMAND_ARG_NAME_PREFIX "-n"
|
||||
#define TOTP_CLI_COMMAND_ARG_ALGO "algo"
|
||||
#define TOTP_CLI_COMMAND_ARG_ALGO_PREFIX "-a"
|
||||
#define TOTP_CLI_COMMAND_ARG_DIGITS "digits"
|
||||
#define TOTP_CLI_COMMAND_ARG_DIGITS_PREFIX "-d"
|
||||
#define TOTP_CLI_COMMAND_ARG_UNSECURE_PREFIX "-u"
|
||||
#define TOTP_CLI_COMMAND_ARG_DURATION "duration"
|
||||
#define TOTP_CLI_COMMAND_ARG_DURATION_PREFIX "-l"
|
||||
#define TOTP_CLI_COMMAND_ARG_AUTOMATION_FEATURE_PREFIX "-b"
|
||||
#define TOTP_CLI_COMMAND_ARG_AUTOMATION_FEATURE "feature"
|
||||
#define TOTP_CLI_COMMAND_ARG_INDEX "index"
|
||||
#define TOTP_CLI_COMMAND_ARG_SECRET_ENCODING_PREFIX "-e"
|
||||
#define TOTP_CLI_COMMAND_ARG_SECRET_ENCODING "encoding"
|
||||
|
||||
/**
|
||||
* @brief Prints information about unknown argument
|
||||
* @param arg
|
||||
*/
|
||||
void totp_cli_printf_unknown_argument(const FuriString* arg);
|
||||
|
||||
/**
|
||||
* @brief Prints information about missed required argument
|
||||
* @param arg
|
||||
*/
|
||||
void totp_cli_printf_missed_argument_value(char* arg);
|
||||
#define TOTP_CLI_COMMAND_ARG_TYPE_PREFIX "-t"
|
||||
#define TOTP_CLI_COMMAND_ARG_COUNTER_PREFIX "-i"
|
||||
|
||||
/**
|
||||
* @brief Tries to read token hashing algo
|
||||
@@ -103,4 +89,36 @@ bool totp_cli_try_read_plain_token_secret_encoding(
|
||||
FuriString* arg,
|
||||
FuriString* args,
|
||||
bool* parsed,
|
||||
PlainTokenSecretEncoding* secret_encoding);
|
||||
PlainTokenSecretEncoding* secret_encoding);
|
||||
|
||||
/**
|
||||
* @brief Tries to read token type
|
||||
* @param token_info token info to set parsed token type to if successfully read and parsed
|
||||
* @param arg argument to parse
|
||||
* @param args rest of arguments
|
||||
* @param parsed will be set to \c true if token type sucecssfully read and parsed; \c false otherwise
|
||||
* @return \c true if \c arg represents token type argument; \c false otherwise
|
||||
*/
|
||||
bool totp_cli_try_read_token_type(
|
||||
TokenInfo* token_info,
|
||||
FuriString* arg,
|
||||
FuriString* args,
|
||||
bool* parsed);
|
||||
|
||||
/**
|
||||
* @brief Tries to read token counter
|
||||
* @param token_info token info to set parsed token counter to if successfully read and parsed
|
||||
* @param arg argument to parse
|
||||
* @param args rest of arguments
|
||||
* @param parsed will be set to \c true if token counter sucecssfully read and parsed; \c false otherwise
|
||||
* @return \c true if \c arg represents token counter argument; \c false otherwise
|
||||
*/
|
||||
bool totp_cli_try_read_token_counter(
|
||||
TokenInfo* token_info,
|
||||
FuriString* arg,
|
||||
FuriString* args,
|
||||
bool* parsed);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
4
applications/external/totp/cli/plugins/modify/update/meta.h
vendored
Normal file
4
applications/external/totp/cli/plugins/modify/update/meta.h
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
#define TOTP_CLI_COMMAND_UPDATE "update"
|
||||
#define TOTP_CLI_PLUGIN_UPDATE_FILE_NAME "totp_cli_update_plugin"
|
||||
@@ -1,12 +1,13 @@
|
||||
#include "update.h"
|
||||
#include <stdlib.h>
|
||||
#include <flipper_application/flipper_application.h>
|
||||
#include <lib/toolbox/args.h>
|
||||
#include "../../../types/token_info.h"
|
||||
#include "../../../services/config/config.h"
|
||||
#include "../../../services/convert/convert.h"
|
||||
#include "../../cli_helpers.h"
|
||||
#include "../../../ui/scene_director.h"
|
||||
#include "../../common_command_arguments.h"
|
||||
#include "../../../cli_helpers.h"
|
||||
#include "../../../cli_shared_methods.h"
|
||||
#include "../../../cli_plugin_interface.h"
|
||||
#include "../../../../types/token_info.h"
|
||||
#include "../../../../services/config/config.h"
|
||||
#include "../../../../services/convert/convert.h"
|
||||
#include "../../../../ui/scene_director.h"
|
||||
#include "../common.h"
|
||||
|
||||
#define TOTP_CLI_COMMAND_UPDATE_ARG_SECRET_PREFIX "-s"
|
||||
|
||||
@@ -70,7 +71,9 @@ static TotpIteratorUpdateTokenResult
|
||||
!totp_cli_try_read_change_secret_flag(temp_str, &parsed, &update_token_secret) &&
|
||||
!totp_cli_try_read_automation_features(token_info, temp_str, context_t->args, &parsed) &&
|
||||
!totp_cli_try_read_plain_token_secret_encoding(
|
||||
temp_str, context_t->args, &parsed, &token_secret_encoding)) {
|
||||
temp_str, context_t->args, &parsed, &token_secret_encoding) &&
|
||||
!totp_cli_try_read_token_type(token_info, temp_str, context_t->args, &parsed) &&
|
||||
!totp_cli_try_read_token_counter(token_info, temp_str, context_t->args, &parsed)) {
|
||||
totp_cli_printf_unknown_argument(temp_str);
|
||||
}
|
||||
|
||||
@@ -85,7 +88,7 @@ static TotpIteratorUpdateTokenResult
|
||||
furi_string_reset(temp_str);
|
||||
TOTP_CLI_PRINTF("Enter token secret and confirm with [ENTER]:\r\n");
|
||||
bool token_secret_read = totp_cli_read_line(context_t->cli, temp_str, mask_user_input);
|
||||
totp_cli_delete_last_line();
|
||||
TOTP_CLI_DELETE_LAST_LINE();
|
||||
if(!token_secret_read) {
|
||||
furi_string_secure_free(temp_str);
|
||||
return TotpIteratorUpdateTokenResultCancelled;
|
||||
@@ -107,32 +110,7 @@ static TotpIteratorUpdateTokenResult
|
||||
return TotpIteratorUpdateTokenResultSuccess;
|
||||
}
|
||||
|
||||
#ifdef TOTP_CLI_RICH_HELP_ENABLED
|
||||
void totp_cli_command_update_docopt_commands() {
|
||||
TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_UPDATE " Update existing token\r\n");
|
||||
}
|
||||
|
||||
void totp_cli_command_update_docopt_usage() {
|
||||
TOTP_CLI_PRINTF(
|
||||
" " TOTP_CLI_COMMAND_NAME
|
||||
" " DOCOPT_REQUIRED(TOTP_CLI_COMMAND_UPDATE) " " DOCOPT_ARGUMENT(TOTP_CLI_COMMAND_ARG_INDEX) " " DOCOPT_OPTIONAL(DOCOPT_OPTION(TOTP_CLI_COMMAND_ARG_ALGO_PREFIX, DOCOPT_ARGUMENT(TOTP_CLI_COMMAND_ARG_ALGO))) " " DOCOPT_OPTIONAL(DOCOPT_OPTION(TOTP_CLI_COMMAND_ARG_SECRET_ENCODING_PREFIX, DOCOPT_ARGUMENT(TOTP_CLI_COMMAND_ARG_SECRET_ENCODING))) " " DOCOPT_OPTIONAL(DOCOPT_OPTION(TOTP_CLI_COMMAND_ARG_NAME_PREFIX, DOCOPT_ARGUMENT(TOTP_CLI_COMMAND_ARG_NAME))) " " DOCOPT_OPTIONAL(
|
||||
DOCOPT_OPTION(
|
||||
TOTP_CLI_COMMAND_ARG_DIGITS_PREFIX,
|
||||
DOCOPT_ARGUMENT(
|
||||
TOTP_CLI_COMMAND_ARG_DIGITS))) " " DOCOPT_OPTIONAL(DOCOPT_OPTION(TOTP_CLI_COMMAND_ARG_DURATION_PREFIX, DOCOPT_ARGUMENT(TOTP_CLI_COMMAND_ARG_DURATION))) " " DOCOPT_OPTIONAL(DOCOPT_SWITCH(TOTP_CLI_COMMAND_ARG_UNSECURE_PREFIX)) " " DOCOPT_OPTIONAL(DOCOPT_SWITCH(TOTP_CLI_COMMAND_UPDATE_ARG_SECRET_PREFIX)) " " DOCOPT_MULTIPLE(DOCOPT_OPTIONAL(DOCOPT_OPTION(TOTP_CLI_COMMAND_ARG_AUTOMATION_FEATURE_PREFIX, DOCOPT_ARGUMENT(TOTP_CLI_COMMAND_ARG_AUTOMATION_FEATURE)))) "\r\n");
|
||||
}
|
||||
|
||||
void totp_cli_command_update_docopt_options() {
|
||||
TOTP_CLI_PRINTF(" " DOCOPT_OPTION(
|
||||
TOTP_CLI_COMMAND_ARG_NAME_PREFIX,
|
||||
DOCOPT_ARGUMENT(TOTP_CLI_COMMAND_ARG_NAME)) " Token name\r\n");
|
||||
|
||||
TOTP_CLI_PRINTF(" " DOCOPT_SWITCH(
|
||||
TOTP_CLI_COMMAND_UPDATE_ARG_SECRET_PREFIX) " Update token secret\r\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
void totp_cli_command_update_handle(PluginState* plugin_state, FuriString* args, Cli* cli) {
|
||||
static void handle(PluginState* plugin_state, FuriString* args, Cli* cli) {
|
||||
if(!totp_cli_ensure_authenticated(plugin_state, cli)) {
|
||||
return;
|
||||
}
|
||||
@@ -143,7 +121,7 @@ void totp_cli_command_update_handle(PluginState* plugin_state, FuriString* args,
|
||||
int token_number;
|
||||
if(!args_read_int_and_trim(args, &token_number) || token_number <= 0 ||
|
||||
(size_t)token_number > totp_token_info_iterator_get_total_count(iterator_context)) {
|
||||
totp_cli_print_invalid_arguments();
|
||||
TOTP_CLI_PRINT_INVALID_ARGUMENTS();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -163,15 +141,27 @@ void totp_cli_command_update_handle(PluginState* plugin_state, FuriString* args,
|
||||
furi_string_get_cstr(
|
||||
totp_token_info_iterator_get_current_token(iterator_context)->name));
|
||||
} else if(update_result == TotpIteratorUpdateTokenResultInvalidArguments) {
|
||||
totp_cli_print_invalid_arguments();
|
||||
TOTP_CLI_PRINT_INVALID_ARGUMENTS();
|
||||
} else if(update_result == TotpIteratorUpdateTokenResultCancelled) {
|
||||
TOTP_CLI_PRINTF_INFO("Cancelled by user\r\n");
|
||||
} else if(update_result == TotpIteratorUpdateTokenResultInvalidSecret) {
|
||||
TOTP_CLI_PRINTF_ERROR("Token secret seems to be invalid and can not be parsed\r\n");
|
||||
} else if(update_result == TotpIteratorUpdateTokenResultFileUpdateFailed) {
|
||||
totp_cli_print_error_updating_config_file();
|
||||
TOTP_CLI_PRINT_ERROR_UPDATING_CONFIG_FILE();
|
||||
}
|
||||
|
||||
totp_token_info_iterator_go_to(iterator_context, previous_index);
|
||||
TOTP_CLI_UNLOCK_UI(plugin_state);
|
||||
}
|
||||
}
|
||||
|
||||
static const CliPlugin plugin = {.name = "TOTP CLI Plugin: Update", .handle = &handle};
|
||||
|
||||
static const FlipperAppPluginDescriptor plugin_descriptor = {
|
||||
.appid = PLUGIN_APP_ID,
|
||||
.ep_api_version = PLUGIN_API_VERSION,
|
||||
.entry_point = &plugin,
|
||||
};
|
||||
|
||||
const FlipperAppPluginDescriptor* totp_cli_update_plugin_ep() {
|
||||
return &plugin_descriptor;
|
||||
}
|
||||
5
applications/external/totp/cli/plugins/move/meta.h
vendored
Normal file
5
applications/external/totp/cli/plugins/move/meta.h
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#define TOTP_CLI_COMMAND_MOVE "move"
|
||||
#define TOTP_CLI_COMMAND_MOVE_ALT "mv"
|
||||
#define TOTP_CLI_PLUGIN_MOVE_FILE_NAME "totp_cli_move_plugin"
|
||||
@@ -1,35 +1,13 @@
|
||||
#include "move.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <flipper_application/flipper_application.h>
|
||||
#include <lib/toolbox/args.h>
|
||||
#include "../../cli_helpers.h"
|
||||
#include "../../cli_shared_methods.h"
|
||||
#include "../../cli_plugin_interface.h"
|
||||
#include "../../../types/token_info.h"
|
||||
#include "../../../services/config/config.h"
|
||||
#include "../../cli_helpers.h"
|
||||
#include "../../../ui/scene_director.h"
|
||||
#include "../../common_command_arguments.h"
|
||||
|
||||
#define TOTP_CLI_COMMAND_MOVE_ARG_NEW_INDEX "new_index"
|
||||
|
||||
#ifdef TOTP_CLI_RICH_HELP_ENABLED
|
||||
void totp_cli_command_move_docopt_commands() {
|
||||
TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_MOVE ", " TOTP_CLI_COMMAND_MOVE_ALT
|
||||
" Move token\r\n");
|
||||
}
|
||||
|
||||
void totp_cli_command_move_docopt_usage() {
|
||||
TOTP_CLI_PRINTF(
|
||||
" " TOTP_CLI_COMMAND_NAME
|
||||
" " 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");
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
#endif
|
||||
|
||||
void totp_cli_command_move_handle(PluginState* plugin_state, FuriString* args, Cli* cli) {
|
||||
static void handle(PluginState* plugin_state, FuriString* args, Cli* cli) {
|
||||
if(!totp_cli_ensure_authenticated(plugin_state, cli)) {
|
||||
return;
|
||||
}
|
||||
@@ -40,7 +18,7 @@ void totp_cli_command_move_handle(PluginState* plugin_state, FuriString* args, C
|
||||
size_t total_count = totp_token_info_iterator_get_total_count(iterator_context);
|
||||
if(!args_read_int_and_trim(args, &token_number) || token_number < 1 ||
|
||||
(size_t)token_number > total_count) {
|
||||
totp_cli_print_invalid_arguments();
|
||||
TOTP_CLI_PRINT_INVALID_ARGUMENTS();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -48,7 +26,7 @@ void totp_cli_command_move_handle(PluginState* plugin_state, FuriString* args, C
|
||||
|
||||
if(!args_read_int_and_trim(args, &new_token_number) || new_token_number < 1 ||
|
||||
(size_t)new_token_number > total_count) {
|
||||
totp_cli_print_invalid_arguments();
|
||||
TOTP_CLI_PRINT_INVALID_ARGUMENTS();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -65,21 +43,33 @@ void totp_cli_command_move_handle(PluginState* plugin_state, FuriString* args, C
|
||||
size_t original_token_index =
|
||||
totp_token_info_iterator_get_current_token_index(iterator_context);
|
||||
|
||||
totp_cli_print_processing();
|
||||
TOTP_CLI_PRINT_PROCESSING();
|
||||
|
||||
if(totp_token_info_iterator_go_to(iterator_context, token_index) &&
|
||||
totp_token_info_iterator_move_current_token_info(iterator_context, new_token_index)) {
|
||||
totp_cli_delete_last_line();
|
||||
TOTP_CLI_DELETE_LAST_LINE();
|
||||
TOTP_CLI_PRINTF_SUCCESS(
|
||||
"Token \"%s\" has been successfully updated\r\n",
|
||||
furi_string_get_cstr(
|
||||
totp_token_info_iterator_get_current_token(iterator_context)->name));
|
||||
} else {
|
||||
totp_cli_delete_last_line();
|
||||
totp_cli_print_error_updating_config_file();
|
||||
TOTP_CLI_DELETE_LAST_LINE();
|
||||
TOTP_CLI_PRINT_ERROR_UPDATING_CONFIG_FILE();
|
||||
}
|
||||
|
||||
totp_token_info_iterator_go_to(iterator_context, original_token_index);
|
||||
|
||||
TOTP_CLI_UNLOCK_UI(plugin_state);
|
||||
}
|
||||
|
||||
static const CliPlugin plugin = {.name = "TOTP CLI Plugin: Move", .handle = &handle};
|
||||
|
||||
static const FlipperAppPluginDescriptor plugin_descriptor = {
|
||||
.appid = PLUGIN_APP_ID,
|
||||
.ep_api_version = PLUGIN_API_VERSION,
|
||||
.entry_point = &plugin,
|
||||
};
|
||||
|
||||
const FlipperAppPluginDescriptor* totp_cli_move_plugin_ep() {
|
||||
return &plugin_descriptor;
|
||||
}
|
||||
4
applications/external/totp/cli/plugins/notification/meta.h
vendored
Normal file
4
applications/external/totp/cli/plugins/notification/meta.h
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
#define TOTP_CLI_COMMAND_NOTIFICATION "notify"
|
||||
#define TOTP_CLI_PLUGIN_NOTIFICATION_FILE_NAME "totp_cli_notification_plugin"
|
||||
@@ -1,35 +1,15 @@
|
||||
#include "notification.h"
|
||||
#include <flipper_application/flipper_application.h>
|
||||
#include <lib/toolbox/args.h>
|
||||
#include "../../../services/config/config.h"
|
||||
#include "../../../ui/scene_director.h"
|
||||
#include "../../cli_helpers.h"
|
||||
#include "../../cli_shared_methods.h"
|
||||
#include "../../cli_plugin_interface.h"
|
||||
|
||||
#define TOTP_CLI_COMMAND_NOTIFICATION_ARG_METHOD "notification"
|
||||
#define TOTP_CLI_COMMAND_NOTIFICATION_METHOD_NONE "none"
|
||||
#define TOTP_CLI_COMMAND_NOTIFICATION_METHOD_SOUND "sound"
|
||||
#define TOTP_CLI_COMMAND_NOTIFICATION_METHOD_VIBRO "vibro"
|
||||
|
||||
#ifdef TOTP_CLI_RICH_HELP_ENABLED
|
||||
void totp_cli_command_notification_docopt_commands() {
|
||||
TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_NOTIFICATION
|
||||
" Get or set notification method\r\n");
|
||||
}
|
||||
|
||||
void totp_cli_command_notification_docopt_usage() {
|
||||
TOTP_CLI_PRINTF(
|
||||
" " TOTP_CLI_COMMAND_NAME " " TOTP_CLI_COMMAND_NOTIFICATION " " DOCOPT_OPTIONAL(
|
||||
DOCOPT_MULTIPLE(DOCOPT_ARGUMENT(TOTP_CLI_COMMAND_NOTIFICATION_ARG_METHOD))) "\r\n");
|
||||
}
|
||||
|
||||
void totp_cli_command_notification_docopt_arguments() {
|
||||
TOTP_CLI_PRINTF(
|
||||
" " TOTP_CLI_COMMAND_NOTIFICATION_ARG_METHOD
|
||||
" Notification method to be set. Must be one of: " TOTP_CLI_COMMAND_NOTIFICATION_METHOD_NONE
|
||||
", " TOTP_CLI_COMMAND_NOTIFICATION_METHOD_SOUND
|
||||
", " TOTP_CLI_COMMAND_NOTIFICATION_METHOD_VIBRO "\r\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
totp_cli_command_notification_print_method(NotificationMethod method, const char* color) {
|
||||
bool has_previous_method = false;
|
||||
@@ -49,7 +29,7 @@ static void
|
||||
}
|
||||
}
|
||||
|
||||
void totp_cli_command_notification_handle(PluginState* plugin_state, FuriString* args, Cli* cli) {
|
||||
static void handle(PluginState* plugin_state, FuriString* args, Cli* cli) {
|
||||
if(!totp_cli_ensure_authenticated(plugin_state, cli)) {
|
||||
return;
|
||||
}
|
||||
@@ -76,7 +56,7 @@ void totp_cli_command_notification_handle(PluginState* plugin_state, FuriString*
|
||||
|
||||
do {
|
||||
if(!args_valid) {
|
||||
totp_cli_print_invalid_arguments();
|
||||
TOTP_CLI_PRINT_INVALID_ARGUMENTS();
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -89,7 +69,7 @@ void totp_cli_command_notification_handle(PluginState* plugin_state, FuriString*
|
||||
totp_cli_command_notification_print_method(new_method, TOTP_CLI_COLOR_SUCCESS);
|
||||
cli_nl();
|
||||
} else {
|
||||
totp_cli_print_error_updating_config_file();
|
||||
TOTP_CLI_PRINT_ERROR_UPDATING_CONFIG_FILE();
|
||||
}
|
||||
|
||||
TOTP_CLI_UNLOCK_UI(plugin_state);
|
||||
@@ -102,4 +82,16 @@ void totp_cli_command_notification_handle(PluginState* plugin_state, FuriString*
|
||||
} while(false);
|
||||
|
||||
furi_string_free(temp_str);
|
||||
}
|
||||
|
||||
static const CliPlugin plugin = {.name = "TOTP CLI Plugin: Notification", .handle = &handle};
|
||||
|
||||
static const FlipperAppPluginDescriptor plugin_descriptor = {
|
||||
.appid = PLUGIN_APP_ID,
|
||||
.ep_api_version = PLUGIN_API_VERSION,
|
||||
.entry_point = &plugin,
|
||||
};
|
||||
|
||||
const FlipperAppPluginDescriptor* totp_cli_notification_plugin_ep() {
|
||||
return &plugin_descriptor;
|
||||
}
|
||||
4
applications/external/totp/cli/plugins/pin/meta.h
vendored
Normal file
4
applications/external/totp/cli/plugins/pin/meta.h
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
#define TOTP_CLI_COMMAND_PIN "pin"
|
||||
#define TOTP_CLI_PLUGIN_PIN_FILE_NAME "totp_cli_pin_plugin"
|
||||
@@ -1,44 +1,18 @@
|
||||
#include "pin.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <flipper_application/flipper_application.h>
|
||||
#include <lib/toolbox/args.h>
|
||||
#include "../../cli_helpers.h"
|
||||
#include "../../cli_shared_methods.h"
|
||||
#include "../../cli_plugin_interface.h"
|
||||
#include "../../../types/token_info.h"
|
||||
#include "../../../types/user_pin_codes.h"
|
||||
#include "../../../services/config/config.h"
|
||||
#include "../../cli_helpers.h"
|
||||
#include <memset_s.h>
|
||||
#include "../../../services/crypto/crypto_facade.h"
|
||||
#include "../../../ui/scene_director.h"
|
||||
#include "../../../lib/polyfills/memset_s.h"
|
||||
|
||||
#define TOTP_CLI_COMMAND_PIN_COMMAND_SET "set"
|
||||
#define TOTP_CLI_COMMAND_PIN_COMMAND_REMOVE "remove"
|
||||
#define TOTP_CLI_COMMAND_PIN_ARG_NEW_CRYPTO_KEY_SLOT_PREFIX "-c"
|
||||
#define TOTP_CLI_COMMAND_PIN_ARG_NEW_CRYPTO_KEY_SLOT "slot"
|
||||
|
||||
#ifdef TOTP_CLI_RICH_HELP_ENABLED
|
||||
void totp_cli_command_pin_docopt_commands() {
|
||||
TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_PIN " Set\\change\\remove PIN\r\n");
|
||||
}
|
||||
|
||||
void totp_cli_command_pin_docopt_usage() {
|
||||
TOTP_CLI_PRINTF(
|
||||
" " TOTP_CLI_COMMAND_NAME " " TOTP_CLI_COMMAND_PIN
|
||||
" " DOCOPT_REQUIRED(TOTP_CLI_COMMAND_PIN_COMMAND_SET " | " TOTP_CLI_COMMAND_PIN_COMMAND_REMOVE) " " DOCOPT_OPTIONAL(
|
||||
DOCOPT_OPTION(
|
||||
TOTP_CLI_COMMAND_PIN_ARG_NEW_CRYPTO_KEY_SLOT_PREFIX,
|
||||
DOCOPT_ARGUMENT(TOTP_CLI_COMMAND_PIN_ARG_NEW_CRYPTO_KEY_SLOT))) "\r\n");
|
||||
}
|
||||
|
||||
void totp_cli_command_pin_docopt_options() {
|
||||
TOTP_CLI_PRINTF(
|
||||
" " DOCOPT_OPTION(
|
||||
TOTP_CLI_COMMAND_PIN_ARG_NEW_CRYPTO_KEY_SLOT_PREFIX,
|
||||
DOCOPT_ARGUMENT(
|
||||
TOTP_CLI_COMMAND_PIN_ARG_NEW_CRYPTO_KEY_SLOT)) " New crypto key slot. Must be between %d and %d\r\n",
|
||||
ACCEPTABLE_CRYPTO_KEY_SLOT_START,
|
||||
ACCEPTABLE_CRYPTO_KEY_SLOT_END);
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline uint8_t totp_cli_key_to_pin_code(uint8_t key) {
|
||||
uint8_t code = 0;
|
||||
@@ -82,14 +56,14 @@ static bool totp_cli_read_pin(Cli* cli, uint8_t* pin, uint8_t* pin_length) {
|
||||
}
|
||||
}
|
||||
} else if(c == CliSymbolAsciiETX) {
|
||||
totp_cli_delete_current_line();
|
||||
TOTP_CLI_DELETE_CURRENT_LINE();
|
||||
TOTP_CLI_PRINTF_INFO("Cancelled by user\r\n");
|
||||
return false;
|
||||
} else if(c == CliSymbolAsciiBackspace || c == CliSymbolAsciiDel) {
|
||||
if(*pin_length > 0) {
|
||||
*pin_length = *pin_length - 1;
|
||||
pin[*pin_length] = 0;
|
||||
totp_cli_delete_last_char();
|
||||
TOTP_CLI_DELETE_LAST_CHAR();
|
||||
}
|
||||
} else if(c == CliSymbolAsciiCR) {
|
||||
cli_nl();
|
||||
@@ -97,11 +71,11 @@ static bool totp_cli_read_pin(Cli* cli, uint8_t* pin, uint8_t* pin_length) {
|
||||
}
|
||||
}
|
||||
|
||||
totp_cli_delete_last_line();
|
||||
TOTP_CLI_DELETE_LAST_LINE();
|
||||
return true;
|
||||
}
|
||||
|
||||
void totp_cli_command_pin_handle(PluginState* plugin_state, FuriString* args, Cli* cli) {
|
||||
static void handle(PluginState* plugin_state, FuriString* args, Cli* cli) {
|
||||
UNUSED(plugin_state);
|
||||
FuriString* temp_str = furi_string_alloc();
|
||||
|
||||
@@ -125,14 +99,14 @@ void totp_cli_command_pin_handle(PluginState* plugin_state, FuriString* args, Cl
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
totp_cli_print_invalid_arguments();
|
||||
TOTP_CLI_PRINT_INVALID_ARGUMENTS();
|
||||
arguments_parsed = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!(do_change || do_remove) || (do_change && do_remove)) {
|
||||
totp_cli_print_invalid_arguments();
|
||||
TOTP_CLI_PRINT_INVALID_ARGUMENTS();
|
||||
arguments_parsed = false;
|
||||
}
|
||||
|
||||
@@ -172,7 +146,7 @@ void totp_cli_command_pin_handle(PluginState* plugin_state, FuriString* args, Cl
|
||||
|
||||
memset_s(&new_pin[0], CRYPTO_IV_LENGTH, 0, CRYPTO_IV_LENGTH);
|
||||
|
||||
totp_cli_delete_last_line();
|
||||
TOTP_CLI_DELETE_LAST_LINE();
|
||||
|
||||
if(update_result) {
|
||||
if(do_change) {
|
||||
@@ -181,7 +155,7 @@ void totp_cli_command_pin_handle(PluginState* plugin_state, FuriString* args, Cl
|
||||
TOTP_CLI_PRINTF_SUCCESS("PIN has been successfully removed\r\n");
|
||||
}
|
||||
} else {
|
||||
totp_cli_print_error_updating_config_file();
|
||||
TOTP_CLI_PRINT_ERROR_UPDATING_CONFIG_FILE();
|
||||
}
|
||||
|
||||
} while(false);
|
||||
@@ -190,4 +164,16 @@ void totp_cli_command_pin_handle(PluginState* plugin_state, FuriString* args, Cl
|
||||
}
|
||||
|
||||
furi_string_free(temp_str);
|
||||
}
|
||||
|
||||
static const CliPlugin plugin = {.name = "TOTP CLI Plugin: PIN", .handle = &handle};
|
||||
|
||||
static const FlipperAppPluginDescriptor plugin_descriptor = {
|
||||
.appid = PLUGIN_APP_ID,
|
||||
.ep_api_version = PLUGIN_API_VERSION,
|
||||
.entry_point = &plugin,
|
||||
};
|
||||
|
||||
const FlipperAppPluginDescriptor* totp_cli_pin_plugin_ep() {
|
||||
return &plugin_descriptor;
|
||||
}
|
||||
4
applications/external/totp/cli/plugins/reset/meta.h
vendored
Normal file
4
applications/external/totp/cli/plugins/reset/meta.h
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
#define TOTP_CLI_COMMAND_RESET "reset"
|
||||
#define TOTP_CLI_PLUGIN_RESET_FILE_NAME "totp_cli_reset_plugin"
|
||||
@@ -1,25 +1,14 @@
|
||||
#include "reset.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <furi/core/string.h>
|
||||
#include <flipper_application/flipper_application.h>
|
||||
#include "../../cli_helpers.h"
|
||||
#include "../../cli_shared_methods.h"
|
||||
#include "../../cli_plugin_interface.h"
|
||||
#include "../../../ui/scene_director.h"
|
||||
#include "../../../services/config/config.h"
|
||||
|
||||
#define TOTP_CLI_RESET_CONFIRMATION_KEYWORD "YES"
|
||||
|
||||
#ifdef TOTP_CLI_RICH_HELP_ENABLED
|
||||
void totp_cli_command_reset_docopt_commands() {
|
||||
TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_RESET
|
||||
" Reset application to default settings\r\n");
|
||||
}
|
||||
|
||||
void totp_cli_command_reset_docopt_usage() {
|
||||
TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_NAME " " TOTP_CLI_COMMAND_RESET "\r\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
void totp_cli_command_reset_handle(PluginState* plugin_state, Cli* cli) {
|
||||
static void handle(PluginState* plugin_state, FuriString* args, Cli* cli) {
|
||||
UNUSED(args);
|
||||
TOTP_CLI_LOCK_UI(plugin_state);
|
||||
TOTP_CLI_PRINTF_WARNING(
|
||||
"As a result of reset all the settings and tokens will be permanently lost.\r\n");
|
||||
@@ -39,4 +28,16 @@ void totp_cli_command_reset_handle(PluginState* plugin_state, Cli* cli) {
|
||||
TOTP_CLI_PRINTF_INFO("Action was not confirmed by user\r\n");
|
||||
TOTP_CLI_UNLOCK_UI(plugin_state);
|
||||
}
|
||||
}
|
||||
|
||||
static const CliPlugin plugin = {.name = "TOTP CLI Plugin: Reset", .handle = &handle};
|
||||
|
||||
static const FlipperAppPluginDescriptor plugin_descriptor = {
|
||||
.appid = PLUGIN_APP_ID,
|
||||
.ep_api_version = PLUGIN_API_VERSION,
|
||||
.entry_point = &plugin,
|
||||
};
|
||||
|
||||
const FlipperAppPluginDescriptor* totp_cli_reset_plugin_ep() {
|
||||
return &plugin_descriptor;
|
||||
}
|
||||
5
applications/external/totp/cli/plugins/timezone/meta.h
vendored
Normal file
5
applications/external/totp/cli/plugins/timezone/meta.h
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#define TOTP_CLI_COMMAND_TIMEZONE "timezone"
|
||||
#define TOTP_CLI_COMMAND_TIMEZONE_ALT "tz"
|
||||
#define TOTP_CLI_PLUGIN_TIMEZONE_FILE_NAME "totp_cli_timezone_plugin"
|
||||
@@ -1,31 +1,14 @@
|
||||
#include "timezone.h"
|
||||
#include <lib/toolbox/args.h>
|
||||
#include <flipper_application/flipper_application.h>
|
||||
#include "../../../services/config/config.h"
|
||||
#include "../../../ui/scene_director.h"
|
||||
#include "../../cli_helpers.h"
|
||||
#include "../../cli_plugin_interface.h"
|
||||
#include "../../cli_shared_methods.h"
|
||||
|
||||
#define TOTP_CLI_COMMAND_TIMEZONE_ARG_TIMEZONE "timezone"
|
||||
|
||||
#ifdef TOTP_CLI_RICH_HELP_ENABLED
|
||||
void totp_cli_command_timezone_docopt_commands() {
|
||||
TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_TIMEZONE ", " TOTP_CLI_COMMAND_TIMEZONE_ALT
|
||||
" Get or set current timezone\r\n");
|
||||
}
|
||||
|
||||
void totp_cli_command_timezone_docopt_usage() {
|
||||
TOTP_CLI_PRINTF(
|
||||
" " TOTP_CLI_COMMAND_NAME
|
||||
" " DOCOPT_REQUIRED(TOTP_CLI_COMMAND_TIMEZONE " | " TOTP_CLI_COMMAND_TIMEZONE_ALT) " " DOCOPT_OPTIONAL(
|
||||
DOCOPT_ARGUMENT(TOTP_CLI_COMMAND_TIMEZONE_ARG_TIMEZONE)) "\r\n");
|
||||
}
|
||||
|
||||
void totp_cli_command_timezone_docopt_arguments() {
|
||||
TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_TIMEZONE_ARG_TIMEZONE
|
||||
" Timezone offset in hours to be set\r\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
void totp_cli_command_timezone_handle(PluginState* plugin_state, FuriString* args, Cli* cli) {
|
||||
static void handle(PluginState* plugin_state, FuriString* args, Cli* cli) {
|
||||
UNUSED(args);
|
||||
UNUSED(plugin_state);
|
||||
if(!totp_cli_ensure_authenticated(plugin_state, cli)) {
|
||||
return;
|
||||
}
|
||||
@@ -40,7 +23,7 @@ void totp_cli_command_timezone_handle(PluginState* plugin_state, FuriString* arg
|
||||
if(totp_config_file_update_timezone_offset(plugin_state)) {
|
||||
TOTP_CLI_PRINTF_SUCCESS("Timezone is set to %f\r\n", (double)tz);
|
||||
} else {
|
||||
totp_cli_print_error_updating_config_file();
|
||||
TOTP_CLI_PRINT_ERROR_UPDATING_CONFIG_FILE();
|
||||
}
|
||||
TOTP_CLI_UNLOCK_UI(plugin_state);
|
||||
} else {
|
||||
@@ -51,4 +34,16 @@ void totp_cli_command_timezone_handle(PluginState* plugin_state, FuriString* arg
|
||||
"Current timezone offset is %f\r\n", (double)plugin_state->timezone_offset);
|
||||
}
|
||||
furi_string_free(temp_str);
|
||||
}
|
||||
|
||||
static const CliPlugin plugin = {.name = "TOTP CLI Plugin: Timezone", .handle = &handle};
|
||||
|
||||
static const FlipperAppPluginDescriptor plugin_descriptor = {
|
||||
.appid = PLUGIN_APP_ID,
|
||||
.ep_api_version = PLUGIN_API_VERSION,
|
||||
.entry_point = &plugin,
|
||||
};
|
||||
|
||||
const FlipperAppPluginDescriptor* totp_cli_timezone_plugin_ep() {
|
||||
return &plugin_descriptor;
|
||||
}
|
||||
4
applications/external/totp/cli/plugins/version/meta.h
vendored
Normal file
4
applications/external/totp/cli/plugins/version/meta.h
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
#define TOTP_CLI_COMMAND_VERSION "version"
|
||||
#define TOTP_CLI_PLUGIN_VERSION_FILE_NAME "totp_cli_version_plugin"
|
||||
27
applications/external/totp/cli/plugins/version/version.c
vendored
Normal file
27
applications/external/totp/cli/plugins/version/version.c
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
#include <flipper_application/flipper_application.h>
|
||||
#include "../../cli_helpers.h"
|
||||
#include "../../cli_plugin_interface.h"
|
||||
#include "../../../version.h"
|
||||
|
||||
static void handle(PluginState* plugin_state, FuriString* args, Cli* cli) {
|
||||
UNUSED(args);
|
||||
UNUSED(cli);
|
||||
UNUSED(plugin_state);
|
||||
TOTP_CLI_PRINTF(
|
||||
"%" PRIu8 ".%" PRIu8 ".%" PRIu8 "\r\n",
|
||||
TOTP_APP_VERSION_MAJOR,
|
||||
TOTP_APP_VERSION_MINOR,
|
||||
TOTP_APP_VERSION_PATCH);
|
||||
}
|
||||
|
||||
static const CliPlugin plugin = {.name = "TOTP CLI Plugin: Version", .handle = &handle};
|
||||
|
||||
static const FlipperAppPluginDescriptor plugin_descriptor = {
|
||||
.appid = PLUGIN_APP_ID,
|
||||
.ep_api_version = PLUGIN_API_VERSION,
|
||||
.entry_point = &plugin,
|
||||
};
|
||||
|
||||
const FlipperAppPluginDescriptor* totp_cli_version_plugin_ep() {
|
||||
return &plugin_descriptor;
|
||||
}
|
||||
Reference in New Issue
Block a user