diff --git a/README.md b/README.md
index 5ba5a02..d2a209e 100644
--- a/README.md
+++ b/README.md
@@ -82,13 +82,13 @@ pm2 start index.js --name easynode-server
> 安装
```shell
-wget https://mirror.ghproxy.com/https://raw.githubusercontent.com/chaos-zhu/easynode/main/client/easynode-client-install.sh | bash
+curl -o- https://mirror.ghproxy.com/https://raw.githubusercontent.com/chaos-zhu/easynode/main/client/easynode-client-install.sh | bash
```
> 卸载
```shell
-wget https://mirror.ghproxy.com/https://raw.githubusercontent.com/chaos-zhu/easynode/main/client/easynode-client-uninstall.sh | bash
+curl -o- https://mirror.ghproxy.com/https://raw.githubusercontent.com/chaos-zhu/easynode/main/client/easynode-client-uninstall.sh | bash
```
> 查看客户端状态:`systemctl status easynode-client`
diff --git a/server/app/config/shell.json b/server/app/config/shell.json
new file mode 100644
index 0000000..cbf4da4
--- /dev/null
+++ b/server/app/config/shell.json
@@ -0,0 +1,17 @@
+[
+ {
+ "name": "easynode客户端安装",
+ "command": "curl -o- https://mirror.ghproxy.com/https://raw.githubusercontent.com/chaos-zhu/easynode/main/client/easynode-client-install.sh | bash",
+ "description": "easynode-客户端-安装脚本"
+ },
+ {
+ "name": "easynode客户端卸载",
+ "command": "curl -o- https://mirror.ghproxy.com/https://raw.githubusercontent.com/chaos-zhu/easynode/main/client/easynode-client-uninstall.sh | bash",
+ "description": "easynode-客户端-卸载脚本"
+ },
+ {
+ "name": "查询本机公网IP",
+ "command": "curl ifconfig.me",
+ "description": "查询本机公网IP"
+ }
+]
\ No newline at end of file
diff --git a/server/app/controller/scripts.js b/server/app/controller/scripts.js
index 4d0bba6..11693e7 100644
--- a/server/app/controller/scripts.js
+++ b/server/app/controller/scripts.js
@@ -1,4 +1,9 @@
-const { readScriptList, writeScriptList } = require('../utils')
+const localShellJson = require('../config/shell.json')
+const { readScriptList, writeScriptList, randomStr } = require('../utils')
+
+let localShell = JSON.parse(JSON.stringify(localShellJson)).map((item) => {
+ return { ...item, id: randomStr(10), index: '--', description: item.description + '|内置脚本' }
+})
async function getScriptList({ res }) {
let data = await readScriptList()
@@ -6,15 +11,20 @@ async function getScriptList({ res }) {
return { ...item, id: item._id }
})
data?.sort((a, b) => Number(b.index || 0) - Number(a.index || 0))
+ data.push(...localShell)
res.success({ data })
}
+async function getLocalScriptList({ res }) {
+ res.success({ data: localShell })
+}
+
const addScript = async ({ res, request }) => {
- let { body: { name, remark, content, index } } = request
- if (!name || !content) return res.fail({ data: false, msg: '参数错误' })
+ let { body: { name, description, command, index } } = request
+ if (!name || !command) return res.fail({ data: false, msg: '参数错误' })
index = Number(index) || 0
let scriptsList = await readScriptList()
- let record = { name, remark, content, index }
+ let record = { name, description, command, index }
scriptsList.push(record)
await writeScriptList(scriptsList)
res.success({ data: '添加成功' })
@@ -22,13 +32,13 @@ const addScript = async ({ res, request }) => {
const updateScriptList = async ({ res, request }) => {
let { params: { id } } = request
- let { body: { name, remark, content, index } } = request
- if (!name || !content) return res.fail({ data: false, msg: '参数错误' })
+ let { body: { name, description, command, index } } = request
+ if (!name || !command) return res.fail({ data: false, msg: '参数错误' })
let scriptsList = await readScriptList()
let idx = scriptsList.findIndex(item => item._id === id)
if (idx === -1) return res.fail({ data: false, msg: `脚本ID${ id }不存在` })
const { _id } = scriptsList[idx]
- let record = Object.assign({ _id }, { name, remark, content, index })
+ let record = Object.assign({ _id }, { name, description, command, index })
scriptsList.splice(idx, 1, record)
await writeScriptList(scriptsList)
res.success({ data: '修改成功' })
@@ -47,6 +57,7 @@ const removeScript = async ({ res, request }) => {
module.exports = {
addScript,
getScriptList,
+ getLocalScriptList,
updateScriptList,
removeScript
}
diff --git a/server/app/db.js b/server/app/db.js
index 328eacb..fdcee3a 100644
--- a/server/app/db.js
+++ b/server/app/db.js
@@ -151,26 +151,24 @@ function initScriptsDB() {
// eslint-disable-next-line no-async-promise-executor
return new Promise(async (resolve) => {
let scriptList = await readScriptList()
- let clientInstallScript = 'wget https://mirror.ghproxy.com/https://raw.githubusercontent.com/chaos-zhu/easynode/main/client/easynode-client-install.sh && sh easynode-client-install.sh'
- let clientUninstallScript = 'wget https://mirror.ghproxy.com/https://raw.githubusercontent.com/chaos-zhu/easynode/main/client/easynode-client-uninstall.sh && sh easynode-client-uninstall.sh'
- let clientVersion = process.env.CLIENT_VERSION
- consola.info('客户端版本:', clientVersion)
- let installId = `clientInstall${ clientVersion }`
- let uninstallId = `clientUninstall${ clientVersion }`
+ let clientInstallScript = 'curl -o- https://mirror.ghproxy.com/https://raw.githubusercontent.com/chaos-zhu/easynode/main/client/easynode-client-install.sh | bash'
+ let clientUninstallScript = 'curl -o- https://mirror.ghproxy.com/https://raw.githubusercontent.com/chaos-zhu/easynode/main/client/easynode-client-uninstall.sh | bash'
+ let installId = 'clientInstall'
+ let uninstallId = 'clientUninstall'
let isClientInstall = scriptList?.find(script => script._id = installId)
let isClientUninstall = scriptList?.find(script => script._id = uninstallId)
let writeFlag = false
if (!isClientInstall) {
console.info('初始化客户端安装脚本')
- scriptList.push({ _id: installId, name: `easynode-客户端-${ clientVersion }安装脚本`, remark: '系统内置|重启生成', content: clientInstallScript, index: 1 })
+ scriptList.push({ _id: installId, name: 'easynode-客户端-安装脚本', description: '系统内置|重启生成', command: clientInstallScript, index: 1 })
writeFlag = true
} else {
console.info('客户端安装脚本已存在')
}
if (!isClientUninstall) {
console.info('初始化客户端卸载脚本')
- scriptList.push({ _id: uninstallId, name: `easynode-客户端-${ clientVersion }卸载脚本`, remark: '系统内置|重启生成', content: clientUninstallScript, index: 0 })
+ scriptList.push({ _id: uninstallId, name: 'easynode-客户端-卸载脚本', description: '系统内置|重启生成', command: clientUninstallScript, index: 0 })
writeFlag = true
} else {
console.info('客户端卸载脚本已存在')
@@ -185,5 +183,5 @@ module.exports = async () => {
await initNotifyDB()
await initGroupDB()
await initEmailNotifyDB()
- await initScriptsDB()
-}
\ No newline at end of file
+ // await initScriptsDB()
+}
diff --git a/server/app/router/routes.js b/server/app/router/routes.js
index 2fd4f01..121c5d2 100644
--- a/server/app/router/routes.js
+++ b/server/app/router/routes.js
@@ -3,7 +3,7 @@ const { getHostList, addHost, updateHost, removeHost, importHost } = require('..
const { login, getpublicKey, updatePwd, getLoginRecord } = require('../controller/user')
const { getSupportEmailList, getUserEmailList, updateUserEmailList, removeUserEmail, pushEmail, getNotifyList, updateNotifyList } = require('../controller/notify')
const { getGroupList, addGroupList, updateGroupList, removeGroup } = require('../controller/group')
-const { getScriptList, addScript, updateScriptList, removeScript } = require('../controller/scripts')
+const { getScriptList, getLocalScriptList, addScript, updateScriptList, removeScript } = require('../controller/scripts')
const { getOnekeyRecord, removeOnekeyRecord } = require('../controller/onekey')
const ssh = [
@@ -149,6 +149,11 @@ const scripts = [
path: '/script',
controller: getScriptList
},
+ {
+ method: 'get',
+ path: '/local-script',
+ controller: getLocalScriptList
+ },
{
method: 'post',
path: '/script',
diff --git a/web/src/api/index.js b/web/src/api/index.js
index 3a3fd8d..c6d4552 100644
--- a/web/src/api/index.js
+++ b/web/src/api/index.js
@@ -91,6 +91,9 @@ export default {
getScriptList() {
return axios({ url: '/script', method: 'get' })
},
+ getLocalScriptList() {
+ return axios({ url: '/local-script', method: 'get' })
+ },
addScript(data) {
return axios({ url: '/script', method: 'post', data })
},
diff --git a/web/src/store/index.js b/web/src/store/index.js
index 5563ff8..2dd8e4e 100644
--- a/web/src/store/index.js
+++ b/web/src/store/index.js
@@ -1,7 +1,7 @@
import { io } from 'socket.io-client'
import { defineStore, acceptHMRUpdate } from 'pinia'
import $api from '@/api'
-import ping from '@/utils/ping'
+// import ping from '@/utils/ping'
const useStore = defineStore({
id: 'global',
@@ -11,6 +11,7 @@ const useStore = defineStore({
groupList: [],
sshList: [],
scriptList: [],
+ localScriptList: [],
HostStatusSocket: null,
user: localStorage.getItem('user') || null,
token: sessionStorage.getItem('token') || localStorage.getItem('token') || null,
@@ -39,6 +40,7 @@ const useStore = defineStore({
await this.getHostList()
await this.getSSHList()
await this.getScriptList()
+ // await this.getLocalScriptList()
},
async getHostList() {
const { data: hostList } = await $api.getHostList()
@@ -61,6 +63,11 @@ const useStore = defineStore({
// console.log('scriptList:', scriptList)
this.$patch({ scriptList })
},
+ async getLocalScriptList() {
+ const { data: localScriptList } = await $api.getLocalScriptList()
+ // console.log('localScriptList:', localScriptList)
+ this.$patch({ localScriptList })
+ },
// getHostPing() {
// setInterval(() => {
// this.hostList.forEach((item) => {
diff --git a/web/src/views/onekey/index.vue b/web/src/views/onekey/index.vue
index eb4d31c..b127e0b 100644
--- a/web/src/views/onekey/index.vue
+++ b/web/src/views/onekey/index.vue
@@ -326,7 +326,7 @@ let selectAllHost = (val) => {
let handleImportScript = (scriptObj) => {
isClient.value = scriptObj.id.startsWith('client')
- formData.command = scriptObj.content
+ formData.command = scriptObj.command
}
let getStatusType = (status) => {
diff --git a/web/src/views/scripts/index.vue b/web/src/views/scripts/index.vue
index 9703fcb..0ed12ac 100644
--- a/web/src/views/scripts/index.vue
+++ b/web/src/views/scripts/index.vue
@@ -6,12 +6,15 @@
-
-
+
+
- 修改
- 删除
+
+ 修改
+ 删除
+
+ --
@@ -40,9 +43,9 @@
autocomplete="off"
/>
-
+
-
+
{
return {
name: { required: true, trigger: 'change' },
- remark: { required: false, trigger: 'change' },
+ description: { required: false, trigger: 'change' },
index: { required: false, type: 'number', trigger: 'change' },
- content: { required: true, trigger: 'change' }
+ command: { required: true, trigger: 'change' }
}
})
diff --git a/web/src/views/terminal/components/terminal.vue b/web/src/views/terminal/components/terminal.vue
index 7b7cdd5..ee4f6d8 100644
--- a/web/src/views/terminal/components/terminal.vue
+++ b/web/src/views/terminal/components/terminal.vue
@@ -219,10 +219,10 @@ const handleCommandHost = (host) => {
}
const handleExecScript = (scriptObj) => {
- // console.log(scriptObj.content)
- if (!isSyncAllSession.value) return handleInputCommand(scriptObj.content)
+ const { command } = scriptObj
+ if (!isSyncAllSession.value) return handleInputCommand(command)
terminalRefs.value.forEach(terminalRef => {
- terminalRef.inputCommand(scriptObj.content)
+ terminalRef.inputCommand(command)
})
}
@@ -307,7 +307,7 @@ const handleInputCommand = async (command) => {
const curTerminalRef = terminalRefs.value[activeTabIndex.value]
await $nextTick()
curTerminalRef?.focusTab()
- curTerminalRef.inputCommand(`${ command }\n`)
+ curTerminalRef.inputCommand(`${ command }`) // \n
showInputCommand.value = false
}