Begin moving packs to new service mechanisms, refactor exceptions for services
This commit is contained in:
parent
46cb71e69d
commit
9d3dca87f2
62 changed files with 492 additions and 303 deletions
39
app/Contracts/Repository/PackRepositoryInterface.php
Normal file
39
app/Contracts/Repository/PackRepositoryInterface.php
Normal file
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
/*
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 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
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Contracts\Repository;
|
||||
|
||||
use Pterodactyl\Contracts\Repository\Attributes\SearchableInterface;
|
||||
|
||||
interface PackRepositoryInterface extends RepositoryInterface, SearchableInterface
|
||||
{
|
||||
/**
|
||||
* Return all of the file archives for a given pack.
|
||||
*
|
||||
* @param int $id
|
||||
* @param bool $collection
|
||||
* @return object|\Illuminate\Support\Collection
|
||||
*/
|
||||
public function getFileArchives($id, $collection = false);
|
||||
}
|
|
@ -22,7 +22,7 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Exceptions\Services;
|
||||
namespace Pterodactyl\Exceptions\Service;
|
||||
|
||||
class HasActiveServersException extends \Exception
|
||||
{
|
30
app/Exceptions/Service/Pack/InvalidFileMimeTypeException.php
Normal file
30
app/Exceptions/Service/Pack/InvalidFileMimeTypeException.php
Normal file
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
/*
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 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
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Exceptions\Service\Pack;
|
||||
|
||||
class InvalidFileMimeTypeException extends \Exception
|
||||
{
|
||||
//
|
||||
}
|
30
app/Exceptions/Service/Pack/InvalidFileUploadException.php
Normal file
30
app/Exceptions/Service/Pack/InvalidFileUploadException.php
Normal file
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
/*
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 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
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Exceptions\Service\Pack;
|
||||
|
||||
class InvalidFileUploadException extends \Exception
|
||||
{
|
||||
//
|
||||
}
|
|
@ -22,7 +22,7 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Exceptions\Services\Server;
|
||||
namespace Pterodactyl\Exceptions\Service\Server;
|
||||
|
||||
use Exception;
|
||||
|
|
@ -22,7 +22,7 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Exceptions\Services\ServiceOption;
|
||||
namespace Pterodactyl\Exceptions\Service\ServiceOption;
|
||||
|
||||
class InvalidCopyFromException extends \Exception
|
||||
{
|
|
@ -22,7 +22,7 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Exceptions\Services\ServiceOption;
|
||||
namespace Pterodactyl\Exceptions\Service\ServiceOption;
|
||||
|
||||
class NoParentConfigurationFoundException extends \Exception
|
||||
{
|
|
@ -22,7 +22,7 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Exceptions\Services\ServiceVariable;
|
||||
namespace Pterodactyl\Exceptions\Service\ServiceVariable;
|
||||
|
||||
use Exception;
|
||||
|
|
@ -30,7 +30,7 @@ use Prologue\Alerts\AlertsMessageBag;
|
|||
use Pterodactyl\Models\ServiceOption;
|
||||
use Pterodactyl\Http\Controllers\Controller;
|
||||
use Pterodactyl\Http\Requests\Admin\Service\EditOptionScript;
|
||||
use Pterodactyl\Exceptions\Services\HasActiveServersException;
|
||||
use Pterodactyl\Exceptions\Service\HasActiveServersException;
|
||||
use Pterodactyl\Services\Services\Options\OptionUpdateService;
|
||||
use Pterodactyl\Contracts\Repository\ServiceRepositoryInterface;
|
||||
use Pterodactyl\Services\Services\Options\OptionCreationService;
|
||||
|
@ -38,8 +38,8 @@ use Pterodactyl\Services\Services\Options\OptionDeletionService;
|
|||
use Pterodactyl\Http\Requests\Admin\Service\ServiceOptionFormRequest;
|
||||
use Pterodactyl\Services\Services\Options\InstallScriptUpdateService;
|
||||
use Pterodactyl\Contracts\Repository\ServiceOptionRepositoryInterface;
|
||||
use Pterodactyl\Exceptions\Services\ServiceOption\InvalidCopyFromException;
|
||||
use Pterodactyl\Exceptions\Services\ServiceOption\NoParentConfigurationFoundException;
|
||||
use Pterodactyl\Exceptions\Service\ServiceOption\InvalidCopyFromException;
|
||||
use Pterodactyl\Exceptions\Service\ServiceOption\NoParentConfigurationFoundException;
|
||||
|
||||
class OptionController extends Controller
|
||||
{
|
||||
|
|
|
@ -30,7 +30,7 @@ use Pterodactyl\Http\Controllers\Controller;
|
|||
use Pterodactyl\Services\Services\ServiceUpdateService;
|
||||
use Pterodactyl\Services\Services\ServiceCreationService;
|
||||
use Pterodactyl\Services\Services\ServiceDeletionService;
|
||||
use Pterodactyl\Exceptions\Services\HasActiveServersException;
|
||||
use Pterodactyl\Exceptions\Service\HasActiveServersException;
|
||||
use Pterodactyl\Http\Requests\Admin\Service\ServiceFormRequest;
|
||||
use Pterodactyl\Contracts\Repository\ServiceRepositoryInterface;
|
||||
use Pterodactyl\Http\Requests\Admin\Service\ServiceFunctionsFormRequest;
|
||||
|
|
|
@ -83,7 +83,7 @@ class VariableController extends Controller
|
|||
* @return \Illuminate\Http\RedirectResponse
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Services\ServiceVariable\ReservedVariableNameException
|
||||
* @throws \Pterodactyl\Exceptions\Service\ServiceVariable\ReservedVariableNameException
|
||||
*/
|
||||
public function store(OptionVariableFormRequest $request, ServiceOption $option)
|
||||
{
|
||||
|
@ -117,7 +117,7 @@ class VariableController extends Controller
|
|||
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
* @throws \Pterodactyl\Exceptions\Services\ServiceVariable\ReservedVariableNameException
|
||||
* @throws \Pterodactyl\Exceptions\Service\ServiceVariable\ReservedVariableNameException
|
||||
*/
|
||||
public function update(OptionVariableFormRequest $request, ServiceOption $option, ServiceVariable $variable)
|
||||
{
|
||||
|
|
|
@ -26,12 +26,15 @@ namespace Pterodactyl\Models;
|
|||
|
||||
use File;
|
||||
use Storage;
|
||||
use Sofa\Eloquence\Eloquence;
|
||||
use Sofa\Eloquence\Validable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Nicolaslopezj\Searchable\SearchableTrait;
|
||||
use Sofa\Eloquence\Contracts\CleansAttributes;
|
||||
use Sofa\Eloquence\Contracts\Validable as ValidableContract;
|
||||
|
||||
class Pack extends Model
|
||||
class Pack extends Model implements CleansAttributes, ValidableContract
|
||||
{
|
||||
use SearchableTrait;
|
||||
use Eloquence, Validable;
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
|
@ -46,7 +49,33 @@ class Pack extends Model
|
|||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'option_id', 'name', 'version', 'description', 'selectable', 'visible', 'locked',
|
||||
'option_id', 'uuid', 'name', 'version', 'description', 'selectable', 'visible', 'locked',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected static $applicationRules = [
|
||||
'name' => 'required',
|
||||
'version' => 'required',
|
||||
'description' => 'sometimes',
|
||||
'selectable' => 'sometimes|required',
|
||||
'visible' => 'sometimes|required',
|
||||
'locked' => 'sometimes|required',
|
||||
'option_id' => 'required',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected static $dataIntegrityRules = [
|
||||
'name' => 'string',
|
||||
'version' => 'string',
|
||||
'description' => 'nullable|string',
|
||||
'selectable' => 'boolean',
|
||||
'visible' => 'boolean',
|
||||
'locked' => 'boolean',
|
||||
'option_id' => 'exists:service_options,id',
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -66,18 +95,13 @@ class Pack extends Model
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $searchable = [
|
||||
'columns' => [
|
||||
'packs.name' => 10,
|
||||
'packs.uuid' => 8,
|
||||
'service_options.name' => 6,
|
||||
'service_options.tag' => 5,
|
||||
'service_options.docker_image' => 5,
|
||||
'packs.version' => 2,
|
||||
],
|
||||
'joins' => [
|
||||
'service_options' => ['packs.option_id', 'service_options.id'],
|
||||
],
|
||||
protected $searchableColumns = [
|
||||
'name' => 10,
|
||||
'uuid' => 8,
|
||||
'option.name' => 6,
|
||||
'option.tag' => 5,
|
||||
'option.docker_image' => 5,
|
||||
'version' => 2,
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -85,6 +109,7 @@ class Pack extends Model
|
|||
*
|
||||
* @param bool $collection
|
||||
* @return \Illuminate\Support\Collection|object
|
||||
* @deprecated
|
||||
*/
|
||||
public function files($collection = false)
|
||||
{
|
||||
|
|
|
@ -22,20 +22,22 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Repositories\Eloquent\Attributes;
|
||||
namespace Pterodactyl\Repositories\Concerns;
|
||||
|
||||
use Pterodactyl\Repositories\Eloquent\EloquentRepository;
|
||||
use Pterodactyl\Contracts\Repository\Attributes\SearchableInterface;
|
||||
|
||||
abstract class SearchableRepository extends EloquentRepository implements SearchableInterface
|
||||
trait Searchable
|
||||
{
|
||||
/**
|
||||
* The term to search.
|
||||
*
|
||||
* @var bool|string
|
||||
*/
|
||||
protected $searchTerm = false;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* Perform a search of the model using the given term.
|
||||
*
|
||||
* @param string $term
|
||||
* @return $this
|
||||
*/
|
||||
public function search($term)
|
||||
{
|
|
@ -28,10 +28,12 @@ use Pterodactyl\Models\Location;
|
|||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
|
||||
use Pterodactyl\Contracts\Repository\LocationRepositoryInterface;
|
||||
use Pterodactyl\Repositories\Eloquent\Attributes\SearchableRepository;
|
||||
use Pterodactyl\Repositories\Concerns\Searchable;
|
||||
|
||||
class LocationRepository extends SearchableRepository implements LocationRepositoryInterface
|
||||
class LocationRepository extends EloquentRepository implements LocationRepositoryInterface
|
||||
{
|
||||
use Searchable;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
|
|
@ -27,10 +27,12 @@ namespace Pterodactyl\Repositories\Eloquent;
|
|||
use Pterodactyl\Models\Node;
|
||||
use Pterodactyl\Contracts\Repository\NodeRepositoryInterface;
|
||||
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
|
||||
use Pterodactyl\Repositories\Eloquent\Attributes\SearchableRepository;
|
||||
use Pterodactyl\Repositories\Concerns\Searchable;
|
||||
|
||||
class NodeRepository extends SearchableRepository implements NodeRepositoryInterface
|
||||
class NodeRepository extends EloquentRepository implements NodeRepositoryInterface
|
||||
{
|
||||
use Searchable;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
65
app/Repositories/Eloquent/PackRepository.php
Normal file
65
app/Repositories/Eloquent/PackRepository.php
Normal file
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
/*
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 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
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Repositories\Eloquent;
|
||||
|
||||
use Pterodactyl\Models\Pack;
|
||||
use Illuminate\Contracts\Filesystem\Factory as FilesystemFactory;
|
||||
use Pterodactyl\Repositories\Concerns\Searchable;
|
||||
use Pterodactyl\Contracts\Repository\PackRepositoryInterface;
|
||||
|
||||
class PackRepository extends EloquentRepository implements PackRepositoryInterface
|
||||
{
|
||||
use Searchable;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function model()
|
||||
{
|
||||
return Pack::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFileArchives($id, $collection = false)
|
||||
{
|
||||
$pack = $this->getBuilder()->find($id, ['id', 'uuid']);
|
||||
$storage = $this->app->make(FilesystemFactory::class);
|
||||
$files = collect($storage->disk('default')->files('packs/' . $pack->uuid));
|
||||
|
||||
$files = $files->map(function ($file) {
|
||||
$path = storage_path('app/' . $file);
|
||||
|
||||
return (object) [
|
||||
'name' => basename($file),
|
||||
'hash' => sha1_file($path),
|
||||
'size' => human_readable($path),
|
||||
];
|
||||
});
|
||||
|
||||
return ($collection) ? $files : (object) $files->all();
|
||||
}
|
||||
}
|
|
@ -25,12 +25,14 @@
|
|||
namespace Pterodactyl\Repositories\Eloquent;
|
||||
|
||||
use Pterodactyl\Models\Server;
|
||||
use Pterodactyl\Repositories\Concerns\Searchable;
|
||||
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
|
||||
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
||||
use Pterodactyl\Repositories\Eloquent\Attributes\SearchableRepository;
|
||||
|
||||
class ServerRepository extends SearchableRepository implements ServerRepositoryInterface
|
||||
class ServerRepository extends EloquentRepository implements ServerRepositoryInterface
|
||||
{
|
||||
use Searchable;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
@ -26,12 +26,14 @@ namespace Pterodactyl\Repositories\Eloquent;
|
|||
|
||||
use Pterodactyl\Models\User;
|
||||
use Illuminate\Foundation\Application;
|
||||
use Pterodactyl\Repositories\Concerns\Searchable;
|
||||
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
|
||||
use Illuminate\Contracts\Config\Repository as ConfigRepository;
|
||||
use Pterodactyl\Repositories\Eloquent\Attributes\SearchableRepository;
|
||||
|
||||
class UserRepository extends SearchableRepository implements UserRepositoryInterface
|
||||
class UserRepository extends EloquentRepository implements UserRepositoryInterface
|
||||
{
|
||||
use Searchable;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Contracts\Config\Repository
|
||||
*/
|
||||
|
|
|
@ -1,163 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 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
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* 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\Task;
|
||||
use Pterodactyl\Models\User;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Pterodactyl\Exceptions\DisplayValidationException;
|
||||
|
||||
class TaskRepository
|
||||
{
|
||||
/**
|
||||
* The default values to use for new tasks.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $defaults = [
|
||||
'year' => '*',
|
||||
'day_of_week' => '*',
|
||||
'month' => '*',
|
||||
'day_of_month' => '*',
|
||||
'hour' => '*',
|
||||
'minute' => '*/30',
|
||||
];
|
||||
|
||||
/**
|
||||
* Task action types.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $actions = [
|
||||
'command',
|
||||
'power',
|
||||
];
|
||||
|
||||
/**
|
||||
* Deletes a given task.
|
||||
*
|
||||
* @param int $id
|
||||
* @return bool
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
$task = Task::findOrFail($id);
|
||||
$task->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles a task active or inactive.
|
||||
*
|
||||
* @param int $id
|
||||
* @return bool
|
||||
*/
|
||||
public function toggle($id)
|
||||
{
|
||||
$task = Task::findOrFail($id);
|
||||
|
||||
$task->active = ! $task->active;
|
||||
$task->queued = false;
|
||||
$task->save();
|
||||
|
||||
return $task->active;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new scheduled task for a given server.
|
||||
*
|
||||
* @param int $server
|
||||
* @param int $user
|
||||
* @param array $data
|
||||
* @return \Pterodactyl\Models\Task
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||
* @throws \Pterodactyl\Exceptions\DisplayValidationException
|
||||
*/
|
||||
public function create($server, $user, $data)
|
||||
{
|
||||
$server = Server::findOrFail($server);
|
||||
$user = User::findOrFail($user);
|
||||
|
||||
$validator = Validator::make($data, [
|
||||
'action' => 'string|required',
|
||||
'data' => 'string|required',
|
||||
'year' => 'string|sometimes',
|
||||
'day_of_week' => 'string|sometimes',
|
||||
'month' => 'string|sometimes',
|
||||
'day_of_month' => 'string|sometimes',
|
||||
'hour' => 'string|sometimes',
|
||||
'minute' => 'string|sometimes',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
throw new DisplayValidationException(json_encode($validator->errors()));
|
||||
}
|
||||
|
||||
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] !== '') {
|
||||
$cron[$setting] = $data[$setting];
|
||||
}
|
||||
}
|
||||
|
||||
// Check that is this a valid Cron Entry
|
||||
try {
|
||||
$buildCron = Cron::factory(sprintf('%s %s %s %s %s %s',
|
||||
$cron['minute'],
|
||||
$cron['hour'],
|
||||
$cron['day_of_month'],
|
||||
$cron['month'],
|
||||
$cron['day_of_week'],
|
||||
$cron['year']
|
||||
));
|
||||
} catch (\Exception $ex) {
|
||||
throw $ex;
|
||||
}
|
||||
|
||||
return Task::create([
|
||||
'user_id' => $user->id,
|
||||
'server_id' => $server->id,
|
||||
'active' => 1,
|
||||
'action' => $data['action'],
|
||||
'data' => $data['data'],
|
||||
'queued' => 0,
|
||||
'year' => $cron['year'],
|
||||
'day_of_week' => $cron['day_of_week'],
|
||||
'month' => $cron['month'],
|
||||
'day_of_month' => $cron['day_of_month'],
|
||||
'hour' => $cron['hour'],
|
||||
'minute' => $cron['minute'],
|
||||
'last_run' => null,
|
||||
'next_run' => $buildCron->getNextRunDate(),
|
||||
]);
|
||||
}
|
||||
}
|
119
app/Services/Packs/PackCreationService.php
Normal file
119
app/Services/Packs/PackCreationService.php
Normal file
|
@ -0,0 +1,119 @@
|
|||
<?php
|
||||
/*
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 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
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Services\Packs;
|
||||
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
use Pterodactyl\Contracts\Repository\PackRepositoryInterface;
|
||||
use Illuminate\Contracts\Config\Repository as ConfigRepository;
|
||||
use Illuminate\Contracts\Filesystem\Factory as FilesystemFactory;
|
||||
use Pterodactyl\Exceptions\Service\Pack\InvalidFileUploadException;
|
||||
use Pterodactyl\Exceptions\Service\Pack\InvalidFileMimeTypeException;
|
||||
|
||||
class PackCreationService
|
||||
{
|
||||
/**
|
||||
* @var \Illuminate\Contracts\Config\Repository
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Database\ConnectionInterface
|
||||
*/
|
||||
protected $connection;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\PackRepositoryInterface
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Contracts\Filesystem\Factory
|
||||
*/
|
||||
protected $storage;
|
||||
|
||||
/**
|
||||
* PackCreationService constructor.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Config\Repository $config
|
||||
* @param \Illuminate\Database\ConnectionInterface $connection
|
||||
* @param \Illuminate\Contracts\Filesystem\Factory $storage
|
||||
* @param \Pterodactyl\Contracts\Repository\PackRepositoryInterface $repository
|
||||
*/
|
||||
public function __construct(
|
||||
ConfigRepository $config,
|
||||
ConnectionInterface $connection,
|
||||
FilesystemFactory $storage,
|
||||
PackRepositoryInterface $repository
|
||||
) {
|
||||
$this->config = $config;
|
||||
$this->connection = $connection;
|
||||
$this->repository = $repository;
|
||||
$this->storage = $storage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new service pack to the system.
|
||||
*
|
||||
* @param array $data
|
||||
* @param \Illuminate\Http\UploadedFile|null $file
|
||||
* @return \Pterodactyl\Models\Pack
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Service\Pack\InvalidFileMimeTypeException
|
||||
* @throws \Pterodactyl\Exceptions\Service\Pack\InvalidFileUploadException
|
||||
*/
|
||||
public function handle(array $data, $file = null)
|
||||
{
|
||||
if (! is_null($file)) {
|
||||
if (! $file->isValid()) {
|
||||
throw new InvalidFileUploadException;
|
||||
}
|
||||
|
||||
if (! in_array($file->getMimeType(), $this->config->get('pterodactyl.files.pack_types'))) {
|
||||
throw new InvalidFileMimeTypeException;
|
||||
}
|
||||
}
|
||||
|
||||
// Transform values to boolean
|
||||
$data['selectable'] = isset($data['selectable']);
|
||||
$data['visible'] = isset($data['visible']);
|
||||
$data['locked'] = isset($data['locked']);
|
||||
|
||||
$this->connection->beginTransaction();
|
||||
$pack = $this->repository->create(array_merge(
|
||||
['uuid' => Uuid::uuid4()], $data
|
||||
));
|
||||
|
||||
$this->storage->disk('default')->makeDirectory('packs/' . $pack->uuid);
|
||||
if (! is_null($file)) {
|
||||
$file->storeAs('packs/' . $pack->uuid, 'archive.tar.gz');
|
||||
}
|
||||
|
||||
$this->connection->commit();
|
||||
|
||||
return $pack;
|
||||
}
|
||||
}
|
|
@ -26,7 +26,7 @@ namespace Pterodactyl\Services\Services\Options;
|
|||
|
||||
use Pterodactyl\Models\ServiceOption;
|
||||
use Pterodactyl\Contracts\Repository\ServiceOptionRepositoryInterface;
|
||||
use Pterodactyl\Exceptions\Services\ServiceOption\InvalidCopyFromException;
|
||||
use Pterodactyl\Exceptions\Service\ServiceOption\InvalidCopyFromException;
|
||||
|
||||
class InstallScriptUpdateService
|
||||
{
|
||||
|
@ -53,7 +53,7 @@ class InstallScriptUpdateService
|
|||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
* @throws \Pterodactyl\Exceptions\Services\ServiceOption\InvalidCopyFromException
|
||||
* @throws \Pterodactyl\Exceptions\Service\ServiceOption\InvalidCopyFromException
|
||||
*/
|
||||
public function handle($option, array $data)
|
||||
{
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
namespace Pterodactyl\Services\Services\Options;
|
||||
|
||||
use Pterodactyl\Contracts\Repository\ServiceOptionRepositoryInterface;
|
||||
use Pterodactyl\Exceptions\Services\ServiceOption\NoParentConfigurationFoundException;
|
||||
use Pterodactyl\Exceptions\Service\ServiceOption\NoParentConfigurationFoundException;
|
||||
|
||||
class OptionCreationService
|
||||
{
|
||||
|
@ -51,7 +51,7 @@ class OptionCreationService
|
|||
* @return \Pterodactyl\Models\ServiceOption
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Services\ServiceOption\NoParentConfigurationFoundException
|
||||
* @throws \Pterodactyl\Exceptions\Service\ServiceOption\NoParentConfigurationFoundException
|
||||
*/
|
||||
public function handle(array $data)
|
||||
{
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
namespace Pterodactyl\Services\Services\Options;
|
||||
|
||||
use Pterodactyl\Exceptions\Services\HasActiveServersException;
|
||||
use Pterodactyl\Exceptions\Service\HasActiveServersException;
|
||||
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\ServiceOptionRepositoryInterface;
|
||||
|
||||
|
@ -60,7 +60,7 @@ class OptionDeletionService
|
|||
* @param int $option
|
||||
* @return int
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Services\HasActiveServersException
|
||||
* @throws \Pterodactyl\Exceptions\Service\HasActiveServersException
|
||||
*/
|
||||
public function handle($option)
|
||||
{
|
||||
|
|
|
@ -26,7 +26,7 @@ namespace Pterodactyl\Services\Services\Options;
|
|||
|
||||
use Pterodactyl\Models\ServiceOption;
|
||||
use Pterodactyl\Contracts\Repository\ServiceOptionRepositoryInterface;
|
||||
use Pterodactyl\Exceptions\Services\ServiceOption\NoParentConfigurationFoundException;
|
||||
use Pterodactyl\Exceptions\Service\ServiceOption\NoParentConfigurationFoundException;
|
||||
|
||||
class OptionUpdateService
|
||||
{
|
||||
|
@ -53,7 +53,7 @@ class OptionUpdateService
|
|||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
* @throws \Pterodactyl\Exceptions\Services\ServiceOption\NoParentConfigurationFoundException
|
||||
* @throws \Pterodactyl\Exceptions\Service\ServiceOption\NoParentConfigurationFoundException
|
||||
*/
|
||||
public function handle($option, array $data)
|
||||
{
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
namespace Pterodactyl\Services\Services;
|
||||
|
||||
use Pterodactyl\Exceptions\Services\HasActiveServersException;
|
||||
use Pterodactyl\Exceptions\Service\HasActiveServersException;
|
||||
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\ServiceRepositoryInterface;
|
||||
|
||||
|
@ -60,7 +60,7 @@ class ServiceDeletionService
|
|||
* @param int $service
|
||||
* @return int
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Services\HasActiveServersException
|
||||
* @throws \Pterodactyl\Exceptions\Service\HasActiveServersException
|
||||
*/
|
||||
public function handle($service)
|
||||
{
|
||||
|
|
|
@ -28,7 +28,7 @@ use Pterodactyl\Models\ServiceOption;
|
|||
use Pterodactyl\Models\ServiceVariable;
|
||||
use Pterodactyl\Contracts\Repository\ServiceOptionRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\ServiceVariableRepositoryInterface;
|
||||
use Pterodactyl\Exceptions\Services\ServiceVariable\ReservedVariableNameException;
|
||||
use Pterodactyl\Exceptions\Service\ServiceVariable\ReservedVariableNameException;
|
||||
|
||||
class VariableCreationService
|
||||
{
|
||||
|
@ -58,7 +58,7 @@ class VariableCreationService
|
|||
* @return \Pterodactyl\Models\ServiceVariable
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Services\ServiceVariable\ReservedVariableNameException
|
||||
* @throws \Pterodactyl\Exceptions\Service\ServiceVariable\ReservedVariableNameException
|
||||
*/
|
||||
public function handle($option, array $data)
|
||||
{
|
||||
|
|
|
@ -27,7 +27,7 @@ namespace Pterodactyl\Services\Services\Variables;
|
|||
use Pterodactyl\Models\ServiceVariable;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Pterodactyl\Contracts\Repository\ServiceVariableRepositoryInterface;
|
||||
use Pterodactyl\Exceptions\Services\ServiceVariable\ReservedVariableNameException;
|
||||
use Pterodactyl\Exceptions\Service\ServiceVariable\ReservedVariableNameException;
|
||||
|
||||
class VariableUpdateService
|
||||
{
|
||||
|
@ -56,7 +56,7 @@ class VariableUpdateService
|
|||
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
* @throws \Pterodactyl\Exceptions\Services\ServiceVariable\ReservedVariableNameException
|
||||
* @throws \Pterodactyl\Exceptions\Service\ServiceVariable\ReservedVariableNameException
|
||||
*/
|
||||
public function handle($variable, array $data)
|
||||
{
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
/**
|
||||
/*
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
|
@ -22,52 +22,16 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Repositories;
|
||||
|
||||
class HelperRepository
|
||||
{
|
||||
if (! function_exists('human_readable')) {
|
||||
/**
|
||||
* Listing of editable files in the control panel.
|
||||
* Generate a human-readable filesize for a given file path.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $editable = [
|
||||
'application/json',
|
||||
'application/javascript',
|
||||
'application/xml',
|
||||
'application/xhtml+xml',
|
||||
'text/xml',
|
||||
'text/css',
|
||||
'text/html',
|
||||
'text/plain',
|
||||
'text/x-perl',
|
||||
'text/x-shellscript',
|
||||
'inode/x-empty',
|
||||
];
|
||||
|
||||
/**
|
||||
* Converts from bytes to the largest possible size that is still readable.
|
||||
*
|
||||
* @param int $bytes
|
||||
* @param int $decimals
|
||||
* @param string $path
|
||||
* @param int $precision
|
||||
* @return string
|
||||
* @deprecated
|
||||
*/
|
||||
public static function bytesToHuman($bytes, $decimals = 2)
|
||||
function human_readable($path, $precision = 2)
|
||||
{
|
||||
$sz = explode(',', 'B,KB,MB,GB');
|
||||
$factor = floor((strlen($bytes) - 1) / 3);
|
||||
|
||||
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . ' ' . $sz[$factor];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns array of editable files.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function editableFiles()
|
||||
{
|
||||
return self::$editable;
|
||||
return app('file')->humanReadableSize($path, $precision);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue