2023-04-05 15:29:58 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Controllers\Admin\Extensions\Blueprint;
|
|
|
|
|
2024-04-08 07:17:29 -04:00
|
|
|
use Artisan;
|
2023-04-05 15:29:58 -04:00
|
|
|
use Illuminate\View\View;
|
|
|
|
use Illuminate\View\Factory as ViewFactory;
|
|
|
|
use Pterodactyl\Http\Controllers\Controller;
|
2024-03-10 17:26:41 -04:00
|
|
|
use Pterodactyl\BlueprintFramework\Services\PlaceholderService\BlueprintPlaceholderService;
|
|
|
|
use Pterodactyl\BlueprintFramework\Services\ConfigService\BlueprintConfigService;
|
2023-09-07 10:17:04 -04:00
|
|
|
use Pterodactyl\BlueprintFramework\Services\TelemetryService\BlueprintTelemetryService;
|
2023-09-07 15:12:33 -04:00
|
|
|
use Pterodactyl\BlueprintFramework\Libraries\ExtensionLibrary\Admin\BlueprintAdminLibrary as BlueprintExtensionLibrary;
|
2023-04-05 15:29:58 -04:00
|
|
|
use Pterodactyl\Contracts\Repository\SettingsRepositoryInterface;
|
|
|
|
use Illuminate\Http\RedirectResponse;
|
2023-06-28 09:48:44 -04:00
|
|
|
use Pterodactyl\Http\Requests\Admin\AdminFormRequest;
|
2023-04-05 15:29:58 -04:00
|
|
|
|
|
|
|
class BlueprintExtensionController extends Controller
|
|
|
|
{
|
|
|
|
|
2023-06-02 10:37:38 -04:00
|
|
|
/**
|
|
|
|
* BlueprintExtensionController constructor.
|
|
|
|
*/
|
|
|
|
public function __construct(
|
2024-03-10 17:26:41 -04:00
|
|
|
private BlueprintTelemetryService $TelemetryService,
|
|
|
|
private BlueprintExtensionLibrary $ExtensionLibrary,
|
|
|
|
private BlueprintPlaceholderService $PlaceholderService,
|
|
|
|
private BlueprintConfigService $ConfigService,
|
2023-04-05 15:29:58 -04:00
|
|
|
|
2023-06-02 10:37:38 -04:00
|
|
|
private ViewFactory $view,
|
|
|
|
private SettingsRepositoryInterface $settings,
|
|
|
|
) {
|
|
|
|
}
|
2023-05-31 04:40:03 -04:00
|
|
|
|
2023-06-02 10:37:38 -04:00
|
|
|
/**
|
|
|
|
* Return the admin index view.
|
|
|
|
*/
|
|
|
|
public function index(): View
|
|
|
|
{
|
2024-03-10 17:26:41 -04:00
|
|
|
$LatestVersion = $this->ConfigService->latest();
|
2023-06-02 10:37:38 -04:00
|
|
|
return $this->view->make(
|
|
|
|
'admin.extensions.blueprint.index', [
|
2024-03-10 17:26:41 -04:00
|
|
|
'ExtensionLibrary' => $this->ExtensionLibrary,
|
|
|
|
'TelemetryService' => $this->TelemetryService,
|
|
|
|
'PlaceholderService' => $this->PlaceholderService,
|
|
|
|
'ConfigService' => $this->ConfigService,
|
|
|
|
'LatestVersion' => $LatestVersion,
|
2024-02-16 10:05:42 -05:00
|
|
|
|
2023-06-02 10:37:38 -04:00
|
|
|
'root' => "/admin/extensions/blueprint",
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
2023-04-05 15:29:58 -04:00
|
|
|
|
2023-06-02 10:37:38 -04:00
|
|
|
/**
|
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
|
|
|
*/
|
2023-06-28 10:57:05 -04:00
|
|
|
public function update(BlueprintAdminFormRequest $request): RedirectResponse
|
2023-06-02 10:37:38 -04:00
|
|
|
{
|
|
|
|
foreach ($request->normalize() as $key => $value) {
|
|
|
|
$this->settings->set('blueprint::' . $key, $value);
|
2023-04-05 15:29:58 -04:00
|
|
|
}
|
2023-06-02 10:37:38 -04:00
|
|
|
|
2023-08-31 04:51:44 -04:00
|
|
|
// Confirm that the database value changes have been applied.
|
2024-03-10 17:26:41 -04:00
|
|
|
$this->ExtensionLibrary->notify("Your changes have been saved.");
|
2024-02-16 10:05:42 -05:00
|
|
|
// Sync database values with the bash side of Blueprint.
|
|
|
|
Artisan::call("bp:sync");
|
2023-08-31 04:51:44 -04:00
|
|
|
// Redirect back to the page the user was on.
|
2023-06-02 10:37:38 -04:00
|
|
|
return redirect()->route('admin.extensions.blueprint.index');
|
|
|
|
}
|
2023-06-18 12:32:02 -04:00
|
|
|
}
|
2023-06-28 09:48:44 -04:00
|
|
|
|
2023-06-28 10:57:05 -04:00
|
|
|
class BlueprintAdminFormRequest extends AdminFormRequest
|
2023-06-28 09:48:44 -04:00
|
|
|
{
|
2023-08-31 04:51:44 -04:00
|
|
|
// Form validation for settings on the Blueprint admin page.
|
|
|
|
// This is included in the controller directly as that
|
|
|
|
// simplifies my work.
|
2023-06-28 09:48:44 -04:00
|
|
|
public function rules(): array {
|
|
|
|
return [
|
|
|
|
'placeholder' => 'string',
|
|
|
|
'developer' => 'string',
|
|
|
|
'telemetry' => 'string',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function attributes(): array {
|
|
|
|
return [
|
|
|
|
'placeholder' => 'Placeholder Value',
|
|
|
|
'developer' => 'Developer Mode',
|
|
|
|
'telemetry' => 'Telemetry',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|