From 465106438a1b5747b163472b07ef7005aeb1edd5 Mon Sep 17 00:00:00 2001 From: jeangab Date: Fri, 27 Sep 2024 16:51:49 -0400 Subject: [PATCH] wip: Actual implementation of opnsense dhcp --- harmony-rs/harmony/src/infra/opnsense/mod.rs | 22 ++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/harmony-rs/harmony/src/infra/opnsense/mod.rs b/harmony-rs/harmony/src/infra/opnsense/mod.rs index 92f1826..0f81d40 100644 --- a/harmony-rs/harmony/src/infra/opnsense/mod.rs +++ b/harmony-rs/harmony/src/infra/opnsense/mod.rs @@ -1,10 +1,10 @@ mod management; pub use management::*; -use crate::topology::{ +use crate::{executors::ExecutorError, topology::{ Backend, DHCPStaticEntry, DhcpServer, DnsServer, Firewall, FirewallError, FirewallRule, Frontend, IpAddress, LoadBalancer, LoadBalancerError, LogicalHost, -}; +}}; use derive_new::new; #[derive(new, Clone)] @@ -16,6 +16,10 @@ impl OPNSenseFirewall { pub fn get_ip(&self) -> IpAddress { self.host.ip } + + fn save_xml_to_config(&self, xml_entry: &str) -> Result<(), ExecutorError> { + todo!("Save XML Entry in opnsense /conf/config.xml {xml_entry}"); + } } impl Firewall for OPNSenseFirewall { @@ -77,6 +81,20 @@ impl DhcpServer for OPNSenseFirewall { &self, entry: &DHCPStaticEntry, ) -> Result<(), crate::topology::DhcpError> { + let mac = &entry.mac; + let name = &entry.name; + let ip = &entry.ip; + + let xml_entry = format!(" +> {mac} +> {ip} +> {name} +> {name} +> +> +> +> "); + self.save_xml_to_config(&xml_entry)?; todo!("Register {:?}", entry) }