| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * Pterodactyl - Panel | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * Copyright (c) 2015 - 2017 Dane Everitt <[email protected]>. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * Permission is hereby granted, free of charge, to any person obtaining a copy | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * of this software and associated documentation files (the "Software"), to deal | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * in the Software without restriction, including without limitation the rights | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * copies of the Software, and to permit persons to whom the Software is | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * furnished to do so, subject to the following conditions: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * The above copyright notice and this permission notice shall be included in all | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * copies or substantial portions of the Software. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  * SOFTWARE. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | namespace Pterodactyl\Http\Controllers\API\User; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | use Log; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | use Auth; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | use Pterodactyl\Models; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | use Illuminate\Http\Request; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | use Pterodactyl\Http\Controllers\API\BaseController; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | class ServerController extends BaseController | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 34 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |     public function info(Request $request, $uuid) | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |         $server = Models\Server::byUuid($uuid)->load('allocations'); | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |         try { | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |             $response = $server->guzzleClient()->request('GET', '/server'); | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |             $json = json_decode($response->getBody()); | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |             $daemon = [ | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |                 'status' => $json->status, | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |                 'stats' => $json->proc, | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |                 'query' =>  $json->query, | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |             ]; | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |         } catch (\Exception $ex) { | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |             $daemon = [ | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |                 'error' => 'An error was encountered while trying to connect to the daemon to collece information. It might be offline.', | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |             ]; | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |             Log::error($ex); | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |         foreach ($server->allocations as &$allocation) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |             $allocation->default = ($allocation->id === $server->allocation_id); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |             unset($allocation->id); | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |         return [ | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |             'uuidShort' => $server->uuidShort, | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |             'uuid' => $server->uuid, | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |             'name' => $server->name, | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |             'node' => $server->node->name, | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |             'limits' => [ | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |                 'memory' => $server->memory, | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |                 'swap' => $server->swap, | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |                 'disk' => $server->disk, | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |                 'io' => $server->io, | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |                 'cpu' => $server->cpu, | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |                 'oom_disabled' => (bool) $server->oom_disabled, | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |             ], | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  |             'allocations' => $server->allocations, | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  |             'sftp' => [ | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  |                 'username' => (Auth::user()->can('view-sftp', $server)) ? $server->username : null, | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  |             ], | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  |             'daemon' => [ | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  |                 'token' => ($request->secure()) ? $server->daemonSecret : false, | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  |                 'response' => $daemon, | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  |             ], | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  |         ]; | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     public function power(Request $request, $uuid) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         $server = Models\Server::byUuid($uuid); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |         Auth::user()->can('power-' . $request->input('action'), $server); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |         $res = $server->guzzleClient()->request('PUT', '/server/power', [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |             'exceptions' => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |             'json' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |                 'action' => $request->input('action'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |         if ($res->getStatusCode() !== 204) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |             return $this->response->error(json_decode($res->getBody())->error, $res->getStatusCode()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |         return $this->response->noContent(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 102 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 103 |  |  |  | 
            
                        
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.