| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * Pterodactyl - Panel | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * Copyright (c) 2015 - 2017 Dane Everitt <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * Some Modifications (c) 2015 Dylan Seidt <[email protected]>. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * Permission is hereby granted, free of charge, to any person obtaining a copy | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * of this software and associated documentation files (the "Software"), to deal | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * in the Software without restriction, including without limitation the rights | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * copies of the Software, and to permit persons to whom the Software is | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * furnished to do so, subject to the following conditions: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * The above copyright notice and this permission notice shall be included in all | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * copies or substantial portions of the Software. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  * SOFTWARE. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | namespace Pterodactyl\Http\Controllers\Base; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | use Log; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | use Alert; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | use Pterodactyl\Models; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | use Illuminate\Http\Request; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | use Pterodactyl\Repositories\APIRepository; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | use Pterodactyl\Exceptions\DisplayException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | use Pterodactyl\Http\Controllers\Controller; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | use Pterodactyl\Exceptions\DisplayValidationException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | class APIController extends Controller | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     public function index(Request $request) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         return view('base.api.index', [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |             'keys' => Models\APIKey::where('user_id', $request->user()->id)->get(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     public function create(Request $request) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         return view('base.api.new'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 51 |  | View Code Duplication |     public function save(Request $request) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |             $repo = new APIRepository($request->user()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |             $secret = $repo->create($request->only([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |                 'memo', 'allowed_ips', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |                 'adminPermissions', 'permissions', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |             ])); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |             Alert::success('An API Key-Pair has successfully been generated. The API secret for this public key is shown below and will not be shown again.<br /><br /><code>' . $secret . '</code>')->flash(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |             return redirect()->route('account.api'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         } catch (DisplayValidationException $ex) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |             return redirect()->route('account.api.new')->withErrors(json_decode($ex->getMessage()))->withInput(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         } catch (DisplayException $ex) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |             Alert::danger($ex->getMessage())->flash(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         } catch (\Exception $ex) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |             Log::error($ex); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |             Alert::danger('An unhandled exception occured while attempting to add this API key.')->flash(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         return redirect()->route('account.api.new')->withInput(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 73 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 74 |  |  |     public function revoke(Request $request, $key) | 
            
                                                        
            
                                    
            
            
                | 75 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 76 |  |  |         try { | 
            
                                                        
            
                                    
            
            
                | 77 |  |  |             $repo = new APIRepository($request->user()); | 
            
                                                        
            
                                    
            
            
                | 78 |  |  |             $repo->revoke($key); | 
            
                                                        
            
                                    
            
            
                | 79 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 80 |  |  |             return response('', 204); | 
            
                                                        
            
                                    
            
            
                | 81 |  |  |         } catch (\Exception $ex) { | 
            
                                                        
            
                                    
            
            
                | 82 |  |  |             return response()->json([ | 
            
                                                        
            
                                    
            
            
                | 83 |  |  |                 'error' => 'An error occured while attempting to remove this key.', | 
            
                                                        
            
                                    
            
            
                | 84 |  |  |             ], 503); | 
            
                                                        
            
                                    
            
            
                | 85 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 86 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 87 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 88 |  |  |  | 
            
                        
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.