hfs 0.49.0 → 0.50.0-alpha1
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/README.md +3 -0
- package/admin/assets/{index-3c80e1c3.js → index-c618ba7d.js} +112 -111
- package/admin/assets/{index-1c2b890b.css → index-f3fd8783.css} +1 -1
- package/{frontend/assets/sha512-37516713.js → admin/assets/sha512-1ee27408.js} +1 -1
- package/admin/index.html +2 -2
- package/frontend/assets/index-83cd0389.js +94 -0
- package/frontend/assets/{index-669a2741.css → index-b50efd06.css} +1 -1
- package/{admin/assets/sha512-03998350.js → frontend/assets/sha512-90bb0108.js} +1 -1
- package/frontend/index.html +2 -2
- package/package.json +1 -1
- package/plugins/antibrute/plugin.js +1 -1
- package/plugins/vhosting/plugin.js +3 -3
- package/src/acme.js +14 -14
- package/src/adminApis.js +12 -13
- package/src/api.accounts.js +7 -1
- package/src/api.auth.js +7 -31
- package/src/api.file_list.js +3 -1
- package/src/api.monitor.js +2 -2
- package/src/api.vfs.js +6 -8
- package/src/auth.js +49 -0
- package/src/block.js +1 -1
- package/src/const.js +1 -1
- package/src/cross.js +43 -3
- package/src/listen.js +16 -5
- package/src/log.js +2 -2
- package/src/middlewares.js +23 -21
- package/src/nat.js +1 -0
- package/src/perm.js +1 -6
- package/src/plugins.js +0 -1
- package/src/selfCheck.js +26 -36
- package/src/serveGuiFiles.js +2 -4
- package/src/srp.js +22 -0
- package/src/upload.js +2 -2
- package/src/vfs.js +10 -14
- package/src/zip.js +2 -0
- package/frontend/assets/index-0be475af.js +0 -94
package/src/listen.js
CHANGED
|
@@ -118,9 +118,20 @@ const considerHttps = (0, misc_1.debounceAsync)(async () => {
|
|
|
118
118
|
if (cn)
|
|
119
119
|
console.log("certificate loaded for", cn);
|
|
120
120
|
const now = new Date();
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
121
|
+
const from = new Date(cert.validFrom);
|
|
122
|
+
const to = new Date(cert.validTo);
|
|
123
|
+
updateError(); // error will change at from and to dates of the certificate
|
|
124
|
+
const cancelTo = (0, misc_1.runAt)(to.getTime(), updateError);
|
|
125
|
+
const cancelFrom = (0, misc_1.runAt)(from.getTime(), updateError);
|
|
126
|
+
httpsSrv.on('close', () => {
|
|
127
|
+
cancelTo();
|
|
128
|
+
cancelFrom();
|
|
129
|
+
});
|
|
130
|
+
function updateError() {
|
|
131
|
+
if (!httpsSrv)
|
|
132
|
+
return;
|
|
133
|
+
httpsSrv.error = from > now ? "certificate not valid yet" : to < now ? "certificate expired" : undefined;
|
|
134
|
+
}
|
|
124
135
|
const namesForOutput = { cert: 'certificate', private_key: 'private key' };
|
|
125
136
|
const missing = (_c = httpsNeeds.find(x => !x.get())) === null || _c === void 0 ? void 0 : _c.key();
|
|
126
137
|
if (missing)
|
|
@@ -247,7 +258,7 @@ function getCurrentPort(srv) {
|
|
|
247
258
|
var _a;
|
|
248
259
|
return (_a = srv === null || srv === void 0 ? void 0 : srv.address()) === null || _a === void 0 ? void 0 : _a.port;
|
|
249
260
|
}
|
|
250
|
-
async function getServerStatus() {
|
|
261
|
+
async function getServerStatus(includeSrv = true) {
|
|
251
262
|
return {
|
|
252
263
|
http: await serverStatus(httpSrv, exports.portCfg.get()),
|
|
253
264
|
https: await serverStatus(httpsSrv, exports.httpsPortCfg.get()),
|
|
@@ -260,7 +271,7 @@ async function getServerStatus() {
|
|
|
260
271
|
busy,
|
|
261
272
|
port: getCurrentPort(srv) || configuredPort,
|
|
262
273
|
configuredPort,
|
|
263
|
-
srv,
|
|
274
|
+
srv: includeSrv ? srv : undefined,
|
|
264
275
|
};
|
|
265
276
|
}
|
|
266
277
|
}
|
package/src/log.js
CHANGED
|
@@ -35,7 +35,7 @@ const util = __importStar(require("util"));
|
|
|
35
35
|
const promises_1 = require("fs/promises");
|
|
36
36
|
const lodash_1 = __importDefault(require("lodash"));
|
|
37
37
|
const util_files_1 = require("./util-files");
|
|
38
|
-
const
|
|
38
|
+
const auth_1 = require("./auth");
|
|
39
39
|
const misc_1 = require("./misc");
|
|
40
40
|
const events_1 = __importDefault(require("./events"));
|
|
41
41
|
class Logger {
|
|
@@ -122,7 +122,7 @@ const logMw = async (ctx, next) => {
|
|
|
122
122
|
const format = '%s - %s [%s] "%s %s HTTP/%s" %d %s %s\n'; // Apache's Common Log Format
|
|
123
123
|
const a = now.toString().split(' ');
|
|
124
124
|
const date = a[2] + '/' + a[1] + '/' + a[3] + ':' + a[4] + ' ' + ((_b = a[5]) === null || _b === void 0 ? void 0 : _b.slice(3));
|
|
125
|
-
const user = (0,
|
|
125
|
+
const user = (0, auth_1.getCurrentUsername)(ctx);
|
|
126
126
|
const length = (_c = ctx.state.length) !== null && _c !== void 0 ? _c : ctx.length;
|
|
127
127
|
const uri = ctx.originalUrl;
|
|
128
128
|
const extra = ctx.state.includesLastByte && ctx.vfsNode && ctx.res.finished && { dl: 1 }
|
package/src/middlewares.js
CHANGED
|
@@ -19,8 +19,7 @@ const block_1 = require("./block");
|
|
|
19
19
|
const perm_1 = require("./perm");
|
|
20
20
|
const connections_1 = require("./connections");
|
|
21
21
|
const basic_auth_1 = __importDefault(require("basic-auth"));
|
|
22
|
-
const
|
|
23
|
-
const api_auth_1 = require("./api.auth");
|
|
22
|
+
const auth_1 = require("./auth");
|
|
24
23
|
const path_1 = require("path");
|
|
25
24
|
const promises_1 = require("stream/promises");
|
|
26
25
|
const formidable_1 = __importDefault(require("formidable"));
|
|
@@ -202,11 +201,14 @@ function getProxyDetected() {
|
|
|
202
201
|
}
|
|
203
202
|
exports.getProxyDetected = getProxyDetected;
|
|
204
203
|
const prepareState = async (ctx, next) => {
|
|
205
|
-
var _a
|
|
206
|
-
if (ctx.session)
|
|
204
|
+
var _a;
|
|
205
|
+
if (ctx.session) {
|
|
206
|
+
if (auth_1.invalidSessions.delete(ctx.session.username))
|
|
207
|
+
delete ctx.session.username;
|
|
207
208
|
ctx.session.maxAge = exports.sessionDuration.compiled();
|
|
209
|
+
}
|
|
208
210
|
// calculate these once and for all
|
|
209
|
-
const a = ctx.state.account = (
|
|
211
|
+
const a = ctx.state.account = await urlLogin() || await getHttpAccount() || (0, perm_1.getAccount)((_a = ctx.session) === null || _a === void 0 ? void 0 : _a.username, false);
|
|
210
212
|
if (a && !(0, perm_1.accountCanLogin)(a))
|
|
211
213
|
ctx.state.account = undefined;
|
|
212
214
|
const conn = ctx.state.connection = (0, connections_1.socket2connection)(ctx.socket);
|
|
@@ -214,24 +216,24 @@ const prepareState = async (ctx, next) => {
|
|
|
214
216
|
if (conn)
|
|
215
217
|
(0, connections_1.updateConnection)(conn, { ctx, op: undefined });
|
|
216
218
|
await next();
|
|
219
|
+
async function urlLogin() {
|
|
220
|
+
const { login } = ctx.query;
|
|
221
|
+
if (!login)
|
|
222
|
+
return;
|
|
223
|
+
const [u, p] = (0, misc_1.splitAt)(':', String(login));
|
|
224
|
+
const a = await (0, auth_1.srpCheck)(u, p);
|
|
225
|
+
if (a) {
|
|
226
|
+
ctx.session.username = a.username;
|
|
227
|
+
ctx.redirect(ctx.originalUrl.slice(0, -ctx.querystring.length - 1));
|
|
228
|
+
}
|
|
229
|
+
return a;
|
|
230
|
+
}
|
|
231
|
+
async function getHttpAccount() {
|
|
232
|
+
const credentials = (0, basic_auth_1.default)(ctx.req);
|
|
233
|
+
return (0, auth_1.srpCheck)((credentials === null || credentials === void 0 ? void 0 : credentials.name) || '', (credentials === null || credentials === void 0 ? void 0 : credentials.pass) || '');
|
|
234
|
+
}
|
|
217
235
|
};
|
|
218
236
|
exports.prepareState = prepareState;
|
|
219
|
-
async function getHttpAccount(ctx) {
|
|
220
|
-
const credentials = (0, basic_auth_1.default)(ctx.req);
|
|
221
|
-
const account = (0, perm_1.getAccount)((credentials === null || credentials === void 0 ? void 0 : credentials.name) || '');
|
|
222
|
-
if (account && await srpCheck(account.username, credentials.pass))
|
|
223
|
-
return account;
|
|
224
|
-
}
|
|
225
|
-
async function srpCheck(username, password) {
|
|
226
|
-
const account = (0, perm_1.getAccount)(username);
|
|
227
|
-
if (!(account === null || account === void 0 ? void 0 : account.srp) || !password)
|
|
228
|
-
return false;
|
|
229
|
-
const { step1, salt, pubKey } = await (0, api_auth_1.srpStep1)(account);
|
|
230
|
-
const client = new tssrp6a_1.SRPClientSession(new tssrp6a_1.SRPRoutines(new tssrp6a_1.SRPParameters()));
|
|
231
|
-
const clientRes1 = await client.step1(username, password);
|
|
232
|
-
const clientRes2 = await clientRes1.step2(BigInt(salt), BigInt(pubKey));
|
|
233
|
-
return await step1.step2(clientRes2.A, clientRes2.M1).then(() => true, () => false);
|
|
234
|
-
}
|
|
235
237
|
const paramsDecoder = async (ctx, next) => {
|
|
236
238
|
ctx.params = ctx.method === 'POST' && ctx.originalUrl.startsWith(const_1.API_URI)
|
|
237
239
|
&& ((0, misc_1.tryJson)(await (0, misc_1.stream2string)(ctx.req)) || {});
|
package/src/nat.js
CHANGED
|
@@ -85,6 +85,7 @@ exports.getNatInfo = (0, debounceAsync_1.debounceAsync)(async () => {
|
|
|
85
85
|
publicIps: exports.defaultBaseUrl.publicIps = await gettingIps,
|
|
86
86
|
externalIp: exports.defaultBaseUrl.externalIp,
|
|
87
87
|
mapped,
|
|
88
|
+
mapped80: lodash_1.default.find(mappings, x => x.private.host === localIp && x.private.port === 80 && x.public.port === 80),
|
|
88
89
|
internalPort,
|
|
89
90
|
externalPort,
|
|
90
91
|
proto: ((_c = status === null || status === void 0 ? void 0 : status.https) === null || _c === void 0 ? void 0 : _c.listening) ? 'https' : ((_d = status === null || status === void 0 ? void 0 : status.http) === null || _d === void 0 ? void 0 : _d.listening) ? 'http' : '',
|
package/src/perm.js
CHANGED
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
5
|
};
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.accountCanLoginAdmin = exports.accountCanLogin = exports.accountHasPassword = exports.getFromAccount = exports.delAccount = exports.setAccount = exports.addAccount = exports.renameAccount = exports.normalizeUsername = exports.accountsConfig = exports.updateAccount = exports.createAdmin = exports.allowClearTextLogin = exports.saveSrpInfo = exports.getAccount = exports.expandUsername =
|
|
7
|
+
exports.accountCanLoginAdmin = exports.accountCanLogin = exports.accountHasPassword = exports.getFromAccount = exports.delAccount = exports.setAccount = exports.addAccount = exports.renameAccount = exports.normalizeUsername = exports.accountsConfig = exports.updateAccount = exports.createAdmin = exports.allowClearTextLogin = exports.saveSrpInfo = exports.getAccount = exports.expandUsername = void 0;
|
|
8
8
|
const lodash_1 = __importDefault(require("lodash"));
|
|
9
9
|
const crypt_1 = require("./crypt");
|
|
10
10
|
const misc_1 = require("./misc");
|
|
@@ -12,11 +12,6 @@ const config_1 = require("./config");
|
|
|
12
12
|
const tssrp6a_1 = require("tssrp6a");
|
|
13
13
|
const events_1 = __importDefault(require("./events"));
|
|
14
14
|
let accounts = {};
|
|
15
|
-
function getCurrentUsername(ctx) {
|
|
16
|
-
var _a;
|
|
17
|
-
return ((_a = ctx.state.account) === null || _a === void 0 ? void 0 : _a.username) || '';
|
|
18
|
-
}
|
|
19
|
-
exports.getCurrentUsername = getCurrentUsername;
|
|
20
15
|
// provides the username and all other usernames it inherits based on the 'belongs' attribute. Useful to check permissions
|
|
21
16
|
function expandUsername(who) {
|
|
22
17
|
const ret = [];
|
package/src/plugins.js
CHANGED
|
@@ -120,7 +120,6 @@ exports.getPluginConfigFields = getPluginConfigFields;
|
|
|
120
120
|
async function initPlugin(pl, more) {
|
|
121
121
|
var _a;
|
|
122
122
|
return Object.assign(pl, await ((_a = pl.init) === null || _a === void 0 ? void 0 : _a.call(pl, {
|
|
123
|
-
const: Const,
|
|
124
123
|
Const,
|
|
125
124
|
require,
|
|
126
125
|
getConnections: connections_1.getConnections,
|
package/src/selfCheck.js
CHANGED
|
@@ -10,51 +10,41 @@ const net_1 = require("net");
|
|
|
10
10
|
const lodash_1 = __importDefault(require("lodash"));
|
|
11
11
|
const cross_1 = require("./cross");
|
|
12
12
|
const util_http_1 = require("./util-http");
|
|
13
|
-
let selfCheckMiddlewareEnabled = false;
|
|
14
13
|
const CHECK_URL = cross_const_1.SPECIAL_URI + 'self-check';
|
|
15
|
-
const selfCheckMiddleware = (ctx, next) =>
|
|
16
|
-
|
|
17
|
-
return next();
|
|
18
|
-
ctx.body = 'HFS';
|
|
19
|
-
};
|
|
14
|
+
const selfCheckMiddleware = (ctx, next) => // koa format
|
|
15
|
+
ctx.url.startsWith(CHECK_URL) ? ctx.body = 'HFS' : next();
|
|
20
16
|
exports.selfCheckMiddleware = selfCheckMiddleware;
|
|
21
17
|
async function selfCheck(url) {
|
|
22
18
|
var _a;
|
|
23
19
|
const prjInfo = await (0, github_1.getProjectInfo)();
|
|
24
20
|
console.log(`checking server ${url}`);
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return { success, service, url };
|
|
46
|
-
}));
|
|
47
|
-
}
|
|
48
|
-
catch (e) {
|
|
49
|
-
console.debug(((_a = e === null || e === void 0 ? void 0 : e.errors) === null || _a === void 0 ? void 0 : _a.map(String)) || (e === null || e === void 0 ? void 0 : e.cause) || String(e));
|
|
50
|
-
}
|
|
21
|
+
const parsed = new URL(url);
|
|
22
|
+
const family = !(0, net_1.isIP)(parsed.hostname) ? undefined : (0, net_1.isIPv6)(parsed.hostname) ? 6 : 4;
|
|
23
|
+
for (const services of lodash_1.default.chunk(lodash_1.default.shuffle(prjInfo.selfCheckServices), 2)) {
|
|
24
|
+
try {
|
|
25
|
+
return await Promise.any(services.map(async (svc) => {
|
|
26
|
+
if (!svc.url || svc.type)
|
|
27
|
+
throw 'unsupported ' + svc.type; // only default type supported for now
|
|
28
|
+
let { url: serviceUrl, body, regexpSuccess, regexpFailure, ...rest } = svc;
|
|
29
|
+
const service = new URL(serviceUrl).hostname;
|
|
30
|
+
console.log('trying external service', service);
|
|
31
|
+
body = applySymbols(body);
|
|
32
|
+
serviceUrl = applySymbols(serviceUrl);
|
|
33
|
+
const res = await (0, cross_1.haveTimeout)(6000, (0, util_http_1.httpString)(serviceUrl, { family, ...rest, body }));
|
|
34
|
+
const success = new RegExp(regexpSuccess).test(res);
|
|
35
|
+
const failure = new RegExp(regexpFailure).test(res);
|
|
36
|
+
if (success === failure)
|
|
37
|
+
throw 'inconsistent: ' + service + ': ' + res; // this result cannot be trusted
|
|
38
|
+
console.debug(service, 'responded', success);
|
|
39
|
+
return { success, service, url };
|
|
40
|
+
}));
|
|
51
41
|
}
|
|
52
|
-
|
|
53
|
-
|
|
42
|
+
catch (e) {
|
|
43
|
+
console.debug(((_a = e === null || e === void 0 ? void 0 : e.errors) === null || _a === void 0 ? void 0 : _a.map(String)) || (e === null || e === void 0 ? void 0 : e.cause) || String(e));
|
|
54
44
|
}
|
|
55
45
|
}
|
|
56
|
-
|
|
57
|
-
|
|
46
|
+
function applySymbols(s) {
|
|
47
|
+
return s === null || s === void 0 ? void 0 : s.replace('$IP', parsed.hostname).replace('$PORT', parsed.port || (parsed.protocol === 'https:' ? '443' : '80')).replace('$URL', url.replace(/\/$/, '') + CHECK_URL);
|
|
58
48
|
}
|
|
59
49
|
}
|
|
60
50
|
exports.selfCheck = selfCheck;
|
package/src/serveGuiFiles.js
CHANGED
|
@@ -44,6 +44,7 @@ const config_1 = require("./config");
|
|
|
44
44
|
const lang_1 = require("./lang");
|
|
45
45
|
const vfs_1 = require("./vfs");
|
|
46
46
|
const logGui = (0, config_1.defineConfig)('log_gui', false);
|
|
47
|
+
lodash_1.default.each(misc_1.FRONTEND_OPTIONS, (v, k) => (0, config_1.defineConfig)(k, v)); // define default values
|
|
47
48
|
// in case of dev env we have our static files within the 'dist' folder'
|
|
48
49
|
const DEV_STATIC = process.env.DEV ? 'dist/' : '';
|
|
49
50
|
function serveStatic(uri) {
|
|
@@ -119,8 +120,7 @@ async function treatIndex(ctx, filesUri, body) {
|
|
|
119
120
|
plugins,
|
|
120
121
|
prefixUrl: ctx.state.revProxyPath,
|
|
121
122
|
customHtml: lodash_1.default.omit(Object.fromEntries(customHtml_1.customHtmlState.sections), ['top', 'bottom']),
|
|
122
|
-
|
|
123
|
-
tilesSize: tilesSize.get(),
|
|
123
|
+
...(0, misc_1.newObj)(misc_1.FRONTEND_OPTIONS, (v, k) => (0, config_1.getConfig)(k)),
|
|
124
124
|
lang
|
|
125
125
|
}, null, 4)
|
|
126
126
|
.replace(/<(\/script)/g, '<"+"$1') /*avoid breaking our script container*/}
|
|
@@ -175,5 +175,3 @@ function serveGuiFiles(proxyPort, uri) {
|
|
|
175
175
|
return serveProxied(proxyPort, uri) || serveStatic(uri);
|
|
176
176
|
}
|
|
177
177
|
exports.serveGuiFiles = serveGuiFiles;
|
|
178
|
-
const fileMenuOnLink = (0, config_1.defineConfig)('file_menu_on_link', true);
|
|
179
|
-
const tilesSize = (0, config_1.defineConfig)('tiles_size', 0);
|
package/src/srp.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// This file is part of HFS - Copyright 2021-2023, Massimo Melina <a@rejetto.com> - License https://www.gnu.org/licenses/gpl-3.0.txt
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.srpClientPart = exports.srpClientSequence = void 0;
|
|
5
|
+
const tssrp6a_1 = require("tssrp6a");
|
|
6
|
+
async function srpClientSequence(username, password, apiCall) {
|
|
7
|
+
const { pubKey, salt } = await apiCall('loginSrp1', { username });
|
|
8
|
+
if (!salt)
|
|
9
|
+
throw Error('salt');
|
|
10
|
+
const client = await srpClientPart(username, password, salt, pubKey);
|
|
11
|
+
const res = await apiCall('loginSrp2', { pubKey: String(client.A), proof: String(client.M1) }); // bigint-s must be cast to string to be json-ed
|
|
12
|
+
await client.step3(BigInt(res.proof)).catch(() => Promise.reject('trust'));
|
|
13
|
+
return res;
|
|
14
|
+
}
|
|
15
|
+
exports.srpClientSequence = srpClientSequence;
|
|
16
|
+
async function srpClientPart(username, password, salt, pubKey) {
|
|
17
|
+
const srp6aNimbusRoutines = new tssrp6a_1.SRPRoutines(new tssrp6a_1.SRPParameters());
|
|
18
|
+
const srp = new tssrp6a_1.SRPClientSession(srp6aNimbusRoutines);
|
|
19
|
+
const res = await srp.step1(username, password);
|
|
20
|
+
return await res.step2(BigInt(salt), BigInt(pubKey));
|
|
21
|
+
}
|
|
22
|
+
exports.srpClientPart = srpClientPart;
|
package/src/upload.js
CHANGED
|
@@ -14,7 +14,7 @@ const config_1 = require("./config");
|
|
|
14
14
|
const util_os_1 = require("./util-os");
|
|
15
15
|
const connections_1 = require("./connections");
|
|
16
16
|
const throttler_1 = require("./throttler");
|
|
17
|
-
const
|
|
17
|
+
const auth_1 = require("./auth");
|
|
18
18
|
const comments_1 = require("./comments");
|
|
19
19
|
exports.deleteUnfinishedUploadsAfter = (0, config_1.defineConfig)('delete_unfinished_uploads_after', 86400);
|
|
20
20
|
exports.minAvailableMb = (0, config_1.defineConfig)('min_available_mb', 100);
|
|
@@ -27,7 +27,7 @@ function getUploadMeta(path) {
|
|
|
27
27
|
exports.getUploadMeta = getUploadMeta;
|
|
28
28
|
function setUploadMeta(path, ctx) {
|
|
29
29
|
return (0, misc_1.storeFileAttr)(path, ATTR_UPLOADER, {
|
|
30
|
-
username: (0,
|
|
30
|
+
username: (0, auth_1.getCurrentUsername)(ctx) || undefined,
|
|
31
31
|
ip: ctx.ip,
|
|
32
32
|
});
|
|
33
33
|
}
|
package/src/vfs.js
CHANGED
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
5
|
};
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.parentMaskApplier = exports.masksCouldGivePermission = exports.walkNode = exports.statusCodeForMissingPerm = exports.hasPermission = exports.nodeIsDirectory = exports.getNodeName = exports.saveVfs = exports.vfs = exports.urlToNode = exports.applyParentToChild = exports.isSameFilenameAs = exports.permsFromParent = exports.MIME_AUTO = void 0;
|
|
7
|
+
exports.parentMaskApplier = exports.masksCouldGivePermission = exports.walkNode = exports.statusCodeForMissingPerm = exports.hasPermission = exports.nodeIsLink = exports.nodeIsDirectory = exports.getNodeName = exports.saveVfs = exports.vfs = exports.urlToNode = exports.applyParentToChild = exports.isSameFilenameAs = exports.permsFromParent = exports.MIME_AUTO = void 0;
|
|
8
8
|
const promises_1 = __importDefault(require("fs/promises"));
|
|
9
9
|
const path_1 = require("path");
|
|
10
10
|
const misc_1 = require("./misc");
|
|
@@ -13,6 +13,7 @@ const config_1 = require("./config");
|
|
|
13
13
|
const const_1 = require("./const");
|
|
14
14
|
const events_1 = __importDefault(require("./events"));
|
|
15
15
|
const perm_1 = require("./perm");
|
|
16
|
+
const auth_1 = require("./auth");
|
|
16
17
|
exports.MIME_AUTO = 'auto';
|
|
17
18
|
function permsFromParent(parent, child) {
|
|
18
19
|
const ret = {};
|
|
@@ -119,12 +120,6 @@ async function urlToNode(url, ctx, parent = exports.vfs, getRest) {
|
|
|
119
120
|
exports.urlToNode = urlToNode;
|
|
120
121
|
exports.vfs = {};
|
|
121
122
|
(0, config_1.defineConfig)('vfs', {}).sub(data => exports.vfs = (function recur(node) {
|
|
122
|
-
if (node.propagate) { // legacy pre-0.47
|
|
123
|
-
for (const [k, v] of (0, misc_1.typedEntries)(node.propagate))
|
|
124
|
-
if (v === false)
|
|
125
|
-
node[k] = { this: node[k] };
|
|
126
|
-
delete node.propagate;
|
|
127
|
-
}
|
|
128
123
|
if (node.children)
|
|
129
124
|
for (const c of node.children)
|
|
130
125
|
recur(c);
|
|
@@ -154,14 +149,15 @@ async function nodeIsDirectory(node) {
|
|
|
154
149
|
var _a;
|
|
155
150
|
if (node.isFolder !== undefined)
|
|
156
151
|
return node.isFolder;
|
|
157
|
-
const isFolder = Boolean(((_a = node.children) === null || _a === void 0 ? void 0 : _a.length) || !node.source || await (0, misc_1.isDirectory)(node.source));
|
|
158
|
-
|
|
159
|
-
node.isFolder = isFolder;
|
|
160
|
-
else
|
|
161
|
-
(0, misc_1.setHidden)(node, { isFolder }); // don't make it to the storage
|
|
152
|
+
const isFolder = Boolean(((_a = node.children) === null || _a === void 0 ? void 0 : _a.length) || !nodeIsLink(node) && (!node.source || await (0, misc_1.isDirectory)(node.source)));
|
|
153
|
+
(0, misc_1.setHidden)(node, { isFolder }); // don't make it to the storage (a node.isTemp doesn't need it to be hidden)
|
|
162
154
|
return isFolder;
|
|
163
155
|
}
|
|
164
156
|
exports.nodeIsDirectory = nodeIsDirectory;
|
|
157
|
+
function nodeIsLink(node) {
|
|
158
|
+
return node.url;
|
|
159
|
+
}
|
|
160
|
+
exports.nodeIsLink = nodeIsLink;
|
|
165
161
|
function hasPermission(node, perm, ctx) {
|
|
166
162
|
return !statusCodeForMissingPerm(node, perm, ctx, false);
|
|
167
163
|
}
|
|
@@ -189,12 +185,12 @@ function statusCodeForMissingPerm(node, perm, ctx, assign = true) {
|
|
|
189
185
|
if (Array.isArray(who)) {
|
|
190
186
|
const arr = who; // shut up ts
|
|
191
187
|
// check if I or any ancestor match `who`, but cache ancestors' usernames inside context state
|
|
192
|
-
const some = (0, misc_1.getOrSet)(ctx.state, 'usernames', () => (0, perm_1.expandUsername)((0,
|
|
188
|
+
const some = (0, misc_1.getOrSet)(ctx.state, 'usernames', () => (0, perm_1.expandUsername)((0, auth_1.getCurrentUsername)(ctx)))
|
|
193
189
|
.some((u) => arr.includes(u));
|
|
194
190
|
return some ? 0 : const_1.HTTP_UNAUTHORIZED;
|
|
195
191
|
}
|
|
196
192
|
return typeof who === 'boolean' ? (who ? 0 : const_1.HTTP_FORBIDDEN)
|
|
197
|
-
: who === misc_1.WHO_ANY_ACCOUNT ? (ctx
|
|
193
|
+
: who === misc_1.WHO_ANY_ACCOUNT ? ((0, auth_1.getCurrentUsername)(ctx) ? 0 : const_1.HTTP_UNAUTHORIZED)
|
|
198
194
|
: (0, misc_1.throw_)(Error('invalid permission: ' + JSON.stringify(who)));
|
|
199
195
|
}
|
|
200
196
|
}
|
package/src/zip.js
CHANGED
|
@@ -43,6 +43,8 @@ async function zipStreamFromFolder(node, ctx) {
|
|
|
43
43
|
}
|
|
44
44
|
})();
|
|
45
45
|
const mappedWalker = (0, misc_1.filterMapGenerator)(walker, async (el) => {
|
|
46
|
+
if ((0, vfs_1.nodeIsLink)(el))
|
|
47
|
+
return;
|
|
46
48
|
if (!(0, vfs_1.hasPermission)(el, 'can_archive', ctx))
|
|
47
49
|
return; // the fact you see it doesn't mean you can get it
|
|
48
50
|
const { source } = el;
|