Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
1171d6e6cc | ||
|
ccec3868bb |
4
.gitignore
vendored
4
.gitignore
vendored
@ -11,7 +11,3 @@ server/app/db/*
|
|||||||
plan.md
|
plan.md
|
||||||
.env
|
.env
|
||||||
.env.local
|
.env.local
|
||||||
.env-encrypt-key
|
|
||||||
*clear.js
|
|
||||||
local-script
|
|
||||||
版本发布.md
|
|
||||||
|
31
CHANGELOG.md
31
CHANGELOG.md
@ -1,34 +1,3 @@
|
|||||||
## [3.0.3](https://github.com/chaos-zhu/easynode/releases) (2024-12-22)
|
|
||||||
|
|
||||||
* 支持keyboard-interactive服务器验证(serv00验证通过)
|
|
||||||
* 支持TG Bot通知方式
|
|
||||||
* 添加web端Plus授权功能
|
|
||||||
* 修复一些UI问题
|
|
||||||
* 修复MFA2登录验证码为0开头无法输入的bug
|
|
||||||
|
|
||||||
## [3.0.2](https://github.com/chaos-zhu/easynode/releases) (2024-11-20)
|
|
||||||
|
|
||||||
* 修复添加实例错误禁用的bug
|
|
||||||
|
|
||||||
|
|
||||||
## [3.0.1](https://github.com/chaos-zhu/easynode/releases) (2024-11-18)
|
|
||||||
|
|
||||||
* 修复同IP实例SFTP连接到其他的实例的bug
|
|
||||||
* 修复一些UI问题
|
|
||||||
|
|
||||||
|
|
||||||
## [3.0.0](https://github.com/chaos-zhu/easynode/releases) (2024-11-09)
|
|
||||||
|
|
||||||
* 新增跳板机功能,支持选择多台机器跳转
|
|
||||||
* 脚本库批量导出导入
|
|
||||||
* 本地socket断开自动重连,无需手动重新连接
|
|
||||||
* 支持脚本库模糊搜索功能
|
|
||||||
* 分组添加实例数量标识
|
|
||||||
* 优化登录逻辑
|
|
||||||
* 默认登录有效期更改为当天有效
|
|
||||||
* 优化脚本库新增脚本时序号自动累加
|
|
||||||
* 修复一些小bug
|
|
||||||
|
|
||||||
## [2.3.0](https://github.com/chaos-zhu/easynode/releases) (2024-10-24)
|
## [2.3.0](https://github.com/chaos-zhu/easynode/releases) (2024-10-24)
|
||||||
|
|
||||||
* 重构本地数据库存储方式(性能提升一个level~)
|
* 重构本地数据库存储方式(性能提升一个level~)
|
||||||
|
128
README.md
128
README.md
@ -1,61 +1,29 @@
|
|||||||
<div align="center">
|
|
||||||
|
|
||||||
# EasyNode
|
# EasyNode
|
||||||
|
|
||||||
_✨ 一个多功能Linux服务器WEB终端面板(webSSH&webSFTP) ✨_
|
<!-- - [功能](#功能)
|
||||||
|
- [安装](#安装)
|
||||||
</div>
|
- [监控服务安装](#监控服务安装)
|
||||||
|
- [版本日志](#版本日志)
|
||||||
<p align="center">
|
- [开发](#开发)
|
||||||
<a href="https://github.com/chaos-zhu/easynode/releases/latest">
|
- [QA](#QA)
|
||||||
<img src="https://img.shields.io/github/v/release/chaos-zhu/easynode?color=brightgreen" alt="release">
|
- [安全与建议](#安全与建议)
|
||||||
</a>
|
- [捐赠](#捐赠)
|
||||||
<a href="https://github.com/chaos-zhu/easynode/actions">
|
- [License](#license) -->
|
||||||
<img src="https://img.shields.io/github/actions/workflow/status/chaos-zhu/easynode/docker-builder.yml?branch=main" alt="deployment status">
|
|
||||||
</a>
|
|
||||||
<a href="https://hub.docker.com/repository/docker/chaoszhu/easynode">
|
|
||||||
<img src="https://img.shields.io/docker/pulls/chaoszhu/easynode?color=brightgreen" alt="docker pull">
|
|
||||||
</a>
|
|
||||||
<a href="https://github.com/chaos-zhu/easynode/releases/latest">
|
|
||||||
<img src="https://img.shields.io/github/downloads/chaos-zhu/easynode/total?color=brightgreen&include_prereleases" alt="release">
|
|
||||||
</a>
|
|
||||||
<a href="https://raw.githubusercontent.com/chaos-zhu/easynode/main/LICENSE">
|
|
||||||
<img src="https://img.shields.io/github/license/chaos-zhu/easynode?color=brightgreen" alt="license">
|
|
||||||
</a>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p align="center">
|
|
||||||
<a href="#功能">功能</a>
|
|
||||||
·
|
|
||||||
<a href="#面板展示">面板展示</a>
|
|
||||||
·
|
|
||||||
<a href="#项目部署">项目部署</a>
|
|
||||||
·
|
|
||||||
<a href="#监控服务安装">监控服务安装</a>
|
|
||||||
·
|
|
||||||
<a href="#安全与建议">安全与建议</a>
|
|
||||||
·
|
|
||||||
<a href="#常见问题">常见问题</a>
|
|
||||||
<!-- ·
|
|
||||||
<a href="#Plus功能">Plus版功能</a> -->
|
|
||||||
</p>
|
|
||||||
|
|
||||||
## 功能
|
## 功能
|
||||||
|
|
||||||
+ [x] 功能完善的**SSH终端**&**SFTP**
|
- [x] 功能完善的**SSH终端**&**SFTP**
|
||||||
+ [x] 批量导入、导出、编辑服务器配置、脚本等
|
- [x] 批量**导入导出**实例(Xshell&FinalShell&EasyNode)
|
||||||
+ [x] 脚本库
|
- [x] **实例分组**
|
||||||
+ [x] 实例分组
|
- [x] **凭据托管**
|
||||||
+ [x] 凭据托管
|
- [x] **多渠道通知**
|
||||||
+ [x] 多渠道通知
|
- [x] **脚本库**
|
||||||
+ [x] 批量下发指令
|
- [x] **批量指令**
|
||||||
+ [x] 自定义终端主题
|
- [x] **终端主题背景自定义**
|
||||||
|
|
||||||
## 面板展示
|

|
||||||
|
|
||||||

|
## 安装
|
||||||
|
|
||||||
## 项目部署
|
|
||||||
|
|
||||||
- 默认账户密码 `admin/admin`
|
- 默认账户密码 `admin/admin`
|
||||||
- web端口:8082
|
- web端口:8082
|
||||||
@ -63,15 +31,34 @@ _✨ 一个多功能Linux服务器WEB终端面板(webSSH&webSFTP) ✨_
|
|||||||
### docker镜像
|
### docker镜像
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
docker run -d -p 8082:8082 --restart=always -v /root/easynode/db:/easynode/app/db chaoszhu/easynode
|
docker run -d -p 8082:8082 --name=easynode --restart=always -v /root/easynode/db:/easynode/app/db chaoszhu/easynode
|
||||||
```
|
```
|
||||||
环境变量:
|
环境变量:
|
||||||
- `DEBUG`: 启动debug日志 0:关闭 1:开启, 默认关闭
|
- `DEBUG`: 启动debug日志 0:关闭 1:开启, 默认关闭
|
||||||
- `ALLOWED_IPS`: 可以访问服务的IP白名单, 多个使用逗号分隔, 支持填写部分ip前缀, 例如: `-e ALLOWED_IPS=127.0.0.1,196.168`
|
- `ALLOWED_IPS`: 可以访问服务的IP白名单, 多个使用逗号分隔, 支持填写部分ip前缀, 例如: `-e ALLOWED_IPS=127.0.0.1,196.168`
|
||||||
|
|
||||||
|
### 手动部署
|
||||||
|
|
||||||
|
依赖Nodejs版本 > 20+
|
||||||
|
|
||||||
|
```shell
|
||||||
|
git clone https://github.com/chaos-zhu/easynode
|
||||||
|
cd easynode
|
||||||
|
yarn
|
||||||
|
cd web
|
||||||
|
yarn build
|
||||||
|
mv dist/* ../server/app/static
|
||||||
|
cd ../server
|
||||||
|
yarn start
|
||||||
|
# 后台运行需安装pm2
|
||||||
|
pm2 start index.js --name easynode-server
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## 监控服务安装
|
## 监控服务安装
|
||||||
|
|
||||||
- 监控服务用于实时向服务端&web端推送**系统、公网IP、CPU、内存、硬盘、网卡**等基础信息
|
- 监控服务用于实时向服务端推送**系统、公网IP、CPU、内存、硬盘、网卡**等基础信息,不安装不影响使用面板,但是无法实时同步cpu占用、实时网速、硬盘容量等实用信息。
|
||||||
|
|
||||||
- 默认端口:**22022**
|
- 默认端口:**22022**
|
||||||
|
|
||||||
@ -79,16 +66,16 @@ docker run -d -p 8082:8082 --restart=always -v /root/easynode/db:/easynode/app/d
|
|||||||
|
|
||||||
```shell
|
```shell
|
||||||
# 使用默认端口22022安装
|
# 使用默认端口22022安装
|
||||||
curl -o- https://git.221022.xyz/https://raw.githubusercontent.com/chaos-zhu/easynode/main/client/easynode-client-install.sh | bash
|
curl -o- https://ghp.ci/https://raw.githubusercontent.com/chaos-zhu/easynode/main/client/easynode-client-install.sh | bash
|
||||||
|
|
||||||
# 使用自定义端口安装, 例如54321
|
# 使用自定义端口安装, 例如54321
|
||||||
curl -o- https://git.221022.xyz/https://raw.githubusercontent.com/chaos-zhu/easynode/main/client/easynode-client-install.sh | bash -s -- 54321
|
curl -o- https://ghp.ci/https://raw.githubusercontent.com/chaos-zhu/easynode/main/client/easynode-client-install.sh | bash -s -- 54321
|
||||||
```
|
```
|
||||||
|
|
||||||
> 卸载
|
> 卸载
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
curl -o- https://git.221022.xyz/https://raw.githubusercontent.com/chaos-zhu/easynode/main/client/easynode-client-uninstall.sh | bash
|
curl -o- https://ghp.ci/https://raw.githubusercontent.com/chaos-zhu/easynode/main/client/easynode-client-uninstall.sh | bash
|
||||||
```
|
```
|
||||||
|
|
||||||
> 查看监控服务状态:`systemctl status easynode-client`
|
> 查看监控服务状态:`systemctl status easynode-client`
|
||||||
@ -99,6 +86,20 @@ curl -o- https://git.221022.xyz/https://raw.githubusercontent.com/chaos-zhu/easy
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## 开发
|
||||||
|
|
||||||
|
1. 拉取代码,环境 `nodejs>=20`
|
||||||
|
2. cd到项目根目录,`yarn install` 执行安装依赖
|
||||||
|
3. `yarn dev`启动项目
|
||||||
|
4. web: `http://localhost:18090/`
|
||||||
|
|
||||||
|
## 版本日志
|
||||||
|
|
||||||
|
- [CHANGELOG](./CHANGELOG.md)
|
||||||
|
|
||||||
|
## QA
|
||||||
|
|
||||||
|
- [QA](./Q%26A.md)
|
||||||
|
|
||||||
## 安全与建议
|
## 安全与建议
|
||||||
|
|
||||||
@ -109,15 +110,12 @@ curl -o- https://git.221022.xyz/https://raw.githubusercontent.com/chaos-zhu/easy
|
|||||||
|
|
||||||
webssh与监控服务都将以`该服务器作为中转`。中国大陆用户建议使用香港、新加坡、日本、韩国等地区的低延迟服务器来安装服务端面板
|
webssh与监控服务都将以`该服务器作为中转`。中国大陆用户建议使用香港、新加坡、日本、韩国等地区的低延迟服务器来安装服务端面板
|
||||||
|
|
||||||
## 常见问题
|
## 捐赠
|
||||||
|
|
||||||
- [QA](./Q%26A.md)
|
如果您认为此项目帮到了您, 您可以请我喝杯阔乐~
|
||||||
|
|
||||||
<!-- ## Plus版功能
|

|
||||||
|
|
||||||
- 跳板机功能,拯救被墙实例与龟速终端输入
|
## License
|
||||||
- 本地socket断开自动重连,无需手动重新连接
|
|
||||||
- 批量修改实例配置(优化版)
|
[MIT](LICENSE). Copyright (c).
|
||||||
- 脚本库批量导出导入
|
|
||||||
- 凭据管理支持解密带密码保护的密钥
|
|
||||||
- 提出的功能需求享有更高的开发优先级 -->
|
|
||||||
|
@ -10,7 +10,7 @@ SERVER_NAME=easynode-client
|
|||||||
FILE_PATH=/root/local/easynode-client
|
FILE_PATH=/root/local/easynode-client
|
||||||
SERVICE_PATH=/etc/systemd/system
|
SERVICE_PATH=/etc/systemd/system
|
||||||
CLIENT_VERSION=client-2024-10-13 # 目前监控客户端版本发布需手动更改为最新版本号
|
CLIENT_VERSION=client-2024-10-13 # 目前监控客户端版本发布需手动更改为最新版本号
|
||||||
SERVER_PROXY="https://git.221022.xyz/"
|
SERVER_PROXY="https://ghp.ci/"
|
||||||
|
|
||||||
if [ ! -z "$1" ]; then
|
if [ ! -z "$1" ]; then
|
||||||
clientPort=$1
|
clientPort=$1
|
||||||
|
@ -22,8 +22,7 @@
|
|||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "concurrently \"yarn workspace web run dev\" \"yarn workspace server run local\"",
|
"dev": "concurrently \"yarn workspace web run dev\" \"yarn workspace server run local\"",
|
||||||
"clean": "rimraf web/node_modules server/node_modules client/node_modules node_modules",
|
"clean": "rimraf web/node_modules server/node_modules client/node_modules node_modules"
|
||||||
"encrypt": "node ./local-script/encrypt-file.js"
|
|
||||||
},
|
},
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/chaos-zhu/easynode/issues"
|
"url": "https://github.com/chaos-zhu/easynode/issues"
|
||||||
|
@ -2,7 +2,4 @@
|
|||||||
DEBUG=1
|
DEBUG=1
|
||||||
|
|
||||||
# 访问IP限制
|
# 访问IP限制
|
||||||
allowedIPs=['127.0.0.1']
|
allowedIPs=['127.0.0.1']
|
||||||
|
|
||||||
# 激活PLUS功能的授权码
|
|
||||||
PLUS_KEY=
|
|
@ -17,7 +17,6 @@ module.exports = {
|
|||||||
notifyConfigDBPath: path.join(process.cwd(),'app/db/notify-config.db'),
|
notifyConfigDBPath: path.join(process.cwd(),'app/db/notify-config.db'),
|
||||||
onekeyDBPath: path.join(process.cwd(),'app/db/onekey.db'),
|
onekeyDBPath: path.join(process.cwd(),'app/db/onekey.db'),
|
||||||
logDBPath: path.join(process.cwd(),'app/db/log.db'),
|
logDBPath: path.join(process.cwd(),'app/db/log.db'),
|
||||||
plusDBPath: path.join(process.cwd(),'app/db/plus.db'),
|
|
||||||
apiPrefix: '/api/v1',
|
apiPrefix: '/api/v1',
|
||||||
logConfig: {
|
logConfig: {
|
||||||
outDir: path.join(process.cwd(),'./app/logs'),
|
outDir: path.join(process.cwd(),'./app/logs'),
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"name": "easynode监控服务安装",
|
"name": "easynode监控服务安装",
|
||||||
"command": "curl -o- https://git.221022.xyz/https://raw.githubusercontent.com/chaos-zhu/easynode/main/client/easynode-client-install.sh | bash",
|
"command": "curl -o- https://ghp.ci/https://raw.githubusercontent.com/chaos-zhu/easynode/main/client/easynode-client-install.sh | bash",
|
||||||
"description": "easynode-监控服务-安装脚本"
|
"description": "easynode-监控服务-安装脚本"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "easynode监控服务卸载",
|
"name": "easynode监控服务卸载",
|
||||||
"command": "curl -o- https://git.221022.xyz/https://raw.githubusercontent.com/chaos-zhu/easynode/main/client/easynode-client-uninstall.sh | bash",
|
"command": "curl -o- https://ghp.ci/https://raw.githubusercontent.com/chaos-zhu/easynode/main/client/easynode-client-uninstall.sh | bash",
|
||||||
"description": "easynode-监控服务-卸载脚本"
|
"description": "easynode-监控服务-卸载脚本"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
const path = require('path')
|
|
||||||
const decryptAndExecuteAsync = require('../utils/decrypt-file')
|
|
||||||
const { RSADecryptAsync, AESEncryptAsync, AESDecryptAsync } = require('../utils/encrypt')
|
const { RSADecryptAsync, AESEncryptAsync, AESDecryptAsync } = require('../utils/encrypt')
|
||||||
const { HostListDB } = require('../utils/db-class')
|
const { HostListDB } = require('../utils/db-class')
|
||||||
const hostListDB = new HostListDB().getInstance()
|
const hostListDB = new HostListDB().getInstance()
|
||||||
|
|
||||||
async function getHostList({ res }) {
|
async function getHostList({ res }) {
|
||||||
|
// console.log('get-host-list')
|
||||||
let data = await hostListDB.findAsync({})
|
let data = await hostListDB.findAsync({})
|
||||||
data?.sort((a, b) => Number(b.index || 0) - Number(a.index || 0))
|
data?.sort((a, b) => Number(b.index || 0) - Number(a.index || 0))
|
||||||
for (const item of data) {
|
for (const item of data) {
|
||||||
try {
|
try {
|
||||||
let { authType, _id: id, credential } = item
|
let { username, port, authType, _id: id, credential } = item
|
||||||
|
// console.log('解密凭证title: ', credential)
|
||||||
if (credential) credential = await AESDecryptAsync(credential)
|
if (credential) credential = await AESDecryptAsync(credential)
|
||||||
const isConfig = Boolean(authType && item[authType])
|
const isConfig = Boolean(username && port && (item[authType]))
|
||||||
Object.assign(item, { id, isConfig, password: '', privateKey: '', credential })
|
Object.assign(item, { id, isConfig, password: '', privateKey: '', credential })
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
consola.error('getHostList error: ', error.message)
|
consola.error('getHostList error: ', error.message)
|
||||||
@ -21,55 +21,94 @@ async function getHostList({ res }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function addHost({ res, request }) {
|
async function addHost({ res, request }) {
|
||||||
let { body } = request
|
let {
|
||||||
if (!body.name || !body.host) return res.fail({ msg: 'missing params: name or host' })
|
body: {
|
||||||
let newRecord = { ...body }
|
name, host, index, expired, expiredNotify, group, consoleUrl, remark,
|
||||||
const { authType, tempKey } = newRecord
|
port: newPort, clientPort, username, authType, password, privateKey, credential, command, tempKey
|
||||||
if (newRecord[authType] && tempKey) {
|
}
|
||||||
const clearTempKey = await RSADecryptAsync(tempKey)
|
} = request
|
||||||
const clearSSHKey = await AESDecryptAsync(newRecord[authType], clearTempKey)
|
// console.log(request)
|
||||||
newRecord[authType] = await AESEncryptAsync(clearSSHKey)
|
if (!host || !name) return res.fail({ msg: 'missing params: name or host' })
|
||||||
|
let record = {
|
||||||
|
name, host, index, expired, expiredNotify, group, consoleUrl, remark,
|
||||||
|
port: newPort, clientPort, username, authType, password, privateKey, credential, command
|
||||||
}
|
}
|
||||||
await hostListDB.insertAsync(newRecord)
|
if (record[authType]) {
|
||||||
|
const clearTempKey = await RSADecryptAsync(tempKey)
|
||||||
|
console.log('clearTempKey:', clearTempKey)
|
||||||
|
const clearSSHKey = await AESDecryptAsync(record[authType], clearTempKey)
|
||||||
|
console.log(`${ authType }原密文: `, clearSSHKey)
|
||||||
|
record[authType] = await AESEncryptAsync(clearSSHKey)
|
||||||
|
// console.log(`${ authType }__commonKey加密存储: `, record[authType])
|
||||||
|
}
|
||||||
|
await hostListDB.insertAsync(record)
|
||||||
res.success()
|
res.success()
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateHost({ res, request }) {
|
async function updateHost({ res, request }) {
|
||||||
let {
|
let {
|
||||||
body
|
body: {
|
||||||
|
hosts,
|
||||||
|
id,
|
||||||
|
host: newHost, name: newName, index, oldHost, expired, expiredNotify, group, consoleUrl, remark,
|
||||||
|
port, clientPort, username, authType, password, privateKey, credential, command, tempKey
|
||||||
|
}
|
||||||
} = request
|
} = request
|
||||||
if (typeof body !== 'object') return res.fail({ msg: '参数错误' })
|
let isBatch = Array.isArray(hosts)
|
||||||
const updateFiled = { ...body }
|
if (isBatch) {
|
||||||
const { id, authType, tempKey } = updateFiled
|
if (!hosts.length) return res.fail({ msg: 'hosts为空' })
|
||||||
if (authType && updateFiled[authType]) {
|
let hostList = await hostListDB.findAsync({})
|
||||||
const clearTempKey = await RSADecryptAsync(tempKey)
|
for (let oldRecord of hostList) {
|
||||||
const clearSSHKey = await AESDecryptAsync(updateFiled[authType], clearTempKey)
|
let target = hosts.find(item => item.id === oldRecord._id)
|
||||||
updateFiled[authType] = await AESEncryptAsync(clearSSHKey)
|
if (!target) continue
|
||||||
delete updateFiled.tempKey
|
let { authType } = target
|
||||||
} else {
|
// 如果存在原认证方式则保存下来
|
||||||
delete updateFiled.authType
|
if (!target[authType]) {
|
||||||
delete updateFiled.password
|
target[authType] = oldRecord[authType]
|
||||||
delete updateFiled.privateKey
|
} else {
|
||||||
delete updateFiled.credential
|
const clearTempKey = await RSADecryptAsync(target.tempKey)
|
||||||
|
// console.log('批量解密tempKey:', clearTempKey)
|
||||||
|
const clearSSHKey = await AESDecryptAsync(target[authType], clearTempKey)
|
||||||
|
// console.log(`${ authType }原密文: `, clearSSHKey)
|
||||||
|
target[authType] = await AESEncryptAsync(clearSSHKey)
|
||||||
|
// console.log(`${ authType }__commonKey加密存储: `, target[authType])
|
||||||
|
}
|
||||||
|
delete target._id
|
||||||
|
delete target.monitorData
|
||||||
|
delete target.tempKey
|
||||||
|
Object.assign(oldRecord, target)
|
||||||
|
await hostListDB.updateAsync({ _id: oldRecord._id }, oldRecord)
|
||||||
|
}
|
||||||
|
return res.success({ msg: '批量修改成功' })
|
||||||
}
|
}
|
||||||
console.log('updateFiled: ', updateFiled)
|
if (!newHost || !newName || !oldHost) return res.fail({ msg: '参数错误' })
|
||||||
await hostListDB.updateAsync({ _id: id }, { $set: { ...updateFiled } })
|
|
||||||
res.success({ msg: '修改成功' })
|
|
||||||
}
|
|
||||||
|
|
||||||
async function batchUpdateHost({ res, request }) {
|
let updateRecord = {
|
||||||
let { updateHosts } = (await decryptAndExecuteAsync(path.join(__dirname, 'plus.js'))) || {}
|
name: newName, host: newHost, index, expired, expiredNotify, group, consoleUrl, remark,
|
||||||
if (updateHosts) {
|
port, clientPort, username, authType, password, privateKey, credential, command
|
||||||
await updateHosts({ res, request })
|
|
||||||
} else {
|
|
||||||
return res.fail({ data: false, msg: 'Plus专属功能!' })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let oldRecord = await hostListDB.findOneAsync({ _id: id })
|
||||||
|
// 如果存在原认证方式则保存下来
|
||||||
|
if (!updateRecord[authType] && oldRecord[authType]) {
|
||||||
|
updateRecord[authType] = oldRecord[authType]
|
||||||
|
} else {
|
||||||
|
const clearTempKey = await RSADecryptAsync(tempKey)
|
||||||
|
// console.log('clearTempKey:', clearTempKey)
|
||||||
|
const clearSSHKey = await AESDecryptAsync(updateRecord[authType], clearTempKey)
|
||||||
|
// console.log(`${ authType }原密文: `, clearSSHKey)
|
||||||
|
updateRecord[authType] = await AESEncryptAsync(clearSSHKey)
|
||||||
|
// console.log(`${ authType }__commonKey加密存储: `, updateRecord[authType])
|
||||||
|
}
|
||||||
|
await hostListDB.updateAsync({ _id: oldRecord._id }, updateRecord)
|
||||||
|
res.success({ msg: '修改成功' })
|
||||||
}
|
}
|
||||||
|
|
||||||
async function removeHost({ res, request }) {
|
async function removeHost({ res, request }) {
|
||||||
let { body: { ids } } = request
|
let { body: { ids } } = request
|
||||||
if (!Array.isArray(ids)) return res.fail({ msg: '参数错误' })
|
if (!Array.isArray(ids)) return res.fail({ msg: '参数错误' })
|
||||||
const numRemoved = await hostListDB.removeAsync({ _id: { $in: ids } }, { multi: true })
|
const numRemoved = await hostListDB.removeAsync({ _id: { $in: ids } }, { multi: true })
|
||||||
|
// console.log('numRemoved: ', numRemoved)
|
||||||
res.success({ data: `已移除,数量: ${ numRemoved }` })
|
res.success({ data: `已移除,数量: ${ numRemoved }` })
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,6 +150,5 @@ module.exports = {
|
|||||||
addHost,
|
addHost,
|
||||||
updateHost,
|
updateHost,
|
||||||
removeHost,
|
removeHost,
|
||||||
importHost,
|
importHost
|
||||||
batchUpdateHost
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
const path = require('path')
|
|
||||||
const decryptAndExecuteAsync = require('../utils/decrypt-file')
|
|
||||||
const { sendServerChan, sendEmail } = require('../utils/notify')
|
const { sendServerChan, sendEmail } = require('../utils/notify')
|
||||||
const { NotifyConfigDB, NotifyDB } = require('../utils/db-class')
|
const { NotifyConfigDB, NotifyDB } = require('../utils/db-class')
|
||||||
const notifyDB = new NotifyDB().getInstance()
|
const notifyDB = new NotifyDB().getInstance()
|
||||||
@ -7,6 +5,7 @@ const notifyConfigDB = new NotifyConfigDB().getInstance()
|
|||||||
|
|
||||||
async function getNotifyConfig({ res }) {
|
async function getNotifyConfig({ res }) {
|
||||||
const data = await notifyConfigDB.findOneAsync({})
|
const data = await notifyConfigDB.findOneAsync({})
|
||||||
|
console.log(data)
|
||||||
return res.success({ data })
|
return res.success({ data })
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -14,7 +13,6 @@ async function updateNotifyConfig({ res, request }) {
|
|||||||
let { body: { noticeConfig } } = request
|
let { body: { noticeConfig } } = request
|
||||||
let { type } = noticeConfig
|
let { type } = noticeConfig
|
||||||
try {
|
try {
|
||||||
// console.log('noticeConfig: ', noticeConfig[type])
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'sct':
|
case 'sct':
|
||||||
await sendServerChan(noticeConfig[type]['sendKey'], 'EasyNode通知测试', '这是一条测试通知')
|
await sendServerChan(noticeConfig[type]['sendKey'], 'EasyNode通知测试', '这是一条测试通知')
|
||||||
@ -22,12 +20,6 @@ async function updateNotifyConfig({ res, request }) {
|
|||||||
case 'email':
|
case 'email':
|
||||||
await sendEmail(noticeConfig[type], 'EasyNode通知测试', '这是一条测试通知')
|
await sendEmail(noticeConfig[type], 'EasyNode通知测试', '这是一条测试通知')
|
||||||
break
|
break
|
||||||
case 'tg':
|
|
||||||
let { sendTg } = await decryptAndExecuteAsync(path.join(__dirname, '../utils/plus.js')) || {}
|
|
||||||
console.log('sendTg: ', sendTg)
|
|
||||||
if (!sendTg) return res.fail({ msg: 'Plus专属功能点,请激活Plus' })
|
|
||||||
await sendTg(noticeConfig[type], 'EasyNode通知测试', '这是一条测试通知')
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
await notifyConfigDB.update({}, { $set: noticeConfig }, { upsert: true })
|
await notifyConfigDB.update({}, { $set: noticeConfig }, { upsert: true })
|
||||||
return res.success({ msg: '测试通过 | 保存成功' })
|
return res.success({ msg: '测试通过 | 保存成功' })
|
||||||
|
@ -1 +0,0 @@
|
|||||||
U2FsdGVkX18Hh5ifqReKzxVcNwA8NC2cGnvuPCHW9V4+sVMxFFE7NxliY3R9Pyu2jZvnRb80+VpkEinfaZX0H1xx+I5PU2/mqIUU+1yxKrmWQtwJm6EwNwyDFrj3Epbl1zkfTUXLhk1a5lff+s1Qic02SbnLMtThV9Pg2m6w7HeJJiYOdaRFGlHvgGL4m7O9Ps135wdsdLU9y5aRiXF+1fi35Y6ZlDwPJGEMfZyIQKF87QksAW6LOP/Y1+mgIfLS6WwJnf8kW4l0KQktfvmsWtn00neZRQJc9I6WVMEN2jq4vbeE0KqtoOV0B/+Y/nLFnJjSYs5VE4qQ3gTFzuHe/dPoWXcBX5J5RhAxeY1qVQUtgKxUVwnBeGyjCmM7scX001AoxMcZFnpl+rx1ccOHYF2wB8GsuhsRlAAgWiyPXVJFSMYW3mFm61wvy1dWFad+kNYNFJo+SW8YUSkUCs3sXHXHn8eFsy75ChgHqMp1hvvyug8eFVPwp3IgtLK1D1Et096h8EhhvCvR7VecWwFi4AeMvuZWSmn+gkgGinx9zKUjkA5Bi65tyXmCa4ozyoi+TtuWKqJZyRQ8K2Kw0fc1AUCN8Cp/89Omb9thA10lvVtEJ+k1anao1llY9tPJsYlb0lNGYUlff29cDQnKIbV8P9mHXAyjRJatypWfLPfvqBT81iEDdB5dMASgm3gZqQPrSE50hBsCjzeNaCQF32TPfEFeOWRS1M1tOFpjanJZwfUreMLR77lANkSjiPYOgUvSzgAu0JVIehjXW2vYhC3+Sg7ETbdeV74pAx+Tc8qNWPyZtbNvdg+5wegr5ICgvXObf/btDUL9Jl7x+x7SY7dDrDj6AJRQROcUCdtNisG8HBKnvWS8nqNaUmR7d2E8pQ6qEFKX1ISvkxUp5RTD+9Vos0BfL4+mUB9iovxhDTfSXCIdJa69obTvvLD9xOJvNDrd72zLTQZSI74i/cFeNlersYiQAgL26oyqkv1eFL7Xd3bzq24EbZjP3hrBEqktW5qFeUAe8cPuA3bwDQwGI5BGkQ2hsS7G8xvx0dwllUOE3XVjxEuH8hkGO/GfFdqPRHfkizoNu1yNQEQeY6s9cMp5ovY20YIPRl8bhakjcUtUjMqee5kDdmScELKzoam8TwNiTBrBiuCwA2DcaC6dWDgOjhRs1Y4LEiQ8KZptuO/zTbJc5qcoKA6CUiVTN7vD4u5DHN60mGU9hoS46hfCe++U6L5FR4lafjRdUR0qkCEtf2SKnXyWqLUTgS2kNLQr4ZZbLMi7Mm+5+Q1JIIjzqqfjOlzeO9T4F9lknUkFXD5bc0Q5g+it89KG8xDbISUznv/UTXSxh485VKecT9Cjgd7I438N6xeL1CcJZiluLOvZ0Z3FDxkrW4Tmwbi852Z7tghFAamMW7GPL8LJRt5q2fhe0/U5oKBuGglRvga2tju3wBfzQdpavyNVyRjN2pywO4fk3qhez0suF9wVOc6GU9PUU2jCRm/gEF/qrj32tUjpDbxS9D1nCs441La7bYV8eCtb+2pEjgvjtIp+BM0lz+aHnseKT/iUGHlubKhrTMJQ7jEAPKtcl2OpS4fXiVIiy0qK4rI8S/vkdcRd07H77FfPDqEHTxTMQhHMGqi+d+YpFgrXSin4vcn8KXS87MEILjn5kmUDOsXAWZCqlD3oQ5ADVt91R+Ty5DcIZgaiQkB1aq6feIfSx4rsioNCOgFqmx4mcCds4Ar6gzsRdXN4Kcw8plrrePttZLyNOleoIX5Diy3GAiq6ENCkbYtsaic5EqCQ6AV5qBzEDu0DKZkdqxUWd0wf5+gJwEFQAMj+lD/UhlHuD8ArSI56jYQUbrcfdLnXutfrNA2Ogte9RltQxiUb6N90uNW1rT/2vlUgmQgbvZriKqpm+K3CZ9+6zsCDSUgr/cJmkSvu5gIpvC81IAQX6K8sUqtc9l3vn5vEvqqIp2yb5N25xs0NB0/yglyAHgXLXbG/sE73TrRMj4W+3HGlF35YSQnsLcyzvqEIoAhjngDf/6HXCkNpUQjyc8+uzIsKTh73WV9rh1/7xoY0lxHGabI+c8j5+WlWD1K0Xec83Sodqf+XStr90w1ceK73/DZGdgJIbdKfgO4Xn9ZY8AlzbeJq0W2/WWi/nPE9UZtVK6EEuOcmG2L5/gv2hTMjko6KG+ygrn0+bSvClXL51Brq7IvfO9mMlAGV8zK8vp82RM0KH38xPaJGTHbdawB1gaatkXywzXw0YTmzfaswt46WcWlLZ8vgr01zMp7pfp6A4GAT952rSprlfE014osCZj2oe+j2FQ0QOIYPSj3IatoqlDGfMOxPAbId8sx3anls9Zbk4feeVEvy0+VEmeZVIyDSzjZWuQYQ7VQLEcyaARRtOnfDYt2STIXy61ScWepdj1tmuhw/Kc0Aov61tEZ1apHHxrugzmN96A/2FST2KkbCtsYvbBqE9bZ3F4dLAfVazWidSQv4wPKgkZHFY94jlXxkN0dkA0yildyiQC5k3Iiw3zSwZO9a91K8uSQbbL54C4Y7aCW1HG//OabzNSg9Qty5a1hoiovpCiziAc3xoxuT+75ICozxKLG8+UN3vEZ2QXMv3b/qlXhRr7t8LtlFiA9nmUMfCAieovrZSB4OzrKHe37mg17USWsF1by73YTriFRTiE7JO5E6GMFz3bloppT64svf0SHgFELOuc4xclZfJTYAhLLxkiwDzmKWWheEz5TOOL/8p+5n7+/AuffGykVu6NlmSXH1uIg9JYNUy6UFnd2vOhx+8DxSVFd+1VdW+u2zpPAgiFAiNZJGx+6BVS05kO2mQ++0BHlmbXTw2tdt/BF1N07J5kIY0yRqrMtlwAb6cNbb+yWHkYX/C+3MDLBd
|
|
@ -1,8 +1,6 @@
|
|||||||
const path = require('path')
|
const localShellJson = require('../config/shell.json')
|
||||||
const decryptAndExecuteAsync = require('../utils/decrypt-file')
|
|
||||||
const { randomStr } = require('../utils/tools')
|
const { randomStr } = require('../utils/tools')
|
||||||
const { ScriptsDB } = require('../utils/db-class')
|
const { ScriptsDB } = require('../utils/db-class')
|
||||||
const localShellJson = require('../config/shell.json')
|
|
||||||
const scriptsDB = new ScriptsDB().getInstance()
|
const scriptsDB = new ScriptsDB().getInstance()
|
||||||
|
|
||||||
let localShell = JSON.parse(JSON.stringify(localShellJson)).map((item) => {
|
let localShell = JSON.parse(JSON.stringify(localShellJson)).map((item) => {
|
||||||
@ -46,28 +44,10 @@ const removeScript = async ({ res, request }) => {
|
|||||||
res.success({ data: '移除成功' })
|
res.success({ data: '移除成功' })
|
||||||
}
|
}
|
||||||
|
|
||||||
const batchRemoveScript = async ({ res, request }) => {
|
|
||||||
let { body: { ids } } = request
|
|
||||||
if (!Array.isArray(ids)) return res.fail({ msg: '参数错误' })
|
|
||||||
const numRemoved = await scriptsDB.removeAsync({ _id: { $in: ids } }, { multi: true })
|
|
||||||
res.success({ data: `批量移除成功,数量: ${ numRemoved }` })
|
|
||||||
}
|
|
||||||
|
|
||||||
const importScript = async ({ res, request }) => {
|
|
||||||
let { impScript } = (await decryptAndExecuteAsync(path.join(__dirname, 'plus.js'))) || {}
|
|
||||||
if (impScript) {
|
|
||||||
await impScript({ res, request })
|
|
||||||
} else {
|
|
||||||
return res.fail({ data: false, msg: 'Plus专属功能!' })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
addScript,
|
addScript,
|
||||||
getScriptList,
|
getScriptList,
|
||||||
getLocalScriptList,
|
getLocalScriptList,
|
||||||
updateScriptList,
|
updateScriptList,
|
||||||
removeScript,
|
removeScript
|
||||||
batchRemoveScript,
|
|
||||||
importScript
|
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
const path = require('path')
|
|
||||||
const { RSADecryptAsync, AESEncryptAsync, AESDecryptAsync } = require('../utils/encrypt')
|
const { RSADecryptAsync, AESEncryptAsync, AESDecryptAsync } = require('../utils/encrypt')
|
||||||
const { HostListDB, CredentialsDB } = require('../utils/db-class')
|
const { HostListDB, CredentialsDB } = require('../utils/db-class')
|
||||||
const decryptAndExecuteAsync = require('../utils/decrypt-file')
|
|
||||||
const hostListDB = new HostListDB().getInstance()
|
const hostListDB = new HostListDB().getInstance()
|
||||||
const credentialsDB = new CredentialsDB().getInstance()
|
const credentialsDB = new CredentialsDB().getInstance()
|
||||||
|
|
||||||
async function getSSHList({ res }) {
|
async function getSSHList({ res }) {
|
||||||
|
// console.log('get-host-list')
|
||||||
let data = await credentialsDB.findAsync({})
|
let data = await credentialsDB.findAsync({})
|
||||||
data = data?.map(item => {
|
data = data?.map(item => {
|
||||||
const { name, authType, _id: id, date } = item
|
const { name, authType, _id: id, date } = item
|
||||||
@ -84,19 +83,10 @@ const getCommand = async ({ res, request }) => {
|
|||||||
let hostInfo = await hostListDB.findAsync({})
|
let hostInfo = await hostListDB.findAsync({})
|
||||||
let record = hostInfo?.find(item => item._id === hostId)
|
let record = hostInfo?.find(item => item._id === hostId)
|
||||||
consola.info('查询登录后执行的指令:', hostId)
|
consola.info('查询登录后执行的指令:', hostId)
|
||||||
if (!record) return res.fail({ data: false, msg: 'host not found' })
|
if (!record) return res.fail({ data: false, msg: 'host not found' }) // host不存在
|
||||||
const { command } = record
|
const { command } = record
|
||||||
if (!command) return res.success({ data: false })
|
if (!command) return res.success({ data: false }) // command不存在
|
||||||
res.success({ data: command })
|
res.success({ data: command }) // 存在
|
||||||
}
|
|
||||||
|
|
||||||
const decryptPrivateKey = async ({ res, request }) => {
|
|
||||||
let { dePrivateKey } = (await decryptAndExecuteAsync(path.join(__dirname, 'plus.js'))) || {}
|
|
||||||
if (dePrivateKey) {
|
|
||||||
await dePrivateKey({ res, request })
|
|
||||||
} else {
|
|
||||||
return res.fail({ data: false, msg: 'Plus专属功能,无法解密私钥!' })
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
@ -104,6 +94,5 @@ module.exports = {
|
|||||||
addSSH,
|
addSSH,
|
||||||
updateSSH,
|
updateSSH,
|
||||||
removeSSH,
|
removeSSH,
|
||||||
getCommand,
|
getCommand
|
||||||
decryptPrivateKey
|
|
||||||
}
|
}
|
||||||
|
@ -2,17 +2,12 @@ const jwt = require('jsonwebtoken')
|
|||||||
const axios = require('axios')
|
const axios = require('axios')
|
||||||
const speakeasy = require('speakeasy')
|
const speakeasy = require('speakeasy')
|
||||||
const QRCode = require('qrcode')
|
const QRCode = require('qrcode')
|
||||||
const version = require('../../package.json').version
|
|
||||||
const getLicenseInfo = require('../utils/get-plus')
|
|
||||||
const { plusServer1, plusServer2 } = require('../utils/plus-server')
|
|
||||||
const { sendNoticeAsync } = require('../utils/notify')
|
const { sendNoticeAsync } = require('../utils/notify')
|
||||||
const { RSADecryptAsync, AESEncryptAsync, SHA1Encrypt } = require('../utils/encrypt')
|
const { RSADecryptAsync, AESEncryptAsync, SHA1Encrypt } = require('../utils/encrypt')
|
||||||
const { getNetIPInfo } = require('../utils/tools')
|
const { getNetIPInfo } = require('../utils/tools')
|
||||||
const { KeyDB, LogDB, PlusDB } = require('../utils/db-class')
|
const { KeyDB, LogDB } = require('../utils/db-class')
|
||||||
|
|
||||||
const keyDB = new KeyDB().getInstance()
|
const keyDB = new KeyDB().getInstance()
|
||||||
const logDB = new LogDB().getInstance()
|
const logDB = new LogDB().getInstance()
|
||||||
const plusDB = new PlusDB().getInstance()
|
|
||||||
|
|
||||||
const getpublicKey = async ({ res }) => {
|
const getpublicKey = async ({ res }) => {
|
||||||
let { publicKey: data } = await keyDB.findOneAsync({})
|
let { publicKey: data } = await keyDB.findOneAsync({})
|
||||||
@ -90,7 +85,7 @@ const beforeLoginHandler = async (clientIp, jwtExpires) => {
|
|||||||
let token = jwt.sign({ date: Date.now() }, commonKey, { expiresIn: jwtExpires }) // 生成token
|
let token = jwt.sign({ date: Date.now() }, commonKey, { expiresIn: jwtExpires }) // 生成token
|
||||||
token = await AESEncryptAsync(token) // 对称加密token后再传输给前端
|
token = await AESEncryptAsync(token) // 对称加密token后再传输给前端
|
||||||
|
|
||||||
// 记录客户端登录IP(用于判断是否异地且只保留最近10<EFBFBD><EFBFBD>)
|
// 记录客户端登录IP(用于判断是否异地且只保留最近10条)
|
||||||
const clientIPInfo = await getNetIPInfo(clientIp)
|
const clientIPInfo = await getNetIPInfo(clientIp)
|
||||||
const { ip, country, city } = clientIPInfo || {}
|
const { ip, country, city } = clientIPInfo || {}
|
||||||
consola.info('登录成功:', new Date(), { ip, country, city })
|
consola.info('登录成功:', new Date(), { ip, country, city })
|
||||||
@ -169,47 +164,6 @@ const disableMFA2 = async ({ res }) => {
|
|||||||
res.success({ msg: 'success' })
|
res.success({ msg: 'success' })
|
||||||
}
|
}
|
||||||
|
|
||||||
const getPlusInfo = async ({ res }) => {
|
|
||||||
let data = await plusDB.findOneAsync({})
|
|
||||||
delete data?._id
|
|
||||||
delete data?.decryptKey
|
|
||||||
res.success({ data, msg: 'success' })
|
|
||||||
}
|
|
||||||
|
|
||||||
const getPlusDiscount = async ({ res } = {}) => {
|
|
||||||
if (process.env.EXEC_ENV === 'local') return res.success({ discount: false })
|
|
||||||
const servers = [plusServer1, plusServer2]
|
|
||||||
for (const server of servers) {
|
|
||||||
try {
|
|
||||||
const url = `${ server }/api/announcement/public?version=${ version }`
|
|
||||||
const response = await fetch(url)
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(`HTTP error! status: ${ response.status }`)
|
|
||||||
}
|
|
||||||
const data = await response.json()
|
|
||||||
return res.success({ data, msg: 'success' })
|
|
||||||
} catch (error) {
|
|
||||||
if (server === servers[servers.length - 1]) {
|
|
||||||
consola.error('All servers failed:', error.message)
|
|
||||||
return res.success({ discount: false })
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const getPlusConf = async ({ res }) => {
|
|
||||||
const { key } = await plusDB.findOneAsync({}) || {}
|
|
||||||
res.success({ data: key || '', msg: 'success' })
|
|
||||||
}
|
|
||||||
|
|
||||||
const updatePlusKey = async ({ res, request }) => {
|
|
||||||
const { body: { key } } = request
|
|
||||||
const { success, msg } = await getLicenseInfo(key)
|
|
||||||
if (!success) return res.fail({ msg })
|
|
||||||
res.success({ msg: 'success' })
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
login,
|
login,
|
||||||
getpublicKey,
|
getpublicKey,
|
||||||
@ -218,9 +172,5 @@ module.exports = {
|
|||||||
getMFA2Status,
|
getMFA2Status,
|
||||||
getMFA2Code,
|
getMFA2Code,
|
||||||
enableMFA2,
|
enableMFA2,
|
||||||
disableMFA2,
|
disableMFA2
|
||||||
getPlusInfo,
|
|
||||||
getPlusDiscount,
|
|
||||||
getPlusConf,
|
|
||||||
updatePlusKey
|
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,8 @@ async function initNotifyDB() {
|
|||||||
|
|
||||||
async function initNotifyConfigDB() {
|
async function initNotifyConfigDB() {
|
||||||
const notifyConfigDB = new NotifyConfigDB().getInstance()
|
const notifyConfigDB = new NotifyConfigDB().getInstance()
|
||||||
let notifyConfig = await notifyConfigDB.findOneAsync({})
|
let count = await notifyConfigDB.countAsync({})
|
||||||
|
if (count !== 0) return
|
||||||
consola.log('初始化NotifyConfigDB✔')
|
consola.log('初始化NotifyConfigDB✔')
|
||||||
const defaultData = {
|
const defaultData = {
|
||||||
type: 'sct',
|
type: 'sct',
|
||||||
@ -82,17 +83,8 @@ async function initNotifyConfigDB() {
|
|||||||
service: 'QQ',
|
service: 'QQ',
|
||||||
user: '',
|
user: '',
|
||||||
pass: ''
|
pass: ''
|
||||||
},
|
|
||||||
tg: {
|
|
||||||
token: '',
|
|
||||||
chatId: ''
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (notifyConfig) {
|
|
||||||
await notifyConfigDB.removeAsync({ _id: notifyConfig._id })
|
|
||||||
delete notifyConfig._id
|
|
||||||
return notifyConfigDB.insertAsync(Object.assign({}, defaultData, notifyConfig))
|
|
||||||
}
|
|
||||||
return notifyConfigDB.insertAsync(defaultData)
|
return notifyConfigDB.insertAsync(defaultData)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
|
const consola = require('consola')
|
||||||
|
global.consola = consola
|
||||||
const { httpServer } = require('./server')
|
const { httpServer } = require('./server')
|
||||||
const initDB = require('./db')
|
const initDB = require('./db')
|
||||||
const scheduleJob = require('./schedule')
|
const scheduleJob = require('./schedule')
|
||||||
const getLicenseInfo = require('./utils/get-plus')
|
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
await initDB()
|
await initDB()
|
||||||
httpServer()
|
httpServer()
|
||||||
scheduleJob()
|
scheduleJob()
|
||||||
getLicenseInfo()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
@ -3,28 +3,27 @@ const { outDir, recordLog } = require('../config').logConfig
|
|||||||
|
|
||||||
log4js.configure({
|
log4js.configure({
|
||||||
appenders: {
|
appenders: {
|
||||||
console: {
|
// 控制台输出
|
||||||
|
out: {
|
||||||
type: 'stdout',
|
type: 'stdout',
|
||||||
layout: {
|
layout: {
|
||||||
type: 'pattern',
|
type: 'colored'
|
||||||
pattern: '%[%d{yyyy-MM-dd hh:mm:ss.SSS} [%p] -%] %m'
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
// 保存日志文件
|
||||||
cheese: {
|
cheese: {
|
||||||
type: 'file',
|
type: 'file',
|
||||||
maxLogSize: 10 * 1024 * 1024, // unit: bytes 1KB = 1024bytes
|
maxLogSize: 512*1024, // unit: bytes 1KB = 1024bytes
|
||||||
filename: `${ outDir }/receive.log`,
|
filename: `${ outDir }/receive.log`
|
||||||
backups: 10,
|
|
||||||
compress: true,
|
|
||||||
keepFileExt: true
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
categories: {
|
categories: {
|
||||||
default: {
|
default: {
|
||||||
appenders: ['console', 'cheese'],
|
appenders: [ 'out', 'cheese' ], // 配置
|
||||||
level: 'debug'
|
level: 'info' // 只输出info以上级别的日志
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// pm2: true
|
||||||
})
|
})
|
||||||
|
|
||||||
const logger = log4js.getLogger()
|
const logger = log4js.getLogger()
|
||||||
@ -56,7 +55,4 @@ const useLog = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = useLog()
|
module.exports = useLog()
|
||||||
|
|
||||||
// 可以先测试一下日志是否正常工作
|
|
||||||
logger.info('日志系统启动')
|
|
@ -1,9 +1,9 @@
|
|||||||
const { getSSHList, addSSH, updateSSH, removeSSH, getCommand, decryptPrivateKey } = require('../controller/ssh')
|
const { getSSHList, addSSH, updateSSH, removeSSH, getCommand } = require('../controller/ssh')
|
||||||
const { getHostList, addHost, updateHost, batchUpdateHost, removeHost, importHost } = require('../controller/host')
|
const { getHostList, addHost, updateHost, removeHost, importHost } = require('../controller/host')
|
||||||
const { login, getpublicKey, updatePwd, getEasynodeVersion, getMFA2Status, getMFA2Code, enableMFA2, disableMFA2, getPlusInfo, getPlusDiscount, getPlusConf, updatePlusKey } = require('../controller/user')
|
const { login, getpublicKey, updatePwd, getEasynodeVersion, getMFA2Status, getMFA2Code, enableMFA2, disableMFA2 } = require('../controller/user')
|
||||||
const { getNotifyConfig, updateNotifyConfig, getNotifyList, updateNotifyList } = require('../controller/notify')
|
const { getNotifyConfig, updateNotifyConfig, getNotifyList, updateNotifyList } = require('../controller/notify')
|
||||||
const { getGroupList, addGroupList, updateGroupList, removeGroup } = require('../controller/group')
|
const { getGroupList, addGroupList, updateGroupList, removeGroup } = require('../controller/group')
|
||||||
const { getScriptList, getLocalScriptList, addScript, updateScriptList, removeScript, batchRemoveScript, importScript } = require('../controller/scripts')
|
const { getScriptList, getLocalScriptList, addScript, updateScriptList, removeScript } = require('../controller/scripts')
|
||||||
const { getOnekeyRecord, removeOnekeyRecord } = require('../controller/onekey')
|
const { getOnekeyRecord, removeOnekeyRecord } = require('../controller/onekey')
|
||||||
const { getLog } = require('../controller/log')
|
const { getLog } = require('../controller/log')
|
||||||
|
|
||||||
@ -32,11 +32,6 @@ const ssh = [
|
|||||||
method: 'get',
|
method: 'get',
|
||||||
path: '/command',
|
path: '/command',
|
||||||
controller: getCommand
|
controller: getCommand
|
||||||
},
|
|
||||||
{
|
|
||||||
method: 'post',
|
|
||||||
path: '/decrypt-private-key',
|
|
||||||
controller: decryptPrivateKey
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
const host = [
|
const host = [
|
||||||
@ -55,11 +50,6 @@ const host = [
|
|||||||
path: '/host-save',
|
path: '/host-save',
|
||||||
controller: updateHost
|
controller: updateHost
|
||||||
},
|
},
|
||||||
{
|
|
||||||
method: 'put',
|
|
||||||
path: '/batch-update-host',
|
|
||||||
controller: batchUpdateHost
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
method: 'post',
|
method: 'post',
|
||||||
path: '/host-remove',
|
path: '/host-remove',
|
||||||
@ -111,26 +101,6 @@ const user = [
|
|||||||
method: 'post',
|
method: 'post',
|
||||||
path: '/mfa2-disable',
|
path: '/mfa2-disable',
|
||||||
controller: disableMFA2
|
controller: disableMFA2
|
||||||
},
|
|
||||||
{
|
|
||||||
method: 'get',
|
|
||||||
path: '/plus-info',
|
|
||||||
controller: getPlusInfo
|
|
||||||
},
|
|
||||||
{
|
|
||||||
method: 'get',
|
|
||||||
path: '/plus-discount',
|
|
||||||
controller: getPlusDiscount
|
|
||||||
},
|
|
||||||
{
|
|
||||||
method: 'get',
|
|
||||||
path: '/plus-conf',
|
|
||||||
controller: getPlusConf
|
|
||||||
},
|
|
||||||
{
|
|
||||||
method: 'post',
|
|
||||||
path: '/plus-conf',
|
|
||||||
controller: updatePlusKey
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
const notify = [
|
const notify = [
|
||||||
@ -200,20 +170,10 @@ const scripts = [
|
|||||||
path: '/script/:id',
|
path: '/script/:id',
|
||||||
controller: removeScript
|
controller: removeScript
|
||||||
},
|
},
|
||||||
{
|
|
||||||
method: 'post',
|
|
||||||
path: '/batch-remove-script',
|
|
||||||
controller: batchRemoveScript
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
method: 'put',
|
method: 'put',
|
||||||
path: '/script/:id',
|
path: '/script/:id',
|
||||||
controller: updateScriptList
|
controller: updateScriptList
|
||||||
},
|
|
||||||
{
|
|
||||||
method: 'post',
|
|
||||||
path: '/import-script',
|
|
||||||
controller: importScript
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
33
server/app/schedule/expired-notify.js
Normal file
33
server/app/schedule/expired-notify.js
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
const schedule = require('node-schedule')
|
||||||
|
const { sendNoticeAsync } = require('../utils/notify')
|
||||||
|
const { formatTimestamp } = require('../utils/tools')
|
||||||
|
const { HostListDB } = require('../utils/db-class')
|
||||||
|
const hostListDB = new HostListDB().getInstance()
|
||||||
|
|
||||||
|
const expiredNotifyJob = async () => {
|
||||||
|
consola.info('=====开始检测服务器到期时间=====', new Date())
|
||||||
|
const hostList = await hostListDB.findAsync({})
|
||||||
|
for (const item of hostList) {
|
||||||
|
if (!item.expiredNotify) continue
|
||||||
|
const { host, name, expired, consoleUrl } = item
|
||||||
|
const restDay = Number(((expired - Date.now()) / (1000 * 60 * 60 * 24)).toFixed(1))
|
||||||
|
console.log(Date.now(), restDay)
|
||||||
|
let title = '服务器到期提醒'
|
||||||
|
let content = `别名: ${ name }\nIP: ${ host }\n到期时间:${ formatTimestamp(expired, 'week') }\n控制台: ${ consoleUrl || '未填写' }`
|
||||||
|
if (0 <= restDay && restDay <= 1) {
|
||||||
|
let temp = '有服务器将在一天后到期,请关注\n'
|
||||||
|
sendNoticeAsync('host_expired', title, temp + content)
|
||||||
|
} else if (3 <= restDay && restDay < 4) {
|
||||||
|
let temp = '有服务器将在三天后到期,请关注\n'
|
||||||
|
sendNoticeAsync('host_expired', title, temp + content)
|
||||||
|
} else if (7 <= restDay && restDay < 8) {
|
||||||
|
let temp = '有服务器将在七天后到期,请关注\n'
|
||||||
|
sendNoticeAsync('host_expired', title, temp + content)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = () => {
|
||||||
|
// 每天中午12点执行一次。
|
||||||
|
schedule.scheduleJob('0 0 12 1/1 * ?', expiredNotifyJob)
|
||||||
|
}
|
@ -1,32 +1,5 @@
|
|||||||
const schedule = require('node-schedule')
|
const expiredNotify = require('./expired-notify')
|
||||||
const { sendNoticeAsync } = require('../utils/notify')
|
|
||||||
const { formatTimestamp } = require('../utils/tools')
|
|
||||||
const { HostListDB } = require('../utils/db-class')
|
|
||||||
const hostListDB = new HostListDB().getInstance()
|
|
||||||
|
|
||||||
const expiredNotifyJob = async () => {
|
|
||||||
consola.info('=====开始检测服务器到期时间=====', new Date())
|
|
||||||
const hostList = await hostListDB.findAsync({})
|
|
||||||
for (const item of hostList) {
|
|
||||||
if (!item.expiredNotify) continue
|
|
||||||
const { host, name, expired, consoleUrl } = item
|
|
||||||
const restDay = Number(((expired - Date.now()) / (1000 * 60 * 60 * 24)).toFixed(1))
|
|
||||||
console.log(Date.now(), restDay)
|
|
||||||
let title = '服务器到期提醒'
|
|
||||||
let content = `别名: ${ name }\nIP: ${ host }\n到期时间:${ formatTimestamp(expired, 'week') }\n控制台: ${ consoleUrl || '未填写' }`
|
|
||||||
if (0 <= restDay && restDay <= 1) {
|
|
||||||
let temp = '有服务器将在一天后到期,请关注\n'
|
|
||||||
sendNoticeAsync('host_expired', title, temp + content)
|
|
||||||
} else if (3 <= restDay && restDay < 4) {
|
|
||||||
let temp = '有服务器将在三天后到期,请关注\n'
|
|
||||||
sendNoticeAsync('host_expired', title, temp + content)
|
|
||||||
} else if (7 <= restDay && restDay < 8) {
|
|
||||||
let temp = '有服务器将在七天后到期,请关注\n'
|
|
||||||
sendNoticeAsync('host_expired', title, temp + content)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = () => {
|
module.exports = () => {
|
||||||
schedule.scheduleJob('0 0 12 1/1 * ?', expiredNotifyJob)
|
expiredNotify()
|
||||||
}
|
}
|
||||||
|
@ -1 +0,0 @@
|
|||||||
U2FsdGVkX1+P63MsIfF2N9/XM16sWy0/pZMWy+0Ptf+FhySv/AiawI4Pcf/HQU7Auxde+GszGb7+t+i1Ckngo6VK9PkwALR87GbqCJtGeMazZTkEGkmNuePdpej0O3oAuwITI1FOKPW4Xe4RIFAkJfghqCgUD0Ps0Y6sPwIxOX7fTi4TopNksRMQ5X+UvezrGnPsF5EC2CAPmKwtRFWVqx5csAFhifvMxwEA+WCA7l9KLLvcybGtY4RZf0uSLb6qGxrJBN/zbQ1MMxVw9JbUML09uQ3VKLvQMJZmjctIpZDr4YEMMMdDD/qDk64feV8Tc5VPENsyl2i9kxZ4Z3s5pUu6oDm+/GE2ag0OMITgg7Wc6QpeqlWJwgAeGuqxz2nnuQfGbhHv4g800Hwc7C6ylYgHHeSY+gx39PyDQy1tE7vtW/83ZQUSgWRXxMYTMHUgYKh6P3XG+HxJz6vRjpZqwjPIc3jd253EQnHVG4YZ7VxjBFwpcmidnkvKMa+dvQSZypOL3XLKlMSGdMWFbtVuw4MMYnTBadWkS3eekdVFtvpG5NRqga0TBxPeoISLsn717u9BYcROHvPzvX/MKG7S9CGClZb4mYbOPxKmENPT6AvQbCrzOlK6X/kHTLOxivc2O5uzL4CRXBKFDeaAUJqs/PLZuCfvdmMBKPiMQpCLtFBYCXoxDarggu2D8EZYcoxFPJ/YE7sy/bFa52hQ0V1wYXkhwez1Q4Q3PH1dqdzOESOI30KEOk9TwkEhdV69ymZ6rb6cXWy1KOph2Vo8dQhgNItgvNCCyEuojR54eXnh8x7R1FHmITrobfRZZOYmpFFRZntirTpkEDvt8sPR7G+STcfKc+OgNVoCSV2Ca79Ex0BVACRxWTrafC+VX80mQGldt3wwTk2P+7mcTl0NqH6F7hfzaDjHLy/pbd/78lJLToMz7K1/PaPfOAlVsD5MTh2hefAmqTDZRKfBHyQQjwgh2hNqpmzP2tcQqO5qeigk3fzvZjyXAX2Zqu85hc6QI0Quc4zRS1hb0uY93mnOLnOksTgCNPZHDCTmzT7N0v4D/oABq2VyFFDIvMlzy1kD1WnpmhPldfm+J268QnGfMoR7ob6quZB660xc3V/9zN16ZeVKAhFfzwVHApubxTOYtIIQWLzGj9Q2eqYCXf2p3n8CYF8YV3L1LT6FxEK//MOBXZZbf7JC7tkSWb0EdRf2wuxlDocrxXzSTuIFlpBuG4Dcjf9wVCn3NuQJhqVAdxSX98K/sJpKYPELyYwTvSwG8v2MApAAgv7v+NfgSswXGCVlYpeildrVM4AafoZjBVb4OJK5YvDgmhyhzKP8copwAwi2/tGK8x/fiT0oTQhR60c7wZBuaj3/D0uDxNCcRct5/DYvb3dU1qMDmPfw0BNE7xhHouVLM12tdSnZxxFWgq5747aOpD+yYfgQBxToXsAbfEZLZLfRXPqcNjJWdnY1ZlqARyrzFKbBlGu/HhdEpldDxhdOFLkjytrA7NzvKJKfWvxbtv+jkVYL6SNdLfRoaUe0ecPJH/Gq12FhRXXudPRQT/xqQ5TXCJZ41gkmd7B9oMuVrmpDhaSKkX1loSj/Mhezzq5vIrZPd3+qK7wMeFrxvY7E4wIlK1gZdyQXBzUh8VPQzY6KFEDV4fekqkxkdKm4oX8Ij3IJfuX52+lIJdhL3t3p/j7mLLc1L9hvRudgWnujLEOi8syJv8EkKARC9OmO0S1okf1R805fenbS6MiM7zoFqza6iNn/9uJwgzCjxoTqpLoPwU2OYQyN3h4LnRoV5qsCo/RUunrdkAAQp85iTMSTWm0ux9R/jy+IHe62zwfrCq9xsdqMZ/0MZPRAyGIh5Cr0JbhXwT5s8meI5MgjJ107+hfSdo0ufSqGnceTfvfNVGUt8KO2PWFwgb7fyAiirnIL53lgKOo8dD4tDVZjfClGdIG7KJFty5M3rzyCyPl5ZeQJRD6YZVZG3HPFt4BDPDecPMK63zvrX9zSK3FV5GyBgZQQVMQbou+gpnGdSGw3NI0agN47hRYjFsbvGPrVjBKiPrfnBKkd2lyqKvd2cns/yYmgGXtehYasnPLU01dvRHicQ+TduvMR4NYMCytiDbiKqwBaYI+yt7cKNSf4cQQT9b3DD8pl9dQhzrnAY0tHxSLCVZzl7LCbYzaITQRLzBoIzCmPrFGLj6j2HuGc+gQ3Hd2/HisVAYxbW6Fu0SXQa9nnGW7k+3AJFRs5EvF++QffNW2rMYaBqr+c1jfwURzc7dGD8PNtDJkx3T6eSKx9l4iWR5/LDW+SXrk2OCzMdznsBNCJJbaKzUqs1HlIEuwQ/hHMjk4M+f4/SmbECE3cQXd+nseEoUnKbn/MiWi2lNyjacXuLTtrjDITK9jIZD0Ixfci5Eer2fuPJw7RXr1rb8bjlZWttpjN45NORLB8usjiiEdklPjQMUmTjXgALATorkWt6vc76zB4Fbk5jOwJ53+W1RqvUxt5S+WIhH55jOxYHqrEppguVMw1w4RIceaL/CYunwHxiD5w58hjJ4bR5fXjwARwM/EDGHgPvfV0dDxhBxbBtKrcemUYlBI40wwbOuDgfdnfcJNVCxaVX0Hto/VuqXvfP3eoQT2Vasz96y2/GbSS0rBGtNn9EzPwGZvBrumbl4ezQJp+HjSN65GLXjDNY+ZajGaOs+pK1O8ooAqODnfAhPd3LkMxQxlkqNy8l4KFUPA1lqd8ohK+4UThmfRCQDKPLTdFV/oTvEdBo0d/oN3xJM9ValH+0e3w86b+cmXnLzUxUzeIhmXWW8ctGtNmzV2fewh8ChPl75MCU5d88uzC03YbfZHOOtokTqkhLYhz4il7KSnA+EFEWB7GOvVqnkM/LAwDcJ/1qvqBah+WnDs9uQXTF+QXn/N1q/+83lu9JQWK0crV2mTJHk8efTHBn6oEN8P9pXf2BCJQzbukA/q50QvQU33p8P2VOqL/bHwsaolIhWrys5lyM4pwpMqxvnP5YIFjEhGhcCHLtqL5jvETh3X78HHiEhjmNzwtj3wa/NrgvzJhepqWWGGBK1DEYoMj21cFPpUeB/+2
|
|
@ -224,18 +224,18 @@ module.exports = (httpServer) => {
|
|||||||
let sftpClient = new SFTPClient()
|
let sftpClient = new SFTPClient()
|
||||||
consola.success('terminal websocket 已连接')
|
consola.success('terminal websocket 已连接')
|
||||||
|
|
||||||
socket.on('create', async ({ hostId, token }) => {
|
socket.on('create', async ({ host: ip, token }) => {
|
||||||
const { code } = await verifyAuthSync(token, requestIP)
|
const { code } = await verifyAuthSync(token, requestIP)
|
||||||
consola.log('code:', code)
|
|
||||||
if (code !== 1) {
|
if (code !== 1) {
|
||||||
socket.emit('token_verify_fail')
|
socket.emit('token_verify_fail')
|
||||||
socket.disconnect()
|
socket.disconnect()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const targetHostInfo = await hostListDB.findOneAsync({ _id: hostId })
|
|
||||||
if (!targetHostInfo) throw new Error(`Host with ID ${ hostId } not found`)
|
const hostList = await hostListDB.findAsync({})
|
||||||
|
const targetHostInfo = hostList.find(item => item.host === ip) || {}
|
||||||
let { authType, host, port, username } = targetHostInfo
|
let { authType, host, port, username } = targetHostInfo
|
||||||
if (!host) return socket.emit('create_fail', `查找id【${ hostId }】凭证信息失败`)
|
if (!host) return socket.emit('create_fail', `查找【${ ip }】凭证信息失败`)
|
||||||
let authInfo = { host, port, username }
|
let authInfo = { host, port, username }
|
||||||
|
|
||||||
// 解密放到try里面,防止报错【commonKey必须配对, 否则需要重新添加服务器密钥】
|
// 解密放到try里面,防止报错【commonKey必须配对, 否则需要重新添加服务器密钥】
|
||||||
|
@ -1,104 +1,108 @@
|
|||||||
const path = require('path')
|
|
||||||
const { Server } = require('socket.io')
|
const { Server } = require('socket.io')
|
||||||
const { Client: SSHClient } = require('ssh2')
|
const { Client: SSHClient } = require('ssh2')
|
||||||
const { verifyAuthSync } = require('../utils/verify-auth')
|
const { verifyAuthSync } = require('../utils/verify-auth')
|
||||||
|
const { AESDecryptAsync } = require('../utils/encrypt')
|
||||||
const { sendNoticeAsync } = require('../utils/notify')
|
const { sendNoticeAsync } = require('../utils/notify')
|
||||||
const { isAllowedIp, ping } = require('../utils/tools')
|
const { isAllowedIp, ping } = require('../utils/tools')
|
||||||
const { AESDecryptAsync } = require('../utils/encrypt')
|
|
||||||
const { HostListDB, CredentialsDB } = require('../utils/db-class')
|
const { HostListDB, CredentialsDB } = require('../utils/db-class')
|
||||||
const decryptAndExecuteAsync = require('../utils/decrypt-file')
|
|
||||||
const hostListDB = new HostListDB().getInstance()
|
const hostListDB = new HostListDB().getInstance()
|
||||||
const credentialsDB = new CredentialsDB().getInstance()
|
const credentialsDB = new CredentialsDB().getInstance()
|
||||||
|
|
||||||
async function getConnectionOptions(hostId) {
|
function createInteractiveShell(socket, sshClient) {
|
||||||
const hostInfo = await hostListDB.findOneAsync({ _id: hostId })
|
|
||||||
if (!hostInfo) throw new Error(`Host with ID ${ hostId } not found`)
|
|
||||||
let { authType, host, port, username, name } = hostInfo
|
|
||||||
let authInfo = { host, port, username }
|
|
||||||
try {
|
|
||||||
if (authType === 'credential') {
|
|
||||||
let credentialId = await AESDecryptAsync(hostInfo[authType])
|
|
||||||
const sshRecord = await credentialsDB.findOneAsync({ _id: credentialId })
|
|
||||||
authInfo.authType = sshRecord.authType
|
|
||||||
authInfo[authInfo.authType] = await AESDecryptAsync(sshRecord[authInfo.authType])
|
|
||||||
} else {
|
|
||||||
authInfo[authType] = await AESDecryptAsync(hostInfo[authType])
|
|
||||||
}
|
|
||||||
return { authInfo, name }
|
|
||||||
} catch (err) {
|
|
||||||
throw new Error(`解密认证信息失败: ${ err.message }`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function createInteractiveShell(socket, targetSSHClient) {
|
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
targetSSHClient.shell({ term: 'xterm-color' }, (err, stream) => {
|
sshClient.shell({ term: 'xterm-color' }, (err, stream) => {
|
||||||
resolve(stream)
|
resolve(stream)
|
||||||
if (err) return socket.emit('output', err.toString())
|
if (err) return socket.emit('output', err.toString())
|
||||||
|
// 终端输出
|
||||||
stream
|
stream
|
||||||
.on('data', (data) => {
|
.on('data', (data) => {
|
||||||
socket.emit('output', data.toString())
|
socket.emit('output', data.toString())
|
||||||
})
|
})
|
||||||
.on('close', () => {
|
.on('close', () => {
|
||||||
consola.info('交互终端已关闭')
|
consola.info('交互终端已关闭')
|
||||||
targetSSHClient.end()
|
sshClient.end()
|
||||||
})
|
})
|
||||||
socket.emit('connect_shell_success') // 已连接终端,web端可以执行指令了
|
socket.emit('connect_shell_success') // 已连接终端,web端可以执行指令了
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createTerminal(hostId, socket, targetSSHClient) {
|
// function execShell(sshClient, command = '', callback) {
|
||||||
|
// if (!command) return
|
||||||
|
// let result = ''
|
||||||
|
// sshClient.exec(`source ~/.bashrc && ${ command }`, (err, stream) => {
|
||||||
|
// if (err) return callback(err.toString())
|
||||||
|
// stream
|
||||||
|
// .on('data', (data) => {
|
||||||
|
// result += data.toString()
|
||||||
|
// })
|
||||||
|
// .stderr
|
||||||
|
// .on('data', (data) => {
|
||||||
|
// result += data.toString()
|
||||||
|
// })
|
||||||
|
// .on('close', () => {
|
||||||
|
// consola.info('一次性指令执行完成:', command)
|
||||||
|
// callback(result)
|
||||||
|
// })
|
||||||
|
// .on('error', (error) => {
|
||||||
|
// console.log('Error:', error.toString())
|
||||||
|
// })
|
||||||
|
// })
|
||||||
|
// }
|
||||||
|
|
||||||
|
async function createTerminal(hostId, socket, sshClient) {
|
||||||
|
// eslint-disable-next-line no-async-promise-executor
|
||||||
return new Promise(async (resolve) => {
|
return new Promise(async (resolve) => {
|
||||||
const targetHostInfo = await hostListDB.findOneAsync({ _id: hostId })
|
const hostList = await hostListDB.findAsync({})
|
||||||
if (!targetHostInfo) return socket.emit('create_fail', `查找hostId【${ hostId }】凭证信息失败`)
|
const targetHostInfo = hostList.find(item => item._id === hostId) || {}
|
||||||
let { connectByJumpHosts = null } = (await decryptAndExecuteAsync(path.join(__dirname, 'plus.js'))) || {}
|
let { authType, host, port, username, name } = targetHostInfo
|
||||||
let { authType, host, port, username, name, jumpHosts } = targetHostInfo
|
if (!host) return socket.emit('create_fail', `查找hostId【${ hostId }】凭证信息失败`)
|
||||||
|
let authInfo = { host, port, username }
|
||||||
|
// 统一使用commonKey解密
|
||||||
try {
|
try {
|
||||||
let { authInfo: targetConnectionOptions } = await getConnectionOptions(hostId)
|
// 解密放到try里面,防止报错【commonKey必须配对, 否则需要重新添加服务器密钥】
|
||||||
let jumpHostResult = connectByJumpHosts && (await connectByJumpHosts(jumpHosts, targetConnectionOptions.host, targetConnectionOptions.port, socket))
|
if (authType === 'credential') {
|
||||||
if (jumpHostResult) {
|
let credentialId = await AESDecryptAsync(targetHostInfo[authType])
|
||||||
targetConnectionOptions.sock = jumpHostResult.sock
|
const sshRecord = await credentialsDB.findOneAsync({ _id: credentialId })
|
||||||
|
authInfo.authType = sshRecord.authType
|
||||||
|
authInfo[authInfo.authType] = await AESDecryptAsync(sshRecord[authInfo.authType])
|
||||||
|
} else {
|
||||||
|
authInfo[authType] = await AESDecryptAsync(targetHostInfo[authType])
|
||||||
}
|
}
|
||||||
|
consola.info('准备连接终端:', host)
|
||||||
socket.emit('terminal_print_info', `准备连接目标终端: ${ name } - ${ host }`)
|
// targetHostInfo[targetHostInfo.authType] = await AESDecryptAsync(targetHostInfo[targetHostInfo.authType])
|
||||||
socket.emit('terminal_print_info', `连接信息: ssh ${ username }@${ host } -p ${ port } -> ${ authType }`)
|
|
||||||
|
|
||||||
consola.info('准备连接目标终端:', host)
|
|
||||||
consola.log('连接信息', { username, port, authType })
|
consola.log('连接信息', { username, port, authType })
|
||||||
let closeNoticeFlag = false // 避免重复发送通知
|
sshClient
|
||||||
targetSSHClient
|
.on('ready', async() => {
|
||||||
.on('ready', async () => {
|
|
||||||
sendNoticeAsync('host_login', '终端登录', `别名: ${ name } \n IP:${ host } \n 端口:${ port } \n 状态: 登录成功`)
|
sendNoticeAsync('host_login', '终端登录', `别名: ${ name } \n IP:${ host } \n 端口:${ port } \n 状态: 登录成功`)
|
||||||
socket.emit('terminal_print_info', `终端连接成功: ${ name } - ${ host }`)
|
|
||||||
consola.success('终端连接成功:', host)
|
consola.success('终端连接成功:', host)
|
||||||
socket.emit('connect_terminal_success', `终端连接成功:${ host }`)
|
socket.emit('connect_terminal_success', `终端连接成功:${ host }`)
|
||||||
let stream = await createInteractiveShell(socket, targetSSHClient)
|
let stream = await createInteractiveShell(socket, sshClient)
|
||||||
resolve(stream)
|
resolve(stream)
|
||||||
|
// execShell(sshClient, 'history', (data) => {
|
||||||
|
// data = data.split('\n').filter(item => item)
|
||||||
|
// console.log(data)
|
||||||
|
// socket.emit('terminal_command_history', data)
|
||||||
|
// })
|
||||||
})
|
})
|
||||||
.on('close', (err) => {
|
.on('close', () => {
|
||||||
if (closeNoticeFlag) return closeNoticeFlag = false
|
consola.info('终端连接断开close: ', host)
|
||||||
const closeReason = err ? '发生错误导致连接断开' : '正常断开连接'
|
socket.emit('connect_close')
|
||||||
consola.info(`终端连接断开(${ closeReason }): ${ host }`)
|
|
||||||
socket.emit('connect_close', { reason: closeReason })
|
|
||||||
})
|
})
|
||||||
.on('error', (err) => {
|
.on('error', (err) => {
|
||||||
closeNoticeFlag = true
|
consola.log(err)
|
||||||
sendNoticeAsync('host_login', '终端登录', `别名: ${ name } \n IP:${ host } \n 端口:${ port } \n 状态: 登录失败`)
|
sendNoticeAsync('host_login', '终端登录', `别名: ${ name } \n IP:${ host } \n 端口:${ port } \n 状态: 登录失败`)
|
||||||
consola.error('连接终端失败:', host, err.message)
|
consola.error('连接终端失败:', host, err.message)
|
||||||
socket.emit('connect_terminal_fail', err.message)
|
socket.emit('connect_fail', err.message)
|
||||||
})
|
|
||||||
.on('keyboard-interactive', function (name, instructions, instructionsLang, prompts, finish) {
|
|
||||||
finish([targetConnectionOptions[authType]])
|
|
||||||
})
|
})
|
||||||
.connect({
|
.connect({
|
||||||
tryKeyboard: true,
|
...authInfo
|
||||||
...targetConnectionOptions
|
// debug: (info) => console.log(info)
|
||||||
// debug: (info) => console.log(info)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
consola.error('创建终端失败: ', host, err.message)
|
consola.error('创建终端失败: ', host, err.message)
|
||||||
socket.emit('create_terminal_fail', err.message)
|
socket.emit('create_fail', err.message)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -107,15 +111,11 @@ module.exports = (httpServer) => {
|
|||||||
const serverIo = new Server(httpServer, {
|
const serverIo = new Server(httpServer, {
|
||||||
path: '/terminal',
|
path: '/terminal',
|
||||||
cors: {
|
cors: {
|
||||||
origin: '*'
|
origin: '*' // 'http://localhost:8080'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
let connectionCount = 0
|
|
||||||
|
|
||||||
serverIo.on('connection', (socket) => {
|
serverIo.on('connection', (socket) => {
|
||||||
connectionCount++
|
// 前者兼容nginx反代, 后者兼容nodejs自身服务
|
||||||
consola.success(`terminal websocket 已连接 - 当前连接数: ${ connectionCount }`)
|
|
||||||
let requestIP = socket.handshake.headers['x-forwarded-for'] || socket.handshake.address
|
let requestIP = socket.handshake.headers['x-forwarded-for'] || socket.handshake.address
|
||||||
if (!isAllowedIp(requestIP)) {
|
if (!isAllowedIp(requestIP)) {
|
||||||
socket.emit('ip_forbidden', 'IP地址不在白名单中')
|
socket.emit('ip_forbidden', 'IP地址不在白名单中')
|
||||||
@ -123,7 +123,7 @@ module.exports = (httpServer) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
consola.success('terminal websocket 已连接')
|
consola.success('terminal websocket 已连接')
|
||||||
let targetSSHClient = null
|
let sshClient = null
|
||||||
socket.on('create', async ({ hostId, token }) => {
|
socket.on('create', async ({ hostId, token }) => {
|
||||||
const { code } = await verifyAuthSync(token, requestIP)
|
const { code } = await verifyAuthSync(token, requestIP)
|
||||||
if (code !== 1) {
|
if (code !== 1) {
|
||||||
@ -131,21 +131,47 @@ module.exports = (httpServer) => {
|
|||||||
socket.disconnect()
|
socket.disconnect()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
targetSSHClient = new SSHClient()
|
sshClient = new SSHClient()
|
||||||
|
|
||||||
|
// 尝试手动断开调试,再次连接后终端输出内容为4份相同的输出,导致异常
|
||||||
|
// setTimeout(() => {
|
||||||
|
// sshClient.end()
|
||||||
|
// }, 3000)
|
||||||
let stream = null
|
let stream = null
|
||||||
|
|
||||||
function listenerInput(key) {
|
function listenerInput(key) {
|
||||||
if (targetSSHClient._sock.writable === false) return consola.info('终端连接已关闭,禁止输入')
|
if (sshClient._sock.writable === false) return consola.info('终端连接已关闭,禁止输入')
|
||||||
stream && stream.write(key)
|
stream && stream.write(key)
|
||||||
}
|
}
|
||||||
function resizeShell({ rows, cols }) {
|
function resizeShell({ rows, cols }) {
|
||||||
|
// consola.info('更改tty终端行&列: ', { rows, cols })
|
||||||
stream && stream.setWindow(rows, cols)
|
stream && stream.setWindow(rows, cols)
|
||||||
}
|
}
|
||||||
socket.on('input', listenerInput)
|
socket.on('input', listenerInput)
|
||||||
socket.on('resize', resizeShell)
|
socket.on('resize', resizeShell)
|
||||||
stream = await createTerminal(hostId, socket, targetSSHClient)
|
|
||||||
|
// 重连
|
||||||
|
socket.on('reconnect_terminal', async () => {
|
||||||
|
consola.info('重连终端: ', hostId)
|
||||||
|
socket.off('input', listenerInput) // 取消监听,重新注册监听,操作新的stream
|
||||||
|
socket.off('resize', resizeShell)
|
||||||
|
sshClient?.end()
|
||||||
|
sshClient?.destroy()
|
||||||
|
sshClient = null
|
||||||
|
stream = null
|
||||||
|
setTimeout(async () => {
|
||||||
|
// 初始化新的SSH客户端对象
|
||||||
|
sshClient = new SSHClient()
|
||||||
|
stream = await createTerminal(hostId, socket, sshClient)
|
||||||
|
socket.emit('reconnect_terminal_success')
|
||||||
|
socket.on('input', listenerInput)
|
||||||
|
socket.on('resize', resizeShell)
|
||||||
|
}, 3000)
|
||||||
|
})
|
||||||
|
stream = await createTerminal(hostId, socket, sshClient)
|
||||||
})
|
})
|
||||||
|
|
||||||
socket.on('get_ping', async (ip) => {
|
socket.on('get_ping',async (ip) => {
|
||||||
try {
|
try {
|
||||||
socket.emit('ping_data', await ping(ip, 2500))
|
socket.emit('ping_data', await ping(ip, 2500))
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -154,10 +180,7 @@ module.exports = (httpServer) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
socket.on('disconnect', (reason) => {
|
socket.on('disconnect', (reason) => {
|
||||||
connectionCount--
|
consola.info('终端socket连接断开:', reason)
|
||||||
consola.info(`终端socket连接断开: ${ reason } - 当前连接数: ${ connectionCount }`)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.getConnectionOptions = getConnectionOptions
|
|
||||||
|
@ -8,8 +8,7 @@ const {
|
|||||||
groupConfDBPath,
|
groupConfDBPath,
|
||||||
scriptsDBPath,
|
scriptsDBPath,
|
||||||
onekeyDBPath,
|
onekeyDBPath,
|
||||||
logDBPath,
|
logDBPath
|
||||||
plusDBPath
|
|
||||||
} = require('../config')
|
} = require('../config')
|
||||||
|
|
||||||
module.exports.KeyDB = class KeyDB {
|
module.exports.KeyDB = class KeyDB {
|
||||||
@ -118,15 +117,4 @@ module.exports.LogDB = class LogDB {
|
|||||||
getInstance() {
|
getInstance() {
|
||||||
return LogDB.instance
|
return LogDB.instance
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
module.exports.PlusDB = class PlusDB {
|
|
||||||
constructor() {
|
|
||||||
if (!PlusDB.instance) {
|
|
||||||
PlusDB.instance = new Datastore({ filename: plusDBPath, autoload: true })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
getInstance() {
|
|
||||||
return PlusDB.instance
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,53 +0,0 @@
|
|||||||
const fs = require('fs-extra')
|
|
||||||
const path = require('path')
|
|
||||||
const CryptoJS = require('crypto-js')
|
|
||||||
const { AESDecryptAsync } = require('./encrypt')
|
|
||||||
const { PlusDB } = require('./db-class')
|
|
||||||
const plusDB = new PlusDB().getInstance()
|
|
||||||
|
|
||||||
function decryptAndExecuteAsync(plusPath) {
|
|
||||||
return new Promise(async (resolve) => {
|
|
||||||
try {
|
|
||||||
let { decryptKey } = await plusDB.findOneAsync({})
|
|
||||||
if (!decryptKey) {
|
|
||||||
throw new Error('缺少解密密钥')
|
|
||||||
}
|
|
||||||
decryptKey = await AESDecryptAsync(decryptKey)
|
|
||||||
const encryptedContent = fs.readFileSync(plusPath, 'utf-8')
|
|
||||||
const bytes = CryptoJS.AES.decrypt(encryptedContent, decryptKey)
|
|
||||||
const decryptedContent = bytes.toString(CryptoJS.enc.Utf8)
|
|
||||||
if (!decryptedContent) {
|
|
||||||
throw new Error('解密失败,请检查密钥是否正确')
|
|
||||||
}
|
|
||||||
const customRequire = (modulePath) => {
|
|
||||||
if (modulePath.startsWith('.')) {
|
|
||||||
const absolutePath = path.resolve(path.dirname(plusPath), modulePath)
|
|
||||||
return require(absolutePath)
|
|
||||||
}
|
|
||||||
return require(modulePath)
|
|
||||||
}
|
|
||||||
const module = {
|
|
||||||
exports: {},
|
|
||||||
require: customRequire,
|
|
||||||
__filename: plusPath,
|
|
||||||
__dirname: path.dirname(plusPath)
|
|
||||||
}
|
|
||||||
const wrapper = Function('module', 'exports', 'require', '__filename', '__dirname',
|
|
||||||
decryptedContent + '\n return module.exports;'
|
|
||||||
)
|
|
||||||
const exports = wrapper(
|
|
||||||
module,
|
|
||||||
module.exports,
|
|
||||||
customRequire,
|
|
||||||
module.__filename,
|
|
||||||
module.__dirname
|
|
||||||
)
|
|
||||||
resolve(exports)
|
|
||||||
} catch (error) {
|
|
||||||
consola.info('解锁plus功能失败: ', error.message)
|
|
||||||
resolve(null)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = decryptAndExecuteAsync
|
|
@ -1,93 +0,0 @@
|
|||||||
const { getLocalNetIP } = require('./tools')
|
|
||||||
const { AESEncryptAsync } = require('./encrypt')
|
|
||||||
const version = require('../../package.json').version
|
|
||||||
const { plusServer1, plusServer2 } = require('./plus-server')
|
|
||||||
const { PlusDB } = require('./db-class')
|
|
||||||
const plusDB = new PlusDB().getInstance()
|
|
||||||
|
|
||||||
async function getLicenseInfo(key = '') {
|
|
||||||
const { key: plusKey } = await plusDB.findOneAsync({}) || {}
|
|
||||||
// console.log('plusKey: ', plusKey)
|
|
||||||
// console.log('key: ', key)
|
|
||||||
// console.log('process.env.PLUS_KEY: ', process.env.PLUS_KEY)
|
|
||||||
key = key || plusKey || process.env.PLUS_KEY
|
|
||||||
if (!key || key.length < 16) return { success: false, msg: 'Invalid Plus Key' }
|
|
||||||
let ip = ''
|
|
||||||
if (global.serverIp && (Date.now() - global.getServerIpLastTime) / 1000 / 60 < 60) {
|
|
||||||
ip = global.serverIp
|
|
||||||
consola.log('get server ip by cache: ', ip)
|
|
||||||
} else {
|
|
||||||
ip = await getLocalNetIP()
|
|
||||||
global.serverIp = ip
|
|
||||||
global.getServerIpLastTime = Date.now()
|
|
||||||
consola.log('get server ip by net: ', ip)
|
|
||||||
}
|
|
||||||
if (!ip) {
|
|
||||||
consola.error('activate plus failed: get public ip failed')
|
|
||||||
global.serverIp = ''
|
|
||||||
return { success: false, msg: 'get public ip failed' }
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
let response
|
|
||||||
let method = 'POST'
|
|
||||||
let body = JSON.stringify({ ip, key, version })
|
|
||||||
let headers = { 'Content-Type': 'application/json' }
|
|
||||||
let timeout = 10000
|
|
||||||
try {
|
|
||||||
response = await fetch(plusServer1 + '/api/licenses/activate', {
|
|
||||||
method,
|
|
||||||
headers,
|
|
||||||
body,
|
|
||||||
timeout
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!response.ok && (response.status !== 403)) {
|
|
||||||
throw new Error('port1 error')
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
consola.log('retry to activate plus by backup server')
|
|
||||||
response = await fetch(plusServer2 + '/api/licenses/activate', {
|
|
||||||
method,
|
|
||||||
headers,
|
|
||||||
body,
|
|
||||||
timeout
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
consola.log('activate plus failed: ', response.status)
|
|
||||||
if (response.status === 403) {
|
|
||||||
const errMsg = await response.json()
|
|
||||||
throw { errMsg, clear: true }
|
|
||||||
}
|
|
||||||
throw Error({ errMsg: `HTTP error! status: ${ response.status }` })
|
|
||||||
}
|
|
||||||
|
|
||||||
const { success, data } = await response.json()
|
|
||||||
if (success) {
|
|
||||||
let { decryptKey, expiryDate, usedIPCount, maxIPs, usedIPs } = data
|
|
||||||
decryptKey = await AESEncryptAsync(decryptKey)
|
|
||||||
consola.success('activate plus success')
|
|
||||||
const plusData = { key, decryptKey, expiryDate, usedIPCount, maxIPs, usedIPs }
|
|
||||||
let count = await plusDB.countAsync({})
|
|
||||||
if (count === 0) {
|
|
||||||
await plusDB.insertAsync(plusData)
|
|
||||||
} else {
|
|
||||||
await plusDB.removeAsync({}, { multi: true })
|
|
||||||
await plusDB.insertAsync(plusData)
|
|
||||||
}
|
|
||||||
return { success: true, msg: '激活成功' }
|
|
||||||
}
|
|
||||||
consola.error('activate plus failed: ', data)
|
|
||||||
return { success: false, msg: '激活失败' }
|
|
||||||
} catch (error) {
|
|
||||||
consola.error(`activate plus failed: ${ error.message || error.errMsg?.message }`)
|
|
||||||
if (error.clear) {
|
|
||||||
await plusDB.removeAsync({}, { multi: true })
|
|
||||||
}
|
|
||||||
return { success: false, msg: error.message || error.errMsg?.message }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = getLicenseInfo
|
|
@ -1,5 +1,3 @@
|
|||||||
const path = require('path')
|
|
||||||
const decryptAndExecuteAsync = require('./decrypt-file')
|
|
||||||
const nodemailer = require('nodemailer')
|
const nodemailer = require('nodemailer')
|
||||||
const axios = require('axios')
|
const axios = require('axios')
|
||||||
const commonTemp = require('../template/commonTemp')
|
const commonTemp = require('../template/commonTemp')
|
||||||
@ -8,6 +6,7 @@ const notifyConfigDB = new NotifyConfigDB().getInstance()
|
|||||||
const notifyDB = new NotifyDB().getInstance()
|
const notifyDB = new NotifyDB().getInstance()
|
||||||
|
|
||||||
function sendServerChan(sendKey, title, content) {
|
function sendServerChan(sendKey, title, content) {
|
||||||
|
if (!sendKey) return consola.error('发送server酱通知失败, sendKey 为空')
|
||||||
return new Promise((async (resolve, reject) => {
|
return new Promise((async (resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
consola.info('server酱通知预发送: ', title)
|
consola.info('server酱通知预发送: ', title)
|
||||||
@ -29,6 +28,7 @@ function sendServerChan(sendKey, title, content) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function sendEmail({ service, user, pass }, title, content) {
|
function sendEmail({ service, user, pass }, title, content) {
|
||||||
|
if (!service || !user || !pass) return consola.info('发送通知失败, 邮箱配置信息不完整: ', { service, user, pass })
|
||||||
return new Promise((async (resolve, reject) => {
|
return new Promise((async (resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
consola.info('邮箱通知预发送: ', title)
|
consola.info('邮箱通知预发送: ', title)
|
||||||
@ -60,8 +60,8 @@ async function sendNoticeAsync(noticeAction, title, content) {
|
|||||||
try {
|
try {
|
||||||
let notifyList = await notifyDB.findAsync({})
|
let notifyList = await notifyDB.findAsync({})
|
||||||
let { sw } = notifyList.find((item) => item.type === noticeAction) // 获取对应动作的通知开关
|
let { sw } = notifyList.find((item) => item.type === noticeAction) // 获取对应动作的通知开关
|
||||||
// console.log('notify swtich: ', noticeAction, sw)
|
console.log('notify swtich: ', noticeAction, sw)
|
||||||
if (!sw) return consola.info('通知开关关闭, 不发送通知: ', noticeAction)
|
if (!sw) return
|
||||||
let notifyConfig = await notifyConfigDB.findOneAsync({})
|
let notifyConfig = await notifyConfigDB.findOneAsync({})
|
||||||
let { type } = notifyConfig
|
let { type } = notifyConfig
|
||||||
if (!type) return consola.error('通知类型不存在: ', type)
|
if (!type) return consola.error('通知类型不存在: ', type)
|
||||||
@ -78,15 +78,7 @@ async function sendNoticeAsync(noticeAction, title, content) {
|
|||||||
if (!service || !user || !pass) return consola.info('未发送邮件通知通知, 未配置邮箱: ', { service, user, pass })
|
if (!service || !user || !pass) return consola.info('未发送邮件通知通知, 未配置邮箱: ', { service, user, pass })
|
||||||
await sendEmail({ service, user, pass }, title, content)
|
await sendEmail({ service, user, pass }, title, content)
|
||||||
break
|
break
|
||||||
case 'tg':
|
|
||||||
let { token, chatId } = notifyConfig['tg']
|
|
||||||
if (!token || !chatId) return consola.info('未发送Telegram通知, 未配置token或chatId: ', { token, chatId })
|
|
||||||
let { sendTg } = await decryptAndExecuteAsync(path.join(__dirname, 'plus.js'))
|
|
||||||
if (!sendTg) return consola.info('未发送Telegram通知, Plus功能解析失败')
|
|
||||||
await sendTg({ token, chatId }, title, content)
|
|
||||||
break
|
|
||||||
default:
|
default:
|
||||||
consola.info('未配置通知类型: ', type)
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -1,4 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
plusServer1: 'https://en1.221022.xyz',
|
|
||||||
plusServer2: 'https://en2.221022.xyz'
|
|
||||||
}
|
|
@ -1 +0,0 @@
|
|||||||
U2FsdGVkX1+Gus2FIC0WsNp0rUXPA+Ui1NQUjtnqP6Ycb1pyHglCADvKu51oxYaGJ0ZdoRZYo7YP3tQgIhp3f96WxP1/QFdypVrVlS7+jbAH6Gzc4CPlD3UeFsCm1j32ArFX60tPSSkq6+DJ3OF6pIVxstGIbCkmv5NQaf0J95zCxgqGm+fo/nZmZ6oj21uspGWZjhHssFRol0KpzINFDSWE9+/hJ43ybT5G6OHvEiaF83YH6h3CXAa6zz2zV18LKvnO8A4nTYR2/EBmGiP6NE3YqQ7hTE7SFmEDtRaxKJfyBxs0bHDCcFifVZh8GE25VyDwvOihUHztgvIRMh9vkgehzx9YN3sZdAsBJqcWyqi1mEPZU/l+zq2tbO+EczCvz6JQ77RZToQxm0vXzJc/ctcCEoVvjDx1pJhsQiTj5tJirFgcYz4VC7ihFYIq2XUQNISZaLynpYUUPdjvIfXGcvk0500SK9VAKb6603Z3fABdsENDGuxl2UKXMed4sL/PFwLy9siEX3BgMg1hFFiwoqqEp/x75341BoeRavEIJBEv8BdTS66mel1lUa/L3so7LyjGpdgfzOZlv+0t6Uhzy82HwYkAWmvuYpK6s6JItsG1ftYrOBzHZbpu36wn0e4N4NLqBnm6Hx1+tQJY7lTmgokgUy+5sVtp4LEsTbgE64HbDLYhME4m/3Yw5ij5D1OhoNwm/9r6MEYyJOyv8j8nDjudLRe1YQ0D2JLQsr04LYpVrjU1+Tsg780K0j0JdnFfVhe/SdkVU8nbkIIfRkv/86N6U2ZQaCYaScZmKYdBQmsK//I2yuYym0tM5q2d5kesYTxy8uAtVIXL1rE065eZFPlg/7Mgu0sqUsspG+EeDJE=
|
|
@ -89,35 +89,6 @@ const getNetIPInfo = async (searchIp = '') => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const getLocalNetIP = async () => {
|
|
||||||
try {
|
|
||||||
let ipUrls = [
|
|
||||||
'http://whois.pconline.com.cn/ipJson.jsp?json=true',
|
|
||||||
'https://www.ip.cn/api/index?ip=&type=0',
|
|
||||||
'https://freeipapi.com/api/json'
|
|
||||||
]
|
|
||||||
let result = await Promise.allSettled(ipUrls.map(url => axios.get(url)))
|
|
||||||
let [pconline, ipCN, freeipapi] = result
|
|
||||||
if (pconline.status === 'fulfilled') {
|
|
||||||
let ip = pconline.value?.data?.ip
|
|
||||||
if (ip) return ip
|
|
||||||
}
|
|
||||||
if (ipCN.status === 'fulfilled') {
|
|
||||||
let ip = ipCN.value?.data?.ip
|
|
||||||
consola.log('ipCN:', ip)
|
|
||||||
if (ip) return ip
|
|
||||||
}
|
|
||||||
if (freeipapi.status === 'fulfilled') {
|
|
||||||
let ip = pconline.value?.data?.ipAddress
|
|
||||||
if (ip) return ip
|
|
||||||
}
|
|
||||||
return null
|
|
||||||
} catch (error) {
|
|
||||||
console.error('getIpInfo Error: ', error?.message || error)
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function isLocalIP(ip) {
|
function isLocalIP(ip) {
|
||||||
// Check if IPv4 or IPv6 address
|
// Check if IPv4 or IPv6 address
|
||||||
const isIPv4 = net.isIPv4(ip)
|
const isIPv4 = net.isIPv4(ip)
|
||||||
@ -188,7 +159,7 @@ const isIP = (ip = '') => {
|
|||||||
return isIPv4.test(ip) || isIPv6.test(ip)
|
return isIPv4.test(ip) || isIPv6.test(ip)
|
||||||
}
|
}
|
||||||
|
|
||||||
const randomStr = (len) => {
|
const randomStr = (len) =>{
|
||||||
len = len || 16
|
len = len || 16
|
||||||
let str = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678',
|
let str = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678',
|
||||||
a = str.length,
|
a = str.length,
|
||||||
@ -207,7 +178,7 @@ const getUTCDate = (num = 8) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const formatTimestamp = (timestamp = Date.now(), format = 'time') => {
|
const formatTimestamp = (timestamp = Date.now(), format = 'time') => {
|
||||||
if (typeof (timestamp) !== 'number') return '--'
|
if (typeof(timestamp) !== 'number') return '--'
|
||||||
let date = new Date(timestamp)
|
let date = new Date(timestamp)
|
||||||
let padZero = (num) => String(num).padStart(2, '0')
|
let padZero = (num) => String(num).padStart(2, '0')
|
||||||
let year = date.getFullYear()
|
let year = date.getFullYear()
|
||||||
@ -216,7 +187,7 @@ const formatTimestamp = (timestamp = Date.now(), format = 'time') => {
|
|||||||
let hours = padZero(date.getHours())
|
let hours = padZero(date.getHours())
|
||||||
let minute = padZero(date.getMinutes())
|
let minute = padZero(date.getMinutes())
|
||||||
let second = padZero(date.getSeconds())
|
let second = padZero(date.getSeconds())
|
||||||
let weekday = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
|
let weekday = ['周日', '周一', '周二', '周三', '周四', '周五', '周六' ]
|
||||||
let week = weekday[date.getDay()]
|
let week = weekday[date.getDay()]
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case 'date':
|
case 'date':
|
||||||
@ -313,7 +284,6 @@ const ping = (ip, timeout = 5000) => {
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getNetIPInfo,
|
getNetIPInfo,
|
||||||
getLocalNetIP,
|
|
||||||
throwError,
|
throwError,
|
||||||
isIP,
|
isIP,
|
||||||
randomStr,
|
randomStr,
|
||||||
|
@ -1,4 +1,2 @@
|
|||||||
const consola = require('consola')
|
|
||||||
global.consola = consola
|
|
||||||
require('dotenv').config()
|
require('dotenv').config()
|
||||||
require('./app/main.js')
|
require('./app/main.js')
|
||||||
|
@ -1,59 +1,58 @@
|
|||||||
{
|
{
|
||||||
"name": "server",
|
"name": "server",
|
||||||
"version": "3.0.3",
|
"version": "1.0.0",
|
||||||
"description": "easynode-server",
|
"description": "easynode-server",
|
||||||
"bin": "./bin/www",
|
"bin": "./bin/www",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"local": "cross-env EXEC_ENV=local nodemon index.js",
|
"local": "cross-env EXEC_ENV=local nodemon index.js",
|
||||||
"prod": "cross-env EXEC_ENV=production nodemon index.js",
|
"prod": "cross-env EXEC_ENV=production nodemon index.js",
|
||||||
"start": "node ./index.js",
|
"start": "node ./index.js",
|
||||||
"lint": "eslint . --ext .js,.vue",
|
"lint": "eslint . --ext .js,.vue",
|
||||||
"lint:fix": "eslint . --ext .js,.jsx,.cjs,.mjs --fix"
|
"lint:fix": "eslint . --ext .js,.jsx,.cjs,.mjs --fix"
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"nodemonConfig": {
|
"nodemonConfig": {
|
||||||
"ignore": [
|
"ignore": [
|
||||||
"*.json"
|
"*.json"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@koa/cors": "^5.0.0",
|
"@koa/cors": "^5.0.0",
|
||||||
"@seald-io/nedb": "^4.0.4",
|
"@seald-io/nedb": "^4.0.4",
|
||||||
"axios": "^1.7.4",
|
"axios": "^1.7.4",
|
||||||
"consola": "^3.2.3",
|
"consola": "^3.2.3",
|
||||||
"cross-env": "^7.0.3",
|
"cross-env": "^7.0.3",
|
||||||
"crypto-js": "^4.2.0",
|
"crypto-js": "^4.2.0",
|
||||||
"dotenv": "^16.4.5",
|
"dotenv": "^16.4.5",
|
||||||
"fs-extra": "^11.2.0",
|
"fs-extra": "^11.2.0",
|
||||||
"global": "^4.4.0",
|
"global": "^4.4.0",
|
||||||
"iconv-lite": "^0.6.3",
|
"iconv-lite": "^0.6.3",
|
||||||
"jsonwebtoken": "^9.0.2",
|
"jsonwebtoken": "^9.0.2",
|
||||||
"koa": "^2.15.3",
|
"koa": "^2.15.3",
|
||||||
"koa-body": "^6.0.1",
|
"koa-body": "^6.0.1",
|
||||||
"koa-compose": "^4.1.0",
|
"koa-compose": "^4.1.0",
|
||||||
"koa-compress": "^5.1.1",
|
"koa-compress": "^5.1.1",
|
||||||
"koa-jwt": "^4.0.4",
|
"koa-jwt": "^4.0.4",
|
||||||
"koa-router": "^12.0.1",
|
"koa-router": "^12.0.1",
|
||||||
"koa-sslify": "^5.0.1",
|
"koa-sslify": "^5.0.1",
|
||||||
"koa-static": "^5.0.0",
|
"koa-static": "^5.0.0",
|
||||||
"koa2-connect-history-api-fallback": "^0.1.3",
|
"koa2-connect-history-api-fallback": "^0.1.3",
|
||||||
"log4js": "^6.9.1",
|
"log4js": "^6.9.1",
|
||||||
"node-os-utils": "^1.3.7",
|
"node-os-utils": "^1.3.7",
|
||||||
"node-rsa": "^1.1.1",
|
"node-rsa": "^1.1.1",
|
||||||
"node-schedule": "^2.1.1",
|
"node-schedule": "^2.1.1",
|
||||||
"node-telegram-bot-api": "^0.66.0",
|
"nodemailer": "^6.9.14",
|
||||||
"nodemailer": "^6.9.14",
|
"qrcode": "^1.5.4",
|
||||||
"qrcode": "^1.5.4",
|
"socket.io": "^4.7.5",
|
||||||
"socket.io": "^4.7.5",
|
"socket.io-client": "^4.7.5",
|
||||||
"socket.io-client": "^4.7.5",
|
"speakeasy": "^2.0.0",
|
||||||
"speakeasy": "^2.0.0",
|
"ssh2": "^1.15.0",
|
||||||
"ssh2": "^1.15.0",
|
"ssh2-sftp-client": "^10.0.3"
|
||||||
"ssh2-sftp-client": "^10.0.3"
|
},
|
||||||
},
|
"devDependencies": {
|
||||||
"devDependencies": {
|
"eslint": "^8.56.0",
|
||||||
"eslint": "^8.56.0",
|
"nodemon": "^3.1.4"
|
||||||
"nodemon": "^3.1.4"
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "web",
|
"name": "web",
|
||||||
"version": "3.0.3",
|
"version": "2.3.0",
|
||||||
"description": "easynode-web",
|
"description": "easynode-web",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -19,18 +19,12 @@ export default {
|
|||||||
removeSSH(id) {
|
removeSSH(id) {
|
||||||
return axios({ url: `/remove-ssh/${ id }`, method: 'delete' })
|
return axios({ url: `/remove-ssh/${ id }`, method: 'delete' })
|
||||||
},
|
},
|
||||||
getPlusInfo() {
|
// existSSH(host) {
|
||||||
return axios({ url: '/plus-info', method: 'get' })
|
// return axios({ url: '/exist-ssh', method: 'post', data: { host } })
|
||||||
},
|
// },
|
||||||
getPlusDiscount() {
|
|
||||||
return axios({ url: '/plus-discount', method: 'get' })
|
|
||||||
},
|
|
||||||
getCommand(hostId) {
|
getCommand(hostId) {
|
||||||
return axios({ url: '/command', method: 'get', params: { hostId } })
|
return axios({ url: '/command', method: 'get', params: { hostId } })
|
||||||
},
|
},
|
||||||
decryptPrivateKey(data) {
|
|
||||||
return axios({ url: '/decrypt-private-key', method: 'post', data })
|
|
||||||
},
|
|
||||||
getHostList() {
|
getHostList() {
|
||||||
return axios({ url: '/host-list', method: 'get' })
|
return axios({ url: '/host-list', method: 'get' })
|
||||||
},
|
},
|
||||||
@ -40,9 +34,6 @@ export default {
|
|||||||
updateHost(data) {
|
updateHost(data) {
|
||||||
return axios({ url: '/host-save', method: 'put', data })
|
return axios({ url: '/host-save', method: 'put', data })
|
||||||
},
|
},
|
||||||
batchUpdateHost(data) {
|
|
||||||
return axios({ url: '/batch-update-host', method: 'put', data })
|
|
||||||
},
|
|
||||||
removeHost(data) {
|
removeHost(data) {
|
||||||
return axios({ url: '/host-remove', method: 'post', data })
|
return axios({ url: '/host-remove', method: 'post', data })
|
||||||
},
|
},
|
||||||
@ -97,11 +88,8 @@ export default {
|
|||||||
deleteGroup(id) {
|
deleteGroup(id) {
|
||||||
return axios({ url: `/group/${ id }`, method: 'delete' })
|
return axios({ url: `/group/${ id }`, method: 'delete' })
|
||||||
},
|
},
|
||||||
getScriptList(params = {}) {
|
getScriptList() {
|
||||||
return axios({ url: '/script', method: 'get', params })
|
return axios({ url: '/script', method: 'get' })
|
||||||
},
|
|
||||||
importScript(data) {
|
|
||||||
return axios({ url: '/import-script', method: 'post', data })
|
|
||||||
},
|
},
|
||||||
getLocalScriptList() {
|
getLocalScriptList() {
|
||||||
return axios({ url: '/local-script', method: 'get' })
|
return axios({ url: '/local-script', method: 'get' })
|
||||||
@ -115,9 +103,6 @@ export default {
|
|||||||
deleteScript(id) {
|
deleteScript(id) {
|
||||||
return axios({ url: `/script/${ id }`, method: 'delete' })
|
return axios({ url: `/script/${ id }`, method: 'delete' })
|
||||||
},
|
},
|
||||||
batchRemoveScript(data) {
|
|
||||||
return axios({ url: '/batch-remove-script', method: 'post', data })
|
|
||||||
},
|
|
||||||
getOnekeyRecord() {
|
getOnekeyRecord() {
|
||||||
return axios({ url: '/onekey', method: 'get' })
|
return axios({ url: '/onekey', method: 'get' })
|
||||||
},
|
},
|
||||||
@ -126,11 +111,5 @@ export default {
|
|||||||
},
|
},
|
||||||
getEasynodeVersion() {
|
getEasynodeVersion() {
|
||||||
return axios({ url: '/version', method: 'get' })
|
return axios({ url: '/version', method: 'get' })
|
||||||
},
|
|
||||||
getPlusConf() {
|
|
||||||
return axios({ url: '/plus-conf', method: 'get' })
|
|
||||||
},
|
|
||||||
updatePlusKey(data) {
|
|
||||||
return axios({ url: '/plus-conf', method: 'post', data })
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,8 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import zhCn from 'element-plus/es/locale/lang/zh-cn'
|
|
||||||
import { ref, getCurrentInstance } from 'vue'
|
import { ref, getCurrentInstance } from 'vue'
|
||||||
|
import zhCn from 'element-plus/es/locale/lang/zh-cn'
|
||||||
const { proxy: { $store } } = getCurrentInstance()
|
const { proxy: { $store } } = getCurrentInstance()
|
||||||
|
|
||||||
const locale = ref(zhCn)
|
const locale = ref(zhCn)
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 4.3 KiB |
Binary file not shown.
Before Width: | Height: | Size: 9.9 KiB |
@ -1,44 +0,0 @@
|
|||||||
<template>
|
|
||||||
<el-tooltip
|
|
||||||
:disabled="isPlusActive"
|
|
||||||
placement="top"
|
|
||||||
>
|
|
||||||
<template #content>
|
|
||||||
<div class="plus_support_tip">
|
|
||||||
此功能需要激活Plus后使用,
|
|
||||||
<el-button
|
|
||||||
size="small"
|
|
||||||
type="primary"
|
|
||||||
link
|
|
||||||
@click="gotoPlusPage"
|
|
||||||
>
|
|
||||||
去激活
|
|
||||||
</el-button>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
<slot />
|
|
||||||
</el-tooltip>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup>
|
|
||||||
import { computed, getCurrentInstance } from 'vue'
|
|
||||||
import { useRouter } from 'vue-router'
|
|
||||||
|
|
||||||
const { proxy: { $store } } = getCurrentInstance()
|
|
||||||
const router = useRouter()
|
|
||||||
|
|
||||||
const isPlusActive = computed(() => $store.isPlusActive)
|
|
||||||
|
|
||||||
const gotoPlusPage = () => {
|
|
||||||
router.push('/setting?tabKey=plus')
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style lang="scss">
|
|
||||||
.plus_support_tip {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
</style>
|
|
||||||
|
|
@ -18,7 +18,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { reactive, markRaw, getCurrentInstance, computed, watchEffect } from 'vue'
|
import { reactive, markRaw, getCurrentInstance, computed, watchEffect, defineEmits } from 'vue'
|
||||||
import { useRoute } from 'vue-router'
|
import { useRoute } from 'vue-router'
|
||||||
import {
|
import {
|
||||||
Menu as IconMenu,
|
Menu as IconMenu,
|
||||||
|
@ -1,206 +0,0 @@
|
|||||||
<template>
|
|
||||||
<div class="comparison-container">
|
|
||||||
<!-- 基础版卡片 -->
|
|
||||||
<el-card class="comparison-card basic-card">
|
|
||||||
<template #header>
|
|
||||||
<div class="card-header">
|
|
||||||
<span class="title">基础功能(免费)</span>
|
|
||||||
<el-tag size="small">Basic</el-tag>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
<div class="feature-list">
|
|
||||||
<div v-for="(feature, index) in basicFeatures" :key="index" class="feature-item">
|
|
||||||
<el-icon>
|
|
||||||
<Check />
|
|
||||||
</el-icon>
|
|
||||||
<span>{{ feature }}</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</el-card>
|
|
||||||
|
|
||||||
<!-- Plus版卡片 -->
|
|
||||||
<el-card class="comparison-card plus-card">
|
|
||||||
<template #header>
|
|
||||||
<div class="card-header">
|
|
||||||
<div>
|
|
||||||
<span class="title">Plus专属功能</span>
|
|
||||||
<span class="link" style="margin-right: 15px;" @click="() => plusTipsShow = true">Plus说明</span>
|
|
||||||
</div>
|
|
||||||
<el-tag type="success" size="small">PLUS</el-tag>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
<div class="feature-list">
|
|
||||||
<div v-for="(feature, index) in plusFeatures" :key="index" class="feature-item plus">
|
|
||||||
<el-icon color="#67c23a">
|
|
||||||
<Check />
|
|
||||||
</el-icon>
|
|
||||||
<span>{{ feature }}</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</el-card>
|
|
||||||
<el-dialog
|
|
||||||
v-model="plusTipsShow"
|
|
||||||
title="Plus说明"
|
|
||||||
top="20vh"
|
|
||||||
width="30%"
|
|
||||||
:append-to-body="false"
|
|
||||||
:close-on-click-modal="false"
|
|
||||||
>
|
|
||||||
<div class="about_content">
|
|
||||||
<p style="line-height: 2;letter-spacing: 1px;">
|
|
||||||
<!-- <strong style="color: #F56C6C;font-weight: 600;">PLUS说明:</strong><br> -->
|
|
||||||
<strong>EasyNode</strong>最初是一个简单的Web终端工具,随着用户群的不断扩大,功能需求也日益增长,为了实现大家的功能需求,我投入了大量的业余时间进行开发和维护。
|
|
||||||
一直在为爱发电,渐渐的也没了开发的动力。
|
|
||||||
<br>
|
|
||||||
为了项目的可持续发展,<strong>后续</strong>版本开始推出<strong>PLUS</strong>版本,后续特性功能开发也会优先在<strong>PLUS</strong>版本中实现,但即使不升级到<strong>PLUS</strong>,也不会影响到<strong>EasyNode</strong>的基础功能使用【注意:
|
|
||||||
暂不支持纯内网用户激活PLUS功能】。
|
|
||||||
<br>
|
|
||||||
<span style="text-decoration: underline;">
|
|
||||||
为了感谢前期赞赏过的用户, 在<strong>PLUS</strong>功能正式发布前,所有进行过赞赏的用户,无论金额大小,均可联系作者TG: <a
|
|
||||||
class="link"
|
|
||||||
href="https://t.me/chaoszhu"
|
|
||||||
target="_blank"
|
|
||||||
>@chaoszhu</a> 凭打赏记录免费获取永久<strong>PLUS</strong>授权码。
|
|
||||||
</span>
|
|
||||||
</p>
|
|
||||||
<div class="about_footer">
|
|
||||||
<el-button type="info" @click="plusTipsShow = false">关闭</el-button>
|
|
||||||
<el-button type="primary" @click="handlePlusSupport">购买Plus Key</el-button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</el-dialog>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup>
|
|
||||||
import { ref } from 'vue'
|
|
||||||
import { Check } from '@element-plus/icons-vue'
|
|
||||||
import { handlePlusSupport } from '@/utils'
|
|
||||||
|
|
||||||
const plusTipsShow = ref(false)
|
|
||||||
|
|
||||||
// 基础版功能列表
|
|
||||||
const basicFeatures = [
|
|
||||||
'服务器管理',
|
|
||||||
'服务器导入导出',
|
|
||||||
'服务器分组',
|
|
||||||
'凭据管理',
|
|
||||||
'脚本库',
|
|
||||||
'批量连接',
|
|
||||||
'批量指令',
|
|
||||||
'通知方式(有限制)',
|
|
||||||
]
|
|
||||||
|
|
||||||
// Plus版专属功能列表
|
|
||||||
const plusFeatures = [
|
|
||||||
'包含基础版全部功能',
|
|
||||||
'服务器跳板机功能,支持任意数量服务器的连续跳板',
|
|
||||||
'批量修改实例配置(优化版)',
|
|
||||||
'脚本库批量导出导入',
|
|
||||||
'凭据管理支持解密带密码保护的密钥',
|
|
||||||
'通知方式无限制',
|
|
||||||
'本地socket断开自动重连',
|
|
||||||
'功能需求更高开发优先级',
|
|
||||||
]
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style scoped lang="scss">
|
|
||||||
.comparison-container {
|
|
||||||
display: flex;
|
|
||||||
gap: 20px;
|
|
||||||
padding-bottom: 20px;
|
|
||||||
max-width: 1200px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.comparison-card {
|
|
||||||
flex: 1;
|
|
||||||
min-width: 300px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.card-header {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: space-between;
|
|
||||||
}
|
|
||||||
|
|
||||||
.title {
|
|
||||||
font-size: 18px;
|
|
||||||
font-weight: bold;
|
|
||||||
margin-right: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.link {
|
|
||||||
text-decoration: underline;
|
|
||||||
}
|
|
||||||
|
|
||||||
.feature-list {
|
|
||||||
// padding: 10px 0;
|
|
||||||
line-height: 1.3;
|
|
||||||
}
|
|
||||||
|
|
||||||
.feature-item {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 8px;
|
|
||||||
padding: 12px 0;
|
|
||||||
/* border-bottom: 1px solid #eee; */
|
|
||||||
border-bottom: 1px solid var(--el-border-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
.feature-item:last-child {
|
|
||||||
border-bottom: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.feature-item .el-icon {
|
|
||||||
color: #409EFF;
|
|
||||||
}
|
|
||||||
|
|
||||||
.plus-card .feature-item.plus {
|
|
||||||
color: #67c23a;
|
|
||||||
}
|
|
||||||
|
|
||||||
.about_content {
|
|
||||||
h1 {
|
|
||||||
font-size: 24px;
|
|
||||||
font-weight: 600;
|
|
||||||
margin: 20px 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
p {
|
|
||||||
line-height: 1.8;
|
|
||||||
margin: 12px 0;
|
|
||||||
font-size: 14px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.link {
|
|
||||||
color: #409EFF;
|
|
||||||
text-decoration: none;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
text-decoration: underline;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.conspicuous {
|
|
||||||
color: #F56C6C;
|
|
||||||
font-weight: 500;
|
|
||||||
}
|
|
||||||
|
|
||||||
.about_footer {
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
margin-top: 20px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 响应式设计 */
|
|
||||||
@media (max-width: 768px) {
|
|
||||||
.comparison-container {
|
|
||||||
flex-direction: column;
|
|
||||||
}
|
|
||||||
|
|
||||||
.comparison-card {
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
|
@ -2,9 +2,7 @@
|
|||||||
<div class="top_bar_container">
|
<div class="top_bar_container">
|
||||||
<div class="bar_wrap">
|
<div class="bar_wrap">
|
||||||
<div class="mobile_menu_btn">
|
<div class="mobile_menu_btn">
|
||||||
<el-icon @click="handleCollapse">
|
<el-icon @click="handleCollapse"><Fold /></el-icon>
|
||||||
<Fold />
|
|
||||||
</el-icon>
|
|
||||||
</div>
|
</div>
|
||||||
<h2>{{ title }}</h2>
|
<h2>{{ title }}</h2>
|
||||||
<el-switch
|
<el-switch
|
||||||
@ -20,15 +18,10 @@
|
|||||||
link
|
link
|
||||||
@click="visible = true"
|
@click="visible = true"
|
||||||
>
|
>
|
||||||
版本更新 <span class="new_version">{{ isNew ? `(新版本可用)` : '' }}</span>
|
关于 <span class="new_version">{{ isNew ? `(新版本可用)` : '' }}</span>
|
||||||
</el-button>
|
</el-button>
|
||||||
<el-dropdown trigger="click">
|
<el-dropdown trigger="click">
|
||||||
<span class="username_wrap">
|
<span class="username"><el-icon><User /></el-icon> {{ user }}</span>
|
||||||
<el-icon>
|
|
||||||
<User />
|
|
||||||
</el-icon>
|
|
||||||
<span class="username">{{ user }}</span>
|
|
||||||
</span>
|
|
||||||
<template #dropdown>
|
<template #dropdown>
|
||||||
<el-dropdown-menu>
|
<el-dropdown-menu>
|
||||||
<el-dropdown-item @click="handleLogout">
|
<el-dropdown-item @click="handleLogout">
|
||||||
@ -37,54 +30,32 @@
|
|||||||
</el-dropdown-menu>
|
</el-dropdown-menu>
|
||||||
</template>
|
</template>
|
||||||
</el-dropdown>
|
</el-dropdown>
|
||||||
<div class="plus_icon_wrapper" @click="gotoPlusPage">
|
|
||||||
<img
|
|
||||||
class="plus_icon"
|
|
||||||
src="@/assets/plus.png"
|
|
||||||
alt="PLUS"
|
|
||||||
:style="{ filter: isPlusActive ? 'grayscale(0%)' : 'grayscale(100%)' }"
|
|
||||||
>
|
|
||||||
<img
|
|
||||||
v-if="!isPlusActive && discount"
|
|
||||||
class="discount_badge"
|
|
||||||
src="@/assets/discount.png"
|
|
||||||
alt="Discount"
|
|
||||||
>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<el-dialog
|
<el-dialog
|
||||||
v-model="visible"
|
v-model="visible"
|
||||||
title="版本更新"
|
title="关于"
|
||||||
top="20vh"
|
top="10vh"
|
||||||
width="30%"
|
width="30%"
|
||||||
:append-to-body="false"
|
:append-to-body="false"
|
||||||
:close-on-click-modal="false"
|
|
||||||
>
|
>
|
||||||
<div class="about_content">
|
<div class="about_content">
|
||||||
<!-- <h1>EasyNode</h1> -->
|
<h1>EasyNode</h1>
|
||||||
<p>当前版本: {{ currentVersion }} <span v-show="!isNew">(最新)</span> </p>
|
<p>当前版本: {{ currentVersion }} <span v-show="!isNew">(最新)</span> </p>
|
||||||
<p v-if="checkVersionErr" class="conspicuous">Error:版本更新检测失败(版本检测API需要外网环境),请手动访问GitHub查看</p>
|
<p v-if="checkVersionErr" class="conspicuous">Error:版本更新检测失败(版本检测API需要外网环境)</p>
|
||||||
<p v-if="isNew" class="conspicuous">
|
<p v-if="isNew" class="conspicuous">
|
||||||
新版本可用: {{ latestVersion }} -> <a
|
新版本可用: {{ latestVersion }} -> <a class="link" href="https://github.com/chaos-zhu/easynode/releases" target="_blank">https://github.com/chaos-zhu/easynode/releases</a>
|
||||||
class="link"
|
|
||||||
href="https://github.com/chaos-zhu/easynode/releases"
|
|
||||||
target="_blank"
|
|
||||||
>https://github.com/chaos-zhu/easynode/releases</a>
|
|
||||||
</p>
|
</p>
|
||||||
|
<p>更新日志:<a class="link" href="https://github.com/chaos-zhu/easynode/blob/main/CHANGELOG.md" target="_blank">https://github.com/chaos-zhu/easynode/blob/main/CHANGELOG.md</a></p>
|
||||||
|
<p>开源仓库: <a class="link" href="https://github.com/chaos-zhu/easynode" target="_blank">https://github.com/chaos-zhu/easynode</a></p>
|
||||||
|
<p>作者: <a class="link" href="https://github.com/chaos-zhu" target="_blank">chaoszhu</a></p>
|
||||||
|
<p>tg更新通知:<a class="link" href="https://t.me/easynode_notify" target="_blank">https://t.me/easynode_notify</a></p>
|
||||||
<p>
|
<p>
|
||||||
功能更新日志:<a
|
打赏: EasyNode开源且无任何收费,如果您认为此项目帮到了您, 您可以请我喝杯阔乐(记得留个备注)~
|
||||||
class="link"
|
|
||||||
href="https://github.com/chaos-zhu/easynode/blob/main/CHANGELOG.md"
|
|
||||||
target="_blank"
|
|
||||||
>https://github.com/chaos-zhu/easynode/blob/main/CHANGELOG.md</a>
|
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p class="qrcode">
|
||||||
TG更新通知频道:<a class="link" href="https://t.me/easynode_notify" target="_blank">https://t.me/easynode_notify</a>
|
<img src="@/assets/wx.jpg" alt="">
|
||||||
</p>
|
</p>
|
||||||
<div class="about_footer">
|
|
||||||
<el-button type="info" @click="visible = false">关闭</el-button>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
|
|
||||||
@ -104,26 +75,22 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, getCurrentInstance, computed, onMounted, onBeforeUnmount } from 'vue'
|
import { ref, getCurrentInstance, computed } from 'vue'
|
||||||
import { useRouter } from 'vue-router'
|
|
||||||
import { User, Sunny, Moon, Fold } from '@element-plus/icons-vue'
|
import { User, Sunny, Moon, Fold } from '@element-plus/icons-vue'
|
||||||
import packageJson from '../../package.json'
|
import packageJson from '../../package.json'
|
||||||
import MenuList from './menuList.vue'
|
import MenuList from './menuList.vue'
|
||||||
|
|
||||||
const { proxy: { $router, $store, $api, $message } } = getCurrentInstance()
|
const { proxy: { $router, $store, $message } } = getCurrentInstance()
|
||||||
const router = useRouter()
|
|
||||||
const visible = ref(false)
|
const visible = ref(false)
|
||||||
const checkVersionErr = ref(false)
|
const checkVersionErr = ref(false)
|
||||||
const currentVersion = ref(`v${ packageJson.version }`)
|
const currentVersion = ref(`v${ packageJson.version }`)
|
||||||
const latestVersion = ref(null)
|
const latestVersion = ref(null)
|
||||||
const menuCollapse = ref(false)
|
const menuCollapse = ref(false)
|
||||||
const discount = ref(false)
|
|
||||||
|
|
||||||
const isNew = computed(() => latestVersion.value && latestVersion.value !== currentVersion.value)
|
const isNew = computed(() => latestVersion.value && latestVersion.value !== currentVersion.value)
|
||||||
const user = computed(() => $store.user)
|
const user = computed(() => $store.user)
|
||||||
const title = computed(() => $store.title)
|
const title = computed(() => $store.title)
|
||||||
const isPlusActive = computed(() => $store.isPlusActive)
|
|
||||||
|
|
||||||
const isDark = computed({
|
const isDark = computed({
|
||||||
get: () => $store.isDark,
|
get: () => $store.isDark,
|
||||||
set: (isDark) => {
|
set: (isDark) => {
|
||||||
@ -141,10 +108,6 @@ const handleLogout = () => {
|
|||||||
$router.push('/login')
|
$router.push('/login')
|
||||||
}
|
}
|
||||||
|
|
||||||
const gotoPlusPage = () => {
|
|
||||||
router.push('/setting?tabKey=plus')
|
|
||||||
}
|
|
||||||
|
|
||||||
async function checkLatestVersion() {
|
async function checkLatestVersion() {
|
||||||
const timeout = 3000
|
const timeout = 3000
|
||||||
try {
|
try {
|
||||||
@ -178,32 +141,6 @@ async function checkLatestVersion() {
|
|||||||
|
|
||||||
checkLatestVersion()
|
checkLatestVersion()
|
||||||
|
|
||||||
let timer = null
|
|
||||||
const checkFirstVisit = () => {
|
|
||||||
timer = setTimeout(() => {
|
|
||||||
const visitedVersion = localStorage.getItem('visitedVersion')
|
|
||||||
if (!visitedVersion || visitedVersion !== currentVersion.value) {
|
|
||||||
visible.value = true
|
|
||||||
localStorage.setItem('visitedVersion', currentVersion.value)
|
|
||||||
}
|
|
||||||
}, 1500)
|
|
||||||
}
|
|
||||||
|
|
||||||
const getPlusDiscount = async () => {
|
|
||||||
const { data } = await $api.getPlusDiscount()
|
|
||||||
if (data?.discount) {
|
|
||||||
discount.value = data.discount
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onMounted(() => {
|
|
||||||
checkFirstVisit()
|
|
||||||
getPlusDiscount()
|
|
||||||
})
|
|
||||||
|
|
||||||
onBeforeUnmount(() => {
|
|
||||||
clearTimeout(timer)
|
|
||||||
})
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
@ -214,228 +151,47 @@ onBeforeUnmount(() => {
|
|||||||
position: sticky;
|
position: sticky;
|
||||||
top: 0;
|
top: 0;
|
||||||
z-index: 999;
|
z-index: 999;
|
||||||
|
|
||||||
.bar_wrap {
|
.bar_wrap {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
padding: 0 20px;
|
padding: 0 20px;
|
||||||
|
|
||||||
h2 {
|
h2 {
|
||||||
font-size: 18px;
|
font-size: 18px;
|
||||||
margin-right: auto;
|
margin-right: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.dark_switch {
|
.dark_switch {
|
||||||
margin-right: 15px;
|
margin-right: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.about_btn {
|
.about_btn {
|
||||||
margin-right: 15px;
|
margin-right: 15px;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
|
|
||||||
.new_version {
|
.new_version {
|
||||||
color: red;
|
color: red;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.username {
|
||||||
.username_wrap {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
|
|
||||||
.username {
|
|
||||||
cursor: pointer;
|
|
||||||
margin-left: 5px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.plus_icon_wrapper {
|
|
||||||
margin-left: 15px;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
|
||||||
.plus_icon {
|
|
||||||
width: 35px;
|
|
||||||
margin-right: 5px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.discount_badge {
|
|
||||||
width: 22px;
|
|
||||||
color: white;
|
|
||||||
font-size: 12px;
|
|
||||||
transform: rotate(25deg);
|
|
||||||
border-radius: 4px;
|
|
||||||
box-shadow: 0 2px 4px rgba(0,0,0,0.2);
|
|
||||||
animation: pulse 2s infinite;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.about_content {
|
.about_content {
|
||||||
h1 {
|
h1 {
|
||||||
font-size: 24px;
|
font-size: 18px;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
margin: 20px 0;
|
margin: 15px 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
p {
|
p {
|
||||||
line-height: 1.8;
|
line-height: 35px;
|
||||||
margin: 12px 0;
|
|
||||||
font-size: 14px;
|
|
||||||
}
|
}
|
||||||
|
.qrcode {
|
||||||
.link {
|
text-align: center;
|
||||||
color: #409EFF;
|
img {
|
||||||
text-decoration: none;
|
width: 250px;
|
||||||
|
|
||||||
&:hover {
|
|
||||||
text-decoration: underline;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.conspicuous {
|
.conspicuous {
|
||||||
color: #F56C6C;
|
color: red;
|
||||||
font-weight: 500;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.about_footer {
|
|
||||||
margin-top: 20px;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@keyframes pulse {
|
|
||||||
0% {
|
|
||||||
transform: rotate(25deg) scale(1);
|
|
||||||
}
|
|
||||||
50% {
|
|
||||||
transform: rotate(25deg) scale(1.1);
|
|
||||||
}
|
|
||||||
100% {
|
|
||||||
transform: rotate(25deg) scale(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<style lang="scss">
|
|
||||||
.plus_content_wrap {
|
|
||||||
.plus_status {
|
|
||||||
margin-bottom: 15px;
|
|
||||||
padding-bottom: 15px;
|
|
||||||
border-bottom: 1px solid #eee;
|
|
||||||
|
|
||||||
.status_header {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
color: #67c23a;
|
|
||||||
margin-bottom: 10px;
|
|
||||||
|
|
||||||
.el-icon {
|
|
||||||
margin-right: 5px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.status_info {
|
|
||||||
.info_item {
|
|
||||||
display: flex;
|
|
||||||
margin: 5px 0;
|
|
||||||
font-size: 13px;
|
|
||||||
|
|
||||||
.label {
|
|
||||||
color: #909399;
|
|
||||||
width: 80px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.holder {
|
|
||||||
color: #EED183;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.ip_list {
|
|
||||||
flex-direction: column;
|
|
||||||
|
|
||||||
.ip_tags {
|
|
||||||
margin-top: 5px;
|
|
||||||
|
|
||||||
.ip_tag {
|
|
||||||
margin: 2px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.plus_benefits {
|
|
||||||
position: relative;
|
|
||||||
|
|
||||||
.support_btn {
|
|
||||||
position: absolute;
|
|
||||||
right: 0;
|
|
||||||
top: 0;
|
|
||||||
padding: 4px 12px;
|
|
||||||
background-color: #409eff;
|
|
||||||
color: white;
|
|
||||||
border-radius: 4px;
|
|
||||||
font-size: 12px;
|
|
||||||
cursor: pointer;
|
|
||||||
transition: all 0.3s;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
background-color: #66b1ff;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.benefits_header {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
font-weight: bold;
|
|
||||||
margin-bottom: 10px;
|
|
||||||
|
|
||||||
.el-icon {
|
|
||||||
color: #e6a23c;
|
|
||||||
margin-right: 5px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.current_benefits {
|
|
||||||
margin-bottom: 15px;
|
|
||||||
|
|
||||||
.benefit_item {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
margin: 8px 0;
|
|
||||||
font-size: 13px;
|
|
||||||
|
|
||||||
.el-icon {
|
|
||||||
margin-right: 5px;
|
|
||||||
color: #409eff;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.coming_soon {
|
|
||||||
.soon_header {
|
|
||||||
font-size: 13px;
|
|
||||||
color: #909399;
|
|
||||||
margin-bottom: 8px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.discount_content {
|
|
||||||
margin: 8px 0;
|
|
||||||
|
|
||||||
.el-tag {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
padding: 6px 12px;
|
|
||||||
|
|
||||||
.el-icon {
|
|
||||||
margin-right: 4px;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ export default {
|
|||||||
},
|
},
|
||||||
// format: time OR date
|
// format: time OR date
|
||||||
formatTimestamp: (timestamp, format = 'time', afterSeparator = ':') => {
|
formatTimestamp: (timestamp, format = 'time', afterSeparator = ':') => {
|
||||||
if (typeof(timestamp) !== 'number') return '--'
|
if(typeof(timestamp) !== 'number') return '--'
|
||||||
let date = new Date(timestamp)
|
let date = new Date(timestamp)
|
||||||
let padZero = (num) => String(num).padStart(2, '0')
|
let padZero = (num) => String(num).padStart(2, '0')
|
||||||
let year = date.getFullYear()
|
let year = date.getFullYear()
|
||||||
|
@ -40,13 +40,10 @@ const useStore = defineStore({
|
|||||||
background: 'linear-gradient(-225deg, #CBBACC 0%, #2580B3 100%)',
|
background: 'linear-gradient(-225deg, #CBBACC 0%, #2580B3 100%)',
|
||||||
quickCopy: isHttps(),
|
quickCopy: isHttps(),
|
||||||
quickPaste: isHttps(),
|
quickPaste: isHttps(),
|
||||||
autoReconnect: true,
|
|
||||||
autoExecuteScript: false
|
autoExecuteScript: false
|
||||||
},
|
},
|
||||||
...(localStorage.getItem('terminalConfig') ? JSON.parse(localStorage.getItem('terminalConfig')) : {})
|
...(localStorage.getItem('terminalConfig') ? JSON.parse(localStorage.getItem('terminalConfig')) : {})
|
||||||
},
|
}
|
||||||
plusInfo: {},
|
|
||||||
isPlusActive: false
|
|
||||||
}),
|
}),
|
||||||
actions: {
|
actions: {
|
||||||
async setJwtToken(token, isSession = true) {
|
async setJwtToken(token, isSession = true) {
|
||||||
@ -71,7 +68,6 @@ const useStore = defineStore({
|
|||||||
await this.getHostList()
|
await this.getHostList()
|
||||||
await this.getSSHList()
|
await this.getSSHList()
|
||||||
await this.getScriptList()
|
await this.getScriptList()
|
||||||
await this.getPlusInfo()
|
|
||||||
this.wsClientsStatus()
|
this.wsClientsStatus()
|
||||||
},
|
},
|
||||||
async getHostList() {
|
async getHostList() {
|
||||||
@ -100,23 +96,6 @@ const useStore = defineStore({
|
|||||||
const { data: localScriptList } = await $api.getLocalScriptList()
|
const { data: localScriptList } = await $api.getLocalScriptList()
|
||||||
this.$patch({ localScriptList })
|
this.$patch({ localScriptList })
|
||||||
},
|
},
|
||||||
async getPlusInfo() {
|
|
||||||
const { data: plusInfo = {} } = await $api.getPlusInfo()
|
|
||||||
if (plusInfo?.expiryDate) {
|
|
||||||
const isPlusActive = new Date(plusInfo.expiryDate) > new Date()
|
|
||||||
this.$patch({ isPlusActive })
|
|
||||||
if (!isPlusActive) {
|
|
||||||
this.setTerminalSetting({ autoReconnect: false })
|
|
||||||
return
|
|
||||||
}
|
|
||||||
plusInfo.expiryDate = dayjs(plusInfo.expiryDate).format('YYYY-MM-DD')
|
|
||||||
plusInfo.expiryDate?.startsWith('9999') && (plusInfo.expiryDate = '永久授权')
|
|
||||||
this.$patch({ plusInfo })
|
|
||||||
} else {
|
|
||||||
this.$patch({ isPlusActive: false })
|
|
||||||
}
|
|
||||||
this.$patch({ plusInfo })
|
|
||||||
},
|
|
||||||
setTerminalSetting(setTarget = {}) {
|
setTerminalSetting(setTarget = {}) {
|
||||||
let newConfig = { ...this.terminalConfig, ...setTarget }
|
let newConfig = { ...this.terminalConfig, ...setTarget }
|
||||||
localStorage.setItem('terminalConfig', JSON.stringify(newConfig))
|
localStorage.setItem('terminalConfig', JSON.stringify(newConfig))
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
// 终端连接状态
|
// 终端连接状态
|
||||||
export const terminalStatus = {
|
export const terminalStatus = {
|
||||||
CONNECTING: 'connecting',
|
CONNECTING: 'connecting',
|
||||||
|
RECONNECTING: 'reconnecting',
|
||||||
CONNECT_FAIL: 'connect_fail',
|
CONNECT_FAIL: 'connect_fail',
|
||||||
CONNECT_SUCCESS: 'connect_success'
|
CONNECT_SUCCESS: 'connect_success'
|
||||||
}
|
}
|
||||||
export const terminalStatusList = [
|
export const terminalStatusList = [
|
||||||
{ value: terminalStatus.CONNECTING, label: '连接中', color: '#FFA500' },
|
{ value: terminalStatus.CONNECTING, label: '连接中', color: '#FFA500' },
|
||||||
|
{ value: terminalStatus.RECONNECTING, label: '重连中', color: '#FFA500' },
|
||||||
{ value: terminalStatus.CONNECT_FAIL, label: '连接失败', color: '#DC3545' },
|
{ value: terminalStatus.CONNECT_FAIL, label: '连接失败', color: '#DC3545' },
|
||||||
{ value: terminalStatus.CONNECT_SUCCESS, label: '已连接', color: '#28A745' },
|
{ value: terminalStatus.CONNECT_SUCCESS, label: '已连接', color: '#28A745' },
|
||||||
]
|
]
|
||||||
|
@ -128,7 +128,7 @@ export const getSuffix = (name = '') => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const exportFile = (data, filename, mimeType = 'application/json') =>{
|
export const exportFile = (data, filename, mimeType = 'application/json') =>{
|
||||||
const blob = new Blob([JSON.stringify(data, null, 2),], { type: mimeType })
|
const blob = new Blob([JSON.stringify(data),], { type: mimeType })
|
||||||
const url = window.URL.createObjectURL(blob)
|
const url = window.URL.createObjectURL(blob)
|
||||||
|
|
||||||
const link = document.createElement('a')
|
const link = document.createElement('a')
|
||||||
@ -149,7 +149,3 @@ export const isMobile = () => {
|
|||||||
let userAgent = navigator.userAgent || navigator.vendor || window.opera
|
let userAgent = navigator.userAgent || navigator.vendor || window.opera
|
||||||
return /android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test(userAgent)
|
return /android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test(userAgent)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const handlePlusSupport = () => {
|
|
||||||
window.open('https://en.221022.xyz/buy-plus', '_blank')
|
|
||||||
}
|
|
||||||
|
@ -84,41 +84,12 @@
|
|||||||
</span>
|
</span>
|
||||||
</template>
|
</template>
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
<el-dialog
|
|
||||||
v-model="keyPasswordVisible"
|
|
||||||
title="输入密钥密码"
|
|
||||||
width="400px"
|
|
||||||
:close-on-click-modal="false"
|
|
||||||
>
|
|
||||||
<el-form @submit.prevent>
|
|
||||||
<el-form-item label="密码">
|
|
||||||
<el-input
|
|
||||||
v-model="keyPassword"
|
|
||||||
type="password"
|
|
||||||
placeholder="请输入密钥密码"
|
|
||||||
show-password
|
|
||||||
autocomplete="off"
|
|
||||||
clearable
|
|
||||||
@keyup.enter="handleDecryptKey"
|
|
||||||
/>
|
|
||||||
</el-form-item>
|
|
||||||
</el-form>
|
|
||||||
<template #footer>
|
|
||||||
<span>
|
|
||||||
<el-button @click="keyPasswordVisible = false">取消</el-button>
|
|
||||||
<PlusSupportTip>
|
|
||||||
<el-button type="primary" :disabled="!isPlusActive" @click="handleDecryptKey">确认</el-button>
|
|
||||||
</PlusSupportTip>
|
|
||||||
</span>
|
|
||||||
</template>
|
|
||||||
</el-dialog>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, reactive, computed, nextTick, getCurrentInstance } from 'vue'
|
import { ref, reactive, computed, nextTick, getCurrentInstance } from 'vue'
|
||||||
import { randomStr, AESEncrypt, RSAEncrypt } from '@utils/index.js'
|
import { randomStr, AESEncrypt, RSAEncrypt } from '@utils/index.js'
|
||||||
import PlusSupportTip from '@/components/common/PlusSupportTip.vue'
|
|
||||||
|
|
||||||
const { proxy: { $api, $message, $messageBox, $store } } = getCurrentInstance()
|
const { proxy: { $api, $message, $messageBox, $store } } = getCurrentInstance()
|
||||||
|
|
||||||
@ -144,7 +115,6 @@ const updateFormRef = ref(null)
|
|||||||
const privateKeyRef = ref(null)
|
const privateKeyRef = ref(null)
|
||||||
|
|
||||||
let sshList = computed(() => $store.sshList)
|
let sshList = computed(() => $store.sshList)
|
||||||
let isPlusActive = computed(() => $store.isPlusActive)
|
|
||||||
|
|
||||||
let addCredentials = () => {
|
let addCredentials = () => {
|
||||||
sshForm.id = null
|
sshForm.id = null
|
||||||
@ -189,9 +159,9 @@ const removeSSH = ({ id, name }) => {
|
|||||||
type: 'warning'
|
type: 'warning'
|
||||||
})
|
})
|
||||||
.then(async () => {
|
.then(async () => {
|
||||||
await $api.removeSSH(id)
|
await $api.removeSSH(id) // 后台会同步删除关联此凭证的credential字段
|
||||||
await $store.getSSHList()
|
await $store.getSSHList()
|
||||||
await $store.getHostList()
|
await $store.getHostList() // 刷新主机字段 isConfig
|
||||||
$message.success('success')
|
$message.success('success')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -200,40 +170,16 @@ const handleClickUploadBtn = () => {
|
|||||||
privateKeyRef.value.click()
|
privateKeyRef.value.click()
|
||||||
}
|
}
|
||||||
|
|
||||||
const keyPasswordVisible = ref(false)
|
|
||||||
const keyPassword = ref('')
|
|
||||||
const tempPrivateKey = ref('')
|
|
||||||
|
|
||||||
const handleSelectPrivateKeyFile = (event) => {
|
const handleSelectPrivateKeyFile = (event) => {
|
||||||
let file = event.target.files[0]
|
let file = event.target.files[0]
|
||||||
let reader = new FileReader()
|
let reader = new FileReader()
|
||||||
reader.onload = async (e) => {
|
reader.onload = (e) => {
|
||||||
const content = e.target.result
|
sshForm.privateKey = e.target.result
|
||||||
// 检查是否是加密的私钥
|
|
||||||
if (content.includes('ENCRYPTED')) {
|
|
||||||
tempPrivateKey.value = content
|
|
||||||
keyPasswordVisible.value = true
|
|
||||||
} else {
|
|
||||||
sshForm.privateKey = content
|
|
||||||
}
|
|
||||||
privateKeyRef.value.value = ''
|
privateKeyRef.value.value = ''
|
||||||
}
|
}
|
||||||
reader.readAsText(file)
|
reader.readAsText(file)
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleDecryptKey = async () => {
|
|
||||||
if (!keyPassword.value) return $message.error('请输入密钥密码')
|
|
||||||
const { data } = await $api.decryptPrivateKey({
|
|
||||||
privateKey: tempPrivateKey.value,
|
|
||||||
password: keyPassword.value
|
|
||||||
})
|
|
||||||
sshForm.privateKey = data
|
|
||||||
keyPasswordVisible.value = false
|
|
||||||
keyPassword.value = ''
|
|
||||||
tempPrivateKey.value = ''
|
|
||||||
$message.success('密钥解密成功')
|
|
||||||
}
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
@ -46,7 +46,7 @@
|
|||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item prop="mfa2Token" label="MFA2验证码">
|
<el-form-item prop="mfa2Token" label="MFA2验证码">
|
||||||
<el-input
|
<el-input
|
||||||
v-model="loginForm.mfa2Token"
|
v-model.trim.number="loginForm.mfa2Token"
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="MFA2应用上的6位数字(未设置可忽略)"
|
placeholder="MFA2应用上的6位数字(未设置可忽略)"
|
||||||
autocomplete="off"
|
autocomplete="off"
|
||||||
@ -90,7 +90,7 @@ const expireEnum = reactive({
|
|||||||
CURRENT_DAY: 'current_day',
|
CURRENT_DAY: 'current_day',
|
||||||
THREE_DAY: 'three_day'
|
THREE_DAY: 'three_day'
|
||||||
})
|
})
|
||||||
const expireTime = ref(expireEnum.CURRENT_DAY)
|
const expireTime = ref(expireEnum.ONE_SESSION)
|
||||||
const loginFormRefs = ref(null)
|
const loginFormRefs = ref(null)
|
||||||
const notKey = ref(false)
|
const notKey = ref(false)
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
@ -103,7 +103,7 @@ const loginForm = reactive({
|
|||||||
const rules = reactive({
|
const rules = reactive({
|
||||||
loginName: { required: true, message: '需输入用户名', trigger: 'change' },
|
loginName: { required: true, message: '需输入用户名', trigger: 'change' },
|
||||||
pwd: { required: true, message: '需输入密码', trigger: 'change' },
|
pwd: { required: true, message: '需输入密码', trigger: 'change' },
|
||||||
mfa2Token: { required: false, message: '需输入MFA2验证码', trigger: 'change' }
|
mfa2Token: { required: false, message: '需输入密码', trigger: 'change' }
|
||||||
})
|
})
|
||||||
|
|
||||||
const handleLogin = () => {
|
const handleLogin = () => {
|
||||||
@ -124,7 +124,7 @@ const handleLogin = () => {
|
|||||||
if (ciphertext === -1) return $message.error({ message: '公钥加载失败', center: true })
|
if (ciphertext === -1) return $message.error({ message: '公钥加载失败', center: true })
|
||||||
loading.value = true
|
loading.value = true
|
||||||
try {
|
try {
|
||||||
let { data, msg } = await $api.login({ loginName, ciphertext, jwtExpires, mfa2Token: Number(mfa2Token) })
|
let { data, msg } = await $api.login({ loginName, ciphertext, jwtExpires, mfa2Token })
|
||||||
const { token } = data
|
const { token } = data
|
||||||
$store.setJwtToken(token, expireEnum.ONE_SESSION === expireTime.value)
|
$store.setJwtToken(token, expireEnum.ONE_SESSION === expireTime.value)
|
||||||
$store.setUser(loginName)
|
$store.setUser(loginName)
|
||||||
|
@ -426,7 +426,7 @@ onActivated(async () => {
|
|||||||
const { hostIds, execClientInstallScript } = route.query
|
const { hostIds, execClientInstallScript } = route.query
|
||||||
if (!hostIds) return
|
if (!hostIds) return
|
||||||
if (execClientInstallScript === 'true') {
|
if (execClientInstallScript === 'true') {
|
||||||
let clientInstallScript = 'curl -o- https://git.221022.xyz/https://raw.githubusercontent.com/chaos-zhu/easynode/main/client/easynode-client-install.sh | bash\n'
|
let clientInstallScript = 'curl -o- https://ghp.ci/https://raw.githubusercontent.com/chaos-zhu/easynode/main/client/easynode-client-install.sh | bash\n'
|
||||||
console.log(hostIds.split(','))
|
console.log(hostIds.split(','))
|
||||||
createExecShell(hostIds.split(','), clientInstallScript, 300)
|
createExecShell(hostIds.split(','), clientInstallScript, 300)
|
||||||
// $messageBox.confirm(`准备安装客户端服务监控应用:${ host }`, 'Warning', {
|
// $messageBox.confirm(`准备安装客户端服务监控应用:${ host }`, 'Warning', {
|
||||||
@ -435,7 +435,7 @@ onActivated(async () => {
|
|||||||
// type: 'warning'
|
// type: 'warning'
|
||||||
// })
|
// })
|
||||||
// .then(async () => {
|
// .then(async () => {
|
||||||
// let clientInstallScript = 'curl -o- https://git.221022.xyz/https://raw.githubusercontent.com/chaos-zhu/easynode/main/client/easynode-client-install.sh | bash\n'
|
// let clientInstallScript = 'curl -o- https://ghp.ci/https://raw.githubusercontent.com/chaos-zhu/easynode/main/client/easynode-client-install.sh | bash\n'
|
||||||
// createExecShell([host,], clientInstallScript, 300)
|
// createExecShell([host,], clientInstallScript, 300)
|
||||||
// })
|
// })
|
||||||
}
|
}
|
||||||
|
@ -1,226 +0,0 @@
|
|||||||
<template>
|
|
||||||
<el-dialog
|
|
||||||
v-model="visible"
|
|
||||||
width="600px"
|
|
||||||
top="225px"
|
|
||||||
modal-class="import_form_dialog"
|
|
||||||
append-to-body
|
|
||||||
title="导入脚本配置"
|
|
||||||
:close-on-click-modal="false"
|
|
||||||
>
|
|
||||||
<h2>选择要导入的文件类型</h2>
|
|
||||||
<ul class="type_list">
|
|
||||||
<li @click="handleFromJson">
|
|
||||||
<svg-icon name="icon-json" class="icon" />
|
|
||||||
<span class="from">JSON</span>
|
|
||||||
<input
|
|
||||||
ref="jsonInputRef"
|
|
||||||
type="file"
|
|
||||||
accept=".json"
|
|
||||||
multiple
|
|
||||||
name="jsonInput"
|
|
||||||
style="display: none;"
|
|
||||||
@change="handleJsonFile"
|
|
||||||
>
|
|
||||||
</li>
|
|
||||||
<li @click="manualInputVisible = true">
|
|
||||||
<svg-icon name="icon-bianji1" class="icon" />
|
|
||||||
<span class="from">手动输入</span>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</el-dialog>
|
|
||||||
|
|
||||||
<el-dialog
|
|
||||||
v-model="manualInputVisible"
|
|
||||||
width="600px"
|
|
||||||
top="150px"
|
|
||||||
title="手动输入"
|
|
||||||
:close-on-click-modal="false"
|
|
||||||
append-to-body
|
|
||||||
>
|
|
||||||
<el-input
|
|
||||||
v-model="manualInput"
|
|
||||||
type="textarea"
|
|
||||||
:autosize="{ minRows: 15 }"
|
|
||||||
placeholder="请输入脚本内容,每行一条脚本"
|
|
||||||
/>
|
|
||||||
<template #footer>
|
|
||||||
<div class="manual-input-footer">
|
|
||||||
<el-button @click="manualInputVisible = false">取消</el-button>
|
|
||||||
<el-button type="primary" @click="handleManualImport">导入</el-button>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
</el-dialog>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup>
|
|
||||||
import { ref, computed, getCurrentInstance } from 'vue'
|
|
||||||
|
|
||||||
const { proxy: { $api, $message, $store } } = getCurrentInstance()
|
|
||||||
|
|
||||||
const props = defineProps({
|
|
||||||
show: {
|
|
||||||
required: true,
|
|
||||||
type: Boolean
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
const emit = defineEmits(['update:show', 'update-list',])
|
|
||||||
|
|
||||||
const jsonInputRef = ref(null)
|
|
||||||
const manualInputVisible = ref(false)
|
|
||||||
const manualInput = ref('')
|
|
||||||
|
|
||||||
let visible = computed({
|
|
||||||
get: () => props.show,
|
|
||||||
set: (newVal) => emit('update:show', newVal)
|
|
||||||
})
|
|
||||||
|
|
||||||
let scriptList = computed(() => $store.scriptList)
|
|
||||||
|
|
||||||
function handleFromJson() {
|
|
||||||
jsonInputRef.value.click()
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleJsonFile = (event) => {
|
|
||||||
let files = event.target.files
|
|
||||||
let jsonFiles = Array.from(files).filter(file => file.name.endsWith('.json'))
|
|
||||||
if (jsonFiles.length === 0) return $message.warning('未选择有效的JSON文件')
|
|
||||||
|
|
||||||
let readerPromises = jsonFiles.map(file => {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
let reader = new FileReader()
|
|
||||||
reader.onload = (e) => {
|
|
||||||
try {
|
|
||||||
let jsonContent = JSON.parse(e.target.result)
|
|
||||||
resolve(jsonContent)
|
|
||||||
} catch (error) {
|
|
||||||
reject(new Error(`Failed to parse JSON file: ${ file.name }`))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
reader.onerror = () => {
|
|
||||||
reject(new Error(`Failed to read file: ${ file.name }`))
|
|
||||||
}
|
|
||||||
reader.readAsText(file)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
Promise.all(readerPromises)
|
|
||||||
.then(async jsonContents => {
|
|
||||||
let formatJson = jsonContents.flat(Infinity)
|
|
||||||
let existCommand = scriptList.value.map(item => item.command)
|
|
||||||
let existId = scriptList.value.map(item => item.id)
|
|
||||||
formatJson = formatJson.filter(({ _id, command }) => {
|
|
||||||
return !existCommand.includes(command) && !existId.includes(_id)
|
|
||||||
})
|
|
||||||
if (formatJson.length === 0) return $message.warning('导入的脚本已存在')
|
|
||||||
try {
|
|
||||||
let { data: { len } } = await $api.importScript({ scripts: formatJson })
|
|
||||||
$message({ type: 'success', center: true, message: `成功导入脚本: ${ len }条` })
|
|
||||||
emit('update-list')
|
|
||||||
visible.value = false
|
|
||||||
} catch (error) {
|
|
||||||
$message.error('导入失败: ' + error.message)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
$message.error('导入失败: ' + error.message)
|
|
||||||
console.error('导入失败: ', error)
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
event.target.value = null
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleManualImport = async () => {
|
|
||||||
if (!manualInput.value.trim()) {
|
|
||||||
return $message.warning('请输入脚本内容')
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
let scripts = manualInput.value.split('\n')
|
|
||||||
scripts = [...new Set(scripts),]
|
|
||||||
.filter(line => line.trim())
|
|
||||||
.map((command) => ({ command: command.trim() }))
|
|
||||||
if (scripts.length === 0) {
|
|
||||||
return $message.warning('未检测到有效的脚本内容')
|
|
||||||
}
|
|
||||||
|
|
||||||
let existCommand = scriptList.value.map(item => item.command)
|
|
||||||
let filterScripts = scripts.filter(({ command }) => {
|
|
||||||
return !existCommand.includes(command)
|
|
||||||
})
|
|
||||||
let filterScriptsLen = filterScripts.length
|
|
||||||
if (filterScriptsLen !== 0 && filterScriptsLen < scripts.length) $message.warning('已过滤重复的脚本')
|
|
||||||
if (filterScriptsLen === 0) return $message.warning('导入的脚本已存在')
|
|
||||||
filterScripts = filterScripts.map((item, index) => {
|
|
||||||
return {
|
|
||||||
...item,
|
|
||||||
name: `${ item.command.slice(0, 15) || `脚本${ index + 1 }` }`,
|
|
||||||
index: scriptList.value.length + index + 1,
|
|
||||||
description: '手动输入'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
let { data: { len } } = await $api.importScript({ scripts: filterScripts })
|
|
||||||
$message({ type: 'success', center: true, message: `成功导入脚本: ${ len }条` })
|
|
||||||
emit('update-list')
|
|
||||||
manualInputVisible.value = false
|
|
||||||
visible.value = false
|
|
||||||
manualInput.value = ''
|
|
||||||
} catch (error) {
|
|
||||||
$message.error('导入失败: ' + error.message)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style lang="scss">
|
|
||||||
.import_form_dialog {
|
|
||||||
h2 {
|
|
||||||
font-size: 14px;
|
|
||||||
font-weight: 600;
|
|
||||||
text-align: center;
|
|
||||||
margin: 15px 0 25px 0;
|
|
||||||
}
|
|
||||||
.type_list {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
user-select: none;
|
|
||||||
li {
|
|
||||||
margin: 0 25px;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
width: 150px;
|
|
||||||
height: 150px;
|
|
||||||
cursor: pointer;
|
|
||||||
border-radius: 3px;
|
|
||||||
&:hover {
|
|
||||||
color: var(--el-menu-active-color);
|
|
||||||
}
|
|
||||||
.icon {
|
|
||||||
width: 35px;
|
|
||||||
height: 35px;
|
|
||||||
}
|
|
||||||
span {
|
|
||||||
display: inline-block;
|
|
||||||
}
|
|
||||||
.from {
|
|
||||||
font-size: 14px;
|
|
||||||
margin: 15px 0;
|
|
||||||
}
|
|
||||||
.type {
|
|
||||||
font-size: 12px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.manual-input-footer {
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
gap: 20px;
|
|
||||||
}
|
|
||||||
</style>
|
|
@ -1,52 +1,9 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="scripts_container">
|
<div class="scripts_container">
|
||||||
<div class="header">
|
<div class="header">
|
||||||
<el-input
|
<el-button type="primary" @click="addScript">添加脚本</el-button>
|
||||||
v-model="searchKeyword"
|
|
||||||
placeholder="搜索名称、描述或指令内容"
|
|
||||||
class="search_input"
|
|
||||||
clearable
|
|
||||||
@input="handleSearch"
|
|
||||||
>
|
|
||||||
<template #prefix>
|
|
||||||
<el-icon><Search /></el-icon>
|
|
||||||
</template>
|
|
||||||
</el-input>
|
|
||||||
<el-button
|
|
||||||
v-show="selectScripts.length"
|
|
||||||
type="danger"
|
|
||||||
class="batch_remove_btn"
|
|
||||||
@click="handleBatchRemove"
|
|
||||||
>
|
|
||||||
批量删除
|
|
||||||
</el-button>
|
|
||||||
<el-button type="primary" class="add_script_btn" @click="addScript">添加脚本</el-button>
|
|
||||||
<PlusSupportTip>
|
|
||||||
<el-dropdown trigger="click" :disabled="!isPlusActive">
|
|
||||||
<el-button type="primary" class="group_action_btn" :disabled="!isPlusActive">
|
|
||||||
导入导出<el-icon class="el-icon--right"><arrow-down /></el-icon>
|
|
||||||
</el-button>
|
|
||||||
<template #dropdown>
|
|
||||||
<el-dropdown-menu>
|
|
||||||
<el-dropdown-item @click="importVisible = true">导入脚本</el-dropdown-item>
|
|
||||||
<el-dropdown-item @click="handleExport">导出脚本</el-dropdown-item>
|
|
||||||
</el-dropdown-menu>
|
|
||||||
</template>
|
|
||||||
</el-dropdown>
|
|
||||||
</PlusSupportTip>
|
|
||||||
</div>
|
</div>
|
||||||
<el-table
|
<el-table v-loading="loading" :data="scriptList">
|
||||||
v-loading="loading"
|
|
||||||
:data="paginatedFilteredList"
|
|
||||||
@selection-change="handleSelectionChange"
|
|
||||||
>
|
|
||||||
<el-table-column
|
|
||||||
type="selection"
|
|
||||||
width="55"
|
|
||||||
:selectable="(row) => {
|
|
||||||
return row.index !== '--' && row.index !== '-' && row.index !== undefined && row.index !== null
|
|
||||||
}"
|
|
||||||
/>
|
|
||||||
<el-table-column prop="index" label="序号" width="100px" />
|
<el-table-column prop="index" label="序号" width="100px" />
|
||||||
<el-table-column prop="name" label="名称" />
|
<el-table-column prop="name" label="名称" />
|
||||||
<el-table-column prop="description" label="描述" />
|
<el-table-column prop="description" label="描述" />
|
||||||
@ -61,19 +18,6 @@
|
|||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
</el-table>
|
</el-table>
|
||||||
|
|
||||||
<div class="pagination-container">
|
|
||||||
<el-pagination
|
|
||||||
v-model:current-page="currentPage"
|
|
||||||
v-model:page-size="pageSize"
|
|
||||||
:page-sizes="[20, 50, 100]"
|
|
||||||
:total="scriptList.length"
|
|
||||||
layout="total, sizes, prev, pager, next"
|
|
||||||
@size-change="handleSizeChange"
|
|
||||||
@current-change="handleCurrentChange"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<el-dialog
|
<el-dialog
|
||||||
v-model="formVisible"
|
v-model="formVisible"
|
||||||
width="600px"
|
width="600px"
|
||||||
@ -134,44 +78,17 @@
|
|||||||
</span>
|
</span>
|
||||||
</template>
|
</template>
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
|
|
||||||
<ImportScript
|
|
||||||
v-model:show="importVisible"
|
|
||||||
@update-list="() => $store.getScriptList()"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, reactive, computed, nextTick, getCurrentInstance, h } from 'vue'
|
import { ref, reactive, computed, nextTick, getCurrentInstance } from 'vue'
|
||||||
import ImportScript from './components/import-script.vue'
|
|
||||||
import PlusSupportTip from '@/components/common/PlusSupportTip.vue'
|
|
||||||
import { ArrowDown, Search } from '@element-plus/icons-vue'
|
|
||||||
import { exportFile } from '@/utils'
|
|
||||||
|
|
||||||
const { proxy: { $api, $message, $messageBox, $store, $tools } } = getCurrentInstance()
|
const { proxy: { $api, $message, $messageBox, $store } } = getCurrentInstance()
|
||||||
|
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const formVisible = ref(false)
|
const formVisible = ref(false)
|
||||||
let isModify = ref(false)
|
let isModify = ref(false)
|
||||||
const selectScripts = ref([])
|
|
||||||
const handleSelectionChange = (val) => {
|
|
||||||
selectScripts.value = val
|
|
||||||
}
|
|
||||||
const handleBatchRemove = () => {
|
|
||||||
if (!selectScripts.value.length) return $message.warning('请选择要批量删除的脚本')
|
|
||||||
let ids = selectScripts.value.map(item => item.id)
|
|
||||||
let names = selectScripts.value.map(item => item.name)
|
|
||||||
$messageBox.confirm(() => h('p', { style: 'line-height: 18px;' }, `确认删除\n${ names.join(', ') }吗?`), 'Warning', {
|
|
||||||
confirmButtonText: '确定',
|
|
||||||
cancelButtonText: '取消',
|
|
||||||
type: 'warning'
|
|
||||||
}).then(async () => {
|
|
||||||
await $api.batchRemoveScript({ ids })
|
|
||||||
await $store.getScriptList()
|
|
||||||
$message.success('success')
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
let formData = reactive({
|
let formData = reactive({
|
||||||
name: '',
|
name: '',
|
||||||
@ -191,12 +108,10 @@ const rules = computed(() => {
|
|||||||
|
|
||||||
const updateFormRef = ref(null)
|
const updateFormRef = ref(null)
|
||||||
|
|
||||||
const scriptList = computed(() => $store.scriptList)
|
let scriptList = computed(() => $store.scriptList)
|
||||||
const isPlusActive = computed(() => $store.isPlusActive)
|
|
||||||
|
|
||||||
let addScript = () => {
|
let addScript = () => {
|
||||||
formData.id = null
|
formData.id = null
|
||||||
formData.index = scriptList.value.reduce((acc, cur) => Math.max(acc, Number(cur.index) || 0), 0) + 1
|
|
||||||
isModify.value = false
|
isModify.value = false
|
||||||
formVisible.value = true
|
formVisible.value = true
|
||||||
}
|
}
|
||||||
@ -239,49 +154,6 @@ const handleRemove = ({ id, name }) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const importVisible = ref(false)
|
|
||||||
|
|
||||||
const handleExport = () => {
|
|
||||||
if (!scriptList.value.length) return $message.warning('暂无可导出的脚本')
|
|
||||||
const fileName = `easynode-scripts-${ $tools.formatTimestamp(Date.now(), 'time', '.') }.json`
|
|
||||||
exportFile(scriptList.value, fileName, 'application/json')
|
|
||||||
}
|
|
||||||
|
|
||||||
const currentPage = ref(1)
|
|
||||||
const pageSize = ref(20)
|
|
||||||
|
|
||||||
const searchKeyword = ref('')
|
|
||||||
|
|
||||||
const filteredScriptList = computed(() => {
|
|
||||||
if (!searchKeyword.value) return scriptList.value
|
|
||||||
|
|
||||||
const keyword = searchKeyword.value.toLowerCase()
|
|
||||||
return scriptList.value.filter(item =>
|
|
||||||
(item.name && item.name.toLowerCase().includes(keyword)) ||
|
|
||||||
(item.description && item.description.toLowerCase().includes(keyword)) ||
|
|
||||||
(item.command && item.command.toLowerCase().includes(keyword))
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
const paginatedFilteredList = computed(() => {
|
|
||||||
const start = (currentPage.value - 1) * pageSize.value
|
|
||||||
const end = start + pageSize.value
|
|
||||||
return filteredScriptList.value.slice(start, end)
|
|
||||||
})
|
|
||||||
|
|
||||||
const handleSizeChange = (val) => {
|
|
||||||
pageSize.value = val
|
|
||||||
currentPage.value = 1
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleCurrentChange = (val) => {
|
|
||||||
currentPage.value = val
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleSearch = () => {
|
|
||||||
currentPage.value = 1
|
|
||||||
}
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
@ -292,13 +164,6 @@ const handleSearch = () => {
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: end;
|
justify-content: end;
|
||||||
.add_script_btn {
|
|
||||||
margin: 0 10px;
|
|
||||||
}
|
|
||||||
.search_input {
|
|
||||||
width: 300px;
|
|
||||||
margin-right: auto;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -310,10 +175,4 @@ const handleSearch = () => {
|
|||||||
color: #87cf63;
|
color: #87cf63;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
.pagination-container {
|
|
||||||
margin-top: 20px;
|
|
||||||
display: flex;
|
|
||||||
justify-content: flex-end;
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
@ -30,261 +30,232 @@
|
|||||||
label-width="100px"
|
label-width="100px"
|
||||||
:show-message="false"
|
:show-message="false"
|
||||||
>
|
>
|
||||||
<el-form-item key="group" label="分组" prop="group">
|
<transition-group name="list" mode="out-in" tag="div">
|
||||||
<el-select
|
<el-form-item key="group" label="分组" prop="group">
|
||||||
v-model="hostForm.group"
|
<el-select
|
||||||
placeholder=""
|
v-model="hostForm.group"
|
||||||
clearable
|
placeholder=""
|
||||||
style="width: 100%;"
|
|
||||||
>
|
|
||||||
<el-option
|
|
||||||
v-for="item in groupList"
|
|
||||||
:key="item.id"
|
|
||||||
:label="item.name"
|
|
||||||
:value="item.id"
|
|
||||||
/>
|
|
||||||
</el-select>
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item
|
|
||||||
v-if="!isBatchModify"
|
|
||||||
key="name"
|
|
||||||
label="名称"
|
|
||||||
prop="name"
|
|
||||||
>
|
|
||||||
<el-input
|
|
||||||
v-model="hostForm.name"
|
|
||||||
clearable
|
|
||||||
placeholder=""
|
|
||||||
autocomplete="off"
|
|
||||||
/>
|
|
||||||
</el-form-item>
|
|
||||||
<div key="instance_info" class="instance_info">
|
|
||||||
<el-form-item
|
|
||||||
v-if="!isBatchModify"
|
|
||||||
key="host"
|
|
||||||
class="form_item_host"
|
|
||||||
label="主机"
|
|
||||||
prop="host"
|
|
||||||
>
|
|
||||||
<el-input
|
|
||||||
v-model.trim="hostForm.host"
|
|
||||||
clearable
|
clearable
|
||||||
placeholder="IP"
|
style="width: 100%;"
|
||||||
autocomplete="off"
|
>
|
||||||
/>
|
<el-option
|
||||||
|
v-for="item in groupList"
|
||||||
|
:key="item.id"
|
||||||
|
:label="item.name"
|
||||||
|
:value="item.id"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item
|
<el-form-item
|
||||||
key="port"
|
v-if="!isBatchModify"
|
||||||
class="form_item_port"
|
key="name"
|
||||||
label="端口"
|
label="名称"
|
||||||
prop="port"
|
prop="name"
|
||||||
>
|
>
|
||||||
<el-input
|
<el-input
|
||||||
v-model.trim.number="hostForm.port"
|
v-model="hostForm.name"
|
||||||
clearable
|
clearable
|
||||||
placeholder=""
|
placeholder=""
|
||||||
autocomplete="off"
|
autocomplete="off"
|
||||||
/>
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</div>
|
<div key="instance_info" class="instance_info">
|
||||||
<el-form-item key="username" label="用户名" prop="username">
|
<el-form-item
|
||||||
<el-autocomplete
|
v-if="!isBatchModify"
|
||||||
v-model.trim="hostForm.username"
|
key="host"
|
||||||
:fetch-suggestions="userSearch"
|
class="form_item_host"
|
||||||
style="width: 100%;"
|
label="主机"
|
||||||
clearable
|
prop="host"
|
||||||
>
|
|
||||||
<template #default="{ item }">
|
|
||||||
<div class="value">{{ item.value }}</div>
|
|
||||||
</template>
|
|
||||||
</el-autocomplete>
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item key="authType" label="认证方式" prop="authType">
|
|
||||||
<el-radio v-model="hostForm.authType" value="privateKey">密钥</el-radio>
|
|
||||||
<el-radio v-model="hostForm.authType" value="password">密码</el-radio>
|
|
||||||
<el-radio v-model="hostForm.authType" value="credential">凭据</el-radio>
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item
|
|
||||||
v-if="hostForm.authType === 'privateKey'"
|
|
||||||
key="privateKey"
|
|
||||||
prop="privateKey"
|
|
||||||
label="密钥"
|
|
||||||
>
|
|
||||||
<el-button type="primary" size="small" @click="handleClickUploadBtn">
|
|
||||||
本地私钥...
|
|
||||||
</el-button>
|
|
||||||
<input
|
|
||||||
ref="privateKeyRef"
|
|
||||||
type="file"
|
|
||||||
name="privateKey"
|
|
||||||
style="display: none;"
|
|
||||||
autocomplete="off"
|
|
||||||
@change="handleSelectPrivateKeyFile"
|
|
||||||
>
|
|
||||||
<el-input
|
|
||||||
v-model="hostForm.privateKey"
|
|
||||||
type="textarea"
|
|
||||||
:rows="3"
|
|
||||||
clearable
|
|
||||||
autocomplete="off"
|
|
||||||
style="margin-top: 5px;"
|
|
||||||
placeholder="-----BEGIN RSA PRIVATE KEY-----"
|
|
||||||
/>
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item
|
|
||||||
v-if="hostForm.authType === 'password'"
|
|
||||||
key="password"
|
|
||||||
prop="password"
|
|
||||||
label="密码"
|
|
||||||
>
|
|
||||||
<el-input
|
|
||||||
v-model.trim="hostForm.password"
|
|
||||||
type="password"
|
|
||||||
placeholder=""
|
|
||||||
autocomplete="new-password"
|
|
||||||
clearable
|
|
||||||
show-password
|
|
||||||
/>
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item
|
|
||||||
v-if="hostForm.authType === 'credential'"
|
|
||||||
key="credential"
|
|
||||||
prop="credential"
|
|
||||||
label="凭据"
|
|
||||||
>
|
|
||||||
<el-select v-model="hostForm.credential" placeholder="">
|
|
||||||
<template #empty>
|
|
||||||
<div class="empty_text">
|
|
||||||
<span>无凭据数据,</span>
|
|
||||||
<el-button type="primary" link @click="toCredentials">
|
|
||||||
去添加
|
|
||||||
</el-button>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
<el-option
|
|
||||||
v-for="item in sshList"
|
|
||||||
:key="item.id"
|
|
||||||
:label="item.name"
|
|
||||||
:value="item.id"
|
|
||||||
>
|
>
|
||||||
<div class="select_warp">
|
<el-input
|
||||||
<span>{{ item.name }}</span>
|
v-model.trim="hostForm.host"
|
||||||
<span class="auth_type_text">
|
clearable
|
||||||
{{ item.authType === 'privateKey' ? '密钥' : '密码' }}
|
placeholder="IP"
|
||||||
</span>
|
autocomplete="off"
|
||||||
</div>
|
/>
|
||||||
</el-option>
|
</el-form-item>
|
||||||
</el-select>
|
<el-form-item
|
||||||
</el-form-item>
|
key="port"
|
||||||
<el-form-item
|
class="form_item_port"
|
||||||
key="jumpHosts"
|
label="端口"
|
||||||
prop="jumpHosts"
|
prop="port"
|
||||||
label="跳板机"
|
|
||||||
>
|
|
||||||
<PlusSupportTip>
|
|
||||||
<el-select
|
|
||||||
v-model="hostForm.jumpHosts"
|
|
||||||
placeholder="支持多选,跳板机连接顺序从前到后"
|
|
||||||
multiple
|
|
||||||
:disabled="!isPlusActive"
|
|
||||||
>
|
>
|
||||||
|
<el-input
|
||||||
|
v-model.trim.number="hostForm.port"
|
||||||
|
clearable
|
||||||
|
placeholder=""
|
||||||
|
autocomplete="off"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
</div>
|
||||||
|
<el-form-item key="username" label="用户名" prop="username">
|
||||||
|
<el-autocomplete
|
||||||
|
v-model.trim="hostForm.username"
|
||||||
|
:fetch-suggestions="userSearch"
|
||||||
|
style="width: 100%;"
|
||||||
|
clearable
|
||||||
|
>
|
||||||
|
<template #default="{ item }">
|
||||||
|
<div class="value">{{ item.value }}</div>
|
||||||
|
</template>
|
||||||
|
</el-autocomplete>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item key="authType" label="认证方式" prop="authType">
|
||||||
|
<el-radio v-model="hostForm.authType" value="privateKey">密钥</el-radio>
|
||||||
|
<el-radio v-model="hostForm.authType" value="password">密码</el-radio>
|
||||||
|
<el-radio v-model="hostForm.authType" value="credential">凭据</el-radio>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item
|
||||||
|
v-if="hostForm.authType === 'privateKey'"
|
||||||
|
key="privateKey"
|
||||||
|
prop="privateKey"
|
||||||
|
label="密钥"
|
||||||
|
>
|
||||||
|
<el-button type="primary" size="small" @click="handleClickUploadBtn">
|
||||||
|
本地私钥...
|
||||||
|
</el-button>
|
||||||
|
<!-- <el-button type="primary" size="small" @click="handleClickUploadBtn">
|
||||||
|
从凭据导入...
|
||||||
|
</el-button> -->
|
||||||
|
<input
|
||||||
|
ref="privateKeyRef"
|
||||||
|
type="file"
|
||||||
|
name="privateKey"
|
||||||
|
style="display: none;"
|
||||||
|
@change="handleSelectPrivateKeyFile"
|
||||||
|
>
|
||||||
|
<el-input
|
||||||
|
v-model="hostForm.privateKey"
|
||||||
|
type="textarea"
|
||||||
|
:rows="3"
|
||||||
|
clearable
|
||||||
|
autocomplete="off"
|
||||||
|
style="margin-top: 5px;"
|
||||||
|
placeholder="-----BEGIN RSA PRIVATE KEY-----"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item
|
||||||
|
v-if="hostForm.authType === 'password'"
|
||||||
|
key="password"
|
||||||
|
prop="password"
|
||||||
|
label="密码"
|
||||||
|
>
|
||||||
|
<el-input
|
||||||
|
v-model.trim="hostForm.password"
|
||||||
|
type="password"
|
||||||
|
placeholder=""
|
||||||
|
autocomplete="off"
|
||||||
|
clearable
|
||||||
|
show-password
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item
|
||||||
|
v-if="hostForm.authType === 'credential'"
|
||||||
|
key="credential"
|
||||||
|
prop="credential"
|
||||||
|
label="凭据"
|
||||||
|
>
|
||||||
|
<el-select v-model="hostForm.credential" class="credential_select" placeholder="">
|
||||||
<template #empty>
|
<template #empty>
|
||||||
<div class="empty_text">
|
<div class="empty_credential">
|
||||||
<span>无可用跳板机器</span>
|
<span>无凭据数据,</span>
|
||||||
|
<el-button type="primary" link @click="toCredentials">
|
||||||
|
去添加
|
||||||
|
</el-button>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<el-option
|
<el-option
|
||||||
v-for="item in confHostList"
|
v-for="item in sshList"
|
||||||
:key="item.id"
|
:key="item.id"
|
||||||
:label="item.name"
|
:label="item.name"
|
||||||
:value="item.id"
|
:value="item.id"
|
||||||
>
|
>
|
||||||
<div class="select_wrap">
|
<div class="auth_type_wrap">
|
||||||
<span>{{ item.name }}</span>
|
<span>{{ item.name }}</span>
|
||||||
|
<span class="auth_type_text">
|
||||||
|
{{ item.authType === 'privateKey' ? '密钥' : '密码' }}
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</el-option>
|
</el-option>
|
||||||
</el-select>
|
</el-select>
|
||||||
</PlusSupportTip>
|
</el-form-item>
|
||||||
</el-form-item>
|
<el-form-item key="command" prop="command" label="执行指令">
|
||||||
<el-form-item key="command" prop="command" label="登录指令">
|
<el-input
|
||||||
<el-input
|
v-model="hostForm.command"
|
||||||
v-model="hostForm.command"
|
type="textarea"
|
||||||
type="textarea"
|
:rows="3"
|
||||||
:rows="3"
|
clearable
|
||||||
clearable
|
autocomplete="off"
|
||||||
autocomplete="off"
|
placeholder="连接服务器后自动执行的指令(例如: sudo -i)"
|
||||||
placeholder="连接服务器后自动执行的指令(例如: sudo -i)"
|
/>
|
||||||
/>
|
</el-form-item>
|
||||||
</el-form-item>
|
|
||||||
|
|
||||||
<el-form-item key="expired" label="到期时间" prop="expired">
|
<el-form-item key="expired" label="到期时间" prop="expired">
|
||||||
<el-date-picker
|
<el-date-picker
|
||||||
v-model="hostForm.expired"
|
v-model="hostForm.expired"
|
||||||
type="date"
|
type="date"
|
||||||
:editable="false"
|
:editable="false"
|
||||||
style="width: 100%;"
|
style="width: 100%;"
|
||||||
value-format="x"
|
value-format="x"
|
||||||
placeholder="实例到期时间"
|
placeholder="实例到期时间"
|
||||||
/>
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item
|
<el-form-item
|
||||||
v-if="hostForm.expired"
|
v-if="hostForm.expired"
|
||||||
key="expiredNotify"
|
key="expiredNotify"
|
||||||
label="到期提醒"
|
label="到期提醒"
|
||||||
prop="expiredNotify"
|
prop="expiredNotify"
|
||||||
>
|
>
|
||||||
<el-tooltip content="将在实例到期前7、3、1天发送提醒(需在设置中绑定有效邮箱)" placement="right">
|
<el-tooltip content="将在实例到期前7、3、1天发送提醒(需在设置中绑定有效邮箱)" placement="right">
|
||||||
<el-switch v-model="hostForm.expiredNotify" :active-value="true" :inactive-value="false" />
|
<el-switch v-model="hostForm.expiredNotify" :active-value="true" :inactive-value="false" />
|
||||||
</el-tooltip>
|
</el-tooltip>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item key="consoleUrl" label="控制台URL" prop="consoleUrl">
|
<el-form-item key="consoleUrl" label="控制台URL" prop="consoleUrl">
|
||||||
<el-input
|
<el-input
|
||||||
v-model.trim="hostForm.consoleUrl"
|
v-model.trim="hostForm.consoleUrl"
|
||||||
clearable
|
clearable
|
||||||
placeholder="用于直达云服务商控制台"
|
placeholder="用于直达云服务商控制台"
|
||||||
autocomplete="off"
|
autocomplete="off"
|
||||||
@keyup.enter="handleSave"
|
@keyup.enter="handleSave"
|
||||||
/>
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item key="clientPort" label="客户端端口" prop="clientPort">
|
<el-form-item key="clientPort" label="客户端端口" prop="clientPort">
|
||||||
<el-input
|
<el-input
|
||||||
v-model.trim.number="hostForm.clientPort"
|
v-model.trim.number="hostForm.clientPort"
|
||||||
clearable
|
clearable
|
||||||
placeholder="客户端上报信息端口(默认22022)"
|
placeholder="客户端上报信息端口(默认22022)"
|
||||||
autocomplete="off"
|
autocomplete="off"
|
||||||
/>
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item
|
<el-form-item
|
||||||
v-if="!isBatchModify"
|
v-if="!isBatchModify"
|
||||||
key="index"
|
key="index"
|
||||||
label="序号"
|
label="序号"
|
||||||
prop="index"
|
prop="index"
|
||||||
>
|
>
|
||||||
<el-input
|
<el-input
|
||||||
v-model.trim.number="hostForm.index"
|
v-model.trim.number="hostForm.index"
|
||||||
clearable
|
clearable
|
||||||
placeholder="用于实例列表中排序(填写数字)"
|
placeholder="用于实例列表中排序(填写数字)"
|
||||||
autocomplete="off"
|
autocomplete="off"
|
||||||
/>
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item key="remark" label="备注" prop="remark">
|
<el-form-item key="remark" label="备注" prop="remark">
|
||||||
<el-input
|
<el-input
|
||||||
v-model="hostForm.remark"
|
v-model="hostForm.remark"
|
||||||
type="textarea"
|
type="textarea"
|
||||||
:rows="3"
|
:rows="3"
|
||||||
clearable
|
clearable
|
||||||
autocomplete="off"
|
autocomplete="off"
|
||||||
placeholder="简单记录实例用途"
|
placeholder="简单记录实例用途"
|
||||||
/>
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
</transition-group>
|
||||||
</el-form>
|
</el-form>
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<span class="dialog-footer">
|
<span class="dialog-footer">
|
||||||
<el-button @click="visible = false">关闭</el-button>
|
<el-button @click="visible = false">关闭</el-button>
|
||||||
<el-button v-if="!isBatchModify" type="primary" @click="handleSave">确认</el-button>
|
<el-button type="primary" @click="handleSave">确认</el-button>
|
||||||
<PlusSupportTip v-else>
|
|
||||||
<el-button type="primary" :disabled="!isPlusActive" @click="handleSave">确认</el-button>
|
|
||||||
</PlusSupportTip>
|
|
||||||
</span>
|
</span>
|
||||||
</template>
|
</template>
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
@ -292,7 +263,6 @@
|
|||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, computed, getCurrentInstance, nextTick } from 'vue'
|
import { ref, computed, getCurrentInstance, nextTick } from 'vue'
|
||||||
import PlusSupportTip from '@/components/common/PlusSupportTip.vue'
|
|
||||||
import { RSAEncrypt, AESEncrypt, randomStr } from '@utils/index.js'
|
import { RSAEncrypt, AESEncrypt, randomStr } from '@utils/index.js'
|
||||||
|
|
||||||
const { proxy: { $api, $router, $message, $store } } = getCurrentInstance()
|
const { proxy: { $api, $router, $message, $store } } = getCurrentInstance()
|
||||||
@ -326,7 +296,7 @@ const formField = {
|
|||||||
host: '',
|
host: '',
|
||||||
port: 22,
|
port: 22,
|
||||||
username: 'root',
|
username: 'root',
|
||||||
authType: 'privateKey', // privateKey, password, credential
|
authType: 'privateKey',
|
||||||
password: '',
|
password: '',
|
||||||
privateKey: '',
|
privateKey: '',
|
||||||
credential: '', // credentials -> _id
|
credential: '', // credentials -> _id
|
||||||
@ -336,12 +306,12 @@ const formField = {
|
|||||||
expiredNotify: false,
|
expiredNotify: false,
|
||||||
consoleUrl: '',
|
consoleUrl: '',
|
||||||
remark: '',
|
remark: '',
|
||||||
command: '',
|
command: ''
|
||||||
jumpHosts: []
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let hostForm = ref({ ...formField })
|
let hostForm = ref({ ...formField })
|
||||||
let privateKeyRef = ref(null)
|
let privateKeyRef = ref(null)
|
||||||
|
let oldHost = ref('')
|
||||||
let formRef = ref(null)
|
let formRef = ref(null)
|
||||||
|
|
||||||
let isBatchModify = computed(() => props.isBatchModify)
|
let isBatchModify = computed(() => props.isBatchModify)
|
||||||
@ -353,8 +323,7 @@ const rules = computed(() => {
|
|||||||
name: { required: !isBatchModify.value, message: '输入实例别名', trigger: 'change' },
|
name: { required: !isBatchModify.value, message: '输入实例别名', trigger: 'change' },
|
||||||
host: { required: !isBatchModify.value, message: '输入IP/域名', trigger: 'change' },
|
host: { required: !isBatchModify.value, message: '输入IP/域名', trigger: 'change' },
|
||||||
port: { required: !isBatchModify.value, type: 'number', message: '输入ssh端口', trigger: 'change' },
|
port: { required: !isBatchModify.value, type: 'number', message: '输入ssh端口', trigger: 'change' },
|
||||||
clientPort: { required: false, type: 'number' },
|
clientPort: { required: false, type: 'number', message: '输入ssh端口', trigger: 'change' },
|
||||||
jumpHosts: { required: false, type: 'array' },
|
|
||||||
index: { required: !isBatchModify.value, type: 'number', message: '输入数字', trigger: 'change' },
|
index: { required: !isBatchModify.value, type: 'number', message: '输入数字', trigger: 'change' },
|
||||||
// password: [{ required: hostForm.authType === 'password', trigger: 'change' },],
|
// password: [{ required: hostForm.authType === 'password', trigger: 'change' },],
|
||||||
// privateKey: [{ required: hostForm.authType === 'privateKey', trigger: 'change' },],
|
// privateKey: [{ required: hostForm.authType === 'privateKey', trigger: 'change' },],
|
||||||
@ -364,7 +333,6 @@ const rules = computed(() => {
|
|||||||
remark: { required: false }
|
remark: { required: false }
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
const isPlusActive = computed(() => $store.isPlusActive)
|
|
||||||
|
|
||||||
const visible = computed({
|
const visible = computed({
|
||||||
get: () => props.show,
|
get: () => props.show,
|
||||||
@ -377,38 +345,29 @@ const title = computed(() => {
|
|||||||
|
|
||||||
let groupList = computed(() => $store.groupList)
|
let groupList = computed(() => $store.groupList)
|
||||||
let sshList = computed(() => $store.sshList)
|
let sshList = computed(() => $store.sshList)
|
||||||
let hostList = computed(() => $store.hostList)
|
|
||||||
let confHostList = computed(() => {
|
|
||||||
return hostList.value?.filter(item => item.isConfig)
|
|
||||||
})
|
|
||||||
|
|
||||||
const setDefaultData = () => {
|
const setDefaultData = () => {
|
||||||
if (!defaultData.value) return
|
if (!defaultData.value) return
|
||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
let { id, ...rest } = defaultData.value
|
let { host, monitorData, ...rest } = defaultData.value
|
||||||
for (let [key,] of Object.entries(hostForm.value)) {
|
oldHost.value = host
|
||||||
if (rest[key] !== undefined) hostForm.value[key] = rest[key]
|
Object.assign(hostForm.value, { host, ...rest })
|
||||||
}
|
|
||||||
hostForm.value.id = id
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const setBatchDefaultData = () => {
|
const setBatchDefaultData = () => {
|
||||||
if (!isBatchModify.value) return
|
if (!isBatchModify.value) return
|
||||||
Object.assign(hostForm.value, { ...formField }, { group: '', port: '', username: '', authType: '', clientPort: '', jumpHosts: [] })
|
Object.assign(hostForm.value, { ...formField }, { group: '', port: '', username: '', authType: '', clientPort: '' })
|
||||||
}
|
}
|
||||||
const handleOpen = async () => {
|
const handleOpen = async () => {
|
||||||
if (isBatchModify.value) {
|
setDefaultData()
|
||||||
setBatchDefaultData()
|
setBatchDefaultData()
|
||||||
} else {
|
|
||||||
setDefaultData()
|
|
||||||
}
|
|
||||||
await nextTick()
|
await nextTick()
|
||||||
formRef.value.clearValidate()
|
formRef.value.clearValidate()
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleClosed = async () => {
|
const handleClosed = async () => {
|
||||||
emit('closed')
|
emit('closed')
|
||||||
hostForm.value = { ...formField }
|
Object.assign(hostForm.value, { ...formField })
|
||||||
await nextTick()
|
await nextTick()
|
||||||
formRef.value.resetFields()
|
formRef.value.resetFields()
|
||||||
}
|
}
|
||||||
@ -455,39 +414,30 @@ const handleSave = () => {
|
|||||||
let formData = { ...hostForm.value }
|
let formData = { ...hostForm.value }
|
||||||
if (isBatchModify.value) {
|
if (isBatchModify.value) {
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
let updateFieldData = Object.fromEntries(Object.entries(formData).filter(([key, value]) => {
|
let updateFileData = Object.fromEntries(Object.entries(formData).filter(([key, value]) => Boolean(value))) // 剔除掉未更改的值
|
||||||
if (Array.isArray(value)) return value.length > 0
|
if (Object.keys(updateFileData).length === 0) return $message.warning('没有任何修改')
|
||||||
return Boolean(value)
|
console.log(updateFileData)
|
||||||
})) // 剔除掉未更改的值
|
let newHosts = batchHosts.value
|
||||||
let { authType = '' } = updateFieldData
|
.map(item => ({ ...item, ...updateFileData }))
|
||||||
if (authType && !updateFieldData[authType]) {
|
.map(item => {
|
||||||
delete updateFieldData.authType
|
const { authType } = item
|
||||||
delete updateFieldData.privateKey
|
let tempKey = randomStr(16)
|
||||||
delete updateFieldData.password
|
if (item[authType]) item[authType] = AESEncrypt(item[authType], tempKey)
|
||||||
delete updateFieldData.credential
|
item.tempKey = RSAEncrypt(tempKey)
|
||||||
}
|
return item
|
||||||
if (Object.keys(updateFieldData).length === 0) return $message.warning('没有任何修改')
|
})
|
||||||
console.log(updateFieldData)
|
let { msg } = await $api.updateHost({ hosts: newHosts })
|
||||||
if (updateFieldData.authType) {
|
|
||||||
let tempKey = randomStr(16)
|
|
||||||
updateFieldData[authType] = AESEncrypt(updateFieldData[authType], tempKey)
|
|
||||||
updateFieldData.tempKey = RSAEncrypt(tempKey)
|
|
||||||
}
|
|
||||||
let updateIds = batchHosts.value.map(item => item.id)
|
|
||||||
let { msg } = await $api.batchUpdateHost({ updateIds, updateFieldData })
|
|
||||||
$message({ type: 'success', center: true, message: msg })
|
$message({ type: 'success', center: true, message: msg })
|
||||||
} else {
|
} else {
|
||||||
|
let tempKey = randomStr(16)
|
||||||
let { authType } = formData
|
let { authType } = formData
|
||||||
if (formData[authType]) {
|
if (formData[authType]) formData[authType] = AESEncrypt(formData[authType], tempKey)
|
||||||
let tempKey = randomStr(16)
|
formData.tempKey = RSAEncrypt(tempKey)
|
||||||
formData[authType] = AESEncrypt(formData[authType], tempKey)
|
|
||||||
formData.tempKey = RSAEncrypt(tempKey)
|
|
||||||
}
|
|
||||||
if (defaultData.value) {
|
if (defaultData.value) {
|
||||||
let { msg } = await $api.updateHost({ ...formData })
|
let { msg } = await $api.updateHost(Object.assign({}, formData, { oldHost: oldHost.value }))
|
||||||
$message({ type: 'success', center: true, message: msg })
|
$message({ type: 'success', center: true, message: msg })
|
||||||
} else {
|
} else {
|
||||||
let { msg } = await $api.addHost({ ...formData })
|
let { msg } = await $api.addHost(formData)
|
||||||
$message({ type: 'success', center: true, message: msg })
|
$message({ type: 'success', center: true, message: msg })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -522,13 +472,13 @@ const handleSave = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.empty_text {
|
.empty_credential {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.select_warp {
|
.auth_type_wrap {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
@ -133,7 +133,7 @@ const handleCsvFile = (event) => {
|
|||||||
|
|
||||||
const handleJsonFile = (event) => {
|
const handleJsonFile = (event) => {
|
||||||
let files = event.target.files
|
let files = event.target.files
|
||||||
let jsonFiles = Array.from(files).filter(file => file.name.endsWith('.json'))
|
let jsonFiles = Array.from(files).filter(file => file.type === 'application/json')
|
||||||
if (jsonFiles.length === 0) return $message.warning('未选择有效的JSON文件')
|
if (jsonFiles.length === 0) return $message.warning('未选择有效的JSON文件')
|
||||||
|
|
||||||
let readerPromises = jsonFiles.map(file => {
|
let readerPromises = jsonFiles.map(file => {
|
||||||
|
@ -3,6 +3,10 @@
|
|||||||
<div class="server_group_header">
|
<div class="server_group_header">
|
||||||
<!-- <el-button v-show="selectHosts.length" type="primary" @click="hostFormVisible = true">批量操作</el-button> -->
|
<!-- <el-button v-show="selectHosts.length" type="primary" @click="hostFormVisible = true">批量操作</el-button> -->
|
||||||
<el-button type="primary" class="add_host_btn" @click="hostFormVisible = true">添加实例</el-button>
|
<el-button type="primary" class="add_host_btn" @click="hostFormVisible = true">添加实例</el-button>
|
||||||
|
<!-- <el-button type="primary" @click="handleHiddenIP">
|
||||||
|
{{ hiddenIp ? '显示IP' : '隐藏IP' }}
|
||||||
|
</el-button> -->
|
||||||
|
<!-- <el-button type="primary" @click="importVisible = true">导入实例</el-button> -->
|
||||||
<el-dropdown trigger="click">
|
<el-dropdown trigger="click">
|
||||||
<el-button type="primary" class="group_action_btn">
|
<el-button type="primary" class="group_action_btn">
|
||||||
导入导出<el-icon class="el-icon--right"><arrow-down /></el-icon>
|
导入导出<el-icon class="el-icon--right"><arrow-down /></el-icon>
|
||||||
@ -78,15 +82,17 @@ import { exportFile } from '@/utils'
|
|||||||
|
|
||||||
const { proxy: { $api, $store, $router, $message, $messageBox, $tools } } = getCurrentInstance()
|
const { proxy: { $api, $store, $router, $message, $messageBox, $tools } } = getCurrentInstance()
|
||||||
|
|
||||||
const updateHostData = ref(null)
|
let updateHostData = ref(null)
|
||||||
const hostFormVisible = ref(false)
|
let hostFormVisible = ref(false)
|
||||||
const importVisible = ref(false)
|
let importVisible = ref(false)
|
||||||
const selectHosts = ref([])
|
let selectHosts = ref([])
|
||||||
const isBatchModify = ref(false)
|
let isBatchModify = ref(false)
|
||||||
const hostTableRefs = ref([])
|
const hostTableRefs = ref([])
|
||||||
const activeGroup = ref([])
|
|
||||||
|
|
||||||
const handleUpdateList = async () => {
|
let hiddenIp = ref(Number(localStorage.getItem('hiddenIp') || 0))
|
||||||
|
let activeGroup = ref([])
|
||||||
|
|
||||||
|
let handleUpdateList = async () => {
|
||||||
try {
|
try {
|
||||||
await $store.getHostList()
|
await $store.getHostList()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@ -164,6 +170,11 @@ let handleBatchExport = () => {
|
|||||||
hostTableRefs.value.forEach(item => item.clearSelection())
|
hostTableRefs.value.forEach(item => item.clearSelection())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let handleHiddenIP = () => {
|
||||||
|
hiddenIp.value = hiddenIp.value ? 0 : 1
|
||||||
|
localStorage.setItem('hiddenIp', String(hiddenIp.value))
|
||||||
|
}
|
||||||
|
|
||||||
let hostList = computed(() => $store.hostList)
|
let hostList = computed(() => $store.hostList)
|
||||||
|
|
||||||
let groupHostList = computed(() => {
|
let groupHostList = computed(() => {
|
||||||
|
@ -69,45 +69,20 @@
|
|||||||
/>
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</template>
|
</template>
|
||||||
<!-- Telegram -->
|
|
||||||
<template v-if="noticeConfig.type === 'tg'">
|
|
||||||
<el-form-item label="Token" prop="tg.token" class="form_item">
|
|
||||||
<el-input
|
|
||||||
v-model.trim="noticeConfig.tg.token"
|
|
||||||
clearable
|
|
||||||
placeholder="Telegram Token"
|
|
||||||
autocomplete="off"
|
|
||||||
class="input"
|
|
||||||
/>
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item label="ChatId" prop="tg.chatId" class="form_item">
|
|
||||||
<el-input
|
|
||||||
v-model="noticeConfig.tg.chatId"
|
|
||||||
clearable
|
|
||||||
placeholder="Telegram ChatId"
|
|
||||||
autocomplete="off"
|
|
||||||
class="input"
|
|
||||||
/>
|
|
||||||
<span class="tips">Telegram Token/ChatId 获取: <a class="link" href="https://easynode.chaoszhu.com/zh/guide/get-tg-token" target="_blank">查看教程</a> </span>
|
|
||||||
</el-form-item>
|
|
||||||
</template>
|
|
||||||
<el-form-item label="" class="form_item">
|
<el-form-item label="" class="form_item">
|
||||||
<el-button
|
<el-button type="primary" :loading="loading" @click="handleSave">
|
||||||
type="primary"
|
|
||||||
:loading="loading"
|
|
||||||
@click="handleSave"
|
|
||||||
>
|
|
||||||
测试并保存
|
测试并保存
|
||||||
</el-button>
|
</el-button>
|
||||||
|
<!-- <el-tooltip effect="dark" content="重复添加的邮箱将会被覆盖" placement="right">
|
||||||
|
</el-tooltip> -->
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, reactive, onMounted, getCurrentInstance, computed } from 'vue'
|
import { ref, reactive, onMounted, getCurrentInstance } from 'vue'
|
||||||
// import PlusSupportTip from '@/components/common/PlusSupportTip.vue'
|
|
||||||
|
|
||||||
const { proxy: { $api, $notification, $store } } = getCurrentInstance()
|
const { proxy: { $api, $notification } } = getCurrentInstance()
|
||||||
|
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const noticeConfig = ref({})
|
const noticeConfig = ref({})
|
||||||
@ -120,28 +95,14 @@ const noticeTypeList = ref([
|
|||||||
type: 'sct',
|
type: 'sct',
|
||||||
desc: 'Server酱'
|
desc: 'Server酱'
|
||||||
},
|
},
|
||||||
{
|
|
||||||
type: 'tg',
|
|
||||||
desc: 'Telegram'
|
|
||||||
},
|
|
||||||
])
|
])
|
||||||
const formRef = ref(null)
|
const formRef = ref(null)
|
||||||
const isPlusActive = computed(() => $store.isPlusActive)
|
|
||||||
|
|
||||||
const rules = reactive({
|
const rules = reactive({
|
||||||
'sct.sendKey': { required: true, message: '需输入sendKey', trigger: 'change' },
|
'sct.sendKey': { required: true, message: '需输入sendKey', trigger: 'change' },
|
||||||
'email.service': { required: true, message: '需输入邮箱提供商', trigger: 'change' },
|
'email.service': { required: true, message: '需输入邮箱提供商', trigger: 'change' },
|
||||||
'email.user': { required: true, type: 'email', message: '需输入邮箱', trigger: 'change' },
|
'email.user': { required: true, type: 'email', message: '需输入邮箱', trigger: 'change' },
|
||||||
'email.pass': { required: true, message: '需输入邮箱SMTP授权码', trigger: 'change' },
|
'email.pass': { required: true, message: '需输入邮箱SMTP授权码', trigger: 'change' }
|
||||||
'tg.token': { required: true, message: '需输入Telegram Token', trigger: 'change' },
|
|
||||||
'tg.chatId': [
|
|
||||||
{ required: true, message: '需输入Telegram ChatId', trigger: 'change' },
|
|
||||||
{
|
|
||||||
pattern: /^-?\d+$/,
|
|
||||||
message: 'ChatId必须为数字',
|
|
||||||
trigger: ['blur', 'change',]
|
|
||||||
},
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const handleSave = () => {
|
const handleSave = () => {
|
||||||
|
@ -1,234 +0,0 @@
|
|||||||
<template>
|
|
||||||
<el-form
|
|
||||||
ref="formRef"
|
|
||||||
class="plus-form"
|
|
||||||
:model="formData"
|
|
||||||
:rules="rules"
|
|
||||||
:hide-required-asterisk="true"
|
|
||||||
label-suffix=":"
|
|
||||||
label-width="86px"
|
|
||||||
:show-message="false"
|
|
||||||
@submit.prevent
|
|
||||||
>
|
|
||||||
<el-form-item label="Plus Key" prop="key" class="form_item">
|
|
||||||
<el-input
|
|
||||||
v-model.trim="formData.key"
|
|
||||||
clearable
|
|
||||||
placeholder=""
|
|
||||||
autocomplete="off"
|
|
||||||
class="input"
|
|
||||||
@keyup.enter.prevent="handleUpdate"
|
|
||||||
/>
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item>
|
|
||||||
<div class="form_footer">
|
|
||||||
<el-button type="primary" :loading="loading" @click="handleUpdate">立即激活</el-button>
|
|
||||||
<el-button type="success" @click="handlePlusSupport">
|
|
||||||
购买Plus
|
|
||||||
<el-icon class="el-icon--right"><TopRight /></el-icon>
|
|
||||||
</el-button>
|
|
||||||
<span v-if="!isPlusActive && discount" class="discount_wrapper" @click="handlePlusSupport">
|
|
||||||
<img
|
|
||||||
class="discount_badge"
|
|
||||||
src="@/assets/discount.png"
|
|
||||||
alt="Discount"
|
|
||||||
>
|
|
||||||
<span class="discount_content">{{ discountContent }}</span>
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</el-form-item>
|
|
||||||
</el-form>
|
|
||||||
<!-- Plus 激活状态信息 -->
|
|
||||||
<div v-if="isPlusActive" class="plus_status">
|
|
||||||
<div class="status_header">
|
|
||||||
<span>Plus专属功能已激活</span>
|
|
||||||
</div>
|
|
||||||
<div class="status_info">
|
|
||||||
<div class="info_item">
|
|
||||||
<span class="label">到期时间:</span>
|
|
||||||
<span class="value holder">{{ plusInfo.expiryDate }}</span>
|
|
||||||
</div>
|
|
||||||
<div class="info_item">
|
|
||||||
<span class="label">授权IP数:</span>
|
|
||||||
<span class="value">{{ plusInfo.maxIPs }}</span>
|
|
||||||
</div>
|
|
||||||
<div class="info_item">
|
|
||||||
<span class="label">已授权IP数:</span>
|
|
||||||
<span class="value">{{ plusInfo.usedIPCount }}</span>
|
|
||||||
</div>
|
|
||||||
<div class="info_item ip_list">
|
|
||||||
<span class="label">已授权IP:</span>
|
|
||||||
<div class="ip_tags">
|
|
||||||
<el-tag
|
|
||||||
v-for="ip in plusInfo.usedIPs"
|
|
||||||
:key="ip"
|
|
||||||
size="small"
|
|
||||||
class="ip_tag"
|
|
||||||
>
|
|
||||||
{{ ip }}
|
|
||||||
</el-tag>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<PlusTable />
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup>
|
|
||||||
import { ref, reactive, onMounted, getCurrentInstance, computed } from 'vue'
|
|
||||||
import { ElMessageBox } from 'element-plus'
|
|
||||||
import { TopRight } from '@element-plus/icons-vue'
|
|
||||||
import { handlePlusSupport } from '@/utils'
|
|
||||||
import PlusTable from '@/components/plus-table.vue'
|
|
||||||
|
|
||||||
const { proxy: { $api, $message, $store } } = getCurrentInstance()
|
|
||||||
|
|
||||||
const errCount = ref(Number(localStorage.getItem('plusErrCount') || 0))
|
|
||||||
const loading = ref(false)
|
|
||||||
const formRef = ref(null)
|
|
||||||
const formData = reactive({
|
|
||||||
key: ''
|
|
||||||
})
|
|
||||||
const rules = reactive({
|
|
||||||
key: { required: true, message: '输入Plus Key', trigger: 'change' }
|
|
||||||
})
|
|
||||||
const discount = ref(false)
|
|
||||||
const discountContent = ref('')
|
|
||||||
|
|
||||||
const plusInfo = computed(() => $store.plusInfo)
|
|
||||||
const isPlusActive = computed(() => $store.isPlusActive)
|
|
||||||
|
|
||||||
const handleUpdate = () => {
|
|
||||||
formRef.value.validate()
|
|
||||||
.then(async () => {
|
|
||||||
try {
|
|
||||||
loading.value = true
|
|
||||||
let { key } = formData
|
|
||||||
await $api.updatePlusKey({ key })
|
|
||||||
$message({ type: 'success', center: true, message: '激活成功,感谢支持' })
|
|
||||||
localStorage.setItem('plusErrCount', 0)
|
|
||||||
} catch (error) {
|
|
||||||
localStorage.setItem('plusErrCount', ++errCount.value)
|
|
||||||
if (errCount.value > 3) {
|
|
||||||
ElMessageBox.confirm(
|
|
||||||
'激活失败,请确认key正确(20位不规则字符串),有疑问请tg联系@chaoszhu。',
|
|
||||||
'Warning',
|
|
||||||
{
|
|
||||||
showCancelButton : false,
|
|
||||||
confirmButtonText: '确认',
|
|
||||||
type: 'warning'
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
loading.value = false
|
|
||||||
$store.getPlusInfo()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const getPlusConf = async () => {
|
|
||||||
try {
|
|
||||||
loading.value = true
|
|
||||||
let { data } = await $api.getPlusConf()
|
|
||||||
formData.key = data
|
|
||||||
} catch (error) {
|
|
||||||
$message({ type: 'error', center: true, message: error.message })
|
|
||||||
} finally {
|
|
||||||
loading.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const getPlusDiscount = async () => {
|
|
||||||
const { data } = await $api.getPlusDiscount()
|
|
||||||
if (data?.discount) {
|
|
||||||
discount.value = data.discount
|
|
||||||
discountContent.value = data.content
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onMounted(() => {
|
|
||||||
getPlusConf()
|
|
||||||
getPlusDiscount()
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
|
||||||
.form_item {
|
|
||||||
.input {
|
|
||||||
width: 450px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.form_footer {
|
|
||||||
height: 100%;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: start;
|
|
||||||
margin-bottom: 15px;
|
|
||||||
.discount_wrapper {
|
|
||||||
height: 100%;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
cursor: pointer;
|
|
||||||
.discount_badge {
|
|
||||||
margin: 0 5px 0 10px;
|
|
||||||
width: 22px;
|
|
||||||
color: white;
|
|
||||||
font-size: 12px;
|
|
||||||
}
|
|
||||||
.discount_content {
|
|
||||||
font-size: 12px;
|
|
||||||
line-height: 1.3;
|
|
||||||
color: #ff4806;
|
|
||||||
text-decoration: underline;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.plus_status {
|
|
||||||
margin-bottom: 15px;
|
|
||||||
|
|
||||||
.status_header {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
color: #67c23a;
|
|
||||||
margin-bottom: 10px;
|
|
||||||
|
|
||||||
.el-icon {
|
|
||||||
margin-right: 5px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.status_info {
|
|
||||||
.info_item {
|
|
||||||
display: flex;
|
|
||||||
margin: 5px 0;
|
|
||||||
font-size: 13px;
|
|
||||||
|
|
||||||
.label {
|
|
||||||
color: #909399;
|
|
||||||
width: 80px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.holder {
|
|
||||||
color: #EED183;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.ip_list {
|
|
||||||
flex-direction: column;
|
|
||||||
|
|
||||||
.ip_tags {
|
|
||||||
margin-top: 5px;
|
|
||||||
|
|
||||||
.ip_tag {
|
|
||||||
margin: 2px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
@ -9,16 +9,15 @@
|
|||||||
label-width="86px"
|
label-width="86px"
|
||||||
:show-message="false"
|
:show-message="false"
|
||||||
>
|
>
|
||||||
<el-form-item label="原用户名" prop="oldLoginName" class="form_item">
|
<el-form-item label="原用户名" prop="oldLoginName">
|
||||||
<el-input
|
<el-input
|
||||||
v-model.trim="formData.oldLoginName"
|
v-model.trim="formData.oldLoginName"
|
||||||
clearable
|
clearable
|
||||||
placeholder=""
|
placeholder=""
|
||||||
autocomplete="off"
|
autocomplete="off"
|
||||||
class="input"
|
|
||||||
/>
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="原密码" prop="oldPwd" class="form_item">
|
<el-form-item label="原密码" prop="oldPwd">
|
||||||
<el-input
|
<el-input
|
||||||
v-model.trim="formData.oldPwd"
|
v-model.trim="formData.oldPwd"
|
||||||
type="password"
|
type="password"
|
||||||
@ -26,19 +25,17 @@
|
|||||||
show-password
|
show-password
|
||||||
placeholder=""
|
placeholder=""
|
||||||
autocomplete="off"
|
autocomplete="off"
|
||||||
class="input"
|
|
||||||
/>
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="新用户名" prop="newLoginName" class="form_item">
|
<el-form-item label="新用户名" prop="newLoginName">
|
||||||
<el-input
|
<el-input
|
||||||
v-model.trim="formData.newLoginName"
|
v-model.trim="formData.newLoginName"
|
||||||
clearable
|
clearable
|
||||||
placeholder=""
|
placeholder=""
|
||||||
autocomplete="off"
|
autocomplete="off"
|
||||||
class="input"
|
|
||||||
/>
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="新密码" prop="newPwd" class="form_item">
|
<el-form-item label="新密码" prop="newPwd">
|
||||||
<el-input
|
<el-input
|
||||||
v-model.trim="formData.newPwd"
|
v-model.trim="formData.newPwd"
|
||||||
type="password"
|
type="password"
|
||||||
@ -46,7 +43,6 @@
|
|||||||
clearable
|
clearable
|
||||||
placeholder=""
|
placeholder=""
|
||||||
autocomplete="off"
|
autocomplete="off"
|
||||||
class="input"
|
|
||||||
@keyup.enter="handleUpdate"
|
@keyup.enter="handleUpdate"
|
||||||
/>
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
@ -163,11 +159,7 @@ onMounted(() => {
|
|||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
.password-form {
|
.password-form {
|
||||||
.form_item {
|
width: 500px;
|
||||||
.input {
|
|
||||||
width: 450px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.mfa2_title {
|
.mfa2_title {
|
||||||
font-size: 18px;
|
font-size: 18px;
|
||||||
|
@ -1,56 +1,33 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="setting_container">
|
<div class="setting_container">
|
||||||
<el-tabs v-model="tabKey" tab-position="top">
|
<el-tabs tab-position="top">
|
||||||
<el-tab-pane label="修改密码" name="user">
|
<el-tab-pane label="修改密码" lazy>
|
||||||
<User />
|
<User />
|
||||||
</el-tab-pane>
|
</el-tab-pane>
|
||||||
<el-tab-pane label="登录日志" name="record" lazy>
|
<el-tab-pane label="登录日志">
|
||||||
<Record />
|
<Record />
|
||||||
</el-tab-pane>
|
</el-tab-pane>
|
||||||
<el-tab-pane label="全局通知" name="notify">
|
<el-tab-pane label="全局通知" lazy>
|
||||||
<GlobalNotify />
|
<GlobalNotify />
|
||||||
</el-tab-pane>
|
</el-tab-pane>
|
||||||
<el-tab-pane label="通知配置" name="notify-config">
|
<el-tab-pane label="通知配置" lazy>
|
||||||
<NotifyConfig />
|
<NotifyConfig />
|
||||||
</el-tab-pane>
|
</el-tab-pane>
|
||||||
<el-tab-pane label="Plus激活" name="plus">
|
|
||||||
<UserPlus />
|
|
||||||
</el-tab-pane>
|
|
||||||
</el-tabs>
|
</el-tabs>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { watch, computed } from 'vue'
|
|
||||||
import { useRoute, useRouter } from 'vue-router'
|
|
||||||
import GlobalNotify from './components/global-notify.vue'
|
import GlobalNotify from './components/global-notify.vue'
|
||||||
|
// import EmailList from './components/email-list.vue'
|
||||||
import Record from './components/record.vue'
|
import Record from './components/record.vue'
|
||||||
import User from './components/user.vue'
|
import User from './components/user.vue'
|
||||||
import NotifyConfig from './components/notify-config.vue'
|
import NotifyConfig from './components/notify-config.vue'
|
||||||
import UserPlus from './components/user-plus.vue'
|
|
||||||
|
|
||||||
const route = useRoute()
|
|
||||||
const router = useRouter()
|
|
||||||
|
|
||||||
const tabKey = computed({
|
|
||||||
get() {
|
|
||||||
return route.query.tabKey || 'user'
|
|
||||||
},
|
|
||||||
set(newVal) {
|
|
||||||
router.push({ query: { tabKey: newVal } })
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
watch(() => tabKey.value, (newVal) => {
|
|
||||||
router.push({ query: { tabKey: newVal } })
|
|
||||||
})
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
.setting_container {
|
.setting_container {
|
||||||
height: 100%;
|
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
overflow: auto;
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
@ -15,11 +15,9 @@
|
|||||||
</template>
|
</template>
|
||||||
<span style="margin-right: 10px;">{{ host }}</span>
|
<span style="margin-right: 10px;">{{ host }}</span>
|
||||||
<template v-if="pingMs">
|
<template v-if="pingMs">
|
||||||
<el-tooltip effect="dark" content="该值为EasyNode服务端主机到目标主机的ping值" placement="bottom">
|
<span class="host-ping" :style="{backgroundColor: handlePingColor(pingMs)}">{{ pingMs }}ms</span>
|
||||||
<span class="host-ping" :style="{backgroundColor: handlePingColor(pingMs)}">{{ pingMs }}ms</span>
|
|
||||||
</el-tooltip>
|
|
||||||
</template>
|
</template>
|
||||||
<el-tag size="small" style="cursor: pointer;margin-left: 10px;" @click="handleCopy">复制</el-tag>
|
<el-tag size="small" style="cursor: pointer;margin-left: 15px;" @click="handleCopy">复制</el-tag>
|
||||||
</el-descriptions-item>
|
</el-descriptions-item>
|
||||||
<el-descriptions-item>
|
<el-descriptions-item>
|
||||||
<template #label>
|
<template #label>
|
||||||
|
@ -168,7 +168,7 @@ import unknowIcon from '@/assets/image/system/unknow.png'
|
|||||||
const { io } = socketIo
|
const { io } = socketIo
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
hostId: {
|
host: {
|
||||||
required: true,
|
required: true,
|
||||||
type: String
|
type: String
|
||||||
}
|
}
|
||||||
@ -270,7 +270,7 @@ const connectSftp = () => {
|
|||||||
socket.value.on('connect', () => {
|
socket.value.on('connect', () => {
|
||||||
console.log('/sftp socket已连接:', socket.value.id)
|
console.log('/sftp socket已连接:', socket.value.id)
|
||||||
listenSftp()
|
listenSftp()
|
||||||
socket.value.emit('create', { hostId: props.hostId, token: token.value })
|
socket.value.emit('create', { host: props.host, token: token.value })
|
||||||
socket.value.on('root_ls', (tree) => {
|
socket.value.on('root_ls', (tree) => {
|
||||||
let temp = sortDirTree(tree).filter((item) => isDir(item.type))
|
let temp = sortDirTree(tree).filter((item) => isDir(item.type))
|
||||||
temp.unshift({ name: '/', type: 'd' })
|
temp.unshift({ name: '/', type: 'd' })
|
||||||
|
@ -66,22 +66,6 @@
|
|||||||
label-width="100px"
|
label-width="100px"
|
||||||
:show-message="false"
|
:show-message="false"
|
||||||
>
|
>
|
||||||
<el-form-item label="自动重连" prop="autoReconnect">
|
|
||||||
<PlusSupportTip>
|
|
||||||
<span>
|
|
||||||
<el-switch
|
|
||||||
v-model="autoReconnect"
|
|
||||||
class="swtich"
|
|
||||||
inline-prompt
|
|
||||||
:disabled="!isPlusActive"
|
|
||||||
style="--el-switch-on-color: #13ce66; --el-switch-off-color: #ff4949"
|
|
||||||
active-text="开启"
|
|
||||||
inactive-text="关闭"
|
|
||||||
/>
|
|
||||||
<span class="plus_support_tip_text">(Plus专属功能)</span>
|
|
||||||
</span>
|
|
||||||
</PlusSupportTip>
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item label="选中复制" prop="quickCopy">
|
<el-form-item label="选中复制" prop="quickCopy">
|
||||||
<el-tooltip
|
<el-tooltip
|
||||||
effect="dark"
|
effect="dark"
|
||||||
@ -145,7 +129,6 @@
|
|||||||
import { computed, getCurrentInstance } from 'vue'
|
import { computed, getCurrentInstance } from 'vue'
|
||||||
import themeList from 'xterm-theme'
|
import themeList from 'xterm-theme'
|
||||||
import useMobileWidth from '@/composables/useMobileWidth'
|
import useMobileWidth from '@/composables/useMobileWidth'
|
||||||
import PlusSupportTip from '@/components/common/PlusSupportTip.vue'
|
|
||||||
const { proxy: { $store } } = getCurrentInstance()
|
const { proxy: { $store } } = getCurrentInstance()
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
@ -179,10 +162,6 @@ const quickCopy = computed({
|
|||||||
get: () => $store.terminalConfig.quickCopy,
|
get: () => $store.terminalConfig.quickCopy,
|
||||||
set: (newVal) => $store.setTerminalSetting({ quickCopy: newVal })
|
set: (newVal) => $store.setTerminalSetting({ quickCopy: newVal })
|
||||||
})
|
})
|
||||||
const autoReconnect = computed({
|
|
||||||
get: () => $store.terminalConfig.autoReconnect,
|
|
||||||
set: (newVal) => $store.setTerminalSetting({ autoReconnect: newVal })
|
|
||||||
})
|
|
||||||
const quickPaste = computed({
|
const quickPaste = computed({
|
||||||
get: () => $store.terminalConfig.quickPaste,
|
get: () => $store.terminalConfig.quickPaste,
|
||||||
set: (newVal) => $store.setTerminalSetting({ quickPaste: newVal })
|
set: (newVal) => $store.setTerminalSetting({ quickPaste: newVal })
|
||||||
@ -191,7 +170,6 @@ const autoExecuteScript = computed({
|
|||||||
get: () => $store.terminalConfig.autoExecuteScript,
|
get: () => $store.terminalConfig.autoExecuteScript,
|
||||||
set: (newVal) => $store.setTerminalSetting({ autoExecuteScript: newVal })
|
set: (newVal) => $store.setTerminalSetting({ autoExecuteScript: newVal })
|
||||||
})
|
})
|
||||||
const isPlusActive = computed(() => $store.isPlusActive)
|
|
||||||
|
|
||||||
const changeBackground = (item) => {
|
const changeBackground = (item) => {
|
||||||
background.value = item || ''
|
background.value = item || ''
|
||||||
@ -247,8 +225,5 @@ const changeBackground = (item) => {
|
|||||||
margin-bottom: 0 !important;
|
margin-bottom: 0 !important;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.plus_support_tip_text {
|
|
||||||
margin-left: 5px;
|
|
||||||
color: var(--el-text-color-placeholder);
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
@ -24,7 +24,7 @@ import socketIo from 'socket.io-client'
|
|||||||
import themeList from 'xterm-theme'
|
import themeList from 'xterm-theme'
|
||||||
import { terminalStatus } from '@/utils/enum'
|
import { terminalStatus } from '@/utils/enum'
|
||||||
|
|
||||||
const { CONNECTING, CONNECT_SUCCESS, CONNECT_FAIL } = terminalStatus
|
const { CONNECTING, RECONNECTING, CONNECT_SUCCESS, CONNECT_FAIL } = terminalStatus
|
||||||
|
|
||||||
const { io } = socketIo
|
const { io } = socketIo
|
||||||
const { proxy: { $api, $store, $serviceURI, $notification, $router, $message } } = getCurrentInstance()
|
const { proxy: { $api, $store, $serviceURI, $notification, $router, $message } } = getCurrentInstance()
|
||||||
@ -49,11 +49,12 @@ const emit = defineEmits(['inputCommand', 'cdCommand', 'ping-data', 'reset-long-
|
|||||||
const socket = ref(null)
|
const socket = ref(null)
|
||||||
// const commandHistoryList = ref([])
|
// const commandHistoryList = ref([])
|
||||||
const term = ref(null)
|
const term = ref(null)
|
||||||
const initCommand = ref('')
|
const command = ref('')
|
||||||
const timer = ref(null)
|
const timer = ref(null)
|
||||||
const pingTimer = ref(null)
|
const pingTimer = ref(null)
|
||||||
const fitAddon = ref(null)
|
const fitAddon = ref(null)
|
||||||
// const searchBar = ref(null)
|
// const searchBar = ref(null)
|
||||||
|
const hasRegisterEvent = ref(false)
|
||||||
|
|
||||||
const socketConnected = ref(false)
|
const socketConnected = ref(false)
|
||||||
const curStatus = ref(CONNECTING)
|
const curStatus = ref(CONNECTING)
|
||||||
@ -71,8 +72,6 @@ const menuCollapse = computed(() => $store.menuCollapse)
|
|||||||
const quickCopy = computed(() => $store.terminalConfig.quickCopy)
|
const quickCopy = computed(() => $store.terminalConfig.quickCopy)
|
||||||
const quickPaste = computed(() => $store.terminalConfig.quickPaste)
|
const quickPaste = computed(() => $store.terminalConfig.quickPaste)
|
||||||
const autoExecuteScript = computed(() => $store.terminalConfig.autoExecuteScript)
|
const autoExecuteScript = computed(() => $store.terminalConfig.autoExecuteScript)
|
||||||
const autoReconnect = computed(() => $store.terminalConfig.autoReconnect)
|
|
||||||
const isPlusActive = computed(() => $store.isPlusActive)
|
|
||||||
const isLongPressCtrl = computed(() => props.longPressCtrl)
|
const isLongPressCtrl = computed(() => props.longPressCtrl)
|
||||||
const isLongPressAlt = computed(() => props.longPressAlt)
|
const isLongPressAlt = computed(() => props.longPressAlt)
|
||||||
|
|
||||||
@ -92,6 +91,7 @@ watch(theme, () => {
|
|||||||
watch(fontSize, () => {
|
watch(fontSize, () => {
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
terminal.value.options.fontSize = fontSize.value
|
terminal.value.options.fontSize = fontSize.value
|
||||||
|
// fitAddon.value.fit()
|
||||||
handleResize()
|
handleResize()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -116,16 +116,14 @@ watch(curStatus, () => {
|
|||||||
|
|
||||||
const getCommand = async () => {
|
const getCommand = async () => {
|
||||||
let { data } = await $api.getCommand(hostId.value)
|
let { data } = await $api.getCommand(hostId.value)
|
||||||
if (data) initCommand.value = data
|
if (data) command.value = data
|
||||||
}
|
}
|
||||||
|
|
||||||
const connectIO = () => {
|
const connectIO = () => {
|
||||||
curStatus.value = CONNECTING
|
|
||||||
socket.value = io($serviceURI, {
|
socket.value = io($serviceURI, {
|
||||||
path: '/terminal',
|
path: '/terminal',
|
||||||
forceNew: false,
|
forceNew: false,
|
||||||
reconnection: false,
|
reconnectionAttempts: 1
|
||||||
reconnectionAttempts: 0
|
|
||||||
})
|
})
|
||||||
socket.value.on('connect', () => {
|
socket.value.on('connect', () => {
|
||||||
console.log('/terminal socket已连接:', hostId.value)
|
console.log('/terminal socket已连接:', hostId.value)
|
||||||
@ -133,14 +131,20 @@ const connectIO = () => {
|
|||||||
socketConnected.value = true
|
socketConnected.value = true
|
||||||
socket.value.emit('create', { hostId: hostId.value, token: token.value })
|
socket.value.emit('create', { hostId: hostId.value, token: token.value })
|
||||||
socket.value.on('connect_terminal_success', () => {
|
socket.value.on('connect_terminal_success', () => {
|
||||||
|
if (hasRegisterEvent.value) return // 以下事件连接成功后仅可注册一次, 否则会多次触发. 除非socket重连
|
||||||
|
hasRegisterEvent.value = true
|
||||||
|
|
||||||
socket.value.on('output', (str) => {
|
socket.value.on('output', (str) => {
|
||||||
term.value.write(str)
|
term.value.write(str)
|
||||||
terminalText.value += str
|
terminalText.value += str
|
||||||
})
|
})
|
||||||
|
|
||||||
socket.value.on('connect_shell_success', () => {
|
socket.value.on('connect_shell_success', () => {
|
||||||
curStatus.value = CONNECT_SUCCESS
|
curStatus.value = CONNECT_SUCCESS
|
||||||
shellResize()
|
onResize()
|
||||||
if (initCommand.value) socket.value.emit('input', initCommand.value + '\n')
|
onFindText()
|
||||||
|
onWebLinks()
|
||||||
|
if (command.value) socket.value.emit('input', command.value + '\n')
|
||||||
})
|
})
|
||||||
|
|
||||||
// socket.value.on('terminal_command_history', (data) => {
|
// socket.value.on('terminal_command_history', (data) => {
|
||||||
@ -151,7 +155,7 @@ const connectIO = () => {
|
|||||||
|
|
||||||
if (pingTimer.value) clearInterval(pingTimer.value)
|
if (pingTimer.value) clearInterval(pingTimer.value)
|
||||||
pingTimer.value = setInterval(() => {
|
pingTimer.value = setInterval(() => {
|
||||||
socket.value?.emit('get_ping', host.value)
|
socket.value.emit('get_ping', host.value)
|
||||||
}, 3000)
|
}, 3000)
|
||||||
socket.value.emit('get_ping', host.value) // 获取服务端到客户端的ping值
|
socket.value.emit('get_ping', host.value) // 获取服务端到客户端的ping值
|
||||||
socket.value.on('ping_data', (pingMs) => {
|
socket.value.on('ping_data', (pingMs) => {
|
||||||
@ -163,79 +167,50 @@ const connectIO = () => {
|
|||||||
$router.push('/login')
|
$router.push('/login')
|
||||||
})
|
})
|
||||||
|
|
||||||
socket.value.on('terminal_print_info', (msg) => {
|
|
||||||
term.value.write(`${ msg }\r\n`)
|
|
||||||
})
|
|
||||||
|
|
||||||
socket.value.on('connect_close', () => {
|
socket.value.on('connect_close', () => {
|
||||||
curStatus.value = CONNECT_FAIL
|
if (curStatus.value === CONNECT_FAIL) return // 连接失败不需要自动重连
|
||||||
term.value.write('\r\n\x1b[91m终端主动断开连接, 回车重新发起连接\x1b[0m')
|
curStatus.value = RECONNECTING
|
||||||
|
console.warn('连接断开,3秒后自动重连: ', hostId.value)
|
||||||
|
term.value.write('\r\n连接断开,3秒后自动重连...\r\n')
|
||||||
|
socket.value.emit('reconnect_terminal')
|
||||||
})
|
})
|
||||||
|
|
||||||
socket.value.on('connect_terminal_fail', (message) => {
|
socket.value.on('reconnect_terminal_success', () => {
|
||||||
curStatus.value = CONNECT_FAIL
|
curStatus.value = CONNECT_SUCCESS
|
||||||
term.value.write(`\r\n\x1b[91m连接终端失败: ${ message }, 回车重新发起连接\x1b[0m`)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
socket.value.on('create_terminal_fail', (message) => {
|
socket.value.on('create_fail', (message) => {
|
||||||
curStatus.value = CONNECT_FAIL
|
curStatus.value = CONNECT_FAIL
|
||||||
term.value.write(`\r\n\x1b[91m创建终端失败: ${ message }, 回车重新发起连接\x1b[0m`)
|
console.error('n创建失败:', hostId.value, message)
|
||||||
|
term.value.write(`\r\n创建失败: ${ message }\r\n`)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
socket.value.on('connect_fail', (message) => {
|
||||||
|
curStatus.value = CONNECT_FAIL
|
||||||
|
console.error('连接失败:', hostId.value, message)
|
||||||
|
term.value.write(`\r\n连接失败: ${ message }\r\n`)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
socket.value.on('disconnect', (reason) => {
|
socket.value.on('disconnect', () => {
|
||||||
console.warn('terminal websocket 连接断开:', reason)
|
console.warn('terminal websocket 连接断开')
|
||||||
switch (reason) {
|
socket.value.removeAllListeners() // 取消所有监听
|
||||||
case 'io server disconnect':
|
// socket.value.off('output') // 取消output监听,取消onData输入监听,重新注册
|
||||||
reconnectTerminal(true, '服务端主动断开连接')
|
curStatus.value = CONNECT_FAIL
|
||||||
break
|
socketConnected.value = false
|
||||||
case 'io client disconnect': // 客户端主动断开连接
|
term.value.write('\r\nError: 与面板socket连接断开。请关闭此tab,并检查本地与面板连接是否稳定\r\n')
|
||||||
break
|
|
||||||
case 'transport close':
|
|
||||||
reconnectTerminal(true, '本地网络连接异常')
|
|
||||||
break
|
|
||||||
case 'transport error':
|
|
||||||
reconnectTerminal(true, '建立连接错误')
|
|
||||||
break
|
|
||||||
case 'parse error':
|
|
||||||
reconnectTerminal(true, '数据解析错误')
|
|
||||||
break
|
|
||||||
default:
|
|
||||||
reconnectTerminal(true, '连接意外断开')
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
socket.value.on('connect_error', (err) => {
|
socket.value.on('connect_error', (err) => {
|
||||||
console.error('EasyNode服务端连接错误:', err)
|
console.error('terminal websocket 连接错误:', err)
|
||||||
curStatus.value = CONNECT_FAIL
|
|
||||||
term.value.write('\r\n\x1b[91mError: 连接失败,请检查EasyNode服务端是否正常, 回车重新发起连接\x1b[0m \r\n')
|
|
||||||
$notification({
|
$notification({
|
||||||
title: '服务端连接失败',
|
title: '终端连接失败',
|
||||||
message: '请检查EasyNode服务端是否正常',
|
message: '请检查socket服务是否正常',
|
||||||
type: 'error'
|
type: 'error'
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const reconnectTerminal = (isCommonTips = false, tips) => {
|
|
||||||
socket.value.removeAllListeners()
|
|
||||||
socket.value.close()
|
|
||||||
socket.value = null
|
|
||||||
socketConnected.value = false
|
|
||||||
if (isCommonTips) {
|
|
||||||
if (isPlusActive.value && autoReconnect.value) {
|
|
||||||
term.value.write(`\r\n\x1b[91m${ tips },自动重连中...\x1b[0m \r\n`)
|
|
||||||
connectIO()
|
|
||||||
} else {
|
|
||||||
term.value.write(`\r\n\x1b[91mError: ${ tips },请重新连接。([功能项->本地设置->快捷操作]中开启自动重连)\x1b[0m \r\n`)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
term.value.write(`\n${ tips } \n`)
|
|
||||||
connectIO()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const createLocalTerminal = () => {
|
const createLocalTerminal = () => {
|
||||||
let terminalInstance = new Terminal({
|
let terminalInstance = new Terminal({
|
||||||
rendererType: 'dom',
|
rendererType: 'dom',
|
||||||
@ -248,6 +223,13 @@ const createLocalTerminal = () => {
|
|||||||
fontFamily: 'Cascadia Code, Menlo, monospace',
|
fontFamily: 'Cascadia Code, Menlo, monospace',
|
||||||
fontSize: fontSize.value,
|
fontSize: fontSize.value,
|
||||||
theme: theme.value
|
theme: theme.value
|
||||||
|
// {
|
||||||
|
// foreground: '#ECECEC',
|
||||||
|
// background: '#000000', // 'transparent',
|
||||||
|
// // cursor: 'help',
|
||||||
|
// selection: '#ff9900',
|
||||||
|
// lineHeight: 20
|
||||||
|
// }
|
||||||
})
|
})
|
||||||
term.value = terminalInstance
|
term.value = terminalInstance
|
||||||
terminalInstance.open(terminalRef.value)
|
terminalInstance.open(terminalRef.value)
|
||||||
@ -255,20 +237,15 @@ const createLocalTerminal = () => {
|
|||||||
terminalInstance.writeln('\x1b[1;32mAn experimental Web-SSH Terminal\x1b[0m.')
|
terminalInstance.writeln('\x1b[1;32mAn experimental Web-SSH Terminal\x1b[0m.')
|
||||||
terminalInstance.focus()
|
terminalInstance.focus()
|
||||||
onSelectionChange()
|
onSelectionChange()
|
||||||
onFindText()
|
|
||||||
onWebLinks()
|
|
||||||
onResize()
|
|
||||||
terminal.value = terminalInstance
|
terminal.value = terminalInstance
|
||||||
}
|
}
|
||||||
|
|
||||||
const shellResize = () => {
|
|
||||||
fitAddon.value.fit()
|
|
||||||
let { rows, cols } = term.value
|
|
||||||
socket.value?.emit('resize', { rows, cols })
|
|
||||||
}
|
|
||||||
const onResize = () => {
|
const onResize = () => {
|
||||||
fitAddon.value = new FitAddon()
|
fitAddon.value = new FitAddon()
|
||||||
term.value.loadAddon(fitAddon.value)
|
term.value.loadAddon(fitAddon.value)
|
||||||
|
fitAddon.value.fit()
|
||||||
|
let { rows, cols } = term.value
|
||||||
|
socket.value.emit('resize', { rows, cols })
|
||||||
window.addEventListener('resize', handleResize)
|
window.addEventListener('resize', handleResize)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -282,7 +259,10 @@ const handleResize = () => {
|
|||||||
temp[index] = item.style.display
|
temp[index] = item.style.display
|
||||||
item.style.display = 'block'
|
item.style.display = 'block'
|
||||||
})
|
})
|
||||||
shellResize()
|
fitAddon.value?.fit()
|
||||||
|
let { rows, cols } = term.value
|
||||||
|
socket.value?.emit('resize', { rows, cols })
|
||||||
|
|
||||||
panes.forEach((item, index) => {
|
panes.forEach((item, index) => {
|
||||||
item.style.display = temp[index]
|
item.style.display = temp[index]
|
||||||
})
|
})
|
||||||
@ -353,12 +333,7 @@ function extractLastCdPath(text) {
|
|||||||
|
|
||||||
const onData = () => {
|
const onData = () => {
|
||||||
term.value.onData((key) => {
|
term.value.onData((key) => {
|
||||||
if ('\r' === key && curStatus.value === CONNECT_FAIL) {
|
if (socketConnected.value === false) return
|
||||||
reconnectTerminal(false, '重新连接中...')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (!socket.value || !socketConnected.value) return
|
|
||||||
|
|
||||||
if (isLongPressCtrl.value || isLongPressAlt.value) {
|
if (isLongPressCtrl.value || isLongPressAlt.value) {
|
||||||
const keyCode = key.toUpperCase().charCodeAt(0)
|
const keyCode = key.toUpperCase().charCodeAt(0)
|
||||||
console.log('keyCode: ', keyCode)
|
console.log('keyCode: ', keyCode)
|
||||||
@ -379,6 +354,12 @@ const onData = () => {
|
|||||||
enterTimer.value = setTimeout(() => {
|
enterTimer.value = setTimeout(() => {
|
||||||
if (enterTimer.value) clearTimeout(enterTimer.value)
|
if (enterTimer.value) clearTimeout(enterTimer.value)
|
||||||
if (key === '\r') { // Enter
|
if (key === '\r') { // Enter
|
||||||
|
if (curStatus.value === CONNECT_FAIL) { // 连接失败&&未正在连接,按回车可触发重连
|
||||||
|
curStatus.value = CONNECTING
|
||||||
|
term.value.write('\r\n连接中...\r\n')
|
||||||
|
socket.value.emit('reconnect_terminal')
|
||||||
|
return
|
||||||
|
}
|
||||||
if (curStatus.value === CONNECT_SUCCESS) {
|
if (curStatus.value === CONNECT_SUCCESS) {
|
||||||
let cleanText = applyBackspace(filterAnsiSequences(terminalText.value))
|
let cleanText = applyBackspace(filterAnsiSequences(terminalText.value))
|
||||||
const lines = cleanText.split('\n')
|
const lines = cleanText.split('\n')
|
||||||
@ -388,6 +369,7 @@ const onData = () => {
|
|||||||
// 截取最后一个提示符后的内容('$'或'#'后的内容)
|
// 截取最后一个提示符后的内容('$'或'#'后的内容)
|
||||||
const commandStartIndex = lastLine.lastIndexOf('#') + 1
|
const commandStartIndex = lastLine.lastIndexOf('#') + 1
|
||||||
const commandText = lastLine.substring(commandStartIndex).trim()
|
const commandText = lastLine.substring(commandStartIndex).trim()
|
||||||
|
// console.log('Processed command: ', commandText)
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
const cdPath = extractLastCdPath(commandText)
|
const cdPath = extractLastCdPath(commandText)
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@
|
|||||||
<el-tooltip
|
<el-tooltip
|
||||||
effect="dark"
|
effect="dark"
|
||||||
content="开启后同步键盘输入到所有会话"
|
content="开启后同步键盘输入到所有会话"
|
||||||
placement="bottom"
|
placement="top"
|
||||||
>
|
>
|
||||||
<el-switch
|
<el-switch
|
||||||
v-model="isSyncAllSession"
|
v-model="isSyncAllSession"
|
||||||
@ -89,7 +89,7 @@
|
|||||||
<el-tooltip
|
<el-tooltip
|
||||||
effect="dark"
|
effect="dark"
|
||||||
content="SFTP文件传输"
|
content="SFTP文件传输"
|
||||||
placement="bottom"
|
placement="top"
|
||||||
>
|
>
|
||||||
<el-switch
|
<el-switch
|
||||||
v-model="showSftp"
|
v-model="showSftp"
|
||||||
@ -167,7 +167,7 @@
|
|||||||
<Sftp
|
<Sftp
|
||||||
v-if="showSftp"
|
v-if="showSftp"
|
||||||
ref="sftpRefs"
|
ref="sftpRefs"
|
||||||
:host-id="item.id"
|
:host="item.host"
|
||||||
@resize="resizeTerminal"
|
@resize="resizeTerminal"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
}}</span>
|
}}</span>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column fixed="right" width="80px">
|
<el-table-column v-show="!isAllConfssh" fixed="right" width="80px">
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
<div class="actios_btns">
|
<div class="actios_btns">
|
||||||
<el-button
|
<el-button
|
||||||
@ -71,6 +71,9 @@ const route = useRoute()
|
|||||||
|
|
||||||
let showLinkTips = computed(() => !Boolean(terminalTabs.length))
|
let showLinkTips = computed(() => !Boolean(terminalTabs.length))
|
||||||
let hostList = computed(() => $store.hostList)
|
let hostList = computed(() => $store.hostList)
|
||||||
|
let isAllConfssh = computed(() => {
|
||||||
|
return hostList.value?.every(item => item.isConfig)
|
||||||
|
})
|
||||||
|
|
||||||
function linkTerminal(hostInfo) {
|
function linkTerminal(hostInfo) {
|
||||||
let targetHost = hostList.value.find(item => item.id === hostInfo.id)
|
let targetHost = hostList.value.find(item => item.id === hostInfo.id)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user