diff --git a/app/Http/Controllers/Remote/RemoteController.php b/app/Http/Controllers/Daemon/ActionController.php similarity index 67% rename from app/Http/Controllers/Remote/RemoteController.php rename to app/Http/Controllers/Daemon/ActionController.php index 892a82842..79c04839d 100644 --- a/app/Http/Controllers/Remote/RemoteController.php +++ b/app/Http/Controllers/Daemon/ActionController.php @@ -22,14 +22,15 @@ * SOFTWARE. */ -namespace Pterodactyl\Http\Controllers\Remote; +namespace Pterodactyl\Http\Controllers\Daemon; -use Carbon\Carbon; -use Pterodactyl\Models; use Illuminate\Http\Request; +use Pterodactyl\Models\Server; +use Pterodactyl\Models\Download; use Pterodactyl\Http\Controllers\Controller; +use Pterodactyl\Models\NodeConfigurationToken; -class RemoteController extends Controller +class ActionController extends Controller { /** * Handles download request from daemon. @@ -37,9 +38,9 @@ class RemoteController extends Controller * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\JsonResponse */ - public function postDownload(Request $request) + public function authenticateDownload(Request $request) { - $download = Models\Download::where('token', $request->input('token'))->first(); + $download = Download::where('token', $request->input('token'))->first(); if (! $download) { return response()->json([ 'error' => 'An invalid request token was recieved with this request.', @@ -60,9 +61,9 @@ class RemoteController extends Controller * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\JsonResponse */ - public function postInstall(Request $request) + public function markInstall(Request $request) { - $server = Models\Server::where('uuid', $request->input('server'))->with('node')->first(); + $server = Server::where('uuid', $request->input('server'))->with('node')->first(); if (! $server) { return response()->json([ 'error' => 'No server by that ID was found on the system.', @@ -72,7 +73,7 @@ class RemoteController extends Controller $hmac = $request->input('signed'); $status = $request->input('installed'); - if (base64_decode($hmac) !== hash_hmac('sha256', $server->uuid, $server->node->daemonSecret, true)) { + if (! hash_equals(base64_decode($hmac), hash_hmac('sha256', $server->uuid, $server->node->daemonSecret, true))) { return response()->json([ 'error' => 'Signed HMAC was invalid.', ], 403); @@ -81,35 +82,7 @@ class RemoteController extends Controller $server->installed = ($status === 'installed') ? 1 : 2; $server->save(); - return response()->json([ - 'message' => 'Recieved!', - ], 200); - } - - /** - * Handles event from daemon. - * - * @param \Illuminate\Http\Request $request - * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Response - * @deprecated - */ - public function event(Request $request) - { - $server = Models\Server::where('uuid', $request->input('server'))->with('node')->first(); - if (! $server) { - return response()->json([ - 'error' => 'No server by that ID was found on the system.', - ], 422); - } - - $hmac = $request->input('signed'); - if (base64_decode($hmac) !== hash_hmac('sha256', $server->uuid, $server->node->daemonSecret, true)) { - return response()->json([ - 'error' => 'Signed HMAC was invalid.', - ], 403); - } - - return response('', 201); + return response('', 204); } /** @@ -119,11 +92,11 @@ class RemoteController extends Controller * @param string $token * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Response */ - public function getConfiguration(Request $request, $token) + public function configuration(Request $request, $token) { // Try to query the token and the node from the database try { - $model = Models\NodeConfigurationToken::with('node')->where('token', $token)->firstOrFail(); + $model = NodeConfigurationToken::with('node')->where('token', $token)->firstOrFail(); } catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) { return response()->json(['error' => 'token_invalid'], 403); } diff --git a/app/Models/Node.php b/app/Models/Node.php index 62b4c891a..9c454cfcb 100644 --- a/app/Models/Node.php +++ b/app/Models/Node.php @@ -145,8 +145,6 @@ class Node extends Model ], 'remote' => [ 'base' => route('index'), - 'download' => route('remote.download'), - 'installed' => route('remote.install'), ], 'uploads' => [ 'size_limit' => $this->upload_size, diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index d129489af..00d40bdbd 100644 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -57,10 +57,6 @@ class RouteServiceProvider extends ServiceProvider ->namespace($this->namespace . '\Server') ->group(base_path('routes/server.php')); - Route::middleware(['web'])->prefix('/remote') - ->namespace($this->namespace . '\Remote') - ->group(base_path('routes/remote.php')); - Route::middleware(['web', 'daemon'])->prefix('/daemon') ->namespace($this->namespace . '\Daemon') ->group(base_path('routes/daemon.php')); diff --git a/app/Repositories/NodeRepository.php b/app/Repositories/NodeRepository.php index 6cb61daa1..80dc0d902 100644 --- a/app/Repositories/NodeRepository.php +++ b/app/Repositories/NodeRepository.php @@ -177,8 +177,6 @@ class NodeRepository ], 'remote' => [ 'base' => config('app.url'), - 'download' => route('remote.download'), - 'installed' => route('remote.install'), ], 'uploads' => [ 'size_limit' => $node->upload_size, diff --git a/routes/daemon.php b/routes/daemon.php index 82619ad00..44d4e5a8c 100644 --- a/routes/daemon.php +++ b/routes/daemon.php @@ -26,3 +26,7 @@ Route::get('/services/pull/{service}/{file}', 'ServiceController@pull')->name('d Route::get('/packs/pull/{uuid}', 'PackController@pull')->name('daemon.pack.pull'); Route::get('/packs/pull/{uuid}/hash', 'PackController@hash')->name('daemon.pack.hash'); Route::get('/details/option/{server}', 'OptionController@details')->name('daemon.option.details'); +Route::get('/configure/{token}', 'ActionController@configuration')->name('daemon.configuration'); + +Route::post('/download', 'ActionController@authentiateDownload')->name('daemon.download'); +Route::post('/install', 'ActionController@markInstall')->name('daemon.install'); diff --git a/routes/remote.php b/routes/remote.php deleted file mode 100644 index d7fe471c5..000000000 --- a/routes/remote.php +++ /dev/null @@ -1,27 +0,0 @@ -. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -Route::get('/configuration/{token}', 'RemoteController@getConfiguration')->name('remote.configuration'); - -Route::post('/download', 'RemoteController@postDownload')->name('remote.download'); -Route::post('/install', 'RemoteController@postInstall')->name('remote.install');