From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 54BBCB39BB for ; Wed, 29 Nov 2023 13:15:03 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 289D761A2 for ; Wed, 29 Nov 2023 13:14:33 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Wed, 29 Nov 2023 13:14:31 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 19AC74091B for ; Wed, 29 Nov 2023 13:14:31 +0100 (CET) From: Markus Frank To: pbs-devel@lists.proxmox.com Date: Wed, 29 Nov 2023 13:14:23 +0100 Message-Id: <20231129121423.70408-1-m.frank@proxmox.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.034 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - Subject: [pbs-devel] [PATCH proxmox-backup] cli: add interactive confirmation for block device wipe X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 29 Nov 2023 12:15:03 -0000 If stdin is a TTY, an interactive prompt is added to confirm the deletion of a block device, ensuring user verification before proceeding. Signed-off-by: Markus Frank --- src/bin/proxmox_backup_manager/disk.rs | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/bin/proxmox_backup_manager/disk.rs b/src/bin/proxmox_backup_manager/disk.rs index 7a292098..4baa2a25 100644 --- a/src/bin/proxmox_backup_manager/disk.rs +++ b/src/bin/proxmox_backup_manager/disk.rs @@ -3,6 +3,8 @@ use serde_json::Value; use proxmox_router::{cli::*, ApiHandler, RpcEnvironment}; use proxmox_schema::api; +use proxmox_sys::linux::tty::stdin_isatty; +use std::io::Write; use pbs_api_types::{ ZfsCompressionType, ZfsRaidLevel, BLOCKDEVICE_DISK_AND_PARTITION_NAME_SCHEMA, @@ -152,6 +154,31 @@ async fn initialize_disk( async fn wipe_disk(mut param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result { param["node"] = "localhost".into(); + // If we're on a TTY, query the user + if stdin_isatty() { + loop { + eprintln!("You are about to wipe block device {}.", param["disk"]); + eprintln!("Please make sure you have selected the correct device!"); + eprint!("Are you sure you want to continue? (y/n): "); + let _ = std::io::stdout().flush(); + use std::io::{BufRead, BufReader}; + let mut line = String::new(); + match BufReader::new(std::io::stdin()).read_line(&mut line) { + Ok(_) => { + let trimmed = line.trim(); + if trimmed == "y" || trimmed == "Y" { + break; + } else if trimmed == "n" || trimmed == "N" { + bail!("Aborting."); + } else { + continue; + } + } + Err(err) => bail!("Failed to read line - {}.", err), + } + } + } + let info = &api2::node::disks::API_METHOD_WIPE_DISK; let result = match info.handler { ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?, -- 2.39.2