Skip to content

Commit d73d580

Browse files
authored
Merge pull request pterodactyl#701 from Pterodactyl/feature/add-frontend-server-configuration
Add database/startup/allocation management to server front-end views
2 parents b1fae66 + 25b2093 commit d73d580

File tree

89 files changed

+3286
-2020
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+3286
-2020
lines changed

CHANGELOG.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,34 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
1212
* New CLI command to disabled 2-Factor Authentication on an account if necessary.
1313
* Ability to delete users and locations via the CLI.
1414
* You can now require 2FA for all users, admins only, or at will using a simple configuration in the Admin CP.
15-
* Added ability to export and import service options and their associated settings and environment variables via the Admin CP.
15+
* **Added ability to export and import service options and their associated settings and environment variables via the Admin CP.**
16+
* Default allocation for a server can be changed on the front-end by users. This includes two new subuser permissions as well.
17+
* Significant improvements to environment variable control for servers. Now ships with built-in abilities to define extra variables in the Panel's configuration file, or in-code for those heavily modifying the Panel.
18+
* Quick link to server edit view in ACP on frontend when viewing servers.
19+
* Databases created in the Panel now include `EXECUTE` privilege.
1620

1721
### Changed
22+
* **Services renamed to Nests. Service Options renamed to Eggs.** 🥚
1823
* Theme colors and login pages updated to give a more unique feel to the project.
1924
* Massive overhaul to the backend code that allows for much easier updating of core functionality as well as support for better testing. This overhaul also reduces complex code logic, and allows for faster response times in the application.
2025
* CLI commands updated to be easier to type, now stored in the `p:` namespace.
2126
* Logout icon is now more universal and not just a power icon.
2227
* Administrative logout notice now uses SWAL rather than a generic javascript popup.
2328
* Server creation page now only asks for a node to deploy to, rather than requiring a location and then a node.
29+
* Database passwords are now hidden by default and will only show if clicked on. In addition, database view in ACP now indicates that passwords must be viewed on the front-end.
30+
* Localhost cannot be used as a connection address in the environment configuration script. `127.0.0.1` is allowed.
2431

2532
### Fixed
2633
* Unable to change the daemon secret for a server via the Admin CP.
2734
* Using default value in rules when creating a new variable if the rules is empty.
2835
* Fixes a design-flaw in the allocation management part of nodes that would run a MySQL query for each port being allocated. This behavior is now changed to only execute one query to add multiple ports at once.
2936
* Attempting to create a server when no nodes are configured now redirects to the node creation page.
3037
* Fixes missing library issue for teamspeak when used with mariadb.
38+
* Fixes inability to change the default port on front-end when viewing a server.
39+
* Fixes bug preventing deletion of nests that have other nests referencing them as children.
40+
41+
### Removed
42+
* SFTP settings page now only displays connection address and username. Password setting was removed as it is no longer necessary with Daemon changes.
3143

3244
## v0.6.4 (Courageous Carniadactylus)
3345
### Fixed

app/Contracts/Repository/DatabaseRepositoryInterface.php

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,35 @@
99

1010
namespace Pterodactyl\Contracts\Repository;
1111

12+
use Illuminate\Support\Collection;
13+
1214
interface DatabaseRepositoryInterface extends RepositoryInterface
1315
{
16+
const DEFAULT_CONNECTION_NAME = 'dynamic';
17+
18+
/**
19+
* Set the connection name to execute statements against.
20+
*
21+
* @param string $connection
22+
* @return $this
23+
*/
24+
public function setConnection(string $connection);
25+
26+
/**
27+
* Return the connection to execute statements aganist.
28+
*
29+
* @return string
30+
*/
31+
public function getConnection(): string;
32+
33+
/**
34+
* Return all of the databases belonging to a server.
35+
*
36+
* @param int $server
37+
* @return \Illuminate\Support\Collection
38+
*/
39+
public function getDatabasesForServer(int $server): Collection;
40+
1441
/**
1542
* Create a new database if it does not already exist on the host with
1643
* the provided details.
@@ -26,58 +53,52 @@ public function createIfNotExists(array $data);
2653
/**
2754
* Create a new database on a given connection.
2855
*
29-
* @param string $database
30-
* @param null|string $connection
56+
* @param string $database
3157
* @return bool
3258
*/
33-
public function createDatabase($database, $connection = null);
59+
public function createDatabase($database);
3460

3561
/**
3662
* Create a new database user on a given connection.
3763
*
38-
* @param string $username
39-
* @param string $remote
40-
* @param string $password
41-
* @param null|string $connection
64+
* @param string $username
65+
* @param string $remote
66+
* @param string $password
4267
* @return bool
4368
*/
44-
public function createUser($username, $remote, $password, $connection = null);
69+
public function createUser($username, $remote, $password);
4570

4671
/**
4772
* Give a specific user access to a given database.
4873
*
49-
* @param string $database
50-
* @param string $username
51-
* @param string $remote
52-
* @param null|string $connection
74+
* @param string $database
75+
* @param string $username
76+
* @param string $remote
5377
* @return bool
5478
*/
55-
public function assignUserToDatabase($database, $username, $remote, $connection = null);
79+
public function assignUserToDatabase($database, $username, $remote);
5680

5781
/**
5882
* Flush the privileges for a given connection.
5983
*
60-
* @param null|string $connection
6184
* @return mixed
6285
*/
63-
public function flush($connection = null);
86+
public function flush();
6487

6588
/**
6689
* Drop a given database on a specific connection.
6790
*
68-
* @param string $database
69-
* @param null|string $connection
91+
* @param string $database
7092
* @return bool
7193
*/
72-
public function dropDatabase($database, $connection = null);
94+
public function dropDatabase($database);
7395

7496
/**
7597
* Drop a given user on a specific connection.
7698
*
77-
* @param string $username
78-
* @param string $remote
79-
* @param null|string $connection
99+
* @param string $username
100+
* @param string $remote
80101
* @return mixed
81102
*/
82-
public function dropUser($username, $remote, $connection = null);
103+
public function dropUser($username, $remote);
83104
}

app/Contracts/Repository/EggVariableRepositoryInterface.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@
99

1010
namespace Pterodactyl\Contracts\Repository;
1111

12+
use Illuminate\Support\Collection;
13+
1214
interface EggVariableRepositoryInterface extends RepositoryInterface
1315
{
16+
/**
17+
* Return editable variables for a given egg. Editable variables must be set to
18+
* user viewable in order to be picked up by this function.
19+
*
20+
* @param int $egg
21+
* @return \Illuminate\Support\Collection
22+
*/
23+
public function getEditableVariables(int $egg): Collection;
1424
}

app/Contracts/Repository/ServerRepositoryInterface.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace Pterodactyl\Contracts\Repository;
1111

12+
use Pterodactyl\Models\Server;
1213
use Pterodactyl\Contracts\Repository\Attributes\SearchableInterface;
1314

1415
interface ServerRepositoryInterface extends RepositoryInterface, SearchableInterface
@@ -53,14 +54,26 @@ public function findWithVariables($id);
5354
public function getVariablesWithValues($id, $returnAsObject = false);
5455

5556
/**
56-
* Return enough data to be used for the creation of a server via the daemon.
57+
* Get the primary allocation for a given server. If a model is passed into
58+
* the function, load the allocation relationship onto it. Otherwise, find and
59+
* return the server from the database.
5760
*
58-
* @param int $id
59-
* @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model
61+
* @param int|\Pterodactyl\Models\Server $server
62+
* @param bool $refresh
63+
* @return \Pterodactyl\Models\Server
6064
*
6165
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
6266
*/
63-
public function getDataForCreation($id);
67+
public function getPrimaryAllocation($server, bool $refresh = false): Server;
68+
69+
/**
70+
* Return enough data to be used for the creation of a server via the daemon.
71+
*
72+
* @param \Pterodactyl\Models\Server $server
73+
* @param bool $refresh
74+
* @return \Pterodactyl\Models\Server
75+
*/
76+
public function getDataForCreation(Server $server, bool $refresh = false): Server;
6477

6578
/**
6679
* Return a server as well as associated databases and their hosts.

app/Exceptions/DisplayException.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ class DisplayException extends PterodactylException
2828
* @param string $message
2929
* @param Throwable|null $previous
3030
* @param string $level
31-
* @internal param mixed $log
31+
* @param int $code
3232
*/
33-
public function __construct($message, Throwable $previous = null, $level = self::LEVEL_ERROR)
33+
public function __construct($message, Throwable $previous = null, $level = self::LEVEL_ERROR, $code = 0)
3434
{
3535
$this->level = $level;
3636

3737
if (! is_null($previous)) {
3838
Log::{$level}($previous);
3939
}
4040

41-
parent::__construct($message);
41+
parent::__construct($message, $code, $previous);
4242
}
4343

4444
/**
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace Pterodactyl\Exceptions\Service\Allocation;
4+
5+
use Pterodactyl\Exceptions\PterodactylException;
6+
7+
class AllocationDoesNotBelongToServerException extends PterodactylException
8+
{
9+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
3+
namespace Pterodactyl\Http\Controllers\API\Remote;
4+
5+
use Illuminate\Http\Request;
6+
use Illuminate\Http\JsonResponse;
7+
use Illuminate\Auth\AuthenticationException;
8+
use Pterodactyl\Http\Controllers\Controller;
9+
use Illuminate\Foundation\Auth\ThrottlesLogins;
10+
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
11+
use Pterodactyl\Services\Sftp\AuthenticateUsingPasswordService;
12+
use Pterodactyl\Http\Requests\API\Remote\SftpAuthenticationFormRequest;
13+
14+
class SftpController extends Controller
15+
{
16+
use ThrottlesLogins;
17+
18+
/**
19+
* @var \Pterodactyl\Services\Sftp\AuthenticateUsingPasswordService
20+
*/
21+
private $authenticationService;
22+
23+
/**
24+
* SftpController constructor.
25+
*
26+
* @param \Pterodactyl\Services\Sftp\AuthenticateUsingPasswordService $authenticationService
27+
*/
28+
public function __construct(AuthenticateUsingPasswordService $authenticationService)
29+
{
30+
$this->authenticationService = $authenticationService;
31+
}
32+
33+
/**
34+
* Authenticate a set of credentials and return the associated server details
35+
* for a SFTP connection on the daemon.
36+
*
37+
* @param \Pterodactyl\Http\Requests\API\Remote\SftpAuthenticationFormRequest $request
38+
* @return \Illuminate\Http\JsonResponse
39+
*
40+
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
41+
*/
42+
public function index(SftpAuthenticationFormRequest $request): JsonResponse
43+
{
44+
$connection = explode('.', $request->input('username'));
45+
$this->incrementLoginAttempts($request);
46+
47+
if ($this->hasTooManyLoginAttempts($request)) {
48+
return response()->json([
49+
'error' => 'Logins throttled.',
50+
], 429);
51+
}
52+
53+
try {
54+
$data = $this->authenticationService->handle(
55+
array_get($connection, 0),
56+
$request->input('password'),
57+
object_get($request->attributes->get('node'), 'id', 0),
58+
array_get($connection, 1)
59+
);
60+
61+
$this->clearLoginAttempts($request);
62+
} catch (AuthenticationException $exception) {
63+
return response()->json([
64+
'error' => 'Invalid credentials.',
65+
], 403);
66+
} catch (RecordNotFoundException $exception) {
67+
return response()->json([
68+
'error' => 'Invalid server.',
69+
], 404);
70+
}
71+
72+
return response()->json($data);
73+
}
74+
75+
/**
76+
* Get the throttle key for the given request.
77+
*
78+
* @param \Illuminate\Http\Request $request
79+
* @return string
80+
*/
81+
protected function throttleKey(Request $request)
82+
{
83+
return strtolower(array_get(explode('.', $request->input('username')), 0) . '|' . $request->ip());
84+
}
85+
}

0 commit comments

Comments
 (0)