Skip to content

Commit 5455446

Browse files
committed
Add more front-end controllers, language file cleanup
1 parent 4532811 commit 5455446

File tree

59 files changed

+1100
-336
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1100
-336
lines changed

app/Contracts/Repository/Daemon/FileRepositoryInterface.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ interface FileRepositoryInterface extends BaseRepositoryInterface
3131
*
3232
* @param string $path
3333
* @return object
34+
*
35+
* @throws \GuzzleHttp\Exception\RequestException
3436
*/
3537
public function getFileStat($path);
3638

@@ -39,6 +41,8 @@ public function getFileStat($path);
3941
*
4042
* @param string $path
4143
* @return object
44+
*
45+
* @throws \GuzzleHttp\Exception\RequestException
4246
*/
4347
public function getContent($path);
4448

@@ -48,6 +52,8 @@ public function getContent($path);
4852
* @param string $path
4953
* @param string $content
5054
* @return \Psr\Http\Message\ResponseInterface
55+
*
56+
* @throws \GuzzleHttp\Exception\RequestException
5157
*/
5258
public function putContent($path, $content);
5359

@@ -56,6 +62,8 @@ public function putContent($path, $content);
5662
*
5763
* @param string $path
5864
* @return array
65+
*
66+
* @throws \GuzzleHttp\Exception\RequestException
5967
*/
6068
public function getDirectory($path);
6169
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/*
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
namespace Pterodactyl\Exceptions\Http\Server;
26+
27+
use Pterodactyl\Exceptions\DisplayException;
28+
29+
class FileSizeTooLargeException extends DisplayException
30+
{
31+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/*
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
namespace Pterodactyl\Exceptions\Http\Server;
26+
27+
use Pterodactyl\Exceptions\DisplayException;
28+
29+
class FileTypeNotEditableException extends DisplayException
30+
{
31+
}

app/Http/Controllers/Server/AjaxController.php

Lines changed: 0 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
use Pterodactyl\Repositories;
3131
use Pterodactyl\Exceptions\DisplayException;
3232
use Pterodactyl\Http\Controllers\Controller;
33-
use Pterodactyl\Exceptions\DisplayValidationException;
3433

3534
class AjaxController extends Controller
3635
{
@@ -49,134 +48,6 @@ class AjaxController extends Controller
4948
*/
5049
protected $directory;
5150

52-
/**
53-
* Returns a listing of files in a given directory for a server.
54-
*
55-
* @param \Illuminate\Http\Request $request
56-
* @param string $uuid
57-
* @return \Illuminate\View\View|\Illuminate\Http\Response
58-
*/
59-
public function postDirectoryList(Request $request, $uuid)
60-
{
61-
$server = Models\Server::byUuid($uuid);
62-
$this->authorize('list-files', $server);
63-
64-
$this->directory = '/' . trim(urldecode($request->input('directory', '/')), '/');
65-
$prevDir = [
66-
'header' => ($this->directory !== '/') ? $this->directory : '',
67-
];
68-
if ($this->directory !== '/') {
69-
$prevDir['first'] = true;
70-
}
71-
72-
// Determine if we should show back links in the file browser.
73-
// This code is strange, and could probably be rewritten much better.
74-
$goBack = explode('/', trim($this->directory, '/'));
75-
if (! empty(array_filter($goBack)) && count($goBack) >= 2) {
76-
$prevDir['show'] = true;
77-
array_pop($goBack);
78-
$prevDir['link'] = '/' . implode('/', $goBack);
79-
$prevDir['link_show'] = implode('/', $goBack) . '/';
80-
}
81-
82-
$controller = new Repositories\old_Daemon\FileRepository($uuid);
83-
84-
try {
85-
$directoryContents = $controller->returnDirectoryListing($this->directory);
86-
} catch (DisplayException $ex) {
87-
return response($ex->getMessage(), 500);
88-
} catch (\Exception $ex) {
89-
Log::error($ex);
90-
91-
return response('An error occured while attempting to load the requested directory, please try again.', 500);
92-
}
93-
94-
return view('server.files.list', [
95-
'server' => $server,
96-
'files' => $directoryContents->files,
97-
'folders' => $directoryContents->folders,
98-
'editableMime' => Repositories\HelperRepository::editableFiles(),
99-
'directory' => $prevDir,
100-
]);
101-
}
102-
103-
/**
104-
* Handles a POST request to save a file.
105-
*
106-
* @param \Illuminate\Http\Request $request
107-
* @param string $uuid
108-
* @return \Illuminate\Http\Response
109-
*/
110-
public function postSaveFile(Request $request, $uuid)
111-
{
112-
$server = Models\Server::byUuid($uuid);
113-
$this->authorize('save-files', $server);
114-
115-
$controller = new Repositories\old_Daemon\FileRepository($uuid);
116-
117-
try {
118-
$controller->saveFileContents($request->input('file'), $request->input('contents'));
119-
120-
return response(null, 204);
121-
} catch (DisplayException $ex) {
122-
return response($ex->getMessage(), 500);
123-
} catch (\Exception $ex) {
124-
Log::error($ex);
125-
126-
return response('An error occured while attempting to save this file, please try again.', 500);
127-
}
128-
}
129-
130-
/**
131-
* Sets the primary allocation for a server.
132-
*
133-
* @param \Illuminate\Http\Request $request
134-
* @param string $uuid
135-
* @return \Illuminate\Http\JsonResponse
136-
* @deprecated
137-
*/
138-
public function postSetPrimary(Request $request, $uuid)
139-
{
140-
$server = Models\Server::byUuid($uuid)->load('allocations');
141-
$this->authorize('set-connection', $server);
142-
143-
if ((int) $request->input('allocation') === $server->allocation_id) {
144-
return response()->json([
145-
'error' => 'You are already using this as your default connection.',
146-
], 409);
147-
}
148-
149-
try {
150-
$allocation = $server->allocations->where('id', $request->input('allocation'))->where('server_id', $server->id)->first();
151-
if (! $allocation) {
152-
return response()->json([
153-
'error' => 'No allocation matching your request was found in the system.',
154-
], 422);
155-
}
156-
157-
$repo = new Repositories\ServerRepository;
158-
$repo->changeBuild($server->id, [
159-
'default' => $allocation->ip . ':' . $allocation->port,
160-
]);
161-
162-
return response('The default connection for this server has been updated. Please be aware that you will need to restart your server for this change to go into effect.');
163-
} catch (DisplayValidationException $ex) {
164-
return response()->json([
165-
'error' => json_decode($ex->getMessage(), true),
166-
], 422);
167-
} catch (DisplayException $ex) {
168-
return response()->json([
169-
'error' => $ex->getMessage(),
170-
], 503);
171-
} catch (\Exception $ex) {
172-
Log::error($ex);
173-
174-
return response()->json([
175-
'error' => 'An unhandled exception occured while attemping to modify the default connection for this server.',
176-
], 503);
177-
}
178-
}
179-
18051
/**
18152
* Resets a database password for a server.
18253
*

app/Http/Controllers/Server/ConsoleController.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626

2727
use Illuminate\Contracts\Session\Session;
2828
use Pterodactyl\Http\Controllers\Controller;
29-
use Pterodactyl\Traits\Controllers\ServerToJavascript;
29+
use Pterodactyl\Traits\Controllers\JavascriptInjection;
3030
use Illuminate\Contracts\Config\Repository as ConfigRepository;
3131

3232
class ConsoleController extends Controller
3333
{
34-
use ServerToJavascript;
34+
use JavascriptInjection;
3535

3636
/**
3737
* @var \Illuminate\Contracts\Config\Repository
@@ -77,7 +77,7 @@ public function index()
7777
],
7878
]);
7979

80-
return view('server.index', ['server' => $server, 'node' => $server->node]);
80+
return view('server.index');
8181
}
8282

8383
/**
@@ -87,13 +87,11 @@ public function index()
8787
*/
8888
public function console()
8989
{
90-
$server = $this->session->get('server_data.model');
91-
9290
$this->injectJavascript(['config' => [
9391
'console_count' => $this->config->get('pterodactyl.console.count'),
9492
'console_freq' => $this->config->get('pterodactyl.console.frequency'),
9593
]]);
9694

97-
return view('server.console', ['server' => $server, 'node' => $server->node]);
95+
return view('server.console');
9896
}
9997
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
/*
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
namespace Pterodactyl\Http\Controllers\Server\Files;
26+
27+
use Illuminate\Cache\Repository;
28+
use Illuminate\Contracts\Session\Session;
29+
use Pterodactyl\Http\Controllers\Controller;
30+
31+
class DownloadController extends Controller
32+
{
33+
/**
34+
* @var \Illuminate\Cache\Repository
35+
*/
36+
protected $cache;
37+
38+
/**
39+
* @var \Illuminate\Contracts\Session\Session
40+
*/
41+
protected $session;
42+
43+
/**
44+
* DownloadController constructor.
45+
*
46+
* @param \Illuminate\Cache\Repository $cache
47+
* @param \Illuminate\Contracts\Session\Session $session
48+
*/
49+
public function __construct(Repository $cache, Session $session)
50+
{
51+
$this->cache = $cache;
52+
$this->session = $session;
53+
}
54+
55+
/**
56+
* Setup a unique download link for a user to download a file from.
57+
*
58+
* @param string $uuid
59+
* @param string $file
60+
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
61+
*
62+
* @throws \Illuminate\Auth\Access\AuthorizationException
63+
*/
64+
public function index($uuid, $file)
65+
{
66+
$server = $this->session->get('server_data.model');
67+
$this->authorize('download-files', $server);
68+
69+
$token = str_random(40);
70+
$this->cache->tags(['Server:Downloads'])->put($token, ['server' => $server->uuid, 'path' => $file], 5);
71+
72+
return redirect(sprintf(
73+
'%s://%s:%s/server/file/download/%s', $server->node->scheme, $server->node->fqdn, $server->node->daemonListen, $token
74+
));
75+
}
76+
}

0 commit comments

Comments
 (0)