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.
Files changed (170) hide show
  1. package/.acl +10 -0
  2. package/.github/workflows/ci.yml +47 -0
  3. package/.nvmrc +1 -0
  4. package/.snyk +35 -0
  5. package/.well-known/.acl +15 -0
  6. package/CHANGELOG.md +198 -0
  7. package/CONTRIBUTING.md +139 -0
  8. package/CONTRIBUTORS.md +36 -0
  9. package/Dockerfile +22 -0
  10. package/LICENSE.md +23 -0
  11. package/README.md +453 -0
  12. package/bin/lib/cli-utils.js +85 -0
  13. package/bin/lib/cli.js +39 -0
  14. package/bin/lib/init.js +94 -0
  15. package/bin/lib/invalidUsernames.js +148 -0
  16. package/bin/lib/migrateLegacyResources.js +69 -0
  17. package/bin/lib/options.js +399 -0
  18. package/bin/lib/start.js +148 -0
  19. package/bin/lib/updateIndex.js +56 -0
  20. package/bin/solid +3 -0
  21. package/bin/solid-test +12 -0
  22. package/bin/solid.js +3 -0
  23. package/common/css/solid.css +58 -0
  24. package/common/fonts/glyphicons-halflings-regular.eot +0 -0
  25. package/common/fonts/glyphicons-halflings-regular.svg +288 -0
  26. package/common/fonts/glyphicons-halflings-regular.ttf +0 -0
  27. package/common/fonts/glyphicons-halflings-regular.woff +0 -0
  28. package/common/fonts/glyphicons-halflings-regular.woff2 +0 -0
  29. package/common/img/.gitkeep +0 -0
  30. package/common/js/auth-buttons.js +65 -0
  31. package/common/js/solid.js +454 -0
  32. package/common/well-known/security.txt +2 -0
  33. package/config/defaults.js +25 -0
  34. package/config/usernames-blacklist.json +4 -0
  35. package/config.json-default +22 -0
  36. package/default-templates/emails/delete-account.js +49 -0
  37. package/default-templates/emails/invalid-username.js +30 -0
  38. package/default-templates/emails/reset-password.js +49 -0
  39. package/default-templates/emails/welcome.js +39 -0
  40. package/default-templates/new-account/.acl +26 -0
  41. package/default-templates/new-account/.meta +5 -0
  42. package/default-templates/new-account/.meta.acl +25 -0
  43. package/default-templates/new-account/.well-known/.acl +19 -0
  44. package/default-templates/new-account/favicon.ico +0 -0
  45. package/default-templates/new-account/favicon.ico.acl +26 -0
  46. package/default-templates/new-account/inbox/.acl +26 -0
  47. package/default-templates/new-account/private/.acl +10 -0
  48. package/default-templates/new-account/profile/.acl +19 -0
  49. package/default-templates/new-account/profile/card$.ttl +25 -0
  50. package/default-templates/new-account/public/.acl +19 -0
  51. package/default-templates/new-account/robots.txt +3 -0
  52. package/default-templates/new-account/robots.txt.acl +26 -0
  53. package/default-templates/new-account/settings/.acl +20 -0
  54. package/default-templates/new-account/settings/prefs.ttl +15 -0
  55. package/default-templates/new-account/settings/privateTypeIndex.ttl +4 -0
  56. package/default-templates/new-account/settings/publicTypeIndex.ttl +4 -0
  57. package/default-templates/new-account/settings/publicTypeIndex.ttl.acl +25 -0
  58. package/default-templates/new-account/settings/serverSide.ttl.acl +13 -0
  59. package/default-templates/new-account/settings/serverSide.ttl.inactive +12 -0
  60. package/default-templates/server/.acl +10 -0
  61. package/default-templates/server/.well-known/.acl +15 -0
  62. package/default-templates/server/favicon.ico +0 -0
  63. package/default-templates/server/favicon.ico.acl +15 -0
  64. package/default-templates/server/index.html +55 -0
  65. package/default-templates/server/robots.txt +3 -0
  66. package/default-templates/server/robots.txt.acl +15 -0
  67. package/default-views/account/account-deleted.hbs +17 -0
  68. package/default-views/account/delete-confirm.hbs +51 -0
  69. package/default-views/account/delete-link-sent.hbs +17 -0
  70. package/default-views/account/delete.hbs +51 -0
  71. package/default-views/account/invalid-username.hbs +22 -0
  72. package/default-views/account/register-disabled.hbs +6 -0
  73. package/default-views/account/register-form.hbs +132 -0
  74. package/default-views/account/register.hbs +24 -0
  75. package/default-views/auth/auth-hidden-fields.hbs +8 -0
  76. package/default-views/auth/change-password.hbs +58 -0
  77. package/default-views/auth/goodbye.hbs +23 -0
  78. package/default-views/auth/login-required.hbs +34 -0
  79. package/default-views/auth/login-tls.hbs +11 -0
  80. package/default-views/auth/login-username-password.hbs +28 -0
  81. package/default-views/auth/login.hbs +55 -0
  82. package/default-views/auth/no-permission.hbs +29 -0
  83. package/default-views/auth/password-changed.hbs +27 -0
  84. package/default-views/auth/reset-link-sent.hbs +21 -0
  85. package/default-views/auth/reset-password.hbs +52 -0
  86. package/default-views/auth/sharing.hbs +49 -0
  87. package/default-views/shared/create-account.hbs +8 -0
  88. package/default-views/shared/error.hbs +5 -0
  89. package/docs/how-to-delete-your-account.md +56 -0
  90. package/docs/login-and-grant-access-to-application.md +32 -0
  91. package/examples/custom-error-handling.js +31 -0
  92. package/examples/ldp-with-webid.js +12 -0
  93. package/examples/simple-express-app.js +20 -0
  94. package/examples/simple-ldp-server.js +8 -0
  95. package/favicon.ico +0 -0
  96. package/favicon.ico.acl +15 -0
  97. package/index.html +48 -0
  98. package/index.js +3 -0
  99. package/lib/acl-checker.js +274 -0
  100. package/lib/api/accounts/user-accounts.js +88 -0
  101. package/lib/api/authn/force-user.js +21 -0
  102. package/lib/api/authn/index.js +5 -0
  103. package/lib/api/authn/webid-oidc.js +202 -0
  104. package/lib/api/authn/webid-tls.js +69 -0
  105. package/lib/api/index.js +6 -0
  106. package/lib/capability-discovery.js +54 -0
  107. package/lib/common/fs-utils.js +43 -0
  108. package/lib/common/template-utils.js +50 -0
  109. package/lib/common/user-utils.js +28 -0
  110. package/lib/create-app.js +322 -0
  111. package/lib/create-server.js +107 -0
  112. package/lib/debug.js +17 -0
  113. package/lib/handlers/allow.js +82 -0
  114. package/lib/handlers/auth-proxy.js +63 -0
  115. package/lib/handlers/copy.js +39 -0
  116. package/lib/handlers/cors-proxy.js +95 -0
  117. package/lib/handlers/delete.js +23 -0
  118. package/lib/handlers/error-pages.js +212 -0
  119. package/lib/handlers/get.js +219 -0
  120. package/lib/handlers/index.js +42 -0
  121. package/lib/handlers/options.js +33 -0
  122. package/lib/handlers/patch/n3-patch-parser.js +49 -0
  123. package/lib/handlers/patch/sparql-update-parser.js +16 -0
  124. package/lib/handlers/patch.js +203 -0
  125. package/lib/handlers/post.js +99 -0
  126. package/lib/handlers/put.js +56 -0
  127. package/lib/handlers/restrict-to-top-domain.js +13 -0
  128. package/lib/header.js +136 -0
  129. package/lib/http-error.js +34 -0
  130. package/lib/ldp-container.js +161 -0
  131. package/lib/ldp-copy.js +73 -0
  132. package/lib/ldp-middleware.js +32 -0
  133. package/lib/ldp.js +620 -0
  134. package/lib/lock.js +10 -0
  135. package/lib/metadata.js +10 -0
  136. package/lib/models/account-manager.js +603 -0
  137. package/lib/models/account-template.js +152 -0
  138. package/lib/models/authenticator.js +333 -0
  139. package/lib/models/oidc-manager.js +53 -0
  140. package/lib/models/solid-host.js +131 -0
  141. package/lib/models/user-account.js +112 -0
  142. package/lib/models/webid-tls-certificate.js +184 -0
  143. package/lib/payment-pointer-discovery.js +83 -0
  144. package/lib/requests/add-cert-request.js +138 -0
  145. package/lib/requests/auth-request.js +234 -0
  146. package/lib/requests/create-account-request.js +468 -0
  147. package/lib/requests/delete-account-confirm-request.js +170 -0
  148. package/lib/requests/delete-account-request.js +144 -0
  149. package/lib/requests/login-request.js +205 -0
  150. package/lib/requests/password-change-request.js +201 -0
  151. package/lib/requests/password-reset-email-request.js +199 -0
  152. package/lib/requests/sharing-request.js +259 -0
  153. package/lib/resource-mapper.js +198 -0
  154. package/lib/server-config.js +167 -0
  155. package/lib/services/blacklist-service.js +33 -0
  156. package/lib/services/email-service.js +162 -0
  157. package/lib/services/token-service.js +47 -0
  158. package/lib/utils.js +254 -0
  159. package/lib/webid/index.js +13 -0
  160. package/lib/webid/lib/get.js +27 -0
  161. package/lib/webid/lib/parse.js +12 -0
  162. package/lib/webid/tls/index.js +185 -0
  163. package/package.json +172 -0
  164. package/renovate.json +5 -0
  165. package/robots.txt +3 -0
  166. package/robots.txt.acl +15 -0
  167. package/static/account-recovery.html +78 -0
  168. package/static/popup-redirect.html +1 -0
  169. package/static/signup.html +108 -0
  170. package/static/signup.html.acl +14 -0
package/README.md ADDED
@@ -0,0 +1,453 @@
1
+ # solid-server in Node
2
+
3
+ [![](https://img.shields.io/badge/project-Solid-7C4DFF.svg?style=flat-square)](https://github.com/solid/solid)
4
+ [![Build Status](https://travis-ci.org/solid/node-solid-server.svg?branch=master&style=flat-square)](https://travis-ci.org/solid/node-solid-server)
5
+ [![NPM Version](https://img.shields.io/npm/v/solid-server.svg?style=flat-square)](https://npm.im/solid-server)
6
+ [![Gitter chat](https://img.shields.io/badge/gitter-join%20chat%20%E2%86%92-brightgreen.svg?style=flat-square)](http://gitter.im/solid/node-solid-server)
7
+
8
+ > [Solid](https://github.com/solid) server in [NodeJS](https://nodejs.org/)
9
+
10
+ `solid-server` lets you run a Solid server on top of the file-system. You can use it as a [command-line tool](https://github.com/solid/node-solid-server/blob/master/README.md#command-line-usage) (easy) or as a [library](https://github.com/solid/node-solid-server/blob/master/README.md#library-usage) (advanced).
11
+
12
+ ## Solid Features supported
13
+ - [x] [Linked Data Platform](http://www.w3.org/TR/ldp/)
14
+ - [x] [Web Access Control](http://www.w3.org/wiki/WebAccessControl)
15
+ - [x] [WebID+TLS Authentication](https://www.w3.org/2005/Incubator/webid/spec/tls/)
16
+ - [x] [Real-time live updates](https://github.com/solid/solid-spec#subscribing) (using WebSockets)
17
+ - [x] Identity provider for WebID
18
+ - [x] CORS proxy for cross-site data access
19
+ - [x] Group members in ACL
20
+ - [x] Email account recovery
21
+
22
+ ## Command Line Usage
23
+
24
+ ### Install
25
+
26
+ You can install and run the server either using Node.js directly or using
27
+ [Docker](https://www.docker.com/). This and the following sections describe the
28
+ first approach, for the second approach see the section [use Docker](#use-docker)
29
+ Section below.
30
+
31
+ To install, first install [Node](https://nodejs.org/en/) and then run the following
32
+
33
+ ```bash
34
+ $ npm install -g solid-server
35
+ ```
36
+
37
+ ### Run a single-user server (beginner)
38
+
39
+ The easiest way to setup `solid-server` is by running the wizard. This will create a `config.json` in your current folder
40
+
41
+ ```bash
42
+ $ solid init
43
+ ```
44
+ **Note**: If prompted for an SSL key and certificate, follow the instructions below.
45
+
46
+ To run your server, simply run `solid start`:
47
+
48
+ ```bash
49
+ $ solid start
50
+ # Solid server (solid v0.2.24) running on https://localhost:8443/
51
+ ```
52
+
53
+ If you prefer to use flags instead, the following would be the equivalent
54
+
55
+ ```bash
56
+ $ solid start --port 8443 --ssl-key path/to/ssl-key.pem --ssl-cert path/to/ssl-cert.pem
57
+ # Solid server (solid v0.2.24) running on https://localhost:8443/
58
+ ```
59
+
60
+ If you want to run `solid` on a particular folder (different from the one you are in, e.g. `path/to/folder`):
61
+
62
+ ```bash
63
+ $ solid start --root path/to/folder --port 8443 --ssl-key path/to/ssl-key.pem --ssl-cert path/to/ssl-cert.pem
64
+ # Solid server (solid v0.2.24) running on https://localhost:8443/
65
+ ```
66
+
67
+ ### Running in development environments
68
+
69
+ Solid requires SSL certificates to be valid, so you cannot use self-signed certificates. To switch off this security feature in development environments, you can use the `bin/solid-test` executable, which unsets the `NODE_TLS_REJECT_UNAUTHORIZED` flag and sets the `rejectUnauthorized` option.
70
+
71
+ If you want to run in multi-user mode on localhost, do the following:
72
+ * configure the server as such with `bin/solid-test init`
73
+ * start the server with `bin/solid-test start`
74
+ * visit https://localhost:8443 and register a user, for instance 'myusername'.
75
+ * Edit your hosts file and add a line `127.0.0.1 myusername.localhost`
76
+ * Now you can visit https://myusername.localhost:8443.
77
+
78
+ ##### How do I get an SSL key and certificate?
79
+ You need an SSL certificate from a _certificate authority_, such as your domain provider or [Let's Encrypt!](https://letsencrypt.org/getting-started/).
80
+
81
+ For testing purposes, you can use `bin/solid-test` with a _self-signed_ certificate, generated as follows:
82
+
83
+ ```
84
+ $ openssl req -outform PEM -keyform PEM -new -x509 -sha256 -newkey rsa:2048 -nodes -keyout ../privkey.pem -days 365 -out ../fullchain.pem
85
+
86
+ ```
87
+
88
+ Note that this example creates the `fullchain.pem` and `privkey.pem` files
89
+ in a directory one level higher from the current, so that you don't
90
+ accidentally commit your certificates to `solid` while you're developing.
91
+
92
+ If you would like to get rid of the browser warnings, import your fullchain.pem certificate into your 'Trusted Root Certificate' store.
93
+
94
+ ### Running Solid behind a reverse proxy (such as NGINX)
95
+ See [Running Solid behind a reverse proxy](https://github.com/solid/node-solid-server/wiki/Running-Solid-behind-a-reverse-proxy).
96
+
97
+ ### Run multi-user server (intermediate)
98
+
99
+ You can run `solid` so that new users can sign up, in other words, get their WebIDs _username.yourdomain.com_.
100
+
101
+ Pre-requisites:
102
+ - Get a [Wildcard Certificate](https://en.wikipedia.org/wiki/Wildcard_certificate)
103
+ - Add a Wildcard DNS record in your DNS zone (e.g.`*.yourdomain.com`)
104
+ - (If you are running locally) Add the line `127.0.0.1 *.localhost` to `/etc/hosts`
105
+
106
+ ```bash
107
+ $ solid init
108
+ ..
109
+ ? Allow users to register their WebID (y/N) # write `y` here
110
+ ..
111
+ $ solid start
112
+ ```
113
+
114
+ Otherwise, if you want to use flags, this would be the equivalent
115
+
116
+ ```bash
117
+ $ solid start --multiuser --port 8443 --ssl-cert /path/to/cert --ssl-key /path/to/key --root ./data
118
+ ```
119
+
120
+ Your users will have a dedicated folder under `./data` at `./data/<username>.<yourdomain.tld>`. Also, your root domain's website will be in `./data/<yourdomain.tld>`. New users can create accounts on `/api/accounts/new` and create new certificates on `/api/accounts/cert`. An easy-to-use sign-up tool is found on `/api/accounts`.
121
+
122
+ ##### How can I send emails to my users with my Gmail?
123
+
124
+ > To use Gmail you may need to configure ["Allow Less Secure Apps"](https://www.google.com/settings/security/lesssecureapps) in your Gmail account unless you are using 2FA in which case you would have to create an [Application Specific](https://security.google.com/settings/security/apppasswords) password. You also may need to unlock your account with ["Allow access to your Google account"](https://accounts.google.com/DisplayUnlockCaptcha) to use SMTP.
125
+
126
+ also add to `config.json`
127
+ ```
128
+ "useEmail": true,
129
+ "emailHost": "smtp.gmail.com",
130
+ "emailPort": "465",
131
+ "emailAuthUser": "xxxx@gmail.com",
132
+ "emailAuthPass": "gmailPass"
133
+ ```
134
+
135
+ ### Upgrading from version <5.3
136
+ Please take into account the [v5.3 upgrade notes](https://github.com/solid/node-solid-server/blob/master/CHANGELOG.md#530-upgrade-notes).
137
+
138
+ ### Upgrading from version <5.0
139
+ To upgrade from version 4 to the current version 5, you need to run a migration script, as explained in the [v5.0 upgrade notes](https://github.com/solid/node-solid-server/blob/master/CHANGELOG.md#500-upgrade-notes).
140
+
141
+ Also, be aware that starting from version 5, third-party apps are untrusted by default. To trust a third-party app, before you can log in to it, you first need to go to your profile at https://example.com/profile/card#me (important to include the '#me' there), and then hover over the 'card' header to reveal the context menu. From there, select the 'A' symbol to go to your trusted applications pane, where you can whitelist third-party apps before using them. See also https://github.com/solid/node-solid-server/issues/1142 about streamlining this UX flow.
142
+
143
+ ### Extra flags (expert)
144
+ The command line tool has the following options
145
+
146
+ ```
147
+ $ solid
148
+
149
+ Usage: solid [options] [command]
150
+
151
+ Commands:
152
+ init [options] create solid server configurations
153
+ start [options] run the Solid server
154
+
155
+ Options:
156
+ -h, --help output usage information
157
+ -V, --version output the version number
158
+
159
+
160
+ $ solid init --help
161
+
162
+ Usage: init [options]
163
+ Create solid server configurations
164
+
165
+ Options:
166
+ -h, --help output usage information
167
+ --advanced Ask for all the settings
168
+
169
+
170
+ $ solid start --help
171
+
172
+ Usage: start [options]
173
+
174
+ run the Solid server
175
+
176
+
177
+ Options:
178
+
179
+ --root [value] Root folder to serve (default: './data')
180
+ --port [value] SSL port to use
181
+ --server-uri [value] Solid server uri (default: 'https://localhost:8443')
182
+ --webid Enable WebID authentication and access control (uses HTTPS)
183
+ --mount [value] Serve on a specific URL path (default: '/')
184
+ --config-path [value]
185
+ --config-file [value]
186
+ --db-path [value]
187
+ --auth [value] Pick an authentication strategy for WebID: `tls` or `oidc`
188
+ --owner [value] Set the owner of the storage (overwrites the root ACL file)
189
+ --ssl-key [value] Path to the SSL private key in PEM format
190
+ --ssl-cert [value] Path to the SSL certificate key in PEM format
191
+ --no-reject-unauthorized Accept self-signed certificates
192
+ --multiuser Enable multi-user mode
193
+ --idp [value] Obsolete; use --multiuser
194
+ --no-live Disable live support through WebSockets
195
+ --proxy [value] Obsolete; use --corsProxy
196
+ --cors-proxy [value] Serve the CORS proxy on this path
197
+ --suppress-data-browser Suppress provision of a data browser
198
+ --data-browser-path [value] An HTML file which is sent to allow users to browse the data (eg using mashlib.js)
199
+ --suffix-acl [value] Suffix for acl files (default: '.acl')
200
+ --suffix-meta [value] Suffix for metadata files (default: '.meta')
201
+ --secret [value] Secret used to sign the session ID cookie (e.g. "your secret phrase")
202
+ --error-pages [value] Folder from which to look for custom error pages files (files must be named <error-code>.html -- eg. 500.html)
203
+ --force-user [value] Force a WebID to always be logged in (useful when offline)
204
+ --strict-origin Enforce same origin policy in the ACL
205
+ --use-email Do you want to set up an email service?
206
+ --email-host [value] Host of your email service
207
+ --email-port [value] Port of your email service
208
+ --email-auth-user [value] User of your email service
209
+ --email-auth-pass [value] Password of your email service
210
+ --use-api-apps Do you want to load your default apps on /api/apps?
211
+ --api-apps [value] Path to the folder to mount on /api/apps
212
+ --redirect-http-from [value] HTTP port or ','-separated ports to redirect to the solid server port (e.g. "80,8080").
213
+ --server-name [value] A name for your server (not required, but will be presented on your server's frontpage)
214
+ --server-description [value] A description of your server (not required)
215
+ --server-logo [value] A logo that represents you, your brand, or your server (not required)
216
+ --enforce-toc Do you want to enforce Terms & Conditions for your service?
217
+ --toc-uri [value] URI to your Terms & Conditions
218
+ --support-email [value] The support email you provide for your users (not required)
219
+ -q, --quiet Do not print the logs to console
220
+ -h, --help output usage information
221
+ ```
222
+
223
+ Instead of using flags, these same options can also be configured via environment variables taking the form of `SOLID_` followed by the `SNAKE_CASE` of the flag. For example `--api-apps` can be set via the `SOLID_API_APPS`environment variable, and `--serverUri` can be set with `SOLID_SERVER_URI`.
224
+
225
+ CLI flags take precedence over Environment variables, which take precedence over entries in the config file.
226
+
227
+ Configuring Solid via the config file can be a concise and convenient method and is the generally recommended approach. CLI flags can be useful when you would like to override a single configuration parameter, and using environment variables can be helpful in situations where you wish to deploy a single generic Docker image to multiple environments.
228
+
229
+ ## Use Docker
230
+
231
+
232
+ ### Production usage
233
+
234
+ See the [documentation to run Solid using docker and docker-compose](https://github.com/solid/node-solid-server/tree/master/docker-image).
235
+
236
+ We have automatic builds set up, so commits to master will trigger a build of https://hub.docker.com/r/nodesolidserver/node-solid-server.
237
+
238
+ ### Development usage
239
+
240
+ If you want to use Docker in development, then you can build it locally with:
241
+
242
+ ```bash
243
+ git clone https://github.com/solid/node-solid-server
244
+ cd node-solid-server
245
+ docker build -t node-solid-server .
246
+ ```
247
+
248
+ Run with:
249
+ ```bash
250
+ docker run -p 8443:8443 --name solid node-solid-server
251
+ ```
252
+
253
+ This will enable you to login to solid on https://localhost:8443 and then create a new account
254
+ but not yet use that account. After a new account is made you will need to create an entry for
255
+ it in your local (/etc/)hosts file in line with the account and subdomain, i.e. --
256
+
257
+ ```pre
258
+ 127.0.0.1 newsoliduser.localhost
259
+ ```
260
+
261
+ You can modify the config within the docker container as follows:
262
+
263
+ - Copy the `config.json` to the current directory with:
264
+ ```bash
265
+ docker cp solid:/usr/src/app/config.json .
266
+ ```
267
+ - Edit the `config.json` file
268
+ - Copy the file back with
269
+ ```bash
270
+ docker cp config.json solid:/usr/src/app/
271
+ ```
272
+ - Restart the server with
273
+ ```bash
274
+ docker restart solid
275
+ ```
276
+
277
+ ## Library Usage
278
+
279
+ ### Install Dependencies
280
+
281
+ ```
282
+ npm install
283
+ ```
284
+
285
+ ### Library Usage
286
+
287
+ The library provides two APIs:
288
+
289
+ - `solid.createServer(settings)`: starts a ready to use
290
+ [Express](http://expressjs.com) app.
291
+ - `lnode(settings)`: creates an [Express](http://expressjs.com) that you can
292
+ mount in your existing express app.
293
+
294
+ In case the `settings` is not passed, then it will start with the following
295
+ default settings.
296
+
297
+ ```javascript
298
+ {
299
+ cache: 0, // Set cache time (in seconds), 0 for no cache
300
+ live: true, // Enable live support through WebSockets
301
+ root: './', // Root location on the filesystem to serve resources
302
+ secret: 'node-ldp', // Express Session secret key
303
+ cert: false, // Path to the ssl cert
304
+ key: false, // Path to the ssl key
305
+ mount: '/', // Where to mount Linked Data Platform
306
+ webid: false, // Enable WebID+TLS authentication
307
+ suffixAcl: '.acl', // Suffix for acl files
308
+ corsProxy: false, // Where to mount the CORS proxy
309
+ errorHandler: false, // function(err, req, res, next) to have a custom error handler
310
+ errorPages: false // specify a path where the error pages are
311
+ }
312
+ ```
313
+
314
+ Have a look at the following examples or in the
315
+ [`examples/`](https://github.com/solid/node-solid-server/tree/master/examples) folder
316
+ for more complex ones
317
+
318
+ ##### Simple Example
319
+
320
+ You can create a `solid` server ready to use using `solid.createServer(opts)`
321
+
322
+ ```javascript
323
+ var solid = require('solid-server')
324
+ var ldp = solid.createServer({
325
+ key: '/path/to/sslKey.pem',
326
+ cert: '/path/to/sslCert.pem',
327
+ webid: true
328
+ })
329
+ ldp.listen(3000, function() {
330
+ // Started Linked Data Platform
331
+ })
332
+ ```
333
+
334
+ ##### Advanced Example
335
+
336
+ You can integrate `solid` in your existing [Express](https://expressjs.org)
337
+ app, by mounting the `solid` app on a specific path using `lnode(opts)`.
338
+
339
+ ```javascript
340
+ var solid = require('solid-server')
341
+ var app = require('express')()
342
+ app.use('/test', solid(yourSettings))
343
+ app.listen(3000, function() {
344
+ // Started Express app with ldp on '/test'
345
+ })
346
+ ...
347
+ ```
348
+
349
+ ##### Logging
350
+
351
+ Run your app with the `DEBUG` variable set:
352
+
353
+ ```bash
354
+ $ DEBUG="solid:*" node app.js
355
+ ```
356
+
357
+ ## Testing `solid` Locally
358
+
359
+ #### Pre-Requisites
360
+
361
+ In order to really get a feel for the Solid platform, and to test out `solid`,
362
+ you will need the following:
363
+
364
+ 1. A WebID profile and browser certificate from one of the Solid-compliant
365
+ identity providers, such as [solidcommunity.net](https://solidcommunity.net).
366
+
367
+ 2. A server-side SSL certificate for `solid` to use (see the section below
368
+ on creating a self-signed certificate for testing).
369
+
370
+ While these steps are technically optional (since you could launch it in
371
+ HTTP/LDP-only mode), you will not be able to use any actual Solid features
372
+ without them.
373
+
374
+ #### Creating a certificate for local testing
375
+
376
+ When deploying `solid` in production, we recommend that you go the
377
+ usual Certificate Authority route to generate your SSL certificate (as you
378
+ would with any website that supports HTTPS). However, for testing it locally,
379
+ you can easily [generate a self-signed certificate for whatever domain you're
380
+ Working with](https://github.com/solid/node-solid-server#how-do-i-get-an-ssl-key-and-certificate).
381
+
382
+ #### Accessing your server
383
+
384
+ If you started your `solid` server locally on port 8443 as in the example
385
+ above, you would then be able to visit `https://localhost:8443` in the browser
386
+ (ignoring the Untrusted Connection browser warnings as usual), where your
387
+ `solid` server would redirect you to the default data viewer app.
388
+
389
+ #### Editing your local `/etc/hosts`
390
+
391
+ To test certificates and account creation on subdomains, `solid`'s test suite
392
+ uses the following localhost domains: `nic.localhost`, `tim.localhost`, and
393
+ `nicola.localhost`. You will need to create host file entries for these, in
394
+ order for the tests to pass.
395
+
396
+ Edit your `/etc/hosts` file, and append:
397
+
398
+ ```
399
+ # Used for unit testing solid
400
+ 127.0.0.1 nic.localhost
401
+ 127.0.0.1 tim.localhost
402
+ 127.0.0.1 nicola.localhost
403
+ ```
404
+
405
+ #### Running the Unit Tests
406
+
407
+ ```bash
408
+ $ npm test
409
+ # running the tests with logs
410
+ $ DEBUG="solid:*" npm test
411
+ ```
412
+
413
+ In order to test a single component, you can run
414
+
415
+ ```javascript
416
+ npm run test-(acl|formats|params|patch)
417
+ ```
418
+
419
+ ## Blacklisted usernames
420
+
421
+ By default Solid will not allow [certain usernames as they might cause
422
+ confusion or allow vulnerabilies for social engineering](https://github.com/marteinn/The-Big-Username-Blacklist).
423
+ This list is configurable via `config/usernames-blacklist.json`. Solid does not
424
+ blacklist profanities by default.
425
+
426
+ ## Quota
427
+
428
+ By default, a file `serverSide.ttl.inactive` will be installed to new
429
+ PODs. If you rename it to `serverSide.ttl`, it will currently set a
430
+ quota for disk usage. This file is not writeable to users, only
431
+ server administrators who are authorized on the backend can modify
432
+ it. It is currently adviceable to remove it or set it inactive rather
433
+ than set a large quota, because the current implementation will impair
434
+ write performance if there is a lot of data.
435
+
436
+ ## Get help and contribute
437
+
438
+ Solid is only possible because of a large community of [contributors](https://github.com/solid/node-solid-server/blob/master/CONTRIBUTORS.md).
439
+ A heartfelt thank you to everyone for all of your efforts!
440
+
441
+ You can receive or provide help too:
442
+
443
+ - [Join us in Gitter](https://gitter.im/solid/chat) to chat about Solid or to hang out with us :)
444
+ - [NSS Gitter channel](https://gitter.im/solid/node-solid-server) for specific (installation) advice about this code base
445
+ - [Create a new issue](https://github.com/solid/node-solid-server/issues/new) to report bugs
446
+ - [Fix an issue](https://github.com/solid/node-solid-server/issues)
447
+ - Reach out to Jackson at jacksonm@inrupt.com to become more involved in maintaining Node Solid Server
448
+
449
+ Have a look at [CONTRIBUTING.md](https://github.com/solid/node-solid-server/blob/master/CONTRIBUTING.md).
450
+
451
+ ## License
452
+
453
+ [The MIT License](https://github.com/solid/node-solid-server/blob/master/LICENSE.md)
@@ -0,0 +1,85 @@
1
+ const fs = require('fs-extra')
2
+ const { red, cyan, bold } = require('colorette')
3
+ const { URL } = require('url')
4
+ const LDP = require('../../lib/ldp')
5
+ const AccountManager = require('../../lib/models/account-manager')
6
+ const SolidHost = require('../../lib/models/solid-host')
7
+
8
+ module.exports.getAccountManager = getAccountManager
9
+ module.exports.loadAccounts = loadAccounts
10
+ module.exports.loadConfig = loadConfig
11
+ module.exports.loadUsernames = loadUsernames
12
+
13
+ /**
14
+ * Returns an instance of AccountManager
15
+ *
16
+ * @param {Object} config
17
+ * @param {Object} [options]
18
+ * @returns {AccountManager}
19
+ */
20
+ function getAccountManager (config, options = {}) {
21
+ const ldp = options.ldp || new LDP(config)
22
+ const host = options.host || SolidHost.from({ port: config.port, serverUri: config.serverUri })
23
+ return AccountManager.from({
24
+ host,
25
+ store: ldp,
26
+ multiuser: config.multiuser
27
+ })
28
+ }
29
+
30
+ function loadConfig (program, options) {
31
+ let argv = {
32
+ ...options,
33
+ version: program.version()
34
+ }
35
+ const configFile = argv.configFile || './config.json'
36
+
37
+ try {
38
+ const file = fs.readFileSync(configFile)
39
+
40
+ // Use flags with priority over config file
41
+ const config = JSON.parse(file)
42
+ argv = { ...config, ...argv }
43
+ } catch (err) {
44
+ // If config file was specified, but it doesn't exist, stop with error message
45
+ if (typeof argv.configFile !== 'undefined') {
46
+ if (!fs.existsSync(configFile)) {
47
+ console.log(red(bold('ERR')), 'Config file ' + configFile + ' doesn\'t exist.')
48
+ process.exit(1)
49
+ }
50
+ }
51
+
52
+ // If the file exists, but parsing failed, stop with error message
53
+ if (fs.existsSync(configFile)) {
54
+ console.log(red(bold('ERR')), 'config file ' + configFile + ' couldn\'t be parsed: ' + err)
55
+ process.exit(1)
56
+ }
57
+
58
+ // Legacy behavior - if config file does not exist, start with default
59
+ // values, but an info message to create a config file.
60
+ console.log(cyan(bold('TIP')), 'create a config.json: `$ solid init`')
61
+ }
62
+
63
+ return argv
64
+ }
65
+
66
+ /**
67
+ *
68
+ * @param root
69
+ * @param [serverUri] If not set, hostname must be set
70
+ * @param [hostname] If not set, serverUri must be set
71
+ * @returns {*}
72
+ */
73
+ function loadAccounts ({ root, serverUri, hostname }) {
74
+ const files = fs.readdirSync(root)
75
+ hostname = hostname || new URL(serverUri).hostname
76
+ const isUserDirectory = new RegExp(`.${hostname}$`)
77
+ return files
78
+ .filter(file => isUserDirectory.test(file))
79
+ }
80
+
81
+ function loadUsernames ({ root, serverUri }) {
82
+ const hostname = new URL(serverUri).hostname
83
+ return loadAccounts({ root, hostname })
84
+ .map(userDirectory => userDirectory.substr(0, userDirectory.length - hostname.length - 1))
85
+ }
package/bin/lib/cli.js ADDED
@@ -0,0 +1,39 @@
1
+ const program = require('commander')
2
+ const loadInit = require('./init')
3
+ const loadStart = require('./start')
4
+ const loadInvalidUsernames = require('./invalidUsernames')
5
+ const loadMigrateLegacyResources = require('./migrateLegacyResources')
6
+ const loadUpdateIndex = require('./updateIndex')
7
+ const { spawnSync } = require('child_process')
8
+ const path = require('path')
9
+
10
+ module.exports = function startCli (server) {
11
+ program.version(getVersion())
12
+
13
+ loadInit(program)
14
+ loadStart(program, server)
15
+ loadInvalidUsernames(program)
16
+ loadMigrateLegacyResources(program)
17
+ loadUpdateIndex(program)
18
+
19
+ program.parse(process.argv)
20
+ if (program.args.length === 0) program.help()
21
+ }
22
+
23
+ function getVersion () {
24
+ try {
25
+ // Obtain version from git
26
+ const options = { cwd: __dirname, encoding: 'utf8' }
27
+ const { stdout } = spawnSync('git', ['describe', '--tags'], options)
28
+ const { stdout: gitStatusStdout } = spawnSync('git', ['status'], options)
29
+ const version = stdout.trim()
30
+ if (version === '' || gitStatusStdout.match('Not currently on any branch')) {
31
+ throw new Error('No git version here')
32
+ }
33
+ return version
34
+ } catch (e) {
35
+ // Obtain version from package.json
36
+ const { version } = require(path.join(__dirname, '../../package.json'))
37
+ return version
38
+ }
39
+ }
@@ -0,0 +1,94 @@
1
+ const inquirer = require('inquirer')
2
+ const fs = require('fs')
3
+ const options = require('./options')
4
+ const camelize = require('camelize')
5
+
6
+ let questions = options
7
+ .map((option) => {
8
+ if (!option.type) {
9
+ if (option.flag) {
10
+ option.type = 'confirm'
11
+ } else {
12
+ option.type = 'input'
13
+ }
14
+ }
15
+
16
+ option.message = option.question || option.help
17
+ return option
18
+ })
19
+
20
+ module.exports = function (program) {
21
+ program
22
+ .command('init')
23
+ .option('--advanced', 'Ask for all the settings')
24
+ .description('create solid server configurations')
25
+ .action((opts) => {
26
+ // Filter out advanced commands
27
+ if (!opts.advanced) {
28
+ questions = questions.filter((option) => option.prompt)
29
+ }
30
+
31
+ // Prompt to the user
32
+ inquirer.prompt(questions)
33
+ .then((answers) => {
34
+ manipulateEmailSection(answers)
35
+ manipulateServerSection(answers)
36
+ cleanupAnswers(answers)
37
+
38
+ // write config file
39
+ const config = JSON.stringify(camelize(answers), null, ' ')
40
+ const configPath = process.cwd() + '/config.json'
41
+
42
+ fs.writeFile(configPath, config, (err) => {
43
+ if (err) {
44
+ return console.log('failed to write config.json')
45
+ }
46
+ console.log('config created on', configPath)
47
+ })
48
+ })
49
+ .catch((err) => {
50
+ console.log('Error:', err)
51
+ })
52
+ })
53
+ }
54
+
55
+ function cleanupAnswers (answers) {
56
+ // clean answers
57
+ Object.keys(answers).forEach((answer) => {
58
+ if (answer.startsWith('use')) {
59
+ delete answers[answer]
60
+ }
61
+ })
62
+ }
63
+
64
+ function manipulateEmailSection (answers) {
65
+ // setting email
66
+ if (answers.useEmail) {
67
+ answers.email = {
68
+ host: answers['email-host'],
69
+ port: answers['email-port'],
70
+ secure: true,
71
+ auth: {
72
+ user: answers['email-auth-user'],
73
+ pass: answers['email-auth-pass']
74
+ }
75
+ }
76
+ delete answers['email-host']
77
+ delete answers['email-port']
78
+ delete answers['email-auth-user']
79
+ delete answers['email-auth-pass']
80
+ }
81
+ }
82
+
83
+ function manipulateServerSection (answers) {
84
+ answers.server = {
85
+ name: answers['server-info-name'],
86
+ description: answers['server-info-description'],
87
+ logo: answers['server-info-logo']
88
+ }
89
+ Object.keys(answers).forEach((answer) => {
90
+ if (answer.startsWith('server-info-')) {
91
+ delete answers[answer]
92
+ }
93
+ })
94
+ }