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 8f1adfe3c..51e0eb720 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 @@ -45,9 +45,11 @@ class ServerState "nokeyserver" => 'NO_KEY_SERVER', "withdrawn" => 'WITHDRAWN', ]; + private $osVersion; private $osVersionBranch; private $registered; private $rebootDetails; + private $caseModel; /** * Constructor to initialize class properties and gather server information. @@ -83,13 +85,23 @@ class ServerState : (file_exists('/var/log/plugins/dynamix.unraid.net.staging.plg') ? trim(@exec('/usr/local/sbin/plugin version /var/log/plugins/dynamix.unraid.net.staging.plg 2>/dev/null')) : 'base-' . $this->var['version']); - + /** + * @todo can we read this from somewhere other than the flash? Connect page uses this path and /boot/config/plugins/dynamix.my.servers/myservers.cfg… + * - $myservers_memory_cfg_path ='/var/local/emhttp/myservers.cfg'; + * - $mystatus = (file_exists($myservers_memory_cfg_path)) ? @parse_ini_file($myservers_memory_cfg_path) : []; + */ $this->myserversFlashCfgPath = '/boot/config/plugins/dynamix.my.servers/myservers.cfg'; $this->myservers = file_exists($this->myserversFlashCfgPath) ? @parse_ini_file($this->myserversFlashCfgPath, true) : []; + $this->osVersion = $this->var['version']; $this->osVersionBranch = trim(@exec('plugin category /var/log/plugins/unRAIDServer.plg') ?? 'stable'); $this->registered = !empty($this->myservers['remote']['apikey']) && $this->connectPluginInstalled; + // if we're on 6.12.6 or newer, get the case model as this version will include the cookie with the case model when it's reset + if (version_compare('6.12.6', $osVersion, '>=')) { + $this->caseModel = $this->getServerCase(); + } + $this->rebootDetails = new RebootDetails(); } @@ -100,6 +112,28 @@ class ServerState return $this->webguiGlobals[$key]; } + public function getServerCase() { + $caseModel = $_COOKIE['caseModel'] ?? false; + // if we don't have a cookie, check the file and set the cookie if we find one + if (!$caseModel) { + $caseModelFile = '/boot/config/plugins/dynamix/case-model.cfg'; + $caseModel = file_exists($caseModelFile) ? file_get_contents($caseModelFile) : false; + if ($caseModel) { + $cookieOptions = array ( + 'expires' => time() + (10 * 365 * 24 * 60 * 60), // overkill with 10 years + 'path' => '/', + 'secure' => false, + 'httponly' => false, + 'samesite' => 'Strict', + ); + setcookie('caseModel', $caseModel, $cookieOptions); + } else { + $caseModel = 'unknown'; + } + } + return $caseModel; + } + /** * Retrieve the server information as an associative array * @@ -111,6 +145,7 @@ class ServerState "apiKey" => $this->myservers['upc']['apikey'] ?? '', "apiVersion" => $this->myservers['api']['version'] ?? '', "avatar" => (!empty($this->myservers['remote']['avatar']) && $this->connectPluginInstalled) ? $this->myservers['remote']['avatar'] : '', + "caseModel" => $this->caseModel, "config" => [ 'valid' => ($this->var['configValid'] === 'yes'), 'error' => isset($this->configErrorEnum[$this->var['configValid']]) ? $this->configErrorEnum[$this->var['configValid']] : 'UNKNOWN_ERROR', diff --git a/web/store/server.ts b/web/store/server.ts index 518ffd6b3..b6a1eb5a0 100644 --- a/web/store/server.ts +++ b/web/store/server.ts @@ -65,6 +65,7 @@ export const useServerStore = defineStore('server', () => { }); const apiVersion = ref(''); const avatar = ref(''); // @todo potentially move to a user store + const caseModel = ref(''); const cloud = ref(); const config = ref(); const connectPluginInstalled = ref(''); @@ -215,6 +216,7 @@ export const useServerStore = defineStore('server', () => { const serverAccountPayload = computed((): ServerAccountCallbackSendPayload => { return { apiVersion: apiVersion.value, + caseModel: caseModel.value, connectPluginVersion: connectPluginVersion.value, description: description.value, expireTime: expireTime.value, @@ -749,6 +751,7 @@ export const useServerStore = defineStore('server', () => { if (typeof data?.apiKey !== 'undefined') { apiKey.value = data.apiKey; } if (typeof data?.apiVersion !== 'undefined') { apiVersion.value = data.apiVersion; } if (typeof data?.avatar !== 'undefined') { avatar.value = data.avatar; } + if (typeof data?.caseModel !== 'undefined') { caseModel.value = data.caseModel; } if (typeof data?.cloud !== 'undefined') { cloud.value = data.cloud; } if (typeof data?.config !== 'undefined') { config.value = data.config; } if (typeof data?.connectPluginInstalled !== 'undefined') { connectPluginInstalled.value = data.connectPluginInstalled; } diff --git a/web/types/server.ts b/web/types/server.ts index d36ff909e..fa28e901f 100644 --- a/web/types/server.ts +++ b/web/types/server.ts @@ -53,6 +53,7 @@ export interface Server { apiKey?: string; apiVersion?: string; avatar?: string; + caseModel?: string; cloud?: PartialCloudFragment | undefined; config?: Config | undefined; connectPluginInstalled?: ServerconnectPluginInstalled; @@ -97,6 +98,7 @@ export interface Server { export interface ServerAccountCallbackSendPayload { apiVersion?: string; + caseModel?: string; connectPluginVersion?: string; description?: string; deviceCount?: number;