diff --git a/Certman.class.php b/Certman.class.php index 1011b54..1e1cea3 100644 --- a/Certman.class.php +++ b/Certman.class.php @@ -708,6 +708,8 @@ public function checkUpdateCertificates($force = false) { if($update) { $this->updateCertificate($cert, $cert['description'], $cert['additional']); exec(fpbx_which("fwconsole")." reload"); + // Reload HAProxy if it's enabled to pick up renewed SSL certificates + $this->reloadHAProxyIfEnabled(); } } $notification = ''; @@ -2219,4 +2221,34 @@ function addAutoUpdateCron() { )); } } + + /** + * Reload HAProxy service if it's enabled to pick up renewed SSL certificates + * + * This method checks if the sysadmin module is available and HAProxy is enabled, + * then triggers the appropriate hook to reload HAProxy with the new certificate. + */ + private function reloadHAProxyIfEnabled() { + // Check if sysadmin module is available + if (!$this->FreePBX->Modules->checkStatus("sysadmin")) { + return; + } + + try { + // Get the sysadmin module instance + $sysadmin = $this->FreePBX->Sysadmin; + // Check if HAProxy is enabled + $haproxyEnabled = $sysadmin->getConfig("enbableHaproxy"); + dbug("reloadHAProxyIfEnabled: HAProxy is enabled: " . $haproxyEnabled); + if ($haproxyEnabled === 'enabled') { + // Trigger the sysadmin hook to restart HAProxy with new certificate + $sysadmin->runHook("update-sslconf", ['restart_haproxy' => true]); + // Log the action for debugging + dbug("Certificate Manager: HAProxy reloaded after Let's Encrypt certificate renewal"); + } + } catch (Exception $e) { + // Log error but don't fail the certificate renewal process + dbug("Certificate Manager: Failed to reload HAProxy after certificate renewal: " . $e->getMessage()); + } + } }