Fix command sends to server

This commit is contained in:
amcmanu3 2023-03-02 13:24:07 -05:00
parent d473a6ccf4
commit 81e4e7e450
2 changed files with 22 additions and 16 deletions

View File

@ -14,7 +14,8 @@
<div class="col-12">
<div class="page-header">
<h4 class="page-title">
{{ translate('serverDetails', 'serverDetails', data['lang']) }} - {{ data['server_stats']['server_id']['server_name'] }}
{{ translate('serverDetails', 'serverDetails', data['lang']) }} - {{
data['server_stats']['server_id']['server_name'] }}
<br />
<small>UUID: {{ data['server_stats']['server_id']['server_uuid'] }}</small>
</h4>
@ -76,10 +77,14 @@
<li class="playerItem">
<h3>{{ player }}</h3>
<div class="buttons">
<button onclick="send_command_to_server('ban {{ player }}')" type="button" class="btn btn-danger">Ban</button>
<button onclick="send_command_to_server('kick {{ player }}')" type="button" class="btn btn-outline-danger">Kick</button>
<button onclick="send_command_to_server('op {{ player }}')" type="button" class="btn btn-warning">OP</button>
<button onclick="send_command_to_server('deop {{ player }}')" type="button" class="btn btn-outline-warning">De-OP</button>
<button onclick="send_command_to_server('ban {{ player }}')" type="button"
class="btn btn-danger">Ban</button>
<button onclick="send_command_to_server('kick {{ player }}')" type="button"
class="btn btn-outline-danger">Kick</button>
<button onclick="send_command_to_server('op {{ player }}')" type="button"
class="btn btn-warning">OP</button>
<button onclick="send_command_to_server('deop {{ player }}')" type="button"
class="btn btn-outline-warning">De-OP</button>
</div>
</li>
{% end %}
@ -136,21 +141,22 @@
});
function send_command_to_server(command) {
async function send_command_to_server(command) {
console.log(command)
var token = getCookie("_xsrf")
console.log('sending command: ' + command)
$.ajax({
type: "POST",
headers: { 'X-XSRFToken': token },
url: '/ajax/send_command?id=' + serverId,
data: { command },
success: function (data) {
console.log("got response:");
console.log(data);
let res = await fetch(`/api/v2/servers/${serverId}/stdin`, {
method: 'POST',
headers: {
'X-XSRFToken': token
},
body: command,
});
let responseData = await res.text();
console.log("got response:");
console.log(responseData);
}

View File

@ -311,12 +311,12 @@
formdata.append('command', serverCommand)
console.log('sending command: ' + serverCommand)
let res = await fetch("/ajax/send_command?id=" + serverId, {
let res = await fetch(`/api/v2/servers/${serverId}/stdin`, {
method: 'POST',
headers: {
'X-XSRFToken': token
},
body: formdata,
body: serverCommand,
});
let responseData = await res.text();