diff --git a/app/Models/Node.php b/app/Models/Node.php
index 242493152..8297cc103 100644
--- a/app/Models/Node.php
+++ b/app/Models/Node.php
@@ -69,7 +69,7 @@ class Node extends Model
// @TODO: Better solution to disabling verification. Security risk.
self::$guzzle[$node] = new Client([
- 'base_uri' => sprintf('https://%s:%s/', $nodeData->fqdn, $nodeData->daemonListen),
+ 'base_uri' => sprintf('http%s://%s:%s/', ($nodeData->https === true) ? 's' : '', $nodeData->fqdn, $nodeData->daemonListen),
'timeout' => 10.0,
'connect_timeout' => 5.0,
'verify' => false,
diff --git a/database/migrations/2015_12_31_210400_add_https_toggle.php b/database/migrations/2015_12_31_210400_add_https_toggle.php
new file mode 100644
index 000000000..7a39e5ce7
--- /dev/null
+++ b/database/migrations/2015_12_31_210400_add_https_toggle.php
@@ -0,0 +1,31 @@
+boolean('https')->after('fqdn')->default(false);
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::table('nodes', function (Blueprint $table) {
+ $table->dropColumn('https');
+ });
+ }
+}
diff --git a/resources/views/layouts/master.blade.php b/resources/views/layouts/master.blade.php
index bc1f7f247..3ebfcafa4 100644
--- a/resources/views/layouts/master.blade.php
+++ b/resources/views/layouts/master.blade.php
@@ -40,7 +40,7 @@
$(window).load(function () {
// Main Socket Object
- socket = io('https://{{ $node->fqdn }}:{{ $node->daemonListen }}/server/{{ $server->uuid }}', {
+ socket = io('http{{ ($node->https === true) ? 's' : '' }}://{{ $node->fqdn }}:{{ $node->daemonListen }}/ws/{{ $server->uuid }}', {
'query': 'token={{ $server->daemonSecret }}'
});
@@ -67,9 +67,12 @@
}
});
+ socket.on('error', function (err) {
+ alert('There was an error while attemping to connect to the websocket: ' + err + '\n\nPlease try loading this page again.');
+ });
+
// Socket Sends Server Status on Connect
socket.on('initial_status', function (data) {
-
var color = '#E33200';
var selector = 'fa-times-circle';
@@ -79,12 +82,10 @@
}
$('#applyUpdate').removeClass('fa-circle-o-notch fa-spinner fa-spin fa-check-circle fa-times-circle').addClass(selector).css({ color: color });
-
});
// Socket Recieves New Status from Scales
socket.on('status', function(data) {
-
if(data.status !== 'crashed') {
var newStatus, selector = 'fa-times-circle';
@@ -100,10 +101,10 @@
selector = "fa-check-circle";
break;
case 2:
- newStatus = 'STOPPING';
+ newStatus = 'STARTING';
break;
case 3:
- newStatus = 'STARTING';
+ newStatus = 'STOPPING';
break;
}
diff --git a/resources/views/server/index.blade.php b/resources/views/server/index.blade.php
index 553d9fcde..499a8a878 100644
--- a/resources/views/server/index.blade.php
+++ b/resources/views/server/index.blade.php
@@ -102,10 +102,10 @@
-
-
-
-
+
+
+
+
@@ -164,6 +164,7 @@ $(window).load(function () {
// New Console Data Recieved
socket.on('console', function (data) {
+ console.log(JSON.stringify(data));
$('#live_console').val($('#live_console').val() + data.line);
$('#live_console').scrollTop($('#live_console')[0].scrollHeight);
});
@@ -177,16 +178,16 @@ $(window).load(function () {
'X-Access-Token': '{{ $server->daemonSecret }}',
'X-Access-Server': '{{ $server->uuid }}'
},
- url: 'https://{{ $node->fqdn }}:{{ $node->daemonListen }}/server/log/750',
+ url: 'http{{ $node->https ? 's' : '' }}://{{ $node->fqdn }}:{{ $node->daemonListen }}/server/log',
timeout: 10000
}).done(function(data) {
$('#live_console').val(data);
$('#live_console').scrollTop($('#live_console')[0].scrollHeight);
}).fail(function(jqXHR, textStatus, errorThrown) {
- $('#pw_resp').attr('class', 'alert alert-danger').html('Unable to load initial server log.').fadeIn().delay(5000).fadeOut();
+ alert('Unable to load initial server log, try reloading the page.');
});
} else {
- $('#live_console').val('');
+ $('#live_console').val('Server is currently off.');
}
updateServerPowerControls(data.status);
updatePlayerListVisibility(data.status);
@@ -225,7 +226,7 @@ $(window).load(function () {
var cpuChart = new Chart(cty).Bar(cpuChartData,{animation:!1,showScale:!0,barShowStroke:!1,scaleOverride:!1,tooltipTemplate:"<%= value %> %",barValueSpacing:1,barStrokeWidth:1,scaleShowGridLines:!1});
function updatePlayerListVisibility(data) {
// Server is On or Starting
- if(data == 1 || data == 3) {
+ if(data !== 0) {
$('#stats_players').show();
} else {
$('#stats_players').hide();
@@ -248,9 +249,10 @@ $(window).load(function () {
'X-Access-Token': '{{ $server->daemonSecret }}',
'X-Access-Server': '{{ $server->uuid }}'
},
- url: 'https://{{ $node->fqdn }}:{{ $node->daemonListen }}/server/console',
+ contentType: 'application/json; charset=utf-8',
+ url: 'http{{ $node->https ? 's' : '' }}://{{ $node->fqdn }}:{{ $node->daemonListen }}/server/command',
timeout: 10000,
- data: { command: ccmd }
+ data: JSON.stringify({ command: ccmd })
}).fail(function (jqXHR) {
$('#sc_resp').html('Unable to process your request. Please try again.').fadeIn().delay(5000).fadeOut();
}).always(function () {
@@ -265,126 +267,57 @@ $(window).load(function () {
// Server is On or Starting
if(data == 1 || data == 3) {
- $('#server_start').addClass('disabled');
- $('#server_stop, #server_restart').removeClass('disabled');
+ $('[data-attr="power"][data-action="start"]').addClass('disabled');
+ $('[data-attr="power"][data-action="stop"], [data-attr="power"][data-action="restart"]').removeClass('disabled');
} else {
- $('#server_start').removeClass('disabled');
- $('#server_stop, #server_restart').addClass('disabled');
+ $('[data-attr="power"][data-action="start"]').removeClass('disabled');
+ $('[data-attr="power"][data-action="stop"], [data-attr="power"][data-action="restart"]').addClass('disabled');
}
if(data !== 0) {
- $('#kill_proc').removeClass('disabled');
+ $('[data-attr="power"][data-action="kill"]').removeClass('disabled');
} else {
- $('#kill_proc').addClass('disabled');
+ $('[data-attr="power"][data-action="kill"]').addClass('disabled');
}
}
- // Kill Server Process Button
- $('#kill_proc').click(function (e){
-
- e.preventDefault();
- var killConfirm = confirm('WARNING: This operation will not save your server data gracefully. You should only use this if your server is failing to respond to stops.');
+ $('[data-attr="power"]').click(function (event) {
+ event.preventDefault();
+ var action = $(this).data('action');
+ if (action === 'kill') {
+ var killConfirm = confirm('WARNING: This operation will not save your server data gracefully. You should only use this if your server is failing to respond to normal stop commands.');
+ } else { var killConfirm = true; }
if(killConfirm) {
+ if (action === 'start') {
+ $("#live_console").val('');
+ }
$.ajax({
- type: 'GET',
+ type: 'PUT',
headers: {
'X-Access-Token': '{{ $server->daemonSecret }}',
'X-Access-Server': '{{ $server->uuid }}'
},
- url: 'https://{{ $node->fqdn }}:{{ $node->daemonListen }}/server/power/kill',
+ contentType: 'application/json; charset=utf-8',
+ data: JSON.stringify({
+ action: action
+ }),
+ url: 'http{{ $node->https ? 's' : '' }}://{{ $node->fqdn }}:{{ $node->daemonListen }}/server/power',
timeout: 10000
}).done(function(data) {
- $('#pw_resp').attr('class', 'alert alert-success').html('Server has been killed successfully.').fadeIn().delay(5000).fadeOut();
- }).fail(function(jqXHR, textStatus, errorThrown) {
- $('#pw_resp').attr('class', 'alert alert-danger').html('Unable to process your request. Please try again. ('+ errorThrown +')').fadeIn().delay(5000).fadeOut();
+ $('#pw_resp').attr('class', 'alert alert-success').html('Server has been ' + action + 'ed successfully.').fadeIn().delay(5000).fadeOut();
+ }).fail(function(jqXHR) {
+ var error = 'An unknown error occured processing this request.';
+ if (typeof jqXHR.responseJSON.error !== 'undefined') {
+ error = jqXHR.responseJSON.error;
+ }
+ $('#pw_resp').attr('class', 'alert alert-danger').html('Unable to process your request. Please try again. (' + error + ')').fadeIn().delay(5000).fadeOut();
});
}
});
- $('#server_stop').click(function (e){
- e.preventDefault();
- if(can_run) {
- can_run = false;
- $(this).append(' ').toggleClass('disabled');
- $.ajax({
- type: 'GET',
- headers: {
- 'X-Access-Token': '{{ $server->daemonSecret }}',
- 'X-Access-Server': '{{ $server->uuid }}'
- },
- url: 'https://{{ $node->fqdn }}:{{ $node->daemonListen }}/server/power/off',
- timeout: 10000
- }).done(function(data) {
- $('#pw_resp').attr('class', 'alert alert-success').html('Server is now stopping...').fadeIn().delay(5000).fadeOut();
- $('#server_stop').removeClass('disabled').html('Stop');
- can_run = true;
- return false;
- }).fail(function(jqXHR, textStatus, errorThrown) {
- $('#pw_resp').attr('class', 'alert alert-danger').html('Unable to process your request. Please try again. ('+ errorThrown +')').fadeIn().delay(5000).fadeOut();
- $('#server_stop').removeClass('disabled').html('Stop');
- can_run = true;
- });
- }
- });
-
- $('#server_restart').click(function(e){
- e.preventDefault();
- if(can_run) {
- can_run = false;
- $(this).append(' ').toggleClass('disabled');
- $.ajax({
- type: 'GET',
- headers: {
- 'X-Access-Token': '{{ $server->daemonSecret }}',
- 'X-Access-Server': '{{ $server->uuid }}'
- },
- url: 'https://{{ $node->fqdn }}:{{ $node->daemonListen }}/server/power/restart',
- timeout: 10000
- }).done(function(data) {
- $('#pw_resp').attr('class', 'alert alert-success').html('Server is now restarting...').fadeIn().delay(5000).fadeOut();
- $('#server_restart').removeClass('disabled').html('Restart');
- can_run = true;
- return false;
- }).fail(function(jqXHR, textStatus, errorThrown) {
- $('#pw_resp').attr('class', 'alert alert-danger').html('Unable to process your request. Please try again. ('+ errorThrown +')').fadeIn().delay(5000).fadeOut();
- $('#server_restart').removeClass('disabled').html('Restart');
- can_run = true;
- });
- }
- });
- $('#server_start').click(function(e){
- e.preventDefault();
- start_server();
- });
- function start_server() {
- if(can_run === true){
- can_run = false;
- $('#server_start').append(' ').toggleClass('disabled');
- $.ajax({
- type: 'GET',
- headers: {
- 'X-Access-Token': '{{ $server->daemonSecret }}',
- 'X-Access-Server': '{{ $server->uuid }}'
- },
- url: 'https://{{ $node->fqdn }}:{{ $node->daemonListen }}/server/power/on',
- timeout: 10000
- }).done(function(data) {
- $('#live_console').val('Server is starting...\n');
- $('#pw_resp').attr('class', 'alert alert-success').html('Server is now starting...').fadeIn().delay(5000).fadeOut();
- $('#server_start').toggleClass('disabled');
- $('#server_start').html('Start');
- can_run = true;
- }).fail(function(jqXHR, textStatus, errorThrown) {
- $('#pw_resp').attr('class', 'alert alert-danger').html('Unable to process your request. Please try again. ('+ errorThrown +')').fadeIn().delay(5000).fadeOut();
- $('#server_start').removeClass('disabled');
- $('#server_start').html('Start');
- can_run = true;
- });
- }
- }
@endcan
});