mirror of
git://f0xx.org/ac/ac-deploy
synced 2026-07-29 05:59:05 +03:00
fix(cluster0): Gitea cluster proxy, 2FA seed, hub downloads nginx
Bind Gitea on all interfaces for cast02/03 proxy, fix stale 2FA lab-seed approve flow, add /v0/downloads/ and GITEA_UPSTREAM_HOST, and guard nginx configure against empty templates. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,35 +1,56 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/** 2FA challenge page helpers (QR short link for mobile handoff). */
|
||||
/** 2FA challenge page helpers — cross-device approval QR. */
|
||||
final class AuthTwoFactorPage {
|
||||
/** @return array{short_url?:string,qr_url?:string,long_url:string}|null */
|
||||
/**
|
||||
* Build the QR payload for the 2FA challenge screen.
|
||||
*
|
||||
* @return array{long_url:string,short_url?:string,qr_url?:string,raw_token:string}|null
|
||||
*/
|
||||
public static function qrPayload(): ?array {
|
||||
$uid = Auth::pending2faUserId();
|
||||
if ($uid <= 0) {
|
||||
return null;
|
||||
}
|
||||
$project = Auth::projectBasePath();
|
||||
$longUrl = 'https://apps.f0xx.org' . $project . '/?ref=2fa&uid=' . $uid;
|
||||
$ip = Auth::clientIp();
|
||||
$rawToken = AuthApproval::create($uid, session_id(), $ip);
|
||||
|
||||
$_SESSION['pending_2fa_approval_token'] = $rawToken;
|
||||
|
||||
$origin = rtrim((string) cfg('public_origin', 'https://apps.f0xx.org'), '/');
|
||||
$approveUrl = $origin . $project . '/two-factor/approve?token=' . urlencode($rawToken);
|
||||
|
||||
$payload = [
|
||||
'long_url' => $approveUrl,
|
||||
'raw_token' => $rawToken,
|
||||
'qr_url' => AuthTotp::qrImageUrl($approveUrl),
|
||||
];
|
||||
|
||||
if (!UrlShortenerDatabase::enabled() || !UrlShortenerDatabase::ping()) {
|
||||
return ['long_url' => $longUrl];
|
||||
return $payload;
|
||||
}
|
||||
$bearers = ShortLinksRepository::listBearers();
|
||||
if ($bearers === []) {
|
||||
return ['long_url' => $longUrl];
|
||||
return $payload;
|
||||
}
|
||||
$bearerId = (int) ($bearers[0]['id'] ?? 0);
|
||||
if ($bearerId <= 0) {
|
||||
return ['long_url' => $longUrl];
|
||||
return $payload;
|
||||
}
|
||||
$mint = ShortLinksRepository::createLink($bearerId, $longUrl, 900);
|
||||
$mint = ShortLinksRepository::createLink($bearerId, $approveUrl, 900);
|
||||
if (empty($mint['ok'])) {
|
||||
return ['long_url' => $longUrl];
|
||||
return $payload;
|
||||
}
|
||||
return [
|
||||
'long_url' => $longUrl,
|
||||
'short_url' => (string) ($mint['short_url'] ?? ''),
|
||||
'qr_url' => (string) ($mint['qr_url'] ?? ''),
|
||||
];
|
||||
$shortUrl = (string) ($mint['short_url'] ?? '');
|
||||
$qrUrl = (string) ($mint['qr_url'] ?? '');
|
||||
if ($qrUrl !== '') {
|
||||
$payload['qr_url'] = $qrUrl;
|
||||
}
|
||||
if ($shortUrl !== '') {
|
||||
$payload['short_url'] = $shortUrl;
|
||||
}
|
||||
return $payload;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user