harmony/harmony-rs/opnsense-config/src/modules/dns.rs
2024-12-18 15:58:49 -05:00

46 lines
1.3 KiB
Rust

use std::sync::Arc;
use opnsense_config_xml::{Host, OPNsense};
use crate::config::OPNsenseShell;
pub struct DnsConfig<'a> {
opnsense: &'a mut OPNsense,
opnsense_shell: Arc<dyn OPNsenseShell>,
}
impl<'a> DnsConfig<'a> {
pub fn new(opnsense: &'a mut OPNsense, opnsense_shell: Arc<dyn OPNsenseShell>) -> Self {
Self {
opnsense,
opnsense_shell,
}
}
pub fn register_hosts(&mut self, mut hosts: Vec<Host>) {
let unbound = match &mut self.opnsense.opnsense.unboundplus {
Some(unbound) => unbound,
None => todo!("Handle case where unboundplus is not used"),
};
unbound.hosts.hosts.append(&mut hosts);
}
pub fn get_hosts(&self) -> Vec<Host> {
let unbound = match &self.opnsense.opnsense.unboundplus {
Some(unbound) => unbound,
None => todo!("Handle case where unboundplus is not used"),
};
unbound.hosts.hosts.clone()
}
pub fn register_dhcp_leases(&mut self, register: bool) {
let unbound = match &mut self.opnsense.opnsense.unboundplus {
Some(unbound) => unbound,
None => todo!("Handle case where unboundplus is not used"),
};
unbound.general.regdhcp = register as i8;
unbound.general.regdhcpstatic = register as i8;
}
}