libfireparse/lib.rs
1mod models;
2mod opnsense;
3mod pfsense;
4mod utils;
5
6pub use models::*;
7pub use nullnet_libconfmon::{FileData, Platform, Snapshot};
8use pfsense::PfSenseParser;
9
10use crate::opnsense::OpnSenseParser;
11
12/// Represents possible errors that can occur while parsing firewall configurations.
13pub enum FireparseError {
14 UnsupportedPlatform(String),
15 ParserError(String),
16}
17
18/// A generic parser for firewall configuration files.
19///
20/// This parser determines the correct parsing logic based on the specified platform.
21pub struct Parser {}
22
23impl Parser {
24 /// Parses a firewall configuration snapshot based on the specified platform.
25 ///
26 /// # Arguments
27 /// * `platform` - The firewall platform (e.g., `Platform::PfSense` or `Platform::OPNsense`).
28 /// * `snapshot` - A `Snapshot` representing the firewall configuration state.
29 ///
30 /// # Returns
31 /// * `Ok(Configuration)` - If parsing is successful, returns a `Configuration` struct.
32 /// * `Err(FireparseError)` - If the platform is unsupported or the snapshot is invalid.
33 ///
34 /// # Supported Platforms
35 /// - `Platform::PfSense`: Uses `PfSenseParser` to process pfSense configurations.
36 /// - `Platform::OPNsense`: Uses `OpnSenseParser` to process OPNsense configurations.
37 pub fn parse(platfom: Platform, snapshot: Snapshot) -> Result<Configuration, FireparseError> {
38 match platfom {
39 Platform::PfSense => PfSenseParser::parse(snapshot),
40 Platform::OPNsense => OpnSenseParser::parse(snapshot),
41 }
42 }
43}