General warning and documentation pass.

This commit is contained in:
Herbert Wolverson
2024-01-26 16:33:35 -06:00
parent 50bc071db1
commit d851161670
4 changed files with 11 additions and 4 deletions

View File

@@ -190,7 +190,7 @@ impl EtcLqos {
error!("Unable to parse TOML from /etc/lqos.conf");
error!("Full error: {:?}", e);
panic!();
Err(EtcLqosError::CannotParseToml)
//Err(EtcLqosError::CannotParseToml)
}
}
}
@@ -220,6 +220,7 @@ impl EtcLqos {
/// Run this if you've received the OK from the licensing server, and been
/// sent a license key. This appends a [long_term_stats] section to your
/// config file - ONLY if one doesn't already exist.
#[allow(dead_code)]
pub fn enable_long_term_stats(license_key: String) {
if let Ok(raw) = std::fs::read_to_string("/etc/lqos.conf") {
let document = raw.parse::<Document>();
@@ -296,8 +297,6 @@ pub enum EtcLqosError {
CannotParseToml,
#[error("Unable to backup /etc/lqos.conf to /etc/lqos.conf.backup")]
BackupFail,
#[error("Unable to serialize new configuration")]
SerializeFail,
#[error("Unable to write to /etc/lqos.conf")]
WriteFail,
}

View File

@@ -49,6 +49,7 @@ pub fn load_config() -> Result<Config, LibreQoSConfigError> {
Ok(lock.as_ref().unwrap().clone())
}
/// Enables LTS reporting in the configuration file.
pub fn enable_long_term_stats(license_key: String) -> Result<(), LibreQoSConfigError> {
let mut config = load_config()?;
let mut lock = CONFIG.lock().unwrap();

View File

@@ -7,6 +7,7 @@ use sha2::digest::Update;
use sha2::Digest;
use uuid::Uuid;
/// Top-level configuration file for LibreQoS.
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Config {
/// Version number for the configuration file.
@@ -95,6 +96,8 @@ impl Config {
Ok(())
}
/// Loads a config file from a string (used for testing only)
#[allow(dead_code)]
pub fn load_from_string(s: &str) -> Result<Self, String> {
let config: Config = toml::from_str(s).map_err(|e| format!("Error parsing config: {}", e))?;
config.validate()?;
@@ -127,6 +130,7 @@ impl Default for Config {
}
impl Config {
/// Calculate the unterface facing the Internet
pub fn internet_interface(&self) -> String {
if let Some(bridge) = &self.bridge {
bridge.to_internet.clone()
@@ -137,6 +141,7 @@ impl Config {
}
}
/// Calculate the interface facing the ISP
pub fn isp_interface(&self) -> String {
if let Some(bridge) = &self.bridge {
bridge.to_network.clone()
@@ -147,10 +152,12 @@ impl Config {
}
}
/// Are we in single-interface mode?
pub fn on_a_stick_mode(&self) -> bool {
self.bridge.is_none()
}
/// Get the VLANs for the stick interface
pub fn stick_vlans(&self) -> (u32, u32) {
if let Some(stick) = &self.single_interface {
(stick.network_vlan, stick.internet_vlan)

View File

@@ -1,6 +1,6 @@
mod serializable;
mod shaped_device;
use crate::{etc, SUPPORTED_CUSTOMERS};
use crate::SUPPORTED_CUSTOMERS;
use csv::{QuoteStyle, ReaderBuilder, WriterBuilder};
use log::error;
use serializable::SerializableShapedDevice;