コード例 #1
0
ファイル: NodeController.php プロジェクト: Pterodactyl/Panel
 /**
  * List all Node Allocations
  *
  * Returns a listing of all allocations for every node.
  *
  * @Get("/nodes/allocations")
  * @Versions({"v1"})
  * @Response(200)
  */
 public function allocations(Request $request)
 {
     $allocations = Models\Allocation::paginate(100);
     if ($allocations->count() < 1) {
         throw new NotFoundHttpException('No allocations have been created.');
     }
     return $this->response->paginator($allocations, new AllocationTransformer());
 }
コード例 #2
0
ファイル: NodeRepository.php プロジェクト: Pterodactyl/Panel
 public function addAllocations($id, array $allocations)
 {
     $node = Models\Node::findOrFail($id);
     DB::beginTransaction();
     try {
         foreach ($allocations as $rawIP => $ports) {
             $parsedIP = Network::parse($rawIP);
             foreach ($parsedIP as $ip) {
                 foreach ($ports as $port) {
                     if (!is_int($port) && !preg_match('/^(\\d{1,5})-(\\d{1,5})$/', $port)) {
                         throw new DisplayException('The mapping for ' . $port . ' is invalid and cannot be processed.');
                     }
                     if (preg_match('/^(\\d{1,5})-(\\d{1,5})$/', $port, $matches)) {
                         foreach (range($matches[1], $matches[2]) as $assignPort) {
                             $alloc = Models\Allocation::firstOrNew(['node' => $node->id, 'ip' => $ip, 'port' => $assignPort]);
                             if (!$alloc->exists) {
                                 $alloc->fill(['node' => $node->id, 'ip' => $ip, 'port' => $assignPort, 'assigned_to' => null]);
                                 $alloc->save();
                             }
                         }
                     } else {
                         $alloc = Models\Allocation::firstOrNew(['node' => $node->id, 'ip' => $ip, 'port' => $port]);
                         if (!$alloc->exists) {
                             $alloc->fill(['node' => $node->id, 'ip' => $ip, 'port' => $port, 'assigned_to' => null]);
                             $alloc->save();
                         }
                     }
                 }
             }
         }
         DB::commit();
         return true;
     } catch (\Exception $ex) {
         DB::rollBack();
         throw $ex;
     }
 }
コード例 #3
0
 /**
  * Renders server settings page.
  *
  * @param  \Illuminate\Http\Request $request
  * @return \Illuminate\Contracts\View\View
  */
 public function getSettings(Request $request, $uuid)
 {
     $server = Models\Server::getByUUID($uuid);
     $allocation = Models\Allocation::findOrFail($server->allocation);
     $variables = Models\ServiceVariables::select('service_variables.*', DB::raw('COALESCE(server_variables.variable_value, service_variables.default_value) as a_serverValue'))->leftJoin('server_variables', 'server_variables.variable_id', '=', 'service_variables.id')->where('service_variables.option_id', $server->option)->where('server_variables.server_id', $server->id)->get();
     $service = Models\Service::select(DB::raw('IFNULL(service_options.executable, services.executable) as executable'))->leftJoin('service_options', 'service_options.parent_service', '=', 'services.id')->where('service_options.id', $server->option)->where('services.id', $server->service)->first();
     $serverVariables = ['{{SERVER_MEMORY}}' => $server->memory, '{{SERVER_IP}}' => $allocation->ip, '{{SERVER_PORT}}' => $allocation->port];
     $processed = str_replace(array_keys($serverVariables), array_values($serverVariables), $server->startup);
     foreach ($variables as &$variable) {
         $replace = $variable->user_viewable === 1 ? $variable->a_serverValue : '**';
         $processed = str_replace('{{' . $variable->env_variable . '}}', $replace, $processed);
     }
     return view('server.settings', ['server' => $server, 'databases' => Models\Database::select('databases.*', 'database_servers.host as a_host', 'database_servers.port as a_port')->where('server_id', $server->id)->join('database_servers', 'database_servers.id', '=', 'databases.db_server')->get(), 'node' => Models\Node::find($server->node), 'variables' => $variables->where('user_viewable', 1), 'service' => $service, 'processedStartup' => $processed]);
 }
コード例 #4
0
ファイル: AjaxController.php プロジェクト: Pterodactyl/Panel
 /**
  * [postSetConnection description]
  * @param  Request $request
  * @param  string  $uuid
  * @return \Illuminate\Http\Response
  */
 public function postSetConnection(Request $request, $uuid)
 {
     $server = Models\Server::getByUUID($uuid);
     $allocation = Models\Allocation::findOrFail($server->allocation);
     $this->authorize('set-connection', $server);
     if ($request->input('connection') === $allocation->ip . ':' . $allocation->port) {
         return response()->json(['error' => 'You are already using this as your default connection.'], 409);
     }
     try {
         $repo = new Repositories\ServerRepository();
         $repo->changeBuild($server->id, ['default' => $request->input('connection')]);
         return response('The default connection for this server has been updated. Please be aware that you will need to restart your server for this change to go into effect.');
     } catch (DisplayValidationException $ex) {
         return response()->json(['error' => json_decode($ex->getMessage(), true)], 503);
     } catch (DisplayException $ex) {
         return response()->json(['error' => $ex->getMessage()], 503);
     } catch (\Exception $ex) {
         Log::error($ex);
         return response()->json(['error' => 'An unhandled exception occured while attemping to modify the default connection for this server.'], 503);
     }
 }
コード例 #5
0
 public function deleteServer($id, $force)
 {
     $server = Models\Server::findOrFail($id);
     $node = Models\Node::findOrFail($server->node);
     DB::beginTransaction();
     try {
         // Delete Allocations
         Models\Allocation::where('assigned_to', $server->id)->update(['assigned_to' => null]);
         // Remove Variables
         Models\ServerVariables::where('server_id', $server->id)->delete();
         // Remove SubUsers
         Models\Subuser::where('server_id', $server->id)->delete();
         // Remove Permissions
         Models\Permission::where('server_id', $server->id)->delete();
         // Remove Downloads
         Models\Download::where('server', $server->uuid)->delete();
         $client = Models\Node::guzzleRequest($server->node);
         $client->request('DELETE', '/servers', ['headers' => ['X-Access-Token' => $node->daemonSecret, 'X-Access-Server' => $server->uuid]]);
         $server->delete();
         DB::commit();
         return true;
     } catch (\GuzzleHttp\Exception\TransferException $ex) {
         if ($force === 'force') {
             $server->delete();
             DB::commit();
             return true;
         } else {
             DB::rollBack();
             throw new DisplayException('An error occured while attempting to delete the server on the daemon.', $ex);
         }
     } catch (\Exception $ex) {
         DB::rollBack();
         throw $ex;
     }
 }
コード例 #6
0
 /**
  * Returns a JSON tree of all avaliable IPs and Ports on a given node.
  *
  * @param  \Illuminate\Http\Request $request
  * @return \Illuminate\Contracts\View\View
  */
 public function postNewServerGetIps(Request $request)
 {
     if (!$request->input('node')) {
         return response()->json(['error' => 'Missing node in request.'], 500);
     }
     $ips = Models\Allocation::where('node', $request->input('node'))->whereNull('assigned_to')->get();
     $listing = [];
     foreach ($ips as &$ip) {
         if (array_key_exists($ip->ip, $listing)) {
             $listing[$ip->ip] = array_merge($listing[$ip->ip], [$ip->port]);
         } else {
             $listing[$ip->ip] = [$ip->port];
         }
     }
     return response()->json($listing);
 }
コード例 #7
0
ファイル: NodesController.php プロジェクト: Pterodactyl/Panel
 public function getAllocationsJson(Request $request, $id)
 {
     $allocations = Models\Allocation::select('ip')->where('node', $id)->groupBy('ip')->get();
     return response()->json($allocations);
 }