Skip to content

Commit

Permalink
✨ 更新版本通知
Browse files Browse the repository at this point in the history
  • Loading branch information
chaos-zhu committed Nov 18, 2024
1 parent c04989b commit 079c62b
Show file tree
Hide file tree
Showing 15 changed files with 176 additions and 47 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ plan.md
.env.local
.env-encrypt-key
*clear.js
local-script
local-script
版本发布.md
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [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)

* 新增跳板机功能,支持选择多台机器跳转
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,9 @@ _✨ 一个多功能Linux服务器WEB终端面板(webSSH&webSFTP) ✨_
docker run -d -p 8082:8082 --restart=always -v /root/easynode/db:/easynode/app/db chaoszhu/easynode
```
环境变量:
- `PLUS_KEY`: 激活PLUS功能的授权码
- `DEBUG`: 启动debug日志 0:关闭 1:开启, 默认关闭
- `ALLOWED_IPS`: 可以访问服务的IP白名单, 多个使用逗号分隔, 支持填写部分ip前缀, 例如: `-e ALLOWED_IPS=127.0.0.1,196.168`


## 监控服务安装

- 监控服务用于实时向服务端&web端推送**系统、公网IP、CPU、内存、硬盘、网卡**等基础信息
Expand Down
28 changes: 26 additions & 2 deletions server/app/controller/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const jwt = require('jsonwebtoken')
const axios = require('axios')
const speakeasy = require('speakeasy')
const QRCode = require('qrcode')
const version = require('../../package.json').version
const { plusServer1, plusServer2 } = require('../utils/plus-server')
const { sendNoticeAsync } = require('../utils/notify')
const { RSADecryptAsync, AESEncryptAsync, SHA1Encrypt } = require('../utils/encrypt')
const { getNetIPInfo } = require('../utils/tools')
Expand Down Expand Up @@ -86,7 +88,7 @@ const beforeLoginHandler = async (clientIp, jwtExpires) => {
let token = jwt.sign({ date: Date.now() }, commonKey, { expiresIn: jwtExpires }) // 生成token
token = await AESEncryptAsync(token) // 对称加密token后再传输给前端

// 记录客户端登录IP(用于判断是否异地且只保留最近10条)
// 记录客户端登录IP(用于判断是否异地且只保留最近10��)
const clientIPInfo = await getNetIPInfo(clientIp)
const { ip, country, city } = clientIPInfo || {}
consola.info('登录成功:', new Date(), { ip, country, city })
Expand Down Expand Up @@ -172,6 +174,27 @@ const getPlusInfo = async ({ res }) => {
res.success({ data, msg: 'success' })
}

const getPlusDiscount = async ({ res } = {}) => {
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
}
}
}

module.exports = {
login,
getpublicKey,
Expand All @@ -181,5 +204,6 @@ module.exports = {
getMFA2Code,
enableMFA2,
disableMFA2,
getPlusInfo
getPlusInfo,
getPlusDiscount
}
7 changes: 6 additions & 1 deletion server/app/router/routes.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { getSSHList, addSSH, updateSSH, removeSSH, getCommand, decryptPrivateKey } = require('../controller/ssh')
const { getHostList, addHost, updateHost, batchUpdateHost, removeHost, importHost } = require('../controller/host')
const { login, getpublicKey, updatePwd, getEasynodeVersion, getMFA2Status, getMFA2Code, enableMFA2, disableMFA2, getPlusInfo } = require('../controller/user')
const { login, getpublicKey, updatePwd, getEasynodeVersion, getMFA2Status, getMFA2Code, enableMFA2, disableMFA2, getPlusInfo, getPlusDiscount } = require('../controller/user')
const { getNotifyConfig, updateNotifyConfig, getNotifyList, updateNotifyList } = require('../controller/notify')
const { getGroupList, addGroupList, updateGroupList, removeGroup } = require('../controller/group')
const { getScriptList, getLocalScriptList, addScript, updateScriptList, removeScript, batchRemoveScript, importScript } = require('../controller/scripts')
Expand Down Expand Up @@ -116,6 +116,11 @@ const user = [
method: 'get',
path: '/plus-info',
controller: getPlusInfo
},
{
method: 'get',
path: '/plus-discount',
controller: getPlusDiscount
}
]
const notify = [
Expand Down
10 changes: 5 additions & 5 deletions server/app/socket/sftp.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,18 +224,18 @@ module.exports = (httpServer) => {
let sftpClient = new SFTPClient()
consola.success('terminal websocket 已连接')

socket.on('create', async ({ host: ip, token }) => {
socket.on('create', async ({ hostId, token }) => {
const { code } = await verifyAuthSync(token, requestIP)
consola.log('code:', code)
if (code !== 1) {
socket.emit('token_verify_fail')
socket.disconnect()
return
}

const hostList = await hostListDB.findAsync({})
const targetHostInfo = hostList.find(item => item.host === ip) || {}
const targetHostInfo = await hostListDB.findOneAsync({ _id: hostId })
if (!targetHostInfo) throw new Error(`Host with ID ${ hostId } not found`)
let { authType, host, port, username } = targetHostInfo
if (!host) return socket.emit('create_fail', `查找${ ip }】凭证信息失败`)
if (!host) return socket.emit('create_fail', `查找id${ hostId }】凭证信息失败`)
let authInfo = { host, port, username }

// 解密放到try里面,防止报错【commonKey必须配对, 否则需要重新添加服务器密钥】
Expand Down
5 changes: 3 additions & 2 deletions server/app/utils/get-plus.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const schedule = require('node-schedule')
const { getLocalNetIP } = require('./tools')
const { AESEncryptAsync } = require('./encrypt')
const version = require('../../package.json').version
const { plusServer1, plusServer2 } = require('./plus-server')

async function getLicenseInfo() {
let key = process.env.PLUS_KEY
Expand All @@ -28,7 +29,7 @@ async function getLicenseInfo() {
let headers = { 'Content-Type': 'application/json' }
let timeout = 10000
try {
response = await fetch('https://en1.221022.xyz/api/licenses/activate', {
response = await fetch(plusServer1 + '/api/licenses/activate', {
method,
headers,
body,
Expand All @@ -41,7 +42,7 @@ async function getLicenseInfo() {

} catch (error) {
consola.log('retry to activate plus by backup server')
response = await fetch('https://en2.221022.xyz/api/licenses/activate', {
response = await fetch(plusServer2 + '/api/licenses/activate', {
method,
headers,
body,
Expand Down
4 changes: 4 additions & 0 deletions server/app/utils/plus-server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
plusServer1: 'https://en1.221022.xyz',
plusServer2: 'https://en2.221022.xyz'
}
2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "server",
"version": "3.0.0",
"version": "3.0.1",
"description": "easynode-server",
"bin": "./bin/www",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "web",
"version": "3.0.0",
"version": "3.0.1",
"description": "easynode-web",
"private": true,
"scripts": {
Expand Down
3 changes: 3 additions & 0 deletions web/src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export default {
getPlusInfo() {
return axios({ url: '/plus-info', method: 'get' })
},
getPlusDiscount() {
return axios({ url: '/plus-discount', method: 'get' })
},
getCommand(hostId) {
return axios({ url: '/command', method: 'get', params: { hostId } })
},
Expand Down
Binary file added web/src/assets/discount.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 079c62b

Please sign in to comment.