Merge branch 'develop' into feature/option-scripts
# Conflicts: # app/Http/Routes/AdminRoutes.php # app/Http/Routes/DaemonRoutes.php # app/Models/ServiceOption.php
This commit is contained in:
commit
8d24e5f168
683 changed files with 8854 additions and 12362 deletions
|
@ -28,6 +28,13 @@ use Illuminate\Database\Eloquent\Model;
|
|||
|
||||
class APIKey extends Model
|
||||
{
|
||||
/**
|
||||
* Public key defined length used in verification methods.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const PUBLIC_KEY_LEN = 16;
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
|
@ -42,6 +49,15 @@ class APIKey extends Model
|
|||
*/
|
||||
protected $hidden = ['secret'];
|
||||
|
||||
/**
|
||||
* Cast values to correct type.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'allowed_ips' => 'json',
|
||||
];
|
||||
|
||||
/**
|
||||
* Fields that are not mass assignable.
|
||||
*
|
||||
|
|
|
@ -49,12 +49,12 @@ class APILog extends Model
|
|||
*/
|
||||
protected $guarded = ['id', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* Cast values to correct type.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'authorized' => 'boolean',
|
||||
];
|
||||
/**
|
||||
* Cast values to correct type.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'authorized' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
|
|
@ -42,14 +42,14 @@ class APIPermission extends Model
|
|||
*/
|
||||
protected $guarded = ['id'];
|
||||
|
||||
/**
|
||||
* Cast values to correct type.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'key_id' => 'integer',
|
||||
];
|
||||
/**
|
||||
* Cast values to correct type.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'key_id' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* Disable timestamps for this table.
|
||||
|
@ -57,4 +57,75 @@ class APIPermission extends Model
|
|||
* @var bool
|
||||
*/
|
||||
public $timestamps = false;
|
||||
|
||||
/**
|
||||
* List of permissions available for the API.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $permissions = [
|
||||
// Items within this block are available to non-adminitrative users.
|
||||
'_user' => [
|
||||
'server' => [
|
||||
'list',
|
||||
'view',
|
||||
'power',
|
||||
'command',
|
||||
],
|
||||
],
|
||||
|
||||
// All other pemissions below are administrative actions.
|
||||
'server' => [
|
||||
'list',
|
||||
'create',
|
||||
'view',
|
||||
'edit-details',
|
||||
'edit-container',
|
||||
'edit-build',
|
||||
'edit-startup',
|
||||
'suspend',
|
||||
'install',
|
||||
'rebuild',
|
||||
'delete',
|
||||
],
|
||||
'location' => [
|
||||
'list',
|
||||
],
|
||||
'node' => [
|
||||
'list',
|
||||
'view',
|
||||
'view-config',
|
||||
'create',
|
||||
'delete',
|
||||
],
|
||||
'user' => [
|
||||
'list',
|
||||
'view',
|
||||
'create',
|
||||
'edit',
|
||||
'delete',
|
||||
],
|
||||
'service' => [
|
||||
'list',
|
||||
'view',
|
||||
],
|
||||
'option' => [
|
||||
'list',
|
||||
'view',
|
||||
],
|
||||
'pack' => [
|
||||
'list',
|
||||
'view',
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Return permissions for API.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function permissions()
|
||||
{
|
||||
return self::$permissions;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ class Allocation extends Model
|
|||
/**
|
||||
* Accessor to automatically provide the IP alias if defined.
|
||||
*
|
||||
* @param null|string $value
|
||||
* @param null|string $value
|
||||
* @return string
|
||||
*/
|
||||
public function getAliasAttribute($value)
|
||||
|
@ -67,7 +67,7 @@ class Allocation extends Model
|
|||
/**
|
||||
* Accessor to quickly determine if this allocation has an alias.
|
||||
*
|
||||
* @param null|string $value
|
||||
* @param null|string $value
|
||||
* @return bool
|
||||
*/
|
||||
public function getHasAliasAttribute($value)
|
||||
|
|
|
@ -51,33 +51,33 @@ class Database extends Model
|
|||
'server_id', 'database_host_id', 'database', 'username', 'remote',
|
||||
];
|
||||
|
||||
/**
|
||||
* Cast values to correct type.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'server_id' => 'integer',
|
||||
'database_host_id' => 'integer',
|
||||
];
|
||||
/**
|
||||
* Cast values to correct type.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'server_id' => 'integer',
|
||||
'database_host_id' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* Gets the host database server associated with a database.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function host()
|
||||
{
|
||||
return $this->belongsTo(DatabaseHost::class, 'database_host_id');
|
||||
}
|
||||
/**
|
||||
* Gets the host database server associated with a database.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function host()
|
||||
{
|
||||
return $this->belongsTo(DatabaseHost::class, 'database_host_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the server associated with a database.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function server()
|
||||
{
|
||||
return $this->belongsTo(Server::class);
|
||||
}
|
||||
/**
|
||||
* Gets the server associated with a database.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function server()
|
||||
{
|
||||
return $this->belongsTo(Server::class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
|
||||
namespace Pterodactyl\Models;
|
||||
|
||||
use Crypt;
|
||||
use Config;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class DatabaseHost extends Model
|
||||
|
@ -51,34 +53,54 @@ class DatabaseHost extends Model
|
|||
'name', 'host', 'port', 'username', 'max_databases', 'node_id',
|
||||
];
|
||||
|
||||
/**
|
||||
* Cast values to correct type.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'id' => 'integer',
|
||||
'max_databases' => 'integer',
|
||||
'node_id' => 'integer',
|
||||
];
|
||||
/**
|
||||
* Cast values to correct type.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'id' => 'integer',
|
||||
'max_databases' => 'integer',
|
||||
'node_id' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* Gets the node associated with a database host.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function node()
|
||||
{
|
||||
return $this->belongsTo(Node::class);
|
||||
}
|
||||
/**
|
||||
* Sets the database connection name with the details of the host.
|
||||
*
|
||||
* @param string $connection
|
||||
* @return void
|
||||
*/
|
||||
public function setDynamicConnection($connection = 'dynamic')
|
||||
{
|
||||
Config::set('database.connections.' . $connection, [
|
||||
'driver' => 'mysql',
|
||||
'host' => $this->host,
|
||||
'port' => $this->port,
|
||||
'database' => 'mysql',
|
||||
'username' => $this->username,
|
||||
'password' => Crypt::decrypt($this->password),
|
||||
'charset' => 'utf8',
|
||||
'collation' => 'utf8_unicode_ci',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the databases assocaited with this host.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function databases()
|
||||
{
|
||||
return $this->hasMany(Database::class);
|
||||
}
|
||||
/**
|
||||
* Gets the node associated with a database host.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function node()
|
||||
{
|
||||
return $this->belongsTo(Node::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the databases assocaited with this host.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function databases()
|
||||
{
|
||||
return $this->hasMany(Database::class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,6 +75,11 @@ class Node extends Model
|
|||
'daemonSFTP', 'daemonListen',
|
||||
];
|
||||
|
||||
/**
|
||||
* Fields that are searchable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $searchable = [
|
||||
'columns' => [
|
||||
'nodes.name' => 10,
|
||||
|
@ -90,7 +95,7 @@ class Node extends Model
|
|||
/**
|
||||
* Return an instance of the Guzzle client for this specific node.
|
||||
*
|
||||
* @param array $headers
|
||||
* @param array $headers
|
||||
* @return \GuzzleHttp\Client
|
||||
*/
|
||||
public function guzzleClient($headers = [])
|
||||
|
@ -106,8 +111,8 @@ class Node extends Model
|
|||
/**
|
||||
* Returns the configuration in JSON format.
|
||||
*
|
||||
* @param bool $pretty Wether to pretty print the JSON or not
|
||||
* @return string The configration in JSON format
|
||||
* @param bool $pretty
|
||||
* @return string
|
||||
*/
|
||||
public function getConfigurationAsJson($pretty = false)
|
||||
{
|
||||
|
|
|
@ -83,7 +83,7 @@ class Pack extends Model
|
|||
/**
|
||||
* Returns all of the archived files for a given pack.
|
||||
*
|
||||
* @param bool $collection
|
||||
* @param bool $collection
|
||||
* @return \Illuminate\Support\Collection|object
|
||||
*/
|
||||
public function files($collection = false)
|
||||
|
|
|
@ -58,6 +58,80 @@ class Permission extends Model
|
|||
'subuser_id' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* A list of all permissions available for a user.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $permissions = [
|
||||
'power' => [
|
||||
'power-start' => 's:power:start',
|
||||
'power-stop' => 's:power:stop',
|
||||
'power-restart' => 's:power:restart',
|
||||
'power-kill' => 's:power:kill',
|
||||
'send-command' => 's:command',
|
||||
],
|
||||
'subuser' => [
|
||||
'list-subusers' => null,
|
||||
'view-subuser' => null,
|
||||
'edit-subuser' => null,
|
||||
'create-subuser' => null,
|
||||
'delete-subuser' => null,
|
||||
],
|
||||
'server' => [
|
||||
'set-connection' => null,
|
||||
'view-startup' => null,
|
||||
'edit-startup' => null,
|
||||
],
|
||||
'sftp' => [
|
||||
'view-sftp' => null,
|
||||
'view-sftp-password' => null,
|
||||
'reset-sftp' => 's:set-password',
|
||||
],
|
||||
'file' => [
|
||||
'list-files' => 's:files:get',
|
||||
'edit-files' => 's:files:read',
|
||||
'save-files' => 's:files:post',
|
||||
'move-files' => 's:files:move',
|
||||
'copy-files' => 's:files:copy',
|
||||
'compress-files' => 's:files:compress',
|
||||
'decompress-files' => 's:files:decompress',
|
||||
'create-files' => 's:files:create',
|
||||
'upload-files' => 's:files:upload',
|
||||
'delete-files' => 's:files:delete',
|
||||
'download-files' => null,
|
||||
],
|
||||
'task' => [
|
||||
'list-tasks' => null,
|
||||
'view-task' => null,
|
||||
'toggle-task' => null,
|
||||
'queue-task' => null,
|
||||
'create-task' => null,
|
||||
'delete-task' => null,
|
||||
],
|
||||
'database' => [
|
||||
'view-databases' => null,
|
||||
'reset-db-password' => null,
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Return a collection of permissions available.
|
||||
*
|
||||
* @param array $single
|
||||
* @return \Illuminate\Support\Collection|array
|
||||
*/
|
||||
public static function list($single = false)
|
||||
{
|
||||
if ($single) {
|
||||
return collect(self::$permissions)->mapWithKeys(function ($item) {
|
||||
return $item;
|
||||
})->all();
|
||||
}
|
||||
|
||||
return collect(self::$permissions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find permission by permission node.
|
||||
*
|
||||
|
|
|
@ -27,15 +27,15 @@ namespace Pterodactyl\Models;
|
|||
use Auth;
|
||||
use Cache;
|
||||
use Carbon;
|
||||
use Schema;
|
||||
use Javascript;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Nicolaslopezj\Searchable\SearchableTrait;
|
||||
|
||||
class Server extends Model
|
||||
{
|
||||
use Notifiable, SearchableTrait, SoftDeletes;
|
||||
use Notifiable, SearchableTrait;
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
|
@ -115,8 +115,11 @@ class Server extends Model
|
|||
* DO NOT USE THIS TO MODIFY SERVER DETAILS OR SAVE THOSE DETAILS.
|
||||
* YOU WILL OVERWRITE THE SECRET KEY AND BREAK THINGS.
|
||||
*
|
||||
* @param string $uuid The Short-UUID of the server to return an object about.
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
* @param string $uuid
|
||||
* @param array $with
|
||||
* @param array $withCount
|
||||
* @return \Pterodactyl\Models\Server
|
||||
* @todo Remove $with and $withCount due to cache issues, they aren't used anyways.
|
||||
*/
|
||||
public static function byUuid($uuid, array $with = [], array $withCount = [])
|
||||
{
|
||||
|
@ -147,30 +150,39 @@ class Server extends Model
|
|||
/**
|
||||
* Returns non-administrative headers for accessing a server on the daemon.
|
||||
*
|
||||
* @param string $uuid
|
||||
* @param Pterodactyl\Models\User|null $user
|
||||
* @return array
|
||||
*/
|
||||
public function guzzleHeaders()
|
||||
public function guzzleHeaders(User $user = null)
|
||||
{
|
||||
// If no specific user is passed, see if we can find an active
|
||||
// auth session to pull data from.
|
||||
if (is_null($user) && Auth::check()) {
|
||||
$user = Auth::user();
|
||||
}
|
||||
|
||||
return [
|
||||
'X-Access-Server' => $this->uuid,
|
||||
'X-Access-Token' => Auth::user()->daemonToken($this),
|
||||
'X-Access-Token' => ($user) ? $user->daemonToken($this) : $this->daemonSecret,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an instance of the Guzzle client for this specific server using defined access token.
|
||||
*
|
||||
* @param Pterodactyl\Models\User|null $user
|
||||
* @return \GuzzleHttp\Client
|
||||
*/
|
||||
public function guzzleClient()
|
||||
public function guzzleClient(User $user = null)
|
||||
{
|
||||
return $this->node->guzzleClient($this->guzzleHeaders());
|
||||
return $this->node->guzzleClient($this->guzzleHeaders($user));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns javascript object to be embedded on server view pages with relevant information.
|
||||
*
|
||||
* @param array|null $additional
|
||||
* @param array|null $overwrite
|
||||
* @return \Laracasts\Utilities\JavaScript\JavaScriptFacade
|
||||
*/
|
||||
public function js($additional = null, $overwrite = null)
|
||||
|
@ -200,6 +212,16 @@ class Server extends Model
|
|||
return Javascript::put($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the columns available for this table.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTableColumns()
|
||||
{
|
||||
return Schema::getColumnListing($this->getTable());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the user who owns the server.
|
||||
*
|
||||
|
@ -298,7 +320,7 @@ class Server extends Model
|
|||
*/
|
||||
public function tasks()
|
||||
{
|
||||
return $this->hasMany(Task::class, 'server', 'id');
|
||||
return $this->hasMany(Task::class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -310,4 +332,24 @@ class Server extends Model
|
|||
{
|
||||
return $this->hasMany(Database::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all downloads associated with a server.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function downloads()
|
||||
{
|
||||
return $this->hasMany(Download::class, 'server', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the location of the server.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function location()
|
||||
{
|
||||
return $this->node->location();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,6 +42,7 @@ class ServiceOption extends Model
|
|||
*/
|
||||
protected $guarded = ['id', 'created_at', 'updated_at'];
|
||||
|
||||
<<<<<<< HEAD
|
||||
/**
|
||||
* Cast values to correct type.
|
||||
*
|
||||
|
@ -51,55 +52,65 @@ class ServiceOption extends Model
|
|||
'service_id' => 'integer',
|
||||
'script_is_privileged' => 'boolean',
|
||||
];
|
||||
=======
|
||||
/**
|
||||
* Cast values to correct type.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'service_id' => 'integer',
|
||||
];
|
||||
>>>>>>> develop
|
||||
|
||||
/**
|
||||
* Returns the display startup string for the option and will use the parent
|
||||
* service one if the option does not have one defined.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDisplayStartupAttribute($value)
|
||||
{
|
||||
return (is_null($this->startup)) ? $this->service->startup : $this->startup;
|
||||
}
|
||||
/**
|
||||
* Returns the display startup string for the option and will use the parent
|
||||
* service one if the option does not have one defined.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDisplayStartupAttribute($value)
|
||||
{
|
||||
return (is_null($this->startup)) ? $this->service->startup : $this->startup;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets service associated with a service option.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function service()
|
||||
{
|
||||
return $this->belongsTo(Service::class);
|
||||
}
|
||||
/**
|
||||
* Gets service associated with a service option.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function service()
|
||||
{
|
||||
return $this->belongsTo(Service::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all servers associated with this service option.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function servers()
|
||||
{
|
||||
return $this->hasMany(Server::class, 'option_id');
|
||||
}
|
||||
/**
|
||||
* Gets all servers associated with this service option.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function servers()
|
||||
{
|
||||
return $this->hasMany(Server::class, 'option_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all variables associated with this service.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function variables()
|
||||
{
|
||||
return $this->hasMany(ServiceVariable::class, 'option_id');
|
||||
}
|
||||
/**
|
||||
* Gets all variables associated with this service.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function variables()
|
||||
{
|
||||
return $this->hasMany(ServiceVariable::class, 'option_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all packs associated with this service.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function packs()
|
||||
{
|
||||
return $this->hasMany(Pack::class, 'option_id');
|
||||
}
|
||||
/**
|
||||
* Gets all packs associated with this service.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function packs()
|
||||
{
|
||||
return $this->hasMany(Pack::class, 'option_id');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ class ServiceVariable extends Model
|
|||
* Returns the display executable for the option and will use the parent
|
||||
* service one if the option does not have one defined.
|
||||
*
|
||||
* @return string
|
||||
* @return bool
|
||||
*/
|
||||
public function getRequiredAttribute($value)
|
||||
{
|
||||
|
|
|
@ -35,13 +35,13 @@ class Session extends Model
|
|||
*/
|
||||
protected $table = 'sessions';
|
||||
|
||||
/**
|
||||
* Cast values to correct type.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'id' => 'string',
|
||||
'user_id' => 'integer',
|
||||
];
|
||||
/**
|
||||
* Cast values to correct type.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'id' => 'string',
|
||||
'user_id' => 'integer',
|
||||
];
|
||||
}
|
||||
|
|
|
@ -42,16 +42,18 @@ class Task extends Model
|
|||
*/
|
||||
protected $guarded = ['id', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* Cast values to correct type.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'id' => 'integer',
|
||||
'server' => 'integer',
|
||||
'queued' => 'integer',
|
||||
];
|
||||
/**
|
||||
* Cast values to correct type.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'id' => 'integer',
|
||||
'user_id' => 'integer',
|
||||
'server_id' => 'integer',
|
||||
'queued' => 'boolean',
|
||||
'active' => 'boolean',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be mutated to dates.
|
||||
|
@ -59,4 +61,24 @@ class Task extends Model
|
|||
* @var array
|
||||
*/
|
||||
protected $dates = ['last_run', 'next_run', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* Gets the server associated with a task.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function server()
|
||||
{
|
||||
return $this->belongsTo(Server::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the user associated with a task.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,16 +42,16 @@ class TaskLog extends Model
|
|||
*/
|
||||
protected $guarded = ['id', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* Cast values to correct type.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'id' => 'integer',
|
||||
'task_id' => 'integer',
|
||||
'run_status' => 'integer',
|
||||
];
|
||||
/**
|
||||
* Cast values to correct type.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'id' => 'integer',
|
||||
'task_id' => 'integer',
|
||||
'run_status' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be mutated to dates.
|
||||
|
|
|
@ -70,16 +70,16 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
|
|||
*/
|
||||
protected $fillable = ['username', 'email', 'name_first', 'name_last', 'password', 'language', 'use_totp', 'totp_secret', 'gravatar', 'root_admin'];
|
||||
|
||||
/**
|
||||
* Cast values to correct type.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'root_admin' => 'integer',
|
||||
'use_totp' => 'integer',
|
||||
'gravatar' => 'integer',
|
||||
];
|
||||
/**
|
||||
* Cast values to correct type.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'root_admin' => 'integer',
|
||||
'use_totp' => 'integer',
|
||||
'gravatar' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes excluded from the model's JSON form.
|
||||
|
@ -103,10 +103,12 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
|
|||
],
|
||||
];
|
||||
|
||||
protected $query;
|
||||
|
||||
/**
|
||||
* Enables or disables TOTP on an account if the token is valid.
|
||||
*
|
||||
* @param int $token The token that we want to verify.
|
||||
* @param int $token
|
||||
* @return bool
|
||||
*/
|
||||
public function toggleTotp($token)
|
||||
|
@ -116,9 +118,8 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
|
|||
}
|
||||
|
||||
$this->use_totp = ! $this->use_totp;
|
||||
$this->save();
|
||||
|
||||
return true;
|
||||
return $this->save();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -128,8 +129,8 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
|
|||
* - at least one lowercase character
|
||||
* - at least one number.
|
||||
*
|
||||
* @param string $password The raw password to set the account password to.
|
||||
* @param string $regex The regex to use when validating the password. Defaults to '((?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,})'.
|
||||
* @param string $password
|
||||
* @param string $regex
|
||||
* @return void
|
||||
*/
|
||||
public function setPassword($password, $regex = '((?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,})')
|
||||
|
@ -156,7 +157,7 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
|
|||
/**
|
||||
* Return true or false depending on wether the user is root admin or not.
|
||||
*
|
||||
* @return bool the user is root admin
|
||||
* @return bool
|
||||
*/
|
||||
public function isRootAdmin()
|
||||
{
|
||||
|
@ -165,7 +166,8 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
|
|||
|
||||
/**
|
||||
* Returns the user's daemon secret for a given server.
|
||||
* @param Server $server \Pterodactyl\Models\Server
|
||||
*
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
* @return null|string
|
||||
*/
|
||||
public function daemonToken(Server $server)
|
||||
|
@ -174,13 +176,9 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
|
|||
return $server->daemonSecret;
|
||||
}
|
||||
|
||||
$subuser = Subuser::where('server_id', $server->id)->where('user_id', $this->id)->first();
|
||||
$subuser = $this->subuserOf->where('server_id', $server->id)->first();
|
||||
|
||||
if (is_null($subuser)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $subuser->daemonSecret;
|
||||
return ($subuser) ? $subuser->daemonSecret : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -191,25 +189,31 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
|
|||
*/
|
||||
public function serverAccessArray()
|
||||
{
|
||||
$union = Subuser::select('server_id')->where('user_id', $this->id);
|
||||
|
||||
return Server::select('id')->where('owner_id', $this->id)->union($union)->pluck('id')->all();
|
||||
return Server::select('id')->where('owner_id', $this->id)->union(
|
||||
Subuser::select('server_id')->where('user_id', $this->id)
|
||||
)->pluck('id')->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of all servers a user is able to access.
|
||||
* Note: does not account for user admin status.
|
||||
*
|
||||
* @return Collection
|
||||
* @param array $load
|
||||
* @return \Illuiminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function serverAccessCollection($paginate = null, $load = ['service', 'node', 'allocation'])
|
||||
public function access(...$load)
|
||||
{
|
||||
$query = Server::with($load);
|
||||
if (count($load) > 0 && is_null($load[0])) {
|
||||
$query = Server::query();
|
||||
} else {
|
||||
$query = Server::with(! empty($load) ? $load : ['service', 'node', 'allocation']);
|
||||
}
|
||||
|
||||
if (! $this->isRootAdmin()) {
|
||||
$query->whereIn('id', $this->serverAccessArray());
|
||||
}
|
||||
|
||||
return (is_numeric($paginate)) ? $query->paginate($paginate) : $query->get();
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -231,4 +235,14 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
|
|||
{
|
||||
return $this->hasMany(Server::class, 'owner_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all servers that user is listed as a subuser of directly.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function subuserOf()
|
||||
{
|
||||
return $this->hasMany(Subuser::class);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue