From cbc6fa02ac640e8469a91426f82c6f6df9f07c2b Mon Sep 17 00:00:00 2001
From: chaos-zhu
Date: Sun, 22 Dec 2024 17:45:22 +0800
Subject: [PATCH] =?UTF-8?q?:bug:=20=E4=BF=AE=E5=A4=8Dmfa2=E7=99=BB?=
=?UTF-8?q?=E5=BD=95=E9=A6=96=E5=AD=97=E7=AC=A6=E4=B8=BA0=E6=97=B6?=
=?UTF-8?q?=E6=97=A0=E6=B3=95=E8=BE=93=E5=85=A5=E7=9A=84bug&=E5=89=8D?=
=?UTF-8?q?=E7=AB=AF=E6=94=AF=E6=8C=81=E6=BF=80=E6=B4=BBplus?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
server/app/controller/user.js | 19 +-
server/app/router/routes.js | 12 +-
server/app/utils/get-plus.js | 22 +-
web/src/api/index.js | 6 +
web/src/components/plus-table.vue | 206 ++++++++++++++++++
web/src/components/top-bar.vue | 145 ++----------
web/src/store/index.js | 5 +-
web/src/utils/index.js | 4 +
web/src/views/login/index.vue | 6 +-
.../views/setting/components/user-plus.vue | 181 +++++++++++++++
web/src/views/setting/index.vue | 38 +++-
11 files changed, 500 insertions(+), 144 deletions(-)
create mode 100644 web/src/components/plus-table.vue
create mode 100644 web/src/views/setting/components/user-plus.vue
diff --git a/server/app/controller/user.js b/server/app/controller/user.js
index bda28bd..e9cff7e 100644
--- a/server/app/controller/user.js
+++ b/server/app/controller/user.js
@@ -3,11 +3,13 @@ const axios = require('axios')
const speakeasy = require('speakeasy')
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 { RSADecryptAsync, AESEncryptAsync, SHA1Encrypt } = require('../utils/encrypt')
const { getNetIPInfo } = require('../utils/tools')
const { KeyDB, LogDB, PlusDB } = require('../utils/db-class')
+
const keyDB = new KeyDB().getInstance()
const logDB = new LogDB().getInstance()
const plusDB = new PlusDB().getInstance()
@@ -175,6 +177,7 @@ const getPlusInfo = async ({ res }) => {
}
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 {
@@ -195,6 +198,18 @@ const getPlusDiscount = async ({ res } = {}) => {
}
}
+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 = {
login,
getpublicKey,
@@ -205,5 +220,7 @@ module.exports = {
enableMFA2,
disableMFA2,
getPlusInfo,
- getPlusDiscount
+ getPlusDiscount,
+ getPlusConf,
+ updatePlusKey
}
diff --git a/server/app/router/routes.js b/server/app/router/routes.js
index e55a906..d3c2b55 100644
--- a/server/app/router/routes.js
+++ b/server/app/router/routes.js
@@ -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, getPlusDiscount } = require('../controller/user')
+const { login, getpublicKey, updatePwd, getEasynodeVersion, getMFA2Status, getMFA2Code, enableMFA2, disableMFA2, getPlusInfo, getPlusDiscount, getPlusConf, updatePlusKey } = 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')
@@ -121,6 +121,16 @@ const user = [
method: 'get',
path: '/plus-discount',
controller: getPlusDiscount
+ },
+ {
+ method: 'get',
+ path: '/plus-conf',
+ controller: getPlusConf
+ },
+ {
+ method: 'post',
+ path: '/plus-conf',
+ controller: updatePlusKey
}
]
const notify = [
diff --git a/server/app/utils/get-plus.js b/server/app/utils/get-plus.js
index 5184915..f850f74 100644
--- a/server/app/utils/get-plus.js
+++ b/server/app/utils/get-plus.js
@@ -3,10 +3,16 @@ 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() {
- let key = process.env.PLUS_KEY
- if (!key || typeof key !== 'string' || key.length < 20) return
+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
@@ -20,7 +26,7 @@ async function getLicenseInfo() {
if (!ip) {
consola.error('activate plus failed: get public ip failed')
global.serverIp = ''
- return
+ return { success: false, msg: 'get public ip failed' }
}
try {
let response
@@ -64,9 +70,7 @@ async function getLicenseInfo() {
let { decryptKey, expiryDate, usedIPCount, maxIPs, usedIPs } = data
decryptKey = await AESEncryptAsync(decryptKey)
consola.success('activate plus success')
- const { PlusDB } = require('./db-class')
const plusData = { key, decryptKey, expiryDate, usedIPCount, maxIPs, usedIPs }
- const plusDB = new PlusDB().getInstance()
let count = await plusDB.countAsync({})
if (count === 0) {
await plusDB.insertAsync(plusData)
@@ -74,14 +78,16 @@ async function getLicenseInfo() {
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) {
- const { PlusDB } = require('./db-class')
- const plusDB = new PlusDB().getInstance()
await plusDB.removeAsync({}, { multi: true })
}
+ return { success: false, msg: error.message || error.errMsg?.message }
}
}
diff --git a/web/src/api/index.js b/web/src/api/index.js
index 2c15ee9..0e013d4 100644
--- a/web/src/api/index.js
+++ b/web/src/api/index.js
@@ -126,5 +126,11 @@ export default {
},
getEasynodeVersion() {
return axios({ url: '/version', method: 'get' })
+ },
+ getPlusConf() {
+ return axios({ url: '/plus-conf', method: 'get' })
+ },
+ updatePlusKey(data) {
+ return axios({ url: '/plus-conf', method: 'post', data })
}
}
diff --git a/web/src/components/plus-table.vue b/web/src/components/plus-table.vue
new file mode 100644
index 0000000..58ece10
--- /dev/null
+++ b/web/src/components/plus-table.vue
@@ -0,0 +1,206 @@
+
+
+
+
+
+
+
+
+
+
+
+
+ {{ feature }}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {{ feature }}
+
+
+
+
+
+
+
+ EasyNode最初是一个简单的Web终端工具,随着用户群的不断扩大,功能需求也日益增长,为了实现大家的功能需求,我投入了大量的业余时间进行开发和维护。
+ 一直在为爱发电,渐渐的也没了开发的动力。
+
+ 为了项目的可持续发展,后续版本开始推出PLUS版本,具体特性鼠标悬浮右上角PLUS图标查看,后续特性功能开发也会优先在PLUS版本中实现,但即使不升级到PLUS,也不会影响到EasyNode的基础功能使用【注意:
+ 暂不支持纯内网用户激活PLUS功能】。
+
+
+ 为了感谢前期赞赏过的用户, 在PLUS功能正式发布前,所有进行过赞赏的用户,无论金额大小,均可联系作者TG: @chaoszhu 凭打赏记录免费获取永久PLUS授权码。
+
+
+
+
+
+
+
+
+
+
+
diff --git a/web/src/components/top-bar.vue b/web/src/components/top-bar.vue
index 9635c88..07d3f57 100644
--- a/web/src/components/top-bar.vue
+++ b/web/src/components/top-bar.vue
@@ -37,107 +37,26 @@
-
-
-
-
-

-

-
-
-
-
-
-
-
-
-
- 到期时间:
- {{ plusInfo.expiryDate }}
-
-
- 授权IP数:
- {{ plusInfo.maxIPs }}
-
-
- 已授权IP数:
- {{ plusInfo.usedIPCount }}
-
-
-
已授权IP:
-
-
- {{ ip }}
-
-
-
-
-
-
-
-
激活PLUS
-
-
-
- {{ discountContent || '限时优惠活动' }}
-
-
-
-
-
-
-
-
- {{ plusFeature }}
-
-
-
-
-
-
-
-
+
+

+

+
TG更新通知频道:https://t.me/easynode_notify
-
- PLUS说明:
- EasyNode最初是一个简单的Web终端工具,随着用户群的不断扩大,功能需求也日益增长,为了实现大家的功能需求,我投入了大量的业余时间进行开发和维护。
- 一直在为爱发电,渐渐的也没了开发的动力。
-
- 为了项目的可持续发展,从3.0.0版本开始推出了PLUS版本,具体特性鼠标悬浮右上角PLUS图标查看,后续特性功能开发也会优先在PLUS版本中实现,但即使不升级到PLUS,也不会影响到EasyNode的基础功能使用【注意: 暂不支持纯内网用户激活PLUS功能】。
-
-
- 为了感谢前期赞赏过的用户, 在PLUS功能正式发布前,所有进行过赞赏的用户,无论金额大小,均可联系作者TG: @chaoszhu 凭打赏记录免费获取永久PLUS授权码。
-
-
@@ -198,12 +105,14 @@
+
+
+
diff --git a/web/src/views/setting/index.vue b/web/src/views/setting/index.vue
index a059d26..eac1ca3 100644
--- a/web/src/views/setting/index.vue
+++ b/web/src/views/setting/index.vue
@@ -1,33 +1,61 @@
-
-
+
+
-
+
-
+
-
+
+
+
+