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-04-09 17:15:15 +00:00
|
|
|
use Schema;
|
2017-07-20 01:49:41 +00:00
|
|
|
use Sofa\Eloquence\Eloquence;
|
|
|
|
use Sofa\Eloquence\Validable;
|
2015-12-06 18:58:49 +00:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2017-01-25 00:15:03 +00:00
|
|
|
use Illuminate\Notifications\Notifiable;
|
2017-09-24 01:45:25 +00:00
|
|
|
use Znck\Eloquent\Traits\BelongsToThrough;
|
2017-08-12 20:29:01 +00:00
|
|
|
use Sofa\Eloquence\Contracts\CleansAttributes;
|
2017-07-20 01:49:41 +00:00
|
|
|
use Sofa\Eloquence\Contracts\Validable as ValidableContract;
|
2015-12-06 18:58:49 +00:00
|
|
|
|
2017-08-12 20:29:01 +00:00
|
|
|
class Server extends Model implements CleansAttributes, ValidableContract
|
2015-12-06 18:58:49 +00:00
|
|
|
{
|
2017-09-24 01:45:25 +00:00
|
|
|
use BelongsToThrough, Eloquence, Notifiable, Validable;
|
2016-10-28 00:05:29 +00:00
|
|
|
|
2018-01-20 03:47:06 +00:00
|
|
|
/**
|
|
|
|
* The resource name for this model when it is transformed into an
|
|
|
|
* API representation using fractal.
|
|
|
|
*/
|
|
|
|
const RESOURCE_NAME = 'server';
|
|
|
|
|
2015-12-06 18:58:49 +00:00
|
|
|
/**
|
|
|
|
* The table associated with the model.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $table = 'servers';
|
|
|
|
|
2016-10-28 00:05:29 +00:00
|
|
|
/**
|
|
|
|
* The attributes that should be mutated to dates.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2017-10-25 04:35:25 +00:00
|
|
|
protected $dates = [self::CREATED_AT, self::UPDATED_AT, 'deleted_at'];
|
2015-12-06 18:58:49 +00:00
|
|
|
|
2017-09-25 02:12:30 +00:00
|
|
|
/**
|
|
|
|
* Always eager load these relationships on the model.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $with = ['key'];
|
|
|
|
|
2015-12-15 20:08:41 +00:00
|
|
|
/**
|
|
|
|
* Fields that are not mass assignable.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2017-10-25 04:35:25 +00:00
|
|
|
protected $guarded = ['id', 'installed', self::CREATED_AT, self::UPDATED_AT, 'deleted_at'];
|
2015-12-15 20:08:41 +00:00
|
|
|
|
2017-08-05 22:20:07 +00:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2017-07-20 01:49:41 +00:00
|
|
|
protected static $applicationRules = [
|
2018-02-24 17:57:12 +00:00
|
|
|
'external_id' => 'sometimes',
|
2017-07-20 01:49:41 +00:00
|
|
|
'owner_id' => 'required',
|
|
|
|
'name' => 'required',
|
|
|
|
'memory' => 'required',
|
|
|
|
'swap' => 'required',
|
|
|
|
'io' => 'required',
|
|
|
|
'cpu' => 'required',
|
|
|
|
'disk' => 'required',
|
2017-10-07 04:57:53 +00:00
|
|
|
'nest_id' => 'required',
|
|
|
|
'egg_id' => 'required',
|
2017-09-21 23:03:29 +00:00
|
|
|
'node_id' => 'required',
|
|
|
|
'allocation_id' => 'required',
|
2017-07-20 01:49:41 +00:00
|
|
|
'pack_id' => 'sometimes',
|
|
|
|
'skip_scripts' => 'sometimes',
|
2018-01-28 23:14:14 +00:00
|
|
|
'image' => 'required',
|
|
|
|
'startup' => 'required',
|
2018-03-02 02:08:27 +00:00
|
|
|
'database_limit' => 'present',
|
|
|
|
'allocation_limit' => 'present',
|
2017-07-20 01:49:41 +00:00
|
|
|
];
|
|
|
|
|
2017-08-05 22:20:07 +00:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2017-07-20 01:49:41 +00:00
|
|
|
protected static $dataIntegrityRules = [
|
2018-02-24 17:57:12 +00:00
|
|
|
'external_id' => 'nullable|string|between:1,191|unique:servers',
|
2018-01-28 23:14:14 +00:00
|
|
|
'owner_id' => 'integer|exists:users,id',
|
2018-01-20 22:03:23 +00:00
|
|
|
'name' => 'string|min:1|max:255',
|
2017-07-20 01:49:41 +00:00
|
|
|
'node_id' => 'exists:nodes,id',
|
2018-01-01 18:23:45 +00:00
|
|
|
'description' => 'string',
|
2017-07-20 01:49:41 +00:00
|
|
|
'memory' => 'numeric|min:0',
|
|
|
|
'swap' => 'numeric|min:-1',
|
|
|
|
'io' => 'numeric|between:10,1000',
|
|
|
|
'cpu' => 'numeric|min:0',
|
|
|
|
'disk' => 'numeric|min:0',
|
2018-02-17 19:53:38 +00:00
|
|
|
'allocation_id' => 'bail|unique:servers|exists:allocations,id',
|
2017-10-07 04:57:53 +00:00
|
|
|
'nest_id' => 'exists:nests,id',
|
|
|
|
'egg_id' => 'exists:eggs,id',
|
2017-07-20 01:49:41 +00:00
|
|
|
'pack_id' => 'nullable|numeric|min:0',
|
2018-01-28 23:14:14 +00:00
|
|
|
'startup' => 'string',
|
2017-07-20 01:49:41 +00:00
|
|
|
'skip_scripts' => 'boolean',
|
2018-01-28 23:14:14 +00:00
|
|
|
'image' => 'string|max:255',
|
2018-01-31 04:40:21 +00:00
|
|
|
'installed' => 'boolean',
|
2018-03-02 02:08:27 +00:00
|
|
|
'database_limit' => 'nullable|integer|min:0',
|
|
|
|
'allocation_limit' => 'nullable|integer|min:0',
|
2017-07-20 01:49:41 +00:00
|
|
|
];
|
|
|
|
|
2017-03-15 01:18:36 +00:00
|
|
|
/**
|
|
|
|
* Cast values to correct type.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $casts = [
|
|
|
|
'node_id' => 'integer',
|
2017-04-21 21:52:44 +00:00
|
|
|
'skip_scripts' => 'boolean',
|
2017-03-15 01:18:36 +00:00
|
|
|
'suspended' => 'integer',
|
|
|
|
'owner_id' => 'integer',
|
|
|
|
'memory' => 'integer',
|
|
|
|
'swap' => 'integer',
|
|
|
|
'disk' => 'integer',
|
|
|
|
'io' => 'integer',
|
|
|
|
'cpu' => 'integer',
|
|
|
|
'oom_disabled' => 'integer',
|
|
|
|
'allocation_id' => 'integer',
|
2017-10-07 04:57:53 +00:00
|
|
|
'nest_id' => 'integer',
|
|
|
|
'egg_id' => 'integer',
|
2017-03-15 01:18:36 +00:00
|
|
|
'pack_id' => 'integer',
|
|
|
|
'installed' => 'integer',
|
2018-03-02 02:08:27 +00:00
|
|
|
'database_limit' => 'integer',
|
|
|
|
'allocation_limit' => 'integer',
|
2017-03-15 01:18:36 +00:00
|
|
|
];
|
2016-01-27 03:17:51 +00:00
|
|
|
|
2017-03-15 01:18:36 +00:00
|
|
|
/**
|
|
|
|
* Parameters for search querying.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2017-08-05 22:20:07 +00:00
|
|
|
protected $searchableColumns = [
|
2018-02-24 17:57:12 +00:00
|
|
|
'name' => 100,
|
|
|
|
'uuid' => 80,
|
|
|
|
'uuidShort' => 80,
|
|
|
|
'external_id' => 50,
|
|
|
|
'user.email' => 40,
|
|
|
|
'user.username' => 30,
|
2018-01-06 00:49:00 +00:00
|
|
|
'node.name' => 10,
|
2018-02-24 17:57:12 +00:00
|
|
|
'pack.name' => 10,
|
2017-03-15 01:18:36 +00:00
|
|
|
];
|
2017-02-19 00:31:44 +00:00
|
|
|
|
2017-04-09 17:15:15 +00:00
|
|
|
/**
|
|
|
|
* Return the columns available for this table.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2017-04-09 23:16:39 +00:00
|
|
|
public function getTableColumns()
|
|
|
|
{
|
2017-04-09 17:15:15 +00:00
|
|
|
return Schema::getColumnListing($this->getTable());
|
|
|
|
}
|
|
|
|
|
2017-02-03 21:50:28 +00:00
|
|
|
/**
|
|
|
|
* Gets the user who owns the server.
|
|
|
|
*
|
2017-02-05 23:00:39 +00:00
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
2017-02-03 21:50:28 +00:00
|
|
|
*/
|
|
|
|
public function user()
|
|
|
|
{
|
2017-02-05 23:00:39 +00:00
|
|
|
return $this->belongsTo(User::class, 'owner_id');
|
2017-02-03 21:50:28 +00:00
|
|
|
}
|
|
|
|
|
2017-02-10 00:38:54 +00:00
|
|
|
/**
|
|
|
|
* Gets the subusers associated with a server.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
|
|
*/
|
|
|
|
public function subusers()
|
|
|
|
{
|
|
|
|
return $this->hasMany(Subuser::class);
|
|
|
|
}
|
|
|
|
|
2017-02-06 00:19:46 +00:00
|
|
|
/**
|
|
|
|
* Gets the default allocation for a server.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
|
|
|
*/
|
|
|
|
public function allocation()
|
|
|
|
{
|
|
|
|
return $this->hasOne(Allocation::class, 'id', 'allocation_id');
|
|
|
|
}
|
|
|
|
|
2017-02-02 21:24:08 +00:00
|
|
|
/**
|
|
|
|
* Gets all allocations associated with this server.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
|
|
*/
|
|
|
|
public function allocations()
|
|
|
|
{
|
2017-02-03 21:50:28 +00:00
|
|
|
return $this->hasMany(Allocation::class, 'server_id');
|
2017-02-02 21:24:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets information for the pack associated with this server.
|
|
|
|
*
|
2017-03-15 01:18:36 +00:00
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
2017-02-02 21:24:08 +00:00
|
|
|
*/
|
|
|
|
public function pack()
|
|
|
|
{
|
2017-03-15 01:18:36 +00:00
|
|
|
return $this->belongsTo(Pack::class);
|
2017-02-02 21:24:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-10-07 04:57:53 +00:00
|
|
|
* Gets information for the nest associated with this server.
|
2017-02-02 21:24:08 +00:00
|
|
|
*
|
2017-02-05 23:00:39 +00:00
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
2017-02-02 21:24:08 +00:00
|
|
|
*/
|
2017-10-07 04:57:53 +00:00
|
|
|
public function nest()
|
2017-02-02 21:24:08 +00:00
|
|
|
{
|
2017-10-07 04:57:53 +00:00
|
|
|
return $this->belongsTo(Nest::class);
|
2017-02-02 21:24:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-10-07 04:57:53 +00:00
|
|
|
* Gets information for the egg associated with this server.
|
2017-02-02 21:24:08 +00:00
|
|
|
*
|
2017-02-05 23:00:39 +00:00
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
2017-02-02 21:24:08 +00:00
|
|
|
*/
|
2017-10-07 04:57:53 +00:00
|
|
|
public function egg()
|
2017-02-02 21:24:08 +00:00
|
|
|
{
|
2017-10-07 04:57:53 +00:00
|
|
|
return $this->belongsTo(Egg::class);
|
2017-02-02 21:24:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets information for the service variables associated with this server.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
|
|
*/
|
|
|
|
public function variables()
|
|
|
|
{
|
2017-02-12 21:03:17 +00:00
|
|
|
return $this->hasMany(ServerVariable::class);
|
2017-02-02 21:24:08 +00:00
|
|
|
}
|
2017-02-02 23:21:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets information for the node associated with this server.
|
|
|
|
*
|
2017-02-05 23:00:39 +00:00
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
2017-02-02 23:21:36 +00:00
|
|
|
*/
|
|
|
|
public function node()
|
|
|
|
{
|
2017-02-05 23:00:39 +00:00
|
|
|
return $this->belongsTo(Node::class);
|
2017-02-02 23:21:36 +00:00
|
|
|
}
|
2017-02-03 00:41:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets information for the tasks associated with this server.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
|
|
*/
|
2017-09-24 01:45:25 +00:00
|
|
|
public function schedule()
|
2017-02-03 00:41:38 +00:00
|
|
|
{
|
2017-09-24 01:45:25 +00:00
|
|
|
return $this->hasMany(Schedule::class);
|
2017-02-03 00:41:38 +00:00
|
|
|
}
|
2017-02-09 22:43:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets all databases associated with a server.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
|
|
*/
|
|
|
|
public function databases()
|
|
|
|
{
|
|
|
|
return $this->hasMany(Database::class);
|
|
|
|
}
|
2017-04-08 00:28:58 +00:00
|
|
|
|
|
|
|
/**
|
2017-09-24 01:45:25 +00:00
|
|
|
* Returns the location that a server belongs to.
|
2017-04-08 00:28:58 +00:00
|
|
|
*
|
2017-09-24 01:45:25 +00:00
|
|
|
* @return \Znck\Eloquent\Relations\BelongsToThrough
|
|
|
|
*
|
|
|
|
* @throws \Exception
|
2017-04-08 00:28:58 +00:00
|
|
|
*/
|
|
|
|
public function location()
|
|
|
|
{
|
2017-09-24 01:45:25 +00:00
|
|
|
return $this->belongsToThrough(Location::class, Node::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the key belonging to the server owner.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
|
|
|
*/
|
2017-09-25 02:12:30 +00:00
|
|
|
public function key()
|
2017-09-24 01:45:25 +00:00
|
|
|
{
|
|
|
|
return $this->hasOne(DaemonKey::class, 'user_id', 'owner_id');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns all of the daemon keys belonging to this server.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
|
|
*/
|
|
|
|
public function keys()
|
|
|
|
{
|
|
|
|
return $this->hasMany(DaemonKey::class);
|
2017-04-08 00:28:58 +00:00
|
|
|
}
|
2015-12-06 18:58:49 +00:00
|
|
|
}
|