Skip to content

Commit

Permalink
Split args sub dir
Browse files Browse the repository at this point in the history
  • Loading branch information
knassar702 committed Apr 10, 2023
1 parent 08ed93e commit 2709993
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 45 deletions.
17 changes: 17 additions & 0 deletions src/cli/args/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
pub mod scan;
pub mod new;
use structopt::StructOpt;
use scan::UrlsOpts;
use new::NewOpts;

#[derive(Debug, StructOpt)]
#[structopt(
name = "Lotus",
about = "Fast Web Security Scanner written in Rust based on Lua Scripts"
)]
pub enum Opts {
#[structopt(about = "Create a lua example code based on the type of scan")]
NEW(NewOpts),
#[structopt(about = "Use CVE, VULN scripts to scan the given URLs")]
URLS(UrlsOpts),
}
42 changes: 42 additions & 0 deletions src/cli/args/new.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use crate::cli::errors::CliErrors;
use std::path::PathBuf;
use structopt::StructOpt;


fn get_script_type(script_type: &str) -> Result<ScriptType, CliErrors> {
let script_type = match script_type {
"fuzz" => ScriptType::Fuzz,
"cve" => ScriptType::CVE,
"passive" => ScriptType::PASSIVE,
"service" => ScriptType::SERVICE,
_ => ScriptType::NotSupported,
};
if script_type == ScriptType::NotSupported {
Err(CliErrors::UnsupportedScript)
} else {
Ok(script_type)
}
}




#[derive(Debug, PartialEq)]
pub enum ScriptType {
Fuzz,
CVE,
PASSIVE,
SERVICE,
NotSupported,
}



#[derive(Debug, StructOpt)]
pub struct NewOpts {
#[structopt(short = "-s", long, parse(try_from_str = get_script_type))]
pub scan_type: ScriptType,
#[structopt(short = "f", long)]
pub file_name: PathBuf,
}

44 changes: 0 additions & 44 deletions src/cli/args.rs → src/cli/args/scan.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::cli::errors::CliErrors;
use reqwest::header::HeaderMap;
use reqwest::header::{HeaderName, HeaderValue};
use std::collections::HashMap;
Expand Down Expand Up @@ -32,49 +31,6 @@ fn parse_headers(raw_headers: &str) -> Result<HeaderMap, serde_json::Error> {
Ok(user_headers)
}

fn get_script_type(script_type: &str) -> Result<ScriptType, CliErrors> {
let script_type = match script_type {
"fuzz" => ScriptType::Fuzz,
"cve" => ScriptType::CVE,
"passive" => ScriptType::PASSIVE,
"service" => ScriptType::SERVICE,
_ => ScriptType::NotSupported,
};
if script_type == ScriptType::NotSupported {
Err(CliErrors::UnsupportedScript)
} else {
Ok(script_type)
}
}

#[derive(Debug, PartialEq)]
pub enum ScriptType {
Fuzz,
CVE,
PASSIVE,
SERVICE,
NotSupported,
}

#[derive(Debug, StructOpt)]
#[structopt(
name = "Lotus",
about = "Fast Web Security Scanner written in Rust based on Lua Scripts"
)]
pub enum Opts {
#[structopt(about = "Create a lua example code based on the type of scan")]
NEW(NewOpts),
#[structopt(about = "Use CVE, VULN scripts to scan the given URLs")]
URLS(UrlsOpts),
}

#[derive(Debug, StructOpt)]
pub struct NewOpts {
#[structopt(short = "-s", long, parse(try_from_str = get_script_type))]
pub scan_type: ScriptType,
#[structopt(short = "f", long)]
pub file_name: PathBuf,
}

#[derive(Debug, StructOpt)]
pub struct UrlsOpts {
Expand Down
2 changes: 1 addition & 1 deletion src/cli/startup/new.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
cli::{
args::ScriptType,
args::new::ScriptType,
default_scripts::{
write_file, CVE_EXAMPLE, FUZZ_EXAMPLE, PASSIVE_EXAMPLE, SERVICE_EXAMPLE,
},
Expand Down

0 comments on commit 2709993

Please sign in to comment.