53 lines
1.6 KiB
PHP
53 lines
1.6 KiB
PHP
<?php
|
|
header('Content-Type: application/json; charset=UTF-8');
|
|
header('Cache-Control: no-store');
|
|
|
|
function mvlog_load_push_config_for_public_key(string $mvlogRoot): ?array {
|
|
$candidates = [
|
|
'/etc/mvlog/push.php',
|
|
'/etc/mvlog/push.json',
|
|
$mvlogRoot . '/push.json',
|
|
(getenv('HOME') !== false ? getenv('HOME') . '/.config/mvlog/push.json' : null),
|
|
];
|
|
|
|
foreach ($candidates as $candidate) {
|
|
if (!$candidate || !is_file($candidate) || !is_readable($candidate)) continue;
|
|
|
|
$cfg = null;
|
|
if (str_ends_with($candidate, '.php')) {
|
|
$loaded = @require $candidate;
|
|
if (is_array($loaded)) $cfg = $loaded;
|
|
} else {
|
|
$decoded = json_decode((string)@file_get_contents($candidate), true);
|
|
if (is_array($decoded)) $cfg = $decoded;
|
|
}
|
|
|
|
if (!is_array($cfg)) continue;
|
|
|
|
$public = (string)($cfg['public_key'] ?? $cfg['vapidPublicKey'] ?? '');
|
|
$private = (string)($cfg['private_key'] ?? $cfg['vapidPrivateKey'] ?? '');
|
|
$subject = (string)($cfg['subject'] ?? $cfg['vapidSubject'] ?? '');
|
|
|
|
if ($public !== '' && $private !== '') {
|
|
return [
|
|
'public_key' => $public,
|
|
'private_key' => $private,
|
|
'subject' => $subject,
|
|
'_source' => $candidate,
|
|
];
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
$cfg = mvlog_load_push_config_for_public_key(__DIR__);
|
|
if (!$cfg) {
|
|
echo json_encode(['enabled' => false]);
|
|
exit;
|
|
}
|
|
|
|
echo json_encode([
|
|
'enabled' => true,
|
|
'publicKey' => (string)$cfg['public_key'],
|
|
], JSON_UNESCAPED_SLASHES);
|