feat: DhcpConfig can now effectively manage a config file to add a static map entry

This commit is contained in:
Jean-Gabriel Gill-Couture
2024-11-18 17:05:48 -05:00
parent cb1fea1eda
commit cc9bcb902c
13 changed files with 1595 additions and 1114 deletions

View File

@@ -1,23 +1,9 @@
use crate::data::dhcpd::Dhcpd;
use yaserde::{MaybeString, RawXml};
use crate::{data::dhcpd::DhcpInterface, xml_utils::to_xml_str};
use log::error;
use yaserde::{MaybeString, NamedList, RawXml};
use yaserde_derive::{YaDeserialize, YaSerialize};
impl From<String> for OPNsense {
fn from(content: String) -> Self {
yaserde::de::from_str(&content)
.map_err(|e| error!("{}", e.to_string()))
.expect("OPNSense received invalid string, should be full XML")
}
}
impl OPNsense {
pub fn to_xml(&self) -> String {
yaserde::ser::to_string(self)
.map_err(|e| error!("{}", e.to_string()))
.expect("OPNSense could not serialize to XML")
}
}
use super::Interface;
#[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)]
#[yaserde(rename = "opnsense")]
@@ -25,8 +11,9 @@ pub struct OPNsense {
pub theme: String,
pub sysctl: Sysctl,
pub system: RawXml,
pub interfaces: RawXml,
pub dhcpd: Dhcpd,
// pub interfaces: RawXml,
pub interfaces: NamedList<Interface>,
pub dhcpd: NamedList<DhcpInterface>,
pub snmpd: Snmpd,
pub syslog: Syslog,
pub nat: Nat,
@@ -56,6 +43,23 @@ pub struct OPNsense {
pub ifgroups: Ifgroups,
}
impl From<String> for OPNsense {
fn from(content: String) -> Self {
yaserde::de::from_str(&content)
.map_err(|e| println!("{}", e.to_string()))
.expect("OPNSense received invalid string, should be full XML")
}
}
impl OPNsense {
pub fn to_xml(&self) -> String {
to_xml_str(self)
.map_err(|e| error!("{}", e.to_string()))
.expect("OPNSense could not serialize to XML")
}
}
#[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)]
pub struct LoadBalancer {
pub monitor_type: Vec<MonitorType>,
@@ -945,6 +949,7 @@ pub struct Acl {
pub browser: MaybeString,
#[yaserde(rename = "mimeType")]
pub mime_type: MaybeString,
#[yaserde(rename = "googleapps")]
pub google_apps: MaybeString,
pub youtube: MaybeString,
#[yaserde(rename = "safePorts")]