🆕 内置常用脚本
This commit is contained in:
parent
44d9557f17
commit
71958699ea
@ -82,13 +82,13 @@ pm2 start index.js --name easynode-server
|
|||||||
> 安装
|
> 安装
|
||||||
|
|
||||||
```shell
|
```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
|
```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`
|
> 查看客户端状态:`systemctl status easynode-client`
|
||||||
|
17
server/app/config/shell.json
Normal file
17
server/app/config/shell.json
Normal file
@ -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"
|
||||||
|
}
|
||||||
|
]
|
@ -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 }) {
|
async function getScriptList({ res }) {
|
||||||
let data = await readScriptList()
|
let data = await readScriptList()
|
||||||
@ -6,15 +11,20 @@ async function getScriptList({ res }) {
|
|||||||
return { ...item, id: item._id }
|
return { ...item, id: item._id }
|
||||||
})
|
})
|
||||||
data?.sort((a, b) => Number(b.index || 0) - Number(a.index || 0))
|
data?.sort((a, b) => Number(b.index || 0) - Number(a.index || 0))
|
||||||
|
data.push(...localShell)
|
||||||
res.success({ data })
|
res.success({ data })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getLocalScriptList({ res }) {
|
||||||
|
res.success({ data: localShell })
|
||||||
|
}
|
||||||
|
|
||||||
const addScript = async ({ res, request }) => {
|
const addScript = async ({ res, request }) => {
|
||||||
let { body: { name, remark, content, index } } = request
|
let { body: { name, description, command, index } } = request
|
||||||
if (!name || !content) return res.fail({ data: false, msg: '参数错误' })
|
if (!name || !command) return res.fail({ data: false, msg: '参数错误' })
|
||||||
index = Number(index) || 0
|
index = Number(index) || 0
|
||||||
let scriptsList = await readScriptList()
|
let scriptsList = await readScriptList()
|
||||||
let record = { name, remark, content, index }
|
let record = { name, description, command, index }
|
||||||
scriptsList.push(record)
|
scriptsList.push(record)
|
||||||
await writeScriptList(scriptsList)
|
await writeScriptList(scriptsList)
|
||||||
res.success({ data: '添加成功' })
|
res.success({ data: '添加成功' })
|
||||||
@ -22,13 +32,13 @@ const addScript = async ({ res, request }) => {
|
|||||||
|
|
||||||
const updateScriptList = async ({ res, request }) => {
|
const updateScriptList = async ({ res, request }) => {
|
||||||
let { params: { id } } = request
|
let { params: { id } } = request
|
||||||
let { body: { name, remark, content, index } } = request
|
let { body: { name, description, command, index } } = request
|
||||||
if (!name || !content) return res.fail({ data: false, msg: '参数错误' })
|
if (!name || !command) return res.fail({ data: false, msg: '参数错误' })
|
||||||
let scriptsList = await readScriptList()
|
let scriptsList = await readScriptList()
|
||||||
let idx = scriptsList.findIndex(item => item._id === id)
|
let idx = scriptsList.findIndex(item => item._id === id)
|
||||||
if (idx === -1) return res.fail({ data: false, msg: `脚本ID${ id }不存在` })
|
if (idx === -1) return res.fail({ data: false, msg: `脚本ID${ id }不存在` })
|
||||||
const { _id } = scriptsList[idx]
|
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)
|
scriptsList.splice(idx, 1, record)
|
||||||
await writeScriptList(scriptsList)
|
await writeScriptList(scriptsList)
|
||||||
res.success({ data: '修改成功' })
|
res.success({ data: '修改成功' })
|
||||||
@ -47,6 +57,7 @@ const removeScript = async ({ res, request }) => {
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
addScript,
|
addScript,
|
||||||
getScriptList,
|
getScriptList,
|
||||||
|
getLocalScriptList,
|
||||||
updateScriptList,
|
updateScriptList,
|
||||||
removeScript
|
removeScript
|
||||||
}
|
}
|
||||||
|
@ -151,26 +151,24 @@ function initScriptsDB() {
|
|||||||
// eslint-disable-next-line no-async-promise-executor
|
// eslint-disable-next-line no-async-promise-executor
|
||||||
return new Promise(async (resolve) => {
|
return new Promise(async (resolve) => {
|
||||||
let scriptList = await readScriptList()
|
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 clientInstallScript = 'curl -o- https://mirror.ghproxy.com/https://raw.githubusercontent.com/chaos-zhu/easynode/main/client/easynode-client-install.sh | bash'
|
||||||
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 clientUninstallScript = 'curl -o- https://mirror.ghproxy.com/https://raw.githubusercontent.com/chaos-zhu/easynode/main/client/easynode-client-uninstall.sh | bash'
|
||||||
let clientVersion = process.env.CLIENT_VERSION
|
let installId = 'clientInstall'
|
||||||
consola.info('客户端版本:', clientVersion)
|
let uninstallId = 'clientUninstall'
|
||||||
let installId = `clientInstall${ clientVersion }`
|
|
||||||
let uninstallId = `clientUninstall${ clientVersion }`
|
|
||||||
|
|
||||||
let isClientInstall = scriptList?.find(script => script._id = installId)
|
let isClientInstall = scriptList?.find(script => script._id = installId)
|
||||||
let isClientUninstall = scriptList?.find(script => script._id = uninstallId)
|
let isClientUninstall = scriptList?.find(script => script._id = uninstallId)
|
||||||
let writeFlag = false
|
let writeFlag = false
|
||||||
if (!isClientInstall) {
|
if (!isClientInstall) {
|
||||||
console.info('初始化客户端安装脚本')
|
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
|
writeFlag = true
|
||||||
} else {
|
} else {
|
||||||
console.info('客户端安装脚本已存在')
|
console.info('客户端安装脚本已存在')
|
||||||
}
|
}
|
||||||
if (!isClientUninstall) {
|
if (!isClientUninstall) {
|
||||||
console.info('初始化客户端卸载脚本')
|
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
|
writeFlag = true
|
||||||
} else {
|
} else {
|
||||||
console.info('客户端卸载脚本已存在')
|
console.info('客户端卸载脚本已存在')
|
||||||
@ -185,5 +183,5 @@ module.exports = async () => {
|
|||||||
await initNotifyDB()
|
await initNotifyDB()
|
||||||
await initGroupDB()
|
await initGroupDB()
|
||||||
await initEmailNotifyDB()
|
await initEmailNotifyDB()
|
||||||
await initScriptsDB()
|
// await initScriptsDB()
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ const { getHostList, addHost, updateHost, removeHost, importHost } = require('..
|
|||||||
const { login, getpublicKey, updatePwd, getLoginRecord } = require('../controller/user')
|
const { login, getpublicKey, updatePwd, getLoginRecord } = require('../controller/user')
|
||||||
const { getSupportEmailList, getUserEmailList, updateUserEmailList, removeUserEmail, pushEmail, getNotifyList, updateNotifyList } = require('../controller/notify')
|
const { getSupportEmailList, getUserEmailList, updateUserEmailList, removeUserEmail, pushEmail, getNotifyList, updateNotifyList } = require('../controller/notify')
|
||||||
const { getGroupList, addGroupList, updateGroupList, removeGroup } = require('../controller/group')
|
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 { getOnekeyRecord, removeOnekeyRecord } = require('../controller/onekey')
|
||||||
|
|
||||||
const ssh = [
|
const ssh = [
|
||||||
@ -149,6 +149,11 @@ const scripts = [
|
|||||||
path: '/script',
|
path: '/script',
|
||||||
controller: getScriptList
|
controller: getScriptList
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
method: 'get',
|
||||||
|
path: '/local-script',
|
||||||
|
controller: getLocalScriptList
|
||||||
|
},
|
||||||
{
|
{
|
||||||
method: 'post',
|
method: 'post',
|
||||||
path: '/script',
|
path: '/script',
|
||||||
|
@ -91,6 +91,9 @@ export default {
|
|||||||
getScriptList() {
|
getScriptList() {
|
||||||
return axios({ url: '/script', method: 'get' })
|
return axios({ url: '/script', method: 'get' })
|
||||||
},
|
},
|
||||||
|
getLocalScriptList() {
|
||||||
|
return axios({ url: '/local-script', method: 'get' })
|
||||||
|
},
|
||||||
addScript(data) {
|
addScript(data) {
|
||||||
return axios({ url: '/script', method: 'post', data })
|
return axios({ url: '/script', method: 'post', data })
|
||||||
},
|
},
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { io } from 'socket.io-client'
|
import { io } from 'socket.io-client'
|
||||||
import { defineStore, acceptHMRUpdate } from 'pinia'
|
import { defineStore, acceptHMRUpdate } from 'pinia'
|
||||||
import $api from '@/api'
|
import $api from '@/api'
|
||||||
import ping from '@/utils/ping'
|
// import ping from '@/utils/ping'
|
||||||
|
|
||||||
const useStore = defineStore({
|
const useStore = defineStore({
|
||||||
id: 'global',
|
id: 'global',
|
||||||
@ -11,6 +11,7 @@ const useStore = defineStore({
|
|||||||
groupList: [],
|
groupList: [],
|
||||||
sshList: [],
|
sshList: [],
|
||||||
scriptList: [],
|
scriptList: [],
|
||||||
|
localScriptList: [],
|
||||||
HostStatusSocket: null,
|
HostStatusSocket: null,
|
||||||
user: localStorage.getItem('user') || null,
|
user: localStorage.getItem('user') || null,
|
||||||
token: sessionStorage.getItem('token') || localStorage.getItem('token') || null,
|
token: sessionStorage.getItem('token') || localStorage.getItem('token') || null,
|
||||||
@ -39,6 +40,7 @@ const useStore = defineStore({
|
|||||||
await this.getHostList()
|
await this.getHostList()
|
||||||
await this.getSSHList()
|
await this.getSSHList()
|
||||||
await this.getScriptList()
|
await this.getScriptList()
|
||||||
|
// await this.getLocalScriptList()
|
||||||
},
|
},
|
||||||
async getHostList() {
|
async getHostList() {
|
||||||
const { data: hostList } = await $api.getHostList()
|
const { data: hostList } = await $api.getHostList()
|
||||||
@ -61,6 +63,11 @@ const useStore = defineStore({
|
|||||||
// console.log('scriptList:', scriptList)
|
// console.log('scriptList:', scriptList)
|
||||||
this.$patch({ scriptList })
|
this.$patch({ scriptList })
|
||||||
},
|
},
|
||||||
|
async getLocalScriptList() {
|
||||||
|
const { data: localScriptList } = await $api.getLocalScriptList()
|
||||||
|
// console.log('localScriptList:', localScriptList)
|
||||||
|
this.$patch({ localScriptList })
|
||||||
|
},
|
||||||
// getHostPing() {
|
// getHostPing() {
|
||||||
// setInterval(() => {
|
// setInterval(() => {
|
||||||
// this.hostList.forEach((item) => {
|
// this.hostList.forEach((item) => {
|
||||||
|
@ -326,7 +326,7 @@ let selectAllHost = (val) => {
|
|||||||
|
|
||||||
let handleImportScript = (scriptObj) => {
|
let handleImportScript = (scriptObj) => {
|
||||||
isClient.value = scriptObj.id.startsWith('client')
|
isClient.value = scriptObj.id.startsWith('client')
|
||||||
formData.command = scriptObj.content
|
formData.command = scriptObj.command
|
||||||
}
|
}
|
||||||
|
|
||||||
let getStatusType = (status) => {
|
let getStatusType = (status) => {
|
||||||
|
@ -6,12 +6,15 @@
|
|||||||
<el-table v-loading="loading" :data="scriptList">
|
<el-table v-loading="loading" :data="scriptList">
|
||||||
<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="remark" label="备注" />
|
<el-table-column prop="description" label="描述" />
|
||||||
<el-table-column prop="content" label="脚本内容" show-overflow-tooltip />
|
<el-table-column prop="command" label="指令内容" show-overflow-tooltip />
|
||||||
<el-table-column label="操作">
|
<el-table-column label="操作">
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
<el-button type="primary" @click="handleChange(row)">修改</el-button>
|
<template v-if="row.index !== '--'">
|
||||||
<el-button v-show="row.id !== 'own'" type="danger" @click="handleRemove(row)">删除</el-button>
|
<el-button type="primary" @click="handleChange(row)">修改</el-button>
|
||||||
|
<el-button v-show="row.id !== 'own'" type="danger" @click="handleRemove(row)">删除</el-button>
|
||||||
|
</template>
|
||||||
|
<span v-else>--</span>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
</el-table>
|
</el-table>
|
||||||
@ -40,9 +43,9 @@
|
|||||||
autocomplete="off"
|
autocomplete="off"
|
||||||
/>
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="备注" prop="remark">
|
<el-form-item label="描述" prop="description">
|
||||||
<el-input
|
<el-input
|
||||||
v-model="formData.remark"
|
v-model="formData.description"
|
||||||
clearable
|
clearable
|
||||||
placeholder=""
|
placeholder=""
|
||||||
autocomplete="off"
|
autocomplete="off"
|
||||||
@ -56,9 +59,9 @@
|
|||||||
autocomplete="off"
|
autocomplete="off"
|
||||||
/>
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item prop="content" label="内容">
|
<el-form-item prop="command" label="内容">
|
||||||
<el-input
|
<el-input
|
||||||
v-model="formData.content"
|
v-model="formData.command"
|
||||||
type="textarea"
|
type="textarea"
|
||||||
:rows="5"
|
:rows="5"
|
||||||
clearable
|
clearable
|
||||||
@ -89,17 +92,17 @@ let isModify = ref(false)
|
|||||||
|
|
||||||
let formData = reactive({
|
let formData = reactive({
|
||||||
name: '',
|
name: '',
|
||||||
remark: '',
|
description: '',
|
||||||
index: 0,
|
index: 0,
|
||||||
content: ''
|
command: ''
|
||||||
})
|
})
|
||||||
|
|
||||||
const rules = computed(() => {
|
const rules = computed(() => {
|
||||||
return {
|
return {
|
||||||
name: { required: true, trigger: 'change' },
|
name: { required: true, trigger: 'change' },
|
||||||
remark: { required: false, trigger: 'change' },
|
description: { required: false, trigger: 'change' },
|
||||||
index: { required: false, type: 'number', trigger: 'change' },
|
index: { required: false, type: 'number', trigger: 'change' },
|
||||||
content: { required: true, trigger: 'change' }
|
command: { required: true, trigger: 'change' }
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -219,10 +219,10 @@ const handleCommandHost = (host) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handleExecScript = (scriptObj) => {
|
const handleExecScript = (scriptObj) => {
|
||||||
// console.log(scriptObj.content)
|
const { command } = scriptObj
|
||||||
if (!isSyncAllSession.value) return handleInputCommand(scriptObj.content)
|
if (!isSyncAllSession.value) return handleInputCommand(command)
|
||||||
terminalRefs.value.forEach(terminalRef => {
|
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]
|
const curTerminalRef = terminalRefs.value[activeTabIndex.value]
|
||||||
await $nextTick()
|
await $nextTick()
|
||||||
curTerminalRef?.focusTab()
|
curTerminalRef?.focusTab()
|
||||||
curTerminalRef.inputCommand(`${ command }\n`)
|
curTerminalRef.inputCommand(`${ command }`) // \n
|
||||||
showInputCommand.value = false
|
showInputCommand.value = false
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user