mirror of
https://github.com/unraid/webgui.git
synced 2026-01-05 09:10:07 -06:00
174 lines
5.2 KiB
Plaintext
174 lines
5.2 KiB
Plaintext
Menu="About:20"
|
|
Title="Downgrade OS"
|
|
Icon="icon-update"
|
|
Tag="upload"
|
|
---
|
|
<?php
|
|
/* Copyright 2005-2023, Lime Technology
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License version 2,
|
|
* as published by the Free Software Foundation.
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in
|
|
* all copies or substantial portions of the Software.
|
|
*/
|
|
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';
|
|
|
|
$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>
|
|
const nchan_diagnostics = new NchanSubscriber('/sub/diagnostics', { subscriber: 'websocket' });
|
|
const reportUrl = new URL('https://forums.unraid.net/bug-reports/');
|
|
let diagnosticsFile = '';
|
|
|
|
nchan_diagnostics.on('message', function(data) {
|
|
if (data == '_DONE_') {
|
|
nchan_diagnostics.stop();
|
|
$('.sweet-alert').hide('fast').removeClass('nchan');
|
|
swal.close();
|
|
$('div.spinner').show('slow');
|
|
location = diagnosticsFile;
|
|
|
|
setTimeout(() => {
|
|
cleanupDiagnostics();
|
|
reportAfterDiagnosticsDownload();
|
|
}, 2000);
|
|
} else if (data) {
|
|
let box = $('pre#swaltext');
|
|
box.html(box.html() + '<br>' + data).scrollTop(box[0].scrollHeight);
|
|
}
|
|
});
|
|
|
|
function downloadDiagnostics() {
|
|
const tzoffset = (new Date()).getTimezoneOffset() * 60000; // offset in milliseconds
|
|
const localISOTime = (new Date(Date.now() - tzoffset));
|
|
const year = localISOTime.getFullYear();
|
|
const month = String(localISOTime.getMonth() + 1).padStart(2, '0');
|
|
const day = String(localISOTime.getDate()).padStart(2, '0');
|
|
const hours = String(localISOTime.getHours()).padStart(2, '0');
|
|
const minutes = String(localISOTime.getMinutes()).padStart(2, '0');
|
|
const dateOutput = `${year}${month}${day}_${hours}${minutes}`;
|
|
const zipName = '<?=$serverNameEscaped?>-diagnostics-' + dateOutput + '.zip';
|
|
|
|
nchan_diagnostics.start();
|
|
|
|
$.post(
|
|
'/webGui/include/Download.php',
|
|
{
|
|
cmd: 'diag',
|
|
file: zipName,
|
|
anonymize: '',
|
|
},
|
|
function(zip) {
|
|
if (!zip) {
|
|
return nchan_diagnostics.stop();
|
|
}
|
|
|
|
diagnosticsFile = zip;
|
|
swal({
|
|
title: "_(Downloading)_...",
|
|
text: "/boot/logs" + zip + "<hr><pre id='swaltext'></pre>",
|
|
html: true,
|
|
animation: 'none',
|
|
showConfirmButton: false,
|
|
});
|
|
$('.sweet-alert').addClass('nchan');
|
|
$('button.confirm').prop('disabled', true);
|
|
},
|
|
);
|
|
}
|
|
|
|
function reportAfterDiagnosticsDownload() {
|
|
$('div.spinner').hide('fast');
|
|
swal({
|
|
title: "_(Open a bug report)_",
|
|
text: "_(Create a bug report on our forums with a description of the issue along with your diagsnotics)_",
|
|
html: true,
|
|
type: 'warning',
|
|
showCancelButton: true,
|
|
confirmButtonText: "<?= _('Create Bug Report') ?>",
|
|
cancelButtonText: "<?= _('Close') ?>",
|
|
}, function(confirm) {
|
|
if (!confirm) {
|
|
return false;
|
|
}
|
|
window.open(reportUrl, '_blank');
|
|
});
|
|
}
|
|
|
|
function cleanupDiagnostics() {
|
|
if (document.hasFocus()) {
|
|
return $.post('/webGui/include/Download.php', { cmd: 'delete', file: diagnosticsFile });
|
|
}
|
|
setTimeout(cleanupDiagnostics, 2000);
|
|
}
|
|
|
|
function startDowngrade() {
|
|
$('div.spinner').show('slow');
|
|
|
|
$.get(
|
|
'/plugins/dynamix.plugin.manager/include/Downgrade.php',
|
|
{
|
|
version: '<?=$restoreVersion?>',
|
|
},
|
|
function() {
|
|
refresh();
|
|
}
|
|
);
|
|
}
|
|
|
|
function confirmDowngrade() {
|
|
swal({
|
|
title: "_(Confirm Downgrade)_",
|
|
text: "<?= $restoreVersion ?><br>_(A reboot will be required)_",
|
|
html: true,
|
|
type: 'warning',
|
|
showCancelButton: true,
|
|
confirmButtonText: "<?= _('Confirm') ?>",
|
|
cancelButtonText: "<?= _('Cancel') ?>",
|
|
}, function(confirm) {
|
|
if (!confirm) {
|
|
return false;
|
|
}
|
|
startDowngrade();
|
|
});
|
|
}
|
|
</script>
|
|
|
|
<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>
|
|
</unraid-i18n-host>
|