nodes: rename port columns, add public_ port columns
This commit is contained in:
parent
b7ee2195d7
commit
5f56ff0fed
9 changed files with 116 additions and 45 deletions
|
@ -21,6 +21,10 @@ class StoreNodeRequest extends ApplicationApiRequest
|
|||
'name',
|
||||
'location_id',
|
||||
'fqdn',
|
||||
'listen_port_http',
|
||||
'listen_port_sftp',
|
||||
'public_port_http',
|
||||
'public_port_sftp',
|
||||
'scheme',
|
||||
'behind_proxy',
|
||||
'memory',
|
||||
|
@ -28,12 +32,8 @@ class StoreNodeRequest extends ApplicationApiRequest
|
|||
'disk',
|
||||
'disk_overallocate',
|
||||
'upload_size',
|
||||
'daemonListen',
|
||||
'daemonSFTP',
|
||||
'daemonBase',
|
||||
'daemon_base',
|
||||
])->mapWithKeys(function ($value, $key) {
|
||||
$key = ($key === 'daemonSFTP') ? 'daemonSftp' : $key;
|
||||
|
||||
return [snake_case($key) => $value];
|
||||
})->toArray();
|
||||
}
|
||||
|
@ -62,11 +62,7 @@ class StoreNodeRequest extends ApplicationApiRequest
|
|||
public function validated()
|
||||
{
|
||||
$response = parent::validated();
|
||||
$response['daemonListen'] = $response['daemon_listen'];
|
||||
$response['daemonSFTP'] = $response['daemon_sftp'];
|
||||
$response['daemonBase'] = $response['daemon_base'] ?? (new Node())->getAttribute('daemonBase');
|
||||
|
||||
unset($response['daemon_base'], $response['daemon_listen'], $response['daemon_sftp']);
|
||||
$response['daemon_base'] = $response['daemon_base'] ?? (new Node())->getAttribute('daemon_base');
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Pterodactyl\Models;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
|
@ -14,7 +15,12 @@ use Illuminate\Contracts\Encryption\Encrypter;
|
|||
* @property string $name
|
||||
* @property string|null $description
|
||||
* @property int $location_id
|
||||
* @property int|null $database_host_id
|
||||
* @property string $fqdn
|
||||
* @property int $listen_port_http
|
||||
* @property int $public_port_http
|
||||
* @property int $listen_port_sftp
|
||||
* @property int $public_port_sftp
|
||||
* @property string $scheme
|
||||
* @property bool $behind_proxy
|
||||
* @property bool $maintenance_mode
|
||||
|
@ -25,10 +31,7 @@ use Illuminate\Contracts\Encryption\Encrypter;
|
|||
* @property int $upload_size
|
||||
* @property string $daemon_token_id
|
||||
* @property string $daemon_token
|
||||
* @property int $daemonListen
|
||||
* @property int $daemonSFTP
|
||||
* @property string $daemonBase
|
||||
* @property int|null $database_host_id
|
||||
* @property string $daemon_base
|
||||
* @property \Carbon\Carbon $created_at
|
||||
* @property \Carbon\Carbon $updated_at
|
||||
* @property \Pterodactyl\Models\Location $location
|
||||
|
@ -71,10 +74,13 @@ class Node extends Model
|
|||
*/
|
||||
protected $casts = [
|
||||
'location_id' => 'integer',
|
||||
'database_host_id' => 'integer',
|
||||
'listen_port_http' => 'integer',
|
||||
'listen_port_sftp' => 'integer',
|
||||
'public_port_http' => 'integer',
|
||||
'public_port_sftp' => 'integer',
|
||||
'memory' => 'integer',
|
||||
'disk' => 'integer',
|
||||
'daemonListen' => 'integer',
|
||||
'daemonSFTP' => 'integer',
|
||||
'behind_proxy' => 'boolean',
|
||||
'public' => 'boolean',
|
||||
'maintenance_mode' => 'boolean',
|
||||
|
@ -86,11 +92,11 @@ class Node extends Model
|
|||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'public', 'name', 'location_id',
|
||||
'public', 'name', 'location_id', 'database_host_id',
|
||||
'listen_port_http', 'listen_port_sftp', 'public_port_http', 'public_port_sftp',
|
||||
'fqdn', 'scheme', 'behind_proxy',
|
||||
'memory', 'memory_overallocate', 'disk',
|
||||
'disk_overallocate', 'upload_size', 'daemonBase',
|
||||
'daemonSFTP', 'daemonListen',
|
||||
'disk_overallocate', 'upload_size', 'daemon_base',
|
||||
'description', 'maintenance_mode',
|
||||
];
|
||||
|
||||
|
@ -101,17 +107,20 @@ class Node extends Model
|
|||
'name' => 'required|regex:/^([\w .-]{1,100})$/',
|
||||
'description' => 'string|nullable',
|
||||
'location_id' => 'required|exists:locations,id',
|
||||
'database_host_id' => 'required|exists:database_hosts,id',
|
||||
'public' => 'boolean',
|
||||
'fqdn' => 'required|string',
|
||||
'listen_port_http' => 'required|numeric|between:1,65535',
|
||||
'listen_port_sftp' => 'required|numeric|between:1,65535',
|
||||
'public_port_http' => 'required|numeric|between:1,65535',
|
||||
'public_port_sftp' => 'required|numeric|between:1,65535',
|
||||
'scheme' => 'required',
|
||||
'behind_proxy' => 'boolean',
|
||||
'memory' => 'required|numeric|min:1',
|
||||
'memory_overallocate' => 'required|numeric|min:-1',
|
||||
'disk' => 'required|numeric|min:1',
|
||||
'disk_overallocate' => 'required|numeric|min:-1',
|
||||
'daemonBase' => 'sometimes|required|regex:/^([\/][\d\w.\-\/]+)$/',
|
||||
'daemonSFTP' => 'required|numeric|between:1,65535',
|
||||
'daemonListen' => 'required|numeric|between:1,65535',
|
||||
'daemon_base' => 'sometimes|required|regex:/^([\/][\d\w.\-\/]+)$/',
|
||||
'maintenance_mode' => 'boolean',
|
||||
'upload_size' => 'int|between:1,1024',
|
||||
];
|
||||
|
@ -122,13 +131,15 @@ class Node extends Model
|
|||
* @var array
|
||||
*/
|
||||
protected $attributes = [
|
||||
'listen_port_http' => 8080,
|
||||
'listen_port_sftp' => 2022,
|
||||
'public_port_http' => 8080,
|
||||
'public_port_sftp' => 2022,
|
||||
'public' => true,
|
||||
'behind_proxy' => false,
|
||||
'memory_overallocate' => 0,
|
||||
'disk_overallocate' => 0,
|
||||
'daemonBase' => '/var/lib/pterodactyl/volumes',
|
||||
'daemonSFTP' => 2022,
|
||||
'daemonListen' => 8080,
|
||||
'daemon_base' => '/var/lib/pterodactyl/volumes',
|
||||
'maintenance_mode' => false,
|
||||
];
|
||||
|
||||
|
@ -137,13 +148,14 @@ class Node extends Model
|
|||
*/
|
||||
public function getConnectionAddress(): string
|
||||
{
|
||||
return sprintf('%s://%s:%s', $this->scheme, $this->fqdn, $this->daemonListen);
|
||||
return sprintf('%s://%s:%s', $this->scheme, $this->fqdn, $this->public_port_http);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the configuration as an array.
|
||||
*
|
||||
* @return array
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function getConfiguration()
|
||||
{
|
||||
|
@ -154,18 +166,18 @@ class Node extends Model
|
|||
'token' => Container::getInstance()->make(Encrypter::class)->decrypt($this->daemon_token),
|
||||
'api' => [
|
||||
'host' => '0.0.0.0',
|
||||
'port' => $this->daemonListen,
|
||||
'port' => $this->listen_port_http,
|
||||
'ssl' => [
|
||||
'enabled' => (!$this->behind_proxy && $this->scheme === 'https'),
|
||||
'cert' => '/etc/letsencrypt/live/' . $this->fqdn . '/fullchain.pem',
|
||||
'key' => '/etc/letsencrypt/live/' . $this->fqdn . '/privkey.pem',
|
||||
'cert' => '/etc/letsencrypt/live/' . Str::lower($this->fqdn) . '/fullchain.pem',
|
||||
'key' => '/etc/letsencrypt/live/' . Str::lower($this->fqdn) . '/privkey.pem',
|
||||
],
|
||||
'upload_limit' => $this->upload_size,
|
||||
],
|
||||
'system' => [
|
||||
'data' => $this->daemonBase,
|
||||
'data' => $this->daemon_base,
|
||||
'sftp' => [
|
||||
'bind_port' => $this->daemonSFTP,
|
||||
'bind_port' => $this->listen_port_sftp,
|
||||
],
|
||||
],
|
||||
'allowed_mounts' => $this->mounts->pluck('source')->toArray(),
|
||||
|
@ -177,6 +189,7 @@ class Node extends Model
|
|||
* Returns the configuration in Yaml format.
|
||||
*
|
||||
* @return string
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function getYamlConfiguration()
|
||||
{
|
||||
|
@ -187,6 +200,7 @@ class Node extends Model
|
|||
* Returns the configuration in JSON format.
|
||||
*
|
||||
* @return string
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function getJsonConfiguration(bool $pretty = false)
|
||||
{
|
||||
|
@ -195,6 +209,8 @@ class Node extends Model
|
|||
|
||||
/**
|
||||
* Helper function to return the decrypted key for a node.
|
||||
*
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function getDecryptedKey(): string
|
||||
{
|
||||
|
|
|
@ -144,7 +144,7 @@ class NodeRepository extends EloquentRepository implements NodeRepositoryInterfa
|
|||
public function getNodeWithResourceUsage(int $node_id): Node
|
||||
{
|
||||
$instance = $this->getBuilder()
|
||||
->select(['nodes.id', 'nodes.fqdn', 'nodes.scheme', 'nodes.daemon_token', 'nodes.daemonListen', 'nodes.memory', 'nodes.disk', 'nodes.memory_overallocate', 'nodes.disk_overallocate'])
|
||||
->select(['nodes.id', 'nodes.fqdn', 'nodes.public_port_http', 'nodes.scheme', 'nodes.daemon_token', 'nodes.memory', 'nodes.disk', 'nodes.memory_overallocate', 'nodes.disk_overallocate'])
|
||||
->selectRaw('IFNULL(SUM(servers.memory), 0) as sum_memory, IFNULL(SUM(servers.disk), 0) as sum_disk')
|
||||
->leftJoin('servers', 'servers.node_id', '=', 'nodes.id')
|
||||
->where('nodes.id', $node_id);
|
||||
|
|
|
@ -28,13 +28,7 @@ class NodeTransformer extends BaseTransformer
|
|||
*/
|
||||
public function transform(Node $model): array
|
||||
{
|
||||
$response = collect($model->toArray())->mapWithKeys(function ($value, $key) {
|
||||
// I messed up early in 2016 when I named this column as poorly
|
||||
// as I did. This is the tragic result of my mistakes.
|
||||
$key = ($key === 'daemonSFTP') ? 'daemonSftp' : $key;
|
||||
|
||||
return [snake_case($key) => $value];
|
||||
})->toArray();
|
||||
$response = $model->toArray();
|
||||
|
||||
$response[$model->getUpdatedAtColumn()] = $this->formatTimestamp($model->updated_at);
|
||||
$response[$model->getCreatedAtColumn()] = $this->formatTimestamp($model->created_at);
|
||||
|
|
|
@ -46,7 +46,7 @@ class ServerTransformer extends BaseClientTransformer
|
|||
'node' => $server->node->name,
|
||||
'sftp_details' => [
|
||||
'ip' => $server->node->fqdn,
|
||||
'port' => $server->node->daemonSFTP,
|
||||
'port' => $server->node->public_port_sftp,
|
||||
],
|
||||
'description' => $server->description,
|
||||
'limits' => [
|
||||
|
|
|
@ -27,6 +27,10 @@ class NodeFactory extends Factory
|
|||
'public' => true,
|
||||
'name' => $this->faker->firstName,
|
||||
'fqdn' => $this->faker->ipv4,
|
||||
'listen_port_http' => 8080,
|
||||
'listen_port_sftp' => 2022,
|
||||
'public_port_http' => 8080,
|
||||
'public_port_sftp' => 2022,
|
||||
'scheme' => 'http',
|
||||
'behind_proxy' => false,
|
||||
'memory' => 1024,
|
||||
|
@ -36,9 +40,7 @@ class NodeFactory extends Factory
|
|||
'upload_size' => 100,
|
||||
'daemon_token_id' => Str::random(Node::DAEMON_TOKEN_ID_LENGTH),
|
||||
'daemon_token' => Crypt::encrypt(Str::random(Node::DAEMON_TOKEN_LENGTH)),
|
||||
'daemonListen' => 8080,
|
||||
'daemonSFTP' => 2022,
|
||||
'daemonBase' => '/var/lib/pterodactyl/volumes',
|
||||
'daemon_base' => '/var/lib/pterodactyl/volumes',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ class AddNodes extends Migration
|
|||
$table->mediumInteger('disk_overallocate')->unsigned()->nullable();
|
||||
$table->char('daemonSecret', 36)->unique();
|
||||
$table->smallInteger('daemonListen')->unsigned()->default(8080);
|
||||
$table->smallInteger('daemonSFTP')->unsgined()->default(2022);
|
||||
$table->smallInteger('daemonSFTP')->unsigned()->default(2022);
|
||||
$table->string('daemonBase')->default('/home/daemon-files');
|
||||
$table->timestamps();
|
||||
});
|
||||
|
|
|
@ -19,7 +19,7 @@ class AddDatabaseHostIdColumnToNodesTable extends Migration
|
|||
});
|
||||
|
||||
Schema::table('nodes', function (Blueprint $table) {
|
||||
$table->integer('database_host_id')->nullable()->unsigned()->after('daemonBase');
|
||||
$table->integer('database_host_id')->nullable()->unsigned()->after('location_id');
|
||||
$table->index('database_host_id')->nullable();
|
||||
$table->foreign('database_host_id')->references('id')->on('database_hosts')->onDelete('set null');
|
||||
});
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class ChangePortColumnsOnNodesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('nodes', function (Blueprint $table) {
|
||||
$table->renameColumn('daemonListen', 'listen_port_http');
|
||||
$table->renameColumn('daemonSFTP', 'listen_port_sftp');
|
||||
$table->renameColumn('daemonBase', 'daemon_base');
|
||||
});
|
||||
|
||||
Schema::table('nodes', function (Blueprint $table) {
|
||||
$table->integer('listen_port_http')->unsigned()->default(8080)->after('fqdn')->change();
|
||||
$table->integer('listen_port_sftp')->unsigned()->default(2022)->after('listen_port_sftp')->change();
|
||||
|
||||
$table->integer('public_port_http')->unsigned()->default(8080)->after('listen_port_http');
|
||||
$table->integer('public_port_sftp')->unsigned()->default(2022)->after('listen_port_sftp');
|
||||
});
|
||||
|
||||
DB::transaction(function () {
|
||||
foreach (DB::select('SELECT id, listen_port_http, listen_port_sftp FROM nodes') as $datum) {
|
||||
DB::update('UPDATE nodes SET public_port_http = ?, public_port_sftp = ? WHERE id = ?', [
|
||||
$datum->listen_port_http,
|
||||
$datum->listen_port_sftp,
|
||||
$datum->id,
|
||||
]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('nodes', function (Blueprint $table) {
|
||||
$table->renameColumn('listen_port_http', 'daemonListen');
|
||||
$table->renameColumn('listen_port_sftp', 'daemonSFTP');
|
||||
$table->renameColumn('daemon_base', 'daemonBase');
|
||||
|
||||
$table->dropColumn('public_port_http');
|
||||
$table->dropColumn('public_port_sftp');
|
||||
});
|
||||
|
||||
Schema::table('nodes', function (Blueprint $table) {
|
||||
$table->smallInteger('daemonListen')->unsigned()->default(8080)->after('daemon_token')->change();
|
||||
$table->smallInteger('daemonSFTP')->unsigned()->default(2022)->after('daemonListen')->change();
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue