Skip to content

Commit

Permalink
beautify(shoots): use colored for colorful output // contents
Browse files Browse the repository at this point in the history
  • Loading branch information
pwnwriter committed Sep 9, 2023
1 parent 2b2ae95 commit 2ccdd79
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 19 deletions.
23 changes: 23 additions & 0 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,27 @@ pub mod hxn_helper {

urls
}

#[allow(dead_code)]
pub fn read_urls_from_file(url: &Option<String>) -> Vec<String> {
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() {}
}
35 changes: 19 additions & 16 deletions src/cli/screenshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -72,7 +73,6 @@ pub async fn run(

let urls: Vec<String>;

#[allow(unreachable_patterns)]
match stdin {
true => {
urls = crate::cli::hxn_helper::read_urls_from_stdin();
Expand All @@ -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();
Expand Down Expand Up @@ -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(())
}
Expand All @@ -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<&str>>(),
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);
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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<dyn std::error::Error + Send + Sync>> {
let cli = args::Cli::parse();
crate::cli::screenshot::run(
run(
cli.url,
Some(cli.outdir),
cli.tabs,
Expand Down

0 comments on commit 2ccdd79

Please sign in to comment.