2018-01-22 13:01:38 -08:00
|
|
|
'use strict';
|
|
|
|
|
|
2022-12-24 11:10:04 +01:00
|
|
|
/* global $, angular, tld, SECRET_PLACEHOLDER, STORAGE_PROVIDERS, BACKUP_FORMATS */
|
2022-09-27 13:31:13 +02:00
|
|
|
/* global REGIONS_S3, REGIONS_WASABI, REGIONS_DIGITALOCEAN, REGIONS_EXOSCALE, REGIONS_SCALEWAY, REGIONS_LINODE, REGIONS_OVH, REGIONS_IONOS, REGIONS_UPCLOUD, REGIONS_VULTR */
|
2018-01-22 13:01:38 -08:00
|
|
|
|
|
|
|
|
// create main application module
|
2020-11-08 10:48:30 +01:00
|
|
|
var app = angular.module('Application', ['pascalprecht.translate', 'ngCookies', 'angular-md5', 'ui-notification', 'ui.bootstrap']);
|
2018-01-22 13:01:38 -08:00
|
|
|
|
|
|
|
|
app.filter('zoneName', function () {
|
|
|
|
|
return function (domain) {
|
|
|
|
|
return tld.getDomain(domain);
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
2019-09-05 22:22:42 +02:00
|
|
|
app.controller('RestoreController', ['$scope', 'Client', function ($scope, Client) {
|
2018-01-22 13:01:38 -08:00
|
|
|
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; }, {});
|
|
|
|
|
|
2019-09-05 22:22:42 +02:00
|
|
|
$scope.client = Client;
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.busy = false;
|
|
|
|
|
$scope.error = {};
|
2018-12-15 16:08:44 -08:00
|
|
|
$scope.message = ''; // progress
|
2020-05-16 11:19:47 -07:00
|
|
|
|
|
|
|
|
// variables here have to match the import config logic!
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.provider = '';
|
|
|
|
|
$scope.bucket = '';
|
|
|
|
|
$scope.prefix = '';
|
2021-01-07 19:41:39 +01:00
|
|
|
$scope.mountPoint = '';
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.accessKeyId = '';
|
|
|
|
|
$scope.secretAccessKey = '';
|
|
|
|
|
$scope.gcsKey = { keyFileName: '', content: '' };
|
|
|
|
|
$scope.region = '';
|
|
|
|
|
$scope.endpoint = '';
|
|
|
|
|
$scope.backupFolder = '';
|
2022-04-05 09:41:09 -07:00
|
|
|
$scope.remotePath = '';
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.instanceId = '';
|
|
|
|
|
$scope.acceptSelfSignedCerts = false;
|
|
|
|
|
$scope.format = 'tgz';
|
2019-11-11 11:07:52 -08:00
|
|
|
$scope.advancedVisible = false;
|
2020-05-12 22:24:03 -07:00
|
|
|
$scope.password = '';
|
2022-06-27 09:02:44 -07:00
|
|
|
$scope.encryptedFilenames = true;
|
2020-05-15 00:32:49 +02:00
|
|
|
$scope.encrypted = false; // only used if a backup config contains that flag
|
2020-12-21 22:36:43 -08:00
|
|
|
$scope.setupToken = '';
|
2021-02-24 15:16:29 -08:00
|
|
|
$scope.skipDnsSetup = false;
|
2019-11-11 11:07:52 -08:00
|
|
|
|
2021-05-27 15:01:44 -07:00
|
|
|
$scope.mountOptions = {
|
|
|
|
|
host: '',
|
|
|
|
|
remoteDir: '',
|
|
|
|
|
username: '',
|
|
|
|
|
password: '',
|
2021-05-27 15:31:37 -07:00
|
|
|
diskPath: '',
|
|
|
|
|
user: '',
|
2022-01-10 16:30:12 +01:00
|
|
|
seal: false,
|
2021-05-27 15:31:37 -07:00
|
|
|
port: 22,
|
|
|
|
|
privateKey: ''
|
2021-05-27 15:01:44 -07:00
|
|
|
};
|
|
|
|
|
|
2019-11-11 11:07:52 -08:00
|
|
|
$scope.sysinfo = {
|
|
|
|
|
provider: 'generic',
|
2022-05-02 12:02:52 +02:00
|
|
|
ipv4: '',
|
2019-11-11 11:07:52 -08:00
|
|
|
ifname: ''
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.sysinfoProvider = [
|
|
|
|
|
{ name: 'Public IP', value: 'generic' },
|
|
|
|
|
{ name: 'Static IP Address', value: 'fixed' },
|
|
|
|
|
{ name: 'Network Interface', value: 'network-interface' }
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$scope.prettySysinfoProviderName = function (provider) {
|
|
|
|
|
switch (provider) {
|
|
|
|
|
case 'generic': return 'Public IP';
|
|
|
|
|
case 'fixed': return 'Static IP Address';
|
|
|
|
|
case 'network-interface': return 'Network Interface';
|
|
|
|
|
default: return 'Unknown';
|
|
|
|
|
}
|
|
|
|
|
};
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2022-09-27 13:31:13 +02:00
|
|
|
$scope.s3Regions = REGIONS_S3;
|
|
|
|
|
$scope.wasabiRegions = REGIONS_WASABI;
|
|
|
|
|
$scope.doSpacesRegions = REGIONS_DIGITALOCEAN;
|
|
|
|
|
$scope.exoscaleSosRegions = REGIONS_EXOSCALE;
|
|
|
|
|
$scope.scalewayRegions = REGIONS_SCALEWAY;
|
|
|
|
|
$scope.linodeRegions = REGIONS_LINODE;
|
|
|
|
|
$scope.ovhRegions = REGIONS_OVH;
|
|
|
|
|
$scope.ionosRegions = REGIONS_IONOS;
|
|
|
|
|
$scope.upcloudRegions = REGIONS_UPCLOUD;
|
|
|
|
|
$scope.vultrRegions = REGIONS_VULTR;
|
2019-01-23 18:04:43 -08:00
|
|
|
|
2022-12-24 11:10:04 +01:00
|
|
|
$scope.storageProviders = STORAGE_PROVIDERS;
|
2020-04-29 12:54:19 -07:00
|
|
|
|
2022-09-27 13:31:13 +02:00
|
|
|
$scope.formats = BACKUP_FORMATS;
|
2018-01-22 13:01:38 -08:00
|
|
|
|
|
|
|
|
$scope.s3like = function (provider) {
|
2019-07-30 10:42:18 -07:00
|
|
|
return provider === 's3' || provider === 'minio' || provider === 's3-v4-compat' || provider === 'exoscale-sos'
|
2020-02-26 09:08:34 -08:00
|
|
|
|| provider === 'digitalocean-spaces' || provider === 'wasabi' || provider === 'scaleway-objectstorage'
|
2022-09-27 19:40:58 +02:00
|
|
|
|| provider === 'linode-objectstorage' || provider === 'ovh-objectstorage' || provider === 'backblaze-b2' || provider === 'cloudflare-r2'
|
2023-01-10 11:16:09 +01:00
|
|
|
|| provider === 'ionos-objectstorage' || provider === 'vultr-objectstorage' || provider === 'upcloud-objectstorage' || provider === 'idrive-e2';
|
2018-01-22 13:01:38 -08:00
|
|
|
};
|
|
|
|
|
|
2021-01-07 19:41:39 +01:00
|
|
|
$scope.mountlike = function (provider) {
|
2022-06-08 10:38:54 -07:00
|
|
|
return provider === 'sshfs' || provider === 'cifs' || provider === 'nfs' || provider === 'mountpoint' || provider === 'ext4' || provider === 'xfs';
|
2021-01-07 19:41:39 +01:00
|
|
|
};
|
|
|
|
|
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.restore = function () {
|
|
|
|
|
$scope.error = {};
|
|
|
|
|
$scope.busy = true;
|
|
|
|
|
|
|
|
|
|
var backupConfig = {
|
|
|
|
|
provider: $scope.provider,
|
2020-12-21 22:36:43 -08:00
|
|
|
format: $scope.format,
|
2018-01-22 13:01:38 -08:00
|
|
|
};
|
2022-06-27 09:02:44 -07:00
|
|
|
if ($scope.password) {
|
|
|
|
|
backupConfig.password = $scope.password;
|
|
|
|
|
backupConfig.encryptedFilenames = $scope.encryptedFilenames;
|
|
|
|
|
}
|
2018-01-22 13:01:38 -08:00
|
|
|
|
|
|
|
|
// only set provider specific fields, this will clear them in the db
|
|
|
|
|
if ($scope.s3like(backupConfig.provider)) {
|
|
|
|
|
backupConfig.bucket = $scope.bucket;
|
|
|
|
|
backupConfig.prefix = $scope.prefix;
|
|
|
|
|
backupConfig.accessKeyId = $scope.accessKeyId;
|
|
|
|
|
backupConfig.secretAccessKey = $scope.secretAccessKey;
|
|
|
|
|
|
|
|
|
|
if ($scope.endpoint) backupConfig.endpoint = $scope.endpoint;
|
|
|
|
|
|
|
|
|
|
if (backupConfig.provider === 's3') {
|
|
|
|
|
if ($scope.region) backupConfig.region = $scope.region;
|
2018-07-30 07:29:20 -07:00
|
|
|
delete backupConfig.endpoint;
|
2018-01-22 13:01:38 -08:00
|
|
|
} else if (backupConfig.provider === 'minio' || backupConfig.provider === 's3-v4-compat') {
|
2020-07-05 10:58:20 -07:00
|
|
|
backupConfig.region = backupConfig.region || 'us-east-1';
|
2018-01-22 13:01:38 -08:00
|
|
|
backupConfig.acceptSelfSignedCerts = $scope.acceptSelfSignedCerts;
|
2020-07-05 10:58:20 -07:00
|
|
|
backupConfig.s3ForcePathStyle = true; // might want to expose this in the UI
|
2018-01-22 13:01:38 -08:00
|
|
|
} else if (backupConfig.provider === 'exoscale-sos') {
|
|
|
|
|
backupConfig.region = 'us-east-1';
|
2018-02-02 16:29:08 -08:00
|
|
|
backupConfig.signatureVersion = 'v4';
|
2019-07-30 10:42:18 -07:00
|
|
|
} else if (backupConfig.provider === 'wasabi') {
|
2020-05-19 14:52:40 +02:00
|
|
|
backupConfig.region = $scope.wasabiRegions.find(function (x) { return x.value === $scope.endpoint; }).region;
|
2019-07-30 10:42:18 -07:00
|
|
|
backupConfig.signatureVersion = 'v4';
|
2019-06-21 11:06:50 -07:00
|
|
|
} else if (backupConfig.provider === 'scaleway-objectstorage') {
|
|
|
|
|
backupConfig.region = $scope.scalewayRegions.find(function (x) { return x.value === $scope.endpoint; }).region;
|
|
|
|
|
backupConfig.signatureVersion = 'v4';
|
2020-02-26 09:08:34 -08:00
|
|
|
} else if (backupConfig.provider === 'linode-objectstorage') {
|
|
|
|
|
backupConfig.region = $scope.linodeRegions.find(function (x) { return x.value === $scope.endpoint; }).region;
|
|
|
|
|
backupConfig.signatureVersion = 'v4';
|
2020-04-29 12:54:19 -07:00
|
|
|
} else if (backupConfig.provider === 'ovh-objectstorage') {
|
|
|
|
|
backupConfig.region = $scope.ovhRegions.find(function (x) { return x.value === $scope.endpoint; }).region;
|
|
|
|
|
backupConfig.signatureVersion = 'v4';
|
2021-02-04 10:14:42 -08:00
|
|
|
} else if (backupConfig.provider === 'ionos-objectstorage') {
|
|
|
|
|
backupConfig.region = $scope.ionosRegions.find(function (x) { return x.value === $scope.endpoint; }).region;
|
|
|
|
|
backupConfig.signatureVersion = 'v4';
|
2021-06-16 22:35:46 -07:00
|
|
|
} else if (backupConfig.provider === 'vultr-objectstorage') {
|
|
|
|
|
backupConfig.region = $scope.vultrRegions.find(function (x) { return x.value === $scope.endpoint; }).region;
|
|
|
|
|
backupConfig.signatureVersion = 'v4';
|
2021-09-27 10:01:09 -07:00
|
|
|
} else if (backupConfig.provider === 'upcloud-objectstorage') {
|
|
|
|
|
var m = /^.*\.(.*)\.upcloudobjects.com$/.exec(backupConfig.endpoint);
|
|
|
|
|
backupConfig.region = m ? m[1] : 'us-east-1'; // let it fail in validation phase if m is not valid
|
|
|
|
|
backupConfig.signatureVersion = 'v4';
|
2018-01-22 13:01:38 -08:00
|
|
|
} else if (backupConfig.provider === 'digitalocean-spaces') {
|
|
|
|
|
backupConfig.region = 'us-east-1';
|
|
|
|
|
}
|
|
|
|
|
} else if (backupConfig.provider === 'gcs') {
|
|
|
|
|
backupConfig.bucket = $scope.bucket;
|
|
|
|
|
backupConfig.prefix = $scope.prefix;
|
|
|
|
|
try {
|
|
|
|
|
var serviceAccountKey = JSON.parse($scope.gcsKey.content);
|
|
|
|
|
backupConfig.projectId = serviceAccountKey.project_id;
|
|
|
|
|
backupConfig.credentials = {
|
|
|
|
|
client_email: serviceAccountKey.client_email,
|
|
|
|
|
private_key: serviceAccountKey.private_key
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (!backupConfig.projectId || !backupConfig.credentials || !backupConfig.credentials.client_email || !backupConfig.credentials.private_key) {
|
|
|
|
|
throw 'fields_missing';
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
$scope.error.generic = 'Cannot parse Google Service Account Key: ' + e.message;
|
|
|
|
|
$scope.error.gcsKeyInput = true;
|
|
|
|
|
$scope.busy = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-05-27 15:01:44 -07:00
|
|
|
} else if ($scope.mountlike(backupConfig.provider)) {
|
2021-01-07 19:41:39 +01:00
|
|
|
backupConfig.prefix = $scope.prefix;
|
2021-05-27 15:01:44 -07:00
|
|
|
backupConfig.mountOptions = {};
|
|
|
|
|
|
|
|
|
|
if (backupConfig.provider === 'cifs' || backupConfig.provider === 'sshfs' || backupConfig.provider === 'nfs') {
|
|
|
|
|
backupConfig.mountOptions.host = $scope.mountOptions.host;
|
|
|
|
|
backupConfig.mountOptions.remoteDir = $scope.mountOptions.remoteDir;
|
|
|
|
|
|
|
|
|
|
if (backupConfig.provider === 'cifs') {
|
|
|
|
|
backupConfig.mountOptions.username = $scope.mountOptions.username;
|
|
|
|
|
backupConfig.mountOptions.password = $scope.mountOptions.password;
|
2022-01-10 16:30:12 +01:00
|
|
|
backupConfig.mountOptions.seal = $scope.mountOptions.seal;
|
2021-05-27 15:31:37 -07:00
|
|
|
} else if (backupConfig.provider === 'sshfs') {
|
|
|
|
|
backupConfig.mountOptions.user = $scope.mountOptions.user;
|
|
|
|
|
backupConfig.mountOptions.port = $scope.mountOptions.port;
|
|
|
|
|
backupConfig.mountOptions.privateKey = $scope.mountOptions.privateKey;
|
2021-05-27 15:01:44 -07:00
|
|
|
}
|
2022-06-08 10:38:54 -07:00
|
|
|
} else if (backupConfig.provider === 'ext4' || backupConfig.provider === 'xfs') {
|
2022-01-26 13:00:30 -08:00
|
|
|
backupConfig.mountOptions.diskPath = $scope.mountOptions.diskPath;
|
2021-06-22 14:29:51 -07:00
|
|
|
} else if (backupConfig.provider === 'mountpoint') {
|
|
|
|
|
backupConfig.mountPoint = $scope.mountPoint;
|
2021-05-27 15:01:44 -07:00
|
|
|
}
|
2021-06-22 14:29:51 -07:00
|
|
|
} else if (backupConfig.provider === 'filesystem') {
|
2022-01-26 11:22:18 +01:00
|
|
|
backupConfig.backupFolder = $scope.backupFolder;
|
2018-01-22 13:01:38 -08:00
|
|
|
}
|
|
|
|
|
|
2022-04-05 09:41:09 -07:00
|
|
|
if ($scope.remotePath.indexOf('/') === -1) {
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.error.generic = 'Backup id must include the directory path';
|
2022-04-05 09:41:09 -07:00
|
|
|
$scope.error.remotePath = true;
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.busy = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-05 09:41:09 -07:00
|
|
|
if ($scope.remotePath.indexOf('box') === -1) {
|
2019-11-11 16:21:27 -08:00
|
|
|
$scope.error.generic = 'Backup id must contain "box"';
|
2022-04-05 09:41:09 -07:00
|
|
|
$scope.error.remotePath = true;
|
2019-11-11 09:46:47 -08:00
|
|
|
$scope.busy = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-05 09:41:09 -07:00
|
|
|
var version = $scope.remotePath.match(/_v(\d+.\d+.\d+)/);
|
2018-01-22 13:01:38 -08:00
|
|
|
if (!version) {
|
|
|
|
|
$scope.error.generic = 'Backup id is missing version information';
|
2022-04-05 09:41:09 -07:00
|
|
|
$scope.error.remotePath = true;
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.busy = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-11 11:07:52 -08:00
|
|
|
var sysinfoConfig = {
|
|
|
|
|
provider: $scope.sysinfo.provider
|
|
|
|
|
};
|
|
|
|
|
if ($scope.sysinfo.provider === 'fixed') {
|
2022-05-02 12:02:52 +02:00
|
|
|
sysinfoConfig.ipv4 = $scope.sysinfo.ipv4;
|
2019-11-11 11:07:52 -08:00
|
|
|
} else if ($scope.sysinfo.provider === 'network-interface') {
|
2019-11-11 16:06:29 -08:00
|
|
|
sysinfoConfig.ifname = $scope.sysinfo.ifname;
|
2019-11-11 11:07:52 -08:00
|
|
|
}
|
|
|
|
|
|
2022-04-05 09:41:09 -07:00
|
|
|
Client.restore(backupConfig, $scope.remotePath.replace(/\.tar\.gz(\.enc)?$/, ''), version ? version[1] : '', sysinfoConfig, $scope.skipDnsSetup, $scope.setupToken, function (error) {
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.busy = false;
|
|
|
|
|
|
|
|
|
|
if (error) {
|
2018-09-10 10:36:32 -07:00
|
|
|
if (error.statusCode === 424) {
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.error.generic = error.message;
|
|
|
|
|
|
|
|
|
|
if (error.message.indexOf('AWS Access Key Id') !== -1) {
|
|
|
|
|
$scope.error.accessKeyId = true;
|
|
|
|
|
$scope.accessKeyId = '';
|
|
|
|
|
$scope.configureBackupForm.accessKeyId.$setPristine();
|
|
|
|
|
$('#inputConfigureBackupAccessKeyId').focus();
|
|
|
|
|
} else if (error.message.indexOf('not match the signature') !== -1 ) {
|
|
|
|
|
$scope.error.secretAccessKey = true;
|
|
|
|
|
$scope.secretAccessKey = '';
|
|
|
|
|
$scope.configureBackupForm.secretAccessKey.$setPristine();
|
|
|
|
|
$('#inputConfigureBackupSecretAccessKey').focus();
|
|
|
|
|
} else if (error.message.toLowerCase() === 'access denied') {
|
|
|
|
|
$scope.error.bucket = true;
|
|
|
|
|
$scope.bucket = '';
|
|
|
|
|
$scope.configureBackupForm.bucket.$setPristine();
|
|
|
|
|
$('#inputConfigureBackupBucket').focus();
|
|
|
|
|
} else if (error.message.indexOf('ECONNREFUSED') !== -1) {
|
|
|
|
|
$scope.error.generic = 'Unknown region';
|
|
|
|
|
$scope.error.region = true;
|
|
|
|
|
$scope.configureBackupForm.region.$setPristine();
|
2018-04-10 18:05:35 +02:00
|
|
|
$('#inputConfigureBackupDORegion').focus();
|
2018-01-22 13:01:38 -08:00
|
|
|
} else if (error.message.toLowerCase() === 'wrong region') {
|
|
|
|
|
$scope.error.generic = 'Wrong S3 Region';
|
|
|
|
|
$scope.error.region = true;
|
|
|
|
|
$scope.configureBackupForm.region.$setPristine();
|
2018-04-10 18:05:35 +02:00
|
|
|
$('#inputConfigureBackupS3Region').focus();
|
2018-01-22 13:01:38 -08:00
|
|
|
} else {
|
|
|
|
|
$('#inputConfigureBackupBucket').focus();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$scope.error.generic = error.message;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
waitForRestore();
|
|
|
|
|
});
|
2019-11-11 09:49:41 -08:00
|
|
|
};
|
2018-01-22 13:01:38 -08:00
|
|
|
|
|
|
|
|
function waitForRestore() {
|
|
|
|
|
$scope.busy = true;
|
|
|
|
|
|
|
|
|
|
Client.getStatus(function (error, status) {
|
2018-12-14 15:24:00 -08:00
|
|
|
if (!error && !status.restore.active) { // restore finished
|
|
|
|
|
if (status.restore.errorMessage) {
|
2018-07-29 20:33:21 -07:00
|
|
|
$scope.busy = false;
|
2018-12-14 15:24:00 -08:00
|
|
|
$scope.error.generic = status.restore.errorMessage;
|
2018-07-29 20:33:21 -07:00
|
|
|
} else { // restore worked, redirect to admin page
|
|
|
|
|
window.location.href = '/';
|
|
|
|
|
}
|
|
|
|
|
return;
|
2018-01-22 13:01:38 -08:00
|
|
|
}
|
|
|
|
|
|
2020-09-21 21:48:22 -07:00
|
|
|
if (!error) $scope.message = status.restore.message;
|
2018-12-15 16:08:44 -08:00
|
|
|
|
2018-01-22 13:01:38 -08:00
|
|
|
setTimeout(waitForRestore, 5000);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function readFileLocally(obj, file, fileName) {
|
|
|
|
|
return function (event) {
|
|
|
|
|
$scope.$apply(function () {
|
|
|
|
|
obj[file] = null;
|
|
|
|
|
obj[fileName] = event.target.files[0].name;
|
|
|
|
|
|
|
|
|
|
var reader = new FileReader();
|
|
|
|
|
reader.onload = function (result) {
|
|
|
|
|
if (!result.target || !result.target.result) return console.error('Unable to read local file');
|
|
|
|
|
obj[file] = result.target.result;
|
|
|
|
|
};
|
|
|
|
|
reader.readAsText(event.target.files[0]);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
document.getElementById('gcsKeyFileInput').onchange = readFileLocally($scope.gcsKey, 'content', 'keyFileName');
|
|
|
|
|
|
2020-05-15 00:32:49 +02:00
|
|
|
document.getElementById('backupConfigFileInput').onchange = function (event) {
|
|
|
|
|
var reader = new FileReader();
|
|
|
|
|
reader.onload = function (result) {
|
|
|
|
|
if (!result.target || !result.target.result) return console.error('Unable to read backup config');
|
|
|
|
|
|
|
|
|
|
var backupConfig;
|
|
|
|
|
try {
|
|
|
|
|
backupConfig = JSON.parse(result.target.result);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error('Unable to parse backup config');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$scope.$apply(function () {
|
|
|
|
|
// we assume property names match here, this does not yet work for gcs keys
|
|
|
|
|
Object.keys(backupConfig).forEach(function (k) {
|
|
|
|
|
if (k in $scope) $scope[k] = backupConfig[k];
|
|
|
|
|
});
|
2022-03-30 11:42:30 -07:00
|
|
|
|
|
|
|
|
// this allows the config to potentially have a raw password (though our UI sets it to placeholder)
|
|
|
|
|
if ($scope.mountOptions.password === SECRET_PLACEHOLDER) $scope.mountOptions.password = '';
|
2020-05-15 00:32:49 +02:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
reader.readAsText(event.target.files[0]);
|
|
|
|
|
};
|
|
|
|
|
|
2019-09-05 22:22:42 +02:00
|
|
|
function init() {
|
|
|
|
|
Client.getStatus(function (error, status) {
|
|
|
|
|
if (error) return Client.initError(error, init);
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2019-09-05 22:22:42 +02:00
|
|
|
if (status.restore.active) return waitForRestore();
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2019-09-05 22:22:42 +02:00
|
|
|
if (status.restore.errorMessage) $scope.error.generic = status.restore.errorMessage;
|
2018-08-05 23:30:22 -07:00
|
|
|
|
2019-09-05 22:22:42 +02:00
|
|
|
if (status.activated) {
|
|
|
|
|
window.location.href = '/';
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-15 11:40:41 +02:00
|
|
|
$scope.status = status;
|
2019-09-05 22:22:42 +02:00
|
|
|
$scope.instanceId = search.instanceId;
|
2020-12-21 22:36:43 -08:00
|
|
|
$scope.setupToken = search.setupToken;
|
2019-09-05 22:22:42 +02:00
|
|
|
$scope.initialized = true;
|
|
|
|
|
});
|
|
|
|
|
}
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2019-09-05 22:22:42 +02:00
|
|
|
init();
|
2018-01-22 13:01:38 -08:00
|
|
|
}]);
|