diff --git a/emhttp/plugins/dynamix/include/InstallKey.php b/emhttp/plugins/dynamix/include/InstallKey.php index 467a90322..7f08e760d 100644 --- a/emhttp/plugins/dynamix/include/InstallKey.php +++ b/emhttp/plugins/dynamix/include/InstallKey.php @@ -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()]); } } } diff --git a/emhttp/plugins/dynamix/scripts/install_key b/emhttp/plugins/dynamix/scripts/install_key index 74b6c156f..b8c0e8534 100755 --- a/emhttp/plugins/dynamix/scripts/install_key +++ b/emhttp/plugins/dynamix/scripts/install_key @@ -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 {