@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.
Files changed (362) hide show
  1. package/.dockerignore +13 -0
  2. package/.env.example +7 -0
  3. package/AGENTS.md +2 -2
  4. package/README-en.md +24 -0
  5. package/README.md +24 -0
  6. package/back/protos/api.proto +9 -1
  7. package/back/protos/cron.proto +8 -1
  8. package/deploy/kubernetes/README.md +81 -0
  9. package/deploy/kubernetes/base/kustomization.yaml +5 -0
  10. package/deploy/kubernetes/base/qinglong.yaml +95 -0
  11. package/deploy/kubernetes/overlays/example/kustomization.yaml +10 -0
  12. package/docker/Dockerfile +31 -12
  13. package/docker/Dockerfile.310 +31 -12
  14. package/docker/Dockerfile.debian +22 -14
  15. package/docker/Dockerfile.debian310 +24 -14
  16. package/docker/build-manifest.cjs +28 -0
  17. package/docker/verify-build.cjs +49 -0
  18. package/docs/development/node-cron-migration.md +49 -0
  19. package/docs/development/task-startup.md +78 -0
  20. package/docs/releases/2.22.0-validation.md +49 -0
  21. package/docs/releases/2.22.0.md +62 -0
  22. package/docs/releases/2.23.0.md +33 -0
  23. package/docs/script-history.md +53 -0
  24. package/ecosystem.config.js +10 -1
  25. package/package.json +19 -13
  26. package/sample/config.sample.sh +17 -2
  27. package/sample/notify.js +118 -0
  28. package/sample/notify.py +93 -0
  29. package/scripts/benchmark-execution.cjs +96 -0
  30. package/scripts/benchmark-script-history.cjs +39 -0
  31. package/scripts/publish-static.sh +34 -0
  32. package/scripts/sync-static.sh +20 -0
  33. package/scripts/wait-for-mirror.sh +214 -0
  34. package/scripts/write-build-info.cjs +27 -0
  35. package/shell/api.sh +96 -83
  36. package/shell/check.sh +59 -19
  37. package/shell/lang/en.sh +6 -0
  38. package/shell/lang/zh.sh +6 -0
  39. package/shell/node_path_cache.sh +136 -0
  40. package/shell/otask.sh +17 -10
  41. package/shell/preload/sitecustomize.js +11 -3
  42. package/shell/preload/sitecustomize.py +4 -2
  43. package/shell/share.sh +27 -10
  44. package/shell/start.sh +6 -3
  45. package/shell/task-timeout.sh +63 -0
  46. package/shell/task.sh +21 -9
  47. package/shell/update.sh +104 -98
  48. package/shell/upgrade.cjs +8 -0
  49. package/static/build/api/clientIp.js +42 -0
  50. package/static/build/api/config.js +9 -21
  51. package/static/build/api/cron.js +39 -3
  52. package/static/build/api/dashboard.js +50 -6
  53. package/static/build/api/env.js +17 -16
  54. package/static/build/api/health.js +2 -2
  55. package/static/build/api/index.js +4 -0
  56. package/static/build/api/log.js +39 -19
  57. package/static/build/api/open.js +2 -1
  58. package/static/build/api/retention.js +63 -0
  59. package/static/build/api/script.js +172 -25
  60. package/static/build/api/subscription.js +19 -8
  61. package/static/build/api/system.js +66 -12
  62. package/static/build/api/user.js +75 -15
  63. package/static/build/app.js +63 -54
  64. package/static/build/bootstrap/database.js +51 -0
  65. package/static/build/config/const.js +2 -0
  66. package/static/build/config/grpcCerts.js +93 -44
  67. package/static/build/config/index.js +0 -4
  68. package/static/build/config/share.js +5 -4
  69. package/static/build/config/subscription.js +19 -11
  70. package/static/build/config/util.js +142 -45
  71. package/static/build/data/cron.js +1 -0
  72. package/static/build/data/notify.js +18 -1
  73. package/static/build/data/sock.js +1 -0
  74. package/static/build/loaders/app.js +8 -6
  75. package/static/build/loaders/db.js +5 -35
  76. package/static/build/loaders/deps.js +30 -22
  77. package/static/build/loaders/express.js +46 -32
  78. package/static/build/loaders/initData.js +26 -33
  79. package/static/build/loaders/initFile.js +1 -1
  80. package/static/build/loaders/initTask.js +14 -3
  81. package/static/build/loaders/server.js +1 -1
  82. package/static/build/loaders/sock.js +72 -6
  83. package/static/build/middlewares/monitoring.js +12 -33
  84. package/static/build/middlewares/protectedPathCase.js +17 -0
  85. package/static/build/middlewares/uniqueConstraintError.js +15 -0
  86. package/static/build/protos/api.js +78 -2
  87. package/static/build/protos/cron.js +83 -5
  88. package/static/build/protos/health.js +1 -1
  89. package/static/build/schedule/addCron.js +67 -19
  90. package/static/build/schedule/api.js +5 -2
  91. package/static/build/schedule/client.js +56 -6
  92. package/static/build/schedule/delCron.js +11 -1
  93. package/static/build/schedule/health.js +72 -7
  94. package/static/build/schedule/setConcurrency.js +27 -0
  95. package/static/build/services/config.js +5 -43
  96. package/static/build/services/cron.js +389 -174
  97. package/static/build/services/dependence.js +66 -18
  98. package/static/build/services/env.js +1 -1
  99. package/static/build/services/grpc.js +4 -3
  100. package/static/build/services/health.js +4 -7
  101. package/static/build/services/http.js +9 -3
  102. package/static/build/services/log.js +2 -3
  103. package/static/build/services/metrics.js +46 -14
  104. package/static/build/services/notify.js +73 -5
  105. package/static/build/services/open.js +106 -31
  106. package/static/build/services/retention.js +123 -0
  107. package/static/build/services/schedule.js +77 -43
  108. package/static/build/services/script.js +4 -5
  109. package/static/build/services/scriptHistory.js +30 -0
  110. package/static/build/services/sshKey.js +39 -14
  111. package/static/build/services/subscription.js +161 -87
  112. package/static/build/services/system.js +116 -43
  113. package/static/build/services/user.js +255 -37
  114. package/static/build/shared/auth.js +22 -3
  115. package/static/build/shared/authMutation.js +17 -0
  116. package/static/build/shared/childProcess.js +82 -0
  117. package/static/build/shared/clientIp.js +27 -0
  118. package/static/build/shared/cronCommand.js +17 -0
  119. package/static/build/shared/cronSchedule.js +101 -0
  120. package/static/build/shared/cronScheduler.js +73 -0
  121. package/static/build/shared/errors.js +9 -0
  122. package/static/build/shared/fileAccess.js +60 -0
  123. package/static/build/shared/i18n.js +63 -4
  124. package/static/build/shared/logPath.js +15 -0
  125. package/static/build/shared/logReader.js +85 -0
  126. package/static/build/shared/logStreamManager.js +80 -60
  127. package/static/build/shared/loginThrottle.js +45 -0
  128. package/static/build/shared/pLimit.js +22 -8
  129. package/static/build/shared/password.js +30 -0
  130. package/static/build/shared/retention.js +58 -0
  131. package/static/build/shared/runCron.js +39 -17
  132. package/static/build/shared/schedulerMutationLock.js +44 -0
  133. package/static/build/shared/schedulerReadiness.js +82 -0
  134. package/static/build/shared/schemaMigrations.js +58 -0
  135. package/static/build/shared/scriptHistory.js +445 -0
  136. package/static/build/shared/shellQuote.js +11 -0
  137. package/static/build/shared/startupProcess.js +48 -0
  138. package/static/build/shared/store.js +7 -0
  139. package/static/build/shared/subscriptionMutationLock.js +34 -0
  140. package/static/build/shared/subscriptionPath.js +41 -0
  141. package/static/build/shared/subscriptionStorage.js +98 -0
  142. package/static/build/shared/trustProxy.js +119 -0
  143. package/static/build/shared/utils.js +2 -1
  144. package/static/build/token.js +3 -14
  145. package/static/build/validation/schedule.js +6 -12
  146. package/static/dist/{1885.e1ea09f6.async.js → 1885.b8f427bf.async.js} +1 -1
  147. package/static/dist/2031.6af40025.async.js +1 -0
  148. package/static/dist/2693.51c2636b.async.js +1 -0
  149. package/static/dist/{2890.9e373f5b.async.js → 2890.add55e85.async.js} +1 -1
  150. package/static/dist/2901.2ca95295.async.js +1 -0
  151. package/static/dist/292.264757f0.async.js +1 -0
  152. package/static/dist/3512.95e41255.async.js +1 -0
  153. package/static/dist/445.a65ff63b.async.js +1 -0
  154. package/static/dist/4736.1d2b5cb6.async.js +1 -0
  155. package/static/dist/{6013.4e38de36.async.js → 6013.db535339.async.js} +1 -1
  156. package/static/dist/6212.9e6d9913.async.js +1 -0
  157. package/static/dist/{6339.ab305e96.async.js → 6431.4603ad0e.async.js} +1 -1
  158. package/static/dist/{6872.42f939f1.async.js → 6872.a503ef55.async.js} +1 -1
  159. package/static/dist/7231.f7e5b668.async.js +1 -0
  160. package/static/dist/{7355.f9f263d8.async.js → 7355.fca746f5.async.js} +1 -1
  161. package/static/dist/{7508.7dcee91c.async.js → 7508.d90eac63.async.js} +1 -1
  162. package/static/dist/{7984.594296a5.async.js → 7984.eaac7402.async.js} +1 -1
  163. package/static/dist/8844.a0fef08e.async.js +1 -0
  164. package/static/dist/index.html +2 -2
  165. package/static/dist/layouts__index.633d3553.async.js +1 -0
  166. package/static/dist/preload_helper.01fcd534.js +1 -0
  167. package/static/dist/{src__pages__config__index.a22ff7dc.async.js → src__pages__config__index.9aba4054.async.js} +1 -1
  168. package/static/dist/src__pages__crontab__detail.86b2eebb.async.js +1 -0
  169. package/static/dist/src__pages__crontab__index.ae4e06f2.async.js +1 -0
  170. package/static/dist/{src__pages__crontab__logModal.0b8cce8c.async.js → src__pages__crontab__logModal.930535e2.async.js} +1 -1
  171. package/static/dist/src__pages__crontab__modal.a2c8fdcc.async.js +1 -0
  172. package/static/dist/src__pages__crontab__viewCreateModal.7b4f9cbe.async.js +1 -0
  173. package/static/dist/src__pages__crontab__viewManageModal.cd454ea0.async.js +1 -0
  174. package/static/dist/src__pages__dashboard__index.243c5a35.async.js +1 -0
  175. package/static/dist/src__pages__dashboard__taskResultModal.7795d6e1.async.js +1 -0
  176. package/static/dist/src__pages__dependence__index.874d501f.async.js +1 -0
  177. package/static/dist/src__pages__dependence__logModal.154efe7a.async.js +1 -0
  178. package/static/dist/src__pages__dependence__modal.0fa8b421.async.js +1 -0
  179. package/static/dist/src__pages__diff__index.b94e5dc5.async.js +1 -0
  180. package/static/dist/src__pages__env__editNameModal.c13d47d2.async.js +1 -0
  181. package/static/dist/src__pages__env__index.fd6fd2b0.async.js +1 -0
  182. package/static/dist/src__pages__env__modal.4d71adb3.async.js +1 -0
  183. package/static/dist/src__pages__error__index.aae50c94.async.js +1 -0
  184. package/static/dist/src__pages__initialization__index.82a2e967.async.js +1 -0
  185. package/static/dist/src__pages__log__index.71250e0d.async.js +1 -0
  186. package/static/dist/{src__pages__login__index.8c813eb1.async.js → src__pages__login__index.a0fd5ed8.async.js} +1 -1
  187. package/static/dist/src__pages__script__editModal.afabf073.async.js +1 -0
  188. package/static/dist/src__pages__script__editNameModal.789ad87b.async.js +1 -0
  189. package/static/dist/src__pages__script__historyDrawer.8c58d958.async.js +1 -0
  190. package/static/dist/src__pages__script__historyDrawer.a449193a.chunk.css +1 -0
  191. package/static/dist/src__pages__script__index.ab360776.chunk.css +1 -0
  192. package/static/dist/src__pages__script__index.fc575945.async.js +1 -0
  193. package/static/dist/src__pages__script__renameModal.0ab029e7.async.js +1 -0
  194. package/static/dist/src__pages__script__saveModal.8fca1a22.async.js +1 -0
  195. package/static/dist/src__pages__script__saveWithHistory.99ece830.async.js +1 -0
  196. package/static/dist/src__pages__script__setting.35ad4f02.async.js +1 -0
  197. package/static/dist/src__pages__setting__appModal.7eaeb9d3.async.js +1 -0
  198. package/static/dist/src__pages__setting__checkUpdate.d175b154.async.js +1 -0
  199. package/static/dist/src__pages__setting__clientIp.3a8711ed.async.js +1 -0
  200. package/static/dist/src__pages__setting__dependence.9c0f749b.async.js +1 -0
  201. package/static/dist/src__pages__setting__index.cb397741.async.js +1 -0
  202. package/static/dist/src__pages__setting__loginLog.e0a1f54d.async.js +1 -0
  203. package/static/dist/src__pages__setting__notification.2ffe4e5a.async.js +1 -0
  204. package/static/dist/src__pages__setting__other.3d0b8492.async.js +1 -0
  205. package/static/dist/{src__pages__setting__progress.8823ac90.async.js → src__pages__setting__progress.2ccae3d7.async.js} +1 -1
  206. package/static/dist/src__pages__setting__security.e2d71ebb.async.js +1 -0
  207. package/static/dist/src__pages__setting__systemLog.b3046955.async.js +1 -0
  208. package/static/dist/src__pages__subscription__index.43086a06.async.js +1 -0
  209. package/static/dist/src__pages__subscription__logModal.cdba5139.async.js +1 -0
  210. package/static/dist/src__pages__subscription__modal.30868ba8.async.js +1 -0
  211. package/static/dist/{umi.ca04a019.js → umi.3a24a9fa.js} +1 -1
  212. package/test/back/advisory-input-security.test.cjs +416 -0
  213. package/test/back/auth-security.test.cjs +74 -0
  214. package/test/back/build-provenance.test.cjs +150 -0
  215. package/test/back/code-scanning-security.test.cjs +189 -0
  216. package/test/back/cron-log-name.test.cjs +110 -0
  217. package/test/back/cron-macros.test.cjs +51 -0
  218. package/test/back/cron-schedule-compatibility.test.cjs +69 -0
  219. package/test/back/cron-scheduler-routing.test.cjs +59 -0
  220. package/test/back/cron-validation.test.cjs +45 -0
  221. package/test/back/dashboard-failures.test.cjs +173 -0
  222. package/test/back/database-bootstrap.test.cjs +193 -0
  223. package/test/back/dependence-cache-status.test.cjs +125 -0
  224. package/test/back/deprecated-file-routes.test.cjs +82 -0
  225. package/test/back/draft-path-security.test.cjs +235 -0
  226. package/test/back/ecosystem.test.cjs +28 -0
  227. package/test/back/env-import-security.test.cjs +91 -0
  228. package/test/back/env-name-parsing.test.cjs +96 -0
  229. package/test/back/execution-lifecycle.test.cjs +236 -0
  230. package/test/back/file-access-scope.test.cjs +180 -0
  231. package/test/back/file-access-security.test.cjs +47 -0
  232. package/test/back/fileTreeListing.test.cjs +57 -0
  233. package/test/back/grpc-cron-response.test.cjs +60 -0
  234. package/test/back/grpc-mtls-security.test.cjs +136 -0
  235. package/test/back/http-exclusive-listen.test.cjs +31 -0
  236. package/test/back/http-security.test.cjs +313 -0
  237. package/test/back/legacy-cron-recovery.test.cjs +76 -0
  238. package/test/back/linux-mirror-result.test.cjs +176 -0
  239. package/test/back/listen-security.test.cjs +68 -0
  240. package/test/back/log-path-security.test.cjs +158 -0
  241. package/test/back/logReader.test.cjs +72 -0
  242. package/test/back/manual-execution.test.cjs +85 -0
  243. package/test/back/manual-stop-claim.test.cjs +220 -0
  244. package/test/back/metrics.test.cjs +34 -0
  245. package/test/back/mirror-status.test.cjs +257 -0
  246. package/test/back/monitoring.test.cjs +73 -0
  247. package/test/back/node-cron-migration.test.cjs +65 -0
  248. package/test/back/node-path-cache.test.cjs +202 -0
  249. package/test/back/node-path-lock.test.cjs +182 -0
  250. package/test/back/npm-publication.test.cjs +70 -0
  251. package/test/back/preload-lazy-notify.test.cjs +168 -0
  252. package/test/back/primary-apm.test.cjs +24 -0
  253. package/test/back/process-exit-state.test.cjs +81 -0
  254. package/test/back/process-stop-signal.test.cjs +77 -0
  255. package/test/back/protected-path-case.test.cjs +58 -0
  256. package/test/back/qlServiceLogCommand.test.cjs +128 -0
  257. package/test/back/queued-cron-invalidation.test.cjs +98 -0
  258. package/test/back/restart-instance-recovery.test.cjs +116 -0
  259. package/test/back/retention.test.cjs +131 -0
  260. package/test/back/role-loading.test.cjs +118 -0
  261. package/test/back/schedule-health.test.cjs +86 -0
  262. package/test/back/scheduler-bulk-recovery.test.cjs +40 -0
  263. package/test/back/scheduler-concurrency.test.cjs +411 -0
  264. package/test/back/scheduler-file-lock.test.cjs +51 -0
  265. package/test/back/scheduler-mutation.test.cjs +312 -0
  266. package/test/back/scheduler-readiness.test.cjs +85 -0
  267. package/test/back/scheduler-reconciliation.test.cjs +206 -0
  268. package/test/back/scheduler-rpc-timeout.test.cjs +49 -0
  269. package/test/back/schema-migrations.test.cjs +127 -0
  270. package/test/back/script-file-access.test.cjs +210 -0
  271. package/test/back/script-history-api.test.cjs +551 -0
  272. package/test/back/script-history.test.cjs +383 -0
  273. package/test/back/shell-api-parsing.test.cjs +184 -0
  274. package/test/back/shell-translation-output.test.cjs +16 -0
  275. package/test/back/shell-upgrade.test.cjs +312 -0
  276. package/test/back/shellApiToken.test.cjs +151 -0
  277. package/test/back/sock-polling.test.cjs +297 -0
  278. package/test/back/sock-security.test.cjs +72 -0
  279. package/test/back/ssh-config-home.test.cjs +113 -0
  280. package/test/back/start-env-preservation.test.cjs +53 -0
  281. package/test/back/static-mirror-trigger.test.cjs +441 -0
  282. package/test/back/static-mirror.test.cjs +179 -0
  283. package/test/back/stop-failure-feedback.test.cjs +158 -0
  284. package/test/back/stop-race.test.cjs +171 -0
  285. package/test/back/subscription-cleanup.test.cjs +53 -0
  286. package/test/back/subscription-mutation-lock.test.cjs +83 -0
  287. package/test/back/subscription-review-regression.test.cjs +607 -0
  288. package/test/back/subscription-stop-state.test.cjs +66 -0
  289. package/test/back/subscription-storage-regression.test.cjs +553 -0
  290. package/test/back/system-dependence-cache.test.cjs +127 -0
  291. package/test/back/system-export-history.test.cjs +119 -0
  292. package/test/back/systemTokenRenewal.test.cjs +497 -0
  293. package/test/back/task-shell-lifecycle.test.cjs +194 -0
  294. package/test/back/task-time.test.cjs +116 -0
  295. package/test/back/unique-constraint-error.test.cjs +72 -0
  296. package/test/back/upgrade-guards.test.cjs +285 -0
  297. package/test/back/upgrade-lifecycle.test.cjs +288 -0
  298. package/test/back/upgrade-transaction.test.cjs +133 -0
  299. package/test/back/user-api.test.cjs +99 -0
  300. package/test/back/user-security.test.cjs +349 -0
  301. package/test/back/worker-apm.test.cjs +84 -0
  302. package/test/back/wpush-grpc.test.cjs +116 -0
  303. package/test/fixtures/legacy-cron.json +1371 -0
  304. package/test/front/cron-log-pagination.test.cjs +214 -0
  305. package/test/front/diff-file-routing.test.cjs +126 -0
  306. package/test/front/http-auth.test.cjs +152 -0
  307. package/test/front/http-error.test.cjs +29 -0
  308. package/test/front/script-history-save.test.cjs +121 -0
  309. package/test/helpers/load-security-module.cjs +42 -0
  310. package/test/helpers/upgrade-fixture.cjs +30 -0
  311. package/version.yaml +14 -34
  312. package/CLAUDE.md +0 -43
  313. package/static/dist/1147.c420132e.async.js +0 -1
  314. package/static/dist/134.54df9e38.async.js +0 -1
  315. package/static/dist/2096.6d98fd12.async.js +0 -1
  316. package/static/dist/2208.f7ba3dfa.async.js +0 -1
  317. package/static/dist/2286.164bb089.async.js +0 -1
  318. package/static/dist/3191.63263871.async.js +0 -1
  319. package/static/dist/4859.6592cebb.async.js +0 -1
  320. package/static/dist/4902.555f92ab.async.js +0 -1
  321. package/static/dist/5520.ff2cfd6b.async.js +0 -1
  322. package/static/dist/6431.c50479be.async.js +0 -1
  323. package/static/dist/6707.801b886b.async.js +0 -1
  324. package/static/dist/8826.2447a104.async.js +0 -1
  325. package/static/dist/layouts__index.a7a2bfe0.async.js +0 -1
  326. package/static/dist/preload_helper.0431c0f3.js +0 -1
  327. package/static/dist/src__pages__crontab__detail.b9c36808.async.js +0 -1
  328. package/static/dist/src__pages__crontab__index.fed99fd0.async.js +0 -1
  329. package/static/dist/src__pages__crontab__modal.f7041c7c.async.js +0 -1
  330. package/static/dist/src__pages__crontab__viewCreateModal.4d589f66.async.js +0 -1
  331. package/static/dist/src__pages__crontab__viewManageModal.0e317746.async.js +0 -1
  332. package/static/dist/src__pages__dashboard__index.b30f2f47.async.js +0 -1
  333. package/static/dist/src__pages__dependence__index.3d87ceac.async.js +0 -1
  334. package/static/dist/src__pages__dependence__logModal.0681830b.async.js +0 -1
  335. package/static/dist/src__pages__dependence__modal.11124896.async.js +0 -1
  336. package/static/dist/src__pages__diff__index.013b7c75.async.js +0 -1
  337. package/static/dist/src__pages__env__editNameModal.5d264b25.async.js +0 -1
  338. package/static/dist/src__pages__env__index.baa27d4e.async.js +0 -1
  339. package/static/dist/src__pages__env__modal.7f2ef1bc.async.js +0 -1
  340. package/static/dist/src__pages__error__index.f156b45e.async.js +0 -1
  341. package/static/dist/src__pages__initialization__index.e96d4ba8.async.js +0 -1
  342. package/static/dist/src__pages__log__index.e0978bae.async.js +0 -1
  343. package/static/dist/src__pages__script__editModal.cbf4ec0e.async.js +0 -1
  344. package/static/dist/src__pages__script__editNameModal.3e7e100d.async.js +0 -1
  345. package/static/dist/src__pages__script__index.2765d1b8.async.js +0 -1
  346. package/static/dist/src__pages__script__index.60b6f827.chunk.css +0 -1
  347. package/static/dist/src__pages__script__renameModal.5e987ef5.async.js +0 -1
  348. package/static/dist/src__pages__script__saveModal.3f9d23d6.async.js +0 -1
  349. package/static/dist/src__pages__script__setting.a535793a.async.js +0 -1
  350. package/static/dist/src__pages__setting__appModal.251cd14f.async.js +0 -1
  351. package/static/dist/src__pages__setting__checkUpdate.46efe057.async.js +0 -1
  352. package/static/dist/src__pages__setting__dependence.8a7a9529.async.js +0 -1
  353. package/static/dist/src__pages__setting__index.cc85fdfb.async.js +0 -1
  354. package/static/dist/src__pages__setting__loginLog.cea6056c.async.js +0 -1
  355. package/static/dist/src__pages__setting__notification.390fc905.async.js +0 -1
  356. package/static/dist/src__pages__setting__other.b22d2165.async.js +0 -1
  357. package/static/dist/src__pages__setting__security.598720a8.async.js +0 -1
  358. package/static/dist/src__pages__setting__systemLog.67406721.async.js +0 -1
  359. package/static/dist/src__pages__subscription__index.d0ab2abc.async.js +0 -1
  360. package/static/dist/src__pages__subscription__logModal.3864b37f.async.js +0 -1
  361. package/static/dist/src__pages__subscription__modal.3562c670.async.js +0 -1
  362. /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
- const tab = Object.assign({}, payload);
36
- tab.client_id = (0, util_1.createRandomString)(12, 12);
37
- tab.client_secret = (0, util_1.createRandomString)(24, 24);
38
- const doc = await this.insert(tab);
39
- const apps = await this.find({});
40
- await store_1.shareStore.updateApps(apps);
41
- return Object.assign(Object.assign({}, doc), { tokens: [] });
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
- await open_1.AppModel.update(payload, { where: { id: payload.id } });
57
- const apps = await this.find({});
58
- await store_1.shareStore.updateApps(apps);
59
- return apps === null || apps === void 0 ? void 0 : apps.find((x) => x.id === payload.id);
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
- await open_1.AppModel.destroy({ where: { id: ids } });
70
- const apps = await this.find({});
71
- await store_1.shareStore.updateApps(apps);
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({ client_id, client_secret, }) {
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
- var _a;
150
- const apps = await store_1.shareStore.getApps();
151
- const systemApp = apps === null || apps === void 0 ? void 0 : apps.find((x) => x.name === 'system');
152
- if (!systemApp) {
153
- throw new Error('system app not found');
154
- }
155
- const now = Math.round(Date.now() / 1000);
156
- const currentToken = (_a = systemApp.tokens) === null || _a === void 0 ? void 0 : _a.find((x) => x.expiration > now);
157
- if (currentToken) {
158
- return currentToken;
159
- }
160
- const { data } = await this.authToken({
161
- client_id: systemApp.client_id,
162
- client_secret: systemApp.client_secret,
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 node_schedule_1 = __importDefault(require("node-schedule"));
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
- return pLimit_1.default[this.taskLimitMap[runOrigin]](others, () => {
50
- return new Promise(async (resolve, reject) => {
51
- var _a, _b, _c;
52
- this.logger.info(`[panel][开始执行任务] 参数: ${JSON.stringify(Object.assign(Object.assign({}, others), { command }))}`);
53
- try {
54
- const startTime = (0, dayjs_1.default)();
55
- await ((_a = callbacks.onBefore) === null || _a === void 0 ? void 0 : _a.call(callbacks, startTime));
56
- const cp = (0, cross_spawn_1.spawn)(command, { shell: '/bin/bash' });
57
- (_b = callbacks.onStart) === null || _b === void 0 ? void 0 : _b.call(callbacks, cp, startTime);
58
- completionTime === 'start' && resolve(cp.pid);
59
- cp.stdout.on('data', async (data) => {
60
- var _a;
61
- await ((_a = callbacks.onLog) === null || _a === void 0 ? void 0 : _a.call(callbacks, data.toString()));
62
- });
63
- cp.stderr.on('data', async (data) => {
64
- var _a;
65
- this.logger.info('[panel][执行任务失败] 命令: %s, 错误信息: %j', command, data.toString());
66
- await ((_a = callbacks.onError) === null || _a === void 0 ? void 0 : _a.call(callbacks, data.toString()));
67
- });
68
- cp.on('error', async (err) => {
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
- this.logger.info('[panel][执行任务结束] 参数: %s, 退出码: %j', JSON.stringify(Object.assign(Object.assign({}, others), { command })), code);
76
- const endTime = (0, dayjs_1.default)();
77
- await ((_a = callbacks.onEnd) === null || _a === void 0 ? void 0 : _a.call(callbacks, cp, endTime, endTime.diff(startTime, 'seconds')));
78
- resolve(Object.assign(Object.assign({}, others), { pid: cp.pid, code }));
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][执行任务失败] 命令: %s, 错误信息: %j', command, error);
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
- this.scheduleStacks.set(_id, node_schedule_1.default.scheduleJob(_id, schedule, async () => {
92
- this.runTask(command, callbacks, {
93
- name,
94
- schedule,
95
- command,
96
- id: _id,
97
- runOrigin,
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
- try {
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
- const finalPath = path_1.default.resolve(config_1.default.scriptPath, filePath, fileName);
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 = path_1.default.join(this.sshPath, alias);
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 = path_1.default.join(this.sshPath, alias);
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 ${path_1.default.join(this.sshPath, alias)}\n StrictHostKeyChecking no\n${proxyStr}`;
79
- await (0, utils_1.writeFileWithLock)(`${path_1.default.join(this.sshPath, `${alias}.config`)}`, config, {
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 = path_1.default.join(this.sshPath, `${alias}.config`);
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
- const { alias, proxy } = doc;
105
- const { host } = (0, subscription_1.formatUrl)(doc);
106
- await this.removePrivateKeyFile(alias);
107
- await this.removeSshConfig(alias);
108
- await this.generatePrivateKeyFile(alias, doc.pull_option.private_key);
109
- await this.generateSingleSshConfig(alias, host, proxy);
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 ${path_1.default.join(this.sshPath, alias)}\n StrictHostKeyChecking no\n`;
126
- await (0, utils_1.writeFileWithLock)(`${path_1.default.join(this.sshPath, `${alias}.config`)}`, config, {
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
  });