feat: DhcpConfig can now effectively manage a config file to add a static map entry
This commit is contained in:
parent
cb1fea1eda
commit
cc9bcb902c
@ -1,586 +1,9 @@
|
|||||||
mod interfaces {
|
mod interfaces {
|
||||||
use xml::reader::XmlEvent;
|
|
||||||
use yaserde::{
|
use yaserde::{
|
||||||
raw_xml::RawXml, YaDeserialize as YaDeserializeTrait,
|
NamedList, YaDeserialize as YaDeserializeTrait, YaSerialize as YaSerializeTrait,
|
||||||
YaSerialize as YaSerializeTrait,
|
|
||||||
};
|
};
|
||||||
use yaserde_derive::{YaDeserialize, YaSerialize};
|
use yaserde_derive::{YaDeserialize, YaSerialize};
|
||||||
use std::collections::HashMap;
|
use yaserde::MaybeString;
|
||||||
use crate::xml_utils::MaybeString;
|
|
||||||
pub struct Interfaces {
|
|
||||||
pub testraw: RawXml,
|
|
||||||
pub interfaces: HashMap<String, Interface>,
|
|
||||||
}
|
|
||||||
#[automatically_derived]
|
|
||||||
impl ::core::default::Default for Interfaces {
|
|
||||||
#[inline]
|
|
||||||
fn default() -> Interfaces {
|
|
||||||
Interfaces {
|
|
||||||
testraw: ::core::default::Default::default(),
|
|
||||||
interfaces: ::core::default::Default::default(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[automatically_derived]
|
|
||||||
impl ::core::marker::StructuralPartialEq for Interfaces {}
|
|
||||||
#[automatically_derived]
|
|
||||||
impl ::core::cmp::PartialEq for Interfaces {
|
|
||||||
#[inline]
|
|
||||||
fn eq(&self, other: &Interfaces) -> bool {
|
|
||||||
self.testraw == other.testraw && self.interfaces == other.interfaces
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[automatically_derived]
|
|
||||||
impl ::core::fmt::Debug for Interfaces {
|
|
||||||
#[inline]
|
|
||||||
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
|
|
||||||
::core::fmt::Formatter::debug_struct_field2_finish(
|
|
||||||
f,
|
|
||||||
"Interfaces",
|
|
||||||
"testraw",
|
|
||||||
&self.testraw,
|
|
||||||
"interfaces",
|
|
||||||
&&self.interfaces,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
|
|
||||||
const _IMPL_YA_SERIALIZE_FOR_Interfaces: () = {
|
|
||||||
use ::std::str::FromStr as _;
|
|
||||||
impl ::yaserde::YaSerialize for Interfaces {
|
|
||||||
#[allow(unused_variables)]
|
|
||||||
fn serialize<W: ::std::io::Write>(
|
|
||||||
&self,
|
|
||||||
writer: &mut ::yaserde::ser::Serializer<W>,
|
|
||||||
) -> ::std::result::Result<(), ::std::string::String> {
|
|
||||||
let skip = writer.skip_start_end();
|
|
||||||
if !false && !skip {
|
|
||||||
let mut child_attributes = ::alloc::vec::Vec::new();
|
|
||||||
let mut child_attributes_namespace = ::yaserde::__xml::namespace::Namespace::empty();
|
|
||||||
let yaserde_label = writer
|
|
||||||
.get_start_event_name()
|
|
||||||
.unwrap_or_else(|| "Interfaces".to_string());
|
|
||||||
let struct_start_event = ::yaserde::__xml::writer::XmlEvent::start_element(
|
|
||||||
yaserde_label.as_ref(),
|
|
||||||
);
|
|
||||||
let event: ::yaserde::__xml::writer::events::XmlEvent = struct_start_event
|
|
||||||
.into();
|
|
||||||
if let ::yaserde::__xml::writer::events::XmlEvent::StartElement {
|
|
||||||
name,
|
|
||||||
attributes,
|
|
||||||
namespace,
|
|
||||||
} = event {
|
|
||||||
let mut attributes: ::std::vec::Vec<
|
|
||||||
::yaserde::__xml::attribute::OwnedAttribute,
|
|
||||||
> = attributes
|
|
||||||
.into_owned()
|
|
||||||
.to_vec()
|
|
||||||
.iter()
|
|
||||||
.map(|k| k.to_owned())
|
|
||||||
.collect();
|
|
||||||
attributes.extend(child_attributes);
|
|
||||||
let all_attributes = attributes
|
|
||||||
.iter()
|
|
||||||
.map(|ca| ca.borrow())
|
|
||||||
.collect();
|
|
||||||
let mut all_namespaces = namespace.into_owned();
|
|
||||||
all_namespaces.extend(&child_attributes_namespace);
|
|
||||||
writer
|
|
||||||
.write(::yaserde::__xml::writer::events::XmlEvent::StartElement {
|
|
||||||
name,
|
|
||||||
attributes: ::std::borrow::Cow::Owned(all_attributes),
|
|
||||||
namespace: ::std::borrow::Cow::Owned(all_namespaces),
|
|
||||||
})
|
|
||||||
.map_err(|e| e.to_string())?;
|
|
||||||
} else {
|
|
||||||
::core::panicking::panic(
|
|
||||||
"internal error: entered unreachable code",
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !false {
|
|
||||||
writer
|
|
||||||
.set_start_event_name(
|
|
||||||
::std::option::Option::Some("testraw".to_string()),
|
|
||||||
);
|
|
||||||
writer.set_skip_start_end(false);
|
|
||||||
::yaserde::YaSerialize::serialize(&self.testraw, writer)?;
|
|
||||||
}
|
|
||||||
if !false {
|
|
||||||
writer
|
|
||||||
.set_start_event_name(
|
|
||||||
::std::option::Option::Some("interfaces".to_string()),
|
|
||||||
);
|
|
||||||
writer.set_skip_start_end(false);
|
|
||||||
::yaserde::YaSerialize::serialize(&self.interfaces, writer)?;
|
|
||||||
}
|
|
||||||
if !false && !skip {
|
|
||||||
let struct_end_event = ::yaserde::__xml::writer::XmlEvent::end_element();
|
|
||||||
writer.write(struct_end_event).map_err(|e| e.to_string())?;
|
|
||||||
}
|
|
||||||
::std::result::Result::Ok(())
|
|
||||||
}
|
|
||||||
fn serialize_attributes(
|
|
||||||
&self,
|
|
||||||
mut source_attributes: ::std::vec::Vec<
|
|
||||||
::yaserde::__xml::attribute::OwnedAttribute,
|
|
||||||
>,
|
|
||||||
mut source_namespace: ::yaserde::__xml::namespace::Namespace,
|
|
||||||
) -> ::std::result::Result<
|
|
||||||
(
|
|
||||||
::std::vec::Vec<::yaserde::__xml::attribute::OwnedAttribute>,
|
|
||||||
::yaserde::__xml::namespace::Namespace,
|
|
||||||
),
|
|
||||||
::std::string::String,
|
|
||||||
> {
|
|
||||||
let mut child_attributes = ::std::vec::Vec::<
|
|
||||||
::yaserde::__xml::attribute::OwnedAttribute,
|
|
||||||
>::new();
|
|
||||||
let mut child_attributes_namespace = ::yaserde::__xml::namespace::Namespace::empty();
|
|
||||||
let struct_start_event = ::yaserde::__xml::writer::XmlEvent::start_element(
|
|
||||||
"temporary_element_to_generate_attributes",
|
|
||||||
);
|
|
||||||
let event: ::yaserde::__xml::writer::events::XmlEvent = struct_start_event
|
|
||||||
.into();
|
|
||||||
if let ::yaserde::__xml::writer::events::XmlEvent::StartElement {
|
|
||||||
attributes,
|
|
||||||
namespace,
|
|
||||||
..
|
|
||||||
} = event {
|
|
||||||
source_namespace.extend(&namespace.into_owned());
|
|
||||||
source_namespace.extend(&child_attributes_namespace);
|
|
||||||
let a: ::std::vec::Vec<
|
|
||||||
::yaserde::__xml::attribute::OwnedAttribute,
|
|
||||||
> = attributes
|
|
||||||
.into_owned()
|
|
||||||
.to_vec()
|
|
||||||
.iter()
|
|
||||||
.map(|k| k.to_owned())
|
|
||||||
.collect();
|
|
||||||
source_attributes.extend(a);
|
|
||||||
source_attributes.extend(child_attributes);
|
|
||||||
::std::result::Result::Ok((source_attributes, source_namespace))
|
|
||||||
} else {
|
|
||||||
::core::panicking::panic("internal error: entered unreachable code");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
|
|
||||||
const _IMPL_YA_DESERIALIZE_FOR_Interfaces: () = {
|
|
||||||
use ::std::str::FromStr as _;
|
|
||||||
use ::yaserde::Visitor as _;
|
|
||||||
impl ::yaserde::YaDeserialize for Interfaces {
|
|
||||||
#[allow(unused_variables)]
|
|
||||||
fn deserialize<R: ::std::io::Read>(
|
|
||||||
reader: &mut ::yaserde::de::Deserializer<R>,
|
|
||||||
) -> ::std::result::Result<Self, ::std::string::String> {
|
|
||||||
let (named_element, struct_namespace) = if let ::yaserde::__xml::reader::XmlEvent::StartElement {
|
|
||||||
name,
|
|
||||||
..
|
|
||||||
} = reader.peek()?.to_owned()
|
|
||||||
{
|
|
||||||
(name.local_name.to_owned(), name.namespace.clone())
|
|
||||||
} else {
|
|
||||||
(
|
|
||||||
::std::string::String::from("Interfaces"),
|
|
||||||
::std::option::Option::None,
|
|
||||||
)
|
|
||||||
};
|
|
||||||
let start_depth = reader.depth();
|
|
||||||
{
|
|
||||||
let lvl = ::log::Level::Debug;
|
|
||||||
if lvl <= ::log::STATIC_MAX_LEVEL && lvl <= ::log::max_level() {
|
|
||||||
::log::__private_api::log(
|
|
||||||
format_args!(
|
|
||||||
"Struct {0} @ {1}: start to parse {2:?}",
|
|
||||||
"Interfaces",
|
|
||||||
start_depth,
|
|
||||||
named_element,
|
|
||||||
),
|
|
||||||
lvl,
|
|
||||||
&(
|
|
||||||
"yaserde_derive",
|
|
||||||
"opnsense_config_xml::data::interfaces",
|
|
||||||
::log::__private_api::loc(),
|
|
||||||
),
|
|
||||||
(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if reader.depth() == 0 {
|
|
||||||
if let Some(namespace) = struct_namespace {
|
|
||||||
match namespace.as_str() {
|
|
||||||
bad_namespace => {
|
|
||||||
let msg = ::alloc::__export::must_use({
|
|
||||||
let res = ::alloc::fmt::format(
|
|
||||||
format_args!(
|
|
||||||
"bad namespace for {0}, found {1}",
|
|
||||||
named_element,
|
|
||||||
bad_namespace,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
res
|
|
||||||
});
|
|
||||||
return Err(msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[allow(unused_mut)]
|
|
||||||
let mut __testraw_value: Option<RawXml> = None;
|
|
||||||
#[allow(unused_mut)]
|
|
||||||
let mut __interfaces_value: Option<HashMap<String, Interface>> = None;
|
|
||||||
let mut depth = 0;
|
|
||||||
loop {
|
|
||||||
let event = reader.peek()?.to_owned();
|
|
||||||
{
|
|
||||||
let lvl = ::log::Level::Trace;
|
|
||||||
if lvl <= ::log::STATIC_MAX_LEVEL && lvl <= ::log::max_level() {
|
|
||||||
::log::__private_api::log(
|
|
||||||
format_args!(
|
|
||||||
"Struct {0} @ {1}: matching {2:?}",
|
|
||||||
"Interfaces",
|
|
||||||
start_depth,
|
|
||||||
event,
|
|
||||||
),
|
|
||||||
lvl,
|
|
||||||
&(
|
|
||||||
"yaserde_derive",
|
|
||||||
"opnsense_config_xml::data::interfaces",
|
|
||||||
::log::__private_api::loc(),
|
|
||||||
),
|
|
||||||
(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
match event {
|
|
||||||
::yaserde::__xml::reader::XmlEvent::StartElement {
|
|
||||||
ref name,
|
|
||||||
ref attributes,
|
|
||||||
..
|
|
||||||
} => {
|
|
||||||
let namespace = name.namespace.clone().unwrap_or_default();
|
|
||||||
if depth == 0 && name.local_name == "Interfaces"
|
|
||||||
&& namespace.as_str() == ""
|
|
||||||
{
|
|
||||||
let event = reader.next_event()?;
|
|
||||||
} else {
|
|
||||||
match (namespace.as_str(), name.local_name.as_str()) {
|
|
||||||
("", "testraw") => {
|
|
||||||
if depth == 0 {
|
|
||||||
let _root = reader.next_event();
|
|
||||||
}
|
|
||||||
{
|
|
||||||
let lvl = ::log::Level::Debug;
|
|
||||||
if lvl <= ::log::STATIC_MAX_LEVEL
|
|
||||||
&& lvl <= ::log::max_level()
|
|
||||||
{
|
|
||||||
::log::__private_api::log(
|
|
||||||
format_args!("Looking at startElement"),
|
|
||||||
lvl,
|
|
||||||
&(
|
|
||||||
"yaserde_derive",
|
|
||||||
"opnsense_config_xml::data::interfaces",
|
|
||||||
::log::__private_api::loc(),
|
|
||||||
),
|
|
||||||
(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
{
|
|
||||||
let lvl = ::log::Level::Warn;
|
|
||||||
if lvl <= ::log::STATIC_MAX_LEVEL
|
|
||||||
&& lvl <= ::log::max_level()
|
|
||||||
{
|
|
||||||
::log::__private_api::log(
|
|
||||||
format_args!("matching field type ASPDOJIASDPJIDASPJASDJI"),
|
|
||||||
lvl,
|
|
||||||
&(
|
|
||||||
"opnsense_config_xml::data::interfaces",
|
|
||||||
"opnsense_config_xml::data::interfaces",
|
|
||||||
::log::__private_api::loc(),
|
|
||||||
),
|
|
||||||
(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if let Ok(
|
|
||||||
::yaserde::__xml::reader::XmlEvent::StartElement { .. },
|
|
||||||
) = reader.peek()
|
|
||||||
{
|
|
||||||
{
|
|
||||||
let lvl = ::log::Level::Warn;
|
|
||||||
if lvl <= ::log::STATIC_MAX_LEVEL
|
|
||||||
&& lvl <= ::log::max_level()
|
|
||||||
{
|
|
||||||
::log::__private_api::log(
|
|
||||||
format_args!("Found start element ?? {0}", "RawXml"),
|
|
||||||
lvl,
|
|
||||||
&(
|
|
||||||
"opnsense_config_xml::data::interfaces",
|
|
||||||
"opnsense_config_xml::data::interfaces",
|
|
||||||
::log::__private_api::loc(),
|
|
||||||
),
|
|
||||||
(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let value = <RawXml as ::yaserde::YaDeserialize>::deserialize(
|
|
||||||
reader,
|
|
||||||
)?;
|
|
||||||
__testraw_value = ::std::option::Option::Some(value);
|
|
||||||
let _event = reader.next_event()?;
|
|
||||||
} else {
|
|
||||||
{
|
|
||||||
let lvl = ::log::Level::Warn;
|
|
||||||
if lvl <= ::log::STATIC_MAX_LEVEL
|
|
||||||
&& lvl <= ::log::max_level()
|
|
||||||
{
|
|
||||||
::log::__private_api::log(
|
|
||||||
format_args!(
|
|
||||||
"matching field type did not find substruct start element ? {0}",
|
|
||||||
"RawXml",
|
|
||||||
),
|
|
||||||
lvl,
|
|
||||||
&(
|
|
||||||
"opnsense_config_xml::data::interfaces",
|
|
||||||
"opnsense_config_xml::data::interfaces",
|
|
||||||
::log::__private_api::loc(),
|
|
||||||
),
|
|
||||||
(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
("", "interfaces") => {
|
|
||||||
if depth == 0 {
|
|
||||||
let _root = reader.next_event();
|
|
||||||
}
|
|
||||||
{
|
|
||||||
let lvl = ::log::Level::Debug;
|
|
||||||
if lvl <= ::log::STATIC_MAX_LEVEL
|
|
||||||
&& lvl <= ::log::max_level()
|
|
||||||
{
|
|
||||||
::log::__private_api::log(
|
|
||||||
format_args!("Looking at startElement"),
|
|
||||||
lvl,
|
|
||||||
&(
|
|
||||||
"yaserde_derive",
|
|
||||||
"opnsense_config_xml::data::interfaces",
|
|
||||||
::log::__private_api::loc(),
|
|
||||||
),
|
|
||||||
(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
{
|
|
||||||
let lvl = ::log::Level::Warn;
|
|
||||||
if lvl <= ::log::STATIC_MAX_LEVEL
|
|
||||||
&& lvl <= ::log::max_level()
|
|
||||||
{
|
|
||||||
::log::__private_api::log(
|
|
||||||
format_args!("matching field type ASPDOJIASDPJIDASPJASDJI"),
|
|
||||||
lvl,
|
|
||||||
&(
|
|
||||||
"opnsense_config_xml::data::interfaces",
|
|
||||||
"opnsense_config_xml::data::interfaces",
|
|
||||||
::log::__private_api::loc(),
|
|
||||||
),
|
|
||||||
(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if let Ok(
|
|
||||||
::yaserde::__xml::reader::XmlEvent::StartElement { .. },
|
|
||||||
) = reader.peek()
|
|
||||||
{
|
|
||||||
{
|
|
||||||
let lvl = ::log::Level::Warn;
|
|
||||||
if lvl <= ::log::STATIC_MAX_LEVEL
|
|
||||||
&& lvl <= ::log::max_level()
|
|
||||||
{
|
|
||||||
::log::__private_api::log(
|
|
||||||
format_args!(
|
|
||||||
"Found start element ?? {0}",
|
|
||||||
"HashMap < String, Interface >",
|
|
||||||
),
|
|
||||||
lvl,
|
|
||||||
&(
|
|
||||||
"opnsense_config_xml::data::interfaces",
|
|
||||||
"opnsense_config_xml::data::interfaces",
|
|
||||||
::log::__private_api::loc(),
|
|
||||||
),
|
|
||||||
(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let value = <HashMap<
|
|
||||||
String,
|
|
||||||
Interface,
|
|
||||||
> as ::yaserde::YaDeserialize>::deserialize(reader)?;
|
|
||||||
__interfaces_value = ::std::option::Option::Some(value);
|
|
||||||
let _event = reader.next_event()?;
|
|
||||||
} else {
|
|
||||||
{
|
|
||||||
let lvl = ::log::Level::Warn;
|
|
||||||
if lvl <= ::log::STATIC_MAX_LEVEL
|
|
||||||
&& lvl <= ::log::max_level()
|
|
||||||
{
|
|
||||||
::log::__private_api::log(
|
|
||||||
format_args!(
|
|
||||||
"matching field type did not find substruct start element ? {0}",
|
|
||||||
"HashMap < String, Interface >",
|
|
||||||
),
|
|
||||||
lvl,
|
|
||||||
&(
|
|
||||||
"opnsense_config_xml::data::interfaces",
|
|
||||||
"opnsense_config_xml::data::interfaces",
|
|
||||||
::log::__private_api::loc(),
|
|
||||||
),
|
|
||||||
(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
{
|
|
||||||
let lvl = ::log::Level::Trace;
|
|
||||||
if lvl <= ::log::STATIC_MAX_LEVEL
|
|
||||||
&& lvl <= ::log::max_level()
|
|
||||||
{
|
|
||||||
::log::__private_api::log(
|
|
||||||
format_args!("Got StartElement {0:?}", name.local_name),
|
|
||||||
lvl,
|
|
||||||
&(
|
|
||||||
"yaserde_derive",
|
|
||||||
"opnsense_config_xml::data::interfaces",
|
|
||||||
::log::__private_api::loc(),
|
|
||||||
),
|
|
||||||
(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let event = reader.next_event()?;
|
|
||||||
{
|
|
||||||
let lvl = ::log::Level::Trace;
|
|
||||||
if lvl <= ::log::STATIC_MAX_LEVEL
|
|
||||||
&& lvl <= ::log::max_level()
|
|
||||||
{
|
|
||||||
::log::__private_api::log(
|
|
||||||
format_args!("Next event {0:?}", event),
|
|
||||||
lvl,
|
|
||||||
&(
|
|
||||||
"yaserde_derive",
|
|
||||||
"opnsense_config_xml::data::interfaces",
|
|
||||||
::log::__private_api::loc(),
|
|
||||||
),
|
|
||||||
(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if depth > 0 {
|
|
||||||
return Err(
|
|
||||||
::alloc::__export::must_use({
|
|
||||||
let res = ::alloc::fmt::format(
|
|
||||||
format_args!(
|
|
||||||
"Found unauthorized element {0}",
|
|
||||||
name.local_name,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
res
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
reader.skip_element(|event| {})?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if depth == 0 {}
|
|
||||||
depth += 1;
|
|
||||||
}
|
|
||||||
::yaserde::__xml::reader::XmlEvent::EndElement { ref name } => {
|
|
||||||
{
|
|
||||||
let lvl = ::log::Level::Warn;
|
|
||||||
if lvl <= ::log::STATIC_MAX_LEVEL
|
|
||||||
&& lvl <= ::log::max_level()
|
|
||||||
{
|
|
||||||
::log::__private_api::log(
|
|
||||||
format_args!("endElement {0}", named_element),
|
|
||||||
lvl,
|
|
||||||
&(
|
|
||||||
"opnsense_config_xml::data::interfaces",
|
|
||||||
"opnsense_config_xml::data::interfaces",
|
|
||||||
::log::__private_api::loc(),
|
|
||||||
),
|
|
||||||
(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if name.local_name == named_element
|
|
||||||
&& reader.depth() == start_depth + 1
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
let event = reader.next_event()?;
|
|
||||||
depth -= 1;
|
|
||||||
}
|
|
||||||
::yaserde::__xml::reader::XmlEvent::EndDocument => {
|
|
||||||
if false {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
::yaserde::__xml::reader::XmlEvent::Characters(
|
|
||||||
ref text_content,
|
|
||||||
) => {
|
|
||||||
let event = reader.next_event()?;
|
|
||||||
}
|
|
||||||
event => {
|
|
||||||
return ::std::result::Result::Err(
|
|
||||||
::alloc::__export::must_use({
|
|
||||||
let res = ::alloc::fmt::format(
|
|
||||||
format_args!("unknown event {0:?}", event),
|
|
||||||
);
|
|
||||||
res
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
{
|
|
||||||
let lvl = ::log::Level::Debug;
|
|
||||||
if lvl <= ::log::STATIC_MAX_LEVEL && lvl <= ::log::max_level() {
|
|
||||||
::log::__private_api::log(
|
|
||||||
format_args!(
|
|
||||||
"Struct {0} @ {1}: success",
|
|
||||||
"Interfaces",
|
|
||||||
start_depth,
|
|
||||||
),
|
|
||||||
lvl,
|
|
||||||
&(
|
|
||||||
"yaserde_derive",
|
|
||||||
"opnsense_config_xml::data::interfaces",
|
|
||||||
::log::__private_api::loc(),
|
|
||||||
),
|
|
||||||
(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
::std::result::Result::Ok(Interfaces {
|
|
||||||
testraw: __testraw_value
|
|
||||||
.ok_or_else(|| {
|
|
||||||
"testraw is a required field of Interfaces".to_string()
|
|
||||||
})?,
|
|
||||||
interfaces: __interfaces_value
|
|
||||||
.ok_or_else(|| {
|
|
||||||
"interfaces is a required field of Interfaces".to_string()
|
|
||||||
})?,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
pub struct Interface {
|
pub struct Interface {
|
||||||
#[yaserde(rename = "if")]
|
#[yaserde(rename = "if")]
|
||||||
pub physical_interface_name: String,
|
pub physical_interface_name: String,
|
||||||
|
|||||||
@ -4,12 +4,12 @@ use yaserde::MaybeString;
|
|||||||
|
|
||||||
use super::opnsense::{NumberOption, Range, StaticMap};
|
use super::opnsense::{NumberOption, Range, StaticMap};
|
||||||
|
|
||||||
#[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)]
|
// #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)]
|
||||||
#[yaserde(rename = "dhcpd")]
|
// #[yaserde(rename = "dhcpd")]
|
||||||
pub struct Dhcpd {
|
// pub struct Dhcpd {
|
||||||
#[yaserde(rename = "lan")]
|
// #[yaserde(rename = "lan")]
|
||||||
pub lan: DhcpInterface,
|
// pub lan: DhcpInterface,
|
||||||
}
|
// }
|
||||||
|
|
||||||
#[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)]
|
#[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)]
|
||||||
pub struct DhcpInterface {
|
pub struct DhcpInterface {
|
||||||
|
|||||||
@ -1,65 +1,106 @@
|
|||||||
use yaserde::{NamedList, YaDeserialize as YaDeserializeTrait, YaSerialize as YaSerializeTrait};
|
|
||||||
use yaserde_derive::{YaDeserialize, YaSerialize};
|
use yaserde_derive::{YaDeserialize, YaSerialize};
|
||||||
|
|
||||||
use yaserde::MaybeString;
|
use yaserde::MaybeString;
|
||||||
|
|
||||||
#[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)]
|
|
||||||
pub struct Interfaces {
|
|
||||||
pub interfaces: NamedList<Interface>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Default, PartialEq, Debug, YaDeserialize, YaSerialize)]
|
#[derive(Default, PartialEq, Debug, YaDeserialize, YaSerialize)]
|
||||||
pub struct Interface {
|
pub struct Interface {
|
||||||
|
pub internal_dynamic: Option<MaybeString>,
|
||||||
#[yaserde(rename = "if")]
|
#[yaserde(rename = "if")]
|
||||||
pub physical_interface_name: String,
|
pub physical_interface_name: String,
|
||||||
pub descr: String,
|
pub descr: String,
|
||||||
pub enable: MaybeString,
|
pub enable: MaybeString,
|
||||||
|
pub lock: Option<MaybeString>,
|
||||||
#[yaserde(rename = "spoofmac")]
|
#[yaserde(rename = "spoofmac")]
|
||||||
pub spoof_mac: Option<MaybeString>,
|
pub spoof_mac: Option<MaybeString>,
|
||||||
pub internal_dynamic: Option<MaybeString>,
|
|
||||||
pub ipaddr: Option<MaybeString>,
|
pub ipaddr: Option<MaybeString>,
|
||||||
#[yaserde(rename = "blockpriv")]
|
#[yaserde(rename = "blockpriv")]
|
||||||
pub block_priv: Option<MaybeString>,
|
pub block_priv: Option<MaybeString>,
|
||||||
#[yaserde(rename = "blockbogons")]
|
#[yaserde(rename = "blockbogons")]
|
||||||
pub block_bogons: Option<MaybeString>,
|
pub block_bogons: Option<MaybeString>,
|
||||||
pub lock: Option<MaybeString>,
|
|
||||||
#[yaserde(rename = "type")]
|
#[yaserde(rename = "type")]
|
||||||
pub r#type: Option<MaybeString>,
|
pub r#type: Option<MaybeString>,
|
||||||
#[yaserde(rename = "virtual")]
|
#[yaserde(rename = "virtual")]
|
||||||
pub r#virtual: Option<MaybeString>,
|
pub r#virtual: Option<MaybeString>,
|
||||||
pub subnet: Option<MaybeString>,
|
pub subnet: Option<MaybeString>,
|
||||||
|
pub ipaddrv6: Option<MaybeString>,
|
||||||
pub networks: Option<MaybeString>,
|
pub networks: Option<MaybeString>,
|
||||||
pub subnetv6: Option<MaybeString>,
|
pub subnetv6: Option<MaybeString>,
|
||||||
pub ipaddrv6: Option<MaybeString>,
|
|
||||||
#[yaserde(rename = "track6-interface")]
|
#[yaserde(rename = "track6-interface")]
|
||||||
pub track6_interface: Option<MaybeString>,
|
pub track6_interface: Option<MaybeString>,
|
||||||
#[yaserde(rename = "track6-prefix-id")]
|
#[yaserde(rename = "track6-prefix-id")]
|
||||||
pub track6_prefix_id: Option<MaybeString>,
|
pub track6_prefix_id: Option<MaybeString>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait MyDeserialize: YaDeserializeTrait {}
|
|
||||||
pub trait MySerialize: YaSerializeTrait {}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
|
use crate::xml_utils::to_xml_str;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
|
use yaserde::NamedList;
|
||||||
|
|
||||||
#[derive(Default, PartialEq, Debug, YaDeserialize, YaSerialize)]
|
#[derive(Default, PartialEq, Debug, YaDeserialize, YaSerialize)]
|
||||||
pub struct TestStruct {
|
pub struct InterfacesParent {
|
||||||
foo: String,
|
foo: String,
|
||||||
|
interfaces: NamedList<Interface>,
|
||||||
bar: String,
|
bar: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn should_deserialize_interfaces() {
|
fn should_deserialize_interfaces() {
|
||||||
let test_struct =
|
let interfaces =
|
||||||
yaserde::de::from_str::<TestStruct>("<xml><foo>aodisj</foo><bar>barbaba</bar></xml>")
|
yaserde::de::from_str::<NamedList<Interface>>(FULL_INTERFACES_XML).unwrap();
|
||||||
.unwrap();
|
assert_eq!(interfaces.elements.len(), 6)
|
||||||
println!("test_struct : {:?}", test_struct);
|
}
|
||||||
|
|
||||||
let interfaces = yaserde::de::from_str::<Interfaces>(FULL_INTERFACES_XML).unwrap();
|
#[test]
|
||||||
assert_eq!(interfaces.interfaces.elements.len(), 6)
|
fn should_serialize_interfaces() {
|
||||||
|
let named_list = NamedList {
|
||||||
|
elements: vec![
|
||||||
|
(String::from("paul"), Interface::default()),
|
||||||
|
(String::from("anotherpaul"), Interface::default()),
|
||||||
|
(String::from("thirdone"), Interface::default()),
|
||||||
|
(String::from("andgofor4"), Interface::default()),
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
let parent = InterfacesParent {
|
||||||
|
foo: String::from("foo"),
|
||||||
|
interfaces: named_list,
|
||||||
|
bar: String::from("foo"),
|
||||||
|
};
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
&to_xml_str(&parent).unwrap(),
|
||||||
|
r#"<?xml version="1.0"?>
|
||||||
|
<InterfacesParent>
|
||||||
|
<foo>foo</foo>
|
||||||
|
<interfaces>
|
||||||
|
<paul>
|
||||||
|
<if></if>
|
||||||
|
<descr></descr>
|
||||||
|
<enable/>
|
||||||
|
</paul>
|
||||||
|
<anotherpaul>
|
||||||
|
<if></if>
|
||||||
|
<descr></descr>
|
||||||
|
<enable/>
|
||||||
|
</anotherpaul>
|
||||||
|
<thirdone>
|
||||||
|
<if></if>
|
||||||
|
<descr></descr>
|
||||||
|
<enable/>
|
||||||
|
</thirdone>
|
||||||
|
<andgofor4>
|
||||||
|
<if></if>
|
||||||
|
<descr></descr>
|
||||||
|
<enable/>
|
||||||
|
</andgofor4>
|
||||||
|
</interfaces>
|
||||||
|
<bar>foo</bar>
|
||||||
|
</InterfacesParent>
|
||||||
|
"#
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const FULL_INTERFACES_XML: &str = "<interfaces>
|
const FULL_INTERFACES_XML: &str = "<interfaces>
|
||||||
|
|||||||
@ -1,23 +1,9 @@
|
|||||||
use crate::data::dhcpd::Dhcpd;
|
use crate::{data::dhcpd::DhcpInterface, xml_utils::to_xml_str};
|
||||||
use yaserde::{MaybeString, RawXml};
|
|
||||||
use log::error;
|
use log::error;
|
||||||
|
use yaserde::{MaybeString, NamedList, RawXml};
|
||||||
use yaserde_derive::{YaDeserialize, YaSerialize};
|
use yaserde_derive::{YaDeserialize, YaSerialize};
|
||||||
|
|
||||||
impl From<String> for OPNsense {
|
use super::Interface;
|
||||||
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")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)]
|
#[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)]
|
||||||
#[yaserde(rename = "opnsense")]
|
#[yaserde(rename = "opnsense")]
|
||||||
@ -25,8 +11,9 @@ pub struct OPNsense {
|
|||||||
pub theme: String,
|
pub theme: String,
|
||||||
pub sysctl: Sysctl,
|
pub sysctl: Sysctl,
|
||||||
pub system: RawXml,
|
pub system: RawXml,
|
||||||
pub interfaces: RawXml,
|
// pub interfaces: RawXml,
|
||||||
pub dhcpd: Dhcpd,
|
pub interfaces: NamedList<Interface>,
|
||||||
|
pub dhcpd: NamedList<DhcpInterface>,
|
||||||
pub snmpd: Snmpd,
|
pub snmpd: Snmpd,
|
||||||
pub syslog: Syslog,
|
pub syslog: Syslog,
|
||||||
pub nat: Nat,
|
pub nat: Nat,
|
||||||
@ -56,6 +43,23 @@ pub struct OPNsense {
|
|||||||
pub ifgroups: Ifgroups,
|
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)]
|
#[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)]
|
||||||
pub struct LoadBalancer {
|
pub struct LoadBalancer {
|
||||||
pub monitor_type: Vec<MonitorType>,
|
pub monitor_type: Vec<MonitorType>,
|
||||||
@ -945,6 +949,7 @@ pub struct Acl {
|
|||||||
pub browser: MaybeString,
|
pub browser: MaybeString,
|
||||||
#[yaserde(rename = "mimeType")]
|
#[yaserde(rename = "mimeType")]
|
||||||
pub mime_type: MaybeString,
|
pub mime_type: MaybeString,
|
||||||
|
#[yaserde(rename = "googleapps")]
|
||||||
pub google_apps: MaybeString,
|
pub google_apps: MaybeString,
|
||||||
pub youtube: MaybeString,
|
pub youtube: MaybeString,
|
||||||
#[yaserde(rename = "safePorts")]
|
#[yaserde(rename = "safePorts")]
|
||||||
|
|||||||
@ -1,256 +0,0 @@
|
|||||||
use xml::reader::XmlEvent as ReadEvent;
|
|
||||||
use yaserde::{ser, YaDeserialize as YaDeserializeTrait, YaSerialize as YaSerializeTrait};
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Default)]
|
|
||||||
pub struct RawXml(String);
|
|
||||||
|
|
||||||
impl YaDeserializeTrait for RawXml {
|
|
||||||
fn deserialize<R: std::io::Read>(
|
|
||||||
reader: &mut yaserde::de::Deserializer<R>,
|
|
||||||
) -> Result<Self, String> {
|
|
||||||
let mut buffer = String::new();
|
|
||||||
let mut depth = 0;
|
|
||||||
|
|
||||||
let own_name = match reader.peek()? {
|
|
||||||
ReadEvent::StartElement { name, .. } => name.local_name.clone(),
|
|
||||||
_ => return Err("RawXml Should start deserializing with StartElement".to_string()),
|
|
||||||
};
|
|
||||||
println!("RawXml deserialize from root element name : {own_name}");
|
|
||||||
loop {
|
|
||||||
let current_event = reader.peek()?.to_owned();
|
|
||||||
match current_event.clone() {
|
|
||||||
ReadEvent::StartElement {
|
|
||||||
name, attributes, ..
|
|
||||||
} => {
|
|
||||||
println!("StartElement {name} depth {depth}");
|
|
||||||
depth += 1;
|
|
||||||
let mut attr_string = String::new();
|
|
||||||
attributes.iter().for_each(|a| {
|
|
||||||
attr_string.push_str(&format!(r#" {}="{}""#, &a.name, &a.value));
|
|
||||||
});
|
|
||||||
buffer.push_str(&format!("<{}{}>", name, attr_string));
|
|
||||||
let _event = reader.next_event()?;
|
|
||||||
}
|
|
||||||
ReadEvent::EndElement { name } => {
|
|
||||||
println!("EndElement {name} depth {depth}");
|
|
||||||
depth -= 1;
|
|
||||||
buffer.push_str(&format!("</{}>", name));
|
|
||||||
println!(
|
|
||||||
"Checking if name.local_name {} matches own_name {} at depth {depth}",
|
|
||||||
&name.local_name, &own_name
|
|
||||||
);
|
|
||||||
if name.local_name == own_name && depth == 0 {
|
|
||||||
println!(
|
|
||||||
"Found next EndElement is closing my struct, breaking out of loop"
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
let _event = reader.next_event()?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ReadEvent::Characters(content) => {
|
|
||||||
println!("Characters {content} depth {depth}");
|
|
||||||
buffer.push_str(&content);
|
|
||||||
let _event = reader.next_event()?;
|
|
||||||
}
|
|
||||||
ReadEvent::StartDocument {
|
|
||||||
version,
|
|
||||||
encoding,
|
|
||||||
standalone,
|
|
||||||
} => todo!(
|
|
||||||
"StartDocument {:?} {:?} {:?}",
|
|
||||||
version,
|
|
||||||
encoding,
|
|
||||||
standalone
|
|
||||||
),
|
|
||||||
ReadEvent::EndDocument => todo!(),
|
|
||||||
ReadEvent::ProcessingInstruction { name, data } => {
|
|
||||||
todo!("ProcessingInstruction {:?}, {:?}", name, data)
|
|
||||||
}
|
|
||||||
ReadEvent::CData(cdata) => todo!("CData, {:?}", cdata),
|
|
||||||
ReadEvent::Comment(comment) => todo!("Comment, {:?}", comment),
|
|
||||||
ReadEvent::Whitespace(whitespace) => todo!("Whitespace, {:?}", whitespace),
|
|
||||||
}
|
|
||||||
let next = reader.peek()?;
|
|
||||||
println!(
|
|
||||||
"Processing done on \ncurrent_event : {:?} \nnext : {:?}",
|
|
||||||
¤t_event, &next
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
println!("buffered events {buffer}");
|
|
||||||
let next = reader.peek()?;
|
|
||||||
println!("next : {:?}", &next);
|
|
||||||
|
|
||||||
Ok(RawXml(buffer))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl YaSerializeTrait for RawXml {
|
|
||||||
fn serialize<W: std::io::Write>(&self, writer: &mut ser::Serializer<W>) -> Result<(), String> {
|
|
||||||
let content = self.0.clone();
|
|
||||||
let content = xml::EventReader::from_str(content.as_str());
|
|
||||||
let mut reader = yaserde::de::Deserializer::new(content);
|
|
||||||
loop {
|
|
||||||
let e = reader.next_event()?;
|
|
||||||
if let ReadEvent::EndDocument = e {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
writer
|
|
||||||
.write(e.as_writer_event().unwrap())
|
|
||||||
.expect("Writer should write write event");
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn serialize_attributes(
|
|
||||||
&self,
|
|
||||||
attributes: Vec<xml::attribute::OwnedAttribute>,
|
|
||||||
namespace: xml::namespace::Namespace,
|
|
||||||
) -> Result<
|
|
||||||
(
|
|
||||||
Vec<xml::attribute::OwnedAttribute>,
|
|
||||||
xml::namespace::Namespace,
|
|
||||||
),
|
|
||||||
String,
|
|
||||||
> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod test {
|
|
||||||
use crate::xml_utils::to_xml_str;
|
|
||||||
|
|
||||||
use super::*;
|
|
||||||
use pretty_assertions::assert_eq;
|
|
||||||
use yaserde_derive::YaDeserialize;
|
|
||||||
use yaserde_derive::YaSerialize;
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Default, YaDeserialize)]
|
|
||||||
pub struct Parent {
|
|
||||||
// pub rawxml_child: RawXml,
|
|
||||||
pub string_child: String,
|
|
||||||
pub child_child: Child,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Default, YaDeserialize)]
|
|
||||||
pub struct Child {
|
|
||||||
pub child_val: String,
|
|
||||||
pub child_val2: String,
|
|
||||||
pub child_option: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn rawxml_should_buffer_empty_element() {
|
|
||||||
let rawxml: RawXml = yaserde::de::from_str("<something/>").unwrap();
|
|
||||||
assert_eq!(rawxml.0, String::from("<something></something>"));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn rawxml_should_buffer_elements_with_different_case_as_they_are() {
|
|
||||||
let xml = "<xml><Some_thing></Some_thing><something></something></xml>";
|
|
||||||
let rawxml: RawXml = yaserde::de::from_str(xml).unwrap();
|
|
||||||
assert_eq!(rawxml.0, String::from(xml));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn rawxml_should_buffer_elements_with_attributes() {
|
|
||||||
let xml = r#"<xml version="ababa"><Some_thing></Some_thing><something></something></xml>"#;
|
|
||||||
let rawxml: RawXml = yaserde::de::from_str(xml).unwrap();
|
|
||||||
assert_eq!(rawxml.0, String::from(xml));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn rawxml_should_handle_complex_documents() {
|
|
||||||
let xml = r#"<xml><OpenVPN version="1.0.0"><Overwrites></Overwrites><Instances></Instances><StaticKeys></StaticKeys></OpenVPN><Gateways version="0.0.1"></Gateways><HAProxy version="4.0.0"><general><enabled>1</enabled><gracefulStop>0</gracefulStop><hardStopAfter>60s</hardStopAfter><closeSpreadTime></closeSpreadTime><seamlessReload>0</seamlessReload><storeOcsp>0</storeOcsp><showIntro>1</showIntro><peers><enabled>0</enabled><name1></name1><listen1></listen1><port1>1024</port1><name2></name2><listen2></listen2><port2>1024</port2></peers><tuning><root>0</root><maxConnections></maxConnections><nbthread>1</nbthread><sslServerVerify>ignore</sslServerVerify><maxDHSize>2048</maxDHSize><bufferSize>16384</bufferSize></tuning></general></HAProxy></xml>"#;
|
|
||||||
let rawxml: RawXml = yaserde::de::from_str(xml).unwrap();
|
|
||||||
assert_eq!(rawxml.0, String::from(xml));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn rawxml_should_serialize_simple_documents() {
|
|
||||||
let xml = r#"<?xml version="1.0" encoding="utf-8"?><xml />"#;
|
|
||||||
let rawxml: RawXml = yaserde::de::from_str(xml).unwrap();
|
|
||||||
assert_eq!(yaserde::ser::to_string(&rawxml).unwrap(), xml);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn rawxml_should_serialize_complex_documents() {
|
|
||||||
let xml = r#"<?xml version="1.0"?>
|
|
||||||
<xml>
|
|
||||||
<OpenVPN version="1.0.0">
|
|
||||||
<Overwrites/>
|
|
||||||
<Instances/>
|
|
||||||
<StaticKeys/>
|
|
||||||
</OpenVPN>
|
|
||||||
<Gateways version="0.0.1"/>
|
|
||||||
<HAProxy version="4.0.0">
|
|
||||||
<general>
|
|
||||||
<enabled>1</enabled>
|
|
||||||
<gracefulStop>0</gracefulStop>
|
|
||||||
<hardStopAfter>60s</hardStopAfter>
|
|
||||||
<closeSpreadTime/>
|
|
||||||
<seamlessReload>0</seamlessReload>
|
|
||||||
<storeOcsp>0</storeOcsp>
|
|
||||||
<showIntro>1</showIntro>
|
|
||||||
<peers>
|
|
||||||
<enabled>0</enabled>
|
|
||||||
<name1/>
|
|
||||||
<listen1/>
|
|
||||||
<port1>1024</port1>
|
|
||||||
<name2/>
|
|
||||||
<listen2/>
|
|
||||||
<port2>1024</port2>
|
|
||||||
</peers>
|
|
||||||
<tuning>
|
|
||||||
<root>0</root>
|
|
||||||
<maxConnections/>
|
|
||||||
<nbthread>1</nbthread>
|
|
||||||
<sslServerVerify>ignore</sslServerVerify>
|
|
||||||
<maxDHSize>2048</maxDHSize>
|
|
||||||
<bufferSize>16384</bufferSize>
|
|
||||||
</tuning>
|
|
||||||
</general>
|
|
||||||
</HAProxy>
|
|
||||||
</xml>
|
|
||||||
"#;
|
|
||||||
let rawxml: RawXml = yaserde::de::from_str(xml).unwrap();
|
|
||||||
assert_eq!(to_xml_str(&rawxml).unwrap(), xml);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn rawxml_should_allow_siblings_before() {
|
|
||||||
#[derive(YaDeserialize, YaSerialize)]
|
|
||||||
struct Config {
|
|
||||||
paul: Vec<String>,
|
|
||||||
raw: RawXml,
|
|
||||||
}
|
|
||||||
let xml = r#"<?xml version="1.0" encoding="utf-8"?><Config><paul>bobob</paul><paul>patate</paul><raw>allo something</raw></Config>"#;
|
|
||||||
let config: Config = yaserde::de::from_str(xml).unwrap();
|
|
||||||
assert_eq!(yaserde::ser::to_string(&config).unwrap(), xml);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn rawxml_should_allow_siblings_after() {
|
|
||||||
#[derive(YaDeserialize, YaSerialize)]
|
|
||||||
struct Config {
|
|
||||||
raw: RawXml,
|
|
||||||
paul: Vec<String>,
|
|
||||||
}
|
|
||||||
let xml = r#"<?xml version="1.0" encoding="utf-8"?><Config><raw>allo something</raw><paul>bobob</paul><paul>patate</paul></Config>"#;
|
|
||||||
let config: Config = yaserde::de::from_str(xml).unwrap();
|
|
||||||
assert_eq!(config.paul.get(0).unwrap(), "bobob");
|
|
||||||
assert_eq!(config.paul.get(1).unwrap(), "patate");
|
|
||||||
assert_eq!(config.paul.len(), 2);
|
|
||||||
assert_eq!(config.raw.0, "<raw>allo something</raw>");
|
|
||||||
assert_eq!(yaserde::ser::to_string(&config).unwrap(), xml);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn rawxml_should_allow_being_end_of_document() {
|
|
||||||
let xml = r#"<?xml version="1.0" encoding="utf-8"?><Config><raw>allo something</raw><paul>bobob</paul><paul>patate</paul></Config>"#;
|
|
||||||
let config: RawXml = yaserde::de::from_str(xml).unwrap();
|
|
||||||
assert_eq!(yaserde::ser::to_string(&config).unwrap(), xml);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,173 +0,0 @@
|
|||||||
use xml::reader::XmlEvent as ReadEvent;
|
|
||||||
use xml::writer::XmlEvent as WriteEvent;
|
|
||||||
use yaserde::{ser, YaDeserialize as YaDeserializeTrait, YaSerialize as YaSerializeTrait};
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Default)]
|
|
||||||
pub struct MaybeString {
|
|
||||||
field_name: String,
|
|
||||||
content: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl YaDeserializeTrait for MaybeString {
|
|
||||||
fn deserialize<R: std::io::Read>(
|
|
||||||
reader: &mut yaserde::de::Deserializer<R>,
|
|
||||||
) -> Result<Self, String> {
|
|
||||||
let field_name = match reader.peek()? {
|
|
||||||
ReadEvent::StartElement {
|
|
||||||
name, attributes, ..
|
|
||||||
} => {
|
|
||||||
if attributes.len() > 0 {
|
|
||||||
return Err(String::from(
|
|
||||||
"Attributes not currently supported by MaybeString",
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
name.local_name.clone()
|
|
||||||
}
|
|
||||||
_ => return Err(String::from("Unsupporte ReadEvent type")),
|
|
||||||
};
|
|
||||||
reader.next_event()?;
|
|
||||||
|
|
||||||
let content = match reader.peek()? {
|
|
||||||
ReadEvent::Characters(content) => Some(content.clone()),
|
|
||||||
ReadEvent::EndElement { name } => {
|
|
||||||
if name.local_name != field_name {
|
|
||||||
return Err(format!(
|
|
||||||
"Invalid EndElement, expected {field_name} but got {}",
|
|
||||||
name.local_name
|
|
||||||
));
|
|
||||||
}
|
|
||||||
None
|
|
||||||
}
|
|
||||||
_ => return Err(String::from("Unsupporte ReadEvent type")),
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(Self {
|
|
||||||
field_name,
|
|
||||||
content,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl YaSerializeTrait for MaybeString {
|
|
||||||
fn serialize<W: std::io::Write>(&self, writer: &mut ser::Serializer<W>) -> Result<(), String> {
|
|
||||||
let start_element_event = WriteEvent::start_element(self.field_name.as_str());
|
|
||||||
writer.write(start_element_event).expect("Writer failed");
|
|
||||||
match &self.content {
|
|
||||||
Some(content) => {
|
|
||||||
writer
|
|
||||||
.write(WriteEvent::characters(content))
|
|
||||||
.expect("Writer failed");
|
|
||||||
}
|
|
||||||
None => {}
|
|
||||||
};
|
|
||||||
|
|
||||||
writer
|
|
||||||
.write(WriteEvent::end_element())
|
|
||||||
.expect("Writer failed");
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn serialize_attributes(
|
|
||||||
&self,
|
|
||||||
_attributes: Vec<xml::attribute::OwnedAttribute>,
|
|
||||||
_namespace: xml::namespace::Namespace,
|
|
||||||
) -> Result<
|
|
||||||
(
|
|
||||||
Vec<xml::attribute::OwnedAttribute>,
|
|
||||||
xml::namespace::Namespace,
|
|
||||||
),
|
|
||||||
String,
|
|
||||||
> {
|
|
||||||
unimplemented!("MaybeString does not currently support attributes")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod test {
|
|
||||||
use super::*;
|
|
||||||
use pretty_assertions::assert_eq;
|
|
||||||
use yaserde_derive::YaDeserialize;
|
|
||||||
use yaserde_derive::YaSerialize;
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Default, YaDeserialize, YaSerialize)]
|
|
||||||
struct TestStruct {
|
|
||||||
maybe: MaybeString,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn maybe_string_should_deserialize_empty_element() {
|
|
||||||
let initial_xml = "<struct><maybe/></struct>";
|
|
||||||
let test_struct: TestStruct =
|
|
||||||
yaserde::de::from_str(initial_xml).expect("Shoudl deserialize teststruct");
|
|
||||||
println!("Got test_struct {:?}", test_struct);
|
|
||||||
assert_eq!(
|
|
||||||
test_struct,
|
|
||||||
TestStruct {
|
|
||||||
maybe: MaybeString {
|
|
||||||
field_name: String::from("maybe"),
|
|
||||||
content: None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn maybe_string_should_deserialize_content() {
|
|
||||||
let initial_xml = "<struct><maybe>some content</maybe></struct>";
|
|
||||||
let test_struct: TestStruct =
|
|
||||||
yaserde::de::from_str(initial_xml).expect("Shoudl deserialize teststruct");
|
|
||||||
println!("Got test_struct {:?}", test_struct);
|
|
||||||
assert_eq!(
|
|
||||||
test_struct,
|
|
||||||
TestStruct {
|
|
||||||
maybe: MaybeString {
|
|
||||||
field_name: String::from("maybe"),
|
|
||||||
content: Some(String::from("some content"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn maybe_string_should_deserialize_empty_long_format() {
|
|
||||||
let initial_xml = "<struct><maybe></maybe></struct>";
|
|
||||||
let test_struct: TestStruct =
|
|
||||||
yaserde::de::from_str(initial_xml).expect("Shoudl deserialize teststruct");
|
|
||||||
println!("Got test_struct {:?}", test_struct);
|
|
||||||
assert_eq!(
|
|
||||||
test_struct,
|
|
||||||
TestStruct {
|
|
||||||
maybe: MaybeString {
|
|
||||||
field_name: String::from("maybe"),
|
|
||||||
content: None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn maybe_string_should_serialize_to_empty_element() {
|
|
||||||
let initial_xml =
|
|
||||||
r#"<?xml version="1.0" encoding="utf-8"?><TestStruct><maybe /></TestStruct>"#;
|
|
||||||
let test_struct: TestStruct =
|
|
||||||
yaserde::de::from_str(initial_xml).expect("Shoudl deserialize teststruct");
|
|
||||||
println!("Got test_struct {:?}", test_struct);
|
|
||||||
assert_eq!(
|
|
||||||
yaserde::ser::to_string(&test_struct).expect("should serialize teststruct"),
|
|
||||||
initial_xml
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn maybe_string_should_serialize_content() {
|
|
||||||
let initial_xml = r#"<?xml version="1.0" encoding="utf-8"?><TestStruct><maybe>some content</maybe></TestStruct>"#;
|
|
||||||
let test_struct: TestStruct =
|
|
||||||
yaserde::de::from_str(initial_xml).expect("Shoudl deserialize teststruct");
|
|
||||||
println!("Got test_struct {:?}", test_struct);
|
|
||||||
assert_eq!(
|
|
||||||
yaserde::ser::to_string(&test_struct).expect("should serialize teststruct"),
|
|
||||||
initial_xml
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,6 +1,20 @@
|
|||||||
//mod generic_xml;
|
use yaserde::YaSerialize;
|
||||||
//mod maybe_string;
|
|
||||||
mod yaserde;
|
pub fn to_xml_str<T: YaSerialize>(model: &T) -> Result<String, String> {
|
||||||
//pub use generic_xml::*;
|
let yaserde_cfg = yaserde::ser::Config {
|
||||||
//pub use maybe_string::*;
|
perform_indent: true,
|
||||||
pub use yaserde::*;
|
write_document_declaration: false,
|
||||||
|
pad_self_closing: false,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
let serialized = yaserde::ser::to_string_with_config::<T>(model, &yaserde_cfg)?;
|
||||||
|
|
||||||
|
// Opnsense does not specify encoding in the document declaration
|
||||||
|
//
|
||||||
|
// yaserde / xml-rs does not allow disabling the encoding attribute in the
|
||||||
|
// document declaration
|
||||||
|
//
|
||||||
|
// So here we just manually prefix the xml document with the exact document declaration
|
||||||
|
// that opnsense uses
|
||||||
|
Ok(format!("<?xml version=\"1.0\"?>\n{serialized}\n"))
|
||||||
|
}
|
||||||
|
|||||||
@ -1,20 +0,0 @@
|
|||||||
use yaserde::YaSerialize;
|
|
||||||
|
|
||||||
pub fn to_xml_str<T: YaSerialize>(model: &T) -> Result<String, String> {
|
|
||||||
let yaserde_cfg = yaserde::ser::Config {
|
|
||||||
perform_indent: true,
|
|
||||||
write_document_declaration: false,
|
|
||||||
pad_self_closing: false,
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
let serialized = yaserde::ser::to_string_with_config::<T>(model, &yaserde_cfg)?;
|
|
||||||
|
|
||||||
// Opnsense does not specify encoding in the document declaration
|
|
||||||
//
|
|
||||||
// yaserde / xml-rs does not allow disabling the encoding attribute in the
|
|
||||||
// document declaration
|
|
||||||
//
|
|
||||||
// So here we just manually prefix the xml document with the exact document declaration
|
|
||||||
// that opnsense uses
|
|
||||||
Ok(format!("<?xml version=\"1.0\"?>\n{serialized}\n"))
|
|
||||||
}
|
|
||||||
@ -170,9 +170,11 @@ impl Config {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use crate::modules::dhcp::DhcpConfig;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use std::path::PathBuf;
|
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_load_config_from_local_file() {
|
async fn test_load_config_from_local_file() {
|
||||||
@ -199,23 +201,31 @@ mod tests {
|
|||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_add_dhcpd_static_entry() {
|
async fn test_add_dhcpd_static_entry() {
|
||||||
let mut test_file_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
let mut test_file_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||||
test_file_path.push("src/tests/data/config-full-1.xml");
|
test_file_path.push("src/tests/data/config-structure.xml");
|
||||||
|
|
||||||
let config_file_path = test_file_path.to_str().unwrap().to_string();
|
let config_file_path = test_file_path.to_str().unwrap().to_string();
|
||||||
println!("File path {config_file_path}");
|
println!("File path {config_file_path}");
|
||||||
let repository = Box::new(LocalFileConfigRepository::new(config_file_path));
|
let repository = Box::new(LocalFileConfigRepository::new(config_file_path));
|
||||||
let config_file_str = repository.load().await.unwrap();
|
|
||||||
let mut config = Config::new(repository)
|
let mut config = Config::new(repository)
|
||||||
.await
|
.await
|
||||||
.expect("Failed to load config");
|
.expect("Failed to load config");
|
||||||
|
|
||||||
println!("Config {:?}", config);
|
println!("Config {:?}", config);
|
||||||
|
|
||||||
|
let mut dhcp_config = DhcpConfig::new(&mut config.opnsense);
|
||||||
|
dhcp_config.add_static_mapping("00:00:00:00:00:00", Ipv4Addr::new(192,168,20,100), "hostname").expect("Should add static mapping");
|
||||||
|
|
||||||
let serialized = config.opnsense.to_xml();
|
let serialized = config.opnsense.to_xml();
|
||||||
|
|
||||||
fs::write("/tmp/serialized.xml", &serialized).unwrap();
|
fs::write("/tmp/serialized.xml", &serialized).unwrap();
|
||||||
|
|
||||||
assert_eq!(config_file_str, serialized);
|
let mut test_file_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||||
todo!();
|
test_file_path.push("src/tests/data/config-structure-with-dhcp-staticmap-entry.xml");
|
||||||
|
|
||||||
|
let config_file_path = test_file_path.to_str().unwrap().to_string();
|
||||||
|
println!("File path {config_file_path}");
|
||||||
|
let repository = Box::new(LocalFileConfigRepository::new(config_file_path));
|
||||||
|
let expected_config_file_str = repository.load().await.unwrap();
|
||||||
|
assert_eq!(expected_config_file_str, serialized);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -51,7 +51,16 @@ impl<'a> DhcpConfig<'a> {
|
|||||||
) -> Result<(), DhcpError> {
|
) -> Result<(), DhcpError> {
|
||||||
let mac = mac.to_string();
|
let mac = mac.to_string();
|
||||||
let hostname = hostname.to_string();
|
let hostname = hostname.to_string();
|
||||||
let range = &self.opnsense.dhcpd.lan.range;
|
let lan_dhcpd = &mut self
|
||||||
|
.opnsense
|
||||||
|
.dhcpd
|
||||||
|
.elements
|
||||||
|
.iter_mut()
|
||||||
|
.find(|(name, _config)| return name == "lan")
|
||||||
|
.expect("Interface lan should have dhcpd activated")
|
||||||
|
.1;
|
||||||
|
|
||||||
|
let range = &lan_dhcpd.range;
|
||||||
|
|
||||||
if !Self::is_valid_mac(&mac) {
|
if !Self::is_valid_mac(&mac) {
|
||||||
return Err(DhcpError::InvalidMacAddress(mac));
|
return Err(DhcpError::InvalidMacAddress(mac));
|
||||||
@ -61,7 +70,7 @@ impl<'a> DhcpConfig<'a> {
|
|||||||
return Err(DhcpError::IpAddressOutOfRange(ipaddr.to_string()));
|
return Err(DhcpError::IpAddressOutOfRange(ipaddr.to_string()));
|
||||||
}
|
}
|
||||||
|
|
||||||
let existing_mappings = &self.opnsense.dhcpd.lan.staticmaps;
|
let existing_mappings: &mut Vec<StaticMap> = &mut lan_dhcpd.staticmaps;
|
||||||
|
|
||||||
if existing_mappings.iter().any(|m| {
|
if existing_mappings.iter().any(|m| {
|
||||||
m.ipaddr
|
m.ipaddr
|
||||||
@ -86,14 +95,10 @@ impl<'a> DhcpConfig<'a> {
|
|||||||
ntpserver: Default::default(),
|
ntpserver: Default::default(),
|
||||||
};
|
};
|
||||||
|
|
||||||
self.opnsense.dhcpd.lan.staticmaps.push(static_map);
|
existing_mappings.push(static_map);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_static_mappings(&self) -> &[StaticMap] {
|
|
||||||
&self.opnsense.dhcpd.lan.staticmaps
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_valid_mac(mac: &str) -> bool {
|
fn is_valid_mac(mac: &str) -> bool {
|
||||||
let parts: Vec<&str> = mac.split(':').collect();
|
let parts: Vec<&str> = mac.split(':').collect();
|
||||||
if parts.len() != 6 {
|
if parts.len() != 6 {
|
||||||
@ -158,5 +163,4 @@ mod test {
|
|||||||
let ip = "192.168.1.201".parse::<Ipv4Addr>().unwrap();
|
let ip = "192.168.1.201".parse::<Ipv4Addr>().unwrap();
|
||||||
assert_eq!(DhcpConfig::is_ip_in_range(&ip, &range), false);
|
assert_eq!(DhcpConfig::is_ip_in_range(&ip, &range), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -320,9 +320,9 @@
|
|||||||
<enable>1</enable>
|
<enable>1</enable>
|
||||||
<lock>1</lock>
|
<lock>1</lock>
|
||||||
<spoofmac/>
|
<spoofmac/>
|
||||||
|
<ipaddr>pppoe</ipaddr>
|
||||||
<blockpriv>1</blockpriv>
|
<blockpriv>1</blockpriv>
|
||||||
<blockbogons>1</blockbogons>
|
<blockbogons>1</blockbogons>
|
||||||
<ipaddr>pppoe</ipaddr>
|
|
||||||
</wan>
|
</wan>
|
||||||
<lan>
|
<lan>
|
||||||
<if>em1</if>
|
<if>em1</if>
|
||||||
@ -337,15 +337,15 @@
|
|||||||
</lan>
|
</lan>
|
||||||
<lo0>
|
<lo0>
|
||||||
<internal_dynamic>1</internal_dynamic>
|
<internal_dynamic>1</internal_dynamic>
|
||||||
|
<if>lo0</if>
|
||||||
<descr>Loopback</descr>
|
<descr>Loopback</descr>
|
||||||
<enable>1</enable>
|
<enable>1</enable>
|
||||||
<if>lo0</if>
|
|
||||||
<ipaddr>127.0.0.1</ipaddr>
|
<ipaddr>127.0.0.1</ipaddr>
|
||||||
<ipaddrv6>::1</ipaddrv6>
|
|
||||||
<subnet>8</subnet>
|
|
||||||
<subnetv6>128</subnetv6>
|
|
||||||
<type>none</type>
|
<type>none</type>
|
||||||
<virtual>1</virtual>
|
<virtual>1</virtual>
|
||||||
|
<subnet>8</subnet>
|
||||||
|
<ipaddrv6>::1</ipaddrv6>
|
||||||
|
<subnetv6>128</subnetv6>
|
||||||
</lo0>
|
</lo0>
|
||||||
<opt1>
|
<opt1>
|
||||||
<if>em5</if>
|
<if>em5</if>
|
||||||
@ -358,18 +358,18 @@
|
|||||||
</opt1>
|
</opt1>
|
||||||
<wireguard>
|
<wireguard>
|
||||||
<internal_dynamic>1</internal_dynamic>
|
<internal_dynamic>1</internal_dynamic>
|
||||||
<descr>WireGuard (Group)</descr>
|
|
||||||
<if>wireguard</if>
|
<if>wireguard</if>
|
||||||
<virtual>1</virtual>
|
<descr>WireGuard (Group)</descr>
|
||||||
<enable>1</enable>
|
<enable>1</enable>
|
||||||
<type>group</type>
|
<type>group</type>
|
||||||
|
<virtual>1</virtual>
|
||||||
<networks/>
|
<networks/>
|
||||||
</wireguard>
|
</wireguard>
|
||||||
<openvpn>
|
<openvpn>
|
||||||
<internal_dynamic>1</internal_dynamic>
|
<internal_dynamic>1</internal_dynamic>
|
||||||
<enable>1</enable>
|
|
||||||
<if>openvpn</if>
|
<if>openvpn</if>
|
||||||
<descr>OpenVPN</descr>
|
<descr>OpenVPN</descr>
|
||||||
|
<enable>1</enable>
|
||||||
<type>group</type>
|
<type>group</type>
|
||||||
<virtual>1</virtual>
|
<virtual>1</virtual>
|
||||||
<networks/>
|
<networks/>
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -132,9 +132,9 @@
|
|||||||
<enable>1</enable>
|
<enable>1</enable>
|
||||||
<lock>1</lock>
|
<lock>1</lock>
|
||||||
<spoofmac/>
|
<spoofmac/>
|
||||||
|
<ipaddr>pppoe</ipaddr>
|
||||||
<blockpriv>1</blockpriv>
|
<blockpriv>1</blockpriv>
|
||||||
<blockbogons>1</blockbogons>
|
<blockbogons>1</blockbogons>
|
||||||
<ipaddr>pppoe</ipaddr>
|
|
||||||
</wan>
|
</wan>
|
||||||
<lan>
|
<lan>
|
||||||
<if>em1</if>
|
<if>em1</if>
|
||||||
@ -149,15 +149,15 @@
|
|||||||
</lan>
|
</lan>
|
||||||
<lo0>
|
<lo0>
|
||||||
<internal_dynamic>1</internal_dynamic>
|
<internal_dynamic>1</internal_dynamic>
|
||||||
|
<if>lo0</if>
|
||||||
<descr>Loopback</descr>
|
<descr>Loopback</descr>
|
||||||
<enable>1</enable>
|
<enable>1</enable>
|
||||||
<if>lo0</if>
|
|
||||||
<ipaddr>127.0.0.1</ipaddr>
|
<ipaddr>127.0.0.1</ipaddr>
|
||||||
<ipaddrv6>::1</ipaddrv6>
|
|
||||||
<subnet>8</subnet>
|
|
||||||
<subnetv6>128</subnetv6>
|
|
||||||
<type>none</type>
|
<type>none</type>
|
||||||
<virtual>1</virtual>
|
<virtual>1</virtual>
|
||||||
|
<subnet>8</subnet>
|
||||||
|
<ipaddrv6>::1</ipaddrv6>
|
||||||
|
<subnetv6>128</subnetv6>
|
||||||
</lo0>
|
</lo0>
|
||||||
<opt1>
|
<opt1>
|
||||||
<if>em5</if>
|
<if>em5</if>
|
||||||
@ -170,18 +170,18 @@
|
|||||||
</opt1>
|
</opt1>
|
||||||
<wireguard>
|
<wireguard>
|
||||||
<internal_dynamic>1</internal_dynamic>
|
<internal_dynamic>1</internal_dynamic>
|
||||||
<descr>WireGuard (Group)</descr>
|
|
||||||
<if>wireguard</if>
|
<if>wireguard</if>
|
||||||
<virtual>1</virtual>
|
<descr>WireGuard (Group)</descr>
|
||||||
<enable>1</enable>
|
<enable>1</enable>
|
||||||
<type>group</type>
|
<type>group</type>
|
||||||
|
<virtual>1</virtual>
|
||||||
<networks/>
|
<networks/>
|
||||||
</wireguard>
|
</wireguard>
|
||||||
<openvpn>
|
<openvpn>
|
||||||
<internal_dynamic>1</internal_dynamic>
|
<internal_dynamic>1</internal_dynamic>
|
||||||
<enable>1</enable>
|
|
||||||
<if>openvpn</if>
|
<if>openvpn</if>
|
||||||
<descr>OpenVPN</descr>
|
<descr>OpenVPN</descr>
|
||||||
|
<enable>1</enable>
|
||||||
<type>group</type>
|
<type>group</type>
|
||||||
<virtual>1</virtual>
|
<virtual>1</virtual>
|
||||||
<networks/>
|
<networks/>
|
||||||
@ -337,19 +337,19 @@
|
|||||||
</rule>
|
</rule>
|
||||||
<rule>
|
<rule>
|
||||||
<associated-rule-id>nat_670979b3279551.73601303</associated-rule-id>
|
<associated-rule-id>nat_670979b3279551.73601303</associated-rule-id>
|
||||||
|
<interface>wan</interface>
|
||||||
|
<ipprotocol>inet</ipprotocol>
|
||||||
|
<statetype>keep state</statetype>
|
||||||
|
<descr>port forwarding for virtual ip for someservice2 servers</descr>
|
||||||
|
<category/>
|
||||||
|
<protocol>tcp</protocol>
|
||||||
<source>
|
<source>
|
||||||
<any>1</any>
|
<any>1</any>
|
||||||
</source>
|
</source>
|
||||||
<interface>wan</interface>
|
|
||||||
<statetype>keep state</statetype>
|
|
||||||
<protocol>tcp</protocol>
|
|
||||||
<ipprotocol>inet</ipprotocol>
|
|
||||||
<destination>
|
<destination>
|
||||||
<address>192.168.20.1</address>
|
<address>192.168.20.1</address>
|
||||||
<port>55555</port>
|
<port>55555</port>
|
||||||
</destination>
|
</destination>
|
||||||
<descr>port forwarding for virtual ip for someservice2 servers</descr>
|
|
||||||
<category/>
|
|
||||||
<created>
|
<created>
|
||||||
<username>root@172.12.0.12</username>
|
<username>root@172.12.0.12</username>
|
||||||
<time>1728674227.1622</time>
|
<time>1728674227.1622</time>
|
||||||
@ -1264,13 +1264,15 @@
|
|||||||
<tcp_matchType>string</tcp_matchType>
|
<tcp_matchType>string</tcp_matchType>
|
||||||
<tcp_negate>0</tcp_negate>
|
<tcp_negate>0</tcp_negate>
|
||||||
<tcp_matchValue/>
|
<tcp_matchValue/>
|
||||||
<agentPort/>
|
<agent_port/>
|
||||||
<mysql_user/>
|
<mysql_user/>
|
||||||
<mysql_post41>0</mysql_post41>
|
<mysql_post41>0</mysql_post41>
|
||||||
<pgsql_user/>
|
<pgsql_user/>
|
||||||
<smtp_domain/>
|
<smtp_domain/>
|
||||||
<esmtp_domain/>
|
<esmtp_domain/>
|
||||||
|
<agentPort/>
|
||||||
<dbUser/>
|
<dbUser/>
|
||||||
|
<smtpDomain/>
|
||||||
</healthcheck>
|
</healthcheck>
|
||||||
</healthchecks>
|
</healthchecks>
|
||||||
<acls/>
|
<acls/>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user