Added Menu and save logic
This commit is contained in:
1 parent
80fd57810e
commit
c6d9b775bc
9 files changed
+400
-31
No files matched your search
+11
-4
@@ -4,11 +4,16 @@ use core::fmt;
|
||||
pub struct Config {
|
||||
pub subdomains: Vec<String>,
|
||||
pub wildcard_test: String,
|
||||
pub data_dir: String,
|
||||
}
|
||||
|
||||
impl fmt::Display for Config {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "Subdomains: {:?}\nWildcard Test: {}", self.subdomains, self.wildcard_test)
|
||||
write!(
|
||||
f,
|
||||
"Subdomains: {:?}\nWildcard Test: {}",
|
||||
self.subdomains, self.wildcard_test
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,11 +28,13 @@ impl Config {
|
||||
for x in subdomains.split(',') {
|
||||
subvec.push(x.to_string());
|
||||
}
|
||||
|
||||
|
||||
let wildcard_test = config.get("General", "wildcard_test");
|
||||
let datadir = config.get("General", "data_directory");
|
||||
Config {
|
||||
subdomains: subvec,
|
||||
wildcard_test: wildcard_test.unwrap()
|
||||
wildcard_test: wildcard_test.unwrap(),
|
||||
data_dir: datadir.unwrap(),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
use chrono::Local;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::error::Error;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
|
||||
use crate::config::Config;
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct DomainData {
|
||||
name: String,
|
||||
dns_records: Vec<String>,
|
||||
whois_info: Vec<String>,
|
||||
}
|
||||
|
||||
impl DomainData {
|
||||
pub fn new(domain: String, dns: Vec<String>, whois_data: Vec<String>) -> DomainData {
|
||||
DomainData {
|
||||
name: domain,
|
||||
dns_records: dns,
|
||||
whois_info: whois_data,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn save_lookup(&self, config: &Config) -> Result<(), Box<dyn Error>> {
|
||||
let output = serde_json::to_string(&self).unwrap();
|
||||
let date = Local::now();
|
||||
let filepath = format!(
|
||||
"{}/lookups/{}-{}.json",
|
||||
config.data_dir,
|
||||
date.format("%Y-%m-%d_%H-%M-%S"),
|
||||
self.name
|
||||
);
|
||||
let data_dir = Path::new(&config.data_dir.clone()).exists();
|
||||
if data_dir != true {
|
||||
match fs::create_dir_all(format!("{}/lookups", config.data_dir)) {
|
||||
Ok(_val) => {}
|
||||
Err(_err) => {}
|
||||
}
|
||||
}
|
||||
fs::write(filepath, output)?;
|
||||
|
||||
Ok(())
|
||||
// println!("{}", output);
|
||||
}
|
||||
}
|
||||
+26
-2
@@ -13,6 +13,9 @@ use crate::app::*;
|
||||
mod ui;
|
||||
use crate::ui::*;
|
||||
|
||||
mod fs;
|
||||
use crate::fs::*;
|
||||
|
||||
use crossterm::event::{
|
||||
self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode, KeyEventKind,
|
||||
};
|
||||
@@ -64,7 +67,9 @@ fn run_app<B: Backend>(
|
||||
}
|
||||
match app.current_state {
|
||||
CurrentState::Lookup => match key.code {
|
||||
KeyCode::Esc => return Ok(false),
|
||||
KeyCode::Esc => {
|
||||
app.current_state = CurrentState::Menu;
|
||||
}
|
||||
KeyCode::Backspace => {
|
||||
app.domain_input.pop();
|
||||
}
|
||||
@@ -73,6 +78,10 @@ fn run_app<B: Backend>(
|
||||
}
|
||||
KeyCode::Enter => {
|
||||
// This will do the lookup and populate the UI with the info
|
||||
if &app.domain_input == "" {
|
||||
// Ignore empty input
|
||||
continue;
|
||||
}
|
||||
let mut domain = Domain::new(app.domain_input.clone());
|
||||
domain.apply_config(&config);
|
||||
domain.lookup_all_records();
|
||||
@@ -85,7 +94,22 @@ fn run_app<B: Backend>(
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
CurrentState::Menu => {}
|
||||
CurrentState::Menu => match key.code {
|
||||
KeyCode::Esc => {
|
||||
app.current_state = CurrentState::Lookup;
|
||||
}
|
||||
KeyCode::Char('s') => {
|
||||
let domain_data = DomainData::new(
|
||||
app.domain_input.clone(),
|
||||
app.dns_info.clone(),
|
||||
app.whois_info.clone(),
|
||||
);
|
||||
domain_data.save_lookup(&config).unwrap();
|
||||
app.current_state = CurrentState::Lookup;
|
||||
}
|
||||
KeyCode::Char('q') => return Ok(false),
|
||||
_ => {}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ pub fn ui(f: &mut Frame, app: &mut App) {
|
||||
.style(Style::default());
|
||||
|
||||
let key_hint = Paragraph::new(Text::styled(
|
||||
"[ESC] Quit / [Enter] Check domain / [Del] Clear Input",
|
||||
"[ESC] Menu / [Enter] Check domain / [Del] Clear Input",
|
||||
Style::default().fg(Color::Red),
|
||||
))
|
||||
.block(key_hint_block);
|
||||
@@ -187,6 +187,62 @@ pub fn ui(f: &mut Frame, app: &mut App) {
|
||||
}
|
||||
}
|
||||
}
|
||||
CurrentState::Menu => {}
|
||||
CurrentState::Menu => {
|
||||
let chunks = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.constraints([
|
||||
Constraint::Length(3),
|
||||
Constraint::Min(1),
|
||||
Constraint::Length(3),
|
||||
])
|
||||
.split(f.size());
|
||||
|
||||
let title_block = Block::new().borders(Borders::ALL).style(Style::default());
|
||||
|
||||
let title = Paragraph::new(Text::styled(
|
||||
"**** Menu ****",
|
||||
Style::default().fg(Color::Cyan),
|
||||
))
|
||||
.block(title_block);
|
||||
f.render_widget(title, chunks[0]);
|
||||
|
||||
let mut options_list = Vec::<ListItem>::new();
|
||||
options_list.push(ListItem::new(Line::from(Span::styled(
|
||||
"ESC) Return to lookup",
|
||||
Style::default(),
|
||||
))));
|
||||
|
||||
// TODO: Add code to save lookup
|
||||
options_list.push(ListItem::new(Line::from(Span::styled(
|
||||
"S) Save lookup",
|
||||
Style::default(),
|
||||
))));
|
||||
|
||||
// TODO: Add code to load and UI to list saved lookups
|
||||
options_list.push(ListItem::new(Line::from(Span::styled(
|
||||
"L) List previous lookups",
|
||||
Style::default(),
|
||||
))));
|
||||
|
||||
// TODO: Add code to read lookup and display
|
||||
options_list.push(ListItem::new(Line::from(Span::styled(
|
||||
"V) View previous lookup",
|
||||
Style::default(),
|
||||
))));
|
||||
|
||||
options_list.push(ListItem::new(Line::from(Span::styled(
|
||||
"Q) Quit",
|
||||
Style::default(),
|
||||
))));
|
||||
|
||||
let options = List::new(options_list);
|
||||
f.render_widget(options, chunks[1]);
|
||||
|
||||
let footer_block = Block::new().borders(Borders::ALL).style(Style::default());
|
||||
|
||||
let footer = Paragraph::new(Text::styled("[q] Quit", Style::default().fg(Color::Red)))
|
||||
.block(footer_block);
|
||||
f.render_widget(footer, chunks[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
+28
-22
@@ -6,7 +6,7 @@ use hickory_resolver::proto::{
|
||||
use regex::Regex;
|
||||
use whois_rust::{WhoIs, WhoIsLookupOptions};
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone)]
|
||||
enum RegistrantType {
|
||||
Registrant,
|
||||
Admin,
|
||||
@@ -33,7 +33,7 @@ impl RegexQuery {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone)]
|
||||
struct NameServer {
|
||||
host: String,
|
||||
}
|
||||
@@ -44,7 +44,7 @@ impl NameServer {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone)]
|
||||
struct Registrant {
|
||||
name: String,
|
||||
org: String,
|
||||
@@ -76,11 +76,11 @@ struct Eligibility {
|
||||
}
|
||||
|
||||
pub struct WhoisData {
|
||||
registrar: String,
|
||||
domain_status: String,
|
||||
registrant: Vec<Registrant>,
|
||||
nameservers: Vec<NameServer>,
|
||||
dnssec: String,
|
||||
registrar: Option<String>,
|
||||
domain_status: Option<String>,
|
||||
registrant: Option<Vec<Registrant>>,
|
||||
nameservers: Option<Vec<NameServer>>,
|
||||
dnssec: Option<String>,
|
||||
eligibility_type: Option<Eligibility>,
|
||||
}
|
||||
|
||||
@@ -89,7 +89,11 @@ impl fmt::Display for WhoisData {
|
||||
write!(
|
||||
f,
|
||||
"Registrar: {}\nStatus: {}\nRegistrant: {:?}\nNameservers: {:?}\nDNSSEC: {}",
|
||||
self.registrar, self.domain_status, self.registrant, self.nameservers, self.dnssec
|
||||
self.registrar.clone().unwrap(),
|
||||
self.domain_status.clone().unwrap(),
|
||||
self.registrant.clone().unwrap(),
|
||||
self.nameservers.clone().unwrap(),
|
||||
self.dnssec.clone().unwrap()
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -123,20 +127,22 @@ impl WhoisData {
|
||||
for nameserver in nameserver_regex.get_matches(&result) {
|
||||
nameservers.push(NameServer::new(nameserver));
|
||||
}
|
||||
let dnssec = dnssec_regex.get_matches(&result);
|
||||
|
||||
let mut dnssec = dnssec_regex.get_matches(&result);
|
||||
if dnssec.len() == 0 {
|
||||
dnssec = vec![String::from("Failed to get DNSSEC")];
|
||||
}
|
||||
// println!("{:?}", registrar[0]);
|
||||
WhoisData {
|
||||
registrar: registrar.clone(),
|
||||
domain_status: domain_status.clone(),
|
||||
registrant: vec![Registrant::new(
|
||||
registrar: Some(registrar.clone()),
|
||||
domain_status: Some(domain_status.clone()),
|
||||
registrant: Some(vec![Registrant::new(
|
||||
reg_name.clone(),
|
||||
reg_org.clone(),
|
||||
reg_email,
|
||||
RegistrantType::Registrant,
|
||||
)],
|
||||
nameservers: nameservers,
|
||||
dnssec: dnssec[0].clone(),
|
||||
)]),
|
||||
nameservers: Some(nameservers),
|
||||
dnssec: Some(dnssec[0].clone()),
|
||||
eligibility_type: None,
|
||||
}
|
||||
}
|
||||
@@ -144,19 +150,19 @@ impl WhoisData {
|
||||
pub fn to_vec(&self) -> Vec<String> {
|
||||
let mut ret_vec: Vec<String> = vec![];
|
||||
let mut registrar = String::from("Registrar: ");
|
||||
registrar.push_str(&self.registrar);
|
||||
registrar.push_str(&self.registrar.clone().unwrap());
|
||||
ret_vec.push(registrar);
|
||||
|
||||
let mut domain_status = String::from("Status: ");
|
||||
domain_status.push_str(&self.domain_status);
|
||||
domain_status.push_str(&self.domain_status.clone().unwrap());
|
||||
ret_vec.push(domain_status);
|
||||
|
||||
let mut dnssec = String::from("DNSSEC: ");
|
||||
dnssec.push_str(&self.dnssec);
|
||||
dnssec.push_str(&self.dnssec.clone().unwrap());
|
||||
ret_vec.push(dnssec);
|
||||
|
||||
let mut registrant_type = String::new();
|
||||
for registrant in &self.registrant {
|
||||
for registrant in &self.registrant.clone().unwrap() {
|
||||
match registrant.rtype {
|
||||
RegistrantType::Admin => {
|
||||
registrant_type.push_str("Admin ");
|
||||
@@ -187,7 +193,7 @@ impl WhoisData {
|
||||
ret_vec.push(email);
|
||||
}
|
||||
|
||||
for nameserver in &self.nameservers {
|
||||
for nameserver in &self.nameservers.clone().unwrap() {
|
||||
let mut tmp = String::from("Nameserver: ");
|
||||
tmp.push_str(&nameserver.host);
|
||||
ret_vec.push(tmp);
|
||||
|
||||
Reference in new issue
Block a user