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-10-19 03:32:19 +00:00
|
|
|
use Illuminate\Http\Request;
|
2017-09-03 02:35:33 +00:00
|
|
|
|
2017-09-03 21:32:52 +00:00
|
|
|
trait JavascriptInjection
|
2017-09-03 02:35:33 +00:00
|
|
|
{
|
2017-10-21 02:32:57 +00:00
|
|
|
/**
|
|
|
|
* @var \Illuminate\Http\Request
|
|
|
|
*/
|
|
|
|
private $request;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the request object to use when injecting JS.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
public function setRequest(Request $request)
|
|
|
|
{
|
|
|
|
$this->request = $request;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2017-09-03 02:35:33 +00:00
|
|
|
/**
|
|
|
|
* Injects server javascript into the page to be used by other services.
|
|
|
|
*
|
2017-10-21 02:32:57 +00:00
|
|
|
* @param array $args
|
|
|
|
* @param bool $overwrite
|
2017-10-19 03:32:19 +00:00
|
|
|
* @return array
|
2017-09-03 02:35:33 +00:00
|
|
|
*/
|
2017-10-21 02:32:57 +00:00
|
|
|
public function injectJavascript($args = [], $overwrite = false)
|
2017-09-03 02:35:33 +00:00
|
|
|
{
|
2017-10-21 02:32:57 +00:00
|
|
|
$request = $this->request ?? app()->make(Request::class);
|
2017-10-19 03:32:19 +00:00
|
|
|
$server = $request->attributes->get('server');
|
|
|
|
$token = $request->attributes->get('server_token');
|
2017-09-03 02:35:33 +00:00
|
|
|
|
2017-11-26 19:17:40 +00:00
|
|
|
$response = array_merge_recursive([
|
2017-09-03 02:35:33 +00:00
|
|
|
'server' => [
|
|
|
|
'uuid' => $server->uuid,
|
|
|
|
'uuidShort' => $server->uuidShort,
|
|
|
|
'daemonSecret' => $token,
|
|
|
|
],
|
2017-11-18 22:50:08 +00:00
|
|
|
'server_token' => $token,
|
2017-09-03 02:35:33 +00:00
|
|
|
'node' => [
|
|
|
|
'fqdn' => $server->node->fqdn,
|
|
|
|
'scheme' => $server->node->scheme,
|
|
|
|
'daemonListen' => $server->node->daemonListen,
|
|
|
|
],
|
|
|
|
], $args);
|
|
|
|
|
|
|
|
return Javascript::put($overwrite ? $args : $response);
|
|
|
|
}
|
|
|
|
}
|