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
|
|
|
*/
|
|
|
|
|
2017-09-03 21:32:52 +00:00
|
|
|
namespace Pterodactyl\Http\Controllers\Server\Files;
|
2017-09-03 02:35:33 +00:00
|
|
|
|
2018-03-02 01:19:19 +00:00
|
|
|
use Ramsey\Uuid\Uuid;
|
2017-10-28 02:42:53 +00:00
|
|
|
use Illuminate\Http\Request;
|
2017-09-03 21:32:52 +00:00
|
|
|
use Illuminate\Cache\Repository;
|
2017-10-28 02:42:53 +00:00
|
|
|
use Illuminate\Http\RedirectResponse;
|
2017-09-03 21:32:52 +00:00
|
|
|
use Pterodactyl\Http\Controllers\Controller;
|
2017-09-03 02:35:33 +00:00
|
|
|
|
2017-09-03 21:32:52 +00:00
|
|
|
class DownloadController extends Controller
|
2017-09-03 02:35:33 +00:00
|
|
|
{
|
2017-09-03 21:32:52 +00:00
|
|
|
/**
|
|
|
|
* @var \Illuminate\Cache\Repository
|
|
|
|
*/
|
|
|
|
protected $cache;
|
|
|
|
|
2017-09-03 02:35:33 +00:00
|
|
|
/**
|
2017-09-03 21:32:52 +00:00
|
|
|
* DownloadController constructor.
|
|
|
|
*
|
2017-10-28 02:42:53 +00:00
|
|
|
* @param \Illuminate\Cache\Repository $cache
|
2017-09-03 21:32:52 +00:00
|
|
|
*/
|
2017-10-28 02:42:53 +00:00
|
|
|
public function __construct(Repository $cache)
|
2017-09-03 21:32:52 +00:00
|
|
|
{
|
|
|
|
$this->cache = $cache;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup a unique download link for a user to download a file from.
|
|
|
|
*
|
2017-10-28 02:42:53 +00:00
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param string $uuid
|
|
|
|
* @param string $file
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
2017-09-03 02:35:33 +00:00
|
|
|
*
|
2017-09-03 21:32:52 +00:00
|
|
|
* @throws \Illuminate\Auth\Access\AuthorizationException
|
2017-09-03 02:35:33 +00:00
|
|
|
*/
|
2017-10-28 02:42:53 +00:00
|
|
|
public function index(Request $request, string $uuid, string $file): RedirectResponse
|
2017-09-03 02:35:33 +00:00
|
|
|
{
|
2017-10-28 02:42:53 +00:00
|
|
|
$server = $request->attributes->get('server');
|
2017-09-03 21:32:52 +00:00
|
|
|
$this->authorize('download-files', $server);
|
2017-09-03 02:35:33 +00:00
|
|
|
|
2018-03-02 01:19:19 +00:00
|
|
|
$token = Uuid::uuid4()->toString();
|
2017-10-28 02:42:53 +00:00
|
|
|
$node = $server->getRelation('node');
|
2018-03-02 01:19:19 +00:00
|
|
|
|
2018-03-02 00:46:59 +00:00
|
|
|
$this->cache->put('Server:Downloads:' . $token, ['server' => $server->uuid, 'path' => $file], 5);
|
2017-09-03 02:35:33 +00:00
|
|
|
|
2017-10-28 02:42:53 +00:00
|
|
|
return redirect(sprintf('%s://%s:%s/v1/server/file/download/%s', $node->scheme, $node->fqdn, $node->daemonListen, $token));
|
2017-09-03 02:35:33 +00:00
|
|
|
}
|
|
|
|
}
|