2023-04-05 15:29:58 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Controllers\Admin\Extensions\Blueprint;
|
|
|
|
|
|
|
|
use Illuminate\View\View;
|
|
|
|
use Illuminate\View\Factory as ViewFactory;
|
|
|
|
use Prologue\Alerts\AlertsMessageBag;
|
|
|
|
use Illuminate\Contracts\Console\Kernel;
|
|
|
|
use Pterodactyl\Http\Controllers\Controller;
|
|
|
|
use Pterodactyl\Services\Helpers\SoftwareVersionService;
|
2023-09-07 10:17:04 -04:00
|
|
|
use Pterodactyl\BlueprintFramework\Services\VariableService\BlueprintVariableService;
|
|
|
|
use Pterodactyl\BlueprintFramework\Services\TelemetryService\BlueprintTelemetryService;
|
2023-09-07 15:12:33 -04:00
|
|
|
use Pterodactyl\BlueprintFramework\Libraries\ExtensionLibrary\Admin\BlueprintAdminLibrary as BlueprintExtensionLibrary;
|
2023-09-07 10:17:04 -04:00
|
|
|
use Pterodactyl\BlueprintFramework\Services\PlaceholderService\BlueprintPlaceholderService;
|
2023-04-05 15:29:58 -04:00
|
|
|
use Pterodactyl\Contracts\Repository\SettingsRepositoryInterface;
|
|
|
|
use Illuminate\Contracts\Config\Repository as ConfigRepository;
|
|
|
|
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(
|
|
|
|
private BlueprintVariableService $bp,
|
|
|
|
private BlueprintTelemetryService $telemetry,
|
2023-09-07 15:12:33 -04:00
|
|
|
private BlueprintExtensionLibrary $bplib,
|
2023-06-02 10:37:38 -04:00
|
|
|
private BlueprintPlaceholderService $placeholderservice,
|
2023-04-05 15:29:58 -04:00
|
|
|
|
2023-06-02 10:37:38 -04:00
|
|
|
private SoftwareVersionService $version,
|
|
|
|
private ViewFactory $view,
|
|
|
|
private Kernel $kernel,
|
|
|
|
private AlertsMessageBag $alert,
|
|
|
|
private ConfigRepository $config,
|
|
|
|
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
|
|
|
|
{
|
2023-08-29 08:18:07 -04:00
|
|
|
// The following code rerolls the panel identifier used for telemetry
|
|
|
|
// when the version name changes.
|
2023-06-02 10:37:38 -04:00
|
|
|
if ($this->settings->get('blueprint::panel:id') == "" || $this->bp->version() != $this->settings->get('blueprint::version:cache')) {
|
|
|
|
$this->settings->set('blueprint::panel:id', uniqid(rand())."@".$this->bp->version());
|
|
|
|
$this->settings->set('blueprint::version:cache', $this->bp->version());
|
2023-07-17 07:29:32 -04:00
|
|
|
$this->bp->config('TELEMETRY_ID',$this->settings->get("blueprint::panel:id"));
|
2023-06-02 10:37:38 -04:00
|
|
|
};
|
2023-08-29 08:18:07 -04:00
|
|
|
// Sync developer mode option with the core of Blueprint.
|
2023-08-07 09:50:54 -04:00
|
|
|
$this->bp->config('DEVELOPER', $this->settings->get('blueprint::developer'));
|
2023-06-02 10:37:38 -04:00
|
|
|
return $this->view->make(
|
|
|
|
'admin.extensions.blueprint.index', [
|
|
|
|
'version' => $this->version,
|
2023-04-24 11:34:02 -04:00
|
|
|
|
2023-06-02 10:37:38 -04:00
|
|
|
'bp' => $this->bp,
|
|
|
|
'bplib' => $this->bplib,
|
|
|
|
'telemetry' => $this->telemetry,
|
2023-04-05 15:29:58 -04: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.
|
2023-06-02 10:37:38 -04:00
|
|
|
$this->bplib->notify("Your changes have been saved.");
|
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',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|