Base UI implemented

This commit is contained in:
Benjamyn Love 2024-03-29 23:39:39 +11:00
parent d932bb234b
commit 067112ae2d
4 changed files with 142 additions and 23 deletions

View File

@ -67,6 +67,51 @@ impl Domain {
} }
} }
pub fn to_vec(&self) -> Vec<String> {
let mut ret_vec: Vec<String> = vec![];
for rec in &self.a_records {
let mut tmp = String::from("A: ");
tmp.push_str(rec.to_string().as_ref());
ret_vec.push(tmp);
}
for rec in &self.aaaa_records {
let mut tmp = String::from("AAAA: ");
tmp.push_str(rec.to_string().as_ref());
ret_vec.push(tmp);
}
for rec in &self.mx_records {
let mut tmp = String::from("MX: ");
tmp.push_str(rec.to_string().as_ref());
ret_vec.push(tmp);
}
for rec in &self.txt_records {
let mut tmp = String::from("TXT: ");
tmp.push_str(rec.to_string().as_ref());
ret_vec.push(tmp);
}
for rec in &self.ns_records {
let mut tmp = String::from("NS: ");
tmp.push_str(rec.to_string().as_ref());
ret_vec.push(tmp);
}
for rec in &self.soa_records {
let mut tmp = String::from("SOA: ");
tmp.push_str(rec.to_string().as_ref());
ret_vec.push(tmp);
}
for subdomain in &self.subdomains {
let mut subdomain_name = String::from(subdomain.domain_name.clone());
subdomain_name.push_str("\t");
for rec in &subdomain.a_records {
let mut tmp = String::from(&subdomain_name);
tmp.push_str(" A: ");
tmp.push_str(rec.to_string().as_ref());
ret_vec.push(tmp);
}
}
return ret_vec;
}
pub fn append_subdomain(&mut self, subdomain: String) { pub fn append_subdomain(&mut self, subdomain: String) {
let mut new_domain = String::from(subdomain); let mut new_domain = String::from(subdomain);
new_domain.push_str("."); new_domain.push_str(".");

View File

@ -102,7 +102,11 @@ fn run_app<B: Backend>(
KeyCode::Enter => { KeyCode::Enter => {
// This will do the lookup and populate the UI with the info // This will do the lookup and populate the UI with the info
let mut domain = Domain::new(app.domain_input.clone()); let mut domain = Domain::new(app.domain_input.clone());
domain.apply_config(&config);
domain.lookup_all_records(); domain.lookup_all_records();
app.dns_info = domain.to_vec();
let whois = WhoisData::new(app.domain_input.clone());
app.whois_info = whois.to_vec();
} }
_ => {} _ => {}
}, },

View File

@ -51,31 +51,42 @@ pub fn ui(f: &mut Frame, app: &App) {
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)]) .constraints([Constraint::Percentage(50), Constraint::Percentage(50)])
.split(chunks[1]); .split(chunks[1]);
let whois_block = Block::default() // let whois_block = Block::default()
.borders(Borders::RIGHT) // .borders(Borders::RIGHT)
.style(Style::default()); // .style(Style::default());
let whois_text = Paragraph::new(Text::styled( // let whois_text = Paragraph::new(Text::styled(
"Whois data in // "Whois data in
style // style
with // with
multiline support", // multiline support",
Style::default().fg(Color::Green), // Style::default().fg(Color::Green),
)) // ))
.block(whois_block); // .block(whois_block);
f.render_widget(whois_text, data_layout[0]);
let dns_block = Block::default().style(Style::default()); // Whois list
let dns_text = Paragraph::new(Text::styled( let mut whois_list_items = Vec::<ListItem>::new();
"Dns records for record in &app.whois_info {
also whois_list_items.push(ListItem::new(Line::from(Span::styled(
with record,
multiline Style::default(),
support", ))))
Style::default().fg(Color::Red), }
)) let whois_list = List::new(whois_list_items);
.block(dns_block);
f.render_widget(dns_text, data_layout[1]); f.render_widget(whois_list, data_layout[0]);
// DNS list
let mut dns_list_items = Vec::<ListItem>::new();
for record in &app.dns_info {
dns_list_items.push(ListItem::new(Line::from(Span::styled(
record,
Style::default(),
))))
}
let dns_list = List::new(dns_list_items);
f.render_widget(dns_list, data_layout[1]);
let footer_chunks = Layout::default() let footer_chunks = Layout::default()
.direction(Direction::Horizontal) .direction(Direction::Horizontal)

View File

@ -1,4 +1,8 @@
use core::fmt; use core::fmt;
use hickory_resolver::proto::{
rr::{domain, rdata::name},
xfer::dns_handle,
};
use regex::Regex; use regex::Regex;
use whois_rust::{WhoIs, WhoIsLookupOptions}; use whois_rust::{WhoIs, WhoIsLookupOptions};
@ -137,6 +141,61 @@ 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);
ret_vec.push(registrar);
let mut domain_status = String::from("Status: ");
domain_status.push_str(&self.domain_status);
ret_vec.push(domain_status);
let mut dnssec = String::from("DNSSEC: ");
dnssec.push_str(&self.dnssec);
ret_vec.push(dnssec);
let mut registrant_type = String::new();
for registrant in &self.registrant {
match registrant.rtype {
RegistrantType::Admin => {
registrant_type.push_str("Admin ");
}
RegistrantType::Billing => {
registrant_type.push_str("Billing ");
}
RegistrantType::Tech => {
registrant_type.push_str("Tech ");
}
RegistrantType::Registrant => {
registrant_type.push_str("Registrant ");
}
}
let mut name = registrant_type.clone();
name.push_str("Name: ");
name.push_str(&registrant.name);
ret_vec.push(name);
let mut org = registrant_type.clone();
org.push_str("Organisation: ");
org.push_str(&registrant.org);
ret_vec.push(org);
let mut email = registrant_type.clone();
email.push_str("Email: ");
email.push_str(&registrant.email);
ret_vec.push(email);
}
for nameserver in &self.nameservers {
let mut tmp = String::from("Nameserver: ");
tmp.push_str(&nameserver.host);
ret_vec.push(tmp);
}
return ret_vec;
}
fn return_regex(caps: Vec<String>, index: usize) -> String { fn return_regex(caps: Vec<String>, index: usize) -> String {
let data: String; let data: String;
match caps.get(index) { match caps.get(index) {