Skip to content

Commit 08ed93e

Browse files
committed
Split Args to structs
1 parent 7f03f8a commit 08ed93e

File tree

3 files changed

+116
-129
lines changed

3 files changed

+116
-129
lines changed

src/cli/args.rs

+98-92
Original file line numberDiff line numberDiff line change
@@ -63,105 +63,111 @@ pub enum ScriptType {
6363
)]
6464
pub enum Opts {
6565
#[structopt(about = "Create a lua example code based on the type of scan")]
66-
NEW {
67-
#[structopt(short = "-s", long, parse(try_from_str = get_script_type))]
68-
scan_type: ScriptType,
69-
#[structopt(short = "f", long)]
70-
file_name: PathBuf,
71-
},
66+
NEW(NewOpts),
7267
#[structopt(about = "Use CVE, VULN scripts to scan the given URLs")]
73-
URLS {
74-
// redirects limit
75-
#[structopt(
76-
short,
77-
long,
78-
default_value = "10",
79-
help = "Number of allowed http redirects"
80-
)]
81-
redirects: u32,
82-
#[structopt(
83-
long = "fuzz-workers",
84-
default_value = "15",
85-
help = "The number of workers who will be involved in the fuzzing process"
86-
)]
87-
fuzz_workers: usize,
68+
URLS(UrlsOpts),
69+
}
70+
71+
#[derive(Debug, StructOpt)]
72+
pub struct NewOpts {
73+
#[structopt(short = "-s", long, parse(try_from_str = get_script_type))]
74+
pub scan_type: ScriptType,
75+
#[structopt(short = "f", long)]
76+
pub file_name: PathBuf,
77+
}
78+
79+
#[derive(Debug, StructOpt)]
80+
pub struct UrlsOpts {
81+
// redirects limit
82+
#[structopt(
83+
short,
84+
long,
85+
default_value = "10",
86+
help = "Number of allowed http redirects"
87+
)]
88+
pub redirects: u32,
89+
#[structopt(
90+
long = "fuzz-workers",
91+
default_value = "15",
92+
help = "The number of workers who will be involved in the fuzzing process"
93+
)]
94+
pub fuzz_workers: usize,
8895

89-
// threads
90-
#[structopt(
91-
short = "w",
92-
long = "workers",
93-
default_value = "10",
94-
help = "Number of workers"
95-
)]
96-
workers: usize,
97-
#[structopt(
98-
short = "v",
99-
long = "verbose",
100-
help = "verbose mode (show sending requests)"
101-
)]
102-
verbose: bool,
96+
// threads
97+
#[structopt(
98+
short = "w",
99+
long = "workers",
100+
default_value = "10",
101+
help = "Number of workers"
102+
)]
103+
pub workers: usize,
104+
#[structopt(
105+
short = "v",
106+
long = "verbose",
107+
help = "verbose mode (show sending requests)"
108+
)]
109+
pub verbose: bool,
103110

104-
#[structopt(
105-
short = "sw",
106-
long = "scripts-worker",
107-
default_value = "10",
108-
help = "How many scripts to run at the same time for one url"
109-
)]
110-
scripts_workers: usize,
111+
#[structopt(
112+
short = "sw",
113+
long = "scripts-worker",
114+
default_value = "10",
115+
help = "How many scripts to run at the same time for one url"
116+
)]
117+
pub scripts_workers: usize,
111118

112-
// timeout
113-
#[structopt(
114-
short = "t",
115-
long = "timeout",
116-
default_value = "10",
117-
help = "Connection timeout"
118-
)]
119-
timeout: u64,
119+
// timeout
120+
#[structopt(
121+
short = "t",
122+
long = "timeout",
123+
default_value = "10",
124+
help = "Connection timeout"
125+
)]
126+
pub timeout: u64,
120127

121-
/// Input file
122-
#[structopt(parse(from_os_str), help = "Scripts path")]
123-
script_path: PathBuf,
128+
/// Input file
129+
#[structopt(parse(from_os_str), help = "Scripts path")]
130+
pub script_path: PathBuf,
124131

125-
/// Output file, stdout if not present
126-
#[structopt(
127-
short = "o",
128-
long = "output",
129-
parse(from_os_str),
130-
help = "output json file"
131-
)]
132-
output: Option<PathBuf>,
132+
/// Output file, stdout if not present
133+
#[structopt(
134+
short = "o",
135+
long = "output",
136+
parse(from_os_str),
137+
help = "output json file"
138+
)]
139+
pub output: Option<PathBuf>,
133140

134-
#[structopt(
135-
short = "p",
136-
long = "proxy",
137-
help = "Set http proxy for all connections"
138-
)]
139-
proxy: Option<String>,
140-
#[structopt(
141-
long = "requests-limit",
142-
help = "requests limit",
143-
default_value = "2000"
144-
)]
145-
requests_limit: i32,
146-
#[structopt(long = "delay", help = "sleeping dalay", default_value = "5")]
147-
delay: u64,
141+
#[structopt(
142+
short = "p",
143+
long = "proxy",
144+
help = "Set http proxy for all connections"
145+
)]
146+
pub proxy: Option<String>,
147+
#[structopt(
148+
long = "requests-limit",
149+
help = "requests limit",
150+
default_value = "2000"
151+
)]
152+
pub requests_limit: i32,
153+
#[structopt(long = "delay", help = "sleeping dalay", default_value = "5")]
154+
pub delay: u64,
148155

149-
#[structopt(long = "log", help = "Saving Lotus Logs for debugging")]
150-
log: Option<PathBuf>,
151-
#[structopt(
152-
long = "urls",
153-
help = "Reading urls from text file",
154-
parse(from_os_str)
155-
)]
156-
urls: Option<PathBuf>,
156+
#[structopt(long = "log", help = "Saving Lotus Logs for debugging")]
157+
pub log: Option<PathBuf>,
158+
#[structopt(
159+
long = "urls",
160+
help = "Reading urls from text file",
161+
parse(from_os_str)
162+
)]
163+
pub urls: Option<PathBuf>,
157164

158-
#[structopt(long = "headers", parse(try_from_str = parse_headers), required = false, default_value = "{}", help = "Default Headers (eg: '{\"X-API\":\"123\"}')")]
159-
headers: HeaderMap,
160-
#[structopt(
161-
long = "exit-after-errors",
162-
default_value = "2000",
163-
help = "Exit after X number of script errors"
164-
)]
165-
exit_after: i32,
166-
},
165+
#[structopt(long = "headers", parse(try_from_str = parse_headers), required = false, default_value = "{}", help = "Default Headers (eg: '{\"X-API\":\"123\"}')")]
166+
pub headers: HeaderMap,
167+
#[structopt(
168+
long = "exit-after-errors",
169+
default_value = "2000",
170+
help = "Exit after X number of script errors"
171+
)]
172+
pub exit_after: i32,
167173
}

src/cli/startup/urls.rs

+16-32
Original file line numberDiff line numberDiff line change
@@ -39,39 +39,23 @@ pub fn args_urls() -> UrlArgs {
3939
fuzz_workers,
4040
verbose,
4141
) = match Opts::from_args() {
42-
Opts::URLS {
43-
redirects,
44-
workers,
45-
scripts_workers,
46-
timeout,
47-
script_path,
48-
output,
49-
proxy,
50-
log,
51-
urls,
52-
headers,
53-
exit_after,
54-
requests_limit,
55-
delay,
56-
fuzz_workers,
57-
verbose,
58-
} => {
42+
Opts::URLS(url_opts) => {
5943
// setup logger
60-
init_log(log).unwrap();
44+
init_log(url_opts.log).unwrap();
6145
let req_opts = RequestOpts {
62-
headers,
63-
proxy,
64-
timeout,
65-
redirects,
46+
headers: url_opts.headers,
47+
proxy: url_opts.proxy,
48+
timeout: url_opts.timeout,
49+
redirects: url_opts.redirects,
6650
};
6751
let lotus_obj = Lotus {
68-
script_path,
69-
output,
70-
workers,
71-
script_workers: scripts_workers,
52+
script_path: url_opts.script_path,
53+
output: url_opts.output,
54+
workers: url_opts.workers,
55+
script_workers: url_opts.scripts_workers,
7256
stop_after: Arc::new(Mutex::new(1)),
7357
};
74-
let urls = get_target_urls(urls);
58+
let urls = get_target_urls(url_opts.urls);
7559
if urls.is_err() {
7660
match urls {
7761
Err(CliErrors::EmptyStdin) => {
@@ -95,13 +79,13 @@ pub fn args_urls() -> UrlArgs {
9579
urls_vec,
9680
hosts,
9781
paths,
98-
exit_after,
82+
url_opts.exit_after,
9983
req_opts,
10084
lotus_obj,
101-
requests_limit,
102-
delay,
103-
fuzz_workers,
104-
verbose,
85+
url_opts.requests_limit,
86+
url_opts.delay,
87+
url_opts.fuzz_workers,
88+
url_opts.verbose,
10589
)
10690
}
10791
_ => {

src/main.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,8 @@ async fn main() -> Result<(), std::io::Error> {
8484
runner::scan_futures(scan_futures, 3, None).await;
8585
BAR.lock().unwrap().finish();
8686
}
87-
Opts::NEW {
88-
scan_type,
89-
file_name,
90-
} => {
91-
new_args(scan_type, file_name);
87+
Opts::NEW(new_opts) => {
88+
new_args(new_opts.scan_type, new_opts.file_name);
9289
std::process::exit(0);
9390
}
9491
};

0 commit comments

Comments
 (0)