44 lines
1.4 KiB
Rust
44 lines
1.4 KiB
Rust
static HEADLESS: std::sync::OnceLock<crate::settings::Listeners> = std::sync::OnceLock::new();
|
|
|
|
pub fn enable_headless(listeners: crate::settings::Listeners) -> bool {
|
|
HEADLESS.set(listeners).is_ok()
|
|
}
|
|
|
|
pub fn headless_enabled() -> bool {
|
|
HEADLESS.get().is_some()
|
|
}
|
|
|
|
pub fn headless_listeners() -> Option<&'static crate::settings::Listeners> {
|
|
HEADLESS.get()
|
|
}
|
|
|
|
pub fn ensure_headless_supported(config: &config::Config) -> anyhow::Result<()> {
|
|
if let Some(certificate) = config.tls.certificates.iter().find(|certificate| {
|
|
certificate
|
|
.issuer
|
|
.as_ref()
|
|
.is_some_and(|issuer| issuer.auto_renew)
|
|
}) {
|
|
anyhow::bail!(
|
|
"certificate {} uses ACME auto-renewal, which needs the administration panel; in headless mode renew it externally (for example with certbot) and reference the files in cert_file/key_file",
|
|
certificate.id
|
|
);
|
|
}
|
|
Ok(())
|
|
}
|
|
|
|
static LAST_RELOAD: std::sync::Mutex<Option<(i64, Option<String>)>> = std::sync::Mutex::new(None);
|
|
|
|
pub fn record_headless_reload(error: Option<String>) {
|
|
if let Ok(mut slot) = LAST_RELOAD.lock() {
|
|
*slot = Some((crate::auth::now(), error));
|
|
}
|
|
}
|
|
|
|
fn last_headless_reload() -> serde_json::Value {
|
|
match LAST_RELOAD.lock().ok().and_then(|slot| slot.clone()) {
|
|
Some((at, error)) => json!({ "ok": error.is_none(), "at_unix": at, "error": error }),
|
|
None => serde_json::Value::Null,
|
|
}
|
|
}
|