2017-01-24 22:57:08 +00:00
|
|
|
// Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>
|
2017-01-15 23:52:22 +00:00
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
|
|
// in the Software without restriction, including without limitation the rights
|
|
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
|
|
// furnished to do so, subject to the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included in all
|
|
|
|
// copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
// SOFTWARE.
|
2017-06-29 02:39:30 +00:00
|
|
|
var CONSOLE_PUSH_COUNT = Pterodactyl.config.console_count || 50;
|
2017-04-14 05:21:38 +00:00
|
|
|
var CONSOLE_PUSH_FREQ = Pterodactyl.config.console_freq || 200;
|
|
|
|
var CONSOLE_OUTPUT_LIMIT = Pterodactyl.config.console_limit || 2000;
|
2017-06-27 03:36:09 +00:00
|
|
|
|
2017-07-01 01:41:16 +00:00
|
|
|
var KEYCODE_UP_ARROW = 38;
|
|
|
|
var KEYCODE_DOWN_ARROW = 40;
|
|
|
|
|
2017-06-27 03:36:09 +00:00
|
|
|
var AnsiUp = new AnsiUp;
|
2017-06-29 02:39:30 +00:00
|
|
|
AnsiUp.use_classes = true;
|
2017-04-14 05:21:38 +00:00
|
|
|
|
2017-06-27 03:36:09 +00:00
|
|
|
var $terminal = $('#terminal');
|
2017-07-01 01:41:16 +00:00
|
|
|
var $terminalInput = $('.terminal_input--input');
|
2017-06-27 03:36:09 +00:00
|
|
|
var $scrollNotify = $('#terminalNotify');
|
|
|
|
|
|
|
|
$(document).ready(function () {
|
2017-07-01 01:41:16 +00:00
|
|
|
var storage = window.localStorage;
|
|
|
|
var activeHx = [];
|
|
|
|
var currentHxIndex = 0;
|
|
|
|
var currentKeyCount = 0;
|
|
|
|
|
|
|
|
var storedConsoleHistory = storage.getItem('console_hx_' + Pterodactyl.server.uuid);
|
|
|
|
try {
|
|
|
|
activeHx = JSON.parse(storedConsoleHistory) || [];
|
|
|
|
currentKeyCount = activeHx.length - 1;
|
|
|
|
} catch (ex) {
|
|
|
|
//
|
|
|
|
}
|
2017-06-27 03:36:09 +00:00
|
|
|
|
2017-07-01 01:41:16 +00:00
|
|
|
$terminalInput.focus();
|
|
|
|
$('.terminal_input--prompt, #terminal_input, #terminal, #terminalNotify').on('click', function () {
|
|
|
|
$terminalInput.focus();
|
2017-04-14 05:21:38 +00:00
|
|
|
});
|
2017-01-15 23:52:22 +00:00
|
|
|
|
2017-07-01 01:41:16 +00:00
|
|
|
$terminalInput.on('keyup', function (e) {
|
|
|
|
if (e.which === KEYCODE_DOWN_ARROW || e.which === KEYCODE_UP_ARROW) {
|
|
|
|
var value = consoleHistory(e.which);
|
|
|
|
|
|
|
|
if (value !== false) {
|
|
|
|
$terminalInput.val(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (e.which === 27) {
|
|
|
|
$(this).val('');
|
|
|
|
}
|
|
|
|
|
2017-06-27 03:36:09 +00:00
|
|
|
if (e.which === 13) {
|
2017-07-01 01:41:16 +00:00
|
|
|
saveToHistory($(this).val());
|
2017-06-27 03:36:09 +00:00
|
|
|
Socket.emit((ConsoleServerStatus !== 0) ? 'send command' : 'set status', $(this).val());
|
2017-01-26 21:57:33 +00:00
|
|
|
|
2017-06-27 03:36:09 +00:00
|
|
|
$(this).val('');
|
2017-04-14 05:21:38 +00:00
|
|
|
}
|
2017-06-27 03:36:09 +00:00
|
|
|
});
|
2017-07-01 01:41:16 +00:00
|
|
|
|
|
|
|
function consoleHistory(key) {
|
|
|
|
// Get previous
|
|
|
|
if (key === KEYCODE_UP_ARROW) {
|
|
|
|
// currentHxIndex++;
|
|
|
|
var index = activeHx.length - (currentHxIndex + 1);
|
|
|
|
|
|
|
|
if (typeof activeHx[index - 1] === 'undefined') {
|
|
|
|
return activeHx[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
currentHxIndex++;
|
|
|
|
return activeHx[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get more recent
|
|
|
|
if (key === KEYCODE_DOWN_ARROW) {
|
|
|
|
var index = activeHx.length - currentHxIndex;
|
|
|
|
|
|
|
|
if (typeof activeHx[index + 1] === 'undefined') {
|
|
|
|
return activeHx[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
currentHxIndex--;
|
|
|
|
return activeHx[index];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function saveToHistory(command) {
|
|
|
|
if (command.length === 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (activeHx.length >= 50) {
|
|
|
|
activeHx.pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
currentHxIndex = 0;
|
|
|
|
currentKeyCount++;
|
|
|
|
activeHx[currentKeyCount] = command;
|
|
|
|
|
|
|
|
storage.setItem('console_hx_' + Pterodactyl.server.uuid, JSON.stringify(activeHx));
|
|
|
|
}
|
2017-06-27 03:36:09 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$terminal.on('scroll', function () {
|
2017-07-03 06:46:53 +00:00
|
|
|
if ($(this).scrollTop() + $(this).innerHeight() + 50 < $(this)[0].scrollHeight) {
|
2017-06-27 03:36:09 +00:00
|
|
|
$scrollNotify.removeClass('hidden');
|
|
|
|
} else {
|
|
|
|
$scrollNotify.addClass('hidden');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
window.scrollToBottom = function () {
|
|
|
|
$terminal.scrollTop($terminal[0].scrollHeight);
|
|
|
|
};
|
|
|
|
|
2017-06-29 02:39:30 +00:00
|
|
|
function pushToTerminal(string) {
|
|
|
|
$terminal.append('<div class="cmd">' + AnsiUp.ansi_to_html(string + '\u001b[0m') + '</div>');
|
|
|
|
}
|
|
|
|
|
2017-06-27 03:36:09 +00:00
|
|
|
(function initConsole() {
|
|
|
|
window.TerminalQueue = [];
|
|
|
|
window.ConsoleServerStatus = 0;
|
|
|
|
window.ConsoleElements = 0;
|
|
|
|
|
|
|
|
$scrollNotify.on('click', function () {
|
|
|
|
window.scrollToBottom();
|
|
|
|
$scrollNotify.addClass('hidden');
|
|
|
|
});
|
2017-04-14 05:21:38 +00:00
|
|
|
})();
|
2017-01-26 21:57:33 +00:00
|
|
|
|
2017-04-14 05:21:38 +00:00
|
|
|
(function pushOutputQueue() {
|
|
|
|
if (TerminalQueue.length > CONSOLE_PUSH_COUNT) {
|
|
|
|
// console throttled warning show
|
2017-01-26 21:20:04 +00:00
|
|
|
}
|
|
|
|
|
2017-04-14 05:21:38 +00:00
|
|
|
if (TerminalQueue.length > 0) {
|
|
|
|
for (var i = 0; i < CONSOLE_PUSH_COUNT && TerminalQueue.length > 0; i++) {
|
2017-06-29 02:39:30 +00:00
|
|
|
pushToTerminal(TerminalQueue[0]);
|
2017-06-27 03:36:09 +00:00
|
|
|
|
|
|
|
if (! $scrollNotify.is(':visible')) {
|
|
|
|
window.scrollToBottom();
|
|
|
|
}
|
|
|
|
|
|
|
|
window.ConsoleElements++;
|
2017-04-14 05:21:38 +00:00
|
|
|
TerminalQueue.shift();
|
|
|
|
}
|
2017-01-26 21:20:04 +00:00
|
|
|
|
2017-06-27 03:36:09 +00:00
|
|
|
var removeElements = window.ConsoleElements - CONSOLE_OUTPUT_LIMIT;
|
|
|
|
if (removeElements > 0) {
|
|
|
|
$('#terminal').find('.cmd').slice(0, removeElements).remove();
|
|
|
|
window.ConsoleElements = window.ConsoleElements - removeElements;
|
2017-04-14 05:21:38 +00:00
|
|
|
}
|
|
|
|
}
|
2017-01-26 21:20:04 +00:00
|
|
|
|
2017-04-14 05:21:38 +00:00
|
|
|
window.setTimeout(pushOutputQueue, CONSOLE_PUSH_FREQ);
|
|
|
|
})();
|
2017-01-26 21:20:04 +00:00
|
|
|
|
2017-04-14 05:21:38 +00:00
|
|
|
(function setupSocketListeners() {
|
|
|
|
// Update Listings on Initial Status
|
|
|
|
Socket.on('initial status', function (data) {
|
2017-04-15 22:23:29 +00:00
|
|
|
ConsoleServerStatus = data.status;
|
2017-06-29 02:39:30 +00:00
|
|
|
updateServerPowerControls(data.status);
|
2017-01-26 21:20:04 +00:00
|
|
|
|
2017-06-29 02:39:30 +00:00
|
|
|
if (data.status === 1 || data.status === 2) {
|
|
|
|
Socket.emit('send server log');
|
2017-01-15 23:52:22 +00:00
|
|
|
}
|
2017-04-14 05:21:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Update Listings on Status
|
|
|
|
Socket.on('status', function (data) {
|
2017-04-15 22:23:29 +00:00
|
|
|
ConsoleServerStatus = data.status;
|
2017-04-14 05:21:38 +00:00
|
|
|
updateServerPowerControls(data.status);
|
|
|
|
});
|
|
|
|
|
2017-06-29 02:39:30 +00:00
|
|
|
// Skips the queue so we don't wait
|
|
|
|
// 10 minutes to load the log...
|
2017-04-14 05:21:38 +00:00
|
|
|
Socket.on('server log', function (data) {
|
2017-06-29 02:39:30 +00:00
|
|
|
$('#terminal').html('');
|
|
|
|
data.split(/\n/g).forEach(function (item) {
|
|
|
|
pushToTerminal(item);
|
|
|
|
window.scrollToBottom();
|
|
|
|
});
|
2017-04-14 05:21:38 +00:00
|
|
|
});
|
2017-01-26 21:12:33 +00:00
|
|
|
|
2017-04-14 05:21:38 +00:00
|
|
|
Socket.on('console', function (data) {
|
2017-06-27 03:36:09 +00:00
|
|
|
data.line.split(/\n/g).forEach(function (item) {
|
|
|
|
TerminalQueue.push(item);
|
|
|
|
});
|
2017-04-14 05:21:38 +00:00
|
|
|
});
|
|
|
|
})();
|
2017-01-26 21:57:33 +00:00
|
|
|
|
2017-04-14 05:21:38 +00:00
|
|
|
function updateServerPowerControls (data) {
|
|
|
|
// Server is On or Starting
|
|
|
|
if(data == 1 || data == 2) {
|
|
|
|
$('[data-attr="power"][data-action="start"]').addClass('disabled');
|
|
|
|
$('[data-attr="power"][data-action="stop"], [data-attr="power"][data-action="restart"]').removeClass('disabled');
|
|
|
|
} else {
|
|
|
|
if (data == 0) {
|
|
|
|
$('[data-attr="power"][data-action="start"]').removeClass('disabled');
|
2017-01-26 21:12:33 +00:00
|
|
|
}
|
2017-04-14 05:21:38 +00:00
|
|
|
$('[data-attr="power"][data-action="stop"], [data-attr="power"][data-action="restart"]').addClass('disabled');
|
|
|
|
}
|
2017-01-26 21:12:33 +00:00
|
|
|
|
2017-04-14 05:21:38 +00:00
|
|
|
if(data !== 0) {
|
|
|
|
$('[data-attr="power"][data-action="kill"]').removeClass('disabled');
|
|
|
|
} else {
|
|
|
|
$('[data-attr="power"][data-action="kill"]').addClass('disabled');
|
2017-01-15 23:52:22 +00:00
|
|
|
}
|
2017-04-14 05:21:38 +00:00
|
|
|
}
|
2017-01-15 23:52:22 +00:00
|
|
|
|
2017-04-14 05:21:38 +00:00
|
|
|
$(document).ready(function () {
|
|
|
|
$('[data-attr="power"]').click(function (event) {
|
|
|
|
if (! $(this).hasClass('disabled')) {
|
|
|
|
Socket.emit('set status', $(this).data('action'));
|
2017-01-26 21:20:04 +00:00
|
|
|
}
|
2017-04-14 05:21:38 +00:00
|
|
|
});
|
2017-01-26 21:20:04 +00:00
|
|
|
|
2017-04-15 22:23:29 +00:00
|
|
|
(function setupChartElements() {
|
|
|
|
if (typeof SkipConsoleCharts !== 'undefined') {
|
|
|
|
return;
|
2017-01-26 21:20:04 +00:00
|
|
|
}
|
|
|
|
|
2017-04-15 22:23:29 +00:00
|
|
|
Socket.on('proc', function (proc) {
|
|
|
|
if (CPUData.length > 10) {
|
|
|
|
CPUData.shift();
|
|
|
|
MemoryData.shift();
|
|
|
|
TimeLabels.shift();
|
2017-04-14 05:21:38 +00:00
|
|
|
}
|
|
|
|
|
2017-04-15 22:23:29 +00:00
|
|
|
var cpuUse = (Pterodactyl.server.cpu > 0) ? parseFloat(((proc.data.cpu.total / Pterodactyl.server.cpu) * 100).toFixed(3).toString()) : proc.data.cpu.total;
|
|
|
|
CPUData.push(cpuUse);
|
|
|
|
MemoryData.push(parseInt(proc.data.memory.total / (1024 * 1024)));
|
|
|
|
|
|
|
|
TimeLabels.push($.format.date(new Date(), 'HH:mm:ss'));
|
|
|
|
|
|
|
|
CPUChart.update();
|
|
|
|
MemoryChart.update();
|
|
|
|
});
|
|
|
|
|
|
|
|
var ctc = $('#chart_cpu');
|
|
|
|
var TimeLabels = [];
|
|
|
|
var CPUData = [];
|
|
|
|
var CPUChart = new Chart(ctc, {
|
|
|
|
type: 'line',
|
|
|
|
data: {
|
|
|
|
labels: TimeLabels,
|
|
|
|
datasets: [
|
|
|
|
{
|
|
|
|
label: "Percent Use",
|
|
|
|
fill: false,
|
|
|
|
lineTension: 0.03,
|
|
|
|
backgroundColor: "#3c8dbc",
|
|
|
|
borderColor: "#3c8dbc",
|
|
|
|
borderCapStyle: 'butt',
|
|
|
|
borderDash: [],
|
|
|
|
borderDashOffset: 0.0,
|
|
|
|
borderJoinStyle: 'miter',
|
|
|
|
pointBorderColor: "#3c8dbc",
|
|
|
|
pointBackgroundColor: "#fff",
|
|
|
|
pointBorderWidth: 1,
|
|
|
|
pointHoverRadius: 5,
|
|
|
|
pointHoverBackgroundColor: "#3c8dbc",
|
|
|
|
pointHoverBorderColor: "rgba(220,220,220,1)",
|
|
|
|
pointHoverBorderWidth: 2,
|
|
|
|
pointRadius: 1,
|
|
|
|
pointHitRadius: 10,
|
|
|
|
data: CPUData,
|
|
|
|
spanGaps: false,
|
|
|
|
}
|
|
|
|
]
|
2017-04-14 05:21:38 +00:00
|
|
|
},
|
2017-04-15 22:23:29 +00:00
|
|
|
options: {
|
|
|
|
title: {
|
|
|
|
display: true,
|
|
|
|
text: 'CPU Usage (as Percent Total)'
|
|
|
|
},
|
|
|
|
legend: {
|
|
|
|
display: false,
|
|
|
|
},
|
|
|
|
animation: {
|
|
|
|
duration: 1,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var ctm = $('#chart_memory');
|
|
|
|
MemoryData = [];
|
|
|
|
MemoryChart = new Chart(ctm, {
|
|
|
|
type: 'line',
|
|
|
|
data: {
|
|
|
|
labels: TimeLabels,
|
|
|
|
datasets: [
|
|
|
|
{
|
|
|
|
label: "Memory Use",
|
|
|
|
fill: false,
|
|
|
|
lineTension: 0.03,
|
|
|
|
backgroundColor: "#3c8dbc",
|
|
|
|
borderColor: "#3c8dbc",
|
|
|
|
borderCapStyle: 'butt',
|
|
|
|
borderDash: [],
|
|
|
|
borderDashOffset: 0.0,
|
|
|
|
borderJoinStyle: 'miter',
|
|
|
|
pointBorderColor: "#3c8dbc",
|
|
|
|
pointBackgroundColor: "#fff",
|
|
|
|
pointBorderWidth: 1,
|
|
|
|
pointHoverRadius: 5,
|
|
|
|
pointHoverBackgroundColor: "#3c8dbc",
|
|
|
|
pointHoverBorderColor: "rgba(220,220,220,1)",
|
|
|
|
pointHoverBorderWidth: 2,
|
|
|
|
pointRadius: 1,
|
|
|
|
pointHitRadius: 10,
|
|
|
|
data: MemoryData,
|
|
|
|
spanGaps: false,
|
|
|
|
}
|
|
|
|
]
|
2017-04-14 05:21:38 +00:00
|
|
|
},
|
2017-04-15 22:23:29 +00:00
|
|
|
options: {
|
|
|
|
title: {
|
|
|
|
display: true,
|
|
|
|
text: 'Memory Usage (in Megabytes)'
|
|
|
|
},
|
|
|
|
legend: {
|
|
|
|
display: false,
|
|
|
|
},
|
|
|
|
animation: {
|
|
|
|
duration: 1,
|
|
|
|
}
|
2017-04-14 05:21:38 +00:00
|
|
|
}
|
2017-04-15 22:23:29 +00:00
|
|
|
});
|
|
|
|
})();
|
2017-01-15 23:52:22 +00:00
|
|
|
});
|