public function getView(Request $request, $id)
 {
     $server = Models\Server::select('servers.*', 'nodes.name as a_nodeName', 'users.email as a_ownerEmail', 'locations.long as a_locationName', 'services.name as a_serviceName', DB::raw('IFNULL(service_options.executable, services.executable) as a_serviceExecutable'), 'service_options.docker_image', 'service_options.name as a_servceOptionName', 'allocations.ip', 'allocations.port', 'allocations.ip_alias')->join('nodes', 'servers.node', '=', 'nodes.id')->join('users', 'servers.owner', '=', 'users.id')->join('locations', 'nodes.location', '=', 'locations.id')->join('services', 'servers.service', '=', 'services.id')->join('service_options', 'servers.option', '=', 'service_options.id')->join('allocations', 'servers.allocation', '=', 'allocations.id')->where('servers.id', $id)->first();
     if (!$server) {
         return abort(404);
     }
     return view('admin.servers.view', ['server' => $server, 'assigned' => Models\Allocation::where('assigned_to', $id)->orderBy('ip', 'asc')->orderBy('port', 'asc')->get(), 'unassigned' => Models\Allocation::where('node', $server->node)->whereNull('assigned_to')->orderBy('ip', 'asc')->orderBy('port', 'asc')->get(), 'startup' => Models\ServiceVariables::select('service_variables.*', 'server_variables.variable_value as a_serverValue')->join('server_variables', 'server_variables.variable_id', '=', 'service_variables.id')->where('service_variables.option_id', $server->option)->where('server_variables.server_id', $server->id)->get(), '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(), 'db_servers' => Models\DatabaseServer::all()]);
 }
 public function getIndex(Request $request)
 {
     return view('admin.databases.index', ['databases' => Models\Database::select('databases.*', 'database_servers.host as a_host', 'database_servers.port as a_port', 'servers.id as a_serverId', 'servers.name as a_serverName')->join('database_servers', 'database_servers.id', '=', 'databases.db_server')->join('servers', 'databases.server_id', '=', 'servers.id')->paginate(20), 'dbh' => Models\DatabaseServer::select('database_servers.*', 'nodes.name as a_linkedNode', DB::raw('(SELECT COUNT(*) FROM `databases` WHERE `databases`.`db_server` = database_servers.id) as c_databases'))->join('nodes', 'nodes.id', '=', 'database_servers.linked_node')->paginate(20)]);
 }
Beispiel #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]);
 }
 /**
  * Deletes a database server from the system if it is empty.
  * @param  int $server The ID of the Database Server.
  * @return
  */
 public function delete($server)
 {
     $dbh = Models\DatabaseServer::findOrFail($server);
     $databases = Models\Database::where('db_server', $dbh->id)->count();
     if ($databases > 0) {
         throw new DisplayException('You cannot delete a database server that has active databases attached to it.');
     }
     return $dbh->delete();
 }
Beispiel #5
0
 public function postResetDatabasePassword(Request $request, $uuid)
 {
     $server = Models\Server::getByUUID($uuid);
     $database = Models\Database::where('id', $request->input('database'))->where('server_id', $server->id)->firstOrFail();
     $this->authorize('reset-db-password', $server);
     try {
         $repo = new Repositories\DatabaseRepository();
         $password = str_random(16);
         $repo->modifyPassword($request->input('database'), $password);
         return response($password);
     } catch (\Pterodactyl\Exceptions\DisplayException $ex) {
         return response()->json(['error' => $ex->getMessage()], 503);
     } catch (\Exception $ex) {
         Log::error($ex);
         return response()->json(['error' => 'An unhandled error occured while attempting to modify this database\'s password.'], 503);
     }
 }