mirror of
https://github.com/pterodactyl/panel.git
synced 2026-12-02 20:35:50 -05:00
Added custom user avatar support.
## Extra Details:
- Users can upload custom `PNG, JPEG, SVG, WebP, AVIF`, and `ICO`
avatars.
- Added avatar management to the user account area.
- Added admin controls to update and remove user avatars.
- Custom User avatars appear in:
- Panel Navbar.
- Panel Admin Activity Logs.
- Server Sub user List.
- Server Activity Logs
- Personal Account Activity Logs.
- Server Ownership Details.
---
<img width="1329" height="327"
alt="{B32EBD7F-1FCA-4356-966C-0D60A9A23E49}"
src="https://github.com/user-attachments/assets/881fa5b3-9599-4370-975d-83b6bd91a7d1"
/>
---
<img width="997" height="847" alt="adminpage"
src="https://github.com/user-attachments/assets/989acbcc-351c-431b-ab7f-557ba4c7e070"
/>
---
<img width="955" height="781" alt="serverinfo"
src="https://github.com/user-attachments/assets/6556afac-1971-4112-9686-b71137072c5f"
/>
---
<img width="1376" height="919" alt="userarea"
src="https://github.com/user-attachments/assets/d49f0ddb-1f38-4884-b186-8db78bfed4b0"
/>
---
<img width="936" height="232" alt="userslist"
src="https://github.com/user-attachments/assets/0e8a4b4a-719a-4d52-a485-d7577736b43f"
/>
---
<img width="983" height="772" alt="activity"
src="https://github.com/user-attachments/assets/37ef7176-a804-43f7-ae32-ae65e1a2671b"
/>
145 lines
4.3 KiB
PHP
145 lines
4.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Pterodactyl\Providers;
|
|
|
|
use Illuminate\Contracts\Config\Repository as ConfigRepository;
|
|
use Illuminate\Contracts\Encryption\DecryptException;
|
|
use Illuminate\Contracts\Encryption\Encrypter;
|
|
use Illuminate\Database\QueryException;
|
|
use Illuminate\Support\Arr;
|
|
use Illuminate\Support\ServiceProvider;
|
|
use Psr\Log\LoggerInterface as Log;
|
|
use Pterodactyl\Models\Setting;
|
|
|
|
class SettingsServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* An array of configuration keys to override with database values
|
|
* if they exist.
|
|
*
|
|
* @var list<string>
|
|
*/
|
|
protected array $keys = [
|
|
'app:name',
|
|
'app:locale',
|
|
'recaptcha:enabled',
|
|
'recaptcha:secret_key',
|
|
'recaptcha:website_key',
|
|
'pterodactyl:guzzle:timeout',
|
|
'pterodactyl:guzzle:connect_timeout',
|
|
'pterodactyl:console:count',
|
|
'pterodactyl:console:frequency',
|
|
'pterodactyl:auth:2fa_required',
|
|
'pterodactyl:client_features:allocations:enabled',
|
|
'pterodactyl:client_features:allocations:range_start',
|
|
'pterodactyl:client_features:allocations:range_end',
|
|
'pterodactyl:client_features:avatars:enabled',
|
|
];
|
|
|
|
/**
|
|
* Keys specific to the mail driver that are only grabbed from the database
|
|
* when using the SMTP driver.
|
|
*
|
|
* @var list<string>
|
|
*/
|
|
protected array $emailKeys = [
|
|
'mail:mailers:smtp:host',
|
|
'mail:mailers:smtp:port',
|
|
'mail:mailers:smtp:encryption',
|
|
'mail:mailers:smtp:username',
|
|
'mail:mailers:smtp:password',
|
|
'mail:from:address',
|
|
'mail:from:name',
|
|
];
|
|
|
|
/**
|
|
* Keys that are encrypted and should be decrypted when set in the
|
|
* configuration array.
|
|
*
|
|
* @var list<string>
|
|
*/
|
|
protected static array $encrypted = [
|
|
'mail:mailers:smtp:password',
|
|
];
|
|
|
|
/**
|
|
* @return list<string>
|
|
*/
|
|
public static function getEncryptedKeys(): array
|
|
{
|
|
return self::$encrypted;
|
|
}
|
|
|
|
/**
|
|
* Boot the service provider.
|
|
*/
|
|
public function boot(ConfigRepository $config, Encrypter $encrypter, Log $log): void
|
|
{
|
|
// Only set the email driver settings from the database if we
|
|
// are configured using SMTP as the driver.
|
|
if ($config->get('mail.default') === 'smtp') {
|
|
$this->keys = array_merge($this->keys, $this->emailKeys);
|
|
}
|
|
|
|
try {
|
|
$values = Setting::query()->pluck('value', 'key')->all();
|
|
} catch (QueryException $queryException) {
|
|
$log->notice('A query exception was encountered while trying to load settings from the database: '.$queryException->getMessage());
|
|
|
|
return;
|
|
}
|
|
|
|
foreach ($this->keys as $key) {
|
|
$default = $config->get(str_replace(':', '.', $key));
|
|
$value = Arr::get($values, 'settings::'.$key, $default);
|
|
if (in_array($key, self::$encrypted, true) && is_string($value)) {
|
|
try {
|
|
$value = $encrypter->decrypt($value);
|
|
} catch (DecryptException) {
|
|
}
|
|
}
|
|
|
|
switch (is_string($value) ? mb_strtolower($value) : $value) {
|
|
case 'true':
|
|
case '(true)':
|
|
$value = true;
|
|
break;
|
|
case 'false':
|
|
case '(false)':
|
|
$value = false;
|
|
break;
|
|
case 'empty':
|
|
case '(empty)':
|
|
$value = '';
|
|
break;
|
|
case 'null':
|
|
case '(null)':
|
|
$value = null;
|
|
}
|
|
|
|
$config->set(str_replace(':', '.', $key), $this->cast($value, $default));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Settings are stored as strings, so a stored value takes the type of the
|
|
* configuration value it replaces. Keys without a typed default keep the
|
|
* stored value.
|
|
*/
|
|
protected function cast(mixed $value, mixed $default): mixed
|
|
{
|
|
if (! is_string($value)) {
|
|
return $value;
|
|
}
|
|
|
|
return match (true) {
|
|
is_int($default) => (int) $value,
|
|
is_float($default) => (float) $value,
|
|
is_bool($default) => filter_var($value, FILTER_VALIDATE_BOOL),
|
|
default => $value,
|
|
};
|
|
}
|
|
}
|