diff --git a/dashboard/src/models/CloudronModel.js b/dashboard/src/models/CloudronModel.js
index 6ab5cf777..2297a21d7 100644
--- a/dashboard/src/models/CloudronModel.js
+++ b/dashboard/src/models/CloudronModel.js
@@ -84,6 +84,17 @@ function create() {
if (error || result.status !== 200) return [error || result];
return [null];
},
+ async provisionStatus() {
+ let error, result;
+ try {
+ result = await fetcher.get(`${API_ORIGIN}/api/v1/provision/status`, {});
+ } catch (e) {
+ error = e;
+ }
+
+ if (error || result.status !== 200) return [error || result];
+ return [null, result.body];
+ },
async createAdmin(data) {
let error, result;
try {
diff --git a/dashboard/src/utils.js b/dashboard/src/utils.js
index e34abdc23..f33c35298 100644
--- a/dashboard/src/utils.js
+++ b/dashboard/src/utils.js
@@ -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,
};
diff --git a/dashboard/src/views/ActivationView.vue b/dashboard/src/views/ActivationView.vue
index 6c81079bd..754f7af2c 100644
--- a/dashboard/src/views/ActivationView.vue
+++ b/dashboard/src/views/ActivationView.vue
@@ -1,8 +1,9 @@
@@ -69,38 +90,41 @@ async function onOwnerSubmit() {
Welcome to Cloudron
Set up Admin Account
- {{ error.generic }}
+ {{ formError.generic }}
-
-
+