/** * [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); } }
/** * Update Server Build Configuration * * Updates server build information on panel and on node. * * @Patch("/servers/{id}/build") * @Versions({"v1"}) * @Transaction({ * @Request({ * "default": "192.168.0.1:25565", * "add_additional": [ * "192.168.0.1:25566", * "192.168.0.1:25567", * "192.168.0.1:25568" * ], * "remove_additional": [], * "memory": 1024, * "swap": 0, * "io": 500, * "cpu": 0, * "disk": 1024 * }, headers={"Authorization": "Bearer <token>"}), * @Response(200, body={"name": "New Name"}), * @Response(422) * }) * @Parameters({ * @Parameter("id", type="integer", required=true, description="The ID of the server to modify.") * }) */ public function build(Request $request, $id) { try { throw new BadRequestHttpException('There was an error while attempting to add this node to the system.'); $server = new ServerRepository(); $server->changeBuild($id, $request->all()); return Models\Server::findOrFail($id); } catch (DisplayValidationException $ex) { throw new ResourceException('A validation error occured.', json_decode($ex->getMessage(), true)); } catch (DisplayException $ex) { throw new ResourceException($ex->getMessage()); } catch (\Exception $ex) { throw new ServiceUnavailableHttpException('Unable to update server on system due to an error.'); } }
public function postUpdateServerUpdateBuild(Request $request, $id) { try { $server = new ServerRepository(); $server->changeBuild($id, ['default' => $request->input('default'), 'add_additional' => $request->input('add_additional'), 'remove_additional' => $request->input('remove_additional'), 'memory' => $request->input('memory'), 'swap' => $request->input('swap'), 'io' => $request->input('io'), 'cpu' => $request->input('cpu')]); Alert::success('Server details were successfully updated.')->flash(); } catch (DisplayValidationException $ex) { return redirect()->route('admin.servers.view', ['id' => $id, 'tab' => 'tab_build'])->withErrors(json_decode($ex->getMessage()))->withInput(); } catch (DisplayException $ex) { Alert::danger($ex->getMessage())->flash(); return redirect()->route('admin.servers.view', ['id' => $id, 'tab' => 'tab_build']); } catch (\Exception $ex) { Log::error($ex); Alert::danger('An unhandled exception occured while attemping to add this server. Please try again.')->flash(); } return redirect()->route('admin.servers.view', ['id' => $id, 'tab' => 'tab_build']); }