diff --git a/src/handler.rs b/src/handler.rs index 3261d3c..4499511 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -8,9 +8,13 @@ use deltachat::{ message::Message, }; use eui48::MacAddress; +use russh::{ + client::AuthResult, + keys::PrivateKeyWithHashAlg, +}; use tokio::sync::Mutex; -use crate::config::BotConfig; +use crate::{AUTH_REQUIRED, config::BotConfig, data_path}; pub struct BotContext { authed_contacts: HashSet, @@ -45,6 +49,16 @@ pub async fn auth_command( let mut ctx_lock = ctx.lock().await; let dchat_ctx_lock = dchat_ctx.lock().await; + if !AUTH_REQUIRED { + chat::send_text_msg( + &dchat_ctx_lock, + chat_id, + "Authentication is disabled".to_owned(), + ) + .await?; + return Ok(()); + } + if ctx_lock.authed_contacts.contains(&contact_id) { chat::send_text_msg(&dchat_ctx_lock, chat_id, "Already authenticated".to_owned()).await?; return Ok(()); @@ -199,6 +213,9 @@ async fn ensure_auth( chat_id: ChatId, contact_id: ContactId, ) -> AnyhowResult { + if !AUTH_REQUIRED { + return Ok(true); + } if !ctx.authed_contacts.contains(&contact_id) { chat::send_text_msg( dchat_ctx, diff --git a/src/main.rs b/src/main.rs index 3deecb8..7d371e2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,6 +21,7 @@ const APP_NAME: &str = "deltachat-remotecontrol-bot"; const APP_CONFIG_DIR: &str = APP_NAME; const APP_DATA_DIR: &str = APP_NAME; const BOT_DISPLAY_NAME: &str = "🤖Remote🖲️"; +const AUTH_REQUIRED: bool = true; /// Delta Chat bot for remote control of local network machines. #[derive(Parser)]