feat: add exception handling and reload active key after installation

- Wrap installKey method in try-catch for better error handling
- Execute checkRegistration=Apply after successful key download
- Add error response for installation failures
- Apply changes to both PHP class and shell script
This commit is contained in:
Zack Spear
2025-07-09 15:54:33 -07:00
parent cd0c2623b2
commit 2350d8ec08
2 changed files with 26 additions and 20 deletions

View File

@@ -47,33 +47,38 @@ class KeyInstaller
public function installKey($keyUrl = null): string
{
$url = unscript($keyUrl ?? _var($_GET, 'url'));
$host = parse_url($url)['host'] ?? '';
try {
$url = unscript($keyUrl ?? _var($_GET, 'url'));
$host = parse_url($url)['host'] ?? '';
if (!function_exists('_')) {
function _($text) {return $text;}
}
if (!function_exists('_')) {
function _($text) {return $text;}
}
if ($host && in_array($host, ['keys.lime-technology.com', 'lime-technology.com'])) {
$keyFile = basename($url);
exec("/usr/bin/wget -q -O " . escapeshellarg("/boot/config/$keyFile") . " " . escapeshellarg($url), $output, $returnVar);
if ($host && in_array($host, ['keys.lime-technology.com', 'lime-technology.com'])) {
$keyFile = basename($url);
exec("/usr/bin/wget -q -O " . escapeshellarg("/boot/config/$keyFile") . " " . escapeshellarg($url), $output, $returnVar);
if ($returnVar === 0) {
$var = (array)@parse_ini_file('/var/local/emhttp/var.ini');
if (_var($var, 'mdState') == "STARTED") {
return $this->responseComplete(200, [
'status' => 'success',
'message' => _('Please Stop array to complete key installation'),
]);
if ($returnVar === 0) {
exec("emcmd \"checkRegistration=Apply\"");
$var = (array)@parse_ini_file('/var/local/emhttp/var.ini');
if (_var($var, 'mdState') == "STARTED") {
return $this->responseComplete(200, [
'status' => 'success',
'message' => _('Please Stop array to complete key installation'),
]);
} else {
return $this->responseComplete(200, ['status' => 'success']);
}
} else {
return $this->responseComplete(200, ['status' => 'success']);
@unlink(escapeshellarg("/boot/config/$keyFile"));
return $this->responseComplete(406, ['error' => _('download error') . " $returnVar"]);
}
} else {
@unlink(escapeshellarg("/boot/config/$keyFile"));
return $this->responseComplete(406, ['error' => _('download error') . " $returnVar"]);
return $this->responseComplete(406, ['error' => _('bad or missing key file') . ": $url"]);
}
} else {
return $this->responseComplete(406, ['error' => _('bad or missing key file') . ": $url"]);
} catch (Exception $e) {
return $this->responseComplete(500, ['error' => _('installation failed') . ": " . $e->getMessage()]);
}
}
}

View File

@@ -34,6 +34,7 @@ if (in_array($host,['keys.lime-technology.com','lime-technology.com'])) {
write("Downloading $keyfile ...\n");
exec("/usr/bin/wget -q -O ".escapeshellarg("/boot/config/$key_file")." ".escapeshellarg($url), $output, $return_var);
if ($return_var === 0) {
exec("emcmd \"checkRegistration=Apply\"");
if (parse_ini_file('/var/local/emhttp/var.ini')['mdState'] == 'STARTED') {
write("Installing ... Please Stop array to complete key installation.\n");
} else {