2023-09-07 10:17:04 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// Core file for the admin-side library for Blueprint Extensions
|
|
|
|
|
|
|
|
|
|
|
|
namespace Pterodactyl\BlueprintFramework\Libraries\ExtensionLibrary\Admin;
|
|
|
|
|
|
|
|
use Pterodactyl\Contracts\Repository\SettingsRepositoryInterface;
|
|
|
|
|
|
|
|
class BlueprintAdminLibrary
|
|
|
|
{
|
|
|
|
// Construct core
|
|
|
|
public function __construct(
|
|
|
|
private SettingsRepositoryInterface $settings,
|
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
2024-04-27 09:08:03 -04:00
|
|
|
/**
|
|
|
|
* Fetch a record from the database.
|
|
|
|
*
|
|
|
|
* @param string $table Database table
|
|
|
|
* @param string $record Database record
|
|
|
|
* @return mixed Database value
|
|
|
|
*
|
|
|
|
* [BlueprintExtensionLibrary documentation](https://blueprint.zip/docs/?page=documentation/$blueprint)
|
|
|
|
*/
|
2024-04-27 09:17:09 -04:00
|
|
|
public function dbGet($table, $record): mixed {
|
2023-09-07 10:17:04 -04:00
|
|
|
return $this->settings->get($table."::".$record);
|
|
|
|
}
|
|
|
|
|
2024-04-27 09:08:03 -04:00
|
|
|
/**
|
|
|
|
* Set a database record.
|
|
|
|
*
|
|
|
|
* @param string $table Database table
|
|
|
|
* @param string $record Database record
|
|
|
|
* @param string $value Value to store
|
|
|
|
*
|
|
|
|
* [BlueprintExtensionLibrary documentation](https://blueprint.zip/docs/?page=documentation/$blueprint)
|
|
|
|
*/
|
2023-09-07 10:17:04 -04:00
|
|
|
public function dbSet($table, $record, $value) {
|
|
|
|
return $this->settings->set($table."::".$record, $value);
|
|
|
|
}
|
|
|
|
|
2024-04-27 09:17:09 -04:00
|
|
|
/**
|
|
|
|
* Delete/forget a database record.
|
|
|
|
*
|
|
|
|
* @param string $table Database table
|
|
|
|
* @param string $record Database record
|
|
|
|
*
|
|
|
|
* [BlueprintExtensionLibrary documentation](https://blueprint.zip/docs/?page=documentation/$blueprint)
|
|
|
|
*/
|
|
|
|
public function dbForget($table, $record) {
|
|
|
|
return $this->settings->forget($table."::".$record);
|
|
|
|
}
|
|
|
|
|
2024-04-27 09:08:03 -04:00
|
|
|
/**
|
|
|
|
* Display a notification on the Pterodactyl admin panel (on next page load).
|
|
|
|
*
|
|
|
|
* @param string $text Notification contents
|
|
|
|
* @return void Nothing is returned
|
|
|
|
*
|
|
|
|
* [BlueprintExtensionLibrary documentation](https://blueprint.zip/docs/?page=documentation/$blueprint)
|
|
|
|
*/
|
|
|
|
public function notify($text): void {
|
2023-09-07 10:17:04 -04:00
|
|
|
$this->dbSet("blueprint", "notification:text", $text);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-04-27 09:08:03 -04:00
|
|
|
/**
|
|
|
|
* Display a notification on the Pterodactyl admin panel and refresh the page after a certain delay.
|
|
|
|
*
|
|
|
|
* @param string $delay Refresh after (in seconds)
|
|
|
|
* @param string $text Notification contents
|
|
|
|
* @return void Nothing is returned
|
|
|
|
*
|
|
|
|
* [BlueprintExtensionLibrary documentation](https://blueprint.zip/docs/?page=documentation/$blueprint)
|
|
|
|
*/
|
|
|
|
public function notifyAfter($delay, $text): void {
|
2023-09-07 10:17:04 -04:00
|
|
|
$this->dbSet("blueprint", "notification:text", $text);
|
|
|
|
header("Refresh:$delay");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-04-27 09:08:03 -04:00
|
|
|
/**
|
|
|
|
* Display a notification on the Pterodactyl admin panel and refresh the page instantly.
|
|
|
|
* Behaves the same as calling `notifyAfter()` with a delay of zero.
|
|
|
|
*
|
|
|
|
* @param string $text Notification contents
|
|
|
|
* @return void Nothing is returned
|
|
|
|
*
|
|
|
|
* [BlueprintExtensionLibrary documentation](https://blueprint.zip/docs/?page=documentation/$blueprint)
|
|
|
|
*/
|
|
|
|
public function notifyNow($text): void {
|
2023-09-07 10:17:04 -04:00
|
|
|
$this->dbSet("blueprint", "notification:text", $text);
|
|
|
|
header("Refresh:0");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-04-27 09:08:03 -04:00
|
|
|
/**
|
|
|
|
* Read and returns the content of a given file.
|
|
|
|
*
|
|
|
|
* @param string $path Path to file
|
|
|
|
* @return string File contents
|
|
|
|
* @throws string Errors encountered by `cat` shell utility
|
|
|
|
*
|
|
|
|
* [BlueprintExtensionLibrary documentation](https://blueprint.zip/docs/?page=documentation/$blueprint)
|
|
|
|
*/
|
2023-09-07 10:17:04 -04:00
|
|
|
public function fileRead($path) {
|
2023-10-06 08:31:49 -04:00
|
|
|
return shell_exec("cat ".escapeshellarg($path).";");
|
2023-09-07 10:17:04 -04:00
|
|
|
}
|
|
|
|
|
2024-04-27 09:08:03 -04:00
|
|
|
/**
|
|
|
|
* Attempts to (non-recursively) create a file.
|
|
|
|
*
|
|
|
|
* @param string $path File name/path
|
|
|
|
* @return string Empty string unless error
|
|
|
|
* @throws string Errors encountered by `touch` shell utility
|
|
|
|
*
|
|
|
|
* [BlueprintExtensionLibrary documentation](https://blueprint.zip/docs/?page=documentation/$blueprint)
|
|
|
|
*/
|
2023-09-07 10:17:04 -04:00
|
|
|
public function fileMake($path) {
|
|
|
|
return shell_exec("touch ".escapeshellarg($path).";");
|
|
|
|
}
|
|
|
|
|
2024-04-27 09:08:03 -04:00
|
|
|
/**
|
|
|
|
* Attempts to (recursively) remove a file/folder.
|
|
|
|
* It's good practice to terminate this function after a certain timeout, to prevent infinite page loads upon input. Blueprint attempts to use `yes` as an input for all questions, but might not succeed.
|
|
|
|
*
|
|
|
|
* @param string $path Path to file/folder
|
|
|
|
* @return string Empty string unless error
|
|
|
|
* @throws string Errors encountered by `rm` shell utility
|
|
|
|
*
|
|
|
|
* [BlueprintExtensionLibrary documentation](https://blueprint.zip/docs/?page=documentation/$blueprint)
|
|
|
|
*/
|
2023-09-07 10:17:04 -04:00
|
|
|
public function fileWipe($path) {
|
2024-04-27 09:08:03 -04:00
|
|
|
return shell_exec("yes | rm -r ".escapeshellarg($path).";");
|
2023-09-07 10:17:04 -04:00
|
|
|
}
|
2024-02-27 16:34:10 -05:00
|
|
|
|
2024-04-27 09:08:03 -04:00
|
|
|
/**
|
|
|
|
* Check if an extension is installed based on it's identifier.
|
|
|
|
*
|
|
|
|
* @param string $identifier Extension identifier
|
|
|
|
* @return bool Boolean
|
|
|
|
*
|
|
|
|
* [BlueprintExtensionLibrary documentation](https://blueprint.zip/docs/?page=documentation/$blueprint)
|
|
|
|
*/
|
|
|
|
public function extension($identifier): bool {
|
2024-02-27 16:34:10 -05:00
|
|
|
if(str_contains($this->fileRead("::f/.blueprint/extensions/blueprint/private/db/installed_extensions"), $identifier.',')) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2023-09-07 10:17:04 -04:00
|
|
|
}
|