solid-server 5.6.9-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.acl +10 -0
- package/.github/workflows/ci.yml +47 -0
- package/.nvmrc +1 -0
- package/.snyk +35 -0
- package/.well-known/.acl +15 -0
- package/CHANGELOG.md +198 -0
- package/CONTRIBUTING.md +139 -0
- package/CONTRIBUTORS.md +36 -0
- package/Dockerfile +22 -0
- package/LICENSE.md +23 -0
- package/README.md +453 -0
- package/bin/lib/cli-utils.js +85 -0
- package/bin/lib/cli.js +39 -0
- package/bin/lib/init.js +94 -0
- package/bin/lib/invalidUsernames.js +148 -0
- package/bin/lib/migrateLegacyResources.js +69 -0
- package/bin/lib/options.js +399 -0
- package/bin/lib/start.js +148 -0
- package/bin/lib/updateIndex.js +56 -0
- package/bin/solid +3 -0
- package/bin/solid-test +12 -0
- package/bin/solid.js +3 -0
- package/common/css/solid.css +58 -0
- package/common/fonts/glyphicons-halflings-regular.eot +0 -0
- package/common/fonts/glyphicons-halflings-regular.svg +288 -0
- package/common/fonts/glyphicons-halflings-regular.ttf +0 -0
- package/common/fonts/glyphicons-halflings-regular.woff +0 -0
- package/common/fonts/glyphicons-halflings-regular.woff2 +0 -0
- package/common/img/.gitkeep +0 -0
- package/common/js/auth-buttons.js +65 -0
- package/common/js/solid.js +454 -0
- package/common/well-known/security.txt +2 -0
- package/config/defaults.js +25 -0
- package/config/usernames-blacklist.json +4 -0
- package/config.json-default +22 -0
- package/default-templates/emails/delete-account.js +49 -0
- package/default-templates/emails/invalid-username.js +30 -0
- package/default-templates/emails/reset-password.js +49 -0
- package/default-templates/emails/welcome.js +39 -0
- package/default-templates/new-account/.acl +26 -0
- package/default-templates/new-account/.meta +5 -0
- package/default-templates/new-account/.meta.acl +25 -0
- package/default-templates/new-account/.well-known/.acl +19 -0
- package/default-templates/new-account/favicon.ico +0 -0
- package/default-templates/new-account/favicon.ico.acl +26 -0
- package/default-templates/new-account/inbox/.acl +26 -0
- package/default-templates/new-account/private/.acl +10 -0
- package/default-templates/new-account/profile/.acl +19 -0
- package/default-templates/new-account/profile/card$.ttl +25 -0
- package/default-templates/new-account/public/.acl +19 -0
- package/default-templates/new-account/robots.txt +3 -0
- package/default-templates/new-account/robots.txt.acl +26 -0
- package/default-templates/new-account/settings/.acl +20 -0
- package/default-templates/new-account/settings/prefs.ttl +15 -0
- package/default-templates/new-account/settings/privateTypeIndex.ttl +4 -0
- package/default-templates/new-account/settings/publicTypeIndex.ttl +4 -0
- package/default-templates/new-account/settings/publicTypeIndex.ttl.acl +25 -0
- package/default-templates/new-account/settings/serverSide.ttl.acl +13 -0
- package/default-templates/new-account/settings/serverSide.ttl.inactive +12 -0
- package/default-templates/server/.acl +10 -0
- package/default-templates/server/.well-known/.acl +15 -0
- package/default-templates/server/favicon.ico +0 -0
- package/default-templates/server/favicon.ico.acl +15 -0
- package/default-templates/server/index.html +55 -0
- package/default-templates/server/robots.txt +3 -0
- package/default-templates/server/robots.txt.acl +15 -0
- package/default-views/account/account-deleted.hbs +17 -0
- package/default-views/account/delete-confirm.hbs +51 -0
- package/default-views/account/delete-link-sent.hbs +17 -0
- package/default-views/account/delete.hbs +51 -0
- package/default-views/account/invalid-username.hbs +22 -0
- package/default-views/account/register-disabled.hbs +6 -0
- package/default-views/account/register-form.hbs +132 -0
- package/default-views/account/register.hbs +24 -0
- package/default-views/auth/auth-hidden-fields.hbs +8 -0
- package/default-views/auth/change-password.hbs +58 -0
- package/default-views/auth/goodbye.hbs +23 -0
- package/default-views/auth/login-required.hbs +34 -0
- package/default-views/auth/login-tls.hbs +11 -0
- package/default-views/auth/login-username-password.hbs +28 -0
- package/default-views/auth/login.hbs +55 -0
- package/default-views/auth/no-permission.hbs +29 -0
- package/default-views/auth/password-changed.hbs +27 -0
- package/default-views/auth/reset-link-sent.hbs +21 -0
- package/default-views/auth/reset-password.hbs +52 -0
- package/default-views/auth/sharing.hbs +49 -0
- package/default-views/shared/create-account.hbs +8 -0
- package/default-views/shared/error.hbs +5 -0
- package/docs/how-to-delete-your-account.md +56 -0
- package/docs/login-and-grant-access-to-application.md +32 -0
- package/examples/custom-error-handling.js +31 -0
- package/examples/ldp-with-webid.js +12 -0
- package/examples/simple-express-app.js +20 -0
- package/examples/simple-ldp-server.js +8 -0
- package/favicon.ico +0 -0
- package/favicon.ico.acl +15 -0
- package/index.html +48 -0
- package/index.js +3 -0
- package/lib/acl-checker.js +274 -0
- package/lib/api/accounts/user-accounts.js +88 -0
- package/lib/api/authn/force-user.js +21 -0
- package/lib/api/authn/index.js +5 -0
- package/lib/api/authn/webid-oidc.js +202 -0
- package/lib/api/authn/webid-tls.js +69 -0
- package/lib/api/index.js +6 -0
- package/lib/capability-discovery.js +54 -0
- package/lib/common/fs-utils.js +43 -0
- package/lib/common/template-utils.js +50 -0
- package/lib/common/user-utils.js +28 -0
- package/lib/create-app.js +322 -0
- package/lib/create-server.js +107 -0
- package/lib/debug.js +17 -0
- package/lib/handlers/allow.js +82 -0
- package/lib/handlers/auth-proxy.js +63 -0
- package/lib/handlers/copy.js +39 -0
- package/lib/handlers/cors-proxy.js +95 -0
- package/lib/handlers/delete.js +23 -0
- package/lib/handlers/error-pages.js +212 -0
- package/lib/handlers/get.js +219 -0
- package/lib/handlers/index.js +42 -0
- package/lib/handlers/options.js +33 -0
- package/lib/handlers/patch/n3-patch-parser.js +49 -0
- package/lib/handlers/patch/sparql-update-parser.js +16 -0
- package/lib/handlers/patch.js +203 -0
- package/lib/handlers/post.js +99 -0
- package/lib/handlers/put.js +56 -0
- package/lib/handlers/restrict-to-top-domain.js +13 -0
- package/lib/header.js +136 -0
- package/lib/http-error.js +34 -0
- package/lib/ldp-container.js +161 -0
- package/lib/ldp-copy.js +73 -0
- package/lib/ldp-middleware.js +32 -0
- package/lib/ldp.js +620 -0
- package/lib/lock.js +10 -0
- package/lib/metadata.js +10 -0
- package/lib/models/account-manager.js +603 -0
- package/lib/models/account-template.js +152 -0
- package/lib/models/authenticator.js +333 -0
- package/lib/models/oidc-manager.js +53 -0
- package/lib/models/solid-host.js +131 -0
- package/lib/models/user-account.js +112 -0
- package/lib/models/webid-tls-certificate.js +184 -0
- package/lib/payment-pointer-discovery.js +83 -0
- package/lib/requests/add-cert-request.js +138 -0
- package/lib/requests/auth-request.js +234 -0
- package/lib/requests/create-account-request.js +468 -0
- package/lib/requests/delete-account-confirm-request.js +170 -0
- package/lib/requests/delete-account-request.js +144 -0
- package/lib/requests/login-request.js +205 -0
- package/lib/requests/password-change-request.js +201 -0
- package/lib/requests/password-reset-email-request.js +199 -0
- package/lib/requests/sharing-request.js +259 -0
- package/lib/resource-mapper.js +198 -0
- package/lib/server-config.js +167 -0
- package/lib/services/blacklist-service.js +33 -0
- package/lib/services/email-service.js +162 -0
- package/lib/services/token-service.js +47 -0
- package/lib/utils.js +254 -0
- package/lib/webid/index.js +13 -0
- package/lib/webid/lib/get.js +27 -0
- package/lib/webid/lib/parse.js +12 -0
- package/lib/webid/tls/index.js +185 -0
- package/package.json +172 -0
- package/renovate.json +5 -0
- package/robots.txt +3 -0
- package/robots.txt.acl +15 -0
- package/static/account-recovery.html +78 -0
- package/static/popup-redirect.html +1 -0
- package/static/signup.html +108 -0
- package/static/signup.html.acl +14 -0
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
module.exports.addContainerStats = addContainerStats
|
|
2
|
+
module.exports.addFile = addFile
|
|
3
|
+
module.exports.addStats = addStats
|
|
4
|
+
module.exports.readdir = readdir
|
|
5
|
+
|
|
6
|
+
const $rdf = require('rdflib')
|
|
7
|
+
const debug = require('./debug')
|
|
8
|
+
const error = require('./http-error')
|
|
9
|
+
const fs = require('fs')
|
|
10
|
+
const ns = require('solid-namespace')($rdf)
|
|
11
|
+
const mime = require('mime-types')
|
|
12
|
+
const path = require('path')
|
|
13
|
+
|
|
14
|
+
async function addContainerStats (ldp, reqUri, filename, resourceGraph) {
|
|
15
|
+
const containerStats = await ldp.stat(filename)
|
|
16
|
+
addStats(resourceGraph, reqUri, containerStats, filename)
|
|
17
|
+
resourceGraph.add(
|
|
18
|
+
resourceGraph.sym(reqUri),
|
|
19
|
+
ns.rdf('type'),
|
|
20
|
+
ns.ldp('BasicContainer'))
|
|
21
|
+
resourceGraph.add(
|
|
22
|
+
resourceGraph.sym(reqUri),
|
|
23
|
+
ns.rdf('type'),
|
|
24
|
+
ns.ldp('Container'))
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async function addFile (ldp, resourceGraph, containerUri, reqUri, container, file) {
|
|
28
|
+
// Skip .meta and .acl
|
|
29
|
+
if (file.endsWith(ldp.suffixMeta) || file.endsWith(ldp.suffixAcl)) {
|
|
30
|
+
return null
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const filePath = path.join(container, file)
|
|
34
|
+
|
|
35
|
+
// Get file stats
|
|
36
|
+
let stats
|
|
37
|
+
try {
|
|
38
|
+
stats = await ldp.stat(filePath)
|
|
39
|
+
} catch (e) {
|
|
40
|
+
return null
|
|
41
|
+
}
|
|
42
|
+
const memberUri = reqUri + (stats.isDirectory() ? '/' : '')
|
|
43
|
+
|
|
44
|
+
// Add fileStats to resource Graph
|
|
45
|
+
addStats(resourceGraph, memberUri, stats, file)
|
|
46
|
+
|
|
47
|
+
// Add to `contains` list
|
|
48
|
+
resourceGraph.add(
|
|
49
|
+
resourceGraph.sym(containerUri),
|
|
50
|
+
ns.ldp('contains'),
|
|
51
|
+
resourceGraph.sym(memberUri))
|
|
52
|
+
|
|
53
|
+
// Set up a metaFile path
|
|
54
|
+
// Earlier code used a .ttl file as its own meta file, which
|
|
55
|
+
// caused massive data files to parsed as part of deirectory listings just looking for type triples
|
|
56
|
+
const metaFile = containerUri + file + ldp.suffixMeta
|
|
57
|
+
|
|
58
|
+
let metadataGraph
|
|
59
|
+
try {
|
|
60
|
+
metadataGraph = await getMetadataGraph(ldp, metaFile, memberUri)
|
|
61
|
+
} catch (err) {
|
|
62
|
+
metadataGraph = $rdf.graph()
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Add Container or BasicContainer types
|
|
66
|
+
if (stats.isDirectory()) {
|
|
67
|
+
resourceGraph.add(
|
|
68
|
+
metadataGraph.sym(memberUri),
|
|
69
|
+
ns.rdf('type'),
|
|
70
|
+
ns.ldp('BasicContainer'))
|
|
71
|
+
|
|
72
|
+
resourceGraph.add(
|
|
73
|
+
metadataGraph.sym(memberUri),
|
|
74
|
+
ns.rdf('type'),
|
|
75
|
+
ns.ldp('Container'))
|
|
76
|
+
}
|
|
77
|
+
// Add generic LDP type
|
|
78
|
+
resourceGraph.add(
|
|
79
|
+
metadataGraph.sym(memberUri),
|
|
80
|
+
ns.rdf('type'),
|
|
81
|
+
ns.ldp('Resource'))
|
|
82
|
+
|
|
83
|
+
// Add type from metadataGraph
|
|
84
|
+
metadataGraph
|
|
85
|
+
.statementsMatching(
|
|
86
|
+
metadataGraph.sym(memberUri),
|
|
87
|
+
ns.rdf('type'),
|
|
88
|
+
undefined)
|
|
89
|
+
.forEach(function (typeStatement) {
|
|
90
|
+
// If the current is a file and its type is BasicContainer,
|
|
91
|
+
// This is not possible, so do not infer its type!
|
|
92
|
+
if (
|
|
93
|
+
(
|
|
94
|
+
typeStatement.object.uri !== ns.ldp('BasicContainer').uri &&
|
|
95
|
+
typeStatement.object.uri !== ns.ldp('Container').uri
|
|
96
|
+
) ||
|
|
97
|
+
!stats.isFile()
|
|
98
|
+
) {
|
|
99
|
+
resourceGraph.add(
|
|
100
|
+
resourceGraph.sym(reqUri),
|
|
101
|
+
typeStatement.predicate,
|
|
102
|
+
typeStatement.object)
|
|
103
|
+
}
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
return null
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function addStats (resourceGraph, reqUri, stats, filename) {
|
|
110
|
+
resourceGraph.add(
|
|
111
|
+
resourceGraph.sym(reqUri),
|
|
112
|
+
ns.stat('mtime'), // Deprecate?
|
|
113
|
+
stats.mtime.getTime() / 1000)
|
|
114
|
+
|
|
115
|
+
resourceGraph.add(
|
|
116
|
+
resourceGraph.sym(reqUri),
|
|
117
|
+
ns.dct('modified'),
|
|
118
|
+
stats.mtime) // An actual datetime value from a Date object
|
|
119
|
+
|
|
120
|
+
resourceGraph.add(
|
|
121
|
+
resourceGraph.sym(reqUri),
|
|
122
|
+
ns.stat('size'),
|
|
123
|
+
stats.size)
|
|
124
|
+
|
|
125
|
+
if (!reqUri.endsWith('/') && mime.lookup(filename)) { // Is the file has a well-known type,
|
|
126
|
+
const type = 'http://www.w3.org/ns/iana/media-types/' + mime.lookup(filename) + '#Resource'
|
|
127
|
+
resourceGraph.add(
|
|
128
|
+
resourceGraph.sym(reqUri),
|
|
129
|
+
ns.rdf('type'), // convert MIME type to RDF
|
|
130
|
+
resourceGraph.sym(type)
|
|
131
|
+
)
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function readdir (filename) {
|
|
136
|
+
debug.handlers('GET -- Reading directory')
|
|
137
|
+
return new Promise((resolve, reject) => {
|
|
138
|
+
fs.readdir(filename, function (err, files) {
|
|
139
|
+
if (err) {
|
|
140
|
+
debug.handlers('GET -- Error reading files: ' + err)
|
|
141
|
+
return reject(error(err, 'Can\'t read container'))
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
debug.handlers('Files in directory: ' + files.toString().slice(0, 100))
|
|
145
|
+
return resolve(files)
|
|
146
|
+
})
|
|
147
|
+
})
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
async function getMetadataGraph (ldp, metaFile) {
|
|
151
|
+
const metaStats = await ldp.stat(metaFile)
|
|
152
|
+
if (metaStats && metaStats.isFile()) {
|
|
153
|
+
try {
|
|
154
|
+
return await ldp.getGraph(metaFile)
|
|
155
|
+
} catch (err) {
|
|
156
|
+
throw error(err, 'Can\'t parse container metadata')
|
|
157
|
+
}
|
|
158
|
+
} else {
|
|
159
|
+
return $rdf.graph()
|
|
160
|
+
}
|
|
161
|
+
}
|
package/lib/ldp-copy.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
module.exports = copy
|
|
2
|
+
|
|
3
|
+
const debug = require('./debug')
|
|
4
|
+
const fs = require('fs')
|
|
5
|
+
const mkdirp = require('fs-extra').mkdirp
|
|
6
|
+
const error = require('./http-error')
|
|
7
|
+
const path = require('path')
|
|
8
|
+
const http = require('http')
|
|
9
|
+
const https = require('https')
|
|
10
|
+
const getContentType = require('./utils').getContentType
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Cleans up a file write stream (ends stream, deletes the file).
|
|
14
|
+
* @method cleanupFileStream
|
|
15
|
+
* @private
|
|
16
|
+
* @param stream {WriteStream}
|
|
17
|
+
*/
|
|
18
|
+
function cleanupFileStream (stream) {
|
|
19
|
+
const streamPath = stream.path
|
|
20
|
+
stream.destroy()
|
|
21
|
+
fs.unlinkSync(streamPath)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Performs an LDP Copy operation, imports a remote resource to a local path.
|
|
26
|
+
* @param resourceMapper {ResourceMapper} A resource mapper instance.
|
|
27
|
+
* @param copyToUri {Object} The location (in the current domain) to copy to.
|
|
28
|
+
* @param copyFromUri {String} Location of remote resource to copy from
|
|
29
|
+
* @return A promise resolving when the copy operation is finished
|
|
30
|
+
*/
|
|
31
|
+
function copy (resourceMapper, copyToUri, copyFromUri) {
|
|
32
|
+
return new Promise((resolve, reject) => {
|
|
33
|
+
const request = /^https:/.test(copyFromUri) ? https : http
|
|
34
|
+
request.get(copyFromUri)
|
|
35
|
+
.on('error', function (err) {
|
|
36
|
+
debug.handlers('COPY -- Error requesting source file: ' + err)
|
|
37
|
+
this.end()
|
|
38
|
+
return reject(new Error('Error writing data: ' + err))
|
|
39
|
+
})
|
|
40
|
+
.on('response', function (response) {
|
|
41
|
+
if (response.statusCode !== 200) {
|
|
42
|
+
debug.handlers('COPY -- HTTP error reading source file: ' + response.statusMessage)
|
|
43
|
+
this.end()
|
|
44
|
+
const error = new Error('Error reading source file: ' + response.statusMessage)
|
|
45
|
+
error.statusCode = response.statusCode
|
|
46
|
+
return reject(error)
|
|
47
|
+
}
|
|
48
|
+
// Grab the content type from the source
|
|
49
|
+
const contentType = getContentType(response.headers)
|
|
50
|
+
resourceMapper.mapUrlToFile({ url: copyToUri, createIfNotExists: true, contentType })
|
|
51
|
+
.then(({ path: copyToPath }) => {
|
|
52
|
+
mkdirp(path.dirname(copyToPath), function (err) {
|
|
53
|
+
if (err) {
|
|
54
|
+
debug.handlers('COPY -- Error creating destination directory: ' + err)
|
|
55
|
+
return reject(new Error('Failed to create the path to the destination resource: ' + err))
|
|
56
|
+
}
|
|
57
|
+
const destinationStream = fs.createWriteStream(copyToPath)
|
|
58
|
+
.on('error', function (err) {
|
|
59
|
+
cleanupFileStream(this)
|
|
60
|
+
return reject(new Error('Error writing data: ' + err))
|
|
61
|
+
})
|
|
62
|
+
.on('finish', function () {
|
|
63
|
+
// Success
|
|
64
|
+
debug.handlers('COPY -- Wrote data to: ' + copyToPath)
|
|
65
|
+
resolve()
|
|
66
|
+
})
|
|
67
|
+
response.pipe(destinationStream)
|
|
68
|
+
})
|
|
69
|
+
})
|
|
70
|
+
.catch(() => reject(error(500, 'Could not find target file to copy')))
|
|
71
|
+
})
|
|
72
|
+
})
|
|
73
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
module.exports = LdpMiddleware
|
|
2
|
+
|
|
3
|
+
const express = require('express')
|
|
4
|
+
const header = require('./header')
|
|
5
|
+
const allow = require('./handlers/allow')
|
|
6
|
+
const get = require('./handlers/get')
|
|
7
|
+
const post = require('./handlers/post')
|
|
8
|
+
const put = require('./handlers/put')
|
|
9
|
+
const del = require('./handlers/delete')
|
|
10
|
+
const patch = require('./handlers/patch')
|
|
11
|
+
const index = require('./handlers/index')
|
|
12
|
+
const copy = require('./handlers/copy')
|
|
13
|
+
|
|
14
|
+
function LdpMiddleware (corsSettings) {
|
|
15
|
+
const router = express.Router('/')
|
|
16
|
+
|
|
17
|
+
// Add Link headers
|
|
18
|
+
router.use(header.linksHandler)
|
|
19
|
+
|
|
20
|
+
if (corsSettings) {
|
|
21
|
+
router.use(corsSettings)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
router.copy('/*', allow('Write'), copy)
|
|
25
|
+
router.get('/*', index, allow('Read'), header.addPermissions, get)
|
|
26
|
+
router.post('/*', allow('Append'), post)
|
|
27
|
+
router.patch('/*', allow('Append'), patch)
|
|
28
|
+
router.put('/*', allow('Write'), put)
|
|
29
|
+
router.delete('/*', allow('Write'), del)
|
|
30
|
+
|
|
31
|
+
return router
|
|
32
|
+
}
|