@whyour/qinglong 2.22.0 → 2.23.0
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/back/protos/cron.proto +4 -0
- package/docs/development/node-cron-migration.md +49 -0
- package/docs/development/task-startup.md +78 -0
- package/docs/releases/2.22.0.md +8 -0
- package/docs/releases/2.23.0.md +33 -0
- package/docs/script-history.md +53 -0
- package/package.json +9 -8
- package/scripts/benchmark-script-history.cjs +39 -0
- package/scripts/publish-static.sh +34 -0
- package/scripts/sync-static.sh +20 -0
- package/scripts/wait-for-mirror.sh +214 -0
- package/shell/api.sh +56 -70
- package/shell/node_path_cache.sh +10 -2
- package/shell/otask.sh +7 -9
- package/shell/preload/sitecustomize.js +6 -2
- package/shell/preload/sitecustomize.py +4 -2
- package/shell/share.sh +1 -1
- package/shell/task-timeout.sh +63 -0
- package/shell/task.sh +8 -6
- package/shell/update.sh +40 -95
- package/shell/upgrade.cjs +8 -0
- package/static/build/api/config.js +2 -6
- package/static/build/api/env.js +15 -14
- package/static/build/api/open.js +2 -1
- package/static/build/api/script.js +155 -9
- package/static/build/api/subscription.js +3 -6
- package/static/build/api/system.js +35 -3
- package/static/build/config/grpcCerts.js +89 -40
- package/static/build/config/subscription.js +19 -11
- package/static/build/config/util.js +6 -4
- package/static/build/loaders/express.js +2 -0
- package/static/build/loaders/initData.js +20 -30
- package/static/build/loaders/initTask.js +11 -1
- package/static/build/middlewares/uniqueConstraintError.js +15 -0
- package/static/build/protos/cron.js +63 -2
- package/static/build/schedule/addCron.js +45 -63
- package/static/build/schedule/client.js +19 -1
- package/static/build/schedule/delCron.js +1 -1
- package/static/build/schedule/setConcurrency.js +27 -0
- package/static/build/services/config.js +2 -3
- package/static/build/services/cron.js +36 -10
- package/static/build/services/env.js +1 -1
- package/static/build/services/grpc.js +2 -1
- package/static/build/services/log.js +1 -1
- package/static/build/services/open.js +106 -31
- package/static/build/services/schedule.js +20 -10
- package/static/build/services/script.js +1 -1
- package/static/build/services/scriptHistory.js +30 -0
- package/static/build/services/sshKey.js +39 -14
- package/static/build/services/subscription.js +104 -53
- package/static/build/services/system.js +67 -32
- package/static/build/services/user.js +15 -10
- package/static/build/shared/cronCommand.js +17 -0
- package/static/build/shared/cronSchedule.js +101 -0
- package/static/build/shared/cronScheduler.js +73 -0
- package/static/build/shared/i18n.js +3 -2
- package/static/build/shared/logPath.js +15 -0
- package/static/build/shared/loginThrottle.js +45 -0
- package/static/build/shared/pLimit.js +19 -6
- package/static/build/shared/runCron.js +13 -4
- package/static/build/shared/scriptHistory.js +445 -0
- package/static/build/shared/shellQuote.js +11 -0
- package/static/build/shared/subscriptionMutationLock.js +34 -0
- package/static/build/shared/subscriptionPath.js +41 -0
- package/static/build/shared/subscriptionStorage.js +98 -0
- package/static/build/shared/utils.js +2 -1
- package/static/build/token.js +3 -14
- package/static/build/validation/schedule.js +3 -18
- package/static/dist/292.264757f0.async.js +1 -0
- package/static/dist/3512.95e41255.async.js +1 -0
- package/static/dist/index.html +2 -2
- package/static/dist/preload_helper.01fcd534.js +1 -0
- package/static/dist/src__pages__dependence__modal.0fa8b421.async.js +1 -0
- package/static/dist/src__pages__diff__index.b94e5dc5.async.js +1 -0
- package/static/dist/src__pages__script__editModal.afabf073.async.js +1 -0
- package/static/dist/src__pages__script__editNameModal.789ad87b.async.js +1 -0
- package/static/dist/src__pages__script__historyDrawer.8c58d958.async.js +1 -0
- package/static/dist/src__pages__script__historyDrawer.a449193a.chunk.css +1 -0
- package/static/dist/src__pages__script__index.ab360776.chunk.css +1 -0
- package/static/dist/src__pages__script__index.fc575945.async.js +1 -0
- package/static/dist/src__pages__script__saveModal.8fca1a22.async.js +1 -0
- package/static/dist/src__pages__script__saveWithHistory.99ece830.async.js +1 -0
- package/static/dist/src__pages__subscription__modal.30868ba8.async.js +1 -0
- package/static/dist/{umi.fc019050.js → umi.3a24a9fa.js} +1 -1
- package/test/back/advisory-input-security.test.cjs +416 -0
- package/test/back/code-scanning-security.test.cjs +189 -0
- package/test/back/cron-macros.test.cjs +51 -0
- package/test/back/cron-schedule-compatibility.test.cjs +69 -0
- package/test/back/cron-scheduler-routing.test.cjs +59 -0
- package/test/back/draft-path-security.test.cjs +235 -0
- package/test/back/env-import-security.test.cjs +91 -0
- package/test/back/execution-lifecycle.test.cjs +1 -1
- package/test/back/file-access-scope.test.cjs +180 -0
- package/test/back/grpc-mtls-security.test.cjs +136 -0
- package/test/back/http-security.test.cjs +105 -5
- package/test/back/legacy-cron-recovery.test.cjs +76 -0
- package/test/back/linux-mirror-result.test.cjs +176 -0
- package/test/back/listen-security.test.cjs +1 -0
- package/test/back/mirror-status.test.cjs +257 -0
- package/test/back/node-cron-migration.test.cjs +65 -0
- package/test/back/node-path-cache.test.cjs +29 -0
- package/test/back/node-path-lock.test.cjs +6 -2
- package/test/back/preload-lazy-notify.test.cjs +168 -0
- package/test/back/queued-cron-invalidation.test.cjs +98 -0
- package/test/back/restart-instance-recovery.test.cjs +116 -0
- package/test/back/scheduler-bulk-recovery.test.cjs +40 -0
- package/test/back/scheduler-concurrency.test.cjs +411 -0
- package/test/back/scheduler-reconciliation.test.cjs +58 -4
- package/test/back/script-file-access.test.cjs +210 -0
- package/test/back/script-history-api.test.cjs +551 -0
- package/test/back/script-history.test.cjs +383 -0
- package/test/back/shell-api-parsing.test.cjs +4 -4
- package/test/back/shell-translation-output.test.cjs +16 -0
- package/test/back/shell-upgrade.test.cjs +312 -0
- package/test/back/shellApiToken.test.cjs +151 -0
- package/test/back/ssh-config-home.test.cjs +113 -0
- package/test/back/static-mirror-trigger.test.cjs +441 -0
- package/test/back/static-mirror.test.cjs +179 -0
- package/test/back/stop-race.test.cjs +5 -1
- package/test/back/subscription-mutation-lock.test.cjs +83 -0
- package/test/back/subscription-review-regression.test.cjs +607 -0
- package/test/back/subscription-storage-regression.test.cjs +553 -0
- package/test/back/system-dependence-cache.test.cjs +1 -0
- package/test/back/system-export-history.test.cjs +119 -0
- package/test/back/systemTokenRenewal.test.cjs +497 -0
- package/test/back/task-shell-lifecycle.test.cjs +194 -0
- package/test/back/unique-constraint-error.test.cjs +72 -0
- package/test/back/upgrade-guards.test.cjs +285 -0
- package/test/back/upgrade-lifecycle.test.cjs +288 -0
- package/test/back/upgrade-transaction.test.cjs +133 -0
- package/test/back/user-security.test.cjs +102 -1
- package/test/back/wpush-grpc.test.cjs +1 -0
- package/test/fixtures/legacy-cron.json +1371 -0
- package/test/front/diff-file-routing.test.cjs +126 -0
- package/test/front/script-history-save.test.cjs +121 -0
- package/test/helpers/upgrade-fixture.cjs +30 -0
- package/version.yaml +14 -19
- package/static/dist/2096.6d98fd12.async.js +0 -1
- package/static/dist/4859.97d6653c.async.js +0 -1
- package/static/dist/6707.801b886b.async.js +0 -1
- package/static/dist/preload_helper.cf7de3fa.js +0 -1
- package/static/dist/src__pages__dependence__modal.a29c1a0f.async.js +0 -1
- package/static/dist/src__pages__diff__index.1714b941.async.js +0 -1
- package/static/dist/src__pages__script__editModal.22acdf7c.async.js +0 -1
- package/static/dist/src__pages__script__editNameModal.1a521cc0.async.js +0 -1
- package/static/dist/src__pages__script__index.60b6f827.chunk.css +0 -1
- package/static/dist/src__pages__script__index.a18b2692.async.js +0 -1
- package/static/dist/src__pages__script__saveModal.8965b74c.async.js +0 -1
- package/static/dist/src__pages__subscription__modal.38991e1e.async.js +0 -1
- /package/static/dist/{4859.1b962b29.chunk.css → 292.1b962b29.chunk.css} +0 -0
|
@@ -1,33 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
2
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
3
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
4
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
5
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
22
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
7
|
};
|
|
24
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
25
|
-
if (mod && mod.__esModule) return mod;
|
|
26
|
-
var result = {};
|
|
27
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
28
|
-
__setModuleDefault(result, mod);
|
|
29
|
-
return result;
|
|
30
|
-
};
|
|
31
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
32
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
33
10
|
};
|
|
@@ -45,7 +22,7 @@ const subscription_1 = require("../data/subscription");
|
|
|
45
22
|
const util_1 = require("../config/util");
|
|
46
23
|
const promises_1 = __importDefault(require("fs/promises"));
|
|
47
24
|
const sequelize_1 = require("sequelize");
|
|
48
|
-
const path_1 =
|
|
25
|
+
const path_1 = __importDefault(require("path"));
|
|
49
26
|
const schedule_1 = __importDefault(require("./schedule"));
|
|
50
27
|
const sock_1 = __importDefault(require("./sock"));
|
|
51
28
|
const i18n_1 = require("../shared/i18n");
|
|
@@ -53,6 +30,10 @@ const sshKey_1 = __importDefault(require("./sshKey"));
|
|
|
53
30
|
const const_1 = require("../config/const");
|
|
54
31
|
const subscription_2 = require("../config/subscription");
|
|
55
32
|
const cron_1 = require("../data/cron");
|
|
33
|
+
const subscriptionPath_1 = require("../shared/subscriptionPath");
|
|
34
|
+
const logPath_1 = require("../shared/logPath");
|
|
35
|
+
const subscriptionStorage_1 = require("../shared/subscriptionStorage");
|
|
36
|
+
const subscriptionMutationLock_1 = require("../shared/subscriptionMutationLock");
|
|
56
37
|
const cron_2 = __importDefault(require("./cron"));
|
|
57
38
|
const logStreamManager_1 = require("../shared/logStreamManager");
|
|
58
39
|
const logReader_1 = require("../shared/logReader");
|
|
@@ -100,8 +81,11 @@ let SubscriptionService = class SubscriptionService {
|
|
|
100
81
|
}
|
|
101
82
|
}
|
|
102
83
|
async handleTask(doc, needCreate = true, runImmediately = false) {
|
|
103
|
-
|
|
104
|
-
|
|
84
|
+
// Cancelling by ID must also work for invalid historical subscriptions.
|
|
85
|
+
if (needCreate) {
|
|
86
|
+
const { url } = (0, subscription_2.formatUrl)(doc);
|
|
87
|
+
doc.command = (0, subscription_2.formatCommand)(doc, url);
|
|
88
|
+
}
|
|
105
89
|
if (doc.schedule_type === 'crontab') {
|
|
106
90
|
this.scheduleService.cancelCronTask(doc);
|
|
107
91
|
needCreate &&
|
|
@@ -201,28 +185,49 @@ let SubscriptionService = class SubscriptionService {
|
|
|
201
185
|
};
|
|
202
186
|
}
|
|
203
187
|
async create(payload) {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
188
|
+
(0, subscriptionPath_1.assertSubscriptionAlias)(payload.alias);
|
|
189
|
+
return (0, subscriptionMutationLock_1.withSubscriptionMutation)(async () => {
|
|
190
|
+
const tab = new subscription_1.Subscription(payload);
|
|
191
|
+
const doc = await this.insert(tab);
|
|
192
|
+
await this.handleTask(doc.get({ plain: true }));
|
|
193
|
+
await this.setSshConfig();
|
|
194
|
+
return doc;
|
|
195
|
+
});
|
|
209
196
|
}
|
|
210
197
|
async insert(payload) {
|
|
211
198
|
return await subscription_1.SubscriptionModel.create(payload, { returning: true });
|
|
212
199
|
}
|
|
213
200
|
async update(payload) {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
201
|
+
(0, subscriptionPath_1.assertSubscriptionAlias)(payload.alias);
|
|
202
|
+
return (0, subscriptionMutationLock_1.withSubscriptionMutation)(async () => {
|
|
203
|
+
const doc = await this.getDb({ id: payload.id });
|
|
204
|
+
const tab = new subscription_1.Subscription(Object.assign(Object.assign({}, doc), payload));
|
|
205
|
+
const newDoc = await this.updateDb(tab);
|
|
206
|
+
await this.handleTask(newDoc, !newDoc.is_disabled);
|
|
207
|
+
await this.removeSshConfigForSubscription(doc);
|
|
208
|
+
await this.setSshConfig();
|
|
209
|
+
return newDoc;
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
async removeSshConfigForSubscription(doc) {
|
|
213
|
+
if (doc.type !== 'private-repo' || doc.pull_type !== 'ssh-key')
|
|
214
|
+
return;
|
|
215
|
+
// Invalid historical rows must remain deletable without deriving unsafe paths.
|
|
216
|
+
try {
|
|
217
|
+
(0, subscriptionPath_1.assertSubscriptionAlias)(doc.alias);
|
|
218
|
+
}
|
|
219
|
+
catch (_a) {
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
await this.sshKeyService.removeSSHKey(doc.alias, '');
|
|
220
223
|
}
|
|
221
224
|
async updateDb(payload) {
|
|
222
225
|
await subscription_1.SubscriptionModel.update(payload, { where: { id: payload.id } });
|
|
223
226
|
return await this.getDb({ id: payload.id });
|
|
224
227
|
}
|
|
225
228
|
async status({ ids, status, pid, log_path, last_running_time = 0, last_execution_time = 0, }) {
|
|
229
|
+
if (log_path)
|
|
230
|
+
(0, logPath_1.resolveLogPath)(config_1.default.logPath, log_path);
|
|
226
231
|
const options = {
|
|
227
232
|
status,
|
|
228
233
|
pid,
|
|
@@ -235,24 +240,70 @@ let SubscriptionService = class SubscriptionService {
|
|
|
235
240
|
return await subscription_1.SubscriptionModel.update(Object.assign({}, options), { where: { id: ids } });
|
|
236
241
|
}
|
|
237
242
|
async remove(ids, query) {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
243
|
+
return (0, subscriptionMutationLock_1.withSubscriptionMutation)(async () => {
|
|
244
|
+
const docs = await subscription_1.SubscriptionModel.findAll({ where: { id: ids } });
|
|
245
|
+
const storagePaths = [];
|
|
246
|
+
const retainedPaths = [];
|
|
247
|
+
const collectPaths = (doc, targets, deleting = false) => {
|
|
248
|
+
for (const names of (0, subscriptionStorage_1.getSubscriptionStorageCandidates)(doc)) {
|
|
249
|
+
// A URL accepted by one engine can produce an invalid name in another.
|
|
250
|
+
// Validate each candidate independently, retaining the safe candidate.
|
|
251
|
+
if (!Object.values(names).every(subscriptionStorage_1.isSubscriptionStorageName))
|
|
252
|
+
continue;
|
|
253
|
+
const resolve = deleting ? subscriptionStorage_1.resolveSubscriptionStoragePath : path_1.default.resolve;
|
|
254
|
+
const scriptPath = resolve(config_1.default.scriptPath, names.script);
|
|
255
|
+
if (scriptPath)
|
|
256
|
+
targets.push(scriptPath);
|
|
257
|
+
if (names.repo) {
|
|
258
|
+
const repoPath = resolve(config_1.default.repoPath, names.repo);
|
|
259
|
+
if (repoPath)
|
|
260
|
+
targets.push(repoPath);
|
|
261
|
+
}
|
|
262
|
+
if (names.raw) {
|
|
263
|
+
const rawPath = resolve(path_1.default.join(config_1.default.dataPath, 'raw'), names.raw);
|
|
264
|
+
if (rawPath)
|
|
265
|
+
targets.push(rawPath);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
// Validate all deletion targets before changing rows or removing any files.
|
|
270
|
+
if ((query === null || query === void 0 ? void 0 : query.force) === true) {
|
|
271
|
+
for (const doc of docs) {
|
|
272
|
+
(0, subscriptionPath_1.assertSubscriptionAlias)(doc.alias);
|
|
273
|
+
(0, subscriptionStorage_1.resolveSubscriptionStoragePath)(config_1.default.scriptPath, doc.alias);
|
|
274
|
+
(0, subscriptionStorage_1.resolveSubscriptionStoragePath)(config_1.default.repoPath, doc.alias);
|
|
275
|
+
collectPaths(doc, storagePaths, true);
|
|
276
|
+
}
|
|
277
|
+
const remaining = await subscription_1.SubscriptionModel.findAll({ where: {} });
|
|
278
|
+
for (const doc of remaining) {
|
|
279
|
+
if (!ids.includes(doc.id))
|
|
280
|
+
collectPaths(doc, retainedPaths);
|
|
281
|
+
}
|
|
248
282
|
}
|
|
249
283
|
for (const doc of docs) {
|
|
250
|
-
|
|
251
|
-
const repoPath = (0, path_1.join)(config_1.default.repoPath, doc.alias);
|
|
252
|
-
await (0, util_1.rmPath)(filePath);
|
|
253
|
-
await (0, util_1.rmPath)(repoPath);
|
|
284
|
+
await this.handleTask(doc.get({ plain: true }), false);
|
|
254
285
|
}
|
|
255
|
-
|
|
286
|
+
await subscription_1.SubscriptionModel.destroy({ where: { id: ids } });
|
|
287
|
+
for (const doc of docs) {
|
|
288
|
+
await this.removeSshConfigForSubscription(doc);
|
|
289
|
+
}
|
|
290
|
+
await this.setSshConfig();
|
|
291
|
+
if ((query === null || query === void 0 ? void 0 : query.force) === true) {
|
|
292
|
+
const crons = await cron_1.CrontabModel.findAll({ where: { sub_id: ids } });
|
|
293
|
+
if (crons === null || crons === void 0 ? void 0 : crons.length) {
|
|
294
|
+
await this.crontabService.remove(crons.map((x) => x.id));
|
|
295
|
+
}
|
|
296
|
+
for (const storagePath of new Set(storagePaths)) {
|
|
297
|
+
// rm is recursive: an ancestor must also be retained if a surviving
|
|
298
|
+
// subscription uses a nested branch, and vice versa.
|
|
299
|
+
const shared = retainedPaths.some((retained) => retained === storagePath ||
|
|
300
|
+
retained.startsWith(`${storagePath}${path_1.default.sep}`) ||
|
|
301
|
+
storagePath.startsWith(`${retained}${path_1.default.sep}`));
|
|
302
|
+
if (!shared)
|
|
303
|
+
await (0, util_1.rmPath)(storagePath);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
});
|
|
256
307
|
}
|
|
257
308
|
async getDb(query) {
|
|
258
309
|
const doc = await subscription_1.SubscriptionModel.findOne({ where: Object.assign({}, query) });
|
|
@@ -337,7 +388,7 @@ let SubscriptionService = class SubscriptionService {
|
|
|
337
388
|
}
|
|
338
389
|
if (doc.log_path) {
|
|
339
390
|
const relativeDir = path_1.default.dirname(`${doc.log_path}`);
|
|
340
|
-
const dir = path_1.default.
|
|
391
|
+
const dir = path_1.default.dirname((0, logPath_1.resolveLogPath)(config_1.default.logPath, doc.log_path));
|
|
341
392
|
const _exist = await (0, util_1.fileExist)(dir);
|
|
342
393
|
if (_exist) {
|
|
343
394
|
let files = await promises_1.default.readdir(dir);
|
|
@@ -27,6 +27,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
const cross_spawn_1 = require("cross-spawn");
|
|
30
|
+
const child_process_1 = require("child_process");
|
|
31
|
+
const util_1 = require("util");
|
|
32
|
+
const shellQuote_1 = require("../shared/shellQuote");
|
|
30
33
|
const fs_1 = __importDefault(require("fs"));
|
|
31
34
|
const undici_1 = require("undici");
|
|
32
35
|
const path_1 = __importDefault(require("path"));
|
|
@@ -34,17 +37,19 @@ const typedi_1 = require("typedi");
|
|
|
34
37
|
const winston_1 = __importDefault(require("winston"));
|
|
35
38
|
const config_1 = __importDefault(require("../config"));
|
|
36
39
|
const const_1 = require("../config/const");
|
|
37
|
-
const
|
|
40
|
+
const util_2 = require("../config/util");
|
|
38
41
|
const dependence_1 = require("../data/dependence");
|
|
39
42
|
const system_1 = require("../data/system");
|
|
40
43
|
const pLimit_1 = __importDefault(require("../shared/pLimit"));
|
|
44
|
+
const client_1 = __importDefault(require("../schedule/client"));
|
|
45
|
+
const schedulerMutationLock_1 = require("../shared/schedulerMutationLock");
|
|
41
46
|
const notify_1 = __importDefault(require("./notify"));
|
|
42
47
|
const schedule_1 = __importDefault(require("./schedule"));
|
|
43
48
|
const sock_1 = __importDefault(require("./sock"));
|
|
44
49
|
const os_1 = __importDefault(require("os"));
|
|
45
50
|
const dayjs_1 = __importDefault(require("dayjs"));
|
|
46
51
|
const i18n_1 = require("../shared/i18n");
|
|
47
|
-
const
|
|
52
|
+
const util_3 = require("../config/util");
|
|
48
53
|
let SystemService = class SystemService {
|
|
49
54
|
constructor(logger, scheduleService, sockService) {
|
|
50
55
|
this.logger = logger;
|
|
@@ -104,18 +109,33 @@ let SystemService = class SystemService {
|
|
|
104
109
|
return { code: 200, data: info };
|
|
105
110
|
}
|
|
106
111
|
async updateCronConcurrency(info) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
if (
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
return
|
|
112
|
+
var _a;
|
|
113
|
+
const limit = (_a = info.cronConcurrency) !== null && _a !== void 0 ? _a : 0;
|
|
114
|
+
if (!Number.isInteger(limit) || limit < 0 || limit > 2147483647) {
|
|
115
|
+
throw Object.assign(new Error((0, i18n_1.t)('参数错误')), { status: 400 });
|
|
116
|
+
}
|
|
117
|
+
return (0, schedulerMutationLock_1.withSchedulerMutation)(async () => {
|
|
118
|
+
const oDoc = await this.getSystemConfig();
|
|
119
|
+
await this.updateAuthDb(Object.assign(Object.assign({}, oDoc), { info: Object.assign(Object.assign(Object.assign({}, oDoc.info), info), { cronConcurrency: limit }) }));
|
|
120
|
+
await pLimit_1.default.setCustomLimit(limit || Math.max(os_1.default.cpus().length, 4));
|
|
121
|
+
await client_1.default.setConcurrency(limit);
|
|
122
|
+
return { code: 200, data: info };
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
async restoreCronConcurrency() {
|
|
126
|
+
await (0, schedulerMutationLock_1.withSchedulerMutation)(async () => {
|
|
127
|
+
var _a, _b;
|
|
128
|
+
const doc = await this.getSystemConfig();
|
|
129
|
+
const limit = (_b = (_a = doc.info) === null || _a === void 0 ? void 0 : _a.cronConcurrency) !== null && _b !== void 0 ? _b : 0;
|
|
130
|
+
await pLimit_1.default.setCustomLimit(limit || Math.max(os_1.default.cpus().length, 4));
|
|
131
|
+
await client_1.default.setConcurrency(limit);
|
|
132
|
+
});
|
|
113
133
|
}
|
|
114
134
|
async updateDependenceProxy(info) {
|
|
115
135
|
const oDoc = await this.getSystemConfig();
|
|
116
136
|
await this.updateAuthDb(Object.assign(Object.assign({}, oDoc), { info: Object.assign(Object.assign({}, oDoc.info), info) }));
|
|
117
137
|
if (info.dependenceProxy) {
|
|
118
|
-
await fs_1.default.promises.writeFile(config_1.default.dependenceProxyFile, `export http_proxy
|
|
138
|
+
await fs_1.default.promises.writeFile(config_1.default.dependenceProxyFile, `export http_proxy=${(0, shellQuote_1.shellQuote)(info.dependenceProxy)}\nexport https_proxy=${(0, shellQuote_1.shellQuote)(info.dependenceProxy)}`);
|
|
119
139
|
}
|
|
120
140
|
else {
|
|
121
141
|
await fs_1.default.promises.rm(config_1.default.dependenceProxyFile);
|
|
@@ -127,7 +147,7 @@ let SystemService = class SystemService {
|
|
|
127
147
|
await this.updateAuthDb(Object.assign(Object.assign({}, oDoc), { info: Object.assign(Object.assign({}, oDoc.info), info) }));
|
|
128
148
|
let cmd = 'pnpm config delete registry';
|
|
129
149
|
if (info.nodeMirror) {
|
|
130
|
-
cmd = `pnpm config set registry ${info.nodeMirror}`;
|
|
150
|
+
cmd = `pnpm config set registry ${(0, shellQuote_1.shellQuote)(info.nodeMirror)}`;
|
|
131
151
|
}
|
|
132
152
|
let command = `cd && ${cmd}`;
|
|
133
153
|
const docs = await dependence_1.DependenceModel.findAll({
|
|
@@ -168,9 +188,9 @@ let SystemService = class SystemService {
|
|
|
168
188
|
await this.updateAuthDb(Object.assign(Object.assign({}, oDoc), { info: Object.assign(Object.assign({}, oDoc.info), info) }));
|
|
169
189
|
let cmd = 'pip config unset global.index-url';
|
|
170
190
|
if (info.pythonMirror) {
|
|
171
|
-
cmd = `pip3 config set global.index-url ${info.pythonMirror}`;
|
|
191
|
+
cmd = `pip3 config set global.index-url ${(0, shellQuote_1.shellQuote)(info.pythonMirror)}`;
|
|
172
192
|
}
|
|
173
|
-
await (0,
|
|
193
|
+
await (0, util_2.promiseExec)(cmd);
|
|
174
194
|
return { code: 200, data: info };
|
|
175
195
|
}
|
|
176
196
|
async updateLinuxMirror(info, res, onEnd) {
|
|
@@ -178,26 +198,25 @@ let SystemService = class SystemService {
|
|
|
178
198
|
if (os_1.default.platform() !== 'linux') {
|
|
179
199
|
return;
|
|
180
200
|
}
|
|
181
|
-
const command = await (0,
|
|
182
|
-
let hasError = false;
|
|
201
|
+
const command = await (0, util_3.updateLinuxMirrorFile)(info.linuxMirror || '');
|
|
183
202
|
this.scheduleService.runTask(command, {
|
|
184
203
|
onStart: async (cp) => {
|
|
185
204
|
res === null || res === void 0 ? void 0 : res.setHeader('QL-Task-Pid', `${cp.pid}`);
|
|
186
205
|
res === null || res === void 0 ? void 0 : res.end();
|
|
187
206
|
},
|
|
188
|
-
onEnd: async () => {
|
|
207
|
+
onEnd: async (cp) => {
|
|
189
208
|
this.sockService.sendMessage({
|
|
190
209
|
type: 'updateLinuxMirror',
|
|
191
210
|
message: 'update linux mirror end',
|
|
192
211
|
status: 'completed',
|
|
193
212
|
});
|
|
194
213
|
onEnd === null || onEnd === void 0 ? void 0 : onEnd();
|
|
195
|
-
|
|
214
|
+
// Tools such as sudo and apt may write warnings to stderr on success.
|
|
215
|
+
if ((cp === null || cp === void 0 ? void 0 : cp.exitCode) === 0 && cp.signalCode === null) {
|
|
196
216
|
await this.updateAuthDb(Object.assign(Object.assign({}, oDoc), { info: Object.assign(Object.assign({}, oDoc.info), info) }));
|
|
197
217
|
}
|
|
198
218
|
},
|
|
199
219
|
onError: async (message) => {
|
|
200
|
-
hasError = true;
|
|
201
220
|
this.sockService.sendMessage({ type: 'updateLinuxMirror', message });
|
|
202
221
|
},
|
|
203
222
|
onLog: async (message) => {
|
|
@@ -211,7 +230,7 @@ let SystemService = class SystemService {
|
|
|
211
230
|
}
|
|
212
231
|
async checkUpdate() {
|
|
213
232
|
try {
|
|
214
|
-
const currentVersionContent = await (0,
|
|
233
|
+
const currentVersionContent = await (0, util_2.parseVersion)(config_1.default.versionFile);
|
|
215
234
|
let lastVersionContent;
|
|
216
235
|
try {
|
|
217
236
|
const { body } = await (0, undici_1.request)(`${config_1.default.lastVersionFile}?t=${Date.now()}`, {
|
|
@@ -221,7 +240,7 @@ let SystemService = class SystemService {
|
|
|
221
240
|
}),
|
|
222
241
|
});
|
|
223
242
|
const text = await body.text();
|
|
224
|
-
lastVersionContent = (0,
|
|
243
|
+
lastVersionContent = (0, util_2.parseContentVersion)(text);
|
|
225
244
|
}
|
|
226
245
|
catch (error) { }
|
|
227
246
|
if (!lastVersionContent) {
|
|
@@ -291,7 +310,10 @@ let SystemService = class SystemService {
|
|
|
291
310
|
return { code: 200 };
|
|
292
311
|
}
|
|
293
312
|
async reloadSystem(target) {
|
|
294
|
-
|
|
313
|
+
if (target && !['system', 'data'].includes(target)) {
|
|
314
|
+
return { code: 400, message: (0, i18n_1.t)('参数错误') };
|
|
315
|
+
}
|
|
316
|
+
const cmd = `real_time=true ql reload ${(0, shellQuote_1.shellQuote)(target || '')}`;
|
|
295
317
|
const cp = (0, cross_spawn_1.spawn)(cmd, {
|
|
296
318
|
shell: '/bin/bash',
|
|
297
319
|
detached: true,
|
|
@@ -334,15 +356,15 @@ let SystemService = class SystemService {
|
|
|
334
356
|
return { code: 400, message: (0, i18n_1.t)('参数错误') };
|
|
335
357
|
}
|
|
336
358
|
if (pid) {
|
|
337
|
-
await (0,
|
|
359
|
+
await (0, util_2.killTask)(pid);
|
|
338
360
|
return { code: 200 };
|
|
339
361
|
}
|
|
340
362
|
if (!command.startsWith(const_1.TASK_COMMAND)) {
|
|
341
363
|
command = `${const_1.TASK_COMMAND} ${command}`;
|
|
342
364
|
}
|
|
343
|
-
const _pid = await (0,
|
|
365
|
+
const _pid = await (0, util_2.getPid)(command);
|
|
344
366
|
if (_pid) {
|
|
345
|
-
await (0,
|
|
367
|
+
await (0, util_2.killTask)(_pid);
|
|
346
368
|
return { code: 200 };
|
|
347
369
|
}
|
|
348
370
|
else {
|
|
@@ -355,8 +377,21 @@ let SystemService = class SystemService {
|
|
|
355
377
|
if (type && type.length) {
|
|
356
378
|
dataDirs = dataDirs.concat(type.filter((x) => x !== 'base'));
|
|
357
379
|
}
|
|
358
|
-
const
|
|
359
|
-
|
|
380
|
+
const allowed = new Set(['db', 'upload', 'config', 'scripts', 'log', 'deps',
|
|
381
|
+
'syslog', 'dep_cache', 'raw', 'repo', 'ssh.d', 'script-history']);
|
|
382
|
+
if (dataDirs.some((dir) => !allowed.has(dir))) {
|
|
383
|
+
return res.status(400).send({ code: 400, message: (0, i18n_1.t)('参数错误') });
|
|
384
|
+
}
|
|
385
|
+
if (dataDirs.includes('scripts'))
|
|
386
|
+
dataDirs.push('script-history');
|
|
387
|
+
// History is created lazily; old/fresh installations must still export.
|
|
388
|
+
if (!fs_1.default.existsSync(path_1.default.join(config_1.default.dataPath, 'script-history'))) {
|
|
389
|
+
dataDirs = dataDirs.filter((dir) => dir !== 'script-history');
|
|
390
|
+
}
|
|
391
|
+
const dataPaths = [...new Set(dataDirs)].map((dir) => `data/${dir}`);
|
|
392
|
+
await (0, util_1.promisify)(child_process_1.execFile)('tar', ['-zcf', config_1.default.dataTgzFile, '--', ...dataPaths], {
|
|
393
|
+
cwd: path_1.default.dirname(config_1.default.dataPath),
|
|
394
|
+
});
|
|
360
395
|
res.download(config_1.default.dataTgzFile);
|
|
361
396
|
}
|
|
362
397
|
catch (error) {
|
|
@@ -365,8 +400,8 @@ let SystemService = class SystemService {
|
|
|
365
400
|
}
|
|
366
401
|
async importData() {
|
|
367
402
|
try {
|
|
368
|
-
await (0,
|
|
369
|
-
const res = await (0,
|
|
403
|
+
await (0, util_2.promiseExec)(`rm -rf ${path_1.default.join(config_1.default.tmpPath, 'data')}`);
|
|
404
|
+
const res = await (0, util_2.promiseExec)(`cd ${config_1.default.tmpPath} && tar -zxvf ${config_1.default.dataTgzFile}`);
|
|
370
405
|
return { code: 200, data: res };
|
|
371
406
|
}
|
|
372
407
|
catch (error) {
|
|
@@ -380,7 +415,7 @@ let SystemService = class SystemService {
|
|
|
380
415
|
const endTime = (0, dayjs_1.default)(query.endTime || undefined)
|
|
381
416
|
.endOf('d')
|
|
382
417
|
.valueOf();
|
|
383
|
-
const result = await (0,
|
|
418
|
+
const result = await (0, util_2.readDirs)(config_1.default.systemLogPath, config_1.default.systemLogPath);
|
|
384
419
|
const logs = result
|
|
385
420
|
.reverse()
|
|
386
421
|
.filter((x) => x.title.endsWith('.log'))
|
|
@@ -423,10 +458,10 @@ let SystemService = class SystemService {
|
|
|
423
458
|
})(res, selected);
|
|
424
459
|
}
|
|
425
460
|
async deleteSystemLog() {
|
|
426
|
-
const result = await (0,
|
|
461
|
+
const result = await (0, util_2.readDirs)(config_1.default.systemLogPath, config_1.default.systemLogPath);
|
|
427
462
|
const logs = result.reverse().filter((x) => x.title.endsWith('.log'));
|
|
428
463
|
for (const log of logs) {
|
|
429
|
-
await (0,
|
|
464
|
+
await (0, util_2.rmPath)(path_1.default.join(config_1.default.systemLogPath, log.title));
|
|
430
465
|
}
|
|
431
466
|
}
|
|
432
467
|
async updateTimezone(info) {
|
|
@@ -435,7 +470,7 @@ let SystemService = class SystemService {
|
|
|
435
470
|
}
|
|
436
471
|
const oDoc = await this.getSystemConfig();
|
|
437
472
|
await this.updateAuthDb(Object.assign(Object.assign({}, oDoc), { info: Object.assign(Object.assign({}, oDoc.info), info) }));
|
|
438
|
-
const success = await (0,
|
|
473
|
+
const success = await (0, util_2.setSystemTimezone)(info.timezone);
|
|
439
474
|
if (success) {
|
|
440
475
|
return { code: 200, data: info };
|
|
441
476
|
}
|
|
@@ -449,7 +484,7 @@ let SystemService = class SystemService {
|
|
|
449
484
|
await this.updateAuthDb(Object.assign(Object.assign({}, oDoc), { info: Object.assign(Object.assign({}, oDoc.info), { lang }) }));
|
|
450
485
|
// Write to standalone lang_env.sh, sourced by shell scripts
|
|
451
486
|
try {
|
|
452
|
-
await fs_1.default.promises.writeFile(config_1.default.langEnvFile, `export QL_LANG
|
|
487
|
+
await fs_1.default.promises.writeFile(config_1.default.langEnvFile, `export QL_LANG=${(0, shellQuote_1.shellQuote)(lang)}\n`);
|
|
453
488
|
}
|
|
454
489
|
catch (error) {
|
|
455
490
|
this.logger.error(`Failed to write lang_env.sh: ${error}`);
|
|
@@ -36,11 +36,13 @@ const clientIp_1 = require("../shared/clientIp");
|
|
|
36
36
|
const auth_1 = require("../shared/auth");
|
|
37
37
|
const password_1 = require("../shared/password");
|
|
38
38
|
const authMutation_1 = require("../shared/authMutation");
|
|
39
|
+
const loginThrottle_1 = require("../shared/loginThrottle");
|
|
39
40
|
let UserService = class UserService {
|
|
40
41
|
constructor(logger, scheduleService, sockService) {
|
|
41
42
|
this.logger = logger;
|
|
42
43
|
this.scheduleService = scheduleService;
|
|
43
44
|
this.sockService = sockService;
|
|
45
|
+
this.loginThrottle = new loginThrottle_1.LoginThrottle();
|
|
44
46
|
}
|
|
45
47
|
async login(payloads, req) {
|
|
46
48
|
return this.authenticate(payloads, req);
|
|
@@ -76,9 +78,8 @@ let UserService = class UserService {
|
|
|
76
78
|
this.getLoginLog();
|
|
77
79
|
return { code: 403, message: (0, i18n_1.t)('该 IP 已被列入黑名单') };
|
|
78
80
|
}
|
|
79
|
-
const
|
|
80
|
-
if (
|
|
81
|
-
const waitTime = Math.ceil((retriesTime - (timestamp - lastlogon)) / 1000);
|
|
81
|
+
const waitTime = this.loginThrottle.retryAfter(ip, timestamp);
|
|
82
|
+
if (waitTime > 0) {
|
|
82
83
|
return {
|
|
83
84
|
code: 410,
|
|
84
85
|
message: (0, i18n_1.tf)('失败次数过多,请%s秒后重试', waitTime),
|
|
@@ -97,6 +98,7 @@ let UserService = class UserService {
|
|
|
97
98
|
};
|
|
98
99
|
}
|
|
99
100
|
if (passwordMatches) {
|
|
101
|
+
this.loginThrottle.reset(ip);
|
|
100
102
|
const data = (0, util_1.createRandomString)(50, 100);
|
|
101
103
|
const expiration = twoFactorActivated ? '60d' : '20d';
|
|
102
104
|
let token = jsonwebtoken_1.default.sign({ data }, config_1.default.jwt.secret, {
|
|
@@ -161,8 +163,9 @@ let UserService = class UserService {
|
|
|
161
163
|
};
|
|
162
164
|
}
|
|
163
165
|
else {
|
|
166
|
+
const failures = this.loginThrottle.fail(ip, timestamp);
|
|
164
167
|
await this.updateAuthInfo(content, {
|
|
165
|
-
retries:
|
|
168
|
+
retries: failures,
|
|
166
169
|
lastlogon: timestamp,
|
|
167
170
|
lastip: ip,
|
|
168
171
|
lastaddr: address,
|
|
@@ -191,8 +194,8 @@ let UserService = class UserService {
|
|
|
191
194
|
},
|
|
192
195
|
});
|
|
193
196
|
this.getLoginLog();
|
|
194
|
-
if (
|
|
195
|
-
const waitTime =
|
|
197
|
+
if (failures > 3) {
|
|
198
|
+
const waitTime = this.loginThrottle.retryAfter(ip, timestamp);
|
|
196
199
|
return {
|
|
197
200
|
code: 410,
|
|
198
201
|
message: (0, i18n_1.tf)('失败次数过多,请%s秒后重试', waitTime),
|
|
@@ -334,8 +337,8 @@ let UserService = class UserService {
|
|
|
334
337
|
const authInfo = await this.getAuthInfo();
|
|
335
338
|
const { isTwoFactorChecking, twoFactorSecret } = authInfo;
|
|
336
339
|
const now = Date.now();
|
|
337
|
-
const
|
|
338
|
-
if (
|
|
340
|
+
const source = (0, clientIp_1.getClientIp)(req);
|
|
341
|
+
if (this.loginThrottle.retryAfter(source, now) > 0) {
|
|
339
342
|
return { code: 410, message: (0, i18n_1.t)('失败次数过多,请稍后重试') };
|
|
340
343
|
}
|
|
341
344
|
if (!isTwoFactorChecking ||
|
|
@@ -365,9 +368,8 @@ let UserService = class UserService {
|
|
|
365
368
|
.join(' ');
|
|
366
369
|
}
|
|
367
370
|
await this.updateAuthInfo(authInfo, {
|
|
368
|
-
retries:
|
|
371
|
+
retries: this.loginThrottle.fail(source, now),
|
|
369
372
|
lastlogon: now,
|
|
370
|
-
isTwoFactorChecking: retries + 1 < 5,
|
|
371
373
|
lastip: ip,
|
|
372
374
|
lastaddr: address,
|
|
373
375
|
platform: req.platform,
|
|
@@ -530,6 +532,9 @@ let UserService = class UserService {
|
|
|
530
532
|
});
|
|
531
533
|
}
|
|
532
534
|
await this.updateAuthInfo(authInfo, payload);
|
|
535
|
+
if (retries === 0 || password !== undefined || username !== undefined) {
|
|
536
|
+
this.loginThrottle.clear();
|
|
537
|
+
}
|
|
533
538
|
}
|
|
534
539
|
};
|
|
535
540
|
__decorate([
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findCronId = void 0;
|
|
4
|
+
// Match command text literally: looking up a task must never execute its input.
|
|
5
|
+
function findCronId(crontab, command) {
|
|
6
|
+
if (!command)
|
|
7
|
+
return '';
|
|
8
|
+
for (const line of crontab.split('\n')) {
|
|
9
|
+
const id = /\bID=(\d+)\s/.exec(line);
|
|
10
|
+
if (id && line.includes(command, id.index + id[0].length)) {
|
|
11
|
+
return id[1];
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return '';
|
|
15
|
+
}
|
|
16
|
+
exports.findCronId = findCronId;
|
|
17
|
+
//# sourceMappingURL=cronCommand.js.map
|