Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flexible report #28

Merged
merged 1 commit into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ path = "src/cli/main.rs"

[dependencies]
# LUA
mlua = { version = "0.8"}
mlua = { version = "0.8" , features=["serialize"]}
tealr = {version="0.9.0-alpha1", features=["mlua", "mlua_lua54", "mlua_vendored", "mlua_async"]}

# Threading
Expand Down
34 changes: 15 additions & 19 deletions src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,25 @@ pub mod utils;
use futures::{stream, StreamExt};
use log::{debug, error, info, warn};
use mlua::Lua;
use serde::{Deserialize, Serialize};
use thirtyfour::prelude::*;

use utils::html::{css_selector, html_parse, html_search};
use utils::is_match;
use utils::url::{change_urlquery, set_urlvalue, urljoin};

use std::fs::File;
use std::io::Read;
use std::fs::OpenOptions;
use std::io::Read;
use std::io::Write;
use std::sync::{Arc, Mutex};
use std::collections::HashMap;

#[derive(Clone)]
pub struct LuaLoader<'a> {
output_dir: Arc<Mutex<String>>,
bar: &'a indicatif::ProgressBar,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct Report {
pub payload: String,
pub match_payload: String,
pub url: String,
}

impl<'a> LuaLoader<'a> {
pub fn new(bar: &'a indicatif::ProgressBar, output_dir: String) -> LuaLoader {
LuaLoader {
Expand Down Expand Up @@ -190,8 +183,9 @@ impl<'a> LuaLoader<'a> {
)
.unwrap();
lua.globals()
.set("read",
lua.create_function(|_ctx, file_path: String| {
.set(
"read",
lua.create_function(|_ctx, file_path: String| {
use std::path::Path;
if Path::new(&file_path).exists() == true {
let mut file = File::open(&file_path)?;
Expand All @@ -201,8 +195,10 @@ impl<'a> LuaLoader<'a> {
} else {
Ok(0.to_string())
}
}).unwrap()
).unwrap();
})
.unwrap(),
)
.unwrap();

lua.globals()
.set(
Expand Down Expand Up @@ -296,12 +292,12 @@ impl<'a> LuaLoader<'a> {
let out_table = lua.globals().get::<_, bool>("VALID".to_owned()).unwrap();
if out_table == true {
reports.iter().for_each(|out| {
let new_report = Report {
url: out.get("url").unwrap_or("".into()),
match_payload: out.get("match").unwrap_or("".into()),
payload: out.get("payload").unwrap_or("".to_string()),
};
let results = serde_json::to_string(&new_report).unwrap();
let mut test_report: HashMap<String, mlua::Value> = HashMap::new();
out.clone().pairs::<String,mlua::Value>().for_each(|out_report| {
let current_out = out_report.clone();
test_report.insert(current_out.unwrap().0,out_report.unwrap().1);
});
let results = serde_json::to_string(&test_report).unwrap();
self.write_report(&results);
});
}
Expand Down
16 changes: 10 additions & 6 deletions src/core/utils/bar.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
use indicatif::{ProgressBar, ProgressStyle};


pub fn create_progress(bar: u64) -> ProgressBar {
let bar = ProgressBar::new(bar);
bar.set_style(ProgressStyle::default_bar()
.template("{spinner:.green} [{elapsed_precise}] [{bar:40.cyan/blue}] {pos:>7}/{len:7} {msg}").expect("ProgressBar Error")
let bar = ProgressBar::new(bar);
bar.set_style(
ProgressStyle::default_bar()
.template(
"{spinner:.green} [{elapsed_precise}] [{bar:40.cyan/blue}] {pos:>7}/{len:7} {msg}",
)
.expect("ProgressBar Error")
.tick_chars(format!("{}", "⣾⣽⣻⢿⡿⣟⣯⣷").as_str())
.progress_chars("#>-"));
bar
.progress_chars("#>-"),
);
bar
}
2 changes: 1 addition & 1 deletion src/core/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use log::debug;
pub mod bar;
pub mod files;
pub mod html;
pub mod http;
pub mod url;
pub mod bar;

pub fn is_match(pattern: String, resp: String) -> bool {
let re = fancy_regex::Regex::new(&pattern);
Expand Down