diff --git a/app/Http/Controllers/Server/AjaxController.php b/app/Http/Controllers/Server/AjaxController.php index fe353a3a6..48af2eb9d 100644 --- a/app/Http/Controllers/Server/AjaxController.php +++ b/app/Http/Controllers/Server/AjaxController.php @@ -178,4 +178,38 @@ class AjaxController extends Controller } + /** + * [postSetConnection description] + * @param Request $request + * @param string $uuid + * @return \Illuminate\Http\Response + */ + public function postSetConnection(Request $request, $uuid) + { + + $server = Server::getByUUID($uuid); + $this->authorize('set-connection', $server); + + 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 (\Exception $e) { + if ($e instanceof \Pterodactyl\Exceptions\DisplayException || $e instanceof \Pterodactyl\Exceptions\DisplayValidationException) { + return response()->json([ + 'error' => $e->getMessage(), + ], 503); + } else { + Log::error($e); + return response()->json([ + 'error' => 'An unhandled exception occured while attemping to modify the default connection for this server.' + ], 503); + } + } + } + } diff --git a/app/Http/Routes/ServerRoutes.php b/app/Http/Routes/ServerRoutes.php index b775eeccb..5c97156c0 100644 --- a/app/Http/Routes/ServerRoutes.php +++ b/app/Http/Routes/ServerRoutes.php @@ -18,6 +18,7 @@ class ServerRoutes { // Ajax Routes $router->group(['prefix' => 'ajax'], function ($server) use ($router) { $router->get('status', [ 'uses' => 'Server\AjaxController@getStatus' ]); + $router->post('set-connection', [ 'uses' => 'Server\AjaxController@postSetConnection' ]); $router->post('files/directory-list', [ 'uses' => 'Server\AjaxController@postDirectoryList' ]); $router->post('files/save', [ 'uses' => 'Server\AjaxController@postSaveFile' ]); }); diff --git a/app/Policies/ServerPolicy.php b/app/Policies/ServerPolicy.php index 338a33852..2f9355cca 100644 --- a/app/Policies/ServerPolicy.php +++ b/app/Policies/ServerPolicy.php @@ -175,4 +175,20 @@ class ServerPolicy return $user->permissions()->server($server)->permission('download-files')->exists(); } + /** + * Check if user has permission to change the default connection information. + * + * @param Pterodactyl\Models\User $user + * @param Pterodactyl\Models\Server $server + * @return boolean + */ + public function setConnection(User $user, Server $server) + { + if ($this->isOwner($user, $server)) { + return true; + } + + return $user->permissions()->server($server)->permission('set-connection')->exists(); + } + } diff --git a/resources/views/server/index.blade.php b/resources/views/server/index.blade.php index 45719eb74..b84ba2298 100644 --- a/resources/views/server/index.blade.php +++ b/resources/views/server/index.blade.php @@ -88,7 +88,7 @@
Below is a listing of all avaliable IPs and Ports for your service. To change the default connection address for your server, simply click on the one you would like to make default below.
-