From 93d79994f808e566359d06ab3f5ad9dd3e9f43e2 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sun, 9 Apr 2017 19:16:39 -0400 Subject: [PATCH] Apply fixes from StyleCI (#372) --- app/Exceptions/Handler.php | 1 - .../Controllers/API/Admin/NodeController.php | 4 +++- .../Controllers/API/Admin/ServerController.php | 17 ++++++++++++++++- .../Controllers/API/Admin/UserController.php | 5 ++++- .../Controllers/API/User/ServerController.php | 3 +-- app/Http/Middleware/CheckServer.php | 4 ++-- app/Http/Middleware/HMACAuthorization.php | 13 +++++++------ app/Models/APIPermission.php | 4 ++-- app/Models/Server.php | 3 ++- app/Providers/MacroServiceProvider.php | 4 ++-- app/Repositories/APIRepository.php | 2 +- app/Repositories/UserRepository.php | 2 +- .../Admin/ServiceVariableTransformer.php | 2 +- config/pterodactyl.php | 2 +- routes/admin.php | 1 - routes/api-admin.php | 2 -- routes/api.php | 1 - routes/auth.php | 1 - routes/base.php | 1 - routes/daemon.php | 1 - routes/remote.php | 1 - routes/server.php | 1 - 22 files changed, 43 insertions(+), 32 deletions(-) diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 22d79a952..71d66cdc6 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -4,7 +4,6 @@ namespace Pterodactyl\Exceptions; use Log; use Exception; -use DisplayException; use Illuminate\Auth\AuthenticationException; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; diff --git a/app/Http/Controllers/API/Admin/NodeController.php b/app/Http/Controllers/API/Admin/NodeController.php index 4992638b2..d70e89969 100644 --- a/app/Http/Controllers/API/Admin/NodeController.php +++ b/app/Http/Controllers/API/Admin/NodeController.php @@ -27,8 +27,8 @@ namespace Pterodactyl\Http\Controllers\API\Admin; use Fractal; use Illuminate\Http\Request; use Pterodactyl\Models\Node; -use Pterodactyl\Http\Controllers\Controller; use Pterodactyl\Exceptions\DisplayException; +use Pterodactyl\Http\Controllers\Controller; use Pterodactyl\Repositories\NodeRepository; use Pterodactyl\Transformers\Admin\NodeTransformer; use Pterodactyl\Exceptions\DisplayValidationException; @@ -135,6 +135,7 @@ class NodeController extends Controller ], 400); } catch (\Exception $ex) { Log::error($ex); + return response()->json([ 'error' => 'An unhandled exception occured while attemping to create this node. Please try again.', ], 500); @@ -163,6 +164,7 @@ class NodeController extends Controller ], 400); } catch (\Exception $ex) { Log::error($ex); + return response()->json([ 'error' => 'An unhandled exception occured while attemping to delete this node. Please try again.', ], 500); diff --git a/app/Http/Controllers/API/Admin/ServerController.php b/app/Http/Controllers/API/Admin/ServerController.php index 8d1962822..89dfd8cd0 100644 --- a/app/Http/Controllers/API/Admin/ServerController.php +++ b/app/Http/Controllers/API/Admin/ServerController.php @@ -113,11 +113,13 @@ class ServerController extends Controller ], 400); } catch (TransferException $ex) { Log::warning($ex); + return response()->json([ 'error' => 'A TransferException was encountered while trying to contact the daemon, please ensure it is online and accessible. This error has been logged.', ], 504); } catch (\Exception $ex) { Log::error($ex); + return response()->json([ 'error' => 'An unhandled exception occured while attemping to add this server. Please try again.', ], 500); @@ -146,18 +148,20 @@ class ServerController extends Controller ], 400); } catch (TransferException $ex) { Log::warning($ex); + return response()->json([ 'error' => 'A TransferException was encountered while trying to contact the daemon, please ensure it is online and accessible. This error has been logged.', ], 504); } catch (\Exception $ex) { Log::error($ex); + return response()->json([ 'error' => 'An unhandled exception occured while attemping to add this server. Please try again.', ], 500); } } - /** + /** * Update the details for a server. * * @param \Illuminate\Http\Request $request @@ -190,6 +194,7 @@ class ServerController extends Controller ], 400); } catch (\Exception $ex) { Log::error($ex); + return response()->json([ 'error' => 'An unhandled exception occured while attemping to modify this server. Please try again.', ], 500); @@ -223,11 +228,13 @@ class ServerController extends Controller ], 400); } catch (TransferException $ex) { Log::warning($ex); + return response()->json([ 'error' => 'A TransferException was encountered while trying to contact the daemon, please ensure it is online and accessible. This error has been logged.', ], 504); } catch (\Exception $ex) { Log::error($ex); + return response()->json([ 'error' => 'An unhandled exception occured while attemping to modify this server container. Please try again.', ], 500); @@ -256,6 +263,7 @@ class ServerController extends Controller ], 400); } catch (\Exception $ex) { Log::error($ex); + return response()->json([ 'error' => 'An unhandled exception occured while attemping to toggle the install status for this server. Please try again.', ], 500); @@ -283,6 +291,7 @@ class ServerController extends Controller return response('', 204); } catch (TransferException $ex) { Log::warning($ex); + return response()->json([ 'error' => 'A TransferException was encountered while trying to contact the daemon, please ensure it is online and accessible. This error has been logged.', ], 504); @@ -318,11 +327,13 @@ class ServerController extends Controller ], 400); } catch (TransferException $ex) { Log::warning($ex); + return response()->json([ 'error' => 'A TransferException was encountered while trying to contact the daemon, please ensure it is online and accessible. This error has been logged.', ], 504); } catch (\Exception $ex) { Log::error($ex); + return response()->json([ 'error' => 'An unhandled exception occured while attemping to ' . $action . ' this server. Please try again.', ], 500); @@ -363,11 +374,13 @@ class ServerController extends Controller ], 400); } catch (TransferException $ex) { Log::warning($ex); + return response()->json([ 'error' => 'A TransferException was encountered while trying to contact the daemon, please ensure it is online and accessible. This error has been logged.', ], 504); } catch (\Exception $ex) { Log::error($ex); + return response()->json([ 'error' => 'An unhandled exception occured while attemping to modify the build settings for this server. Please try again.', ], 500); @@ -400,11 +413,13 @@ class ServerController extends Controller ], 400); } catch (TransferException $ex) { Log::warning($ex); + return response()->json([ 'error' => 'A TransferException was encountered while trying to contact the daemon, please ensure it is online and accessible. This error has been logged.', ], 504); } catch (\Exception $ex) { Log::error($ex); + return response()->json([ 'error' => 'An unhandled exception occured while attemping to modify the startup settings for this server. Please try again.', ], 500); diff --git a/app/Http/Controllers/API/Admin/UserController.php b/app/Http/Controllers/API/Admin/UserController.php index 7268c263c..150ca4f87 100644 --- a/app/Http/Controllers/API/Admin/UserController.php +++ b/app/Http/Controllers/API/Admin/UserController.php @@ -27,8 +27,8 @@ namespace Pterodactyl\Http\Controllers\API\Admin; use Fractal; use Illuminate\Http\Request; use Pterodactyl\Models\User; -use Pterodactyl\Http\Controllers\Controller; use Pterodactyl\Exceptions\DisplayException; +use Pterodactyl\Http\Controllers\Controller; use Pterodactyl\Repositories\UserRepository; use Pterodactyl\Transformers\Admin\UserTransformer; use Pterodactyl\Exceptions\DisplayValidationException; @@ -109,6 +109,7 @@ class UserController extends Controller ], 400); } catch (\Exception $ex) { Log::error($ex); + return response()->json([ 'error' => 'An unhandled exception occured while attemping to create this user. Please try again.', ], 500); @@ -145,6 +146,7 @@ class UserController extends Controller ], 400); } catch (\Exception $ex) { Log::error($ex); + return response()->json([ 'error' => 'An unhandled exception occured while attemping to update this user. Please try again.', ], 500); @@ -173,6 +175,7 @@ class UserController extends Controller ], 400); } catch (\Exception $ex) { Log::error($ex); + return response()->json([ 'error' => 'An unhandled exception occured while attemping to delete this user. Please try again.', ], 500); diff --git a/app/Http/Controllers/API/User/ServerController.php b/app/Http/Controllers/API/User/ServerController.php index 4064ad8c1..1c5399cf9 100644 --- a/app/Http/Controllers/API/User/ServerController.php +++ b/app/Http/Controllers/API/User/ServerController.php @@ -27,10 +27,9 @@ namespace Pterodactyl\Http\Controllers\API\User; use Fractal; use Illuminate\Http\Request; use Pterodactyl\Models\Server; -use GuzzleHttp\Exception\ConnectException; use Pterodactyl\Http\Controllers\Controller; -use Pterodactyl\Transformers\User\ServerTransformer; use Pterodactyl\Repositories\Daemon\PowerRepository; +use Pterodactyl\Transformers\User\ServerTransformer; class ServerController extends Controller { diff --git a/app/Http/Middleware/CheckServer.php b/app/Http/Middleware/CheckServer.php index a913b87ea..4cfe08191 100644 --- a/app/Http/Middleware/CheckServer.php +++ b/app/Http/Middleware/CheckServer.php @@ -64,7 +64,7 @@ class CheckServer $this->request = $request; $this->server = Server::byUuid($request->route()->server); - if(! $this->exists()) { + if (! $this->exists()) { return response()->view('errors.404', [], 404); } @@ -124,6 +124,6 @@ class CheckServer } } - return ($this->server->installed === 1); + return $this->server->installed === 1; } } diff --git a/app/Http/Middleware/HMACAuthorization.php b/app/Http/Middleware/HMACAuthorization.php index 7b4e84b7f..2c08c1449 100644 --- a/app/Http/Middleware/HMACAuthorization.php +++ b/app/Http/Middleware/HMACAuthorization.php @@ -28,13 +28,11 @@ use Auth; use Crypt; use Config; use Closure; -use Response; use Debugbar; use IPTools\IP; use IPTools\Range; use Illuminate\Http\Request; use Pterodactyl\Models\APIKey; -use Pterodactyl\Models\APIPermission; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; // 400 use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; // 403 @@ -150,7 +148,7 @@ class HMACAuthorization protected function validateIPAccess() { if (! is_null($this->key()->allowed_ips)) { - foreach($this->key()->allowed_ips as $ip) { + foreach ($this->key()->allowed_ips as $ip) { if (Range::parse($ip)->contains(new IP($this->request()->ip()))) { return true; } @@ -194,7 +192,8 @@ class HMACAuthorization * * @return string */ - protected function public() { + protected function public() + { return $this->token['public']; } @@ -203,7 +202,8 @@ class HMACAuthorization * * @return string */ - protected function hash() { + protected function hash() + { return $this->token['hash']; } @@ -212,7 +212,8 @@ class HMACAuthorization * * @return \Pterodactyl\Models\APIKey */ - protected function key() { + protected function key() + { return $this->key; } diff --git a/app/Models/APIPermission.php b/app/Models/APIPermission.php index 67eec35be..bfe2fc908 100644 --- a/app/Models/APIPermission.php +++ b/app/Models/APIPermission.php @@ -71,7 +71,7 @@ class APIPermission extends Model 'view', 'power', 'command', - ] + ], ], // All other pemissions below are administrative actions. @@ -120,7 +120,7 @@ class APIPermission extends Model ]; /** - * Return permissions for API + * Return permissions for API. * * @return array */ diff --git a/app/Models/Server.php b/app/Models/Server.php index 18c86c157..8a3725ed6 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -209,7 +209,8 @@ class Server extends Model * * @return array */ - public function getTableColumns() { + public function getTableColumns() + { return Schema::getColumnListing($this->getTable()); } diff --git a/app/Providers/MacroServiceProvider.php b/app/Providers/MacroServiceProvider.php index 980634dd6..8dd08f73b 100644 --- a/app/Providers/MacroServiceProvider.php +++ b/app/Providers/MacroServiceProvider.php @@ -66,7 +66,7 @@ class MacroServiceProvider extends ServiceProvider return Cache::tags([ 'ApiKeyMacro', 'ApiKeyMacro:Key:' . $parts[0], - ])->remember('ApiKeyMacro.' . $parts[0], Carbon::now()->addMinutes(15), function() use ($parts) { + ])->remember('ApiKeyMacro.' . $parts[0], Carbon::now()->addMinutes(15), function () use ($parts) { return APIKey::where('public', $parts[0])->first(); }); } @@ -74,7 +74,7 @@ class MacroServiceProvider extends ServiceProvider return false; }); - Request::macro('apiKeyHasPermission', function($permission) { + Request::macro('apiKeyHasPermission', function ($permission) { $key = Request::apiKey(); if (! $key) { return false; diff --git a/app/Repositories/APIRepository.php b/app/Repositories/APIRepository.php index 561266c3f..db9b9d6b7 100644 --- a/app/Repositories/APIRepository.php +++ b/app/Repositories/APIRepository.php @@ -31,8 +31,8 @@ use Validator; use IPTools\Network; use Pterodactyl\Models\User; use Pterodactyl\Models\APIKey as Key; -use Pterodactyl\Models\APIPermission as Permission; use Pterodactyl\Exceptions\DisplayException; +use Pterodactyl\Models\APIPermission as Permission; use Pterodactyl\Exceptions\DisplayValidationException; class APIRepository diff --git a/app/Repositories/UserRepository.php b/app/Repositories/UserRepository.php index 902cebf15..b2ddaeadd 100644 --- a/app/Repositories/UserRepository.php +++ b/app/Repositories/UserRepository.php @@ -147,7 +147,7 @@ class UserRepository unset($data['password']); } - $user->fill($data)->save();; + $user->fill($data)->save(); return $user; } diff --git a/app/Transformers/Admin/ServiceVariableTransformer.php b/app/Transformers/Admin/ServiceVariableTransformer.php index 7f41a1079..aa10428d9 100644 --- a/app/Transformers/Admin/ServiceVariableTransformer.php +++ b/app/Transformers/Admin/ServiceVariableTransformer.php @@ -25,8 +25,8 @@ namespace Pterodactyl\Transformers\Admin; use Illuminate\Http\Request; -use Pterodactyl\Models\ServiceVariable; use League\Fractal\TransformerAbstract; +use Pterodactyl\Models\ServiceVariable; class ServiceVariableTransformer extends TransformerAbstract { diff --git a/config/pterodactyl.php b/config/pterodactyl.php index f217e4c05..dc3f3072c 100644 --- a/config/pterodactyl.php +++ b/config/pterodactyl.php @@ -32,7 +32,7 @@ return [ 'nodes' => env('APP_PAGINATE_API_NODES', 25), 'servers' => env('APP_PAGINATE_API_SERVERS', 25), 'users' => env('APP_PAGINATE_API_USERS', 25), - ] + ], ], /* diff --git a/routes/admin.php b/routes/admin.php index 96fa47256..36b8e6239 100644 --- a/routes/admin.php +++ b/routes/admin.php @@ -21,7 +21,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ - Route::get('/', 'BaseController@getIndex')->name('admin.index'); /* diff --git a/routes/api-admin.php b/routes/api-admin.php index fcd0a0a70..d5ca5b0b3 100644 --- a/routes/api-admin.php +++ b/routes/api-admin.php @@ -21,10 +21,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ - Route::get('/', 'CoreController@index'); - /* |-------------------------------------------------------------------------- | Server Controller Routes diff --git a/routes/api.php b/routes/api.php index 88a9d5ee7..9b2e01dfa 100644 --- a/routes/api.php +++ b/routes/api.php @@ -21,7 +21,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ - Route::get('/', 'CoreController@index')->name('api.user'); /* diff --git a/routes/auth.php b/routes/auth.php index 2d0ae392b..46de5a1b5 100644 --- a/routes/auth.php +++ b/routes/auth.php @@ -21,7 +21,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ - Route::get('/logout', 'LoginController@logout')->name('auth.logout')->middleware('auth'); Route::get('/login', 'LoginController@showLoginForm')->name('auth.login'); Route::get('/login/totp', 'LoginController@totp')->name('auth.totp'); diff --git a/routes/base.php b/routes/base.php index e63f5b43b..e13e1284a 100644 --- a/routes/base.php +++ b/routes/base.php @@ -21,7 +21,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ - Route::get('/', 'IndexController@getIndex')->name('index'); Route::get('/index', function () { redirect()->route('index'); diff --git a/routes/daemon.php b/routes/daemon.php index 5a1fc35c9..78edf308f 100644 --- a/routes/daemon.php +++ b/routes/daemon.php @@ -21,7 +21,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ - Route::get('/services', 'ServiceController@list')->name('daemon.services'); Route::get('/services/pull/{service}/{file}', 'ServiceController@pull')->name('daemon.pull'); Route::get('/packs/pull/{uuid}', 'PackController@pull')->name('daemon.pack.pull'); diff --git a/routes/remote.php b/routes/remote.php index c592ad325..d7fe471c5 100644 --- a/routes/remote.php +++ b/routes/remote.php @@ -21,7 +21,6 @@ * 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'); diff --git a/routes/server.php b/routes/server.php index 75fc56c7d..953eab2b2 100644 --- a/routes/server.php +++ b/routes/server.php @@ -21,7 +21,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ - Route::get('/', 'ServerController@getIndex')->name('server.index'); /*