mirror of
git://f0xx.org/ac/ac-deploy
synced 2026-08-12 18:12:19 +03:00
Use ac_crash_sess shared session, allow password reset without auth_request, update grafana.ini template and alert rules. Co-authored-by: Cursor <cursoragent@cursor.com>
36 lines
935 B
PHP
36 lines
935 B
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* Grafana / Alertmanager / broadcast auth_request endpoint.
|
|
*
|
|
* nginx `internal;` blocks direct browser access. Returns 200 + X-WEBAUTH-USER when
|
|
* the shared Android Cast PHP session (ac_crash_sess) is valid, 401 otherwise.
|
|
*
|
|
* Deploy: /var/www/ac/composed/backend/public/api/grafana-auth-check.php
|
|
*/
|
|
|
|
require_once dirname(__DIR__, 4) . '/platform/shared_session.php';
|
|
|
|
platform_start_session('ac_crash_sess', '/app/androidcast_project');
|
|
|
|
$user = $_SESSION['user'] ?? null;
|
|
|
|
if (empty($user['id'])) {
|
|
http_response_code(401);
|
|
exit;
|
|
}
|
|
|
|
if (!empty($user['pending_2fa'])) {
|
|
http_response_code(401);
|
|
exit;
|
|
}
|
|
|
|
$username = (string) ($user['username'] ?? $user['email'] ?? 'user_' . $user['id']);
|
|
$grafanaUser = preg_replace('/[^a-zA-Z0-9._@-]/', '_', $username);
|
|
|
|
http_response_code(200);
|
|
header('X-WEBAUTH-USER: ' . $grafanaUser);
|
|
header('Content-Type: text/plain');
|
|
echo 'ok';
|