mirror of
https://github.com/unraid/api.git
synced 2026-05-08 08:00:19 -05:00
feat(web): caseModel
This commit is contained in:
+36
-1
@@ -45,9 +45,11 @@ class ServerState
|
|||||||
"nokeyserver" => 'NO_KEY_SERVER',
|
"nokeyserver" => 'NO_KEY_SERVER',
|
||||||
"withdrawn" => 'WITHDRAWN',
|
"withdrawn" => 'WITHDRAWN',
|
||||||
];
|
];
|
||||||
|
private $osVersion;
|
||||||
private $osVersionBranch;
|
private $osVersionBranch;
|
||||||
private $registered;
|
private $registered;
|
||||||
private $rebootDetails;
|
private $rebootDetails;
|
||||||
|
private $caseModel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor to initialize class properties and gather server information.
|
* 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')
|
: (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'))
|
? trim(@exec('/usr/local/sbin/plugin version /var/log/plugins/dynamix.unraid.net.staging.plg 2>/dev/null'))
|
||||||
: 'base-' . $this->var['version']);
|
: '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->myserversFlashCfgPath = '/boot/config/plugins/dynamix.my.servers/myservers.cfg';
|
||||||
$this->myservers = file_exists($this->myserversFlashCfgPath) ? @parse_ini_file($this->myserversFlashCfgPath, true) : [];
|
$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->osVersionBranch = trim(@exec('plugin category /var/log/plugins/unRAIDServer.plg') ?? 'stable');
|
||||||
$this->registered = !empty($this->myservers['remote']['apikey']) && $this->connectPluginInstalled;
|
$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();
|
$this->rebootDetails = new RebootDetails();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,6 +112,28 @@ class ServerState
|
|||||||
return $this->webguiGlobals[$key];
|
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
|
* Retrieve the server information as an associative array
|
||||||
*
|
*
|
||||||
@@ -111,6 +145,7 @@ class ServerState
|
|||||||
"apiKey" => $this->myservers['upc']['apikey'] ?? '',
|
"apiKey" => $this->myservers['upc']['apikey'] ?? '',
|
||||||
"apiVersion" => $this->myservers['api']['version'] ?? '',
|
"apiVersion" => $this->myservers['api']['version'] ?? '',
|
||||||
"avatar" => (!empty($this->myservers['remote']['avatar']) && $this->connectPluginInstalled) ? $this->myservers['remote']['avatar'] : '',
|
"avatar" => (!empty($this->myservers['remote']['avatar']) && $this->connectPluginInstalled) ? $this->myservers['remote']['avatar'] : '',
|
||||||
|
"caseModel" => $this->caseModel,
|
||||||
"config" => [
|
"config" => [
|
||||||
'valid' => ($this->var['configValid'] === 'yes'),
|
'valid' => ($this->var['configValid'] === 'yes'),
|
||||||
'error' => isset($this->configErrorEnum[$this->var['configValid']]) ? $this->configErrorEnum[$this->var['configValid']] : 'UNKNOWN_ERROR',
|
'error' => isset($this->configErrorEnum[$this->var['configValid']]) ? $this->configErrorEnum[$this->var['configValid']] : 'UNKNOWN_ERROR',
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ export const useServerStore = defineStore('server', () => {
|
|||||||
});
|
});
|
||||||
const apiVersion = ref<string>('');
|
const apiVersion = ref<string>('');
|
||||||
const avatar = ref<string>(''); // @todo potentially move to a user store
|
const avatar = ref<string>(''); // @todo potentially move to a user store
|
||||||
|
const caseModel = ref<string>('');
|
||||||
const cloud = ref<PartialCloudFragment | undefined>();
|
const cloud = ref<PartialCloudFragment | undefined>();
|
||||||
const config = ref<Config | undefined>();
|
const config = ref<Config | undefined>();
|
||||||
const connectPluginInstalled = ref<ServerconnectPluginInstalled>('');
|
const connectPluginInstalled = ref<ServerconnectPluginInstalled>('');
|
||||||
@@ -215,6 +216,7 @@ export const useServerStore = defineStore('server', () => {
|
|||||||
const serverAccountPayload = computed((): ServerAccountCallbackSendPayload => {
|
const serverAccountPayload = computed((): ServerAccountCallbackSendPayload => {
|
||||||
return {
|
return {
|
||||||
apiVersion: apiVersion.value,
|
apiVersion: apiVersion.value,
|
||||||
|
caseModel: caseModel.value,
|
||||||
connectPluginVersion: connectPluginVersion.value,
|
connectPluginVersion: connectPluginVersion.value,
|
||||||
description: description.value,
|
description: description.value,
|
||||||
expireTime: expireTime.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?.apiKey !== 'undefined') { apiKey.value = data.apiKey; }
|
||||||
if (typeof data?.apiVersion !== 'undefined') { apiVersion.value = data.apiVersion; }
|
if (typeof data?.apiVersion !== 'undefined') { apiVersion.value = data.apiVersion; }
|
||||||
if (typeof data?.avatar !== 'undefined') { avatar.value = data.avatar; }
|
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?.cloud !== 'undefined') { cloud.value = data.cloud; }
|
||||||
if (typeof data?.config !== 'undefined') { config.value = data.config; }
|
if (typeof data?.config !== 'undefined') { config.value = data.config; }
|
||||||
if (typeof data?.connectPluginInstalled !== 'undefined') { connectPluginInstalled.value = data.connectPluginInstalled; }
|
if (typeof data?.connectPluginInstalled !== 'undefined') { connectPluginInstalled.value = data.connectPluginInstalled; }
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ export interface Server {
|
|||||||
apiKey?: string;
|
apiKey?: string;
|
||||||
apiVersion?: string;
|
apiVersion?: string;
|
||||||
avatar?: string;
|
avatar?: string;
|
||||||
|
caseModel?: string;
|
||||||
cloud?: PartialCloudFragment | undefined;
|
cloud?: PartialCloudFragment | undefined;
|
||||||
config?: Config | undefined;
|
config?: Config | undefined;
|
||||||
connectPluginInstalled?: ServerconnectPluginInstalled;
|
connectPluginInstalled?: ServerconnectPluginInstalled;
|
||||||
@@ -97,6 +98,7 @@ export interface Server {
|
|||||||
|
|
||||||
export interface ServerAccountCallbackSendPayload {
|
export interface ServerAccountCallbackSendPayload {
|
||||||
apiVersion?: string;
|
apiVersion?: string;
|
||||||
|
caseModel?: string;
|
||||||
connectPluginVersion?: string;
|
connectPluginVersion?: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
deviceCount?: number;
|
deviceCount?: number;
|
||||||
|
|||||||
Reference in New Issue
Block a user