컨트롤 mnt 공용 인증 의존 제거

This commit is contained in:
seo committed 2026-07-28 22:36:04 +09:00
1 parent 3a41351b0b
commit 892e37e72d
2 files changed
+53 -26

No files matched your search

+51 -24
View File
@@ -865,36 +865,66 @@ function control_admin_session_from_rhymix_or_custom(): bool
}
$checked = false;
$commonAuth = '/mnt/synology-web/custom/common/auth.php';
if (!is_file($commonAuth) || !is_readable($commonAuth)) {
$cookieHeader = trim((string)($_SERVER['HTTP_COOKIE'] ?? ''));
if ($cookieHeader === '') {
return false;
}
try {
require_once $commonAuth;
$checked = (function_exists('custom_auth_cookie_is_admin') && custom_auth_cookie_is_admin())
|| (function_exists('custom_is_site_admin') && custom_is_site_admin());
} catch (Throwable) {
$checked = false;
}
$session = control_launcher_session($cookieHeader);
$checked = is_array($session) && !empty($session['authenticated']) && !empty($session['admin']);
return $checked;
}
function clear_common_admin_auth_cookie_if_available(): void
{
$commonAuth = '/mnt/synology-web/custom/common/auth.php';
if (!is_file($commonAuth) || !is_readable($commonAuth)) {
return;
$secure = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off');
foreach (['custom_access', 'access'] as $name) {
setcookie($name, '', [
'expires' => time() - 3600,
'path' => '/',
'secure' => $secure,
'httponly' => $name !== 'access',
'samesite' => 'Strict',
]);
}
}
function control_launcher_session(string $cookieHeader): ?array
{
$url = 'https://chaegeon.com/custom/launcher/api.php?session=1';
$body = false;
if (function_exists('curl_init')) {
$ch = curl_init($url);
if ($ch !== false) {
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 2,
CURLOPT_TIMEOUT => 4,
CURLOPT_HTTPHEADER => [
'Cookie: ' . $cookieHeader,
'User-Agent: control-auth/1.0',
],
]);
$body = curl_exec($ch);
curl_close($ch);
}
}
try {
require_once $commonAuth;
if (function_exists('custom_clear_auth_cookie')) {
custom_clear_auth_cookie();
}
} catch (Throwable) {
if ($body === false) {
$context = stream_context_create([
'http' => [
'method' => 'GET',
'timeout' => 4,
'header' => "Cookie: {$cookieHeader}\r\nUser-Agent: control-auth/1.0\r\n",
],
]);
$body = @file_get_contents($url, false, $context);
}
$data = is_string($body) ? json_decode($body, true) : null;
return is_array($data) ? $data : null;
}
function require_login(): void
@@ -1256,17 +1286,14 @@ function update_presence_fan_policy_state(array $values): void
function control_common_config(): array
{
global $controlSecretConfig;
static $config = null;
if ($config !== null) {
return $config;
}
$file = '/mnt/synology-web/custom/common/config.php';
if (!is_file($file)) {
return $config = [];
}
$loaded = require $file;
$loaded = $controlSecretConfig['common'] ?? [];
return $config = is_array($loaded) ? $loaded : [];
}