Patch up activation view with current Cloudron provision status

This commit is contained in:
Johannes Zellner
2025-03-31 22:56:03 +02:00
parent b2e1d4cc61
commit d718c88353
3 changed files with 122 additions and 18 deletions

View File

@@ -504,6 +504,73 @@ function taskNameFromInstallationState(installationState) {
}
}
// checks provision status and redirects to correct view
// {
// setup: { active, message, errorMessage }
// restore { active, message, errorMessage }
// activated
// adminFqn
// }
// returns true if redirected . currentView is one of dashboard/restore/setup/activation
function redirectIfNeeded(status, currentView) {
var search = decodeURIComponent(window.location.search).slice(1).split('&').map(function (item) { return item.split('='); }).reduce(function (o, k) { o[k[0]] = k[1]; return o; }, {});
if ('develop' in search || localStorage.getItem('develop')) {
console.warn('Cloudron develop mode on. To disable run localStorage.removeItem(\'develop\')');
localStorage.setItem('develop', true);
return false;
}
if (status.activated) {
console.log('Already activated');
if (currentView === 'dashboard') {
// support local development with localhost check
if (window.location.hostname !== status.adminFqdn && window.location.hostname !== 'localhost' && !window.location.hostname.startsWith('192.')) {
// user is accessing by IP or by the old admin location (pre-migration)
window.location.href = '/setup.html' + window.location.search;
return true;
}
return false;
}
window.location.href = 'https://' + status.adminFqdn + '/';
return true;
}
if (status.setup.active) {
console.log('Setup is active');
if (currentView === 'setup') return false;
window.location.href = '/setup.html' + window.location.search;
return true;
}
if (status.restore.active) {
console.log('Restore is active');
if (currentView === 'restore') return;
window.location.href = '/restore.html' + window.location.search;
return true;
}
if (status.adminFqdn) {
console.log('adminFqdn is set');
// if we are here from https://ip/activation.html ,go to https://admin/activation.html
if (status.adminFqdn !== window.location.hostname) {
window.location.href = 'https://' + status.adminFqdn + '/activation.html' + (window.location.search);
return true;
}
if (currentView === 'activation') return false;
window.location.href = 'https://' + status.adminFqdn + '/activation.html' + (window.location.search);
return true;
}
if (currentView === 'dashboard') {
window.location.href = '/setup.html' + window.location.search;
return true;
}
// if we are here, proceed with current view
return false;
}
// named exports
export {
@@ -513,6 +580,7 @@ export {
eventlogDetails,
eventlogSource,
taskNameFromInstallationState,
redirectIfNeeded,
};
// default export
@@ -523,4 +591,5 @@ export default {
eventlogDetails,
eventlogSource,
taskNameFromInstallationState,
redirectIfNeeded,
};