forked from NationTech/harmony
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.
92 lines
3.1 KiB
Rust
92 lines
3.1 KiB
Rust
use std::{
|
|
net::{IpAddr, Ipv4Addr},
|
|
sync::Arc,
|
|
};
|
|
|
|
use cidr::Ipv4Cidr;
|
|
use harmony::{
|
|
hardware::{FirewallGroup, HostCategory, Location, PhysicalHost, SwitchGroup},
|
|
infra::opnsense::OPNSenseManagementInterface,
|
|
inventory::Inventory,
|
|
maestro::Maestro,
|
|
modules::{
|
|
http::HttpScore, okd::{dhcp::OKDBootstrapDhcpScore, dns::OKDBootstrapDnsScore}, tftp::TftpScore
|
|
},
|
|
topology::{LogicalHost, UnmanagedRouter, Url},
|
|
};
|
|
use harmony_macros::ip;
|
|
|
|
#[tokio::main]
|
|
async fn main() {
|
|
env_logger::init();
|
|
|
|
let firewall = harmony::topology::LogicalHost {
|
|
ip: ip!("192.168.5.229"),
|
|
name: String::from("opnsense-1"),
|
|
};
|
|
|
|
let opnsense = Arc::new(
|
|
harmony::infra::opnsense::OPNSenseFirewall::new(firewall, None, "lan", "root", "opnsense")
|
|
.await,
|
|
);
|
|
let lan_subnet = Ipv4Addr::new(10, 100, 8, 0);
|
|
let gateway_ipv4 = Ipv4Addr::new(10, 100, 8, 1);
|
|
let gateway_ip = IpAddr::V4(gateway_ipv4);
|
|
let topology = harmony::topology::HAClusterTopology {
|
|
domain_name: "demo.harmony.mcd".to_string(),
|
|
router: Arc::new(UnmanagedRouter::new(
|
|
gateway_ip,
|
|
Ipv4Cidr::new(lan_subnet, 24).unwrap(),
|
|
)),
|
|
load_balancer: opnsense.clone(),
|
|
firewall: opnsense.clone(),
|
|
tftp_server: opnsense.clone(),
|
|
http_server: opnsense.clone(),
|
|
dhcp_server: opnsense.clone(),
|
|
dns_server: opnsense.clone(),
|
|
control_plane: vec![LogicalHost {
|
|
ip: ip!("10.100.8.20"),
|
|
name: "cp0".to_string(),
|
|
}],
|
|
workers: vec![],
|
|
switch: vec![],
|
|
};
|
|
|
|
let inventory = Inventory {
|
|
location: Location::new(
|
|
"232 des Éperviers, Wendake, Qc, G0A 4V0".to_string(),
|
|
"wk".to_string(),
|
|
),
|
|
switch: SwitchGroup::from([]),
|
|
firewall: FirewallGroup::from([PhysicalHost {
|
|
category: HostCategory::Firewall,
|
|
network: vec![],
|
|
management: Arc::new(OPNSenseManagementInterface::new()),
|
|
storage: vec![],
|
|
labels: vec![],
|
|
}]),
|
|
worker_host: vec![],
|
|
storage_host: vec![],
|
|
control_plane_host: vec![],
|
|
};
|
|
|
|
// TODO regroup smaller scores in a larger one such as this
|
|
// let okd_boostrap_preparation();
|
|
|
|
// let dhcp_score = OKDBootstrapDhcpScore::new(&topology, &inventory);
|
|
// let dns_score = OKDBootstrapDnsScore::new(&topology);
|
|
// let load_balancer_score =
|
|
// harmony::modules::okd::load_balancer::OKDLoadBalancerScore::new(&topology);
|
|
|
|
let tftp_score = TftpScore::new(Url::LocalFolder("../../../watchguard/tftpboot".to_string()));
|
|
let http_score = HttpScore::new(Url::LocalFolder(
|
|
"../../../watchguard/pxe-http-files".to_string(),
|
|
));
|
|
let maestro = Maestro::new(inventory, topology);
|
|
// maestro.interpret(dns_score).await.unwrap();
|
|
// maestro.interpret(dhcp_score).await.unwrap();
|
|
// maestro.interpret(load_balancer_score).await.unwrap();
|
|
// maestro.interpret(tftp_score).await.unwrap();
|
|
maestro.interpret(http_score).await.unwrap();
|
|
}
|