/** * Constructor * * @param string $server The server Short UUID */ public function __construct($uuid) { $this->server = Server::getByUUID($uuid); $this->node = Node::getByID($this->server->node); $this->client = Node::guzzleRequest($this->server->node); $this->headers = Server::getGuzzleHeaders($uuid); }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { if (!Auth::user()) { return redirect()->guest('auth/login'); } $server = Server::getByUUID($request->route()->server); if (!$server) { return response()->view('errors.404', [], 404); } if ($server->suspended === 1) { return response()->view('errors.suspended', [], 403); } if ($server->installed !== 1) { return response()->view('errors.installing', [], 403); } return $next($request); }
public function postSettingsStartup(Request $request, $uuid) { $server = Models\Server::getByUUID($uuid); $this->authorize('edit-startup', $server); try { $repo = new ServerRepository(); $repo->updateStartup($server->id, $request->except(['_token'])); Alert::success('Server startup variables were successfully updated.')->flash(); } catch (DisplayException $ex) { Alert::danger($ex->getMessage())->flash(); } catch (\Exception $ex) { Log::error($ex); Alert::danger('An unhandled exception occured while attemping to update startup variables for this server. Please try again.')->flash(); } return redirect()->route('server.settings', ['uuid' => $uuid, 'tab' => 'tab_startup']); }
public function toggleTask(Request $request, $uuid, $id) { $server = Models\Server::getByUUID($uuid); $this->authorize('toggle-task', $server); $task = Models\Task::findOrFail($id); if (!$task || $server->id !== $task->server) { return response()->json(['error' => 'No task by that ID was found associated with this server.'], 404); } try { $repo = new Repositories\TaskRepository(); $resp = $repo->toggle($id); return response()->json(['status' => $resp]); } catch (\Exception $ex) { Log::error($ex); return response()->json(['error' => 'A server error occured while attempting to toggle this task.'], 503); } }
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); } }
public function deleteSubuser(Request $request, $uuid, $id) { $server = Models\Server::getByUUID($uuid); $this->authorize('delete-subuser', $server); try { $subuser = Models\Subuser::select('id')->where(DB::raw('md5(id)'), $id)->where('server_id', $server->id)->first(); if (!$subuser) { throw new DisplayException('No subuser by that ID was found on the system.'); } $repo = new SubuserRepository(); $repo->delete($subuser->id); return response('', 204); } catch (DisplayException $ex) { response()->json(['error' => $ex->getMessage()], 422); } catch (\Exception $ex) { Log::error($ex); response()->json(['error' => 'An unknown error occured while attempting to delete this subuser.'], 503); } }