Fix known issues from the upgrade guide
This commit is contained in:
parent
0dcf2aaed6
commit
3c48947f9d
11 changed files with 71 additions and 88 deletions
|
@ -1,27 +1,16 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
|
||||||
* Pterodactyl - Panel
|
|
||||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
|
||||||
*
|
|
||||||
* This software is licensed under the terms of the MIT license.
|
|
||||||
* https://opensource.org/licenses/MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Pterodactyl\Console\Commands\Maintenance;
|
namespace Pterodactyl\Console\Commands\Maintenance;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
|
use Symfony\Component\Finder\SplFileInfo;
|
||||||
use Illuminate\Contracts\Filesystem\Factory as FilesystemFactory;
|
use Illuminate\Contracts\Filesystem\Factory as FilesystemFactory;
|
||||||
|
|
||||||
class CleanServiceBackupFilesCommand extends Command
|
class CleanServiceBackupFilesCommand extends Command
|
||||||
{
|
{
|
||||||
const BACKUP_THRESHOLD_MINUTES = 5;
|
const BACKUP_THRESHOLD_MINUTES = 5;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var \Carbon\Carbon
|
|
||||||
*/
|
|
||||||
protected $carbon;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
|
@ -40,14 +29,12 @@ class CleanServiceBackupFilesCommand extends Command
|
||||||
/**
|
/**
|
||||||
* CleanServiceBackupFilesCommand constructor.
|
* CleanServiceBackupFilesCommand constructor.
|
||||||
*
|
*
|
||||||
* @param \Carbon\Carbon $carbon
|
|
||||||
* @param \Illuminate\Contracts\Filesystem\Factory $filesystem
|
* @param \Illuminate\Contracts\Filesystem\Factory $filesystem
|
||||||
*/
|
*/
|
||||||
public function __construct(Carbon $carbon, FilesystemFactory $filesystem)
|
public function __construct(FilesystemFactory $filesystem)
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
$this->carbon = $carbon;
|
|
||||||
$this->disk = $filesystem->disk();
|
$this->disk = $filesystem->disk();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,11 +45,11 @@ class CleanServiceBackupFilesCommand extends Command
|
||||||
{
|
{
|
||||||
$files = $this->disk->files('services/.bak');
|
$files = $this->disk->files('services/.bak');
|
||||||
|
|
||||||
collect($files)->each(function ($file) {
|
collect($files)->each(function (SplFileInfo $file) {
|
||||||
$lastModified = $this->carbon->timestamp($this->disk->lastModified($file));
|
$lastModified = Carbon::createFromTimestamp($this->disk->lastModified($file->getPath()));
|
||||||
if ($lastModified->diffInMinutes($this->carbon->now()) > self::BACKUP_THRESHOLD_MINUTES) {
|
if ($lastModified->diffInMinutes(Carbon::now()) > self::BACKUP_THRESHOLD_MINUTES) {
|
||||||
$this->disk->delete($file);
|
$this->disk->delete($file->getPath());
|
||||||
$this->info(trans('command/messages.maintenance.deleting_service_backup', ['file' => $file]));
|
$this->info(trans('command/messages.maintenance.deleting_service_backup', ['file' => $file->getFilename()]));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -163,7 +163,7 @@ class PackController extends Controller
|
||||||
*/
|
*/
|
||||||
public function store(PackFormRequest $request)
|
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'));
|
$pack = $this->templateUploadService->handle($request->input('egg_id'), $request->file('file_upload'));
|
||||||
} else {
|
} else {
|
||||||
$pack = $this->creationService->handle($request->normalize(), $request->file('file_upload'));
|
$pack = $this->creationService->handle($request->normalize(), $request->file('file_upload'));
|
||||||
|
|
|
@ -524,7 +524,7 @@ class ServersController extends Controller
|
||||||
*/
|
*/
|
||||||
public function delete(Request $request, Server $server)
|
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();
|
$this->alert->success(trans('admin/server.alerts.server_deleted'))->flash();
|
||||||
|
|
||||||
return redirect()->route('admin.servers');
|
return redirect()->route('admin.servers');
|
||||||
|
|
|
@ -107,6 +107,8 @@ class LoginController extends Controller
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Http\Request $request
|
* @param \Illuminate\Http\Request $request
|
||||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\Response
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\Response
|
||||||
|
*
|
||||||
|
* @throws \Illuminate\Validation\ValidationException
|
||||||
*/
|
*/
|
||||||
public function login(Request $request)
|
public function login(Request $request)
|
||||||
{
|
{
|
||||||
|
@ -115,8 +117,7 @@ class LoginController extends Controller
|
||||||
|
|
||||||
if ($this->hasTooManyLoginAttempts($request)) {
|
if ($this->hasTooManyLoginAttempts($request)) {
|
||||||
$this->fireLockoutEvent($request);
|
$this->fireLockoutEvent($request);
|
||||||
|
$this->sendLockoutResponse($request);
|
||||||
return $this->sendLockoutResponse($request);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -39,7 +39,7 @@ class VerifyReCaptcha
|
||||||
return $next($request);
|
return $next($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->has('g-recaptcha-response')) {
|
if ($request->filled('g-recaptcha-response')) {
|
||||||
$client = new Client();
|
$client = new Client();
|
||||||
$res = $client->post($this->config->get('recaptcha.domain'), [
|
$res = $client->post($this->config->get('recaptcha.domain'), [
|
||||||
'form_params' => [
|
'form_params' => [
|
||||||
|
|
|
@ -18,7 +18,7 @@ class DatabaseHostFormRequest extends AdminFormRequest
|
||||||
*/
|
*/
|
||||||
public function rules()
|
public function rules()
|
||||||
{
|
{
|
||||||
if (! $this->has('node_id')) {
|
if (! $this->filled('node_id')) {
|
||||||
$this->merge(['node_id' => null]);
|
$this->merge(['node_id' => null]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,6 @@
|
||||||
|
|
||||||
namespace Pterodactyl\Models;
|
namespace Pterodactyl\Models;
|
||||||
|
|
||||||
use File;
|
|
||||||
use Storage;
|
|
||||||
use Sofa\Eloquence\Eloquence;
|
use Sofa\Eloquence\Eloquence;
|
||||||
use Sofa\Eloquence\Validable;
|
use Sofa\Eloquence\Validable;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
@ -88,30 +86,6 @@ class Pack extends Model implements CleansAttributes, ValidableContract
|
||||||
'version' => 2,
|
'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.
|
* Gets egg associated with a service pack.
|
||||||
*
|
*
|
||||||
|
|
|
@ -51,4 +51,17 @@ class ServerPolicy
|
||||||
|
|
||||||
return $this->checkPermission($user, $server, $ability);
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
$config->set(str_replace(':', '.', $key), $value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,13 +113,6 @@
|
||||||
<th>SHA1 Hash</th>
|
<th>SHA1 Hash</th>
|
||||||
<th>File Size</th>
|
<th>File Size</th>
|
||||||
</tr>
|
</tr>
|
||||||
@foreach($pack->files() as $file)
|
|
||||||
<tr>
|
|
||||||
<td>{{ $file->name }}</td>
|
|
||||||
<td><code>{{ $file->hash }}</code></td>
|
|
||||||
<td>{{ $file->size }}</td>
|
|
||||||
</tr>
|
|
||||||
@endforeach
|
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<div class="box-footer">
|
<div class="box-footer">
|
||||||
|
|
|
@ -1,14 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
|
||||||
* Pterodactyl - Panel
|
|
||||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
|
||||||
*
|
|
||||||
* This software is licensed under the terms of the MIT license.
|
|
||||||
* https://opensource.org/licenses/MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Tests\Unit\Commands\Maintenance;
|
namespace Tests\Unit\Commands\Maintenance;
|
||||||
|
|
||||||
|
use SplFileInfo;
|
||||||
use Mockery as m;
|
use Mockery as m;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Tests\Unit\Commands\CommandTestCase;
|
use Tests\Unit\Commands\CommandTestCase;
|
||||||
|
@ -18,11 +12,6 @@ use Pterodactyl\Console\Commands\Maintenance\CleanServiceBackupFilesCommand;
|
||||||
|
|
||||||
class CleanServiceBackupFilesCommandTest extends CommandTestCase
|
class CleanServiceBackupFilesCommandTest extends CommandTestCase
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var \Carbon\Carbon|\Mockery\Mock
|
|
||||||
*/
|
|
||||||
protected $carbon;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Pterodactyl\Console\Commands\Maintenance\CleanServiceBackupFilesCommand
|
* @var \Pterodactyl\Console\Commands\Maintenance\CleanServiceBackupFilesCommand
|
||||||
*/
|
*/
|
||||||
|
@ -45,13 +34,10 @@ class CleanServiceBackupFilesCommandTest extends CommandTestCase
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
$this->carbon = m::mock(Carbon::class);
|
Carbon::setTestNow();
|
||||||
$this->disk = m::mock(Filesystem::class);
|
$this->disk = m::mock(Filesystem::class);
|
||||||
$this->filesystem = m::mock(Factory::class);
|
$this->filesystem = m::mock(Factory::class);
|
||||||
$this->filesystem->shouldReceive('disk')->withNoArgs()->once()->andReturn($this->disk);
|
$this->filesystem->shouldReceive('disk')->withNoArgs()->once()->andReturn($this->disk);
|
||||||
|
|
||||||
$this->command = new CleanServiceBackupFilesCommand($this->carbon, $this->filesystem);
|
|
||||||
$this->command->setLaravel($this->app);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -59,14 +45,13 @@ class CleanServiceBackupFilesCommandTest extends CommandTestCase
|
||||||
*/
|
*/
|
||||||
public function testCommandCleansFilesMoreThan5MinutesOld()
|
public function testCommandCleansFilesMoreThan5MinutesOld()
|
||||||
{
|
{
|
||||||
$this->disk->shouldReceive('files')->with('services/.bak')->once()->andReturn(['testfile.txt']);
|
$file = new SplFileInfo('testfile.txt');
|
||||||
$this->disk->shouldReceive('lastModified')->with('testfile.txt')->once()->andReturn('disk:last:modified');
|
|
||||||
$this->carbon->shouldReceive('timestamp')->with('disk:last:modified')->once()->andReturnSelf();
|
|
||||||
$this->carbon->shouldReceive('now')->withNoArgs()->once()->andReturnNull();
|
|
||||||
$this->carbon->shouldReceive('diffInMinutes')->with(null)->once()->andReturn(10);
|
|
||||||
$this->disk->shouldReceive('delete')->with('testfile.txt')->once()->andReturnNull();
|
|
||||||
|
|
||||||
$display = $this->runCommand($this->command);
|
$this->disk->shouldReceive('files')->with('services/.bak')->once()->andReturn([$file]);
|
||||||
|
$this->disk->shouldReceive('lastModified')->with($file->getPath())->once()->andReturn(Carbon::now()->subDays(100));
|
||||||
|
$this->disk->shouldReceive('delete')->with($file->getPath())->once()->andReturnNull();
|
||||||
|
|
||||||
|
$display = $this->runCommand($this->getCommand());
|
||||||
|
|
||||||
$this->assertNotEmpty($display);
|
$this->assertNotEmpty($display);
|
||||||
$this->assertContains(trans('command/messages.maintenance.deleting_service_backup', ['file' => 'testfile.txt']), $display);
|
$this->assertContains(trans('command/messages.maintenance.deleting_service_backup', ['file' => 'testfile.txt']), $display);
|
||||||
|
@ -77,14 +62,26 @@ class CleanServiceBackupFilesCommandTest extends CommandTestCase
|
||||||
*/
|
*/
|
||||||
public function testCommandDoesNotCleanFileLessThan5MinutesOld()
|
public function testCommandDoesNotCleanFileLessThan5MinutesOld()
|
||||||
{
|
{
|
||||||
$this->disk->shouldReceive('files')->with('services/.bak')->once()->andReturn(['testfile.txt']);
|
$file = new SplFileInfo('testfile.txt');
|
||||||
$this->disk->shouldReceive('lastModified')->with('testfile.txt')->once()->andReturn('disk:last:modified');
|
|
||||||
$this->carbon->shouldReceive('timestamp')->with('disk:last:modified')->once()->andReturnSelf();
|
|
||||||
$this->carbon->shouldReceive('now')->withNoArgs()->once()->andReturnNull();
|
|
||||||
$this->carbon->shouldReceive('diffInMinutes')->with(null)->once()->andReturn(2);
|
|
||||||
|
|
||||||
$display = $this->runCommand($this->command);
|
$this->disk->shouldReceive('files')->with('services/.bak')->once()->andReturn([$file]);
|
||||||
|
$this->disk->shouldReceive('lastModified')->with($file->getPath())->once()->andReturn(Carbon::now());
|
||||||
|
|
||||||
|
$display = $this->runCommand($this->getCommand());
|
||||||
|
|
||||||
$this->assertEmpty($display);
|
$this->assertEmpty($display);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an instance of the command for testing.
|
||||||
|
*
|
||||||
|
* @return \Pterodactyl\Console\Commands\Maintenance\CleanServiceBackupFilesCommand
|
||||||
|
*/
|
||||||
|
private function getCommand(): CleanServiceBackupFilesCommand
|
||||||
|
{
|
||||||
|
$command = new CleanServiceBackupFilesCommand($this->filesystem);
|
||||||
|
$command->setLaravel($this->app);
|
||||||
|
|
||||||
|
return $command;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue