feat(core): Sync telemetry id and developer mode status through artisan command.

This commit is contained in:
purple 2023-11-01 14:51:42 +01:00
parent 4d05f71f98
commit aa3668285c
5 changed files with 55 additions and 14 deletions

View file

@ -0,0 +1,44 @@
<?php
namespace Pterodactyl\Console\Commands\BlueprintFramework;
use Illuminate\Console\Command;
use Pterodactyl\BlueprintFramework\Services\VariableService\BlueprintVariableService;
use Pterodactyl\BlueprintFramework\Libraries\ExtensionLibrary\Admin\BlueprintAdminLibrary as BlueprintExtensionLibrary;
use Pterodactyl\Contracts\Repository\SettingsRepositoryInterface;
class SyncCommand extends Command
{
protected $description = 'Forward some database values to Blueprint.';
protected $signature = 'bp:sync';
/**
* TelemetryCommand constructor.
*/
public function __construct(
private BlueprintVariableService $bp,
private BlueprintExtensionLibrary $blueprint,
private SettingsRepositoryInterface $settings,
) { parent::__construct(); }
/**
* Handle execution of command.
*/
public function handle()
{
// The following code rerolls the panel identifier used for telemetry
// when the version name changes.
if ($this->settings->get('blueprint::panel:id') == "" || $this->bp->version() != $this->settings->get('blueprint::version:cache')) {
if ($this->settings->get('blueprint::telemetry') == "") {$this->settings->set('blueprint::telemetry', "true");}
if ($this->settings->get('blueprint::telemetry') == "false") {
$this->bp->config('TELEMETRY_ID','KEY_NOT_UPDATED');
} else {
$this->settings->set('blueprint::panel:id', uniqid(rand())."@".$this->bp->version());
$this->settings->set('blueprint::version:cache', $this->bp->version());
$this->bp->config('TELEMETRY_ID',$this->settings->get("blueprint::panel:id"));
}
};
// Sync developer mode option with the core of Blueprint.
$this->bp->config('DEVELOPER', $this->settings->get('blueprint::developer'));
}
}

View file

@ -43,13 +43,6 @@ class BlueprintExtensionController extends Controller
*/ */
public function index(): View public function index(): View
{ {
// The following code rerolls the panel identifier used for telemetry
// when the version name changes.
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());
$this->bp->config('TELEMETRY_ID',$this->settings->get("blueprint::panel:id"));
};
// Sync developer mode option with the core of Blueprint. // Sync developer mode option with the core of Blueprint.
$this->bp->config('DEVELOPER', $this->settings->get('blueprint::developer')); $this->bp->config('DEVELOPER', $this->settings->get('blueprint::developer'));
return $this->view->make( return $this->view->make(

View file

@ -61,6 +61,7 @@ fi
# Write environment variables. # Write environment variables.
export BLUEPRINT__FOLDER=$FOLDER export BLUEPRINT__FOLDER=$FOLDER
export BLUEPRINT__VERSION=$VERSION export BLUEPRINT__VERSION=$VERSION
export NODE_OPTIONS=--openssl-legacy-provider
# Automatically navigate to the Pterodactyl directory when running the core. # Automatically navigate to the Pterodactyl directory when running the core.
cd $FOLDER cd $FOLDER
@ -110,9 +111,6 @@ if [[ $LIB__bash_colors == "missing" ]]; then
log_yellowb() { echo -e "$1"; } log_yellowb() { echo -e "$1"; }
fi fi
# Make sure yarn doesn't freak out when building the panel.
export NODE_OPTIONS=--openssl-legacy-provider
# -config # -config
@ -128,8 +126,11 @@ if [[ "$1" == "-config" ]]; then
# cDEVELOPER # cDEVELOPER
# Enable/Disable developer mode. # Enable/Disable developer mode.
if [[ $cDEVELOPER != "" ]]; then if [[ $cDEVELOPER != "" ]]; then
if [[ $cDEVELOPER == "true" ]]; then dbAdd "blueprint.developerEnabled" if [[ $cDEVELOPER == "true" ]]; then
else dbRemove "blueprint.developerEnabled"; fi dbAdd "blueprint.developerEnabled"
else
dbRemove "blueprint.developerEnabled"
fi
fi fi
echo . echo .
@ -279,6 +280,10 @@ if [[ $1 != "-bash" ]]; then
log_bright "[INFO] Updating route cache to include recent changes.." log_bright "[INFO] Updating route cache to include recent changes.."
php artisan route:cache &> /dev/null php artisan route:cache &> /dev/null
# Sync some database values.
log_bright "[INFO] Syncing database values.."
php artisan bp:sync &> /dev/null
# Put application into production. # Put application into production.
log_bright "[INFO] Disable maintenance." log_bright "[INFO] Disable maintenance."
php artisan up php artisan up
@ -875,7 +880,7 @@ fi
if [[ ( $2 == "help" ) || ( $2 == "-help" ) || ( $2 == "--help" ) || if [[ ( $2 == "help" ) || ( $2 == "-help" ) || ( $2 == "--help" ) ||
( $2 == "h" ) || ( $2 == "-h" ) || ( $2 == "--h" ) ]]; then VCMD="y" ( $2 == "h" ) || ( $2 == "-h" ) || ( $2 == "--h" ) ]]; then VCMD="y"
if [[ $(cat .blueprint/data/internal/db/developer) == "true"* ]]; then if dbValidate "blueprint.developerEnabled"; then
help_dev_status="" help_dev_status=""
help_dev_primary="\e[34;1m" help_dev_primary="\e[34;1m"
help_dev_secondary="\e[34m" help_dev_secondary="\e[34m"

0
blueprint/tmp/.gitkeep Normal file
View file

View file

@ -1 +0,0 @@
This folder contains temp files for Blueprint. When this folder is deleted, Blueprint may not function correctly.