2020-09-01 17:29:39 +00:00
|
|
|
{% extends ../base.html %}
|
|
|
|
|
|
|
|
{% block meta %}
|
|
|
|
{% end %}
|
|
|
|
|
2021-09-29 02:25:47 +00:00
|
|
|
{% block title %}Crafty Controller - {{ translate('serverDetails', 'serverDetails', data['lang']) }}{% end %}
|
2020-09-01 17:29:39 +00:00
|
|
|
|
|
|
|
{% block content %}
|
|
|
|
|
|
|
|
<div class="content-wrapper">
|
|
|
|
|
2022-01-21 22:50:04 +00:00
|
|
|
<!-- Page Title Header Starts-->
|
2020-09-01 17:29:39 +00:00
|
|
|
<div class="row page-title-header">
|
|
|
|
<div class="col-12">
|
|
|
|
<div class="page-header">
|
|
|
|
<h4 class="page-title">
|
2022-09-25 21:52:01 +00:00
|
|
|
{{ translate('serverDetails', 'serverDetails', data['lang']) }} - {{
|
|
|
|
data['server_stats']['server_id']['server_name'] }}
|
2022-01-21 22:50:04 +00:00
|
|
|
<br />
|
2023-11-01 17:44:56 +00:00
|
|
|
<small>UUID: {{ data['server_stats']['server_id']['server_id'] }}</small>
|
2020-09-01 17:29:39 +00:00
|
|
|
</h4>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<!-- Page Title Header Ends-->
|
|
|
|
|
2022-01-21 22:50:04 +00:00
|
|
|
{% include "parts/details_stats.html %}
|
2020-09-02 01:30:39 +00:00
|
|
|
|
2020-09-01 17:29:39 +00:00
|
|
|
<div class="row">
|
|
|
|
|
|
|
|
<div class="col-sm-12 grid-margin">
|
|
|
|
<div class="card">
|
|
|
|
<div class="card-body pt-0">
|
2022-03-26 22:37:08 +00:00
|
|
|
|
|
|
|
<span class="d-none d-sm-block">
|
|
|
|
{% include "parts/server_controls_list.html %}
|
|
|
|
</span>
|
|
|
|
<span class="d-block d-sm-none">
|
|
|
|
{% include "parts/m_server_controls_list.html %}
|
|
|
|
</span>
|
2022-01-21 22:50:04 +00:00
|
|
|
|
|
|
|
<div class="col-md-12">
|
2023-02-02 22:48:12 +00:00
|
|
|
<button id="to-bottom" style="visibility: hidden; float: right;" class="btn btn-outline-success" hidden>{{
|
2022-09-25 21:52:01 +00:00
|
|
|
translate('serverDetails', 'reset', data['lang']) }}</button>
|
2023-02-02 22:48:12 +00:00
|
|
|
|
2022-01-21 22:50:04 +00:00
|
|
|
<div class="input-group">
|
2022-09-25 21:52:01 +00:00
|
|
|
<div id="virt_console" class=""
|
2023-09-04 23:22:11 +00:00
|
|
|
style="width: 100%; font-size: .8em; padding: 5px 10px; border: 1px solid var(--outline); background-color:var(--card-banner-bg);height:500px; overflow: scroll;">
|
2022-09-25 21:52:01 +00:00
|
|
|
</div>
|
2020-09-02 01:30:39 +00:00
|
|
|
</div>
|
2022-01-21 22:50:04 +00:00
|
|
|
<br />
|
2020-09-01 17:29:39 +00:00
|
|
|
|
2022-01-21 22:50:04 +00:00
|
|
|
<div style="gap: 0.5rem;" class="input-group flex-wrap">
|
2022-09-25 21:52:01 +00:00
|
|
|
<input style="min-width: 10rem;" type="text" class="form-control" id="server_command"
|
2023-09-04 23:22:11 +00:00
|
|
|
name="server_command" placeholder="{{ translate('serverTerm', 'commandInput', data['lang']) }}"
|
|
|
|
autofocus="">
|
2022-01-21 22:50:04 +00:00
|
|
|
<span class="input-group-btn ml-5">
|
|
|
|
<button id="submit" class="btn btn-sm btn-info" type="button">{{ translate('serverTerm', 'sendCommand',
|
|
|
|
data['lang']) }}</button>
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
{% if data['permissions']['Commands'] in data['user_permissions'] %}
|
2022-11-19 20:45:29 +00:00
|
|
|
{% if data['importing'] and data['server_stats']['running']%}
|
|
|
|
<div id="update_control_buttons"
|
2023-09-04 23:22:11 +00:00
|
|
|
class="mt-4 flex-wrap d-flex justify-content-between justify-content-md-center align-items-center px-5 px-md-0"
|
|
|
|
style="visibility: visible">
|
2022-11-19 20:45:29 +00:00
|
|
|
<button onclick="" id="start-btn" style="max-width: 7rem;"
|
2023-09-04 23:22:11 +00:00
|
|
|
class="btn btn-warning m-1 flex-grow-1 disabled"><i
|
|
|
|
class="fa fa-spinner fa-spin"></i> {{translate('serverTerm', 'installing', data['lang'])
|
|
|
|
}}</button>
|
2022-11-19 20:45:29 +00:00
|
|
|
<button onclick="" id="restart-btn" style="max-width: 7rem;"
|
2023-09-04 23:22:11 +00:00
|
|
|
class="btn btn-outline-primary m-1 flex-grow-1 disabled">{% raw translate('serverTerm', 'restart',
|
2022-11-19 20:45:29 +00:00
|
|
|
data['lang']) %}</button>
|
|
|
|
<button onclick="" id="stop-btn" style="max-width: 7rem;"
|
2023-09-04 23:22:11 +00:00
|
|
|
class="btn btn-danger m-1 flex-grow-1 disabled">{{ translate('serverTerm', 'stop', data['lang'])
|
2022-11-19 20:45:29 +00:00
|
|
|
}}</button>
|
|
|
|
</div>
|
|
|
|
{% elif data['server_stats']['updating']%}
|
2022-09-25 21:52:01 +00:00
|
|
|
<div id="update_control_buttons"
|
2023-09-04 23:22:11 +00:00
|
|
|
class="mt-4 flex-wrap d-flex justify-content-between justify-content-md-center align-items-center px-5 px-md-0"
|
|
|
|
style="visibility: visible">
|
2022-09-25 21:52:01 +00:00
|
|
|
<button onclick="" id="start-btn" style="max-width: 7rem;"
|
2023-09-04 23:22:11 +00:00
|
|
|
class="btn btn-warning m-1 flex-grow-1 disabled"><i class="fa fa-spinner fa-spin"></i> {{
|
2022-09-25 21:52:01 +00:00
|
|
|
translate('serverTerm', 'updating', data['lang']) }}</button>
|
|
|
|
<button onclick="" id="restart-btn" style="max-width: 7rem;"
|
2023-09-04 23:22:11 +00:00
|
|
|
class="btn btn-outline-primary m-1 flex-grow-1 disabled">{% raw translate('serverTerm', 'restart',
|
2022-09-25 21:52:01 +00:00
|
|
|
data['lang']) %}</button>
|
|
|
|
<button onclick="" id="stop-btn" style="max-width: 7rem;"
|
2023-09-04 23:22:11 +00:00
|
|
|
class="btn btn-danger m-1 flex-grow-1 disabled">{{ translate('serverTerm', 'stop', data['lang'])
|
2022-09-25 21:52:01 +00:00
|
|
|
}}</button>
|
2022-01-21 22:50:04 +00:00
|
|
|
</div>
|
|
|
|
{% elif data['waiting_start'] %}
|
2022-09-25 21:52:01 +00:00
|
|
|
<div id="control_buttons"
|
2023-09-04 23:22:11 +00:00
|
|
|
class="mt-4 flex-wrap d-flex justify-content-between justify-content-md-center align-items-center px-5 px-md-0"
|
|
|
|
style="visibility: visible">
|
2022-09-25 21:52:01 +00:00
|
|
|
<button onclick="" id="start-btn" style="max-width: 7rem; white-space: nowrap;"
|
2023-09-04 23:22:11 +00:00
|
|
|
class="btn btn-secondary m-1 flex-grow-1 disabled" data-toggle="tooltip"
|
|
|
|
title="{{ translate('serverTerm', 'delay-explained', data['lang'])}}">{{ translate('serverTerm',
|
2022-09-25 21:52:01 +00:00
|
|
|
'starting', data['lang']) }}</button>
|
|
|
|
<button onclick="" id="restart-btn" style="max-width: 7rem;"
|
2023-09-04 23:22:11 +00:00
|
|
|
class="btn btn-outline-primary m-1 flex-grow-1 disabled">{% raw translate('serverTerm', 'restart',
|
2022-09-25 21:52:01 +00:00
|
|
|
data['lang']) %}</button>
|
|
|
|
<button onclick="" id="stop-btn" style="max-width: 7rem;"
|
2023-09-04 23:22:11 +00:00
|
|
|
class="btn btn-danger m-1 flex-grow-1 disabled">{{ translate('serverTerm', 'stop', data['lang'])
|
2022-09-25 21:52:01 +00:00
|
|
|
}}</button>
|
2022-01-21 22:50:04 +00:00
|
|
|
</div>
|
2022-08-17 18:48:05 +00:00
|
|
|
{% elif data['importing'] %}
|
2022-09-25 21:52:01 +00:00
|
|
|
<div id="control_buttons"
|
2023-09-04 23:22:11 +00:00
|
|
|
class="mt-4 flex-wrap d-flex justify-content-between justify-content-md-center align-items-center px-5 px-md-0"
|
|
|
|
style="visibility: visible">
|
2022-09-25 21:52:01 +00:00
|
|
|
<button onclick="" id="start-btn" style="max-width: 12rem; white-space: nowrap;"
|
2023-09-04 23:22:11 +00:00
|
|
|
class="btn btn-secondary m-1 flex-grow-1 disabled"><i class="fa fa-spinner fa-spin"></i> {{
|
2022-09-25 21:52:01 +00:00
|
|
|
translate('serverTerm', 'importing',
|
2022-03-26 22:37:08 +00:00
|
|
|
data['lang']) }}</button>
|
2022-09-25 21:52:01 +00:00
|
|
|
<button onclick="" id="restart-btn" style="max-width: 7rem;"
|
2023-09-04 23:22:11 +00:00
|
|
|
class="btn btn-outline-primary m-1 flex-grow-1 disabled">{% raw translate('serverTerm', 'restart',
|
2022-09-25 21:52:01 +00:00
|
|
|
data['lang']) %}</button>
|
|
|
|
<button onclick="" id="stop-btn" style="max-width: 7rem;"
|
2023-09-04 23:22:11 +00:00
|
|
|
class="btn btn-danger m-1 flex-grow-1 disabled">{{ translate('serverTerm', 'stop', data['lang'])
|
2022-09-25 21:52:01 +00:00
|
|
|
}}</button>
|
2022-03-26 22:37:08 +00:00
|
|
|
</div>
|
2022-01-21 22:50:04 +00:00
|
|
|
{% else %}
|
2022-09-25 21:52:01 +00:00
|
|
|
<div id="control_buttons"
|
2023-09-04 23:22:11 +00:00
|
|
|
class="mt-4 flex-wrap d-flex justify-content-between justify-content-md-center align-items-center px-5 px-md-0"
|
|
|
|
style="visibility: visible">
|
2022-09-25 21:52:01 +00:00
|
|
|
<button onclick="send_command(serverId, 'start_server');" id="start-btn" style="max-width: 7rem;"
|
2023-09-04 23:22:11 +00:00
|
|
|
class="btn btn-primary m-1 flex-grow-1">{{ translate('serverTerm', 'start', data['lang']) }}</button>
|
2022-09-25 21:52:01 +00:00
|
|
|
<button onclick="send_command(serverId, 'restart_server');" id="restart-btn" style="max-width: 7rem;"
|
2023-09-04 23:22:11 +00:00
|
|
|
class="btn btn-outline-primary m-1 flex-grow-1">{% raw translate('serverTerm', 'restart', data['lang'])
|
2022-09-25 21:52:01 +00:00
|
|
|
%}</button>
|
|
|
|
<button onclick="send_command(serverId, 'stop_server');" id="stop-btn" style="max-width: 7rem;"
|
2023-09-04 23:22:11 +00:00
|
|
|
class="btn btn-danger m-1 flex-grow-1">{{ translate('serverTerm', 'stop', data['lang']) }}</button>
|
2022-01-21 22:50:04 +00:00
|
|
|
</div>
|
|
|
|
{% end %}
|
|
|
|
{% end %}
|
|
|
|
</div>
|
2020-09-01 17:29:39 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-08-24 00:24:40 +00:00
|
|
|
</div>
|
2020-09-01 17:29:39 +00:00
|
|
|
</div>
|
2021-08-21 22:52:46 +00:00
|
|
|
<style>
|
2022-01-21 22:50:04 +00:00
|
|
|
#virt_console::-webkit-scrollbar {
|
|
|
|
display: none;
|
|
|
|
}
|
2021-08-21 22:52:46 +00:00
|
|
|
|
2022-01-21 22:50:04 +00:00
|
|
|
/* Hide scrollbar for IE, Edge and Firefox */
|
|
|
|
#virt_console {
|
|
|
|
-ms-overflow-style: none;
|
|
|
|
/* IE and Edge */
|
|
|
|
scrollbar-width: none;
|
|
|
|
/* Firefox */
|
2023-09-04 23:22:11 +00:00
|
|
|
font-family: Consolas, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace;
|
2023-05-22 20:58:02 +00:00
|
|
|
white-space: pre-wrap;
|
2022-01-21 22:50:04 +00:00
|
|
|
}
|
2021-08-21 22:52:46 +00:00
|
|
|
</style>
|
2020-09-01 17:29:39 +00:00
|
|
|
<!-- content-wrapper ends -->
|
|
|
|
|
|
|
|
{% end %}
|
|
|
|
|
|
|
|
{% block js %}
|
|
|
|
<script>
|
2020-12-12 16:44:40 +00:00
|
|
|
|
2022-02-27 17:26:54 +00:00
|
|
|
const serverId = new URLSearchParams(document.location.search).get('id')
|
|
|
|
|
2024-01-28 21:20:58 +00:00
|
|
|
async function send_command(serverId, command) {
|
2022-01-21 22:50:04 +00:00
|
|
|
if (command == 'start_server') {
|
|
|
|
startBtn.setAttribute('disabled', 'disabled');
|
|
|
|
restartBtn.removeAttribute('disabled');
|
|
|
|
stopBtn.removeAttribute('disabled');
|
|
|
|
}
|
|
|
|
if (command == 'stop_server') {
|
|
|
|
startBtn.removeAttribute('disabled');
|
2021-08-21 19:17:07 +00:00
|
|
|
restartBtn.setAttribute('disabled', 'disabled');
|
|
|
|
stopBtn.setAttribute('disabled', 'disabled');
|
2020-12-12 16:44:40 +00:00
|
|
|
}
|
2022-01-21 22:50:04 +00:00
|
|
|
//<!-- this getCookie function is in base.html-->
|
2023-09-04 23:22:11 +00:00
|
|
|
const token = getCookie("_xsrf");
|
2022-01-21 22:50:04 +00:00
|
|
|
|
2024-01-28 21:20:58 +00:00
|
|
|
let res = await fetch(`/api/v2/servers/${serverId}/action/${command}`, {
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
'token': token,
|
|
|
|
},
|
2022-01-21 22:50:04 +00:00
|
|
|
});
|
2024-01-28 21:20:58 +00:00
|
|
|
let responseData = await res.json();
|
|
|
|
if (responseData.status === "ok") {
|
|
|
|
console.log("Command received successfully")
|
|
|
|
} else {
|
|
|
|
bootbox.alert({
|
|
|
|
title: responseData.status,
|
|
|
|
message: responseData.error
|
|
|
|
});
|
|
|
|
}
|
2022-01-21 22:50:04 +00:00
|
|
|
}
|
2024-01-28 21:20:58 +00:00
|
|
|
|
2022-01-21 22:50:04 +00:00
|
|
|
if (webSocket) {
|
|
|
|
webSocket.on('update_button_status', function (updateButton) {
|
|
|
|
if (updateButton.isUpdating) {
|
2022-02-27 17:26:54 +00:00
|
|
|
if (updateButton.server_id == serverId) {
|
2022-03-26 22:37:08 +00:00
|
|
|
console.log(updateButton.isUpdating)
|
|
|
|
document.getElementById('control_buttons').innerHTML = '<button onclick="" id="start-btn" style="max-width: 7rem;" class="btn btn-primary m-1 flex-grow-1">{{ translate("serverTerm", "updating", data["lang"]) }}</button><button onclick="" id="restart-btn" style="max-width: 7rem;" class="btn btn-outline-primary m-1 flex-grow-1">{% raw translate("serverTerm", "restart", data["lang"]) %}</button><button onclick="" id="stop-btn" style="max-width: 7rem;" class="btn btn-danger m-1 flex-grow-1 disabled">{{ translate("serverTerm", "stop", data["lang"]) }}</button>';
|
|
|
|
}
|
|
|
|
}
|
2023-09-05 00:05:25 +00:00
|
|
|
else if (updateButton.server_id == serverId) {
|
2022-03-26 22:37:08 +00:00
|
|
|
window.location.reload()
|
|
|
|
document.getElementById('update_control_buttons').innerHTML = '<button onclick="send_command(serverId, "start_server");" id="start-btn" style="max-width: 7rem;" class="btn btn-primary m-1 flex-grow-1">{{ translate("serverTerm", "start", data["lang"]) }}</button><button onclick="send_command(serverId, "restart_server");" id="restart-btn" style="max-width: 7rem;" class="btn btn-outline-primary m-1 flex-grow-1">{% raw translate("serverTerm", "restart", data["lang"]) %}</button><button onclick="" id="stop-btn" style="max-width: 7rem;" class="btn btn-danger m-1 flex-grow-1 disabled">{{ translate("serverTerm", "stop", data["lang"]) }}</button>';
|
|
|
|
}
|
2022-01-21 22:50:04 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
// Convert running to lower case (example: 'True' converts to 'true') and
|
|
|
|
// then to boolean via JSON.parse()
|
2022-02-27 17:26:54 +00:00
|
|
|
let online = JSON.parse("{{ data['server_stats']['running'] }}".toLowerCase());
|
2022-01-21 22:50:04 +00:00
|
|
|
|
|
|
|
let startBtn = document.querySelector('#start-btn');
|
|
|
|
let restartBtn = document.querySelector('#restart-btn');
|
|
|
|
let stopBtn = document.querySelector('#stop-btn');
|
|
|
|
|
2022-02-27 17:26:54 +00:00
|
|
|
//{% if data['permissions']['Commands'] in data['user_permissions'] %}
|
2022-01-21 22:50:04 +00:00
|
|
|
if (online) {
|
|
|
|
startBtn.setAttribute('disabled', 'disabled');
|
|
|
|
restartBtn.removeAttribute('disabled');
|
|
|
|
stopBtn.removeAttribute('disabled');
|
|
|
|
} else {
|
|
|
|
startBtn.removeAttribute('disabled');
|
|
|
|
restartBtn.setAttribute('disabled', 'disabled');
|
|
|
|
stopBtn.setAttribute('disabled', 'disabled');
|
|
|
|
}
|
2022-03-04 00:36:36 +00:00
|
|
|
|
|
|
|
if (webSocket) {
|
2022-03-26 22:37:08 +00:00
|
|
|
webSocket.on('send_start_reload', function () {
|
|
|
|
location.reload()
|
|
|
|
});
|
|
|
|
}
|
2022-02-27 17:26:54 +00:00
|
|
|
//{% end %}
|
2022-01-21 22:50:04 +00:00
|
|
|
|
2023-09-04 17:54:24 +00:00
|
|
|
async function get_server_log() {
|
2023-09-04 23:22:11 +00:00
|
|
|
const token = getCookie("_xsrf")
|
|
|
|
let colors = true;
|
2023-09-04 17:54:24 +00:00
|
|
|
let res = await fetch(`/api/v2/servers/${serverId}/logs?colors=${colors}`, {
|
2023-09-04 23:22:11 +00:00
|
|
|
method: 'GET',
|
|
|
|
headers: {
|
|
|
|
'X-XSRFToken': token
|
|
|
|
},
|
|
|
|
});
|
|
|
|
let responseData = await res.json();
|
2023-09-05 00:05:25 +00:00
|
|
|
let html = ``
|
2023-09-04 23:22:11 +00:00
|
|
|
if (responseData.status === "ok") {
|
2023-09-05 01:14:03 +00:00
|
|
|
for (let value of responseData.data) {
|
|
|
|
html += `<span class='box'>${value}<br /></span>`
|
2023-09-04 17:54:24 +00:00
|
|
|
}
|
2023-09-04 23:22:11 +00:00
|
|
|
console.log('Got Log From Server')
|
|
|
|
$('#virt_console').html(html);
|
|
|
|
scrollConsole();
|
|
|
|
} else {
|
|
|
|
|
|
|
|
bootbox.alert({
|
|
|
|
title: responseData.status,
|
|
|
|
message: responseData.error
|
|
|
|
});
|
|
|
|
}
|
2021-07-26 22:43:57 +00:00
|
|
|
}
|
2020-12-12 16:44:40 +00:00
|
|
|
|
|
|
|
|
2022-01-21 22:50:04 +00:00
|
|
|
|
|
|
|
function new_line_handler(data) {
|
|
|
|
$('#virt_console').append(data.line)
|
|
|
|
const elem = document.getElementById('virt_console');
|
2022-09-25 21:52:01 +00:00
|
|
|
try {
|
2022-09-20 00:17:02 +00:00
|
|
|
if (!scrolled) {
|
|
|
|
scrollConsole();
|
|
|
|
}
|
2022-09-25 21:52:01 +00:00
|
|
|
} catch {
|
2022-09-20 00:17:02 +00:00
|
|
|
scrollConsole();
|
2020-09-02 01:30:39 +00:00
|
|
|
}
|
2022-01-21 22:50:04 +00:00
|
|
|
}
|
2020-09-02 01:30:39 +00:00
|
|
|
|
2022-01-21 22:50:04 +00:00
|
|
|
//used to get cookies from browser - this is part of tornados xsrf protection - it's for extra security
|
|
|
|
function getCookie(name) {
|
2023-09-05 00:05:25 +00:00
|
|
|
let r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
|
2022-01-21 22:50:04 +00:00
|
|
|
return r ? r[1] : undefined;
|
|
|
|
}
|
2021-08-21 20:17:35 +00:00
|
|
|
|
2022-01-21 22:50:04 +00:00
|
|
|
$(document).ready(function () {
|
|
|
|
console.log("ready!");
|
|
|
|
get_server_log()
|
2021-08-21 20:17:35 +00:00
|
|
|
|
2022-01-21 22:50:04 +00:00
|
|
|
webSocket.on('vterm_new_line', new_line_handler)
|
|
|
|
});
|
2020-09-02 01:30:39 +00:00
|
|
|
|
2022-01-21 22:50:04 +00:00
|
|
|
$('#server_command').on('keydown', function (e) {
|
|
|
|
if (e.which == 13) {
|
|
|
|
$(this).attr("disabled", "disabled"); //Disable textbox to prevent multiple submit
|
2022-02-27 17:26:54 +00:00
|
|
|
sendConsoleCommand()
|
2022-01-21 22:50:04 +00:00
|
|
|
$(this).removeAttr("disabled"); //Enable the textbox again if needed.
|
|
|
|
$(this).focus();
|
|
|
|
}
|
|
|
|
else if (e.which == 38) {
|
|
|
|
e.preventDefault();
|
|
|
|
$('#server_command').val(cmdHistory.getPrev());
|
|
|
|
} else if (e.which == 40) {
|
|
|
|
e.preventDefault();
|
|
|
|
$('#server_command').val(cmdHistory.getNext());
|
2020-09-02 01:30:39 +00:00
|
|
|
}
|
|
|
|
|
2022-01-21 22:50:04 +00:00
|
|
|
});
|
2020-09-02 01:30:39 +00:00
|
|
|
|
2022-01-21 22:50:04 +00:00
|
|
|
$("#submit").click(function (e) {
|
|
|
|
e.preventDefault();
|
2022-02-27 17:26:54 +00:00
|
|
|
sendConsoleCommand();
|
2020-09-02 01:30:39 +00:00
|
|
|
|
2022-01-21 22:50:04 +00:00
|
|
|
});
|
2020-09-02 01:30:39 +00:00
|
|
|
|
2022-01-21 22:50:04 +00:00
|
|
|
function scrollConsole() {
|
2023-09-05 00:05:25 +00:00
|
|
|
let logview = $('#virt_console');
|
2022-01-21 22:50:04 +00:00
|
|
|
if (logview.length)
|
|
|
|
logview.scrollTop(logview[0].scrollHeight - logview.height());
|
|
|
|
}
|
2020-09-02 01:30:39 +00:00
|
|
|
|
|
|
|
|
2022-02-27 17:26:54 +00:00
|
|
|
async function sendConsoleCommand() {
|
|
|
|
let serverCommand = $("#server_command").val()
|
|
|
|
console.log(serverCommand)
|
2020-09-02 01:30:39 +00:00
|
|
|
|
2022-02-27 17:26:54 +00:00
|
|
|
cmdHistory.push(serverCommand);
|
2022-01-14 07:35:26 +00:00
|
|
|
|
2022-02-27 17:26:54 +00:00
|
|
|
let token = getCookie("_xsrf")
|
2022-01-21 22:50:04 +00:00
|
|
|
|
2022-02-27 17:26:54 +00:00
|
|
|
let formdata = new FormData();
|
2022-01-21 22:50:04 +00:00
|
|
|
|
2022-02-27 17:26:54 +00:00
|
|
|
formdata.append('command', serverCommand)
|
|
|
|
|
|
|
|
console.log('sending command: ' + serverCommand)
|
2023-03-02 18:24:07 +00:00
|
|
|
let res = await fetch(`/api/v2/servers/${serverId}/stdin`, {
|
2022-02-27 17:26:54 +00:00
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
'X-XSRFToken': token
|
2022-01-14 07:35:26 +00:00
|
|
|
},
|
2023-03-02 18:24:07 +00:00
|
|
|
body: serverCommand,
|
2022-01-21 22:50:04 +00:00
|
|
|
});
|
2022-03-26 22:37:08 +00:00
|
|
|
|
2022-02-27 17:26:54 +00:00
|
|
|
let responseData = await res.text();
|
|
|
|
console.log("got response:");
|
|
|
|
console.log(responseData);
|
|
|
|
$("#server_command").val('')
|
2022-01-21 22:50:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const cmdHistory = {
|
|
|
|
history: [],
|
|
|
|
current: 0,
|
|
|
|
push: function (cmd) {
|
|
|
|
this.history.push(cmd);
|
|
|
|
this.current = this.history.length - 1;
|
|
|
|
},
|
|
|
|
getPrev: function () {
|
|
|
|
const prevCommand = this.history[this.current];
|
|
|
|
this.current--;
|
|
|
|
if (this.current < 0) this.current = 0;
|
|
|
|
return prevCommand;
|
|
|
|
},
|
|
|
|
getNext: function () {
|
|
|
|
this.current++;
|
|
|
|
if (this.current > (this.history.length - 1)) {
|
|
|
|
this.current = (this.history.length - 1);
|
|
|
|
return '';
|
2022-01-14 07:35:26 +00:00
|
|
|
}
|
2022-01-21 22:50:04 +00:00
|
|
|
const nextCommand = this.history[this.current];
|
|
|
|
return nextCommand;
|
|
|
|
}
|
2022-01-14 07:35:26 +00:00
|
|
|
}
|
2022-09-07 22:02:49 +00:00
|
|
|
|
|
|
|
const chkScroll = (e) => {
|
|
|
|
const elem = $(e.currentTarget);
|
|
|
|
if (Math.round(elem[0].scrollHeight - elem.scrollTop()) <= elem.outerHeight()) {
|
|
|
|
document.getElementById("to-bottom").style.visibility = "hidden";
|
2023-02-02 22:48:12 +00:00
|
|
|
document.getElementById("to-bottom").hidden = true;
|
2022-09-07 22:16:18 +00:00
|
|
|
scrolled = false;
|
2022-09-25 21:52:01 +00:00
|
|
|
} else {
|
2022-09-07 22:02:49 +00:00
|
|
|
document.getElementById("to-bottom").style.visibility = "visible";
|
2023-02-02 22:48:12 +00:00
|
|
|
document.getElementById("to-bottom").hidden = false;
|
2022-09-07 22:16:18 +00:00
|
|
|
scrolled = true;
|
2022-09-07 22:02:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const scrollToBottom = (id) => {
|
2022-09-25 21:52:01 +00:00
|
|
|
const element = $(`#virt_console`);
|
|
|
|
element.animate({
|
2022-09-07 22:02:49 +00:00
|
|
|
scrollTop: element.prop("scrollHeight")
|
2022-09-25 21:52:01 +00:00
|
|
|
}, 500);
|
|
|
|
}
|
2022-09-07 22:02:49 +00:00
|
|
|
|
|
|
|
$(document).ready(() => {
|
|
|
|
$('#virt_console').on('scroll', chkScroll);
|
|
|
|
$('#to-bottom').on('click', scrollToBottom)
|
|
|
|
});
|
2020-09-01 17:29:39 +00:00
|
|
|
</script>
|
|
|
|
|
2022-03-26 22:37:08 +00:00
|
|
|
{% end %}
|