Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Encryption.vue « components « src - github.com/nextcloud/privacy.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9e443ad01cea72b6511caa57fa7381c375d327d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<!--
  - @copyright Copyright (c) 2019 Georg Ehrke <oc.list@georgehrke.com>
  - @author Georg Ehrke <oc.list@georgehrke.com>
  -
  - @license GNU AGPL version 3 or any later version
  -
  - This program is free software: you can redistribute it and/or modify
  - it under the terms of the GNU Affero General Public License as
  - published by the Free Software Foundation, either version 3 of the
  - License, or (at your option) any later version.
  -
  - This program is distributed in the hope that it will be useful,
  - but WITHOUT ANY WARRANTY; without even the implied warranty of
  - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  - GNU Affero General Public License for more details.
  -
  - You should have received a copy of the GNU Affero General Public License
  - along with this program. If not, see <http://www.gnu.org/licenses/>.
  -
  -->

<template>
	<div class="who-has-access">
		<div class="encryption-details">
			<!-- eslint-disable vue/no-v-html -->
			<p v-for="label in labels"
				v-show="!isEditing"
				:key="label"
				v-html="label" />
			<!--eslint-enable-->
		</div>
		<Actions v-if="$is_admin && !isEditing">
			<ActionButton icon="icon-rename" @click.stop.prevent="openEditFullDiskEncryptionForm" />
		</Actions>
		<div v-if="isEditing" v-click-outside="cancelEditFullDiskEncryptionForm">
			<form>
				<input id="fullDiskEncryptionEnabledCheckbox"
					v-model="fullDiskEncryptionEnabled"
					:disabled="isSavingChanges"
					type="checkbox"
					name="fullDiskEncryptionEnabledCheckbox"
					class="checkbox"
					@change="saveFullDiskEncryptionForm">
				<label for="fullDiskEncryptionEnabledCheckbox">
					{{ $t('privacy', 'This server is using full-disk-encryption.') }}
				</label>
			</form>
		</div>
	</div>
</template>

<script>
import ClickOutside from 'vue-click-outside'

import HttpClient from '@nextcloud/axios'
import { generateUrl } from '@nextcloud/router'
import Actions from '@nextcloud/vue/dist/Components/Actions'
import ActionButton from '@nextcloud/vue/dist/Components/ActionButton'
import { loadState } from '@nextcloud/initial-state'
import { showError } from '@nextcloud/dialogs'

export default {
	name: 'Encryption',
	components: {
		Actions,
		ActionButton,
	},
	directives: {
		ClickOutside,
	},
	data() {
		return {
			fullDiskEncryptionEnabled: false,
			serverSideEncryptionEnabled: false,
			homeStorageEncryptionEnabled: false,
			masterKeyEncryptionEnabled: false,
			isEditing: false,
			isSavingChanges: false,
		}
	},
	computed: {
		labels() {
			const labels = []

			const addLabel = (text) => labels.push(text
				.replace('{linkopen}', '<a href="https://nextcloud.com/blog/encryption-in-nextcloud/" target="_blank" title="" rel="noreferrer noopener">')
				.replace('{linkclose}', '</a>'))

			if (this.serverSideEncryptionEnabled) {
				if (this.homeStorageEncryptionEnabled) {
					if (this.masterKeyEncryptionEnabled) {
						addLabel(this.$t('privacy', 'Your home storage is encrypted using {linkopen}server-side-encryption ↗{linkclose} with a master key.'))
						addLabel(this.$t('privacy', 'Your files on external storages may be encrypted using {linkopen}server-side-encryption ↗{linkclose} with a master key based on their configuration.'))
					} else {
						addLabel(this.$t('privacy', 'Your home storage is encrypted using {linkopen}server-side-encryption ↗{linkclose} with an individual user key.'))
						addLabel(this.$t('privacy', 'Your files on external storages may be encrypted using {linkopen}server-side-encryption ↗{linkclose} with an individual key based on their configuration.'))
					}
				} else {
					if (this.masterKeyEncryptionEnabled) {
						addLabel(this.$t('privacy', 'Your files on external storages may be encrypted using {linkopen}server-side-encryption ↗{linkclose} with a master key based on their configuration.'))
					} else {
						addLabel(this.$t('privacy', 'Your files on external storages may be encrypted using {linkopen}server-side-encryption ↗{linkclose} with an individual key based on their configuration.'))
					}
				}
			}

			if (this.fullDiskEncryptionEnabled && this.serverSideEncryptionEnabled) {
				labels.push(this.$t('privacy', 'Additionally, this server is protected with full-disk-encryption.'))
			} else if (this.fullDiskEncryptionEnabled && !this.serverSideEncryptionEnabled) {
				labels.push(this.$t('privacy', 'This server is protected with full-disk-encryption.'))
			}

			if (labels.length === 0) {
				labels.push(this.$t('privacy', 'Your files are not protected by encryption.'))
			}

			return labels
		},
	},
	/**
	 * This function is called on mount of the Vue component
	 * It checks if full-disk-encryption or server-side-encryption
	 * are enabled
	 */
	mounted() {
		this.fullDiskEncryptionEnabled = loadState('privacy', 'fullDiskEncryptionEnabled')
		this.serverSideEncryptionEnabled = loadState('privacy', 'serverSideEncryptionEnabled')
		this.homeStorageEncryptionEnabled = loadState('privacy', 'homeStorageEncryptionEnabled')
		this.masterKeyEncryptionEnabled = loadState('privacy', 'masterKeyEncryptionEnabled')
	},
	methods: {
		/**
		 * Opens the form to edit the full-disk-encryption-state
		 */
		openEditFullDiskEncryptionForm() {
			this.isEditing = true
		},
		/**
		 * Closes the form to edit the full-disk-encryption-state
		 */
		cancelEditFullDiskEncryptionForm() {
			this.isEditing = false
		},
		/**
		 * Saves the new full-disk-encryption-state
		 *
		 * @returns {Promise<void>}
		 */
		async saveFullDiskEncryptionForm() {
			const url = generateUrl('/apps/privacy/api/fullDiskEncryption')
			this.isSavingChanges = true

			try {
				await HttpClient.post(url, { enabled: this.fullDiskEncryptionEnabled ? '1' : '0' })
			} catch (error) {
				console.error(error)
				showError('Error saving new state of full-disk-encryption')

				// Reset state
				this.fullDiskEncryptionEnabled = !this.fullDiskEncryptionEnabled
			} finally {
				this.isSavingChanges = false
				this.isEditing = false
			}
		},
	},
}
</script>
<style>
.encryption-details {
	margin-right: 20px;
}
</style>