-
Notifications
You must be signed in to change notification settings - Fork 305
/
Copy pathoptions.js
399 lines (396 loc) · 9.82 KB
/
options.js
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
const fs = require('fs')
const path = require('path')
const validUrl = require('valid-url')
const { URL } = require('url')
const { isEmail } = require('validator')
module.exports = [
// {
// abbr: 'v',
// flag: true,
// help: 'Print the logs to console\n'
// },
{
name: 'root',
help: "Root folder to serve (default: './data')",
question: 'Path to the folder you want to serve. Default is',
default: './data',
prompt: true,
filter: (value) => path.resolve(value)
},
{
name: 'port',
help: 'SSL port to use',
question: 'SSL port to run on. Default is',
default: '8443',
prompt: true
},
{
name: 'server-uri',
question: 'Solid server uri (with protocol, hostname and port)',
help: "Solid server uri (default: 'https://localhost:8443')",
default: 'https://localhost:8443',
validate: validUri,
prompt: true
},
{
name: 'webid',
help: 'Enable WebID authentication and access control (uses HTTPS)',
flag: true,
default: true,
question: 'Enable WebID authentication',
prompt: true
},
{
name: 'mount',
help: "Serve on a specific URL path (default: '/')",
question: 'Serve Solid on URL path',
default: '/',
prompt: true
},
{
name: 'config-path',
question: 'Path to the config directory (for example: ./config)',
default: './config',
prompt: true
},
{
name: 'config-file',
question: 'Path to the config file (for example: ./config.json)',
default: './config.json',
prompt: true
},
{
name: 'db-path',
question: 'Path to the server metadata db directory (for users/apps etc)',
default: './.db',
prompt: true
},
{
name: 'auth',
help: 'Pick an authentication strategy for WebID: `tls` or `oidc`',
question: 'Select authentication strategy',
type: 'list',
choices: [
'WebID-OpenID Connect'
],
prompt: false,
default: 'WebID-OpenID Connect',
filter: (value) => {
if (value === 'WebID-OpenID Connect') return 'oidc'
},
when: (answers) => {
return answers.webid
}
},
{
name: 'use-owner',
question: 'Do you already have a WebID?',
type: 'confirm',
default: false,
hide: true
},
{
name: 'owner',
help: 'Set the owner of the storage (overwrites the root ACL file)',
question: 'Your webid (to overwrite the root ACL with)',
prompt: false,
validate: function (value) {
if (value === '' || !value.startsWith('http')) {
return 'Enter a valid Webid'
}
return true
},
when: function (answers) {
return answers['use-owner']
}
},
{
name: 'ssl-key',
help: 'Path to the SSL private key in PEM format',
validate: validPath,
prompt: true
},
{
name: 'ssl-cert',
help: 'Path to the SSL certificate key in PEM format',
validate: validPath,
prompt: true
},
{
name: 'no-reject-unauthorized',
help: 'Accept self-signed certificates',
flag: true,
default: false,
prompt: false
},
{
name: 'multiuser',
help: 'Enable multi-user mode',
question: 'Enable multi-user mode',
flag: true,
default: false,
prompt: true
},
{
name: 'idp',
help: 'Obsolete; use --multiuser',
prompt: false
},
{
name: 'no-live',
help: 'Disable live support through WebSockets',
flag: true,
default: false
},
// {
// full: 'default-app',
// help: 'URI to use as a default app for resources (default: https://linkeddata.github.io/warp/#/list/)'
// },
{
name: 'use-cors-proxy',
help: 'Do you want to have a CORS proxy endpoint?',
flag: true,
default: false,
hide: true
},
{
name: 'proxy',
help: 'Obsolete; use --corsProxy',
prompt: false
},
{
name: 'cors-proxy',
help: 'Serve the CORS proxy on this path',
when: function (answers) {
return answers['use-cors-proxy']
},
default: '/proxy',
prompt: true
},
{
name: 'auth-proxy',
help: 'Object with path/server pairs to reverse proxy',
default: {},
prompt: false,
hide: true
},
{
name: 'suppress-data-browser',
help: 'Suppress provision of a data browser',
flag: true,
prompt: false,
default: false,
hide: false
},
{
name: 'data-browser-path',
help: 'An HTML file which is sent to allow users to browse the data (eg using mashlib.js)',
question: 'Path of data viewer page (defaults to using mashlib)',
validate: validPath,
default: 'default',
prompt: false
},
{
name: 'suffix-acl',
full: 'suffix-acl',
help: "Suffix for acl files (default: '.acl')",
default: '.acl',
prompt: false
},
{
name: 'suffix-meta',
full: 'suffix-meta',
help: "Suffix for metadata files (default: '.meta')",
default: '.meta',
prompt: false
},
{
name: 'secret',
help: 'Secret used to sign the session ID cookie (e.g. "your secret phrase")',
question: 'Session secret for cookie',
default: 'random',
prompt: false,
filter: function (value) {
if (value === '' || value === 'random') {
return
}
return value
}
},
// {
// full: 'no-error-pages',
// flag: true,
// help: 'Disable custom error pages (use Node.js default pages instead)'
// },
{
name: 'error-pages',
help: 'Folder from which to look for custom error pages files (files must be named <error-code>.html -- eg. 500.html)',
validate: validPath,
prompt: false
},
{
name: 'force-user',
help: 'Force a WebID to always be logged in (useful when offline)'
},
{
name: 'strict-origin',
help: 'Enforce same origin policy in the ACL',
flag: true,
default: false,
prompt: false
},
{
name: 'use-email',
help: 'Do you want to set up an email service?',
flag: true,
prompt: true,
default: false
},
{
name: 'email-host',
help: 'Host of your email service',
prompt: true,
default: 'smtp.gmail.com',
when: (answers) => {
return answers['use-email']
}
},
{
name: 'email-port',
help: 'Port of your email service',
prompt: true,
default: '465',
when: (answers) => {
return answers['use-email']
}
},
{
name: 'email-auth-user',
help: 'User of your email service',
prompt: true,
when: (answers) => {
return answers['use-email']
},
validate: (value) => {
if (!value) {
return 'You must enter this information'
}
return true
}
},
{
name: 'email-auth-pass',
help: 'Password of your email service',
type: 'password',
prompt: true,
when: (answers) => {
return answers['use-email']
}
},
{
name: 'use-api-apps',
help: 'Do you want to load your default apps on /api/apps?',
flag: true,
prompt: false,
default: true
},
{
name: 'api-apps',
help: 'Path to the folder to mount on /api/apps',
prompt: true,
validate: validPath,
when: (answers) => {
return answers['use-api-apps']
}
},
{ // copied from name: 'owner'
name: 'redirect-http-from',
help: 'HTTP port or \',\'-separated ports to redirect to the solid server port (e.g. "80,8080").',
prompt: false,
validate: function (value) {
if (!value.match(/^[0-9]+(,[0-9]+)*$/)) {
return 'direct-port(s) must be a comma-separated list of integers.'
}
const list = value.split(/,/).map(v => parseInt(v))
const bad = list.find(v => { return v < 1 || v > 65535 })
if (bad.length) {
return 'redirect-http-from port(s) ' + bad + ' out of range'
}
return true
}
},
{
// This property is packaged into an object for the server property in config.json
name: 'server-info-name', // All properties with prefix server-info- will be removed from the config
help: 'A name for your server (not required, but will be presented on your server\'s frontpage)',
prompt: true,
default: answers => new URL(answers['server-uri']).hostname
},
{
// This property is packaged into an object for the server property in config.json
name: 'server-info-description', // All properties with prefix server-info- will be removed from the config
help: 'A description of your server (not required)',
prompt: true
},
{
// This property is packaged into an object for the server property in config.json
name: 'server-info-logo', // All properties with prefix server-info- will be removed from the config
help: 'A logo that represents you, your brand, or your server (not required)',
prompt: true
},
{
name: 'enforce-toc',
help: 'Do you want to enforce Terms & Conditions for your service?',
flag: true,
prompt: true,
default: false,
when: answers => answers.multiuser
},
{
name: 'toc-uri',
help: 'URI to your Terms & Conditions',
prompt: true,
validate: validUri,
when: answers => answers['enforce-toc']
},
{
name: 'disable-password-checks',
help: 'Do you want to disable password strength checking?',
flag: true,
prompt: true,
default: false,
when: answers => answers.multiuser
},
{
name: 'support-email',
help: 'The support email you provide for your users (not required)',
prompt: true,
validate: (value) => {
if (value && !isEmail(value)) {
return 'Must be a valid email'
}
return true
},
when: answers => answers.multiuser
}
]
function validPath (value) {
if (value === 'default') {
return Promise.resolve(true)
}
if (!value) {
return Promise.resolve('You must enter a valid path')
}
return new Promise((resolve) => {
fs.stat(value, function (err) {
if (err) return resolve('Nothing found at this path')
return resolve(true)
})
})
}
function validUri (value) {
if (!validUrl.isUri(value)) {
return 'Enter a valid uri (with protocol)'
}
return true
}