Skip to content

Commit f8e98e9

Browse files
committed
Add ability to change server name, closes pterodactyl#563
1 parent e55d3c1 commit f8e98e9

File tree

8 files changed

+156
-3
lines changed

8 files changed

+156
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
1313
* Fix data integrity exception thrown when attempting to store updated server egg variables.
1414
* Added missing permissions check on 'SFTP Configuration' page to ensure user has permission to access a server's SFTP server before showing a user credentials.
1515

16+
### Added
17+
* Added ability for end users to change the name of their server through the UI. This option is only open to the server owner or an admin.
18+
1619
### Changed
1720
* Panel now throws proper 504: Gateway Timeout errors on server listing when daemon is offline.
1821
* Sessions handled through redis now use a seperate database (default `1`) to store session database to avoid logging users out when flushing the cache.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
namespace Pterodactyl\Http\Controllers\Server\Settings;
4+
5+
use Illuminate\Http\Request;
6+
use Illuminate\Http\RedirectResponse;
7+
use Pterodactyl\Http\Controllers\Controller;
8+
use Pterodactyl\Traits\Controllers\JavascriptInjection;
9+
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
10+
use Pterodactyl\Http\Requests\Server\Settings\ChangeServerNameRequest;
11+
12+
class NameController extends Controller
13+
{
14+
use JavascriptInjection;
15+
16+
/**
17+
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
18+
*/
19+
private $repository;
20+
21+
/**
22+
* NameController constructor.
23+
*
24+
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
25+
*/
26+
public function __construct(ServerRepositoryInterface $repository)
27+
{
28+
$this->repository = $repository;
29+
}
30+
31+
/**
32+
* @param \Illuminate\Http\Request $request
33+
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
34+
* @throws \Illuminate\Auth\Access\AuthorizationException
35+
*/
36+
public function index(Request $request)
37+
{
38+
$this->authorize('view-name', $request->attributes->get('server'));
39+
$this->setRequest($request)->injectJavascript();
40+
41+
return view('server.settings.name');
42+
}
43+
44+
/**
45+
* Update the stored name for a specific server.
46+
*
47+
* @param \Pterodactyl\Http\Requests\Server\Settings\ChangeServerNameRequest $request
48+
* @return \Illuminate\Http\RedirectResponse
49+
*
50+
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
51+
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
52+
*/
53+
public function update(ChangeServerNameRequest $request): RedirectResponse
54+
{
55+
$this->repository->update($request->getServer()->id, $request->validated());
56+
57+
return redirect()->route('server.settings.name', $request->getServer()->uuidShort);
58+
}
59+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Pterodactyl\Http\Requests\Server\Settings;
4+
5+
use Pterodactyl\Models\Server;
6+
use Pterodactyl\Http\Requests\Server\ServerFormRequest;
7+
8+
class ChangeServerNameRequest extends ServerFormRequest
9+
{
10+
/**
11+
* Permission to use when checking if a user can access this resource.
12+
*
13+
* @return string
14+
*/
15+
protected function permission(): string
16+
{
17+
return 'edit-name';
18+
}
19+
20+
/**
21+
* Rules to use when validating the submitted data.
22+
*
23+
* @return array
24+
*/
25+
public function rules()
26+
{
27+
return [
28+
'name' => Server::getCreateRules()['name'],
29+
];
30+
}
31+
}

resources/lang/en/navigation.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@
2727
'edit_file' => 'Edit File',
2828
'admin_header' => 'ADMINISTRATIVE',
2929
'admin' => 'Server Configuration',
30+
'server_name' => 'Server Name',
3031
],
3132
];

resources/lang/en/server.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,11 @@
289289
],
290290
],
291291
'config' => [
292+
'name' => [
293+
'header' => 'Server Name',
294+
'header_sub' => 'Change this server\'s name.',
295+
'details' => 'The server name is only a reference to this server on the panel, and will not affect any server specific configurations that may display to users in games.',
296+
],
292297
'startup' => [
293298
'header' => 'Start Configuration',
294299
'header_sub' => 'Control server startup arguments.',

resources/themes/pterodactyl/layouts/master.blade.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ class="active"
184184
</span>
185185
</a>
186186
<ul class="treeview-menu">
187+
@can('view-name', $server)
188+
<li class="{{ Route::currentRouteName() !== 'server.settings.name' ?: 'active' }}"><a href="{{ route('server.settings.name', $server->uuidShort) }}"><i class="fa fa-angle-right"></i> @lang('navigation.server.server_name')</a></li>
189+
@endcan
187190
@can('view-allocations', $server)
188191
<li class="{{ Route::currentRouteName() !== 'server.settings.allocation' ?: 'active' }}"><a href="{{ route('server.settings.allocation', $server->uuidShort) }}"><i class="fa fa-angle-right"></i> @lang('navigation.server.port_allocations')</a></li>
189192
@endcan
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{{-- Pterodactyl - Panel --}}
2+
{{-- Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com> --}}
3+
4+
{{-- This software is licensed under the terms of the MIT license. --}}
5+
{{-- https://opensource.org/licenses/MIT --}}
6+
@extends('layouts.master')
7+
8+
@section('title')
9+
@lang('server.config.name.header')
10+
@endsection
11+
12+
@section('content-header')
13+
<h1>@lang('server.config.name.header')<small>@lang('server.config.name.header_sub')</small></h1>
14+
<ol class="breadcrumb">
15+
<li><a href="{{ route('index') }}">@lang('strings.home')</a></li>
16+
<li><a href="{{ route('server.index', $server->uuidShort) }}">{{ $server->name }}</a></li>
17+
<li>@lang('navigation.server.configuration')</li>
18+
<li class="active">@lang('navigation.server.server_name')</li>
19+
</ol>
20+
@endsection
21+
22+
@section('content')
23+
<div class="row">
24+
<div class="col-xs-12">
25+
<form action="{{ route('server.settings.name', $server->uuidShort) }}" method="POST">
26+
<div class="box">
27+
<div class="box-body">
28+
<div class="form-group no-margin-bottom">
29+
<label class="control-label" for="pServerName">@lang('server.config.name.header')</label>
30+
<div>
31+
<input type="text" name="name" id="pServerName" class="form-control" value="{{ $server->name }}" />
32+
<p class="small text-muted no-margin-bottom">@lang('server.config.name.details')</p>
33+
</div>
34+
</div>
35+
</div>
36+
<div class="box-footer">
37+
{{ method_field('PATCH') }}
38+
{{ csrf_field() }}
39+
<input type="submit" class="btn btn-sm btn-primary pull-right" value="@lang('strings.submit')" />
40+
</div>
41+
</div>
42+
</form>
43+
</div>
44+
</div>
45+
@endsection
46+
47+
@section('footer-scripts')
48+
@parent
49+
{!! Theme::js('js/frontend/server.socket.js') !!}
50+
@endsection

routes/server.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919
*/
2020
Route::group(['prefix' => 'settings'], function () {
2121
Route::get('/allocation', 'Settings\AllocationController@index')->name('server.settings.allocation');
22-
Route::patch('/allocation', 'Settings\AllocationController@update');
23-
22+
Route::get('/name', 'Settings\NameController@index')->name('server.settings.name');
2423
Route::get('/sftp', 'Settings\SftpController@index')->name('server.settings.sftp');
25-
2624
Route::get('/startup', 'Settings\StartupController@index')->name('server.settings.startup');
25+
26+
Route::patch('/allocation', 'Settings\AllocationController@update');
27+
Route::patch('/name', 'Settings\NameController@update');
2728
Route::patch('/startup', 'Settings\StartupController@update');
2829
});
2930

0 commit comments

Comments
 (0)