19#include <mbedtls/platform_util.h>
29constexpr uint16_t PASSPHRASE_MAX = 64;
34static ListView* s_backupMenu =
nullptr;
37static char s_firstPass[PASSPHRASE_MAX + 1] = {0};
41 mbedtls_platform_zeroize(s_firstPass,
sizeof(s_firstPass));
45 s_passInput.init(title,
nullptr, PASSPHRASE_MAX);
46 s_passInput.setOnSave(onSave);
52void onExportConfirm(
const char* text) {
53 if (!text || std::strcmp(text, s_firstPass) != 0) {
68void onExportFirst(
const char* text) {
69 if (!text || text[0] ==
'\0') {
73 strncpy(s_firstPass, text, PASSPHRASE_MAX);
74 s_firstPass[PASSPHRASE_MAX] =
'\0';
75 pushPassphrase(
ui::tr(
"core.backup_confirm_passphrase"), onExportConfirm);
80 pushPassphrase(
ui::tr(
"core.backup_passphrase"), onExportFirst);
85void onImportPass(
const char* text) {
86 if (!text || text[0] ==
'\0') {
100 snprintf(s_summaryText,
sizeof(s_summaryText),
101 "%s\n\n%s: %u\n%s: %u\n%s: %u\n%s: %u\n%s: %s",
102 ui::tr(
"core.backup_scope_info"),
103 ui::tr(
"core.backup_imported"), s.imported,
104 ui::tr(
"core.backup_failed"), s.failed,
105 ui::tr(
"core.backup_modules"), s.modules,
106 ui::tr(
"core.backup_skipped"), s.skipped,
107 ui::tr(
"core.backup_system"),
108 ui::tr(s.system ?
"core.yes" :
"core.no"));
117 pushPassphrase(
ui::tr(
"core.backup_passphrase"), onImportPass);
122void onDeleteConfirm(
void* ) {
139void onBackupMenuSelect(uint16_t index,
void* ) {
141 case 0: startExport();
break;
142 case 1: startImport();
break;
143 case 2: startDelete();
break;
150using cdc::serial::Console;
152void cmdBackupExport(
const char* args) {
153 if (!args || !*args) {
Console::printf(
"Usage: BACKUP EXPORT <passphrase>\r\n");
return; }
161void cmdBackupImport(
const char* args) {
162 if (!args || !*args) {
Console::printf(
"Usage: BACKUP IMPORT <passphrase>\r\n");
return; }
169 Console::printf(
"ERROR: Import failed (wrong passphrase or corrupt file)\r\n");
173 Console::printf(
"OK: imported=%u failed=%u modules=%u skipped=%u system=%u\r\n",
174 s.imported, s.failed, s.modules, s.skipped, s.system ? 1 : 0);
177void cmdBackupDelete(
const char* ) {
183 ?
"OK: Backup deleted\r\n"
184 :
"ERROR: Delete failed\r\n");
187const cdc::serial::SubCommand kBackupSubs[] = {
188 {
"EXPORT",
"<passphrase>",
"Write encrypted backup to vFAT", cmdBackupExport},
189 {
"IMPORT",
"<passphrase>",
"Restore from the on-device backup", cmdBackupImport},
190 {
"DELETE",
"",
"Delete the on-device backup", cmdBackupDelete},
191 {
nullptr,
nullptr,
nullptr,
nullptr},
194void cmdBackup(
const char* args) {
206 s_backupMenu->setOnSelect(onBackupMenuSelect);
208 s_backupItems[0] = {
ui::tr(
"core.backup_export"), 0,
false,
nullptr};
209 s_backupItems[1] = {
ui::tr(
"core.backup_import"), 0,
false,
nullptr};
210 s_backupItems[2] = {
ui::tr(
"core.backup_delete"), 0,
false,
nullptr};
211 s_backupMenu->init(
ui::tr(
"core.backup"), s_backupItems, 3);
220 {
"BACKUP",
"Encrypted backup: EXPORT/IMPORT/DELETE",
221 cmdBackup,
"backup",
true, kBackupSubs});
bool exportTo(const char *passphrase)
Exports all module sections into one encrypted backup file.
BackupSummary importFrom(const char *passphrase)
Restores from the on-device backup file (best-effort).
bool deleteBackup()
Deletes the on-device backup file.
static BackupManager & instance()
Returns the process-wide singleton.
virtual bool registerCommand(const Command &cmd)=0
static void printf(const char *format,...) __attribute__((format(printf
Prints formatted text to console.
static constexpr uint16_t MAX_TEXT_LEN
T9 input variant for secrets: displays asterisks instead of letters and offers a long-press reveal to...
static ViewStack & instance()
Returns singleton view-stack instance.
void push(IView *view, void *context=nullptr)
ICommandRegistry & getCommandRegistry()
Returns singleton command-registry interface.
void dispatchSubCommand(const char *parent, const char *args, const SubCommand *table)
Routes a sub-command line to its handler.
Centralized key-code constants for cdc_views.
const char * tr(const char *key)
Look up a translation by string key.
void showToast(const char *message, uint16_t durationMs=1500)
Shows a plain toast message.
InfoView * showInfo(const char *title, const char *text, const char *hint=nullptr)
Shows a shared info view instance and pushes it onto the view stack.
static constexpr uint32_t TOAST_DURATION_LONG_MS
void showToastTask(const char *message, uint16_t durationMs=0)
Shows a task/progress toast message.
static constexpr uint32_t TOAST_DURATION_MEDIUM_MS
void registerBackupSerialCommand()
Registers the AUTH-gated BACKUP serial command.
void showConfirm(const char *message, ConfirmView::ConfirmCallback onConfirm, ConfirmView::CancelCallback onCancel=nullptr, ConfirmView::Icon icon=ConfirmView::Icon::QUESTION, void *userData=nullptr)
Shows a shared modal confirmation dialog instance.
static constexpr uint32_t TOAST_DURATION_SHORT_MS
void showToastInfo(const char *message, uint16_t durationMs=1500)
Shows an informational toast message.
void showToastError(const char *message, uint16_t durationMs=1500)
Shows an error toast message.
void showBackupMenu()
Shows the Backup submenu (Export / Import / Delete).