Added config parsing
This commit is contained in:
parent
91db678c55
commit
bca8892147
7
Cargo.lock
generated
7
Cargo.lock
generated
@ -73,6 +73,12 @@ version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "configparser"
|
||||
version = "3.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4ec6d3da8e550377a85339063af6e3735f4b1d9392108da4e083a1b3b9820288"
|
||||
|
||||
[[package]]
|
||||
name = "data-encoding"
|
||||
version = "2.5.0"
|
||||
@ -83,6 +89,7 @@ checksum = "7e962a19be5cfc3f3bf6dd8f61eb50107f356ad6270fbb3ed41476571db78be5"
|
||||
name = "dns_lookup_project"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"configparser",
|
||||
"hickory-resolver",
|
||||
]
|
||||
|
||||
|
||||
@ -6,4 +6,5 @@ edition = "2021"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
configparser = "3.0.4"
|
||||
hickory-resolver = { version = "0.24.0" }
|
||||
|
||||
33
src/config.rs
Normal file
33
src/config.rs
Normal file
@ -0,0 +1,33 @@
|
||||
use configparser::ini::Ini;
|
||||
use core::fmt;
|
||||
|
||||
pub struct Config {
|
||||
pub subdomains: Vec<String>,
|
||||
wildcard_test: 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)
|
||||
}
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn from_file(file_path: String) -> Config {
|
||||
let mut config = Ini::new();
|
||||
let _map = config.load(file_path).unwrap();
|
||||
|
||||
let subdomains = config.get("General", "subdomains").unwrap();
|
||||
let mut subvec: Vec<String> = vec![];
|
||||
|
||||
for x in subdomains.split(',') {
|
||||
subvec.push(x.to_string());
|
||||
}
|
||||
|
||||
let wildcard_test = config.get("General", "wildcard_test");
|
||||
Config {
|
||||
subdomains: subvec,
|
||||
wildcard_test: wildcard_test.unwrap()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -4,6 +4,8 @@ use hickory_resolver::config::*;
|
||||
|
||||
use core::fmt;
|
||||
|
||||
use crate::config::Config;
|
||||
|
||||
// #[derive(Debug)]
|
||||
pub struct Domain {
|
||||
domain_name: String,
|
||||
@ -14,7 +16,7 @@ pub struct Domain {
|
||||
mx_records: Vec<MX>,
|
||||
ns_records: Vec<NS>,
|
||||
soa_records: Vec<SOA>, // Subdomains CAN have there own SOA records if their zones point elsewhere
|
||||
resolver: Resolver
|
||||
resolver: Resolver,
|
||||
}
|
||||
|
||||
impl fmt::Display for Domain {
|
||||
@ -74,6 +76,12 @@ impl Domain {
|
||||
// println!("Added: {}", new_domain);
|
||||
}
|
||||
|
||||
pub fn apply_config(&mut self, config: &Config) {
|
||||
for subdomain in &config.subdomains {
|
||||
self.append_subdomain(subdomain.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
pub fn lookup_all_records(&mut self) {
|
||||
// Lookup A records
|
||||
self.lookup_a();
|
||||
|
||||
10
src/main.rs
10
src/main.rs
@ -1,11 +1,15 @@
|
||||
mod domain;
|
||||
use crate::domain::Domain;
|
||||
|
||||
mod config;
|
||||
use crate::config::Config;
|
||||
|
||||
fn main() {
|
||||
|
||||
let mut test = Domain::new("pigandpilgrim.com.au".to_string());
|
||||
test.append_subdomain("www".to_string());
|
||||
test.append_subdomain("mail".to_string());
|
||||
test.append_subdomain("ftp".to_string());
|
||||
let config = Config::from_file("test.ini".to_string());
|
||||
test.apply_config(&config);
|
||||
|
||||
test.lookup_all_records();
|
||||
|
||||
println!("{}", test);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user