Apply fixes from StyleCI
This commit is contained in:
parent
a1d3bbf73d
commit
c1fb0a665f
150 changed files with 1558 additions and 1760 deletions
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>
|
||||
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -21,21 +21,20 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Repositories;
|
||||
|
||||
use Auth;
|
||||
use DB;
|
||||
use Auth;
|
||||
use Crypt;
|
||||
use Validator;
|
||||
use IPTools\Network;
|
||||
|
||||
use Pterodactyl\Models;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Pterodactyl\Exceptions\DisplayValidationException;
|
||||
|
||||
class APIRepository
|
||||
{
|
||||
|
||||
/**
|
||||
* Valid API permissions.
|
||||
* @var array
|
||||
|
@ -97,7 +96,7 @@ class APIRepository
|
|||
protected $user;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct(Models\User $user = null)
|
||||
{
|
||||
|
@ -122,12 +121,12 @@ class APIRepository
|
|||
$validator = Validator::make($data, [
|
||||
'memo' => 'string|max:500',
|
||||
'permissions' => 'sometimes|required|array',
|
||||
'adminPermissions' => 'sometimes|required|array'
|
||||
'adminPermissions' => 'sometimes|required|array',
|
||||
]);
|
||||
|
||||
$validator->after(function($validator) use ($data) {
|
||||
if (array_key_exists('allowed_ips', $data) && !empty($data['allowed_ips'])) {
|
||||
foreach(explode("\n", $data['allowed_ips']) as $ip) {
|
||||
$validator->after(function ($validator) use ($data) {
|
||||
if (array_key_exists('allowed_ips', $data) && ! empty($data['allowed_ips'])) {
|
||||
foreach (explode("\n", $data['allowed_ips']) as $ip) {
|
||||
$ip = trim($ip);
|
||||
try {
|
||||
Network::parse($ip);
|
||||
|
@ -155,14 +154,16 @@ class APIRepository
|
|||
'secret' => Crypt::encrypt($secretKey),
|
||||
'allowed_ips' => empty($this->allowed) ? null : json_encode($this->allowed),
|
||||
'memo' => $data['memo'],
|
||||
'expires_at' => null
|
||||
'expires_at' => null,
|
||||
]);
|
||||
$key->save();
|
||||
|
||||
$totalPermissions = 0;
|
||||
if (isset($data['permissions'])) {
|
||||
foreach($data['permissions'] as $permNode) {
|
||||
if (!strpos($permNode, ':')) continue;
|
||||
foreach ($data['permissions'] as $permNode) {
|
||||
if (! strpos($permNode, ':')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
list($toss, $permission) = explode(':', $permNode);
|
||||
if (in_array($permission, $this->permissions['user'])) {
|
||||
|
@ -170,7 +171,7 @@ class APIRepository
|
|||
$model = new Models\APIPermission;
|
||||
$model->fill([
|
||||
'key_id' => $key->id,
|
||||
'permission' => 'api.user.' . $permission
|
||||
'permission' => 'api.user.' . $permission,
|
||||
]);
|
||||
$model->save();
|
||||
}
|
||||
|
@ -178,8 +179,10 @@ class APIRepository
|
|||
}
|
||||
|
||||
if ($this->user->root_admin === 1 && isset($data['adminPermissions'])) {
|
||||
foreach($data['adminPermissions'] as $permNode) {
|
||||
if (!strpos($permNode, ':')) continue;
|
||||
foreach ($data['adminPermissions'] as $permNode) {
|
||||
if (! strpos($permNode, ':')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
list($toss, $permission) = explode(':', $permNode);
|
||||
if (in_array($permission, $this->permissions['admin'])) {
|
||||
|
@ -187,7 +190,7 @@ class APIRepository
|
|||
$model = new Models\APIPermission;
|
||||
$model->fill([
|
||||
'key_id' => $key->id,
|
||||
'permission' => 'api.admin.' . $permission
|
||||
'permission' => 'api.admin.' . $permission,
|
||||
]);
|
||||
$model->save();
|
||||
}
|
||||
|
@ -199,12 +202,12 @@ class APIRepository
|
|||
}
|
||||
|
||||
DB::commit();
|
||||
|
||||
return $secretKey;
|
||||
} catch (\Exception $ex) {
|
||||
DB::rollBack();
|
||||
throw $ex;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -231,5 +234,4 @@ class APIRepository
|
|||
throw $ex;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>
|
||||
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -21,16 +21,16 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Repositories\Daemon;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use Pterodactyl\Models;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
|
||||
class CommandRepository {
|
||||
|
||||
class CommandRepository
|
||||
{
|
||||
protected $server;
|
||||
protected $node;
|
||||
protected $client;
|
||||
|
@ -43,9 +43,9 @@ class CommandRepository {
|
|||
}
|
||||
|
||||
/**
|
||||
* [send description]
|
||||
* [send description].
|
||||
* @param string $command
|
||||
* @return boolean
|
||||
* @return bool
|
||||
* @throws DisplayException
|
||||
* @throws RequestException
|
||||
*/
|
||||
|
@ -59,11 +59,11 @@ class CommandRepository {
|
|||
$response = $this->client->request('POST', '/server/command', [
|
||||
'headers' => [
|
||||
'X-Access-Token' => $this->server->daemonSecret,
|
||||
'X-Access-Server' => $this->server->uuid
|
||||
'X-Access-Server' => $this->server->uuid,
|
||||
],
|
||||
'json' => [
|
||||
'command' => $command
|
||||
]
|
||||
'command' => $command,
|
||||
],
|
||||
]);
|
||||
|
||||
if ($response->getStatusCode() < 200 || $response->getStatusCode() >= 300) {
|
||||
|
@ -75,5 +75,4 @@ class CommandRepository {
|
|||
throw $ex;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>
|
||||
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -21,22 +21,18 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Repositories\Daemon;
|
||||
|
||||
use \Exception;
|
||||
use Log;
|
||||
|
||||
use Pterodactyl\Models\Server;
|
||||
use Pterodactyl\Models\Node;
|
||||
use Pterodactyl\Repositories\HelperRepository;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
|
||||
use Exception;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use Pterodactyl\Models\Node;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Pterodactyl\Repositories\HelperRepository;
|
||||
|
||||
class FileRepository
|
||||
{
|
||||
|
||||
/**
|
||||
* The Eloquent Model associated with the requested server.
|
||||
*
|
||||
|
@ -60,25 +56,23 @@ class FileRepository
|
|||
|
||||
/**
|
||||
* The Guzzle Client headers associated with the requested server and node.
|
||||
* (non-administrative headers)
|
||||
* (non-administrative headers).
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $headers;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $server The server Short UUID
|
||||
*/
|
||||
public function __construct($uuid)
|
||||
{
|
||||
|
||||
$this->server = Server::getByUUID($uuid);
|
||||
$this->node = Node::getByID($this->server->node);
|
||||
$this->client = Node::guzzleRequest($this->server->node);
|
||||
$this->headers = Server::getGuzzleHeaders($uuid);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -89,7 +83,6 @@ class FileRepository
|
|||
*/
|
||||
public function returnFileContents($file)
|
||||
{
|
||||
|
||||
if (empty($file)) {
|
||||
throw new Exception('Not all parameters were properly passed to the function.');
|
||||
}
|
||||
|
@ -98,16 +91,16 @@ class FileRepository
|
|||
|
||||
$file->dirname = (in_array($file->dirname, ['.', './', '/'])) ? null : trim($file->dirname, '/') . '/';
|
||||
|
||||
$res = $this->client->request('GET', '/server/file/stat/' . rawurlencode($file->dirname.$file->basename) , [
|
||||
'headers' => $this->headers
|
||||
$res = $this->client->request('GET', '/server/file/stat/' . rawurlencode($file->dirname . $file->basename), [
|
||||
'headers' => $this->headers,
|
||||
]);
|
||||
|
||||
$stat = json_decode($res->getBody());
|
||||
if($res->getStatusCode() !== 200 || !isset($stat->size)) {
|
||||
if ($res->getStatusCode() !== 200 || ! isset($stat->size)) {
|
||||
throw new DisplayException('The daemon provided a non-200 error code on stat lookup: HTTP\\' . $res->getStatusCode());
|
||||
}
|
||||
|
||||
if (!in_array($stat->mime, HelperRepository::editableFiles())) {
|
||||
if (! in_array($stat->mime, HelperRepository::editableFiles())) {
|
||||
throw new DisplayException('You cannot edit that type of file (' . $stat->mime . ') through the panel.');
|
||||
}
|
||||
|
||||
|
@ -115,20 +108,19 @@ class FileRepository
|
|||
throw new DisplayException('That file is too large to open in the browser, consider using a SFTP client.');
|
||||
}
|
||||
|
||||
$res = $this->client->request('GET', '/server/file/f/' . rawurlencode($file->dirname.$file->basename) , [
|
||||
'headers' => $this->headers
|
||||
$res = $this->client->request('GET', '/server/file/f/' . rawurlencode($file->dirname . $file->basename), [
|
||||
'headers' => $this->headers,
|
||||
]);
|
||||
|
||||
$json = json_decode($res->getBody());
|
||||
if($res->getStatusCode() !== 200 || !isset($json->content)) {
|
||||
if ($res->getStatusCode() !== 200 || ! isset($json->content)) {
|
||||
throw new DisplayException('The daemon provided a non-200 error code: HTTP\\' . $res->getStatusCode());
|
||||
}
|
||||
|
||||
return [
|
||||
'file' => $json,
|
||||
'stat' => $stat
|
||||
'stat' => $stat,
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -140,7 +132,6 @@ class FileRepository
|
|||
*/
|
||||
public function saveFileContents($file, $content)
|
||||
{
|
||||
|
||||
if (empty($file)) {
|
||||
throw new Exception('A valid file and path must be specified to save a file.');
|
||||
}
|
||||
|
@ -152,9 +143,9 @@ class FileRepository
|
|||
$res = $this->client->request('POST', '/server/file/save', [
|
||||
'headers' => $this->headers,
|
||||
'json' => [
|
||||
'path' => rawurlencode($file->dirname.$file->basename),
|
||||
'content' => $content
|
||||
]
|
||||
'path' => rawurlencode($file->dirname . $file->basename),
|
||||
'content' => $content,
|
||||
],
|
||||
]);
|
||||
|
||||
if ($res->getStatusCode() !== 204) {
|
||||
|
@ -162,7 +153,6 @@ class FileRepository
|
|||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -173,25 +163,23 @@ class FileRepository
|
|||
*/
|
||||
public function returnDirectoryListing($directory)
|
||||
{
|
||||
|
||||
if (empty($directory)) {
|
||||
throw new Exception('A valid directory must be specified in order to list its contents.');
|
||||
}
|
||||
|
||||
$res = $this->client->request('GET', '/server/directory/' . rawurlencode($directory), [
|
||||
'headers' => $this->headers
|
||||
'headers' => $this->headers,
|
||||
]);
|
||||
|
||||
$json = json_decode($res->getBody());
|
||||
if($res->getStatusCode() !== 200) {
|
||||
if ($res->getStatusCode() !== 200) {
|
||||
throw new DisplayException('An error occured while attempting to save this file. ' . $res->getBody());
|
||||
}
|
||||
|
||||
// Iterate through results
|
||||
$files = [];
|
||||
$folders = [];
|
||||
foreach($json as &$value) {
|
||||
|
||||
foreach ($json as &$value) {
|
||||
if ($value->directory === true) {
|
||||
|
||||
// @TODO Handle Symlinks
|
||||
|
@ -200,29 +188,23 @@ class FileRepository
|
|||
'directory' => trim($directory, '/'),
|
||||
'size' => null,
|
||||
'date' => strtotime($value->modified),
|
||||
'mime' => $value->mime
|
||||
'mime' => $value->mime,
|
||||
]]);
|
||||
|
||||
} else if ($value->file === true) {
|
||||
|
||||
} elseif ($value->file === true) {
|
||||
$files = array_merge($files, [[
|
||||
'entry' => $value->name,
|
||||
'directory' => trim($directory, '/'),
|
||||
'extension' => pathinfo($value->name, PATHINFO_EXTENSION),
|
||||
'size' => HelperRepository::bytesToHuman($value->size),
|
||||
'date' => strtotime($value->modified),
|
||||
'mime' => $value->mime
|
||||
'mime' => $value->mime,
|
||||
]]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return (object) [
|
||||
'files' => $files,
|
||||
'folders' => $folders,
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>
|
||||
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -21,16 +21,15 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Repositories\Daemon;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use Pterodactyl\Models;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
|
||||
class PowerRepository {
|
||||
|
||||
class PowerRepository
|
||||
{
|
||||
protected $server;
|
||||
protected $node;
|
||||
protected $client;
|
||||
|
@ -52,11 +51,11 @@ class PowerRepository {
|
|||
$response = $this->client->request('PUT', '/server/power', [
|
||||
'headers' => [
|
||||
'X-Access-Token' => $this->server->daemonSecret,
|
||||
'X-Access-Server' => $this->server->uuid
|
||||
'X-Access-Server' => $this->server->uuid,
|
||||
],
|
||||
'json' => [
|
||||
'action' => $action
|
||||
]
|
||||
'action' => $action,
|
||||
],
|
||||
]);
|
||||
|
||||
if ($response->getStatusCode() < 200 || $response->getStatusCode() >= 300) {
|
||||
|
@ -88,5 +87,4 @@ class PowerRepository {
|
|||
{
|
||||
$this->do('kill');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>
|
||||
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -21,21 +21,19 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Repositories;
|
||||
|
||||
use Crypt;
|
||||
use Log;
|
||||
use DB;
|
||||
use Crypt;
|
||||
use Validator;
|
||||
|
||||
use Pterodactyl\Models;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
use Pterodactyl\Exceptions\DisplayValidationException;
|
||||
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
|
||||
class DatabaseRepository {
|
||||
|
||||
class DatabaseRepository
|
||||
{
|
||||
/**
|
||||
* Adds a new database to a given database server.
|
||||
* @param int $server Id of the server to add a database for.
|
||||
|
@ -64,7 +62,7 @@ class DatabaseRepository {
|
|||
'database' => "s{$server->id}_{$options['database']}",
|
||||
'username' => $server->uuidShort . '_' . str_random(7),
|
||||
'remote' => $options['remote'],
|
||||
'password' => Crypt::encrypt(str_random(20))
|
||||
'password' => Crypt::encrypt(str_random(20)),
|
||||
]);
|
||||
$db->save();
|
||||
|
||||
|
@ -84,11 +82,10 @@ class DatabaseRepository {
|
|||
'prefix' => '',
|
||||
'options' => [
|
||||
\PDO::ATTR_TIMEOUT => 3,
|
||||
]
|
||||
],
|
||||
]);
|
||||
|
||||
$capsule->setAsGlobal();
|
||||
|
||||
} catch (\Exception $ex) {
|
||||
DB::rollBack();
|
||||
throw new DisplayException('There was an error while connecting to the Database Host Server. Please check the error logs.', $ex);
|
||||
|
@ -128,7 +125,6 @@ class DatabaseRepository {
|
|||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
|
||||
$db->password = Crypt::encrypt($password);
|
||||
$db->save();
|
||||
|
||||
|
@ -145,7 +141,7 @@ class DatabaseRepository {
|
|||
'prefix' => '',
|
||||
'options' => [
|
||||
\PDO::ATTR_TIMEOUT => 3,
|
||||
]
|
||||
],
|
||||
]);
|
||||
|
||||
$capsule->setAsGlobal();
|
||||
|
@ -157,16 +153,16 @@ class DatabaseRepository {
|
|||
));
|
||||
|
||||
DB::commit();
|
||||
} catch(\Exception $ex) {
|
||||
} catch (\Exception $ex) {
|
||||
DB::rollback();
|
||||
throw $ex;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Drops a database from the associated MySQL Server
|
||||
* Drops a database from the associated MySQL Server.
|
||||
* @param int $database The ID of the database to drop.
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function drop($database)
|
||||
{
|
||||
|
@ -189,7 +185,7 @@ class DatabaseRepository {
|
|||
'prefix' => '',
|
||||
'options' => [
|
||||
\PDO::ATTR_TIMEOUT => 3,
|
||||
]
|
||||
],
|
||||
]);
|
||||
|
||||
$capsule->setAsGlobal();
|
||||
|
@ -200,12 +196,12 @@ class DatabaseRepository {
|
|||
$db->delete();
|
||||
|
||||
DB::commit();
|
||||
|
||||
return true;
|
||||
} catch (\Exception $ex) {
|
||||
DB::rollback();
|
||||
throw $ex;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -231,7 +227,6 @@ class DatabaseRepository {
|
|||
*/
|
||||
public function add(array $data)
|
||||
{
|
||||
|
||||
if (isset($data['host'])) {
|
||||
$data['host'] = gethostbyname($data['host']);
|
||||
}
|
||||
|
@ -265,7 +260,7 @@ class DatabaseRepository {
|
|||
'prefix' => '',
|
||||
'options' => [
|
||||
\PDO::ATTR_TIMEOUT => 3,
|
||||
]
|
||||
],
|
||||
]);
|
||||
|
||||
$capsule->setAsGlobal();
|
||||
|
@ -280,8 +275,8 @@ class DatabaseRepository {
|
|||
'port' => $data['port'],
|
||||
'username' => $data['username'],
|
||||
'password' => Crypt::encrypt($data['password']),
|
||||
'max_databases' => NULL,
|
||||
'linked_node' => (!empty($data['linked_node']) && $data['linked_node'] > 0) ? $data['linked_node'] : NULL
|
||||
'max_databases' => null,
|
||||
'linked_node' => (! empty($data['linked_node']) && $data['linked_node'] > 0) ? $data['linked_node'] : null,
|
||||
]);
|
||||
$dbh->save();
|
||||
|
||||
|
@ -291,5 +286,4 @@ class DatabaseRepository {
|
|||
throw $ex;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>
|
||||
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -21,10 +21,11 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Repositories;
|
||||
|
||||
class HelperRepository {
|
||||
|
||||
class HelperRepository
|
||||
{
|
||||
/**
|
||||
* Listing of editable files in the control panel.
|
||||
* @var array
|
||||
|
@ -40,10 +41,9 @@ class HelperRepository {
|
|||
'text/plain',
|
||||
'text/x-perl',
|
||||
'text/x-shellscript',
|
||||
'inode/x-empty'
|
||||
'inode/x-empty',
|
||||
];
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
|
@ -58,17 +58,14 @@ class HelperRepository {
|
|||
*/
|
||||
public static function bytesToHuman($bytes, $decimals = 2)
|
||||
{
|
||||
|
||||
$sz = explode(',', 'B,KB,MB,GB');
|
||||
$factor = floor((strlen($bytes) - 1) / 3);
|
||||
|
||||
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)).' '.$sz[$factor];
|
||||
|
||||
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . ' ' . $sz[$factor];
|
||||
}
|
||||
|
||||
public static function editableFiles()
|
||||
{
|
||||
return self::$editable;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>
|
||||
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -21,16 +21,15 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Repositories;
|
||||
|
||||
use Validator;
|
||||
|
||||
use Pterodactyl\Models;
|
||||
use Pterodactyl\Exceptions\DisplayValidationException;
|
||||
|
||||
class LocationRepository
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
|
@ -40,13 +39,13 @@ class LocationRepository
|
|||
* Creates a new location on the system.
|
||||
* @param array $data
|
||||
* @throws Pterodactyl\Exceptions\DisplayValidationException
|
||||
* @return integer
|
||||
* @return int
|
||||
*/
|
||||
public function create(array $data)
|
||||
{
|
||||
$validator = Validator::make($data, [
|
||||
'short' => 'required|regex:/^[a-z0-9_.-]{1,10}$/i|unique:locations,short',
|
||||
'long' => 'required|string|min:1|max:255'
|
||||
'long' => 'required|string|min:1|max:255',
|
||||
]);
|
||||
|
||||
// Run validator, throw catchable and displayable exception if it fails.
|
||||
|
@ -58,7 +57,7 @@ class LocationRepository
|
|||
$location = new Models\Location;
|
||||
$location->fill([
|
||||
'long' => $data['long'],
|
||||
'short' => $data['short']
|
||||
'short' => $data['short'],
|
||||
]);
|
||||
$location->save();
|
||||
|
||||
|
@ -67,16 +66,16 @@ class LocationRepository
|
|||
|
||||
/**
|
||||
* Modifies a location based on the fields passed in $data.
|
||||
* @param integer $id
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
* @throws Pterodactyl\Exceptions\DisplayValidationException
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function edit($id, array $data)
|
||||
{
|
||||
$validator = Validator::make($data, [
|
||||
'short' => 'regex:/^[a-z0-9_.-]{1,10}$/i',
|
||||
'long' => 'string|min:1|max:255'
|
||||
'long' => 'string|min:1|max:255',
|
||||
]);
|
||||
|
||||
// Run validator, throw catchable and displayable exception if it fails.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>
|
||||
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -21,20 +21,19 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Repositories;
|
||||
|
||||
use DB;
|
||||
use Validator;
|
||||
|
||||
use IPTools\Network;
|
||||
use Pterodactyl\Models;
|
||||
use Pterodactyl\Services\UuidService;
|
||||
|
||||
use IPTools\Network;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Pterodactyl\Exceptions\DisplayValidationException;
|
||||
|
||||
class NodeRepository {
|
||||
|
||||
class NodeRepository
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
|
@ -70,7 +69,7 @@ class NodeRepository {
|
|||
}
|
||||
|
||||
// Verify FQDN is resolvable, or if not using SSL that the IP is valid.
|
||||
if (!filter_var(gethostbyname($data['fqdn']), FILTER_VALIDATE_IP)) {
|
||||
if (! filter_var(gethostbyname($data['fqdn']), FILTER_VALIDATE_IP)) {
|
||||
throw new DisplayException('The FQDN (or IP Address) provided does not resolve to a valid IP address.');
|
||||
}
|
||||
|
||||
|
@ -88,7 +87,6 @@ class NodeRepository {
|
|||
$node->save();
|
||||
|
||||
return $node->id;
|
||||
|
||||
}
|
||||
|
||||
public function update($id, array $data)
|
||||
|
@ -123,17 +121,16 @@ class NodeRepository {
|
|||
if (isset($data['fqdn'])) {
|
||||
|
||||
// Verify the FQDN if using SSL
|
||||
if ((isset($data['scheme']) && $data['scheme'] === 'https') || (!isset($data['scheme']) && $node->scheme === 'https')) {
|
||||
if ((isset($data['scheme']) && $data['scheme'] === 'https') || (! isset($data['scheme']) && $node->scheme === 'https')) {
|
||||
if (filter_var($data['fqdn'], FILTER_VALIDATE_IP)) {
|
||||
throw new DisplayException('A fully qualified domain name is required to use secure comunication on this node.');
|
||||
}
|
||||
}
|
||||
|
||||
// Verify FQDN is resolvable, or if not using SSL that the IP is valid.
|
||||
if (!filter_var(gethostbyname($data['fqdn']), FILTER_VALIDATE_IP)) {
|
||||
if (! filter_var(gethostbyname($data['fqdn']), FILTER_VALIDATE_IP)) {
|
||||
throw new DisplayException('The FQDN (or IP Address) provided does not resolve to a valid IP address.');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Should we be nulling the overallocations?
|
||||
|
@ -165,7 +162,7 @@ class NodeRepository {
|
|||
'listen' => $node->daemonListen,
|
||||
'ssl' => [
|
||||
'enabled' => ($node->scheme === 'https'),
|
||||
'certificate' => '/etc/letsencrypt/live/' . $node->fqdn .'/fullchain.pem',
|
||||
'certificate' => '/etc/letsencrypt/live/' . $node->fqdn . '/fullchain.pem',
|
||||
'key' => '/etc/letsencrypt/live/' . $node->fqdn . '/privkey.pem',
|
||||
],
|
||||
],
|
||||
|
@ -183,13 +180,12 @@ class NodeRepository {
|
|||
],
|
||||
'keys' => [
|
||||
$node->daemonSecret,
|
||||
]
|
||||
],
|
||||
],
|
||||
]);
|
||||
} catch (\Exception $ex) {
|
||||
throw new DisplayException('Failed to update the node configuration, however your changes have been saved to the database. You will need to manually update the configuration file for the node to apply these changes.');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function addAllocations($id, array $allocations)
|
||||
|
@ -199,7 +195,7 @@ class NodeRepository {
|
|||
DB::beginTransaction();
|
||||
|
||||
try {
|
||||
foreach($allocations as $rawIP => $ports) {
|
||||
foreach ($allocations as $rawIP => $ports) {
|
||||
try {
|
||||
$setAlias = null;
|
||||
$parsedIP = Network::parse($rawIP);
|
||||
|
@ -211,25 +207,25 @@ class NodeRepository {
|
|||
throw $ex;
|
||||
}
|
||||
}
|
||||
foreach($parsedIP as $ip) {
|
||||
foreach($ports as $port) {
|
||||
if (!is_int($port) && !preg_match('/^(\d{1,5})-(\d{1,5})$/', $port)) {
|
||||
foreach ($parsedIP as $ip) {
|
||||
foreach ($ports as $port) {
|
||||
if (! is_int($port) && ! preg_match('/^(\d{1,5})-(\d{1,5})$/', $port)) {
|
||||
throw new DisplayException('The mapping for ' . $port . ' is invalid and cannot be processed.');
|
||||
}
|
||||
if (preg_match('/^(\d{1,5})-(\d{1,5})$/', $port, $matches)) {
|
||||
foreach(range($matches[1], $matches[2]) as $assignPort) {
|
||||
foreach (range($matches[1], $matches[2]) as $assignPort) {
|
||||
$alloc = Models\Allocation::firstOrNew([
|
||||
'node' => $node->id,
|
||||
'ip' => $ip,
|
||||
'port' => $assignPort
|
||||
'port' => $assignPort,
|
||||
]);
|
||||
if (!$alloc->exists) {
|
||||
if (! $alloc->exists) {
|
||||
$alloc->fill([
|
||||
'node' => $node->id,
|
||||
'ip' => $ip,
|
||||
'port' => $assignPort,
|
||||
'ip_alias' => $setAlias,
|
||||
'assigned_to' => null
|
||||
'assigned_to' => null,
|
||||
]);
|
||||
$alloc->save();
|
||||
}
|
||||
|
@ -238,15 +234,15 @@ class NodeRepository {
|
|||
$alloc = Models\Allocation::firstOrNew([
|
||||
'node' => $node->id,
|
||||
'ip' => $ip,
|
||||
'port' => $port
|
||||
'port' => $port,
|
||||
]);
|
||||
if (!$alloc->exists) {
|
||||
if (! $alloc->exists) {
|
||||
$alloc->fill([
|
||||
'node' => $node->id,
|
||||
'ip' => $ip,
|
||||
'port' => $port,
|
||||
'ip_alias' => $setAlias,
|
||||
'assigned_to' => null
|
||||
'assigned_to' => null,
|
||||
]);
|
||||
$alloc->save();
|
||||
}
|
||||
|
@ -290,5 +286,4 @@ class NodeRepository {
|
|||
throw $ex;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>
|
||||
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -21,29 +21,25 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Repositories;
|
||||
|
||||
use Crypt;
|
||||
use DB;
|
||||
use Debugbar;
|
||||
use Validator;
|
||||
use Log;
|
||||
|
||||
use Crypt;
|
||||
use Validator;
|
||||
use Pterodactyl\Models;
|
||||
use Pterodactyl\Events\ServerDeleted;
|
||||
use Pterodactyl\Services\UuidService;
|
||||
use Pterodactyl\Services\DeploymentService;
|
||||
use Pterodactyl\Notifications\ServerCreated;
|
||||
use Pterodactyl\Events\ServerDeleted;
|
||||
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Pterodactyl\Exceptions\AccountNotFoundException;
|
||||
use Pterodactyl\Notifications\ServerCreated;
|
||||
use Pterodactyl\Exceptions\DisplayValidationException;
|
||||
|
||||
class ServerRepository
|
||||
{
|
||||
|
||||
protected $daemonPermissions = [
|
||||
's:*'
|
||||
's:*',
|
||||
];
|
||||
|
||||
public function __construct()
|
||||
|
@ -53,7 +49,7 @@ class ServerRepository
|
|||
|
||||
/**
|
||||
* Generates a SFTP username for a server given a server name.
|
||||
* format: mumble_67c7a4b0
|
||||
* format: mumble_67c7a4b0.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $uuid
|
||||
|
@ -61,16 +57,15 @@ class ServerRepository
|
|||
*/
|
||||
protected function generateSFTPUsername($name, $uuid = null)
|
||||
{
|
||||
|
||||
$uuid = is_null($uuid) ? str_random(8) : $uuid;
|
||||
return strtolower(substr(preg_replace('/\s+/', '', $name), 0, 6) . '_' . $uuid);
|
||||
|
||||
return strtolower(substr(preg_replace('/\s+/', '', $name), 0, 6) . '_' . $uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new server to the system.
|
||||
* @param array $data An array of data descriptors for creating the server. These should align to the columns in the database.
|
||||
* @return integer
|
||||
* @return int
|
||||
*/
|
||||
public function create(array $data)
|
||||
{
|
||||
|
@ -93,22 +88,21 @@ class ServerRepository
|
|||
]);
|
||||
|
||||
$validator->sometimes('node', 'bail|required|numeric|min:1|exists:nodes,id', function ($input) {
|
||||
return !($input->auto_deploy);
|
||||
return ! ($input->auto_deploy);
|
||||
});
|
||||
|
||||
$validator->sometimes('ip', 'required|ip', function ($input) {
|
||||
return (!$input->auto_deploy && !$input->allocation);
|
||||
return ! $input->auto_deploy && ! $input->allocation;
|
||||
});
|
||||
|
||||
$validator->sometimes('port', 'required|numeric|min:1|max:65535', function ($input) {
|
||||
return (!$input->auto_deploy && !$input->allocation);
|
||||
return ! $input->auto_deploy && ! $input->allocation;
|
||||
});
|
||||
|
||||
$validator->sometimes('allocation', 'numeric|exists:allocations,id', function ($input) {
|
||||
return !($input->auto_deploy || ($input->port && $input->ip));
|
||||
return ! ($input->auto_deploy || ($input->port && $input->ip));
|
||||
});
|
||||
|
||||
|
||||
// Run validator, throw catchable and displayable exception if it fails.
|
||||
// Exception includes a JSON result of failed validation rules.
|
||||
if ($validator->fails()) {
|
||||
|
@ -121,12 +115,12 @@ class ServerRepository
|
|||
$user = Models\User::select('id', 'email')->where('email', $data['owner'])->first();
|
||||
}
|
||||
|
||||
if (!$user) {
|
||||
if (! $user) {
|
||||
throw new DisplayException('The user id or email passed to the function was not found on the system.');
|
||||
}
|
||||
|
||||
$autoDeployed = false;
|
||||
if (isset($data['auto_deploy']) && in_array($data['auto_deploy'], [true, 1, "1"])) {
|
||||
if (isset($data['auto_deploy']) && in_array($data['auto_deploy'], [true, 1, '1'])) {
|
||||
// This is an auto-deployment situation
|
||||
// Ignore any other passed node data
|
||||
unset($data['node'], $data['ip'], $data['port'], $data['allocation']);
|
||||
|
@ -140,16 +134,16 @@ class ServerRepository
|
|||
|
||||
// Verify IP & Port are a.) free and b.) assigned to the node.
|
||||
// We know the node exists because of 'exists:nodes,id' in the validation
|
||||
if (!$autoDeployed) {
|
||||
if (!isset($data['allocation'])) {
|
||||
if (! $autoDeployed) {
|
||||
if (! isset($data['allocation'])) {
|
||||
$allocation = Models\Allocation::where('ip', $data['ip'])->where('port', $data['port'])->where('node', $data['node'])->whereNull('assigned_to')->first();
|
||||
} else {
|
||||
$allocation = Models\Allocation::where('id' , $data['allocation'])->where('node', $data['node'])->whereNull('assigned_to')->first();
|
||||
$allocation = Models\Allocation::where('id', $data['allocation'])->where('node', $data['node'])->whereNull('assigned_to')->first();
|
||||
}
|
||||
}
|
||||
|
||||
// Something failed in the query, either that combo doesn't exist, or it is in use.
|
||||
if (!$allocation) {
|
||||
if (! $allocation) {
|
||||
throw new DisplayException('The selected IP/Port combination or Allocation ID is either already in use, or unavaliable for this node.');
|
||||
}
|
||||
|
||||
|
@ -158,7 +152,7 @@ class ServerRepository
|
|||
// We need to verify that the option exists for the service, and then check for
|
||||
// any required variable fields. (fields are labeled env_<env_variable>)
|
||||
$option = Models\ServiceOptions::where('id', $data['option'])->where('parent_service', $data['service'])->first();
|
||||
if (!$option) {
|
||||
if (! $option) {
|
||||
throw new DisplayException('The requested service option does not exist for the specified service.');
|
||||
}
|
||||
|
||||
|
@ -169,46 +163,45 @@ class ServerRepository
|
|||
$variables = Models\ServiceVariables::where('option_id', $data['option'])->get();
|
||||
$variableList = [];
|
||||
if ($variables) {
|
||||
foreach($variables as $variable) {
|
||||
foreach ($variables as $variable) {
|
||||
|
||||
// Is the variable required?
|
||||
if (!$data['env_' . $variable->env_variable]) {
|
||||
if (! $data['env_' . $variable->env_variable]) {
|
||||
if ($variable->required === 1) {
|
||||
throw new DisplayException('A required service option variable field (env_' . $variable->env_variable . ') was missing from the request.');
|
||||
}
|
||||
$variableList = array_merge($variableList, [[
|
||||
'id' => $variable->id,
|
||||
'env' => $variable->env_variable,
|
||||
'val' => $variable->default_value
|
||||
'val' => $variable->default_value,
|
||||
]]);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check aganist Regex Pattern
|
||||
if (!is_null($variable->regex) && !preg_match($variable->regex, $data['env_' . $variable->env_variable])) {
|
||||
if (! is_null($variable->regex) && ! preg_match($variable->regex, $data['env_' . $variable->env_variable])) {
|
||||
throw new DisplayException('Failed to validate service option variable field (env_' . $variable->env_variable . ') aganist regex (' . $variable->regex . ').');
|
||||
}
|
||||
|
||||
$variableList = array_merge($variableList, [[
|
||||
'id' => $variable->id,
|
||||
'env' => $variable->env_variable,
|
||||
'val' => $data['env_' . $variable->env_variable]
|
||||
'val' => $data['env_' . $variable->env_variable],
|
||||
]]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Check Overallocation
|
||||
if (!$autoDeployed) {
|
||||
if (! $autoDeployed) {
|
||||
if (is_numeric($node->memory_overallocate) || is_numeric($node->disk_overallocate)) {
|
||||
|
||||
$totals = Models\Server::select(DB::raw('SUM(memory) as memory, SUM(disk) as disk'))->where('node', $node->id)->first();
|
||||
|
||||
// Check memory limits
|
||||
if (is_numeric($node->memory_overallocate)) {
|
||||
$newMemory = $totals->memory + $data['memory'];
|
||||
$memoryLimit = ($node->memory * (1 + ($node->memory_overallocate / 100)));
|
||||
if($newMemory > $memoryLimit) {
|
||||
if ($newMemory > $memoryLimit) {
|
||||
throw new DisplayException('The amount of memory allocated to this server would put the node over its allocation limits. This node is allowed ' . ($node->memory_overallocate + 100) . '% of its assigned ' . $node->memory . 'Mb of memory (' . $memoryLimit . 'Mb) of which ' . (($totals->memory / $node->memory) * 100) . '% (' . $totals->memory . 'Mb) is in use already. By allocating this server the node would be at ' . (($newMemory / $node->memory) * 100) . '% (' . $newMemory . 'Mb) usage.');
|
||||
}
|
||||
}
|
||||
|
@ -217,7 +210,7 @@ class ServerRepository
|
|||
if (is_numeric($node->disk_overallocate)) {
|
||||
$newDisk = $totals->disk + $data['disk'];
|
||||
$diskLimit = ($node->disk * (1 + ($node->disk_overallocate / 100)));
|
||||
if($newDisk > $diskLimit) {
|
||||
if ($newDisk > $diskLimit) {
|
||||
throw new DisplayException('The amount of disk allocated to this server would put the node over its allocation limits. This node is allowed ' . ($node->disk_overallocate + 100) . '% of its assigned ' . $node->disk . 'Mb of disk (' . $diskLimit . 'Mb) of which ' . (($totals->disk / $node->disk) * 100) . '% (' . $totals->disk . 'Mb) is in use already. By allocating this server the node would be at ' . (($newDisk / $node->disk) * 100) . '% (' . $newDisk . 'Mb) usage.');
|
||||
}
|
||||
}
|
||||
|
@ -233,7 +226,7 @@ class ServerRepository
|
|||
$server = new Models\Server;
|
||||
$genUuid = $uuid->generate('servers', 'uuid');
|
||||
$genShortUuid = $uuid->generateShort('servers', 'uuidShort', $genUuid);
|
||||
|
||||
|
||||
if (isset($data['custom_id'])) {
|
||||
$server->id = $data['custom_id'];
|
||||
}
|
||||
|
@ -258,7 +251,7 @@ class ServerRepository
|
|||
'daemonSecret' => $uuid->generate('servers', 'daemonSecret'),
|
||||
'image' => (isset($data['custom_image_name'])) ? $data['custom_image_name'] : $option->docker_image,
|
||||
'username' => $this->generateSFTPUsername($data['name'], $genShortUuid),
|
||||
'sftp_password' => Crypt::encrypt('not set')
|
||||
'sftp_password' => Crypt::encrypt('not set'),
|
||||
]);
|
||||
$server->save();
|
||||
|
||||
|
@ -269,16 +262,16 @@ class ServerRepository
|
|||
// Add Variables
|
||||
$environmentVariables = [];
|
||||
$environmentVariables = array_merge($environmentVariables, [
|
||||
'STARTUP' => $data['startup']
|
||||
'STARTUP' => $data['startup'],
|
||||
]);
|
||||
foreach($variableList as $item) {
|
||||
foreach ($variableList as $item) {
|
||||
$environmentVariables = array_merge($environmentVariables, [
|
||||
$item['env'] => $item['val']
|
||||
$item['env'] => $item['val'],
|
||||
]);
|
||||
Models\ServerVariables::create([
|
||||
'server_id' => $server->id,
|
||||
'variable_id' => $item['id'],
|
||||
'variable_value' => $item['val']
|
||||
'variable_value' => $item['val'],
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -289,13 +282,13 @@ class ServerRepository
|
|||
'node' => $node->name,
|
||||
'service' => $service->name,
|
||||
'option' => $option->name,
|
||||
'uuidShort' => $server->uuidShort
|
||||
'uuidShort' => $server->uuidShort,
|
||||
])));
|
||||
|
||||
$client = Models\Node::guzzleRequest($node->id);
|
||||
$client->request('POST', '/servers', [
|
||||
'headers' => [
|
||||
'X-Access-Token' => $node->daemonSecret
|
||||
'X-Access-Token' => $node->daemonSecret,
|
||||
],
|
||||
'json' => [
|
||||
'uuid' => (string) $server->uuid,
|
||||
|
@ -303,10 +296,10 @@ class ServerRepository
|
|||
'build' => [
|
||||
'default' => [
|
||||
'ip' => $allocation->ip,
|
||||
'port' => (int) $allocation->port
|
||||
'port' => (int) $allocation->port,
|
||||
],
|
||||
'ports' => [
|
||||
(string) $allocation->ip => [ (int) $allocation->port ]
|
||||
(string) $allocation->ip => [(int) $allocation->port],
|
||||
],
|
||||
'env' => $environmentVariables,
|
||||
'memory' => (int) $server->memory,
|
||||
|
@ -314,20 +307,21 @@ class ServerRepository
|
|||
'io' => (int) $server->io,
|
||||
'cpu' => (int) $server->cpu,
|
||||
'disk' => (int) $server->disk,
|
||||
'image' => (isset($data['custom_image_name'])) ? $data['custom_image_name'] : $option->docker_image
|
||||
'image' => (isset($data['custom_image_name'])) ? $data['custom_image_name'] : $option->docker_image,
|
||||
],
|
||||
'service' => [
|
||||
'type' => $service->file,
|
||||
'option' => $option->tag
|
||||
'option' => $option->tag,
|
||||
],
|
||||
'keys' => [
|
||||
(string) $server->daemonSecret => $this->daemonPermissions
|
||||
(string) $server->daemonSecret => $this->daemonPermissions,
|
||||
],
|
||||
'rebuild' => false
|
||||
]
|
||||
'rebuild' => false,
|
||||
],
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return $server->id;
|
||||
} catch (\GuzzleHttp\Exception\TransferException $ex) {
|
||||
DB::rollBack();
|
||||
|
@ -336,25 +330,23 @@ class ServerRepository
|
|||
DB::rollBack();
|
||||
throw $ex;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* [updateDetails description]
|
||||
* @param integer $id
|
||||
* [updateDetails description].
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function updateDetails($id, array $data)
|
||||
{
|
||||
|
||||
$uuid = new UuidService;
|
||||
$resetDaemonKey = false;
|
||||
|
||||
// Validate Fields
|
||||
$validator = Validator::make($data, [
|
||||
'owner' => 'email|exists:users,email',
|
||||
'name' => 'regex:([\w -]{4,35})'
|
||||
'name' => 'regex:([\w -]{4,35})',
|
||||
]);
|
||||
|
||||
// Run validator, throw catchable and displayable exception if it fails.
|
||||
|
@ -391,8 +383,9 @@ class ServerRepository
|
|||
$server->save();
|
||||
|
||||
// Do we need to update? If not, return successful.
|
||||
if (!$resetDaemonKey) {
|
||||
if (! $resetDaemonKey) {
|
||||
DB::commit();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -403,19 +396,20 @@ class ServerRepository
|
|||
$res = $client->request('PATCH', '/server', [
|
||||
'headers' => [
|
||||
'X-Access-Server' => $server->uuid,
|
||||
'X-Access-Token' => $node->daemonSecret
|
||||
'X-Access-Token' => $node->daemonSecret,
|
||||
],
|
||||
'exceptions' => false,
|
||||
'json' => [
|
||||
'keys' => [
|
||||
(string) $oldDaemonKey => [],
|
||||
(string) $server->daemonSecret => $this->daemonPermissions
|
||||
]
|
||||
]
|
||||
(string) $server->daemonSecret => $this->daemonPermissions,
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
if ($res->getStatusCode() === 204) {
|
||||
DB::commit();
|
||||
|
||||
return true;
|
||||
} else {
|
||||
throw new DisplayException('Daemon returned a a non HTTP/204 error code. HTTP/' + $res->getStatusCode());
|
||||
|
@ -425,11 +419,10 @@ class ServerRepository
|
|||
Log::error($ex);
|
||||
throw new DisplayException('An error occured while attempting to update this server\'s information.');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* [updateContainer description]
|
||||
* [updateContainer description].
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
* @return bool
|
||||
|
@ -437,7 +430,7 @@ class ServerRepository
|
|||
public function updateContainer($id, array $data)
|
||||
{
|
||||
$validator = Validator::make($data, [
|
||||
'image' => 'required|string'
|
||||
'image' => 'required|string',
|
||||
]);
|
||||
|
||||
// Run validator, throw catchable and displayable exception if it fails.
|
||||
|
@ -459,16 +452,17 @@ class ServerRepository
|
|||
$client->request('PATCH', '/server', [
|
||||
'headers' => [
|
||||
'X-Access-Server' => $server->uuid,
|
||||
'X-Access-Token' => $node->daemonSecret
|
||||
'X-Access-Token' => $node->daemonSecret,
|
||||
],
|
||||
'json' => [
|
||||
'build' => [
|
||||
'image' => $server->image
|
||||
]
|
||||
]
|
||||
'image' => $server->image,
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return true;
|
||||
} catch (\GuzzleHttp\Exception\TransferException $ex) {
|
||||
DB::rollBack();
|
||||
|
@ -477,22 +471,20 @@ class ServerRepository
|
|||
DB::rollBack();
|
||||
throw $ex;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* [changeBuild description]
|
||||
* @param integer $id
|
||||
* [changeBuild description].
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function changeBuild($id, array $data)
|
||||
{
|
||||
|
||||
$validator = Validator::make($data, [
|
||||
'default' => [
|
||||
'string',
|
||||
'regex:/^(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))\.(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))\.(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))\.(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5])):(\d{1,5})$/'
|
||||
'regex:/^(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))\.(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))\.(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))\.(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5])):(\d{1,5})$/',
|
||||
],
|
||||
'add_additional' => 'nullable|array',
|
||||
'remove_additional' => 'nullable|array',
|
||||
|
@ -500,7 +492,7 @@ class ServerRepository
|
|||
'swap' => 'integer|min:-1',
|
||||
'io' => 'integer|min:10|max:1000',
|
||||
'cpu' => 'integer|min:0',
|
||||
'disk' => 'integer|min:0'
|
||||
'disk' => 'integer|min:0',
|
||||
]);
|
||||
|
||||
// Run validator, throw catchable and displayable exception if it fails.
|
||||
|
@ -521,14 +513,14 @@ class ServerRepository
|
|||
list($ip, $port) = explode(':', $data['default']);
|
||||
if ($ip !== $allocation->ip || (int) $port !== $allocation->port) {
|
||||
$selection = Models\Allocation::where('ip', $ip)->where('port', $port)->where('assigned_to', $server->id)->first();
|
||||
if (!$selection) {
|
||||
if (! $selection) {
|
||||
throw new DisplayException('The requested default connection (' . $ip . ':' . $port . ') is not allocated to this server.');
|
||||
}
|
||||
|
||||
$server->allocation = $selection->id;
|
||||
$newBuild['default'] = [
|
||||
'ip' => $ip,
|
||||
'port' => (int) $port
|
||||
'port' => (int) $port,
|
||||
];
|
||||
|
||||
// Re-Run to keep updated for rest of function
|
||||
|
@ -542,7 +534,7 @@ class ServerRepository
|
|||
foreach ($data['remove_additional'] as $id => $combo) {
|
||||
list($ip, $port) = explode(':', $combo);
|
||||
// Invalid, not worth killing the whole thing, we'll just skip over it.
|
||||
if (!filter_var($ip, FILTER_VALIDATE_IP) || !preg_match('/^(\d{1,5})$/', $port)) {
|
||||
if (! filter_var($ip, FILTER_VALIDATE_IP) || ! preg_match('/^(\d{1,5})$/', $port)) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -553,7 +545,7 @@ class ServerRepository
|
|||
|
||||
$newPorts = true;
|
||||
Models\Allocation::where('ip', $ip)->where('port', $port)->where('assigned_to', $server->id)->update([
|
||||
'assigned_to' => null
|
||||
'assigned_to' => null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -563,7 +555,7 @@ class ServerRepository
|
|||
foreach ($data['add_additional'] as $id => $combo) {
|
||||
list($ip, $port) = explode(':', $combo);
|
||||
// Invalid, not worth killing the whole thing, we'll just skip over it.
|
||||
if (!filter_var($ip, FILTER_VALIDATE_IP) || !preg_match('/^(\d{1,5})$/', $port)) {
|
||||
if (! filter_var($ip, FILTER_VALIDATE_IP) || ! preg_match('/^(\d{1,5})$/', $port)) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -574,7 +566,7 @@ class ServerRepository
|
|||
|
||||
$newPorts = true;
|
||||
Models\Allocation::where('ip', $ip)->where('port', $port)->whereNull('assigned_to')->update([
|
||||
'assigned_to' => $server->id
|
||||
'assigned_to' => $server->id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -584,9 +576,9 @@ class ServerRepository
|
|||
$assignments = Models\Allocation::where('assigned_to', $server->id)->get();
|
||||
foreach ($assignments as &$assignment) {
|
||||
if (array_key_exists((string) $assignment->ip, $additionalAssignments)) {
|
||||
array_push($additionalAssignments[ (string) $assignment->ip ], (int) $assignment->port);
|
||||
array_push($additionalAssignments[(string) $assignment->ip], (int) $assignment->port);
|
||||
} else {
|
||||
$additionalAssignments[ (string) $assignment->ip ] = [ (int) $assignment->port ];
|
||||
$additionalAssignments[(string) $assignment->ip] = [(int) $assignment->port];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -627,22 +619,23 @@ class ServerRepository
|
|||
// This won't be committed unless the HTTP request succeedes anyways
|
||||
$server->save();
|
||||
|
||||
if (!empty($newBuild)) {
|
||||
if (! empty($newBuild)) {
|
||||
$node = Models\Node::getByID($server->node);
|
||||
$client = Models\Node::guzzleRequest($server->node);
|
||||
|
||||
$client->request('PATCH', '/server', [
|
||||
'headers' => [
|
||||
'X-Access-Server' => $server->uuid,
|
||||
'X-Access-Token' => $node->daemonSecret
|
||||
'X-Access-Token' => $node->daemonSecret,
|
||||
],
|
||||
'json' => [
|
||||
'build' => $newBuild
|
||||
]
|
||||
'build' => $newBuild,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
|
||||
return true;
|
||||
} catch (\GuzzleHttp\Exception\TransferException $ex) {
|
||||
DB::rollBack();
|
||||
|
@ -651,12 +644,10 @@ class ServerRepository
|
|||
DB::rollBack();
|
||||
throw $ex;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function updateStartup($id, array $data, $admin = false)
|
||||
{
|
||||
|
||||
$server = Models\Server::findOrFail($id);
|
||||
|
||||
DB::beginTransaction();
|
||||
|
@ -678,13 +669,13 @@ class ServerRepository
|
|||
|
||||
$variableList = [];
|
||||
if ($variables) {
|
||||
foreach($variables as &$variable) {
|
||||
foreach ($variables as &$variable) {
|
||||
// Move on if the new data wasn't even sent
|
||||
if (!isset($data[$variable->env_variable])) {
|
||||
if (! isset($data[$variable->env_variable])) {
|
||||
$variableList = array_merge($variableList, [[
|
||||
'id' => $variable->id,
|
||||
'env' => $variable->env_variable,
|
||||
'val' => $variable->a_currentValue
|
||||
'val' => $variable->a_currentValue,
|
||||
]]);
|
||||
continue;
|
||||
}
|
||||
|
@ -694,7 +685,7 @@ class ServerRepository
|
|||
$variableList = array_merge($variableList, [[
|
||||
'id' => $variable->id,
|
||||
'env' => $variable->env_variable,
|
||||
'val' => null
|
||||
'val' => null,
|
||||
]]);
|
||||
continue;
|
||||
}
|
||||
|
@ -708,19 +699,19 @@ class ServerRepository
|
|||
}
|
||||
|
||||
// Variable hidden and/or not user editable
|
||||
if (($variable->user_viewable === 0 || $variable->user_editable === 0) && !$admin) {
|
||||
if (($variable->user_viewable === 0 || $variable->user_editable === 0) && ! $admin) {
|
||||
throw new DisplayException('A service option variable field (' . $variable->env_variable . ') does not exist or you do not have permission to edit it.');
|
||||
}
|
||||
|
||||
// Check aganist Regex Pattern
|
||||
if (!is_null($variable->regex) && !preg_match($variable->regex, $data[$variable->env_variable])) {
|
||||
if (! is_null($variable->regex) && ! preg_match($variable->regex, $data[$variable->env_variable])) {
|
||||
throw new DisplayException('Failed to validate service option variable field (' . $variable->env_variable . ') aganist regex (' . $variable->regex . ').');
|
||||
}
|
||||
|
||||
$variableList = array_merge($variableList, [[
|
||||
'id' => $variable->id,
|
||||
'env' => $variable->env_variable,
|
||||
'val' => $data[$variable->env_variable]
|
||||
'val' => $data[$variable->env_variable],
|
||||
]]);
|
||||
}
|
||||
}
|
||||
|
@ -728,17 +719,17 @@ class ServerRepository
|
|||
// Add Variables
|
||||
$environmentVariables = [];
|
||||
$environmentVariables = array_merge($environmentVariables, [
|
||||
'STARTUP' => $server->startup
|
||||
'STARTUP' => $server->startup,
|
||||
]);
|
||||
foreach($variableList as $item) {
|
||||
foreach ($variableList as $item) {
|
||||
$environmentVariables = array_merge($environmentVariables, [
|
||||
$item['env'] => $item['val']
|
||||
$item['env'] => $item['val'],
|
||||
]);
|
||||
|
||||
// Update model or make a new record if it doesn't exist.
|
||||
$model = Models\ServerVariables::firstOrNew([
|
||||
'variable_id' => $item['id'],
|
||||
'server_id' => $server->id
|
||||
'server_id' => $server->id,
|
||||
]);
|
||||
$model->variable_value = $item['val'];
|
||||
$model->save();
|
||||
|
@ -750,16 +741,17 @@ class ServerRepository
|
|||
$client->request('PATCH', '/server', [
|
||||
'headers' => [
|
||||
'X-Access-Server' => $server->uuid,
|
||||
'X-Access-Token' => $node->daemonSecret
|
||||
'X-Access-Token' => $node->daemonSecret,
|
||||
],
|
||||
'json' => [
|
||||
'build' => [
|
||||
'env|overwrite' => $environmentVariables
|
||||
]
|
||||
]
|
||||
'env|overwrite' => $environmentVariables,
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return true;
|
||||
} catch (\GuzzleHttp\Exception\TransferException $ex) {
|
||||
DB::rollBack();
|
||||
|
@ -768,7 +760,6 @@ class ServerRepository
|
|||
DB::rollBack();
|
||||
throw $ex;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function deleteServer($id, $force)
|
||||
|
@ -792,13 +783,14 @@ class ServerRepository
|
|||
}
|
||||
}
|
||||
|
||||
public function deleteNow($id, $force = false) {
|
||||
public function deleteNow($id, $force = false)
|
||||
{
|
||||
$server = Models\Server::withTrashed()->findOrFail($id);
|
||||
$node = Models\Node::findOrFail($server->node);
|
||||
|
||||
// Handle server being restored previously or
|
||||
// an accidental queue.
|
||||
if (!$server->trashed()) {
|
||||
if (! $server->trashed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -806,7 +798,7 @@ class ServerRepository
|
|||
try {
|
||||
// Unassign Allocations
|
||||
Models\Allocation::where('assigned_to', $server->id)->update([
|
||||
'assigned_to' => null
|
||||
'assigned_to' => null,
|
||||
]);
|
||||
|
||||
// Remove Variables
|
||||
|
@ -828,7 +820,7 @@ class ServerRepository
|
|||
// This is the one un-recoverable point where
|
||||
// transactions will not save us.
|
||||
$repository = new DatabaseRepository;
|
||||
foreach(Models\Database::select('id')->where('server_id', $server->id)->get() as &$database) {
|
||||
foreach (Models\Database::select('id')->where('server_id', $server->id)->get() as &$database) {
|
||||
$repository->drop($database->id);
|
||||
}
|
||||
|
||||
|
@ -836,8 +828,8 @@ class ServerRepository
|
|||
$client->request('DELETE', '/servers', [
|
||||
'headers' => [
|
||||
'X-Access-Token' => $node->daemonSecret,
|
||||
'X-Access-Server' => $server->uuid
|
||||
]
|
||||
'X-Access-Server' => $server->uuid,
|
||||
],
|
||||
]);
|
||||
|
||||
$server->forceDelete();
|
||||
|
@ -873,13 +865,14 @@ class ServerRepository
|
|||
throw new DisplayException('This server was marked as having a failed install, you cannot override this.');
|
||||
}
|
||||
$server->installed = ($server->installed === 1) ? 0 : 1;
|
||||
|
||||
return $server->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Suspends a server instance making it unable to be booted or used by a user.
|
||||
* @param integer $id
|
||||
* @return boolean
|
||||
* @param int $id
|
||||
* @return bool
|
||||
*/
|
||||
public function suspend($id, $deleted = false)
|
||||
{
|
||||
|
@ -902,8 +895,8 @@ class ServerRepository
|
|||
$client->request('POST', '/server/suspend', [
|
||||
'headers' => [
|
||||
'X-Access-Token' => $node->daemonSecret,
|
||||
'X-Access-Server' => $server->uuid
|
||||
]
|
||||
'X-Access-Server' => $server->uuid,
|
||||
],
|
||||
]);
|
||||
|
||||
return DB::commit();
|
||||
|
@ -918,8 +911,8 @@ class ServerRepository
|
|||
|
||||
/**
|
||||
* Unsuspends a server instance.
|
||||
* @param integer $id
|
||||
* @return boolean
|
||||
* @param int $id
|
||||
* @return bool
|
||||
*/
|
||||
public function unsuspend($id)
|
||||
{
|
||||
|
@ -942,8 +935,8 @@ class ServerRepository
|
|||
$client->request('POST', '/server/unsuspend', [
|
||||
'headers' => [
|
||||
'X-Access-Token' => $node->daemonSecret,
|
||||
'X-Access-Server' => $server->uuid
|
||||
]
|
||||
'X-Access-Server' => $server->uuid,
|
||||
],
|
||||
]);
|
||||
|
||||
return DB::commit();
|
||||
|
@ -964,7 +957,7 @@ class ServerRepository
|
|||
$validator = Validator::make([
|
||||
'password' => $password,
|
||||
], [
|
||||
'password' => 'required|regex:/^((?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,})$/'
|
||||
'password' => 'required|regex:/^((?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,})$/',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
|
@ -981,7 +974,7 @@ class ServerRepository
|
|||
$client->request('POST', '/server/password', [
|
||||
'headers' => [
|
||||
'X-Access-Token' => $node->daemonSecret,
|
||||
'X-Access-Server' => $server->uuid
|
||||
'X-Access-Server' => $server->uuid,
|
||||
],
|
||||
'json' => [
|
||||
'password' => $password,
|
||||
|
@ -989,6 +982,7 @@ class ServerRepository
|
|||
]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return true;
|
||||
} catch (\GuzzleHttp\Exception\TransferException $ex) {
|
||||
DB::rollBack();
|
||||
|
@ -997,7 +991,5 @@ class ServerRepository
|
|||
DB::rollBack();
|
||||
throw $ex;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>
|
||||
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -21,20 +21,17 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Repositories\ServiceRepository;
|
||||
|
||||
use DB;
|
||||
use Validator;
|
||||
|
||||
use Pterodactyl\Models;
|
||||
use Pterodactyl\Services\UuidService;
|
||||
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Pterodactyl\Exceptions\DisplayValidationException;
|
||||
|
||||
class Option
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
|
@ -50,7 +47,7 @@ class Option
|
|||
'tag' => 'required|string|max:255',
|
||||
'executable' => 'sometimes|string|max:255',
|
||||
'docker_image' => 'required|string|max:255',
|
||||
'startup' => 'sometimes|string'
|
||||
'startup' => 'sometimes|string',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
|
@ -105,7 +102,7 @@ class Option
|
|||
'tag' => 'sometimes|required|string|max:255',
|
||||
'executable' => 'sometimes|string|max:255',
|
||||
'docker_image' => 'sometimes|required|string|max:255',
|
||||
'startup' => 'sometimes|string'
|
||||
'startup' => 'sometimes|string',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
|
@ -123,5 +120,4 @@ class Option
|
|||
$option->fill($data);
|
||||
$option->save();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>
|
||||
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -21,21 +21,18 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Repositories\ServiceRepository;
|
||||
|
||||
use DB;
|
||||
use Validator;
|
||||
use Uuid;
|
||||
|
||||
use Validator;
|
||||
use Pterodactyl\Models;
|
||||
use Pterodactyl\Services\UuidService;
|
||||
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Pterodactyl\Exceptions\DisplayValidationException;
|
||||
|
||||
class Service
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
|
@ -48,7 +45,7 @@ class Service
|
|||
'description' => 'required|string',
|
||||
'file' => 'required|regex:/^[\w.-]{1,50}$/',
|
||||
'executable' => 'max:255|regex:/^(.*)$/',
|
||||
'startup' => 'string'
|
||||
'startup' => 'string',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
|
@ -77,7 +74,7 @@ class Service
|
|||
'description' => 'sometimes|required|string',
|
||||
'file' => 'sometimes|required|regex:/^[\w.-]{1,50}$/',
|
||||
'executable' => 'sometimes|max:255|regex:/^(.*)$/',
|
||||
'startup' => 'sometimes|string'
|
||||
'startup' => 'sometimes|string',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
|
@ -109,5 +106,4 @@ class Service
|
|||
throw $ex;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>
|
||||
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -21,20 +21,17 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Repositories\ServiceRepository;
|
||||
|
||||
use DB;
|
||||
use Validator;
|
||||
|
||||
use Pterodactyl\Models;
|
||||
use Pterodactyl\Services\UuidService;
|
||||
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Pterodactyl\Exceptions\DisplayValidationException;
|
||||
|
||||
class Variable
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
|
@ -52,14 +49,14 @@ class Variable
|
|||
'user_viewable' => 'sometimes|required|numeric|size:1',
|
||||
'user_editable' => 'sometimes|required|numeric|size:1',
|
||||
'required' => 'sometimes|required|numeric|size:1',
|
||||
'regex' => 'required|string|min:1'
|
||||
'regex' => 'required|string|min:1',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
throw new DisplayValidationException($validator->errors());
|
||||
}
|
||||
|
||||
if ($data['default_value'] !== '' && !preg_match($data['regex'], $data['default_value'])) {
|
||||
if ($data['default_value'] !== '' && ! preg_match($data['regex'], $data['default_value'])) {
|
||||
throw new DisplayException('The default value you entered cannot violate the regex requirements.');
|
||||
}
|
||||
|
||||
|
@ -77,7 +74,8 @@ class Variable
|
|||
$variable->save();
|
||||
}
|
||||
|
||||
public function delete($id) {
|
||||
public function delete($id)
|
||||
{
|
||||
$variable = Models\ServiceVariables::findOrFail($id);
|
||||
|
||||
DB::beginTransaction();
|
||||
|
@ -104,7 +102,7 @@ class Variable
|
|||
'user_viewable' => 'sometimes|required|numeric|boolean',
|
||||
'user_editable' => 'sometimes|required|numeric|boolean',
|
||||
'required' => 'sometimes|required|numeric|boolean',
|
||||
'regex' => 'sometimes|required|string|min:1'
|
||||
'regex' => 'sometimes|required|string|min:1',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
|
@ -114,7 +112,7 @@ class Variable
|
|||
$data['default_value'] = (isset($data['default_value'])) ? $data['default_value'] : $variable->default_value;
|
||||
$data['regex'] = (isset($data['regex'])) ? $data['regex'] : $variable->regex;
|
||||
|
||||
if ($data['default_value'] !== '' && !preg_match($data['regex'], $data['default_value'])) {
|
||||
if ($data['default_value'] !== '' && ! preg_match($data['regex'], $data['default_value'])) {
|
||||
throw new DisplayException('The default value you entered cannot violate the regex requirements.');
|
||||
}
|
||||
|
||||
|
@ -129,5 +127,4 @@ class Variable
|
|||
$variable->fill($data);
|
||||
$variable->save();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>
|
||||
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -21,23 +21,20 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Repositories;
|
||||
|
||||
use DB;
|
||||
use Mail;
|
||||
use Settings;
|
||||
use Validator;
|
||||
use Mail;
|
||||
|
||||
use Pterodactyl\Models;
|
||||
use Pterodactyl\Repositories\UserRepository;
|
||||
use Pterodactyl\Services\UuidService;
|
||||
|
||||
use Pterodactyl\Exceptions\DisplayValidationException;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Pterodactyl\Exceptions\DisplayValidationException;
|
||||
|
||||
class SubuserRepository
|
||||
{
|
||||
|
||||
/**
|
||||
* Core permissions required for every subuser on the daemon.
|
||||
* Without this we cannot connect the websocket or get basic
|
||||
|
@ -46,7 +43,7 @@ class SubuserRepository
|
|||
*/
|
||||
protected $coreDaemonPermissions = [
|
||||
's:get',
|
||||
's:console'
|
||||
's:console',
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -101,7 +98,7 @@ class SubuserRepository
|
|||
|
||||
// Databases
|
||||
'view-databases' => null,
|
||||
'reset-db-password' => null
|
||||
'reset-db-password' => null,
|
||||
];
|
||||
|
||||
public function __construct()
|
||||
|
@ -111,18 +108,18 @@ class SubuserRepository
|
|||
|
||||
/**
|
||||
* Creates a new subuser on the server.
|
||||
* @param integer $id The ID of the server to add this subuser to.
|
||||
* @param int $id The ID of the server to add this subuser to.
|
||||
* @param array $data
|
||||
* @throws DisplayValidationException
|
||||
* @throws DisplayException
|
||||
* @return integer Returns the ID of the newly created subuser.
|
||||
* @return int Returns the ID of the newly created subuser.
|
||||
*/
|
||||
public function create($sid, array $data)
|
||||
{
|
||||
$server = Models\Server::findOrFail($sid);
|
||||
$validator = Validator::make($data, [
|
||||
'permissions' => 'required|array',
|
||||
'email' => 'required|email'
|
||||
'email' => 'required|email',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
|
@ -134,7 +131,7 @@ class SubuserRepository
|
|||
try {
|
||||
// Determine if this user exists or if we need to make them an account.
|
||||
$user = Models\User::where('email', $data['email'])->first();
|
||||
if (!$user) {
|
||||
if (! $user) {
|
||||
$password = str_random(16);
|
||||
try {
|
||||
$repo = new UserRepository;
|
||||
|
@ -151,22 +148,22 @@ class SubuserRepository
|
|||
$subuser->fill([
|
||||
'user_id' => $user->id,
|
||||
'server_id' => $server->id,
|
||||
'daemonSecret' => (string) $uuid->generate('servers', 'uuid')
|
||||
'daemonSecret' => (string) $uuid->generate('servers', 'uuid'),
|
||||
]);
|
||||
$subuser->save();
|
||||
|
||||
$daemonPermissions = $this->coreDaemonPermissions;
|
||||
foreach($data['permissions'] as $permission) {
|
||||
foreach ($data['permissions'] as $permission) {
|
||||
if (array_key_exists($permission, $this->permissions)) {
|
||||
// Build the daemon permissions array for sending.
|
||||
if (!is_null($this->permissions[$permission])) {
|
||||
if (! is_null($this->permissions[$permission])) {
|
||||
array_push($daemonPermissions, $this->permissions[$permission]);
|
||||
}
|
||||
$model = new Models\Permission;
|
||||
$model->fill([
|
||||
'user_id' => $user->id,
|
||||
'server_id' => $server->id,
|
||||
'permission' => $permission
|
||||
'permission' => $permission,
|
||||
]);
|
||||
$model->save();
|
||||
}
|
||||
|
@ -182,13 +179,13 @@ class SubuserRepository
|
|||
$res = $client->request('PATCH', '/server', [
|
||||
'headers' => [
|
||||
'X-Access-Server' => $server->uuid,
|
||||
'X-Access-Token' => $node->daemonSecret
|
||||
'X-Access-Token' => $node->daemonSecret,
|
||||
],
|
||||
'json' => [
|
||||
'keys' => [
|
||||
$subuser->daemonSecret => $daemonPermissions
|
||||
]
|
||||
]
|
||||
$subuser->daemonSecret => $daemonPermissions,
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$email = $data['email'];
|
||||
|
@ -201,6 +198,7 @@ class SubuserRepository
|
|||
$message->subject(Settings::get('company') . ' - Added to Server');
|
||||
});
|
||||
DB::commit();
|
||||
|
||||
return $subuser->id;
|
||||
} catch (\GuzzleHttp\Exception\TransferException $ex) {
|
||||
DB::rollBack();
|
||||
|
@ -209,12 +207,13 @@ class SubuserRepository
|
|||
DB::rollBack();
|
||||
throw $ex;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Revokes a users permissions on a server.
|
||||
* @param integer $id The ID of the subuser row in MySQL.
|
||||
* @param int $id The ID of the subuser row in MySQL.
|
||||
* @param array $data
|
||||
* @throws DisplayValidationException
|
||||
* @throws DisplayException
|
||||
|
@ -236,17 +235,18 @@ class SubuserRepository
|
|||
$res = $client->request('PATCH', '/server', [
|
||||
'headers' => [
|
||||
'X-Access-Server' => $server->uuid,
|
||||
'X-Access-Token' => $node->daemonSecret
|
||||
'X-Access-Token' => $node->daemonSecret,
|
||||
],
|
||||
'json' => [
|
||||
'keys' => [
|
||||
$subuser->daemonSecret => []
|
||||
]
|
||||
]
|
||||
$subuser->daemonSecret => [],
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$subuser->delete();
|
||||
DB::commit();
|
||||
|
||||
return true;
|
||||
} catch (\GuzzleHttp\Exception\TransferException $ex) {
|
||||
DB::rollBack();
|
||||
|
@ -255,12 +255,13 @@ class SubuserRepository
|
|||
DB::rollBack();
|
||||
throw $ex;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates permissions for a given subuser.
|
||||
* @param integer $id The ID of the subuser row in MySQL. (Not the user ID)
|
||||
* @param int $id The ID of the subuser row in MySQL. (Not the user ID)
|
||||
* @param array $data
|
||||
* @throws DisplayValidationException
|
||||
* @throws DisplayException
|
||||
|
@ -287,17 +288,17 @@ class SubuserRepository
|
|||
Models\Permission::where('user_id', $subuser->user_id)->where('server_id', $subuser->server_id)->delete();
|
||||
|
||||
$daemonPermissions = $this->coreDaemonPermissions;
|
||||
foreach($data['permissions'] as $permission) {
|
||||
foreach ($data['permissions'] as $permission) {
|
||||
if (array_key_exists($permission, $this->permissions)) {
|
||||
// Build the daemon permissions array for sending.
|
||||
if (!is_null($this->permissions[$permission])) {
|
||||
if (! is_null($this->permissions[$permission])) {
|
||||
array_push($daemonPermissions, $this->permissions[$permission]);
|
||||
}
|
||||
$model = new Models\Permission;
|
||||
$model->fill([
|
||||
'user_id' => $data['user'],
|
||||
'server_id' => $data['server'],
|
||||
'permission' => $permission
|
||||
'permission' => $permission,
|
||||
]);
|
||||
$model->save();
|
||||
}
|
||||
|
@ -312,16 +313,17 @@ class SubuserRepository
|
|||
$res = $client->request('PATCH', '/server', [
|
||||
'headers' => [
|
||||
'X-Access-Server' => $server->uuid,
|
||||
'X-Access-Token' => $node->daemonSecret
|
||||
'X-Access-Token' => $node->daemonSecret,
|
||||
],
|
||||
'json' => [
|
||||
'keys' => [
|
||||
$subuser->daemonSecret => $daemonPermissions
|
||||
]
|
||||
]
|
||||
$subuser->daemonSecret => $daemonPermissions,
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return true;
|
||||
} catch (\GuzzleHttp\Exception\TransferException $ex) {
|
||||
DB::rollBack();
|
||||
|
@ -330,7 +332,7 @@ class SubuserRepository
|
|||
DB::rollBack();
|
||||
throw $ex;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>
|
||||
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -21,19 +21,17 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Repositories;
|
||||
|
||||
use Cron;
|
||||
use Validator;
|
||||
|
||||
use Pterodactyl\Models;
|
||||
|
||||
use Pterodactyl\Exceptions\DisplayValidationException;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Pterodactyl\Exceptions\DisplayValidationException;
|
||||
|
||||
class TaskRepository
|
||||
{
|
||||
|
||||
protected $defaults = [
|
||||
'year' => '*',
|
||||
'day_of_week' => '*',
|
||||
|
@ -64,6 +62,7 @@ class TaskRepository
|
|||
$task = Models\Task::findOrFail($id);
|
||||
try {
|
||||
$task->delete();
|
||||
|
||||
return true;
|
||||
} catch (\Exception $ex) {
|
||||
throw $ex;
|
||||
|
@ -111,20 +110,20 @@ class TaskRepository
|
|||
'month' => 'string|sometimes',
|
||||
'day_of_month' => 'string|sometimes',
|
||||
'hour' => 'string|sometimes',
|
||||
'minute' => 'string|sometimes'
|
||||
'minute' => 'string|sometimes',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
throw new DisplayValidationException(json_encode($validator->errors()));
|
||||
}
|
||||
|
||||
if (!in_array($data['action'], $this->actions)) {
|
||||
if (! in_array($data['action'], $this->actions)) {
|
||||
throw new DisplayException('The action provided is not valid.');
|
||||
}
|
||||
|
||||
$cron = $this->defaults;
|
||||
foreach ($this->defaults as $setting => $value) {
|
||||
if (array_key_exists($setting, $data) && !is_null($data[$setting]) && $data[$setting] !== '') {
|
||||
if (array_key_exists($setting, $data) && ! is_null($data[$setting]) && $data[$setting] !== '') {
|
||||
$cron[$setting] = $data[$setting];
|
||||
}
|
||||
}
|
||||
|
@ -157,11 +156,9 @@ class TaskRepository
|
|||
'hour' => $cron['hour'],
|
||||
'minute' => $cron['minute'],
|
||||
'last_run' => null,
|
||||
'next_run' => $buildCron->getNextRunDate()
|
||||
'next_run' => $buildCron->getNextRunDate(),
|
||||
]);
|
||||
|
||||
return $task->save();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>
|
||||
* Some Modifications (c) 2015 Dylan Seidt <dylan.seidt@gmail.com>
|
||||
* Some Modifications (c) 2015 Dylan Seidt <dylan.seidt@gmail.com>.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -22,26 +22,22 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Repositories;
|
||||
|
||||
use DB;
|
||||
use Settings;
|
||||
use Hash;
|
||||
use Validator;
|
||||
use Mail;
|
||||
use Carbon;
|
||||
use Auth;
|
||||
|
||||
use Hash;
|
||||
use Carbon;
|
||||
use Validator;
|
||||
use Pterodactyl\Models;
|
||||
use Pterodactyl\Services\UuidService;
|
||||
use Pterodactyl\Notifications\AccountCreated;
|
||||
|
||||
use Pterodactyl\Exceptions\DisplayValidationException;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Pterodactyl\Notifications\AccountCreated;
|
||||
use Pterodactyl\Exceptions\DisplayValidationException;
|
||||
|
||||
class UserRepository
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
|
@ -54,7 +50,7 @@ class UserRepository
|
|||
* @param string|null $password An unhashed version of the user's password.
|
||||
* @param bool $admin Boolean value if user should be an admin or not.
|
||||
* @param int $token A custom user ID.
|
||||
* @return bool|integer
|
||||
* @return bool|int
|
||||
*/
|
||||
public function create($email, $password = null, $admin = false, $token = null)
|
||||
{
|
||||
|
@ -83,7 +79,7 @@ class UserRepository
|
|||
$uuid = new UuidService;
|
||||
|
||||
// Support for API Services
|
||||
if (!is_null($token)) {
|
||||
if (! is_null($token)) {
|
||||
$user->id = $token;
|
||||
}
|
||||
|
||||
|
@ -99,12 +95,13 @@ class UserRepository
|
|||
DB::table('password_resets')->insert([
|
||||
'email' => $user->email,
|
||||
'token' => $token,
|
||||
'created_at' => Carbon::now()->toDateTimeString()
|
||||
'created_at' => Carbon::now()->toDateTimeString(),
|
||||
]);
|
||||
|
||||
$user->notify((new AccountCreated($token)));
|
||||
|
||||
DB::commit();
|
||||
|
||||
return $user->id;
|
||||
} catch (\Exception $ex) {
|
||||
DB::rollBack();
|
||||
|
@ -115,9 +112,9 @@ class UserRepository
|
|||
/**
|
||||
* Updates a user on the panel.
|
||||
*
|
||||
* @param integer $id
|
||||
* @param int $id
|
||||
* @param array $data An array of columns and their associated values to update for the user.
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function update($id, array $data)
|
||||
{
|
||||
|
@ -129,7 +126,7 @@ class UserRepository
|
|||
'root_admin' => 'sometimes|required|boolean',
|
||||
'language' => 'sometimes|required|string|min:1|max:5',
|
||||
'use_totp' => 'sometimes|required|boolean',
|
||||
'totp_secret' => 'sometimes|required|size:16'
|
||||
'totp_secret' => 'sometimes|required|size:16',
|
||||
]);
|
||||
|
||||
// Run validator, throw catchable and displayable exception if it fails.
|
||||
|
@ -138,7 +135,7 @@ class UserRepository
|
|||
throw new DisplayValidationException($validator->errors());
|
||||
}
|
||||
|
||||
if(array_key_exists('password', $data)) {
|
||||
if (array_key_exists('password', $data)) {
|
||||
$data['password'] = Hash::make($data['password']);
|
||||
}
|
||||
|
||||
|
@ -153,18 +150,18 @@ class UserRepository
|
|||
/**
|
||||
* Deletes a user on the panel, returns the number of records deleted.
|
||||
*
|
||||
* @param integer $id
|
||||
* @return integer
|
||||
* @param int $id
|
||||
* @return int
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
if(Models\Server::where('owner', $id)->count() > 0) {
|
||||
if (Models\Server::where('owner', $id)->count() > 0) {
|
||||
throw new DisplayException('Cannot delete a user with active servers attached to thier account.');
|
||||
}
|
||||
|
||||
// @TODO: this should probably be checked outside of this method because we won't always have Auth::user()
|
||||
if(!is_null(Auth::user()) && Auth::user()->id === $id) {
|
||||
throw new DisplayException('Cannot delete your own account.');
|
||||
if (! is_null(Auth::user()) && Auth::user()->id === $id) {
|
||||
throw new DisplayException('Cannot delete your own account.');
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
|
@ -175,11 +172,11 @@ class UserRepository
|
|||
Models\User::destroy($id);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return true;
|
||||
} catch (\Exception $ex) {
|
||||
DB::rollBack();
|
||||
throw $ex;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Reference in a new issue