Skip to content

Commit c7f3bb5

Browse files
committed
New theme assigned to server console page.
1 parent 4cc9f74 commit c7f3bb5

File tree

8 files changed

+390
-6
lines changed

8 files changed

+390
-6
lines changed

app/Http/Controllers/Server/ServerController.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,19 @@ public function __construct()
5858
public function getIndex(Request $request)
5959
{
6060
$server = Models\Server::getByUUID($request->route()->server);
61+
$node = Models\Node::find($server->node);
6162

6263
Javascript::put([
64+
'server' => [
65+
'uuid' => $server->uuid,
66+
'daemonSecret' => $server->daemonSecret,
67+
'username' => $server->username,
68+
],
69+
'node' => [
70+
'scheme' => $node->scheme,
71+
'fqdn' => $node->fqdn,
72+
'daemonListen' => $node->daemonListen,
73+
],
6374
'meta' => [
6475
'saveFile' => route('server.files.save', $server->uuidShort),
6576
'csrfToken' => csrf_token(),
@@ -69,7 +80,7 @@ public function getIndex(Request $request)
6980
return view('server.index', [
7081
'server' => $server,
7182
'allocations' => Models\Allocation::where('assigned_to', $server->id)->orderBy('ip', 'asc')->orderBy('port', 'asc')->get(),
72-
'node' => Models\Node::find($server->node),
83+
'node' => $node,
7384
]);
7485
}
7586

public/js/plugins/minecraft/eula.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
// SOFTWARE.
2020
$(window).load(function () {
21-
socket.on('console', function (data) {
21+
Socket.on('console', function (data) {
2222
if (data.line.indexOf('You need to agree to the EULA in order to run the server') > -1) {
2323
swal({
2424
title: 'EULA Acceptance',
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
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+
});
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
(function initSocket() {
21+
if (typeof io !== 'function') {
22+
console.error('Socket.io is reqired to use this panel.');
23+
return;
24+
}
25+
26+
window.Socket = io(Pterodactyl.node.scheme + '://' + Pterodactyl.node.fqdn + ':' + Pterodactyl.node.daemonListen + '/ws/' + Pterodactyl.server.uuid, {
27+
'query': 'token=' + Pterodactyl.server.daemonSecret,
28+
});
29+
30+
Socket.io.on('connect_error', function (err) {
31+
console.error('Could not connect to socket.io.', err);
32+
});
33+
34+
// Connected to Socket Successfully
35+
Socket.on('connect', function () {
36+
console.log('connected to socket');
37+
});
38+
39+
Socket.on('initial status', function (data) {
40+
setStatusIcon(data.status);
41+
});
42+
43+
Socket.on('status', function (data) {
44+
setStatusIcon(data.status);
45+
});
46+
47+
Socket.on('console', function (data) {
48+
TerminalQueue.push(data.line);
49+
});
50+
})();
51+
52+
function setStatusIcon(status) {
53+
switch (status) {
54+
case 0:
55+
$('#server_status_icon').html('<i class="fa fa-circle text-danger"></i> Offline');
56+
break;
57+
case 1:
58+
$('#server_status_icon').html('<i class="fa fa-circle text-success"></i> Online');
59+
break;
60+
case 2:
61+
$('#server_status_icon').html('<i class="fa fa-circle text-warning"></i> Starting');
62+
break;
63+
case 3:
64+
$('#server_status_icon').html('<i class="fa fa-circle text-warning"></i> Stopping');
65+
break;
66+
default:
67+
break;
68+
}
69+
}

resources/lang/en/server.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
return [
4+
'index' => [
5+
'title' => 'Viewing Server :name',
6+
'header' => 'Server Console',
7+
'header_sub' => 'Control your server in real time.',
8+
]
9+
];

resources/themes/pterodactyl/base/index.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
@foreach($servers as $server)
6262
<tr class="dynamic-update" data-server="{{ $server->uuidShort }}">
6363
<td><code>{{ $server->uuidShort }}</code></td>
64-
<td><a href="/server/{{ $server->uuidShort }}">{{ $server->name }}</a></td>
64+
<td><a href="{{ route('server.index', $server->uuidShort) }}">{{ $server->name }}</a></td>
6565
<td>{{ $server->nodeName }}</td>
6666
<td><code>@if(!is_null($server->ip_alias)){{ $server->ip_alias }}@else{{ $server->ip }}@endif:{{ $server->port }}</code></td>
6767
<td class="text-center hidden-sm hidden-xs"><span data-action="memory">--</span> / {{ $server->memory === 0 ? '&infin;' : $server->memory }} MB</td>

resources/themes/pterodactyl/layouts/master.blade.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
<div class="user-panel">
102102
<div class="info">
103103
<p>{{ $server->name }}</p>
104-
<a href="#"><i class="fa fa-circle text-success"></i> Online</a>
104+
<a href="#" id="server_status_icon"><i class="fa fa-circle text-default"></i> Checking...</a>
105105
</div>
106106
</div>
107107
@endif
@@ -129,12 +129,12 @@
129129
</li>
130130
@if (isset($server->name) && isset($node->name))
131131
<li class="header">SERVER MANAGEMENT</li>
132-
<li>
132+
<li class="{{ Route::currentRouteName() !== 'server.index' ?: 'active' }}">
133133
<a href="{{ route('server.index', $server->uuidShort) }}">
134134
<i class="fa fa-terminal"></i> <span>Console</span>
135135
</a>
136136
</li>
137-
<li class="treeview">
137+
<li class="treeview {{ Route::currentRouteName() !== 'server.files.index' ?: 'active' }}">
138138
<a href="#">
139139
<i class="fa fa-files-o"></i>
140140
<span>File Management</span>
@@ -248,6 +248,7 @@
248248
{!! Theme::js('vendor/bootstrap/bootstrap.min.js') !!}
249249
{!! Theme::js('vendor/slimscroll/jquery.slimscroll.min.js') !!}
250250
{!! Theme::js('vendor/adminlte/app.min.js') !!}
251+
{!! Theme::js('js/vendor/socketio/socket.io.min.js') !!}
251252
@show
252253
</body>
253254
</html>

0 commit comments

Comments
 (0)