mirror of
https://github.com/whyour/qinglong.git
synced 2026-08-09 02:14:33 +08:00
Compare commits
31 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4667af4ebe | |||
| 3f775a0e6c | |||
| fa79de3f05 | |||
| ffa8b25a66 | |||
| 05f8bbd26e | |||
| 7d43b14f81 | |||
| cecc5aeb15 | |||
| 43d6ac2071 | |||
| 678e3e2dc6 | |||
| 75f91e1473 | |||
| bdc45c538c | |||
| 955c7377d7 | |||
| c71abd8c86 | |||
| ab27a4c908 | |||
| 026640a757 | |||
| a1501705c1 | |||
| b321530dcf | |||
| 02c6ad8004 | |||
| fff572869e | |||
| b733937691 | |||
| 0d9eba4b6e | |||
| 20c6a1e8bf | |||
| 56bc2f0b1d | |||
| ecc55883f0 | |||
| 185fd2ff91 | |||
| 3822c37fa0 | |||
| 4244502949 | |||
| 71dd82f74e | |||
| 6ea8d361fd | |||
| 3f71f9acdb | |||
| 418695c4aa |
+11
-11
@@ -2,22 +2,22 @@
|
||||
**/*.svg
|
||||
**/*.ejs
|
||||
**/*.html
|
||||
.umi
|
||||
.umi-production
|
||||
.umi-test
|
||||
.history
|
||||
.tmp
|
||||
node_modules
|
||||
/.umi
|
||||
/.umi-production
|
||||
/.umi-test
|
||||
/.history
|
||||
/.tmp
|
||||
/node_modules
|
||||
npm-debug.log*
|
||||
yarn-error.log
|
||||
yarn.lock
|
||||
package-lock.json
|
||||
static
|
||||
data
|
||||
/static
|
||||
/data
|
||||
DS_Store
|
||||
src/.umi
|
||||
src/.umi-production
|
||||
src/.umi-test
|
||||
/src/.umi
|
||||
/src/.umi-production
|
||||
/src/.umi-test
|
||||
.env.local
|
||||
.env
|
||||
version.ts
|
||||
|
||||
@@ -43,19 +43,12 @@ export default defineConfig({
|
||||
}),
|
||||
);
|
||||
}) as any,
|
||||
externals: {
|
||||
react: 'window.React',
|
||||
'react-dom': 'window.ReactDOM',
|
||||
},
|
||||
headScripts: [
|
||||
`./api/env.js`,
|
||||
'https://gw.alipayobjects.com/os/lib/react/18.2.0/umd/react.production.min.js',
|
||||
'https://gw.alipayobjects.com/os/lib/react-dom/18.2.0/umd/react-dom.production.min.js',
|
||||
],
|
||||
headScripts: [`./api/env.js`],
|
||||
copy: [
|
||||
{
|
||||
from: 'node_modules/monaco-editor/min/vs',
|
||||
to: 'static/dist/monaco-editor/min/vs',
|
||||
},
|
||||
],
|
||||
npmClient: 'pnpm',
|
||||
});
|
||||
|
||||
+1
-1
@@ -126,7 +126,7 @@ curl -sL https://deb.nodesource.com/setup_20.x | sudo -E bash -
|
||||
npm install -g node-pre-gyp pnpm@8.3.1
|
||||
npm install -g @whyour/qinglong
|
||||
qinglong
|
||||
# Add the environment variables QL_DIR and QL_DATA_DIR when prompted
|
||||
# Add the environment variables QL_DIR and QL_DATA_DIR when prompted, QL_DATA_DIR must end with /data.
|
||||
export QL_DIR=""
|
||||
export QL_DATA_DIR=""
|
||||
# Run again
|
||||
|
||||
@@ -88,7 +88,7 @@ docker run -dit \
|
||||
|
||||
```bash
|
||||
# curl -L https://github.com/docker/compose/releases/download/1.16.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
|
||||
mkdir qinglong
|
||||
mkdir qinglong && cd $_
|
||||
wget https://raw.githubusercontent.com/whyour/qinglong/master/docker/docker-compose.yml
|
||||
|
||||
# 启动
|
||||
@@ -128,7 +128,7 @@ curl -sL https://deb.nodesource.com/setup_20.x | sudo -E bash -
|
||||
npm install -g node-pre-gyp pnpm@8.3.1
|
||||
npm install -g @whyour/qinglong
|
||||
qinglong
|
||||
# 根据提示增加环境变量 QL_DIR 和 QL_DATA_DIR
|
||||
# 根据提示增加环境变量 QL_DIR 和 QL_DATA_DIR,QL_DATA_DIR 必须以 /data 结尾
|
||||
export QL_DIR=""
|
||||
export QL_DATA_DIR=""
|
||||
# 再次执行
|
||||
|
||||
+2
-1
@@ -7,6 +7,7 @@ import { celebrate, Joi } from 'celebrate';
|
||||
import { join } from 'path';
|
||||
import { SAMPLE_FILES } from '../config/const';
|
||||
import ConfigService from '../services/config';
|
||||
import { writeFileWithLock } from '../shared/utils';
|
||||
const route = Router();
|
||||
|
||||
export default (app: Router) => {
|
||||
@@ -77,7 +78,7 @@ export default (app: Router) => {
|
||||
if (name.startsWith('data/scripts/')) {
|
||||
path = join(config.rootPath, name);
|
||||
}
|
||||
await fs.writeFile(path, content);
|
||||
await writeFileWithLock(path, content);
|
||||
res.send({ code: 200, message: '保存成功' });
|
||||
} catch (e) {
|
||||
return next(e);
|
||||
|
||||
+4
-3
@@ -8,6 +8,7 @@ import { celebrate, Joi } from 'celebrate';
|
||||
import path, { join, parse } from 'path';
|
||||
import ScriptService from '../services/script';
|
||||
import multer from 'multer';
|
||||
import { writeFileWithLock } from '../shared/utils';
|
||||
const route = Router();
|
||||
|
||||
const storage = multer.diskStorage({
|
||||
@@ -156,7 +157,7 @@ export default (app: Router) => {
|
||||
await rmPath(originFilePath);
|
||||
}
|
||||
}
|
||||
await fs.writeFile(filePath, content);
|
||||
await writeFileWithLock(filePath, content);
|
||||
return res.send({ code: 200 });
|
||||
} catch (e) {
|
||||
return next(e);
|
||||
@@ -182,7 +183,7 @@ export default (app: Router) => {
|
||||
path: string;
|
||||
};
|
||||
const filePath = join(config.scriptPath, path, filename);
|
||||
await fs.writeFile(filePath, content);
|
||||
await writeFileWithLock(filePath, content);
|
||||
return res.send({ code: 200 });
|
||||
} catch (e) {
|
||||
return next(e);
|
||||
@@ -261,7 +262,7 @@ export default (app: Router) => {
|
||||
let { filename, content, path } = req.body;
|
||||
const { name, ext } = parse(filename);
|
||||
const filePath = join(config.scriptPath, path, `${name}.swap${ext}`);
|
||||
await fs.writeFile(filePath, content || '', { encoding: 'utf8' });
|
||||
await writeFileWithLock(filePath, content || '');
|
||||
|
||||
const scriptService = Container.get(ScriptService);
|
||||
const result = await scriptService.runScript(filePath);
|
||||
|
||||
+20
-1
@@ -33,7 +33,7 @@ export default (app: Router) => {
|
||||
const logger: Logger = Container.get('logger');
|
||||
try {
|
||||
const userService = Container.get(UserService);
|
||||
const authInfo = await userService.getUserInfo();
|
||||
const authInfo = await userService.getAuthInfo();
|
||||
const { version, changeLog, changeLogLink, publishTime } =
|
||||
await parseVersion(config.versionFile);
|
||||
|
||||
@@ -377,4 +377,23 @@ export default (app: Router) => {
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
route.put(
|
||||
'/auth/reset',
|
||||
celebrate({
|
||||
body: Joi.object({
|
||||
retries: Joi.number().optional(),
|
||||
twoFactorActivated: Joi.boolean().optional(),
|
||||
}),
|
||||
}),
|
||||
async (req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
const userService = Container.get(UserService);
|
||||
await userService.resetAuthInfo(req.body);
|
||||
res.send({ code: 200, message: '更新成功' });
|
||||
} catch (e) {
|
||||
return next(e);
|
||||
}
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
+1
-1
@@ -90,7 +90,7 @@ export default (app: Router) => {
|
||||
const logger: Logger = Container.get('logger');
|
||||
try {
|
||||
const userService = Container.get(UserService);
|
||||
const authInfo = await userService.getUserInfo();
|
||||
const authInfo = await userService.getAuthInfo();
|
||||
res.send({
|
||||
code: 200,
|
||||
data: {
|
||||
|
||||
+15
-7
@@ -10,6 +10,7 @@ import { load } from 'js-yaml';
|
||||
import config from './index';
|
||||
import { TASK_COMMAND } from './const';
|
||||
import Logger from '../loaders/logger';
|
||||
import { writeFileWithLock } from '../shared/utils';
|
||||
|
||||
export * from './share';
|
||||
|
||||
@@ -145,12 +146,14 @@ export function getPlatform(userAgent: string): 'mobile' | 'desktop' {
|
||||
system = 'android'; // android系统
|
||||
} else if (testUa(/ios|iphone|ipad|ipod|iwatch/g)) {
|
||||
system = 'ios'; // ios系统
|
||||
} else if (testUa(/openharmony/g)) {
|
||||
system = 'openharmony'; // openharmony系统
|
||||
}
|
||||
|
||||
let platform = 'desktop';
|
||||
if (system === 'windows' || system === 'macos' || system === 'linux') {
|
||||
platform = 'desktop';
|
||||
} else if (system === 'android' || system === 'ios' || testUa(/mobile/g)) {
|
||||
} else if (system === 'android' || system === 'ios' || system === 'openharmony' || testUa(/mobile/g)) {
|
||||
platform = 'mobile';
|
||||
}
|
||||
|
||||
@@ -168,7 +171,7 @@ export async function fileExist(file: any) {
|
||||
|
||||
export async function createFile(file: string, data: string = '') {
|
||||
await fs.mkdir(path.dirname(file), { recursive: true });
|
||||
await fs.writeFile(file, data);
|
||||
await writeFileWithLock(file, data);
|
||||
}
|
||||
|
||||
export async function handleLogPath(
|
||||
@@ -469,13 +472,18 @@ export async function getUniqPath(
|
||||
command: string,
|
||||
id: string,
|
||||
): Promise<string> {
|
||||
let suffix = '';
|
||||
if (/^\d+$/.test(id)) {
|
||||
id = `_${id}`;
|
||||
} else {
|
||||
id = '';
|
||||
suffix = `_${id}`;
|
||||
}
|
||||
|
||||
let items = command.split(/ +/);
|
||||
|
||||
const maxTimeCommandIndex = items.findIndex((x) => x === '-m');
|
||||
if (maxTimeCommandIndex !== -1) {
|
||||
items = items.slice(maxTimeCommandIndex + 2);
|
||||
}
|
||||
|
||||
const items = command.split(/ +/);
|
||||
let str = items[0];
|
||||
if (items[0] === TASK_COMMAND) {
|
||||
str = items[1];
|
||||
@@ -499,7 +507,7 @@ export async function getUniqPath(
|
||||
str = `${tempStr}_${str.slice(slashIndex + 1)}`;
|
||||
}
|
||||
|
||||
return `${str}${id}`;
|
||||
return `${str}${suffix}`;
|
||||
}
|
||||
|
||||
export function safeJSONParse(value?: string) {
|
||||
|
||||
+22
-2
@@ -20,6 +20,8 @@ export enum NotificationMode {
|
||||
'feishu' = 'feishu',
|
||||
'webhook' = 'webhook',
|
||||
'chronocat' = 'Chronocat',
|
||||
'ntfy' = 'ntfy',
|
||||
'wxPusherBot' = 'wxPusherBot',
|
||||
}
|
||||
|
||||
abstract class NotificationBaseInfo {
|
||||
@@ -99,6 +101,11 @@ export class IGotNotification extends NotificationBaseInfo {
|
||||
export class PushPlusNotification extends NotificationBaseInfo {
|
||||
public pushPlusToken = '';
|
||||
public pushPlusUser = '';
|
||||
public pushPlusTemplate = '';
|
||||
public pushplusChannel = '';
|
||||
public pushplusWebhook = '';
|
||||
public pushplusCallbackUrl = '';
|
||||
public pushplusTo = '';
|
||||
}
|
||||
|
||||
export class WePlusBotNotification extends NotificationBaseInfo {
|
||||
@@ -139,6 +146,18 @@ export class LarkNotification extends NotificationBaseInfo {
|
||||
public larkKey = '';
|
||||
}
|
||||
|
||||
export class NtfyNotification extends NotificationBaseInfo {
|
||||
public ntfyUrl = '';
|
||||
public ntfyTopic = '';
|
||||
public ntfyPriority = '';
|
||||
}
|
||||
|
||||
export class WxPusherBotNotification extends NotificationBaseInfo {
|
||||
public wxPusherBotAppToken = '';
|
||||
public wxPusherBotTopicIds = '';
|
||||
public wxPusherBotUids = '';
|
||||
}
|
||||
|
||||
export interface NotificationInfo
|
||||
extends GoCqHttpBotNotification,
|
||||
GotifyNotification,
|
||||
@@ -158,5 +177,6 @@ export interface NotificationInfo
|
||||
PushMeNotification,
|
||||
WebhookNotification,
|
||||
ChronocatNotification,
|
||||
LarkNotification {}
|
||||
|
||||
LarkNotification,
|
||||
NtfyNotification,
|
||||
WxPusherBotNotification {}
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ export interface AppToken {
|
||||
expiration: number;
|
||||
}
|
||||
|
||||
export type AppScope = 'envs' | 'crons' | 'configs' | 'scripts' | 'logs';
|
||||
export type AppScope = 'envs' | 'crons' | 'configs' | 'scripts' | 'logs' | 'system';
|
||||
|
||||
export interface AppInstance extends Model<App, App>, App {}
|
||||
export const AppModel = sequelize.define<AppInstance>('App', {
|
||||
|
||||
+22
-2
@@ -27,6 +27,7 @@ export enum AuthDataType {
|
||||
'notification' = 'notification',
|
||||
'removeLogFrequency' = 'removeLogFrequency',
|
||||
'systemConfig' = 'systemConfig',
|
||||
'authConfig' = 'authConfig',
|
||||
}
|
||||
|
||||
export interface SystemConfigInfo {
|
||||
@@ -46,11 +47,30 @@ export interface LoginLogInfo {
|
||||
status?: LoginStatus;
|
||||
}
|
||||
|
||||
export interface AuthInfo {
|
||||
username: string;
|
||||
password: string;
|
||||
retries: number;
|
||||
lastlogon: number;
|
||||
lastip: string;
|
||||
lastaddr: string;
|
||||
platform: string;
|
||||
isTwoFactorChecking: boolean;
|
||||
token: string;
|
||||
tokens: Record<string, string>;
|
||||
twoFactorActivated: boolean;
|
||||
twoFactorSecret: string;
|
||||
avatar: string;
|
||||
}
|
||||
|
||||
export type SystemModelInfo = SystemConfigInfo &
|
||||
Partial<NotificationInfo> &
|
||||
LoginLogInfo;
|
||||
LoginLogInfo &
|
||||
Partial<AuthInfo>;
|
||||
|
||||
export interface SystemInstance extends Model<SystemInfo, SystemInfo>, SystemInfo { }
|
||||
export interface SystemInstance
|
||||
extends Model<SystemInfo, SystemInfo>,
|
||||
SystemInfo {}
|
||||
export const SystemModel = sequelize.define<SystemInstance>('Auth', {
|
||||
ip: DataTypes.STRING,
|
||||
type: DataTypes.STRING,
|
||||
|
||||
+14
-16
@@ -3,19 +3,15 @@ import bodyParser from 'body-parser';
|
||||
import cors from 'cors';
|
||||
import routes from '../api';
|
||||
import config from '../config';
|
||||
import jwt, { UnauthorizedError } from 'express-jwt';
|
||||
import fs from 'fs/promises';
|
||||
import { getPlatform, getToken, safeJSONParse } from '../config/util';
|
||||
import Container from 'typedi';
|
||||
import OpenService from '../services/open';
|
||||
import { UnauthorizedError, expressjwt } from 'express-jwt';
|
||||
import { getPlatform, getToken } from '../config/util';
|
||||
import rewrite from 'express-urlrewrite';
|
||||
import UserService from '../services/user';
|
||||
import * as Sentry from '@sentry/node';
|
||||
import { EnvModel } from '../data/env';
|
||||
import { errors } from 'celebrate';
|
||||
import { createProxyMiddleware } from 'http-proxy-middleware';
|
||||
import { serveEnv } from '../config/serverEnv';
|
||||
import Logger from './logger';
|
||||
import { IKeyvStore, shareStore } from '../shared/store';
|
||||
|
||||
export default ({ app }: { app: Application }) => {
|
||||
app.set('trust proxy', 'loopback');
|
||||
@@ -29,7 +25,7 @@ export default ({ app }: { app: Application }) => {
|
||||
target: `http://0.0.0.0:${config.publicPort}/api`,
|
||||
changeOrigin: true,
|
||||
pathRewrite: { '/api/public': '' },
|
||||
logProvider: () => Logger,
|
||||
logger: Logger,
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -37,7 +33,7 @@ export default ({ app }: { app: Application }) => {
|
||||
app.use(bodyParser.urlencoded({ limit: '50mb', extended: true }));
|
||||
|
||||
app.use(
|
||||
jwt({
|
||||
expressjwt({
|
||||
secret: config.secret,
|
||||
algorithms: ['HS384'],
|
||||
}).unless({
|
||||
@@ -58,8 +54,10 @@ export default ({ app }: { app: Application }) => {
|
||||
app.use(async (req, res, next) => {
|
||||
const headerToken = getToken(req);
|
||||
if (req.path.startsWith('/open/')) {
|
||||
const openService = Container.get(OpenService);
|
||||
const doc = await openService.findTokenByValue(headerToken);
|
||||
const apps = await shareStore.getApps();
|
||||
const doc = apps?.filter((x) =>
|
||||
x.tokens?.find((y) => y.value === headerToken),
|
||||
)?.[0];
|
||||
if (doc && doc.tokens && doc.tokens.length > 0) {
|
||||
const currentToken = doc.tokens.find((x) => x.value === headerToken);
|
||||
const keyMatch = req.path.match(/\/open\/([a-z]+)\/*/);
|
||||
@@ -83,9 +81,9 @@ export default ({ app }: { app: Application }) => {
|
||||
return next();
|
||||
}
|
||||
|
||||
const data = await fs.readFile(config.authConfigFile, 'utf8');
|
||||
if (data && headerToken) {
|
||||
const { token = '', tokens = {} } = safeJSONParse(data);
|
||||
const authInfo = await shareStore.getAuthInfo();
|
||||
if (authInfo && headerToken) {
|
||||
const { token = '', tokens = {} } = authInfo;
|
||||
if (headerToken === token || tokens[req.platform] === headerToken) {
|
||||
return next();
|
||||
}
|
||||
@@ -103,8 +101,8 @@ export default ({ app }: { app: Application }) => {
|
||||
if (!['/api/user/init', '/api/user/notification/init'].includes(req.path)) {
|
||||
return next();
|
||||
}
|
||||
const userService = Container.get(UserService);
|
||||
const authInfo = await userService.getUserInfo();
|
||||
const authInfo =
|
||||
(await shareStore.getAuthInfo()) || ({} as IKeyvStore['authInfo']);
|
||||
|
||||
let isInitialized = true;
|
||||
if (
|
||||
|
||||
@@ -12,7 +12,11 @@ import { initPosition } from '../data/env';
|
||||
import { AuthDataType, SystemModel } from '../data/system';
|
||||
import SystemService from '../services/system';
|
||||
import UserService from '../services/user';
|
||||
import { writeFile } from 'fs/promises';
|
||||
import { writeFile, readFile } from 'fs/promises';
|
||||
import { safeJSONParse } from '../config/util';
|
||||
import OpenService from '../services/open';
|
||||
import { shareStore } from '../shared/store';
|
||||
import Logger from './logger';
|
||||
|
||||
export default async () => {
|
||||
const cronService = Container.get(CronService);
|
||||
@@ -20,14 +24,40 @@ export default async () => {
|
||||
const dependenceService = Container.get(DependenceService);
|
||||
const systemService = Container.get(SystemService);
|
||||
const userService = Container.get(UserService);
|
||||
const openService = Container.get(OpenService);
|
||||
|
||||
// 初始化增加系统配置
|
||||
await SystemModel.upsert({ type: AuthDataType.systemConfig });
|
||||
await SystemModel.upsert({ type: AuthDataType.notification });
|
||||
const [systemConfig] = await SystemModel.findOrCreate({
|
||||
where: { type: AuthDataType.systemConfig },
|
||||
});
|
||||
const [notifyConfig] = await SystemModel.findOrCreate({
|
||||
where: { type: AuthDataType.notification },
|
||||
});
|
||||
const [authConfig] = await SystemModel.findOrCreate({
|
||||
where: { type: AuthDataType.authConfig },
|
||||
});
|
||||
if (!authConfig?.info) {
|
||||
let authInfo = {
|
||||
username: 'admin',
|
||||
password: 'admin',
|
||||
};
|
||||
try {
|
||||
const content = await readFile(config.authConfigFile, 'utf8');
|
||||
authInfo = safeJSONParse(content);
|
||||
} catch (error) {
|
||||
Logger.warn('Failed to read auth config file, using default credentials');
|
||||
}
|
||||
await SystemModel.upsert({
|
||||
id: authConfig?.id,
|
||||
info: authInfo,
|
||||
type: AuthDataType.authConfig,
|
||||
});
|
||||
}
|
||||
|
||||
// 初始化通知配置
|
||||
const notifyConfig = await userService.getNotificationMode();
|
||||
await writeFile(config.systemNotifyFile, JSON.stringify(notifyConfig));
|
||||
if (notifyConfig.info) {
|
||||
await writeFile(config.systemNotifyFile, JSON.stringify(notifyConfig.info));
|
||||
}
|
||||
|
||||
const installDependencies = () => {
|
||||
// 初始化时安装所有处于安装中,安装成功,安装失败的依赖
|
||||
@@ -50,7 +80,6 @@ export default async () => {
|
||||
};
|
||||
|
||||
// 初始化更新 linux/python/nodejs 镜像源配置
|
||||
const systemConfig = await systemService.getSystemConfig();
|
||||
if (systemConfig.info?.pythonMirror) {
|
||||
systemService.updatePythonMirror({
|
||||
pythonMirror: systemConfig.info?.pythonMirror,
|
||||
@@ -169,4 +198,11 @@ export default async () => {
|
||||
// 初始化保存一次ck和定时任务数据
|
||||
await cronService.autosave_crontab();
|
||||
await envService.set_envs();
|
||||
|
||||
const authInfo = await userService.getAuthInfo();
|
||||
const apps = await openService.findApps();
|
||||
await shareStore.updateAuthInfo(authInfo);
|
||||
if (apps?.length) {
|
||||
await shareStore.updateApps(apps);
|
||||
}
|
||||
};
|
||||
|
||||
+77
-103
@@ -3,6 +3,7 @@ import path from 'path';
|
||||
import os from 'os';
|
||||
import Logger from './logger';
|
||||
import { fileExist } from '../config/util';
|
||||
import { writeFileWithLock } from '../shared/utils';
|
||||
|
||||
const rootPath = process.env.QL_DIR as string;
|
||||
let dataPath = path.join(rootPath, 'data/');
|
||||
@@ -20,9 +21,7 @@ const bakPath = path.join(dataPath, 'bak/');
|
||||
const samplePath = path.join(rootPath, 'sample/');
|
||||
const tmpPath = path.join(logPath, '.tmp/');
|
||||
const confFile = path.join(configPath, 'config.sh');
|
||||
const authConfigFile = path.join(configPath, 'auth.json');
|
||||
const sampleConfigFile = path.join(samplePath, 'config.sample.sh');
|
||||
const sampleAuthFile = path.join(samplePath, 'auth.sample.json');
|
||||
const sampleTaskShellFile = path.join(samplePath, 'task.sample.sh');
|
||||
const sampleNotifyJsFile = path.join(samplePath, 'notify.js');
|
||||
const sampleNotifyPyFile = path.join(samplePath, 'notify.py');
|
||||
@@ -39,112 +38,87 @@ const sshPath = path.resolve(homedir, '.ssh');
|
||||
const sshdPath = path.join(dataPath, 'ssh.d');
|
||||
const systemLogPath = path.join(dataPath, 'syslog');
|
||||
|
||||
export default async () => {
|
||||
const authFileExist = await fileExist(authConfigFile);
|
||||
const confFileExist = await fileExist(confFile);
|
||||
const scriptDirExist = await fileExist(scriptPath);
|
||||
const preloadDirExist = await fileExist(preloadPath);
|
||||
const logDirExist = await fileExist(logPath);
|
||||
const configDirExist = await fileExist(configPath);
|
||||
const uploadDirExist = await fileExist(uploadPath);
|
||||
const sshDirExist = await fileExist(sshPath);
|
||||
const bakDirExist = await fileExist(bakPath);
|
||||
const sshdDirExist = await fileExist(sshdPath);
|
||||
const systemLogDirExist = await fileExist(systemLogPath);
|
||||
const tmpDirExist = await fileExist(tmpPath);
|
||||
const scriptNotifyJsFileExist = await fileExist(scriptNotifyJsFile);
|
||||
const scriptNotifyPyFileExist = await fileExist(scriptNotifyPyFile);
|
||||
const TaskBeforeFileExist = await fileExist(TaskBeforeFile);
|
||||
const TaskBeforeJsFileExist = await fileExist(TaskBeforeJsFile);
|
||||
const TaskBeforePyFileExist = await fileExist(TaskBeforePyFile);
|
||||
const TaskAfterFileExist = await fileExist(TaskAfterFile);
|
||||
const directories = [
|
||||
configPath,
|
||||
scriptPath,
|
||||
preloadPath,
|
||||
logPath,
|
||||
tmpPath,
|
||||
uploadPath,
|
||||
sshPath,
|
||||
bakPath,
|
||||
sshdPath,
|
||||
systemLogPath,
|
||||
];
|
||||
|
||||
if (!configDirExist) {
|
||||
await fs.mkdir(configPath);
|
||||
}
|
||||
|
||||
if (!scriptDirExist) {
|
||||
await fs.mkdir(scriptPath);
|
||||
}
|
||||
|
||||
if (!preloadDirExist) {
|
||||
await fs.mkdir(preloadPath);
|
||||
}
|
||||
|
||||
if (!logDirExist) {
|
||||
await fs.mkdir(logPath);
|
||||
}
|
||||
|
||||
if (!tmpDirExist) {
|
||||
await fs.mkdir(tmpPath);
|
||||
}
|
||||
|
||||
if (!uploadDirExist) {
|
||||
await fs.mkdir(uploadPath);
|
||||
}
|
||||
|
||||
if (!sshDirExist) {
|
||||
await fs.mkdir(sshPath);
|
||||
}
|
||||
|
||||
if (!bakDirExist) {
|
||||
await fs.mkdir(bakPath);
|
||||
}
|
||||
|
||||
if (!sshdDirExist) {
|
||||
await fs.mkdir(sshdPath);
|
||||
}
|
||||
|
||||
if (!systemLogDirExist) {
|
||||
await fs.mkdir(systemLogPath);
|
||||
}
|
||||
|
||||
// 初始化文件
|
||||
if (!authFileExist) {
|
||||
await fs.writeFile(authConfigFile, await fs.readFile(sampleAuthFile));
|
||||
}
|
||||
|
||||
if (!confFileExist) {
|
||||
await fs.writeFile(confFile, await fs.readFile(sampleConfigFile));
|
||||
}
|
||||
|
||||
await fs.writeFile(jsNotifyFile, await fs.readFile(sampleNotifyJsFile));
|
||||
await fs.writeFile(pyNotifyFile, await fs.readFile(sampleNotifyPyFile));
|
||||
|
||||
if (!scriptNotifyJsFileExist) {
|
||||
await fs.writeFile(
|
||||
scriptNotifyJsFile,
|
||||
await fs.readFile(sampleNotifyJsFile),
|
||||
);
|
||||
}
|
||||
|
||||
if (!scriptNotifyPyFileExist) {
|
||||
await fs.writeFile(
|
||||
scriptNotifyPyFile,
|
||||
await fs.readFile(sampleNotifyPyFile),
|
||||
);
|
||||
}
|
||||
|
||||
if (!TaskBeforeFileExist) {
|
||||
await fs.writeFile(TaskBeforeFile, await fs.readFile(sampleTaskShellFile));
|
||||
}
|
||||
|
||||
if (!TaskBeforeJsFileExist) {
|
||||
await fs.writeFile(
|
||||
TaskBeforeJsFile,
|
||||
const files = [
|
||||
{
|
||||
target: confFile,
|
||||
source: sampleConfigFile,
|
||||
checkExistence: true,
|
||||
},
|
||||
{
|
||||
target: jsNotifyFile,
|
||||
source: sampleNotifyJsFile,
|
||||
checkExistence: false,
|
||||
},
|
||||
{
|
||||
target: pyNotifyFile,
|
||||
source: sampleNotifyPyFile,
|
||||
checkExistence: false,
|
||||
},
|
||||
{
|
||||
target: scriptNotifyJsFile,
|
||||
source: sampleNotifyJsFile,
|
||||
checkExistence: true,
|
||||
},
|
||||
{
|
||||
target: scriptNotifyPyFile,
|
||||
source: sampleNotifyPyFile,
|
||||
checkExistence: true,
|
||||
},
|
||||
{
|
||||
target: TaskBeforeFile,
|
||||
source: sampleTaskShellFile,
|
||||
checkExistence: true,
|
||||
},
|
||||
{
|
||||
target: TaskBeforeJsFile,
|
||||
content:
|
||||
'// The JavaScript code that executes before the JavaScript task execution will execute.',
|
||||
);
|
||||
}
|
||||
|
||||
if (!TaskBeforePyFileExist) {
|
||||
await fs.writeFile(
|
||||
TaskBeforePyFile,
|
||||
checkExistence: true,
|
||||
},
|
||||
{
|
||||
target: TaskBeforePyFile,
|
||||
content:
|
||||
'# The Python code that executes before the Python task execution will execute.',
|
||||
);
|
||||
checkExistence: true,
|
||||
},
|
||||
{
|
||||
target: TaskAfterFile,
|
||||
source: sampleTaskShellFile,
|
||||
checkExistence: true,
|
||||
},
|
||||
];
|
||||
|
||||
export default async () => {
|
||||
for (const dirPath of directories) {
|
||||
if (!(await fileExist(dirPath))) {
|
||||
await fs.mkdir(dirPath);
|
||||
}
|
||||
}
|
||||
|
||||
if (!TaskAfterFileExist) {
|
||||
await fs.writeFile(TaskAfterFile, await fs.readFile(sampleTaskShellFile));
|
||||
for (const item of files) {
|
||||
const exists = await fileExist(item.target);
|
||||
if (!item.checkExistence || !exists) {
|
||||
if (!item.content && !item.source) {
|
||||
throw new Error(
|
||||
`Neither content nor source specified for ${item.target}`,
|
||||
);
|
||||
}
|
||||
const content = item.content || (await fs.readFile(item.source!));
|
||||
await writeFileWithLock(item.target, content);
|
||||
}
|
||||
}
|
||||
|
||||
Logger.info('✌️ Init file down');
|
||||
|
||||
@@ -4,10 +4,10 @@ import config from '../config';
|
||||
import path from 'path';
|
||||
|
||||
const levelMap: Record<string, string> = {
|
||||
info: '🔵',
|
||||
warn: '🟡',
|
||||
error: '🔴',
|
||||
debug: '🔶'
|
||||
info: '\ue6f5',
|
||||
warn: '\ue880',
|
||||
error: '\ue602',
|
||||
debug: '\ue67f'
|
||||
}
|
||||
|
||||
const customFormat = winston.format.combine(
|
||||
|
||||
@@ -2,9 +2,8 @@ import sockJs from 'sockjs';
|
||||
import { Server } from 'http';
|
||||
import { Container } from 'typedi';
|
||||
import SockService from '../services/sock';
|
||||
import config from '../config/index';
|
||||
import fs from 'fs/promises';
|
||||
import { getPlatform, safeJSONParse } from '../config/util';
|
||||
import { getPlatform } from '../config/util';
|
||||
import { shareStore } from '../shared/store';
|
||||
|
||||
export default async ({ server }: { server: Server }) => {
|
||||
const echo = sockJs.createServer({ prefix: '/api/ws', log: () => {} });
|
||||
@@ -15,11 +14,11 @@ export default async ({ server }: { server: Server }) => {
|
||||
conn.close('404');
|
||||
}
|
||||
|
||||
const data = await fs.readFile(config.authConfigFile, 'utf8');
|
||||
const authInfo = await shareStore.getAuthInfo();
|
||||
const platform = getPlatform(conn.headers['user-agent'] || '') || 'desktop';
|
||||
const headerToken = conn.url.replace(`${conn.pathname}?token=`, '');
|
||||
if (data) {
|
||||
const { token = '', tokens = {} } = safeJSONParse(data);
|
||||
if (authInfo) {
|
||||
const { token = '', tokens = {} } = authInfo;
|
||||
if (headerToken === token || tokens[platform] === headerToken) {
|
||||
sockService.addClient(conn);
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import bodyParser from 'body-parser';
|
||||
import { errors } from 'celebrate';
|
||||
import cors from 'cors';
|
||||
import { Application, NextFunction, Request, Response } from 'express';
|
||||
import jwt from 'express-jwt';
|
||||
import { expressjwt } from 'express-jwt';
|
||||
import Container from 'typedi';
|
||||
import config from '../config';
|
||||
import SystemService from '../services/system';
|
||||
@@ -16,7 +16,7 @@ export default ({ app }: { app: Application }) => {
|
||||
app.use(bodyParser.urlencoded({ limit: '50mb', extended: true }));
|
||||
|
||||
app.use(
|
||||
jwt({
|
||||
expressjwt({
|
||||
secret: config.secret,
|
||||
algorithms: ['HS384'],
|
||||
}),
|
||||
|
||||
@@ -17,7 +17,6 @@ server.bindAsync(
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
server.start();
|
||||
Logger.debug(`✌️ 定时服务启动成功!`);
|
||||
console.debug(`✌️ 定时服务启动成功!`);
|
||||
process.send?.('ready');
|
||||
|
||||
@@ -21,6 +21,7 @@ import { spawn } from 'cross-spawn';
|
||||
import dayjs from 'dayjs';
|
||||
import pickBy from 'lodash/pickBy';
|
||||
import omit from 'lodash/omit';
|
||||
import { writeFileWithLock } from '../shared/utils';
|
||||
|
||||
@Service()
|
||||
export default class CronService {
|
||||
@@ -601,7 +602,7 @@ export default class CronService {
|
||||
}
|
||||
});
|
||||
|
||||
await fs.writeFile(config.crontabFile, crontab_string);
|
||||
await writeFileWithLock(config.crontabFile, crontab_string);
|
||||
|
||||
execSync(`crontab ${config.crontabFile}`);
|
||||
await CrontabModel.update({ saved: true }, { where: {} });
|
||||
|
||||
@@ -353,7 +353,7 @@ export default class DependenceService {
|
||||
});
|
||||
this.updateLog(depIds, message);
|
||||
|
||||
let status = null;
|
||||
let status: number;
|
||||
if (isSucceed) {
|
||||
status = isInstall
|
||||
? DependenceStatus.installed
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
} from '../data/env';
|
||||
import groupBy from 'lodash/groupBy';
|
||||
import { FindOptions, Op } from 'sequelize';
|
||||
import { writeFileWithLock } from '../shared/utils';
|
||||
|
||||
@Service()
|
||||
export default class EnvService {
|
||||
@@ -225,8 +226,8 @@ export default class EnvService {
|
||||
}
|
||||
}
|
||||
}
|
||||
await fs.writeFile(config.envFile, env_string);
|
||||
await fs.writeFile(config.jsEnvFile, js_env_string);
|
||||
await fs.writeFile(config.pyEnvFile, py_env_string);
|
||||
await writeFileWithLock(config.envFile, env_string);
|
||||
await writeFileWithLock(config.jsEnvFile, js_env_string);
|
||||
await writeFileWithLock(config.pyEnvFile, py_env_string);
|
||||
}
|
||||
}
|
||||
|
||||
+97
-15
@@ -35,6 +35,8 @@ export default class NotificationService {
|
||||
['webhook', this.webhook],
|
||||
['lark', this.lark],
|
||||
['chronocat', this.chronocat],
|
||||
['ntfy', this.ntfy],
|
||||
['wxPusherBot', this.wxPusherBot],
|
||||
]);
|
||||
|
||||
private title = '';
|
||||
@@ -151,14 +153,16 @@ export default class NotificationService {
|
||||
|
||||
private async serverChan() {
|
||||
const { serverChanKey } = this.params;
|
||||
const url = serverChanKey.startsWith('SCT')
|
||||
? `https://sctapi.ftqq.com/${serverChanKey}.send`
|
||||
: `https://sc.ftqq.com/${serverChanKey}.send`;
|
||||
const matchResult = serverChanKey.match(/^sctp(\d+)t/i);
|
||||
const url = matchResult && matchResult[1]
|
||||
? `https://${matchResult[1]}.push.ft07.com/send/${serverChanKey}.send`
|
||||
: `https://sctapi.ftqq.com/${serverChanKey}.send`;
|
||||
|
||||
try {
|
||||
const res: any = await got
|
||||
.post(url, {
|
||||
...this.gotOption,
|
||||
body: `title=${this.title}&desp=${this.content}`,
|
||||
body: `title=${encodeURIComponent(this.title)}&desp=${encodeURIComponent(this.content)}`,
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
})
|
||||
.json();
|
||||
@@ -516,22 +520,29 @@ export default class NotificationService {
|
||||
} catch (error: any) {
|
||||
throw new Error(error.response ? error.response.body : error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async pushPlus() {
|
||||
const { pushPlusToken, pushPlusUser } = this.params;
|
||||
const { pushPlusToken, pushPlusUser, pushplusWebhook, pushPlusTemplate, pushplusChannel, pushplusCallbackUrl, pushplusTo} = this.params;
|
||||
const url = `https://www.pushplus.plus/send`;
|
||||
try {
|
||||
let body = {
|
||||
...this.gotOption,
|
||||
json: {
|
||||
token: `${pushPlusToken}`,
|
||||
title: `${this.title}`,
|
||||
content: `${this.content.replace(/[\n\r]/g, '<br>')}`,
|
||||
topic: `${pushPlusUser || ''}`,
|
||||
template: `${pushPlusTemplate || 'html'}`,
|
||||
channel: `${pushplusChannel || 'wechat'}`,
|
||||
webhook: `${pushplusWebhook || ''}`,
|
||||
callbackUrl: `${pushplusCallbackUrl || ''}`,
|
||||
to: `${pushplusTo || ''}`
|
||||
},
|
||||
}
|
||||
|
||||
const res: any = await got
|
||||
.post(url, {
|
||||
...this.gotOption,
|
||||
json: {
|
||||
token: `${pushPlusToken}`,
|
||||
title: `${this.title}`,
|
||||
content: `${this.content.replace(/[\n\r]/g, '<br>')}`,
|
||||
topic: `${pushPlusUser || ''}`,
|
||||
},
|
||||
})
|
||||
.post(url, body)
|
||||
.json();
|
||||
|
||||
if (res.code === 200) {
|
||||
@@ -661,6 +672,77 @@ export default class NotificationService {
|
||||
}
|
||||
}
|
||||
|
||||
private async ntfy() {
|
||||
const { ntfyUrl, ntfyTopic, ntfyPriority } = this.params;
|
||||
// 编码函数
|
||||
const encodeRfc2047 = (text: string, charset: string = 'UTF-8'): string => {
|
||||
const encodedText = Buffer.from(text).toString('base64');
|
||||
return `=?${charset}?B?${encodedText}?=`;
|
||||
};
|
||||
try {
|
||||
const encodedTitle = encodeRfc2047(this.title);
|
||||
const res: any = await got
|
||||
.post(`${ntfyUrl || 'https://ntfy.sh'}/${ntfyTopic}`, {
|
||||
...this.gotOption,
|
||||
body: `${this.content}`,
|
||||
headers: { 'Title': encodedTitle, 'Priority': `${ntfyPriority || '3'}` },
|
||||
});
|
||||
if (res.statusCode === 200) {
|
||||
return true;
|
||||
} else {
|
||||
throw new Error(JSON.stringify(res));
|
||||
}
|
||||
} catch (error: any) {
|
||||
throw new Error(error.response ? error.response.body : error);
|
||||
}
|
||||
}
|
||||
|
||||
private async wxPusherBot() {
|
||||
const { wxPusherBotAppToken, wxPusherBotTopicIds, wxPusherBotUids } = this.params;
|
||||
// 处理 topicIds,将分号分隔的字符串转为数组
|
||||
const topicIds = wxPusherBotTopicIds ? wxPusherBotTopicIds.split(';')
|
||||
.map(id => id.trim())
|
||||
.filter(id => id)
|
||||
.map(id => parseInt(id)) : [];
|
||||
|
||||
// 处理 uids,将分号分隔的字符串转为数组
|
||||
const uids = wxPusherBotUids ? wxPusherBotUids.split(';')
|
||||
.map(uid => uid.trim())
|
||||
.filter(uid => uid) : [];
|
||||
|
||||
// topic_ids 和 uids 至少要有一个
|
||||
if (!topicIds.length && !uids.length) {
|
||||
throw new Error('wxPusher 服务的 TopicIds 和 Uids 至少配置一个才行');
|
||||
}
|
||||
|
||||
const url = `https://wxpusher.zjiecode.com/api/send/message`;
|
||||
try {
|
||||
const res: any = await got
|
||||
.post(url, {
|
||||
...this.gotOption,
|
||||
json: {
|
||||
appToken: wxPusherBotAppToken,
|
||||
content: `<h1>${this.title}</h1><br/><div style='white-space: pre-wrap;'>${this.content}</div>`,
|
||||
summary: this.title,
|
||||
contentType: 2,
|
||||
topicIds: topicIds,
|
||||
uids: uids,
|
||||
verifyPayType: 0
|
||||
},
|
||||
})
|
||||
.json();
|
||||
|
||||
if (res.code === 1000) {
|
||||
return true;
|
||||
} else {
|
||||
throw new Error(JSON.stringify(res));
|
||||
}
|
||||
} catch (error: any) {
|
||||
throw new Error(error.response ? error.response.body : error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private async chronocat() {
|
||||
const { chronocatURL, chronocatQQ, chronocatToken } = this.params;
|
||||
try {
|
||||
|
||||
+25
-16
@@ -1,19 +1,18 @@
|
||||
import { Service, Inject } from 'typedi';
|
||||
import winston from 'winston';
|
||||
import { createRandomString } from '../config/util';
|
||||
import config from '../config';
|
||||
import { App, AppModel } from '../data/open';
|
||||
import { v4 as uuidV4 } from 'uuid';
|
||||
import sequelize, { Op } from 'sequelize';
|
||||
import { shareStore } from '../shared/store';
|
||||
|
||||
@Service()
|
||||
export default class OpenService {
|
||||
constructor(@Inject('logger') private logger: winston.Logger) {}
|
||||
|
||||
public async findTokenByValue(token: string): Promise<App | null> {
|
||||
public async findApps(): Promise<App[] | null> {
|
||||
const docs = await this.find({});
|
||||
const doc = docs.filter((x) => x.tokens?.find((y) => y.value === token));
|
||||
return doc[0];
|
||||
return docs;
|
||||
}
|
||||
|
||||
public async create(payload: App): Promise<App> {
|
||||
@@ -21,6 +20,8 @@ export default class OpenService {
|
||||
tab.client_id = createRandomString(12, 12);
|
||||
tab.client_secret = createRandomString(24, 24);
|
||||
const doc = await this.insert(tab);
|
||||
const apps = await this.find({});
|
||||
await shareStore.updateApps(apps);
|
||||
return { ...doc, tokens: [] };
|
||||
}
|
||||
|
||||
@@ -34,17 +35,19 @@ export default class OpenService {
|
||||
name: payload.name,
|
||||
scopes: payload.scopes,
|
||||
id: payload.id,
|
||||
} as any);
|
||||
} as App);
|
||||
return { ...newDoc, tokens: [] };
|
||||
}
|
||||
|
||||
private async updateDb(payload: App): Promise<App> {
|
||||
private async updateDb(payload: Partial<App>): Promise<App> {
|
||||
await AppModel.update(payload, { where: { id: payload.id } });
|
||||
return await this.getDb({ id: payload.id });
|
||||
const apps = await this.find({});
|
||||
await shareStore.updateApps(apps);
|
||||
return apps?.find((x) => x.id === payload.id) as App;
|
||||
}
|
||||
|
||||
public async getDb(query: any): Promise<App> {
|
||||
const doc: any = await AppModel.findOne({ where: query });
|
||||
public async getDb(query: Record<string, any>): Promise<App> {
|
||||
const doc = await AppModel.findOne({ where: query });
|
||||
if (!doc) {
|
||||
throw new Error(`App ${JSON.stringify(query)} not found`);
|
||||
}
|
||||
@@ -53,10 +56,12 @@ export default class OpenService {
|
||||
|
||||
public async remove(ids: number[]) {
|
||||
await AppModel.destroy({ where: { id: ids } });
|
||||
const apps = await this.find({});
|
||||
await shareStore.updateApps(apps);
|
||||
}
|
||||
|
||||
public async resetSecret(id: number): Promise<App> {
|
||||
const tab: any = {
|
||||
const tab: Partial<App> = {
|
||||
client_secret: createRandomString(24, 24),
|
||||
tokens: [],
|
||||
id,
|
||||
@@ -74,7 +79,7 @@ export default class OpenService {
|
||||
public async list(
|
||||
searchText: string = '',
|
||||
sort: any = {},
|
||||
query: any = {},
|
||||
query: Record<string, any> = {},
|
||||
): Promise<App[]> {
|
||||
let condition = { ...query };
|
||||
if (searchText) {
|
||||
@@ -101,7 +106,7 @@ export default class OpenService {
|
||||
}
|
||||
}
|
||||
|
||||
private async find(query: any, sort?: any): Promise<App[]> {
|
||||
private async find(query: Record<string, any>, sort?: any): Promise<App[]> {
|
||||
const docs = await AppModel.findAll({ where: { ...query } });
|
||||
return docs.map((x) => x.get({ plain: true }));
|
||||
}
|
||||
@@ -135,6 +140,8 @@ export default class OpenService {
|
||||
{ tokens },
|
||||
{ where: { client_id, client_secret } },
|
||||
);
|
||||
const apps = await this.find({});
|
||||
await shareStore.updateApps(apps);
|
||||
return {
|
||||
code: 200,
|
||||
data: {
|
||||
@@ -144,7 +151,7 @@ export default class OpenService {
|
||||
},
|
||||
};
|
||||
} else {
|
||||
return { code: 400, message: 'client_id或client_seret有误' };
|
||||
return { code: 400, message: 'client_id 或 client_seret 有误' };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,9 +159,11 @@ export default class OpenService {
|
||||
value: string;
|
||||
expiration: number;
|
||||
}> {
|
||||
let systemApp = (await AppModel.findOne({
|
||||
where: { name: 'system' },
|
||||
})) as App;
|
||||
let systemApp = (
|
||||
await AppModel.findOne({
|
||||
where: { name: 'system' },
|
||||
})
|
||||
)?.get({ plain: true });
|
||||
if (!systemApp) {
|
||||
systemApp = await this.create({
|
||||
name: 'system',
|
||||
|
||||
@@ -214,7 +214,7 @@ export default class ScheduleService {
|
||||
const job = new LongIntervalJob(
|
||||
{ runImmediately: false, ...schedule },
|
||||
task,
|
||||
_id,
|
||||
{ id: _id },
|
||||
);
|
||||
|
||||
this.intervalSchedule.addIntervalJob(job);
|
||||
|
||||
+17
-12
@@ -7,6 +7,7 @@ import { Subscription } from '../data/subscription';
|
||||
import { formatUrl } from '../config/subscription';
|
||||
import config from '../config';
|
||||
import { fileExist, rmPath } from '../config/util';
|
||||
import { writeFileWithLock } from '../shared/utils';
|
||||
|
||||
@Service()
|
||||
export default class SshKeyService {
|
||||
@@ -25,13 +26,12 @@ export default class SshKeyService {
|
||||
if (_exist) {
|
||||
config = await fs.readFile(this.sshConfigFilePath, { encoding: 'utf-8' });
|
||||
} else {
|
||||
await fs.writeFile(this.sshConfigFilePath, '');
|
||||
await writeFileWithLock(this.sshConfigFilePath, '');
|
||||
}
|
||||
if (!config.includes(this.sshConfigHeader)) {
|
||||
await fs.writeFile(
|
||||
await writeFileWithLock(
|
||||
this.sshConfigFilePath,
|
||||
`${this.sshConfigHeader}\n\n${config}`,
|
||||
{ encoding: 'utf-8' },
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -41,10 +41,14 @@ export default class SshKeyService {
|
||||
key: string,
|
||||
): Promise<void> {
|
||||
try {
|
||||
await fs.writeFile(path.join(this.sshPath, alias), `${key}${os.EOL}`, {
|
||||
encoding: 'utf8',
|
||||
mode: '400',
|
||||
});
|
||||
await writeFileWithLock(
|
||||
path.join(this.sshPath, alias),
|
||||
`${key}${os.EOL}`,
|
||||
{
|
||||
encoding: 'utf8',
|
||||
mode: '400',
|
||||
},
|
||||
);
|
||||
} catch (error) {
|
||||
this.logger.error('生成私钥文件失败', error);
|
||||
}
|
||||
@@ -74,12 +78,9 @@ export default class SshKeyService {
|
||||
this.sshPath,
|
||||
alias,
|
||||
)}\n StrictHostKeyChecking no\n${proxyStr}`;
|
||||
await fs.writeFile(
|
||||
await writeFileWithLock(
|
||||
`${path.join(this.sshPath, `${alias}.config`)}`,
|
||||
config,
|
||||
{
|
||||
encoding: 'utf8',
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -102,7 +103,11 @@ export default class SshKeyService {
|
||||
await this.generateSingleSshConfig(alias, host, proxy);
|
||||
}
|
||||
|
||||
public async removeSSHKey(alias: string, host: string, proxy?: string): Promise<void> {
|
||||
public async removeSSHKey(
|
||||
alias: string,
|
||||
host: string,
|
||||
proxy?: string,
|
||||
): Promise<void> {
|
||||
await this.removePrivateKeyFile(alias);
|
||||
await this.removeSshConfig(alias);
|
||||
}
|
||||
|
||||
@@ -54,13 +54,14 @@ export default class SystemService {
|
||||
}
|
||||
|
||||
private async updateAuthDb(payload: SystemInfo): Promise<SystemInfo> {
|
||||
await SystemModel.upsert({ ...payload });
|
||||
const doc = await this.getDb({ type: payload.type });
|
||||
const { id, ...others } = payload;
|
||||
await SystemModel.update(others, { where: { id } });
|
||||
const doc = await this.getDb({ id });
|
||||
return doc;
|
||||
}
|
||||
|
||||
public async getDb(query: any): Promise<SystemInfo> {
|
||||
const doc = await SystemModel.findOne({ where: { ...query } });
|
||||
const doc = await SystemModel.findOne({ where: query });
|
||||
if (!doc) {
|
||||
throw new Error(`System ${JSON.stringify(query)} not found`);
|
||||
}
|
||||
@@ -402,7 +403,7 @@ export default class SystemService {
|
||||
public async exportData(res: Response) {
|
||||
try {
|
||||
await promiseExec(
|
||||
`cd ${config.rootPath} && tar -zcvf ${config.dataTgzFile} data/`,
|
||||
`cd ${config.dataPath} && cd ../ && tar -zcvf ${config.dataTgzFile} data/`,
|
||||
);
|
||||
res.download(config.dataTgzFile);
|
||||
} catch (error: any) {
|
||||
@@ -414,7 +415,7 @@ export default class SystemService {
|
||||
try {
|
||||
await promiseExec(`rm -rf ${path.join(config.tmpPath, 'data')}`);
|
||||
const res = await promiseExec(
|
||||
`cd ${config.tmpPath} && tar -zxvf data.tgz`,
|
||||
`cd ${config.tmpPath} && tar -zxvf ${config.dataTgzFile}`,
|
||||
);
|
||||
return { code: 200, data: res };
|
||||
} catch (error: any) {
|
||||
|
||||
+148
-183
@@ -18,6 +18,7 @@ import {
|
||||
SystemModel,
|
||||
SystemModelInfo,
|
||||
LoginStatus,
|
||||
AuthInfo,
|
||||
} from '../data/system';
|
||||
import { NotificationInfo } from '../data/notify';
|
||||
import NotificationService from './notify';
|
||||
@@ -28,6 +29,7 @@ import dayjs from 'dayjs';
|
||||
import IP2Region from 'ip2region';
|
||||
import requestIp from 'request-ip';
|
||||
import uniq from 'lodash/uniq';
|
||||
import { shareStore } from '../shared/store';
|
||||
|
||||
@Service()
|
||||
export default class UserService {
|
||||
@@ -48,161 +50,138 @@ export default class UserService {
|
||||
req: Request,
|
||||
needTwoFactor = true,
|
||||
): Promise<any> {
|
||||
const _exist = await fileExist(config.authConfigFile);
|
||||
if (!_exist) {
|
||||
return this.initAuthInfo();
|
||||
}
|
||||
|
||||
let { username, password } = payloads;
|
||||
const content = await this.getAuthInfo();
|
||||
const timestamp = Date.now();
|
||||
if (content) {
|
||||
let {
|
||||
username: cUsername,
|
||||
password: cPassword,
|
||||
retries = 0,
|
||||
lastlogon,
|
||||
lastip,
|
||||
lastaddr,
|
||||
twoFactorActivated,
|
||||
twoFactorActived,
|
||||
tokens = {},
|
||||
platform,
|
||||
} = content;
|
||||
// patch old field
|
||||
twoFactorActivated = twoFactorActivated || twoFactorActived;
|
||||
let {
|
||||
username: cUsername,
|
||||
password: cPassword,
|
||||
retries = 0,
|
||||
lastlogon,
|
||||
lastip,
|
||||
lastaddr,
|
||||
twoFactorActivated,
|
||||
tokens = {},
|
||||
platform,
|
||||
} = content;
|
||||
const retriesTime = Math.pow(3, retries) * 1000;
|
||||
if (retries > 2 && timestamp - lastlogon < retriesTime) {
|
||||
const waitTime = Math.ceil(
|
||||
(retriesTime - (timestamp - lastlogon)) / 1000,
|
||||
);
|
||||
return {
|
||||
code: 410,
|
||||
message: `失败次数过多,请${waitTime}秒后重试`,
|
||||
data: waitTime,
|
||||
};
|
||||
}
|
||||
|
||||
if (
|
||||
(cUsername === 'admin' && cPassword === 'admin') ||
|
||||
!cUsername ||
|
||||
!cPassword
|
||||
) {
|
||||
return this.initAuthInfo();
|
||||
}
|
||||
if (
|
||||
username === cUsername &&
|
||||
password === cPassword &&
|
||||
twoFactorActivated &&
|
||||
needTwoFactor
|
||||
) {
|
||||
await this.updateAuthInfo(content, {
|
||||
isTwoFactorChecking: true,
|
||||
});
|
||||
return {
|
||||
code: 420,
|
||||
message: '',
|
||||
};
|
||||
}
|
||||
|
||||
const retriesTime = Math.pow(3, retries) * 1000;
|
||||
if (retries > 2 && timestamp - lastlogon < retriesTime) {
|
||||
const waitTime = Math.ceil(
|
||||
(retriesTime - (timestamp - lastlogon)) / 1000,
|
||||
);
|
||||
const ip = requestIp.getClientIp(req) || '';
|
||||
const query = new IP2Region();
|
||||
const ipAddress = query.search(ip);
|
||||
let address = '';
|
||||
if (ipAddress) {
|
||||
const { country, province, city, isp } = ipAddress;
|
||||
address = uniq([country, province, city, isp]).filter(Boolean).join(' ');
|
||||
}
|
||||
if (username === cUsername && password === cPassword) {
|
||||
const data = createRandomString(50, 100);
|
||||
const expiration = twoFactorActivated ? 60 : 20;
|
||||
let token = jwt.sign({ data }, config.secret as any, {
|
||||
expiresIn: 60 * 60 * 24 * expiration,
|
||||
algorithm: 'HS384',
|
||||
});
|
||||
|
||||
await this.updateAuthInfo(content, {
|
||||
token,
|
||||
tokens: {
|
||||
...tokens,
|
||||
[req.platform]: token,
|
||||
},
|
||||
lastlogon: timestamp,
|
||||
retries: 0,
|
||||
lastip: ip,
|
||||
lastaddr: address,
|
||||
platform: req.platform,
|
||||
isTwoFactorChecking: false,
|
||||
});
|
||||
this.notificationService.notify(
|
||||
'登录通知',
|
||||
`你于${dayjs(timestamp).format('YYYY-MM-DD HH:mm:ss')}在 ${address} ${
|
||||
req.platform
|
||||
}端 登录成功,ip地址 ${ip}`,
|
||||
);
|
||||
await this.insertDb({
|
||||
type: AuthDataType.loginLog,
|
||||
info: {
|
||||
timestamp,
|
||||
address,
|
||||
ip,
|
||||
platform: req.platform,
|
||||
status: LoginStatus.success,
|
||||
},
|
||||
});
|
||||
this.getLoginLog();
|
||||
return {
|
||||
code: 200,
|
||||
data: { token, lastip, lastaddr, lastlogon, retries, platform },
|
||||
};
|
||||
} else {
|
||||
await this.updateAuthInfo(content, {
|
||||
retries: retries + 1,
|
||||
lastlogon: timestamp,
|
||||
lastip: ip,
|
||||
lastaddr: address,
|
||||
platform: req.platform,
|
||||
});
|
||||
this.notificationService.notify(
|
||||
'登录通知',
|
||||
`你于${dayjs(timestamp).format('YYYY-MM-DD HH:mm:ss')}在 ${address} ${
|
||||
req.platform
|
||||
}端 登录失败,ip地址 ${ip}`,
|
||||
);
|
||||
await this.insertDb({
|
||||
type: AuthDataType.loginLog,
|
||||
info: {
|
||||
timestamp,
|
||||
address,
|
||||
ip,
|
||||
platform: req.platform,
|
||||
status: LoginStatus.fail,
|
||||
},
|
||||
});
|
||||
this.getLoginLog();
|
||||
if (retries > 2) {
|
||||
const waitTime = Math.round(Math.pow(3, retries + 1));
|
||||
return {
|
||||
code: 410,
|
||||
message: `失败次数过多,请${waitTime}秒后重试`,
|
||||
data: waitTime,
|
||||
};
|
||||
}
|
||||
|
||||
if (
|
||||
username === cUsername &&
|
||||
password === cPassword &&
|
||||
twoFactorActivated &&
|
||||
needTwoFactor
|
||||
) {
|
||||
this.updateAuthInfo(content, {
|
||||
isTwoFactorChecking: true,
|
||||
});
|
||||
return {
|
||||
code: 420,
|
||||
message: '',
|
||||
};
|
||||
}
|
||||
|
||||
const ip = requestIp.getClientIp(req) || '';
|
||||
const query = new IP2Region();
|
||||
const ipAddress = query.search(ip);
|
||||
let address = '';
|
||||
if (ipAddress) {
|
||||
const { country, province, city, isp } = ipAddress;
|
||||
address = uniq([country, province, city, isp])
|
||||
.filter(Boolean)
|
||||
.join(' ');
|
||||
}
|
||||
if (username === cUsername && password === cPassword) {
|
||||
const data = createRandomString(50, 100);
|
||||
const expiration = twoFactorActivated ? 60 : 20;
|
||||
let token = jwt.sign({ data }, config.secret as any, {
|
||||
expiresIn: 60 * 60 * 24 * expiration,
|
||||
algorithm: 'HS384',
|
||||
});
|
||||
|
||||
this.updateAuthInfo(content, {
|
||||
token,
|
||||
tokens: {
|
||||
...tokens,
|
||||
[req.platform]: token,
|
||||
},
|
||||
lastlogon: timestamp,
|
||||
retries: 0,
|
||||
lastip: ip,
|
||||
lastaddr: address,
|
||||
platform: req.platform,
|
||||
isTwoFactorChecking: false,
|
||||
});
|
||||
this.notificationService.notify(
|
||||
'登录通知',
|
||||
`你于${dayjs(timestamp).format('YYYY-MM-DD HH:mm:ss')}在 ${address} ${
|
||||
req.platform
|
||||
}端 登录成功,ip地址 ${ip}`,
|
||||
);
|
||||
await this.insertDb({
|
||||
type: AuthDataType.loginLog,
|
||||
info: {
|
||||
timestamp,
|
||||
address,
|
||||
ip,
|
||||
platform: req.platform,
|
||||
status: LoginStatus.success,
|
||||
},
|
||||
});
|
||||
this.getLoginLog();
|
||||
return {
|
||||
code: 200,
|
||||
data: { token, lastip, lastaddr, lastlogon, retries, platform },
|
||||
};
|
||||
} else {
|
||||
this.updateAuthInfo(content, {
|
||||
retries: retries + 1,
|
||||
lastlogon: timestamp,
|
||||
lastip: ip,
|
||||
lastaddr: address,
|
||||
platform: req.platform,
|
||||
});
|
||||
this.notificationService.notify(
|
||||
'登录通知',
|
||||
`你于${dayjs(timestamp).format('YYYY-MM-DD HH:mm:ss')}在 ${address} ${
|
||||
req.platform
|
||||
}端 登录失败,ip地址 ${ip}`,
|
||||
);
|
||||
await this.insertDb({
|
||||
type: AuthDataType.loginLog,
|
||||
info: {
|
||||
timestamp,
|
||||
address,
|
||||
ip,
|
||||
platform: req.platform,
|
||||
status: LoginStatus.fail,
|
||||
},
|
||||
});
|
||||
this.getLoginLog();
|
||||
if (retries > 2) {
|
||||
const waitTime = Math.round(Math.pow(3, retries + 1));
|
||||
return {
|
||||
code: 410,
|
||||
message: `失败次数过多,请${waitTime}秒后重试`,
|
||||
data: waitTime,
|
||||
};
|
||||
} else {
|
||||
return { code: 400, message: config.authError };
|
||||
}
|
||||
return { code: 400, message: config.authError };
|
||||
}
|
||||
} else {
|
||||
return this.initAuthInfo();
|
||||
}
|
||||
}
|
||||
|
||||
public async logout(platform: string): Promise<any> {
|
||||
const authInfo = await this.getAuthInfo();
|
||||
this.updateAuthInfo(authInfo, {
|
||||
await this.updateAuthInfo(authInfo, {
|
||||
token: '',
|
||||
tokens: { ...authInfo.tokens, [platform]: '' },
|
||||
});
|
||||
@@ -217,7 +196,7 @@ export default class UserService {
|
||||
(a, b) => b.info!.timestamp! - a.info!.timestamp!,
|
||||
);
|
||||
if (result.length > 100) {
|
||||
const ids = result.slice(0, result.length - 100).map((x) => x.id!);
|
||||
const ids = result.slice(100).map((x) => x.id!);
|
||||
await SystemModel.destroy({
|
||||
where: { id: ids },
|
||||
});
|
||||
@@ -232,20 +211,6 @@ export default class UserService {
|
||||
return doc;
|
||||
}
|
||||
|
||||
private async initAuthInfo() {
|
||||
await fs.writeFile(
|
||||
config.authConfigFile,
|
||||
JSON.stringify({
|
||||
username: 'admin',
|
||||
password: 'admin',
|
||||
}),
|
||||
);
|
||||
return {
|
||||
code: 100,
|
||||
message: '未找到认证文件,重新初始化',
|
||||
};
|
||||
}
|
||||
|
||||
public async updateUsernameAndPassword({
|
||||
username,
|
||||
password,
|
||||
@@ -257,35 +222,21 @@ export default class UserService {
|
||||
return { code: 400, message: '密码不能设置为admin' };
|
||||
}
|
||||
const authInfo = await this.getAuthInfo();
|
||||
this.updateAuthInfo(authInfo, { username, password });
|
||||
await this.updateAuthInfo(authInfo, { username, password });
|
||||
return { code: 200, message: '更新成功' };
|
||||
}
|
||||
|
||||
public async updateAvatar(avatar: string) {
|
||||
const authInfo = await this.getAuthInfo();
|
||||
this.updateAuthInfo(authInfo, { avatar });
|
||||
await this.updateAuthInfo(authInfo, { avatar });
|
||||
return { code: 200, data: avatar, message: '更新成功' };
|
||||
}
|
||||
|
||||
public async getUserInfo(): Promise<any> {
|
||||
const authFileExist = await fileExist(config.authConfigFile);
|
||||
if (!authFileExist) {
|
||||
await createFile(
|
||||
config.authConfigFile,
|
||||
JSON.stringify({
|
||||
username: 'admin',
|
||||
password: 'admin',
|
||||
}),
|
||||
);
|
||||
}
|
||||
return await this.getAuthInfo();
|
||||
}
|
||||
|
||||
public async initTwoFactor() {
|
||||
const secret = authenticator.generateSecret();
|
||||
const authInfo = await this.getAuthInfo();
|
||||
const otpauth = authenticator.keyuri(authInfo.username, 'qinglong', secret);
|
||||
this.updateAuthInfo(authInfo, { twoFactorSecret: secret });
|
||||
await this.updateAuthInfo(authInfo, { twoFactorSecret: secret });
|
||||
return { secret, url: otpauth };
|
||||
}
|
||||
|
||||
@@ -296,7 +247,7 @@ export default class UserService {
|
||||
secret: authInfo.twoFactorSecret,
|
||||
});
|
||||
if (isValid) {
|
||||
this.updateAuthInfo(authInfo, { twoFactorActivated: true });
|
||||
await this.updateAuthInfo(authInfo, { twoFactorActivated: true });
|
||||
}
|
||||
return isValid;
|
||||
}
|
||||
@@ -322,7 +273,7 @@ export default class UserService {
|
||||
return this.login({ username, password }, req, false);
|
||||
} else {
|
||||
const { ip, address } = await getNetIp(req);
|
||||
this.updateAuthInfo(authInfo, {
|
||||
await this.updateAuthInfo(authInfo, {
|
||||
lastip: ip,
|
||||
lastaddr: address,
|
||||
platform: req.platform,
|
||||
@@ -333,24 +284,29 @@ export default class UserService {
|
||||
|
||||
public async deactiveTwoFactor() {
|
||||
const authInfo = await this.getAuthInfo();
|
||||
this.updateAuthInfo(authInfo, {
|
||||
await this.updateAuthInfo(authInfo, {
|
||||
twoFactorActivated: false,
|
||||
twoFactorActived: false,
|
||||
twoFactorSecret: '',
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
private async getAuthInfo() {
|
||||
const content = await fs.readFile(config.authConfigFile, 'utf8');
|
||||
return safeJSONParse(content);
|
||||
public async getAuthInfo() {
|
||||
const authInfo = await shareStore.getAuthInfo();
|
||||
if (authInfo) {
|
||||
return authInfo;
|
||||
}
|
||||
const doc = await this.getDb({ type: AuthDataType.authConfig });
|
||||
return (doc.info || {}) as AuthInfo;
|
||||
}
|
||||
|
||||
private async updateAuthInfo(authInfo: any, info: any) {
|
||||
await fs.writeFile(
|
||||
config.authConfigFile,
|
||||
JSON.stringify({ ...authInfo, ...info }),
|
||||
);
|
||||
private async updateAuthInfo(authInfo: AuthInfo, info: Partial<AuthInfo>) {
|
||||
const result = { ...authInfo, ...info };
|
||||
await shareStore.updateAuthInfo(result);
|
||||
await this.updateAuthDb({
|
||||
type: AuthDataType.authConfig,
|
||||
info: result,
|
||||
});
|
||||
}
|
||||
|
||||
public async getNotificationMode(): Promise<NotificationInfo> {
|
||||
@@ -359,7 +315,7 @@ export default class UserService {
|
||||
}
|
||||
|
||||
private async updateAuthDb(payload: SystemInfo): Promise<any> {
|
||||
let doc = await SystemModel.findOne({ type: payload.type });
|
||||
let doc = await SystemModel.findOne({ where: { type: payload.type } });
|
||||
if (doc) {
|
||||
const updateResult = await SystemModel.update(payload, {
|
||||
where: { id: doc.id },
|
||||
@@ -397,4 +353,13 @@ export default class UserService {
|
||||
return { code: 400, message: '通知发送失败,请检查参数' };
|
||||
}
|
||||
}
|
||||
|
||||
public async resetAuthInfo(info: Partial<AuthInfo>) {
|
||||
const { retries, twoFactorActivated } = info;
|
||||
const authInfo = await this.getAuthInfo();
|
||||
await this.updateAuthInfo(authInfo, {
|
||||
retries,
|
||||
twoFactorActivated,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import { AuthInfo } from '../data/system';
|
||||
import { App } from '../data/open';
|
||||
import Keyv from 'keyv';
|
||||
import KeyvSqlite from '@keyv/sqlite';
|
||||
import config from '../config';
|
||||
import path from 'path';
|
||||
|
||||
export enum EKeyv {
|
||||
'apps' = 'apps',
|
||||
'authInfo' = 'authInfo',
|
||||
}
|
||||
|
||||
export interface IKeyvStore {
|
||||
apps: App[];
|
||||
authInfo: AuthInfo;
|
||||
}
|
||||
|
||||
const keyvSqlite = new KeyvSqlite(path.join(config.dbPath, 'keyv.sqlite'));
|
||||
export const keyvStore = new Keyv<IKeyvStore>({ store: keyvSqlite });
|
||||
|
||||
export const shareStore = {
|
||||
getAuthInfo() {
|
||||
return keyvStore.get<IKeyvStore['authInfo']>(EKeyv.authInfo);
|
||||
},
|
||||
updateAuthInfo(value: IKeyvStore['authInfo']) {
|
||||
return keyvStore.set<IKeyvStore['authInfo']>(EKeyv.authInfo, value);
|
||||
},
|
||||
getApps() {
|
||||
return keyvStore.get<IKeyvStore['apps']>(EKeyv.apps);
|
||||
},
|
||||
updateApps(apps: App[]) {
|
||||
return keyvStore.set<IKeyvStore['apps']>(EKeyv.apps, apps);
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,27 @@
|
||||
import { lock } from 'proper-lockfile';
|
||||
import { writeFile, open } from 'fs/promises';
|
||||
import { fileExist } from '../config/util';
|
||||
|
||||
export async function writeFileWithLock(
|
||||
path: string,
|
||||
content: string | Buffer,
|
||||
options: Parameters<typeof writeFile>[2] = {},
|
||||
) {
|
||||
if (typeof options === 'string') {
|
||||
options = { encoding: options };
|
||||
}
|
||||
if (!(await fileExist(path))) {
|
||||
const fileHandle = await open(path, 'w');
|
||||
fileHandle.close();
|
||||
}
|
||||
const release = await lock(path, {
|
||||
retries: {
|
||||
retries: 10,
|
||||
factor: 2,
|
||||
minTimeout: 100,
|
||||
maxTimeout: 3000,
|
||||
},
|
||||
});
|
||||
await writeFile(path, content, { encoding: 'utf8', ...options });
|
||||
await release();
|
||||
}
|
||||
+2
-10
@@ -6,6 +6,7 @@ import fs from 'fs';
|
||||
import config from './config';
|
||||
import path from 'path';
|
||||
import os from 'os';
|
||||
import { writeFileWithLock } from './shared/utils';
|
||||
|
||||
const tokenFile = path.join(config.configPath, 'token.json');
|
||||
|
||||
@@ -25,16 +26,7 @@ async function getToken() {
|
||||
}
|
||||
|
||||
async function writeFile(data: any) {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
fs.writeFile(
|
||||
tokenFile,
|
||||
`${JSON.stringify(data)}${os.EOL}`,
|
||||
{ encoding: 'utf8' },
|
||||
() => {
|
||||
resolve();
|
||||
},
|
||||
);
|
||||
});
|
||||
await writeFileWithLock(tokenFile, `${JSON.stringify(data)}${os.EOL}`);
|
||||
}
|
||||
|
||||
getToken();
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
import { CommandModule } from 'yargs';
|
||||
export const updateCommand: CommandModule = {
|
||||
command: 'update',
|
||||
describe: 'Update and restart qinglong',
|
||||
builder: (yargs) => {
|
||||
return yargs.option('repositority', {
|
||||
type: 'string',
|
||||
alias: 'r',
|
||||
describe: `Specify the release warehouse address of the package`,
|
||||
});
|
||||
},
|
||||
handler: async (argv) => {},
|
||||
};
|
||||
@@ -1,13 +0,0 @@
|
||||
import * as yargs from 'yargs';
|
||||
import { green, red } from 'chalk';
|
||||
import { updateCommand } from './commands/update';
|
||||
|
||||
yargs
|
||||
.usage('Usage: ql [command] <options>')
|
||||
.command(updateCommand)
|
||||
.fail((err) => {
|
||||
console.error(`${red(err)}`);
|
||||
})
|
||||
.alias('h', 'help')
|
||||
.showHelp()
|
||||
.recommendCommands().argv;
|
||||
@@ -1,15 +1,10 @@
|
||||
version: '2'
|
||||
services:
|
||||
web:
|
||||
# alpine 基础镜像版本
|
||||
image: whyour/qinglong:latest
|
||||
# debian-slim 基础镜像版本
|
||||
# image: whyour/qinglong:debian
|
||||
image: whyour/qinglong:latest # 基于 Debian 的版本:whyour/qinglong:debian
|
||||
volumes:
|
||||
- ./data:/ql/data
|
||||
ports:
|
||||
- "0.0.0.0:5700:5700"
|
||||
- "5700:5700"
|
||||
environment:
|
||||
# 部署路径非必须,以斜杠开头和结尾,比如 /test/
|
||||
QlBaseUrl: '/'
|
||||
QlBaseUrl: '/' # 部署路径非必须,以斜杠开头和结尾,比如 /test/
|
||||
restart: unless-stopped
|
||||
|
||||
+46
-40
@@ -54,62 +54,68 @@
|
||||
"react-dom": "18",
|
||||
"dva-core": "2"
|
||||
}
|
||||
},
|
||||
"overrides": {
|
||||
"sqlite3": "git+https://github.com/whyour/node-sqlite3.git#v1.0.3"
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"@grpc/grpc-js": "^1.8.13",
|
||||
"@grpc/grpc-js": "^1.12.3",
|
||||
"@otplib/preset-default": "^12.0.1",
|
||||
"@sentry/node": "^8.26.0",
|
||||
"body-parser": "^1.19.2",
|
||||
"celebrate": "^15.0.1",
|
||||
"chokidar": "^3.5.3",
|
||||
"@sentry/node": "^8.42.0",
|
||||
"body-parser": "^1.20.3",
|
||||
"celebrate": "^15.0.3",
|
||||
"chokidar": "^4.0.1",
|
||||
"cors": "^2.8.5",
|
||||
"cron-parser": "^4.2.1",
|
||||
"cross-spawn": "^7.0.3",
|
||||
"dayjs": "^1.11.2",
|
||||
"dotenv": "^16.0.0",
|
||||
"express": "^4.17.3",
|
||||
"express-jwt": "^6.1.1",
|
||||
"express-rate-limit": "^7.0.0",
|
||||
"express-urlrewrite": "^1.4.0",
|
||||
"cron-parser": "^4.9.0",
|
||||
"cross-spawn": "^7.0.6",
|
||||
"dayjs": "^1.11.13",
|
||||
"dotenv": "^16.4.6",
|
||||
"express": "^4.21.1",
|
||||
"express-jwt": "^8.4.1",
|
||||
"express-rate-limit": "^7.4.1",
|
||||
"express-urlrewrite": "^2.0.3",
|
||||
"form-data": "^4.0.0",
|
||||
"got": "^11.8.2",
|
||||
"hpagent": "^1.2.0",
|
||||
"http-proxy-middleware": "^2.0.6",
|
||||
"http-proxy-middleware": "^3.0.3",
|
||||
"iconv-lite": "^0.6.3",
|
||||
"js-yaml": "^4.1.0",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"jsonwebtoken": "^9.0.2",
|
||||
"lodash": "^4.17.21",
|
||||
"multer": "1.4.5-lts.1",
|
||||
"nedb": "^1.8.0",
|
||||
"node-schedule": "^2.1.0",
|
||||
"nodemailer": "^6.7.2",
|
||||
"nodemailer": "^6.9.16",
|
||||
"p-queue-cjs": "7.3.4",
|
||||
"protobufjs": "^7.3.0",
|
||||
"protobufjs": "^7.4.0",
|
||||
"pstree.remy": "^1.1.8",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"sequelize": "^6.25.5",
|
||||
"serve-handler": "^6.1.3",
|
||||
"reflect-metadata": "^0.2.2",
|
||||
"sequelize": "^6.37.5",
|
||||
"serve-handler": "^6.1.6",
|
||||
"sockjs": "^0.3.24",
|
||||
"sqlite3": "git+https://github.com/whyour/node-sqlite3.git#v1.0.3",
|
||||
"toad-scheduler": "^1.6.0",
|
||||
"toad-scheduler": "^3.0.1",
|
||||
"typedi": "^0.10.0",
|
||||
"uuid": "^8.3.2",
|
||||
"winston": "^3.6.0",
|
||||
"winston-daily-rotate-file": "^4.7.1",
|
||||
"yargs": "^17.3.1",
|
||||
"tough-cookie": "^4.0.0",
|
||||
"uuid": "^11.0.3",
|
||||
"winston": "^3.17.0",
|
||||
"winston-daily-rotate-file": "^5.0.0",
|
||||
"request-ip": "3.3.0",
|
||||
"ip2region": "2.3.0"
|
||||
"ip2region": "2.3.0",
|
||||
"keyv": "^5.2.3",
|
||||
"@keyv/sqlite": "^4.0.1",
|
||||
"proper-lockfile": "^4.1.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"moment": "2.30.1",
|
||||
"@ant-design/icons": "^4.7.0",
|
||||
"@ant-design/icons": "^5.0.1",
|
||||
"@ant-design/pro-layout": "6.38.22",
|
||||
"@codemirror/view": "^6.34.1",
|
||||
"@codemirror/state": "^6.4.1",
|
||||
"@monaco-editor/react": "4.2.1",
|
||||
"@react-hook/resize-observer": "^1.2.6",
|
||||
"@react-hook/resize-observer": "^2.0.2",
|
||||
"react-router-dom": "6.26.1",
|
||||
"@sentry/react": "^8.26.0",
|
||||
"@sentry/react": "^8.42.0",
|
||||
"@types/body-parser": "^1.19.2",
|
||||
"@types/cors": "^2.8.12",
|
||||
"@types/cross-spawn": "^6.0.2",
|
||||
@@ -133,18 +139,19 @@
|
||||
"@types/sockjs-client": "^1.5.1",
|
||||
"@types/uuid": "^8.3.4",
|
||||
"@types/request-ip": "0.0.41",
|
||||
"@types/proper-lockfile": "^4.1.4",
|
||||
"@uiw/codemirror-extensions-langs": "^4.21.9",
|
||||
"@uiw/react-codemirror": "^4.21.9",
|
||||
"@umijs/max": "^4.0.72",
|
||||
"@umijs/max": "^4.3.36",
|
||||
"@umijs/ssr-darkreader": "^4.9.45",
|
||||
"ahooks": "^3.7.8",
|
||||
"ansi-to-react": "^6.1.6",
|
||||
"antd": "^4.24.8",
|
||||
"antd-img-crop": "^4.2.3",
|
||||
"antd-img-crop": "^4.23.0",
|
||||
"axios": "^1.4.0",
|
||||
"compression-webpack-plugin": "9.2.0",
|
||||
"concurrently": "^7.0.0",
|
||||
"react-hotkeys-hook": "^4.4.1",
|
||||
"react-hotkeys-hook": "^4.6.1",
|
||||
"file-saver": "2.0.2",
|
||||
"lint-staged": "^13.0.3",
|
||||
"monaco-editor": "0.33.0",
|
||||
@@ -155,14 +162,14 @@
|
||||
"qrcode.react": "^1.0.1",
|
||||
"query-string": "^7.1.1",
|
||||
"rc-tween-one": "^3.0.6",
|
||||
"rc-virtual-list": "3.5.3",
|
||||
"react": "18.2.0",
|
||||
"rc-virtual-list": "3.15.0",
|
||||
"react": "18.3.1",
|
||||
"react-copy-to-clipboard": "^5.1.0",
|
||||
"react-diff-viewer": "^3.1.1",
|
||||
"react-dnd": "^14.0.2",
|
||||
"react-dnd-html5-backend": "^14.0.0",
|
||||
"react-dom": "18.2.0",
|
||||
"react-intl-universal": "^2.6.21",
|
||||
"react-dnd": "^16.0.1",
|
||||
"react-dnd-html5-backend": "^16.0.1",
|
||||
"react-dom": "18.3.1",
|
||||
"react-intl-universal": "^2.12.0",
|
||||
"react-split-pane": "^0.1.92",
|
||||
"sockjs-client": "^1.6.0",
|
||||
"ts-node": "^10.9.2",
|
||||
@@ -171,7 +178,6 @@
|
||||
"typescript": "5.2.2",
|
||||
"vh-check": "^2.0.5",
|
||||
"virtualizedtableforantd4": "1.3.0",
|
||||
"webpack": "^5.70.0",
|
||||
"yorkie": "^2.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
Generated
+5278
-6117
File diff suppressed because it is too large
Load Diff
+30
-1
@@ -117,6 +117,16 @@ export PUSH_PLUS_TOKEN=""
|
||||
## 下方填写您的一对多推送的 "群组编码" ,(一对多推送下面->您的群组(如无则新建)->群组编码)
|
||||
## 1. 需订阅者扫描二维码 2、如果您是创建群组所属人,也需点击“查看二维码”扫描绑定,否则不能接受群组消息推送
|
||||
export PUSH_PLUS_USER=""
|
||||
## 发送模板,支持html,txt,json,markdown,cloudMonitor,jenkins,route,pay
|
||||
export PUSH_PLUS_TEMPLATE="html"
|
||||
## 发送渠道,支持wechat,webhook,cp,mail,sms
|
||||
export PUSH_PLUS_CHANNEL="wechat"
|
||||
## webhook编码,可在pushplus公众号上扩展配置出更多渠道
|
||||
export PUSH_PLUS_WEBHOOK=""
|
||||
## 发送结果回调地址,会把推送最终结果通知到这个地址上
|
||||
export PUSH_PLUS_CALLBACKURL=""
|
||||
## 好友令牌,微信公众号渠道填写好友令牌,企业微信渠道填写企业微信用户id
|
||||
export PUSH_PLUS_TO=""
|
||||
|
||||
## 9. 微加机器人
|
||||
## 官方网站:http://www.weplusbot.com
|
||||
@@ -211,7 +221,26 @@ export FSKEY=""
|
||||
export QMSG_KEY=""
|
||||
export QMSG_TYPE=""
|
||||
|
||||
## 20. 自定义通知
|
||||
## 20.Ntfy
|
||||
## 官方文档: https://docs.ntfy.sh
|
||||
## ntfy_url 填写ntfy地址,如https://ntfy.sh
|
||||
## ntfy_topic 填写ntfy的消息应用topic
|
||||
## ntfy_priority 填写推送消息优先级,默认为3
|
||||
export NTFY_URL=""
|
||||
export NTFY_TOPIC=""
|
||||
export NTFY_PRIORITY="3"
|
||||
|
||||
## 21. wxPusher
|
||||
## 官方文档: https://wxpusher.zjiecode.com/docs/
|
||||
## 管理后台: https://wxpusher.zjiecode.com/admin/
|
||||
## wxPusher 的 appToken
|
||||
export WXPUSHER_APP_TOKEN=""
|
||||
## wxPusher 的 topicIds,多个用英文分号;分隔 topic_ids 与 uids 至少配置一个才行
|
||||
export WXPUSHER_TOPIC_IDS=""
|
||||
## wxPusher 的 用户ID,多个用英文分号;分隔 topic_ids 与 uids 至少配置一个才行
|
||||
export WXPUSHER_UIDS=""
|
||||
|
||||
## 22. 自定义通知
|
||||
## 自定义通知 接收回调的URL
|
||||
export WEBHOOK_URL=""
|
||||
## WEBHOOK_BODY 和 WEBHOOK_HEADERS 多个参数时,直接换行或者使用 $'\n' 连接多行字符串,比如 export dd="line 1"$'\n'"line 2"
|
||||
|
||||
+160
-12
@@ -40,9 +40,14 @@ const push_config = {
|
||||
CHAT_URL: '', // synology chat url
|
||||
CHAT_TOKEN: '', // synology chat token
|
||||
|
||||
// 官方文档:http://www.pushplus.plus/
|
||||
PUSH_PLUS_TOKEN: '', // push+ 微信推送的用户令牌
|
||||
PUSH_PLUS_USER: '', // push+ 微信推送的群组编码
|
||||
// 官方文档:https://www.pushplus.plus/
|
||||
PUSH_PLUS_TOKEN: '', // pushplus 推送的用户令牌
|
||||
PUSH_PLUS_USER: '', // pushplus 推送的群组编码
|
||||
PUSH_PLUS_TEMPLATE: 'html', // pushplus 发送模板,支持html,txt,json,markdown,cloudMonitor,jenkins,route,pay
|
||||
PUSH_PLUS_CHANNEL: 'wechat', // pushplus 发送渠道,支持wechat,webhook,cp,mail,sms
|
||||
PUSH_PLUS_WEBHOOK: '', // pushplus webhook编码,可在pushplus公众号上扩展配置出更多渠道
|
||||
PUSH_PLUS_CALLBACKURL: '', // pushplus 发送结果回调地址,会把推送最终结果通知到这个地址上
|
||||
PUSH_PLUS_TO: '', // pushplus 好友令牌,微信公众号渠道填写好友令牌,企业微信渠道填写企业微信用户id
|
||||
|
||||
// 微加机器人,官方网站:https://www.weplusbot.com/
|
||||
WE_PLUS_BOT_TOKEN: '', // 微加机器人的用户令牌
|
||||
@@ -95,6 +100,16 @@ const push_config = {
|
||||
WEBHOOK_HEADERS: '', // 自定义通知 请求头
|
||||
WEBHOOK_METHOD: '', // 自定义通知 请求方法
|
||||
WEBHOOK_CONTENT_TYPE: '', // 自定义通知 content-type
|
||||
|
||||
NTFY_URL: '', // ntfy地址,如https://ntfy.sh,默认为https://ntfy.sh
|
||||
NTFY_TOPIC: '', // ntfy的消息应用topic
|
||||
NTFY_PRIORITY: '3', // 推送消息优先级,默认为3
|
||||
|
||||
// 官方文档: https://wxpusher.zjiecode.com/docs/
|
||||
// 管理后台: https://wxpusher.zjiecode.com/admin/
|
||||
WXPUSHER_APP_TOKEN: '', // wxpusher 的 appToken
|
||||
WXPUSHER_TOPIC_IDS: '', // wxpusher 的 主题ID,多个用英文分号;分隔 topic_ids 与 uids 至少配置一个才行
|
||||
WXPUSHER_UIDS: '', // wxpusher 的 用户ID,多个用英文分号;分隔 topic_ids 与 uids 至少配置一个才行
|
||||
};
|
||||
|
||||
for (const key in push_config) {
|
||||
@@ -224,11 +239,16 @@ function serverNotify(text, desp) {
|
||||
if (PUSH_KEY) {
|
||||
// 微信server酱推送通知一个\n不会换行,需要两个\n才能换行,故做此替换
|
||||
desp = desp.replace(/[\n\r]/g, '\n\n');
|
||||
|
||||
const matchResult = PUSH_KEY.match(/^sctp(\d+)t/i);
|
||||
const options = {
|
||||
url: PUSH_KEY.includes('SCT')
|
||||
? `https://sctapi.ftqq.com/${PUSH_KEY}.send`
|
||||
: `https://sc.ftqq.com/${PUSH_KEY}.send`,
|
||||
body: `text=${text}&desp=${desp}`,
|
||||
url:
|
||||
matchResult && matchResult[1]
|
||||
? `https://${matchResult[1]}.push.ft07.com/send/${PUSH_KEY}.send`
|
||||
: `https://sctapi.ftqq.com/${PUSH_KEY}.send`,
|
||||
body: `text=${encodeURIComponent(text)}&desp=${encodeURIComponent(
|
||||
desp,
|
||||
)}`,
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
@@ -759,7 +779,15 @@ function iGotNotify(text, desp, params = {}) {
|
||||
|
||||
function pushPlusNotify(text, desp) {
|
||||
return new Promise((resolve) => {
|
||||
const { PUSH_PLUS_TOKEN, PUSH_PLUS_USER } = push_config;
|
||||
const {
|
||||
PUSH_PLUS_TOKEN,
|
||||
PUSH_PLUS_USER,
|
||||
PUSH_PLUS_TEMPLATE,
|
||||
PUSH_PLUS_CHANNEL,
|
||||
PUSH_PLUS_WEBHOOK,
|
||||
PUSH_PLUS_CALLBACKURL,
|
||||
PUSH_PLUS_TO,
|
||||
} = push_config;
|
||||
if (PUSH_PLUS_TOKEN) {
|
||||
desp = desp.replace(/[\n\r]/g, '<br>'); // 默认为html, 不支持plaintext
|
||||
const body = {
|
||||
@@ -767,6 +795,11 @@ function pushPlusNotify(text, desp) {
|
||||
title: `${text}`,
|
||||
content: `${desp}`,
|
||||
topic: `${PUSH_PLUS_USER}`,
|
||||
template: `${PUSH_PLUS_TEMPLATE}`,
|
||||
channel: `${PUSH_PLUS_CHANNEL}`,
|
||||
webhook: `${PUSH_PLUS_WEBHOOK}`,
|
||||
callbackUrl: `${PUSH_PLUS_CALLBACKURL}`,
|
||||
to: `${PUSH_PLUS_TO}`,
|
||||
};
|
||||
const options = {
|
||||
url: `https://www.pushplus.plus/send`,
|
||||
@@ -780,7 +813,7 @@ function pushPlusNotify(text, desp) {
|
||||
try {
|
||||
if (err) {
|
||||
console.log(
|
||||
`Push+ 发送${
|
||||
`pushplus 发送${
|
||||
PUSH_PLUS_USER ? '一对多' : '一对一'
|
||||
}通知消息失败😞\n`,
|
||||
err,
|
||||
@@ -788,13 +821,15 @@ function pushPlusNotify(text, desp) {
|
||||
} else {
|
||||
if (data.code === 200) {
|
||||
console.log(
|
||||
`Push+ 发送${
|
||||
`pushplus 发送${
|
||||
PUSH_PLUS_USER ? '一对多' : '一对一'
|
||||
}通知消息完成🎉\n`,
|
||||
}通知请求成功🎉,可根据流水号查询推送结果:${
|
||||
data.data
|
||||
}\n注意:请求成功并不代表推送成功,如未收到消息,请到pushplus官网使用流水号查询推送最终结果`,
|
||||
);
|
||||
} else {
|
||||
console.log(
|
||||
`Push+ 发送${
|
||||
`pushplus 发送${
|
||||
PUSH_PLUS_USER ? '一对多' : '一对一'
|
||||
}通知消息异常 ${data.msg}\n`,
|
||||
);
|
||||
@@ -1188,6 +1223,117 @@ function webhookNotify(text, desp) {
|
||||
});
|
||||
}
|
||||
|
||||
function ntfyNotify(text, desp) {
|
||||
function encodeRFC2047(text) {
|
||||
const encodedBase64 = Buffer.from(text).toString('base64');
|
||||
return `=?utf-8?B?${encodedBase64}?=`;
|
||||
}
|
||||
|
||||
return new Promise((resolve) => {
|
||||
const { NTFY_URL, NTFY_TOPIC, NTFY_PRIORITY } = push_config;
|
||||
if (NTFY_TOPIC) {
|
||||
const options = {
|
||||
url: `${NTFY_URL || 'https://ntfy.sh'}/${NTFY_TOPIC}`,
|
||||
body: `${desp}`,
|
||||
headers: {
|
||||
Title: `${encodeRFC2047(text)}`,
|
||||
Priority: NTFY_PRIORITY || '3',
|
||||
},
|
||||
timeout,
|
||||
};
|
||||
$.post(options, (err, resp, data) => {
|
||||
try {
|
||||
if (err) {
|
||||
console.log('Ntfy 通知调用API失败😞\n', err);
|
||||
} else {
|
||||
if (data.id) {
|
||||
console.log('Ntfy 发送通知消息成功🎉\n');
|
||||
} else {
|
||||
console.log(`Ntfy 发送通知消息异常 ${JSON.stringify(data)}`);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
$.logErr(e, resp);
|
||||
} finally {
|
||||
resolve(data);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function wxPusherNotify(text, desp) {
|
||||
return new Promise((resolve) => {
|
||||
const { WXPUSHER_APP_TOKEN, WXPUSHER_TOPIC_IDS, WXPUSHER_UIDS } =
|
||||
push_config;
|
||||
if (WXPUSHER_APP_TOKEN) {
|
||||
// 处理topic_ids,将分号分隔的字符串转为数组
|
||||
const topicIds = WXPUSHER_TOPIC_IDS
|
||||
? WXPUSHER_TOPIC_IDS.split(';')
|
||||
.map((id) => id.trim())
|
||||
.filter((id) => id)
|
||||
.map((id) => parseInt(id))
|
||||
: [];
|
||||
|
||||
// 处理uids,将分号分隔的字符串转为数组
|
||||
const uids = WXPUSHER_UIDS
|
||||
? WXPUSHER_UIDS.split(';')
|
||||
.map((uid) => uid.trim())
|
||||
.filter((uid) => uid)
|
||||
: [];
|
||||
|
||||
// topic_ids uids 至少有一个
|
||||
if (!topicIds.length && !uids.length) {
|
||||
console.log(
|
||||
'wxpusher 服务的 WXPUSHER_TOPIC_IDS 和 WXPUSHER_UIDS 至少设置一个!!',
|
||||
);
|
||||
return resolve();
|
||||
}
|
||||
|
||||
const body = {
|
||||
appToken: WXPUSHER_APP_TOKEN,
|
||||
content: `<h1>${text}</h1><br/><div style='white-space: pre-wrap;'>${desp}</div>`,
|
||||
summary: text,
|
||||
contentType: 2,
|
||||
topicIds: topicIds,
|
||||
uids: uids,
|
||||
verifyPayType: 0,
|
||||
};
|
||||
|
||||
const options = {
|
||||
url: 'https://wxpusher.zjiecode.com/api/send/message',
|
||||
body: JSON.stringify(body),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
timeout,
|
||||
};
|
||||
|
||||
$.post(options, (err, resp, data) => {
|
||||
try {
|
||||
if (err) {
|
||||
console.log('wxpusher发送通知消息失败!\n', err);
|
||||
} else {
|
||||
if (data.code === 1000) {
|
||||
console.log('wxpusher发送通知消息完成!');
|
||||
} else {
|
||||
console.log(`wxpusher发送通知消息异常:${data.msg}`);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
$.logErr(e, resp);
|
||||
} finally {
|
||||
resolve(data);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function parseString(input, valueFormatFn) {
|
||||
const regex = /(\w+):\s*((?:(?!\n\w+:).)*)/g;
|
||||
const matches = {};
|
||||
@@ -1316,6 +1462,8 @@ async function sendNotify(text, desp, params = {}) {
|
||||
chronocatNotify(text, desp), // Chronocat
|
||||
webhookNotify(text, desp), // 自定义通知
|
||||
qmsgNotify(text, desp), // 自定义通知
|
||||
ntfyNotify(text, desp), // Ntfy
|
||||
wxPusherNotify(text, desp), // wxpusher
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
+135
-36
@@ -72,8 +72,13 @@ push_config = {
|
||||
'CHAT_URL': '', # synology chat url
|
||||
'CHAT_TOKEN': '', # synology chat token
|
||||
|
||||
'PUSH_PLUS_TOKEN': '', # push+ 微信推送的用户令牌
|
||||
'PUSH_PLUS_USER': '', # push+ 微信推送的群组编码
|
||||
'PUSH_PLUS_TOKEN': '', # pushplus 推送的用户令牌
|
||||
'PUSH_PLUS_USER': '', # pushplus 推送的群组编码
|
||||
'PUSH_PLUS_TEMPLATE': 'html', # pushplus 发送模板,支持html,txt,json,markdown,cloudMonitor,jenkins,route,pay
|
||||
'PUSH_PLUS_CHANNEL': 'wechat', # pushplus 发送渠道,支持wechat,webhook,cp,mail,sms
|
||||
'PUSH_PLUS_WEBHOOK': '', # pushplus webhook编码,可在pushplus公众号上扩展配置出更多渠道
|
||||
'PUSH_PLUS_CALLBACKURL': '', # pushplus 发送结果回调地址,会把推送最终结果通知到这个地址上
|
||||
'PUSH_PLUS_TO': '', # pushplus 好友令牌,微信公众号渠道填写好友令牌,企业微信渠道填写企业微信用户id
|
||||
|
||||
'WE_PLUS_BOT_TOKEN': '', # 微加机器人的用户令牌
|
||||
'WE_PLUS_BOT_RECEIVER': '', # 微加机器人的消息接收者
|
||||
@@ -116,7 +121,15 @@ push_config = {
|
||||
'WEBHOOK_BODY': '', # 自定义通知 请求体
|
||||
'WEBHOOK_HEADERS': '', # 自定义通知 请求头
|
||||
'WEBHOOK_METHOD': '', # 自定义通知 请求方法
|
||||
'WEBHOOK_CONTENT_TYPE': '' # 自定义通知 content-type
|
||||
'WEBHOOK_CONTENT_TYPE': '', # 自定义通知 content-type
|
||||
|
||||
'NTFY_URL': '', # ntfy地址,如https://ntfy.sh
|
||||
'NTFY_TOPIC': '', # ntfy的消息应用topic
|
||||
'NTFY_PRIORITY':'3', # 推送消息优先级,默认为3
|
||||
|
||||
'WXPUSHER_APP_TOKEN': '', # wxpusher 的 appToken 官方文档: https://wxpusher.zjiecode.com/docs/ 管理后台: https://wxpusher.zjiecode.com/admin/
|
||||
'WXPUSHER_TOPIC_IDS': '', # wxpusher 的 主题ID,多个用英文分号;分隔 topic_ids 与 uids 至少配置一个才行
|
||||
'WXPUSHER_UIDS': '', # wxpusher 的 用户ID,多个用英文分号;分隔 topic_ids 与 uids 至少配置一个才行
|
||||
}
|
||||
# fmt: on
|
||||
|
||||
@@ -131,7 +144,6 @@ def bark(title: str, content: str) -> None:
|
||||
使用 bark 推送消息。
|
||||
"""
|
||||
if not push_config.get("BARK_PUSH"):
|
||||
print("bark 服务的 BARK_PUSH 未设置!!\n取消推送")
|
||||
return
|
||||
print("bark 服务启动")
|
||||
|
||||
@@ -183,7 +195,6 @@ def dingding_bot(title: str, content: str) -> None:
|
||||
使用 钉钉机器人 推送消息。
|
||||
"""
|
||||
if not push_config.get("DD_BOT_SECRET") or not push_config.get("DD_BOT_TOKEN"):
|
||||
print("钉钉机器人 服务的 DD_BOT_SECRET 或者 DD_BOT_TOKEN 未设置!!\n取消推送")
|
||||
return
|
||||
print("钉钉机器人 服务启动")
|
||||
|
||||
@@ -213,7 +224,6 @@ def feishu_bot(title: str, content: str) -> None:
|
||||
使用 飞书机器人 推送消息。
|
||||
"""
|
||||
if not push_config.get("FSKEY"):
|
||||
print("飞书 服务的 FSKEY 未设置!!\n取消推送")
|
||||
return
|
||||
print("飞书 服务启动")
|
||||
|
||||
@@ -232,7 +242,6 @@ def go_cqhttp(title: str, content: str) -> None:
|
||||
使用 go_cqhttp 推送消息。
|
||||
"""
|
||||
if not push_config.get("GOBOT_URL") or not push_config.get("GOBOT_QQ"):
|
||||
print("go-cqhttp 服务的 GOBOT_URL 或 GOBOT_QQ 未设置!!\n取消推送")
|
||||
return
|
||||
print("go-cqhttp 服务启动")
|
||||
|
||||
@@ -250,7 +259,6 @@ def gotify(title: str, content: str) -> None:
|
||||
使用 gotify 推送消息。
|
||||
"""
|
||||
if not push_config.get("GOTIFY_URL") or not push_config.get("GOTIFY_TOKEN"):
|
||||
print("gotify 服务的 GOTIFY_URL 或 GOTIFY_TOKEN 未设置!!\n取消推送")
|
||||
return
|
||||
print("gotify 服务启动")
|
||||
|
||||
@@ -273,7 +281,6 @@ def iGot(title: str, content: str) -> None:
|
||||
使用 iGot 推送消息。
|
||||
"""
|
||||
if not push_config.get("IGOT_PUSH_KEY"):
|
||||
print("iGot 服务的 IGOT_PUSH_KEY 未设置!!\n取消推送")
|
||||
return
|
||||
print("iGot 服务启动")
|
||||
|
||||
@@ -293,15 +300,18 @@ def serverJ(title: str, content: str) -> None:
|
||||
通过 serverJ 推送消息。
|
||||
"""
|
||||
if not push_config.get("PUSH_KEY"):
|
||||
print("serverJ 服务的 PUSH_KEY 未设置!!\n取消推送")
|
||||
return
|
||||
print("serverJ 服务启动")
|
||||
|
||||
data = {"text": title, "desp": content.replace("\n", "\n\n")}
|
||||
if push_config.get("PUSH_KEY").find("SCT") != -1:
|
||||
url = f'https://sctapi.ftqq.com/{push_config.get("PUSH_KEY")}.send'
|
||||
|
||||
match = re.match(r"sctp(\d+)t", push_config.get("PUSH_KEY"))
|
||||
if match:
|
||||
num = match.group(1)
|
||||
url = f'https://{num}.push.ft07.com/send/{push_config.get("PUSH_KEY")}.send'
|
||||
else:
|
||||
url = f'https://sc.ftqq.com/{push_config.get("PUSH_KEY")}.send'
|
||||
url = f'https://sctapi.ftqq.com/{push_config.get("PUSH_KEY")}.send'
|
||||
|
||||
response = requests.post(url, data=data).json()
|
||||
|
||||
if response.get("errno") == 0 or response.get("code") == 0:
|
||||
@@ -315,7 +325,6 @@ def pushdeer(title: str, content: str) -> None:
|
||||
通过PushDeer 推送消息
|
||||
"""
|
||||
if not push_config.get("DEER_KEY"):
|
||||
print("PushDeer 服务的 DEER_KEY 未设置!!\n取消推送")
|
||||
return
|
||||
print("PushDeer 服务启动")
|
||||
data = {
|
||||
@@ -341,7 +350,6 @@ def chat(title: str, content: str) -> None:
|
||||
通过Chat 推送消息
|
||||
"""
|
||||
if not push_config.get("CHAT_URL") or not push_config.get("CHAT_TOKEN"):
|
||||
print("chat 服务的 CHAT_URL或CHAT_TOKEN 未设置!!\n取消推送")
|
||||
return
|
||||
print("chat 服务启动")
|
||||
data = "payload=" + json.dumps({"text": title + "\n" + content})
|
||||
@@ -356,26 +364,36 @@ def chat(title: str, content: str) -> None:
|
||||
|
||||
def pushplus_bot(title: str, content: str) -> None:
|
||||
"""
|
||||
通过 push+ 推送消息。
|
||||
通过 pushplus 推送消息。
|
||||
"""
|
||||
if not push_config.get("PUSH_PLUS_TOKEN"):
|
||||
print("PUSHPLUS 服务的 PUSH_PLUS_TOKEN 未设置!!\n取消推送")
|
||||
return
|
||||
print("PUSHPLUS 服务启动")
|
||||
|
||||
url = "http://www.pushplus.plus/send"
|
||||
url = "https://www.pushplus.plus/send"
|
||||
data = {
|
||||
"token": push_config.get("PUSH_PLUS_TOKEN"),
|
||||
"title": title,
|
||||
"content": content,
|
||||
"topic": push_config.get("PUSH_PLUS_USER"),
|
||||
"template": push_config.get("PUSH_PLUS_TEMPLATE"),
|
||||
"channel": push_config.get("PUSH_PLUS_CHANNEL"),
|
||||
"webhook": push_config.get("PUSH_PLUS_WEBHOOK"),
|
||||
"callbackUrl": push_config.get("PUSH_PLUS_CALLBACKURL"),
|
||||
"to": push_config.get("PUSH_PLUS_TO"),
|
||||
}
|
||||
body = json.dumps(data).encode(encoding="utf-8")
|
||||
headers = {"Content-Type": "application/json"}
|
||||
response = requests.post(url=url, data=body, headers=headers).json()
|
||||
|
||||
if response["code"] == 200:
|
||||
print("PUSHPLUS 推送成功!")
|
||||
code = response["code"]
|
||||
if code == 200:
|
||||
print("PUSHPLUS 推送请求成功,可根据流水号查询推送结果:" + response["data"])
|
||||
print(
|
||||
"注意:请求成功并不代表推送成功,如未收到消息,请到pushplus官网使用流水号查询推送最终结果"
|
||||
)
|
||||
elif code == 900 or code == 903 or code == 905 or code == 999:
|
||||
print(response["msg"])
|
||||
|
||||
else:
|
||||
url_old = "http://pushplus.hxtrip.com/send"
|
||||
@@ -394,7 +412,6 @@ def weplus_bot(title: str, content: str) -> None:
|
||||
通过 微加机器人 推送消息。
|
||||
"""
|
||||
if not push_config.get("WE_PLUS_BOT_TOKEN"):
|
||||
print("微加机器人 服务的 WE_PLUS_BOT_TOKEN 未设置!!\n取消推送")
|
||||
return
|
||||
print("微加机器人 服务启动")
|
||||
|
||||
@@ -426,7 +443,6 @@ def qmsg_bot(title: str, content: str) -> None:
|
||||
使用 qmsg 推送消息。
|
||||
"""
|
||||
if not push_config.get("QMSG_KEY") or not push_config.get("QMSG_TYPE"):
|
||||
print("qmsg 的 QMSG_KEY 或者 QMSG_TYPE 未设置!!\n取消推送")
|
||||
return
|
||||
print("qmsg 服务启动")
|
||||
|
||||
@@ -445,11 +461,10 @@ def wecom_app(title: str, content: str) -> None:
|
||||
通过 企业微信 APP 推送消息。
|
||||
"""
|
||||
if not push_config.get("QYWX_AM"):
|
||||
print("QYWX_AM 未设置!!\n取消推送")
|
||||
return
|
||||
QYWX_AM_AY = re.split(",", push_config.get("QYWX_AM"))
|
||||
if 4 < len(QYWX_AM_AY) > 5:
|
||||
print("QYWX_AM 设置错误!!\n取消推送")
|
||||
print("QYWX_AM 设置错误!!")
|
||||
return
|
||||
print("企业微信 APP 服务启动")
|
||||
|
||||
@@ -542,7 +557,6 @@ def wecom_bot(title: str, content: str) -> None:
|
||||
通过 企业微信机器人 推送消息。
|
||||
"""
|
||||
if not push_config.get("QYWX_KEY"):
|
||||
print("企业微信机器人 服务的 QYWX_KEY 未设置!!\n取消推送")
|
||||
return
|
||||
print("企业微信机器人服务启动")
|
||||
|
||||
@@ -568,7 +582,6 @@ def telegram_bot(title: str, content: str) -> None:
|
||||
使用 telegram 机器人 推送消息。
|
||||
"""
|
||||
if not push_config.get("TG_BOT_TOKEN") or not push_config.get("TG_USER_ID"):
|
||||
print("tg 服务的 bot_token 或者 user_id 未设置!!\n取消推送")
|
||||
return
|
||||
print("tg 服务启动")
|
||||
|
||||
@@ -617,9 +630,6 @@ def aibotk(title: str, content: str) -> None:
|
||||
or not push_config.get("AIBOTK_TYPE")
|
||||
or not push_config.get("AIBOTK_NAME")
|
||||
):
|
||||
print(
|
||||
"智能微秘书 的 AIBOTK_KEY 或者 AIBOTK_TYPE 或者 AIBOTK_NAME 未设置!!\n取消推送"
|
||||
)
|
||||
return
|
||||
print("智能微秘书 服务启动")
|
||||
|
||||
@@ -658,9 +668,6 @@ def smtp(title: str, content: str) -> None:
|
||||
or not push_config.get("SMTP_PASSWORD")
|
||||
or not push_config.get("SMTP_NAME")
|
||||
):
|
||||
print(
|
||||
"SMTP 邮件 的 SMTP_SERVER 或者 SMTP_SSL 或者 SMTP_EMAIL 或者 SMTP_PASSWORD 或者 SMTP_NAME 未设置!!\n取消推送"
|
||||
)
|
||||
return
|
||||
print("SMTP 邮件 服务启动")
|
||||
|
||||
@@ -704,7 +711,6 @@ def pushme(title: str, content: str) -> None:
|
||||
使用 PushMe 推送消息。
|
||||
"""
|
||||
if not push_config.get("PUSHME_KEY"):
|
||||
print("PushMe 服务的 PUSHME_KEY 未设置!!\n取消推送")
|
||||
return
|
||||
print("PushMe 服务启动")
|
||||
|
||||
@@ -737,7 +743,6 @@ def chronocat(title: str, content: str) -> None:
|
||||
or not push_config.get("CHRONOCAT_QQ")
|
||||
or not push_config.get("CHRONOCAT_TOKEN")
|
||||
):
|
||||
print("CHRONOCAT 服务的 CHRONOCAT_URL 或 CHRONOCAT_QQ 未设置!!\n取消推送")
|
||||
return
|
||||
|
||||
print("CHRONOCAT 服务启动")
|
||||
@@ -777,6 +782,96 @@ def chronocat(title: str, content: str) -> None:
|
||||
print(f"QQ群消息:{ids}推送失败!")
|
||||
|
||||
|
||||
def ntfy(title: str, content: str) -> None:
|
||||
"""
|
||||
通过 Ntfy 推送消息
|
||||
"""
|
||||
|
||||
def encode_rfc2047(text: str) -> str:
|
||||
"""将文本编码为符合 RFC 2047 标准的格式"""
|
||||
encoded_bytes = base64.b64encode(text.encode("utf-8"))
|
||||
encoded_str = encoded_bytes.decode("utf-8")
|
||||
return f"=?utf-8?B?{encoded_str}?="
|
||||
|
||||
if not push_config.get("NTFY_TOPIC"):
|
||||
return
|
||||
print("ntfy 服务启动")
|
||||
priority = "3"
|
||||
if not push_config.get("NTFY_PRIORITY"):
|
||||
print("ntfy 服务的NTFY_PRIORITY 未设置!!默认设置为3")
|
||||
else:
|
||||
priority = push_config.get("NTFY_PRIORITY")
|
||||
|
||||
# 使用 RFC 2047 编码 title
|
||||
encoded_title = encode_rfc2047(title)
|
||||
|
||||
data = content.encode(encoding="utf-8")
|
||||
headers = {"Title": encoded_title, "Priority": priority} # 使用编码后的 title
|
||||
|
||||
url = push_config.get("NTFY_URL") + "/" + push_config.get("NTFY_TOPIC")
|
||||
response = requests.post(url, data=data, headers=headers)
|
||||
if response.status_code == 200: # 使用 response.status_code 进行检查
|
||||
print("Ntfy 推送成功!")
|
||||
else:
|
||||
print("Ntfy 推送失败!错误信息:", response.text)
|
||||
|
||||
|
||||
def wxpusher_bot(title: str, content: str) -> None:
|
||||
"""
|
||||
通过 wxpusher 推送消息。
|
||||
支持的环境变量:
|
||||
- WXPUSHER_APP_TOKEN: appToken
|
||||
- WXPUSHER_TOPIC_IDS: 主题ID, 多个用英文分号;分隔
|
||||
- WXPUSHER_UIDS: 用户ID, 多个用英文分号;分隔
|
||||
"""
|
||||
if not push_config.get("WXPUSHER_APP_TOKEN"):
|
||||
return
|
||||
|
||||
url = "https://wxpusher.zjiecode.com/api/send/message"
|
||||
|
||||
# 处理topic_ids和uids,将分号分隔的字符串转为数组
|
||||
topic_ids = []
|
||||
if push_config.get("WXPUSHER_TOPIC_IDS"):
|
||||
topic_ids = [
|
||||
int(id.strip())
|
||||
for id in push_config.get("WXPUSHER_TOPIC_IDS").split(";")
|
||||
if id.strip()
|
||||
]
|
||||
|
||||
uids = []
|
||||
if push_config.get("WXPUSHER_UIDS"):
|
||||
uids = [
|
||||
uid.strip()
|
||||
for uid in push_config.get("WXPUSHER_UIDS").split(";")
|
||||
if uid.strip()
|
||||
]
|
||||
|
||||
# topic_ids uids 至少有一个
|
||||
if not topic_ids and not uids:
|
||||
print("wxpusher 服务的 WXPUSHER_TOPIC_IDS 和 WXPUSHER_UIDS 至少设置一个!!")
|
||||
return
|
||||
|
||||
print("wxpusher 服务启动")
|
||||
|
||||
data = {
|
||||
"appToken": push_config.get("WXPUSHER_APP_TOKEN"),
|
||||
"content": f"<h1>{title}</h1><br/><div style='white-space: pre-wrap;'>{content}</div>",
|
||||
"summary": title,
|
||||
"contentType": 2,
|
||||
"topicIds": topic_ids,
|
||||
"uids": uids,
|
||||
"verifyPayType": 0,
|
||||
}
|
||||
|
||||
headers = {"Content-Type": "application/json"}
|
||||
response = requests.post(url=url, json=data, headers=headers).json()
|
||||
|
||||
if response.get("code") == 1000:
|
||||
print("wxpusher 推送成功!")
|
||||
else:
|
||||
print(f"wxpusher 推送失败!错误信息:{response.get('msg')}")
|
||||
|
||||
|
||||
def parse_headers(headers):
|
||||
if not headers:
|
||||
return {}
|
||||
@@ -833,7 +928,6 @@ def custom_notify(title: str, content: str) -> None:
|
||||
通过 自定义通知 推送消息。
|
||||
"""
|
||||
if not push_config.get("WEBHOOK_URL") or not push_config.get("WEBHOOK_METHOD"):
|
||||
print("自定义通知的 WEBHOOK_URL 或 WEBHOOK_METHOD 未设置!!\n取消推送")
|
||||
return
|
||||
|
||||
print("自定义通知服务启动")
|
||||
@@ -937,7 +1031,12 @@ def add_notify_function():
|
||||
notify_function.append(chronocat)
|
||||
if push_config.get("WEBHOOK_URL") and push_config.get("WEBHOOK_METHOD"):
|
||||
notify_function.append(custom_notify)
|
||||
|
||||
if push_config.get("NTFY_TOPIC"):
|
||||
notify_function.append(ntfy)
|
||||
if push_config.get("WXPUSHER_APP_TOKEN") and (
|
||||
push_config.get("WXPUSHER_TOPIC_IDS") or push_config.get("WXPUSHER_UIDS")
|
||||
):
|
||||
notify_function.append(wxpusher_bot)
|
||||
if not notify_function:
|
||||
print(f"无推送渠道,请检查通知变量是否正确")
|
||||
return notify_function
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -231,4 +231,30 @@ find_cron_api() {
|
||||
fi
|
||||
}
|
||||
|
||||
update_auth_config() {
|
||||
local body="$1"
|
||||
local tip="$2"
|
||||
local currentTimeStamp=$(date +%s)
|
||||
local api=$(
|
||||
curl -s --noproxy "*" "http://0.0.0.0:5600/open/system/auth/reset?t=$currentTimeStamp" \
|
||||
-X 'PUT' \
|
||||
-H "Accept: application/json" \
|
||||
-H "Authorization: Bearer ${__ql_token__}" \
|
||||
-H "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36" \
|
||||
-H "Content-Type: application/json;charset=UTF-8" \
|
||||
-H "Origin: http://0.0.0.0:5700" \
|
||||
-H "Referer: http://0.0.0.0:5700/crontab" \
|
||||
-H "Accept-Language: en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7" \
|
||||
--data-raw "{$body}" \
|
||||
--compressed
|
||||
)
|
||||
code=$(echo "$api" | jq -r .code)
|
||||
message=$(echo "$api" | jq -r .message)
|
||||
if [[ $code == 200 ]]; then
|
||||
echo -e "${tip}成功🎉"
|
||||
else
|
||||
echo -e "${tip}失败(${message})"
|
||||
fi
|
||||
}
|
||||
|
||||
get_token
|
||||
|
||||
+2
-1
@@ -125,7 +125,8 @@ run_concurrent() {
|
||||
fi
|
||||
|
||||
handle_env_split
|
||||
single_log_time=$(date "+%Y-%m-%d-%H-%M-%S.%3N")
|
||||
time=$(date "+$mtime_format")
|
||||
single_log_time=$(format_log_time "$mtime_format" "$time")
|
||||
|
||||
cd $dir_scripts
|
||||
local relative_path="${file_param%/*}"
|
||||
|
||||
@@ -29,7 +29,7 @@ function run() {
|
||||
file_task_before_js,
|
||||
dir_scripts,
|
||||
task_before,
|
||||
PREV_NODE_OPTIONS
|
||||
PREV_NODE_OPTIONS,
|
||||
} = process.env;
|
||||
|
||||
try {
|
||||
@@ -56,16 +56,18 @@ function run() {
|
||||
for (const key in newEnvObject) {
|
||||
process.env[key] = newEnvObject[key];
|
||||
}
|
||||
console.log(output);
|
||||
if (output) {
|
||||
console.log(output);
|
||||
}
|
||||
if (task_before) {
|
||||
console.log('执行前置命令结束\n');
|
||||
}
|
||||
} catch (error) {
|
||||
if (!error.message.includes('spawnSync /bin/sh E2BIG')) {
|
||||
console.log(`❌ run task before error: `, error);
|
||||
console.log(`\ue926 run task before error: `, error);
|
||||
} else {
|
||||
console.log(
|
||||
`❌ The environment variable is too large. It is recommended to use task_before.js instead of task_before.sh\n`,
|
||||
`\ue926 The environment variable is too large. It is recommended to use task_before.js instead of task_before.sh\n`,
|
||||
);
|
||||
}
|
||||
if (task_before) {
|
||||
@@ -89,6 +91,10 @@ try {
|
||||
return;
|
||||
}
|
||||
|
||||
process.on('SIGTERM', (code) => {
|
||||
process.exit(15);
|
||||
});
|
||||
|
||||
run();
|
||||
|
||||
const { sendNotify } = require('./notify.js');
|
||||
|
||||
@@ -5,6 +5,7 @@ import json
|
||||
import builtins
|
||||
import sys
|
||||
import env
|
||||
import signal
|
||||
|
||||
|
||||
def try_parse_int(value):
|
||||
@@ -63,7 +64,8 @@ def run():
|
||||
for key, value in env_json.items():
|
||||
os.environ[key] = value
|
||||
|
||||
print(output)
|
||||
if len(output) > 0:
|
||||
print(output)
|
||||
if task_before:
|
||||
print("执行前置命令结束")
|
||||
|
||||
@@ -72,10 +74,10 @@ def run():
|
||||
except OSError as error:
|
||||
error_message = str(error)
|
||||
if "Argument list too long" not in error_message:
|
||||
print(f"❌ run task before error: {error}")
|
||||
print(f"\ue926 run task before error: {error}")
|
||||
else:
|
||||
print(
|
||||
"❌ The environment variable is too large. It is recommended to use task_before.py instead of task_before.sh\n"
|
||||
"\ue926 The environment variable is too large. It is recommended to use task_before.py instead of task_before.sh\n"
|
||||
)
|
||||
if task_before:
|
||||
print("执行前置命令结束")
|
||||
@@ -95,7 +97,13 @@ def run():
|
||||
os.environ[env_param] = env_str
|
||||
|
||||
|
||||
def handle_sigterm(signum, frame):
|
||||
sys.exit(15)
|
||||
|
||||
|
||||
try:
|
||||
signal.signal(signal.SIGTERM, handle_sigterm)
|
||||
|
||||
run()
|
||||
|
||||
from notify import send
|
||||
|
||||
+6
-10
@@ -193,12 +193,6 @@ fix_config() {
|
||||
echo
|
||||
fi
|
||||
|
||||
if [[ ! -s $file_auth_user ]]; then
|
||||
echo -e "复制一份 $file_auth_sample 为 $file_auth_user\n"
|
||||
cp -fv $file_auth_sample $file_auth_user
|
||||
echo
|
||||
fi
|
||||
|
||||
if [[ ! -s $file_notify_py ]]; then
|
||||
echo -e "复制一份 $file_notify_py_sample 为 $file_notify_py\n"
|
||||
cp -fv $file_notify_py_sample $file_notify_py
|
||||
@@ -340,7 +334,7 @@ format_log_time() {
|
||||
local time="$2"
|
||||
|
||||
if [[ $is_macos -eq 1 ]]; then
|
||||
echo $(date -j -f "$format" "$time" "+%Y-%m-%d-%H-%M-%S-%3N")
|
||||
echo $(python3 -c 'from datetime import datetime; print(datetime.now().strftime("%Y-%m-%d-%H-%M-%S-%f")[:-3])')
|
||||
else
|
||||
echo $(date -d "$time" "+%Y-%m-%d-%H-%M-%S-%3N")
|
||||
fi
|
||||
@@ -453,7 +447,7 @@ run_task_before() {
|
||||
|
||||
if [[ ${task_before:=} ]]; then
|
||||
echo -e "执行前置命令\n"
|
||||
eval "${task_before%;}" "$@"
|
||||
eval "${task_before%;}"
|
||||
echo -e "\n执行前置命令结束\n"
|
||||
fi
|
||||
}
|
||||
@@ -463,7 +457,7 @@ run_task_after() {
|
||||
|
||||
if [[ ${task_after:=} ]]; then
|
||||
echo -e "\n执行后置命令\n"
|
||||
eval "${task_after%;}" "$@"
|
||||
eval "${task_after%;}"
|
||||
echo -e "\n执行后置命令结束"
|
||||
fi
|
||||
}
|
||||
@@ -473,10 +467,12 @@ handle_task_end() {
|
||||
local end_time=$(format_time "$time_format" "$etime")
|
||||
local end_timestamp=$(format_timestamp "$time_format" "$etime")
|
||||
local diff_time=$(($end_timestamp - $begin_timestamp))
|
||||
local suffix=""
|
||||
[[ "$MANUAL" == "true" ]] && suffix="(手动停止)"
|
||||
|
||||
[[ "$diff_time" == 0 ]] && diff_time=1
|
||||
|
||||
echo -e "\n## 执行结束... $end_time 耗时 $diff_time 秒 "
|
||||
echo -e "\n## 执行结束$suffix... $end_time 耗时 $diff_time 秒 "
|
||||
[[ $ID ]] && update_cron "\"$ID\"" "1" "" "$log_path" "$begin_timestamp" "$diff_time"
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ dir_shell=$QL_DIR/shell
|
||||
|
||||
trap "single_hanle" 2 3 20 15 14 19 1
|
||||
single_hanle() {
|
||||
eval handle_task_end "$@" "$cmd"
|
||||
eval MANUAL=true handle_task_end "$@" "$cmd"
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
||||
+2
-6
@@ -537,14 +537,10 @@ main() {
|
||||
eval . $dir_shell/check.sh $cmd
|
||||
;;
|
||||
resetlet)
|
||||
auth_value=$(cat $file_auth_user | jq '.retries =0' -c)
|
||||
echo "$auth_value" >$file_auth_user
|
||||
eval echo -e "重置登录错误次数成功" $cmd
|
||||
eval update_auth_config "\\\"retries\\\":0" "重置登录错误次数" $cmd
|
||||
;;
|
||||
resettfa)
|
||||
auth_value=$(cat $file_auth_user | jq '.twoFactorActivated =false' | jq '.twoFactorActived =false' -c)
|
||||
echo "$auth_value" >$file_auth_user
|
||||
eval echo -e "禁用两步验证成功" $cmd
|
||||
eval update_auth_config "\\\"twoFactorActivated\\\":false" "禁用两步验证" $cmd
|
||||
;;
|
||||
*)
|
||||
eval echo -e "命令输入错误...\\\n" $cmd
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -8,6 +8,13 @@
|
||||
url('../assets/fonts/SourceCodePro-Regular.ttf') format('truetype');
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: Log;
|
||||
src: url('../assets/fonts/log.woff2') format('woff2'),
|
||||
url('../assets/fonts/log.woff') format('woff'),
|
||||
url('../assets/fonts/log.ttf') format('truetype');
|
||||
}
|
||||
|
||||
body {
|
||||
// 禁止手机页面下拉刷新
|
||||
overflow: hidden;
|
||||
@@ -52,6 +59,11 @@ body {
|
||||
width: 100%;
|
||||
padding: 24px;
|
||||
overflow-y: auto;
|
||||
code,
|
||||
span {
|
||||
font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo,
|
||||
Courier, monospace, Log;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,6 +75,10 @@ body {
|
||||
}
|
||||
}
|
||||
|
||||
.ͼ1 .cm-scroller {
|
||||
font-family: monospace, Log;
|
||||
}
|
||||
|
||||
.monaco-editor:not(.rename-box) {
|
||||
height: calc(100vh - 128px) !important;
|
||||
height: calc(100vh - var(--vh-offset, 0px) - 128px) !important;
|
||||
|
||||
@@ -379,6 +379,11 @@
|
||||
"iGot的信息推送key,例如:https://push.hellyw.com/XXXXXXXX": "iGot information push key, e.g., https://push.hellyw.com/XXXXXXXX",
|
||||
"微信扫码登录后一对一推送或一对多推送下面的token(您的Token),不提供PUSH_PLUS_USER则默认为一对一推送,参考 https://www.pushplus.plus/": "After WeChat scan login, one-to-one or one-to-many push using the provided token (your Token). If PUSH_PLUS_USER is not provided, it defaults to one-to-one push. See reference at https://www.pushplus.plus/",
|
||||
"一对多推送的“群组编码”(一对多推送下面->您的群组(如无则创建)->群组编码,如果您是创建群组人。也需点击“查看二维码”扫描绑定,否则不能接受群组消息推送)": "The 'group code' for one-to-many push (one-to-many push -> your group (if none, create one) -> group code). If you are the creator of the group, you need to click 'View QR code' to scan and bind, otherwise, you won't receive group messages.",
|
||||
"发送模板": "send template, can use type: 'html,txt,json,markdown,cloudMonitor,jenkins,route,pay'",
|
||||
"发送渠道": "send channel, can use type: 'wechat,webhook,cp,mail,sms'",
|
||||
"webhook编码": "webhook code",
|
||||
"发送结果回调地址": "send result callback url",
|
||||
"好友令牌": "friend token",
|
||||
"用户令牌,扫描登录后 我的—>设置->令牌 中获取,参考 https://www.weplusbot.com/": "Token, which can be obtained after scanning and logging in, is available under 'My Account' -> 'Settings' -> 'Tokens'. Please refer to the instructions for detailed steps: https://www.weplusbot.com/",
|
||||
"消息接收人": "message recipient",
|
||||
"调用版本;专业版填写pro,个人版填写personal,为空默认使用专业版": "Version, you can specify 'pro' for the Professional version and 'personal' for the Personal version. If left blank, it will default to the Professional version.",
|
||||
@@ -388,6 +393,11 @@
|
||||
"SMTP 登录密码,也可能为特殊口令,视具体邮件服务商说明而定": "The SMTP login password may also be a special passphrase, depending on the specific email service provider's instructions",
|
||||
"PushMe的Key,https://push.i-i.me/": "PushMe key, https://push.i-i.me/",
|
||||
"自建的PushMeServer消息接口地址,例如:http://127.0.0.1:3010,不填则使用官方消息接口": "The self built PushMeServer message interface address, for example: http://127.0.0.1:3010 If left blank, use the official message interface",
|
||||
"ntfy的url地址,例如 https://ntfy.sh'": "The URL address of ntfy, for example, https://ntfy.sh.",
|
||||
"ntfy的消息应用topic": "The topic for ntfy's messaging application.",
|
||||
"wxPusherBot的appToken": "wxPusherBot's appToken, obtain according to docs https://wxpusher.zjiecode.com/docs/",
|
||||
"wxPusherBot的topicIds": "wxPusherBot's topicIds, at least one of topicIds or uids must be configured",
|
||||
"wxPusherBot的uids": "wxPusherBot's uids, at least one of topicIds or uids must be configured",
|
||||
"请求方法": "Request Method",
|
||||
"请求头Content-Type": "Request Header Content-Type",
|
||||
"请求链接以http或者https开头。url或者body中必须包含$title,$content可选,对应api内容的位置": "Request URL should start with http or https. URL or body must contain $title, $content is optional and corresponds to the API content position.",
|
||||
|
||||
+11
-1
@@ -377,8 +377,13 @@
|
||||
"好友": "好友",
|
||||
"要发送的用户昵称或群名,如果目标是群,需要填群名,如果目标是好友,需要填好友昵称": "要发送的用户昵称或群名,如果目标是群,需要填群名,如果目标是好友,需要填好友昵称",
|
||||
"iGot的信息推送key,例如:https://push.hellyw.com/XXXXXXXX": "iGot的信息推送key,例如:https://push.hellyw.com/XXXXXXXX",
|
||||
"微信扫码登录后一对一推送或一对多推送下面的token(您的Token),不提供PUSH_PLUS_USER则默认为一对一推送,参考 https://www.pushplus.plus/": "微信扫码登录后一对一推送或一对多推送下面的token(您的Token),不提供PUSH_PLUS_USER则默认为一对一推送,参考 https://www.pushplus.plus/",
|
||||
"微信扫码登录后一对一推送或一对多推送下面的token(您的Token),不提供PUSH_PLUS_USER则默认为一对一推送,参考 https://www.pushplus.plus/": "微信扫码登录后一对一推送或一对多推送下面的token(你的Token),不提供PUSH_PLUS_USER则默认为一对一推送,参考 https://www.pushplus.plus/",
|
||||
"一对多推送的“群组编码”(一对多推送下面->您的群组(如无则创建)->群组编码,如果您是创建群组人。也需点击“查看二维码”扫描绑定,否则不能接受群组消息推送)": "一对多推送的“群组编码”(一对多推送下面->您的群组(如无则创建)->群组编码,如果您是创建群组人。也需点击“查看二维码”扫描绑定,否则不能接受群组消息推送)",
|
||||
"发送模板": "发送模板,支持html,txt,json,markdown,cloudMonitor,jenkins,route,pay",
|
||||
"发送渠道": "发送渠道,支持wechat,webhook,cp,mail,sms",
|
||||
"webhook编码": "webhook编码,可在pushplus公众号上扩展配置出更多渠道",
|
||||
"发送结果回调地址": "发送结果回调地址,会把推送最终结果通知到这个地址上",
|
||||
"好友令牌": "好友令牌,微信公众号渠道填写好友令牌,企业微信渠道填写企业微信用户id",
|
||||
"用户令牌,扫描登录后 我的—>设置->令牌 中获取,参考 https://www.weplusbot.com/": "用户令牌,扫描登录后 我的—>设置->令牌 中获取,参考 https://www.weplusbot.com/",
|
||||
"消息接收人": "消息接收人",
|
||||
"调用版本;专业版填写pro,个人版填写personal,为空默认使用专业版": "调用版本;专业版填写pro,个人版填写personal,为空默认使用专业版",
|
||||
@@ -388,6 +393,11 @@
|
||||
"SMTP 登录密码,也可能为特殊口令,视具体邮件服务商说明而定": "SMTP 登录密码,也可能为特殊口令,视具体邮件服务商说明而定",
|
||||
"PushMe的Key,https://push.i-i.me/": "PushMe的Key,https://push.i-i.me/",
|
||||
"自建的PushMeServer消息接口地址,例如:http://127.0.0.1:3010,不填则使用官方消息接口": "自建的PushMeServer消息接口地址,例如:http://127.0.0.1:3010,不填则使用官方消息接口",
|
||||
"ntfy的url地址,例如 https://ntfy.sh": "ntfy的url地址,例如 https://ntfy.sh",
|
||||
"ntfy的消息应用topic": "ntfy的消息应用topic",
|
||||
"wxPusherBot的appToken": "wxPusherBot的appToken, 按照文档获取 https://wxpusher.zjiecode.com/docs/",
|
||||
"wxPusherBot的topicIds": "wxPusherBot的topicIds, topicIds 和 uids 至少配置一个才行",
|
||||
"wxPusherBot的uids": "wxPusherBot的uids, topicIds 和 uids 至少配置一个才行",
|
||||
"请求方法": "请求方法",
|
||||
"请求头Content-Type": "请求头Content-Type",
|
||||
"请求链接以http或者https开头。url或者body中必须包含$title,$content可选,对应api内容的位置": "请求链接以http或者https开头。url或者body中必须包含$title,$content可选,对应api内容的位置",
|
||||
|
||||
@@ -36,6 +36,7 @@ import {
|
||||
PlusOutlined,
|
||||
UnorderedListOutlined,
|
||||
CheckOutlined,
|
||||
CopyOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import config from '@/utils/config';
|
||||
import { PageContainer } from '@ant-design/pro-layout';
|
||||
@@ -57,10 +58,11 @@ import { useVT } from 'virtualizedtableforantd4';
|
||||
import { ICrontab, OperationName, OperationPath, CrontabStatus } from './type';
|
||||
import Name from '@/components/name';
|
||||
import dayjs from 'dayjs';
|
||||
import { noop } from 'lodash';
|
||||
import { noop, omit } from 'lodash';
|
||||
|
||||
const { Text, Paragraph, Link } = Typography;
|
||||
const { Search } = Input;
|
||||
const SHOW_TAB_COUNT = 10;
|
||||
|
||||
const Crontab = () => {
|
||||
const { headerStyle, isPhone, theme } = useOutletContext<SharedContext>();
|
||||
@@ -620,6 +622,7 @@ const Crontab = () => {
|
||||
icon:
|
||||
record.isDisabled === 1 ? <CheckCircleOutlined /> : <StopOutlined />,
|
||||
},
|
||||
{ label: intl.get('复制'), key: 'copy', icon: <CopyOutlined /> },
|
||||
{ label: intl.get('删除'), key: 'delete', icon: <DeleteOutlined /> },
|
||||
{
|
||||
label: record.isPinned === 1 ? intl.get('取消置顶') : intl.get('置顶'),
|
||||
@@ -655,6 +658,9 @@ const Crontab = () => {
|
||||
case 'edit':
|
||||
editCron(record, index);
|
||||
break;
|
||||
case 'copy':
|
||||
editCron(omit(record, 'id'), index);
|
||||
break;
|
||||
case 'enableOrDisable':
|
||||
enabledOrDisabledCron(record, index);
|
||||
break;
|
||||
@@ -800,7 +806,7 @@ const Crontab = () => {
|
||||
|
||||
useEffect(() => {
|
||||
if (viewConf && enabledCronViews && enabledCronViews.length > 0) {
|
||||
const view = enabledCronViews.slice(4).find((x) => x.id === viewConf.id);
|
||||
const view = enabledCronViews.slice(SHOW_TAB_COUNT).find((x) => x.id === viewConf.id);
|
||||
setMoreMenuActive(!!view);
|
||||
}
|
||||
}, [viewConf, enabledCronViews]);
|
||||
@@ -830,7 +836,7 @@ const Crontab = () => {
|
||||
viewAction(key);
|
||||
},
|
||||
items: [
|
||||
...[...enabledCronViews].slice(4).map((x) => ({
|
||||
...[...enabledCronViews].slice(SHOW_TAB_COUNT).map((x) => ({
|
||||
label: (
|
||||
<Space style={{ display: 'flex', justifyContent: 'space-between' }}>
|
||||
<span>{x.name}</span>
|
||||
@@ -950,7 +956,7 @@ const Crontab = () => {
|
||||
}
|
||||
onTabClick={tabClick}
|
||||
items={[
|
||||
...[...enabledCronViews].slice(0, 4).map((x) => ({
|
||||
...[...enabledCronViews].slice(0, SHOW_TAB_COUNT).map((x) => ({
|
||||
key: x.id,
|
||||
label: x.name,
|
||||
})),
|
||||
|
||||
@@ -21,9 +21,9 @@ const CronModal = ({
|
||||
|
||||
const handleOk = async (values: any) => {
|
||||
setLoading(true);
|
||||
const method = cron ? 'put' : 'post';
|
||||
const method = cron?.id ? 'put' : 'post';
|
||||
const payload = { ...values };
|
||||
if (cron) {
|
||||
if (cron?.id) {
|
||||
payload.id = cron.id;
|
||||
}
|
||||
try {
|
||||
@@ -34,7 +34,7 @@ const CronModal = ({
|
||||
|
||||
if (code === 200) {
|
||||
message.success(
|
||||
cron ? intl.get('更新任务成功') : intl.get('创建任务成功'),
|
||||
cron?.id ? intl.get('更新任务成功') : intl.get('创建任务成功'),
|
||||
);
|
||||
handleCancel(data);
|
||||
}
|
||||
@@ -50,7 +50,7 @@ const CronModal = ({
|
||||
|
||||
return (
|
||||
<Modal
|
||||
title={cron ? intl.get('编辑任务') : intl.get('创建任务')}
|
||||
title={cron?.id ? intl.get('编辑任务') : intl.get('创建任务')}
|
||||
open={visible}
|
||||
forceRender
|
||||
centered
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import intl from 'react-intl-universal';
|
||||
import React, { useRef, useState } from 'react';
|
||||
import CodeMirror from '@uiw/react-codemirror';
|
||||
import { Button, DatePicker, Empty, message, Spin } from 'antd';
|
||||
@@ -9,6 +10,13 @@ import { request } from '@/utils/http';
|
||||
import config from '@/utils/config';
|
||||
import { useRequest } from 'ahooks';
|
||||
import moment from 'moment';
|
||||
import {
|
||||
systemLogDebugHighlightPlugin,
|
||||
systemLogErrorHighlightPlugin,
|
||||
systemLogInfoHighlightPlugin,
|
||||
systemLogTheme,
|
||||
systemLogWarnHighlightPlugin,
|
||||
} from '@/utils/codemirror/systemLog';
|
||||
|
||||
const { RangePicker } = DatePicker;
|
||||
|
||||
@@ -83,7 +91,7 @@ const SystemLog = ({ height, theme }: any) => {
|
||||
deleteLog();
|
||||
}}
|
||||
>
|
||||
清空日志
|
||||
{intl.get('清空日志')}
|
||||
</Button>
|
||||
</div>
|
||||
{systemLogData ? (
|
||||
@@ -94,6 +102,13 @@ const SystemLog = ({ height, theme }: any) => {
|
||||
onCreateEditor={(view) => {
|
||||
editorRef.current = view;
|
||||
}}
|
||||
extensions={[
|
||||
systemLogDebugHighlightPlugin,
|
||||
systemLogErrorHighlightPlugin,
|
||||
systemLogInfoHighlightPlugin,
|
||||
systemLogWarnHighlightPlugin,
|
||||
systemLogTheme,
|
||||
]}
|
||||
readOnly={true}
|
||||
theme={theme.includes('dark') ? 'dark' : 'light'}
|
||||
/>
|
||||
|
||||
@@ -0,0 +1,174 @@
|
||||
import {
|
||||
Decoration,
|
||||
EditorView,
|
||||
ViewPlugin,
|
||||
ViewUpdate,
|
||||
} from '@codemirror/view';
|
||||
import { RangeSet, RangeSetBuilder } from '@codemirror/state';
|
||||
|
||||
const infoWord = /\[\ue6f5info\]/g;
|
||||
const debugWord = /\[\ue67fdebug\]/g;
|
||||
const warnWord = /\[\ue880warn\]/g;
|
||||
const errorWord = /\[\ue602error\]/g;
|
||||
|
||||
const customWordClassMap = {
|
||||
info: 'system-log-info',
|
||||
warn: 'system-warn-info',
|
||||
error: 'system-error-info',
|
||||
debug: 'system-debug-info',
|
||||
};
|
||||
|
||||
export const systemLogInfoHighlightPlugin = ViewPlugin.fromClass(
|
||||
class {
|
||||
decorations: RangeSet<Decoration>;
|
||||
|
||||
constructor(view: EditorView) {
|
||||
this.decorations = this.getDecorations(view);
|
||||
}
|
||||
|
||||
update(update: ViewUpdate) {
|
||||
if (update.docChanged) {
|
||||
this.decorations = this.getDecorations(update.view);
|
||||
}
|
||||
}
|
||||
|
||||
getDecorations(view: EditorView) {
|
||||
const builder = new RangeSetBuilder<Decoration>();
|
||||
const doc = view.state.doc.toString();
|
||||
let match;
|
||||
|
||||
while ((match = infoWord.exec(doc)) !== null) {
|
||||
const deco = Decoration.mark({
|
||||
class: customWordClassMap.info,
|
||||
});
|
||||
|
||||
builder.add(match.index, match.index + match[0].length, deco);
|
||||
}
|
||||
|
||||
return builder.finish();
|
||||
}
|
||||
},
|
||||
{
|
||||
decorations: (v) => v.decorations,
|
||||
},
|
||||
);
|
||||
|
||||
export const systemLogWarnHighlightPlugin = ViewPlugin.fromClass(
|
||||
class {
|
||||
decorations: RangeSet<Decoration>;
|
||||
|
||||
constructor(view: EditorView) {
|
||||
this.decorations = this.getDecorations(view);
|
||||
}
|
||||
|
||||
update(update: ViewUpdate) {
|
||||
if (update.docChanged) {
|
||||
this.decorations = this.getDecorations(update.view);
|
||||
}
|
||||
}
|
||||
|
||||
getDecorations(view: EditorView) {
|
||||
const builder = new RangeSetBuilder<Decoration>();
|
||||
const doc = view.state.doc.toString();
|
||||
let match;
|
||||
|
||||
while ((match = warnWord.exec(doc)) !== null) {
|
||||
const deco = Decoration.mark({
|
||||
class: customWordClassMap.warn,
|
||||
});
|
||||
|
||||
builder.add(match.index, match.index + match[0].length, deco);
|
||||
}
|
||||
|
||||
return builder.finish();
|
||||
}
|
||||
},
|
||||
{
|
||||
decorations: (v) => v.decorations,
|
||||
},
|
||||
);
|
||||
|
||||
export const systemLogDebugHighlightPlugin = ViewPlugin.fromClass(
|
||||
class {
|
||||
decorations: RangeSet<Decoration>;
|
||||
|
||||
constructor(view: EditorView) {
|
||||
this.decorations = this.getDecorations(view);
|
||||
}
|
||||
|
||||
update(update: ViewUpdate) {
|
||||
if (update.docChanged) {
|
||||
this.decorations = this.getDecorations(update.view);
|
||||
}
|
||||
}
|
||||
|
||||
getDecorations(view: EditorView) {
|
||||
const builder = new RangeSetBuilder<Decoration>();
|
||||
const doc = view.state.doc.toString();
|
||||
let match;
|
||||
|
||||
while ((match = debugWord.exec(doc)) !== null) {
|
||||
const deco = Decoration.mark({
|
||||
class: customWordClassMap.debug,
|
||||
});
|
||||
|
||||
builder.add(match.index, match.index + match[0].length, deco);
|
||||
}
|
||||
|
||||
return builder.finish();
|
||||
}
|
||||
},
|
||||
{
|
||||
decorations: (v) => v.decorations,
|
||||
},
|
||||
);
|
||||
|
||||
export const systemLogErrorHighlightPlugin = ViewPlugin.fromClass(
|
||||
class {
|
||||
decorations: RangeSet<Decoration>;
|
||||
|
||||
constructor(view: EditorView) {
|
||||
this.decorations = this.getDecorations(view);
|
||||
}
|
||||
|
||||
update(update: ViewUpdate) {
|
||||
if (update.docChanged) {
|
||||
this.decorations = this.getDecorations(update.view);
|
||||
}
|
||||
}
|
||||
|
||||
getDecorations(view: EditorView) {
|
||||
const builder = new RangeSetBuilder<Decoration>();
|
||||
const doc = view.state.doc.toString();
|
||||
let match;
|
||||
|
||||
while ((match = errorWord.exec(doc)) !== null) {
|
||||
const deco = Decoration.mark({
|
||||
class: customWordClassMap.error,
|
||||
});
|
||||
|
||||
builder.add(match.index, match.index + match[0].length, deco);
|
||||
}
|
||||
|
||||
return builder.finish();
|
||||
}
|
||||
},
|
||||
{
|
||||
decorations: (v) => v.decorations,
|
||||
},
|
||||
);
|
||||
|
||||
export const systemLogTheme = EditorView.baseTheme({
|
||||
'.system-log-info': {
|
||||
color: '#2196F3',
|
||||
},
|
||||
'.system-warn-info': {
|
||||
color: '#FFB827',
|
||||
},
|
||||
'.system-error-info': {
|
||||
color: '#FA5151',
|
||||
},
|
||||
'.system-debug-info': {
|
||||
color: '#009A29',
|
||||
},
|
||||
});
|
||||
@@ -84,6 +84,7 @@ export default {
|
||||
},
|
||||
notificationModes: [
|
||||
{ value: 'gotify', label: 'Gotify' },
|
||||
{ value: 'ntfy', label: 'Ntfy' },
|
||||
{ value: 'goCqHttpBot', label: 'GoCqHttpBot' },
|
||||
{ value: 'serverChan', label: intl.get('Server酱') },
|
||||
{ value: 'pushDeer', label: 'PushDeer' },
|
||||
@@ -96,6 +97,7 @@ export default {
|
||||
{ value: 'iGot', label: 'IGot' },
|
||||
{ value: 'pushPlus', label: 'PushPlus' },
|
||||
{ value: 'wePlusBot', label: intl.get('微加机器人') },
|
||||
{ value: 'wxPusherBot', label: 'wxPusher' },
|
||||
{ value: 'chat', label: intl.get('群晖chat') },
|
||||
{ value: 'email', label: intl.get('邮箱') },
|
||||
{ value: 'lark', label: intl.get('飞书机器人') },
|
||||
@@ -118,6 +120,19 @@ export default {
|
||||
},
|
||||
{ label: 'gotifyPriority', tip: intl.get('推送消息的优先级') },
|
||||
],
|
||||
ntfy: [
|
||||
{
|
||||
label: 'ntfyUrl',
|
||||
tip: intl.get('ntfy的url地址,例如 https://ntfy.sh'),
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
label: 'ntfyTopic',
|
||||
tip: intl.get('ntfy的消息应用topic'),
|
||||
required: true,
|
||||
},
|
||||
{ label: 'ntfyPriority', tip: intl.get('推送消息的优先级') },
|
||||
],
|
||||
chat: [
|
||||
{
|
||||
label: 'chatUrl',
|
||||
@@ -312,6 +327,36 @@ export default {
|
||||
'一对多推送的“群组编码”(一对多推送下面->您的群组(如无则创建)->群组编码,如果您是创建群组人。也需点击“查看二维码”扫描绑定,否则不能接受群组消息推送)',
|
||||
),
|
||||
},
|
||||
{
|
||||
label: 'pushplusTemplate',
|
||||
tip: intl.get(
|
||||
'发送模板',
|
||||
),
|
||||
},
|
||||
{
|
||||
label: 'pushplusChannel',
|
||||
tip: intl.get(
|
||||
'发送渠道',
|
||||
),
|
||||
},
|
||||
{
|
||||
label: 'pushplusWebhook',
|
||||
tip: intl.get(
|
||||
'webhook编码',
|
||||
),
|
||||
},
|
||||
{
|
||||
label: 'pushplusCallbackUrl',
|
||||
tip: intl.get(
|
||||
'发送结果回调地址',
|
||||
),
|
||||
},
|
||||
{
|
||||
label: 'pushplusTo',
|
||||
tip: intl.get(
|
||||
'好友令牌',
|
||||
),
|
||||
},
|
||||
],
|
||||
wePlusBot: [
|
||||
{
|
||||
@@ -334,6 +379,23 @@ export default {
|
||||
),
|
||||
},
|
||||
],
|
||||
wxPusherBot: [
|
||||
{
|
||||
label: 'wxPusherBotAppToken',
|
||||
tip: intl.get('wxPusherBot的appToken'),
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
label: 'wxPusherBotTopicIds',
|
||||
tip: intl.get('wxPusherBot的topicIds'),
|
||||
required: false,
|
||||
},
|
||||
{
|
||||
label: 'wxPusherBotUids',
|
||||
tip: intl.get('wxPusherBot的uids'),
|
||||
required: false,
|
||||
},
|
||||
],
|
||||
lark: [
|
||||
{
|
||||
label: 'larkKey',
|
||||
|
||||
@@ -6,4 +6,6 @@ export const LANG_MAP = {
|
||||
'.mjs': 'javascript',
|
||||
'.sh': 'shell',
|
||||
'.ts': 'typescript',
|
||||
'.ini': 'ini',
|
||||
'.json': 'json'
|
||||
};
|
||||
|
||||
+3
-2
@@ -1,6 +1,7 @@
|
||||
import intl from 'react-intl-universal';
|
||||
import { LANG_MAP, LOG_END_SYMBOL } from './const';
|
||||
import cron_parser from 'cron-parser';
|
||||
import { ICrontab } from '@/pages/crontab/type';
|
||||
|
||||
export default function browserType() {
|
||||
// 权重:系统 + 系统版本 > 平台 > 内核 + 载体 + 内核版本 + 载体版本 > 外壳 + 外壳版本
|
||||
@@ -343,12 +344,12 @@ export function parseCrontab(schedule: string): Date | null {
|
||||
|
||||
export function getCrontabsNextDate(
|
||||
schedule: string,
|
||||
extra_schedules: string[],
|
||||
extra_schedules: ICrontab['extra_schedules'],
|
||||
): Date | null {
|
||||
let date = parseCrontab(schedule);
|
||||
if (extra_schedules?.length) {
|
||||
extra_schedules.forEach((x) => {
|
||||
const _date = parseCrontab(x);
|
||||
const _date = parseCrontab(x.schedule);
|
||||
if (_date && (!date || _date < date)) {
|
||||
date = _date;
|
||||
}
|
||||
|
||||
@@ -3,9 +3,6 @@
|
||||
"target": "es2017",
|
||||
"lib": ["ESNext"],
|
||||
"typeRoots": ["./node_modules/celebrate/lib", "./node_modules/@types"],
|
||||
"paths": {
|
||||
"@/*": ["./back/*"]
|
||||
},
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"experimentalDecorators": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
|
||||
+2
-6
@@ -22,10 +22,6 @@
|
||||
"allowJs": true,
|
||||
"noEmit": false
|
||||
},
|
||||
"include": ["src/**/*", ".umirc.ts", "typings.d.ts", "back/**/*"],
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"static",
|
||||
"data",
|
||||
]
|
||||
"include": ["src/**/*", ".umirc.ts", "typings.d.ts"],
|
||||
"exclude": ["node_modules", "static", "data"]
|
||||
}
|
||||
|
||||
+7
-7
@@ -1,8 +1,8 @@
|
||||
version: 2.17.11
|
||||
changeLogLink: https://t.me/jiao_long/422
|
||||
publishTime: 2024-09-13 23:00
|
||||
version: 2.18.0
|
||||
changeLogLink: https://t.me/jiao_long/424
|
||||
publishTime: 2025-01-05 13:00
|
||||
changeLog: |
|
||||
1. 修复无法获取设置的环境变量 PYTHONPATH 和 NODE_OPTIONS
|
||||
2. 修复定时任务视图过多时,无法看到视图管理
|
||||
3. 修复自定义通知 json 解析
|
||||
4. 修复可能产生目录遍历攻击 API
|
||||
1. 由于安全问题,修改认证信息存储方式,不再使用 auth.json 存储
|
||||
2. 修复初始化 SystemConfig 数据
|
||||
3. 修改通知文件未设置时提示
|
||||
4. 修复配置文件更新可能异常
|
||||
|
||||
Reference in New Issue
Block a user