You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.5 KiB
PHP
55 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Cloud;
|
|
|
|
use App\Models\User;
|
|
use App\Services\Config;
|
|
|
|
/**
|
|
* Resolve the configured super administrator used by read-only daemons.
|
|
*
|
|
* This is an authentication boundary for internal engine requests, not an
|
|
* interactive login. Callers supply a fixed, non-secret session label so the
|
|
* signed actor remains attributable without duplicating super-admin parsing.
|
|
*/
|
|
final class CloudDaemonActor
|
|
{
|
|
public static function resolve(string $sessionId): ?array
|
|
{
|
|
if (preg_match('/^cloud-[a-z0-9-]{3,48}$/D', $sessionId) !== 1) {
|
|
return null;
|
|
}
|
|
|
|
$ids = [];
|
|
foreach (explode(',', (string) Config::get('super_admin', '')) as $value) {
|
|
$id = filter_var(trim($value), FILTER_VALIDATE_INT,
|
|
['options' => ['min_range' => 1]]);
|
|
if ($id !== false) {
|
|
$ids[(int) $id] = true;
|
|
}
|
|
}
|
|
if ($ids === []) {
|
|
return null;
|
|
}
|
|
|
|
try {
|
|
$user = User::whereIn('id', array_keys($ids))
|
|
->where('enable', 1)->where('is_admin', 1)
|
|
->orderBy('id')->first(['id']);
|
|
} catch (\Throwable $error) {
|
|
return null;
|
|
}
|
|
if ($user === null || (int) $user->id < 1) {
|
|
return null;
|
|
}
|
|
|
|
return [
|
|
'user_id' => (int) $user->id,
|
|
'is_admin' => true,
|
|
'is_super_admin' => true,
|
|
'can_manage' => true,
|
|
'session_id' => $sessionId,
|
|
];
|
|
}
|
|
}
|