Add EULA acceptance popup when starting server
This commit is contained in:
parent
4b40fa65d4
commit
2160613163
7 changed files with 80 additions and 10 deletions
|
@ -29,6 +29,15 @@ class ServerController extends Controller
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getJavascript(Request $request, $uuid, $file)
|
||||||
|
{
|
||||||
|
$server = Server::getByUUID($uuid);
|
||||||
|
return response()->view('server.js.' . $server->a_serviceFile . '.' . basename($file, '.js'), [
|
||||||
|
'server' => $server,
|
||||||
|
'node' => Node::find($server->node)
|
||||||
|
])->header('Content-Type', 'application/javascript');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renders server index page for specified server.
|
* Renders server index page for specified server.
|
||||||
*
|
*
|
||||||
|
|
|
@ -41,6 +41,16 @@ class ServerRoutes {
|
||||||
'uses' => 'Server\ServerController@getAddFile'
|
'uses' => 'Server\ServerController@getAddFile'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$router->post('files/directory-list', [
|
||||||
|
'as' => 'server.files.directory-list',
|
||||||
|
'uses' => 'Server\AjaxController@postDirectoryList'
|
||||||
|
]);
|
||||||
|
|
||||||
|
$router->post('files/save', [
|
||||||
|
'as' => 'server.files.save',
|
||||||
|
'uses' => 'Server\AjaxController@postSaveFile'
|
||||||
|
]);
|
||||||
|
|
||||||
// Assorted AJAX Routes
|
// Assorted AJAX Routes
|
||||||
$router->group(['prefix' => 'ajax'], function ($server) use ($router) {
|
$router->group(['prefix' => 'ajax'], function ($server) use ($router) {
|
||||||
// Returns Server Status
|
// Returns Server Status
|
||||||
|
@ -52,15 +62,16 @@ class ServerRoutes {
|
||||||
$router->post('set-connection', [
|
$router->post('set-connection', [
|
||||||
'uses' => 'Server\AjaxController@postSetConnection'
|
'uses' => 'Server\AjaxController@postSetConnection'
|
||||||
]);
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
// Assorted File Manager URLs
|
// Assorted AJAX Routes
|
||||||
$router->post('files/directory-list', [
|
$router->group(['prefix' => 'js'], function ($server) use ($router) {
|
||||||
'uses' => 'Server\AjaxController@postDirectoryList'
|
// Returns Server Status
|
||||||
]);
|
$router->get('{file}', [
|
||||||
|
'as' => 'server.js',
|
||||||
|
'uses' => 'Server\ServerController@getJavascript'
|
||||||
|
])->where('file', '.*');
|
||||||
|
|
||||||
$router->post('files/save', [
|
|
||||||
'uses' => 'Server\AjaxController@postSaveFile'
|
|
||||||
]);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,7 +112,9 @@ class Server extends Model
|
||||||
return self::$serverUUIDInstance[$uuid];
|
return self::$serverUUIDInstance[$uuid];
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = self::where('uuidShort', $uuid)->where('active', 1);
|
$query = self::select('servers.*', 'services.file as a_serviceFile')
|
||||||
|
->join('services', 'services.id', '=', 'servers.id')
|
||||||
|
->where('uuidShort', $uuid)->where('active', 1);
|
||||||
|
|
||||||
if (self::$user->root_admin !== 1) {
|
if (self::$user->root_admin !== 1) {
|
||||||
$query->whereIn('servers.id', Subuser::accessServers());
|
$query->whereIn('servers.id', Subuser::accessServers());
|
||||||
|
@ -120,6 +122,9 @@ class Server extends Model
|
||||||
|
|
||||||
$result = $query->first();
|
$result = $query->first();
|
||||||
|
|
||||||
|
// @TODO: saving after calling this could end up resetting the daemon secret.
|
||||||
|
// We probably need to just allow access to self::getUserDaemonSecret() to
|
||||||
|
// get this result.
|
||||||
if(!is_null($result)) {
|
if(!is_null($result)) {
|
||||||
$result->daemonSecret = self::getUserDaemonSecret($result);
|
$result->daemonSecret = self::getUserDaemonSecret($result);
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ $(document).ready(function () {
|
||||||
$('#save_file').append(' <i class="fa fa-spinner fa fa-spin"></i>').addClass('disabled');
|
$('#save_file').append(' <i class="fa fa-spinner fa fa-spin"></i>').addClass('disabled');
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
url: '/server/{{ $server->uuidShort }}/ajax/files/save',
|
url: '{{ route('server.files.save', $server->uuidShort) }}',
|
||||||
headers: { 'X-CSRF-Token': '{{ csrf_token() }}' },
|
headers: { 'X-CSRF-Token': '{{ csrf_token() }}' },
|
||||||
data: {
|
data: {
|
||||||
file: fileName,
|
file: fileName,
|
||||||
|
|
|
@ -114,7 +114,7 @@
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
url: '/server/{{ $server->uuidShort }}/ajax/files/directory-list',
|
url: '{{ route('server.files.directory-list', $server->uuidShort) }}',
|
||||||
headers: { 'X-CSRF-Token': '{{ csrf_token() }}' },
|
headers: { 'X-CSRF-Token': '{{ csrf_token() }}' },
|
||||||
data: { directory: urlDirectory }
|
data: { directory: urlDirectory }
|
||||||
}).done(function (data) {
|
}).done(function (data) {
|
||||||
|
|
|
@ -112,6 +112,9 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@if($server->a_serviceFile === 'minecraft')
|
||||||
|
<script src="{{ route('server.js', [$server->uuidShort, 'minecraft/eula.js']) }}"></script>
|
||||||
|
@endif
|
||||||
<script>
|
<script>
|
||||||
$(window).load(function () {
|
$(window).load(function () {
|
||||||
$('[data-toggle="tooltip"]').tooltip();
|
$('[data-toggle="tooltip"]').tooltip();
|
||||||
|
|
42
resources/views/server/js/minecraft/eula.blade.php
Normal file
42
resources/views/server/js/minecraft/eula.blade.php
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
$(window).load(function () {
|
||||||
|
socket.on('console', function (data) {
|
||||||
|
if (data.line.indexOf('You need to agree to the EULA in order to run the server') > -1) {
|
||||||
|
swal({
|
||||||
|
title: 'EULA Acceptance',
|
||||||
|
text: 'By pressing \'I Accept\' below you are indicating your agreement to the <a href="https://account.mojang.com/documents/minecraft_eula" target="_blank">Mojang EULA</a>.',
|
||||||
|
type: 'info',
|
||||||
|
html: true,
|
||||||
|
showCancelButton: true,
|
||||||
|
showConfirmButton: true,
|
||||||
|
cancelButtonText: 'I do not Accept',
|
||||||
|
confirmButtonText: 'I Accept',
|
||||||
|
closeOnConfirm: false,
|
||||||
|
showLoaderOnConfirm: true
|
||||||
|
}, function () {
|
||||||
|
$.ajax({
|
||||||
|
type: 'POST',
|
||||||
|
url: '{{ route('server.files.save', $server->uuidShort) }}',
|
||||||
|
headers: { 'X-CSRF-Token': '{{ csrf_token() }}' },
|
||||||
|
data: {
|
||||||
|
file: 'eula.txt',
|
||||||
|
contents: 'eula=true'
|
||||||
|
}
|
||||||
|
}).done(function (data) {
|
||||||
|
$('[data-attr="power"][data-action="start"]').trigger('click');
|
||||||
|
swal({
|
||||||
|
type: 'success',
|
||||||
|
title: '',
|
||||||
|
text: 'The EULA for this server has been accepted, restarting server now.',
|
||||||
|
});
|
||||||
|
}).fail(function (jqXHR) {
|
||||||
|
console.error(jqXHR);
|
||||||
|
swal({
|
||||||
|
title: 'Whoops!',
|
||||||
|
text: 'An error occured while attempting to set the EULA as accepted: ' . jqXHR.responseJSON.error,
|
||||||
|
type: 'error'
|
||||||
|
})
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in a new issue