@whyour/qinglong 2.21.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/.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 +9 -1
- package/back/protos/cron.proto +8 -1
- package/deploy/kubernetes/README.md +81 -0
- package/deploy/kubernetes/base/kustomization.yaml +5 -0
- package/deploy/kubernetes/base/qinglong.yaml +95 -0
- package/deploy/kubernetes/overlays/example/kustomization.yaml +10 -0
- 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/development/node-cron-migration.md +49 -0
- package/docs/development/task-startup.md +78 -0
- package/docs/releases/2.22.0-validation.md +49 -0
- package/docs/releases/2.22.0.md +62 -0
- package/docs/releases/2.23.0.md +33 -0
- package/docs/script-history.md +53 -0
- package/ecosystem.config.js +10 -1
- package/package.json +19 -13
- package/sample/config.sample.sh +17 -2
- package/sample/notify.js +118 -0
- package/sample/notify.py +93 -0
- package/scripts/benchmark-execution.cjs +96 -0
- 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/scripts/write-build-info.cjs +27 -0
- package/shell/api.sh +96 -83
- 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 +136 -0
- package/shell/otask.sh +17 -10
- package/shell/preload/sitecustomize.js +11 -3
- package/shell/preload/sitecustomize.py +4 -2
- package/shell/share.sh +27 -10
- package/shell/start.sh +6 -3
- package/shell/task-timeout.sh +63 -0
- package/shell/task.sh +21 -9
- package/shell/update.sh +104 -98
- package/shell/upgrade.cjs +8 -0
- package/static/build/api/clientIp.js +42 -0
- package/static/build/api/config.js +9 -21
- package/static/build/api/cron.js +39 -3
- package/static/build/api/dashboard.js +50 -6
- package/static/build/api/env.js +17 -16
- package/static/build/api/health.js +2 -2
- package/static/build/api/index.js +4 -0
- package/static/build/api/log.js +39 -19
- package/static/build/api/open.js +2 -1
- package/static/build/api/retention.js +63 -0
- package/static/build/api/script.js +172 -25
- package/static/build/api/subscription.js +19 -8
- package/static/build/api/system.js +66 -12
- package/static/build/api/user.js +75 -15
- package/static/build/app.js +63 -54
- package/static/build/bootstrap/database.js +51 -0
- package/static/build/config/const.js +2 -0
- package/static/build/config/grpcCerts.js +93 -44
- package/static/build/config/index.js +0 -4
- package/static/build/config/share.js +5 -4
- package/static/build/config/subscription.js +19 -11
- package/static/build/config/util.js +142 -45
- package/static/build/data/cron.js +1 -0
- package/static/build/data/notify.js +18 -1
- package/static/build/data/sock.js +1 -0
- package/static/build/loaders/app.js +8 -6
- package/static/build/loaders/db.js +5 -35
- package/static/build/loaders/deps.js +30 -22
- package/static/build/loaders/express.js +46 -32
- package/static/build/loaders/initData.js +26 -33
- package/static/build/loaders/initFile.js +1 -1
- package/static/build/loaders/initTask.js +14 -3
- package/static/build/loaders/server.js +1 -1
- 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/middlewares/uniqueConstraintError.js +15 -0
- package/static/build/protos/api.js +78 -2
- package/static/build/protos/cron.js +83 -5
- package/static/build/protos/health.js +1 -1
- package/static/build/schedule/addCron.js +67 -19
- package/static/build/schedule/api.js +5 -2
- package/static/build/schedule/client.js +56 -6
- package/static/build/schedule/delCron.js +11 -1
- package/static/build/schedule/health.js +72 -7
- package/static/build/schedule/setConcurrency.js +27 -0
- package/static/build/services/config.js +5 -43
- package/static/build/services/cron.js +389 -174
- package/static/build/services/dependence.js +66 -18
- package/static/build/services/env.js +1 -1
- package/static/build/services/grpc.js +4 -3
- package/static/build/services/health.js +4 -7
- package/static/build/services/http.js +9 -3
- package/static/build/services/log.js +2 -3
- package/static/build/services/metrics.js +46 -14
- package/static/build/services/notify.js +73 -5
- package/static/build/services/open.js +106 -31
- package/static/build/services/retention.js +123 -0
- package/static/build/services/schedule.js +77 -43
- package/static/build/services/script.js +4 -5
- package/static/build/services/scriptHistory.js +30 -0
- package/static/build/services/sshKey.js +39 -14
- package/static/build/services/subscription.js +161 -87
- package/static/build/services/system.js +116 -43
- package/static/build/services/user.js +255 -37
- package/static/build/shared/auth.js +22 -3
- 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/cronCommand.js +17 -0
- package/static/build/shared/cronSchedule.js +101 -0
- package/static/build/shared/cronScheduler.js +73 -0
- package/static/build/shared/errors.js +9 -0
- package/static/build/shared/fileAccess.js +60 -0
- package/static/build/shared/i18n.js +63 -4
- package/static/build/shared/logPath.js +15 -0
- package/static/build/shared/logReader.js +85 -0
- package/static/build/shared/logStreamManager.js +80 -60
- package/static/build/shared/loginThrottle.js +45 -0
- package/static/build/shared/pLimit.js +22 -8
- package/static/build/shared/password.js +30 -0
- package/static/build/shared/retention.js +58 -0
- package/static/build/shared/runCron.js +39 -17
- 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/scriptHistory.js +445 -0
- package/static/build/shared/shellQuote.js +11 -0
- package/static/build/shared/startupProcess.js +48 -0
- package/static/build/shared/store.js +7 -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/trustProxy.js +119 -0
- package/static/build/shared/utils.js +2 -1
- package/static/build/token.js +3 -14
- package/static/build/validation/schedule.js +6 -12
- 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/292.264757f0.async.js +1 -0
- package/static/dist/3512.95e41255.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/{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.01fcd534.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.0b8cce8c.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.0fa8b421.async.js +1 -0
- package/static/dist/src__pages__diff__index.b94e5dc5.async.js +1 -0
- 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.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__renameModal.0ab029e7.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__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.d175b154.async.js +1 -0
- 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.30868ba8.async.js +1 -0
- package/static/dist/{umi.ca04a019.js → umi.3a24a9fa.js} +1 -1
- package/test/back/advisory-input-security.test.cjs +416 -0
- package/test/back/auth-security.test.cjs +74 -0
- package/test/back/build-provenance.test.cjs +150 -0
- package/test/back/code-scanning-security.test.cjs +189 -0
- package/test/back/cron-log-name.test.cjs +110 -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/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/draft-path-security.test.cjs +235 -0
- package/test/back/ecosystem.test.cjs +28 -0
- package/test/back/env-import-security.test.cjs +91 -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-scope.test.cjs +180 -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/grpc-mtls-security.test.cjs +136 -0
- package/test/back/http-exclusive-listen.test.cjs +31 -0
- package/test/back/http-security.test.cjs +313 -0
- 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 +68 -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/mirror-status.test.cjs +257 -0
- package/test/back/monitoring.test.cjs +73 -0
- package/test/back/node-cron-migration.test.cjs +65 -0
- package/test/back/node-path-cache.test.cjs +202 -0
- package/test/back/node-path-lock.test.cjs +182 -0
- package/test/back/npm-publication.test.cjs +70 -0
- package/test/back/preload-lazy-notify.test.cjs +168 -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/queued-cron-invalidation.test.cjs +98 -0
- package/test/back/restart-instance-recovery.test.cjs +116 -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-bulk-recovery.test.cjs +40 -0
- package/test/back/scheduler-concurrency.test.cjs +411 -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 +206 -0
- package/test/back/scheduler-rpc-timeout.test.cjs +49 -0
- package/test/back/schema-migrations.test.cjs +127 -0
- 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 +184 -0
- 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/sock-polling.test.cjs +297 -0
- package/test/back/sock-security.test.cjs +72 -0
- package/test/back/ssh-config-home.test.cjs +113 -0
- package/test/back/start-env-preservation.test.cjs +53 -0
- package/test/back/static-mirror-trigger.test.cjs +441 -0
- package/test/back/static-mirror.test.cjs +179 -0
- package/test/back/stop-failure-feedback.test.cjs +158 -0
- package/test/back/stop-race.test.cjs +171 -0
- package/test/back/subscription-cleanup.test.cjs +53 -0
- package/test/back/subscription-mutation-lock.test.cjs +83 -0
- package/test/back/subscription-review-regression.test.cjs +607 -0
- package/test/back/subscription-stop-state.test.cjs +66 -0
- package/test/back/subscription-storage-regression.test.cjs +553 -0
- package/test/back/system-dependence-cache.test.cjs +127 -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/task-time.test.cjs +116 -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-api.test.cjs +99 -0
- package/test/back/user-security.test.cjs +349 -0
- package/test/back/worker-apm.test.cjs +84 -0
- package/test/back/wpush-grpc.test.cjs +116 -0
- package/test/fixtures/legacy-cron.json +1371 -0
- package/test/front/cron-log-pagination.test.cjs +214 -0
- package/test/front/diff-file-routing.test.cjs +126 -0
- package/test/front/http-auth.test.cjs +152 -0
- package/test/front/http-error.test.cjs +29 -0
- package/test/front/script-history-save.test.cjs +121 -0
- package/test/helpers/load-security-module.cjs +42 -0
- package/test/helpers/upgrade-fixture.cjs +30 -0
- package/version.yaml +14 -34
- package/CLAUDE.md +0 -43
- package/static/dist/1147.c420132e.async.js +0 -1
- package/static/dist/134.54df9e38.async.js +0 -1
- package/static/dist/2096.6d98fd12.async.js +0 -1
- package/static/dist/2208.f7ba3dfa.async.js +0 -1
- package/static/dist/2286.164bb089.async.js +0 -1
- package/static/dist/3191.63263871.async.js +0 -1
- package/static/dist/4859.6592cebb.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/6707.801b886b.async.js +0 -1
- package/static/dist/8826.2447a104.async.js +0 -1
- package/static/dist/layouts__index.a7a2bfe0.async.js +0 -1
- package/static/dist/preload_helper.0431c0f3.js +0 -1
- package/static/dist/src__pages__crontab__detail.b9c36808.async.js +0 -1
- package/static/dist/src__pages__crontab__index.fed99fd0.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.b30f2f47.async.js +0 -1
- package/static/dist/src__pages__dependence__index.3d87ceac.async.js +0 -1
- package/static/dist/src__pages__dependence__logModal.0681830b.async.js +0 -1
- package/static/dist/src__pages__dependence__modal.11124896.async.js +0 -1
- package/static/dist/src__pages__diff__index.013b7c75.async.js +0 -1
- package/static/dist/src__pages__env__editNameModal.5d264b25.async.js +0 -1
- package/static/dist/src__pages__env__index.baa27d4e.async.js +0 -1
- package/static/dist/src__pages__env__modal.7f2ef1bc.async.js +0 -1
- package/static/dist/src__pages__error__index.f156b45e.async.js +0 -1
- package/static/dist/src__pages__initialization__index.e96d4ba8.async.js +0 -1
- package/static/dist/src__pages__log__index.e0978bae.async.js +0 -1
- package/static/dist/src__pages__script__editModal.cbf4ec0e.async.js +0 -1
- package/static/dist/src__pages__script__editNameModal.3e7e100d.async.js +0 -1
- package/static/dist/src__pages__script__index.2765d1b8.async.js +0 -1
- package/static/dist/src__pages__script__index.60b6f827.chunk.css +0 -1
- package/static/dist/src__pages__script__renameModal.5e987ef5.async.js +0 -1
- package/static/dist/src__pages__script__saveModal.3f9d23d6.async.js +0 -1
- package/static/dist/src__pages__script__setting.a535793a.async.js +0 -1
- package/static/dist/src__pages__setting__appModal.251cd14f.async.js +0 -1
- package/static/dist/src__pages__setting__checkUpdate.46efe057.async.js +0 -1
- package/static/dist/src__pages__setting__dependence.8a7a9529.async.js +0 -1
- package/static/dist/src__pages__setting__index.cc85fdfb.async.js +0 -1
- package/static/dist/src__pages__setting__loginLog.cea6056c.async.js +0 -1
- package/static/dist/src__pages__setting__notification.390fc905.async.js +0 -1
- package/static/dist/src__pages__setting__other.b22d2165.async.js +0 -1
- package/static/dist/src__pages__setting__security.598720a8.async.js +0 -1
- package/static/dist/src__pages__setting__systemLog.67406721.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.3562c670.async.js +0 -1
- /package/static/dist/{4859.1b962b29.chunk.css → 292.1b962b29.chunk.css} +0 -0
|
@@ -23,22 +23,68 @@ const uuid_1 = require("uuid");
|
|
|
23
23
|
const sequelize_1 = require("sequelize");
|
|
24
24
|
const store_1 = require("../shared/store");
|
|
25
25
|
const i18n_1 = require("../shared/i18n");
|
|
26
|
+
const proper_lockfile_1 = require("proper-lockfile");
|
|
27
|
+
const path_1 = __importDefault(require("path"));
|
|
28
|
+
const os_1 = __importDefault(require("os"));
|
|
29
|
+
const promises_1 = require("fs/promises");
|
|
30
|
+
const config_1 = __importDefault(require("../config"));
|
|
26
31
|
let OpenService = class OpenService {
|
|
27
32
|
constructor(logger) {
|
|
28
33
|
this.logger = logger;
|
|
29
34
|
}
|
|
35
|
+
// Every database mutation and full authentication-cache publication shares
|
|
36
|
+
// this cross-process lock. Lock a separate marker, not token.json itself.
|
|
37
|
+
async withAppsLock(operation) {
|
|
38
|
+
const target = path_1.default.join(config_1.default.configPath, '.apps-state');
|
|
39
|
+
const release = await (0, proper_lockfile_1.lock)(target, {
|
|
40
|
+
realpath: false,
|
|
41
|
+
stale: 10000,
|
|
42
|
+
retries: { retries: 10, factor: 2, minTimeout: 100, maxTimeout: 3000 },
|
|
43
|
+
});
|
|
44
|
+
try {
|
|
45
|
+
return await operation();
|
|
46
|
+
}
|
|
47
|
+
finally {
|
|
48
|
+
await release();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async initializeSystemApp() {
|
|
52
|
+
await this.withAppsLock(async () => {
|
|
53
|
+
const doc = await open_1.AppModel.findOne({ where: { name: 'system' } });
|
|
54
|
+
const app = doc === null || doc === void 0 ? void 0 : doc.get({ plain: true });
|
|
55
|
+
if (!app) {
|
|
56
|
+
await this.insert({
|
|
57
|
+
name: 'system',
|
|
58
|
+
scopes: ['crons', 'system', 'dashboard'],
|
|
59
|
+
client_id: (0, util_1.createRandomString)(12, 12),
|
|
60
|
+
client_secret: (0, util_1.createRandomString)(24, 24),
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
else if (!app.scopes.includes('dashboard')) {
|
|
64
|
+
await open_1.AppModel.update({ scopes: [...app.scopes, 'dashboard'] }, { where: { id: app.id } });
|
|
65
|
+
}
|
|
66
|
+
await store_1.shareStore.updateApps(await this.find({}));
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
async refreshApps() {
|
|
70
|
+
await this.withAppsLock(async () => {
|
|
71
|
+
await store_1.shareStore.updateApps(await this.find({}));
|
|
72
|
+
});
|
|
73
|
+
}
|
|
30
74
|
async findApps() {
|
|
31
75
|
const docs = await this.find({});
|
|
32
76
|
return docs;
|
|
33
77
|
}
|
|
34
78
|
async create(payload) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
79
|
+
return this.withAppsLock(async () => {
|
|
80
|
+
const tab = Object.assign({}, payload);
|
|
81
|
+
tab.client_id = (0, util_1.createRandomString)(12, 12);
|
|
82
|
+
tab.client_secret = (0, util_1.createRandomString)(24, 24);
|
|
83
|
+
const doc = await this.insert(tab);
|
|
84
|
+
const apps = await this.find({});
|
|
85
|
+
await store_1.shareStore.updateApps(apps);
|
|
86
|
+
return Object.assign(Object.assign({}, doc), { tokens: [] });
|
|
87
|
+
});
|
|
42
88
|
}
|
|
43
89
|
async insert(payload) {
|
|
44
90
|
const doc = await open_1.AppModel.create(payload, { returning: true });
|
|
@@ -53,10 +99,12 @@ let OpenService = class OpenService {
|
|
|
53
99
|
return Object.assign(Object.assign({}, newDoc), { tokens: [] });
|
|
54
100
|
}
|
|
55
101
|
async updateDb(payload) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
102
|
+
return this.withAppsLock(async () => {
|
|
103
|
+
await open_1.AppModel.update(payload, { where: { id: payload.id } });
|
|
104
|
+
const apps = await this.find({});
|
|
105
|
+
await store_1.shareStore.updateApps(apps);
|
|
106
|
+
return apps === null || apps === void 0 ? void 0 : apps.find((x) => x.id === payload.id);
|
|
107
|
+
});
|
|
60
108
|
}
|
|
61
109
|
async getDb(query) {
|
|
62
110
|
const doc = await open_1.AppModel.findOne({ where: query });
|
|
@@ -66,9 +114,11 @@ let OpenService = class OpenService {
|
|
|
66
114
|
return doc.get({ plain: true });
|
|
67
115
|
}
|
|
68
116
|
async remove(ids) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
117
|
+
return this.withAppsLock(async () => {
|
|
118
|
+
await open_1.AppModel.destroy({ where: { id: ids } });
|
|
119
|
+
const apps = await this.find({});
|
|
120
|
+
await store_1.shareStore.updateApps(apps);
|
|
121
|
+
});
|
|
72
122
|
}
|
|
73
123
|
async resetSecret(id) {
|
|
74
124
|
const tab = {
|
|
@@ -111,7 +161,11 @@ let OpenService = class OpenService {
|
|
|
111
161
|
const docs = await open_1.AppModel.findAll({ where: Object.assign({}, query) });
|
|
112
162
|
return docs.map((x) => x.get({ plain: true }));
|
|
113
163
|
}
|
|
114
|
-
async authToken(
|
|
164
|
+
async authToken(credentials) {
|
|
165
|
+
return this.withAppsLock(() => this.issueToken(credentials));
|
|
166
|
+
}
|
|
167
|
+
// Caller holds withAppsLock through database update and cache publication.
|
|
168
|
+
async issueToken({ client_id, client_secret, }) {
|
|
115
169
|
let token = (0, uuid_1.v4)();
|
|
116
170
|
const expiration = Math.round(Date.now() / 1000) + 2592000; // 2592000 30天
|
|
117
171
|
const doc = await open_1.AppModel.findOne({ where: { client_id, client_secret } });
|
|
@@ -145,23 +199,44 @@ let OpenService = class OpenService {
|
|
|
145
199
|
return { code: 400, message: (0, i18n_1.t)('client_id 或 client_seret 有误') };
|
|
146
200
|
}
|
|
147
201
|
}
|
|
148
|
-
async generateSystemToken() {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
202
|
+
async generateSystemToken(renew = false) {
|
|
203
|
+
return this.withAppsLock(async () => {
|
|
204
|
+
var _a;
|
|
205
|
+
// Read after acquiring the lock; a concurrent issuer may have renewed.
|
|
206
|
+
const systemApp = await this.getDb({ name: 'system' });
|
|
207
|
+
const now = Math.round(Date.now() / 1000);
|
|
208
|
+
let appToken = (_a = systemApp.tokens) === null || _a === void 0 ? void 0 : _a.filter((token) => token.expiration > now).sort((left, right) => right.expiration - left.expiration)[0];
|
|
209
|
+
if (renew || !appToken) {
|
|
210
|
+
const { data } = await this.issueToken({
|
|
211
|
+
client_id: systemApp.client_id,
|
|
212
|
+
client_secret: systemApp.client_secret,
|
|
213
|
+
});
|
|
214
|
+
appToken = { value: data.token, expiration: data.expiration };
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
// Recover a prior database commit whose cache publication failed.
|
|
218
|
+
await store_1.shareStore.updateApps(await this.find({}));
|
|
219
|
+
}
|
|
220
|
+
const tokenFile = path_1.default.join(config_1.default.configPath, 'token.json');
|
|
221
|
+
const temporaryFile = `${tokenFile}.${process.pid}.tmp`;
|
|
222
|
+
const mode = await (0, promises_1.stat)(tokenFile).then((file) => file.mode & 0o777, (error) => {
|
|
223
|
+
if (error.code === 'ENOENT')
|
|
224
|
+
return 0o600;
|
|
225
|
+
throw error;
|
|
226
|
+
});
|
|
227
|
+
try {
|
|
228
|
+
await (0, promises_1.writeFile)(temporaryFile, `${JSON.stringify(appToken)}${os_1.default.EOL}`, {
|
|
229
|
+
mode,
|
|
230
|
+
});
|
|
231
|
+
await (0, promises_1.chmod)(temporaryFile, mode);
|
|
232
|
+
// Shell readers see a complete old or new document, never a partial one.
|
|
233
|
+
await (0, promises_1.rename)(temporaryFile, tokenFile);
|
|
234
|
+
}
|
|
235
|
+
finally {
|
|
236
|
+
await (0, promises_1.rm)(temporaryFile, { force: true });
|
|
237
|
+
}
|
|
238
|
+
return appToken;
|
|
163
239
|
});
|
|
164
|
-
return Object.assign(Object.assign({}, data), { value: data.token });
|
|
165
240
|
}
|
|
166
241
|
};
|
|
167
242
|
OpenService = __decorate([
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
13
|
+
const path_1 = __importDefault(require("path"));
|
|
14
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
15
|
+
const sequelize_1 = require("sequelize");
|
|
16
|
+
const typedi_1 = require("typedi");
|
|
17
|
+
const config_1 = __importDefault(require("../config"));
|
|
18
|
+
const cronStats_1 = require("../data/cronStats");
|
|
19
|
+
const data_1 = require("../data");
|
|
20
|
+
const runningInstance_1 = require("../data/runningInstance");
|
|
21
|
+
const system_1 = require("../data/system");
|
|
22
|
+
const retention_1 = require("../shared/retention");
|
|
23
|
+
function runningInstanceWhere(days) {
|
|
24
|
+
const cutoff = (0, dayjs_1.default)().subtract(days, 'day').unix();
|
|
25
|
+
return {
|
|
26
|
+
status: { [sequelize_1.Op.ne]: runningInstance_1.InstanceStatus.running },
|
|
27
|
+
[sequelize_1.Op.or]: [
|
|
28
|
+
{ finished_at: { [sequelize_1.Op.lt]: cutoff } },
|
|
29
|
+
{
|
|
30
|
+
finished_at: { [sequelize_1.Op.is]: null },
|
|
31
|
+
started_at: { [sequelize_1.Op.lt]: cutoff },
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function cronStatWhere(days) {
|
|
37
|
+
return {
|
|
38
|
+
date: { [sequelize_1.Op.lt]: (0, dayjs_1.default)().subtract(days, 'day').format('YYYY-MM-DD') },
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
let RetentionService = class RetentionService {
|
|
42
|
+
async updatePolicy(policy) {
|
|
43
|
+
const normalized = (0, retention_1.normalizeRetentionPolicy)(policy);
|
|
44
|
+
const systemConfig = await system_1.SystemModel.findOne({
|
|
45
|
+
where: { type: system_1.AuthDataType.systemConfig },
|
|
46
|
+
});
|
|
47
|
+
if (!systemConfig) {
|
|
48
|
+
throw new Error('System config not found');
|
|
49
|
+
}
|
|
50
|
+
await system_1.SystemModel.update({
|
|
51
|
+
info: Object.assign(Object.assign({}, systemConfig.info), normalized),
|
|
52
|
+
}, { where: { id: systemConfig.id } });
|
|
53
|
+
return normalized;
|
|
54
|
+
}
|
|
55
|
+
async preview(request) {
|
|
56
|
+
const policy = (0, retention_1.normalizeRetentionPolicy)(request);
|
|
57
|
+
const dependenceCacheTypes = (request.dependenceCacheTypes || []).filter(retention_1.isDependenceCacheType);
|
|
58
|
+
const [runningInstances, cronStats, dependenceCaches] = await Promise.all([
|
|
59
|
+
policy.runningInstanceRetentionDays > 0
|
|
60
|
+
? runningInstance_1.RunningInstanceModel.count({
|
|
61
|
+
where: runningInstanceWhere(policy.runningInstanceRetentionDays),
|
|
62
|
+
})
|
|
63
|
+
: 0,
|
|
64
|
+
policy.cronStatRetentionDays > 0
|
|
65
|
+
? cronStats_1.CrontabStatModel.count({
|
|
66
|
+
where: cronStatWhere(policy.cronStatRetentionDays),
|
|
67
|
+
})
|
|
68
|
+
: 0,
|
|
69
|
+
Promise.all(dependenceCacheTypes.map(async (type) => ({
|
|
70
|
+
type,
|
|
71
|
+
bytes: await (0, retention_1.getDirectorySize)(path_1.default.join(config_1.default.dependenceCachePath, type)),
|
|
72
|
+
}))),
|
|
73
|
+
]);
|
|
74
|
+
return {
|
|
75
|
+
policy,
|
|
76
|
+
runningInstances,
|
|
77
|
+
cronStats,
|
|
78
|
+
dependenceCaches,
|
|
79
|
+
dependenceCacheBytes: dependenceCaches.reduce((total, cache) => total + cache.bytes, 0),
|
|
80
|
+
compactDatabase: Boolean(request.compactDatabase),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
async cleanup(request) {
|
|
84
|
+
const preview = await this.preview(request);
|
|
85
|
+
const deleted = await data_1.sequelize.transaction(async (transaction) => {
|
|
86
|
+
const runningInstances = preview.policy.runningInstanceRetentionDays > 0
|
|
87
|
+
? await runningInstance_1.RunningInstanceModel.destroy({
|
|
88
|
+
where: runningInstanceWhere(preview.policy.runningInstanceRetentionDays),
|
|
89
|
+
transaction,
|
|
90
|
+
})
|
|
91
|
+
: 0;
|
|
92
|
+
const cronStats = preview.policy.cronStatRetentionDays > 0
|
|
93
|
+
? await cronStats_1.CrontabStatModel.destroy({
|
|
94
|
+
where: cronStatWhere(preview.policy.cronStatRetentionDays),
|
|
95
|
+
transaction,
|
|
96
|
+
})
|
|
97
|
+
: 0;
|
|
98
|
+
return { runningInstances, cronStats };
|
|
99
|
+
});
|
|
100
|
+
const dependenceCaches = [];
|
|
101
|
+
for (const cache of preview.dependenceCaches) {
|
|
102
|
+
await promises_1.default.rm(path_1.default.join(config_1.default.dependenceCachePath, cache.type), {
|
|
103
|
+
recursive: true,
|
|
104
|
+
force: true,
|
|
105
|
+
});
|
|
106
|
+
dependenceCaches.push(cache);
|
|
107
|
+
}
|
|
108
|
+
if (request.compactDatabase &&
|
|
109
|
+
(deleted.runningInstances || deleted.cronStats)) {
|
|
110
|
+
await data_1.sequelize.query('VACUUM');
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
deleted: Object.assign(Object.assign({}, deleted), { dependenceCaches, dependenceCacheBytes: preview.dependenceCacheBytes }),
|
|
114
|
+
compactedDatabase: Boolean(request.compactDatabase &&
|
|
115
|
+
(deleted.runningInstances || deleted.cronStats)),
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
RetentionService = __decorate([
|
|
120
|
+
(0, typedi_1.Service)()
|
|
121
|
+
], RetentionService);
|
|
122
|
+
exports.default = RetentionService;
|
|
123
|
+
//# sourceMappingURL=retention.js.map
|
|
@@ -28,11 +28,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
const typedi_1 = require("typedi");
|
|
30
30
|
const winston_1 = __importDefault(require("winston"));
|
|
31
|
-
const
|
|
31
|
+
const cronScheduler_1 = require("../shared/cronScheduler");
|
|
32
32
|
const toad_scheduler_1 = require("toad-scheduler");
|
|
33
33
|
const dayjs_1 = __importDefault(require("dayjs"));
|
|
34
34
|
const pLimit_1 = __importDefault(require("../shared/pLimit"));
|
|
35
35
|
const cross_spawn_1 = require("cross-spawn");
|
|
36
|
+
const childProcess_1 = require("../shared/childProcess");
|
|
36
37
|
let ScheduleService = class ScheduleService {
|
|
37
38
|
constructor(logger) {
|
|
38
39
|
this.logger = logger;
|
|
@@ -46,57 +47,90 @@ let ScheduleService = class ScheduleService {
|
|
|
46
47
|
}
|
|
47
48
|
async runTask(command, callbacks = {}, params, completionTime = 'end') {
|
|
48
49
|
const { runOrigin } = params, others = __rest(params, ["runOrigin"]);
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
var _a;
|
|
70
|
-
this.logger.error('[panel][创建任务失败] 命令: %s, 错误信息: %j', command, err);
|
|
71
|
-
await ((_a = callbacks.onError) === null || _a === void 0 ? void 0 : _a.call(callbacks, JSON.stringify(err)));
|
|
72
|
-
});
|
|
73
|
-
cp.on('exit', async (code) => {
|
|
50
|
+
let resolveStart;
|
|
51
|
+
let rejectStart;
|
|
52
|
+
const startResult = new Promise((resolve, reject) => {
|
|
53
|
+
resolveStart = resolve;
|
|
54
|
+
rejectStart = reject;
|
|
55
|
+
});
|
|
56
|
+
// Most scheduled callers only observe completion (or intentionally detach).
|
|
57
|
+
void startResult.catch(() => { });
|
|
58
|
+
const completion = pLimit_1.default[this.taskLimitMap[runOrigin]](others, async () => {
|
|
59
|
+
var _a, _b, _c, _d;
|
|
60
|
+
const startTime = (0, dayjs_1.default)();
|
|
61
|
+
let cp;
|
|
62
|
+
let result = { code: null, signal: null };
|
|
63
|
+
try {
|
|
64
|
+
this.logger.info('[panel][开始执行任务] 任务ID: %s', others.id);
|
|
65
|
+
await ((_a = callbacks.onBefore) === null || _a === void 0 ? void 0 : _a.call(callbacks, startTime));
|
|
66
|
+
cp = (0, cross_spawn_1.spawn)(command, { shell: '/bin/bash' });
|
|
67
|
+
const child = cp;
|
|
68
|
+
const observed = (0, childProcess_1.observeChildProcess)(child, {
|
|
69
|
+
onStart: async () => {
|
|
74
70
|
var _a;
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
71
|
+
await ((_a = callbacks.onStart) === null || _a === void 0 ? void 0 : _a.call(callbacks, child, startTime));
|
|
72
|
+
},
|
|
73
|
+
onStdout: callbacks.onLog,
|
|
74
|
+
onStderr: callbacks.onError,
|
|
75
|
+
});
|
|
76
|
+
observed.started.then(resolveStart, rejectStart);
|
|
77
|
+
result = await observed.completed;
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
result.error = (0, childProcess_1.asError)(error);
|
|
81
|
+
rejectStart(result.error);
|
|
82
|
+
}
|
|
83
|
+
if (result.error) {
|
|
84
|
+
this.logger.error('[panel][执行任务失败] 任务ID: %s, 错误: %s', others.id, result.error.message);
|
|
85
|
+
try {
|
|
86
|
+
await ((_b = callbacks.onError) === null || _b === void 0 ? void 0 : _b.call(callbacks, result.error.message));
|
|
80
87
|
}
|
|
81
88
|
catch (error) {
|
|
82
|
-
this.logger.error('[panel][
|
|
83
|
-
await ((_c = callbacks.onError) === null || _c === void 0 ? void 0 : _c.call(callbacks, JSON.stringify(error)));
|
|
89
|
+
this.logger.error('[panel][任务错误回调失败] %s', (0, childProcess_1.asError)(error).message);
|
|
84
90
|
}
|
|
85
|
-
}
|
|
91
|
+
}
|
|
92
|
+
// Cleanup also runs after setup/spawn failure, and only after both pipes drain.
|
|
93
|
+
const endTime = (0, dayjs_1.default)();
|
|
94
|
+
try {
|
|
95
|
+
await ((_c = callbacks.onEnd) === null || _c === void 0 ? void 0 : _c.call(callbacks, cp, endTime, endTime.diff(startTime, 'seconds')));
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
(_d = result.error) !== null && _d !== void 0 ? _d : (result.error = (0, childProcess_1.asError)(error));
|
|
99
|
+
this.logger.error('[panel][任务结束回调失败] %s', (0, childProcess_1.asError)(error).message);
|
|
100
|
+
}
|
|
101
|
+
this.logger.info('[panel][执行任务结束] 任务ID: %s, 退出码: %j', others.id, result.code);
|
|
102
|
+
return Object.assign(Object.assign(Object.assign({}, others), { pid: cp === null || cp === void 0 ? void 0 : cp.pid }), result);
|
|
103
|
+
}).catch((error) => {
|
|
104
|
+
// Queue/setup failures must not become unhandled rejections in detached callers.
|
|
105
|
+
rejectStart((0, childProcess_1.asError)(error));
|
|
106
|
+
this.logger.error('[panel][任务队列失败] %s', (0, childProcess_1.asError)(error).message);
|
|
107
|
+
return Object.assign(Object.assign({}, others), { code: null, signal: null, error: (0, childProcess_1.asError)(error) });
|
|
86
108
|
});
|
|
109
|
+
// Returning a PID must not release the execution slot while the process runs.
|
|
110
|
+
return completionTime === 'start' ? startResult : completion;
|
|
87
111
|
}
|
|
88
112
|
async createCronTask({ id = 0, command, name, schedule = '', runOrigin }, callbacks, runImmediately = false) {
|
|
113
|
+
var _a;
|
|
89
114
|
const _id = this.formatId(id);
|
|
90
115
|
this.logger.info('[panel][创建cron任务] 任务ID: %s, cron: %s, 任务名: %s, 执行命令: %s', _id, schedule, name, command);
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
116
|
+
if (schedule) {
|
|
117
|
+
try {
|
|
118
|
+
const job = (0, cronScheduler_1.createCronJob)(schedule, () => this.runTask(command, callbacks, {
|
|
119
|
+
name,
|
|
120
|
+
schedule,
|
|
121
|
+
command,
|
|
122
|
+
id: _id,
|
|
123
|
+
runOrigin,
|
|
124
|
+
}), { name: `${_id}: ${name || ''}`, logger: this.logger, start: false });
|
|
125
|
+
(_a = this.scheduleStacks.get(_id)) === null || _a === void 0 ? void 0 : _a.cancel();
|
|
126
|
+
this.scheduleStacks.set(_id, job);
|
|
127
|
+
job.start();
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
// A persisted invalid subscription must not become an unhandled startup rejection.
|
|
131
|
+
this.logger.warn('[panel][跳过无效定时任务] 任务ID: %s, cron: %s, 错误: %s', _id, schedule, (0, childProcess_1.asError)(error).message);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
100
134
|
if (runImmediately) {
|
|
101
135
|
this.runTask(command, callbacks, {
|
|
102
136
|
name,
|
|
@@ -15,6 +15,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
15
15
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
16
16
|
};
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
const fileAccess_1 = require("../shared/fileAccess");
|
|
18
19
|
const typedi_1 = require("typedi");
|
|
19
20
|
const winston_1 = __importDefault(require("winston"));
|
|
20
21
|
const path_1 = __importDefault(require("path"));
|
|
@@ -63,15 +64,13 @@ let ScriptService = class ScriptService {
|
|
|
63
64
|
pLimit_1.default.removeQueuedCron(relativePath.replace(/ /g, '-'));
|
|
64
65
|
pid = (await (0, util_1.getPid)(`${const_1.TASK_COMMAND} ${relativePath} now`));
|
|
65
66
|
}
|
|
66
|
-
|
|
67
|
-
await (0, util_1.killTask)(pid);
|
|
67
|
+
if (pid) {
|
|
68
|
+
await (0, util_1.killTask)(pid, true);
|
|
68
69
|
}
|
|
69
|
-
catch (error) { }
|
|
70
70
|
return { code: 200 };
|
|
71
71
|
}
|
|
72
72
|
checkFilePath(filePath, fileName) {
|
|
73
|
-
|
|
74
|
-
return finalPath.startsWith(config_1.default.scriptPath) ? finalPath : '';
|
|
73
|
+
return (0, fileAccess_1.resolveFileAccess)(config_1.default.scriptPath, [filePath || '', fileName]);
|
|
75
74
|
}
|
|
76
75
|
async getFile(filePath, fileName) {
|
|
77
76
|
const finalPath = this.checkFilePath(filePath, fileName);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const path_1 = __importDefault(require("path"));
|
|
16
|
+
const typedi_1 = require("typedi");
|
|
17
|
+
const config_1 = __importDefault(require("../config"));
|
|
18
|
+
const scriptHistory_1 = require("../shared/scriptHistory");
|
|
19
|
+
/** Panel configuration and lifecycle; the storage core stays independently testable. */
|
|
20
|
+
let ScriptHistoryService = class ScriptHistoryService extends scriptHistory_1.ScriptHistory {
|
|
21
|
+
constructor() {
|
|
22
|
+
super(config_1.default.scriptPath, path_1.default.join(config_1.default.dataPath, 'script-history'));
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
ScriptHistoryService = __decorate([
|
|
26
|
+
(0, typedi_1.Service)(),
|
|
27
|
+
__metadata("design:paramtypes", [])
|
|
28
|
+
], ScriptHistoryService);
|
|
29
|
+
exports.default = ScriptHistoryService;
|
|
30
|
+
//# sourceMappingURL=scriptHistory.js.map
|
|
@@ -24,16 +24,30 @@ const subscription_1 = require("../config/subscription");
|
|
|
24
24
|
const config_1 = __importDefault(require("../config"));
|
|
25
25
|
const util_1 = require("../config/util");
|
|
26
26
|
const utils_1 = require("../shared/utils");
|
|
27
|
+
const subscriptionPath_1 = require("../shared/subscriptionPath");
|
|
27
28
|
let SshKeyService = class SshKeyService {
|
|
29
|
+
// OpenSSH uses the effective user's passwd entry, not the HOME override.
|
|
30
|
+
get homedir() {
|
|
31
|
+
try {
|
|
32
|
+
return os_1.default.userInfo().homedir;
|
|
33
|
+
}
|
|
34
|
+
catch (_a) {
|
|
35
|
+
// Custom container UIDs may have no passwd entry. Keep startup working.
|
|
36
|
+
return os_1.default.homedir();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
28
39
|
constructor(logger) {
|
|
29
40
|
this.logger = logger;
|
|
30
|
-
this.homedir = os_1.default.homedir();
|
|
31
41
|
this.sshPath = config_1.default.sshdPath;
|
|
32
42
|
this.sshConfigFilePath = path_1.default.resolve(this.homedir, '.ssh', 'config');
|
|
33
43
|
this.sshConfigHeader = `Include ${path_1.default.join(this.sshPath, '*.config')}`;
|
|
34
44
|
this.initSshConfigFile();
|
|
35
45
|
}
|
|
36
46
|
async initSshConfigFile() {
|
|
47
|
+
await promises_1.default.mkdir(path_1.default.dirname(this.sshConfigFilePath), {
|
|
48
|
+
recursive: true,
|
|
49
|
+
mode: 0o700,
|
|
50
|
+
});
|
|
37
51
|
let config = '';
|
|
38
52
|
const _exist = await (0, util_1.fileExist)(this.sshConfigFilePath);
|
|
39
53
|
if (_exist) {
|
|
@@ -48,7 +62,7 @@ let SshKeyService = class SshKeyService {
|
|
|
48
62
|
}
|
|
49
63
|
async generatePrivateKeyFile(alias, key) {
|
|
50
64
|
try {
|
|
51
|
-
const filePath =
|
|
65
|
+
const filePath = (0, subscriptionPath_1.resolveSubscriptionPath)(this.sshPath, alias);
|
|
52
66
|
try {
|
|
53
67
|
await (0, util_1.rmPath)(filePath);
|
|
54
68
|
}
|
|
@@ -61,7 +75,7 @@ let SshKeyService = class SshKeyService {
|
|
|
61
75
|
}
|
|
62
76
|
async removePrivateKeyFile(alias) {
|
|
63
77
|
try {
|
|
64
|
-
const filePath =
|
|
78
|
+
const filePath = (0, subscriptionPath_1.resolveSubscriptionPath)(this.sshPath, alias);
|
|
65
79
|
await (0, util_1.rmPath)(filePath);
|
|
66
80
|
}
|
|
67
81
|
catch (error) {
|
|
@@ -69,21 +83,25 @@ let SshKeyService = class SshKeyService {
|
|
|
69
83
|
}
|
|
70
84
|
}
|
|
71
85
|
async generateSingleSshConfig(alias, host, proxy) {
|
|
86
|
+
if (!/^[a-zA-Z0-9.-]+$/.test(host) ||
|
|
87
|
+
(proxy && !/^[a-zA-Z0-9.:[\]-]+$/.test(proxy))) {
|
|
88
|
+
throw Object.assign(new Error('Invalid SSH host or proxy'), { status: 400 });
|
|
89
|
+
}
|
|
72
90
|
if (host === 'github.com') {
|
|
73
91
|
host = `ssh.github.com\n Port 443\n HostkeyAlgorithms +ssh-rsa`;
|
|
74
92
|
}
|
|
75
93
|
const proxyStr = proxy
|
|
76
94
|
? ` ProxyCommand nc -v -x ${proxy} %h %p 2>/dev/null\n`
|
|
77
95
|
: '';
|
|
78
|
-
const config = `Host ${alias}\n Hostname ${host}\n IdentityFile ${
|
|
79
|
-
await (0, utils_1.writeFileWithLock)(`${
|
|
96
|
+
const config = `Host ${alias}\n Hostname ${host}\n IdentityFile ${(0, subscriptionPath_1.resolveSubscriptionPath)(this.sshPath, alias)}\n StrictHostKeyChecking no\n${proxyStr}`;
|
|
97
|
+
await (0, utils_1.writeFileWithLock)(`${(0, subscriptionPath_1.resolveSubscriptionPath)(this.sshPath, alias, '.config')}`, config, {
|
|
80
98
|
encoding: 'utf8',
|
|
81
99
|
mode: '600',
|
|
82
100
|
});
|
|
83
101
|
}
|
|
84
102
|
async removeSshConfig(alias) {
|
|
85
103
|
try {
|
|
86
|
-
const filePath =
|
|
104
|
+
const filePath = (0, subscriptionPath_1.resolveSubscriptionPath)(this.sshPath, alias, '.config');
|
|
87
105
|
await (0, util_1.rmPath)(filePath);
|
|
88
106
|
}
|
|
89
107
|
catch (error) {
|
|
@@ -91,22 +109,29 @@ let SshKeyService = class SshKeyService {
|
|
|
91
109
|
}
|
|
92
110
|
}
|
|
93
111
|
async addSSHKey(key, alias, host, proxy) {
|
|
112
|
+
alias = (0, subscriptionPath_1.getSubscriptionSshAlias)(alias);
|
|
94
113
|
await this.generatePrivateKeyFile(alias, key);
|
|
95
114
|
await this.generateSingleSshConfig(alias, host, proxy);
|
|
96
115
|
}
|
|
97
116
|
async removeSSHKey(alias, host, proxy) {
|
|
117
|
+
alias = (0, subscriptionPath_1.getSubscriptionSshAlias)(alias);
|
|
98
118
|
await this.removePrivateKeyFile(alias);
|
|
99
119
|
await this.removeSshConfig(alias);
|
|
100
120
|
}
|
|
101
121
|
async setSshConfig(docs) {
|
|
102
122
|
for (const doc of docs) {
|
|
103
123
|
if (doc.type === 'private-repo' && doc.pull_type === 'ssh-key') {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
124
|
+
try {
|
|
125
|
+
const alias = (0, subscriptionPath_1.getSubscriptionSshAlias)(doc.alias);
|
|
126
|
+
const { host } = (0, subscription_1.formatUrl)(doc);
|
|
127
|
+
await this.removePrivateKeyFile(alias);
|
|
128
|
+
await this.removeSshConfig(alias);
|
|
129
|
+
await this.generatePrivateKeyFile(alias, doc.pull_option.private_key);
|
|
130
|
+
await this.generateSingleSshConfig(alias, host, doc.proxy);
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
this.logger.warn('跳过订阅 %s 的无效 SSH 配置: %s', doc.id, error);
|
|
134
|
+
}
|
|
110
135
|
}
|
|
111
136
|
}
|
|
112
137
|
}
|
|
@@ -122,8 +147,8 @@ let SshKeyService = class SshKeyService {
|
|
|
122
147
|
}
|
|
123
148
|
async generateGlobalSshConfig(alias) {
|
|
124
149
|
// Create a config that matches all hosts, making this key globally available
|
|
125
|
-
const config = `Host *\n IdentityFile ${
|
|
126
|
-
await (0, utils_1.writeFileWithLock)(`${
|
|
150
|
+
const config = `Host *\n IdentityFile ${(0, subscriptionPath_1.resolveSubscriptionPath)(this.sshPath, alias)}\n StrictHostKeyChecking no\n`;
|
|
151
|
+
await (0, utils_1.writeFileWithLock)(`${(0, subscriptionPath_1.resolveSubscriptionPath)(this.sshPath, alias, '.config')}`, config, {
|
|
127
152
|
encoding: 'utf8',
|
|
128
153
|
mode: '600',
|
|
129
154
|
});
|