2025-04-28 18:05:29 +02:00
|
|
|
<script setup>
|
|
|
|
|
|
|
|
|
|
import { ref, useTemplateRef } from 'vue';
|
2025-08-13 20:11:29 +02:00
|
|
|
import { Dialog, FormGroup, TextInput, PasswordInput, Checkbox } from '@cloudron/pankow';
|
2025-04-29 16:58:36 +02:00
|
|
|
import { s3like } from '../utils.js';
|
|
|
|
|
import BackupProviderForm from './BackupProviderForm.vue';
|
|
|
|
|
import AppsModel from '../models/AppsModel.js';
|
2025-04-29 17:06:31 +02:00
|
|
|
import { REGIONS_CONTABO, REGIONS_VULTR, REGIONS_IONOS, REGIONS_OVH, REGIONS_LINODE, REGIONS_SCALEWAY, REGIONS_WASABI } from '../constants.js';
|
2025-07-28 11:45:10 +02:00
|
|
|
import { SECRET_PLACEHOLDER } from '../constants.js';
|
2025-04-29 16:58:36 +02:00
|
|
|
|
|
|
|
|
const appsModel = AppsModel.create();
|
2025-04-28 18:05:29 +02:00
|
|
|
|
|
|
|
|
const dialog = useTemplateRef('dialog');
|
2025-04-29 19:50:28 +02:00
|
|
|
const form = useTemplateRef('form');
|
2025-04-29 16:58:36 +02:00
|
|
|
const backupConfigInput = useTemplateRef('backupConfigInput');
|
|
|
|
|
const appId = ref('');
|
2025-04-28 18:05:29 +02:00
|
|
|
const busy = ref(false);
|
|
|
|
|
const formError = ref({});
|
|
|
|
|
const providerConfig = ref({});
|
|
|
|
|
const provider = ref('');
|
2025-04-29 16:58:36 +02:00
|
|
|
const remotePath = ref('');
|
2025-07-28 11:45:10 +02:00
|
|
|
const format = ref('');
|
2025-08-13 20:11:29 +02:00
|
|
|
const encrypted = ref(false);
|
|
|
|
|
const encryptionPasswordHint = ref('');
|
2025-07-28 11:45:10 +02:00
|
|
|
const encryptionPassword = ref('');
|
|
|
|
|
const encryptedFilenames = ref(false);
|
2025-04-28 18:05:29 +02:00
|
|
|
|
|
|
|
|
async function onSubmit() {
|
2025-04-29 19:50:28 +02:00
|
|
|
if (!form.value.reportValidity()) return;
|
|
|
|
|
|
2025-04-29 16:58:36 +02:00
|
|
|
formError.value = {};
|
|
|
|
|
busy.value = true;
|
|
|
|
|
|
2025-08-02 19:09:21 +02:00
|
|
|
let backupPath = remotePath.value;
|
|
|
|
|
const backupConfig = {};
|
2025-04-29 16:58:36 +02:00
|
|
|
|
|
|
|
|
// only set provider specific fields, this will clear them in the db
|
|
|
|
|
if (s3like(provider.value)) {
|
|
|
|
|
backupConfig.bucket = providerConfig.value.bucket;
|
|
|
|
|
backupConfig.prefix = providerConfig.value.prefix;
|
|
|
|
|
backupConfig.accessKeyId = providerConfig.value.accessKeyId;
|
|
|
|
|
backupConfig.secretAccessKey = providerConfig.value.secretAccessKey;
|
|
|
|
|
|
|
|
|
|
if (providerConfig.value.endpoint) backupConfig.endpoint = providerConfig.value.endpoint;
|
|
|
|
|
|
|
|
|
|
if (provider.value === 's3') {
|
|
|
|
|
if (providerConfig.value.region) backupConfig.region = providerConfig.value.region;
|
|
|
|
|
delete backupConfig.endpoint;
|
|
|
|
|
} else if (provider.value === 'minio' || provider.value === 's3-v4-compat') {
|
|
|
|
|
backupConfig.region = providerConfig.value.region || 'us-east-1';
|
|
|
|
|
backupConfig.acceptSelfSignedCerts = !!providerConfig.value.acceptSelfSignedCerts;
|
|
|
|
|
backupConfig.s3ForcePathStyle = true; // might want to expose this in the UI
|
|
|
|
|
} else if (provider.value === 'exoscale-sos') {
|
|
|
|
|
backupConfig.region = 'us-east-1';
|
|
|
|
|
backupConfig.signatureVersion = 'v4';
|
|
|
|
|
} else if (provider.value === 'wasabi') {
|
2025-04-29 17:06:31 +02:00
|
|
|
backupConfig.region = REGIONS_WASABI.find(function (x) { return x.value === backupConfig.endpoint; }).region;
|
2025-04-29 16:58:36 +02:00
|
|
|
backupConfig.signatureVersion = 'v4';
|
|
|
|
|
} else if (provider.value === 'scaleway-objectstorage') {
|
2025-04-29 17:06:31 +02:00
|
|
|
backupConfig.region = REGIONS_SCALEWAY.find(function (x) { return x.value === backupConfig.endpoint; }).region;
|
2025-04-29 16:58:36 +02:00
|
|
|
backupConfig.signatureVersion = 'v4';
|
|
|
|
|
} else if (provider.value === 'linode-objectstorage') {
|
2025-04-29 17:06:31 +02:00
|
|
|
backupConfig.region = REGIONS_LINODE.find(function (x) { return x.value === backupConfig.endpoint; }).region;
|
2025-04-29 16:58:36 +02:00
|
|
|
backupConfig.signatureVersion = 'v4';
|
|
|
|
|
} else if (provider.value === 'ovh-objectstorage') {
|
2025-04-29 17:06:31 +02:00
|
|
|
backupConfig.region = REGIONS_OVH.find(function (x) { return x.value === backupConfig.endpoint; }).region;
|
2025-04-29 16:58:36 +02:00
|
|
|
backupConfig.signatureVersion = 'v4';
|
|
|
|
|
} else if (provider.value === 'ionos-objectstorage') {
|
2025-04-29 17:06:31 +02:00
|
|
|
backupConfig.region = REGIONS_IONOS.find(function (x) { return x.value === backupConfig.endpoint; }).region;
|
2025-04-29 16:58:36 +02:00
|
|
|
backupConfig.signatureVersion = 'v4';
|
|
|
|
|
} else if (provider.value === 'vultr-objectstorage') {
|
2025-04-29 17:06:31 +02:00
|
|
|
backupConfig.region = REGIONS_VULTR.find(function (x) { return x.value === backupConfig.endpoint; }).region;
|
2025-04-29 16:58:36 +02:00
|
|
|
backupConfig.signatureVersion = 'v4';
|
|
|
|
|
} else if (provider.value === 'contabo-objectstorage') {
|
2025-04-29 17:06:31 +02:00
|
|
|
backupConfig.region = REGIONS_CONTABO.find(function (x) { return x.value === backupConfig.endpoint; }).region;
|
2025-04-29 16:58:36 +02:00
|
|
|
backupConfig.signatureVersion = 'v4';
|
|
|
|
|
backupConfig.s3ForcePathStyle = true; // https://docs.contabo.com/docs/products/Object-Storage/technical-description (no virtual buckets)
|
|
|
|
|
} else if (provider.value === 'upcloud-objectstorage') {
|
|
|
|
|
const m = /^.*\.(.*)\.upcloudobjects.com$/.exec(providerConfig.value.endpoint);
|
|
|
|
|
backupConfig.region = m ? m[1] : 'us-east-1'; // let it fail in validation phase if m is not valid
|
|
|
|
|
backupConfig.signatureVersion = 'v4';
|
|
|
|
|
} else if (provider.value === 'digitalocean-spaces') {
|
|
|
|
|
backupConfig.region = 'us-east-1';
|
|
|
|
|
} else if (provider.value === 'hetzner-objectstorage') {
|
|
|
|
|
backupConfig.region = 'us-east-1';
|
|
|
|
|
backupConfig.signatureVersion = 'v4';
|
|
|
|
|
}
|
|
|
|
|
} else if (provider.value === 'gcs') {
|
|
|
|
|
backupConfig.bucket = providerConfig.value.bucket;
|
|
|
|
|
backupConfig.prefix = providerConfig.value.prefix;
|
2025-05-05 17:43:23 +02:00
|
|
|
backupConfig.projectId = providerConfig.value.projectId;
|
|
|
|
|
backupConfig.credentials = providerConfig.value.credentials;
|
2025-04-29 16:58:36 +02:00
|
|
|
} else if (provider.value === 'sshfs' || provider.value === 'cifs' || provider.value === 'nfs' || provider.value === 'ext4' || provider.value === 'xfs') {
|
|
|
|
|
backupConfig.mountOptions = providerConfig.value.mountOptions;
|
|
|
|
|
backupConfig.prefix = providerConfig.value.prefix;
|
|
|
|
|
} else if (provider.value === 'mountpoint') {
|
|
|
|
|
backupConfig.prefix = providerConfig.value.prefix;
|
|
|
|
|
backupConfig.mountPoint = providerConfig.value.mountPoint;
|
|
|
|
|
} else if (provider.value === 'filesystem') {
|
|
|
|
|
const parts = remotePath.value.split('/');
|
2025-08-02 19:09:21 +02:00
|
|
|
backupPath = parts.pop() || parts.pop(); // removes any trailing slash. this is basename()
|
|
|
|
|
backupConfig.backupDir = parts.join('/'); // this is dirname()
|
2025-04-29 16:58:36 +02:00
|
|
|
}
|
|
|
|
|
|
2025-08-02 19:09:21 +02:00
|
|
|
const data = {
|
|
|
|
|
format: format.value,
|
|
|
|
|
provider: provider.value,
|
|
|
|
|
config: backupConfig,
|
|
|
|
|
remotePath: backupPath
|
|
|
|
|
};
|
|
|
|
|
|
2025-08-13 20:11:29 +02:00
|
|
|
if (encrypted.value) {
|
|
|
|
|
data.encryptionPassword = encryptionPassword.value;
|
|
|
|
|
data.encryptedFilenames = encryptedFilenames.value;
|
2025-04-29 16:58:36 +02:00
|
|
|
}
|
|
|
|
|
|
2025-08-02 19:09:21 +02:00
|
|
|
const [error] = await appsModel.import(appId.value, data);
|
2025-04-29 16:58:36 +02:00
|
|
|
if (error) {
|
|
|
|
|
busy.value = false;
|
|
|
|
|
formError.value = {};
|
2025-04-28 18:05:29 +02:00
|
|
|
|
2025-04-29 16:58:36 +02:00
|
|
|
if (error.status === 424) {
|
|
|
|
|
formError.value.generic = error.body.message;
|
|
|
|
|
|
|
|
|
|
if (error.body.message.indexOf('AWS Access Key Id') !== -1) {
|
|
|
|
|
formError.value.accessKeyId = true;
|
|
|
|
|
} else if (error.body.message.indexOf('not match the signature') !== -1 || error.body.message.indexOf('Signature') !== -1) {
|
|
|
|
|
formError.value.secretAccessKey = true;
|
|
|
|
|
} else if (error.body.message.toLowerCase() === 'access denied') {
|
|
|
|
|
formError.value.accessKeyId = true;
|
|
|
|
|
} else if (error.body.message.indexOf('ECONNREFUSED') !== -1) {
|
|
|
|
|
formError.value.generic = 'Unknown region';
|
|
|
|
|
formError.value.region = true;
|
|
|
|
|
} else if (error.body.message.toLowerCase() === 'wrong region') {
|
|
|
|
|
formError.value.generic = 'Wrong S3 Region';
|
|
|
|
|
formError.value.region = true;
|
|
|
|
|
} else {
|
|
|
|
|
formError.value.bucket = true;
|
|
|
|
|
}
|
|
|
|
|
} else if (error.status === 400) {
|
|
|
|
|
formError.value.generic = error.body.message;
|
|
|
|
|
|
|
|
|
|
if (provider.value === 'filesystem') {
|
2025-08-02 19:09:21 +02:00
|
|
|
formError.value.backupDir = true;
|
2025-04-29 16:58:36 +02:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
formError.value.generic = 'Internal error';
|
|
|
|
|
console.error(error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dialog.value.close();
|
|
|
|
|
busy.value = false;
|
|
|
|
|
formError.value = {};
|
|
|
|
|
|
|
|
|
|
// clear potential post-install flag
|
|
|
|
|
delete localStorage['confirmPostInstall_' + appId.value];
|
2025-04-28 18:05:29 +02:00
|
|
|
}
|
|
|
|
|
|
2025-04-29 16:58:36 +02:00
|
|
|
function onBackupConfigChanged(event) {
|
|
|
|
|
const reader = new FileReader();
|
|
|
|
|
reader.onload = function (result) {
|
|
|
|
|
if (!result.target || !result.target.result) return console.error('Unable to read backup config');
|
|
|
|
|
|
2025-07-28 11:45:10 +02:00
|
|
|
let data;
|
2025-04-29 16:58:36 +02:00
|
|
|
try {
|
2025-07-28 11:45:10 +02:00
|
|
|
data = JSON.parse(result.target.result); // 'provider', 'config', 'limits', 'format', 'remotePath', 'encrypted', 'encryptedFilenames'
|
|
|
|
|
if (data.provider === 'filesystem') { // this allows a user to upload a backup to server and import easily with an absolute path
|
2025-08-02 19:09:21 +02:00
|
|
|
data.remotePath = `${data.config.backupDir}/${data.remotePath}`;
|
2025-04-29 16:58:36 +02:00
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error('Unable to parse backup config', e);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-04-28 18:05:29 +02:00
|
|
|
|
2025-07-28 11:45:10 +02:00
|
|
|
provider.value = data.provider;
|
|
|
|
|
remotePath.value = data.remotePath;
|
|
|
|
|
providerConfig.value = data.config;
|
|
|
|
|
format.value = data.format;
|
2025-08-13 20:11:29 +02:00
|
|
|
encrypted.value = !!data.encrypted;
|
|
|
|
|
encryptionPasswordHint.value = data.encryptionPasswordHint || '';
|
|
|
|
|
encryptionPassword.value = '';
|
2025-07-28 11:45:10 +02:00
|
|
|
encryptedFilenames.value = data.encryptedFilenames;
|
2025-04-29 16:58:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
reader.readAsText(event.target.files[0]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onUploadBackupConfig() {
|
|
|
|
|
backupConfigInput.value.click();
|
2025-04-28 18:05:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
defineExpose({
|
2025-04-29 16:58:36 +02:00
|
|
|
async open(id) {
|
|
|
|
|
appId.value = id;
|
2025-04-28 18:05:29 +02:00
|
|
|
busy.value = false;
|
|
|
|
|
formError.value = {};
|
2025-04-29 16:58:36 +02:00
|
|
|
provider.value = '';
|
2025-04-28 18:05:29 +02:00
|
|
|
providerConfig.value = {};
|
2025-04-29 16:58:36 +02:00
|
|
|
remotePath.value = '';
|
2025-08-13 20:11:29 +02:00
|
|
|
encrypted.value = false;
|
|
|
|
|
encryptionPassword.value = '';
|
|
|
|
|
encryptedFilenames.value = false;
|
|
|
|
|
encryptionPasswordHint.value = '';
|
2025-04-28 18:05:29 +02:00
|
|
|
|
|
|
|
|
dialog.value.open();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
<div>
|
2025-04-29 16:58:36 +02:00
|
|
|
<input ref="backupConfigInput" type="file" style="display: none" accept="application/json, text/json" @change="onBackupConfigChanged"/>
|
|
|
|
|
|
2025-04-28 18:05:29 +02:00
|
|
|
<Dialog ref="dialog" :title="$t('app.importBackupDialog.title')"
|
|
|
|
|
:confirm-label="$t('app.importBackupDialog.importAction')"
|
|
|
|
|
:confirm-active="!busy"
|
|
|
|
|
:confirm-busy="busy"
|
|
|
|
|
:reject-label="busy ? '' : $t('main.dialog.cancel')"
|
|
|
|
|
reject-style="secondary"
|
|
|
|
|
:alternate-label="$t('app.importBackupDialog.uploadAction')"
|
|
|
|
|
@alternate="onUploadBackupConfig()"
|
|
|
|
|
@confirm="onSubmit()"
|
|
|
|
|
>
|
|
|
|
|
<div>
|
|
|
|
|
<div>{{ $t('app.importBackupDialog.description') }}</div>
|
|
|
|
|
|
2025-04-29 19:50:28 +02:00
|
|
|
<form @submit.prevent="onSubmit()" autocomplete="off" ref="form">
|
|
|
|
|
<fieldset :disabled="busy">
|
|
|
|
|
<input style="display: none;" type="submit"/>
|
|
|
|
|
|
|
|
|
|
<!-- remotePath contains the prefix as well -->
|
|
|
|
|
<FormGroup>
|
|
|
|
|
<label for="inputRemotePath">{{ $t('app.importBackupDialog.remotePath') }} <sup><a href="https://docs.cloudron.io/backups/#import-app-backup" class="help" target="_blank"><i class="fa fa-question-circle"></i></a></sup></label>
|
|
|
|
|
<TextInput id="inputRemotePath" v-model="remotePath" required />
|
|
|
|
|
</FormGroup>
|
2025-04-29 16:58:36 +02:00
|
|
|
|
2025-07-28 11:45:10 +02:00
|
|
|
<BackupProviderForm ref="form"
|
|
|
|
|
v-model:provider="provider"
|
|
|
|
|
v-model:provider-config="providerConfig"
|
|
|
|
|
v-model:format="format"
|
|
|
|
|
:form-error="formError"
|
|
|
|
|
:import-only="true" />
|
2025-08-13 20:11:29 +02:00
|
|
|
|
2025-08-19 10:49:27 +02:00
|
|
|
<Checkbox style="padding-top: 12px" v-model="encrypted" :label="$t('backups.configureBackupStorage.usesEncryption')"/>
|
2025-08-13 20:11:29 +02:00
|
|
|
<FormGroup v-if="encrypted">
|
|
|
|
|
<label for="encryptionPassswordInput">{{ $t('backups.configureBackupStorage.encryptionPassword') }}</label>
|
|
|
|
|
<PasswordInput id="encryptionPassswordInput" v-model="encryptionPassword" :placeholder="$t('backups.configureBackupStorage.encryptionPasswordPlaceholder')" required/>
|
2025-08-16 19:26:19 +02:00
|
|
|
<div class="warning-label" v-if="encryptionPasswordHint">{{ $t('backups.configureBackupStorage.encryptionHint') }}: {{ encryptionPasswordHint }}</div>
|
2025-08-13 20:11:29 +02:00
|
|
|
</FormGroup>
|
|
|
|
|
<Checkbox v-if="encrypted && format === 'rsync'" v-model="encryptedFilenames" :label="$t('backups.configureBackupStorage.encryptFilenames')"/>
|
2025-04-29 19:50:28 +02:00
|
|
|
</fieldset>
|
|
|
|
|
</form>
|
2025-04-28 18:05:29 +02:00
|
|
|
</div>
|
|
|
|
|
</Dialog>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|