diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 2efa6fc..9da7be2 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -26,4 +26,27 @@ pub mod hxn_helper { urls } + + #[allow(dead_code)] + pub fn read_urls_from_file(url: &Option) -> Vec { + let mut urls = Vec::new(); + + if let Some(url) = url { + if std::path::Path::new(url).exists() { + if let Ok(file) = std::fs::File::open(url) { + let lines = std::io::BufReader::new(file).lines().map_while(Result::ok); + urls = lines.collect(); + } else { + urls = vec![url.clone()]; + } + } else { + urls = vec![url.clone()]; + } + } + + urls + } + + #[allow(dead_code)] + pub fn read_ports() {} } diff --git a/src/cli/screenshot.rs b/src/cli/screenshot.rs index 6cabd7c..2ac682a 100644 --- a/src/cli/screenshot.rs +++ b/src/cli/screenshot.rs @@ -2,6 +2,7 @@ use crate::cli::ascii::{BAR, RESET}; use crate::log::error; use chromiumoxide::browser::{Browser, BrowserConfig}; use chromiumoxide::handler::viewport::Viewport; +use colored::{Color, Colorize}; use futures::StreamExt; use std::{ env, @@ -72,7 +73,6 @@ pub async fn run( let urls: Vec; - #[allow(unreachable_patterns)] match stdin { true => { urls = crate::cli::hxn_helper::read_urls_from_stdin(); @@ -81,22 +81,16 @@ pub async fn run( false => { if let Some(url) = &url { if Path::new(url).exists() { - // Read URLs from file let file = std::fs::File::open(url)?; let lines = BufReader::new(file).lines().map_while(Result::ok); urls = lines.collect(); } else { - // URL is a single URL - urls = vec![url.clone()]; + urls = vec![url.clone()]; } } else { urls = vec![]; } } - - _ => { - urls = vec![]; - } } let mut url_chunks = Vec::new(); @@ -127,7 +121,13 @@ pub async fn run( .expect("Something went wrong while waiting for taking screenshot and saving to file"); } - println!("Screenshots saved in dir {outdir}"); + println!( + "{}: {}", + "Screenshots Taken and saved in directory" + .bold() + .color(Color::Green), + outdir + ); Ok(()) } @@ -152,22 +152,25 @@ async fn take_screenshots( ) .await?; - #[allow(clippy::useless_format)] - let _info = Columns::from(vec![ + let info = Columns::from(vec![ format!("{RESET}").split('\n').collect::>(), vec![ - &format!("{BAR}"), - &format!(" URL = {}", url), - &format!("Title = {}", page.get_title().await?.unwrap_or_default()), - &format!("Status = {}", _res.status()), + &format!(" {BAR}").bold().blue(), + &format!(" 🔗 URL = {}", url.red()), + &format!( + " 🏠 Title = {}", + page.get_title().await?.unwrap_or_default().purple() + ), + &format!(" 🔥 Status = {}", _res.status()).green(), ], ]) .set_tabsize(0) .make_columns(); if !silent { - println!("{_info}"); + println!("{info}"); } } else { + error("Please increase timout value by --timeout flag"); println!("[-] Timed out URL = {}", url); } } diff --git a/src/main.rs b/src/main.rs index ea4ca1f..e618ff0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,12 +1,13 @@ +use crate::cli::{args, screenshot::run}; +use clap::Parser; + mod cli; mod log; -use cli::args; -use clap::Parser; #[tokio::main] async fn main() -> Result<(), Box> { let cli = args::Cli::parse(); - crate::cli::screenshot::run( + run( cli.url, Some(cli.outdir), cli.tabs,