From d5f81773a8a26b7ce88c14cc21d5a2e587c644f3 Mon Sep 17 00:00:00 2001 From: Yukino Song Date: Wed, 22 Jan 2025 22:28:57 +0800 Subject: [PATCH] Per client DO/UNDO commands frontend part - done --- src/confighttp.cpp | 3 + .../assets/web/configs/tabs/General.vue | 16 ++-- src_assets/common/assets/web/pin.html | 93 ++++++++++++++++++- .../assets/web/public/assets/locale/en.json | 4 + 4 files changed, 105 insertions(+), 11 deletions(-) diff --git a/src/confighttp.cpp b/src/confighttp.cpp index e1781ff2..a321b9bd 100644 --- a/src/confighttp.cpp +++ b/src/confighttp.cpp @@ -1223,6 +1223,9 @@ namespace confighttp { pt::ptree outputTree; outputTree.put("status", false); outputTree.add_child("named_certs", named_certs); + #ifdef _WIN32 + outputTree.put("platform", "windows"); + #endif outputTree.put("status", true); send_response(response, outputTree); } diff --git a/src_assets/common/assets/web/configs/tabs/General.vue b/src_assets/common/assets/web/configs/tabs/General.vue index 807a9cae..f89c1202 100644 --- a/src_assets/common/assets/web/configs/tabs/General.vue +++ b/src_assets/common/assets/web/configs/tabs/General.vue @@ -23,13 +23,17 @@ const serverCmdTemplate = { cmd: "" } -function addCmd(cmdArr, template) { +function addCmd(cmdArr, template, idx) { const _tpl = Object.assign({}, template); if (props.platform === 'windows') { _tpl.elevated = false; } - cmdArr.push(_tpl); + if (idx < 0) { + cmdArr.push(_tpl); + } else { + cmdArr.splice(idx + 1, 0, _tpl); + } } function removeCmd(cmdArr, index) { @@ -129,14 +133,14 @@ onMounted(() => { - - @@ -178,14 +182,14 @@ onMounted(() => { - - diff --git a/src_assets/common/assets/web/pin.html b/src_assets/common/assets/web/pin.html index ce7e002c..7086992c 100644 --- a/src_assets/common/assets/web/pin.html +++ b/src_assets/common/assets/web/pin.html @@ -104,6 +104,48 @@ + + +
+ +
{{ $t(`config.client_${cmdType}_cmd_desc`) }} {{ $t('_common.learn_more') }}
+ + + + + + + + + + + + + + + +
{{ $t('_common.cmd_val') }} + {{ $t('_common.run_as') }} +
+ + +
+ + +
+
+ + +
+ +
@@ -272,6 +314,7 @@ const data = () => { return { + platform: '', editingHost: false, currentTab: location.hash || '#OTP', otp: '', @@ -290,6 +333,11 @@ } } + const cmdTpl = { + cmd: '', + elevated: 'false' + } + let app = createApp({ components: { Navbar @@ -413,6 +461,17 @@ clickedApplyBanner() { this.showApplyMessage = false; }, + addCmd(arr, idx) { + const newCmd = Object.assign({}, cmdTpl); + if (idx < 0) { + arr.push(newCmd); + } else { + arr.splice(idx + 1, 0, newCmd); + } + }, + removeCmd(arr, idx) { + arr.splice(idx, 1); + }, editClient(client) { if (currentEditingClient) { this.cancelEdit(currentEditingClient); @@ -421,6 +480,10 @@ client.editing = true; client.editPerm = client.perm; client.editName = client.name; + client.edit_do = JSON.parse(JSON.stringify(client.do || [])); + client.edit_undo = JSON.parse(JSON.stringify(client.undo || [])); + + console.log(client.do, client.undo) }, cancelEdit(client) { client.editing = false; @@ -434,7 +497,27 @@ const editedClient = { uuid: client.uuid, name: client.editName, - perm: client.editPerm & permissionMapping._all + perm: client.editPerm & permissionMapping._all, + do: client.edit_do.reduce((filtered, {cmd: _cmd, elevated}) => { + const cmd = _cmd.trim() + if (cmd) { + filtered.push({ + cmd, + elevated + }) + } + return filtered + }, []), + undo: client.edit_undo.reduce((filtered, {cmd: _cmd, elevated}) => { + const cmd = _cmd.trim() + if (cmd) { + filtered.push({ + cmd, + elevated + }) + } + return filtered + }, []) } fetch("./api/clients/update", { credentials: 'include', @@ -515,9 +598,9 @@ fetch("./api/clients/list", { credentials: 'include' }) .then((response) => response.json()) .then((response) => { - const clientList = document.querySelector("#client-list"); if (response.status === 'true' && response.named_certs && response.named_certs.length) { - this.clients = response.named_certs.map(({name, uuid, perm, connected}) => { + this.platform = response.platform + this.clients = response.named_certs.map(({name, uuid, perm, connected, do: _do, undo}) => { const permInt = parseInt(perm, 10); return { name, @@ -525,8 +608,8 @@ perm: permInt, connected: connected === 'true', editing: false, - editPerm: permInt, - editName: name + do: _do, + undo } }) currentEditingClient = null; diff --git a/src_assets/common/assets/web/public/assets/locale/en.json b/src_assets/common/assets/web/public/assets/locale/en.json index 292141a4..b0bb8525 100644 --- a/src_assets/common/assets/web/public/assets/locale/en.json +++ b/src_assets/common/assets/web/public/assets/locale/en.json @@ -169,6 +169,10 @@ "channels": "Maximum Connected Clients", "channels_desc_1": "Apollo can allow a single streaming session to be shared with multiple clients simultaneously.", "channels_desc_2": "Some hardware encoders may have limitations that reduce performance with multiple streams.", + "client_do_cmd": "Client connect commands", + "client_do_cmd_desc": "Commands to be executed when client connects. All of the commands are executed detached.", + "client_undo_cmd": "Client disconnect commands", + "client_undo_cmd_desc": "Commands to be executed when client disconnects. All of the commands are executed detached.", "coder_cabac": "cabac -- context adaptive binary arithmetic coding - higher quality", "coder_cavlc": "cavlc -- context adaptive variable-length coding - faster decode", "configuration": "Configuration",