feat(opnsense-config): add caddy module with configuration management
Introduce a new Caddy module within opnsense-config to manage Caddy server configurations. This includes enabling/disabling Caddy, setting ports, and reloading/restarting the service via OPNsense shell commands. Additionally, provide a sample Caddy configuration file for PXE booting and a test file in the pxe-http-files directory.
This commit is contained in:
@@ -3,7 +3,7 @@ use std::{sync::Arc, time::Duration};
|
||||
use crate::{
|
||||
config::{SshConfigManager, SshCredentials, SshOPNSenseShell},
|
||||
error::Error,
|
||||
modules::{dhcp::DhcpConfig, dns::DnsConfig, load_balancer::LoadBalancerConfig, tftp::TftpConfig},
|
||||
modules::{caddy::CaddyConfig, dhcp::DhcpConfig, dns::DnsConfig, load_balancer::LoadBalancerConfig, tftp::TftpConfig},
|
||||
};
|
||||
use log::{info, trace};
|
||||
use opnsense_config_xml::OPNsense;
|
||||
@@ -42,6 +42,10 @@ impl Config {
|
||||
TftpConfig::new(&mut self.opnsense, self.shell.clone())
|
||||
}
|
||||
|
||||
pub fn caddy(&mut self) -> CaddyConfig {
|
||||
CaddyConfig::new(&mut self.opnsense, self.shell.clone())
|
||||
}
|
||||
|
||||
pub fn load_balancer(&mut self) -> LoadBalancerConfig {
|
||||
LoadBalancerConfig::new(&mut self.opnsense, self.shell.clone())
|
||||
}
|
||||
@@ -50,6 +54,17 @@ impl Config {
|
||||
self.shell.upload_folder(source, destination).await
|
||||
}
|
||||
|
||||
// Here maybe we should take ownership of `mut self` instead of `&mut self`
|
||||
// I don't think there can be faulty pointers to previous versions of the config but I have a
|
||||
// hard time wrapping my head around it right now :
|
||||
// - the caller has a mutable reference to us
|
||||
// - caller gets a reference to a piece of configuration (.haproxy.general.servers[0])
|
||||
// - caller calls install_package wich reloads the config from remote
|
||||
// - haproxy.general.servers[0] does not exist anymore
|
||||
// - broken?
|
||||
//
|
||||
// Although I did not try explicitely the above workflow so maybe rust prevents taking a
|
||||
// read-only reference across the &mut call
|
||||
pub async fn install_package(&mut self, package_name: &str) -> Result<(), Error> {
|
||||
info!("Installing opnsense package {package_name}");
|
||||
let output = self.shell
|
||||
|
||||
Reference in New Issue
Block a user