bhcli

A TUI for chatting on LE PHP Chats (onion)
git clone https://git.dasho.dev/n0tr1v/bhcli.git
Log | Files | Refs | README

commit e298c1199ab4b21d688ab26fb6db684761740c2f
parent 00ad242dae27cfcdad32f72d27db9e84594d8022
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Sat, 29 Apr 2023 21:14:39 -0700

fix for BHC dynamic form and index

Diffstat:
Msrc/main.rs | 12+++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/main.rs b/src/main.rs @@ -84,6 +84,7 @@ const FAGGOT: &str = "faggot"; const DNMX_URL: &str = "http://hxuzjtocnzvv5g2rtg2bhwkcbupmk7rclb6lly3fo4tvqkk5oyrv3nid.onion"; lazy_static! { + static ref META_REFRESH_RGX: Regex = Regex::new(r#"url='([^']+)'"#).unwrap(); static ref SESSION_RGX: Regex = Regex::new(r#"session=([^&]+)"#).unwrap(); static ref COLOR_RGX: Regex = Regex::new(r#"color:\s*([#\w]+)\s*;"#).unwrap(); static ref COLOR1_RGX: Regex = Regex::new(r#"^#([0-9A-Fa-f]{6})$"#).unwrap(); @@ -478,6 +479,15 @@ impl LeChatPHPClient { return Ok(()); } if self.chat_type == ClientType::BHC { + let resp = self.client.get(&self.config.url).send().unwrap().text().unwrap(); + let doc = Document::from(resp.as_str()); + let meta_content = doc.find(Name("meta")).next().unwrap().attr("content").context("meta content not found").unwrap().to_owned(); + let index_url = META_REFRESH_RGX.captures(&meta_content).unwrap()[1].to_owned(); + + let resp = self.client.get(format!("{}/{}", &self.config.url, index_url)).send().unwrap().text().unwrap(); + let doc = Document::from(resp.as_str()); + let form_action = doc.find(Name("form")).next().unwrap().attr("action").context("form action not found").unwrap().to_owned(); + let captcha_bytes = self.client.get(format!("{}/captcha.php", &self.config.url)).send().unwrap().bytes().unwrap(); let img = image::load_from_memory(&captcha_bytes).unwrap(); let img_buf = image::imageops::resize(&img, img.width(), img.height(), image::imageops::FilterType::Nearest); @@ -491,7 +501,7 @@ impl LeChatPHPClient { io::stdin().read_line(&mut captcha_input).unwrap(); trim_newline(&mut captcha_input); let params = vec![("input", captcha_input), ("submit", "Enter+Chat".to_owned())]; - let resp = self.client.post(format!("{}/form.php", &self.config.url)).form(&params).send().unwrap(); + let resp = self.client.post(format!("{}/{}", &self.config.url, form_action)).form(&params).send().unwrap(); if resp.status() != StatusCode::SEE_OTHER { return Err(LoginErr::CaptchaWgErr); }