@whyour/qinglong 2.21.0-8 → 2.22.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/.dockerignore +13 -0
- package/.env.example +7 -0
- package/AGENTS.md +2 -2
- package/README-en.md +24 -0
- package/README.md +24 -0
- package/back/protos/api.proto +6 -1
- package/back/protos/cron.proto +4 -1
- package/docker/Dockerfile +31 -12
- package/docker/Dockerfile.310 +31 -12
- package/docker/Dockerfile.debian +22 -14
- package/docker/Dockerfile.debian310 +24 -14
- package/docker/build-manifest.cjs +28 -0
- package/docker/verify-build.cjs +49 -0
- package/docs/releases/2.22.0-validation.md +49 -0
- package/docs/releases/2.22.0.md +54 -0
- package/ecosystem.config.js +10 -1
- package/package.json +11 -6
- package/sample/config.sample.sh +10 -0
- package/sample/notify.js +54 -0
- package/sample/notify.py +37 -0
- package/scripts/benchmark-execution.cjs +96 -0
- package/scripts/write-build-info.cjs +27 -0
- package/shell/api.sh +34 -13
- package/shell/check.sh +59 -19
- package/shell/lang/en.sh +6 -0
- package/shell/lang/zh.sh +6 -0
- package/shell/node_path_cache.sh +128 -0
- package/shell/otask.sh +7 -1
- package/shell/preload/sitecustomize.js +5 -1
- package/shell/share.sh +25 -8
- package/shell/start.sh +6 -3
- package/shell/task.sh +13 -3
- package/shell/update.sh +65 -4
- package/static/build/api/clientIp.js +42 -0
- package/static/build/api/config.js +8 -16
- package/static/build/api/cron.js +38 -2
- package/static/build/api/dashboard.js +37 -0
- package/static/build/api/health.js +2 -2
- package/static/build/api/index.js +4 -0
- package/static/build/api/log.js +30 -19
- package/static/build/api/retention.js +63 -0
- package/static/build/api/script.js +23 -22
- package/static/build/api/subscription.js +16 -2
- package/static/build/api/system.js +25 -2
- package/static/build/api/user.js +75 -15
- package/static/build/app.js +54 -45
- package/static/build/bootstrap/database.js +51 -0
- package/static/build/config/const.js +1 -0
- package/static/build/config/share.js +5 -4
- package/static/build/config/util.js +133 -38
- package/static/build/data/cron.js +1 -0
- package/static/build/data/notify.js +11 -1
- package/static/build/loaders/app.js +2 -0
- package/static/build/loaders/db.js +3 -33
- package/static/build/loaders/deps.js +29 -0
- package/static/build/loaders/express.js +30 -21
- package/static/build/loaders/initData.js +10 -7
- package/static/build/loaders/sock.js +72 -6
- package/static/build/middlewares/monitoring.js +12 -33
- package/static/build/middlewares/protectedPathCase.js +17 -0
- package/static/build/protos/api.js +56 -2
- package/static/build/protos/cron.js +21 -4
- package/static/build/protos/health.js +1 -1
- package/static/build/schedule/addCron.js +9 -0
- package/static/build/schedule/api.js +5 -2
- package/static/build/schedule/client.js +38 -6
- package/static/build/schedule/health.js +72 -7
- package/static/build/services/config.js +5 -42
- package/static/build/services/cron.js +338 -199
- package/static/build/services/dependence.js +47 -0
- package/static/build/services/grpc.js +1 -1
- package/static/build/services/health.js +4 -7
- package/static/build/services/http.js +8 -2
- package/static/build/services/log.js +2 -3
- package/static/build/services/metrics.js +46 -14
- package/static/build/services/notify.js +26 -0
- package/static/build/services/retention.js +123 -0
- package/static/build/services/schedule.js +57 -33
- package/static/build/services/script.js +4 -5
- package/static/build/services/subscription.js +55 -34
- package/static/build/services/system.js +37 -9
- package/static/build/services/user.js +213 -25
- package/static/build/shared/auth.js +18 -5
- package/static/build/shared/authMutation.js +17 -0
- package/static/build/shared/childProcess.js +82 -0
- package/static/build/shared/clientIp.js +27 -0
- package/static/build/shared/errors.js +9 -0
- package/static/build/shared/fileAccess.js +60 -0
- package/static/build/shared/i18n.js +12 -5
- package/static/build/shared/logReader.js +85 -0
- package/static/build/shared/logStreamManager.js +80 -60
- package/static/build/shared/password.js +30 -0
- package/static/build/shared/retention.js +58 -0
- package/static/build/shared/runCron.js +28 -15
- package/static/build/shared/schedulerMutationLock.js +44 -0
- package/static/build/shared/schedulerReadiness.js +82 -0
- package/static/build/shared/schemaMigrations.js +58 -0
- package/static/build/shared/startupProcess.js +48 -0
- package/static/build/shared/store.js +7 -0
- package/static/build/shared/trustProxy.js +119 -0
- package/static/build/validation/schedule.js +3 -3
- package/static/dist/{1885.e1ea09f6.async.js → 1885.b8f427bf.async.js} +1 -1
- package/static/dist/2031.6af40025.async.js +1 -0
- package/static/dist/2693.51c2636b.async.js +1 -0
- package/static/dist/{2890.9e373f5b.async.js → 2890.add55e85.async.js} +1 -1
- package/static/dist/2901.2ca95295.async.js +1 -0
- package/static/dist/445.a65ff63b.async.js +1 -0
- package/static/dist/4736.1d2b5cb6.async.js +1 -0
- package/static/dist/{4859.6592cebb.async.js → 4859.97d6653c.async.js} +1 -1
- package/static/dist/{6013.4e38de36.async.js → 6013.db535339.async.js} +1 -1
- package/static/dist/6212.9e6d9913.async.js +1 -0
- package/static/dist/{6339.ab305e96.async.js → 6431.4603ad0e.async.js} +1 -1
- package/static/dist/{6872.42f939f1.async.js → 6872.a503ef55.async.js} +1 -1
- package/static/dist/7231.f7e5b668.async.js +1 -0
- package/static/dist/{7355.f9f263d8.async.js → 7355.fca746f5.async.js} +1 -1
- package/static/dist/{7508.7dcee91c.async.js → 7508.d90eac63.async.js} +1 -1
- package/static/dist/{7984.594296a5.async.js → 7984.eaac7402.async.js} +1 -1
- package/static/dist/8844.a0fef08e.async.js +1 -0
- package/static/dist/index.html +2 -2
- package/static/dist/layouts__index.633d3553.async.js +1 -0
- package/static/dist/preload_helper.cf7de3fa.js +1 -0
- package/static/dist/{src__pages__config__index.a22ff7dc.async.js → src__pages__config__index.9aba4054.async.js} +1 -1
- package/static/dist/src__pages__crontab__detail.86b2eebb.async.js +1 -0
- package/static/dist/src__pages__crontab__index.ae4e06f2.async.js +1 -0
- package/static/dist/{src__pages__crontab__logModal.831d5e4b.async.js → src__pages__crontab__logModal.930535e2.async.js} +1 -1
- package/static/dist/src__pages__crontab__modal.a2c8fdcc.async.js +1 -0
- package/static/dist/src__pages__crontab__viewCreateModal.7b4f9cbe.async.js +1 -0
- package/static/dist/src__pages__crontab__viewManageModal.cd454ea0.async.js +1 -0
- package/static/dist/src__pages__dashboard__index.243c5a35.async.js +1 -0
- package/static/dist/src__pages__dashboard__taskResultModal.7795d6e1.async.js +1 -0
- package/static/dist/src__pages__dependence__index.874d501f.async.js +1 -0
- package/static/dist/src__pages__dependence__logModal.154efe7a.async.js +1 -0
- package/static/dist/src__pages__dependence__modal.a29c1a0f.async.js +1 -0
- package/static/dist/{src__pages__diff__index.013b7c75.async.js → src__pages__diff__index.1714b941.async.js} +1 -1
- package/static/dist/src__pages__env__editNameModal.c13d47d2.async.js +1 -0
- package/static/dist/src__pages__env__index.fd6fd2b0.async.js +1 -0
- package/static/dist/src__pages__env__modal.4d71adb3.async.js +1 -0
- package/static/dist/src__pages__error__index.aae50c94.async.js +1 -0
- package/static/dist/src__pages__initialization__index.82a2e967.async.js +1 -0
- package/static/dist/src__pages__log__index.71250e0d.async.js +1 -0
- package/static/dist/{src__pages__login__index.8c813eb1.async.js → src__pages__login__index.a0fd5ed8.async.js} +1 -1
- package/static/dist/src__pages__script__editModal.22acdf7c.async.js +1 -0
- package/static/dist/src__pages__script__editNameModal.1a521cc0.async.js +1 -0
- package/static/dist/src__pages__script__index.a18b2692.async.js +1 -0
- package/static/dist/src__pages__script__renameModal.0ab029e7.async.js +1 -0
- package/static/dist/src__pages__script__saveModal.8965b74c.async.js +1 -0
- package/static/dist/src__pages__script__setting.35ad4f02.async.js +1 -0
- package/static/dist/src__pages__setting__appModal.7eaeb9d3.async.js +1 -0
- package/static/dist/{src__pages__setting__checkUpdate.34d773f2.async.js → src__pages__setting__checkUpdate.d175b154.async.js} +1 -1
- package/static/dist/src__pages__setting__clientIp.3a8711ed.async.js +1 -0
- package/static/dist/src__pages__setting__dependence.9c0f749b.async.js +1 -0
- package/static/dist/src__pages__setting__index.cb397741.async.js +1 -0
- package/static/dist/src__pages__setting__loginLog.e0a1f54d.async.js +1 -0
- package/static/dist/src__pages__setting__notification.2ffe4e5a.async.js +1 -0
- package/static/dist/src__pages__setting__other.3d0b8492.async.js +1 -0
- package/static/dist/{src__pages__setting__progress.8823ac90.async.js → src__pages__setting__progress.2ccae3d7.async.js} +1 -1
- package/static/dist/src__pages__setting__security.e2d71ebb.async.js +1 -0
- package/static/dist/src__pages__setting__systemLog.b3046955.async.js +1 -0
- package/static/dist/src__pages__subscription__index.43086a06.async.js +1 -0
- package/static/dist/src__pages__subscription__logModal.cdba5139.async.js +1 -0
- package/static/dist/src__pages__subscription__modal.38991e1e.async.js +1 -0
- package/static/dist/{umi.a54a59f6.js → umi.fc019050.js} +1 -1
- package/test/back/auth-security.test.cjs +74 -0
- package/test/back/build-provenance.test.cjs +150 -0
- package/test/back/cron-log-name.test.cjs +110 -0
- package/test/back/cron-validation.test.cjs +45 -0
- package/test/back/dashboard-failures.test.cjs +173 -0
- package/test/back/database-bootstrap.test.cjs +193 -0
- package/test/back/dependence-cache-status.test.cjs +125 -0
- package/test/back/deprecated-file-routes.test.cjs +82 -0
- package/test/back/ecosystem.test.cjs +28 -0
- package/test/back/env-name-parsing.test.cjs +96 -0
- package/test/back/execution-lifecycle.test.cjs +236 -0
- package/test/back/file-access-security.test.cjs +47 -0
- package/test/back/fileTreeListing.test.cjs +57 -0
- package/test/back/grpc-cron-response.test.cjs +60 -0
- package/test/back/http-exclusive-listen.test.cjs +31 -0
- package/test/back/http-security.test.cjs +213 -0
- package/test/back/listen-security.test.cjs +67 -0
- package/test/back/log-path-security.test.cjs +158 -0
- package/test/back/logReader.test.cjs +72 -0
- package/test/back/manual-execution.test.cjs +85 -0
- package/test/back/manual-stop-claim.test.cjs +220 -0
- package/test/back/metrics.test.cjs +34 -0
- package/test/back/monitoring.test.cjs +73 -0
- package/test/back/node-path-cache.test.cjs +173 -0
- package/test/back/node-path-lock.test.cjs +178 -0
- package/test/back/npm-publication.test.cjs +70 -0
- package/test/back/primary-apm.test.cjs +24 -0
- package/test/back/process-exit-state.test.cjs +81 -0
- package/test/back/process-stop-signal.test.cjs +77 -0
- package/test/back/protected-path-case.test.cjs +58 -0
- package/test/back/qlServiceLogCommand.test.cjs +128 -0
- package/test/back/retention.test.cjs +131 -0
- package/test/back/role-loading.test.cjs +118 -0
- package/test/back/schedule-health.test.cjs +86 -0
- package/test/back/scheduler-file-lock.test.cjs +51 -0
- package/test/back/scheduler-mutation.test.cjs +312 -0
- package/test/back/scheduler-readiness.test.cjs +85 -0
- package/test/back/scheduler-reconciliation.test.cjs +152 -0
- package/test/back/scheduler-rpc-timeout.test.cjs +49 -0
- package/test/back/schema-migrations.test.cjs +127 -0
- package/test/back/shell-api-parsing.test.cjs +184 -0
- package/test/back/sock-polling.test.cjs +297 -0
- package/test/back/sock-security.test.cjs +72 -0
- package/test/back/start-env-preservation.test.cjs +53 -0
- package/test/back/stop-failure-feedback.test.cjs +158 -0
- package/test/back/stop-race.test.cjs +167 -0
- package/test/back/subscription-cleanup.test.cjs +53 -0
- package/test/back/subscription-stop-state.test.cjs +66 -0
- package/test/back/system-dependence-cache.test.cjs +126 -0
- package/test/back/task-time.test.cjs +116 -0
- package/test/back/user-api.test.cjs +99 -0
- package/test/back/user-security.test.cjs +248 -0
- package/test/back/worker-apm.test.cjs +84 -0
- package/test/back/wpush-grpc.test.cjs +115 -0
- package/test/front/cron-log-pagination.test.cjs +214 -0
- package/test/front/http-auth.test.cjs +152 -0
- package/test/front/http-error.test.cjs +29 -0
- package/test/helpers/load-security-module.cjs +42 -0
- package/version.yaml +19 -34
- package/CLAUDE.md +0 -43
- package/static/dist/1147.62793604.async.js +0 -1
- package/static/dist/134.54df9e38.async.js +0 -1
- package/static/dist/2208.85285476.async.js +0 -1
- package/static/dist/2286.f371c743.async.js +0 -1
- package/static/dist/3191.545ab873.async.js +0 -1
- package/static/dist/4902.555f92ab.async.js +0 -1
- package/static/dist/5520.ff2cfd6b.async.js +0 -1
- package/static/dist/6431.c50479be.async.js +0 -1
- package/static/dist/8826.db34ad8d.async.js +0 -1
- package/static/dist/layouts__index.a7a2bfe0.async.js +0 -1
- package/static/dist/preload_helper.3048fe5b.js +0 -1
- package/static/dist/src__pages__crontab__detail.b98f0084.async.js +0 -1
- package/static/dist/src__pages__crontab__index.68e78a33.async.js +0 -1
- package/static/dist/src__pages__crontab__modal.f7041c7c.async.js +0 -1
- package/static/dist/src__pages__crontab__viewCreateModal.4d589f66.async.js +0 -1
- package/static/dist/src__pages__crontab__viewManageModal.0e317746.async.js +0 -1
- package/static/dist/src__pages__dashboard__index.58177357.async.js +0 -1
- package/static/dist/src__pages__dependence__index.b7bbc795.async.js +0 -1
- package/static/dist/src__pages__dependence__logModal.0681830b.async.js +0 -1
- package/static/dist/src__pages__dependence__modal.f7bb47ba.async.js +0 -1
- package/static/dist/src__pages__env__editNameModal.48715576.async.js +0 -1
- package/static/dist/src__pages__env__index.452cdc47.async.js +0 -1
- package/static/dist/src__pages__env__modal.e1234834.async.js +0 -1
- package/static/dist/src__pages__error__index.dedb2b90.async.js +0 -1
- package/static/dist/src__pages__initialization__index.22620a77.async.js +0 -1
- package/static/dist/src__pages__log__index.9c66639f.async.js +0 -1
- package/static/dist/src__pages__script__editModal.cbf4ec0e.async.js +0 -1
- package/static/dist/src__pages__script__editNameModal.532a3044.async.js +0 -1
- package/static/dist/src__pages__script__index.1fc20f22.async.js +0 -1
- package/static/dist/src__pages__script__renameModal.5cdde919.async.js +0 -1
- package/static/dist/src__pages__script__saveModal.5ffed35f.async.js +0 -1
- package/static/dist/src__pages__script__setting.1a82c6d7.async.js +0 -1
- package/static/dist/src__pages__setting__appModal.43b7758a.async.js +0 -1
- package/static/dist/src__pages__setting__dependence.9c04c79a.async.js +0 -1
- package/static/dist/src__pages__setting__index.7e070838.async.js +0 -1
- package/static/dist/src__pages__setting__loginLog.cea6056c.async.js +0 -1
- package/static/dist/src__pages__setting__notification.bac481c2.async.js +0 -1
- package/static/dist/src__pages__setting__other.707cfafe.async.js +0 -1
- package/static/dist/src__pages__setting__security.b7235753.async.js +0 -1
- package/static/dist/src__pages__setting__systemLog.b81a8c1d.async.js +0 -1
- package/static/dist/src__pages__subscription__index.d0ab2abc.async.js +0 -1
- package/static/dist/src__pages__subscription__logModal.3864b37f.async.js +0 -1
- package/static/dist/src__pages__subscription__modal.562448e2.async.js +0 -1
|
@@ -55,6 +55,7 @@ const subscription_2 = require("../config/subscription");
|
|
|
55
55
|
const cron_1 = require("../data/cron");
|
|
56
56
|
const cron_2 = __importDefault(require("./cron"));
|
|
57
57
|
const logStreamManager_1 = require("../shared/logStreamManager");
|
|
58
|
+
const logReader_1 = require("../shared/logReader");
|
|
58
59
|
let SubscriptionService = class SubscriptionService {
|
|
59
60
|
constructor(logger, scheduleService, sockService, sshKeyService, crontabService) {
|
|
60
61
|
this.logger = logger;
|
|
@@ -149,34 +150,43 @@ let SubscriptionService = class SubscriptionService {
|
|
|
149
150
|
}, { where: { id: doc.id } });
|
|
150
151
|
},
|
|
151
152
|
onEnd: async (cp, endTime, diff) => {
|
|
152
|
-
|
|
153
|
-
const absolutePath = await (0, util_1.handleLogPath)(sub.log_path);
|
|
154
|
-
// 执行 sub_after
|
|
155
|
-
let afterStr = '';
|
|
153
|
+
let absolutePath;
|
|
156
154
|
try {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
155
|
+
const sub = await this.getDb({ id: doc.id });
|
|
156
|
+
absolutePath = await (0, util_1.handleLogPath)(sub.log_path);
|
|
157
|
+
// 执行 sub_after
|
|
158
|
+
let afterStr = '';
|
|
159
|
+
try {
|
|
160
|
+
if (sub.sub_after) {
|
|
161
|
+
await logStreamManager_1.logStreamManager.write(absolutePath, `\n\n## ${(0, i18n_1.t)('执行after命令...')}\n\n`);
|
|
162
|
+
afterStr = await (0, util_1.promiseExec)(sub.sub_after);
|
|
163
|
+
}
|
|
160
164
|
}
|
|
165
|
+
catch (error) {
|
|
166
|
+
afterStr =
|
|
167
|
+
(error.stderr && error.stderr.toString()) || JSON.stringify(error);
|
|
168
|
+
}
|
|
169
|
+
if (afterStr) {
|
|
170
|
+
await logStreamManager_1.logStreamManager.write(absolutePath, `${afterStr}\n`);
|
|
171
|
+
}
|
|
172
|
+
await logStreamManager_1.logStreamManager.write(absolutePath, '\n' +
|
|
173
|
+
(0, i18n_1.tf)('## 执行结束... %s 耗时 %s 秒', endTime.format('YYYY-MM-DD HH:mm:ss'), String(diff)) +
|
|
174
|
+
const_1.LOG_END_SYMBOL);
|
|
161
175
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
176
|
+
finally {
|
|
177
|
+
try {
|
|
178
|
+
if (absolutePath)
|
|
179
|
+
await logStreamManager_1.logStreamManager.closeStream(absolutePath);
|
|
180
|
+
}
|
|
181
|
+
finally {
|
|
182
|
+
await subscription_1.SubscriptionModel.update({ status: subscription_1.SubscriptionStatus.idle, pid: null }, { where: { id: doc.id } });
|
|
183
|
+
this.sockService.sendMessage({
|
|
184
|
+
type: 'runSubscriptionEnd',
|
|
185
|
+
message: (0, i18n_1.t)('订阅执行完成'),
|
|
186
|
+
references: [doc.id],
|
|
187
|
+
});
|
|
188
|
+
}
|
|
168
189
|
}
|
|
169
|
-
await logStreamManager_1.logStreamManager.write(absolutePath, '\n' +
|
|
170
|
-
(0, i18n_1.tf)('## 执行结束... %s 耗时 %s 秒', endTime.format('YYYY-MM-DD HH:mm:ss'), String(diff)) +
|
|
171
|
-
const_1.LOG_END_SYMBOL);
|
|
172
|
-
// Close the stream after task completion
|
|
173
|
-
await logStreamManager_1.logStreamManager.closeStream(absolutePath);
|
|
174
|
-
await subscription_1.SubscriptionModel.update({ status: subscription_1.SubscriptionStatus.idle, pid: undefined }, { where: { id: sub.id } });
|
|
175
|
-
this.sockService.sendMessage({
|
|
176
|
-
type: 'runSubscriptionEnd',
|
|
177
|
-
message: (0, i18n_1.t)('订阅执行完成'),
|
|
178
|
-
references: [doc.id],
|
|
179
|
-
});
|
|
180
190
|
},
|
|
181
191
|
onError: async (message) => {
|
|
182
192
|
const sub = await this.getDb({ id: doc.id });
|
|
@@ -258,18 +268,23 @@ let SubscriptionService = class SubscriptionService {
|
|
|
258
268
|
});
|
|
259
269
|
}
|
|
260
270
|
async stop(ids) {
|
|
271
|
+
var _a;
|
|
261
272
|
const docs = await subscription_1.SubscriptionModel.findAll({ where: { id: ids } });
|
|
273
|
+
let failure;
|
|
262
274
|
for (const doc of docs) {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
await (0, util_1.killTask)(doc.pid);
|
|
266
|
-
}
|
|
267
|
-
catch (error) {
|
|
268
|
-
this.logger.error(error);
|
|
275
|
+
try {
|
|
276
|
+
if (doc.pid) {
|
|
277
|
+
await (0, util_1.killTask)(doc.pid, true);
|
|
269
278
|
}
|
|
279
|
+
await subscription_1.SubscriptionModel.update({ status: subscription_1.SubscriptionStatus.idle, pid: null }, { where: { id: doc.id, pid: (_a = doc.pid) !== null && _a !== void 0 ? _a : null } });
|
|
280
|
+
}
|
|
281
|
+
catch (error) {
|
|
282
|
+
this.logger.error(error);
|
|
283
|
+
failure !== null && failure !== void 0 ? failure : (failure = error);
|
|
270
284
|
}
|
|
271
285
|
}
|
|
272
|
-
|
|
286
|
+
if (failure)
|
|
287
|
+
throw failure;
|
|
273
288
|
}
|
|
274
289
|
async runSingle(subscriptionId) {
|
|
275
290
|
const subscription = await this.getDb({ id: subscriptionId });
|
|
@@ -301,13 +316,19 @@ let SubscriptionService = class SubscriptionService {
|
|
|
301
316
|
await this.handleTask(doc.get({ plain: true }));
|
|
302
317
|
}
|
|
303
318
|
}
|
|
304
|
-
async log(id) {
|
|
319
|
+
async log(id, options = {}) {
|
|
305
320
|
const doc = await this.getDb({ id });
|
|
306
321
|
if (!doc || !doc.log_path) {
|
|
307
|
-
return
|
|
322
|
+
return {
|
|
323
|
+
content: '',
|
|
324
|
+
offset: 0,
|
|
325
|
+
nextOffset: 0,
|
|
326
|
+
total: 0,
|
|
327
|
+
truncated: false,
|
|
328
|
+
};
|
|
308
329
|
}
|
|
309
330
|
const absolutePath = await (0, util_1.handleLogPath)(doc.log_path);
|
|
310
|
-
return await (0,
|
|
331
|
+
return await (0, logReader_1.readLogChunk)(absolutePath, options);
|
|
311
332
|
}
|
|
312
333
|
async logs(id) {
|
|
313
334
|
const doc = await this.getDb({ id });
|
|
@@ -29,7 +29,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
29
29
|
const cross_spawn_1 = require("cross-spawn");
|
|
30
30
|
const fs_1 = __importDefault(require("fs"));
|
|
31
31
|
const undici_1 = require("undici");
|
|
32
|
-
const sum_1 = __importDefault(require("lodash/sum"));
|
|
33
32
|
const path_1 = __importDefault(require("path"));
|
|
34
33
|
const typedi_1 = require("typedi");
|
|
35
34
|
const winston_1 = __importDefault(require("winston"));
|
|
@@ -386,8 +385,24 @@ let SystemService = class SystemService {
|
|
|
386
385
|
.reverse()
|
|
387
386
|
.filter((x) => x.title.endsWith('.log'))
|
|
388
387
|
.filter((x) => x.createTime >= startTime && x.createTime <= endTime);
|
|
388
|
+
const limit = Math.min(Math.max(Number(query.limit) || 1024 * 1024, 1), 1024 * 1024);
|
|
389
|
+
const total = logs.reduce((size, log) => size + (log.size || 0), 0);
|
|
390
|
+
let remaining = limit;
|
|
391
|
+
const selected = [];
|
|
392
|
+
for (let index = logs.length - 1; index >= 0 && remaining > 0; index--) {
|
|
393
|
+
const log = logs[index];
|
|
394
|
+
const size = log.size || 0;
|
|
395
|
+
const length = Math.min(size, remaining);
|
|
396
|
+
if (length > 0) {
|
|
397
|
+
selected.unshift(Object.assign(Object.assign({}, log), { start: size - length, length }));
|
|
398
|
+
remaining -= length;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
const contentLength = selected.reduce((size, log) => size + log.length, 0);
|
|
389
402
|
res.set({
|
|
390
|
-
'Content-Length':
|
|
403
|
+
'Content-Length': contentLength,
|
|
404
|
+
'X-QL-Log-Total': total,
|
|
405
|
+
'X-QL-Log-Truncated': total > contentLength ? 'true' : 'false',
|
|
391
406
|
});
|
|
392
407
|
(function sendFiles(res, fileNames) {
|
|
393
408
|
if (fileNames.length === 0) {
|
|
@@ -396,13 +411,16 @@ let SystemService = class SystemService {
|
|
|
396
411
|
}
|
|
397
412
|
const currentLog = fileNames.shift();
|
|
398
413
|
if (currentLog) {
|
|
399
|
-
const currentFileStream = fs_1.default.createReadStream(path_1.default.join(config_1.default.systemLogPath, currentLog.title)
|
|
414
|
+
const currentFileStream = fs_1.default.createReadStream(path_1.default.join(config_1.default.systemLogPath, currentLog.title), {
|
|
415
|
+
start: currentLog.start,
|
|
416
|
+
end: currentLog.start + currentLog.length - 1,
|
|
417
|
+
});
|
|
400
418
|
currentFileStream.on('end', () => {
|
|
401
419
|
sendFiles(res, fileNames);
|
|
402
420
|
});
|
|
403
421
|
currentFileStream.pipe(res, { end: false });
|
|
404
422
|
}
|
|
405
|
-
})(res,
|
|
423
|
+
})(res, selected);
|
|
406
424
|
}
|
|
407
425
|
async deleteSystemLog() {
|
|
408
426
|
const result = await (0, util_1.readDirs)(config_1.default.systemLogPath, config_1.default.systemLogPath);
|
|
@@ -439,6 +457,13 @@ let SystemService = class SystemService {
|
|
|
439
457
|
(0, i18n_1.setLang)(lang);
|
|
440
458
|
return { code: 200, data: { lang } };
|
|
441
459
|
}
|
|
460
|
+
async updatePanelTitle(info) {
|
|
461
|
+
var _a;
|
|
462
|
+
const oDoc = await this.getSystemConfig();
|
|
463
|
+
const panelTitle = ((_a = info.panelTitle) === null || _a === void 0 ? void 0 : _a.trim()) || '';
|
|
464
|
+
await this.updateAuthDb(Object.assign(Object.assign({}, oDoc), { info: Object.assign(Object.assign({}, oDoc.info), { panelTitle }) }));
|
|
465
|
+
return { code: 200, data: { panelTitle } };
|
|
466
|
+
}
|
|
442
467
|
async updateGlobalSshKey(info) {
|
|
443
468
|
const oDoc = await this.getSystemConfig();
|
|
444
469
|
const result = await this.updateAuthDb(Object.assign(Object.assign({}, oDoc), { info: Object.assign(Object.assign({}, oDoc.info), info) }));
|
|
@@ -458,11 +483,14 @@ let SystemService = class SystemService {
|
|
|
458
483
|
if (!type || !['node', 'python3'].includes(type)) {
|
|
459
484
|
return { code: 400, message: (0, i18n_1.t)('参数错误') };
|
|
460
485
|
}
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
486
|
+
const finalPath = path_1.default.join(config_1.default.dependenceCachePath, type);
|
|
487
|
+
await fs_1.default.promises.rm(finalPath, { recursive: true, force: true });
|
|
488
|
+
await dependence_1.DependenceModel.update({ status: dependence_1.DependenceStatus.installFailed }, {
|
|
489
|
+
where: {
|
|
490
|
+
type: type === 'node' ? dependence_1.DependenceTypes.nodejs : dependence_1.DependenceTypes.python3,
|
|
491
|
+
status: dependence_1.DependenceStatus.installed,
|
|
492
|
+
},
|
|
493
|
+
});
|
|
466
494
|
return { code: 200 };
|
|
467
495
|
}
|
|
468
496
|
};
|
|
@@ -27,23 +27,55 @@ const schedule_1 = __importDefault(require("./schedule"));
|
|
|
27
27
|
const sock_1 = __importDefault(require("./sock"));
|
|
28
28
|
const dayjs_1 = __importDefault(require("dayjs"));
|
|
29
29
|
const ip2region_1 = __importDefault(require("ip2region"));
|
|
30
|
-
const request_ip_1 = __importDefault(require("request-ip"));
|
|
31
30
|
const uniq_1 = __importDefault(require("lodash/uniq"));
|
|
32
31
|
const pickBy_1 = __importDefault(require("lodash/pickBy"));
|
|
33
32
|
const isNil_1 = __importDefault(require("lodash/isNil"));
|
|
34
33
|
const store_1 = require("../shared/store");
|
|
35
34
|
const i18n_1 = require("../shared/i18n");
|
|
35
|
+
const clientIp_1 = require("../shared/clientIp");
|
|
36
|
+
const auth_1 = require("../shared/auth");
|
|
37
|
+
const password_1 = require("../shared/password");
|
|
38
|
+
const authMutation_1 = require("../shared/authMutation");
|
|
36
39
|
let UserService = class UserService {
|
|
37
40
|
constructor(logger, scheduleService, sockService) {
|
|
38
41
|
this.logger = logger;
|
|
39
42
|
this.scheduleService = scheduleService;
|
|
40
43
|
this.sockService = sockService;
|
|
41
44
|
}
|
|
42
|
-
async login(payloads, req
|
|
45
|
+
async login(payloads, req) {
|
|
46
|
+
return this.authenticate(payloads, req);
|
|
47
|
+
}
|
|
48
|
+
async authenticate(payloads, req, needTwoFactor = true) {
|
|
43
49
|
let { username, password } = payloads;
|
|
44
50
|
const content = await this.getAuthInfo();
|
|
51
|
+
if ((0, auth_1.isDefaultAuthInfo)(content)) {
|
|
52
|
+
return { code: 450, message: (0, i18n_1.t)('请先初始化') };
|
|
53
|
+
}
|
|
45
54
|
const timestamp = Date.now();
|
|
46
|
-
|
|
55
|
+
const ip = (0, clientIp_1.getClientIp)(req);
|
|
56
|
+
const query = new ip2region_1.default();
|
|
57
|
+
const ipAddress = query.search(ip);
|
|
58
|
+
let address = '';
|
|
59
|
+
if (ipAddress) {
|
|
60
|
+
const { country, province, city, isp } = ipAddress;
|
|
61
|
+
address = (0, uniq_1.default)([country, province, city, isp]).filter(Boolean).join(' ');
|
|
62
|
+
}
|
|
63
|
+
let { username: cUsername, password: cPassword, retries = 0, lastlogon, lastip, lastaddr, twoFactorActivated, tokens = {}, platform, blockedIps = [], } = content;
|
|
64
|
+
if (ip &&
|
|
65
|
+
blockedIps.some((blockedIp) => (0, clientIp_1.normalizeClientIp)(blockedIp) === ip)) {
|
|
66
|
+
await this.insertDb({
|
|
67
|
+
type: system_1.AuthDataType.loginLog,
|
|
68
|
+
info: {
|
|
69
|
+
timestamp,
|
|
70
|
+
address,
|
|
71
|
+
ip,
|
|
72
|
+
platform: req.platform,
|
|
73
|
+
status: system_1.LoginStatus.fail,
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
this.getLoginLog();
|
|
77
|
+
return { code: 403, message: (0, i18n_1.t)('该 IP 已被列入黑名单') };
|
|
78
|
+
}
|
|
47
79
|
const retriesTime = Math.pow(3, retries) * 1000;
|
|
48
80
|
if (retries > 2 && timestamp - lastlogon < retriesTime) {
|
|
49
81
|
const waitTime = Math.ceil((retriesTime - (timestamp - lastlogon)) / 1000);
|
|
@@ -53,27 +85,18 @@ let UserService = class UserService {
|
|
|
53
85
|
data: waitTime,
|
|
54
86
|
};
|
|
55
87
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
twoFactorActivated &&
|
|
59
|
-
needTwoFactor) {
|
|
88
|
+
const passwordMatches = username === cUsername && (await (0, password_1.verifyPassword)(password, cPassword));
|
|
89
|
+
if (passwordMatches && twoFactorActivated && needTwoFactor) {
|
|
60
90
|
await this.updateAuthInfo(content, {
|
|
61
91
|
isTwoFactorChecking: true,
|
|
92
|
+
twoFactorExpiresAt: timestamp + 5 * 60 * 1000,
|
|
62
93
|
});
|
|
63
94
|
return {
|
|
64
95
|
code: 420,
|
|
65
96
|
message: '',
|
|
66
97
|
};
|
|
67
98
|
}
|
|
68
|
-
|
|
69
|
-
const query = new ip2region_1.default();
|
|
70
|
-
const ipAddress = query.search(ip);
|
|
71
|
-
let address = '';
|
|
72
|
-
if (ipAddress) {
|
|
73
|
-
const { country, province, city, isp } = ipAddress;
|
|
74
|
-
address = (0, uniq_1.default)([country, province, city, isp]).filter(Boolean).join(' ');
|
|
75
|
-
}
|
|
76
|
-
if (username === cUsername && password === cPassword) {
|
|
99
|
+
if (passwordMatches) {
|
|
77
100
|
const data = (0, util_1.createRandomString)(50, 100);
|
|
78
101
|
const expiration = twoFactorActivated ? '60d' : '20d';
|
|
79
102
|
let token = jsonwebtoken_1.default.sign({ data }, config_1.default.jwt.secret, {
|
|
@@ -89,6 +112,9 @@ let UserService = class UserService {
|
|
|
89
112
|
};
|
|
90
113
|
const updatedTokens = this.addTokenToList(tokens, req.platform, tokenInfo);
|
|
91
114
|
await this.updateAuthInfo(content, {
|
|
115
|
+
password: (0, password_1.isPasswordHash)(cPassword)
|
|
116
|
+
? cPassword
|
|
117
|
+
: await (0, password_1.hashPassword)(password),
|
|
92
118
|
token,
|
|
93
119
|
tokens: updatedTokens,
|
|
94
120
|
lastlogon: timestamp,
|
|
@@ -97,6 +123,7 @@ let UserService = class UserService {
|
|
|
97
123
|
lastaddr: address,
|
|
98
124
|
platform: req.platform,
|
|
99
125
|
isTwoFactorChecking: false,
|
|
126
|
+
twoFactorExpiresAt: 0,
|
|
100
127
|
});
|
|
101
128
|
this.notificationService.notify((0, i18n_1.t)('登录通知'), (0, i18n_1.t)('你于') +
|
|
102
129
|
(0, dayjs_1.default)(timestamp).format('YYYY-MM-DD HH:mm:ss') +
|
|
@@ -212,16 +239,63 @@ let UserService = class UserService {
|
|
|
212
239
|
}
|
|
213
240
|
return [];
|
|
214
241
|
}
|
|
242
|
+
async getIpBlacklist() {
|
|
243
|
+
const authInfo = await this.getAuthInfo();
|
|
244
|
+
return (0, uniq_1.default)((authInfo.blockedIps || []).map(clientIp_1.normalizeClientIp)).filter(Boolean);
|
|
245
|
+
}
|
|
246
|
+
async blockIp(ip) {
|
|
247
|
+
const authInfo = await this.getAuthInfo();
|
|
248
|
+
const blockedIps = (0, uniq_1.default)([
|
|
249
|
+
...(authInfo.blockedIps || []).map(clientIp_1.normalizeClientIp),
|
|
250
|
+
(0, clientIp_1.normalizeClientIp)(ip),
|
|
251
|
+
]).filter(Boolean);
|
|
252
|
+
await this.updateAuthInfo(authInfo, { blockedIps });
|
|
253
|
+
return blockedIps;
|
|
254
|
+
}
|
|
255
|
+
async unblockIp(ip) {
|
|
256
|
+
const authInfo = await this.getAuthInfo();
|
|
257
|
+
const normalizedIp = (0, clientIp_1.normalizeClientIp)(ip);
|
|
258
|
+
const blockedIps = (authInfo.blockedIps || [])
|
|
259
|
+
.map(clientIp_1.normalizeClientIp)
|
|
260
|
+
.filter((blockedIp) => blockedIp && blockedIp !== normalizedIp);
|
|
261
|
+
await this.updateAuthInfo(authInfo, { blockedIps });
|
|
262
|
+
return blockedIps;
|
|
263
|
+
}
|
|
215
264
|
async insertDb(payload) {
|
|
216
265
|
const doc = await system_1.SystemModel.create(Object.assign({}, payload), { returning: true });
|
|
217
266
|
return doc;
|
|
218
267
|
}
|
|
268
|
+
async initializeUser({ username, password, }) {
|
|
269
|
+
const authInfo = await this.getAuthInfo();
|
|
270
|
+
if (!(0, auth_1.isDefaultAuthInfo)(authInfo)) {
|
|
271
|
+
return { code: 450, message: (0, i18n_1.t)('未知错误') };
|
|
272
|
+
}
|
|
273
|
+
if (password === 'admin') {
|
|
274
|
+
return { code: 400, message: (0, i18n_1.t)('密码不能设置为admin') };
|
|
275
|
+
}
|
|
276
|
+
await this.updateAuthInfo(authInfo, {
|
|
277
|
+
username,
|
|
278
|
+
password: await (0, password_1.hashPassword)(password),
|
|
279
|
+
token: '',
|
|
280
|
+
tokens: {},
|
|
281
|
+
isTwoFactorChecking: false,
|
|
282
|
+
twoFactorExpiresAt: 0,
|
|
283
|
+
});
|
|
284
|
+
return { code: 200, message: (0, i18n_1.t)('更新成功') };
|
|
285
|
+
}
|
|
219
286
|
async updateUsernameAndPassword({ username, password, }) {
|
|
220
287
|
if (password === 'admin') {
|
|
221
288
|
return { code: 400, message: (0, i18n_1.t)('密码不能设置为admin') };
|
|
222
289
|
}
|
|
223
290
|
const authInfo = await this.getAuthInfo();
|
|
224
|
-
await this.updateAuthInfo(authInfo, {
|
|
291
|
+
await this.updateAuthInfo(authInfo, {
|
|
292
|
+
username,
|
|
293
|
+
password: await (0, password_1.hashPassword)(password),
|
|
294
|
+
token: '',
|
|
295
|
+
tokens: {},
|
|
296
|
+
isTwoFactorChecking: false,
|
|
297
|
+
twoFactorExpiresAt: 0,
|
|
298
|
+
});
|
|
225
299
|
return { code: 200, message: (0, i18n_1.t)('更新成功') };
|
|
226
300
|
}
|
|
227
301
|
async updateAvatar(avatar) {
|
|
@@ -232,6 +306,9 @@ let UserService = class UserService {
|
|
|
232
306
|
async initTwoFactor() {
|
|
233
307
|
const secret = preset_default_1.authenticator.generateSecret();
|
|
234
308
|
const authInfo = await this.getAuthInfo();
|
|
309
|
+
if (authInfo.twoFactorActivated) {
|
|
310
|
+
throw new Error((0, i18n_1.t)('请先关闭两步验证'));
|
|
311
|
+
}
|
|
235
312
|
const otpauth = preset_default_1.authenticator.keyuri(authInfo.username, 'qinglong', secret);
|
|
236
313
|
await this.updateAuthInfo(authInfo, { twoFactorSecret: secret });
|
|
237
314
|
return { secret, url: otpauth };
|
|
@@ -243,25 +320,41 @@ let UserService = class UserService {
|
|
|
243
320
|
secret: authInfo.twoFactorSecret,
|
|
244
321
|
});
|
|
245
322
|
if (isValid) {
|
|
246
|
-
await this.updateAuthInfo(authInfo, {
|
|
323
|
+
await this.updateAuthInfo(authInfo, {
|
|
324
|
+
twoFactorActivated: true,
|
|
325
|
+
token: '',
|
|
326
|
+
tokens: {},
|
|
327
|
+
isTwoFactorChecking: false,
|
|
328
|
+
twoFactorExpiresAt: 0,
|
|
329
|
+
});
|
|
247
330
|
}
|
|
248
331
|
return isValid;
|
|
249
332
|
}
|
|
250
333
|
async twoFactorLogin({ username, password, code, }, req) {
|
|
251
334
|
const authInfo = await this.getAuthInfo();
|
|
252
335
|
const { isTwoFactorChecking, twoFactorSecret } = authInfo;
|
|
253
|
-
|
|
336
|
+
const now = Date.now();
|
|
337
|
+
const retries = authInfo.retries || 0;
|
|
338
|
+
if (retries > 2 && now - authInfo.lastlogon < Math.pow(3, retries) * 1000) {
|
|
339
|
+
return { code: 410, message: (0, i18n_1.t)('失败次数过多,请稍后重试') };
|
|
340
|
+
}
|
|
341
|
+
if (!isTwoFactorChecking ||
|
|
342
|
+
!authInfo.twoFactorActivated ||
|
|
343
|
+
!authInfo.twoFactorExpiresAt ||
|
|
344
|
+
authInfo.twoFactorExpiresAt <= now) {
|
|
254
345
|
return { code: 450, message: (0, i18n_1.t)('未知错误') };
|
|
255
346
|
}
|
|
256
|
-
const
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
347
|
+
const step = Math.floor(now / 30000);
|
|
348
|
+
const isValid = username === authInfo.username &&
|
|
349
|
+
(await (0, password_1.verifyPassword)(password, authInfo.password)) &&
|
|
350
|
+
authInfo.lastTwoFactorStep !== step &&
|
|
351
|
+
preset_default_1.authenticator.verify({ token: code, secret: twoFactorSecret });
|
|
260
352
|
if (isValid) {
|
|
261
|
-
|
|
353
|
+
await this.updateAuthInfo(authInfo, { lastTwoFactorStep: step });
|
|
354
|
+
return this.authenticate({ username, password }, req, false);
|
|
262
355
|
}
|
|
263
356
|
else {
|
|
264
|
-
const ip =
|
|
357
|
+
const ip = (0, clientIp_1.getClientIp)(req);
|
|
265
358
|
const query = new ip2region_1.default();
|
|
266
359
|
const ipAddress = query.search(ip);
|
|
267
360
|
let address = '';
|
|
@@ -272,6 +365,9 @@ let UserService = class UserService {
|
|
|
272
365
|
.join(' ');
|
|
273
366
|
}
|
|
274
367
|
await this.updateAuthInfo(authInfo, {
|
|
368
|
+
retries: retries + 1,
|
|
369
|
+
lastlogon: now,
|
|
370
|
+
isTwoFactorChecking: retries + 1 < 5,
|
|
275
371
|
lastip: ip,
|
|
276
372
|
lastaddr: address,
|
|
277
373
|
platform: req.platform,
|
|
@@ -284,6 +380,10 @@ let UserService = class UserService {
|
|
|
284
380
|
await this.updateAuthInfo(authInfo, {
|
|
285
381
|
twoFactorActivated: false,
|
|
286
382
|
twoFactorSecret: '',
|
|
383
|
+
token: '',
|
|
384
|
+
tokens: {},
|
|
385
|
+
isTwoFactorChecking: false,
|
|
386
|
+
twoFactorExpiresAt: 0,
|
|
287
387
|
});
|
|
288
388
|
return true;
|
|
289
389
|
}
|
|
@@ -302,6 +402,9 @@ let UserService = class UserService {
|
|
|
302
402
|
type: system_1.AuthDataType.authConfig,
|
|
303
403
|
info: result,
|
|
304
404
|
});
|
|
405
|
+
if (info.tokens && Object.keys(info.tokens).length === 0) {
|
|
406
|
+
this.sockService.getClients().forEach((conn) => conn.close('401'));
|
|
407
|
+
}
|
|
305
408
|
}
|
|
306
409
|
async getNotificationMode() {
|
|
307
410
|
const doc = await this.getDb({ type: system_1.AuthDataType.notification });
|
|
@@ -413,6 +516,19 @@ let UserService = class UserService {
|
|
|
413
516
|
password,
|
|
414
517
|
username,
|
|
415
518
|
}, (x) => !(0, isNil_1.default)(x));
|
|
519
|
+
if (password !== undefined) {
|
|
520
|
+
payload.password = await (0, password_1.hashPassword)(password);
|
|
521
|
+
}
|
|
522
|
+
if (password !== undefined ||
|
|
523
|
+
username !== undefined ||
|
|
524
|
+
twoFactorActivated !== undefined) {
|
|
525
|
+
Object.assign(payload, {
|
|
526
|
+
token: '',
|
|
527
|
+
tokens: {},
|
|
528
|
+
isTwoFactorChecking: false,
|
|
529
|
+
twoFactorExpiresAt: 0,
|
|
530
|
+
});
|
|
531
|
+
}
|
|
416
532
|
await this.updateAuthInfo(authInfo, payload);
|
|
417
533
|
}
|
|
418
534
|
};
|
|
@@ -420,6 +536,78 @@ __decorate([
|
|
|
420
536
|
(0, typedi_1.Inject)((type) => notify_1.default),
|
|
421
537
|
__metadata("design:type", notify_1.default)
|
|
422
538
|
], UserService.prototype, "notificationService", void 0);
|
|
539
|
+
__decorate([
|
|
540
|
+
authMutation_1.serializeAuthMutation,
|
|
541
|
+
__metadata("design:type", Function),
|
|
542
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
543
|
+
__metadata("design:returntype", Promise)
|
|
544
|
+
], UserService.prototype, "login", null);
|
|
545
|
+
__decorate([
|
|
546
|
+
authMutation_1.serializeAuthMutation,
|
|
547
|
+
__metadata("design:type", Function),
|
|
548
|
+
__metadata("design:paramtypes", [String, String]),
|
|
549
|
+
__metadata("design:returntype", Promise)
|
|
550
|
+
], UserService.prototype, "logout", null);
|
|
551
|
+
__decorate([
|
|
552
|
+
authMutation_1.serializeAuthMutation,
|
|
553
|
+
__metadata("design:type", Function),
|
|
554
|
+
__metadata("design:paramtypes", [String]),
|
|
555
|
+
__metadata("design:returntype", Promise)
|
|
556
|
+
], UserService.prototype, "blockIp", null);
|
|
557
|
+
__decorate([
|
|
558
|
+
authMutation_1.serializeAuthMutation,
|
|
559
|
+
__metadata("design:type", Function),
|
|
560
|
+
__metadata("design:paramtypes", [String]),
|
|
561
|
+
__metadata("design:returntype", Promise)
|
|
562
|
+
], UserService.prototype, "unblockIp", null);
|
|
563
|
+
__decorate([
|
|
564
|
+
authMutation_1.serializeAuthMutation,
|
|
565
|
+
__metadata("design:type", Function),
|
|
566
|
+
__metadata("design:paramtypes", [Object]),
|
|
567
|
+
__metadata("design:returntype", Promise)
|
|
568
|
+
], UserService.prototype, "initializeUser", null);
|
|
569
|
+
__decorate([
|
|
570
|
+
authMutation_1.serializeAuthMutation,
|
|
571
|
+
__metadata("design:type", Function),
|
|
572
|
+
__metadata("design:paramtypes", [Object]),
|
|
573
|
+
__metadata("design:returntype", Promise)
|
|
574
|
+
], UserService.prototype, "updateUsernameAndPassword", null);
|
|
575
|
+
__decorate([
|
|
576
|
+
authMutation_1.serializeAuthMutation,
|
|
577
|
+
__metadata("design:type", Function),
|
|
578
|
+
__metadata("design:paramtypes", [String]),
|
|
579
|
+
__metadata("design:returntype", Promise)
|
|
580
|
+
], UserService.prototype, "updateAvatar", null);
|
|
581
|
+
__decorate([
|
|
582
|
+
authMutation_1.serializeAuthMutation,
|
|
583
|
+
__metadata("design:type", Function),
|
|
584
|
+
__metadata("design:paramtypes", []),
|
|
585
|
+
__metadata("design:returntype", Promise)
|
|
586
|
+
], UserService.prototype, "initTwoFactor", null);
|
|
587
|
+
__decorate([
|
|
588
|
+
authMutation_1.serializeAuthMutation,
|
|
589
|
+
__metadata("design:type", Function),
|
|
590
|
+
__metadata("design:paramtypes", [String]),
|
|
591
|
+
__metadata("design:returntype", Promise)
|
|
592
|
+
], UserService.prototype, "activeTwoFactor", null);
|
|
593
|
+
__decorate([
|
|
594
|
+
authMutation_1.serializeAuthMutation,
|
|
595
|
+
__metadata("design:type", Function),
|
|
596
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
597
|
+
__metadata("design:returntype", Promise)
|
|
598
|
+
], UserService.prototype, "twoFactorLogin", null);
|
|
599
|
+
__decorate([
|
|
600
|
+
authMutation_1.serializeAuthMutation,
|
|
601
|
+
__metadata("design:type", Function),
|
|
602
|
+
__metadata("design:paramtypes", []),
|
|
603
|
+
__metadata("design:returntype", Promise)
|
|
604
|
+
], UserService.prototype, "deactivateTwoFactor", null);
|
|
605
|
+
__decorate([
|
|
606
|
+
authMutation_1.serializeAuthMutation,
|
|
607
|
+
__metadata("design:type", Function),
|
|
608
|
+
__metadata("design:paramtypes", [Object]),
|
|
609
|
+
__metadata("design:returntype", Promise)
|
|
610
|
+
], UserService.prototype, "resetAuthInfo", null);
|
|
423
611
|
UserService = __decorate([
|
|
424
612
|
(0, typedi_1.Service)(),
|
|
425
613
|
__param(0, (0, typedi_1.Inject)('logger')),
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.isValidToken = exports.isDefaultAuthInfo = void 0;
|
|
7
|
+
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
4
8
|
function isDefaultAuthInfo(authInfo) {
|
|
5
|
-
return
|
|
6
|
-
authInfo.username === 'admin' &&
|
|
7
|
-
authInfo.password === 'admin');
|
|
9
|
+
return authInfo.username === 'admin' && authInfo.password === 'admin';
|
|
8
10
|
}
|
|
9
11
|
exports.isDefaultAuthInfo = isDefaultAuthInfo;
|
|
10
12
|
/**
|
|
@@ -16,10 +18,19 @@ exports.isDefaultAuthInfo = isDefaultAuthInfo;
|
|
|
16
18
|
* @param platform - The platform (desktop, mobile)
|
|
17
19
|
* @returns true if the token is valid, false otherwise
|
|
18
20
|
*/
|
|
19
|
-
function isValidToken(authInfo, headerToken, platform) {
|
|
21
|
+
function isValidToken(authInfo, headerToken, platform, secret) {
|
|
20
22
|
if (!authInfo || !headerToken) {
|
|
21
23
|
return false;
|
|
22
24
|
}
|
|
25
|
+
try {
|
|
26
|
+
const claims = jsonwebtoken_1.default.verify(headerToken, secret, { algorithms: ['HS384'] });
|
|
27
|
+
if (typeof claims === 'string' || typeof claims.exp !== 'number') {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
catch (_a) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
23
34
|
const { token = '', tokens = {} } = authInfo;
|
|
24
35
|
// Check legacy token field
|
|
25
36
|
if (headerToken === token) {
|
|
@@ -37,7 +48,9 @@ function isValidToken(authInfo, headerToken, platform) {
|
|
|
37
48
|
}
|
|
38
49
|
else if (Array.isArray(platformTokens)) {
|
|
39
50
|
// New format: array of TokenInfo objects
|
|
40
|
-
return platformTokens.some((t) => t &&
|
|
51
|
+
return platformTokens.some((t) => t &&
|
|
52
|
+
t.value === headerToken &&
|
|
53
|
+
(t.expiration === undefined || t.expiration > Date.now() / 1000));
|
|
41
54
|
}
|
|
42
55
|
// Unexpected type - log warning and reject
|
|
43
56
|
return false;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serializeAuthMutation = void 0;
|
|
4
|
+
// All account mutations in the HTTP service share one queue. In particular,
|
|
5
|
+
// a login that read old credentials must finish before a password reset revokes
|
|
6
|
+
// its session, and two initialization requests must not both claim the account.
|
|
7
|
+
let pending = Promise.resolve();
|
|
8
|
+
function serializeAuthMutation(_target, _key, descriptor) {
|
|
9
|
+
const method = descriptor.value;
|
|
10
|
+
descriptor.value = function (...args) {
|
|
11
|
+
const result = pending.then(() => method.apply(this, args));
|
|
12
|
+
pending = result.catch(() => undefined);
|
|
13
|
+
return result;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
exports.serializeAuthMutation = serializeAuthMutation;
|
|
17
|
+
//# sourceMappingURL=authMutation.js.map
|