Implement base service file modification through panel
This commit is contained in:
parent
b8a6a15b08
commit
cfd5e0e854
19 changed files with 855 additions and 1 deletions
73
app/Console/Commands/CleanServiceBackup.php
Normal file
73
app/Console/Commands/CleanServiceBackup.php
Normal file
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* 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
|
||||
* 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\Console\Commands;
|
||||
|
||||
use Carbon;
|
||||
use Storage;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class CleanServiceBackup extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'pterodactyl:cleanservices';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Cleans .bak files assocaited with service backups whene editing files through the panel.';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$files = Storage::files('services/.bak');
|
||||
|
||||
foreach($files as $file) {
|
||||
$lastModified = Carbon::createFromTimestamp(Storage::lastModified($file));
|
||||
if ($lastModified->diffInMinutes(Carbon::now()) > 5) {
|
||||
$this->info('Deleting ' . $file);
|
||||
Storage::delete($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -21,6 +21,7 @@ class Kernel extends ConsoleKernel
|
|||
\Pterodactyl\Console\Commands\ClearTasks::class,
|
||||
\Pterodactyl\Console\Commands\ClearServices::class,
|
||||
\Pterodactyl\Console\Commands\UpdateEmailSettings::class,
|
||||
\Pterodactyl\Console\Commands\CleanServiceBackup::class,
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
@ -27,6 +27,7 @@ use Alert;
|
|||
use DB;
|
||||
use Log;
|
||||
use Validator;
|
||||
use Storage;
|
||||
|
||||
use Pterodactyl\Models;
|
||||
use Pterodactyl\Repositories\ServiceRepository;
|
||||
|
@ -274,4 +275,36 @@ class ServiceController extends Controller
|
|||
return redirect()->route('admin.services.option', [$service, $option]);
|
||||
}
|
||||
|
||||
public function getConfiguration(Request $request, $serviceId)
|
||||
{
|
||||
$service = Models\Service::findOrFail($serviceId);
|
||||
return view('admin.services.config', [
|
||||
'service' => $service,
|
||||
'contents' => [
|
||||
'json' => Storage::get('services/' . $service->file . '/main.json'),
|
||||
'index' => Storage::get('services/' . $service->file . '/index.js')
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
public function postConfiguration(Request $request, $serviceId)
|
||||
{
|
||||
try {
|
||||
$repo = new ServiceRepository\Service;
|
||||
$repo->updateFile($serviceId, $request->except([
|
||||
'_token'
|
||||
]));
|
||||
return response('', 204);
|
||||
} catch (DisplayException $ex) {
|
||||
return response()->json([
|
||||
'error' => $ex->getMessage()
|
||||
], 503);
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
return response()->json([
|
||||
'error' => 'An error occured while attempting to save the file.'
|
||||
], 503);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -379,6 +379,15 @@ class AdminRoutes {
|
|||
'uses' => 'Admin\ServiceController@deleteService'
|
||||
]);
|
||||
|
||||
$router->get('/service/{id}/configuration', [
|
||||
'as' => 'admin.services.service.config',
|
||||
'uses' => 'Admin\ServiceController@getConfiguration'
|
||||
]);
|
||||
|
||||
$router->post('/service/{id}/configuration', [
|
||||
'uses' => 'Admin\ServiceController@postConfiguration'
|
||||
]);
|
||||
|
||||
$router->get('/service/{service}/option/new', [
|
||||
'as' => 'admin.services.option.new',
|
||||
'uses' => 'Admin\ServiceController@newOption'
|
||||
|
|
54
app/Models/Checksum.php
Normal file
54
app/Models/Checksum.php
Normal file
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* 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
|
||||
* 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\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Checksum extends Model
|
||||
{
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'checksums';
|
||||
|
||||
/**
|
||||
* Fields that are not mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $guarded = ['id', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* Cast values to correct type.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'service' => 'integer'
|
||||
];
|
||||
|
||||
}
|
|
@ -26,6 +26,7 @@ namespace Pterodactyl\Repositories\ServiceRepository;
|
|||
use DB;
|
||||
use Validator;
|
||||
use Uuid;
|
||||
use Storage;
|
||||
|
||||
use Pterodactyl\Models;
|
||||
use Pterodactyl\Services\UuidService;
|
||||
|
@ -110,4 +111,44 @@ class Service
|
|||
}
|
||||
}
|
||||
|
||||
public function updateFile($id, array $data)
|
||||
{
|
||||
$service = Models\Service::findOrFail($id);
|
||||
|
||||
$validator = Validator::make($data, [
|
||||
'file' => 'required|in:index,main',
|
||||
'contents' => 'required|string'
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
throw new DisplayValidationException($validator->errors());
|
||||
}
|
||||
|
||||
$filename = ($data['file'] === 'main') ? 'main.json' : 'index.js';
|
||||
$filepath = 'services/' . $service->file . '/' . $filename;
|
||||
$backup = 'services/.bak/' . str_random(12) . '.bak';
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
try {
|
||||
Storage::move($filepath, $backup);
|
||||
Storage::put($filepath, $data['contents']);
|
||||
|
||||
$checksum = Models\Checksum::firstOrNew([
|
||||
'service' => $service->id,
|
||||
'filename' => $filename
|
||||
]);
|
||||
|
||||
$checksum->checksum = sha1_file(storage_path('app/' . $filepath));
|
||||
$checksum->save();
|
||||
|
||||
DB::commit();
|
||||
} catch(\Exception $ex) {
|
||||
DB::rollback();
|
||||
Storage::move($backup, $filepath);
|
||||
throw $ex;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Reference in a new issue