@whyour/qinglong 0.9.2 → 0.10.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 (94) hide show
  1. package/docker/Dockerfile +1 -0
  2. package/package.json +1 -1
  3. package/sample/notify.py +1 -1
  4. package/shell/api.sh +1 -1
  5. package/shell/otask.sh +19 -11
  6. package/shell/start.sh +2 -3
  7. package/shell/task.sh +1 -1
  8. package/shell/update.sh +3 -3
  9. package/static/build/api/env.js +2 -1
  10. package/static/build/api/script.js +2 -0
  11. package/static/build/api/system.js +4 -1
  12. package/static/build/config/index.js +2 -2
  13. package/static/build/config/share.js +83 -0
  14. package/static/build/config/util.js +21 -84
  15. package/static/build/loaders/express.js +2 -2
  16. package/static/build/loaders/sock.js +1 -1
  17. package/static/build/schedule/addCron.js +1 -2
  18. package/static/build/schedule/client.js +1 -1
  19. package/static/build/schedule/health.js +1 -1
  20. package/static/build/services/cron.js +18 -14
  21. package/static/build/services/env.js +2 -4
  22. package/static/build/services/schedule.js +8 -8
  23. package/static/build/services/script.js +0 -1
  24. package/static/build/services/subscription.js +0 -3
  25. package/static/build/services/user.js +1 -1
  26. package/static/build/shared/pLimit.js +8 -0
  27. package/static/build/shared/runCron.js +2 -2
  28. package/static/dist/3330.485d94a3.async.js +1 -0
  29. package/static/dist/{4714.4abfa66f.async.js → 4714.bbe9fae0.async.js} +1 -1
  30. package/static/dist/8044.129359a6.async.js +1 -0
  31. package/static/dist/819.525cbfda.async.js +1 -0
  32. package/static/dist/index.html +1 -1
  33. package/static/dist/layouts__index.ddfcd364.chunk.css +1 -0
  34. package/static/dist/src__pages__config__index.fedea3f9.async.js +1 -0
  35. package/static/dist/{src__pages__crontab__detail.91b2b006.async.js → src__pages__crontab__detail.ad4729f7.async.js} +1 -1
  36. package/static/dist/{src__pages__crontab__index.502a1f71.chunk.css → src__pages__crontab__index.686cdb14.chunk.css} +1 -1
  37. package/static/dist/src__pages__crontab__index.a82cfa81.async.js +1 -0
  38. package/static/dist/{src__pages__crontab__logModal.a0c9c75c.async.js → src__pages__crontab__logModal.ad170a0f.async.js} +1 -1
  39. package/static/dist/src__pages__crontab__modal.696faf3d.async.js +1 -0
  40. package/static/dist/{src__pages__dependence__index.20e51efb.async.js → src__pages__dependence__index.9f871d7e.async.js} +1 -1
  41. package/static/dist/src__pages__dependence__logModal.b8dfb9bf.async.js +1 -0
  42. package/static/dist/src__pages__dependence__modal.77688c64.async.js +1 -0
  43. package/static/dist/src__pages__diff__index.73c27cfb.async.js +1 -0
  44. package/static/dist/src__pages__env__editNameModal.0b8b8511.async.js +1 -0
  45. package/static/dist/src__pages__env__index.c2e7f61a.async.js +1 -0
  46. package/static/dist/src__pages__env__modal.d4bcf3f1.async.js +1 -0
  47. package/static/dist/src__pages__error__index.9d76a461.async.js +1 -0
  48. package/static/dist/src__pages__initialization__index.7cb87ba4.async.js +1 -0
  49. package/static/dist/src__pages__script__editModal.dddd633e.async.js +1 -0
  50. package/static/dist/{src__pages__script__editNameModal.d2c2b500.async.js → src__pages__script__editNameModal.159d0a29.async.js} +1 -1
  51. package/static/dist/src__pages__script__index.123b12c6.async.js +1 -0
  52. package/static/dist/src__pages__script__renameModal.d4788f88.async.js +1 -0
  53. package/static/dist/src__pages__script__saveModal.f5fc2c94.async.js +1 -0
  54. package/static/dist/src__pages__script__setting.5004f9a6.async.js +1 -0
  55. package/static/dist/src__pages__setting__about.ef6f0636.async.js +1 -0
  56. package/static/dist/src__pages__setting__appModal.52ba0fb4.async.js +1 -0
  57. package/static/dist/src__pages__setting__index.ccb20d34.async.js +1 -0
  58. package/static/dist/src__pages__setting__notification.4f6be181.async.js +1 -0
  59. package/static/dist/src__pages__setting__other.ef42b461.async.js +1 -0
  60. package/static/dist/src__pages__setting__security.fed987f7.async.js +1 -0
  61. package/static/dist/{src__pages__subscription__index.373b2030.async.js → src__pages__subscription__index.a434b6c5.async.js} +1 -1
  62. package/static/dist/{src__pages__subscription__logModal.1acd5872.async.js → src__pages__subscription__logModal.3037cb57.async.js} +1 -1
  63. package/static/dist/src__pages__subscription__modal.91d85c79.async.js +1 -0
  64. package/static/dist/umi.435eb7e2.js +1 -0
  65. package/version.yaml +12 -9
  66. package/static/dist/3330.6b55d282.async.js +0 -1
  67. package/static/dist/8044.b4f59bd9.async.js +0 -1
  68. package/static/dist/819.14ef9416.async.js +0 -1
  69. package/static/dist/9532.af314989.async.js +0 -1
  70. package/static/dist/layouts__index.dc3fe99d.chunk.css +0 -1
  71. package/static/dist/src__pages__config__index.34473d74.async.js +0 -1
  72. package/static/dist/src__pages__crontab__index.7443956f.async.js +0 -1
  73. package/static/dist/src__pages__crontab__modal.e43fadf0.async.js +0 -1
  74. package/static/dist/src__pages__dependence__logModal.5632c2df.async.js +0 -1
  75. package/static/dist/src__pages__dependence__modal.0e940eb0.async.js +0 -1
  76. package/static/dist/src__pages__diff__index.630603fc.async.js +0 -1
  77. package/static/dist/src__pages__env__editNameModal.a1f5c3e1.async.js +0 -1
  78. package/static/dist/src__pages__env__index.03e934be.async.js +0 -1
  79. package/static/dist/src__pages__env__modal.c44800ec.async.js +0 -1
  80. package/static/dist/src__pages__error__index.521fde97.async.js +0 -1
  81. package/static/dist/src__pages__initialization__index.0e4d45ef.async.js +0 -1
  82. package/static/dist/src__pages__script__editModal.7bec90a6.async.js +0 -1
  83. package/static/dist/src__pages__script__index.f666bbf7.async.js +0 -1
  84. package/static/dist/src__pages__script__renameModal.03a9a63a.async.js +0 -1
  85. package/static/dist/src__pages__script__saveModal.fe022069.async.js +0 -1
  86. package/static/dist/src__pages__script__setting.25861cb9.async.js +0 -1
  87. package/static/dist/src__pages__setting__about.5343d1cb.async.js +0 -1
  88. package/static/dist/src__pages__setting__appModal.b0f04766.async.js +0 -1
  89. package/static/dist/src__pages__setting__index.6cfb3c67.async.js +0 -1
  90. package/static/dist/src__pages__setting__notification.566573dd.async.js +0 -1
  91. package/static/dist/src__pages__setting__other.5babac76.async.js +0 -1
  92. package/static/dist/src__pages__setting__security.ef345c25.async.js +0 -1
  93. package/static/dist/src__pages__subscription__modal.01b60226.async.js +0 -1
  94. package/static/dist/umi.adda7a82.js +0 -1
package/docker/Dockerfile CHANGED
@@ -41,6 +41,7 @@ RUN set -x && \
41
41
  tzdata \
42
42
  perl \
43
43
  openssl \
44
+ openssh-client \
44
45
  nginx \
45
46
  jq \
46
47
  procps \
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whyour/qinglong",
3
- "version": "0.9.2",
3
+ "version": "0.10.0",
4
4
  "description": "Timed task management platform supporting Python3, JavaScript, Shell, Typescript",
5
5
  "repository": {
6
6
  "type": "git",
package/sample/notify.py CHANGED
@@ -456,7 +456,7 @@ class WeCom:
456
456
  return respone["errmsg"]
457
457
 
458
458
  def send_mpnews(self, title, message, media_id, touser="@all"):
459
- send_url = f"https://{self.ORIGIN}/cgi-bin/message/send?access_token={self.get_access_token()}"
459
+ send_url = f"{self.ORIGIN}/cgi-bin/message/send?access_token={self.get_access_token()}"
460
460
  send_values = {
461
461
  "touser": touser,
462
462
  "msgtype": "mpnews",
package/shell/api.sh CHANGED
@@ -36,7 +36,7 @@ add_cron_api() {
36
36
  local sub_id="$4"
37
37
  fi
38
38
 
39
- if [[ ! $sub_id ]];then
39
+ if [[ ! $sub_id ]]; then
40
40
  sub_id="null"
41
41
  fi
42
42
 
package/shell/otask.sh CHANGED
@@ -70,6 +70,11 @@ run_nohup() {
70
70
  }
71
71
 
72
72
 
73
+ env_str_to_array() {
74
+ local IFS="&"
75
+ read -ra array <<<"${!env_param}"
76
+ }
77
+
73
78
  ## 正常运行单个脚本,$1:传入参数
74
79
  run_normal() {
75
80
  local file_param=$1
@@ -97,8 +102,7 @@ run_concurrent() {
97
102
  exit 1
98
103
  fi
99
104
 
100
- local envs=$(eval echo "\$${env_param}")
101
- local array=($(echo $envs | sed 's/&/ /g'))
105
+ env_str_to_array
102
106
  local tempArr=$(echo $num_param | sed "s/-max/-${#array[@]}/g" | sed "s/max-/${#array[@]}-/g" | perl -pe "s|(\d+)(-\|~\|_)(\d+)|{\1..\3}|g")
103
107
  local runArr=($(eval echo $tempArr))
104
108
  runArr=($(awk -v RS=' ' '!a[$1]++' <<<${runArr[@]}))
@@ -109,11 +113,13 @@ run_concurrent() {
109
113
  let n++
110
114
  done
111
115
 
112
- local cookieStr=$(echo ${array_run[*]} | sed 's/\ /\&/g')
113
- [[ ! -z $cookieStr ]] && export ${env_param}=${cookieStr}
116
+ local cookieStr=$(
117
+ IFS="&"
118
+ echo "${array_run[*]}"
119
+ )
120
+ [[ ! -z $cookieStr ]] && export "${env_param}=${cookieStr}"
114
121
 
115
- local envs=$(eval echo "\$${env_param}")
116
- local array=($(echo $envs | sed 's/&/ /g'))
122
+ env_str_to_array
117
123
  single_log_time=$(date "+%Y-%m-%d-%H-%M-%S.%3N")
118
124
 
119
125
  cd $dir_scripts
@@ -123,7 +129,7 @@ run_concurrent() {
123
129
  file_param=${file_param/$relative_path\//}
124
130
  fi
125
131
  for i in "${!array[@]}"; do
126
- export ${env_param}=${array[i]}
132
+ export "${env_param}=${array[i]}"
127
133
  single_log_path="$dir_log/$log_dir/${single_log_time}_$((i + 1)).log"
128
134
  eval $timeoutCmd $which_program $file_param &>$single_log_path &
129
135
  done
@@ -145,8 +151,7 @@ run_designated() {
145
151
  exit 1
146
152
  fi
147
153
 
148
- local envs=$(eval echo "\$${env_param}")
149
- local array=($(echo $envs | sed 's/&/ /g'))
154
+ env_str_to_array
150
155
  local tempArr=$(echo $num_param | sed "s/-max/-${#array[@]}/g" | sed "s/max-/${#array[@]}-/g" | perl -pe "s|(\d+)(-\|~\|_)(\d+)|{\1..\3}|g")
151
156
  local runArr=($(eval echo $tempArr))
152
157
  runArr=($(awk -v RS=' ' '!a[$1]++' <<<${runArr[@]}))
@@ -157,8 +162,11 @@ run_designated() {
157
162
  let n++
158
163
  done
159
164
 
160
- local cookieStr=$(echo ${array_run[*]} | sed 's/\ /\&/g')
161
- [[ ! -z $cookieStr ]] && export ${env_param}=${cookieStr}
165
+ local cookieStr=$(
166
+ IFS="&"
167
+ echo "${array_run[*]}"
168
+ )
169
+ [[ ! -z $cookieStr ]] && export "${env_param}=${cookieStr}"
162
170
 
163
171
  cd $dir_scripts
164
172
  local relative_path="${file_param%/*}"
package/shell/start.sh CHANGED
@@ -43,15 +43,14 @@ if [[ $os_name == 'alpine' ]]; then
43
43
  jq \
44
44
  nginx \
45
45
  openssh \
46
- openssh-client \
47
46
  procps \
48
47
  netcat-openbsd
49
48
  elif [[ $os_name == 'debian' ]] || [[ $os_name == 'ubuntu' ]]; then
50
49
  apt update
51
- apt install -y git curl wget tzdata perl openssl jq nginx procps netcat
50
+ apt install -y git curl wget tzdata perl openssl jq nginx procps netcat openssh-client
52
51
  elif [[ $os_name == 'centos' ]]; then
53
52
  yum update
54
- yum install -y epel-release git curl wget tzdata perl openssl jq nginx procps netcat
53
+ yum install -y epel-release git curl wget tzdata perl openssl jq nginx procps netcat openssh-client
55
54
  else
56
55
  echo -e "暂不支持此系统部署 $os_name"
57
56
  exit 1
package/shell/task.sh CHANGED
@@ -69,7 +69,7 @@ handle_log_path() {
69
69
  if [[ $real_log_path ]]; then
70
70
  log_path="$real_log_path"
71
71
  fi
72
-
72
+
73
73
  cmd=">> $dir_log/$log_path 2>&1"
74
74
  make_dir "$dir_log/$log_dir"
75
75
  if [[ "$show_log" == "true" ]]; then
package/shell/update.sh CHANGED
@@ -31,7 +31,7 @@ output_list_add_drop() {
31
31
  local list=$1
32
32
  local type=$2
33
33
  if [[ -s $list ]]; then
34
- echo -e "检测到有${type}的定时任务:\n"
34
+ echo -e "检测到有${type}的定时任务:"
35
35
  cat $list
36
36
  echo
37
37
  fi
@@ -134,10 +134,10 @@ update_repo() {
134
134
  git_clone_scripts "${formatUrl}" ${repo_path} "${branch}" "${proxy}"
135
135
 
136
136
  if [[ $exit_status -eq 0 ]]; then
137
- echo -e "\n更新${repo_path}成功...\n"
137
+ echo -e "\n拉取 ${uniq_path} 成功...\n"
138
138
  diff_scripts "$repo_path" "$author" "$path" "$blackword" "$dependence" "$extensions" "$autoAddCron" "$autoDelCron"
139
139
  else
140
- echo -e "\n更新${repo_path}失败,请检查网络...\n"
140
+ echo -e "\n拉取 ${uniq_path} 失败,请检查网络...\n"
141
141
  fi
142
142
  }
143
143
 
@@ -10,6 +10,7 @@ const celebrate_1 = require("celebrate");
10
10
  const multer_1 = __importDefault(require("multer"));
11
11
  const config_1 = __importDefault(require("../config"));
12
12
  const fs_1 = __importDefault(require("fs"));
13
+ const util_1 = require("../config/util");
13
14
  const route = (0, express_1.Router)();
14
15
  const storage = multer_1.default.diskStorage({
15
16
  destination: function (req, file, cb) {
@@ -164,7 +165,7 @@ exports.default = (app) => {
164
165
  try {
165
166
  const envService = typedi_1.Container.get(env_1.default);
166
167
  const fileContent = await fs_1.default.promises.readFile(req.file.path, 'utf8');
167
- const parseContent = JSON.parse(fileContent);
168
+ const parseContent = (0, util_1.safeJSONParse)(fileContent);
168
169
  const data = Array.isArray(parseContent)
169
170
  ? parseContent
170
171
  : [parseContent];
@@ -223,8 +223,10 @@ exports.default = (app) => {
223
223
  let { filename, path, pid } = req.body;
224
224
  const { name, ext } = (0, path_1.parse)(filename);
225
225
  const filePath = (0, path_1.join)(config_1.default.scriptPath, path, `${name}.swap${ext}`);
226
+ const logPath = (0, path_1.join)(config_1.default.logPath, path, `${name}.swap`);
226
227
  const scriptService = typedi_1.Container.get(script_1.default);
227
228
  const result = await scriptService.stopScript(filePath, pid);
229
+ (0, util_1.emptyDir)(logPath);
228
230
  res.send(result);
229
231
  }
230
232
  catch (e) {
@@ -164,7 +164,10 @@ exports.default = (app) => {
164
164
  }), async (req, res, next) => {
165
165
  try {
166
166
  const systemService = typedi_1.Container.get(system_1.default);
167
- const uniqPath = await (0, util_1.getUniqPath)(req.body.command);
167
+ const command = req.body.command;
168
+ const idStr = `cat ${config_1.default.crontabFile} | grep -E "${command}" | perl -pe "s|.*ID=(.*) ${command}.*|\\1|" | head -1 | awk -F " " '{print $1}' | xargs echo -n`;
169
+ let id = await (0, util_1.promiseExec)(idStr);
170
+ const uniqPath = await (0, util_1.getUniqPath)(command, id);
168
171
  const logTime = (0, dayjs_1.default)().format('YYYY-MM-DD-HH-mm-ss-SSS');
169
172
  const logPath = `${uniqPath}/${logTime}.log`;
170
173
  res.setHeader('Content-type', 'application/octet-stream');
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const dotenv_1 = __importDefault(require("dotenv"));
7
7
  const path_1 = __importDefault(require("path"));
8
- const util_1 = require("./util");
8
+ const share_1 = require("./share");
9
9
  process.env.NODE_ENV = process.env.NODE_ENV || 'development';
10
10
  if (!process.env.QL_DIR) {
11
11
  // 声明QL_DIR环境变量
@@ -55,7 +55,7 @@ exports.default = {
55
55
  port: parseInt(process.env.BACK_PORT, 10),
56
56
  cronPort: parseInt(process.env.CRON_PORT, 10),
57
57
  publicPort: parseInt(process.env.PUBLIC_PORT, 10),
58
- secret: process.env.SECRET || (0, util_1.createRandomString)(16, 32),
58
+ secret: process.env.SECRET || (0, share_1.createRandomString)(16, 32),
59
59
  logs: {
60
60
  level: process.env.LOG_LEVEL || 'silly',
61
61
  },
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createRandomString = void 0;
4
+ function createRandomString(min, max) {
5
+ const num = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
6
+ const english = [
7
+ 'a',
8
+ 'b',
9
+ 'c',
10
+ 'd',
11
+ 'e',
12
+ 'f',
13
+ 'g',
14
+ 'h',
15
+ 'i',
16
+ 'j',
17
+ 'k',
18
+ 'l',
19
+ 'm',
20
+ 'n',
21
+ 'o',
22
+ 'p',
23
+ 'q',
24
+ 'r',
25
+ 's',
26
+ 't',
27
+ 'u',
28
+ 'v',
29
+ 'w',
30
+ 'x',
31
+ 'y',
32
+ 'z',
33
+ ];
34
+ const ENGLISH = [
35
+ 'A',
36
+ 'B',
37
+ 'C',
38
+ 'D',
39
+ 'E',
40
+ 'F',
41
+ 'G',
42
+ 'H',
43
+ 'I',
44
+ 'J',
45
+ 'K',
46
+ 'L',
47
+ 'M',
48
+ 'N',
49
+ 'O',
50
+ 'P',
51
+ 'Q',
52
+ 'R',
53
+ 'S',
54
+ 'T',
55
+ 'U',
56
+ 'V',
57
+ 'W',
58
+ 'X',
59
+ 'Y',
60
+ 'Z',
61
+ ];
62
+ const special = ['-', '_'];
63
+ const config = num.concat(english).concat(ENGLISH).concat(special);
64
+ const arr = [];
65
+ arr.push(getOne(num));
66
+ arr.push(getOne(english));
67
+ arr.push(getOne(ENGLISH));
68
+ arr.push(getOne(special));
69
+ const len = min + Math.floor(Math.random() * (max - min + 1));
70
+ for (let i = 4; i < len; i++) {
71
+ arr.push(config[Math.floor(Math.random() * config.length)]);
72
+ }
73
+ const newArr = [];
74
+ for (let j = 0; j < len; j++) {
75
+ newArr.push(arr.splice(Math.random() * arr.length, 1)[0]);
76
+ }
77
+ function getOne(arr) {
78
+ return arr[Math.floor(Math.random() * arr.length)];
79
+ }
80
+ return newArr.join('');
81
+ }
82
+ exports.createRandomString = createRandomString;
83
+ //# sourceMappingURL=share.js.map
@@ -22,11 +22,14 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
+ };
25
28
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
29
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
30
  };
28
31
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.getUniqPath = exports.parseContentVersion = exports.parseVersion = exports.getPid = exports.killTask = exports.psTree = exports.parseBody = exports.parseHeaders = exports.promiseExecSuccess = exports.promiseExec = exports.emptyDir = exports.readDir = exports.readDirs = exports.dirSort = exports.concurrentRun = exports.handleLogPath = exports.createFile = exports.fileExist = exports.getPlatform = exports.getNetIp = exports.getToken = exports.createRandomString = exports.getLastModifyFilePath = exports.getFileContentByName = void 0;
32
+ exports.safeJSONParse = exports.getUniqPath = exports.parseContentVersion = exports.parseVersion = exports.getPid = exports.killTask = exports.psTree = exports.parseBody = exports.parseHeaders = exports.promiseExecSuccess = exports.promiseExec = exports.emptyDir = exports.readDir = exports.readDirs = exports.dirSort = exports.concurrentRun = exports.handleLogPath = exports.createFile = exports.fileExist = exports.getPlatform = exports.getNetIp = exports.getToken = exports.getLastModifyFilePath = exports.getFileContentByName = void 0;
30
33
  const fs = __importStar(require("fs"));
31
34
  const path = __importStar(require("path"));
32
35
  const got_1 = __importDefault(require("got"));
@@ -38,6 +41,8 @@ const util_1 = require("util");
38
41
  const js_yaml_1 = require("js-yaml");
39
42
  const index_1 = __importDefault(require("./index"));
40
43
  const const_1 = require("./const");
44
+ const logger_1 = __importDefault(require("../loaders/logger"));
45
+ __exportStar(require("./share"), exports);
41
46
  function getFileContentByName(fileName) {
42
47
  if (fs.existsSync(fileName)) {
43
48
  return fs.readFileSync(fileName, 'utf8');
@@ -62,85 +67,6 @@ function getLastModifyFilePath(dir) {
62
67
  return filePath;
63
68
  }
64
69
  exports.getLastModifyFilePath = getLastModifyFilePath;
65
- function createRandomString(min, max) {
66
- const num = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
67
- const english = [
68
- 'a',
69
- 'b',
70
- 'c',
71
- 'd',
72
- 'e',
73
- 'f',
74
- 'g',
75
- 'h',
76
- 'i',
77
- 'j',
78
- 'k',
79
- 'l',
80
- 'm',
81
- 'n',
82
- 'o',
83
- 'p',
84
- 'q',
85
- 'r',
86
- 's',
87
- 't',
88
- 'u',
89
- 'v',
90
- 'w',
91
- 'x',
92
- 'y',
93
- 'z',
94
- ];
95
- const ENGLISH = [
96
- 'A',
97
- 'B',
98
- 'C',
99
- 'D',
100
- 'E',
101
- 'F',
102
- 'G',
103
- 'H',
104
- 'I',
105
- 'J',
106
- 'K',
107
- 'L',
108
- 'M',
109
- 'N',
110
- 'O',
111
- 'P',
112
- 'Q',
113
- 'R',
114
- 'S',
115
- 'T',
116
- 'U',
117
- 'V',
118
- 'W',
119
- 'X',
120
- 'Y',
121
- 'Z',
122
- ];
123
- const special = ['-', '_'];
124
- const config = num.concat(english).concat(ENGLISH).concat(special);
125
- const arr = [];
126
- arr.push(getOne(num));
127
- arr.push(getOne(english));
128
- arr.push(getOne(ENGLISH));
129
- arr.push(getOne(special));
130
- const len = min + Math.floor(Math.random() * (max - min + 1));
131
- for (let i = 4; i < len; i++) {
132
- arr.push(config[Math.floor(Math.random() * config.length)]);
133
- }
134
- const newArr = [];
135
- for (let j = 0; j < len; j++) {
136
- newArr.push(arr.splice(Math.random() * arr.length, 1)[0]);
137
- }
138
- function getOne(arr) {
139
- return arr[Math.floor(Math.random() * arr.length)];
140
- }
141
- return newArr.join('');
142
- }
143
- exports.createRandomString = createRandomString;
144
70
  function getToken(req) {
145
71
  const { authorization = '' } = req.headers;
146
72
  if (authorization && authorization.split(' ')[0] === 'Bearer') {
@@ -507,10 +433,8 @@ async function parseContentVersion(content) {
507
433
  return (0, js_yaml_1.load)(content);
508
434
  }
509
435
  exports.parseContentVersion = parseContentVersion;
510
- async function getUniqPath(command) {
511
- const idStr = `cat ${index_1.default.crontabFile} | grep -E "${command}" | perl -pe "s|.*ID=(.*) ${command}.*|\\1|" | head -1 | awk -F " " '{print $1}' | xargs echo -n`;
512
- let id = await promiseExec(idStr);
513
- if (/^\d\d*\d$/.test(id)) {
436
+ async function getUniqPath(command, id) {
437
+ if (/^\d+$/.test(id)) {
514
438
  id = `_${id}`;
515
439
  }
516
440
  else {
@@ -538,4 +462,17 @@ async function getUniqPath(command) {
538
462
  return `${str}${id}`;
539
463
  }
540
464
  exports.getUniqPath = getUniqPath;
465
+ function safeJSONParse(value) {
466
+ if (!value) {
467
+ return {};
468
+ }
469
+ try {
470
+ return JSON.parse(value);
471
+ }
472
+ catch (error) {
473
+ logger_1.default.error('[JSON.parse失败]', error);
474
+ return {};
475
+ }
476
+ }
477
+ exports.safeJSONParse = safeJSONParse;
541
478
  //# sourceMappingURL=util.js.map
@@ -50,7 +50,7 @@ exports.default = ({ app }) => {
50
50
  app.get(`${config_1.default.api.prefix}/env.js`, serverEnv_1.serveEnv);
51
51
  app.use(`${config_1.default.api.prefix}/static`, express_1.default.static(config_1.default.uploadPath));
52
52
  app.use('/api/public', (0, http_proxy_middleware_1.createProxyMiddleware)({
53
- target: `http://localhost:${config_1.default.publicPort}/api`,
53
+ target: `http://0.0.0.0:${config_1.default.publicPort}/api`,
54
54
  changeOrigin: true,
55
55
  pathRewrite: { '/api/public': '' },
56
56
  logProvider: () => logger_1.default
@@ -97,7 +97,7 @@ exports.default = ({ app }) => {
97
97
  }
98
98
  const data = fs_1.default.readFileSync(config_1.default.authConfigFile, 'utf8');
99
99
  if (data && headerToken) {
100
- const { token = '', tokens = {} } = JSON.parse(data);
100
+ const { token = '', tokens = {} } = (0, util_1.safeJSONParse)(data);
101
101
  if (headerToken === token || tokens[req.platform] === headerToken) {
102
102
  return next();
103
103
  }
@@ -20,7 +20,7 @@ exports.default = async ({ server }) => {
20
20
  const platform = (0, util_1.getPlatform)(conn.headers['user-agent'] || '') || 'desktop';
21
21
  const headerToken = conn.url.replace(`${conn.pathname}?token=`, '');
22
22
  if (data) {
23
- const { token = '', tokens = {} } = JSON.parse(data);
23
+ const { token = '', tokens = {} } = (0, util_1.safeJSONParse)(data);
24
24
  if (headerToken === token || tokens[platform] === headerToken) {
25
25
  conn.write(JSON.stringify({ type: 'ping', message: 'hanhh' }));
26
26
  sockService.addClient(conn);
@@ -9,7 +9,6 @@ const data_1 = require("./data");
9
9
  const runCron_1 = require("../shared/runCron");
10
10
  const const_1 = require("../config/const");
11
11
  const logger_1 = __importDefault(require("../loaders/logger"));
12
- const dayjs_1 = __importDefault(require("dayjs"));
13
12
  const addCron = (call, callback) => {
14
13
  var _a;
15
14
  for (const item of call.request.crons) {
@@ -23,7 +22,7 @@ const addCron = (call, callback) => {
23
22
  }
24
23
  logger_1.default.info('[schedule][创建定时任务], 任务ID: %s, cron: %s, 执行命令: %s', id, schedule, command);
25
24
  data_1.scheduleStacks.set(id, node_schedule_1.default.scheduleJob(id, schedule, async () => {
26
- logger_1.default.info(`[schedule] 时间: ${(0, dayjs_1.default)().format('YYYY-MM-DD HH:mm:ss')},运行命令: ${cmdStr}`);
25
+ logger_1.default.info(`[schedule][准备运行任务] 命令: ${cmdStr}`);
27
26
  (0, runCron_1.runCron)(`ID=${id} ${cmdStr}`);
28
27
  }));
29
28
  }
@@ -8,7 +8,7 @@ const cron_1 = require("../protos/cron");
8
8
  const config_1 = __importDefault(require("../config"));
9
9
  class Client {
10
10
  constructor() {
11
- this.client = new cron_1.CronClient(`localhost:${config_1.default.cronPort}`, grpc_js_1.credentials.createInsecure());
11
+ this.client = new cron_1.CronClient(`0.0.0.0:${config_1.default.cronPort}`, grpc_js_1.credentials.createInsecure());
12
12
  }
13
13
  addCron(request) {
14
14
  return new Promise((resolve, reject) => {
@@ -9,7 +9,7 @@ const util_1 = require("../config/util");
9
9
  const check = async (call, callback) => {
10
10
  switch (call.request.service) {
11
11
  case 'cron':
12
- const res = await (0, util_1.promiseExec)(`curl -s http://localhost:${config_1.default.port}/api/system`);
12
+ const res = await (0, util_1.promiseExec)(`curl -s http://0.0.0.0:${config_1.default.port}/api/system`);
13
13
  if (res.includes('200')) {
14
14
  return callback(null, { status: 1 });
15
15
  }
@@ -30,6 +30,7 @@ const const_1 = require("../config/const");
30
30
  const client_1 = __importDefault(require("../schedule/client"));
31
31
  const pLimit_1 = __importDefault(require("../shared/pLimit"));
32
32
  const cross_spawn_1 = require("cross-spawn");
33
+ const dayjs_1 = __importDefault(require("dayjs"));
33
34
  let CronService = class CronService {
34
35
  constructor(logger) {
35
36
  this.logger = logger;
@@ -274,9 +275,9 @@ let CronService = class CronService {
274
275
  const searchText = params === null || params === void 0 ? void 0 : params.searchValue;
275
276
  const page = Number((params === null || params === void 0 ? void 0 : params.page) || '0');
276
277
  const size = Number((params === null || params === void 0 ? void 0 : params.size) || '0');
277
- const viewQuery = JSON.parse((params === null || params === void 0 ? void 0 : params.queryString) || '{}');
278
- const filterQuery = JSON.parse((params === null || params === void 0 ? void 0 : params.filters) || '{}');
279
- const sorterQuery = JSON.parse((params === null || params === void 0 ? void 0 : params.sorter) || '{}');
278
+ const viewQuery = (0, util_1.safeJSONParse)(params === null || params === void 0 ? void 0 : params.queryString);
279
+ const filterQuery = (0, util_1.safeJSONParse)(params === null || params === void 0 ? void 0 : params.filters);
280
+ const sorterQuery = (0, util_1.safeJSONParse)(params === null || params === void 0 ? void 0 : params.sorter);
280
281
  let query = {};
281
282
  let order = [
282
283
  ['isPinned', 'DESC'],
@@ -338,14 +339,21 @@ let CronService = class CronService {
338
339
  async runSingle(cronId) {
339
340
  return pLimit_1.default.runWithCpuLimit(() => {
340
341
  return new Promise(async (resolve) => {
342
+ var _a;
341
343
  const cron = await this.getDb({ id: cronId });
342
344
  if (cron.status !== cron_1.CrontabStatus.queued) {
343
345
  resolve();
344
346
  return;
345
347
  }
346
348
  let { id, command, log_path } = cron;
347
- const absolutePath = path_1.default.resolve(config_1.default.logPath, `${log_path}`);
348
- const logFileExist = log_path && (await (0, util_1.fileExist)(absolutePath));
349
+ const uniqPath = await (0, util_1.getUniqPath)(command, `${id}`);
350
+ const logTime = (0, dayjs_1.default)().format('YYYY-MM-DD-HH-mm-ss-SSS');
351
+ const logDirPath = path_1.default.resolve(config_1.default.logPath, `${uniqPath}`);
352
+ if ((_a = log_path === null || log_path === void 0 ? void 0 : log_path.split('/')) === null || _a === void 0 ? void 0 : _a.every(x => x !== uniqPath)) {
353
+ fs_1.default.mkdirSync(logDirPath, { recursive: true });
354
+ }
355
+ const logPath = `${uniqPath}/${logTime}.log`;
356
+ const absolutePath = path_1.default.resolve(config_1.default.logPath, `${logPath}`);
349
357
  this.logger.silly('Running job');
350
358
  this.logger.silly('ID: ' + id);
351
359
  this.logger.silly('Original command: ' + command);
@@ -360,20 +368,16 @@ let CronService = class CronService {
360
368
  cmdStr.endsWith('.ts')) {
361
369
  cmdStr = `${cmdStr} now`;
362
370
  }
363
- const cp = (0, cross_spawn_1.spawn)(`ID=${id} ${cmdStr}`, { shell: '/bin/bash' });
364
- await cron_1.CrontabModel.update({ status: cron_1.CrontabStatus.running, pid: cp.pid }, { where: { id } });
371
+ const cp = (0, cross_spawn_1.spawn)(`real_log_path=${logPath} ID=${id} ${cmdStr}`, { shell: '/bin/bash' });
372
+ await cron_1.CrontabModel.update({ status: cron_1.CrontabStatus.running, pid: cp.pid, log_path: logPath }, { where: { id } });
365
373
  cp.stderr.on('data', (data) => {
366
- if (logFileExist) {
367
- fs_1.default.appendFileSync(`${absolutePath}`, `${data.toString()}`);
368
- }
374
+ fs_1.default.appendFileSync(`${absolutePath}`, `${data.toString()}`);
369
375
  });
370
376
  cp.on('error', (err) => {
371
- if (logFileExist) {
372
- fs_1.default.appendFileSync(`${absolutePath}`, `${JSON.stringify(err)}`);
373
- }
377
+ fs_1.default.appendFileSync(`${absolutePath}`, `${JSON.stringify(err)}`);
374
378
  });
375
379
  cp.on('exit', async (code, signal) => {
376
- this.logger.info(`任务 ${command} 进程id: ${cp.pid} 退出,退出码 ${code}`);
380
+ this.logger.info(`[panel][任务退出] 任务 ${command} 进程id: ${cp.pid}, 退出码 ${code}`);
377
381
  });
378
382
  cp.on('close', async (code) => {
379
383
  await cron_1.CrontabModel.update({ status: cron_1.CrontabStatus.idle, pid: undefined }, { where: { id } });
@@ -198,11 +198,9 @@ let EnvService = class EnvService {
198
198
  let value = group
199
199
  .map((x) => x.value)
200
200
  .join('&')
201
- .replace(/(\\)[^n]/g, '\\\\')
202
- .replace(/(\\$)/, '\\\\')
203
- .replace(/"/g, '\\"')
201
+ .replace(/'/g, "'\\''")
204
202
  .trim();
205
- env_string += `export ${key}="${value}"\n`;
203
+ env_string += `export ${key}='${value}'\n`;
206
204
  }
207
205
  }
208
206
  }