After configuring the domain name4
This commit is contained in:
parent
85e7b9937e
commit
8d544b3721
@ -110,6 +110,12 @@ CERTBOT_DOMAIN1=tloto.net
|
|||||||
# Second name on the same certificate (www). Used by ssl:dns-init --expand.
|
# Second name on the same certificate (www). Used by ssl:dns-init --expand.
|
||||||
CERTBOT_DOMAIN2=www.tloto.net
|
CERTBOT_DOMAIN2=www.tloto.net
|
||||||
APP_PUBLIC_URL=https://tloto.net:9443
|
APP_PUBLIC_URL=https://tloto.net:9443
|
||||||
|
# Admin page Options → SSL certificates (live TLS probes from the backend container).
|
||||||
|
# Defaults to APP_PUBLIC_URL host + www. Override if apex is served on gateway :443:
|
||||||
|
# SSL_STATUS_HOSTS=tloto.net,www.tloto.net
|
||||||
|
# SSL_STATUS_WARN_DAYS=30
|
||||||
|
# SSL_STATUS_CRITICAL_DAYS=7
|
||||||
|
# SSL_STATUS_TIMEOUT_MS=8000
|
||||||
INITIAL_SETUP_TOKEN=your-random-setup-token-min-32-chars
|
INITIAL_SETUP_TOKEN=your-random-setup-token-min-32-chars
|
||||||
# Emergency Super Admin 2FA reset (CLI / Docker only — not an HTTP API). Min 32 chars; distinct from JWT/setup tokens.
|
# Emergency Super Admin 2FA reset (CLI / Docker only — not an HTTP API). Min 32 chars; distinct from JWT/setup tokens.
|
||||||
# Generate: node -e "console.log(require('crypto').randomBytes(48).toString('hex'))"
|
# Generate: node -e "console.log(require('crypto').randomBytes(48).toString('hex'))"
|
||||||
|
|||||||
@ -58,6 +58,11 @@ LARGE_WITHDRAWAL_THRESHOLD_USD=1000
|
|||||||
# App URLs (verification links in emails)
|
# App URLs (verification links in emails)
|
||||||
# SMTP settings can live here or in the repo root .env (root wins for mail vars).
|
# SMTP settings can live here or in the repo root .env (root wins for mail vars).
|
||||||
APP_PUBLIC_URL=http://localhost:5173
|
APP_PUBLIC_URL=http://localhost:5173
|
||||||
|
# Admin SSL expiry page (live TLS probes). Defaults: APP_PUBLIC_URL host + www on :443.
|
||||||
|
# SSL_STATUS_HOSTS=tloto.net,www.tloto.net
|
||||||
|
# SSL_STATUS_WARN_DAYS=30
|
||||||
|
# SSL_STATUS_CRITICAL_DAYS=7
|
||||||
|
# SSL_STATUS_TIMEOUT_MS=8000
|
||||||
# EMAIL_TRANSPORT=console # omit or set smtp when SMTP_* vars are configured
|
# EMAIL_TRANSPORT=console # omit or set smtp when SMTP_* vars are configured
|
||||||
# SMTP_HOST=smtp.gmail.com
|
# SMTP_HOST=smtp.gmail.com
|
||||||
# SMTP_PORT=587
|
# SMTP_PORT=587
|
||||||
|
|||||||
@ -310,4 +310,10 @@ export const config = {
|
|||||||
'change-me-in-production',
|
'change-me-in-production',
|
||||||
downloadTokenTtlSeconds: readEnvInt('APK_DOWNLOAD_TOKEN_TTL_SECONDS', 3600, 60, 86_400),
|
downloadTokenTtlSeconds: readEnvInt('APK_DOWNLOAD_TOKEN_TTL_SECONDS', 3600, 60, 86_400),
|
||||||
},
|
},
|
||||||
|
/** Live TLS probes for admin SSL expiry page (defaults from APP_PUBLIC_URL + www). */
|
||||||
|
sslStatus: {
|
||||||
|
warnDays: readEnvInt('SSL_STATUS_WARN_DAYS', 30, 1, 90),
|
||||||
|
criticalDays: readEnvInt('SSL_STATUS_CRITICAL_DAYS', 7, 1, 30),
|
||||||
|
timeoutMs: readEnvInt('SSL_STATUS_TIMEOUT_MS', 8_000, 1000, 60_000),
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
17
backend/src/controllers/sslCertificateController.ts
Normal file
17
backend/src/controllers/sslCertificateController.ts
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
/**
|
||||||
|
* Admin HTTPS certificate status (expiry planning).
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Response } from 'express';
|
||||||
|
import { AuthRequest } from '../middleware/auth';
|
||||||
|
import * as sslCertificateStatusService from '../services/sslCertificateStatusService';
|
||||||
|
|
||||||
|
export async function getStatus(_req: AuthRequest, res: Response): Promise<void> {
|
||||||
|
try {
|
||||||
|
const result = await sslCertificateStatusService.getSslCertificateStatus();
|
||||||
|
res.json(result);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
res.status(500).json({ error: e instanceof Error ? e.message : 'SSL status check failed' });
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -121,6 +121,7 @@ import * as testWalletController from '../controllers/testWalletController';
|
|||||||
import * as soloEncouragementController from '../controllers/soloEncouragementController';
|
import * as soloEncouragementController from '../controllers/soloEncouragementController';
|
||||||
import * as shareCardController from '../controllers/shareCardController';
|
import * as shareCardController from '../controllers/shareCardController';
|
||||||
import * as mobileAppReleaseController from '../controllers/mobileAppReleaseController';
|
import * as mobileAppReleaseController from '../controllers/mobileAppReleaseController';
|
||||||
|
import * as sslCertificateController from '../controllers/sslCertificateController';
|
||||||
import { apkUpload } from '../middleware/apkUpload';
|
import { apkUpload } from '../middleware/apkUpload';
|
||||||
import { requireSupportedAppVersion } from '../middleware/requireSupportedAppVersion';
|
import { requireSupportedAppVersion } from '../middleware/requireSupportedAppVersion';
|
||||||
import {
|
import {
|
||||||
@ -743,6 +744,13 @@ router.get('/admin/reports/:reportKey', requireRoles('admin'), requirePermission
|
|||||||
router.get('/admin/reports/:reportKey/export', requireRoles('admin'), requirePermissions('reports.admin'), reportsController.exportReport);
|
router.get('/admin/reports/:reportKey/export', requireRoles('admin'), requirePermissions('reports.admin'), reportsController.exportReport);
|
||||||
router.post('/admin/reports/:reportKey/export', requireRoles('admin'), requirePermissions('reports.admin'), reportsController.exportReportPost);
|
router.post('/admin/reports/:reportKey/export', requireRoles('admin'), requirePermissions('reports.admin'), reportsController.exportReportPost);
|
||||||
router.post('/admin/reports/:reportKey/bulk-action', requireRoles('admin'), requirePermissions('reports.admin'), validateBody(reportsBulkActionBodySchema), reportsController.runBulkAction);
|
router.post('/admin/reports/:reportKey/bulk-action', requireRoles('admin'), requirePermissions('reports.admin'), validateBody(reportsBulkActionBodySchema), reportsController.runBulkAction);
|
||||||
|
router.get(
|
||||||
|
'/admin/ssl-certificates',
|
||||||
|
requireRoles('admin'),
|
||||||
|
requirePermissions('settings.admin'),
|
||||||
|
sslCertificateController.getStatus
|
||||||
|
);
|
||||||
|
|
||||||
router.get('/admin/settings', requireRoles('admin'), requirePermissions('settings.admin'), settingsController.getSettings);
|
router.get('/admin/settings', requireRoles('admin'), requirePermissions('settings.admin'), settingsController.getSettings);
|
||||||
router.patch(
|
router.patch(
|
||||||
'/admin/settings',
|
'/admin/settings',
|
||||||
|
|||||||
183
backend/src/services/sslCertificateStatusService.ts
Normal file
183
backend/src/services/sslCertificateStatusService.ts
Normal file
@ -0,0 +1,183 @@
|
|||||||
|
/**
|
||||||
|
* Probe live TLS certificates for admin visibility (expiry planning).
|
||||||
|
*/
|
||||||
|
|
||||||
|
import tls from 'tls';
|
||||||
|
import { config } from '../config';
|
||||||
|
|
||||||
|
export type SslCertProbe = {
|
||||||
|
host: string;
|
||||||
|
port: number;
|
||||||
|
ok: boolean;
|
||||||
|
subject: string | null;
|
||||||
|
issuer: string | null;
|
||||||
|
validFrom: string | null;
|
||||||
|
validTo: string | null;
|
||||||
|
daysRemaining: number | null;
|
||||||
|
status: 'ok' | 'warning' | 'critical' | 'error';
|
||||||
|
error: string | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type SslCertStatusResult = {
|
||||||
|
checkedAt: string;
|
||||||
|
warnDays: number;
|
||||||
|
criticalDays: number;
|
||||||
|
certificates: SslCertProbe[];
|
||||||
|
};
|
||||||
|
|
||||||
|
function parseHosts(): Array<{ host: string; port: number }> {
|
||||||
|
const raw = (process.env.SSL_STATUS_HOSTS || '').trim();
|
||||||
|
if (raw) {
|
||||||
|
return raw.split(',').map((part) => {
|
||||||
|
const p = part.trim();
|
||||||
|
if (!p) return null;
|
||||||
|
if (p.includes('://')) {
|
||||||
|
try {
|
||||||
|
const u = new URL(p);
|
||||||
|
return { host: u.hostname, port: u.port ? parseInt(u.port, 10) : u.protocol === 'https:' ? 443 : 80 };
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const [host, portStr] = p.split(':');
|
||||||
|
return { host, port: portStr ? parseInt(portStr, 10) : 443 };
|
||||||
|
}).filter((x): x is { host: string; port: number } => !!x && !!x.host && Number.isFinite(x.port));
|
||||||
|
}
|
||||||
|
|
||||||
|
const out: Array<{ host: string; port: number }> = [];
|
||||||
|
try {
|
||||||
|
const u = new URL(config.app.publicUrl);
|
||||||
|
if (u.hostname) {
|
||||||
|
out.push({ host: u.hostname, port: u.port ? parseInt(u.port, 10) : 443 });
|
||||||
|
if (!u.hostname.startsWith('www.')) {
|
||||||
|
out.push({ host: `www.${u.hostname}`, port: u.port ? parseInt(u.port, 10) : 443 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
/* ignore */
|
||||||
|
}
|
||||||
|
if (!out.length) {
|
||||||
|
out.push({ host: 'tloto.net', port: 443 });
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
function probeTls(host: string, port: number, timeoutMs: number): Promise<Omit<SslCertProbe, 'status'>> {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
const socket = tls.connect(
|
||||||
|
{
|
||||||
|
host,
|
||||||
|
port,
|
||||||
|
servername: host,
|
||||||
|
rejectUnauthorized: false,
|
||||||
|
timeout: timeoutMs,
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
try {
|
||||||
|
const cert = socket.getPeerCertificate();
|
||||||
|
socket.end();
|
||||||
|
if (!cert || !cert.valid_to) {
|
||||||
|
resolve({
|
||||||
|
host,
|
||||||
|
port,
|
||||||
|
ok: false,
|
||||||
|
subject: null,
|
||||||
|
issuer: null,
|
||||||
|
validFrom: null,
|
||||||
|
validTo: null,
|
||||||
|
daysRemaining: null,
|
||||||
|
error: 'No peer certificate returned',
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const validTo = new Date(cert.valid_to);
|
||||||
|
const validFrom = new Date(cert.valid_from);
|
||||||
|
const daysRemaining = Math.floor((validTo.getTime() - Date.now()) / 86_400_000);
|
||||||
|
resolve({
|
||||||
|
host,
|
||||||
|
port,
|
||||||
|
ok: true,
|
||||||
|
subject: cert.subject?.CN || JSON.stringify(cert.subject || {}),
|
||||||
|
issuer: cert.issuer?.CN || cert.issuer?.O || null,
|
||||||
|
validFrom: validFrom.toISOString(),
|
||||||
|
validTo: validTo.toISOString(),
|
||||||
|
daysRemaining,
|
||||||
|
error: null,
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
socket.destroy();
|
||||||
|
resolve({
|
||||||
|
host,
|
||||||
|
port,
|
||||||
|
ok: false,
|
||||||
|
subject: null,
|
||||||
|
issuer: null,
|
||||||
|
validFrom: null,
|
||||||
|
validTo: null,
|
||||||
|
daysRemaining: null,
|
||||||
|
error: e instanceof Error ? e.message : String(e),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
socket.on('error', (err) => {
|
||||||
|
resolve({
|
||||||
|
host,
|
||||||
|
port,
|
||||||
|
ok: false,
|
||||||
|
subject: null,
|
||||||
|
issuer: null,
|
||||||
|
validFrom: null,
|
||||||
|
validTo: null,
|
||||||
|
daysRemaining: null,
|
||||||
|
error: err.message,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on('timeout', () => {
|
||||||
|
socket.destroy();
|
||||||
|
resolve({
|
||||||
|
host,
|
||||||
|
port,
|
||||||
|
ok: false,
|
||||||
|
subject: null,
|
||||||
|
issuer: null,
|
||||||
|
validFrom: null,
|
||||||
|
validTo: null,
|
||||||
|
daysRemaining: null,
|
||||||
|
error: 'TLS connection timed out',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function classify(daysRemaining: number | null, warnDays: number, criticalDays: number, ok: boolean): SslCertProbe['status'] {
|
||||||
|
if (!ok || daysRemaining == null) return 'error';
|
||||||
|
if (daysRemaining < criticalDays) return 'critical';
|
||||||
|
if (daysRemaining < warnDays) return 'warning';
|
||||||
|
return 'ok';
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Live TLS probes for configured public hosts (planning renewals). */
|
||||||
|
export async function getSslCertificateStatus(): Promise<SslCertStatusResult> {
|
||||||
|
const warnDays = config.sslStatus.warnDays;
|
||||||
|
const criticalDays = config.sslStatus.criticalDays;
|
||||||
|
const hosts = parseHosts();
|
||||||
|
const probes = await Promise.all(
|
||||||
|
hosts.map(async ({ host, port }) => {
|
||||||
|
const raw = await probeTls(host, port, config.sslStatus.timeoutMs);
|
||||||
|
return {
|
||||||
|
...raw,
|
||||||
|
status: classify(raw.daysRemaining, warnDays, criticalDays, raw.ok),
|
||||||
|
};
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
checkedAt: new Date().toISOString(),
|
||||||
|
warnDays,
|
||||||
|
criticalDays,
|
||||||
|
certificates: probes,
|
||||||
|
};
|
||||||
|
}
|
||||||
@ -97,6 +97,11 @@ x-backend-common: &backend-common
|
|||||||
ANDROID_APK_EXPECTED_PACKAGE: ${ANDROID_APK_EXPECTED_PACKAGE:-com.prediqo.mobile}
|
ANDROID_APK_EXPECTED_PACKAGE: ${ANDROID_APK_EXPECTED_PACKAGE:-com.prediqo.mobile}
|
||||||
APK_MAX_UPLOAD_BYTES: ${APK_MAX_UPLOAD_BYTES:-125829120}
|
APK_MAX_UPLOAD_BYTES: ${APK_MAX_UPLOAD_BYTES:-125829120}
|
||||||
APK_DOWNLOAD_TOKEN_TTL_SECONDS: ${APK_DOWNLOAD_TOKEN_TTL_SECONDS:-3600}
|
APK_DOWNLOAD_TOKEN_TTL_SECONDS: ${APK_DOWNLOAD_TOKEN_TTL_SECONDS:-3600}
|
||||||
|
# Admin SSL expiry page — comma-separated host[:port]; empty = APP_PUBLIC_URL + www
|
||||||
|
SSL_STATUS_HOSTS: ${SSL_STATUS_HOSTS:-}
|
||||||
|
SSL_STATUS_WARN_DAYS: ${SSL_STATUS_WARN_DAYS:-30}
|
||||||
|
SSL_STATUS_CRITICAL_DAYS: ${SSL_STATUS_CRITICAL_DAYS:-7}
|
||||||
|
SSL_STATUS_TIMEOUT_MS: ${SSL_STATUS_TIMEOUT_MS:-8000}
|
||||||
|
|
||||||
services:
|
services:
|
||||||
postgres:
|
postgres:
|
||||||
|
|||||||
@ -228,6 +228,11 @@ export const MobileVersionsAdminPage = lazyNamed(
|
|||||||
() => import('../../features/mobile-versions/MobileVersionsAdminPage'),
|
() => import('../../features/mobile-versions/MobileVersionsAdminPage'),
|
||||||
'MobileVersionsAdminPage'
|
'MobileVersionsAdminPage'
|
||||||
);
|
);
|
||||||
|
export const SslCertificatesAdminPage = lazyNamed(
|
||||||
|
'SslCertificatesAdminPage',
|
||||||
|
() => import('../../features/ssl-certificates/SslCertificatesAdminPage'),
|
||||||
|
'SslCertificatesAdminPage'
|
||||||
|
);
|
||||||
|
|
||||||
/** Exact path → page preload. Longest match wins for nested paths. */
|
/** Exact path → page preload. Longest match wins for nested paths. */
|
||||||
const PATH_PRELOAD: Array<{ path: string; preload: () => Promise<unknown> }> = [
|
const PATH_PRELOAD: Array<{ path: string; preload: () => Promise<unknown> }> = [
|
||||||
@ -268,6 +273,7 @@ const PATH_PRELOAD: Array<{ path: string; preload: () => Promise<unknown> }> = [
|
|||||||
{ path: '/admin/rbac', preload: RoleManagementPage.preload },
|
{ path: '/admin/rbac', preload: RoleManagementPage.preload },
|
||||||
{ path: '/admin/admin-users', preload: AdminUsersPage.preload },
|
{ path: '/admin/admin-users', preload: AdminUsersPage.preload },
|
||||||
{ path: '/admin/mobile-versions', preload: MobileVersionsAdminPage.preload },
|
{ path: '/admin/mobile-versions', preload: MobileVersionsAdminPage.preload },
|
||||||
|
{ path: '/admin/ssl-certificates', preload: SslCertificatesAdminPage.preload },
|
||||||
].sort((a, b) => b.path.length - a.path.length);
|
].sort((a, b) => b.path.length - a.path.length);
|
||||||
|
|
||||||
/** Warm the JS chunk for a destination before navigation. */
|
/** Warm the JS chunk for a destination before navigation. */
|
||||||
|
|||||||
@ -49,6 +49,7 @@ import {
|
|||||||
AdminUsersPage,
|
AdminUsersPage,
|
||||||
AdminUserPermissionsPage,
|
AdminUserPermissionsPage,
|
||||||
MobileVersionsAdminPage,
|
MobileVersionsAdminPage,
|
||||||
|
SslCertificatesAdminPage,
|
||||||
} from './routePrefetch';
|
} from './routePrefetch';
|
||||||
|
|
||||||
function RouteFallback() {
|
function RouteFallback() {
|
||||||
@ -344,6 +345,14 @@ export const router = createBrowserRouter([
|
|||||||
</L>
|
</L>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: 'admin/ssl-certificates',
|
||||||
|
element: (
|
||||||
|
<L>
|
||||||
|
<SslCertificatesAdminPage />
|
||||||
|
</L>
|
||||||
|
),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: 'admin/solo-encouragement',
|
path: 'admin/solo-encouragement',
|
||||||
element: (
|
element: (
|
||||||
|
|||||||
@ -23,6 +23,7 @@ import AdminPanelSettingsRoundedIcon from '@mui/icons-material/AdminPanelSetting
|
|||||||
import ManageAccountsRoundedIcon from '@mui/icons-material/ManageAccountsRounded';
|
import ManageAccountsRoundedIcon from '@mui/icons-material/ManageAccountsRounded';
|
||||||
import RuleFolderRoundedIcon from '@mui/icons-material/RuleFolderRounded';
|
import RuleFolderRoundedIcon from '@mui/icons-material/RuleFolderRounded';
|
||||||
import PhoneAndroidRoundedIcon from '@mui/icons-material/PhoneAndroidRounded';
|
import PhoneAndroidRoundedIcon from '@mui/icons-material/PhoneAndroidRounded';
|
||||||
|
import VerifiedUserRoundedIcon from '@mui/icons-material/VerifiedUserRounded';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { useAuth } from '../../shared/auth/AuthContext';
|
import { useAuth } from '../../shared/auth/AuthContext';
|
||||||
@ -49,7 +50,8 @@ type OptionCardKey =
|
|||||||
| 'countries'
|
| 'countries'
|
||||||
| 'rbac'
|
| 'rbac'
|
||||||
| 'adminUsers'
|
| 'adminUsers'
|
||||||
| 'mobileVersions';
|
| 'mobileVersions'
|
||||||
|
| 'sslCertificates';
|
||||||
|
|
||||||
type OptionCardConfig = {
|
type OptionCardConfig = {
|
||||||
key: OptionCardKey;
|
key: OptionCardKey;
|
||||||
@ -243,6 +245,15 @@ const OPTION_CARDS: OptionCardConfig[] = [
|
|||||||
bg: 'rgba(16,185,129,0.14)',
|
bg: 'rgba(16,185,129,0.14)',
|
||||||
border: 'rgba(16,185,129,0.28)',
|
border: 'rgba(16,185,129,0.28)',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
key: 'sslCertificates',
|
||||||
|
path: '/admin/ssl-certificates',
|
||||||
|
icon: VerifiedUserRoundedIcon,
|
||||||
|
badgeKey: 'ssl',
|
||||||
|
badgeColor: 'info',
|
||||||
|
bg: 'rgba(59,130,246,0.14)',
|
||||||
|
border: 'rgba(59,130,246,0.28)',
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
/** Landing page for administrative tools and configuration shortcuts. */
|
/** Landing page for administrative tools and configuration shortcuts. */
|
||||||
|
|||||||
@ -0,0 +1,186 @@
|
|||||||
|
/**
|
||||||
|
* Admin page: live HTTPS certificate expiry for renewal planning.
|
||||||
|
*/
|
||||||
|
import {
|
||||||
|
Alert,
|
||||||
|
Box,
|
||||||
|
Button,
|
||||||
|
Chip,
|
||||||
|
Stack,
|
||||||
|
Table,
|
||||||
|
TableBody,
|
||||||
|
TableCell,
|
||||||
|
TableHead,
|
||||||
|
TableRow,
|
||||||
|
Typography,
|
||||||
|
} from '@mui/material';
|
||||||
|
import RefreshRoundedIcon from '@mui/icons-material/RefreshRounded';
|
||||||
|
import VerifiedUserRoundedIcon from '@mui/icons-material/VerifiedUserRounded';
|
||||||
|
import { useQuery } from '@tanstack/react-query';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { PermissionGate } from '../../shared/auth/PermissionGate';
|
||||||
|
import { ScrollableTable } from '../../shared/components/ScrollableTable';
|
||||||
|
import { fetchSslCertificateStatus, type SslCertProbe } from './api/sslCertificatesApi';
|
||||||
|
|
||||||
|
function statusColor(status: SslCertProbe['status']): 'success' | 'warning' | 'error' | 'default' {
|
||||||
|
switch (status) {
|
||||||
|
case 'ok':
|
||||||
|
return 'success';
|
||||||
|
case 'warning':
|
||||||
|
return 'warning';
|
||||||
|
case 'critical':
|
||||||
|
case 'error':
|
||||||
|
return 'error';
|
||||||
|
default:
|
||||||
|
return 'default';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatDate(iso: string | null, locale: string): string {
|
||||||
|
if (!iso) return '—';
|
||||||
|
try {
|
||||||
|
return new Date(iso).toLocaleString(locale, {
|
||||||
|
dateStyle: 'medium',
|
||||||
|
timeStyle: 'short',
|
||||||
|
});
|
||||||
|
} catch {
|
||||||
|
return iso;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function SslCertificatesAdminPage() {
|
||||||
|
const { t, i18n } = useTranslation();
|
||||||
|
const q = useQuery({
|
||||||
|
queryKey: ['admin', 'ssl-certificates'],
|
||||||
|
queryFn: fetchSslCertificateStatus,
|
||||||
|
refetchOnWindowFocus: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const worst = q.data?.certificates.some((c) => c.status === 'critical' || c.status === 'error')
|
||||||
|
? 'critical'
|
||||||
|
: q.data?.certificates.some((c) => c.status === 'warning')
|
||||||
|
? 'warning'
|
||||||
|
: 'ok';
|
||||||
|
|
||||||
|
return (
|
||||||
|
<PermissionGate permission="admin.settings.view">
|
||||||
|
<Box sx={{ maxWidth: 1100, mx: 'auto', px: { xs: 1.5, md: 2 }, py: 2 }}>
|
||||||
|
<Stack direction="row" alignItems="flex-start" justifyContent="space-between" gap={2} flexWrap="wrap">
|
||||||
|
<Stack direction="row" spacing={1.5} alignItems="center">
|
||||||
|
<VerifiedUserRoundedIcon color="primary" />
|
||||||
|
<Box>
|
||||||
|
<Typography variant="h5" fontWeight={800}>
|
||||||
|
{t('admin.sslCertificates.title')}
|
||||||
|
</Typography>
|
||||||
|
<Typography variant="body2" color="text.secondary">
|
||||||
|
{t('admin.sslCertificates.subtitle')}
|
||||||
|
</Typography>
|
||||||
|
</Box>
|
||||||
|
</Stack>
|
||||||
|
<Button
|
||||||
|
startIcon={<RefreshRoundedIcon />}
|
||||||
|
variant="outlined"
|
||||||
|
onClick={() => void q.refetch()}
|
||||||
|
disabled={q.isFetching}
|
||||||
|
>
|
||||||
|
{t('admin.sslCertificates.refresh')}
|
||||||
|
</Button>
|
||||||
|
</Stack>
|
||||||
|
|
||||||
|
{q.isError && (
|
||||||
|
<Alert severity="error" sx={{ mt: 2 }}>
|
||||||
|
{(q.error as Error)?.message || t('admin.sslCertificates.loadError')}
|
||||||
|
</Alert>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{q.data && worst === 'ok' && (
|
||||||
|
<Alert severity="success" sx={{ mt: 2 }}>
|
||||||
|
{t('admin.sslCertificates.allOk', { days: q.data.warnDays })}
|
||||||
|
</Alert>
|
||||||
|
)}
|
||||||
|
{q.data && worst === 'warning' && (
|
||||||
|
<Alert severity="warning" sx={{ mt: 2 }}>
|
||||||
|
{t('admin.sslCertificates.warnBanner', { days: q.data.warnDays })}
|
||||||
|
</Alert>
|
||||||
|
)}
|
||||||
|
{q.data && worst === 'critical' && (
|
||||||
|
<Alert severity="error" sx={{ mt: 2 }}>
|
||||||
|
{t('admin.sslCertificates.criticalBanner', { days: q.data.criticalDays })}
|
||||||
|
</Alert>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{q.data && (
|
||||||
|
<Typography variant="caption" color="text.secondary" display="block" sx={{ mt: 1.5 }}>
|
||||||
|
{t('admin.sslCertificates.checkedAt', {
|
||||||
|
at: formatDate(q.data.checkedAt, i18n.language),
|
||||||
|
})}
|
||||||
|
</Typography>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<Box sx={{ mt: 2 }}>
|
||||||
|
<ScrollableTable>
|
||||||
|
<Table size="small">
|
||||||
|
<TableHead>
|
||||||
|
<TableRow>
|
||||||
|
<TableCell>{t('admin.sslCertificates.host')}</TableCell>
|
||||||
|
<TableCell>{t('admin.sslCertificates.status')}</TableCell>
|
||||||
|
<TableCell>{t('admin.sslCertificates.validTo')}</TableCell>
|
||||||
|
<TableCell>{t('admin.sslCertificates.daysLeft')}</TableCell>
|
||||||
|
<TableCell>{t('admin.sslCertificates.issuer')}</TableCell>
|
||||||
|
<TableCell>{t('admin.sslCertificates.notes')}</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
</TableHead>
|
||||||
|
<TableBody>
|
||||||
|
{(q.data?.certificates ?? []).map((c) => (
|
||||||
|
<TableRow key={`${c.host}:${c.port}`}>
|
||||||
|
<TableCell>
|
||||||
|
<Typography fontWeight={700}>
|
||||||
|
{c.host}
|
||||||
|
{c.port !== 443 ? `:${c.port}` : ''}
|
||||||
|
</Typography>
|
||||||
|
{c.subject && (
|
||||||
|
<Typography variant="caption" color="text.secondary" display="block">
|
||||||
|
CN={c.subject}
|
||||||
|
</Typography>
|
||||||
|
)}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<Chip
|
||||||
|
size="small"
|
||||||
|
color={statusColor(c.status)}
|
||||||
|
label={t(`admin.sslCertificates.status_${c.status}`)}
|
||||||
|
/>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>{formatDate(c.validTo, i18n.language)}</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
{c.daysRemaining == null ? '—' : t('admin.sslCertificates.daysValue', { count: c.daysRemaining })}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>{c.issuer || '—'}</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
{c.error ? (
|
||||||
|
<Typography variant="caption" color="error">
|
||||||
|
{c.error}
|
||||||
|
</Typography>
|
||||||
|
) : (
|
||||||
|
'—'
|
||||||
|
)}
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
))}
|
||||||
|
{q.isLoading && (
|
||||||
|
<TableRow>
|
||||||
|
<TableCell colSpan={6}>{t('common.loading')}</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
)}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</ScrollableTable>
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
<Alert severity="info" sx={{ mt: 3 }}>
|
||||||
|
{t('admin.sslCertificates.howToRenew')}
|
||||||
|
</Alert>
|
||||||
|
</Box>
|
||||||
|
</PermissionGate>
|
||||||
|
);
|
||||||
|
}
|
||||||
@ -0,0 +1,30 @@
|
|||||||
|
/**
|
||||||
|
* Admin SSL certificate status (live TLS probes).
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { api } from '../../../shared/services/api';
|
||||||
|
|
||||||
|
export type SslCertProbe = {
|
||||||
|
host: string;
|
||||||
|
port: number;
|
||||||
|
ok: boolean;
|
||||||
|
subject: string | null;
|
||||||
|
issuer: string | null;
|
||||||
|
validFrom: string | null;
|
||||||
|
validTo: string | null;
|
||||||
|
daysRemaining: number | null;
|
||||||
|
status: 'ok' | 'warning' | 'critical' | 'error';
|
||||||
|
error: string | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type SslCertStatusResult = {
|
||||||
|
checkedAt: string;
|
||||||
|
warnDays: number;
|
||||||
|
criticalDays: number;
|
||||||
|
certificates: SslCertProbe[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function fetchSslCertificateStatus(): Promise<SslCertStatusResult> {
|
||||||
|
const { data } = await api.get<SslCertStatusResult>('/api/v1/admin/ssl-certificates');
|
||||||
|
return data;
|
||||||
|
}
|
||||||
@ -83,6 +83,7 @@ export const ADMIN_PAGE_PERMISSIONS: Record<string, string> = {
|
|||||||
'/admin/support': 'admin.support.view',
|
'/admin/support': 'admin.support.view',
|
||||||
'/admin/faq': 'admin.faq.view',
|
'/admin/faq': 'admin.faq.view',
|
||||||
'/admin/mobile-versions': 'admin.mobile_releases.view',
|
'/admin/mobile-versions': 'admin.mobile_releases.view',
|
||||||
|
'/admin/ssl-certificates': 'admin.settings.view',
|
||||||
};
|
};
|
||||||
|
|
||||||
export const OPTIONS_CARD_PERMISSIONS: Record<string, string> = {
|
export const OPTIONS_CARD_PERMISSIONS: Record<string, string> = {
|
||||||
@ -107,4 +108,5 @@ export const OPTIONS_CARD_PERMISSIONS: Record<string, string> = {
|
|||||||
rbac: 'admin.rbac.view',
|
rbac: 'admin.rbac.view',
|
||||||
adminUsers: 'admin.rbac.view',
|
adminUsers: 'admin.rbac.view',
|
||||||
mobileVersions: 'admin.mobile_releases.view',
|
mobileVersions: 'admin.mobile_releases.view',
|
||||||
|
sslCertificates: 'admin.settings.view',
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1064,6 +1064,7 @@ export const en = {
|
|||||||
registration: 'Registration',
|
registration: 'Registration',
|
||||||
accessControl: 'Access control',
|
accessControl: 'Access control',
|
||||||
apk: 'APK / Android',
|
apk: 'APK / Android',
|
||||||
|
ssl: 'SSL / TLS',
|
||||||
},
|
},
|
||||||
options: {
|
options: {
|
||||||
title: 'Options',
|
title: 'Options',
|
||||||
@ -1150,8 +1151,36 @@ export const en = {
|
|||||||
title: 'Mobile versions',
|
title: 'Mobile versions',
|
||||||
description: 'Publish Android APK updates, set update policies, and track download stats.',
|
description: 'Publish Android APK updates, set update policies, and track download stats.',
|
||||||
},
|
},
|
||||||
|
sslCertificates: {
|
||||||
|
title: 'SSL certificates',
|
||||||
|
description: 'See HTTPS certificate expiry dates and plan Let’s Encrypt renewals.',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
sslCertificates: {
|
||||||
|
title: 'SSL certificates',
|
||||||
|
subtitle: 'Live TLS status for public hosts — plan renewals before expiry.',
|
||||||
|
refresh: 'Refresh',
|
||||||
|
loadError: 'Could not load certificate status.',
|
||||||
|
checkedAt: 'Last check: {{at}}',
|
||||||
|
host: 'Host',
|
||||||
|
status: 'Status',
|
||||||
|
validTo: 'Expires',
|
||||||
|
daysLeft: 'Days left',
|
||||||
|
issuer: 'Issuer',
|
||||||
|
notes: 'Notes',
|
||||||
|
daysValue: '{{count}} day',
|
||||||
|
daysValue_plural: '{{count}} days',
|
||||||
|
status_ok: 'OK',
|
||||||
|
status_warning: 'Renew soon',
|
||||||
|
status_critical: 'Critical',
|
||||||
|
status_error: 'Error',
|
||||||
|
allOk: 'All checked certificates are valid for at least {{days}} days.',
|
||||||
|
warnBanner: 'At least one certificate expires within {{days}} days — schedule a DNS renewal.',
|
||||||
|
criticalBanner: 'At least one certificate expires within {{days}} days or could not be read.',
|
||||||
|
howToRenew:
|
||||||
|
'Tloto uses manual DNS renewal on the VPS: npm run ssl:dns-renew, update the GoDaddy TXT, verify with Dig, then press Enter. Keep the daily cron + ntfy alert as a safety net.',
|
||||||
|
},
|
||||||
mobileVersions: {
|
mobileVersions: {
|
||||||
title: 'Mobile versions',
|
title: 'Mobile versions',
|
||||||
subtitle: 'Manage Android APK releases distributed from Tloto servers.',
|
subtitle: 'Manage Android APK releases distributed from Tloto servers.',
|
||||||
|
|||||||
@ -1078,6 +1078,7 @@ export const fr = {
|
|||||||
registration: 'Inscription',
|
registration: 'Inscription',
|
||||||
accessControl: 'Contrôle d’accès',
|
accessControl: 'Contrôle d’accès',
|
||||||
apk: 'APK / Android',
|
apk: 'APK / Android',
|
||||||
|
ssl: 'SSL / TLS',
|
||||||
},
|
},
|
||||||
options: {
|
options: {
|
||||||
title: 'Options',
|
title: 'Options',
|
||||||
@ -1168,8 +1169,36 @@ export const fr = {
|
|||||||
title: 'Versions mobiles',
|
title: 'Versions mobiles',
|
||||||
description: 'Publier les mises à jour APK Android, définir les politiques et suivre les téléchargements.',
|
description: 'Publier les mises à jour APK Android, définir les politiques et suivre les téléchargements.',
|
||||||
},
|
},
|
||||||
|
sslCertificates: {
|
||||||
|
title: 'Certificats SSL',
|
||||||
|
description: 'Consulter les dates d’expiration HTTPS et planifier le renouvellement Let’s Encrypt.',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
sslCertificates: {
|
||||||
|
title: 'Certificats SSL',
|
||||||
|
subtitle: 'État TLS en direct des hôtes publics — planifiez le renouvellement avant expiration.',
|
||||||
|
refresh: 'Actualiser',
|
||||||
|
loadError: 'Impossible de charger le statut des certificats.',
|
||||||
|
checkedAt: 'Dernière vérif. : {{at}}',
|
||||||
|
host: 'Hôte',
|
||||||
|
status: 'Statut',
|
||||||
|
validTo: 'Expire le',
|
||||||
|
daysLeft: 'Jours restants',
|
||||||
|
issuer: 'Émetteur',
|
||||||
|
notes: 'Notes',
|
||||||
|
daysValue: '{{count}} jour',
|
||||||
|
daysValue_plural: '{{count}} jours',
|
||||||
|
status_ok: 'OK',
|
||||||
|
status_warning: 'Renouveler bientôt',
|
||||||
|
status_critical: 'Critique',
|
||||||
|
status_error: 'Erreur',
|
||||||
|
allOk: 'Tous les certificats contrôlés sont valides au moins {{days}} jours.',
|
||||||
|
warnBanner: 'Au moins un certificat expire dans moins de {{days}} jours — planifiez un renouvellement DNS.',
|
||||||
|
criticalBanner: 'Au moins un certificat expire dans moins de {{days}} jours ou n’a pas pu être lu.',
|
||||||
|
howToRenew:
|
||||||
|
'Tloto utilise un renouvellement DNS manuel sur le VPS : npm run ssl:dns-renew, mettez à jour le TXT GoDaddy, vérifiez avec Dig, puis Entrée. Gardez le cron quotidien + alerte ntfy en filet de sécurité.',
|
||||||
|
},
|
||||||
mobileVersions: {
|
mobileVersions: {
|
||||||
title: 'Versions mobiles',
|
title: 'Versions mobiles',
|
||||||
subtitle: 'Gérer les releases APK Android distribuées depuis les serveurs Tloto.',
|
subtitle: 'Gérer les releases APK Android distribuées depuis les serveurs Tloto.',
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user