hfs 0.57.24 → 0.57.27-beta2
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/admin/assets/{index-CMArzROW.js → index-DSkhXlWX.js} +129 -129
- package/admin/assets/{sha512-BbjMQS_R.js → sha512-CoddZKeD.js} +1 -1
- package/admin/index.html +1 -1
- package/frontend/assets/{index-legacy-uM-kzXmI.js → index-legacy-C4Gclsbz.js} +4 -4
- package/frontend/assets/{sha512-legacy-CWlrw4EZ.js → sha512-legacy-C-FMk44u.js} +1 -1
- package/frontend/index.html +1 -1
- package/package.json +5 -4
- package/src/QuickZipStream.js +11 -8
- package/src/SendList.js +10 -8
- package/src/ThrottledStream.js +8 -6
- package/src/acme.js +5 -7
- package/src/adminApis.js +6 -7
- package/src/api.accounts.js +7 -9
- package/src/api.auth.js +7 -11
- package/src/api.get_file_list.js +13 -19
- package/src/api.lang.js +1 -1
- package/src/api.log.js +1 -2
- package/src/api.monitor.js +2 -3
- package/src/api.net.js +2 -3
- package/src/api.plugins.js +8 -10
- package/src/api.vfs.js +15 -20
- package/src/apiMiddleware.js +4 -4
- package/src/auth.js +6 -9
- package/src/basicWeb.js +1 -2
- package/src/block.js +1 -1
- package/src/commands.js +9 -9
- package/src/comments.js +4 -5
- package/src/config.js +10 -10
- package/src/connections.js +11 -6
- package/src/consoleLog.js +6 -6
- package/src/const.js +4 -4
- package/src/cross.js +19 -21
- package/src/customHtml.js +3 -4
- package/src/ddns.js +4 -4
- package/src/debounceAsync.js +3 -3
- package/src/errorPages.js +2 -3
- package/src/events.js +7 -10
- package/src/fileAttr.js +12 -8
- package/src/first.js +13 -8
- package/src/frontEndApis.js +5 -5
- package/src/geo.js +5 -7
- package/src/github.js +14 -17
- package/src/i18n.js +3 -4
- package/src/icons.js +1 -1
- package/src/index.js +2 -3
- package/src/lang.js +5 -6
- package/src/listen.js +25 -28
- package/src/log.js +20 -20
- package/src/middlewares.js +12 -15
- package/src/misc.js +15 -14
- package/src/nat.js +14 -16
- package/src/outboundProxy.js +7 -7
- package/src/perm.js +12 -13
- package/src/persistence.js +1 -1
- package/src/plugins.js +62 -73
- package/src/roots.js +1 -2
- package/src/selfCheck.js +5 -4
- package/src/serveFile.js +7 -8
- package/src/serveGuiAndSharedFiles.js +7 -9
- package/src/serveGuiFiles.js +11 -21
- package/src/stat.js +40 -0
- package/src/statWorker.js +11 -0
- package/src/throttler.js +5 -7
- package/src/update.js +9 -9
- package/src/upload.js +11 -13
- package/src/util-files.js +48 -32
- package/src/util-http.js +80 -29
- package/src/util-os.js +5 -8
- package/src/vfs.js +77 -68
- package/src/walkDir.js +9 -9
- package/src/watchLoad.js +4 -4
- package/src/zip.js +5 -10
package/src/misc.js
CHANGED
|
@@ -51,12 +51,10 @@ function isLocalHost(c) {
|
|
|
51
51
|
}
|
|
52
52
|
// this will memory-leak over mask, so be careful with what you use this. Object is 3x faster than _.memoize
|
|
53
53
|
function netMatches(ip, mask, emptyMaskReturns = false) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return (cache[_b = mask + (emptyMaskReturns ? '1' : '0')] || (cache[_b] = makeNetMatcher(mask, emptyMaskReturns)))(ip); // cache the matcher
|
|
54
|
+
const cache = netMatches.cache ||= {};
|
|
55
|
+
return (cache[mask + (emptyMaskReturns ? '1' : '0')] ||= makeNetMatcher(mask, emptyMaskReturns))(ip); // cache the matcher
|
|
57
56
|
}
|
|
58
57
|
function makeNetMatcher(mask, emptyMaskReturns = false) {
|
|
59
|
-
var _a;
|
|
60
58
|
if (!mask)
|
|
61
59
|
return () => emptyMaskReturns;
|
|
62
60
|
mask = mask.replaceAll(' ', '');
|
|
@@ -68,7 +66,7 @@ function makeNetMatcher(mask, emptyMaskReturns = false) {
|
|
|
68
66
|
return (0, cross_1.makeMatcher)(mask);
|
|
69
67
|
}
|
|
70
68
|
const all = mask.split('|');
|
|
71
|
-
const neg =
|
|
69
|
+
const neg = all[0]?.[0] === '!';
|
|
72
70
|
if (neg)
|
|
73
71
|
all[0] = all[0].slice(1);
|
|
74
72
|
const bl = new node_net_1.BlockList();
|
|
@@ -83,15 +81,15 @@ function makeNetMatcher(mask, emptyMaskReturns = false) {
|
|
|
83
81
|
try {
|
|
84
82
|
bl.addSubnet(address, Number(m[2]));
|
|
85
83
|
}
|
|
86
|
-
catch
|
|
84
|
+
catch {
|
|
87
85
|
throw x;
|
|
88
86
|
}
|
|
89
87
|
else if (m[3])
|
|
90
88
|
try {
|
|
91
|
-
bl.addRange(address, parseAddress(m[
|
|
89
|
+
bl.addRange(address, parseAddress(m[3]));
|
|
92
90
|
}
|
|
93
|
-
catch
|
|
94
|
-
throw m[
|
|
91
|
+
catch {
|
|
92
|
+
throw m[3];
|
|
95
93
|
}
|
|
96
94
|
else
|
|
97
95
|
bl.addAddress(address);
|
|
@@ -100,7 +98,7 @@ function makeNetMatcher(mask, emptyMaskReturns = false) {
|
|
|
100
98
|
try {
|
|
101
99
|
return neg !== bl.check(parseAddress(ip));
|
|
102
100
|
}
|
|
103
|
-
catch
|
|
101
|
+
catch {
|
|
104
102
|
console.error("invalid address ", ip);
|
|
105
103
|
return false;
|
|
106
104
|
}
|
|
@@ -122,8 +120,7 @@ function asyncGeneratorToReadable(generator) {
|
|
|
122
120
|
return new stream_1.Readable({
|
|
123
121
|
objectMode: true,
|
|
124
122
|
destroy() {
|
|
125
|
-
|
|
126
|
-
void ((_a = iterator.return) === null || _a === void 0 ? void 0 : _a.call(iterator));
|
|
123
|
+
void iterator.return?.();
|
|
127
124
|
},
|
|
128
125
|
read() {
|
|
129
126
|
iterator.next().then(it => {
|
|
@@ -136,10 +133,11 @@ function asyncGeneratorToReadable(generator) {
|
|
|
136
133
|
}
|
|
137
134
|
// produces as promises resolve, not sequentially
|
|
138
135
|
class AsapStream extends stream_1.Readable {
|
|
136
|
+
promises;
|
|
137
|
+
finished = false;
|
|
139
138
|
constructor(promises) {
|
|
140
139
|
super({ objectMode: true });
|
|
141
140
|
this.promises = promises;
|
|
142
|
-
this.finished = false;
|
|
143
141
|
}
|
|
144
142
|
_read() {
|
|
145
143
|
if (this.finished)
|
|
@@ -152,10 +150,13 @@ class AsapStream extends stream_1.Readable {
|
|
|
152
150
|
}
|
|
153
151
|
exports.AsapStream = AsapStream;
|
|
154
152
|
function apiAssertTypes(paramsByType) {
|
|
155
|
-
for (const [types, params] of Object.entries(paramsByType))
|
|
153
|
+
for (const [types, params] of Object.entries(paramsByType)) {
|
|
154
|
+
if (!lodash_1.default.isPlainObject(params))
|
|
155
|
+
throw "invalid apiAssertTypes call";
|
|
156
156
|
for (const [name, val] of Object.entries(params))
|
|
157
157
|
if (!types.split('_').some(type => type === 'array' ? Array.isArray(val) : typeof val === type))
|
|
158
158
|
throw new apiMiddleware_1.ApiError(const_1.HTTP_BAD_REQUEST, 'bad ' + name);
|
|
159
|
+
}
|
|
159
160
|
}
|
|
160
161
|
function createStreamLimiter(limit) {
|
|
161
162
|
let got = 0;
|
package/src/nat.js
CHANGED
|
@@ -30,10 +30,10 @@ exports.defaultBaseUrl = (0, valtio_1.proxy)({
|
|
|
30
30
|
return `${this.proto}://${(0, cross_1.ipForUrl)(ip || 'localhost')}${!port || port === defPort ? '' : ':' + port}`;
|
|
31
31
|
}
|
|
32
32
|
});
|
|
33
|
-
exports.upnpClient = new nat_upnp_rejetto_1.Client({ timeout:
|
|
33
|
+
exports.upnpClient = new nat_upnp_rejetto_1.Client({ timeout: 4_000 });
|
|
34
34
|
const originalMethod = exports.upnpClient.getGateway;
|
|
35
35
|
// other client methods call getGateway too, so this will ensure they reuse this same result
|
|
36
|
-
exports.upnpClient.getGateway = (0, debounceAsync_1.debounceAsync)(() => originalMethod.apply(exports.upnpClient), { retain: cross_1.HOUR, retainFailure:
|
|
36
|
+
exports.upnpClient.getGateway = (0, debounceAsync_1.debounceAsync)(() => originalMethod.apply(exports.upnpClient), { retain: cross_1.HOUR, retainFailure: 30_000 });
|
|
37
37
|
exports.upnpClient.getGateway().then(res => {
|
|
38
38
|
console.log("upnp found", res.gateway.description);
|
|
39
39
|
}, e => console.debug('upnp failed:', e.message || String(e)));
|
|
@@ -46,16 +46,16 @@ exports.upnpClient.getGateway().then(res => {
|
|
|
46
46
|
}, () => { }));
|
|
47
47
|
exports.getPublicIps = (0, debounceAsync_1.debounceAsync)(async () => {
|
|
48
48
|
const res = await (0, github_1.getProjectInfo)();
|
|
49
|
-
const groupedByVersion = Object.values(lodash_1.default.groupBy(res.publicIpServices, x =>
|
|
49
|
+
const groupedByVersion = Object.values(lodash_1.default.groupBy(res.publicIpServices, x => x.v ?? 4));
|
|
50
50
|
const ips = await (0, cross_1.promiseBestEffort)(groupedByVersion.map(singleVersion => Promise.any(singleVersion.map(async (svc) => {
|
|
51
51
|
if (typeof svc === 'string')
|
|
52
52
|
svc = { type: 'http', url: svc };
|
|
53
53
|
console.debug("trying ip service", svc.url || svc.name);
|
|
54
54
|
if (svc.type === 'http')
|
|
55
|
-
return (0, util_http_1.httpString)(svc.url, { timeout:
|
|
55
|
+
return (0, util_http_1.httpString)(svc.url, { timeout: 5_000 });
|
|
56
56
|
if (svc.type !== 'dns')
|
|
57
57
|
throw "unsupported";
|
|
58
|
-
const resolver = new promises_1.Resolver({ timeout:
|
|
58
|
+
const resolver = new promises_1.Resolver({ timeout: 2_000 });
|
|
59
59
|
resolver.setServers(svc.ips);
|
|
60
60
|
return resolver.resolve(svc.name, svc.dnsRecord);
|
|
61
61
|
}).map(async (ret) => {
|
|
@@ -67,18 +67,17 @@ exports.getPublicIps = (0, debounceAsync_1.debounceAsync)(async () => {
|
|
|
67
67
|
return exports.defaultBaseUrl.publicIps = lodash_1.default.uniq(ips.flat());
|
|
68
68
|
}, { retain: 10 * cross_1.MINUTE });
|
|
69
69
|
exports.getNatInfo = (0, debounceAsync_1.debounceAsync)(async () => {
|
|
70
|
-
var _a, _b, _c, _d;
|
|
71
70
|
const gatewayIpPromise = findGateway().catch(() => undefined);
|
|
72
|
-
const res = await (0, cross_1.haveTimeout)(
|
|
71
|
+
const res = await (0, cross_1.haveTimeout)(10_000, exports.upnpClient.getGateway()).catch(() => null);
|
|
73
72
|
const status = await (0, listen_1.getServerStatus)();
|
|
74
|
-
const mappings = res && await (0, cross_1.haveTimeout)(
|
|
75
|
-
console.debug("mappings found:",
|
|
73
|
+
const mappings = res && await (0, cross_1.haveTimeout)(5_000, exports.upnpClient.getMappings()).catch(() => null);
|
|
74
|
+
console.debug("mappings found:", mappings?.map(x => x.description).join(', ') || "none");
|
|
76
75
|
const localIps = await (0, listen_1.getIps)(false);
|
|
77
76
|
const gatewayIp = await gatewayIpPromise;
|
|
78
|
-
const localIp =
|
|
79
|
-
const internalPort =
|
|
77
|
+
const localIp = res?.address || (gatewayIp ? lodash_1.default.maxBy(localIps, x => (0, cross_1.inCommon)(x, gatewayIp)) : localIps[0]);
|
|
78
|
+
const internalPort = status?.https?.listening && status.https.port || status?.http?.listening && status.http.port || undefined;
|
|
80
79
|
const mapped = lodash_1.default.find(mappings, x => x.private.host === localIp && x.private.port === internalPort);
|
|
81
|
-
const externalPort = mapped
|
|
80
|
+
const externalPort = mapped?.public.port;
|
|
82
81
|
if (localIp)
|
|
83
82
|
exports.defaultBaseUrl.localIp = localIp;
|
|
84
83
|
exports.defaultBaseUrl.port = externalPort || internalPort || 0;
|
|
@@ -91,18 +90,17 @@ exports.getNatInfo = (0, debounceAsync_1.debounceAsync)(async () => {
|
|
|
91
90
|
mapped80: lodash_1.default.find(mappings, x => x.private.host === localIp && x.private.port === 80 && x.public.port === 80),
|
|
92
91
|
internalPort,
|
|
93
92
|
externalPort,
|
|
94
|
-
proto:
|
|
93
|
+
proto: status?.https?.listening ? 'https' : status?.http?.listening ? 'http' : '',
|
|
95
94
|
};
|
|
96
95
|
}, { reuseRunning: true });
|
|
97
96
|
(0, exports.getNatInfo)();
|
|
98
97
|
function findGateway() {
|
|
99
98
|
return new Promise((resolve, reject) => (0, child_process_1.exec)(const_1.IS_WINDOWS || const_1.IS_MAC ? 'netstat -rn' : 'route -n', (err, out) => {
|
|
100
|
-
var _a, _b;
|
|
101
99
|
if (err)
|
|
102
100
|
return reject(err);
|
|
103
101
|
if (!const_1.IS_WINDOWS)
|
|
104
|
-
return resolve(
|
|
102
|
+
return resolve(out.match(const_1.IS_MAC ? /default +([\d.]+)/ : /^0\.0\.0\.0 +([\d.]+)/)?.[1]);
|
|
105
103
|
const sortedByMetric = lodash_1.default.sortBy([...out.matchAll(/(?:0\.0\.0\.0 +){2}([\d.]+)\s+[\d.]+\s+(\d+)/g)], x => Number(x[2]));
|
|
106
|
-
resolve(
|
|
104
|
+
resolve(sortedByMetric[0]?.[1]); // take ip with lowest metric
|
|
107
105
|
}));
|
|
108
106
|
}
|
package/src/outboundProxy.js
CHANGED
|
@@ -13,27 +13,27 @@ const outboundProxy = (0, config_1.defineConfig)(cross_1.CFG.outbound_proxy, '',
|
|
|
13
13
|
if (!v || process.env.HFS_SKIP_PROXY_TEST)
|
|
14
14
|
return;
|
|
15
15
|
const test = 'https://google.com';
|
|
16
|
-
|
|
16
|
+
console.debug("testing proxy using", test);
|
|
17
|
+
(0, util_http_1.httpString)(test, { noRedirect: true }).catch(e => console.error(`proxy test failed on ${test} : ${e?.errors?.[0] || e}`)); // `.errors` in case of AggregateError
|
|
17
18
|
}
|
|
18
|
-
catch
|
|
19
|
+
catch {
|
|
19
20
|
console.warn("invalid URL", v);
|
|
20
21
|
return '';
|
|
21
22
|
}
|
|
22
23
|
});
|
|
23
24
|
config_1.configReady.then(async ([startedWithoutConfig]) => {
|
|
24
|
-
var _a, _b, _c, _d;
|
|
25
25
|
if (!const_1.IS_WINDOWS || !startedWithoutConfig)
|
|
26
26
|
return;
|
|
27
27
|
// try to read Windows system setting for proxy
|
|
28
28
|
const out = await (0, util_os_1.reg)('query', 'HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings');
|
|
29
|
-
if (!Number(
|
|
29
|
+
if (!Number(/ProxyEnable\s+\w+\s+(.+)/.exec(out)?.[1]))
|
|
30
30
|
return;
|
|
31
|
-
const read =
|
|
31
|
+
const read = /ProxyServer\s+\w+\s+(.+)/.exec(out)?.[1];
|
|
32
32
|
if (!read)
|
|
33
33
|
return;
|
|
34
34
|
// it can be like "IP:PORT" or "http=IP:PORT;https=IP:PORT;ftp=IP:PORT"
|
|
35
|
-
const url = (0, cross_1.prefix)('https://',
|
|
36
|
-
|| (0, cross_1.prefix)('http://',
|
|
35
|
+
const url = (0, cross_1.prefix)('https://', /https=([\d:.]+)/.exec(out)?.[1]) // prefer https
|
|
36
|
+
|| (0, cross_1.prefix)('http://', /http=([\d:.]+)/.exec(out)?.[1])
|
|
37
37
|
|| !read.includes('=') && 'http://' + read; // simpler form
|
|
38
38
|
if (!url)
|
|
39
39
|
return;
|
package/src/perm.js
CHANGED
|
@@ -46,8 +46,7 @@ function expandUsername(who) {
|
|
|
46
46
|
}
|
|
47
47
|
// check if current username or any ancestor match the provided usernames
|
|
48
48
|
function ctxBelongsTo(ctx, usernames) {
|
|
49
|
-
|
|
50
|
-
return ((_a = ctx.state).usernames || (_a.usernames = expandUsername((0, auth_1.getCurrentUsername)(ctx)))) // cache ancestors' usernames inside context state
|
|
49
|
+
return (ctx.state.usernames ||= expandUsername((0, auth_1.getCurrentUsername)(ctx))) // cache ancestors' usernames inside context state
|
|
51
50
|
.some((u) => usernames.includes(u));
|
|
52
51
|
}
|
|
53
52
|
function getUsernames() {
|
|
@@ -78,9 +77,13 @@ async function updateAccount(account, change) {
|
|
|
78
77
|
const jsonWas = JSON.stringify(account);
|
|
79
78
|
const { username: usernameWas } = account;
|
|
80
79
|
if (typeof change === 'function')
|
|
81
|
-
await
|
|
82
|
-
else
|
|
80
|
+
await change?.(account);
|
|
81
|
+
else {
|
|
82
|
+
const u = normalizeUsername(change.username || '');
|
|
83
|
+
if (u && u !== usernameWas && getAccount(u))
|
|
84
|
+
throw "username already exists";
|
|
83
85
|
Object.assign(account, (0, misc_1.objSameKeys)(change, x => x || undefined));
|
|
86
|
+
}
|
|
84
87
|
for (const [k, v] of (0, misc_1.typedEntries)(account))
|
|
85
88
|
if (!v)
|
|
86
89
|
delete account[k]; // we consider all account fields, when falsy, as equivalent to be missing (so, default value applies)
|
|
@@ -102,7 +105,7 @@ async function updateAccount(account, change) {
|
|
|
102
105
|
if (!account.belongs.length)
|
|
103
106
|
delete account.belongs;
|
|
104
107
|
}
|
|
105
|
-
account.expire
|
|
108
|
+
account.expire &&= new Date(account.expire);
|
|
106
109
|
if (username !== usernameWas)
|
|
107
110
|
renameAccount(usernameWas, username);
|
|
108
111
|
if (jsonWas !== JSON.stringify(account)) // this test will miss the 'username' field, because hidden, but renameAccount is already calling saveAccountsASAP
|
|
@@ -114,7 +117,7 @@ exports.accounts.sub(lodash_1.default.debounce(obj => {
|
|
|
114
117
|
// consider some validation here, in case of manual edit of the config
|
|
115
118
|
lodash_1.default.each(obj, (rec, k) => {
|
|
116
119
|
const norm = normalizeUsername(k);
|
|
117
|
-
if (
|
|
120
|
+
if (rec?.username !== norm) {
|
|
118
121
|
if (!rec) // an empty object in yaml is parsed as null
|
|
119
122
|
rec = obj[norm] = { username: norm };
|
|
120
123
|
else if ((0, misc_1.objRenameKey)(obj, k, norm))
|
|
@@ -128,7 +131,6 @@ function normalizeUsername(username) {
|
|
|
128
131
|
return username.toLocaleLowerCase();
|
|
129
132
|
}
|
|
130
133
|
function renameAccount(from, to) {
|
|
131
|
-
var _a;
|
|
132
134
|
from = normalizeUsername(from);
|
|
133
135
|
const as = exports.accounts.get();
|
|
134
136
|
to = normalizeUsername(to);
|
|
@@ -140,7 +142,7 @@ function renameAccount(from, to) {
|
|
|
140
142
|
(0, misc_1.setHidden)(as[to], { username: to });
|
|
141
143
|
// update references
|
|
142
144
|
for (const a of Object.values(as)) {
|
|
143
|
-
const idx =
|
|
145
|
+
const idx = a.belongs?.indexOf(from);
|
|
144
146
|
if (idx !== undefined && idx >= 0)
|
|
145
147
|
a.belongs[idx] = to;
|
|
146
148
|
}
|
|
@@ -186,15 +188,12 @@ function accountHasPassword(account) {
|
|
|
186
188
|
return Boolean(account.password || account.srp);
|
|
187
189
|
}
|
|
188
190
|
function accountCanLogin(account) {
|
|
189
|
-
|
|
190
|
-
return (accountHasPassword(account) || ((_a = account.plugin) === null || _a === void 0 ? void 0 : _a.auth)) && !accountIsDisabled(account);
|
|
191
|
+
return (accountHasPassword(account) || account.plugin?.auth) && !accountIsDisabled(account);
|
|
191
192
|
}
|
|
192
193
|
function accountIsDisabled(account) {
|
|
193
|
-
var _a;
|
|
194
194
|
return Boolean(account.disabled
|
|
195
195
|
|| account.expire < Date.now()
|
|
196
|
-
||
|
|
197
|
-
)
|
|
196
|
+
|| account.belongs?.length // don't every() on empty array, as it returns true
|
|
198
197
|
&& account.belongs.map(u => getAccount(u, false)).every(a => a && accountIsDisabled(a)));
|
|
199
198
|
}
|
|
200
199
|
function accountCanLoginAdmin(account) {
|
package/src/persistence.js
CHANGED
|
@@ -9,7 +9,7 @@ exports.storedMap = new kvstorage_1.KvStorage({
|
|
|
9
9
|
maxPutDelay: misc_1.MINUTE,
|
|
10
10
|
maxPutDelayCreate: 1000,
|
|
11
11
|
rewriteLater: true,
|
|
12
|
-
bucketThreshold:
|
|
12
|
+
bucketThreshold: 10_000,
|
|
13
13
|
});
|
|
14
14
|
exports.storedMap.open('data.kv');
|
|
15
15
|
(0, first_1.onProcessExit)(() => exports.storedMap.flush());
|