/** * Renders edit file page for a given file. * * @param Request $request * @param string $uuid * @param string $file * @return \Illuminate\Contracts\View\View */ public function getEditFile(Request $request, $uuid, $file) { $server = Models\Server::getByUUID($uuid); $this->authorize('edit-files', $server); $fileInfo = (object) pathinfo($file); $controller = new FileRepository($uuid); try { $fileContent = $controller->returnFileContents($file); } catch (DisplayException $ex) { Alert::danger($ex->getMessage())->flash(); return redirect()->route('server.files.index', $uuid); } catch (\Exception $ex) { Log::error($ex); Alert::danger('An error occured while attempting to load the requested file for editing, please try again.')->flash(); return redirect()->route('server.files.index', $uuid); } return view('server.files.edit', ['server' => $server, 'node' => Models\Node::find($server->node), 'file' => $file, 'contents' => $fileContent->content, 'directory' => in_array($fileInfo->dirname, ['.', './', '/']) ? '/' : trim($fileInfo->dirname, '/') . '/', 'extension' => $fileInfo->extension]); }
/** * Handles a POST request to save a file. * * @param Request $request * @param string $uuid * @return \Illuminate\Http\Response */ public function postSaveFile(Request $request, $uuid) { $server = Models\Server::getByUUID($uuid); $this->authorize('save-files', $server); $controller = new Repositories\Daemon\FileRepository($uuid); try { $controller->saveFileContents($request->input('file'), $request->input('contents')); return response(null, 204); } catch (DisplayException $ex) { return response($ex->getMessage(), 500); } catch (\Exception $ex) { Log::error($ex); return response('An error occured while attempting to save this file, please try again.', 500); } }