From 3c48947f9ddb91c8004482e4d0abdabe4889e309 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sat, 16 Dec 2017 13:15:09 -0600 Subject: [PATCH] Fix known issues from the upgrade guide --- .../CleanServiceBackupFilesCommand.php | 27 +++------ app/Http/Controllers/Admin/PackController.php | 2 +- .../Controllers/Admin/ServersController.php | 2 +- app/Http/Controllers/Auth/LoginController.php | 5 +- app/Http/Middleware/VerifyReCaptcha.php | 2 +- .../Admin/DatabaseHostFormRequest.php | 2 +- app/Models/Pack.php | 26 --------- app/Policies/ServerPolicy.php | 13 +++++ app/Providers/SettingsServiceProvider.php | 18 ++++++ .../pterodactyl/admin/packs/view.blade.php | 7 --- .../CleanServiceBackupFilesCommandTest.php | 55 +++++++++---------- 11 files changed, 71 insertions(+), 88 deletions(-) diff --git a/app/Console/Commands/Maintenance/CleanServiceBackupFilesCommand.php b/app/Console/Commands/Maintenance/CleanServiceBackupFilesCommand.php index f3982921e..4811a222e 100644 --- a/app/Console/Commands/Maintenance/CleanServiceBackupFilesCommand.php +++ b/app/Console/Commands/Maintenance/CleanServiceBackupFilesCommand.php @@ -1,27 +1,16 @@ . - * - * This software is licensed under the terms of the MIT license. - * https://opensource.org/licenses/MIT - */ namespace Pterodactyl\Console\Commands\Maintenance; use Carbon\Carbon; use Illuminate\Console\Command; +use Symfony\Component\Finder\SplFileInfo; use Illuminate\Contracts\Filesystem\Factory as FilesystemFactory; class CleanServiceBackupFilesCommand extends Command { const BACKUP_THRESHOLD_MINUTES = 5; - /** - * @var \Carbon\Carbon - */ - protected $carbon; - /** * @var string */ @@ -40,14 +29,12 @@ class CleanServiceBackupFilesCommand extends Command /** * CleanServiceBackupFilesCommand constructor. * - * @param \Carbon\Carbon $carbon * @param \Illuminate\Contracts\Filesystem\Factory $filesystem */ - public function __construct(Carbon $carbon, FilesystemFactory $filesystem) + public function __construct(FilesystemFactory $filesystem) { parent::__construct(); - $this->carbon = $carbon; $this->disk = $filesystem->disk(); } @@ -58,11 +45,11 @@ class CleanServiceBackupFilesCommand extends Command { $files = $this->disk->files('services/.bak'); - collect($files)->each(function ($file) { - $lastModified = $this->carbon->timestamp($this->disk->lastModified($file)); - if ($lastModified->diffInMinutes($this->carbon->now()) > self::BACKUP_THRESHOLD_MINUTES) { - $this->disk->delete($file); - $this->info(trans('command/messages.maintenance.deleting_service_backup', ['file' => $file])); + collect($files)->each(function (SplFileInfo $file) { + $lastModified = Carbon::createFromTimestamp($this->disk->lastModified($file->getPath())); + if ($lastModified->diffInMinutes(Carbon::now()) > self::BACKUP_THRESHOLD_MINUTES) { + $this->disk->delete($file->getPath()); + $this->info(trans('command/messages.maintenance.deleting_service_backup', ['file' => $file->getFilename()])); } }); } diff --git a/app/Http/Controllers/Admin/PackController.php b/app/Http/Controllers/Admin/PackController.php index ae6c86fda..fed86f3a0 100644 --- a/app/Http/Controllers/Admin/PackController.php +++ b/app/Http/Controllers/Admin/PackController.php @@ -163,7 +163,7 @@ class PackController extends Controller */ public function store(PackFormRequest $request) { - if ($request->has('from_template')) { + if ($request->filled('from_template')) { $pack = $this->templateUploadService->handle($request->input('egg_id'), $request->file('file_upload')); } else { $pack = $this->creationService->handle($request->normalize(), $request->file('file_upload')); diff --git a/app/Http/Controllers/Admin/ServersController.php b/app/Http/Controllers/Admin/ServersController.php index 1cd63a20d..427bb7d20 100644 --- a/app/Http/Controllers/Admin/ServersController.php +++ b/app/Http/Controllers/Admin/ServersController.php @@ -524,7 +524,7 @@ class ServersController extends Controller */ public function delete(Request $request, Server $server) { - $this->deletionService->withForce($request->has('force_delete'))->handle($server); + $this->deletionService->withForce($request->filled('force_delete'))->handle($server); $this->alert->success(trans('admin/server.alerts.server_deleted'))->flash(); return redirect()->route('admin.servers'); diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index 8e67d9f1a..127802d22 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -107,6 +107,8 @@ class LoginController extends Controller * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\Response + * + * @throws \Illuminate\Validation\ValidationException */ public function login(Request $request) { @@ -115,8 +117,7 @@ class LoginController extends Controller if ($this->hasTooManyLoginAttempts($request)) { $this->fireLockoutEvent($request); - - return $this->sendLockoutResponse($request); + $this->sendLockoutResponse($request); } try { diff --git a/app/Http/Middleware/VerifyReCaptcha.php b/app/Http/Middleware/VerifyReCaptcha.php index 16c3a2f59..7464e854b 100644 --- a/app/Http/Middleware/VerifyReCaptcha.php +++ b/app/Http/Middleware/VerifyReCaptcha.php @@ -39,7 +39,7 @@ class VerifyReCaptcha return $next($request); } - if ($request->has('g-recaptcha-response')) { + if ($request->filled('g-recaptcha-response')) { $client = new Client(); $res = $client->post($this->config->get('recaptcha.domain'), [ 'form_params' => [ diff --git a/app/Http/Requests/Admin/DatabaseHostFormRequest.php b/app/Http/Requests/Admin/DatabaseHostFormRequest.php index 1feb42ed1..76a2f1e55 100644 --- a/app/Http/Requests/Admin/DatabaseHostFormRequest.php +++ b/app/Http/Requests/Admin/DatabaseHostFormRequest.php @@ -18,7 +18,7 @@ class DatabaseHostFormRequest extends AdminFormRequest */ public function rules() { - if (! $this->has('node_id')) { + if (! $this->filled('node_id')) { $this->merge(['node_id' => null]); } diff --git a/app/Models/Pack.php b/app/Models/Pack.php index a029b3614..5d172c252 100644 --- a/app/Models/Pack.php +++ b/app/Models/Pack.php @@ -9,8 +9,6 @@ namespace Pterodactyl\Models; -use File; -use Storage; use Sofa\Eloquence\Eloquence; use Sofa\Eloquence\Validable; use Illuminate\Database\Eloquent\Model; @@ -88,30 +86,6 @@ class Pack extends Model implements CleansAttributes, ValidableContract 'version' => 2, ]; - /** - * Returns all of the archived files for a given pack. - * - * @param bool $collection - * @return \Illuminate\Support\Collection|object - * @deprecated - */ - public function files($collection = false) - { - $files = collect(Storage::files('packs/' . $this->uuid)); - - $files = $files->map(function ($item) { - $path = storage_path('app/' . $item); - - return (object) [ - 'name' => basename($item), - 'hash' => sha1_file($path), - 'size' => File::humanReadableSize($path), - ]; - }); - - return ($collection) ? $files : (object) $files->all(); - } - /** * Gets egg associated with a service pack. * diff --git a/app/Policies/ServerPolicy.php b/app/Policies/ServerPolicy.php index c5e1860c4..9b4db6f05 100644 --- a/app/Policies/ServerPolicy.php +++ b/app/Policies/ServerPolicy.php @@ -51,4 +51,17 @@ class ServerPolicy return $this->checkPermission($user, $server, $ability); } + + /** + * This is a horrendous hack to avoid Laravel's "smart" behavior that does + * not call the before() function if there isn't a function matching the + * policy permission. + * + * @param string $name + * @param mixed $arguments + */ + public function __call($name, $arguments) + { + // do nothing + } } diff --git a/app/Providers/SettingsServiceProvider.php b/app/Providers/SettingsServiceProvider.php index dc9e9cdc6..40802f5c6 100644 --- a/app/Providers/SettingsServiceProvider.php +++ b/app/Providers/SettingsServiceProvider.php @@ -87,6 +87,24 @@ class SettingsServiceProvider extends ServiceProvider } } + switch (strtolower($value)) { + case 'true': + case '(true)': + $value = true; + break; + case 'false': + case '(false)': + $value = false; + break; + case 'empty': + case '(empty)': + $value = ''; + break; + case 'null': + case '(null)': + $value = null; + } + $config->set(str_replace(':', '.', $key), $value); } } diff --git a/resources/themes/pterodactyl/admin/packs/view.blade.php b/resources/themes/pterodactyl/admin/packs/view.blade.php index e9e5804e5..d9bb50390 100644 --- a/resources/themes/pterodactyl/admin/packs/view.blade.php +++ b/resources/themes/pterodactyl/admin/packs/view.blade.php @@ -113,13 +113,6 @@ SHA1 Hash File Size - @foreach($pack->files() as $file) - - {{ $file->name }} - {{ $file->hash }} - {{ $file->size }} - - @endforeach