Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions Certman.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
Expand Down Expand Up @@ -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());
}
}
}