Skip to content

Commit 634a62a

Browse files
authored
Merge pull request pterodactyl#117 from Pterodactyl/feature/filemanager
Feature/filemanager
2 parents 9f2d3bc + 8330e26 commit 634a62a

File tree

396 files changed

+1876
-656
lines changed

Some content is hidden

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

396 files changed

+1876
-656
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,18 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
88
### Added
99
* Support for creating server without having to assign a node and allocation manually. Simply select the checkbox or pass `auto_deploy=true` to the API to auto-select a node and allocation given a location.
1010
* Support for setting IP Aliases through the panel on the node overview page. Also cleaned up allocation removal.
11+
* Support for renaming files through the panel's file mananger.
1112

1213
### Changed
1314
* Prevent clicking server start button until server is completely off, not just stopping.
1415
* Upon successful creation of a node it will redirect to the allocation tab and display a clearer message to add allocations.
1516
* Trying to add a new node if no location exists redirects user to location management page and alerts them to add a location first.
1617
* `Server\AjaxController@postSetConnection` is now `Server\AjaxController@postSetPrimary` and accepts one post parameter of `allocation` rather than a combined `ip:port` value.
1718
* Port allocations on server view are now cleaner and should make more sense.
19+
* Improved File Manager
20+
* Rewritten Javascript to load, rename, and handle other file actions.
21+
* Uses Ace Editor for editing files rather than a non-formatted textarea
22+
* File actions that were previously icons to the right are now contained in a menu that appears when right-clicking a file or folder.
1823

1924
### Fixed
2025
* Team Fortress named 'Insurgency' in panel in database seeder. ([#96](https://github.com/Pterodactyl/Panel/issues/96), PR by [@MeltedLux](https://github.com/MeltedLux))

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
## Pterodactyl Panel
2-
Pterodactyl is the free game server management panel designed by users, for users. Featuring support for Vanilla Minecraft, Spigot, Source Dedicated Servers, BungeeCord, and many more. Pterodactyl is built on the `Laravel PHP Framework (v5.2)`.
2+
Pterodactyl is the free game server management panel designed by users, for users. Featuring support for Vanilla Minecraft, Spigot, Source Dedicated Servers, BungeeCord, and many more. Pterodactyl is built on the `Laravel PHP Framework (v5.3)`.
33

44
## Support & Documentation
55
Support for using Pterodactyl can be found on our [wiki](https://github.com/Pterodactyl/Panel/wiki) or on our [Discord chat](https://discord.gg/0gYt8oU8QOkDhKLS).
@@ -28,6 +28,8 @@ SOFTWARE.
2828
```
2929

3030
### Credits
31+
Ace Editor - [license](https://github.com/ajaxorg/ace/blob/master/LICENSE) - [homepage](https://ace.c9.io)
32+
3133
Animate.css - [license](https://github.com/daneden/animate.css/blob/master/LICENSE) - [homepage](http://daneden.github.io/animate.css/)
3234

3335
Async.js - [license](https://github.com/caolan/async/blob/master/LICENSE) - [homepage](https://github.com/caolan/async/)
@@ -48,6 +50,8 @@ jQuery - [license](https://github.com/jquery/jquery/blob/master/LICENSE.txt) - [
4850

4951
jQuery Terminal - [license](https://github.com/jcubic/jquery.terminal/blob/master/LICENSE) - [homepage](http://terminal.jcubic.pl)
5052

53+
Lodash - [license](https://github.com/lodash/lodash/blob/master/LICENSE) - [homepage](https://lodash.com/)
54+
5155
MetricsGraphics.js - [license](https://github.com/mozilla/metrics-graphics/blob/master/LICENSE) - [homepage](http://metricsgraphicsjs.org/)
5256

5357
Socket.io - [license](https://github.com/socketio/socket.io/blob/master/LICENSE) - [homepage](http://socket.io)

app/Http/Controllers/Server/AjaxController.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,12 @@ public function postDirectoryList(Request $request, $uuid)
115115

116116
// Determine if we should show back links in the file browser.
117117
// This code is strange, and could probably be rewritten much better.
118-
$goBack = explode('/', rtrim($this->directory, '/'));
119-
if (isset($goBack[2]) && !empty($goBack[2])) {
118+
$goBack = explode('/', trim($this->directory, '/'));
119+
if (!empty(array_filter($goBack)) && count($goBack) >= 2) {
120120
$prevDir['show'] = true;
121-
$prevDir['link'] = '/' . trim(str_replace(end($goBack), '', $this->directory), '/');
122-
$prevDir['link_show'] = trim($prevDir['link'], '/');
121+
array_pop($goBack);
122+
$prevDir['link'] = '/' . implode('/', $goBack);
123+
$prevDir['link_show'] = implode('/', $goBack) . '/';
123124
}
124125

125126
$controller = new Repositories\Daemon\FileRepository($uuid);
@@ -137,7 +138,7 @@ public function postDirectoryList(Request $request, $uuid)
137138
'server' => $server,
138139
'files' => $directoryContents->files,
139140
'folders' => $directoryContents->folders,
140-
'extensions' => Repositories\HelperRepository::editableFiles(),
141+
'editableMime' => Repositories\HelperRepository::editableFiles(),
141142
'directory' => $prevDir
142143
]);
143144

app/Http/Controllers/Server/ServerController.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ public function __construct()
5151
//
5252
}
5353

54-
public function getJavascript(Request $request, $uuid, $file)
54+
public function getJavascript(Request $request, $uuid, $folder, $file)
5555
{
5656
$server = Models\Server::getByUUID($uuid);
57-
return response()->view('server.js.' . $server->a_serviceFile . '.' . basename($file, '.js'), [
57+
return response()->view('server.js.' . $folder . '.' . basename($file, '.js'), [
5858
'server' => $server,
5959
'node' => Models\Node::find($server->node)
6060
])->header('Content-Type', 'application/javascript');
@@ -145,9 +145,9 @@ public function getEditFile(Request $request, $uuid, $file)
145145
'server' => $server,
146146
'node' => Models\Node::find($server->node),
147147
'file' => $file,
148-
'contents' => $fileContent->content,
149-
'directory' => (in_array($fileInfo->dirname, ['.', './', '/'])) ? '/' : trim($fileInfo->dirname, '/') . '/',
150-
'extension' => $fileInfo->extension
148+
'stat' => $fileContent['stat'],
149+
'contents' => $fileContent['file']->content,
150+
'directory' => (in_array($fileInfo->dirname, ['.', './', '/'])) ? '/' : trim($fileInfo->dirname, '/') . '/'
151151
]);
152152

153153
}
@@ -172,11 +172,11 @@ public function getDownloadFile(Request $request, $uuid, $file)
172172

173173
$download->token = (string) Uuid::generate(4);
174174
$download->server = $server->uuid;
175-
$download->path = str_replace('../', '', $file);
175+
$download->path = $file;
176176

177177
$download->save();
178178

179-
return redirect( $node->scheme . '://' . $node->fqdn . ':' . $node->daemonListen . '/server/download/' . $download->token);
179+
return redirect( $node->scheme . '://' . $node->fqdn . ':' . $node->daemonListen . '/server/file/download/' . $download->token);
180180

181181
}
182182

app/Http/Routes/ServerRoutes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public function map(Router $router) {
167167
// Assorted AJAX Routes
168168
$router->group(['prefix' => 'js'], function ($server) use ($router) {
169169
// Returns Server Status
170-
$router->get('{file}', [
170+
$router->get('{folder}/{file}', [
171171
'as' => 'server.js',
172172
'uses' => 'Server\ServerController@getJavascript'
173173
])->where('file', '.*');

app/Repositories/Daemon/FileRepository.php

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function __construct($uuid)
8585
* Get the contents of a requested file for the server.
8686
*
8787
* @param string $file
88-
* @return string
88+
* @return array
8989
*/
9090
public function returnFileContents($file)
9191
{
@@ -95,22 +95,39 @@ public function returnFileContents($file)
9595
}
9696

9797
$file = (object) pathinfo($file);
98-
if (!in_array($file->extension, HelperRepository::editableFiles())) {
99-
throw new DisplayException('You do not have permission to edit this type of file.');
100-
}
10198

10299
$file->dirname = (in_array($file->dirname, ['.', './', '/'])) ? null : trim($file->dirname, '/') . '/';
103100

104-
$res = $this->client->request('GET', '/server/file/' . rawurlencode($file->dirname.$file->basename), [
101+
$res = $this->client->request('GET', '/server/file/stat/' . rawurlencode($file->dirname.$file->basename) , [
102+
'headers' => $this->headers
103+
]);
104+
105+
$stat = json_decode($res->getBody());
106+
if($res->getStatusCode() !== 200 || !isset($stat->size)) {
107+
throw new DisplayException('The daemon provided a non-200 error code on stat lookup: HTTP\\' . $res->getStatusCode());
108+
}
109+
110+
if (!in_array($stat->mime, HelperRepository::editableFiles())) {
111+
throw new DisplayException('You cannot edit that type of file (' . $stat->mime . ') through the panel.');
112+
}
113+
114+
if ($stat->size > 5000000) {
115+
throw new DisplayException('That file is too large to open in the browser, consider using a SFTP client.');
116+
}
117+
118+
$res = $this->client->request('GET', '/server/file/f/' . rawurlencode($file->dirname.$file->basename) , [
105119
'headers' => $this->headers
106120
]);
107121

108122
$json = json_decode($res->getBody());
109123
if($res->getStatusCode() !== 200 || !isset($json->content)) {
110-
throw new DisplayException('Scales provided a non-200 error code: HTTP\\' . $res->getStatusCode());
124+
throw new DisplayException('The daemon provided a non-200 error code: HTTP\\' . $res->getStatusCode());
111125
}
112126

113-
return $json;
127+
return [
128+
'file' => $json,
129+
'stat' => $stat
130+
];
114131

115132
}
116133

@@ -119,7 +136,7 @@ public function returnFileContents($file)
119136
*
120137
* @param string $file
121138
* @param string $content
122-
* @return boolean
139+
* @return bool
123140
*/
124141
public function saveFileContents($file, $content)
125142
{
@@ -130,15 +147,12 @@ public function saveFileContents($file, $content)
130147

131148
$file = (object) pathinfo($file);
132149

133-
if(!in_array($file->extension, HelperRepository::editableFiles())) {
134-
throw new DisplayException('You do not have permission to edit this type of file.');
135-
}
136-
137150
$file->dirname = (in_array($file->dirname, ['.', './', '/'])) ? null : trim($file->dirname, '/') . '/';
138151

139-
$res = $this->client->request('POST', '/server/file/' . rawurlencode($file->dirname.$file->basename), [
152+
$res = $this->client->request('POST', '/server/file/save', [
140153
'headers' => $this->headers,
141154
'json' => [
155+
'path' => rawurlencode($file->dirname.$file->basename),
142156
'content' => $content
143157
]
144158
]);
@@ -185,7 +199,8 @@ public function returnDirectoryListing($directory)
185199
'entry' => $value->name,
186200
'directory' => trim($directory, '/'),
187201
'size' => null,
188-
'date' => strtotime($value->modified)
202+
'date' => strtotime($value->modified),
203+
'mime' => $value->mime
189204
]]);
190205

191206
} else if ($value->file === true) {
@@ -195,7 +210,8 @@ public function returnDirectoryListing($directory)
195210
'directory' => trim($directory, '/'),
196211
'extension' => pathinfo($value->name, PATHINFO_EXTENSION),
197212
'size' => HelperRepository::bytesToHuman($value->size),
198-
'date' => strtotime($value->modified)
213+
'date' => strtotime($value->modified),
214+
'mime' => $value->mime
199215
]]);
200216

201217
}

app/Repositories/HelperRepository.php

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,20 @@ class HelperRepository {
3030
* @var array
3131
*/
3232
protected static $editable = [
33-
'txt',
34-
'yml',
35-
'yaml',
36-
'log',
37-
'conf',
38-
'config',
39-
'html',
40-
'json',
41-
'properties',
42-
'props',
43-
'cfg',
44-
'lang',
45-
'ini',
46-
'cmd',
47-
'sh',
48-
'lua',
49-
'0' // Supports BungeeCord Files
33+
'application/json',
34+
'application/javascript',
35+
'application/xml',
36+
'application/xhtml+xml',
37+
'text/xml',
38+
'text/css',
39+
'text/html',
40+
'text/plain',
41+
'text/x-perl',
42+
'text/x-shellscript',
43+
'inode/x-empty'
5044
];
5145

46+
5247
public function __construct()
5348
{
5449
//
File renamed without changes.
File renamed without changes.

public/css/fontawesome/fonts/fontawesome-webfont.eot renamed to public/css/vendor/fontawesome/fonts/fontawesome-webfont.eot

File renamed without changes.

0 commit comments

Comments
 (0)