Skip to content

Commit

Permalink
Merge pull request #125 from BugBlocker/fix_logs
Browse files Browse the repository at this point in the history
Refactor log messages
  • Loading branch information
MindPatch authored Apr 27, 2023
2 parents 6f18502 + 806acc7 commit 6a85a4f
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "lotus"
version = "0.4.0"
version = "0.5.0-beta"
edition = "2021"
license = "GPLv2"
keywords = ["security", "automation", "bugbounty"]
Expand Down
22 changes: 11 additions & 11 deletions src/cli/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ pub fn init_log(log_file: Option<PathBuf>) -> Result<(), std::io::Error> {
let logger = fern::Dispatch::new()
.format(|out, message, record| {
out.finish(format_args!(
"{}[{}][{}] {}",
chrono::Local::now().format("[%Y-%m-%d][%H:%M:%S]"),
"{} [{}][{}] {}",
chrono::Local::now().format("%Y-%m-%d %H:%M:%S"),
record.target(),
record.level(),
message
Expand All @@ -36,15 +36,15 @@ pub fn init_log(log_file: Option<PathBuf>) -> Result<(), std::io::Error> {
.level_for("isahc", log::LevelFilter::Warn)
.level_for("selectors", log::LevelFilter::Warn)
.level_for("html5ever", log::LevelFilter::Warn);
match log_file {
Some(log_path) => {
// Disalbe unwanted loggers
logger
.chain(fern::log_file(log_path).unwrap())
.apply()
.unwrap();
}
None => {}

if let Some(log_path) = log_file {
// Disable unwanted loggers
logger.chain(fern::log_file(log_path.clone()).unwrap()).apply().unwrap();
log::info!("Logging initialized. Writing logs to {}", log_path.to_str().unwrap());
} else {
logger.apply().unwrap();
log::info!("Logging initialized. Writing logs to console.");
}

Ok(())
}
9 changes: 5 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use mlua::ExternalError;
pub use model::{Lotus, RequestOpts, ScanTypes};
use std::sync::Arc;


impl Lotus {
/// Run The Lua Script with real target
/// * `target_data` - Vector with target urls
Expand Down Expand Up @@ -71,15 +72,15 @@ impl Lotus {
env_vars: self.env_vars.clone(),
};
if *self.stop_after.lock().unwrap() == exit_after {
log::debug!("Ignoring scripts");
// No script will be executed
} else {
log::debug!("Running {} script on {}", script_name, script_data);
log::debug!("Starting script execution: {} on {}", script_name, script_data);
match lotus_loader.run_scan(lua_opts).await {
Ok(_) => (),
Err(err) => {
log::error!("script error: {}", err.to_lua_err().to_string());
log::error!("An error occurred while executing the script: {}", err.to_lua_err().to_string());
let mut stop_after = self.stop_after.lock().unwrap();
log::debug!("Errors Counter: {}", *stop_after);
log::debug!("The current number of errors encountered while executing scripts is: {}", *stop_after);
*stop_after += 1;
}
}
Expand Down
20 changes: 10 additions & 10 deletions src/lua/parsing/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ impl ResponseMatcher {
.build()
{
Ok(re) => Ok(re.is_match(&resp)),
Err(_) => {
log::error!("Regex Pattern ERROR {:?}", pattern);
Err(err) => {
log::error!("An error occurred while processing the regular expression pattern: {}", err.to_string());
Err(CliErrors::RegexPatternError)
}
}
Expand All @@ -66,8 +66,8 @@ impl ResponseMatcher {
.collect();
Ok(match_iter)
}
Err(_) => {
log::error!("Regex Pattern ERROR {:?}", regex_pattern);
Err(err) => {
log::error!("An error occurred while processing the regular expression pattern: {}", err.to_string());
Err(CliErrors::RegexPatternError)
}
}
Expand All @@ -90,8 +90,8 @@ impl ResponseMatcher {
let replace_output = re.replacen(response, 2, replacement).to_string();
Ok(replace_output)
}
Err(_) => {
log::error!("Regex Pattern ERROR {:?}", regex_pattern);
Err(err) => {
log::error!("An error occurred while processing the regular expression pattern: {}", err.to_string());
Err(CliErrors::RegexPatternError)
}
}
Expand All @@ -118,8 +118,8 @@ impl ResponseMatcher {
counter += 1;
}
}
Err(_) => {
log::error!("Invalid regex pattern: {:?}", search_pattern);
Err(err) => {
log::error!("An error occurred while processing the regular expression pattern: {}",err.to_string());
return Err(CliErrors::RegexPatternError);
}
},
Expand Down Expand Up @@ -155,8 +155,8 @@ impl ResponseMatcher {
matched_data.push(pattern);
}
}
Err(_) => {
log::error!("Invalid regex pattern: {:?}", pattern);
Err(err) => {
log::error!("An error occurred while processing the regular expression pattern: {}",err.to_string());
return Err(CliErrors::RegexPatternError);
}
},
Expand Down
11 changes: 7 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,22 @@ async fn run_scan() -> Result<(), std::io::Error> {
let opts = args_scan();
let fuzz_workers = opts.fuzz_workers;
show_msg(
&format!("🌐 URLS: {}", opts.target_data.urls.len()),
&format!("Number of URLs: {}", opts.target_data.urls.len()),
MessageLevel::Info,
);

show_msg(
&format!("🏠 HOSTS: {}", opts.target_data.hosts.len()),
&format!("Number of hosts: {}", opts.target_data.hosts.len()),
MessageLevel::Info,
);

show_msg(
&format!("📁 PATHS: {}", opts.target_data.paths.len()),
&format!("Number of paths: {}", opts.target_data.paths.len()),
MessageLevel::Info,
);

show_msg(
&format!("🔧 CUSTOM: {}", opts.target_data.custom.len()),
&format!("Number of custom entries: {}", opts.target_data.custom.len()),
MessageLevel::Info,
);
// Open two threads for URL/HOST scanning
Expand Down

0 comments on commit 6a85a4f

Please sign in to comment.