diff --git a/CHANGELOG.md b/CHANGELOG.md index 0df00aa5..4ab451c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,14 @@ This project follows [Semantic Versioning](http://semver.org) guidelines. ## v0.5.0-pre.2 (Bodacious Boreopterus) +### Added +* Return node configuration from remote API by using `/api/nodes/{id}/config` endpoint. Only accepts SSL connections. + +### Changed +* Creating a user, server, or node now returns `HTTP/1.1 200` and a JSON element with the user/server/node's ID. + +## v0.5.0-pre.2 (Bodacious Boreopterus) + ### Added * Added support for file copying through the file manager. [#127](https://github.com/Pterodactyl/Panel/issues/127) * Creating new files and folders directly from the right-click dropdown menu in the file manager. diff --git a/app/Http/Controllers/API/NodeController.php b/app/Http/Controllers/API/NodeController.php index c3be918b..a0da14af 100755 --- a/app/Http/Controllers/API/NodeController.php +++ b/app/Http/Controllers/API/NodeController.php @@ -85,7 +85,7 @@ class NodeController extends BaseController * 'daemonSFTP' => 2022, * 'daemonListen' => 8080 * }, headers={"Authorization": "Bearer "}), - * @Response(201), + * @Response(200), * @Response(422, body={ * "message": "A validation error occured.", * "errors": {}, @@ -102,9 +102,7 @@ class NodeController extends BaseController try { $node = new NodeRepository; $new = $node->create($request->all()); - return $this->response->created(route('api.nodes.view', [ - 'id' => $new - ])); + return [ 'id' => $new ]; } catch (DisplayValidationException $ex) { throw new ResourceException('A validation error occured.', json_decode($ex->getMessage(), true)); } catch (DisplayException $ex) { @@ -129,23 +127,23 @@ class NodeController extends BaseController */ public function view(Request $request, $id, $fields = null) { - $query = Models\Node::where('id', $id); + $node = Models\Node::where('id', $id); if (!is_null($request->input('fields'))) { foreach(explode(',', $request->input('fields')) as $field) { if (!empty($field)) { - $query->addSelect($field); + $node->addSelect($field); } } } try { - if (!$query->first()) { + if (!$node->first()) { throw new NotFoundHttpException('No node by that ID was found.'); } return [ - 'node' => $query->first(), + 'node' => $node->first(), 'allocations' => [ 'assigned' => Models\Allocation::where('node', $id)->whereNotNull('assigned_to')->get(), 'unassigned' => Models\Allocation::where('node', $id)->whereNull('assigned_to')->get() @@ -158,6 +156,59 @@ class NodeController extends BaseController } } + public function config(Request $request, $id) + { + if (!$request->secure()) { + throw new BadRequestHttpException('This API route can only be accessed using a secure connection.'); + } + + $node = Models\Node::where('id', $id)->first(); + if (!$node) { + throw new NotFoundHttpException('No node by that ID was found.'); + } + + return [ + 'web' => [ + 'listen' => $node->daemonListen, + 'ssl' => [ + 'enabled' => ($node->scheme === 'https'), + 'certificate' => '/etc/certs/' . $node->fqdn . '/fullchain.pem', + 'key' => '/etc/certs/' . $node->fqdn . '/privkey.pem' + ] + ], + 'docker' => [ + 'socket' => '/var/run/docker.sock', + 'autoupdate_images' => true + ], + 'sftp' => [ + 'path' => $node->daemonBase, + 'port' => (int) $node->daemonSFTP, + 'container' => '0x0000' + ], + 'logger' => [ + 'path' => 'logs/', + 'src' => false, + 'level' => 'info', + 'period' => '1d', + 'count' => 3 + ], + 'remote' => [ + 'download' => route('remote.download'), + 'installed' => route('remote.install') + ], + 'uploads' => [ + 'maximumSize' => 100000000 + ], + 'keys' => [ + $node->daemonSecret + ], + 'query' => [ + 'kill_on_fail' => true, + 'fail_limit' => 3 + ] + ]; + } + /** * List all Node Allocations * diff --git a/app/Http/Controllers/API/ServerController.php b/app/Http/Controllers/API/ServerController.php index 91550f27..2b9f0986 100755 --- a/app/Http/Controllers/API/ServerController.php +++ b/app/Http/Controllers/API/ServerController.php @@ -77,9 +77,7 @@ class ServerController extends BaseController try { $server = new ServerRepository; $new = $server->create($request->all()); - return $this->response->created(route('api.servers.view', [ - 'id' => $new - ])); + return [ 'id' => $new ]; } catch (DisplayValidationException $ex) { throw new ResourceException('A validation error occured.', json_decode($ex->getMessage(), true)); } catch (DisplayException $ex) { diff --git a/app/Http/Controllers/API/UserController.php b/app/Http/Controllers/API/UserController.php index abc8b7f7..564f6921 100755 --- a/app/Http/Controllers/API/UserController.php +++ b/app/Http/Controllers/API/UserController.php @@ -129,9 +129,7 @@ class UserController extends BaseController try { $user = new UserRepository; $create = $user->create($request->input('email'), $request->input('password'), $request->input('admin'), $request->input('custom_id')); - return $this->response->created(route('api.users.view', [ - 'id' => $create - ])); + return [ 'id' => $create ]; } catch (DisplayValidationException $ex) { throw new ResourceException('A validation error occured.', json_decode($ex->getMessage(), true)); } catch (DisplayException $ex) { diff --git a/app/Http/Routes/APIRoutes.php b/app/Http/Routes/APIRoutes.php index f50a8e07..15fcab78 100755 --- a/app/Http/Routes/APIRoutes.php +++ b/app/Http/Routes/APIRoutes.php @@ -128,6 +128,11 @@ class APIRoutes 'uses' => 'Pterodactyl\Http\Controllers\API\NodeController@view' ]); + $api->get('nodes/{id}/config', [ + 'as' => 'api.nodes.view', + 'uses' => 'Pterodactyl\Http\Controllers\API\NodeController@config' + ]); + $api->delete('nodes/{id}', [ 'as' => 'api.nodes.delete', 'uses' => 'Pterodactyl\Http\Controllers\API\NodeController@delete'