Improve admin notification api by using Pterodactyl database instead of local files.

This commit is contained in:
purple 2023-09-07 20:51:45 +02:00
parent d6b854c7ea
commit cbfb8f9ce1
4 changed files with 8 additions and 15 deletions

View file

@ -40,20 +40,17 @@ class BlueprintAdminLibrary
*/
public function notify($text) {
$this->dbSet("blueprint", "notification:text", $text);
shell_exec("cd ".escapeshellarg($this->placeholder->folder()).";echo ".escapeshellarg($text)." > .blueprint/data/internal/db/notification;");
return;
}
public function notifyAfter($delay, $text) {
$this->dbSet("blueprint", "notification:text", $text);
shell_exec("cd ".escapeshellarg($this->placeholder->folder()).";echo ".escapeshellarg($text)." > .blueprint/data/internal/db/notification;");
header("Refresh:$delay");
return;
}
public function notifyNow($text) {
$this->dbSet("blueprint", "notification:text", $text);
shell_exec("cd ".escapeshellarg($this->placeholder->folder()).";echo ".escapeshellarg($text)." > .blueprint/data/internal/db/notification;");
header("Refresh:0");
return;
}

View file

@ -33,6 +33,7 @@ class BlueprintVariableService
}
public function dbGet($key): string {
// BlueprintExtensionLibrary is preferred where possible.
$a = $this->settings->get("blueprint::".$key);
if (!$a) {
return "";
@ -42,6 +43,7 @@ class BlueprintVariableService
}
public function dbSet($key, $value): void {
// BlueprintExtensionLibrary is preferred where possible.
$this->settings->set('blueprint::' . $key, $value);
return;
}

View file

@ -1 +0,0 @@
true

View file

@ -62,7 +62,7 @@
</li>
<li>
<!-- The puzzle icon in the admin panel to manage and configure your installed extensions. -->
<li><a href="{{ route('admin.extensions') }}" data-toggle="tooltip" data-placement="bottom" title="Extensions"><i class='fa fa-puzzle-piece <?php if(shell_exec("cd &bp.folder&;cat .blueprint/data/internal/db/onboarding") == "true"){ echo "bx-flashing"; } ?>'></i></a></li>
<li><a href="{{ route('admin.extensions') }}" data-toggle="tooltip" data-placement="bottom" title="Extensions"><i class='fa fa-puzzle-piece <?php if($blueprint->fileRead("&bp.folder&/.blueprint/data/internal/db/onboarding") == "true"){ echo "bx-flashing"; } ?>'></i></a></li>
</li>
<li>
<li><a href="{{ route('index') }}" data-toggle="tooltip" data-placement="bottom" title="Exit Admin Control"><i class="fa fa-server"></i></a></li>
@ -162,29 +162,24 @@
@yield('content')
<?php
// This could be done so much easier if we modified the controller instead of only the blade template.
// However, we need to overwrite the least amount of files as possible to make Blueprint work nice with
// panel updates, other modifications (most of the time) and itself.
//
// Files are currently fetched with shell_exec but this is subject to change. We might switch to using
// built-in PHP stuff instead.
// This might be further improved later.
if(shell_exec("cd &bp.folder&;cat .blueprint/data/internal/db/onboarding") == "true") {
if($blueprint->fileRead("&bp.folder&/.blueprint/data/internal/db/onboarding") == "true") {
echo "
<div class=\"notification\">
<p>Blueprint has now been installed, click the extension icon to take a look.</p>
</div>";
`cd &bp.folder&;rm .blueprint/data/internal/db/onboarding;`;
fileWipe("&bp.folder&/.blueprint/data/internal/db/onboarding");
}
$notification = shell_exec("cd &bp.folder&;cat .blueprint/data/internal/db/notification");
$notification = $blueprint->dbGet("blueprint", "notification:text");
if($notification != null) {
echo "<div class=\"notification\">
<p>".$notification."</p>
</div>
";
shell_exec("cd &bp.folder&;rm .blueprint/data/internal/db/notification;touch .blueprint/data/internal/db/notification;");
$blueprint->dbSet("blueprint", "notification:text", "");
}
?>
</section>