feat: web component enhancements

This commit is contained in:
Zack Spear
2024-05-14 16:16:26 -07:00
parent 7f77338b3d
commit 45308bc7cb
10 changed files with 274 additions and 119 deletions

View File

@@ -13,37 +13,17 @@ Tag="upload"
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*/
/**
* @note icon-update is rotated via CSS in myservers1.php
*/
require_once "$docroot/plugins/dynamix.my.servers/include/reboot-details.php";
// Create an instance of the RebootDetails class
$rebootDetails = new RebootDetails();
/**
* @note icon-update is rotated via CSS in myservers1.php
*
* If /boot/previous/bzroot exists, then the user has the option to downgrade to the previous version.
* Parse the text file /boot/previous/changes.txt to get the version number of the previous version.
* Then we move some files around and reboot.
*/
$restoreVersion = $restoreBranch = $restoreVersionReleaseDate = 'unknown';
$restoreExists = file_exists('/boot/previous/bzroot');
$restoreChangelogPath = '/boot/previous/changes.txt';
// Get the current reboot details if there are any
$rebootDetails->setPrevious();
$serverNameEscaped = htmlspecialchars(str_replace(' ', '_', strtolower($var['NAME'])));
if (file_exists($restoreChangelogPath)) {
exec("head -n4 $restoreChangelogPath", $rows);
foreach ($rows as $row) {
$i = stripos($row,'version');
if ($i !== false) {
[$restoreVersion, $restoreVersionReleaseDate] = explode(' ', trim(substr($row, $i+7)));
break;
}
}
$restoreBranch = strpos($restoreVersion, 'rc') !== false
? _('Next')
: (strpos($restoreVersion, 'beta') !== false
? _('Beta')
: _('Stable'));
}
?>
<script>
@@ -139,7 +119,7 @@ function startDowngrade() {
$.get(
'/plugins/dynamix.plugin.manager/include/Downgrade.php',
{
version: '<?=$restoreVersion?>',
version: '<?= $rebootDetails->previousVersion ?>',
},
function() {
refresh();
@@ -150,7 +130,7 @@ function startDowngrade() {
function confirmDowngrade() {
swal({
title: "_(Confirm Downgrade)_",
text: "<?= $restoreVersion ?><br>_(A reboot will be required)_",
text: "<?= $rebootDetails->previousVersion ?><br>_(A reboot will be required)_",
html: true,
type: 'warning',
showCancelButton: true,
@@ -167,7 +147,7 @@ function confirmDowngrade() {
<unraid-i18n-host>
<unraid-downgrade-os
reboot-version="<?= $rebootDetails->getRebootVersion() ?>"
restore-version="<?= $restoreExists && $restoreVersion != 'unknown' ? $restoreVersion : '' ?>"
restore-release-date="<?= $restoreExists && $restoreVersionReleaseDate != 'unknown' ? $restoreVersionReleaseDate : '' ?>"></unraid-downgrade-os>
reboot-version="<?= $rebootDetails->rebootVersion ?>"
restore-version="<?= $rebootDetails->previousVersion ?>"
restore-release-date="<?= $rebootDetails->previousReleaseDate ?>"></unraid-downgrade-os>
</unraid-i18n-host>

View File

@@ -46,5 +46,5 @@ function flashBackup() {
</script>
<unraid-i18n-host>
<unraid-update-os reboot-version="<?= $rebootDetails->getRebootVersion() ?>"></unraid-update-os>
<unraid-update-os reboot-version="<?= $rebootDetails->rebootVersion ?>"></unraid-update-os>
</unraid-i18n-host>

View File

@@ -37,7 +37,7 @@ class UnraidOsCheck
private const JSON_FILE_IGNORED = '/tmp/unraidcheck/ignored.json';
private const JSON_FILE_IGNORED_KEY = 'updateOsIgnoredReleases';
private const JSON_FILE_RESULT = '/tmp/unraidcheck/result.json';
private const PLG_PATH = '/var/log/plugins/unRAIDServer.plg';
private const PLG_PATH = '/usr/local/emhttp/plugins/unRAIDServer/unRAIDServer.plg';
public function __construct()
{
@@ -124,7 +124,7 @@ class UnraidOsCheck
if ($parsedAltUrl) $params['altUrl'] = $parsedAltUrl;
$urlbase = $parsedAltUrl ?? $defaultUrl;
$url = $urlbase.'?'.http_build_query($params);
$url = $urlbase.'?'.http_build_query($params);
$curlinfo = [];
$response = http_get_contents($url,[],$curlinfo);
if (array_key_exists('error', $curlinfo)) {
@@ -258,4 +258,4 @@ $isGetRequest = !empty($_SERVER) && isset($_SERVER['REQUEST_METHOD']) && $_SERVE
$getHasAction = $_GET !== null && !empty($_GET) && isset($_GET['action']);
if ($isGetRequest && $getHasAction) {
new UnraidOsCheck();
}
}

View File

@@ -0,0 +1,60 @@
<?php
class UnraidUpdateCancel
{
private $PLG_FILENAME;
private $PLG_BOOT;
private $PLG_VAR;
private $USR_LOCAL_PLUGIN_UNRAID_PATH;
public function __construct() {
$this->PLG_FILENAME = "unRAIDServer.plg";
$this->PLG_BOOT = "/boot/config/plugins/{$this->PLG_FILENAME}";
$this->PLG_VAR = "/var/log/plugins/{$this->PLG_FILENAME}";
$this->USR_LOCAL_PLUGIN_UNRAID_PATH = "/usr/local/emhttp/plugins/unRAIDServer";
// Handle the cancellation
$revertResult = $this->revertFiles();
// Return JSON response for front-end client
$statusCode = $revertResult['success'] ? 200 : 500;
http_response_code($statusCode);
header('Content-Type: application/json');
echo json_encode($revertResult);
}
public function revertFiles() {
try {
$command = '/sbin/mount | grep -q "/boot/previous/bz"';
exec($command, $output, $returnCode);
if ($returnCode !== 0) {
return ['success' => true]; // Nothing to revert
}
// Clear the results of previous unraidcheck run
@unlink("/tmp/unraidcheck/result.json");
// Revert changes made by unRAIDServer.plg
shell_exec("mv -f /boot/previous/* /boot");
unlink($this->PLG_BOOT);
unlink($this->PLG_VAR);
symlink("{$this->USR_LOCAL_PLUGIN_UNRAID_PATH}/{$this->PLG_FILENAME}", $this->PLG_VAR);
// Restore README.md by echoing the content into the file
$readmeFile = "{$this->USR_LOCAL_PLUGIN_UNRAID_PATH}/README.md";
$readmeContent = "**Unraid OS**\n\n";
$readmeContent .= "Unraid OS by [Lime Technology, Inc.](https://lime-technology.com).\n";
file_put_contents($readmeFile, $readmeContent);
return ['success' => true]; // Upgrade handled successfully
} catch (\Throwable $th) {
return [
'success' => false,
'message' => $th->getMessage(),
];
}
}
}
// Self instantiate the class and handle the cancellation
new UnraidUpdateCancel();