Implement base service file modification through panel

This commit is contained in:
Dane Everitt 2016-11-09 17:58:14 -05:00
parent b8a6a15b08
commit cfd5e0e854
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
19 changed files with 855 additions and 1 deletions

View file

@ -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;
}
}
}