2020-09-04 02:49:20 +00:00
< div class = "row" >
2022-01-21 22:50:04 +00:00
< div class = "col-sm-12 grid-margin" >
< div class = "card" >
< div class = "card-body pt-3 pb-3" >
< div class = "row" >
< div class = "col-sm-4 mr-2" >
{% if data['server_stats']['running'] %}
2024-01-31 22:04:22 +00:00
< b > {{ translate('serverStats', 'serverStatus', data['lang']) }}:< / b > < span id = "status" 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', 'serverUptime', data['lang']) }}:< / b > < span id = "uptime" > {{ translate('serverStats', 'errorCalculatingUptime', data['lang']) }}< / span >
2022-01-28 02:53:07 +00:00
{% elif data['server_stats']['crashed'] %}
2024-01-31 22:04:22 +00:00
< 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 / >
< 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 >
2022-01-21 22:50:04 +00:00
{% else %}
2024-01-31 22:04:22 +00:00
< b > {{ translate('serverStats', 'serverStatus', data['lang']) }}:< / b > < span id = "status" 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', 'serverUptime', data['lang']) }}:< / b > < span id = "uptime" class = "text-warning" > {{ translate('serverStats', 'offline', data['lang']) }}< / span >
2022-01-21 22:50:04 +00:00
{% end %}
< br >
2024-01-31 22:04:22 +00:00
< b > {{ translate('serverStats', 'serverTimeZone', data['lang']) }}:< / b > < span class = "text-info" > {{ data['serverTZ'] }}< / span >
2020-09-04 02:49:20 +00:00
< / div >
2022-01-21 22:50:04 +00:00
< div class = "col-sm-3 mr-2" >
2024-01-31 22:04:22 +00:00
< b > {{ translate('serverStats', 'cpuUsage', data['lang']) }}:< / b > < span id = "cpu" > {{ data['server_stats']['cpu'] }}%< / span > < br / >
< b > {{ translate('serverStats', 'memUsage', data['lang']) }}:< / b > < span id = "mem" > {{ data['server_stats']['mem'] }}< / span > < br / >
2022-01-21 22:50:04 +00:00
{% if data['server_stats']['int_ping_results'] %}
2024-01-31 22:04:22 +00:00
< b > {{ translate('serverStats', 'players', data['lang']) }}:< / b > < span id = "players" > {{ data['server_stats']['online'] }} / {{ data['server_stats']['max'] }}< / span > < br / >
2022-01-21 22:50:04 +00:00
{% else %}
2022-05-14 23:51:05 +00:00
< b > {{ translate('serverStats', 'players', data['lang']) }}:< / b > < span id = "players" > 0/0< / span > < br / >
2022-01-21 22:50:04 +00:00
{% end %}
< / div >
< div class = "col-sm-3 mr-2" >
{% if data['server_stats']['version'] != 'False' %}
2024-01-31 22:04:22 +00:00
< b > {{ translate('serverStats', 'version', data['lang']) }}:< / b > < span id = "version" > {{ 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 >
2022-05-14 23:51:05 +00:00
< br / >
2022-01-21 22:50:04 +00:00
{% else %}
2024-01-31 22:04:22 +00:00
< b > {{ translate('serverStats', 'version', data['lang']) }}:< / b > < span id = "version" > {{ 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 / >
2022-01-21 22:50:04 +00:00
{% end %}
2022-02-26 17:29:07 +00:00
< b > Server Type: < span class = "text-info" > {{data['server_stats']['server_type']}}< / span > < / b >
2022-01-21 22:50:04 +00:00
< / div >
2020-09-04 02:49:20 +00:00
< / div >
< / div >
2022-01-21 22:50:04 +00:00
< / div >
2020-12-14 15:59:59 +00:00
< / div >
2022-01-21 22:50:04 +00:00
< / div >
2020-12-14 15:59:59 +00:00
2022-01-21 22:50:04 +00:00
< script src = "/static/assets/vendors/moment/moment.min.js" type = "text/javascript" charset = "utf-8" > < / script >
2021-11-19 22:01:47 +00:00
< script src = "/static/assets/js/motd.js" > < / script >
2020-12-14 15:59:59 +00:00
< script >
2022-01-21 22:50:04 +00:00
function durationToHumanizedString(duration) {
2020-12-14 21:52:46 +00:00
duration._data.months += duration._data.years * 12;
// 30.45833333333 = average month length, calculate with (31+28.5+31+30+31+30+31+31+30+31+30+31) / 12
duration._data.days += duration._data.months * 30.45833333333;
duration._data.hours += duration._data.days * 24;
let obj = {
hours: Math.round(duration._data.hours),
minutes: duration._data.minutes,
seconds: duration._data.seconds
}
2022-05-14 23:51:05 +00:00
if (Math.round(duration._data.days)) {
obj = {
days: Math.round(duration._data.days),
hours: Math.round(duration._data.hours -= duration._data.days * 24),
minutes: duration._data.minutes,
seconds: duration._data.seconds
}
}
2020-12-14 21:52:46 +00:00
output = Object.entries(obj)
.map(([type, num]) => {
2022-01-21 22:50:04 +00:00
// make them strings
2020-12-14 21:52:46 +00:00
returnData = num + ' ' + type;
// remove the s in the end if the data is -1 or 1
2020-12-31 17:41:02 +00:00
if (num == -1 || num == 1)
2020-12-14 21:52:46 +00:00
returnData = returnData.slice(0, -1)
return returnData;
})
2020-12-14 15:59:59 +00:00
.map((v, i, a) => // example input: [1,2,3], output: "1, 2 and 3"
v + (i !== a.length - 1
2022-01-21 22:50:04 +00:00
? i !== a.length - 2
2020-12-14 15:59:59 +00:00
? ', '
: ' and '
: '')).join('');
2020-12-14 21:52:46 +00:00
return output;
}
2020-12-14 15:59:59 +00:00
2022-01-21 22:50:04 +00:00
let uptime = document.querySelector('#uptime');
let started = document.querySelector('#started');
let startedUTC;
let startedLocal;
let uptimeLoop;
2020-12-14 15:59:59 +00:00
2022-01-21 22:50:04 +00:00
document.body.onload = (() => {
2020-12-14 21:52:46 +00:00
console.log('calculateTime');
2022-02-27 17:26:54 +00:00
startedUTC = "{{ data['server_stats']['started'] }}";
2022-01-21 22:50:04 +00:00
if (startedUTC != 'False') {
2021-04-17 21:20:23 +00:00
console.log('started utc:', startedUTC);
2020-12-15 23:17:41 +00:00
startedUTC = moment.utc(startedUTC, 'YYYY-MM-DD HH:mm:ss');
2022-01-21 22:50:04 +00:00
var browserUTCOffset = moment().utcOffset(); // This is in minutes
2020-12-15 23:17:41 +00:00
2020-12-31 17:41:02 +00:00
startedLocal = startedUTC.utcOffset(browserUTCOffset);
startedLocalFormatted = startedLocal.format('YYYY-MM-DD HH:mm:ss');
2020-12-15 23:17:41 +00:00
2021-04-17 21:20:23 +00:00
console.log('started local time:', startedLocalFormatted);
2020-12-15 23:17:41 +00:00
2020-12-31 17:41:02 +00:00
started.textContent = startedLocalFormatted
2020-12-15 23:17:41 +00:00
}
2021-04-17 21:20:23 +00:00
var calculateUptime = () => {
2022-01-21 22:50:04 +00:00
var msdiff = moment().diff(startedLocal);
2020-12-14 21:52:46 +00:00
var diff = moment.duration(msdiff);
uptime.textContent = durationToHumanizedString(diff);
2021-04-17 21:20:23 +00:00
}
if (uptime != null & & started != null) {
2020-12-31 17:41:02 +00:00
console.log('startedLocal', startedLocal)
if (startedLocal) {
2022-01-21 22:50:04 +00:00
calculateUptime();
uptimeLoop = setInterval(calculateUptime, 1000);
2020-12-31 17:41:02 +00:00
}
2020-12-14 21:52:46 +00:00
}
2021-11-19 22:01:47 +00:00
initParser('input_motd', 'input_motd');
2020-12-14 21:52:46 +00:00
});
2022-01-21 22:50:04 +00:00
function update_server_details(server) {
server_status = document.getElementById('status');
server_started = document.getElementById('started');
server_uptime = document.getElementById('uptime');
server_cpu = document.getElementById('cpu');
server_mem = document.getElementById('mem');
server_players = document.getElementById('players');
server_version = document.getElementById('version');
server_input_motd = document.getElementById('input_motd');
/* TODO Update each element */
2022-05-14 23:51:05 +00:00
if (server.running) {
server_status.setAttribute("class", "text-success");
server_status.innerHTML = `{{ translate('serverStats', 'online', data['lang']) }}`;
2022-01-21 22:50:04 +00:00
startedUTC = server.started;
startedUTC = moment.utc(startedUTC, 'YYYY-MM-DD HH:mm:ss');
var browserUTCOffset = moment().utcOffset(); // This is in minutes
startedLocal = startedUTC.utcOffset(browserUTCOffset);
startedLocalFormatted = startedLocal.format('YYYY-MM-DD HH:mm:ss');
server_started.setAttribute("class", "");
2022-02-08 06:08:58 +00:00
server_started.innerHTML = startedLocalFormatted;
2022-01-21 22:50:04 +00:00
server_uptime.setAttribute("class", "");
if (!uptimeLoop) {
var calculateUptime = () => {
var msdiff = moment().diff(startedLocal);
var diff = moment.duration(msdiff);
uptime.textContent = durationToHumanizedString(diff);
}
uptimeLoop = setInterval(calculateUptime, 1000);
}
}
2022-05-14 23:51:05 +00:00
else {
if (server.crashed) {
2022-01-28 02:53:07 +00:00
server_status.setAttribute("class", "text-danger");
server_status.innerHTML = `< i class = "fas fa-exclamation-triangle" > < / i > {{ translate('dashboard', 'crashed', data['lang']) }}`;
server_started.setAttribute("class", "text-danger");
server_started.innerHTML = `< i class = "fas fa-exclamation-triangle" > < / i > {{ translate('dashboard', 'crashed', data['lang']) }}`;
clearInterval(uptimeLoop);
uptimeLoop = null;
server_uptime.setAttribute("class", "text-danger");
server_uptime.innerHTML = `< i class = "fas fa-exclamation-triangle" > < / i > {{ translate('dashboard', 'crashed', data['lang']) }}`;
2022-05-14 23:51:05 +00:00
} else {
server_status.setAttribute("class", "text-warning");
server_status.innerHTML = `{{ translate('serverStats', 'offline', data['lang']) }}`;
server_started.setAttribute("class", "text-warning");
server_started.innerHTML = `{{ translate('serverStats', 'offline', data['lang']) }}`;
clearInterval(uptimeLoop);
uptimeLoop = null;
server_uptime.setAttribute("class", "text-warning");
server_uptime.innerHTML = `{{ translate('serverStats', 'offline', data['lang']) }}`;
2022-01-28 02:53:07 +00:00
}
2022-01-21 22:50:04 +00:00
}
server_cpu.innerHTML = server.cpu + ` %`;
server_mem.innerHTML = server.mem;
2022-05-14 23:51:05 +00:00
if (server.int_ping_results) {
2022-01-21 22:50:04 +00:00
server_players.innerHTML = server.online + `/` + server.max;
}
2022-05-14 23:51:05 +00:00
else {
2022-01-21 22:50:04 +00:00
server_players.innerHTML = `0/0`;
}
2022-05-14 23:51:05 +00:00
if (server.version) {
2022-01-21 22:50:04 +00:00
server_version.innerHTML = server.version;
server_input_motd.innerHTML = server.desc;
}
2022-05-14 23:51:05 +00:00
else {
2022-01-21 22:50:04 +00:00
server_version.innerHTML = `{{ translate('serverStats', 'unableToConnect', data['lang']) }}`;
server_input_motd.innerHTML = `{{ translate('serverStats', 'unableToConnect', data['lang']) }}`;
}
initParser('input_motd', 'input_motd');
2023-05-30 04:02:11 +00:00
let text = ""
2024-01-31 22:04:22 +00:00
let players = server.players_cache;
for (let i = 0; i < players.length ; i + + ) {
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 > `;
if (players[i]["status"] === "Online") {
text += `< td > < span class = "text-success" > < i class = "fas fa-signal" > < / i > ${players[i]['status']}< / span > < / td > `
} else {
text += `< td > < span class = "text-warning" > < i class = "fa-regular fa-circle-xmark" > < / i > < span class = "offline-status" > ${players[i]['status']}< / span > < span class = "conn-break" > Last connection :< br > ${players[i]['last_seen']}< / span > < / td > `
}
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 > `
} else {
text += `< td > < span > Unavailable< br > (Server Offline)< / span > < / td > `
}
2023-05-30 04:02:11 +00:00
2024-01-31 22:04:22 +00:00
}
$("#player-body").html(text);
2022-01-21 22:50:04 +00:00
}
2023-11-05 17:06:57 +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;
}
const token = getCookie("_xsrf")
2022-01-21 22:50:04 +00:00
$(window).ready(function () {
console.log("ready!");
//if (webSocket) {
webSocket.on('update_server_details', update_server_details);
2023-11-05 17:06:57 +00:00
add_server_name();
2022-01-21 22:50:04 +00:00
//}
});
2024-01-31 22:04:22 +00:00
async function add_server_name() {
2023-11-05 17:06:57 +00:00
let res = await fetch(`/api/v2/servers/${serverId}`, {
2024-01-31 22:04:22 +00:00
method: 'GET',
headers: {
'X-XSRFToken': token
},
});
let responseData = await res.json();
if (responseData.status === "ok") {
console.log(responseData)
$("#server-name-nav").html(`${responseData.data['server_name']}`)
$("#server-name-nav").show();
} else {
2023-11-05 17:06:57 +00:00
2024-01-31 22:04:22 +00:00
bootbox.alert({
title: responseData.error,
message: responseData.error_data
});
}
2023-11-05 17:06:57 +00:00
}
2022-05-14 23:51:05 +00:00
< / script >