server testing
This commit is contained in:
parent
6a136eb57a
commit
37fa090ee9
843
Cargo.lock
generated
843
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -16,3 +16,4 @@ serde = { version = "*", features = ["derive"] }
|
||||
serde_json = "*"
|
||||
chrono = "*"
|
||||
addr = { version = "0.15.6", features = ["publicsuffix"] }
|
||||
rocket = "0.5.1"
|
||||
|
||||
@ -7,6 +7,13 @@ pub struct Config {
|
||||
pub subdomains: Vec<String>,
|
||||
pub wildcard_test: String,
|
||||
pub data_dir: String,
|
||||
pub mode: ApplicationMode,
|
||||
}
|
||||
|
||||
pub enum ApplicationMode {
|
||||
UI,
|
||||
SERVER,
|
||||
ERROR,
|
||||
}
|
||||
|
||||
impl fmt::Display for Config {
|
||||
@ -34,10 +41,17 @@ impl Config {
|
||||
let wildcard_test = config.get("General", "wildcard");
|
||||
let datadir = config.get("General", "data_directory");
|
||||
|
||||
let mode = match config.get("General", "mode").unwrap().as_str() {
|
||||
"UI" => ApplicationMode::UI,
|
||||
"SERVER" => ApplicationMode::SERVER,
|
||||
_ => ApplicationMode::ERROR,
|
||||
};
|
||||
|
||||
Config {
|
||||
subdomains: subvec,
|
||||
wildcard_test: wildcard_test.unwrap(),
|
||||
data_dir: datadir.unwrap(),
|
||||
mode: mode,
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
@ -75,6 +89,7 @@ impl Config {
|
||||
"data_directory",
|
||||
Some(String::from(default_path.to_str().unwrap())),
|
||||
);
|
||||
config.set("General", "mode", Some(String::from("UI")));
|
||||
|
||||
let mut conf_path = default_path.clone();
|
||||
conf_path.push("/config.ini");
|
||||
|
||||
29
src/main.rs
29
src/main.rs
@ -1,3 +1,6 @@
|
||||
#[macro_use]
|
||||
extern crate rocket;
|
||||
|
||||
mod domain;
|
||||
use crate::domain::Domain;
|
||||
|
||||
@ -18,6 +21,8 @@ use whois::default;
|
||||
use whois::selector::*;
|
||||
|
||||
mod logger;
|
||||
mod server;
|
||||
use server::*;
|
||||
|
||||
use crossterm::event::{
|
||||
self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode, KeyEventKind,
|
||||
@ -32,6 +37,30 @@ use std::error::Error;
|
||||
use std::io::{self, stdout};
|
||||
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
let init_config = Config::load();
|
||||
match init_config.mode {
|
||||
config::ApplicationMode::UI => run_tui(),
|
||||
config::ApplicationMode::SERVER => run_server(),
|
||||
config::ApplicationMode::ERROR => {
|
||||
println!("Failed to parse mode in INI file");
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[get("/")]
|
||||
pub fn hello() -> &'static str {
|
||||
"This is a test"
|
||||
}
|
||||
|
||||
fn run_server() -> Result<(), Box<dyn Error>> {
|
||||
// let server = server::Server::new();
|
||||
let _rocket = rocket::build().mount("/", routes![hello]).launch();
|
||||
Ok(())
|
||||
// server.run()
|
||||
}
|
||||
|
||||
fn run_tui() -> Result<(), Box<dyn Error>> {
|
||||
enable_raw_mode()?;
|
||||
let mut stdout = stdout();
|
||||
execute!(stdout, EnterAlternateScreen)?;
|
||||
|
||||
26
src/server.rs
Normal file
26
src/server.rs
Normal file
@ -0,0 +1,26 @@
|
||||
use rocket::*;
|
||||
use std::error::Error;
|
||||
|
||||
// Initiate server here and have main loop here similar to how UI is done
|
||||
pub struct Server {
|
||||
listen_addr: String,
|
||||
listen_port: i64,
|
||||
}
|
||||
|
||||
impl Server {
|
||||
pub fn new() -> Server {
|
||||
Server {
|
||||
listen_addr: String::from("0.0.0.0"),
|
||||
listen_port: 60009,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run(&self) -> Result<(), Box<dyn Error>> {
|
||||
println!(
|
||||
"Starting server on {}:{}",
|
||||
self.listen_addr, self.listen_port
|
||||
);
|
||||
// rocket::build().mount("/", routes![Server::hello]);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@ -24,6 +24,7 @@ impl Eligibility {
|
||||
pub struct _Whois {
|
||||
base: WhoisData,
|
||||
eligibility: Eligibility,
|
||||
modified: String,
|
||||
}
|
||||
|
||||
impl Whois for _Whois {
|
||||
@ -31,6 +32,7 @@ impl Whois for _Whois {
|
||||
_Whois {
|
||||
base: WhoisData::new(),
|
||||
eligibility: Eligibility::new(),
|
||||
modified: String::new(),
|
||||
}
|
||||
}
|
||||
fn to_vec(&self) -> Vec<String> {
|
||||
@ -39,6 +41,10 @@ impl Whois for _Whois {
|
||||
registrar.push_str(&self.base.registrar.clone().unwrap());
|
||||
ret_vec.push(registrar);
|
||||
|
||||
let mut last_modified = String::from("Last Modified: ");
|
||||
last_modified.push_str(&self.modified.clone());
|
||||
ret_vec.push(last_modified);
|
||||
|
||||
let mut domain_status = String::from("Status: ");
|
||||
domain_status.push_str(&self.base.domain_status.clone().unwrap());
|
||||
ret_vec.push(domain_status);
|
||||
@ -110,6 +116,7 @@ impl Whois for _Whois {
|
||||
.unwrap();
|
||||
let registrar_regex =
|
||||
RegexQuery::new(String::from(r"(?i)(.*registrar:|registrar *name:)(.*)"));
|
||||
let last_modified_regex = RegexQuery::new(String::from(r"(?i)(.*last modified:)(.*)"));
|
||||
let domain_status_regex =
|
||||
RegexQuery::new(String::from(r"(?i)(.*domain status:|.*status:)(.* )"));
|
||||
// TODO: Capture the registrant info for each type
|
||||
@ -128,6 +135,7 @@ impl Whois for _Whois {
|
||||
let registrant_id_regex = RegexQuery::new(String::from(r"(?i)(.*registrant id:)(.*)"));
|
||||
|
||||
let registrar = WhoisData::return_regex(registrar_regex.get_matches(&result), 0);
|
||||
let last_modified = WhoisData::return_regex(last_modified_regex.get_matches(&result), 0);
|
||||
let domain_status = WhoisData::return_regex(domain_status_regex.get_matches(&result), 0);
|
||||
let reg_name = WhoisData::return_regex(registrant_name_regex.get_matches(&result), 0);
|
||||
let reg_org = WhoisData::return_regex(registrant_org_regex.get_matches(&result), 0);
|
||||
@ -163,6 +171,7 @@ impl Whois for _Whois {
|
||||
self.eligibility.e_type = Some(eligebility_type.clone());
|
||||
self.eligibility.e_id = Some(eligebility_id.clone());
|
||||
self.eligibility.r_id = Some(registrant_id.clone());
|
||||
self.modified = last_modified;
|
||||
self.to_vec()
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user