@whyour/qinglong 2.21.0-8 → 2.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (265) 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 +6 -1
  7. package/back/protos/cron.proto +4 -1
  8. package/docker/Dockerfile +31 -12
  9. package/docker/Dockerfile.310 +31 -12
  10. package/docker/Dockerfile.debian +22 -14
  11. package/docker/Dockerfile.debian310 +24 -14
  12. package/docker/build-manifest.cjs +28 -0
  13. package/docker/verify-build.cjs +49 -0
  14. package/docs/releases/2.22.0-validation.md +49 -0
  15. package/docs/releases/2.22.0.md +54 -0
  16. package/ecosystem.config.js +10 -1
  17. package/package.json +11 -6
  18. package/sample/config.sample.sh +10 -0
  19. package/sample/notify.js +54 -0
  20. package/sample/notify.py +37 -0
  21. package/scripts/benchmark-execution.cjs +96 -0
  22. package/scripts/write-build-info.cjs +27 -0
  23. package/shell/api.sh +34 -13
  24. package/shell/check.sh +59 -19
  25. package/shell/lang/en.sh +6 -0
  26. package/shell/lang/zh.sh +6 -0
  27. package/shell/node_path_cache.sh +128 -0
  28. package/shell/otask.sh +7 -1
  29. package/shell/preload/sitecustomize.js +5 -1
  30. package/shell/share.sh +25 -8
  31. package/shell/start.sh +6 -3
  32. package/shell/task.sh +13 -3
  33. package/shell/update.sh +65 -4
  34. package/static/build/api/clientIp.js +42 -0
  35. package/static/build/api/config.js +8 -16
  36. package/static/build/api/cron.js +38 -2
  37. package/static/build/api/dashboard.js +37 -0
  38. package/static/build/api/health.js +2 -2
  39. package/static/build/api/index.js +4 -0
  40. package/static/build/api/log.js +30 -19
  41. package/static/build/api/retention.js +63 -0
  42. package/static/build/api/script.js +23 -22
  43. package/static/build/api/subscription.js +16 -2
  44. package/static/build/api/system.js +25 -2
  45. package/static/build/api/user.js +75 -15
  46. package/static/build/app.js +54 -45
  47. package/static/build/bootstrap/database.js +51 -0
  48. package/static/build/config/const.js +1 -0
  49. package/static/build/config/share.js +5 -4
  50. package/static/build/config/util.js +133 -38
  51. package/static/build/data/cron.js +1 -0
  52. package/static/build/data/notify.js +11 -1
  53. package/static/build/loaders/app.js +2 -0
  54. package/static/build/loaders/db.js +3 -33
  55. package/static/build/loaders/deps.js +29 -0
  56. package/static/build/loaders/express.js +30 -21
  57. package/static/build/loaders/initData.js +10 -7
  58. package/static/build/loaders/sock.js +72 -6
  59. package/static/build/middlewares/monitoring.js +12 -33
  60. package/static/build/middlewares/protectedPathCase.js +17 -0
  61. package/static/build/protos/api.js +56 -2
  62. package/static/build/protos/cron.js +21 -4
  63. package/static/build/protos/health.js +1 -1
  64. package/static/build/schedule/addCron.js +9 -0
  65. package/static/build/schedule/api.js +5 -2
  66. package/static/build/schedule/client.js +38 -6
  67. package/static/build/schedule/health.js +72 -7
  68. package/static/build/services/config.js +5 -42
  69. package/static/build/services/cron.js +338 -199
  70. package/static/build/services/dependence.js +47 -0
  71. package/static/build/services/grpc.js +1 -1
  72. package/static/build/services/health.js +4 -7
  73. package/static/build/services/http.js +8 -2
  74. package/static/build/services/log.js +2 -3
  75. package/static/build/services/metrics.js +46 -14
  76. package/static/build/services/notify.js +26 -0
  77. package/static/build/services/retention.js +123 -0
  78. package/static/build/services/schedule.js +57 -33
  79. package/static/build/services/script.js +4 -5
  80. package/static/build/services/subscription.js +55 -34
  81. package/static/build/services/system.js +37 -9
  82. package/static/build/services/user.js +213 -25
  83. package/static/build/shared/auth.js +18 -5
  84. package/static/build/shared/authMutation.js +17 -0
  85. package/static/build/shared/childProcess.js +82 -0
  86. package/static/build/shared/clientIp.js +27 -0
  87. package/static/build/shared/errors.js +9 -0
  88. package/static/build/shared/fileAccess.js +60 -0
  89. package/static/build/shared/i18n.js +12 -5
  90. package/static/build/shared/logReader.js +85 -0
  91. package/static/build/shared/logStreamManager.js +80 -60
  92. package/static/build/shared/password.js +30 -0
  93. package/static/build/shared/retention.js +58 -0
  94. package/static/build/shared/runCron.js +28 -15
  95. package/static/build/shared/schedulerMutationLock.js +44 -0
  96. package/static/build/shared/schedulerReadiness.js +82 -0
  97. package/static/build/shared/schemaMigrations.js +58 -0
  98. package/static/build/shared/startupProcess.js +48 -0
  99. package/static/build/shared/store.js +7 -0
  100. package/static/build/shared/trustProxy.js +119 -0
  101. package/static/build/validation/schedule.js +3 -3
  102. package/static/dist/{1885.e1ea09f6.async.js → 1885.b8f427bf.async.js} +1 -1
  103. package/static/dist/2031.6af40025.async.js +1 -0
  104. package/static/dist/2693.51c2636b.async.js +1 -0
  105. package/static/dist/{2890.9e373f5b.async.js → 2890.add55e85.async.js} +1 -1
  106. package/static/dist/2901.2ca95295.async.js +1 -0
  107. package/static/dist/445.a65ff63b.async.js +1 -0
  108. package/static/dist/4736.1d2b5cb6.async.js +1 -0
  109. package/static/dist/{4859.6592cebb.async.js → 4859.97d6653c.async.js} +1 -1
  110. package/static/dist/{6013.4e38de36.async.js → 6013.db535339.async.js} +1 -1
  111. package/static/dist/6212.9e6d9913.async.js +1 -0
  112. package/static/dist/{6339.ab305e96.async.js → 6431.4603ad0e.async.js} +1 -1
  113. package/static/dist/{6872.42f939f1.async.js → 6872.a503ef55.async.js} +1 -1
  114. package/static/dist/7231.f7e5b668.async.js +1 -0
  115. package/static/dist/{7355.f9f263d8.async.js → 7355.fca746f5.async.js} +1 -1
  116. package/static/dist/{7508.7dcee91c.async.js → 7508.d90eac63.async.js} +1 -1
  117. package/static/dist/{7984.594296a5.async.js → 7984.eaac7402.async.js} +1 -1
  118. package/static/dist/8844.a0fef08e.async.js +1 -0
  119. package/static/dist/index.html +2 -2
  120. package/static/dist/layouts__index.633d3553.async.js +1 -0
  121. package/static/dist/preload_helper.cf7de3fa.js +1 -0
  122. package/static/dist/{src__pages__config__index.a22ff7dc.async.js → src__pages__config__index.9aba4054.async.js} +1 -1
  123. package/static/dist/src__pages__crontab__detail.86b2eebb.async.js +1 -0
  124. package/static/dist/src__pages__crontab__index.ae4e06f2.async.js +1 -0
  125. package/static/dist/{src__pages__crontab__logModal.831d5e4b.async.js → src__pages__crontab__logModal.930535e2.async.js} +1 -1
  126. package/static/dist/src__pages__crontab__modal.a2c8fdcc.async.js +1 -0
  127. package/static/dist/src__pages__crontab__viewCreateModal.7b4f9cbe.async.js +1 -0
  128. package/static/dist/src__pages__crontab__viewManageModal.cd454ea0.async.js +1 -0
  129. package/static/dist/src__pages__dashboard__index.243c5a35.async.js +1 -0
  130. package/static/dist/src__pages__dashboard__taskResultModal.7795d6e1.async.js +1 -0
  131. package/static/dist/src__pages__dependence__index.874d501f.async.js +1 -0
  132. package/static/dist/src__pages__dependence__logModal.154efe7a.async.js +1 -0
  133. package/static/dist/src__pages__dependence__modal.a29c1a0f.async.js +1 -0
  134. package/static/dist/{src__pages__diff__index.013b7c75.async.js → src__pages__diff__index.1714b941.async.js} +1 -1
  135. package/static/dist/src__pages__env__editNameModal.c13d47d2.async.js +1 -0
  136. package/static/dist/src__pages__env__index.fd6fd2b0.async.js +1 -0
  137. package/static/dist/src__pages__env__modal.4d71adb3.async.js +1 -0
  138. package/static/dist/src__pages__error__index.aae50c94.async.js +1 -0
  139. package/static/dist/src__pages__initialization__index.82a2e967.async.js +1 -0
  140. package/static/dist/src__pages__log__index.71250e0d.async.js +1 -0
  141. package/static/dist/{src__pages__login__index.8c813eb1.async.js → src__pages__login__index.a0fd5ed8.async.js} +1 -1
  142. package/static/dist/src__pages__script__editModal.22acdf7c.async.js +1 -0
  143. package/static/dist/src__pages__script__editNameModal.1a521cc0.async.js +1 -0
  144. package/static/dist/src__pages__script__index.a18b2692.async.js +1 -0
  145. package/static/dist/src__pages__script__renameModal.0ab029e7.async.js +1 -0
  146. package/static/dist/src__pages__script__saveModal.8965b74c.async.js +1 -0
  147. package/static/dist/src__pages__script__setting.35ad4f02.async.js +1 -0
  148. package/static/dist/src__pages__setting__appModal.7eaeb9d3.async.js +1 -0
  149. package/static/dist/{src__pages__setting__checkUpdate.34d773f2.async.js → src__pages__setting__checkUpdate.d175b154.async.js} +1 -1
  150. package/static/dist/src__pages__setting__clientIp.3a8711ed.async.js +1 -0
  151. package/static/dist/src__pages__setting__dependence.9c0f749b.async.js +1 -0
  152. package/static/dist/src__pages__setting__index.cb397741.async.js +1 -0
  153. package/static/dist/src__pages__setting__loginLog.e0a1f54d.async.js +1 -0
  154. package/static/dist/src__pages__setting__notification.2ffe4e5a.async.js +1 -0
  155. package/static/dist/src__pages__setting__other.3d0b8492.async.js +1 -0
  156. package/static/dist/{src__pages__setting__progress.8823ac90.async.js → src__pages__setting__progress.2ccae3d7.async.js} +1 -1
  157. package/static/dist/src__pages__setting__security.e2d71ebb.async.js +1 -0
  158. package/static/dist/src__pages__setting__systemLog.b3046955.async.js +1 -0
  159. package/static/dist/src__pages__subscription__index.43086a06.async.js +1 -0
  160. package/static/dist/src__pages__subscription__logModal.cdba5139.async.js +1 -0
  161. package/static/dist/src__pages__subscription__modal.38991e1e.async.js +1 -0
  162. package/static/dist/{umi.a54a59f6.js → umi.fc019050.js} +1 -1
  163. package/test/back/auth-security.test.cjs +74 -0
  164. package/test/back/build-provenance.test.cjs +150 -0
  165. package/test/back/cron-log-name.test.cjs +110 -0
  166. package/test/back/cron-validation.test.cjs +45 -0
  167. package/test/back/dashboard-failures.test.cjs +173 -0
  168. package/test/back/database-bootstrap.test.cjs +193 -0
  169. package/test/back/dependence-cache-status.test.cjs +125 -0
  170. package/test/back/deprecated-file-routes.test.cjs +82 -0
  171. package/test/back/ecosystem.test.cjs +28 -0
  172. package/test/back/env-name-parsing.test.cjs +96 -0
  173. package/test/back/execution-lifecycle.test.cjs +236 -0
  174. package/test/back/file-access-security.test.cjs +47 -0
  175. package/test/back/fileTreeListing.test.cjs +57 -0
  176. package/test/back/grpc-cron-response.test.cjs +60 -0
  177. package/test/back/http-exclusive-listen.test.cjs +31 -0
  178. package/test/back/http-security.test.cjs +213 -0
  179. package/test/back/listen-security.test.cjs +67 -0
  180. package/test/back/log-path-security.test.cjs +158 -0
  181. package/test/back/logReader.test.cjs +72 -0
  182. package/test/back/manual-execution.test.cjs +85 -0
  183. package/test/back/manual-stop-claim.test.cjs +220 -0
  184. package/test/back/metrics.test.cjs +34 -0
  185. package/test/back/monitoring.test.cjs +73 -0
  186. package/test/back/node-path-cache.test.cjs +173 -0
  187. package/test/back/node-path-lock.test.cjs +178 -0
  188. package/test/back/npm-publication.test.cjs +70 -0
  189. package/test/back/primary-apm.test.cjs +24 -0
  190. package/test/back/process-exit-state.test.cjs +81 -0
  191. package/test/back/process-stop-signal.test.cjs +77 -0
  192. package/test/back/protected-path-case.test.cjs +58 -0
  193. package/test/back/qlServiceLogCommand.test.cjs +128 -0
  194. package/test/back/retention.test.cjs +131 -0
  195. package/test/back/role-loading.test.cjs +118 -0
  196. package/test/back/schedule-health.test.cjs +86 -0
  197. package/test/back/scheduler-file-lock.test.cjs +51 -0
  198. package/test/back/scheduler-mutation.test.cjs +312 -0
  199. package/test/back/scheduler-readiness.test.cjs +85 -0
  200. package/test/back/scheduler-reconciliation.test.cjs +152 -0
  201. package/test/back/scheduler-rpc-timeout.test.cjs +49 -0
  202. package/test/back/schema-migrations.test.cjs +127 -0
  203. package/test/back/shell-api-parsing.test.cjs +184 -0
  204. package/test/back/sock-polling.test.cjs +297 -0
  205. package/test/back/sock-security.test.cjs +72 -0
  206. package/test/back/start-env-preservation.test.cjs +53 -0
  207. package/test/back/stop-failure-feedback.test.cjs +158 -0
  208. package/test/back/stop-race.test.cjs +167 -0
  209. package/test/back/subscription-cleanup.test.cjs +53 -0
  210. package/test/back/subscription-stop-state.test.cjs +66 -0
  211. package/test/back/system-dependence-cache.test.cjs +126 -0
  212. package/test/back/task-time.test.cjs +116 -0
  213. package/test/back/user-api.test.cjs +99 -0
  214. package/test/back/user-security.test.cjs +248 -0
  215. package/test/back/worker-apm.test.cjs +84 -0
  216. package/test/back/wpush-grpc.test.cjs +115 -0
  217. package/test/front/cron-log-pagination.test.cjs +214 -0
  218. package/test/front/http-auth.test.cjs +152 -0
  219. package/test/front/http-error.test.cjs +29 -0
  220. package/test/helpers/load-security-module.cjs +42 -0
  221. package/version.yaml +19 -34
  222. package/CLAUDE.md +0 -43
  223. package/static/dist/1147.62793604.async.js +0 -1
  224. package/static/dist/134.54df9e38.async.js +0 -1
  225. package/static/dist/2208.85285476.async.js +0 -1
  226. package/static/dist/2286.f371c743.async.js +0 -1
  227. package/static/dist/3191.545ab873.async.js +0 -1
  228. package/static/dist/4902.555f92ab.async.js +0 -1
  229. package/static/dist/5520.ff2cfd6b.async.js +0 -1
  230. package/static/dist/6431.c50479be.async.js +0 -1
  231. package/static/dist/8826.db34ad8d.async.js +0 -1
  232. package/static/dist/layouts__index.a7a2bfe0.async.js +0 -1
  233. package/static/dist/preload_helper.3048fe5b.js +0 -1
  234. package/static/dist/src__pages__crontab__detail.b98f0084.async.js +0 -1
  235. package/static/dist/src__pages__crontab__index.68e78a33.async.js +0 -1
  236. package/static/dist/src__pages__crontab__modal.f7041c7c.async.js +0 -1
  237. package/static/dist/src__pages__crontab__viewCreateModal.4d589f66.async.js +0 -1
  238. package/static/dist/src__pages__crontab__viewManageModal.0e317746.async.js +0 -1
  239. package/static/dist/src__pages__dashboard__index.58177357.async.js +0 -1
  240. package/static/dist/src__pages__dependence__index.b7bbc795.async.js +0 -1
  241. package/static/dist/src__pages__dependence__logModal.0681830b.async.js +0 -1
  242. package/static/dist/src__pages__dependence__modal.f7bb47ba.async.js +0 -1
  243. package/static/dist/src__pages__env__editNameModal.48715576.async.js +0 -1
  244. package/static/dist/src__pages__env__index.452cdc47.async.js +0 -1
  245. package/static/dist/src__pages__env__modal.e1234834.async.js +0 -1
  246. package/static/dist/src__pages__error__index.dedb2b90.async.js +0 -1
  247. package/static/dist/src__pages__initialization__index.22620a77.async.js +0 -1
  248. package/static/dist/src__pages__log__index.9c66639f.async.js +0 -1
  249. package/static/dist/src__pages__script__editModal.cbf4ec0e.async.js +0 -1
  250. package/static/dist/src__pages__script__editNameModal.532a3044.async.js +0 -1
  251. package/static/dist/src__pages__script__index.1fc20f22.async.js +0 -1
  252. package/static/dist/src__pages__script__renameModal.5cdde919.async.js +0 -1
  253. package/static/dist/src__pages__script__saveModal.5ffed35f.async.js +0 -1
  254. package/static/dist/src__pages__script__setting.1a82c6d7.async.js +0 -1
  255. package/static/dist/src__pages__setting__appModal.43b7758a.async.js +0 -1
  256. package/static/dist/src__pages__setting__dependence.9c04c79a.async.js +0 -1
  257. package/static/dist/src__pages__setting__index.7e070838.async.js +0 -1
  258. package/static/dist/src__pages__setting__loginLog.cea6056c.async.js +0 -1
  259. package/static/dist/src__pages__setting__notification.bac481c2.async.js +0 -1
  260. package/static/dist/src__pages__setting__other.707cfafe.async.js +0 -1
  261. package/static/dist/src__pages__setting__security.b7235753.async.js +0 -1
  262. package/static/dist/src__pages__setting__systemLog.b81a8c1d.async.js +0 -1
  263. package/static/dist/src__pages__subscription__index.d0ab2abc.async.js +0 -1
  264. package/static/dist/src__pages__subscription__logModal.3864b37f.async.js +0 -1
  265. package/static/dist/src__pages__subscription__modal.562448e2.async.js +0 -1
@@ -0,0 +1,128 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # Cache discovery only, never the installed packages. Ordinary installs at the
4
+ # same root are visible immediately. TTL bounds changes outside known inputs.
5
+ ql_node_path_cache_key() {
6
+ local pnpm_bin node_bin name directory file
7
+ pnpm_bin=$(type -P pnpm) || return 1
8
+ node_bin=$(type -P node) || return 1
9
+ {
10
+ printf '%s\n' 'v1' "$EUID" "$PWD" "$PATH" "${HOME:-}" \
11
+ "${PNPM_HOME:-}" "${XDG_CONFIG_HOME:-}" "${XDG_DATA_HOME:-}" \
12
+ "$pnpm_bin" "$node_bin"
13
+ for name in ${!npm_config_@} ${!NPM_CONFIG_@}; do
14
+ printf '%s=%s\n' "$name" "${!name}"
15
+ done
16
+ # Follow executable symlinks, detecting upgrades at the same command path.
17
+ stat -Lc '%n:%i:%s:%Y:%Z' "$pnpm_bin" "$node_bin" 2>/dev/null || \
18
+ stat -Lf '%N:%i:%z:%m:%c' "$pnpm_bin" "$node_bin" 2>/dev/null
19
+ directory=$PWD
20
+ while :; do
21
+ for file in "$directory/.npmrc" "$directory/pnpm-workspace.yaml"; do
22
+ if [[ -f "$file" ]]; then
23
+ printf '%s\n' "$file"
24
+ cat -- "$file"
25
+ printf '\n'
26
+ fi
27
+ done
28
+ [[ "$directory" == / ]] && break
29
+ directory=${directory%/*}
30
+ [[ -n "$directory" ]] || directory=/
31
+ done
32
+ for file in "${HOME:-}/.npmrc" \
33
+ "${XDG_CONFIG_HOME:-${HOME:-}/.config}/pnpm/rc" \
34
+ "${npm_config_userconfig:-${NPM_CONFIG_USERCONFIG:-/dev/null}}" \
35
+ "${npm_config_globalconfig:-${NPM_CONFIG_GLOBALCONFIG:-/dev/null}}"; do
36
+ if [[ -f "$file" ]]; then
37
+ printf '%s\n' "$file"
38
+ cat -- "$file"
39
+ printf '\n'
40
+ fi
41
+ done
42
+ } | cksum
43
+ }
44
+
45
+ ql_read_node_path_cache() {
46
+ local cache="$1" key="$2" now
47
+ local stored_key="" stored_at="" stored_path=""
48
+ now=${EPOCHSECONDS:-$(date +%s)}
49
+ if [[ -f "$cache" && ! -L "$cache" && -O "$cache" ]]; then
50
+ if ! {
51
+ IFS= read -r stored_key && IFS= read -r stored_at && IFS= read -r stored_path
52
+ } < "$cache"; then
53
+ return 1
54
+ fi
55
+ if [[ "$stored_key" == "$key" && "$stored_at" =~ ^(0|[1-9][0-9]{0,10})$ && "$stored_path" == /* ]] && \
56
+ (( now >= stored_at && now - stored_at < 60 )); then
57
+ printf '%s\n' "$stored_path"
58
+ return 0
59
+ fi
60
+ fi
61
+ return 1
62
+ }
63
+
64
+ # Keep the lock descriptor in a subshell so sourcing this helper never changes
65
+ # the caller's descriptors. A crashed refresher releases the kernel lock.
66
+ ql_refresh_node_global_path() (
67
+ local cache="$1" key="$2" now result previous_umask
68
+ local lock="${cache}.lock"
69
+ previous_umask=$(umask)
70
+ umask 077
71
+ if type -P flock &>/dev/null && mkdir -p -- "$dir_tmp" 2>/dev/null; then
72
+ if [[ ! -L "$lock" && ( ! -e "$lock" || ( -f "$lock" && -O "$lock" ) ) ]] && \
73
+ { exec 9>> "$lock"; } 2>/dev/null; then
74
+ # BusyBox flock (Alpine) has no -w. Both implementations support -n;
75
+ # bound contention retries and fall back immediately on other failures.
76
+ # Never remove the lock file while waiters exist.
77
+ local lock_attempt=0 lock_status
78
+ while :; do
79
+ if flock -n 9 2>/dev/null; then
80
+ if ql_read_node_path_cache "$cache" "$key"; then
81
+ return 0
82
+ fi
83
+ break
84
+ else
85
+ lock_status=$?
86
+ fi
87
+ [[ "$lock_status" == 1 && "$lock_attempt" -lt 20 ]] || break
88
+ lock_attempt=$((lock_attempt + 1))
89
+ sleep 0.1
90
+ done
91
+ fi
92
+ fi
93
+
94
+ # Private lock creation must not change pnpm's inherited creation mask.
95
+ umask "$previous_umask"
96
+ now=${EPOCHSECONDS:-$(date +%s)}
97
+ result=$(pnpm root -g 9>&- 2>/dev/null) || return $?
98
+ # Never cache failed, empty, multiline or non-absolute answers.
99
+ if [[ "$result" == /* && "$result" != *$'\n'* && "$result" != *$'\r'* ]]; then
100
+ (
101
+ umask 077
102
+ mkdir -p -- "$dir_tmp" || exit 0
103
+ local temporary
104
+ temporary=$(mktemp "${cache}.XXXXXX") || exit 0
105
+ if printf '%s\n%s\n%s\n' "$key" "$now" "$result" > "$temporary"; then
106
+ mv -f -- "$temporary" "$cache" || rm -f -- "$temporary"
107
+ else
108
+ rm -f -- "$temporary"
109
+ fi
110
+ ) 2>/dev/null
111
+ fi
112
+ printf '%s\n' "$result"
113
+ )
114
+
115
+ ql_get_node_global_path() {
116
+ if [[ "${QL_NODE_PATH_CACHE:-1}" == 0 ]]; then
117
+ pnpm root -g 2>/dev/null
118
+ return $?
119
+ fi
120
+
121
+ local key cache
122
+ cache="${dir_tmp}/pnpm-root-${EUID}.cache"
123
+ key=$(ql_node_path_cache_key) || { pnpm root -g 2>/dev/null; return $?; }
124
+ if ql_read_node_path_cache "$cache" "$key"; then
125
+ return 0
126
+ fi
127
+ ql_refresh_node_global_path "$cache" "$key"
128
+ }
package/shell/otask.sh CHANGED
@@ -95,7 +95,13 @@ append_node_dependency_path() {
95
95
  # 用户依赖目录加入 NODE_PATH,替代 symlink 到 node_modules 的方式
96
96
  export NODE_PATH="${NODE_PATH:+${NODE_PATH}:}${dir_dep}"
97
97
 
98
- local pnpm_global_path=$(pnpm root -g 2>/dev/null)
98
+ local pnpm_global_path
99
+ if [[ -f "$dir_shell/node_path_cache.sh" ]]; then
100
+ . "$dir_shell/node_path_cache.sh"
101
+ pnpm_global_path=$(ql_get_node_global_path) || true
102
+ else
103
+ pnpm_global_path=$(pnpm root -g 2>/dev/null) || true
104
+ fi
99
105
  if [[ -n "$pnpm_global_path" ]]; then
100
106
  export QL_NODE_GLOBAL_PATH="$pnpm_global_path"
101
107
  export NODE_PATH="${NODE_PATH:+${NODE_PATH}:}${pnpm_global_path}"
@@ -98,7 +98,11 @@ function run() {
98
98
  const newEnvObject = JSON.parse(envStr);
99
99
  if (typeof newEnvObject === 'object' && newEnvObject !== null) {
100
100
  for (const key in newEnvObject) {
101
- if (Object.prototype.hasOwnProperty.call(newEnvObject, key)) {
101
+ if (
102
+ Object.prototype.hasOwnProperty.call(newEnvObject, key) &&
103
+ key !== 'NODE_PATH' &&
104
+ key !== 'QL_NODE_GLOBAL_PATH'
105
+ ) {
102
106
  process.env[key] = newEnvObject[key];
103
107
  }
104
108
  }
package/shell/share.sh CHANGED
@@ -305,8 +305,13 @@ reload_pm2() {
305
305
  # Kill any existing node processes for qinglong
306
306
  pkill -f "node.*static/build/app.js" 2>/dev/null || true
307
307
 
308
- # Start node directly in the background
309
- nohup node static/build/app.js > $dir_log/qinglong.log 2>&1 &
308
+ # Start node directly in the background. In containers, keep application
309
+ # output on the container streams instead of duplicating Winston logs on disk.
310
+ if [[ "$QL_CONTAINER" == "true" ]]; then
311
+ nohup node static/build/app.js >/proc/1/fd/1 2>/proc/1/fd/2 &
312
+ else
313
+ nohup node static/build/app.js >$dir_log/qinglong.log 2>&1 &
314
+ fi
310
315
  local node_pid=$!
311
316
 
312
317
  t '已使用 Node.js 直接启动服务 (PID: %s)' "$node_pid"
@@ -363,9 +368,16 @@ format_timestamp() {
363
368
 
364
369
  get_env_array() {
365
370
  exported_variables=()
366
- while IFS= read -r line; do
367
- exported_variables+=("$line")
368
- done < <(grep '^export ' $file_env | awk '{print $2}' | cut -d= -f1)
371
+ # Preserve the legacy export-line/second-field rules without evaluating values.
372
+ local export_name_program='/^export / { name = $2; sub(/=.*/, "", name); print name }'
373
+ if [[ ${BASH_VERSINFO[0]} -ge 4 ]]; then
374
+ builtin mapfile -t exported_variables < <(awk "$export_name_program" "$file_env")
375
+ else
376
+ # macOS still ships Bash 3, which does not provide mapfile.
377
+ while IFS= read -r line; do
378
+ exported_variables+=("$line")
379
+ done < <(awk "$export_name_program" "$file_env")
380
+ fi
369
381
  }
370
382
 
371
383
  clear_env() {
@@ -406,9 +418,14 @@ run_task_after() {
406
418
  }
407
419
 
408
420
  handle_task_end() {
409
- local etime=$(date "+$time_format")
410
- local end_time=$(format_time "$time_format" "$etime")
411
- local end_timestamp=$(format_timestamp "$time_format" "$etime")
421
+ local etime end_time end_timestamp
422
+ if [[ $is_macos -ne 1 && $time_format == '%Y-%m-%d %H:%M:%S' ]]; then
423
+ IFS='|' read -r end_time end_timestamp < <(date "+$time_format|%s")
424
+ else
425
+ etime=$(date "+$time_format")
426
+ end_time=$(format_time "$time_format" "$etime")
427
+ end_timestamp=$(format_timestamp "$time_format" "$etime")
428
+ fi
412
429
  local diff_time=$(($end_timestamp - $begin_timestamp))
413
430
  local exit_code="${_task_exit_code:-0}"
414
431
  [[ "$diff_time" == 0 ]] && diff_time=1
package/shell/start.sh CHANGED
@@ -74,7 +74,7 @@ if [[ $command != "reload" ]]; then
74
74
  ;;
75
75
  esac
76
76
 
77
- npm install -g pnpm@8.3.1 pm2 ts-node
77
+ npm install -g pnpm@8.3.1 pm2 ts-node typescript@5
78
78
  fi
79
79
 
80
80
  export PYTHON_SHORT_VERSION=$(python3 -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')
@@ -91,8 +91,11 @@ if [[ $command != "reload" ]]; then
91
91
  pip3 install --prefix ${PYTHON_HOME} requests
92
92
  fi
93
93
 
94
- cd ${QL_DIR}
95
- cp -f .env.example .env
94
+ cd "${QL_DIR}"
95
+ if [[ ! -e .env ]]; then
96
+ # Preserve user configuration, including a file created concurrently.
97
+ (umask 077; set -C; cat .env.example > .env)
98
+ fi
96
99
  chmod 777 ${QL_DIR}/shell/*.sh
97
100
 
98
101
  . ${QL_DIR}/shell/share.sh
package/shell/task.sh CHANGED
@@ -52,8 +52,14 @@ handle_log_path() {
52
52
  fi
53
53
  fi
54
54
 
55
- time=$(date "+$mtime_format")
56
- log_time=$(format_log_time "$mtime_format" "$time")
55
+ if [[ $is_macos -ne 1 && $mtime_format == '%Y-%m-%d %H:%M:%S.%3N' ]]; then
56
+ # Render both representations from one clock snapshot, without parsing it
57
+ # again in a second date process.
58
+ IFS='|' read -r time log_time < <(date "+$mtime_format|%Y-%m-%d-%H-%M-%S-%3N")
59
+ else
60
+ time=$(date "+$mtime_format")
61
+ log_time=$(format_log_time "$mtime_format" "$time")
62
+ fi
57
63
  if [[ -z $log_name ]]; then
58
64
  log_dir_tmp="${file_param##*/}"
59
65
  if [[ $file_param =~ "/" ]]; then
@@ -124,7 +130,11 @@ format_params() {
124
130
  }
125
131
 
126
132
  init_begin_time() {
127
- begin_time=$(format_time "$time_format" "$time")
133
+ if [[ $is_macos -ne 1 && $mtime_format == '%Y-%m-%d %H:%M:%S.%3N' && $time_format == '%Y-%m-%d %H:%M:%S' ]]; then
134
+ begin_time=${time%.*}
135
+ else
136
+ begin_time=$(format_time "$time_format" "$time")
137
+ fi
128
138
  begin_timestamp=$(format_timestamp "$time_format" "$time")
129
139
  }
130
140
 
package/shell/update.sh CHANGED
@@ -211,6 +211,60 @@ run_extra_shell() {
211
211
  fi
212
212
  }
213
213
 
214
+ ## 查看青龙服务日志
215
+ show_service_logs() {
216
+ local lines="15"
217
+ local no_stream="false"
218
+ while [[ $# -gt 0 ]]; do
219
+ case "$1" in
220
+ --lines)
221
+ if [[ ! "${2:-}" =~ ^[0-9]+$ ]]; then
222
+ echo "ql log: --lines requires a non-negative integer" >&2
223
+ return 2
224
+ fi
225
+ lines="$2"
226
+ shift 2
227
+ ;;
228
+ --lines=*)
229
+ lines="${1#--lines=}"
230
+ if [[ ! "$lines" =~ ^[0-9]+$ ]]; then
231
+ echo "ql log: --lines requires a non-negative integer" >&2
232
+ return 2
233
+ fi
234
+ shift
235
+ ;;
236
+ --nostream)
237
+ no_stream="true"
238
+ shift
239
+ ;;
240
+ *)
241
+ echo "ql log: unknown option: $1" >&2
242
+ return 2
243
+ ;;
244
+ esac
245
+ done
246
+
247
+ local system_log_dir="$dir_data/syslog"
248
+ local latest_system_log
249
+ latest_system_log=$(ls -1t "$system_log_dir"/*.log* 2>/dev/null | head -n 1)
250
+ if [[ "$lines" != "0" ]] && [[ -f "$latest_system_log" ]]; then
251
+ tail -n "$lines" "$latest_system_log"
252
+ fi
253
+
254
+ if [[ "$no_stream" == "true" ]]; then
255
+ if [[ -z "$latest_system_log" ]]; then
256
+ echo "ql log: no system log found in $system_log_dir" >&2
257
+ return 1
258
+ fi
259
+ return 0
260
+ fi
261
+
262
+ # Winston writes the active runtime log by date. Follow the filename so
263
+ # size-based rotations are handled without involving the PM2 log files.
264
+ local current_system_log="$system_log_dir/$(date +%F).log"
265
+ tail -n 0 --retry -F "$current_system_log"
266
+ }
267
+
214
268
  ## 脚本用法
215
269
  usage() {
216
270
  t "$cmd_update 命令使用方法:"
@@ -221,10 +275,11 @@ usage() {
221
275
  echo -e "5. $cmd_update rmlog <days> # 删除旧日志"
222
276
  echo -e "6. $cmd_update bot # 启动tg-bot"
223
277
  echo -e "7. $cmd_update check # 检测青龙环境并修复"
224
- echo -e "8. $cmd_update resetlet # 重置登录错误次数"
225
- echo -e "9. $cmd_update resettfa # 禁用两步登录"
226
- echo -e "10. $cmd_update resetpwd # 修改登录密码"
227
- echo -e "11. $cmd_update resetname # 修改登录用户名"
278
+ echo -e "8. $cmd_update log [--lines <n>] [--nostream] # 查看青龙运行日志"
279
+ echo -e "9. $cmd_update resetlet # 重置登录错误次数"
280
+ echo -e "10. $cmd_update resettfa # 禁用两步登录"
281
+ echo -e "11. $cmd_update resetpwd # 修改登录密码"
282
+ echo -e "12. $cmd_update resetname # 修改登录用户名"
228
283
  }
229
284
 
230
285
  reload_qinglong() {
@@ -471,6 +526,12 @@ main() {
471
526
  local p8="${8}"
472
527
  local p9="${9}"
473
528
  local p10="${10}"
529
+
530
+ if [[ "$p1" == "log" ]]; then
531
+ show_service_logs "${@:2}"
532
+ return $?
533
+ fi
534
+
474
535
  local log_dir="${p1}"
475
536
  make_dir "$dir_log/$log_dir"
476
537
  local log_time=$(date "+%Y-%m-%d-%H-%M-%S")
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const express_1 = require("express");
4
+ const celebrate_1 = require("celebrate");
5
+ const trustProxy_1 = require("../shared/trustProxy");
6
+ const route = (0, express_1.Router)();
7
+ exports.default = (app) => {
8
+ app.use('/system/client-ip', route);
9
+ route.get('/config', async (req, res, next) => {
10
+ try {
11
+ res.send({ code: 200, data: await (0, trustProxy_1.getTrustProxyConfig)() });
12
+ }
13
+ catch (error) {
14
+ next(error);
15
+ }
16
+ });
17
+ route.put('/config', (0, celebrate_1.celebrate)({
18
+ body: celebrate_1.Joi.object({
19
+ trustProxy: celebrate_1.Joi.string().max(500).required(),
20
+ }),
21
+ }), async (req, res) => {
22
+ try {
23
+ const data = await (0, trustProxy_1.updateTrustProxy)(req.body.trustProxy);
24
+ res.send({ code: 200, data });
25
+ }
26
+ catch (error) {
27
+ res.send({
28
+ code: 400,
29
+ message: error instanceof Error ? error.message : '配置更新失败',
30
+ });
31
+ }
32
+ });
33
+ route.get('/diagnose', async (req, res, next) => {
34
+ try {
35
+ res.send({ code: 200, data: await (0, trustProxy_1.diagnoseClientIp)(req) });
36
+ }
37
+ catch (error) {
38
+ next(error);
39
+ }
40
+ });
41
+ };
42
+ //# sourceMappingURL=clientIp.js.map
@@ -36,6 +36,7 @@ const const_1 = require("../config/const");
36
36
  const i18n_1 = require("../shared/i18n");
37
37
  const config_2 = __importDefault(require("../services/config"));
38
38
  const utils_1 = require("../shared/utils");
39
+ const fileAccess_1 = require("../shared/fileAccess");
39
40
  const route = (0, express_1.Router)();
40
41
  exports.default = (app) => {
41
42
  app.use('/configs', route);
@@ -91,14 +92,8 @@ exports.default = (app) => {
91
92
  basePath = (0, path_1.join)(config_1.default.rootPath, 'data/scripts');
92
93
  }
93
94
  const cleanName = name.replace(/^data\/scripts\//, '');
94
- const resolvedPath = (0, path_1.join)(basePath, cleanName);
95
- const normalized = (0, path_1.join)(resolvedPath);
96
- // Verify the resolved path stays within allowed directory
97
- if (!normalized.startsWith(basePath)) {
98
- return res.send({ code: 403, message: (0, i18n_1.t)('文件路径无效') });
99
- }
100
- // Check blacklist on actual filename (not user input)
101
- if (config_1.default.blackFileList.includes((0, path_1.basename)(normalized))) {
95
+ const normalized = (0, fileAccess_1.resolveFileAccess)(basePath, [cleanName], config_1.default.blackFileList);
96
+ if (!normalized) {
102
97
  return res.send({ code: 403, message: (0, i18n_1.t)('文件无法访问') });
103
98
  }
104
99
  await (0, utils_1.writeFileWithLock)(normalized, content);
@@ -108,14 +103,11 @@ exports.default = (app) => {
108
103
  return next(e);
109
104
  }
110
105
  });
111
- route.get('/:file', async (req, res, next) => {
112
- try {
113
- const configService = typedi_1.Container.get(config_2.default);
114
- await configService.getFile(req.params.file, res);
115
- }
116
- catch (e) {
117
- return next(e);
118
- }
106
+ route.get('/:file', (req, res) => {
107
+ return res.send({
108
+ code: 410,
109
+ message: (0, i18n_1.t)('接口已下线,请使用 /configs/detail 接口'),
110
+ });
119
111
  });
120
112
  };
121
113
  //# sourceMappingURL=config.js.map
@@ -11,9 +11,23 @@ const celebrate_1 = require("celebrate");
11
11
  const schedule_1 = require("../validation/schedule");
12
12
  const runningInstance_1 = require("../data/runningInstance");
13
13
  const i18n_1 = require("../shared/i18n");
14
+ const client_1 = __importDefault(require("../schedule/client"));
14
15
  const route = (0, express_1.Router)();
15
16
  exports.default = (app) => {
16
17
  app.use('/crons', route);
18
+ route.use(async (req, res, next) => {
19
+ // Keep stop/status callbacks available even when the scheduler is down.
20
+ if (['POST', 'PUT', 'DELETE'].includes(req.method) &&
21
+ ['/', '/run', '/enable', '/disable', '/views/enable', '/views/disable'].includes(req.path)) {
22
+ try {
23
+ await client_1.default.readiness.ensureReady();
24
+ }
25
+ catch (error) {
26
+ return next(error);
27
+ }
28
+ }
29
+ return next();
30
+ });
17
31
  route.get('/views', async (req, res, next) => {
18
32
  try {
19
33
  const cronViewService = typedi_1.Container.get(cronView_1.default);
@@ -243,12 +257,34 @@ exports.default = (app) => {
243
257
  params: celebrate_1.Joi.object({
244
258
  id: celebrate_1.Joi.number().required(),
245
259
  }),
260
+ query: celebrate_1.Joi.object({
261
+ offset: celebrate_1.Joi.number().integer().min(0).optional(),
262
+ limit: celebrate_1.Joi.number()
263
+ .integer()
264
+ .min(1)
265
+ .max(1024 * 1024)
266
+ .optional(),
267
+ tail: celebrate_1.Joi.boolean().optional(),
268
+ t: celebrate_1.Joi.string().optional(),
269
+ }).unknown(true),
246
270
  }), async (req, res, next) => {
247
271
  const logger = typedi_1.Container.get('logger');
248
272
  try {
249
273
  const cronService = typedi_1.Container.get(cron_1.default);
250
- const result = await cronService.log(req.params.id);
251
- return res.send({ code: 200, data: result.content, logStatus: result.status });
274
+ const result = await cronService.log(req.params.id, {
275
+ offset: req.query.offset,
276
+ limit: req.query.limit,
277
+ tail: req.query.tail,
278
+ });
279
+ return res.send({
280
+ code: 200,
281
+ data: result.content,
282
+ logStatus: result.status,
283
+ offset: result.offset,
284
+ nextOffset: result.nextOffset,
285
+ total: result.total,
286
+ truncated: result.truncated,
287
+ });
252
288
  }
253
289
  catch (e) {
254
290
  return next(e);
@@ -94,6 +94,43 @@ exports.default = (app) => {
94
94
  next(e);
95
95
  }
96
96
  });
97
+ for (const isSuccess of [false, true]) {
98
+ route.get(isSuccess ? '/successes' : '/failures', async (req, res, next) => {
99
+ try {
100
+ const countColumn = isSuccess ? 'success_count' : 'fail_count';
101
+ const rows = (await cronStats_1.CrontabStatModel.findAll({
102
+ attributes: ['ref_id', [(0, sequelize_1.fn)('SUM', (0, sequelize_1.col)(countColumn)), 'result_count']],
103
+ where: { date: (0, dayjs_1.default)().format('YYYY-MM-DD'), [countColumn]: { [sequelize_1.Op.gt]: 0 } },
104
+ group: ['ref_id'],
105
+ order: [[(0, sequelize_1.fn)('SUM', (0, sequelize_1.col)(countColumn)), 'DESC'], ['ref_id', 'ASC']],
106
+ raw: true,
107
+ }));
108
+ const crons = rows.length > 0 ? await cron_1.CrontabModel.findAll({
109
+ attributes: ['id', 'name', 'command'],
110
+ where: { id: { [sequelize_1.Op.in]: rows.map((row) => Number(row.ref_id)) } },
111
+ raw: true,
112
+ }) : [];
113
+ const cronMap = new Map(crons.map((cron) => [cron.id, cron]));
114
+ res.send({
115
+ code: 200,
116
+ data: rows.map((row) => {
117
+ const id = Number(row.ref_id);
118
+ const cron = cronMap.get(id);
119
+ return {
120
+ id,
121
+ name: (cron === null || cron === void 0 ? void 0 : cron.name) || (cron === null || cron === void 0 ? void 0 : cron.command) || (0, i18n_1.tf)('任务#%s', id),
122
+ command: (cron === null || cron === void 0 ? void 0 : cron.command) || '',
123
+ [isSuccess ? 'successCount' : 'failCount']: Number(row.result_count),
124
+ deleted: !cron,
125
+ };
126
+ }),
127
+ });
128
+ }
129
+ catch (e) {
130
+ next(e);
131
+ }
132
+ });
133
+ }
97
134
  route.get('/trend', async (req, res, next) => {
98
135
  try {
99
136
  const days = parseInt(req.query.days) || 7;
@@ -14,8 +14,8 @@ exports.default = (app) => {
14
14
  try {
15
15
  const healthService = typedi_1.default.get(health_1.HealthService);
16
16
  const health = await healthService.check();
17
- res.status(200).send({
18
- code: 200,
17
+ res.status(health.status === 'ok' ? 200 : 503).send({
18
+ code: health.status === 'ok' ? 200 : 503,
19
19
  data: health,
20
20
  });
21
21
  }
@@ -17,6 +17,8 @@ const subscription_1 = __importDefault(require("./subscription"));
17
17
  const update_1 = __importDefault(require("./update"));
18
18
  const dashboard_1 = __importDefault(require("./dashboard"));
19
19
  const health_1 = __importDefault(require("./health"));
20
+ const clientIp_1 = __importDefault(require("./clientIp"));
21
+ const retention_1 = __importDefault(require("./retention"));
20
22
  exports.default = () => {
21
23
  const app = (0, express_1.Router)();
22
24
  (0, user_1.default)(app);
@@ -32,6 +34,8 @@ exports.default = () => {
32
34
  (0, update_1.default)(app);
33
35
  (0, dashboard_1.default)(app);
34
36
  (0, health_1.default)(app);
37
+ (0, clientIp_1.default)(app);
38
+ (0, retention_1.default)(app);
35
39
  return app;
36
40
  };
37
41
  //# sourceMappingURL=index.js.map
@@ -11,6 +11,7 @@ const i18n_1 = require("../shared/i18n");
11
11
  const util_1 = require("../config/util");
12
12
  const log_1 = __importDefault(require("../services/log"));
13
13
  const runningInstance_1 = require("../data/runningInstance");
14
+ const logReader_1 = require("../shared/logReader");
14
15
  const route = (0, express_1.Router)();
15
16
  const blacklist = ['.tmp'];
16
17
  exports.default = (app) => {
@@ -29,7 +30,20 @@ exports.default = (app) => {
29
30
  return next(e);
30
31
  }
31
32
  });
32
- route.get('/detail', async (req, res, next) => {
33
+ route.get('/detail', (0, celebrate_1.celebrate)({
34
+ query: celebrate_1.Joi.object({
35
+ path: celebrate_1.Joi.string().allow('').optional(),
36
+ file: celebrate_1.Joi.string().required(),
37
+ offset: celebrate_1.Joi.number().integer().min(0).optional(),
38
+ limit: celebrate_1.Joi.number()
39
+ .integer()
40
+ .min(1)
41
+ .max(logReader_1.MAX_LOG_CHUNK_BYTES)
42
+ .optional(),
43
+ tail: celebrate_1.Joi.boolean().optional(),
44
+ t: celebrate_1.Joi.string().optional(),
45
+ }).unknown(true),
46
+ }), async (req, res, next) => {
33
47
  try {
34
48
  const logService = typedi_1.Container.get(log_1.default);
35
49
  const finalPath = logService.checkFilePath(req.query.path || '', req.query.file || '');
@@ -43,33 +57,30 @@ exports.default = (app) => {
43
57
  const runningInstance = await runningInstance_1.RunningInstanceModel.findOne({
44
58
  where: { log_path: logPath, status: runningInstance_1.InstanceStatus.running },
45
59
  });
46
- const content = await (0, util_1.getFileContentByName)(finalPath);
60
+ const chunk = await (0, logReader_1.readLogChunk)(finalPath, {
61
+ offset: req.query.offset,
62
+ limit: req.query.limit,
63
+ tail: req.query.tail,
64
+ });
47
65
  res.send({
48
66
  code: 200,
49
- data: (0, util_1.removeAnsi)(content),
67
+ data: (0, util_1.removeAnsi)(chunk.content),
50
68
  logStatus: runningInstance ? 'running' : undefined,
69
+ offset: chunk.offset,
70
+ nextOffset: chunk.nextOffset,
71
+ total: chunk.total,
72
+ truncated: chunk.truncated,
51
73
  });
52
74
  }
53
75
  catch (e) {
54
76
  return next(e);
55
77
  }
56
78
  });
57
- route.get('/:file', async (req, res, next) => {
58
- try {
59
- const logService = typedi_1.Container.get(log_1.default);
60
- const finalPath = logService.checkFilePath(req.query.path || '', req.params.file || '');
61
- if (!finalPath || blacklist.includes(req.query.path)) {
62
- return res.send({
63
- code: 403,
64
- message: (0, i18n_1.t)('暂无权限'),
65
- });
66
- }
67
- const content = await (0, util_1.getFileContentByName)(finalPath);
68
- res.send({ code: 200, data: content });
69
- }
70
- catch (e) {
71
- return next(e);
72
- }
79
+ route.get('/:file', (req, res) => {
80
+ return res.send({
81
+ code: 410,
82
+ message: (0, i18n_1.t)('接口已下线,请使用 /logs/detail 接口'),
83
+ });
73
84
  });
74
85
  route.delete('/', (0, celebrate_1.celebrate)({
75
86
  body: celebrate_1.Joi.object({