diff --git a/core/scripts/webpanel/routers/api/v1/config/hysteria.py b/core/scripts/webpanel/routers/api/v1/config/hysteria.py index f428d88..6044547 100644 --- a/core/scripts/webpanel/routers/api/v1/config/hysteria.py +++ b/core/scripts/webpanel/routers/api/v1/config/hysteria.py @@ -159,7 +159,7 @@ async def restore_api(file: UploadFile = File(...)): detail=f"Backup is missing required configuration files: {', '.join(missing_files)}" ) - db_dump_prefix = "hysteria_panel/" + db_dump_prefix = "blitz_panel/" if not any(name.startswith(db_dump_prefix) for name in namelist): raise HTTPException( status_code=400, diff --git a/install.sh b/install.sh index 3ecbe43..fae7963 100644 --- a/install.sh +++ b/install.sh @@ -75,14 +75,49 @@ check_os_version() { fi } +install_mongodb() { + log_info "Installing MongoDB..." + + if command -v mongod &> /dev/null; then + log_success "MongoDB is already installed" + return 0 + fi + + local os_name + os_name=$(grep '^ID=' /etc/os-release | cut -d= -f2) + + curl -fsSL https://www.mongodb.org/static/pgp/server-7.0.asc | gpg --dearmor -o /usr/share/keyrings/mongodb-server-7.0.gpg + + if [[ "$os_name" == "ubuntu" ]]; then + local ubuntu_codename + ubuntu_codename=$(lsb_release -cs 2>/dev/null || echo "jammy") + echo "deb [arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg] https://repo.mongodb.org/apt/ubuntu ${ubuntu_codename}/mongodb-org/7.0 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-7.0.list > /dev/null + elif [[ "$os_name" == "debian" ]]; then + echo "deb [signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg] http://repo.mongodb.org/apt/debian bookworm/mongodb-org/7.0 main" | tee /etc/apt/sources.list.d/mongodb-org-7.0.list > /dev/null + fi + + apt update -qq + apt install -y -qq mongodb-org + + systemctl enable mongod + systemctl start mongod + + if systemctl is-active --quiet mongod; then + log_success "MongoDB installed and started successfully" + else + log_error "MongoDB installation failed or service not running" + exit 1 + fi +} + install_packages() { - local REQUIRED_PACKAGES=("jq" "curl" "pwgen" "python3" "python3-pip" "python3-venv" "git" "bc" "zip" "cron" "lsof" "golang-go") + local REQUIRED_PACKAGES=("jq" "curl" "pwgen" "python3" "python3-pip" "python3-venv" "git" "bc" "zip" "cron" "lsof" "golang-go" "gnupg" "lsb-release") local MISSING_PACKAGES=() log_info "Checking required packages..." for package in "${REQUIRED_PACKAGES[@]}"; do - if ! command -v "$package" &> /dev/null; then + if ! command -v "$package" &> /dev/null && ! dpkg -l | grep -q "^ii.*$package "; then MISSING_PACKAGES+=("$package") else log_success "Package $package is already installed" @@ -106,6 +141,8 @@ install_packages() { else log_success "All required packages are already installed." fi + + install_mongodb } clone_repository() { @@ -194,4 +231,4 @@ main() { run_menu } -main +main \ No newline at end of file diff --git a/upgrade.sh b/upgrade.sh index 9e08d67..ddab18f 100644 --- a/upgrade.sh +++ b/upgrade.sh @@ -11,6 +11,7 @@ REPO_URL="https://github.com/ReturnFI/Blitz" REPO_BRANCH="main" GEOSITE_URL="https://raw.githubusercontent.com/Chocolate4U/Iran-v2ray-rules/release/geosite.dat" GEOIP_URL="https://raw.githubusercontent.com/Chocolate4U/Iran-v2ray-rules/release/geoip.dat" +USERS_FILE="$HYSTERIA_INSTALL_DIR/users.json" # ========== Color Setup ========== GREEN=$(tput setaf 2) @@ -46,14 +47,93 @@ for SERVICE in "${ALL_SERVICES[@]}"; do fi done +# ========== New Function to Install MongoDB ========== +install_mongodb() { + info "Checking for MongoDB..." + if ! command -v mongod &>/dev/null; then + warn "MongoDB not found. Attempting to install from official repository..." + apt-get update -qq >/dev/null + apt-get install -y gnupg curl >/dev/null + curl -fsSL https://www.mongodb.org/static/pgp/server-7.0.asc | gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg --dearmor + echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/debian bookworm/mongodb-org/7.0 main" > /etc/apt/sources.list.d/mongodb-org-7.0.list + apt-get update -qq >/dev/null + apt-get install -y mongodb-org >/dev/null + systemctl start mongod + systemctl enable mongod + success "MongoDB installed and started successfully." + else + success "MongoDB is already installed." + fi +} -# ========== New Function to Install Go and Compile Auth Binary ========== +# ========== New Function to Migrate users.json to MongoDB ========== +migrate_users_to_mongodb() { + info "Checking for user data to migrate..." + if [ ! -f "$USERS_FILE" ]; then + warn "users.json not found. No data to migrate." + return + fi + + info "Starting user data migration from users.json to MongoDB..." + python3 - </dev/null; then warn "Go is not installed. Attempting to install..." - #apt-get update -qq >/dev/null - apt install golang-go -y + apt-get install golang-go -y >/dev/null success "Go installed successfully." else success "Go is already installed." @@ -149,7 +229,8 @@ chmod 640 "$HYSTERIA_INSTALL_DIR/ca.key" "$HYSTERIA_INSTALL_DIR/ca.crt" chown -R hysteria:hysteria "$HYSTERIA_INSTALL_DIR/core/scripts/telegrambot" chmod +x "$HYSTERIA_INSTALL_DIR/core/scripts/hysteria2/kick.py" -# ========== Virtual Environment ========== +# ========== Install Dependencies ========== +install_mongodb info "Setting up virtual environment and installing dependencies..." cd "$HYSTERIA_INSTALL_DIR" python3 -m venv "$HYSTERIA_VENV_DIR" @@ -158,7 +239,8 @@ pip install --upgrade pip >/dev/null pip install -r requirements.txt >/dev/null success "Python environment ready." -# ========== Compile Go Binary ========== +# ========== Migrate Data and Compile Go Binary ========== +migrate_users_to_mongodb install_go_and_compile_auth # ========== Systemd Services ========== @@ -203,4 +285,4 @@ fi # ========== Launch Menu ========== sleep 10 chmod +x menu.sh -./menu.sh +./menu.sh \ No newline at end of file