2015-12-06 18:58:49 +00:00
|
|
|
<?php
|
2016-12-07 22:46:38 +00:00
|
|
|
|
2015-12-06 18:58:49 +00:00
|
|
|
namespace Pterodactyl\Models;
|
|
|
|
|
2017-01-25 00:15:03 +00:00
|
|
|
use Illuminate\Notifications\Notifiable;
|
2019-09-05 04:21:07 +00:00
|
|
|
use Pterodactyl\Models\Traits\Searchable;
|
2015-12-06 18:58:49 +00:00
|
|
|
|
2019-09-05 04:00:34 +00:00
|
|
|
class Node extends Validable
|
2015-12-06 18:58:49 +00:00
|
|
|
{
|
2019-09-05 04:21:07 +00:00
|
|
|
use Notifiable, Searchable;
|
2017-01-25 00:15:03 +00:00
|
|
|
|
2018-01-26 03:26:06 +00:00
|
|
|
/**
|
|
|
|
* The resource name for this model when it is transformed into an
|
|
|
|
* API representation using fractal.
|
|
|
|
*/
|
|
|
|
const RESOURCE_NAME = 'node';
|
|
|
|
|
2017-10-27 04:49:54 +00:00
|
|
|
const DAEMON_SECRET_LENGTH = 36;
|
|
|
|
|
2015-12-06 18:58:49 +00:00
|
|
|
/**
|
|
|
|
* The table associated with the model.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $table = 'nodes';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The attributes excluded from the model's JSON form.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $hidden = ['daemonSecret'];
|
|
|
|
|
2017-08-05 22:20:07 +00:00
|
|
|
/**
|
|
|
|
* Cast values to correct type.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $casts = [
|
|
|
|
'location_id' => 'integer',
|
|
|
|
'memory' => 'integer',
|
|
|
|
'disk' => 'integer',
|
|
|
|
'daemonListen' => 'integer',
|
|
|
|
'daemonSFTP' => 'integer',
|
|
|
|
'behind_proxy' => 'boolean',
|
2018-03-26 18:56:58 +00:00
|
|
|
'public' => 'boolean',
|
2018-05-31 14:34:35 +00:00
|
|
|
'maintenance_mode' => 'boolean',
|
2017-08-05 22:20:07 +00:00
|
|
|
];
|
2016-01-27 03:17:51 +00:00
|
|
|
|
2016-01-05 04:59:45 +00:00
|
|
|
/**
|
2017-02-03 20:19:14 +00:00
|
|
|
* Fields that are mass assignable.
|
2016-01-05 04:59:45 +00:00
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2017-02-03 20:19:14 +00:00
|
|
|
protected $fillable = [
|
2017-02-11 01:26:38 +00:00
|
|
|
'public', 'name', 'location_id',
|
2017-04-28 02:52:37 +00:00
|
|
|
'fqdn', 'scheme', 'behind_proxy',
|
|
|
|
'memory', 'memory_overallocate', 'disk',
|
2017-02-11 01:26:38 +00:00
|
|
|
'disk_overallocate', 'upload_size',
|
|
|
|
'daemonSecret', 'daemonBase',
|
|
|
|
'daemonSFTP', 'daemonListen',
|
2018-05-31 14:34:35 +00:00
|
|
|
'description', 'maintenance_mode',
|
2017-02-03 20:19:14 +00:00
|
|
|
];
|
2016-01-05 04:59:45 +00:00
|
|
|
|
2017-03-19 23:36:50 +00:00
|
|
|
/**
|
|
|
|
* Fields that are searchable.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2017-08-05 22:20:07 +00:00
|
|
|
protected $searchableColumns = [
|
|
|
|
'name' => 10,
|
|
|
|
'fqdn' => 8,
|
|
|
|
'location.short' => 4,
|
|
|
|
'location.long' => 4,
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2019-09-05 05:19:57 +00:00
|
|
|
public static $validationRules = [
|
|
|
|
'name' => 'required|regex:/^([\w .-]{1,100})$/',
|
2018-03-26 18:57:24 +00:00
|
|
|
'description' => 'string',
|
2019-09-05 05:19:57 +00:00
|
|
|
'location_id' => 'required|exists:locations,id',
|
2017-08-05 22:20:07 +00:00
|
|
|
'public' => 'boolean',
|
2019-09-05 05:19:57 +00:00
|
|
|
'fqdn' => 'required|string',
|
|
|
|
'scheme' => 'required',
|
2017-08-05 22:20:07 +00:00
|
|
|
'behind_proxy' => 'boolean',
|
2019-09-05 05:19:57 +00:00
|
|
|
'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',
|
2018-05-31 14:34:35 +00:00
|
|
|
'maintenance_mode' => 'boolean',
|
2018-09-03 21:53:58 +00:00
|
|
|
'upload_size' => 'int|between:1,1024',
|
2017-08-05 22:20:07 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Default values for specific columns that are generally not changed on base installs.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $attributes = [
|
|
|
|
'public' => true,
|
|
|
|
'behind_proxy' => false,
|
|
|
|
'memory_overallocate' => 0,
|
|
|
|
'disk_overallocate' => 0,
|
|
|
|
'daemonBase' => '/srv/daemon-data',
|
|
|
|
'daemonSFTP' => 2022,
|
|
|
|
'daemonListen' => 8080,
|
2018-05-31 14:34:35 +00:00
|
|
|
'maintenance_mode' => false,
|
2017-08-05 22:20:07 +00:00
|
|
|
];
|
2017-03-03 22:30:39 +00:00
|
|
|
|
2018-07-21 06:45:07 +00:00
|
|
|
/**
|
|
|
|
* Get the connection address to use when making calls to this node.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getConnectionAddress(): string
|
|
|
|
{
|
|
|
|
return sprintf('%s://%s:%s', $this->scheme, $this->fqdn, $this->daemonListen);
|
|
|
|
}
|
|
|
|
|
2017-01-07 17:06:09 +00:00
|
|
|
/**
|
2017-01-07 17:39:41 +00:00
|
|
|
* Returns the configuration in JSON format.
|
2017-01-07 17:06:09 +00:00
|
|
|
*
|
2017-08-22 03:10:48 +00:00
|
|
|
* @param bool $pretty
|
2017-03-19 23:36:50 +00:00
|
|
|
* @return string
|
2017-01-07 17:06:09 +00:00
|
|
|
*/
|
2017-01-07 17:39:41 +00:00
|
|
|
public function getConfigurationAsJson($pretty = false)
|
|
|
|
{
|
|
|
|
$config = [
|
|
|
|
'web' => [
|
2017-01-07 17:06:09 +00:00
|
|
|
'host' => '0.0.0.0',
|
|
|
|
'listen' => $this->daemonListen,
|
2017-01-07 17:39:41 +00:00
|
|
|
'ssl' => [
|
2017-04-28 02:52:37 +00:00
|
|
|
'enabled' => (! $this->behind_proxy && $this->scheme === 'https'),
|
2017-01-23 00:14:55 +00:00
|
|
|
'certificate' => '/etc/letsencrypt/live/' . $this->fqdn . '/fullchain.pem',
|
|
|
|
'key' => '/etc/letsencrypt/live/' . $this->fqdn . '/privkey.pem',
|
2017-01-07 17:39:41 +00:00
|
|
|
],
|
|
|
|
],
|
|
|
|
'docker' => [
|
2017-10-25 04:35:25 +00:00
|
|
|
'container' => [
|
|
|
|
'user' => null,
|
|
|
|
],
|
|
|
|
'network' => [
|
|
|
|
'name' => 'pterodactyl_nw',
|
|
|
|
],
|
2017-01-07 17:06:09 +00:00
|
|
|
'socket' => '/var/run/docker.sock',
|
2017-01-07 17:39:41 +00:00
|
|
|
'autoupdate_images' => true,
|
|
|
|
],
|
2018-02-17 22:21:37 +00:00
|
|
|
'filesystem' => [
|
|
|
|
'server_logs' => '/tmp/pterodactyl',
|
|
|
|
],
|
2018-02-19 02:39:43 +00:00
|
|
|
'internals' => [
|
|
|
|
'disk_use_seconds' => 30,
|
|
|
|
'set_permissions_on_boot' => true,
|
|
|
|
'throttle' => [
|
2018-02-24 22:00:53 +00:00
|
|
|
'enabled' => true,
|
2018-02-19 02:39:43 +00:00
|
|
|
'kill_at_count' => 5,
|
|
|
|
'decay' => 10,
|
2018-03-09 05:35:36 +00:00
|
|
|
'lines' => 1000,
|
2018-02-19 02:39:43 +00:00
|
|
|
'check_interval_ms' => 100,
|
|
|
|
],
|
|
|
|
],
|
2017-01-07 17:39:41 +00:00
|
|
|
'sftp' => [
|
2017-01-07 17:06:09 +00:00
|
|
|
'path' => $this->daemonBase,
|
2017-10-25 04:35:25 +00:00
|
|
|
'ip' => '0.0.0.0',
|
2017-01-07 17:06:09 +00:00
|
|
|
'port' => $this->daemonSFTP,
|
2017-10-25 04:35:25 +00:00
|
|
|
'keypair' => [
|
|
|
|
'bits' => 2048,
|
|
|
|
'e' => 65537,
|
|
|
|
],
|
2017-01-07 17:39:41 +00:00
|
|
|
],
|
|
|
|
'logger' => [
|
2017-01-07 17:06:09 +00:00
|
|
|
'path' => 'logs/',
|
|
|
|
'src' => false,
|
|
|
|
'level' => 'info',
|
|
|
|
'period' => '1d',
|
2017-01-07 17:39:41 +00:00
|
|
|
'count' => 3,
|
|
|
|
],
|
|
|
|
'remote' => [
|
2017-04-28 02:52:37 +00:00
|
|
|
'base' => route('index'),
|
2017-01-07 17:39:41 +00:00
|
|
|
],
|
|
|
|
'uploads' => [
|
|
|
|
'size_limit' => $this->upload_size,
|
|
|
|
],
|
|
|
|
'keys' => [$this->daemonSecret],
|
|
|
|
];
|
2017-01-07 17:06:09 +00:00
|
|
|
|
2017-02-16 18:31:25 +00:00
|
|
|
return json_encode($config, ($pretty) ? JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT : JSON_UNESCAPED_SLASHES);
|
2017-01-07 17:06:09 +00:00
|
|
|
}
|
2017-02-03 20:19:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the location associated with a node.
|
|
|
|
*
|
2017-02-05 23:00:39 +00:00
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
2017-02-03 20:19:14 +00:00
|
|
|
*/
|
|
|
|
public function location()
|
|
|
|
{
|
2017-02-05 23:00:39 +00:00
|
|
|
return $this->belongsTo(Location::class);
|
2017-02-03 20:19:14 +00:00
|
|
|
}
|
2017-02-03 21:50:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the servers associated with a node.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
|
|
*/
|
|
|
|
public function servers()
|
|
|
|
{
|
|
|
|
return $this->hasMany(Server::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the allocations associated with a node.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
|
|
*/
|
|
|
|
public function allocations()
|
|
|
|
{
|
|
|
|
return $this->hasMany(Allocation::class);
|
|
|
|
}
|
2018-04-08 20:36:40 +00:00
|
|
|
}
|