net/haproxy: fix certificate export

This commit is contained in:
Frank Wall 2016-05-19 15:22:54 +02:00
parent dec85ab09a
commit f997189a77

View file

@ -41,11 +41,11 @@ global $config;
$configObj = Config::getInstance()->object();
if (isset($configObj->OPNsense->HAProxy->frontends)) {
foreach ($configObj->OPNsense->HAProxy->frontends->children() as $frontend) {
if (!isset($frontend->ssl)) {
if (!isset($frontend->ssl_enabled)) {
continue;
}
// multiple comma-separated values are possible
$certs = explode(',', $frontend->ssl->certificates);
$certs = explode(',', $frontend->ssl_certificates);
foreach ($certs as $cert_refid) {
// if the frontend has a cert attached, search for its contents
if ($cert_refid != "") {
@ -53,7 +53,7 @@ if (isset($configObj->OPNsense->HAProxy->frontends)) {
if ($cert_refid == (string)$cert->refid) {
// generate cert pem file
$pem_content = str_replace("\n\n", "\n", str_replace("\r", "", base64_decode((string)$cert->crt)));
$pem_content .= str_replace("\n\n", "\n", str_replace("\r", "", base64_decode((string)$cert->prv)));
$pem_content .= "\n" . str_replace("\n\n", "\n", str_replace("\r", "", base64_decode((string)$cert->prv)));
$output_pem_filename = "/var/etc/haproxy/ssl/" . $cert_refid . ".pem" ;
file_put_contents($output_pem_filename, $pem_content);
chmod($output_pem_filename, 0600);