132 lines
4.4 KiB
Rust
132 lines
4.4 KiB
Rust
mod domain;
|
|
use crate::domain::Domain;
|
|
|
|
mod config;
|
|
use crate::config::Config;
|
|
|
|
mod app;
|
|
use crate::app::*;
|
|
|
|
mod ui;
|
|
use crate::ui::*;
|
|
|
|
mod fsutil;
|
|
use crate::fsutil::*;
|
|
|
|
mod whois;
|
|
use whois::default;
|
|
use whois::selector::*;
|
|
|
|
use crossterm::event::{
|
|
self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode, KeyEventKind,
|
|
};
|
|
use crossterm::execute;
|
|
use crossterm::terminal::{
|
|
disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen,
|
|
};
|
|
use ratatui::backend::{Backend, CrosstermBackend};
|
|
use ratatui::Terminal;
|
|
use std::error::Error;
|
|
use std::io::{self, stderr};
|
|
|
|
fn main() -> Result<(), Box<dyn Error>> {
|
|
enable_raw_mode()?;
|
|
let mut stderr = stderr();
|
|
execute!(stderr, EnterAlternateScreen, EnableMouseCapture)?;
|
|
|
|
let backend = CrosstermBackend::new(stderr);
|
|
let mut terminal = Terminal::new(backend)?;
|
|
|
|
// Initialise the App and config
|
|
let mut app = App::new();
|
|
let config = Config::from_file("test.ini".to_string());
|
|
|
|
// Run the app
|
|
let _res = run_app(&mut terminal, &mut app);
|
|
|
|
disable_raw_mode()?;
|
|
execute!(
|
|
terminal.backend_mut(),
|
|
LeaveAlternateScreen,
|
|
DisableMouseCapture
|
|
)?;
|
|
terminal.show_cursor()?;
|
|
Ok(())
|
|
}
|
|
|
|
fn run_app<B: Backend>(terminal: &mut Terminal<B>, app: &mut App) -> io::Result<bool> {
|
|
loop {
|
|
terminal.draw(|f| ui(f, app))?;
|
|
|
|
if let Event::Key(key) = event::read()? {
|
|
if key.kind == event::KeyEventKind::Release {
|
|
continue;
|
|
}
|
|
match app.current_state {
|
|
CurrentState::Lookup => match key.code {
|
|
KeyCode::Esc => {
|
|
app.current_state = CurrentState::Menu;
|
|
}
|
|
KeyCode::Backspace => {
|
|
app.domain_input.pop();
|
|
}
|
|
KeyCode::Char(char) => {
|
|
app.domain_input.push(char);
|
|
}
|
|
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);
|
|
domain.apply_config(&app.config);
|
|
domain.lookup_all_records();
|
|
app.dns_info = domain.to_vec();
|
|
let whois_server = select_whois_server(app.domain_input.clone());
|
|
match whois_server {
|
|
Ok(mut whois_data) => {
|
|
app.whois_info = whois_data.lookup(app.domain_input.clone());
|
|
}
|
|
Err(_) => {}
|
|
}
|
|
// let whois = WhoisData::new(app.domain_input.clone());
|
|
// app.whois_info = whois.to_vec();
|
|
}
|
|
KeyCode::Delete => {
|
|
app.domain_input = String::new();
|
|
}
|
|
_ => {}
|
|
},
|
|
CurrentState::Menu => match app.menu_state {
|
|
MenuState::Main => 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(&app.config).unwrap();
|
|
app.current_state = CurrentState::Lookup;
|
|
}
|
|
KeyCode::Char('l') => {
|
|
app.menu_state = MenuState::List;
|
|
}
|
|
KeyCode::Char('q') => return Ok(false),
|
|
_ => {}
|
|
},
|
|
MenuState::List => match key.code {
|
|
KeyCode::Esc => {
|
|
app.menu_state = MenuState::Main;
|
|
}
|
|
_ => {}
|
|
},
|
|
},
|
|
}
|
|
}
|
|
}
|
|
}
|