@rocket.chat/houston 0.27.0-next.3 → 2.1.9
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/LICENSE +1 -1
- package/README.md +109 -15
- package/bin/houston +62 -0
- package/data/docs/ARCHITECTURE.md +387 -0
- package/data/docs/automation.md +107 -0
- package/data/docs/e2ee.md +76 -0
- package/data/docs/eks.md +258 -0
- package/data/docs/gui.md +282 -0
- package/data/docs/guide.md +642 -0
- package/data/docs/kubernetes.md +138 -0
- package/data/docs/loadtest.md +264 -0
- package/data/docs/troubleshooting.md +203 -0
- package/data/docs/upgrading.md +84 -0
- package/data/docs/voice.md +253 -0
- package/data/iam/engineer-policy.json +11 -0
- package/data/iam/engineer-rbac.yaml +42 -0
- package/data/iam/operator-policy.json +211 -0
- package/data/loadtest/badbot.js +22 -0
- package/data/loadtest/common.js +170 -0
- package/data/loadtest/custom.js +20 -0
- package/data/loadtest/journey.js +58 -0
- package/data/loadtest/login.js +18 -0
- package/data/loadtest/messages.js +13 -0
- package/data/loadtest/mixed.js +57 -0
- package/data/loadtest/read.js +12 -0
- package/data/loadtest/webhook.js +20 -0
- package/data/monitoring/houston-logs.json +98 -0
- package/data/monitoring/k6-loadtest.json +610 -0
- package/data/monitoring/mongodb-exporter.json +3007 -0
- package/data/monitoring/node-exporter-full.json +16114 -0
- package/data/monitoring/rocketchat-metrics.json +6471 -0
- package/data/presets/airgapped.yaml +16 -0
- package/data/presets/default.yaml +9 -0
- package/data/seed/avatar-0.png +0 -0
- package/data/seed/avatar-1.png +0 -0
- package/data/seed/avatar-2.png +0 -0
- package/data/seed/avatar-3.png +0 -0
- package/data/seed/avatar-4.png +0 -0
- package/data/seed/avatar-5.png +0 -0
- package/data/seed/avatar-6.png +0 -0
- package/data/seed/avatar-7.png +0 -0
- package/data/seed/seed-metrics.csv +3 -0
- package/data/seed/seed-preview.png +0 -0
- package/data/seed/seed-report.pdf +32 -0
- package/data/seed/seed-runbook.txt +3 -0
- package/data/skill/SKILL.md +399 -0
- package/data/versions.yaml +55 -0
- package/data/voice/freeswitch/drachtio.xml +52 -0
- package/data/voice/freeswitch/public.xml +87 -0
- package/data/webui/app.css +2003 -0
- package/data/webui/index.html +678 -0
- package/data/webui/js/api.js +561 -0
- package/data/webui/js/boot.js +44 -0
- package/data/webui/js/clusters-tail.js +1377 -0
- package/data/webui/js/clusters.js +896 -0
- package/data/webui/js/create.js +276 -0
- package/data/webui/js/detail.js +507 -0
- package/data/webui/js/jobs.js +636 -0
- package/data/webui/js/logs.js +634 -0
- package/data/webui/js/main.js +14 -0
- package/data/webui/js/options.js +408 -0
- package/data/webui/js/people.js +438 -0
- package/data/webui/js/perf.js +303 -0
- package/data/webui/js/render.js +438 -0
- package/data/webui/js/shared.js +3 -0
- package/data/webui/js/state.js +583 -0
- package/data/webui/js/theme.js +123 -0
- package/data/webui/js/util.js +584 -0
- package/dist/cli/app.js +593 -0
- package/dist/cli/capabilities.js +76 -0
- package/dist/cli/cell-widths.js +495 -0
- package/dist/cli/entry.js +10 -0
- package/dist/cli/error-panel.js +492 -0
- package/dist/cli/handlers/actor.js +84 -0
- package/dist/cli/handlers/https.js +614 -0
- package/dist/cli/handlers/prompt.js +299 -0
- package/dist/cli/handlers/users.js +226 -0
- package/dist/cli/handlers.js +3694 -0
- package/dist/cli/help.js +183 -0
- package/dist/cli/index.js +15 -0
- package/dist/cli/perf.js +814 -0
- package/dist/cli/render.js +254 -0
- package/dist/cli/serve.js +858 -0
- package/dist/cli/spec-data.js +2599 -0
- package/dist/cli/spec-types.js +8 -0
- package/dist/cli/usage-error.js +520 -0
- package/dist/cli/wire.js +70 -0
- package/dist/core/audit.js +346 -0
- package/dist/core/backup-compat.js +85 -0
- package/dist/core/backup.js +1639 -0
- package/dist/core/cluster.js +1398 -0
- package/dist/core/configimport.js +345 -0
- package/dist/core/data.js +267 -0
- package/dist/core/database-of.js +82 -0
- package/dist/core/diagnose.js +159 -0
- package/dist/core/doctor.js +1518 -0
- package/dist/core/edge/acme.js +338 -0
- package/dist/core/edge/engine.js +500 -0
- package/dist/core/edge/networks.js +174 -0
- package/dist/core/edge/paths.js +107 -0
- package/dist/core/edge/routes.js +251 -0
- package/dist/core/edge/routeyml.js +195 -0
- package/dist/core/edge/runtime.js +493 -0
- package/dist/core/edge/spec.js +305 -0
- package/dist/core/edge/types.js +202 -0
- package/dist/core/eks-docs.js +135 -0
- package/dist/core/eks.js +2240 -0
- package/dist/core/envvars.js +562 -0
- package/dist/core/eventlog.js +541 -0
- package/dist/core/firstrun.js +153 -0
- package/dist/core/journal.js +694 -0
- package/dist/core/kube/ask.js +231 -0
- package/dist/core/kube/capabilities.js +269 -0
- package/dist/core/kube/certmanager.js +452 -0
- package/dist/core/kube/chart.js +413 -0
- package/dist/core/kube/cluster.js +196 -0
- package/dist/core/kube/context.js +545 -0
- package/dist/core/kube/endpoints.js +448 -0
- package/dist/core/kube/exec.js +195 -0
- package/dist/core/kube/forward.js +732 -0
- package/dist/core/kube/grafana-ingress.js +110 -0
- package/dist/core/kube/ingress.js +218 -0
- package/dist/core/kube/manifests.js +361 -0
- package/dist/core/kube/monitoring.js +768 -0
- package/dist/core/kube/names.js +237 -0
- package/dist/core/kube/namespace.js +678 -0
- package/dist/core/kube/operator.js +941 -0
- package/dist/core/kube/probe.js +202 -0
- package/dist/core/kube/reachability.js +163 -0
- package/dist/core/kube/release.js +439 -0
- package/dist/core/kube/replicaset.js +180 -0
- package/dist/core/kube/scale.js +398 -0
- package/dist/core/kube/status.js +633 -0
- package/dist/core/kube/tools.js +238 -0
- package/dist/core/kube/transfer.js +173 -0
- package/dist/core/kube/workspace.js +423 -0
- package/dist/core/lifecycle/admin.js +64 -0
- package/dist/core/lifecycle/create-docker.js +1549 -0
- package/dist/core/lifecycle/create-k8s.js +960 -0
- package/dist/core/lifecycle/destroy.js +339 -0
- package/dist/core/lifecycle/inspect.js +636 -0
- package/dist/core/lifecycle/naming.js +298 -0
- package/dist/core/lifecycle/notes.js +862 -0
- package/dist/core/lifecycle/ownership.js +313 -0
- package/dist/core/lifecycle/payload.js +401 -0
- package/dist/core/lifecycle/ports.js +388 -0
- package/dist/core/lifecycle/preconditions.js +367 -0
- package/dist/core/lifecycle/pruning.js +551 -0
- package/dist/core/lifecycle/ready.js +818 -0
- package/dist/core/lifecycle/request.js +510 -0
- package/dist/core/lifecycle/seeding.js +281 -0
- package/dist/core/lifecycle/sizing.js +392 -0
- package/dist/core/lifecycle/state.js +286 -0
- package/dist/core/lifecycle/tlsplan.js +704 -0
- package/dist/core/lifecycle/types.js +232 -0
- package/dist/core/loadtest.js +1051 -0
- package/dist/core/migrate.js +612 -0
- package/dist/core/monitor.js +494 -0
- package/dist/core/postready.js +976 -0
- package/dist/core/promote.js +804 -0
- package/dist/core/rcapi.js +1336 -0
- package/dist/core/recovery.js +75 -0
- package/dist/core/runner/engine.js +394 -0
- package/dist/core/runner/host.js +298 -0
- package/dist/core/runner/locks.js +129 -0
- package/dist/core/runner/paths.js +173 -0
- package/dist/core/runner/ports.js +172 -0
- package/dist/core/runner/queries.js +612 -0
- package/dist/core/runner/record.js +563 -0
- package/dist/core/scaleseed.js +271 -0
- package/dist/core/seed-db.js +208 -0
- package/dist/core/sessions.js +472 -0
- package/dist/core/skill.js +326 -0
- package/dist/core/sso-identities.js +172 -0
- package/dist/core/sso.js +703 -0
- package/dist/core/tls-local.js +311 -0
- package/dist/core/tls.js +878 -0
- package/dist/core/topology.js +482 -0
- package/dist/core/upgrade.js +877 -0
- package/dist/core/users.js +739 -0
- package/dist/lib/audit.js +100 -0
- package/dist/lib/close-matches.js +238 -0
- package/dist/lib/compose.js +672 -0
- package/dist/lib/config.js +1398 -0
- package/dist/lib/context.js +18 -0
- package/dist/lib/errors.js +305 -0
- package/dist/lib/events.js +208 -0
- package/dist/lib/float-text.js +126 -0
- package/dist/lib/format.js +1320 -0
- package/dist/lib/home.js +325 -0
- package/dist/lib/journal.js +122 -0
- package/dist/lib/json-text.js +733 -0
- package/dist/lib/jsonout.js +382 -0
- package/dist/lib/lock.js +516 -0
- package/dist/lib/login-name.js +202 -0
- package/dist/lib/map-limit.js +29 -0
- package/dist/lib/mkdir-parents.js +90 -0
- package/dist/lib/mongo-kernel.js +67 -0
- package/dist/lib/monitoring.js +492 -0
- package/dist/lib/platform-name.js +59 -0
- package/dist/lib/presets/common.js +390 -0
- package/dist/lib/presets/composite.js +326 -0
- package/dist/lib/presets/e2ee.js +143 -0
- package/dist/lib/presets/email.js +172 -0
- package/dist/lib/presets/guides.js +27 -0
- package/dist/lib/presets/index.js +490 -0
- package/dist/lib/presets/keycloak.js +371 -0
- package/dist/lib/presets/ldap.js +1285 -0
- package/dist/lib/presets/livechat.js +220 -0
- package/dist/lib/presets/multi-instance.js +124 -0
- package/dist/lib/presets/oidc.js +161 -0
- package/dist/lib/presets/public.js +496 -0
- package/dist/lib/presets/registry.js +64 -0
- package/dist/lib/presets/s3-minio.js +300 -0
- package/dist/lib/presets/saml.js +149 -0
- package/dist/lib/presets/scenario.js +51 -0
- package/dist/lib/presets/types.js +86 -0
- package/dist/lib/presets/voice-pbx.js +320 -0
- package/dist/lib/presets/voice.js +345 -0
- package/dist/lib/presets/webhooks.js +182 -0
- package/dist/lib/redact.js +106 -0
- package/dist/lib/seed-options.js +68 -0
- package/dist/lib/seed-profiles.js +59 -0
- package/dist/lib/targz.js +1383 -0
- package/dist/lib/teammode.js +25 -0
- package/dist/lib/tempdir.js +162 -0
- package/dist/lib/unicode-tables.js +2335 -0
- package/dist/lib/version-spec.js +357 -0
- package/dist/lib/versions.js +463 -0
- package/dist/lib/yaml-dump.js +1361 -0
- package/dist/perf/baseline.js +168 -0
- package/dist/perf/constrain.js +299 -0
- package/dist/perf/k6.js +235 -0
- package/dist/perf/mongoprof.js +171 -0
- package/dist/perf/rcmetrics.js +191 -0
- package/dist/perf/report.js +386 -0
- package/dist/perf/resources.js +236 -0
- package/dist/perf/slo.js +111 -0
- package/dist/perf/timeline.js +187 -0
- package/dist/perf/timings.js +85 -0
- package/dist/perf/verdict.js +201 -0
- package/dist/seams/aws-cli.js +126 -0
- package/dist/seams/docker-cli.js +280 -0
- package/dist/seams/exec.js +861 -0
- package/dist/seams/fs/lock.js +528 -0
- package/dist/seams/kubectl.js +83 -0
- package/dist/seams/rc-http.js +921 -0
- package/dist/seed/apply.js +190 -0
- package/dist/seed/assets.js +76 -0
- package/dist/seed/check.js +391 -0
- package/dist/seed/client.js +172 -0
- package/dist/seed/executor.js +726 -0
- package/dist/seed/history.js +281 -0
- package/dist/seed/kinds.js +91 -0
- package/dist/seed/plan.js +432 -0
- package/dist/seed/receipt.js +339 -0
- package/dist/seed/repairs.js +75 -0
- package/dist/seed/verification.js +363 -0
- package/dist/seed/wording.js +248 -0
- package/dist/web/app.js +326 -0
- package/dist/web/jobs.js +510 -0
- package/dist/web/route-deps.js +211 -0
- package/dist/web/route-table.js +213 -0
- package/dist/web/routes/backup.js +244 -0
- package/dist/web/routes/clusters.js +303 -0
- package/dist/web/routes/data.js +187 -0
- package/dist/web/routes/edge.js +82 -0
- package/dist/web/routes/index.js +63 -0
- package/dist/web/routes/jobs.js +95 -0
- package/dist/web/routes/logs.js +297 -0
- package/dist/web/routes/meta.js +191 -0
- package/dist/web/routes/people.js +151 -0
- package/dist/web/routes/perf.js +95 -0
- package/dist/web/routes/repros.js +550 -0
- package/dist/web/routes/session.js +361 -0
- package/dist/web/routes/spa.js +198 -0
- package/dist/web/security.js +475 -0
- package/dist/web/signin.js +246 -0
- package/package.json +70 -32
- package/.eslintrc +0 -94
- package/.swcrc +0 -18
- package/dist/bin.js +0 -3
- package/dist/cli.js +0 -184
- package/dist/commands/createBranch.js +0 -194
- package/dist/outputCI.js +0 -59
- package/src/bin.js +0 -4
- package/src/cli.ts +0 -25
- package/src/commands/createBranch.ts +0 -28
- package/src/outputCI.ts +0 -12
- package/src-old/logs.js +0 -323
- package/src-old/md.js +0 -191
- package/src-old/release-table.js +0 -60
- package/src-old/set-version.js +0 -614
- package/src-old/utils.js +0 -15
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** Sign in, sign out, first run, and the caller's own sessions. */
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
exports.register = register;
|
|
38
|
+
const audit = __importStar(require("../../core/audit"));
|
|
39
|
+
const sessions = __importStar(require("../../core/sessions"));
|
|
40
|
+
const sso_identities_1 = require("../../core/sso-identities");
|
|
41
|
+
const context_1 = require("../../lib/context");
|
|
42
|
+
const route_deps_1 = require("../route-deps");
|
|
43
|
+
const security_1 = require("../security");
|
|
44
|
+
const signin_1 = require("../signin");
|
|
45
|
+
const THEME_COOKIE = 'houston_theme';
|
|
46
|
+
function firstrunModule() {
|
|
47
|
+
return require('../../core/firstrun');
|
|
48
|
+
}
|
|
49
|
+
function usersModule() {
|
|
50
|
+
return require('../../core/users');
|
|
51
|
+
}
|
|
52
|
+
function ssoModule() {
|
|
53
|
+
return require('../../core/sso');
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The cookie that ties an Okta callback to the browser that started it, so a callback URL
|
|
57
|
+
* somebody else started cannot sign this browser in as them. `__Host-` on HTTPS, like the
|
|
58
|
+
* session's, so a sibling host cannot plant one.
|
|
59
|
+
*/
|
|
60
|
+
function ssoCookieName(https) {
|
|
61
|
+
return https ? '__Host-houston_sso' : 'houston_sso';
|
|
62
|
+
}
|
|
63
|
+
/** Never cached, and never in a Referer: these answers carry the provider's codes. */
|
|
64
|
+
function privately(reply) {
|
|
65
|
+
return reply.header('Cache-Control', 'no-store').header('Referrer-Policy', 'no-referrer');
|
|
66
|
+
}
|
|
67
|
+
function cookie(header, name) {
|
|
68
|
+
for (const raw of (header ?? '').split(';')) {
|
|
69
|
+
const part = raw.trim();
|
|
70
|
+
const at = part.indexOf('=');
|
|
71
|
+
if (at !== -1 && part.slice(0, at) === name)
|
|
72
|
+
return part.slice(at + 1);
|
|
73
|
+
}
|
|
74
|
+
return '';
|
|
75
|
+
}
|
|
76
|
+
function firstRunOpen(app) {
|
|
77
|
+
return app.houstonFirstRun && !usersModule().anyUsers();
|
|
78
|
+
}
|
|
79
|
+
function quotedNext(value) {
|
|
80
|
+
return encodeURIComponent(value)
|
|
81
|
+
.replaceAll('%2F', '/')
|
|
82
|
+
.replaceAll('%3F', '?')
|
|
83
|
+
.replaceAll('%3D', '=')
|
|
84
|
+
.replaceAll('%26', '&');
|
|
85
|
+
}
|
|
86
|
+
async function currentSession(request) {
|
|
87
|
+
return await sessions.verify((0, security_1.sessionToken)(request.server.houstonSecurity, request));
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* `/signin?sso=1`, or the Okta tile's `/signin?iss=<issuer>`: send the browser to Okta.
|
|
91
|
+
*
|
|
92
|
+
* On the configured public origin, because that is where Okta sends it back, and the browser
|
|
93
|
+
* cookie must be on it; anywhere else is redirected there first. ONCE (`canon=1`): behind a
|
|
94
|
+
* proxy that hides the https or rewrites Host, this server never sees the public origin even
|
|
95
|
+
* when the browser is on it, and redirecting again would loop.
|
|
96
|
+
*/
|
|
97
|
+
async function ssoStart(request, reply, settings, next, redirected) {
|
|
98
|
+
privately(reply);
|
|
99
|
+
const security = request.server.houstonSecurity;
|
|
100
|
+
const peer = (0, security_1.resolvePeer)(security, request);
|
|
101
|
+
const here = `${peer.https ? 'https' : 'http'}://${(0, route_deps_1.text)(request.headers.host)}`.toLowerCase();
|
|
102
|
+
if (here !== settings.publicUrl.toLowerCase() && !redirected) {
|
|
103
|
+
return reply.redirect(`${settings.publicUrl}/signin?sso=1&canon=1&next=${quotedNext(next)}`, 303);
|
|
104
|
+
}
|
|
105
|
+
if (!(0, security_1.ssoStartAllowed)(peer.address))
|
|
106
|
+
return reply.redirect('/signin?e=rate', 303);
|
|
107
|
+
const sso = ssoModule();
|
|
108
|
+
const held = cookie(request.headers.cookie, ssoCookieName(peer.https));
|
|
109
|
+
const browser = sso.isBrowserId(held) ? held : sso.newBrowserId();
|
|
110
|
+
let target;
|
|
111
|
+
try {
|
|
112
|
+
target = await sso.start(settings, browser, next);
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
return reply.redirect(`/signin?e=sso-${refusalCode(error)}`, 303);
|
|
116
|
+
}
|
|
117
|
+
reply.header('Set-Cookie', `${ssoCookieName(peer.https)}=${browser}; HttpOnly; Max-Age=${String(sso.PENDING_MS / 1000)}` +
|
|
118
|
+
`; Path=/; SameSite=lax${peer.https ? '; Secure' : ''}`);
|
|
119
|
+
return reply.redirect(target, 303);
|
|
120
|
+
}
|
|
121
|
+
function refusalCode(error) {
|
|
122
|
+
return error instanceof ssoModule().Refusal ? error.code : 'provider';
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Okta's redirect back: a session for the account the person resolves to, or one redirect
|
|
126
|
+
* to a fixed refusal. Never HTML here, so the code in this URL never reaches a page.
|
|
127
|
+
*/
|
|
128
|
+
async function ssoCallback(request, reply, callback) {
|
|
129
|
+
privately(reply);
|
|
130
|
+
const security = request.server.houstonSecurity;
|
|
131
|
+
const peer = (0, security_1.resolvePeer)(security, request);
|
|
132
|
+
const sso = ssoModule();
|
|
133
|
+
const ready = sso.readiness();
|
|
134
|
+
if (ready.state !== 'ready')
|
|
135
|
+
return reply.redirect('/signin?e=sso-off', 303);
|
|
136
|
+
let signedIn;
|
|
137
|
+
try {
|
|
138
|
+
signedIn = await sso.finish(ready.settings, callback, cookie(request.headers.cookie, ssoCookieName(peer.https)));
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
const code = refusalCode(error);
|
|
142
|
+
// Not `expired`: anyone can ask for that with a made-up state, unthrottled, and a line per
|
|
143
|
+
// request would rotate the real trail away. Every other refusal needed a started sign-in,
|
|
144
|
+
// which the start limit bounds.
|
|
145
|
+
if (code !== 'expired') {
|
|
146
|
+
audit.audit('-', 'signin', `okta ${code}`, { origin: 'attempt', outcome: 'denied' });
|
|
147
|
+
}
|
|
148
|
+
return reply.redirect(`/signin?e=sso-${code}`, 303);
|
|
149
|
+
}
|
|
150
|
+
const current = await currentSession(request);
|
|
151
|
+
if (current !== null && current.user !== signedIn.name) {
|
|
152
|
+
return reply.redirect('/signin?e=sso-other', 303);
|
|
153
|
+
}
|
|
154
|
+
if (current !== null)
|
|
155
|
+
await sessions.revokeSid(current.sid);
|
|
156
|
+
const token = await sessions.create(signedIn.name, {
|
|
157
|
+
origin: 'sso',
|
|
158
|
+
label: sessions.describeAgent((0, route_deps_1.text)(request.headers['user-agent'])),
|
|
159
|
+
});
|
|
160
|
+
(0, security_1.setSessionCookie)(security, reply, token, peer.https);
|
|
161
|
+
return reply.redirect((0, signin_1.safeNext)(signedIn.next), 303);
|
|
162
|
+
}
|
|
163
|
+
/** Sign-out drops the Okta sign-ins this browser started and has not finished. */
|
|
164
|
+
function forgetSsoBrowser(request) {
|
|
165
|
+
const https = (0, security_1.resolvePeer)(request.server.houstonSecurity, request).https;
|
|
166
|
+
ssoModule().forgetBrowser(cookie(request.headers.cookie, ssoCookieName(https)));
|
|
167
|
+
}
|
|
168
|
+
function register(app) {
|
|
169
|
+
app.get('/setup', async (request, reply) => {
|
|
170
|
+
if (!firstRunOpen(app)) {
|
|
171
|
+
return reply.code(404).send({ error: 'not found', kind: 'NotFoundError' });
|
|
172
|
+
}
|
|
173
|
+
return reply
|
|
174
|
+
.type('text/html; charset=utf-8')
|
|
175
|
+
.send((0, signin_1.setupPage)(cookie(request.headers.cookie, THEME_COOKIE)));
|
|
176
|
+
});
|
|
177
|
+
app.get('/setup.js', async (_request, reply) => {
|
|
178
|
+
if (!firstRunOpen(app)) {
|
|
179
|
+
return reply.code(404).send({ error: 'not found', kind: 'NotFoundError' });
|
|
180
|
+
}
|
|
181
|
+
return reply.type('application/javascript').send(signin_1.SETUP_JS);
|
|
182
|
+
});
|
|
183
|
+
app.post('/api/session/first-run', async (request, reply) => {
|
|
184
|
+
const body = (0, route_deps_1.requestBody)(request.body, true);
|
|
185
|
+
if (!firstRunOpen(app)) {
|
|
186
|
+
return reply
|
|
187
|
+
.code(409)
|
|
188
|
+
.send({ error: 'this server already has accounts', kind: 'ConflictError' });
|
|
189
|
+
}
|
|
190
|
+
const firstrun = firstrunModule();
|
|
191
|
+
const users = usersModule();
|
|
192
|
+
const peer = (0, security_1.resolvePeer)(app.houstonSecurity, request);
|
|
193
|
+
if ((0, security_1.signinRetryAfter)(peer.address)) {
|
|
194
|
+
return reply
|
|
195
|
+
.code(429)
|
|
196
|
+
.send({ error: 'too many attempts from this address', kind: 'Unauthorized' });
|
|
197
|
+
}
|
|
198
|
+
if (!firstrun.valid((0, route_deps_1.orText)(body.key))) {
|
|
199
|
+
(0, security_1.signinFailed)(peer.address);
|
|
200
|
+
return reply.code(401).send({
|
|
201
|
+
error: 'that setup link is wrong or has expired. Restart `houston serve` for a fresh one.',
|
|
202
|
+
kind: 'Unauthorized',
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
const name = users.normalizeName((0, route_deps_1.orText)(body.user));
|
|
206
|
+
const password = (0, route_deps_1.orText)(body.password);
|
|
207
|
+
users.requireValidName(name);
|
|
208
|
+
users.requireValidPassword(password);
|
|
209
|
+
const token = await (0, context_1.runWithContext)({ actor: name, origin: 'setup' }, async () => {
|
|
210
|
+
await users.add(name, password, 'admin');
|
|
211
|
+
firstrun.consume();
|
|
212
|
+
(0, security_1.signinOk)(peer.address);
|
|
213
|
+
const created = await sessions.create(name, {
|
|
214
|
+
origin: 'setup',
|
|
215
|
+
label: sessions.describeAgent((0, route_deps_1.text)(request.headers['user-agent'])),
|
|
216
|
+
});
|
|
217
|
+
audit.audit(name, 'first-run', 'first account created', {
|
|
218
|
+
origin: 'setup',
|
|
219
|
+
outcome: 'ok',
|
|
220
|
+
});
|
|
221
|
+
return created;
|
|
222
|
+
});
|
|
223
|
+
(0, security_1.setSessionCookie)(app.houstonSecurity, reply, token, peer.https);
|
|
224
|
+
return { user: name, role: 'admin' };
|
|
225
|
+
});
|
|
226
|
+
app.get('/signin', async (request, reply) => {
|
|
227
|
+
const query = (0, route_deps_1.bag)(request.query);
|
|
228
|
+
const next = (0, route_deps_1.queryText)(query.next, '/', 'next');
|
|
229
|
+
const state = (0, route_deps_1.queryText)(query.state, '', 'state');
|
|
230
|
+
const sso = ssoModule().readiness();
|
|
231
|
+
// With Okta off, a callback-shaped URL is just the page, as it always was.
|
|
232
|
+
if (sso.state !== 'off' &&
|
|
233
|
+
state !== '' &&
|
|
234
|
+
(query.code !== undefined || query.error !== undefined)) {
|
|
235
|
+
return await ssoCallback(request, reply, {
|
|
236
|
+
state,
|
|
237
|
+
code: (0, route_deps_1.queryText)(query.code, '', 'code'),
|
|
238
|
+
error: (0, route_deps_1.queryText)(query.error, '', 'error'),
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
// Signed in already goes where it was going -- except to say it is somebody else.
|
|
242
|
+
if ((0, route_deps_1.queryText)(query.e, '', 'e') !== 'sso-other' && (await currentSession(request)) !== null) {
|
|
243
|
+
return reply.redirect((0, signin_1.safeNext)(next), 303);
|
|
244
|
+
}
|
|
245
|
+
if (sso.state === 'ready' &&
|
|
246
|
+
((0, route_deps_1.queryText)(query.sso, '', 'sso') === '1' ||
|
|
247
|
+
(query.iss !== undefined && (0, route_deps_1.queryText)(query.iss, '', 'iss') === sso.settings.issuer))) {
|
|
248
|
+
return await ssoStart(request, reply, sso.settings, (0, signin_1.safeNext)(next), (0, route_deps_1.queryText)(query.canon, '', 'canon') === '1');
|
|
249
|
+
}
|
|
250
|
+
const peer = (0, security_1.resolvePeer)(app.houstonSecurity, request);
|
|
251
|
+
const local = ['127.0.0.1', '::1', 'localhost'].includes(peer.address);
|
|
252
|
+
const host = (0, route_deps_1.text)(request.headers.host).split(':', 1)[0] ?? '';
|
|
253
|
+
const document = (0, signin_1.page)({
|
|
254
|
+
error: (0, route_deps_1.queryText)(query.e, '', 'e'),
|
|
255
|
+
nextUrl: next,
|
|
256
|
+
server: host,
|
|
257
|
+
secure: peer.https || local,
|
|
258
|
+
retryAfter: (0, security_1.signinRetryAfter)(peer.address),
|
|
259
|
+
theme: cookie(request.headers.cookie, THEME_COOKIE),
|
|
260
|
+
okta: sso.state === 'ready',
|
|
261
|
+
});
|
|
262
|
+
return reply
|
|
263
|
+
.code((0, route_deps_1.queryText)(query.e, '', 'e') === 'bad' || (0, route_deps_1.queryText)(query.e, '', 'e') === 'rate' ? 401 : 200)
|
|
264
|
+
.type('text/html; charset=utf-8')
|
|
265
|
+
.send(document);
|
|
266
|
+
});
|
|
267
|
+
app.post('/signin', async (request, reply) => {
|
|
268
|
+
const body = (0, route_deps_1.bag)(request.body);
|
|
269
|
+
const peer = (0, security_1.resolvePeer)(app.houstonSecurity, request);
|
|
270
|
+
const [token, error] = await (0, security_1.doSignin)((0, route_deps_1.queryText)(body.user, '', 'user'), (0, route_deps_1.queryText)(body.password, '', 'password'), peer.address, (0, route_deps_1.text)(request.headers['user-agent']));
|
|
271
|
+
const target = (0, signin_1.safeNext)((0, route_deps_1.queryText)(body.next, '/', 'next'));
|
|
272
|
+
if (error)
|
|
273
|
+
return reply.redirect(`/signin?e=${error}&next=${quotedNext(target)}`, 303);
|
|
274
|
+
(0, security_1.setSessionCookie)(app.houstonSecurity, reply, token, peer.https);
|
|
275
|
+
return reply.redirect(target, 303);
|
|
276
|
+
});
|
|
277
|
+
app.post('/api/session', async (request, reply) => {
|
|
278
|
+
const body = (0, route_deps_1.requestBody)(request.body, false);
|
|
279
|
+
const peer = (0, security_1.resolvePeer)(app.houstonSecurity, request);
|
|
280
|
+
const [token, error] = await (0, security_1.doSignin)((0, route_deps_1.orText)(body.user), (0, route_deps_1.orText)(body.password), peer.address, (0, route_deps_1.text)(request.headers['user-agent']));
|
|
281
|
+
if (error) {
|
|
282
|
+
const detail = {
|
|
283
|
+
bad: 'that name or password is not right',
|
|
284
|
+
rate: 'too many attempts from this address',
|
|
285
|
+
nouser: 'there are no accounts on this server yet',
|
|
286
|
+
};
|
|
287
|
+
return reply
|
|
288
|
+
.code(error === 'rate' ? 429 : 401)
|
|
289
|
+
.send({ error: detail[error] ?? '', kind: 'Unauthorized' });
|
|
290
|
+
}
|
|
291
|
+
const found = await sessions.verify(token);
|
|
292
|
+
(0, security_1.setSessionCookie)(app.houstonSecurity, reply, token, peer.https);
|
|
293
|
+
return { user: found?.user ?? '', expires_at: found === null ? 0 : sessions.expiresAt(found) };
|
|
294
|
+
});
|
|
295
|
+
app.get('/api/session', async (request) => {
|
|
296
|
+
const users = usersModule();
|
|
297
|
+
const found = await currentSession(request);
|
|
298
|
+
if (found === null)
|
|
299
|
+
return { user: '', role: '', accounts: app.houstonSecurity.accounts };
|
|
300
|
+
const okta = (0, sso_identities_1.linked)().get(found.user);
|
|
301
|
+
return {
|
|
302
|
+
user: found.user,
|
|
303
|
+
role: users.roleOf(found.user),
|
|
304
|
+
accounts: true,
|
|
305
|
+
origin: found.origin,
|
|
306
|
+
expires_at: sessions.expiresAt(found),
|
|
307
|
+
label: found.label,
|
|
308
|
+
...(okta === undefined ? {} : { sso_user: okta.display || okta.email }),
|
|
309
|
+
};
|
|
310
|
+
});
|
|
311
|
+
app.delete('/api/session', async (request, reply) => {
|
|
312
|
+
forgetSsoBrowser(request);
|
|
313
|
+
const raw = (0, security_1.sessionToken)(app.houstonSecurity, request);
|
|
314
|
+
const ended = raw ? await sessions.revoke(raw) : false;
|
|
315
|
+
(0, security_1.clearSessionCookie)(app.houstonSecurity, reply);
|
|
316
|
+
return { ok: true, ended };
|
|
317
|
+
});
|
|
318
|
+
app.post('/signout', async (request, reply) => {
|
|
319
|
+
forgetSsoBrowser(request);
|
|
320
|
+
const raw = (0, security_1.sessionToken)(app.houstonSecurity, request);
|
|
321
|
+
if (raw)
|
|
322
|
+
await sessions.revoke(raw);
|
|
323
|
+
(0, security_1.clearSessionCookie)(app.houstonSecurity, reply);
|
|
324
|
+
return reply.redirect('/signin?e=signedout', 303);
|
|
325
|
+
});
|
|
326
|
+
app.get('/api/sessions', async (request) => {
|
|
327
|
+
const found = await currentSession(request);
|
|
328
|
+
if (found === null)
|
|
329
|
+
return { sessions: [] };
|
|
330
|
+
const here = found.sid.slice(0, 8);
|
|
331
|
+
return {
|
|
332
|
+
sessions: sessions.listFor(found.user).map((item) => ({
|
|
333
|
+
...sessions.publicView(item),
|
|
334
|
+
current: item.sid.slice(0, 8) === here,
|
|
335
|
+
})),
|
|
336
|
+
};
|
|
337
|
+
});
|
|
338
|
+
app.delete('/api/sessions', async (request, reply) => {
|
|
339
|
+
const found = await currentSession(request);
|
|
340
|
+
if (found === null) {
|
|
341
|
+
return reply.code(401).send({ error: 'not signed in', kind: 'Unauthorized' });
|
|
342
|
+
}
|
|
343
|
+
const query = (0, route_deps_1.bag)(request.query);
|
|
344
|
+
if ((0, route_deps_1.queryBool)(query.all, false, 'all')) {
|
|
345
|
+
const ended = await sessions.revokeUser(found.user);
|
|
346
|
+
(0, security_1.clearSessionCookie)(app.houstonSecurity, reply);
|
|
347
|
+
return { ok: true, ended };
|
|
348
|
+
}
|
|
349
|
+
const prefix = (0, route_deps_1.queryText)(query.sid, '', 'sid');
|
|
350
|
+
const target = sessions.listFor(found.user).find((item) => item.sid.slice(0, 8) === prefix);
|
|
351
|
+
if (target === undefined) {
|
|
352
|
+
return reply.code(404).send({ error: 'no such session', kind: 'NotFoundError' });
|
|
353
|
+
}
|
|
354
|
+
if (!(await sessions.revokeSid(target.sid))) {
|
|
355
|
+
return reply
|
|
356
|
+
.code(404)
|
|
357
|
+
.send({ error: 'that session had already ended', kind: 'NotFoundError' });
|
|
358
|
+
}
|
|
359
|
+
return { ok: true, ended: 1 };
|
|
360
|
+
});
|
|
361
|
+
}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** The frozen single-page application, registered last. */
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
exports.register = register;
|
|
38
|
+
const fs = __importStar(require("node:fs"));
|
|
39
|
+
const path = __importStar(require("node:path"));
|
|
40
|
+
const node_crypto_1 = require("node:crypto");
|
|
41
|
+
const WEBUI = path.resolve(__dirname, '../../../data/webui');
|
|
42
|
+
function contentType(filename) {
|
|
43
|
+
if (filename.endsWith('.html'))
|
|
44
|
+
return 'text/html; charset=utf-8';
|
|
45
|
+
if (filename.endsWith('.css'))
|
|
46
|
+
return 'text/css; charset=utf-8';
|
|
47
|
+
if (filename.endsWith('.js'))
|
|
48
|
+
return 'text/javascript; charset=utf-8';
|
|
49
|
+
return 'application/octet-stream';
|
|
50
|
+
}
|
|
51
|
+
function byteRanges(header, size) {
|
|
52
|
+
const separator = header.indexOf('=');
|
|
53
|
+
if (separator === -1)
|
|
54
|
+
return { status: 400, content: 'Malformed range header.' };
|
|
55
|
+
if (header.slice(0, separator).trim().toLowerCase() !== 'bytes') {
|
|
56
|
+
return { status: 400, content: 'Only support bytes range' };
|
|
57
|
+
}
|
|
58
|
+
const parts = header.slice(separator + 1).split(',');
|
|
59
|
+
if (parts.length > 100)
|
|
60
|
+
return { ranges: [] };
|
|
61
|
+
const found = [];
|
|
62
|
+
for (const raw of parts) {
|
|
63
|
+
const part = raw.trim();
|
|
64
|
+
if (part === '' || part === '-' || !part.includes('-'))
|
|
65
|
+
continue;
|
|
66
|
+
const dash = part.indexOf('-');
|
|
67
|
+
const rawStart = part.slice(0, dash).trim();
|
|
68
|
+
const rawEnd = part.slice(dash + 1).trim();
|
|
69
|
+
if (!/^(?:[+-]?\d+)?$/u.test(rawStart) || !/^(?:[+-]?\d+)?$/u.test(rawEnd))
|
|
70
|
+
continue;
|
|
71
|
+
const start = rawStart === '' ? Math.max(size - Number(rawEnd), 0) : Number(rawStart);
|
|
72
|
+
const end = rawStart !== '' && rawEnd !== '' && Number(rawEnd) < size ? Number(rawEnd) + 1 : size;
|
|
73
|
+
found.push({ start, end });
|
|
74
|
+
}
|
|
75
|
+
if (found.length === 0) {
|
|
76
|
+
return { status: 400, content: 'Range header: range must be requested' };
|
|
77
|
+
}
|
|
78
|
+
if (found.some(({ start }) => !(start >= 0 && start < size)))
|
|
79
|
+
return { status: 416 };
|
|
80
|
+
if (found.some(({ start, end }) => start >= end)) {
|
|
81
|
+
return { status: 400, content: 'Range header: start must be less than end' };
|
|
82
|
+
}
|
|
83
|
+
found.sort((left, right) => left.start - right.start);
|
|
84
|
+
const merged = [];
|
|
85
|
+
for (const item of found) {
|
|
86
|
+
const prior = merged.at(-1);
|
|
87
|
+
if (prior !== undefined && item.start <= prior.end)
|
|
88
|
+
prior.end = Math.max(prior.end, item.end);
|
|
89
|
+
else
|
|
90
|
+
merged.push({ ...item });
|
|
91
|
+
}
|
|
92
|
+
return { ranges: merged };
|
|
93
|
+
}
|
|
94
|
+
function sendSpa(request, reply) {
|
|
95
|
+
const encoded = request.url.split('?', 1)[0] ?? '/';
|
|
96
|
+
let requested;
|
|
97
|
+
try {
|
|
98
|
+
requested = decodeURIComponent(encoded);
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
return reply.code(404).send({ detail: 'Not Found' });
|
|
102
|
+
}
|
|
103
|
+
const relative = requested.replace(/^\/+/, '');
|
|
104
|
+
let candidate = path.resolve(WEBUI, relative);
|
|
105
|
+
const inside = candidate === WEBUI || candidate.startsWith(`${WEBUI}${path.sep}`);
|
|
106
|
+
if (!inside || candidate.includes('\0') || !fs.existsSync(candidate)) {
|
|
107
|
+
return reply.code(404).send({ detail: 'Not Found' });
|
|
108
|
+
}
|
|
109
|
+
let stat = fs.statSync(candidate);
|
|
110
|
+
if (stat.isDirectory()) {
|
|
111
|
+
candidate = path.join(candidate, 'index.html');
|
|
112
|
+
if (!fs.existsSync(candidate) || !fs.statSync(candidate).isFile()) {
|
|
113
|
+
return reply.code(404).send({ detail: 'Not Found' });
|
|
114
|
+
}
|
|
115
|
+
if (!requested.endsWith('/'))
|
|
116
|
+
return reply.redirect(`${encoded}/`, 307);
|
|
117
|
+
stat = fs.statSync(candidate);
|
|
118
|
+
}
|
|
119
|
+
if (!stat.isFile())
|
|
120
|
+
return reply.code(404).send({ detail: 'Not Found' });
|
|
121
|
+
// The page itself is never stored. Back after signing out showed a cached shell whose
|
|
122
|
+
// modules were then sent to sign-in, so nothing ran; unstored, Back asks the server, and a
|
|
123
|
+
// signed-out browser is redirected to sign-in. The modules keep `no-cache` and their ETag.
|
|
124
|
+
if (contentType(candidate).startsWith('text/html'))
|
|
125
|
+
reply.header('Cache-Control', 'no-store');
|
|
126
|
+
const etagBase = `${String(stat.mtimeMs / 1000)}-${String(stat.size)}`;
|
|
127
|
+
const etag = `"${(0, node_crypto_1.createHash)('md5').update(etagBase).digest('hex')}"`;
|
|
128
|
+
const lastModified = stat.mtime.toUTCString();
|
|
129
|
+
if (request.headers['if-none-match']
|
|
130
|
+
?.split(',')
|
|
131
|
+
.some((tag) => tag.trim().replace(/^W\//u, '') === etag) === true ||
|
|
132
|
+
(request.headers['if-none-match'] === undefined &&
|
|
133
|
+
request.headers['if-modified-since'] !== undefined &&
|
|
134
|
+
new Date(request.headers['if-modified-since']).getTime() >=
|
|
135
|
+
Math.floor(stat.mtime.getTime() / 1000) * 1000)) {
|
|
136
|
+
return reply.code(304).header('etag', etag).send();
|
|
137
|
+
}
|
|
138
|
+
const mediaType = contentType(candidate);
|
|
139
|
+
const rangeHeader = request.headers.range;
|
|
140
|
+
const ifRange = request.headers['if-range'];
|
|
141
|
+
let requestedRanges;
|
|
142
|
+
if (rangeHeader !== undefined &&
|
|
143
|
+
(ifRange === undefined || ifRange === etag || ifRange === lastModified)) {
|
|
144
|
+
const parsed = byteRanges(rangeHeader, stat.size);
|
|
145
|
+
if ('status' in parsed) {
|
|
146
|
+
if (parsed.status === 400) {
|
|
147
|
+
return reply.code(400).type('text/plain; charset=utf-8').send(parsed.content);
|
|
148
|
+
}
|
|
149
|
+
return reply
|
|
150
|
+
.code(416)
|
|
151
|
+
.type('text/plain; charset=utf-8')
|
|
152
|
+
.header('content-range', `bytes */${String(stat.size)}`)
|
|
153
|
+
.send('');
|
|
154
|
+
}
|
|
155
|
+
requestedRanges = parsed.ranges;
|
|
156
|
+
}
|
|
157
|
+
const base = reply
|
|
158
|
+
.type(mediaType)
|
|
159
|
+
.header('accept-ranges', 'bytes')
|
|
160
|
+
.header('last-modified', lastModified)
|
|
161
|
+
.header('etag', etag);
|
|
162
|
+
if (requestedRanges !== undefined) {
|
|
163
|
+
if (requestedRanges.length === 1) {
|
|
164
|
+
const { start, end } = requestedRanges[0];
|
|
165
|
+
return base
|
|
166
|
+
.code(206)
|
|
167
|
+
.header('content-range', `bytes ${String(start)}-${String(end - 1)}/${String(stat.size)}`)
|
|
168
|
+
.header('content-length', String(end - start))
|
|
169
|
+
.send(fs.readFileSync(candidate).subarray(start, end));
|
|
170
|
+
}
|
|
171
|
+
if (requestedRanges.length > 1) {
|
|
172
|
+
const boundary = (0, node_crypto_1.randomBytes)(13).toString('hex');
|
|
173
|
+
const document = fs.readFileSync(candidate);
|
|
174
|
+
const parts = [];
|
|
175
|
+
for (const { start, end } of requestedRanges) {
|
|
176
|
+
parts.push(Buffer.from(`--${boundary}\r\nContent-Type: ${mediaType}\r\n` +
|
|
177
|
+
`Content-Range: bytes ${String(start)}-${String(end - 1)}/${String(stat.size)}\r\n\r\n`, 'latin1'), document.subarray(start, end), Buffer.from('\r\n'));
|
|
178
|
+
}
|
|
179
|
+
parts.push(Buffer.from(`--${boundary}--`, 'latin1'));
|
|
180
|
+
const body = Buffer.concat(parts);
|
|
181
|
+
return base
|
|
182
|
+
.code(206)
|
|
183
|
+
.type(`multipart/byteranges; boundary=${boundary}`)
|
|
184
|
+
.header('content-length', String(body.length))
|
|
185
|
+
.send(body);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return base
|
|
189
|
+
.type(contentType(candidate))
|
|
190
|
+
.header('content-length', String(stat.size))
|
|
191
|
+
.send(fs.readFileSync(candidate));
|
|
192
|
+
}
|
|
193
|
+
function register(app) {
|
|
194
|
+
app.head('/', { config: { houstonSpa: true } }, sendSpa);
|
|
195
|
+
app.head('/*', { config: { houstonSpa: true } }, sendSpa);
|
|
196
|
+
app.get('/', { config: { houstonSpa: true } }, sendSpa);
|
|
197
|
+
app.get('/*', { config: { houstonSpa: true } }, sendSpa);
|
|
198
|
+
}
|