@whyour/qinglong 2.21.0 → 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 (279) 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 +4 -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/releases/2.22.0-validation.md +49 -0
  19. package/docs/releases/2.22.0.md +54 -0
  20. package/ecosystem.config.js +10 -1
  21. package/package.json +11 -6
  22. package/sample/config.sample.sh +17 -2
  23. package/sample/notify.js +118 -0
  24. package/sample/notify.py +93 -0
  25. package/scripts/benchmark-execution.cjs +96 -0
  26. package/scripts/write-build-info.cjs +27 -0
  27. package/shell/api.sh +41 -14
  28. package/shell/check.sh +59 -19
  29. package/shell/lang/en.sh +6 -0
  30. package/shell/lang/zh.sh +6 -0
  31. package/shell/node_path_cache.sh +128 -0
  32. package/shell/otask.sh +10 -1
  33. package/shell/preload/sitecustomize.js +5 -1
  34. package/shell/share.sh +26 -9
  35. package/shell/start.sh +6 -3
  36. package/shell/task.sh +13 -3
  37. package/shell/update.sh +65 -4
  38. package/static/build/api/clientIp.js +42 -0
  39. package/static/build/api/config.js +8 -16
  40. package/static/build/api/cron.js +39 -3
  41. package/static/build/api/dashboard.js +50 -6
  42. package/static/build/api/env.js +2 -2
  43. package/static/build/api/health.js +2 -2
  44. package/static/build/api/index.js +4 -0
  45. package/static/build/api/log.js +39 -19
  46. package/static/build/api/retention.js +63 -0
  47. package/static/build/api/script.js +23 -22
  48. package/static/build/api/subscription.js +16 -2
  49. package/static/build/api/system.js +31 -9
  50. package/static/build/api/user.js +75 -15
  51. package/static/build/app.js +63 -54
  52. package/static/build/bootstrap/database.js +51 -0
  53. package/static/build/config/const.js +2 -0
  54. package/static/build/config/grpcCerts.js +4 -4
  55. package/static/build/config/index.js +0 -4
  56. package/static/build/config/share.js +5 -4
  57. package/static/build/config/util.js +136 -41
  58. package/static/build/data/cron.js +1 -0
  59. package/static/build/data/notify.js +18 -1
  60. package/static/build/data/sock.js +1 -0
  61. package/static/build/loaders/app.js +8 -6
  62. package/static/build/loaders/db.js +5 -35
  63. package/static/build/loaders/deps.js +30 -22
  64. package/static/build/loaders/express.js +44 -32
  65. package/static/build/loaders/initData.js +10 -7
  66. package/static/build/loaders/initFile.js +1 -1
  67. package/static/build/loaders/initTask.js +3 -2
  68. package/static/build/loaders/server.js +1 -1
  69. package/static/build/loaders/sock.js +72 -6
  70. package/static/build/middlewares/monitoring.js +12 -33
  71. package/static/build/middlewares/protectedPathCase.js +17 -0
  72. package/static/build/protos/api.js +78 -2
  73. package/static/build/protos/cron.js +21 -4
  74. package/static/build/protos/health.js +1 -1
  75. package/static/build/schedule/addCron.js +76 -10
  76. package/static/build/schedule/api.js +5 -2
  77. package/static/build/schedule/client.js +38 -6
  78. package/static/build/schedule/delCron.js +11 -1
  79. package/static/build/schedule/health.js +72 -7
  80. package/static/build/services/config.js +5 -42
  81. package/static/build/services/cron.js +353 -164
  82. package/static/build/services/dependence.js +66 -18
  83. package/static/build/services/grpc.js +2 -2
  84. package/static/build/services/health.js +4 -7
  85. package/static/build/services/http.js +9 -3
  86. package/static/build/services/log.js +2 -3
  87. package/static/build/services/metrics.js +46 -14
  88. package/static/build/services/notify.js +73 -5
  89. package/static/build/services/retention.js +123 -0
  90. package/static/build/services/schedule.js +57 -33
  91. package/static/build/services/script.js +4 -5
  92. package/static/build/services/subscription.js +57 -34
  93. package/static/build/services/system.js +49 -11
  94. package/static/build/services/user.js +244 -31
  95. package/static/build/shared/auth.js +22 -3
  96. package/static/build/shared/authMutation.js +17 -0
  97. package/static/build/shared/childProcess.js +82 -0
  98. package/static/build/shared/clientIp.js +27 -0
  99. package/static/build/shared/errors.js +9 -0
  100. package/static/build/shared/fileAccess.js +60 -0
  101. package/static/build/shared/i18n.js +62 -4
  102. package/static/build/shared/logReader.js +85 -0
  103. package/static/build/shared/logStreamManager.js +80 -60
  104. package/static/build/shared/pLimit.js +3 -2
  105. package/static/build/shared/password.js +30 -0
  106. package/static/build/shared/retention.js +58 -0
  107. package/static/build/shared/runCron.js +28 -15
  108. package/static/build/shared/schedulerMutationLock.js +44 -0
  109. package/static/build/shared/schedulerReadiness.js +82 -0
  110. package/static/build/shared/schemaMigrations.js +58 -0
  111. package/static/build/shared/startupProcess.js +48 -0
  112. package/static/build/shared/store.js +7 -0
  113. package/static/build/shared/trustProxy.js +119 -0
  114. package/static/build/validation/schedule.js +12 -3
  115. package/static/dist/{1885.e1ea09f6.async.js → 1885.b8f427bf.async.js} +1 -1
  116. package/static/dist/2031.6af40025.async.js +1 -0
  117. package/static/dist/2693.51c2636b.async.js +1 -0
  118. package/static/dist/{2890.9e373f5b.async.js → 2890.add55e85.async.js} +1 -1
  119. package/static/dist/2901.2ca95295.async.js +1 -0
  120. package/static/dist/445.a65ff63b.async.js +1 -0
  121. package/static/dist/4736.1d2b5cb6.async.js +1 -0
  122. package/static/dist/{4859.6592cebb.async.js → 4859.97d6653c.async.js} +1 -1
  123. package/static/dist/{6013.4e38de36.async.js → 6013.db535339.async.js} +1 -1
  124. package/static/dist/6212.9e6d9913.async.js +1 -0
  125. package/static/dist/{6339.ab305e96.async.js → 6431.4603ad0e.async.js} +1 -1
  126. package/static/dist/{6872.42f939f1.async.js → 6872.a503ef55.async.js} +1 -1
  127. package/static/dist/7231.f7e5b668.async.js +1 -0
  128. package/static/dist/{7355.f9f263d8.async.js → 7355.fca746f5.async.js} +1 -1
  129. package/static/dist/{7508.7dcee91c.async.js → 7508.d90eac63.async.js} +1 -1
  130. package/static/dist/{7984.594296a5.async.js → 7984.eaac7402.async.js} +1 -1
  131. package/static/dist/8844.a0fef08e.async.js +1 -0
  132. package/static/dist/index.html +2 -2
  133. package/static/dist/layouts__index.633d3553.async.js +1 -0
  134. package/static/dist/preload_helper.cf7de3fa.js +1 -0
  135. package/static/dist/{src__pages__config__index.a22ff7dc.async.js → src__pages__config__index.9aba4054.async.js} +1 -1
  136. package/static/dist/src__pages__crontab__detail.86b2eebb.async.js +1 -0
  137. package/static/dist/src__pages__crontab__index.ae4e06f2.async.js +1 -0
  138. package/static/dist/{src__pages__crontab__logModal.0b8cce8c.async.js → src__pages__crontab__logModal.930535e2.async.js} +1 -1
  139. package/static/dist/src__pages__crontab__modal.a2c8fdcc.async.js +1 -0
  140. package/static/dist/src__pages__crontab__viewCreateModal.7b4f9cbe.async.js +1 -0
  141. package/static/dist/src__pages__crontab__viewManageModal.cd454ea0.async.js +1 -0
  142. package/static/dist/src__pages__dashboard__index.243c5a35.async.js +1 -0
  143. package/static/dist/src__pages__dashboard__taskResultModal.7795d6e1.async.js +1 -0
  144. package/static/dist/src__pages__dependence__index.874d501f.async.js +1 -0
  145. package/static/dist/src__pages__dependence__logModal.154efe7a.async.js +1 -0
  146. package/static/dist/src__pages__dependence__modal.a29c1a0f.async.js +1 -0
  147. package/static/dist/{src__pages__diff__index.013b7c75.async.js → src__pages__diff__index.1714b941.async.js} +1 -1
  148. package/static/dist/src__pages__env__editNameModal.c13d47d2.async.js +1 -0
  149. package/static/dist/src__pages__env__index.fd6fd2b0.async.js +1 -0
  150. package/static/dist/src__pages__env__modal.4d71adb3.async.js +1 -0
  151. package/static/dist/src__pages__error__index.aae50c94.async.js +1 -0
  152. package/static/dist/src__pages__initialization__index.82a2e967.async.js +1 -0
  153. package/static/dist/src__pages__log__index.71250e0d.async.js +1 -0
  154. package/static/dist/{src__pages__login__index.8c813eb1.async.js → src__pages__login__index.a0fd5ed8.async.js} +1 -1
  155. package/static/dist/src__pages__script__editModal.22acdf7c.async.js +1 -0
  156. package/static/dist/src__pages__script__editNameModal.1a521cc0.async.js +1 -0
  157. package/static/dist/src__pages__script__index.a18b2692.async.js +1 -0
  158. package/static/dist/src__pages__script__renameModal.0ab029e7.async.js +1 -0
  159. package/static/dist/src__pages__script__saveModal.8965b74c.async.js +1 -0
  160. package/static/dist/src__pages__script__setting.35ad4f02.async.js +1 -0
  161. package/static/dist/src__pages__setting__appModal.7eaeb9d3.async.js +1 -0
  162. package/static/dist/src__pages__setting__checkUpdate.d175b154.async.js +1 -0
  163. package/static/dist/src__pages__setting__clientIp.3a8711ed.async.js +1 -0
  164. package/static/dist/src__pages__setting__dependence.9c0f749b.async.js +1 -0
  165. package/static/dist/src__pages__setting__index.cb397741.async.js +1 -0
  166. package/static/dist/src__pages__setting__loginLog.e0a1f54d.async.js +1 -0
  167. package/static/dist/src__pages__setting__notification.2ffe4e5a.async.js +1 -0
  168. package/static/dist/src__pages__setting__other.3d0b8492.async.js +1 -0
  169. package/static/dist/{src__pages__setting__progress.8823ac90.async.js → src__pages__setting__progress.2ccae3d7.async.js} +1 -1
  170. package/static/dist/src__pages__setting__security.e2d71ebb.async.js +1 -0
  171. package/static/dist/src__pages__setting__systemLog.b3046955.async.js +1 -0
  172. package/static/dist/src__pages__subscription__index.43086a06.async.js +1 -0
  173. package/static/dist/src__pages__subscription__logModal.cdba5139.async.js +1 -0
  174. package/static/dist/src__pages__subscription__modal.38991e1e.async.js +1 -0
  175. package/static/dist/{umi.ca04a019.js → umi.fc019050.js} +1 -1
  176. package/test/back/auth-security.test.cjs +74 -0
  177. package/test/back/build-provenance.test.cjs +150 -0
  178. package/test/back/cron-log-name.test.cjs +110 -0
  179. package/test/back/cron-validation.test.cjs +45 -0
  180. package/test/back/dashboard-failures.test.cjs +173 -0
  181. package/test/back/database-bootstrap.test.cjs +193 -0
  182. package/test/back/dependence-cache-status.test.cjs +125 -0
  183. package/test/back/deprecated-file-routes.test.cjs +82 -0
  184. package/test/back/ecosystem.test.cjs +28 -0
  185. package/test/back/env-name-parsing.test.cjs +96 -0
  186. package/test/back/execution-lifecycle.test.cjs +236 -0
  187. package/test/back/file-access-security.test.cjs +47 -0
  188. package/test/back/fileTreeListing.test.cjs +57 -0
  189. package/test/back/grpc-cron-response.test.cjs +60 -0
  190. package/test/back/http-exclusive-listen.test.cjs +31 -0
  191. package/test/back/http-security.test.cjs +213 -0
  192. package/test/back/listen-security.test.cjs +67 -0
  193. package/test/back/log-path-security.test.cjs +158 -0
  194. package/test/back/logReader.test.cjs +72 -0
  195. package/test/back/manual-execution.test.cjs +85 -0
  196. package/test/back/manual-stop-claim.test.cjs +220 -0
  197. package/test/back/metrics.test.cjs +34 -0
  198. package/test/back/monitoring.test.cjs +73 -0
  199. package/test/back/node-path-cache.test.cjs +173 -0
  200. package/test/back/node-path-lock.test.cjs +178 -0
  201. package/test/back/npm-publication.test.cjs +70 -0
  202. package/test/back/primary-apm.test.cjs +24 -0
  203. package/test/back/process-exit-state.test.cjs +81 -0
  204. package/test/back/process-stop-signal.test.cjs +77 -0
  205. package/test/back/protected-path-case.test.cjs +58 -0
  206. package/test/back/qlServiceLogCommand.test.cjs +128 -0
  207. package/test/back/retention.test.cjs +131 -0
  208. package/test/back/role-loading.test.cjs +118 -0
  209. package/test/back/schedule-health.test.cjs +86 -0
  210. package/test/back/scheduler-file-lock.test.cjs +51 -0
  211. package/test/back/scheduler-mutation.test.cjs +312 -0
  212. package/test/back/scheduler-readiness.test.cjs +85 -0
  213. package/test/back/scheduler-reconciliation.test.cjs +152 -0
  214. package/test/back/scheduler-rpc-timeout.test.cjs +49 -0
  215. package/test/back/schema-migrations.test.cjs +127 -0
  216. package/test/back/shell-api-parsing.test.cjs +184 -0
  217. package/test/back/sock-polling.test.cjs +297 -0
  218. package/test/back/sock-security.test.cjs +72 -0
  219. package/test/back/start-env-preservation.test.cjs +53 -0
  220. package/test/back/stop-failure-feedback.test.cjs +158 -0
  221. package/test/back/stop-race.test.cjs +167 -0
  222. package/test/back/subscription-cleanup.test.cjs +53 -0
  223. package/test/back/subscription-stop-state.test.cjs +66 -0
  224. package/test/back/system-dependence-cache.test.cjs +126 -0
  225. package/test/back/task-time.test.cjs +116 -0
  226. package/test/back/user-api.test.cjs +99 -0
  227. package/test/back/user-security.test.cjs +248 -0
  228. package/test/back/worker-apm.test.cjs +84 -0
  229. package/test/back/wpush-grpc.test.cjs +115 -0
  230. package/test/front/cron-log-pagination.test.cjs +214 -0
  231. package/test/front/http-auth.test.cjs +152 -0
  232. package/test/front/http-error.test.cjs +29 -0
  233. package/test/helpers/load-security-module.cjs +42 -0
  234. package/version.yaml +19 -34
  235. package/CLAUDE.md +0 -43
  236. package/static/dist/1147.c420132e.async.js +0 -1
  237. package/static/dist/134.54df9e38.async.js +0 -1
  238. package/static/dist/2208.f7ba3dfa.async.js +0 -1
  239. package/static/dist/2286.164bb089.async.js +0 -1
  240. package/static/dist/3191.63263871.async.js +0 -1
  241. package/static/dist/4902.555f92ab.async.js +0 -1
  242. package/static/dist/5520.ff2cfd6b.async.js +0 -1
  243. package/static/dist/6431.c50479be.async.js +0 -1
  244. package/static/dist/8826.2447a104.async.js +0 -1
  245. package/static/dist/layouts__index.a7a2bfe0.async.js +0 -1
  246. package/static/dist/preload_helper.0431c0f3.js +0 -1
  247. package/static/dist/src__pages__crontab__detail.b9c36808.async.js +0 -1
  248. package/static/dist/src__pages__crontab__index.fed99fd0.async.js +0 -1
  249. package/static/dist/src__pages__crontab__modal.f7041c7c.async.js +0 -1
  250. package/static/dist/src__pages__crontab__viewCreateModal.4d589f66.async.js +0 -1
  251. package/static/dist/src__pages__crontab__viewManageModal.0e317746.async.js +0 -1
  252. package/static/dist/src__pages__dashboard__index.b30f2f47.async.js +0 -1
  253. package/static/dist/src__pages__dependence__index.3d87ceac.async.js +0 -1
  254. package/static/dist/src__pages__dependence__logModal.0681830b.async.js +0 -1
  255. package/static/dist/src__pages__dependence__modal.11124896.async.js +0 -1
  256. package/static/dist/src__pages__env__editNameModal.5d264b25.async.js +0 -1
  257. package/static/dist/src__pages__env__index.baa27d4e.async.js +0 -1
  258. package/static/dist/src__pages__env__modal.7f2ef1bc.async.js +0 -1
  259. package/static/dist/src__pages__error__index.f156b45e.async.js +0 -1
  260. package/static/dist/src__pages__initialization__index.e96d4ba8.async.js +0 -1
  261. package/static/dist/src__pages__log__index.e0978bae.async.js +0 -1
  262. package/static/dist/src__pages__script__editModal.cbf4ec0e.async.js +0 -1
  263. package/static/dist/src__pages__script__editNameModal.3e7e100d.async.js +0 -1
  264. package/static/dist/src__pages__script__index.2765d1b8.async.js +0 -1
  265. package/static/dist/src__pages__script__renameModal.5e987ef5.async.js +0 -1
  266. package/static/dist/src__pages__script__saveModal.3f9d23d6.async.js +0 -1
  267. package/static/dist/src__pages__script__setting.a535793a.async.js +0 -1
  268. package/static/dist/src__pages__setting__appModal.251cd14f.async.js +0 -1
  269. package/static/dist/src__pages__setting__checkUpdate.46efe057.async.js +0 -1
  270. package/static/dist/src__pages__setting__dependence.8a7a9529.async.js +0 -1
  271. package/static/dist/src__pages__setting__index.cc85fdfb.async.js +0 -1
  272. package/static/dist/src__pages__setting__loginLog.cea6056c.async.js +0 -1
  273. package/static/dist/src__pages__setting__notification.390fc905.async.js +0 -1
  274. package/static/dist/src__pages__setting__other.b22d2165.async.js +0 -1
  275. package/static/dist/src__pages__setting__security.598720a8.async.js +0 -1
  276. package/static/dist/src__pages__setting__systemLog.67406721.async.js +0 -1
  277. package/static/dist/src__pages__subscription__index.d0ab2abc.async.js +0 -1
  278. package/static/dist/src__pages__subscription__logModal.3864b37f.async.js +0 -1
  279. package/static/dist/src__pages__subscription__modal.3562c670.async.js +0 -1
package/shell/api.sh CHANGED
@@ -10,16 +10,39 @@ create_token() {
10
10
  }
11
11
 
12
12
  get_token() {
13
- if [[ -f $file_auth_token ]]; then
14
- __ql_token__=$(cat $file_auth_token | jq -r .value)
15
- local expiration=$(cat $file_auth_token | jq -r .expiration)
16
- local currentTimeStamp=$(date +%s)
17
- if [[ $currentTimeStamp -ge $expiration ]]; then
18
- create_token
13
+ local token_data expiration token_value
14
+ local currentTimeStamp=${EPOCHSECONDS:-$(date +%s)}
15
+ if [[ -f "$file_auth_token" ]] && token_data=$(jq -er \
16
+ 'select((.expiration | type) == "number" and (.value | type) == "string" and (.value | length) > 0 and (.value | test("[\r\n]") | not)) | .expiration, .value' \
17
+ "$file_auth_token" 2>/dev/null); then
18
+ expiration=${token_data%%$'\n'*}
19
+ token_value=${token_data#*$'\n'}
20
+ if [[ "$expiration" =~ ^[1-9][0-9]{0,10}$ && -n "$token_value" && "$token_value" != *$'\n'* && "$token_value" != *$'\r'* ]] && \
21
+ (( currentTimeStamp < expiration )); then
22
+ __ql_token__=$token_value
23
+ return 0
19
24
  fi
20
- else
21
- create_token
22
25
  fi
26
+ create_token
27
+ }
28
+
29
+ # Read the status response once; preserve multiline error messages and the
30
+ # legacy code/message variables used by the shell API callers.
31
+ ql_parse_status_response() {
32
+ # Both task status and statistics endpoints normally return this exact body.
33
+ # Match the whole document; all other JSON and malformed responses still
34
+ # use jq. Keep its missing-message result for existing callers.
35
+ if [[ "$1" == '{"code":200}' ]]; then
36
+ code=200
37
+ message=null
38
+ return 0
39
+ fi
40
+ local parsed
41
+ code=""
42
+ message=""
43
+ parsed=$(jq -r '.code, .message' <<< "$1") || return $?
44
+ code=${parsed%%$'\n'*}
45
+ message=${parsed#*$'\n'}
23
46
  }
24
47
 
25
48
  add_cron_api() {
@@ -141,17 +164,22 @@ update_cron() {
141
164
  local logPath="$4"
142
165
  local lastExecutingTime="${5:-0}"
143
166
  local runningTime="${6:-0}"
144
- local currentTimeStamp=$(date +%s)
167
+ local exitCode="${7:-}"
168
+ local currentTimeStamp=${EPOCHSECONDS:-$(date +%s)}
169
+ local dataRaw="{\"ids\":[$ids],\"status\":\"$status\",\"pid\":\"$pid\",\"log_path\":\"$logPath\",\"last_execution_time\":$lastExecutingTime,\"last_running_time\":$runningTime"
170
+ if [[ -n $exitCode ]]; then
171
+ dataRaw="${dataRaw},\"exit_code\":$exitCode"
172
+ fi
173
+ dataRaw="${dataRaw}}"
145
174
  local api=$(
146
175
  curl -s --noproxy "*" "http://localhost:${ql_port}/open/crons/status?t=$currentTimeStamp" \
147
176
  -X 'PUT' \
148
177
  -H "Authorization: Bearer ${__ql_token__}" \
149
178
  -H "Content-Type: application/json;charset=UTF-8" \
150
- --data-raw "{\"ids\":[$ids],\"status\":\"$status\",\"pid\":\"$pid\",\"log_path\":\"$logPath\",\"last_execution_time\":$lastExecutingTime,\"last_running_time\":$runningTime}" \
179
+ --data-raw "$dataRaw" \
151
180
  --compressed
152
181
  )
153
- code=$(echo "$api" | jq -r .code)
154
- message=$(echo "$api" | jq -r .message)
182
+ ql_parse_status_response "$api" || true
155
183
  if [[ $code != 200 ]]; then
156
184
  if [[ ! $message ]]; then
157
185
  message="$api"
@@ -234,8 +262,7 @@ record_cron_stat() {
234
262
  --data-raw "{\"ref_id\":$ref_id,\"code\":$exit_code,\"elapsed\":$elapsed}" \
235
263
  --compressed
236
264
  )
237
- code=$(echo "$api" | jq -r .code)
238
- message=$(echo "$api" | jq -r .message)
265
+ ql_parse_status_response "$api" || true
239
266
  if [[ $code != 200 ]]; then
240
267
  if [[ ! $message ]]; then
241
268
  message="$api"
package/shell/check.sh CHANGED
@@ -23,50 +23,90 @@ copy_dep() {
23
23
  }
24
24
 
25
25
  pm2_log() {
26
- t '---> pm2日志'
27
- local panelOut="/root/.pm2/logs/qinglong-out.log"
28
- local panelError="/root/.pm2/logs/qinglong-error.log"
29
- tail -n 300 "$panelOut"
30
- tail -n 300 "$panelError"
26
+ t '---> 服务诊断信息'
27
+ pm2 status || true
28
+
29
+ local systemLogDir="$dir_data/syslog"
30
+ local latestSystemLog
31
+ latestSystemLog=$(find "$systemLogDir" -maxdepth 1 -type f -name '*.log' 2>/dev/null | sort | tail -n 1)
32
+ if [[ -n "$latestSystemLog" ]]; then
33
+ t '---> 最近的系统日志: %s' "$latestSystemLog"
34
+ tail -n 300 "$latestSystemLog"
35
+ else
36
+ t '---> 未找到系统日志: %s' "$systemLogDir"
37
+ fi
38
+
39
+ if [[ "$QL_CONTAINER" == "true" ]]; then
40
+ t '---> 容器内 PM2 日志不落盘;早期启动错误请执行 docker logs --tail 300 <容器名>'
41
+ return
42
+ fi
43
+
44
+ local pm2Home="${PM2_HOME:-$HOME/.pm2}"
45
+ local panelOut="$pm2Home/logs/qinglong-out.log"
46
+ local panelError="$pm2Home/logs/qinglong-error.log"
47
+ [[ -f "$panelOut" ]] && tail -n 300 "$panelOut"
48
+ [[ -f "$panelError" ]] && tail -n 300 "$panelError"
31
49
  }
32
50
 
33
51
  check_ql() {
34
- local api=$(curl -s --noproxy "*" "http://localhost:${ql_port}")
52
+ local basePath="${ql_base_url%/}"
53
+ local api
54
+ local attempt
55
+ for ((attempt = 1; attempt <= 10; attempt++)); do
56
+ api=$(curl -s --max-time 2 --noproxy "*" "http://localhost:${ql_port}${basePath}/")
57
+ [[ $api =~ "<div id=\"root\"></div>" ]] && break
58
+ sleep 1
59
+ done
35
60
  t '\n=====> 检测面板'
36
61
  echo -e "\n\n$api\n"
37
62
  if [[ $api =~ "<div id=\"root\"></div>" ]]; then
38
63
  t '=====> 面板服务启动正常\n'
64
+ else
65
+ t '=====> 面板服务启动异常,请检查上方诊断信息\n'
66
+ return 1
39
67
  fi
40
68
  }
41
69
 
42
70
  check_pm2() {
43
- pm2_log
44
71
  local currentTimeStamp=$(date +%s)
45
- local api=$(
46
- curl -s --noproxy "*" "http://localhost:${ql_port}/api/system?t=$currentTimeStamp" \
47
- -H 'Accept: */*' \
48
- -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36' \
49
- -H "Referer: http://localhost:${ql_port}/crontab" \
50
- -H 'Accept-Language: en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7' \
51
- --compressed
52
- )
72
+ local basePath="${ql_base_url%/}"
73
+ local api
74
+ local attempt
75
+ for ((attempt = 1; attempt <= 10; attempt++)); do
76
+ api=$(
77
+ curl -s --max-time 2 --noproxy "*" "http://localhost:${ql_port}${basePath}/api/health?t=$currentTimeStamp" \
78
+ -H 'Accept: */*' \
79
+ -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36' \
80
+ -H "Referer: http://localhost:${ql_port}/crontab" \
81
+ -H 'Accept-Language: en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7' \
82
+ --compressed
83
+ )
84
+ [[ $api == *'"code":200'* && $api == *'"status":"ok"'* ]] && break
85
+ sleep 1
86
+ done
53
87
  t '\n=====> 检测后台'
54
88
  echo -e "\n\n$api\n"
55
- if [[ $api =~ "{\"code\"" ]]; then
89
+ if [[ $api == *'"code":200'* && $api == *'"status":"ok"'* ]]; then
56
90
  t '=====> 后台服务启动正常\n'
91
+ else
92
+ pm2_log
93
+ t '=====> 后台服务启动异常,请检查上方诊断信息\n'
94
+ return 1
57
95
  fi
58
96
  }
59
97
 
60
98
  main() {
61
99
  t '=====> 开始检测'
62
- npm i -g pnpm@8.3.1 pm2 ts-node
100
+ npm i -g pnpm@8.3.1 pm2 ts-node typescript@5
63
101
 
64
102
  reset_env
65
103
  copy_dep
66
- check_ql
67
- check_pm2
68
104
  reload_pm2
105
+ local checkStatus=0
106
+ check_ql || checkStatus=1
107
+ check_pm2 || checkStatus=1
69
108
  t '\n=====> 检测结束\n'
109
+ return $checkStatus
70
110
  }
71
111
 
72
112
  main
package/shell/lang/en.sh CHANGED
@@ -82,10 +82,16 @@ declare -gA LANG_MESSAGES=(
82
82
  ['---> 复制一份 %s 为 %s\n']='---> Copying %s to %s\n'
83
83
  ['---> 通知文件复制完成\n']='---> Notification files copied\n'
84
84
  ['---> pm2日志']='---> pm2 log'
85
+ ['---> 服务诊断信息']='---> Service diagnostics'
86
+ ['---> 最近的系统日志: %s']='---> Recent system log: %s'
87
+ ['---> 未找到系统日志: %s']='---> No system log found: %s'
88
+ ['---> 容器内 PM2 日志不落盘;早期启动错误请执行 docker logs --tail 300 <容器名>']='---> PM2 logs are not persisted in containers; run docker logs --tail 300 <container> for early startup errors'
85
89
  ['\n=====> 检测面板']='\n=====> Checking panel'
86
90
  ['=====> 面板服务启动正常\n']='=====> Panel service running normally\n'
91
+ ['=====> 面板服务启动异常,请检查上方诊断信息\n']='=====> Panel failed to start; check the diagnostics above\n'
87
92
  ['\n=====> 检测后台']='\n=====> Checking backend'
88
93
  ['=====> 后台服务启动正常\n']='=====> Backend service running normally\n'
94
+ ['=====> 后台服务启动异常,请检查上方诊断信息\n']='=====> Backend failed to start; check the diagnostics above\n'
89
95
  ['=====> 开始检测']='=====> Starting check'
90
96
  ['\n=====> 检测结束\n']='\n=====> Check complete\n'
91
97
  # rmlog.sh
package/shell/lang/zh.sh CHANGED
@@ -82,10 +82,16 @@ declare -gA LANG_MESSAGES=(
82
82
  ['---> 复制一份 %s 为 %s\n']='---> 复制一份 %s 为 %s\n'
83
83
  ['---> 通知文件复制完成\n']='---> 通知文件复制完成\n'
84
84
  ['---> pm2日志']='---> pm2日志'
85
+ ['---> 服务诊断信息']='---> 服务诊断信息'
86
+ ['---> 最近的系统日志: %s']='---> 最近的系统日志: %s'
87
+ ['---> 未找到系统日志: %s']='---> 未找到系统日志: %s'
88
+ ['---> 容器内 PM2 日志不落盘;早期启动错误请执行 docker logs --tail 300 <容器名>']='---> 容器内 PM2 日志不落盘;早期启动错误请执行 docker logs --tail 300 <容器名>'
85
89
  ['\n=====> 检测面板']='\n=====> 检测面板'
86
90
  ['=====> 面板服务启动正常\n']='=====> 面板服务启动正常\n'
91
+ ['=====> 面板服务启动异常,请检查上方诊断信息\n']='=====> 面板服务启动异常,请检查上方诊断信息\n'
87
92
  ['\n=====> 检测后台']='\n=====> 检测后台'
88
93
  ['=====> 后台服务启动正常\n']='=====> 后台服务启动正常\n'
94
+ ['=====> 后台服务启动异常,请检查上方诊断信息\n']='=====> 后台服务启动异常,请检查上方诊断信息\n'
89
95
  ['=====> 开始检测']='=====> 开始检测'
90
96
  ['\n=====> 检测结束\n']='\n=====> 检测结束\n'
91
97
  # rmlog.sh
@@ -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
@@ -92,7 +92,16 @@ clear_non_sh_env() {
92
92
  append_node_dependency_path() {
93
93
  export PREV_NODE_PATH="${NODE_PATH:=}"
94
94
 
95
- local pnpm_global_path=$(pnpm root -g 2>/dev/null)
95
+ # 用户依赖目录加入 NODE_PATH,替代 symlink 到 node_modules 的方式
96
+ export NODE_PATH="${NODE_PATH:+${NODE_PATH}:}${dir_dep}"
97
+
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
96
105
  if [[ -n "$pnpm_global_path" ]]; then
97
106
  export QL_NODE_GLOBAL_PATH="$pnpm_global_path"
98
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,15 +418,20 @@ 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
415
432
 
416
433
  if [[ $ID ]]; then
417
- local error=$(update_cron "\"$ID\"" "1" "$$" "$log_path" "$begin_timestamp" "$diff_time")
434
+ local error=$(update_cron "\"$ID\"" "1" "$$" "$log_path" "$begin_timestamp" "$diff_time" "$exit_code")
418
435
  if [[ $error ]]; then
419
436
  error_message=", 状态更新失败(${error})"
420
437
  fi
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