refactor(web): state consolidation

This commit is contained in:
Zack Spear
2023-11-06 13:13:53 -08:00
parent fe906c025e
commit bb60cbbc18
3 changed files with 58 additions and 21 deletions

View File

@@ -2,17 +2,6 @@
$docroot = $docroot ?? $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
require_once("$docroot/plugins/dynamix.my.servers/include/state.php");
require_once("$docroot/plugins/dynamix.my.servers/include/translations.php");
/**
* Reboot detection
*/
$readme = @file_get_contents("$docroot/plugins/unRAIDServer/README.md",false,null,0,20)?:''; // read first 20 bytes of README.md
$reboot = preg_match("/^\*\*(REBOOT REQUIRED|DOWNGRADE)/", $readme);
$rebootForDowngrade = $reboot && strpos($readme, 'DOWNGRADE') !== false;
$rebootForUpgrade = $reboot && strpos($readme, 'REBOOT REQUIRED') !== false;
$rebootType = $rebootForDowngrade ? 'downgrade' : ($rebootForUpgrade ? 'upgrade' : '');
?>
<script>
window.LOCALE_DATA = '<?= rawurlencode(json_encode($webComponentTranslations, JSON_UNESCAPED_SLASHES, JSON_UNESCAPED_UNICODE)) ?>';
@@ -32,7 +21,5 @@ if (!document.getElementsByTagName(modalsWebComponent).length) {
<?
echo "
<unraid-i18n-host>
<unraid-user-profile
reboot-type='" . $rebootType . "'
server='" . json_encode($serverState) . "'></unraid-user-profile>
<unraid-user-profile server='" . json_encode($serverState) . "'></unraid-user-profile>
</unraid-i18n-host>";

View File

@@ -31,6 +31,61 @@ $configErrorEnum = [
$osVersionBranch = trim(@exec('plugin category /var/log/plugins/unRAIDServer.plg') ?? 'stable');
$registered = !empty($myservers['remote']['apikey']) && $connectPluginInstalled;
/**
* Reboot detection
*/
$rebootReadme = @file_get_contents("$docroot/plugins/unRAIDServer/README.md",false,null,0,20)?:''; // read first 20 bytes of README.md
$rebootDetected = preg_match("/^\*\*(REBOOT REQUIRED|DOWNGRADE)/", $rebootReadme);
$rebootForDowngrade = $rebootDetected && strpos($rebootReadme, 'DOWNGRADE') !== false;
$rebootForUpdate = $rebootDetected && strpos($rebootReadme, 'REBOOT REQUIRED') !== false;
$rebootType = $rebootForDowngrade ? 'downgrade' : ($rebootForUpdate ? 'update' : '');
$rebootVersion = '';
/**
* Detect if third-party drivers were part of the update process
*/
$processWaitingThirdParthDrivers = "inotifywait -q /boot/changes.txt -e move_self,delete_self";
// Run the ps command to list processes and check if the process is running
$ps_command = "ps aux | grep -E \"$processWaitingThirdParthDrivers\" | grep -v \"grep -E\"";
$output = shell_exec($ps_command) ?? '';
if (strpos($output, $processWaitingThirdParthDrivers) !== false) {
$rebootType = 'thirdPartyDriversDownloading';
}
function rebootExtractVersion() {
$file_path = '/boot/changes.txt';
// Check if the file exists
if (file_exists($file_path)) {
// Open the file for reading
$file = fopen($file_path, 'r');
// Read the file line by line until we find a line that starts with '# Version'
while (($line = fgets($file)) !== false) {
if (strpos($line, '# Version') === 0) {
// Use a regular expression to extract the full version string
if (preg_match('/# Version\s+(\S+)/', $line, $matches)) {
$fullVersion = $matches[1];
return $fullVersion;
} else {
return 'Not found';
}
break;
}
}
// Close the file
fclose($file);
} else {
return 'File not found';
}
}
if ($rebootType === 'downgrade' || $rebootType === 'update') {
$rebootVersion = rebootExtractVersion();
}
$serverState = [
"apiKey" => $myservers['upc']['apikey'] ?? '',
"apiVersion" => $myservers['api']['version'] ?? '',
@@ -66,6 +121,8 @@ $serverState = [
"osVersion" => $var['version'],
"osVersionBranch" => $osVersionBranch,
"protocol" => $_SERVER['REQUEST_SCHEME'],
"rebootType" => $rebootType,
"rebootVersion" => $rebootVersion,
"regDev" => @(int)$var['regDev'] ?? 0,
"regGen" => @(int)$var['regGen'],
"regGuid" => @$var['regGUID'] ?? '',

View File

@@ -15,7 +15,6 @@ import 'tailwindcss/tailwind.css';
import '~/assets/main.css';
export interface Props {
rebootType?: 'downgrade' | 'upgrade' | '';
server?: Server | string;
}
const props = defineProps<Props>();
@@ -27,7 +26,6 @@ const dropdownStore = useDropdownStore();
const replaceRenewCheckStore = useReplaceRenewStore();
const serverStore = useServerStore();
const updateOsStore = useUpdateOsStore();
const updateOsActionsStore = useUpdateOsActionsStore();
const { callbackData } = storeToRefs(useCallbackActionsStore());
const { dropdownVisible } = storeToRefs(dropdownStore);
@@ -96,11 +94,6 @@ onBeforeMount(() => {
// look for any callback params
callbackStore.watcher();
// see if we've started the downgrade or upgrade and need to display a reboot message
if (props.rebootType) {
updateOsActionsStore.setRebootType(props.rebootType);
}
if (guid.value && keyfile.value) {
if (callbackData.value) {
return console.debug('Renew callback detected, skipping auto check for key replacement, renewal eligibility, and OS Update.');