Finish implementing telemetry

This commit is contained in:
purple 2023-04-11 21:54:57 +02:00
parent c897348d8a
commit b63c9951e0
5 changed files with 25 additions and 27 deletions

View file

@ -9,6 +9,7 @@ use Illuminate\Contracts\Console\Kernel;
use Pterodactyl\Http\Controllers\Controller; use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Services\Helpers\SoftwareVersionService; use Pterodactyl\Services\Helpers\SoftwareVersionService;
use Pterodactyl\Services\Helpers\BlueprintVariableService; use Pterodactyl\Services\Helpers\BlueprintVariableService;
use Pterodactyl\Services\Helpers\BlueprintTelemetryService;
use Pterodactyl\Contracts\Repository\SettingsRepositoryInterface; use Pterodactyl\Contracts\Repository\SettingsRepositoryInterface;
use Illuminate\Contracts\Config\Repository as ConfigRepository; use Illuminate\Contracts\Config\Repository as ConfigRepository;
use Pterodactyl\Http\Requests\Admin\Extensions\Blueprint\BlueprintSettingsFormRequest; use Pterodactyl\Http\Requests\Admin\Extensions\Blueprint\BlueprintSettingsFormRequest;
@ -22,6 +23,7 @@ class BlueprintExtensionController extends Controller
*/ */
public function __construct( public function __construct(
private BlueprintVariableService $bp, private BlueprintVariableService $bp,
private BlueprintTelemetryService $telemetry,
private SoftwareVersionService $version, private SoftwareVersionService $version,
private ViewFactory $view, private ViewFactory $view,
@ -44,6 +46,7 @@ class BlueprintExtensionController extends Controller
'admin.extensions.blueprint.index', [ 'admin.extensions.blueprint.index', [
'version' => $this->version, 'version' => $this->version,
'bp' => $this->bp, 'bp' => $this->bp,
'telemetry' => $this->telemetry,
'root' => "/admin/extensions/blueprint", 'root' => "/admin/extensions/blueprint",
'a' => $this->bp->a(), 'a' => $this->bp->a(),
'b' => $this->bp->b(), 'b' => $this->bp->b(),

View file

@ -8,19 +8,12 @@
*/ */
namespace Pterodactyl\Services\Helpers; namespace Pterodactyl\Services\Helpers;
use Pterodactyl\Contracts\Repository\SettingsRepositoryInterface;
use Pterodactyl\Services\Helpers\BlueprintVariableService;
use Pterodactyl\Services\Helpers\BlueprintTelemetryService;
use Pterodactyl\Services\Helpers\BlueprintPlaceholderService;
class BlueprintExtensionLibrary class BlueprintExtensionLibrary
{ {
// Construct BlueprintExtensionLibrary // Construct BlueprintExtensionLibrary
public function __construct( public function __construct(
private SettingsRepositoryInterface $settings, private SettingsRepositoryInterface $settings,
private BlueprintVariableService $bp,
private BlueprintTelemetryService $telemetry,
private BlueprintPlaceholderService $placeholder,
) { ) {
} }

View file

@ -2,18 +2,12 @@
namespace Pterodactyl\Services\Helpers; namespace Pterodactyl\Services\Helpers;
use Pterodactyl\Contracts\Repository\SettingsRepositoryInterface; use Pterodactyl\Contracts\Repository\SettingsRepositoryInterface;
use Pterodactyl\Services\Helpers\BlueprintVariableService;
use Pterodactyl\Services\Helpers\BlueprintExtensionLibrary;
use Pterodactyl\Services\Helpers\BlueprintTelemetryService;
class BlueprintPlaceholderService class BlueprintPlaceholderService
{ {
// Construct BlueprintPlaceholderService // Construct BlueprintPlaceholderService
public function __construct( public function __construct(
private SettingsRepositoryInterface $settings, private SettingsRepositoryInterface $settings,
private BlueprintVariableService $bp,
private BlueprintExtensionLibrary $lib,
private BlueprintTelemetryService $telemetry,
) { ) {
} }

View file

@ -2,28 +2,35 @@
namespace Pterodactyl\Services\Helpers; namespace Pterodactyl\Services\Helpers;
use Pterodactyl\Contracts\Repository\SettingsRepositoryInterface; use Pterodactyl\Contracts\Repository\SettingsRepositoryInterface;
use Pterodactyl\Services\Helpers\BlueprintVariableService;
use Pterodactyl\Services\Helpers\BlueprintExtensionLibrary;
use Pterodactyl\Services\Helpers\BlueprintPlaceholderService;
class BlueprintTelemetryService class BlueprintTelemetryService
{ {
// Construct BlueprintTelemetryService // Construct BlueprintTelemetryService
public function __construct( public function __construct(
private SettingsRepositoryInterface $settings, private SettingsRepositoryInterface $settings,
private BlueprintVariableService $bp,
private BlueprintExtensionLibrary $lib,
private BlueprintPlaceholderService $placeholder,
) { ) {
} }
public function db($type, $table, $key, $value) { public function send($event) {
if ($type === "get") { if ($this->settings->get('blueprint::telemetry') == "false") { return; };
return $this->settings->get($table."::".$key); if ($this->settings->get('blueprint::telemetry:id') == "") { $this->settings->set('blueprint::telemetry:id', uniqid(rand())); };
};
if ($type === "set") { $curl = curl_init();
return $this->settings->set($table."::".$key, $value);
}; curl_setopt_array($curl, array(
return true; CURLOPT_URL => 'http://relay.ptero.shop:3511/send/'.$this->settings->get('blueprint::telemetry:id')."/".$event."/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
));
$response = curl_exec($curl);
curl_close($curl);
return;
} }
} }

View file

@ -16,6 +16,7 @@
@section('content') @section('content')
{{ $bp->rlKey() }} {{ $bp->rlKey() }}
{{ $telemetry->send("SERVE_BLUEPRINT_ADMIN") }}
<p>Blueprint is the framework that powers all Blueprint-compatible extensions, enabling multiple extensions to be installed and used simultaneously.</p> <p>Blueprint is the framework that powers all Blueprint-compatible extensions, enabling multiple extensions to be installed and used simultaneously.</p>
<div class="row"> <div class="row">
<div class="col-xs-3"> <div class="col-xs-3">