From 12ea2ec6b3b9bd5f2cf6de44212bb5dfcfd807eb Mon Sep 17 00:00:00 2001 From: Tom Mortensen Date: Sun, 28 Aug 2022 07:30:35 -0700 Subject: [PATCH] Merge CertUpload into ProvisionCert.php and direct error messages to stderr. --- plugins/dynamix/include/CertUpload.php | 28 ----------------------- plugins/dynamix/include/ProvisionCert.php | 21 ++++++++--------- 2 files changed, 9 insertions(+), 40 deletions(-) delete mode 100644 plugins/dynamix/include/CertUpload.php diff --git a/plugins/dynamix/include/CertUpload.php b/plugins/dynamix/include/CertUpload.php deleted file mode 100644 index 01f793c66..000000000 --- a/plugins/dynamix/include/CertUpload.php +++ /dev/null @@ -1,28 +0,0 @@ - -&1"); -$isLEcert = preg_match('/.*\.myunraid\.net$/', $certSubject) || preg_match('/.*\.unraid\.net$/', $certSubject); -if ($isLEcert) { - rename("{$certFile}.new", "$certFile"); - syslog(LOG_NOTICE, 'Updated *.hash.myunraid.net certificate: '.$certFile); -} else { - unlink("{$certFile}.new"); -} -?> diff --git a/plugins/dynamix/include/ProvisionCert.php b/plugins/dynamix/include/ProvisionCert.php index f8bbef2cc..b7bbda759 100644 --- a/plugins/dynamix/include/ProvisionCert.php +++ b/plugins/dynamix/include/ProvisionCert.php @@ -25,7 +25,7 @@ function response_complete($httpcode, $result, $cli_success_msg='') { if ($cli) { $json = @json_decode($result,true); if (!empty($json['error'])) { - echo 'Error: '.$json['error'].PHP_EOL; + fwrite(STDERR, 'Error: '.$json['error'].PHP_EOL); exit(1); } exit($cli_success_msg.PHP_EOL); @@ -78,18 +78,15 @@ $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); // save the cert -if ($cli) { - $json = @json_decode($result,true); - if (empty($json['bundle'])) { - $strError = _('Server was unable to provision SSL certificate'); - if (!empty($json['error'])) { - $strError .= ' - '.$json['error']; - } - response_complete(406, '{"error":"'.$strError.'"}'); +$json = @json_decode($result,true); +if (empty($json['bundle'])) { + $strError = _('Server was unable to provision SSL certificate'); + if (!empty($json['error'])) { + $strError .= ' - '.$json['error']; } - $_POST['text'] = $json['bundle']; // nice way to leverage CertUpload.php to save the cert - include(__DIR__.'/CertUpload.php'); + response_complete(406, '{"error":"'.$strError.'"}'); } - +file_put_contents("{$certPath}.new", $json['bundle']); +rename("{$certPath}.new", "$certPath"); response_complete($httpcode, $result, _('LE Cert Provisioned successfully')); ?>