2020-09-01 17:29:39 +00:00
|
|
|
{% extends ../base.html %}
|
|
|
|
|
|
|
|
{% block meta %}
|
|
|
|
<!-- <meta http-equiv="refresh" content="60">-->
|
|
|
|
{% 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">
|
|
|
|
|
|
|
|
<!-- Page Title Header Starts-->
|
|
|
|
<div class="row page-title-header">
|
|
|
|
<div class="col-12">
|
|
|
|
<div class="page-header">
|
|
|
|
<h4 class="page-title">
|
2021-09-29 02:25:47 +00:00
|
|
|
{{ translate('serverDetails', 'serverDetails', data['lang']) }} - {{ data['server_stats']['server_id']['server_name'] }}
|
2020-09-04 04:02:03 +00:00
|
|
|
<br />
|
2021-03-22 04:02:18 +00:00
|
|
|
<small>UUID: {{ data['server_stats']['server_id']['server_uuid'] }}</small>
|
2020-09-01 17:29:39 +00:00
|
|
|
</h4>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<!-- Page Title Header Ends-->
|
|
|
|
|
2020-09-04 02:49:20 +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">
|
2021-08-21 08:44:03 +00:00
|
|
|
{% include "parts/server_controls_list.html %}
|
|
|
|
|
2020-09-02 01:30:39 +00:00
|
|
|
<div class="col-md-12">
|
|
|
|
<div class="input-group">
|
2020-09-14 20:01:38 +00:00
|
|
|
<div id="virt_console" class="" style="width: 100%; font-size: .8em; padding: 5px 10px; border: 1px solid #383e5d; background-color:#2a2c44;height:500px; overflow: scroll;"></div>
|
2020-09-02 01:30:39 +00:00
|
|
|
</div>
|
|
|
|
<br />
|
|
|
|
|
2020-12-12 16:44:40 +00:00
|
|
|
<div style="gap: 0.5rem;" class="input-group flex-wrap">
|
2021-09-29 02:25:47 +00:00
|
|
|
<input style="min-width: 10rem;" type="text" class="form-control" id="server_command" name="server_command" placeholder="{{ translate('serverTerm', 'commandInput', data['lang']) }}" autofocus="">
|
2020-09-02 01:30:39 +00:00
|
|
|
<span class="input-group-btn ml-5">
|
2020-09-22 02:01:16 +00:00
|
|
|
<input type="hidden" value="" id="last_command"/>
|
2021-09-29 02:25:47 +00:00
|
|
|
<button id="submit" class="btn btn-sm btn-info" type="button">{{ translate('serverTerm', 'sendCommand', data['lang']) }}</button>
|
2020-09-02 01:30:39 +00:00
|
|
|
</span>
|
|
|
|
</div>
|
2021-08-21 08:44:03 +00:00
|
|
|
{% if data['permissions']['Commands'] in data['user_permissions'] %}
|
2021-07-25 21:04:10 +00:00
|
|
|
{% if data['server_stats']['updating']%}
|
2021-07-26 22:43:57 +00:00
|
|
|
<div id="update_control_buttons" 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">
|
2021-09-29 02:25:47 +00:00
|
|
|
<button onclick="" id="start-btn" style="max-width: 7rem;" class="btn btn-warning m-1 flex-grow-1 disabled">{{ 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 disabled">{% 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>
|
2021-07-25 21:04:10 +00:00
|
|
|
</div>
|
2021-09-20 22:30:17 +00:00
|
|
|
{% elif data['waiting_start'] %}
|
|
|
|
<div id="control_buttons" 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">
|
2021-09-29 02:25:47 +00:00
|
|
|
<button onclick="" id="start-btn" style="max-width: 7rem; white-space: nowrap;" class="btn btn-secondary m-1 flex-grow-1 disabled" data-toggle="tooltip" title="{{ translate('serverTerm', 'delay-explained', data['lang'])}}">{{ translate('serverTerm', 'starting', data['lang']) }}</button>
|
|
|
|
<button onclick="" id="restart-btn" style="max-width: 7rem;" class="btn btn-outline-primary m-1 flex-grow-1 disabled">{% 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>
|
2021-09-20 22:30:17 +00:00
|
|
|
</div>
|
2021-07-25 21:04:10 +00:00
|
|
|
{% else %}
|
2021-07-26 22:43:57 +00:00
|
|
|
<div id="control_buttons" 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">
|
2021-09-29 02:25:47 +00:00
|
|
|
<button onclick="send_command(server_id, '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(server_id, '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="send_command(server_id, 'stop_server');" id="stop-btn" style="max-width: 7rem;" class="btn btn-danger m-1 flex-grow-1">{{ translate('serverTerm', 'stop', data['lang']) }}</button>
|
2020-12-12 16:44:40 +00:00
|
|
|
</div>
|
2021-07-25 21:04:10 +00:00
|
|
|
{% end %}
|
2021-08-21 08:44:03 +00:00
|
|
|
{% end %}
|
2020-09-02 01:30:39 +00:00
|
|
|
</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>
|
|
|
|
#virt_console::-webkit-scrollbar {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Hide scrollbar for IE, Edge and Firefox */
|
|
|
|
#virt_console {
|
|
|
|
-ms-overflow-style: none; /* IE and Edge */
|
|
|
|
scrollbar-width: none; /* Firefox */
|
|
|
|
}
|
|
|
|
|
|
|
|
</style>
|
2020-09-01 17:29:39 +00:00
|
|
|
<!-- content-wrapper ends -->
|
|
|
|
|
|
|
|
{% end %}
|
|
|
|
|
|
|
|
{% block js %}
|
|
|
|
<script>
|
2020-12-12 16:44:40 +00:00
|
|
|
|
|
|
|
function send_command (server_id, command){
|
2021-08-21 19:17:07 +00:00
|
|
|
if (command == 'start_server'){
|
|
|
|
startBtn.setAttribute('disabled', 'disabled');
|
|
|
|
restartBtn.removeAttribute('disabled');
|
|
|
|
stopBtn.removeAttribute('disabled');
|
|
|
|
}
|
|
|
|
if (command == 'stop_server'){
|
|
|
|
startBtn.removeAttribute('disabled');
|
|
|
|
restartBtn.setAttribute('disabled', 'disabled');
|
|
|
|
stopBtn.setAttribute('disabled', 'disabled');
|
|
|
|
}
|
2020-12-12 16:44:40 +00:00
|
|
|
<!-- this getCookie function is in base.html-->
|
|
|
|
var token = getCookie("_xsrf");
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
type: "POST",
|
|
|
|
headers: {'X-XSRFToken': token},
|
|
|
|
url: '/server/command?command=' + command + '&id=' + server_id,
|
|
|
|
success: function(data){
|
|
|
|
console.log("got response:");
|
|
|
|
console.log(data);
|
2021-08-07 19:23:22 +00:00
|
|
|
setTimeout(function(){
|
|
|
|
if (command != 'start_server'){
|
|
|
|
location.reload();
|
|
|
|
}
|
|
|
|
}, 10000);
|
2020-12-12 16:44:40 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2021-07-26 22:43:57 +00:00
|
|
|
if (webSocket) {
|
|
|
|
webSocket.on('update_button_status', function (updateButton) {
|
|
|
|
if (updateButton.isUpdating){
|
|
|
|
console.log(updateButton.isUpdating)
|
2021-09-29 02:25:47 +00:00
|
|
|
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>';
|
2021-07-26 22:43:57 +00:00
|
|
|
}
|
|
|
|
else{
|
2021-07-27 01:05:52 +00:00
|
|
|
window.location.reload()
|
2021-09-29 02:25:47 +00:00
|
|
|
document.getElementById('update_control_buttons').innerHTML = '<button onclick="send_command(server_id, "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(server_id, "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>';
|
2021-07-26 22:43:57 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2020-12-12 16:44:40 +00:00
|
|
|
// Convert running to lower case (example: 'True' converts to 'true') and
|
|
|
|
// then to boolean via JSON.parse()
|
2021-03-22 04:02:18 +00:00
|
|
|
let online = JSON.parse('{{ data['server_stats']['running'] }}'.toLowerCase());
|
2020-12-12 16:44:40 +00:00
|
|
|
|
|
|
|
let startBtn = document.querySelector('#start-btn');
|
|
|
|
let restartBtn = document.querySelector('#restart-btn');
|
|
|
|
let stopBtn = document.querySelector('#stop-btn');
|
|
|
|
|
2021-08-21 23:41:25 +00:00
|
|
|
{% if data['permissions']['Commands'] in data['user_permissions'] %}
|
2020-12-12 16:44:40 +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');
|
|
|
|
}
|
2021-08-21 23:41:25 +00:00
|
|
|
{% end %}
|
2020-12-12 16:44:40 +00:00
|
|
|
|
2021-03-22 04:02:18 +00:00
|
|
|
let server_id = '{{ data['server_stats']['server_id']['server_id'] }}';
|
2020-12-12 16:44:40 +00:00
|
|
|
|
2020-09-02 01:30:39 +00:00
|
|
|
function get_server_log(){
|
|
|
|
$.ajax({
|
|
|
|
type: 'GET',
|
2021-03-22 04:02:18 +00:00
|
|
|
url: '/ajax/server_log?id={{ data['server_stats']['server_id']['server_id'] }}',
|
2020-09-02 01:30:39 +00:00
|
|
|
dataType: 'text',
|
|
|
|
success: function (data) {
|
|
|
|
console.log('Got Log From Server')
|
|
|
|
$('#virt_console').html(data);
|
2021-08-11 20:29:31 +00:00
|
|
|
scrollConsole();
|
|
|
|
},
|
2020-09-02 01:30:39 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-08-21 20:17:35 +00:00
|
|
|
|
|
|
|
|
2021-08-10 20:17:56 +00:00
|
|
|
function new_line_handler(data) {
|
2021-08-11 20:29:31 +00:00
|
|
|
$('#virt_console').append(data.line)
|
2021-08-21 20:17:35 +00:00
|
|
|
const elem = document.getElementById('virt_console');
|
|
|
|
const scrollDiff = (elem.scrollHeight - elem.scrollTop) - elem.clientHeight;
|
|
|
|
if (!$("#stop_scroll").is(':checked') && scrollDiff < 450) {
|
2021-08-11 20:29:31 +00:00
|
|
|
scrollConsole()
|
2021-08-10 20:17:56 +00:00
|
|
|
}
|
2020-09-02 01:30:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//used to get cookies from browser - this is part of tornados xsrf protection - it's for extra security
|
|
|
|
function getCookie(name) {
|
|
|
|
var r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
|
|
|
|
return r ? r[1] : undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
$( document ).ready(function() {
|
|
|
|
console.log( "ready!" );
|
|
|
|
get_server_log()
|
|
|
|
|
2021-08-11 20:29:31 +00:00
|
|
|
webSocket.on('vterm_new_line', new_line_handler)
|
2020-09-02 01:30:39 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$('#server_command').on('keydown', function (e) {
|
|
|
|
if (e.which == 13){
|
|
|
|
$(this).attr("disabled", "disabled"); //Disable textbox to prevent multiple submit
|
|
|
|
send_command_to_server()
|
|
|
|
$(this).removeAttr("disabled"); //Enable the textbox again if needed.
|
|
|
|
$(this).focus();
|
|
|
|
}
|
|
|
|
else if (e.which == 38){
|
|
|
|
last_command = $('#last_command').val()
|
|
|
|
$("#server_command").val(last_command)
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#submit").click(function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
send_command_to_server();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2021-08-11 20:29:31 +00:00
|
|
|
function scrollConsole(){
|
2020-09-02 01:30:39 +00:00
|
|
|
var logview = $('#virt_console');
|
|
|
|
if(logview.length)
|
|
|
|
logview.scrollTop(logview[0].scrollHeight - logview.height());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function send_command_to_server(){
|
|
|
|
var server_command = $("#server_command").val()
|
|
|
|
console.log(server_command)
|
|
|
|
$("#last_command").val(server_command)
|
|
|
|
|
|
|
|
var token = getCookie("_xsrf")
|
|
|
|
|
|
|
|
data_to_send = { command :server_command, }
|
|
|
|
|
|
|
|
console.log('sending command: ' + server_command)
|
|
|
|
$.ajax({
|
|
|
|
type: "POST",
|
|
|
|
headers: {'X-XSRFToken': token},
|
2021-03-22 04:02:18 +00:00
|
|
|
url: '/ajax/send_command?id={{ data['server_stats']['server_id']['server_id'] }}',
|
2020-09-02 01:30:39 +00:00
|
|
|
data: data_to_send,
|
|
|
|
success: function(data){
|
|
|
|
console.log("got response:");
|
|
|
|
console.log(data);
|
|
|
|
$("#server_command").val('')
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2020-09-01 17:29:39 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
{% end %}
|