Fixing issue 322

This commit is contained in:
Silversthorn 2024-01-31 23:04:22 +01:00
parent a68be59396
commit d92d06e4b1
6 changed files with 76 additions and 95 deletions

View File

@ -96,7 +96,7 @@ function initParser(input, output) {
var input = document.getElementById(input), var input = document.getElementById(input),
output = document.getElementById(output); output = document.getElementById(output);
if (input != null && output != null) { if (input != null && output != null) {
var parsed = parseStyle(input.innerHTML); var parsed = parseStyle(input.innerText);
output.innerHTML = ''; output.innerHTML = '';
output.appendChild(parsed); output.appendChild(parsed);
} }

View File

@ -287,8 +287,7 @@
data['lang']) }} <br /> data['lang']) }} <br />
{% if server['stats']['desc'] != 'False' %} {% if server['stats']['desc'] != 'False' %}
<div id="desc_id" style="overflow-wrap: break-word !important; max-width: 85px !important; overflow: scroll;">{{ <div id="desc_id" style="overflow-wrap: break-word !important; max-width: 85px !important; overflow: scroll;">{{ translate('serverStats', 'loadingMotd', data['lang']) }}</div> <br />
server['stats']['desc'] }}</div> <br />
{% end %} {% end %}
{% if server['stats']['version'] != 'False' %} {% if server['stats']['version'] != 'False' %}
@ -554,6 +553,7 @@
display: none; display: none;
/* for Chrome, Safari, and Opera */ /* for Chrome, Safari, and Opera */
} }
.gray { .gray {
color: gray !important; color: gray !important;
} }
@ -736,11 +736,11 @@
try { try {
console.log(`#server_desc_${server.getAttribute("data-serverId")}`) console.log(`#server_desc_${server.getAttribute("data-serverId")}`)
$(`#server_desc_${server.getAttribute("data-serverId")}`).toggleClass("gray", server.getAttribute('data-count') === 'false') $(`#server_desc_${server.getAttribute("data-serverId")}`).toggleClass("gray", server.getAttribute('data-count') === 'false')
if (server.getAttribute('data-count') === 'true'){ if (server.getAttribute('data-count') === 'true') {
all_total_players += parseInt(server.getAttribute('data-players')); all_total_players += parseInt(server.getAttribute('data-players'));
all_total_max_players += parseInt(server.getAttribute('data-max')); all_total_max_players += parseInt(server.getAttribute('data-max'));
} }
} catch { } catch {
console.log("Player totals are not of type int"); console.log("Player totals are not of type int");
} }
}) })
@ -1006,24 +1006,24 @@
async function sendOrder(id_string) { async function sendOrder(id_string) {
const token = getCookie("_xsrf") const token = getCookie("_xsrf")
let res = await fetch(`/api/v2/users/@me`, { let res = await fetch(`/api/v2/users/@me`, {
method: 'PATCH', method: 'PATCH',
headers: { headers: {
'X-XSRFToken': token 'X-XSRFToken': token
}, },
body: JSON.stringify({ body: JSON.stringify({
server_order: id_string, server_order: id_string,
}), }),
});
let responseData = await res.json();
if (responseData.status === "ok") {
return
} else {
bootbox.alert({
title: responseData.status,
message: responseData.error
}); });
} let responseData = await res.json();
if (responseData.status === "ok") {
return
} else {
bootbox.alert({
title: responseData.status,
message: responseData.error
});
}
} }
// Inits the sortable // Inits the sortable
$("table#servers_table tbody") $("table#servers_table tbody")

View File

@ -5,42 +5,27 @@
<div class="row"> <div class="row">
<div class="col-sm-4 mr-2"> <div class="col-sm-4 mr-2">
{% if data['server_stats']['running'] %} {% if data['server_stats']['running'] %}
<b>{{ translate('serverStats', 'serverStatus', data['lang']) }}:</b> <span id="status" <b>{{ translate('serverStats', 'serverStatus', data['lang']) }}:</b> <span id="status" class="text-success">{{ translate('serverStats', 'online', data['lang']) }}</span><br />
class="text-success">{{ translate('serverStats', 'online', data['lang']) }}</span><br /> <b>{{ translate('serverStats', 'serverStarted', data['lang']) }}:</b> <span id="started">{{ data['server_stats']['started'] }}</span><br />
<b>{{ translate('serverStats', 'serverStarted', data['lang']) }}:</b> <span id="started">{{ <b>{{ translate('serverStats', 'serverUptime', data['lang']) }}:</b> <span id="uptime">{{ translate('serverStats', 'errorCalculatingUptime', data['lang']) }}</span>
data['server_stats']['started'] }}</span><br />
<b>{{ translate('serverStats', 'serverUptime', data['lang']) }}:</b> <span id="uptime">{{
translate('serverStats', 'errorCalculatingUptime', data['lang']) }}</span>
{% elif data['server_stats']['crashed'] %} {% elif data['server_stats']['crashed'] %}
<b>{{ translate('serverStats', 'serverStatus', data['lang']) }}:</b> <span id="status" class="text-danger"> <b>{{ translate('serverStats', 'serverStatus', data['lang']) }}:</b> <span id="status" class="text-danger"> <i class="fas fa-exclamation-triangle"></i> {{ translate('dashboard', 'crashed', data['lang']) }}</span><br />
<i class="fas fa-exclamation-triangle"></i> {{ translate('dashboard', 'crashed', data['lang']) <b>{{ translate('serverStats', 'serverStarted', data['lang']) }}:</b> <span id="started" class="text-danger"> <i class="fas fa-exclamation-triangle"></i> {{ translate('dashboard', 'crashed',data['lang']) }}</span><br />
}}</span><br /> <b>{{ translate('serverStats', 'serverUptime', data['lang']) }}:</b> <span id="uptime" class="text-danger"> <i class="fas fa-exclamation-triangle"></i> {{ translate('dashboard', 'crashed', data['lang']) }}</span>
<b>{{ translate('serverStats', 'serverStarted', data['lang']) }}:</b> <span id="started"
class="text-danger"> <i class="fas fa-exclamation-triangle"></i> {{ translate('dashboard', 'crashed',
data['lang']) }}</span><br />
<b>{{ translate('serverStats', 'serverUptime', data['lang']) }}:</b> <span id="uptime" class="text-danger">
<i class="fas fa-exclamation-triangle"></i> {{ translate('dashboard', 'crashed', data['lang']) }}</span>
{% else %} {% else %}
<b>{{ translate('serverStats', 'serverStatus', data['lang']) }}:</b> <span id="status" <b>{{ translate('serverStats', 'serverStatus', data['lang']) }}:</b> <span id="status" class="text-warning">{{ translate('serverStats', 'offline', data['lang']) }}</span><br />
class="text-warning">{{ translate('serverStats', 'offline', data['lang']) }}</span><br /> <b>{{ translate('serverStats', 'serverStarted', data['lang']) }}:</b> <span id="started" class="text-warning">{{ translate('serverStats', 'offline', data['lang']) }}</span><br />
<b>{{ translate('serverStats', 'serverStarted', data['lang']) }}:</b> <span id="started" <b>{{ translate('serverStats', 'serverUptime', data['lang']) }}:</b> <span id="uptime" class="text-warning">{{ translate('serverStats', 'offline', data['lang']) }}</span>
class="text-warning">{{ translate('serverStats', 'offline', data['lang']) }}</span><br />
<b>{{ translate('serverStats', 'serverUptime', data['lang']) }}:</b> <span id="uptime"
class="text-warning">{{ translate('serverStats', 'offline', data['lang']) }}</span>
{% end %} {% end %}
<br> <br>
<b>{{ translate('serverStats', 'serverTimeZone', data['lang']) }}:</b> <span class="text-info">{{ <b>{{ translate('serverStats', 'serverTimeZone', data['lang']) }}:</b> <span class="text-info">{{ data['serverTZ'] }}</span>
data['serverTZ'] }}</span>
</div> </div>
<div class="col-sm-3 mr-2"> <div class="col-sm-3 mr-2">
<b>{{ translate('serverStats', 'cpuUsage', data['lang']) }}:</b> <span id="cpu">{{ <b>{{ translate('serverStats', 'cpuUsage', data['lang']) }}:</b> <span id="cpu">{{ data['server_stats']['cpu'] }}%</span> <br />
data['server_stats']['cpu'] }}%</span> <br /> <b>{{ translate('serverStats', 'memUsage', data['lang']) }}:</b> <span id="mem">{{ data['server_stats']['mem'] }}</span> <br />
<b>{{ translate('serverStats', 'memUsage', data['lang']) }}:</b> <span id="mem">{{
data['server_stats']['mem'] }}</span> <br />
{% if data['server_stats']['int_ping_results'] %} {% if data['server_stats']['int_ping_results'] %}
<b>{{ translate('serverStats', 'players', data['lang']) }}:</b> <span id="players">{{ <b>{{ translate('serverStats', 'players', data['lang']) }}:</b> <span id="players">{{ data['server_stats']['online'] }} / {{ data['server_stats']['max'] }}</span><br />
data['server_stats']['online'] }} / {{ data['server_stats']['max'] }}</span><br />
{% else %} {% else %}
<b>{{ translate('serverStats', 'players', data['lang']) }}:</b> <span id="players">0/0</span><br /> <b>{{ translate('serverStats', 'players', data['lang']) }}:</b> <span id="players">0/0</span><br />
{% end %} {% end %}
@ -48,17 +33,12 @@
<div class="col-sm-3 mr-2"> <div class="col-sm-3 mr-2">
{% if data['server_stats']['version'] != 'False' %} {% if data['server_stats']['version'] != 'False' %}
<b>{{ translate('serverStats', 'version', data['lang']) }}:</b> <span id="version">{{ <b>{{ translate('serverStats', 'version', data['lang']) }}:</b> <span id="version">{{ data['server_stats']['version'] }}</span><br />
data['server_stats']['version'] }}</span><br /> <b>{{ translate('serverStats', 'description', data['lang']) }}:</b> <span id="input_motd" style="max-width: 10px; max-height: 10px" class="input_motd">{{ translate('serverStats', 'loadingMotd', data['lang']) }}</span>
<b>{{ translate('serverStats', 'description', data['lang']) }}:</b> <span id="input_motd"
style="max-width: 10px; max-height: 10px" class="input_motd">{{ data['server_stats']['desc'] }}</span>
<br /> <br />
{% else %} {% else %}
<b>{{ translate('serverStats', 'version', data['lang']) }}:</b> <span id="version">{{ <b>{{ translate('serverStats', 'version', data['lang']) }}:</b> <span id="version">{{ translate('serverStats', 'unableToConnect', data['lang']) }}</span> <br />
translate('serverStats', 'unableToConnect', data['lang']) }}</span> <br /> <b>{{ translate('serverStats', 'description', data['lang']) }}:</b> <span style="max-width: 10px; max-height: 10px" id="input_motd" class="input_motd">{{ translate('serverStats', 'unableToConnect', data['lang']) }}</span> <br />
<b>{{ translate('serverStats', 'description', data['lang']) }}:</b> <span
style="max-width: 10px; max-height: 10px" id="input_motd" class="input_motd">{{ translate('serverStats',
'unableToConnect', data['lang']) }}</span> <br />
{% end %} {% end %}
<b>Server Type: <span class="text-info">{{data['server_stats']['server_type']}}</span></b> <b>Server Type: <span class="text-info">{{data['server_stats']['server_type']}}</span></b>
@ -229,23 +209,23 @@
initParser('input_motd', 'input_motd'); initParser('input_motd', 'input_motd');
let text = "" let text = ""
let players = server.players_cache; let players = server.players_cache;
for(let i=0; i < players.length; i++){ for (let i = 0; i < players.length; i++) {
text += `<tr id="playerItem-${ players[i]["name"] }" class="playerItem--" style="text-align: center;">`; text += `<tr id="playerItem-${players[i]["name"]}" class="playerItem--" style="text-align: center;">`;
text += `<td class="no-scroll" style="overflow: scroll;"><strong>${players[i]["name"]}</strong></td>`; text += `<td class="no-scroll" style="overflow: scroll;"><strong>${players[i]["name"]}</strong></td>`;
if(players[i]["status"] === "Online"){ if (players[i]["status"] === "Online") {
text += `<td><span class="text-success"><i class="fas fa-signal"></i> ${ players[i]['status'] }</span></td>` text += `<td><span class="text-success"><i class="fas fa-signal"></i> ${players[i]['status']}</span></td>`
}else{ } else {
text += `<td><span class="text-warning"><i class="fa-regular fa-circle-xmark"></i><span class="offline-status">&nbsp;${ players[i]['status'] }</span><span class="conn-break"> Last connection :<br> ${ players[i]['last_seen'] }</span></td>` text += `<td><span class="text-warning"><i class="fa-regular fa-circle-xmark"></i><span class="offline-status">&nbsp;${players[i]['status']}</span><span class="conn-break"> Last connection :<br> ${players[i]['last_seen']}</span></td>`
} }
if(server["running"]){ if (server["running"]) {
text += `<td><button onclick="send_command_to_server('ban ${ players[i]['name'] }')" type="button" class="btn btn-danger controls">Ban</button><br class="mobile-break"><button onclick="send_command_to_server('kick ${ players[i]['name'] }')" type="button" class="btn btn-outline-danger controls">Kick</button><br><button onclick="send_command_to_server('op ${ players[i]['name'] }')" type="button" class="btn btn-warning controls">OP</button><br class="mobile-break"><button onclick="send_command_to_server('deop ${ players[i]['name'] }')" type="button" class="btn btn-outline-warning controls">De-OP</button></td>` text += `<td><button onclick="send_command_to_server('ban ${players[i]['name']}')" type="button" class="btn btn-danger controls">Ban</button><br class="mobile-break"><button onclick="send_command_to_server('kick ${players[i]['name']}')" type="button" class="btn btn-outline-danger controls">Kick</button><br><button onclick="send_command_to_server('op ${players[i]['name']}')" type="button" class="btn btn-warning controls">OP</button><br class="mobile-break"><button onclick="send_command_to_server('deop ${players[i]['name']}')" type="button" class="btn btn-outline-warning controls">De-OP</button></td>`
}else{ } else {
text += `<td><span> Unavailable<br> (Server Offline)</span></td>` text += `<td><span> Unavailable<br> (Server Offline)</span></td>`
} }
} }
$("#player-body").html(text); $("#player-body").html(text);
} }
//used to get cookies from browser - this is part of tornados xsrf protection - it's for extra security //used to get cookies from browser - this is part of tornados xsrf protection - it's for extra security
@ -262,24 +242,24 @@
add_server_name(); add_server_name();
//} //}
}); });
async function add_server_name(){ async function add_server_name() {
let res = await fetch(`/api/v2/servers/${serverId}`, { let res = await fetch(`/api/v2/servers/${serverId}`, {
method: 'GET', method: 'GET',
headers: { headers: {
'X-XSRFToken': token 'X-XSRFToken': token
}, },
}); });
let responseData = await res.json(); let responseData = await res.json();
if (responseData.status === "ok") { if (responseData.status === "ok") {
console.log(responseData) console.log(responseData)
$("#server-name-nav").html(`${responseData.data['server_name']}`) $("#server-name-nav").html(`${responseData.data['server_name']}`)
$("#server-name-nav").show(); $("#server-name-nav").show();
} else { } else {
bootbox.alert({ bootbox.alert({
title: responseData.error, title: responseData.error,
message: responseData.error_data message: responseData.error_data
}); });
} }
} }
</script> </script>

View File

@ -49,7 +49,7 @@
<img src="/static/assets/images/pack.png" alt="icon" style="-webkit-filter:grayscale(100%); filter:grayscale(100%)" /> <img src="/static/assets/images/pack.png" alt="icon" style="-webkit-filter:grayscale(100%); filter:grayscale(100%)" />
</div> </div>
<div class="col-auto"> <div class="col-auto">
<span id="input_motd_{{ server['stats']['server_id']['server_id'] }}" class="input_motd">{{ server['stats']['desc'] }}</span> <span id="input_motd_{{ server['stats']['server_id']['server_id'] }}" class="input_motd">{{ translate('serverStats', 'loadingMotd', data['lang']) }}</span>
</div> </div>
</div> </div>
{% end %} {% end %}
@ -133,8 +133,7 @@
<div class="media-body"> <div class="media-body">
{% if server['stats']['desc'] != 'False' %} {% if server['stats']['desc'] != 'False' %}
<div id="m_server_motd_{{ server['stats']['server_id']['server_id'] }}"> <div id="m_server_motd_{{ server['stats']['server_id']['server_id'] }}">
<span id="m_input_motd_{{ server['stats']['server_id']['server_id'] }}" class="input_motd">{{ <span id="m_input_motd_{{ server['stats']['server_id']['server_id'] }}" class="input_motd">{{ translate('serverStats', 'loadingMotd', data['lang']) }}</span> <br />
server['stats']['desc'] }}</span> <br />
</div> </div>
{% end %} {% end %}
</div> </div>

View File

@ -512,6 +512,7 @@
"cpuUsage": "CPU Usage", "cpuUsage": "CPU Usage",
"description": "Description", "description": "Description",
"errorCalculatingUptime": "Error Calculating Uptime", "errorCalculatingUptime": "Error Calculating Uptime",
"loadingMotd": "Loading MOTD",
"memUsage": "Memory Usage", "memUsage": "Memory Usage",
"offline": "Offline", "offline": "Offline",
"online": "Online", "online": "Online",

View File

@ -512,6 +512,7 @@
"cpuUsage": "Utilisation CPU", "cpuUsage": "Utilisation CPU",
"description": "Description", "description": "Description",
"errorCalculatingUptime": "Erreur de Calcul du Temps de Disponibilité", "errorCalculatingUptime": "Erreur de Calcul du Temps de Disponibilité",
"loadingMotd": "Chargement MOTD",
"memUsage": "Utilisation Mémoire", "memUsage": "Utilisation Mémoire",
"offline": "Hors Ligne", "offline": "Hors Ligne",
"online": "En Ligne", "online": "En Ligne",