From 94501e9ee11a2da954204e477f95a3ee9fd535a4 Mon Sep 17 00:00:00 2001 From: Whispering Wind <151555003+ReturnFI@users.noreply.github.com> Date: Sat, 22 Feb 2025 00:27:10 +0330 Subject: [PATCH] Added Restore CLI API --- core/cli_api.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/core/cli_api.py b/core/cli_api.py index 5efb8f3..cd7d28e 100644 --- a/core/cli_api.py +++ b/core/cli_api.py @@ -36,6 +36,7 @@ class Command(Enum): LIST_USERS = os.path.join(SCRIPT_DIR, 'hysteria2', 'list_users.sh') SERVER_INFO = os.path.join(SCRIPT_DIR, 'hysteria2', 'server_info.sh') BACKUP_HYSTERIA2 = os.path.join(SCRIPT_DIR, 'hysteria2', 'backup.sh') + RESTORE_HYSTERIA2 = os.path.join(SCRIPT_DIR, 'hysteria2', 'restore.sh') INSTALL_TELEGRAMBOT = os.path.join(SCRIPT_DIR, 'telegrambot', 'runbot.sh') SHELL_SINGBOX = os.path.join(SCRIPT_DIR, 'singbox', 'singbox_shell.sh') SHELL_WEBPANEL = os.path.join(SCRIPT_DIR, 'webpanel', 'webpanel_shell.sh') @@ -171,8 +172,22 @@ def change_hysteria2_sni(sni: str): def backup_hysteria2(): - '''Backups Hysteria configuration.''' - run_cmd(['bash', Command.BACKUP_HYSTERIA2.value]) + '''Backups Hysteria configuration. Raises an exception on failure.''' + try: + run_cmd(['bash', Command.BACKUP_HYSTERIA2.value]) + except subprocess.CalledProcessError as e: + raise Exception(f"Backup failed: {e}") + except Exception as ex: + raise + +def restore_hysteria2(backup_file_path): + '''Restores Hysteria configuration from the given backup file.''' + try: + run_cmd(['bash', Command.RESTORE_HYSTERIA2.value, backup_file_path]) + except subprocess.CalledProcessError as e: + raise Exception(f"Restore failed: {e}") + except Exception as ex: + raise def enable_hysteria2_obfs():