refactor: Rustdesk Commands

This commit is contained in:
lejianwen
2025-01-12 21:22:29 +08:00
parent 127419e89b
commit 0e9391a4c5
7 changed files with 229 additions and 89 deletions
+69
View File
@@ -0,0 +1,69 @@
<template>
<el-card class="simple-card" shadow="hover" v-loading="form.loading">
<template #header>
<div class="card-header">
<span>ALWAYS_USE_RELAY</span>
</div>
</template>
<el-form :disabled="!canSend">
<el-form-item>
<el-switch v-model="form.option" active-value="Y" inactive-value="N"></el-switch>
</el-form-item>
<el-form-item>
<el-button @click="get">{{ T('Refresh') }}</el-button>
<el-button @click="save" type="primary">{{ T('Save') }}</el-button>
</el-form-item>
</el-form>
</el-card>
</template>
<script setup>
import { T } from '@/utils/i18n'
import { reactive, watch } from 'vue'
import { sendCmd } from '@/api/rustdesk'
import { ElMessage } from 'element-plus'
import { ID_TARGET } from '@/views/rustdesk/options'
const emits = defineEmits('success')
const props = defineProps({
canSend: Boolean,
})
const form = reactive({
cmd: 'aur',
option: '',
target: ID_TARGET,
value: 0,
loading: false,
})
const get = async () => {
form.loading = true
const res = await sendCmd({ cmd: 'aur', target: ID_TARGET }).catch(_ => false)
form.loading = false
if (res) {
if (res.data === 'ALWAYS_USE_RELAY: true' || res.data === 'ALWAYS_USE_RELAY: true\n') {
form.option = 'Y'
} else {
form.option = 'N'
}
}
}
const save = async () => {
const res = await sendCmd(form).catch(_ => false)
if (res) {
ElMessage.success(T('OperationSuccess'))
emits('success')
}
}
watch(() => props.canSend, (v) => {
if (v) {
get()
}
})
</script>
<style scoped lang="scss">
</style>
+1 -1
View File
@@ -36,8 +36,8 @@
import { reactive, watch } from 'vue' import { reactive, watch } from 'vue'
import { sendCmd } from '@/api/rustdesk' import { sendCmd } from '@/api/rustdesk'
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import { RELAY_TARGET } from '@/views/rustdesk/options'
const RELAY_TARGET = '21117'
const props = defineProps({ const props = defineProps({
canSend: Boolean, canSend: Boolean,
}) })
+1 -1
View File
@@ -36,8 +36,8 @@
import { reactive, watch } from 'vue' import { reactive, watch } from 'vue'
import { sendCmd } from '@/api/rustdesk' import { sendCmd } from '@/api/rustdesk'
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import { RELAY_TARGET } from '@/views/rustdesk/options'
const RELAY_TARGET = '21117'
const props = defineProps({ const props = defineProps({
canSend: Boolean, canSend: Boolean,
}) })
+22 -87
View File
@@ -19,38 +19,9 @@
> >
<el-tab-pane :label="T('Simple')" name="Simple"> <el-tab-pane :label="T('Simple')" name="Simple">
<el-space> <el-space>
<el-card class="simple-card" shadow="hover" v-loading="rsForm.loading"> <RelayServers ref="rs" :can-send="canSendCmd(ID_TARGET)"></RelayServers>
<template #header> <alwaysUseRelay :can-send="canSendCmd(ID_TARGET)" @success="handleAlwaysUseRelaySuccess"></alwaysUseRelay>
<div class="card-header"> <mustLogin :can-send="canSendCmd(ID_TARGET)"></mustLogin>
<span>RELAY_SERVERS</span>
</div>
</template>
<el-form :disabled="!canSendCmd(rsForm.target)">
<el-form-item>
<el-input v-model="rsForm.option"></el-input>
</el-form-item>
<el-form-item>
<el-button @click="getRS">{{ T('Refresh') }}</el-button>
<el-button @click="saveRS" type="primary">{{ T('Save') }}</el-button>
</el-form-item>
</el-form>
</el-card>
<el-card class="simple-card" shadow="hover" v-loading="aurForm.loading">
<template #header>
<div class="card-header">
<span>ALWAYS_USE_RELAY</span>
</div>
</template>
<el-form :disabled="!canSendCmd(aurForm.target)">
<el-form-item>
<el-switch v-model="aurForm.option" active-value="Y" inactive-value="N"></el-switch>
</el-form-item>
<el-form-item>
<el-button @click="getAUR">{{ T('Refresh') }}</el-button>
<el-button @click="saveAUR" type="primary">{{ T('Save') }}</el-button>
</el-form-item>
</el-form>
</el-card>
<blocklist :can-send="canSendCmd(RELAY_TARGET)"></blocklist> <blocklist :can-send="canSendCmd(RELAY_TARGET)"></blocklist>
<blacklist :can-send="canSendCmd(RELAY_TARGET)"></blacklist> <blacklist :can-send="canSendCmd(RELAY_TARGET)"></blacklist>
</el-space> </el-space>
@@ -63,12 +34,12 @@
<el-form-item> <el-form-item>
<el-button type="primary" @click="handlerQuery">{{ T('Filter') }}</el-button> <el-button type="primary" @click="handlerQuery">{{ T('Filter') }}</el-button>
<el-button type="danger" @click="toAdd">{{ T('Add') }}</el-button> <el-button type="danger" @click="toAdd">{{ T('Add') }}</el-button>
<el-button type="success" :disabled="!canSendIdServerCmd" @click="showCmd({cmd:'',option:''})">{{ T('Send') }}</el-button> <el-button type="success" :disabled="!canSendIdServerCmd" @click="showCmd({cmd:'',option:'',target:ID_TARGET})">{{ T('Send') }} To Id</el-button>
<el-button type="success" :disabled="!canSendRelayServerCmd" @click="showCmd({cmd:'',option:'',target:RELAY_TARGET})">{{ T('Send') }} To Relay</el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
</el-card> </el-card>
<el-card class="list-body" shadow="hover"> <el-card class="list-body" shadow="hover">
<el-table :data="listRes.list" v-loading="listRes.loading" border> <el-table :data="listRes.list" v-loading="listRes.loading" border>
<el-table-column prop="cmd" label="cmd" align="center"></el-table-column> <el-table-column prop="cmd" label="cmd" align="center"></el-table-column>
<el-table-column prop="alias" label="alias" align="center"></el-table-column> <el-table-column prop="alias" label="alias" align="center"></el-table-column>
@@ -144,17 +115,20 @@
<script setup> <script setup>
import { list, sendCmd, remove, create, update } from '@/api/rustdesk' import { create, list, remove, sendCmd, update } from '@/api/rustdesk'
import { onMounted, reactive, ref } from 'vue' import { onMounted, reactive, ref } from 'vue'
import { T } from '@/utils/i18n' import { T } from '@/utils/i18n'
import { ElMessage, ElMessageBox } from 'element-plus' import { ElMessage, ElMessageBox } from 'element-plus'
import blocklist from '@/views/rustdesk/blocklist.vue' import blocklist from '@/views/rustdesk/blocklist.vue'
import blacklist from '@/views/rustdesk/blacklist.vue' import blacklist from '@/views/rustdesk/blacklist.vue'
import alwaysUseRelay from '@/views/rustdesk/always_use_relay.vue'
import RelayServers from '@/views/rustdesk/relay_servers.vue'
import mustLogin from '@/views/rustdesk/must_login.vue'
import { ID_TARGET, RELAY_TARGET } from '@/views/rustdesk/options'
const ID_TARGET = '21115'
const RELAY_TARGET = '21117'
const activeName = ref('Simple') const activeName = ref('Simple')
const canSendIdServerCmd = ref(false) const canSendIdServerCmd = ref(false)
const checkCanSendIdServerCmd = async () => { const checkCanSendIdServerCmd = async () => {
const res = await sendCmd({ cmd: 'h', target: ID_TARGET }).catch(_ => false) const res = await sendCmd({ cmd: 'h', target: ID_TARGET }).catch(_ => false)
@@ -163,17 +137,20 @@
const refreshCanSendIdServerCmd = () => { const refreshCanSendIdServerCmd = () => {
checkCanSendIdServerCmd().then(_ => { checkCanSendIdServerCmd().then(_ => {
if (canSendIdServerCmd.value) { if (canSendIdServerCmd.value) {
getAUR()
getRS()
} }
}) })
} }
onMounted(refreshCanSendIdServerCmd) onMounted(refreshCanSendIdServerCmd)
const canSendRelayServerCmd = ref(false) const canSendRelayServerCmd = ref(false)
const canControlMustLogin = ref(false)
const checkCanSendRelayServerCmd = async () => { const checkCanSendRelayServerCmd = async () => {
const res = await sendCmd({ cmd: 'h', target: RELAY_TARGET }).catch(_ => false) const res = await sendCmd({ cmd: 'h', target: RELAY_TARGET }).catch(_ => false)
canSendRelayServerCmd.value = !!res.data canSendRelayServerCmd.value = !!res.data
if (canSendRelayServerCmd.value) {
const commands = res.data.split('\n').filter(i => i)
canControlMustLogin.value = commands.some(i => i.includes('must-login'))
}
} }
const refreshCanSendRelayServerCmd = () => { const refreshCanSendRelayServerCmd = () => {
checkCanSendRelayServerCmd().then(_ => { checkCanSendRelayServerCmd().then(_ => {
@@ -183,6 +160,12 @@
} }
onMounted(refreshCanSendRelayServerCmd) onMounted(refreshCanSendRelayServerCmd)
const rs = ref(null)
console.log(rs)
const handleAlwaysUseRelaySuccess = () => {
rs.value.save()
}
const canSendCmd = (target) => { const canSendCmd = (target) => {
if (target === ID_TARGET) { if (target === ID_TARGET) {
return canSendIdServerCmd.value return canSendIdServerCmd.value
@@ -193,54 +176,6 @@
return false return false
} }
const rsForm = reactive({
cmd: 'rs',
option: '',
target: ID_TARGET,
loading: false,
})
const getRS = async () => {
rsForm.loading = true
const res = await sendCmd({ cmd: 'rs', target: ID_TARGET }).catch(_ => false)
rsForm.loading = false
if (res) {
const data = res.data.split('\n').filter(i => i)
rsForm.option = data.join(',')
}
}
const saveRS = async () => {
const res = await sendCmd(rsForm).catch(_ => false)
if (res) {
ElMessage.success(T('OperationSuccess'))
}
}
const aurForm = reactive({
cmd: 'aur',
option: '',
target: ID_TARGET,
value: 0,
loading: false,
})
const getAUR = async () => {
aurForm.loading = true
const res = await sendCmd({ cmd: 'aur', target: ID_TARGET }).catch(_ => false)
aurForm.loading = false
if (res) {
if (res.data === 'ALWAYS_USE_RELAY: true' || res.data === 'ALWAYS_USE_RELAY: true\n') {
aurForm.option = 'Y'
} else {
aurForm.option = 'N'
}
}
}
const saveAUR = async () => {
const res = await sendCmd(aurForm).catch(_ => false)
if (res) {
ElMessage.success(T('OperationSuccess'))
}
}
const listRes = reactive({ const listRes = reactive({
list: [], total: 0, loading: false, list: [], total: 0, loading: false,
}) })
+67
View File
@@ -0,0 +1,67 @@
<template>
<el-card class="simple-card" shadow="hover" v-loading="form.loading">
<template #header>
<div class="card-header">
<span>MUST_LOGIN</span>
</div>
</template>
<el-form :disabled="!canSend">
<el-form-item>
<el-switch v-model="form.option" active-value="Y" inactive-value="N"></el-switch>
</el-form-item>
<el-form-item>
<el-button @click="get">{{ T('Refresh') }}</el-button>
<el-button @click="save" type="primary">{{ T('Save') }}</el-button>
</el-form-item>
</el-form>
</el-card>
</template>
<script setup>
import { T } from '@/utils/i18n'
import { reactive, watch } from 'vue'
import { sendCmd } from '@/api/rustdesk'
import { ElMessage } from 'element-plus'
import { ID_TARGET } from '@/views/rustdesk/options'
const props = defineProps({
canSend: Boolean,
})
const form = reactive({
cmd: 'ml',
option: '',
target: ID_TARGET,
value: 0,
loading: false,
})
const get = async () => {
form.loading = true
const res = await sendCmd({ cmd: 'ml', target: ID_TARGET }).catch(_ => false)
form.loading = false
if (res) {
if (res.data === 'MUST_LOGIN: true' || res.data === 'MUST_LOGIN: true\n') {
form.option = 'Y'
} else {
form.option = 'N'
}
}
}
const save = async () => {
const res = await sendCmd(form).catch(_ => false)
if (res) {
ElMessage.success(T('OperationSuccess'))
}
}
watch(() => props.canSend, (v) => {
if (v) {
get()
}
})
</script>
<style scoped lang="scss">
</style>
+4
View File
@@ -0,0 +1,4 @@
export const ID_TARGET = '21115'
export const RELAY_TARGET = '21117'
+65
View File
@@ -0,0 +1,65 @@
<template>
<el-card class="simple-card" shadow="hover" v-loading="form.loading">
<template #header>
<div class="card-header">
<span>RELAY_SERVERS</span>
</div>
</template>
<el-form :disabled="!canSend">
<el-form-item>
<el-input v-model="form.option"></el-input>
</el-form-item>
<el-form-item>
<el-button @click="get">{{ T('Refresh') }}</el-button>
<el-button @click="save" type="primary">{{ T('Save') }}</el-button>
</el-form-item>
</el-form>
</el-card>
</template>
<script setup>
import { T } from '@/utils/i18n'
import { reactive, watch } from 'vue'
import { sendCmd } from '@/api/rustdesk'
import { ElMessage } from 'element-plus'
import { ID_TARGET } from '@/views/rustdesk/options'
const props = defineProps({
canSend: Boolean,
})
const form = reactive({
cmd: 'rs',
option: '',
target: ID_TARGET,
loading: false,
})
const get = async () => {
form.loading = true
const res = await sendCmd({ cmd: 'rs', target: ID_TARGET }).catch(_ => false)
form.loading = false
if (res) {
const data = res.data.split('\n').filter(i => i)
form.option = data.join(',')
}
}
const save = async () => {
const res = await sendCmd(form).catch(_ => false)
if (res) {
ElMessage.success(T('OperationSuccess'))
}
}
watch(() => props.canSend, (v) => {
if (v) {
get()
}
})
//为了在设置always_use_relay之后自动重新保存,防止被重置
defineExpose({
save,
});
</script>
<style scoped lang="scss">
</style>