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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
|
<!--
- SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->
<template>
<form ref="form"
class="setup-form"
:class="{ 'setup-form--loading': loading }"
action=""
method="POST"
@submit="onSubmit">
<!-- Autoconfig info -->
<NcNoteCard v-if="config.hasAutoconfig"
:heading="t('core', 'Autoconfig file detected')"
type="success">
{{ t('core', 'The setup form below is pre-filled with the values from the config file.') }}
</NcNoteCard>
<!-- Htaccess warning -->
<NcNoteCard v-if="config.htaccessWorking === false"
:heading="t('core', 'Security warning')"
type="warning">
<p v-html="htaccessWarning" />
</NcNoteCard>
<!-- Various errors -->
<NcNoteCard v-for="(error, index) in errors"
:key="index"
:heading="error.heading"
type="error">
{{ error.message }}
</NcNoteCard>
<!-- Admin creation -->
<fieldset class="setup-form__administration">
<legend>{{ t('core', 'Create administration account') }}</legend>
<!-- Username -->
<NcTextField v-model="config.adminlogin"
:label="t('core', 'Administration account name')"
name="adminlogin"
required />
<!-- Password -->
<NcPasswordField v-model="config.adminpass"
:label="t('core', 'Administration account password')"
name="adminpass"
required />
<!-- Password entropy -->
<NcNoteCard v-show="config.adminpass !== ''" :type="passwordHelperType">
{{ passwordHelperText }}
</NcNoteCard>
</fieldset>
<!-- Autoconfig toggle -->
<details :open="!isValidAutoconfig">
<summary>{{ t('core', 'Advanced settings') }}</summary>
<!-- Data folder -->
<fieldset class="setup-form__data-folder">
<legend>{{ t('core', 'Data folder') }}</legend>
<NcTextField v-model="config.directory"
:label="t('core', 'Data folder')"
:placeholder="config.serverRoot + '/data'"
required
autocomplete="off"
autocapitalize="none"
name="directory"
spellcheck="false" />
</fieldset>
<!-- Database -->
<fieldset class="setup-form__database">
<legend>{{ t('core', 'Database configuration') }}</legend>
<!-- Database type select -->
<fieldset class="setup-form__database-type">
<legend>{{ t('core', 'Database type') }}</legend>
<p class="setup-form__database-type-select" v-if="Object.keys(config.databases).length > 1">
<NcCheckboxRadioSwitch v-for="(name, db) in config.databases"
v-model="config.dbtype"
:key="db"
:button-variant="true"
:value="db"
name="dbtype"
button-variant-grouped="horizontal"
type="radio">
{{ name }}
</NcCheckboxRadioSwitch>
</p>
<NcNoteCard v-else type="warning">
{{ t('core', 'Only {db} is available.', { db: Object.values(config.databases).at(0) }) }}<br>
{{ t('core', 'Install and activate additional PHP modules to choose other database types.') }}<br>
<a :href="links.adminSourceInstall" target="_blank" rel="noreferrer noopener">
{{ t('core', 'For more details check out the documentation.') }} ↗
</a>
</NcNoteCard>
<NcNoteCard v-if="config.dbtype === 'sqlite'"
:heading="t('core', 'Performance warning')"
type="warning">
{{ t('core', 'You chose SQLite as database.') }}<br>
{{ t('core', 'SQLite should only be used for minimal and development instances. For production we recommend a different database backend.') }}<br>
{{ t('core', 'If you use clients for file syncing, the use of SQLite is highly discouraged.') }}
</NcNoteCard>
</fieldset>
<!-- Database configuration -->
<fieldset v-if="config.dbtype !== 'sqlite'">
<NcTextField v-model="config.dbuser"
:label="t('core', 'Database user')"
autocapitalize="none"
autocomplete="off"
name="dbuser"
spellcheck="false"
required />
<NcPasswordField v-model="config.dbpass"
:label="t('core', 'Database password')"
autocapitalize="none"
autocomplete="off"
name="dbpass"
spellcheck="false"
required />
<NcTextField v-model="config.dbname"
:label="t('core', 'Database name')"
autocapitalize="none"
autocomplete="off"
name="dbname"
pattern="[0-9a-zA-Z\$_\-]+"
spellcheck="false"
required />
<NcTextField v-if="config.dbtype === 'oci'"
v-model="config.dbtablespace"
:label="t('core', 'Database tablespace')"
autocapitalize="none"
autocomplete="off"
name="dbtablespace"
spellcheck="false" />
<NcTextField v-model="config.dbhost"
:helper-text="t('core', 'Please specify the port number along with the host name (e.g., localhost:5432).')"
:label="t('core', 'Database host')"
:placeholder="t('core', 'localhost')"
autocapitalize="none"
autocomplete="off"
name="dbhost"
spellcheck="false" />
</fieldset>
</fieldset>
</details>
<!-- Submit -->
<NcButton
class="setup-form__button"
:class="{ 'setup-form__button--loading': loading }"
:disabled="loading"
:loading="loading"
:wide="true"
alignment="center-reverse"
native-type="submit"
type="primary">
<template #icon>
<NcLoadingIcon v-if="loading" />
<IconArrowRight v-else />
</template>
{{ loading ? t('core', 'Installing …') : t('core', 'Install') }}
</NcButton>
<!-- Help note -->
<NcNoteCard type="info">
{{ t('core', 'Need help?') }}
<a target="_blank" rel="noreferrer noopener" :href="links.adminInstall">{{ t('core', 'See the documentation') }} ↗</a>
</NcNoteCard>
</form>
</template>
<script lang="ts">
import type { DbType, SetupConfig, SetupLinks } from '../install'
import { defineComponent } from 'vue'
import { loadState } from '@nextcloud/initial-state'
import { t } from '@nextcloud/l10n'
import DomPurify from 'dompurify'
import NcButton from '@nextcloud/vue/components/NcButton'
import NcCheckboxRadioSwitch from '@nextcloud/vue/components/NcCheckboxRadioSwitch'
import NcLoadingIcon from '@nextcloud/vue/components/NcLoadingIcon'
import NcNoteCard from '@nextcloud/vue/components/NcNoteCard'
import NcPasswordField from '@nextcloud/vue/components/NcPasswordField'
import NcTextField from '@nextcloud/vue/components/NcTextField'
import IconArrowRight from 'vue-material-design-icons/ArrowRight.vue'
const config = loadState<SetupConfig>('core', 'config')
const links = loadState<SetupLinks>('core', 'links')
enum PasswordStrength {
VeryWeak,
Weak,
Moderate,
Strong,
VeryStrong,
ExtremelyStrong,
}
export default defineComponent({
name: 'Setup',
components: {
IconArrowRight,
NcButton,
NcCheckboxRadioSwitch,
NcLoadingIcon,
NcNoteCard,
NcPasswordField,
NcTextField,
},
setup() {
return {
links,
t,
}
},
data() {
return {
config,
isValidAutoconfig: false,
loading: false,
}
},
computed: {
passwordHelperText(): string {
if (this.config.adminpass === '') {
return ''
}
const passwordStrength = this.checkPasswordEntropy(this.config.adminpass)
switch (passwordStrength) {
case PasswordStrength.VeryWeak:
return t('core', 'Password is too weak')
case PasswordStrength.Weak:
return t('core', 'Password is weak')
case PasswordStrength.Moderate:
return t('core', 'Password is average')
case PasswordStrength.Strong:
return t('core', 'Password is strong')
case PasswordStrength.VeryStrong:
return t('core', 'Password is very strong')
case PasswordStrength.ExtremelyStrong:
return t('core', 'Password is extremely strong')
}
return t('core', 'Unknown password strength')
},
passwordHelperType() {
if (this.checkPasswordEntropy(this.config.adminpass) < PasswordStrength.Moderate) {
return 'error'
}
if (this.checkPasswordEntropy(this.config.adminpass) < PasswordStrength.Strong) {
return 'warning'
}
return 'success'
},
htaccessWarning(): string {
// We use v-html, let's make sure we're safe
const message = [
t('core', 'Your data directory and files are probably accessible from the internet because the <code>.htaccess</code> file does not work.'),
t('core', 'For information how to properly configure your server, please {linkStart}see the documentation{linkEnd}', {
linkStart: '<a href="' + links.adminInstall + '" target="_blank" rel="noreferrer noopener">',
linkEnd: '</a>',
}, { escape: false }),
].join('<br>')
return DomPurify.sanitize(message)
},
errors() {
return this.config.errors.map(error => {
if (typeof error === 'string') {
return {
heading: '',
message: error,
}
}
// f no hint is set, we don't want to show a heading
if (error.hint === '') {
return {
heading: '',
message: error.error,
}
}
return {
heading: error.error,
message: error.hint,
}
})
},
},
mounted() {
if (this.config.dbtype === '') {
this.config.dbtype = Object.keys(this.config.databases).at(0) as DbType
}
// Validate the legitimacy of the autoconfig
if (this.config.hasAutoconfig) {
const form = this.$refs.form as HTMLFormElement
// Check the form without the administration account fields
form.querySelectorAll('input[name="adminlogin"], input[name="adminpass"]').forEach(input => {
input.removeAttribute('required')
})
if (form.checkValidity() && this.config.errors.length === 0) {
this.isValidAutoconfig = true
} else {
this.isValidAutoconfig = false
}
// Restore the required attribute
// Check the form without the administration account fields
form.querySelectorAll('input[name="adminlogin"], input[name="adminpass"]').forEach(input => {
input.setAttribute('required', 'true')
})
}
},
methods: {
async onSubmit() {
this.loading = true
},
checkPasswordEntropy(password: string): PasswordStrength {
const uniqueCharacters = new Set(password)
const entropy = parseInt(Math.log2(Math.pow(parseInt(uniqueCharacters.size.toString()), password.length)).toFixed(2))
if (entropy < 16) {
return PasswordStrength.VeryWeak
} else if (entropy < 31) {
return PasswordStrength.Weak
} else if (entropy < 46) {
return PasswordStrength.Moderate
} else if (entropy < 61) {
return PasswordStrength.Strong
} else if (entropy < 76) {
return PasswordStrength.VeryStrong
}
return PasswordStrength.ExtremelyStrong
},
},
})
</script>
<style lang="scss">
form {
padding: calc(3 * var(--default-grid-baseline));
color: var(--color-main-text);
border-radius: var(--border-radius-container);
background-color: var(--color-main-background-blur);
box-shadow: 0 0 10px var(--color-box-shadow);
-webkit-backdrop-filter: var(--filter-background-blur);
backdrop-filter: var(--filter-background-blur);
max-width: 300px;
margin-bottom: 30px;
> fieldset:first-child,
> .notecard:first-child {
margin-top: 0;
}
> .notecard:last-child {
margin-bottom: 0;
}
> fieldset,
> details {
margin-block: 1rem;
}
.setup-form__button:not(.setup-form__button--loading) {
.material-design-icon {
transition: all linear var(--animation-quick);
}
&:hover .material-design-icon {
transform: translateX(0.2em);
}
}
// Db select required styling
.setup-form__database-type-select {
display: flex;
}
}
code {
background-color: var(--color-background-dark);
margin-top: 1rem;
padding: 0 0.3em;
border-radius: var(--border-radius);
}
// Various overrides
.input-field {
margin-block-start: 1rem !important;
}
.notecard__heading {
font-size: inherit !important;
}
</style>
|