mirror of
https://github.com/unraid/webgui.git
synced 2026-01-15 22:19:58 -06:00
Merge CertUpload into ProvisionCert.php and direct error messages to stderr.
This commit is contained in:
@@ -1,28 +0,0 @@
|
||||
<?PHP
|
||||
/* Copyright 2005-2020, Lime Technology
|
||||
* Copyright 2012-2020, Bergware International.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License version 2,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*/
|
||||
?>
|
||||
<?
|
||||
$certFile = "/boot/config/ssl/certs/certificate_bundle.pem";
|
||||
$text = $_POST['text'] ?? '';
|
||||
|
||||
file_put_contents("{$certFile}.new", $text);
|
||||
|
||||
//validate certificate_bundle.pem.new is for *.unraid.net before moving it over to certificate_bundle.pem
|
||||
$certSubject = exec("/usr/bin/openssl x509 -in {$certFile}.new -subject -noout 2>&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");
|
||||
}
|
||||
?>
|
||||
@@ -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'));
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user