Skip to content

Commit 67b5aaa

Browse files
authored
Merge pull request #40 from heroesofcode/feature/organize-code-main
Separate block into another file
2 parents 28d9587 + 6b9f0f8 commit 67b5aaa

File tree

2 files changed

+76
-70
lines changed

2 files changed

+76
-70
lines changed

src/block.rs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
use ratatui::{
2+
layout::Alignment,
3+
style::{Color, Style},
4+
widgets::{Block, Borders, Paragraph, Wrap}
5+
};
6+
7+
pub fn add_info_text() -> Paragraph<'static> {
8+
let text = "🌐 🛢️ Command Line Tools to check for SQL Injection vulnerability.\n👨‍💻 https://github.com/heroesofcode/inject-sql";
9+
10+
let info_text = Paragraph::new(text)
11+
.block(Block::default().borders(Borders::ALL))
12+
.style(Style::default().fg(Color::Green));
13+
14+
return info_text;
15+
}
16+
17+
pub fn add_url_block(url: &str) -> Paragraph<'_> {
18+
let url_block = Paragraph::new(&url[..])
19+
.block(
20+
Block::default()
21+
.title("Enter the URL")
22+
.borders(Borders::ALL),
23+
)
24+
.style(Style::default().fg(Color::White))
25+
.wrap(Wrap { trim: true });
26+
27+
return url_block;
28+
}
29+
30+
pub fn add_type_payload_text() -> Paragraph<'static> {
31+
let text = "\n1 - classical 1\n2 - classical 2\n3 - time-based\n4 - blind 1\n5 - blind 2\n6 - boolean 1\n7 - boolean 2\n8 - Get Database\n";
32+
33+
let type_payload_text = Paragraph::new(text).style(Style::default().fg(Color::Green));
34+
35+
return type_payload_text;
36+
}
37+
38+
pub fn add_payload_block(payload_type: &str) -> Paragraph<'_> {
39+
let payload_block = Paragraph::new(&payload_type[..])
40+
.block(
41+
Block::default()
42+
.title("Enter the payload type")
43+
.borders(Borders::all()),
44+
)
45+
.style(Style::default().fg(Color::White))
46+
.wrap(Wrap { trim: true });
47+
48+
return payload_block;
49+
}
50+
51+
pub fn add_result_block(result_text: &str) -> Paragraph<'_> {
52+
let result_block = Paragraph::new(&result_text[..])
53+
.alignment(Alignment::Center)
54+
.block(
55+
Block::default()
56+
.title("Result")
57+
.borders(Borders::TOP)
58+
.style(Style::default().fg(Color::Yellow)),
59+
)
60+
.wrap(Wrap { trim: true });
61+
62+
return result_block;
63+
}
64+
65+
pub fn add_help_text() -> Paragraph<'static> {
66+
let text = "Use TAB to switch between fields. Press ENTER to validate.";
67+
68+
let help_text = Paragraph::new(text)
69+
.style(Style::default().fg(Color::White));
70+
71+
return help_text;
72+
}

src/main.rs

Lines changed: 4 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ use tokio;
44

55
use ratatui::{
66
backend::CrosstermBackend,
7-
layout::{Alignment, Constraint, Direction, Layout},
8-
style::{Color, Style},
9-
widgets::{Block, Borders, Paragraph, Wrap},
7+
layout::{Constraint, Direction, Layout},
108
Terminal,
119
};
1210

@@ -19,7 +17,10 @@ use crossterm::{
1917
use std::io::stdout;
2018

2119
mod response;
20+
mod block;
21+
2222
use response::validation_exist_sql_injection;
23+
use block::*;
2324

2425
#[tokio::main]
2526
async fn main() -> Result<(), io::Error> {
@@ -115,73 +116,6 @@ async fn run_app<B: ratatui::backend::Backend>(terminal: &mut Terminal<B>) -> io
115116
}
116117
}
117118

118-
fn add_info_text() -> Paragraph<'static> {
119-
let text = "🌐 🛢️ Command Line Tools to check for SQL Injection vulnerability.\n👨‍💻 https://github.com/heroesofcode/inject-sql";
120-
121-
let info_text = Paragraph::new(text)
122-
.block(Block::default().borders(Borders::ALL))
123-
.style(Style::default().fg(Color::Green));
124-
125-
return info_text;
126-
}
127-
128-
fn add_url_block(url: &str) -> Paragraph<'_> {
129-
let url_block = Paragraph::new(&url[..])
130-
.block(
131-
Block::default()
132-
.title("Enter the URL")
133-
.borders(Borders::ALL),
134-
)
135-
.style(Style::default().fg(Color::White))
136-
.wrap(Wrap { trim: true });
137-
138-
return url_block;
139-
}
140-
141-
fn add_type_payload_text() -> Paragraph<'static> {
142-
let text = "\n1 - classical 1\n2 - classical 2\n3 - time-based\n4 - blind 1\n5 - blind 2\n6 - boolean 1\n7 - boolean 2\n8 - Get Database\n";
143-
144-
let type_payload_text = Paragraph::new(text).style(Style::default().fg(Color::Green));
145-
146-
return type_payload_text;
147-
}
148-
149-
fn add_payload_block(payload_type: &str) -> Paragraph<'_> {
150-
let payload_block = Paragraph::new(&payload_type[..])
151-
.block(
152-
Block::default()
153-
.title("Enter the payload type")
154-
.borders(Borders::all()),
155-
)
156-
.style(Style::default().fg(Color::White))
157-
.wrap(Wrap { trim: true });
158-
159-
return payload_block;
160-
}
161-
162-
fn add_result_block(result_text: &str) -> Paragraph<'_> {
163-
let result_block = Paragraph::new(&result_text[..])
164-
.alignment(Alignment::Center)
165-
.block(
166-
Block::default()
167-
.title("Result")
168-
.borders(Borders::TOP)
169-
.style(Style::default().fg(Color::Yellow)),
170-
)
171-
.wrap(Wrap { trim: true });
172-
173-
return result_block;
174-
}
175-
176-
fn add_help_text() -> Paragraph<'static> {
177-
let text = "Use TAB to switch between fields. Press ENTER to validate.";
178-
179-
let help_text = Paragraph::new(text)
180-
.style(Style::default().fg(Color::White));
181-
182-
return help_text;
183-
}
184-
185119
async fn show_result(url: &str, payload_type: &str) -> String {
186120
if !url.is_empty() && !payload_type.is_empty() {
187121
match validation_exist_sql_injection(&url, &payload_type).await {

0 commit comments

Comments
 (0)