|
| 1 | +// Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com> |
| 2 | +// |
| 3 | +// Permission is hereby granted, free of charge, to any person obtaining a copy |
| 4 | +// of this software and associated documentation files (the "Software"), to deal |
| 5 | +// in the Software without restriction, including without limitation the rights |
| 6 | +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 7 | +// copies of the Software, and to permit persons to whom the Software is |
| 8 | +// furnished to do so, subject to the following conditions: |
| 9 | +// |
| 10 | +// The above copyright notice and this permission notice shall be included in all |
| 11 | +// copies or substantial portions of the Software. |
| 12 | +// |
| 13 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 14 | +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 15 | +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 16 | +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 17 | +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 18 | +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 19 | +// SOFTWARE. |
| 20 | +var CONSOLE_PUSH_COUNT = 50; |
| 21 | +var CONSOLE_PUSH_FREQ = 200; |
| 22 | + |
| 23 | +(function initConsole() { |
| 24 | + window.TerminalQueue = []; |
| 25 | + window.Terminal = $('#terminal').terminal(function (command, term) { |
| 26 | + Socket.emit('send command', command); |
| 27 | + }, { |
| 28 | + greetings: '', |
| 29 | + name: Pterodactyl.server.uuid, |
| 30 | + height: 450, |
| 31 | + exit: false, |
| 32 | + prompt: Pterodactyl.server.username + ':~$ ', |
| 33 | + scrollOnEcho: false, |
| 34 | + scrollBottomOffset: 5, |
| 35 | + onBlur: function (terminal) { |
| 36 | + return false; |
| 37 | + } |
| 38 | + }); |
| 39 | + |
| 40 | + Socket.on('initial status', function (data) { |
| 41 | + Terminal.clear(); |
| 42 | + if (data.status === 1 || data.status === 2) { |
| 43 | + Socket.emit('send server log'); |
| 44 | + } |
| 45 | + }); |
| 46 | +})(); |
| 47 | + |
| 48 | +(function pushOutputQueue() { |
| 49 | + if (TerminalQueue.length > CONSOLE_PUSH_COUNT) { |
| 50 | + // console throttled warning show |
| 51 | + } |
| 52 | + |
| 53 | + if (TerminalQueue.length > 0) { |
| 54 | + for (var i = 0; i < CONSOLE_PUSH_COUNT && TerminalQueue.length > 0; i++) { |
| 55 | + Terminal.echo(TerminalQueue[0]); |
| 56 | + TerminalQueue.shift(); |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + window.setTimeout(pushOutputQueue, CONSOLE_PUSH_FREQ); |
| 61 | +})(); |
| 62 | + |
| 63 | +$(document).ready(function () { |
| 64 | + $('[data-attr="power"]').click(function (event) { |
| 65 | + Socket.emit('set status', $(this).data('action')); |
| 66 | + }); |
| 67 | + var ctc = $('#chart_cpu'); |
| 68 | + var timeLabels = []; |
| 69 | + var cpuData = []; |
| 70 | + var CPUChart = new Chart(ctc, { |
| 71 | + type: 'line', |
| 72 | + data: { |
| 73 | + labels: timeLabels, |
| 74 | + datasets: [ |
| 75 | + { |
| 76 | + label: "Percent Use", |
| 77 | + fill: false, |
| 78 | + lineTension: 0.03, |
| 79 | + backgroundColor: "#00A1CB", |
| 80 | + borderColor: "#00A1CB", |
| 81 | + borderCapStyle: 'butt', |
| 82 | + borderDash: [], |
| 83 | + borderDashOffset: 0.0, |
| 84 | + borderJoinStyle: 'miter', |
| 85 | + pointBorderColor: "rgba(75,192,192,1)", |
| 86 | + pointBackgroundColor: "#fff", |
| 87 | + pointBorderWidth: 1, |
| 88 | + pointHoverRadius: 5, |
| 89 | + pointHoverBackgroundColor: "rgba(75,192,192,1)", |
| 90 | + pointHoverBorderColor: "rgba(220,220,220,1)", |
| 91 | + pointHoverBorderWidth: 2, |
| 92 | + pointRadius: 1, |
| 93 | + pointHitRadius: 10, |
| 94 | + data: cpuData, |
| 95 | + spanGaps: false, |
| 96 | + } |
| 97 | + ] |
| 98 | + }, |
| 99 | + options: { |
| 100 | + title: { |
| 101 | + display: true, |
| 102 | + text: 'CPU Usage (as Percent Total)' |
| 103 | + }, |
| 104 | + legend: { |
| 105 | + display: false, |
| 106 | + }, |
| 107 | + animation: { |
| 108 | + duration: 1, |
| 109 | + } |
| 110 | + } |
| 111 | + }); |
| 112 | + |
| 113 | + var ctm = $('#chart_memory'); |
| 114 | + var memoryData = []; |
| 115 | + var MemoryChart = new Chart(ctm, { |
| 116 | + type: 'line', |
| 117 | + data: { |
| 118 | + labels: timeLabels, |
| 119 | + datasets: [ |
| 120 | + { |
| 121 | + label: "Memory Use", |
| 122 | + fill: false, |
| 123 | + lineTension: 0.03, |
| 124 | + backgroundColor: "#01A4A4", |
| 125 | + borderColor: "#01A4A4", |
| 126 | + borderCapStyle: 'butt', |
| 127 | + borderDash: [], |
| 128 | + borderDashOffset: 0.0, |
| 129 | + borderJoinStyle: 'miter', |
| 130 | + pointBorderColor: "rgba(75,192,192,1)", |
| 131 | + pointBackgroundColor: "#fff", |
| 132 | + pointBorderWidth: 1, |
| 133 | + pointHoverRadius: 5, |
| 134 | + pointHoverBackgroundColor: "rgba(75,192,192,1)", |
| 135 | + pointHoverBorderColor: "rgba(220,220,220,1)", |
| 136 | + pointHoverBorderWidth: 2, |
| 137 | + pointRadius: 1, |
| 138 | + pointHitRadius: 10, |
| 139 | + data: memoryData, |
| 140 | + spanGaps: false, |
| 141 | + } |
| 142 | + ] |
| 143 | + }, |
| 144 | + options: { |
| 145 | + title: { |
| 146 | + display: true, |
| 147 | + text: 'Memory Usage (in Megabytes)' |
| 148 | + }, |
| 149 | + legend: { |
| 150 | + display: false, |
| 151 | + }, |
| 152 | + animation: { |
| 153 | + duration: 1, |
| 154 | + } |
| 155 | + } |
| 156 | + }); |
| 157 | + Socket.on('proc', function (proc) { |
| 158 | + if (cpuData.length > 10) { |
| 159 | + cpuData.shift(); |
| 160 | + memoryData.shift(); |
| 161 | + timeLabels.shift(); |
| 162 | + } |
| 163 | + |
| 164 | + var cpuUse = (Pterodactyl.server.cpu > 0) ? parseFloat(((proc.data.cpu.total / Pterodactyl.server.cpu) * 100).toFixed(3).toString()) : proc.data.cpu.total; |
| 165 | + cpuData.push(cpuUse); |
| 166 | + memoryData.push(parseInt(proc.data.memory.total / (1024 * 1024))); |
| 167 | + |
| 168 | + var m = new Date(); |
| 169 | + timeLabels.push($.format.date(new Date(), 'HH:mm:ss')); |
| 170 | + |
| 171 | + CPUChart.update(); |
| 172 | + MemoryChart.update(); |
| 173 | + }); |
| 174 | + |
| 175 | + // Update Listings on Initial Status |
| 176 | + Socket.on('initial status', function (data) { |
| 177 | + updateServerPowerControls(data.status); |
| 178 | + }); |
| 179 | + |
| 180 | + // Update Listings on Status |
| 181 | + Socket.on('status', function (data) { |
| 182 | + updateServerPowerControls(data.status); |
| 183 | + }); |
| 184 | + |
| 185 | + function updateServerPowerControls (data) { |
| 186 | + // Server is On or Starting |
| 187 | + if(data == 1 || data == 2) { |
| 188 | + $('[data-attr="power"][data-action="start"]').addClass('disabled'); |
| 189 | + $('[data-attr="power"][data-action="stop"], [data-attr="power"][data-action="restart"]').removeClass('disabled'); |
| 190 | + } else { |
| 191 | + if (data == 0) { |
| 192 | + $('[data-attr="power"][data-action="start"]').removeClass('disabled'); |
| 193 | + } |
| 194 | + $('[data-attr="power"][data-action="stop"], [data-attr="power"][data-action="restart"]').addClass('disabled'); |
| 195 | + } |
| 196 | + |
| 197 | + if(data !== 0) { |
| 198 | + $('[data-attr="power"][data-action="kill"]').removeClass('disabled'); |
| 199 | + } else { |
| 200 | + $('[data-attr="power"][data-action="kill"]').addClass('disabled'); |
| 201 | + } |
| 202 | + } |
| 203 | +}); |
0 commit comments