From 53caba41d6abd6c0e7d3939c7370db598a3bf7c4 Mon Sep 17 00:00:00 2001 From: Pujit Mehrotra Date: Tue, 24 Jun 2025 16:58:02 -0400 Subject: [PATCH 1/5] chore: move activation code extractor here from webgui repo --- .../include/activation-code-extractor.php | 166 ++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100644 plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/include/activation-code-extractor.php diff --git a/plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/include/activation-code-extractor.php b/plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/include/activation-code-extractor.php new file mode 100644 index 0000000000..53b91c016a --- /dev/null +++ b/plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/include/activation-code-extractor.php @@ -0,0 +1,166 @@ +data = $this->fetchJsonData(); + } + + /** + * Fetch JSON data from all files matching the pattern. + * + * @return array Array of extracted JSON data. + */ + private function fetchJsonData(): array { + $data = []; + + if (!is_dir(self::DIR)) { + return $data; + } + + $files = scandir(self::DIR); + + if ($files === false || count($files) === 0) { + return $data; + } + + foreach ($files as $file) { + $filePath = self::DIR . DIRECTORY_SEPARATOR . $file; + + if (preg_match(self::FILE_PATTERN, $file, $matches)) { + // $activationCode = $matches[1]; + $fileContent = file_get_contents($filePath); + $jsonData = json_decode($fileContent, true); + + if (json_last_error() === JSON_ERROR_NONE) { + $data = $jsonData; + } else { + $data = ['error' => 'Invalid JSON format']; + } + + break; // Stop after the first match + } + } + + if (isset($data['partnerName'])) { + $this->partnerName = $data['partnerName']; + } + + if (isset($data['partnerUrl'])) { + $this->partnerUrl = $data['partnerUrl']; + } + + /** + * During the plg install, the partner logo asset is copied to the webgui images dir. + */ + $logo = self::DOCROOT . self::WEBGUI_IMAGES_BASE_DIR . '/' . self::PARTNER_LOGO_FILE_NAME; + if (file_exists($logo)) { + $this->partnerLogoPath = $logo; + } + + return $data; + } + + /** + * Get the partner logo path. + * + * @return string + */ + public function getPartnerLogoPath(): string { + return $this->partnerLogoPath; + } + + /** + * Get the extracted data. + * + * @return array + */ + public function getData(): array { + return $this->data; + } + + /** + * Retrieve the activation code data as JSON string with converted special characters to HTML entities + * + * @return string + */ + public function getDataForHtmlAttr(): string { + $json = json_encode($this->getData()); + return htmlspecialchars($json, ENT_QUOTES, 'UTF-8'); + } + + /** + * Get the partner logo render string. + * + * @return string + */ + public function getPartnerLogoRenderString(): string { + if (empty($this->partnerLogoPath)) { // default logo + return file_get_contents(self::DEFAULT_LOGO); + } + + return file_get_contents($this->partnerLogoPath); + } + + /** + * Get the partner name. + * + * @return string + */ + public function getPartnerName(): string { + return $this->partnerName; + } + + /** + * Get the partner URL. + * + * @return string + */ + public function getPartnerUrl(): string { + return $this->partnerUrl; + } + + /** + * Output for debugging + * @return void + */ + public function debug(): void { + echo "data: "; var_dump($this->data); + echo "partnerName: "; var_dump($this->partnerName); + echo "partnerUrl: "; var_dump($this->partnerUrl); + echo "partnerLogoPath: "; var_dump($this->partnerLogoPath); + + echo $this->getPartnerLogoRenderString(); + } +} From 884cd6e41fc16ac78eda6e047ebabe5f5e8a85b7 Mon Sep 17 00:00:00 2001 From: Pujit Mehrotra Date: Tue, 24 Jun 2025 17:10:49 -0400 Subject: [PATCH 2/5] migrate activationCode into our state.php --- .../dynamix.my.servers/include/state.php | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/include/state.php b/plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/include/state.php index 530240328c..c883fedd08 100644 --- a/plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/include/state.php +++ b/plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/include/state.php @@ -15,6 +15,7 @@ $webguiGlobals = $GLOBALS; $docroot = $docroot ?? $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp'; +require_once "$docroot/plugins/dynamix.my.servers/include/activation-code-extractor.php"; require_once "$docroot/plugins/dynamix.my.servers/include/reboot-details.php"; require_once "$docroot/plugins/dynamix.plugin.manager/include/UnraidCheck.php"; require_once "$docroot/plugins/dynamix.my.servers/include/api-config.php"; @@ -78,6 +79,7 @@ class ServerState public $registered = false; public $myServersMiniGraphConnected = false; public $keyfileBase64 = ''; + public $activationCodeData = []; public $state = 'UNKNOWN'; /** @@ -131,6 +133,7 @@ public function __construct() $this->updateOsResponse = $this->updateOsCheck->getUnraidOSCheckResult(); $this->setConnectValues(); + $this->detectActivationCode(); } /** @@ -244,6 +247,23 @@ private function getConnectKnownOrigins() } } + private function detectActivationCode() + { + // Fresh server and we're not loading with a callback param to install + if ($this->state !== 'ENOKEYFILE' || !empty($_GET['c'])) { + return; + } + + $activationCodeData = new ActivationCodeExtractor(); + $data = $activationCodeData->getData(); + + if (empty($data)) { + return; + } + + $this->activationCodeData = $data; + } + /** * Retrieve the server information as an associative array * @@ -335,6 +355,10 @@ public function getServerState() $serverState['updateOsResponse'] = $this->updateOsResponse; } + if ($this->activationCodeData) { + $serverState['activationCodeData'] = $this->activationCodeData; + } + return $serverState; } From 65df6e8e9d68779784352e8a39314cf6e8cb399e Mon Sep 17 00:00:00 2001 From: Pujit Mehrotra Date: Tue, 24 Jun 2025 17:17:07 -0400 Subject: [PATCH 3/5] rm obsolete style block in myservers1 --- .../dynamix.my.servers/include/myservers1.php | 34 ------------------- 1 file changed, 34 deletions(-) diff --git a/plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/include/myservers1.php b/plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/include/myservers1.php index b9cfc44ff3..d8de6b2eb8 100644 --- a/plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/include/myservers1.php +++ b/plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/include/myservers1.php @@ -9,40 +9,6 @@ * all copies or substantial portions of the Software. */ ?> - Date: Wed, 25 Jun 2025 10:21:14 -0400 Subject: [PATCH 4/5] Revert "migrate activationCode into our state.php" This reverts commit 884cd6e41fc16ac78eda6e047ebabe5f5e8a85b7. --- .../dynamix.my.servers/include/state.php | 24 ------------------- 1 file changed, 24 deletions(-) diff --git a/plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/include/state.php b/plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/include/state.php index c883fedd08..530240328c 100644 --- a/plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/include/state.php +++ b/plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/include/state.php @@ -15,7 +15,6 @@ $webguiGlobals = $GLOBALS; $docroot = $docroot ?? $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp'; -require_once "$docroot/plugins/dynamix.my.servers/include/activation-code-extractor.php"; require_once "$docroot/plugins/dynamix.my.servers/include/reboot-details.php"; require_once "$docroot/plugins/dynamix.plugin.manager/include/UnraidCheck.php"; require_once "$docroot/plugins/dynamix.my.servers/include/api-config.php"; @@ -79,7 +78,6 @@ class ServerState public $registered = false; public $myServersMiniGraphConnected = false; public $keyfileBase64 = ''; - public $activationCodeData = []; public $state = 'UNKNOWN'; /** @@ -133,7 +131,6 @@ public function __construct() $this->updateOsResponse = $this->updateOsCheck->getUnraidOSCheckResult(); $this->setConnectValues(); - $this->detectActivationCode(); } /** @@ -247,23 +244,6 @@ private function getConnectKnownOrigins() } } - private function detectActivationCode() - { - // Fresh server and we're not loading with a callback param to install - if ($this->state !== 'ENOKEYFILE' || !empty($_GET['c'])) { - return; - } - - $activationCodeData = new ActivationCodeExtractor(); - $data = $activationCodeData->getData(); - - if (empty($data)) { - return; - } - - $this->activationCodeData = $data; - } - /** * Retrieve the server information as an associative array * @@ -355,10 +335,6 @@ public function getServerState() $serverState['updateOsResponse'] = $this->updateOsResponse; } - if ($this->activationCodeData) { - $serverState['activationCodeData'] = $this->activationCodeData; - } - return $serverState; } From 9128d95bc3fccd147cff5340ba4a5c9bd1ffb11f Mon Sep 17 00:00:00 2001 From: Pujit Mehrotra Date: Wed, 25 Jun 2025 10:21:27 -0400 Subject: [PATCH 5/5] Revert "chore: move activation code extractor here from webgui repo" This reverts commit 53caba41d6abd6c0e7d3939c7370db598a3bf7c4. --- .../include/activation-code-extractor.php | 166 ------------------ 1 file changed, 166 deletions(-) delete mode 100644 plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/include/activation-code-extractor.php diff --git a/plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/include/activation-code-extractor.php b/plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/include/activation-code-extractor.php deleted file mode 100644 index 53b91c016a..0000000000 --- a/plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/include/activation-code-extractor.php +++ /dev/null @@ -1,166 +0,0 @@ -data = $this->fetchJsonData(); - } - - /** - * Fetch JSON data from all files matching the pattern. - * - * @return array Array of extracted JSON data. - */ - private function fetchJsonData(): array { - $data = []; - - if (!is_dir(self::DIR)) { - return $data; - } - - $files = scandir(self::DIR); - - if ($files === false || count($files) === 0) { - return $data; - } - - foreach ($files as $file) { - $filePath = self::DIR . DIRECTORY_SEPARATOR . $file; - - if (preg_match(self::FILE_PATTERN, $file, $matches)) { - // $activationCode = $matches[1]; - $fileContent = file_get_contents($filePath); - $jsonData = json_decode($fileContent, true); - - if (json_last_error() === JSON_ERROR_NONE) { - $data = $jsonData; - } else { - $data = ['error' => 'Invalid JSON format']; - } - - break; // Stop after the first match - } - } - - if (isset($data['partnerName'])) { - $this->partnerName = $data['partnerName']; - } - - if (isset($data['partnerUrl'])) { - $this->partnerUrl = $data['partnerUrl']; - } - - /** - * During the plg install, the partner logo asset is copied to the webgui images dir. - */ - $logo = self::DOCROOT . self::WEBGUI_IMAGES_BASE_DIR . '/' . self::PARTNER_LOGO_FILE_NAME; - if (file_exists($logo)) { - $this->partnerLogoPath = $logo; - } - - return $data; - } - - /** - * Get the partner logo path. - * - * @return string - */ - public function getPartnerLogoPath(): string { - return $this->partnerLogoPath; - } - - /** - * Get the extracted data. - * - * @return array - */ - public function getData(): array { - return $this->data; - } - - /** - * Retrieve the activation code data as JSON string with converted special characters to HTML entities - * - * @return string - */ - public function getDataForHtmlAttr(): string { - $json = json_encode($this->getData()); - return htmlspecialchars($json, ENT_QUOTES, 'UTF-8'); - } - - /** - * Get the partner logo render string. - * - * @return string - */ - public function getPartnerLogoRenderString(): string { - if (empty($this->partnerLogoPath)) { // default logo - return file_get_contents(self::DEFAULT_LOGO); - } - - return file_get_contents($this->partnerLogoPath); - } - - /** - * Get the partner name. - * - * @return string - */ - public function getPartnerName(): string { - return $this->partnerName; - } - - /** - * Get the partner URL. - * - * @return string - */ - public function getPartnerUrl(): string { - return $this->partnerUrl; - } - - /** - * Output for debugging - * @return void - */ - public function debug(): void { - echo "data: "; var_dump($this->data); - echo "partnerName: "; var_dump($this->partnerName); - echo "partnerUrl: "; var_dump($this->partnerUrl); - echo "partnerLogoPath: "; var_dump($this->partnerLogoPath); - - echo $this->getPartnerLogoRenderString(); - } -}