From 7f231506a27953564302e8b4264d2151e6a0761b Mon Sep 17 00:00:00 2001 From: hanhh Date: Thu, 24 Jun 2021 18:55:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E9=9D=A2=E6=9D=BF=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E6=9F=A5=E7=9C=8B=E6=9C=80=E6=96=B0=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/api/auth.ts | 11 ++++++----- back/data/cron.ts | 4 +++- back/services/cron.ts | 19 +++++++++++++++++-- shell/task.sh | 3 ++- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/back/api/auth.ts b/back/api/auth.ts index aace6a53..7bcd3a6e 100644 --- a/back/api/auth.ts +++ b/back/api/auth.ts @@ -5,6 +5,7 @@ import * as fs from 'fs'; import config from '../config'; import jwt from 'jsonwebtoken'; import { createPassword } from '../config/util'; +import crypto from 'crypto'; const route = Router(); export default (app: Router) => { @@ -41,11 +42,11 @@ export default (app: Router) => { username == authInfo.username && password == authInfo.password ) { - let token = jwt.sign( - { username, password }, - config.secret as any, - { expiresIn: 60 * 60 * 24 * 7, algorithm: 'HS384' }, - ); + const data = createPassword(50, 100); + let token = jwt.sign({ data }, config.secret as any, { + expiresIn: 60 * 60 * 24 * 3, + algorithm: 'HS384', + }); fs.writeFileSync( config.authConfigFile, JSON.stringify({ diff --git a/back/data/cron.ts b/back/data/cron.ts index 96aabe9f..0b050355 100644 --- a/back/data/cron.ts +++ b/back/data/cron.ts @@ -18,7 +18,9 @@ export class Crontab { this.saved = options.saved; this._id = options._id; this.created = options.created; - this.status = options.status || CrontabStatus.idle; + this.status = CrontabStatus[options.status] + ? options.status + : CrontabStatus.idle; this.timestamp = new Date().toString(); this.isSystem = options.isSystem || 0; this.pid = options.pid; diff --git a/back/services/cron.ts b/back/services/cron.ts index 88f94032..355f1c94 100644 --- a/back/services/cron.ts +++ b/back/services/cron.ts @@ -8,6 +8,7 @@ import fs from 'fs'; import cron_parser from 'cron-parser'; import { getFileContentByName } from '../config/util'; import PQueue from 'p-queue'; +import { promises, existsSync } from 'fs'; @Service() export default class CronService { @@ -275,8 +276,22 @@ export default class CronService { } public async log(_id: string) { - let logFile = `${config.manualLogPath}${_id}.log`; - return getFileContentByName(logFile); + const doc = await this.get(_id); + const commandStr = doc.command.split(' ')[1]; + const start = + commandStr.lastIndexOf('/') !== -1 ? commandStr.lastIndexOf('/') + 1 : 0; + const end = + commandStr.lastIndexOf('.') !== -1 + ? commandStr.lastIndexOf('.') + : commandStr.length; + const logPath = commandStr.substring(start, end); + let logDir = `${config.logPath}${logPath}`; + if (existsSync(logDir)) { + const files = await promises.readdir(logDir); + return getFileContentByName(`${logDir}/${files[files.length - 1]}`); + } else { + return ''; + } } private make_command(tab: Crontab) { diff --git a/shell/task.sh b/shell/task.sh index 71395b12..4051155e 100755 --- a/shell/task.sh +++ b/shell/task.sh @@ -108,7 +108,8 @@ run_concurrent() { local array=($(echo $envs | sed 's/&/ /g')) cd $dir_scripts define_program "$p1" - log_dir="$dir_log/${p1%%.*}" + log_dir_tmp="${p1##*/}" + log_dir="$dir_log/${log_dir_tmp%%.*}" make_dir $log_dir log_time=$(date "+%Y-%m-%d-%H-%M-%S.%N") echo -e "\n各账号间已经在后台开始并发执行,前台不输入日志,日志直接写入文件中。\n"