2020-08-13 14:38:36 +00:00
{% extends ../base.html %}
2020-08-27 22:35:08 +00:00
{% block meta %}
{% end %}
2021-09-29 02:25:47 +00:00
{% block title %}Crafty Controller - {{ translate('dashboard', 'dashboard', data['lang']) }}{% end %}
2020-08-13 14:38:36 +00:00
{% block content %}
< div class = "content-wrapper" >
2022-01-19 21:45:52 +00:00
<!-- Page Title Header Starts -->
2020-08-13 14:38:36 +00:00
< div class = "row page-title-header" >
< div class = "col-12" >
< div class = "page-header" >
2022-03-04 00:41:30 +00:00
< h4 class = "page-title" > {{ translate('dashboard', 'dashboard', data['lang']) }}
{% if data['server_stats']['running'] != 0 %}
< span id = "sync" style = "margin-left: 5px;" > < i class = "fas fa-sync fa-spin" > < / i > < / span > < / h4 >
{% end %}
2020-08-13 14:38:36 +00:00
< / div >
< / div >
< / div >
<!-- Page Title Header Ends -->
< div class = "row" >
< div class = "col-md-12 grid-margin" >
< div class = "card" >
< div class = "card-body" >
< div class = "row" >
2021-09-27 17:17:29 +00:00
< div class = "col-lg-4 col-md-6" >
2020-08-13 14:38:36 +00:00
< div class = "d-flex" >
< div class = "wrapper" >
2022-01-19 21:45:52 +00:00
< h5 class = "mb-1 font-weight-medium text-primary" > {{ translate('dashboard', 'host', data['lang']) }}
< / h5 >
2020-08-17 02:47:53 +00:00
< h3 class = "mb-0 font-weight-semibold" > < i class = "fas fa-chart-line" > < / i > < / h3 >
2020-08-13 14:38:36 +00:00
< / div >
< div class = "wrapper my-auto ml-auto ml-lg-4" >
2022-01-19 21:45:52 +00:00
< p id = "cpu_data" class = "mb-0 text-success" data-toggle = "tooltip" data-placement = "top" data-html = "true"
title="{% raw translate('dashboard', 'cpuCores', data['lang']) %}: {{ data.get('hosts_data').get('cpu_cores') }} < br / > {% raw translate('dashboard', 'cpuCurFreq', data['lang']) %}: {{ data.get('hosts_data').get('cpu_cur_freq') }} < br / > {% raw translate('dashboard', 'cpuMaxFreq', data['lang']) %}: {{ data.get('hosts_data').get('cpu_max_freq') }}">
{{ translate('dashboard', 'cpuUsage', data['lang']) }}: < span id = "cpu_usage" > {{
data.get('hosts_data').get('cpu_usage') }}< / span >
2020-08-28 03:21:55 +00:00
< / p >
2022-01-19 21:45:52 +00:00
< p id = "mem_usage" class = "mb-0 text-danger" data-toggle = "tooltip" data-placement = "top"
title="{{ translate('dashboard', 'memUsage', data['lang']) }}: {{ data.get('hosts_data').get('mem_usage') }}">
{{ translate('dashboard', 'memUsage', data['lang']) }}: < span id = "mem_percent" > {{
data.get('hosts_data').get('mem_percent') }}%< / span >
2020-08-28 03:21:55 +00:00
< / p >
2020-08-13 14:38:36 +00:00
< / div >
< / div >
< / div >
2021-09-27 17:17:29 +00:00
< div class = "col-lg-4 col-md-6 mt-md-0 mt-4" >
2020-08-13 14:38:36 +00:00
< div class = "d-flex" >
< div class = "wrapper" >
2022-01-19 21:45:52 +00:00
< h5 class = "mb-1 font-weight-medium text-primary" > {{ translate('dashboard', 'servers', data['lang']) }}
< / h5 >
2020-08-19 01:04:43 +00:00
< h3 class = "mb-0 font-weight-semibold" > {{ data['server_stats']['total'] }}< / h3 >
2020-08-13 14:38:36 +00:00
< / div >
< div class = "wrapper my-auto ml-auto ml-lg-4" >
2022-01-19 21:45:52 +00:00
< p class = "mb-0 text-success" > {{ data['server_stats']['running'] }} {{ translate('dashboard', 'online',
data['lang']).lower() }}< / p >
< p class = "mb-0 text-warning" > {{ data['server_stats']['stopped'] }} {{ translate('dashboard',
'offline', data['lang']).lower() }}< / p >
2020-08-13 14:38:36 +00:00
< / div >
< / div >
< / div >
2021-09-27 17:17:29 +00:00
< div class = "col-lg-4 col-md-6 mt-md-0 mt-4" >
2020-08-13 14:38:36 +00:00
< div class = "d-flex" >
< div class = "wrapper" >
2022-01-19 21:45:52 +00:00
< h5 class = "mb-1 font-weight-medium text-primary" > {{ translate('dashboard', 'players', data['lang']) }}
< / h5 >
2022-01-27 23:16:27 +00:00
< h3 class = "mb-0 font-weight-semibold" id = "total_players" > {{ data['num_players'] }}< / h3 >
2020-08-13 14:38:36 +00:00
< / div >
< div class = "wrapper my-auto ml-auto ml-lg-4" >
2022-01-27 23:16:27 +00:00
< p class = "mb-0 text-warning" > < span id = "max_players" > 0< / span > {{ translate('dashboard', 'max', data['lang']) }}< / p >
2020-08-13 14:38:36 +00:00
< / div >
< / div >
< / div >
< / div >
< / div >
< / div >
< / div >
< / div >
< div class = "row" >
< div class = "col-md-12 col-lg-12 grid-margin stretch-card" >
< div class = "card" >
< div class = "card-header header-sm d-flex justify-content-between align-items-center" >
2022-01-19 21:45:52 +00:00
< h4 class = "card-title" > < i class = "fas fa-server" > < / i > {{ translate('dashboard', 'allServers',
data['lang']) }}< / h4 >
2021-09-27 16:52:43 +00:00
{% if len(data['servers']) > 0 %}
2022-01-19 21:45:52 +00:00
< span class = "too_small" title = "{{ translate('dashboard', 'cannotSeeOnMobile', data['lang']) }}" ,
data-content="{{ translate('dashboard', 'cannotSeeOnMobile2', data['lang']) }}" ,
data-placement="top">< / span >
2021-09-27 17:08:43 +00:00
{% end %}
2022-01-19 21:45:52 +00:00
< div > < a class = "nav-link" href = "/server/step1" > < i class = "fas fa-plus-circle" > < / i > {{
translate('dashboard', 'newServer', data['lang']) }}< / a > < / div >
2020-08-13 14:38:36 +00:00
< / div >
< div class = "card-body" >
< div class = "table-responsive" >
2022-01-19 21:45:52 +00:00
{% if len(data['servers']) == 0%}
< div style = "text-align: center; color: grey;" >
< h1 > {{ translate('dashboard', 'welcome', data['lang']) }}< / h1 >
< br >
< h7 > {{ translate('dashboard', 'no-servers', data['lang']) }} {{ translate('dashboard', 'newServer',
data['lang']) }}.< / h7 >
< / div >
{% end %}
{% if len(data['servers']) > 0 %}
2022-03-13 20:02:55 +00:00
< table id = "servers_table" class = "table table-hover" >
2020-08-13 14:38:36 +00:00
< thead >
2022-03-13 20:02:55 +00:00
< tr class = "rounded" id = "first" draggable = "false" >
< th draggable = "false" > {{ translate('dashboard', 'server', data['lang']) }}< / th >
< th draggable = "false" > {{ translate('dashboard', 'actions', data['lang']) }}< / th >
< th draggable = "false" > {{ translate('dashboard', 'cpuUsage', data['lang']) }}< / th >
< th draggable = "false" > {{ translate('dashboard', 'memUsage', data['lang']) }}< / th >
< th draggable = "false" > {{ translate('dashboard', 'size', data['lang']) }}< / th >
< th draggable = "false" > {{ translate('dashboard', 'players', data['lang']) }}< / th >
< th draggable = "false" > {{ translate('dashboard', 'status', data['lang']) }}< / th >
2020-08-13 14:38:36 +00:00
< / tr >
< / thead >
< tbody >
2020-08-24 17:08:17 +00:00
{% for server in data['servers'] %}
2022-02-26 23:00:54 +00:00
< tr id = "{{server['server_data']['server_id']}}" draggable = "true" ondragstart = "start()" ondragover = "dragover()" ondragend = "dragend()" >
2022-02-27 01:02:10 +00:00
< td draggable = "false" >
2020-08-24 17:08:17 +00:00
< i class = "fas fa-server" > < / i >
2022-02-27 01:02:10 +00:00
< a draggable = "false" href = "/panel/server_detail?id={{server['server_data']['server_id']}}" >
2020-08-27 22:30:56 +00:00
{{ server['server_data']['server_name'] }}
2020-08-24 17:08:17 +00:00
< / a >
< / td >
2022-03-13 20:41:27 +00:00
< td draggable = "false" id = "controls{{server['server_data']['server_id']}}" class = "actions_serverlist" >
2021-08-21 23:41:25 +00:00
{% if server['user_command_permission'] %}
2022-01-19 21:45:52 +00:00
{% if server['stats']['running'] %}
2022-02-27 17:26:54 +00:00
< a data-id = "{{server['server_data']['server_id']}}" class = "stop_button"
data-toggle="tooltip" title="{{ translate('dashboard', 'stop' , data['lang']) }}">
< i class = "fas fa-stop" > < / i >
< / a >
< a data-id = "{{server['server_data']['server_id']}}" class = "restart_button"
data-toggle="tooltip" title="{{ translate('dashboard', 'restart' , data['lang']) }}">
< i class = "fas fa-sync" > < / i >
< / a >
< a data-id = "{{server['server_data']['server_id']}}" class = "kill_button"
data-toggle="tooltip" title="{{ translate('dashboard', 'kill' , data['lang']) }}">
< i class = "fas fa-skull" > < / i >
< / a >
2022-01-19 21:45:52 +00:00
{% elif server['stats']['updating']%}
2022-02-27 17:26:54 +00:00
<!-- WHAT HAPPENED HERE -->
2022-01-19 21:45:52 +00:00
< a data-id = "{{server['server_data']['server_id']}}" class = "" > {{ translate('serverTerm', 'updating',
data['lang']) }}< / i > < / a >
{% elif server['stats']['waiting_start']%}
2022-02-27 17:26:54 +00:00
<!-- WHAT HAPPENED HERE -->
2022-03-04 00:57:06 +00:00
< a data-id = "{{server['server_data']['server_id']}}" class = "" title = "{{
translate('dashboard', 'delay-explained' , data['lang'])}}">{{ translate('dashboard', 'starting',
2022-01-19 21:45:52 +00:00
data['lang']) }}< / i > < / a >
2022-03-04 00:36:36 +00:00
{% elif server['stats']['downloading']%}
< a data-id = "{{server['server_data']['server_id']}}" class = "" > < i class = "fa fa-spinner fa-spin" > < / i > {{ translate('serverTerm', 'downloading',
data['lang']) }}< / a >
2022-01-19 21:45:52 +00:00
{% else %}
2022-02-27 17:26:54 +00:00
< a data-id = "{{server['server_data']['server_id']}}" class = "play_button"
data-toggle="tooltip" title="{{ translate('dashboard', 'start' , data['lang']) }}">
< i class = "fas fa-play" > < / i >
< / a >
< a data-id = "{{server['server_data']['server_id']}}" class = "clone_button"
data-toggle="tooltip" title="{{ translate('dashboard', 'clone' , data['lang']) }}">
< i class = "fas fa-clone" > < / i >
< / a >
< a data-id = "{{server['server_data']['server_id']}}" class = "kill_button"
data-toggle="tooltip" title="{{ translate('dashboard', 'kill' , data['lang']) }}">
< i class = "fas fa-skull" > < / i >
< / a >
2022-01-19 21:45:52 +00:00
{% end %}
2020-08-24 17:08:17 +00:00
{% end %}
2020-08-13 14:38:36 +00:00
< / td >
2020-08-24 17:08:17 +00:00
2022-03-13 20:41:27 +00:00
< td draggable = "false" id = "server_cpu_{{server['server_data']['server_id']}}" >
2022-01-19 21:45:52 +00:00
< div class = "progress mb-1" data-toggle = "tooltip" data-placement = "top"
title="{{server['stats']['cpu']}}">
2020-08-28 00:01:41 +00:00
< div class = "progress-bar
2021-03-22 04:02:18 +00:00
{% if server['stats']['cpu'] < = 33 %}
2020-08-28 00:01:41 +00:00
bg-success
2021-03-22 04:02:18 +00:00
{% elif 34 < = server['stats']['cpu'] < = 66 %}
2020-08-28 00:01:41 +00:00
bg-warning
{% else %}
bg-danger
{% end %}
2022-01-19 21:45:52 +00:00
" role="progressbar" style="width: {{server['stats']['cpu']}}%" aria-valuenow="0"
aria-valuemin="0" aria-valuemax="100">< / div >
2020-08-13 14:38:36 +00:00
< / div >
2021-03-22 04:02:18 +00:00
{{server['stats']['cpu']}}%
2020-08-13 14:38:36 +00:00
< / td >
2020-08-24 17:08:17 +00:00
2022-03-13 20:41:27 +00:00
< td draggable = "false" id = "server_mem_{{server['server_data']['server_id']}}" >
2022-01-19 21:45:52 +00:00
< div class = "progress mb-1" data-toggle = "tooltip" data-placement = "top"
title="{{server['stats']['mem']}}">
2020-08-28 00:01:41 +00:00
< div class = "progress-bar
2021-03-22 04:02:18 +00:00
{% if server['stats']['mem_percent'] < = 33 %}
2020-08-28 00:01:41 +00:00
bg-success
2021-03-22 04:02:18 +00:00
{% elif 34 < = server['stats']['mem_percent'] < = 66 %}
2020-08-28 00:01:41 +00:00
bg-warning
{% else %}
bg-danger
{% end %}
2022-01-19 21:45:52 +00:00
" role="progressbar" style="width: {{server['stats']['mem_percent']}}%" aria-valuenow="0"
aria-valuemin="0" aria-valuemax="100">< / div >
2020-08-13 14:38:36 +00:00
< / div >
2021-03-22 04:02:18 +00:00
{{server['stats']['mem_percent']}}% -
2020-08-31 17:46:25 +00:00
2021-03-22 04:02:18 +00:00
{% if server['stats']['mem'] == 0 %}
2022-01-19 21:45:52 +00:00
0 MB
2020-08-31 17:46:25 +00:00
{% else %}
2022-01-19 21:45:52 +00:00
{{server['stats']['mem']}}
2020-08-31 17:46:25 +00:00
{% end %}
2020-08-13 14:38:36 +00:00
< / td >
2022-03-13 20:41:27 +00:00
< td draggable = "false" id = "server_world_{{server['server_data']['server_id']}}" >
2022-03-02 02:56:12 +00:00
{{ server['stats']['world_size'] }}
2020-08-13 14:38:36 +00:00
< / td >
2022-03-13 20:41:27 +00:00
< td draggable = "false" id = "server_desc_{{server['server_data']['server_id']}}" >
2021-03-22 04:02:18 +00:00
{% if server['stats']['int_ping_results'] %}
2022-01-19 21:45:52 +00:00
{{ server['stats']['online'] }} / {{ server['stats']['max'] }} {{ translate('dashboard', 'max',
data['lang']) }} < br / >
2020-08-31 17:46:25 +00:00
2022-01-19 21:45:52 +00:00
{% if server['stats']['desc'] != 'False' %}
2022-03-14 23:48:53 +00:00
< div id = "desc_id" style = "overflow-wrap: break-word !important; max-width: 85px !important; overflow: scroll;" > {{ server['stats']['desc'] }}< / div > < br / >
2022-01-19 21:45:52 +00:00
{% end %}
2020-08-31 17:46:25 +00:00
2022-01-19 21:45:52 +00:00
{% if server['stats']['version'] != 'False' %}
{{ server['stats']['version'] }}
{% end %}
2020-08-24 23:11:17 +00:00
{% end %}
2020-08-31 17:46:25 +00:00
2020-08-24 17:08:17 +00:00
< / td >
2022-03-13 20:41:27 +00:00
< td draggable = "false" id = "server_running_status_{{server['server_data']['server_id']}}" >
2021-03-22 04:02:18 +00:00
{% if server['stats']['running'] %}
2022-01-26 01:45:30 +00:00
< span class = "text-success" > < i class = "fas fa-signal" > < / i > {{ translate('dashboard', 'online',
2022-01-19 21:45:52 +00:00
data['lang']) }}< / span >
2022-01-28 02:53:07 +00:00
{% elif server['stats']['crashed'] %}
< span class = "text-danger" > < i class = "fas fa-exclamation-triangle" > < / i > {{ translate('dashboard', 'crashed',
data['lang']) }}< / span >
2020-08-24 17:08:17 +00:00
{% else %}
2022-01-27 23:16:27 +00:00
< span class = "text-warning" > < i class = "fas fa-ban" > < / i > {{ translate('dashboard', 'offline',
2022-01-19 21:45:52 +00:00
data['lang']) }}< / span >
2020-08-24 17:08:17 +00:00
{% end %}
2020-08-13 14:38:36 +00:00
< / td >
2022-03-04 00:41:30 +00:00
< span class = "server-player-totals" id = "server_players_{{server['server_data']['server_id']}}" data-players = "{{ server['stats']['online']}}" data-max = "{{ server['stats']['max'] }}" > < / span >
2020-08-13 14:38:36 +00:00
< / tr >
2020-08-24 17:08:17 +00:00
{% end %}
2020-08-13 14:38:36 +00:00
< / tbody >
< / table >
2021-09-25 19:07:39 +00:00
{% end %}
2020-08-13 14:38:36 +00:00
< / div >
< / div >
< / div >
< / div >
< / div >
2020-08-24 17:08:17 +00:00
2020-08-13 14:38:36 +00:00
< / div >
<!-- content - wrapper ends -->
2021-09-27 16:52:43 +00:00
< style >
2022-01-19 21:45:52 +00:00
.popover-body {
color: white !important;
;
}
2022-03-14 23:48:53 +00:00
#desc_id {
-ms-overflow-style: none; /* for Internet Explorer, Edge */
scrollbar-width: none; /* for Firefox */
overflow-y: scroll;
}
#desc_id::-webkit-scrollbar {
display: none; /* for Chrome, Safari, and Opera */
}
2021-09-27 16:52:43 +00:00
< / style >
2020-08-13 14:38:36 +00:00
2020-08-24 23:11:17 +00:00
{% end %}
{% block js %}
2022-01-19 21:45:52 +00:00
< script src = "/static/assets/js/motd.js" > < / script >
2020-08-24 23:11:17 +00:00
< script >
2022-01-21 22:50:04 +00:00
function display_motd() {
var all_motds = Array.from(document.getElementsByClassName('input_motd'));
for (element of all_motds) {
initParser(element.id, element.id);
};
}
2022-01-19 21:45:52 +00:00
$(document).ready(function () {
$('[data-toggle="popover"]').popover();
if ($(window).width() < 1000 ) {
$('.too_small').popover("show");
}
});
$(window).ready(function () {
$('body').click(function () {
$('.too_small').popover("hide");
2021-09-27 16:52:43 +00:00
});
2022-01-19 21:45:52 +00:00
});
$(window).resize(function () {
// This will execute whenever the window is resized
if ($(window).width() < 1000 ) {
$('.too_small').popover("show");
}
else {
$('.too_small').popover("hide");
} // New width
});
2021-09-27 16:52:43 +00:00
< / script >
< script >
2020-08-24 23:11:17 +00:00
2022-01-19 21:45:52 +00:00
function send_command(server_id, command) {
/* 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);
2022-01-21 22:50:04 +00:00
/*setTimeout(function () {
2022-01-19 21:45:52 +00:00
if (command != 'start_server') {
2021-08-07 19:23:22 +00:00
location.reload();
}
2022-01-21 22:50:04 +00:00
}, 10000);*/
2022-01-19 21:45:52 +00:00
}
});
}
function send_kill(server_id) {
/* this getCookie function is in base.html */
var token = getCookie("_xsrf");
$.ajax({
type: "POST",
headers: { 'X-XSRFToken': token },
url: '/ajax/kill?id=' + server_id,
success: function (data) {
console.log("got response:");
console.log(data);
2022-01-21 22:50:04 +00:00
/*setTimeout(function () {
2022-01-19 21:45:52 +00:00
location.reload();
2022-01-21 22:50:04 +00:00
}, 10000);*/
2022-01-19 21:45:52 +00:00
}
});
}
2020-08-24 23:11:17 +00:00
2022-01-19 21:45:52 +00:00
function update_one_server_status(server) {
server_cpu = document.getElementById('server_cpu_' + server.id);
server_mem = document.getElementById('server_mem_' + server.id);
server_world = document.getElementById('server_world_' + server.id);
server_desc = document.getElementById('server_desc_' + server.id);
server_online_status = document.getElementById('server_running_status_' + server.id);
2022-03-04 00:41:30 +00:00
server_players = document.getElementById('server_players_' + server.id);
total_players = document.getElementById('total_players');
2022-01-19 21:45:52 +00:00
console.log("Received Data : " + server.id + ": " + server);
/* TODO Update each element */
/* Update CPU */
cpu_status = "";
if (server.cpu < = 33)
{
cpu_status = "bg-success";
}
else if (server.cpu > 33 & & server.cpu < = 66)
{
cpu_status = "bg-warning";
}
else
{
cpu_status = "bg-danger";
}
server_cpu.innerHTML = `< div class = "progress mb-1" data-toggle = "tooltip" data-placement = "top" title = "`+ server.cpu +`" > < div class = "progress-bar `+ cpu_status + `" role = "progressbar" style = "width: `+ server.cpu + `%" aria-valuenow = "0" aria-valuemin = "0" aria-valuemax = "100" > < / div > < / div > `+ server.cpu +`%`;
/* Update Memory */
mem_status = "";
total_mem = "";
if (server.mem_percent < = 33)
{
mem_status = "bg-success";
} else if (server.mem_percent > 33 & & server.mem_percent < = 66)
{
mem_status = "bg-warning";
}
else
{
mem_status = "bg-danger";
2020-08-24 23:11:17 +00:00
}
2021-09-13 19:03:47 +00:00
2022-01-19 21:45:52 +00:00
if (server.mem == 0)
{
total_mem = "0 MB";
2021-09-13 19:03:47 +00:00
}
2022-01-19 21:45:52 +00:00
else
{
total_mem = server.mem;
}
server_mem.innerHTML = `< div class = "progress mb-1" data-toggle = "tooltip" data-placement = "top" title = "`+ server_mem +`" > < div class = "progress-bar `+ mem_status + `" role = "progressbar" style = "width: `+ server.mem_percent + `%" aria-valuenow = "0" aria-valuemin = "0" aria-valuemax = "100" > < / div > < / div > `+ server.mem_percent +`% - ` + total_mem;
/* Update World Infos */
2022-03-02 02:56:12 +00:00
server_world.innerHTML = server.world_size
2022-01-19 21:45:52 +00:00
/* Update Server Infos */
if (server.int_ping_results) {
/* Update Players */
if (server.players) {
server_desc.innerHTML = server.online + ` / ` + server.max + ` {{ translate('dashboard', 'max', data['lang']) }}< br / > `
2022-03-04 00:41:30 +00:00
server_players.setAttribute('data-players', server.online);
server_players.setAttribute('data-max', server.max);
let servers = document.getElementsByClassName("server-player-totals");
let all_total_players = 0;
let all_total_max_players = 0;
for(var i = 0; i < servers.length ; i + + ) {
try{
all_total_players += parseInt(servers[i].getAttribute('data-players'));
all_total_max_players += parseInt(servers[i].getAttribute('data-max'));
}catch{
console.log("Player totals are not of type int");
}
}
total_players.innerHTML = all_total_players;
document.getElementById('max_players').innerHTML = all_total_max_players;
document.getElementById('sync').innerHTML = '';
2022-01-19 21:45:52 +00:00
server_infos = "";
2022-02-08 06:57:19 +00:00
server_infos = server.online + " / " + server.max + " {{ translate('dashboard', 'max', data['lang']) }}< br / > "
2022-01-19 21:45:52 +00:00
}
/* Update Motd */
var motd = "";
if (server.desc) {
motd = `< span id = "input_motd_` + server.id + `" class = "input_motd" > ` + server.desc + `< / span > `;
2022-03-14 23:48:53 +00:00
server_infos = server_infos + '< div id = "desc_id" style = "word-wrap: break-word; max-width: 85px !important; overflow: auto;" > ' + motd + '< / div > ' + "< br / > ";
2022-01-19 21:45:52 +00:00
}
/* Version */
if (server.version) {
server_infos = server_infos + server.version
}
server_desc.innerHTML = server_infos;
}
/* Update Online Status */
var online_status = "";
if (server.running) {
online_status = `< span class = "text-success" > < i class = "fas fa-signal" > < / i > {{ translate('dashboard', 'online', data['lang'])}}< / span > `;
}
else {
2022-01-28 02:53:07 +00:00
if (server.crashed){
online_status = `< span class = "text-danger" > < i class = "fas fa-exclamation-triangle" > < / i > {{ translate('dashboard', 'crashed', data['lang'])}}< / span > `
}else{
2022-01-27 23:16:27 +00:00
online_status = `< span class = "text-warning" > < i class = "fas fa-ban" > < / i > {{ translate('dashboard', 'offline', data['lang'])}}< / span > `;
2022-01-28 02:53:07 +00:00
}
2022-01-19 21:45:52 +00:00
}
server_online_status.innerHTML = online_status;
}
function update_servers_status(data) {
2022-03-13 20:02:55 +00:00
try{
2022-03-03 22:13:40 +00:00
update_one_server_status(data[0]);
2022-03-13 20:02:55 +00:00
}catch{
}
2022-01-19 21:45:52 +00:00
display_motd();
}
$(document).ready(function () {
console.log('ready for JS!')
$(".play_button").click(function () {
server_id = $(this).attr("data-id");
send_command(server_id, 'start_server');
bootbox.alert({
backdrop: true,
2022-02-27 17:26:54 +00:00
title: '{% raw translate("dashboard", "sendingCommand", data["lang"]) %}',
message: '< div align = "center" > < i class = "fas fa-spin fa-spinner" > < / i > {% raw translate("dashboard", "bePatientStart", data["lang"]) %} < / div > '
});
2020-08-24 23:11:17 +00:00
});
2022-01-19 21:45:52 +00:00
$(".stop_button").click(function () {
console.log("stopping server");
server_id = $(this).attr("data-id");
send_command(server_id, 'stop_server');
bootbox.alert({
backdrop: true,
2022-02-27 17:26:54 +00:00
title: '{% raw translate("dashboard", "sendingCommand", data["lang"]) %}',
message: '< div align = "center" > < i class = "fas fa-spin fa-spinner" > < / i > {% raw translate("dashboard", "bePatientStop", data["lang"]) %} < / div > '
});
2020-08-24 23:11:17 +00:00
});
2022-01-19 21:45:52 +00:00
$(".restart_button").click(function () {
server_id = $(this).attr("data-id");
send_command(server_id, 'restart_server');
bootbox.alert({
backdrop: true,
2022-02-27 17:26:54 +00:00
title: '{% raw translate("dashboard", "sendingCommand", data["lang"]) %}',
message: '< div align = "center" > < i class = "fas fa-spin fa-spinner" > < / i > {% raw translate("dashboard", "bePatientRestart", data["lang"]) %} < / div > '
});
2022-01-19 21:45:52 +00:00
});
$(".kill_button").click(function () {
2021-09-13 19:03:47 +00:00
server_id = $(this).attr("data-id");
bootbox.confirm({
2022-01-19 21:45:52 +00:00
message: "This will kill the server process and all it's subprocesses. Killing a process can potentially corrupt files. Only do this in extreme circumstances. Are you sure you would like to continue?",
buttons: {
confirm: {
2022-02-27 17:26:54 +00:00
label: '{% raw translate("dashboard", "kill", data["lang"]) %}',
2021-09-13 19:03:47 +00:00
className: 'btn-danger'
2022-01-19 21:45:52 +00:00
},
cancel: {
2022-02-27 17:26:54 +00:00
label: '{% raw translate("panelConfig", "cancel", data["lang"]) %}',
2021-09-13 19:03:47 +00:00
className: 'btn-secondary'
2022-01-19 21:45:52 +00:00
}
},
callback: function (result) {
if (result) {
send_kill(server_id);
var dialog = bootbox.dialog({
2022-02-27 17:26:54 +00:00
title: '{% raw translate("dashboard", "killing", data["lang"]) %}',
2022-01-19 21:45:52 +00:00
message: '< p > < i class = "fa fa-spin fa-spinner" > < / i > Loading...< / p > '
});
dialog.init(function () {
setTimeout(function () {
location.reload();
}, 15000);
});
}
2021-09-13 19:03:47 +00:00
}
2022-01-19 21:45:52 +00:00
});
2021-02-27 12:05:04 +00:00
});
2022-01-19 21:45:52 +00:00
if (webSocket) {
cpu_data = document.getElementById('cpu_data');
cpu_usage = document.getElementById('cpu_usage');
mem_usage = document.getElementById('mem_usage');
mem_percent = document.getElementById('mem_percent');
2022-03-04 00:41:30 +00:00
2022-01-19 21:45:52 +00:00
webSocket.on('update_host_stats', function (hostStats) {
var cpuDataTitle = `{% raw translate('dashboard', 'cpuCores', data['lang']) %}: ${hostStats.cpu_cores} < br / > {% raw translate("dashboard", "cpuCurFreq", data['lang']) %}: ${hostStats.cpu_cur_freq} < br / > {% raw translate("dashboard", "cpuMaxFreq", data['lang']) %}: ${hostStats.cpu_max_freq}`;
cpu_data.setAttribute('data-original-title', cpuDataTitle);
cpu_usage.textContent = hostStats.cpu_usage;
mem_usage.setAttribute('data-original-title', `{% raw translate("dashboard", "memUsage", data['lang']) %}: ${hostStats.mem_usage}`);
mem_percent.textContent = hostStats.mem_percent + '%';
});
}
2021-08-21 19:17:07 +00:00
if (webSocket) {
2022-01-19 21:45:52 +00:00
webSocket.on('send_start_reload', function () {
location.reload()
});
}
2021-08-21 20:17:35 +00:00
2022-01-19 21:45:52 +00:00
if (webSocket) {
webSocket.on('update_button_status', function (updateButton) {
2022-02-27 17:26:54 +00:00
let serverId = updateButton.server_id;
let message = updateButton.string;
let updating = updateButton.isUpdating;
let id = 'controls' + serverId;
if (updating) {
console.log(updating)
document.getElementById(id).innerHTML = message;
2021-07-26 22:43:57 +00:00
}
2022-01-19 21:45:52 +00:00
else {
window.location.reload()
}
});
}
if (webSocket) {
webSocket.on('update_server_status', update_servers_status);
}
2021-02-26 15:39:35 +00:00
2022-01-19 21:45:52 +00:00
$(".clone_button").click(function () {
server_id = $(this).attr("data-id");
send_command(server_id, 'clone_server');
bootbox.alert({
backdrop: true,
2022-02-27 17:26:54 +00:00
title: '{% raw translate("dashboard", "sendingCommand", data["lang"]) %}',
message: '< div align = "center" > < i class = "fas fa-spin fa-spinner" > < / i > {% raw translate("dashboard", "bePatientClone", data["lang"]) %} < / div > '
});
2021-01-28 18:46:13 +00:00
});
2022-01-19 21:45:52 +00:00
});
2020-08-24 23:11:17 +00:00
< / script >
2022-02-26 23:00:54 +00:00
< script >
var row;
2022-03-03 22:13:40 +00:00
function start(){
row = event.target;
2022-02-26 23:00:54 +00:00
}
function dragover(){
var e = event;
2022-03-03 22:13:40 +00:00
e.preventDefault();
2022-02-26 23:00:54 +00:00
let children= Array.from(e.target.parentNode.parentNode.children);
2022-03-03 22:13:40 +00:00
2022-02-26 23:00:54 +00:00
if(children.indexOf(e.target.parentNode)>children.indexOf(row))
e.target.parentNode.after(row);
else
e.target.parentNode.before(row);
}
function dragend(){
var id_string = '';
2022-03-03 22:13:40 +00:00
const table = document.querySelector("table");
2022-02-26 23:00:54 +00:00
for (const row of table.rows) {
if (row.getAttribute('id') != null){
if (id_string != ''){
id_string += ',' + String(row.getAttribute('id'));
}else{
id_string +=String(row.getAttribute('id'));
}
}
}
console.log(id_string)
2022-03-13 20:02:55 +00:00
if($('#servers_table').find('input[type=search]').length == 0){
sendOrder(id_string)
}else{
console.log("Will not reorder when servers are filtered")
}
2022-02-26 23:00:54 +00:00
}
2022-03-13 20:02:55 +00:00
2022-02-26 23:00:54 +00:00
function sendOrder(id_string) {
var token = getCookie("_xsrf")
$.ajax({
type: "POST",
headers: {'X-XSRFToken': token},
url: '/ajax/send_order?order='+id_string,
data: {
order: id_string,
},
success: function(data){
console.log("got response:");
console.log(data);
},
});
}
2022-03-13 20:02:55 +00:00
$(document).ready(function () {
var servers_table = $('#servers_table').DataTable({
"ordering": false, // false to disable sorting (or any other option)
"paging": false
});
document.getElementById('first').setAttribute('draggable', false);
$('.dataTables_length').addClass('bs-select');
});
2022-03-13 20:41:27 +00:00
$(document).mousedown(function( event ) {
let value = $('.dataTables_filter input').val()
if(value === ''){
const table = document.querySelector("table");
for (const row of table.rows) {
row.setAttribute('draggable', true)
2022-03-13 20:02:55 +00:00
}
2022-03-13 20:41:27 +00:00
}else{
const table = document.querySelector("table");
for (const row of table.rows) {
row.setAttribute('draggable', false)
}
}
} );
2022-02-26 23:00:54 +00:00
< / script >
2020-08-24 23:11:17 +00:00
2022-02-27 17:26:54 +00:00
{% end %}