@whyour/qinglong 2.19.0-0 → 2.19.0-2

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whyour/qinglong",
3
- "version": "2.19.0-0",
3
+ "version": "2.19.0-2",
4
4
  "description": "Timed task management platform supporting Python3, JavaScript, Shell, Typescript",
5
5
  "repository": {
6
6
  "type": "git",
@@ -54,7 +54,7 @@ def run():
54
54
 
55
55
  task_before = os.getenv("task_before")
56
56
  if task_before:
57
- escaped_task_before = task_before.replace("'", "'\\''")
57
+ escaped_task_before = task_before.replace('"', '\\"').replace("$", "\\$")
58
58
  commands.append(f"eval '{escaped_task_before}'")
59
59
  print("执行前置命令\n")
60
60
 
@@ -29,11 +29,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
29
29
  return (mod && mod.__esModule) ? mod : { "default": mod };
30
30
  };
31
31
  Object.defineProperty(exports, "__esModule", { value: true });
32
- exports.updateLinuxMirrorFile = exports.detectOS = exports.isDemoEnv = exports.getUninstallCommand = exports.getInstallCommand = exports.setSystemTimezone = exports.rmPath = exports.safeJSONParse = exports.getUniqPath = exports.parseContentVersion = exports.parseVersion = exports.getPid = exports.killTask = exports.psTree = exports.parseBody = exports.parseHeaders = exports.promiseExecSuccess = exports.promiseExec = exports.readDir = exports.readDirs = exports.dirSort = exports.concurrentRun = exports.handleLogPath = exports.createFile = exports.fileExist = exports.getPlatform = exports.getNetIp = exports.getToken = exports.getLastModifyFilePath = exports.removeAnsi = exports.getFileContentByName = void 0;
32
+ exports.updateLinuxMirrorFile = exports.detectOS = exports.isDemoEnv = exports.getUninstallCommand = exports.getInstallCommand = exports.setSystemTimezone = exports.rmPath = exports.safeJSONParse = exports.getUniqPath = exports.parseContentVersion = exports.parseVersion = exports.getPid = exports.killTask = exports.psTree = exports.parseBody = exports.parseHeaders = exports.promiseExecSuccess = exports.promiseExec = exports.readDir = exports.readDirs = exports.dirSort = exports.concurrentRun = exports.handleLogPath = exports.createFile = exports.fileExist = exports.getPlatform = exports.getToken = exports.getLastModifyFilePath = exports.removeAnsi = exports.getFileContentByName = void 0;
33
33
  const fs = __importStar(require("fs/promises"));
34
34
  const path = __importStar(require("path"));
35
- const got_1 = __importDefault(require("got"));
36
- const iconv_lite_1 = __importDefault(require("iconv-lite"));
37
35
  const child_process_1 = require("child_process");
38
36
  const form_data_1 = __importDefault(require("form-data"));
39
37
  const ps_tree_1 = __importDefault(require("ps-tree"));
@@ -88,73 +86,6 @@ function getToken(req) {
88
86
  return '';
89
87
  }
90
88
  exports.getToken = getToken;
91
- async function getNetIp(req) {
92
- const ipArray = [
93
- ...new Set([
94
- ...(req.headers['x-real-ip'] || '').split(','),
95
- ...(req.headers['x-forwarded-for'] || '').split(','),
96
- req.ip,
97
- ...req.ips,
98
- req.socket.remoteAddress,
99
- ]),
100
- ].filter(Boolean);
101
- let ip = ipArray[0];
102
- if (ipArray.length > 1) {
103
- for (let i = 0; i < ipArray.length; i++) {
104
- const ipNumArray = ipArray[i].split('.');
105
- const tmp = ipNumArray[0] + '.' + ipNumArray[1];
106
- if (tmp === '192.168' ||
107
- (ipNumArray[0] === '172' &&
108
- ipNumArray[1] >= 16 &&
109
- ipNumArray[1] <= 32) ||
110
- tmp === '10.7' ||
111
- tmp === '127.0') {
112
- continue;
113
- }
114
- ip = ipArray[i];
115
- break;
116
- }
117
- }
118
- ip = ip.substr(ip.lastIndexOf(':') + 1, ip.length);
119
- if (ip.includes('127.0') || ip.includes('192.168') || ip.includes('10.7')) {
120
- ip = '';
121
- }
122
- if (!ip) {
123
- return { address: `获取失败`, ip };
124
- }
125
- try {
126
- const csdnApi = got_1.default
127
- .get(`https://searchplugin.csdn.net/api/v1/ip/get?ip=${ip}`, {
128
- timeout: 10000,
129
- retry: 0,
130
- })
131
- .text();
132
- const pconlineApi = got_1.default
133
- .get(`https://whois.pconline.com.cn/ipJson.jsp?ip=${ip}&json=true`, {
134
- timeout: 10000,
135
- retry: 0,
136
- })
137
- .buffer();
138
- const [csdnBody, pconlineBody] = await await Promise.all([
139
- csdnApi,
140
- pconlineApi,
141
- ]);
142
- const csdnRes = JSON.parse(csdnBody);
143
- const pconlineRes = JSON.parse(iconv_lite_1.default.decode(pconlineBody, 'GBK'));
144
- let address = '';
145
- if (csdnBody && csdnRes.code == 200) {
146
- address = csdnRes.data.address;
147
- }
148
- else if (pconlineRes && pconlineRes.addr) {
149
- address = pconlineRes.addr;
150
- }
151
- return { address, ip };
152
- }
153
- catch (error) {
154
- return { address: `获取失败`, ip };
155
- }
156
- }
157
- exports.getNetIp = getNetIp;
158
89
  function getPlatform(userAgent) {
159
90
  const ua = userAgent.toLowerCase();
160
91
  const testUa = (regexp) => regexp.test(ua);
@@ -20,6 +20,7 @@ let HttpServerService = class HttpServerService {
20
20
  async initialize(expressApp, port) {
21
21
  try {
22
22
  return new Promise((resolve, reject) => {
23
+ var _a;
23
24
  this.server = expressApp.listen(port, '0.0.0.0', () => {
24
25
  logger_1.default.debug(`✌️ HTTP service started successfully`);
25
26
  metrics_1.metricsService.record('http_service_start', 1, {
@@ -27,7 +28,7 @@ let HttpServerService = class HttpServerService {
27
28
  });
28
29
  resolve(this.server);
29
30
  });
30
- this.server.on('error', (err) => {
31
+ (_a = this.server) === null || _a === void 0 ? void 0 : _a.on('error', (err) => {
31
32
  logger_1.default.error('Failed to start HTTP service:', err);
32
33
  reject(err);
33
34
  });
@@ -73,7 +73,7 @@ let NotificationService = class NotificationService {
73
73
  return await (notificationModeAction === null || notificationModeAction === void 0 ? void 0 : notificationModeAction.call(this));
74
74
  }
75
75
  catch (error) {
76
- throw error;
76
+ console.error(error);
77
77
  }
78
78
  }
79
79
  return false;
@@ -216,7 +216,16 @@ let UserService = class UserService {
216
216
  return this.login({ username, password }, req, false);
217
217
  }
218
218
  else {
219
- const { ip, address } = await (0, util_1.getNetIp)(req);
219
+ const ip = request_ip_1.default.getClientIp(req) || '';
220
+ const query = new ip2region_1.default();
221
+ const ipAddress = query.search(ip);
222
+ let address = '';
223
+ if (ipAddress) {
224
+ const { country, province, city, isp } = ipAddress;
225
+ address = (0, uniq_1.default)([country, province, city, isp])
226
+ .filter(Boolean)
227
+ .join(' ');
228
+ }
220
229
  await this.updateAuthInfo(authInfo, {
221
230
  lastip: ip,
222
231
  lastaddr: address,
@@ -289,12 +298,13 @@ let UserService = class UserService {
289
298
  }
290
299
  }
291
300
  async resetAuthInfo(info) {
292
- const { retries, twoFactorActivated, password } = info;
301
+ const { retries, twoFactorActivated, password, username } = info;
293
302
  const authInfo = await this.getAuthInfo();
294
303
  await this.updateAuthInfo(authInfo, {
295
304
  retries,
296
305
  twoFactorActivated,
297
306
  password,
307
+ username
298
308
  });
299
309
  }
300
310
  };