@whyour/qinglong 0.9.3 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/sample/notify.py +1 -1
- package/shell/api.sh +1 -1
- package/shell/otask.sh +19 -11
- package/shell/task.sh +1 -1
- package/shell/update.sh +3 -3
- package/static/build/api/env.js +2 -1
- package/static/build/api/script.js +2 -0
- package/static/build/api/system.js +4 -1
- package/static/build/config/index.js +2 -2
- package/static/build/config/share.js +83 -0
- package/static/build/config/util.js +21 -84
- package/static/build/loaders/express.js +2 -2
- package/static/build/loaders/sock.js +1 -1
- package/static/build/schedule/addCron.js +1 -2
- package/static/build/schedule/client.js +1 -1
- package/static/build/schedule/health.js +1 -1
- package/static/build/services/cron.js +18 -14
- package/static/build/services/env.js +2 -4
- package/static/build/services/schedule.js +8 -8
- package/static/build/services/script.js +0 -1
- package/static/build/services/subscription.js +0 -3
- package/static/build/services/user.js +1 -1
- package/static/build/shared/pLimit.js +8 -0
- package/static/build/shared/runCron.js +2 -2
- package/static/dist/3330.485d94a3.async.js +1 -0
- package/static/dist/{4714.4abfa66f.async.js → 4714.bbe9fae0.async.js} +1 -1
- package/static/dist/8044.129359a6.async.js +1 -0
- package/static/dist/819.525cbfda.async.js +1 -0
- package/static/dist/index.html +1 -1
- package/static/dist/layouts__index.ddfcd364.chunk.css +1 -0
- package/static/dist/src__pages__config__index.fedea3f9.async.js +1 -0
- package/static/dist/{src__pages__crontab__detail.91b2b006.async.js → src__pages__crontab__detail.ad4729f7.async.js} +1 -1
- package/static/dist/{src__pages__crontab__index.502a1f71.chunk.css → src__pages__crontab__index.6c7b7b2c.chunk.css} +1 -1
- package/static/dist/src__pages__crontab__index.a82cfa81.async.js +1 -0
- package/static/dist/{src__pages__crontab__logModal.a0c9c75c.async.js → src__pages__crontab__logModal.ad170a0f.async.js} +1 -1
- package/static/dist/src__pages__crontab__modal.696faf3d.async.js +1 -0
- package/static/dist/{src__pages__dependence__index.20e51efb.async.js → src__pages__dependence__index.9f871d7e.async.js} +1 -1
- package/static/dist/src__pages__dependence__logModal.b8dfb9bf.async.js +1 -0
- package/static/dist/src__pages__dependence__modal.77688c64.async.js +1 -0
- package/static/dist/src__pages__diff__index.73c27cfb.async.js +1 -0
- package/static/dist/src__pages__env__editNameModal.0b8b8511.async.js +1 -0
- package/static/dist/src__pages__env__index.c2e7f61a.async.js +1 -0
- package/static/dist/src__pages__env__modal.d4bcf3f1.async.js +1 -0
- package/static/dist/src__pages__error__index.9d76a461.async.js +1 -0
- package/static/dist/src__pages__initialization__index.7cb87ba4.async.js +1 -0
- package/static/dist/src__pages__script__editModal.dddd633e.async.js +1 -0
- package/static/dist/{src__pages__script__editNameModal.d2c2b500.async.js → src__pages__script__editNameModal.159d0a29.async.js} +1 -1
- package/static/dist/src__pages__script__index.123b12c6.async.js +1 -0
- package/static/dist/src__pages__script__renameModal.d4788f88.async.js +1 -0
- package/static/dist/src__pages__script__saveModal.f5fc2c94.async.js +1 -0
- package/static/dist/src__pages__script__setting.5004f9a6.async.js +1 -0
- package/static/dist/src__pages__setting__about.ef6f0636.async.js +1 -0
- package/static/dist/src__pages__setting__appModal.52ba0fb4.async.js +1 -0
- package/static/dist/src__pages__setting__index.ccb20d34.async.js +1 -0
- package/static/dist/src__pages__setting__notification.4f6be181.async.js +1 -0
- package/static/dist/src__pages__setting__other.ef42b461.async.js +1 -0
- package/static/dist/src__pages__setting__security.fed987f7.async.js +1 -0
- package/static/dist/{src__pages__subscription__index.373b2030.async.js → src__pages__subscription__index.a434b6c5.async.js} +1 -1
- package/static/dist/{src__pages__subscription__logModal.1acd5872.async.js → src__pages__subscription__logModal.3037cb57.async.js} +1 -1
- package/static/dist/src__pages__subscription__modal.91d85c79.async.js +1 -0
- package/static/dist/umi.740bd8f7.js +1 -0
- package/version.yaml +12 -9
- package/static/dist/3330.6b55d282.async.js +0 -1
- package/static/dist/8044.b4f59bd9.async.js +0 -1
- package/static/dist/819.14ef9416.async.js +0 -1
- package/static/dist/9532.af314989.async.js +0 -1
- package/static/dist/layouts__index.dc3fe99d.chunk.css +0 -1
- package/static/dist/src__pages__config__index.34473d74.async.js +0 -1
- package/static/dist/src__pages__crontab__index.7443956f.async.js +0 -1
- package/static/dist/src__pages__crontab__modal.e43fadf0.async.js +0 -1
- package/static/dist/src__pages__dependence__logModal.5632c2df.async.js +0 -1
- package/static/dist/src__pages__dependence__modal.0e940eb0.async.js +0 -1
- package/static/dist/src__pages__diff__index.630603fc.async.js +0 -1
- package/static/dist/src__pages__env__editNameModal.a1f5c3e1.async.js +0 -1
- package/static/dist/src__pages__env__index.03e934be.async.js +0 -1
- package/static/dist/src__pages__env__modal.c44800ec.async.js +0 -1
- package/static/dist/src__pages__error__index.521fde97.async.js +0 -1
- package/static/dist/src__pages__initialization__index.0e4d45ef.async.js +0 -1
- package/static/dist/src__pages__script__editModal.7bec90a6.async.js +0 -1
- package/static/dist/src__pages__script__index.f666bbf7.async.js +0 -1
- package/static/dist/src__pages__script__renameModal.03a9a63a.async.js +0 -1
- package/static/dist/src__pages__script__saveModal.fe022069.async.js +0 -1
- package/static/dist/src__pages__script__setting.25861cb9.async.js +0 -1
- package/static/dist/src__pages__setting__about.5343d1cb.async.js +0 -1
- package/static/dist/src__pages__setting__appModal.b0f04766.async.js +0 -1
- package/static/dist/src__pages__setting__index.6cfb3c67.async.js +0 -1
- package/static/dist/src__pages__setting__notification.566573dd.async.js +0 -1
- package/static/dist/src__pages__setting__other.5babac76.async.js +0 -1
- package/static/dist/src__pages__setting__security.ef345c25.async.js +0 -1
- package/static/dist/src__pages__subscription__modal.01b60226.async.js +0 -1
- package/static/dist/umi.adda7a82.js +0 -1
package/package.json
CHANGED
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"
|
|
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
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
|
-
|
|
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=$(
|
|
113
|
-
|
|
116
|
+
local cookieStr=$(
|
|
117
|
+
IFS="&"
|
|
118
|
+
echo "${array_run[*]}"
|
|
119
|
+
)
|
|
120
|
+
[[ ! -z $cookieStr ]] && export "${env_param}=${cookieStr}"
|
|
114
121
|
|
|
115
|
-
|
|
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
|
-
|
|
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=$(
|
|
161
|
-
|
|
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/task.sh
CHANGED
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}
|
|
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
|
|
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
|
|
140
|
+
echo -e "\n拉取 ${uniq_path} 失败,请检查网络...\n"
|
|
141
141
|
fi
|
|
142
142
|
}
|
|
143
143
|
|
package/static/build/api/env.js
CHANGED
|
@@ -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 =
|
|
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
|
|
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
|
|
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,
|
|
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.
|
|
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
|
-
|
|
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://
|
|
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 = {} } =
|
|
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 = {} } =
|
|
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]
|
|
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(`
|
|
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://
|
|
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 =
|
|
278
|
-
const filterQuery =
|
|
279
|
-
const sorterQuery =
|
|
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
|
|
348
|
-
const
|
|
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
|
-
|
|
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
|
-
|
|
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(
|
|
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(/
|
|
202
|
-
.replace(/(\\$)/, '\\\\')
|
|
203
|
-
.replace(/"/g, '\\"')
|
|
201
|
+
.replace(/'/g, "'\\''")
|
|
204
202
|
.trim();
|
|
205
|
-
env_string += `export ${key}=
|
|
203
|
+
env_string += `export ${key}='${value}'\n`;
|
|
206
204
|
}
|
|
207
205
|
}
|
|
208
206
|
}
|
|
@@ -45,16 +45,16 @@ let ScheduleService = class ScheduleService {
|
|
|
45
45
|
});
|
|
46
46
|
cp.stderr.on('data', async (data) => {
|
|
47
47
|
var _a;
|
|
48
|
-
this.logger.info('[执行任务失败]
|
|
48
|
+
this.logger.info('[panel][执行任务失败] 命令: %s, 错误信息: %j', command, data.toString());
|
|
49
49
|
await ((_a = callbacks.onError) === null || _a === void 0 ? void 0 : _a.call(callbacks, data.toString()));
|
|
50
50
|
});
|
|
51
51
|
cp.on('error', async (err) => {
|
|
52
52
|
var _a;
|
|
53
|
-
this.logger.error('[创建任务失败]
|
|
53
|
+
this.logger.error('[panel][创建任务失败] 命令: %s, 错误信息: %j', command, err);
|
|
54
54
|
await ((_a = callbacks.onError) === null || _a === void 0 ? void 0 : _a.call(callbacks, JSON.stringify(err)));
|
|
55
55
|
});
|
|
56
56
|
cp.on('exit', async (code, signal) => {
|
|
57
|
-
this.logger.info(`[任务退出] ${command} 进程id: ${cp.pid}, 退出码 ${code}`);
|
|
57
|
+
this.logger.info(`[panel][任务退出] ${command} 进程id: ${cp.pid}, 退出码 ${code}`);
|
|
58
58
|
});
|
|
59
59
|
cp.on('close', async (code) => {
|
|
60
60
|
var _a;
|
|
@@ -64,7 +64,7 @@ let ScheduleService = class ScheduleService {
|
|
|
64
64
|
});
|
|
65
65
|
}
|
|
66
66
|
catch (error) {
|
|
67
|
-
|
|
67
|
+
this.logger.error('[panel][执行任务失败] 命令: %s, 错误信息: %j', command, error);
|
|
68
68
|
await ((_c = callbacks.onError) === null || _c === void 0 ? void 0 : _c.call(callbacks, JSON.stringify(error)));
|
|
69
69
|
}
|
|
70
70
|
});
|
|
@@ -72,7 +72,7 @@ let ScheduleService = class ScheduleService {
|
|
|
72
72
|
}
|
|
73
73
|
async createCronTask({ id = 0, command, name, schedule = '' }, callbacks, runImmediately = false) {
|
|
74
74
|
const _id = this.formatId(id);
|
|
75
|
-
this.logger.info('[创建cron任务], 任务ID: %s, cron: %s, 任务名: %s, 执行命令: %s', _id, schedule, name, command);
|
|
75
|
+
this.logger.info('[panel][创建cron任务], 任务ID: %s, cron: %s, 任务名: %s, 执行命令: %s', _id, schedule, name, command);
|
|
76
76
|
this.scheduleStacks.set(_id, node_schedule_1.default.scheduleJob(_id, schedule, async () => {
|
|
77
77
|
this.runTask(command, callbacks);
|
|
78
78
|
}));
|
|
@@ -83,7 +83,7 @@ let ScheduleService = class ScheduleService {
|
|
|
83
83
|
async cancelCronTask({ id = 0, name }) {
|
|
84
84
|
var _a;
|
|
85
85
|
const _id = this.formatId(id);
|
|
86
|
-
this.logger.info('[取消定时任务], 任务名: %s', name);
|
|
86
|
+
this.logger.info('[panel][取消定时任务], 任务名: %s', name);
|
|
87
87
|
if (this.scheduleStacks.has(_id)) {
|
|
88
88
|
(_a = this.scheduleStacks.get(_id)) === null || _a === void 0 ? void 0 : _a.cancel();
|
|
89
89
|
this.scheduleStacks.delete(_id);
|
|
@@ -91,11 +91,11 @@ let ScheduleService = class ScheduleService {
|
|
|
91
91
|
}
|
|
92
92
|
async createIntervalTask({ id = 0, command, name = '' }, schedule, runImmediately = true, callbacks) {
|
|
93
93
|
const _id = this.formatId(id);
|
|
94
|
-
this.logger.info('[创建interval任务], 任务ID: %s, 任务名: %s, 执行命令: %s', _id, name, command);
|
|
94
|
+
this.logger.info('[panel][创建interval任务], 任务ID: %s, 任务名: %s, 执行命令: %s', _id, name, command);
|
|
95
95
|
const task = new toad_scheduler_1.Task(name, () => {
|
|
96
96
|
this.runTask(command, callbacks);
|
|
97
97
|
}, (err) => {
|
|
98
|
-
this.logger.error('[执行任务失败] 命令: %s,
|
|
98
|
+
this.logger.error('[执行任务失败] 命令: %s, 错误信息: %j', command, err);
|
|
99
99
|
});
|
|
100
100
|
const job = new toad_scheduler_1.LongIntervalJob(Object.assign({ runImmediately: false }, schedule), task, _id);
|
|
101
101
|
this.intervalSchedule.addIntervalJob(job);
|
|
@@ -61,7 +61,6 @@ let ScriptService = class ScriptService {
|
|
|
61
61
|
return { code: 200, data: pid };
|
|
62
62
|
}
|
|
63
63
|
async stopScript(filePath, pid) {
|
|
64
|
-
let str = '';
|
|
65
64
|
if (!pid) {
|
|
66
65
|
const relativePath = path_1.default.relative(config_1.default.scriptPath, filePath);
|
|
67
66
|
pid = await (0, util_1.getPid)(`${const_1.TASK_COMMAND} -l ${relativePath} now`);
|