2017-09-03 02:35:33 +00:00
|
|
|
<?php
|
2017-09-26 02:43:01 +00:00
|
|
|
/**
|
2017-09-03 02:35:33 +00:00
|
|
|
* Pterodactyl - Panel
|
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
|
|
|
*
|
2017-09-26 02:43:01 +00:00
|
|
|
* This software is licensed under the terms of the MIT license.
|
|
|
|
* https://opensource.org/licenses/MIT
|
2017-09-03 02:35:33 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Pterodactyl\Traits\Controllers;
|
|
|
|
|
|
|
|
use Javascript;
|
|
|
|
|
2017-09-03 21:32:52 +00:00
|
|
|
trait JavascriptInjection
|
2017-09-03 02:35:33 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var \Illuminate\Contracts\Session\Session
|
|
|
|
*/
|
|
|
|
protected $session;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Injects server javascript into the page to be used by other services.
|
|
|
|
*
|
|
|
|
* @param array $args
|
|
|
|
* @param bool $overwrite
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function injectJavascript($args = [], $overwrite = false)
|
|
|
|
{
|
|
|
|
$server = $this->session->get('server_data.model');
|
|
|
|
$token = $this->session->get('server_data.token');
|
|
|
|
|
|
|
|
$response = array_merge([
|
|
|
|
'server' => [
|
|
|
|
'uuid' => $server->uuid,
|
|
|
|
'uuidShort' => $server->uuidShort,
|
|
|
|
'daemonSecret' => $token,
|
|
|
|
'username' => $server->username,
|
|
|
|
],
|
|
|
|
'node' => [
|
|
|
|
'fqdn' => $server->node->fqdn,
|
|
|
|
'scheme' => $server->node->scheme,
|
|
|
|
'daemonListen' => $server->node->daemonListen,
|
|
|
|
],
|
|
|
|
], $args);
|
|
|
|
|
|
|
|
return Javascript::put($overwrite ? $args : $response);
|
|
|
|
}
|
|
|
|
}
|