From 1768d77c3107f495a33ff974f675dcb4fd0ae4b5 Mon Sep 17 00:00:00 2001 From: Zack Spear Date: Thu, 20 Mar 2025 14:48:29 -0700 Subject: [PATCH] feat: Enhance ReplaceKey to handle installation response and notifications * Added logic to process the response from KeyInstaller's installKey method. * Implemented error handling and notification system based on installation success or failure. * Notifications include event, subject, and description for better user feedback. --- emhttp/plugins/dynamix/include/ReplaceKey.php | 44 +++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/emhttp/plugins/dynamix/include/ReplaceKey.php b/emhttp/plugins/dynamix/include/ReplaceKey.php index b6d7439ab..502064efb 100644 --- a/emhttp/plugins/dynamix/include/ReplaceKey.php +++ b/emhttp/plugins/dynamix/include/ReplaceKey.php @@ -1,5 +1,4 @@ docroot/webGui/include/InstallKey.php"; $KeyInstaller = new KeyInstaller(); - $KeyInstaller->installKey($key); + $installResponse = $KeyInstaller->installKey($key); + + $installSuccess = false; + + if (!empty($installResponse)) { + $decodedResponse = json_decode($installResponse, true); + if (isset($decodedResponse['error'])) { + $this->writeJsonFile( + '/tmp/ReplaceKey/error.json', + [ + 'error' => $decodedResponse['error'], + 'ts' => time(), + ] + ); + $installSuccess = false; + } else { + $installSuccess = true; + } + } + + $keyType = basename($key, '.key'); + $output = isset($GLOBALS['notify']) ? _var($GLOBALS['notify'],'plugin') : ''; + $script = '/usr/local/emhttp/webGui/scripts/notify'; + + if ($installSuccess) { + $event = "Installed New $keyType License"; + $subject = "Your new $keyType license key has been automatically installed"; + $description = ""; + $importance = "normal $output"; + } else { + $event = "Failed to Install New $keyType License"; + $subject = "Failed to automatically install your new $keyType license key"; + $description = isset($decodedResponse['error']) ? $decodedResponse['error'] : "Unknown error occurred"; + $importance = "alert $output"; + } + + exec("$script -e ".escapeshellarg($event)." -s ".escapeshellarg($subject)." -d ".escapeshellarg($description)." -i ".escapeshellarg($importance)." -l '/Tools/Registration' -x"); + + return $installSuccess; } private function writeJsonFile($file, $data) @@ -194,6 +231,7 @@ class ReplaceKey ); return; } + $this->installNewKey($latestKey); } -} +} \ No newline at end of file