Appli de bureau : accès depuis une tablette sur le réseau local (appairage par code, migration V25)

- Activation dans Paramètres > « Accès depuis une tablette » (raccourci tray
  « Connecter une tablette… ») : un second connecteur Tomcat s'ouvre à chaud
  sur le réseau local (port 8765 par défaut, modifiable) ; le connecteur
  habituel reste sur 127.0.0.1, rien ne change pour qui n'active rien.
- Appairage : QR code + code à 6 chiffres (5 min, usage unique, 5 essais,
  20 échecs/min au total) échangé contre un jeton d'appareil posé en cookie
  HttpOnly + SameSite=Strict ; seule son empreinte SHA-256 est stockée
  (tables remote_access_config et remote_devices, migration V25).
- RemoteAccessFilter (avant le HTTP Basic) : depuis le réseau, API réservée
  aux appareils appairés (sinon 401 → écran /pair côté front) ; Paramètres,
  données, mises à jour et licence toujours refusés (403), même appairé.
- Front : section Paramètres (adresse, QR code, compte à rebours, appareils
  autorisés avec « Retirer l'accès »), écran d'appairage plein écran,
  intercepteur de redirection ; dépendance qrcode.
- Mode bureau uniquement (profil local) : Docker inchangé.

Vérifié : core clean verify (1205 tests, dont un test d'intégration sur un
vrai Tomcat : ouverture/fermeture du port, filtre, appairage + cookie),
migration V25 sur H2, web build + 303 vitest, lint sans erreur, parcours PC
et tablette testés en mode bureau isolé ; doc à jour (accès tablette +
Tailscale).
À redéployer : core (migration V25) + web.
This commit is contained in:
2026-10-17 14:00:43 +02:00
parent c2f162d823
commit ab658f27b0
50 changed files with 2966 additions and 52 deletions
@@ -0,0 +1,102 @@
@if (status; as s) {
<section class="card remote-access" id="remote-access">
<h2>{{ 'remoteAccess.settings.title' | translate }}</h2>
<p class="hint">{{ 'remoteAccess.settings.hint' | translate }}</p>
@if (error || s.lastError) {
<div class="alert alert-error" role="alert">
<lucide-icon [img]="AlertCircle" [size]="16"></lucide-icon>
<span>{{ error || s.lastError }}</span>
</div>
}
<label class="switch-row">
<input type="checkbox" [ngModel]="s.enabled" (ngModelChange)="toggle($event)" [disabled]="busy" />
<span>{{ 'remoteAccess.settings.enable' | translate }}</span>
</label>
@if (!s.enabled) {
<p class="note">
<lucide-icon [img]="ShieldCheck" [size]="15"></lucide-icon>
{{ 'remoteAccess.settings.firewallNote' | translate }}
</p>
}
@if (s.running) {
<div class="remote-block">
<h3>{{ 'remoteAccess.settings.addressTitle' | translate }}</h3>
@if (s.urls.length > 0) {
<ul class="url-list">
@for (url of s.urls; track url) {
<li><code>{{ url }}</code></li>
}
</ul>
} @else {
<p class="note">{{ 'remoteAccess.settings.noAddress' | translate }}</p>
}
</div>
<div class="remote-block">
<h3>{{ 'remoteAccess.settings.pairTitle' | translate }}</h3>
@if (pairing) {
<div class="pairing">
@if (qrDataUrl) {
<img class="qr" [src]="qrDataUrl" [alt]="'remoteAccess.settings.qrAlt' | translate" width="220" height="220" />
}
<div class="pairing-info">
<p class="pairing-steps">{{ 'remoteAccess.settings.pairSteps' | translate }}</p>
<div class="code" [attr.aria-label]="'remoteAccess.settings.codeAria' | translate: { code: pairing.code }">
{{ pairing.code.slice(0, 3) }}&nbsp;{{ pairing.code.slice(3) }}
</div>
<p class="expires">{{ 'remoteAccess.settings.expiresIn' | translate: { time: countdownLabel } }}</p>
<button type="button" class="btn-secondary" (click)="newCode()" [disabled]="busy">
<lucide-icon [img]="RefreshCw" [size]="14"></lucide-icon>
{{ 'remoteAccess.settings.newCode' | translate }}
</button>
</div>
</div>
} @else {
<button type="button" class="btn-primary" (click)="newCode()" [disabled]="busy">
<lucide-icon [img]="Tablet" [size]="16"></lucide-icon>
{{ 'remoteAccess.settings.connectDevice' | translate }}
</button>
}
</div>
}
<div class="remote-block">
<h3>{{ 'remoteAccess.settings.devicesTitle' | translate }}</h3>
@if (s.devices.length === 0) {
<p class="note">{{ 'remoteAccess.settings.noDevices' | translate }}</p>
} @else {
<ul class="device-list">
@for (d of s.devices; track d.id) {
<li>
<div class="device-info">
<span class="device-name">{{ d.name }}</span>
<span class="device-meta">{{ 'remoteAccess.settings.lastSeen' | translate: { date: formatDate(d.lastSeenAt) } }}</span>
</div>
<button type="button" class="btn-icon-danger" (click)="revoke(d)"
[title]="'remoteAccess.settings.revoke' | translate"
[attr.aria-label]="('remoteAccess.settings.revoke' | translate) + ' : ' + d.name">
<lucide-icon [img]="Trash2" [size]="16"></lucide-icon>
</button>
</li>
}
</ul>
}
</div>
<details class="advanced">
<summary>{{ 'remoteAccess.settings.advanced' | translate }}</summary>
<div class="port-row">
<label for="remote-port">{{ 'remoteAccess.settings.portLabel' | translate }}</label>
<input id="remote-port" type="number" min="1024" max="65535" [(ngModel)]="port" />
<button type="button" class="btn-secondary" (click)="applyPort()" [disabled]="busy || port === s.port">
{{ 'remoteAccess.settings.applyPort' | translate }}
</button>
</div>
<p class="note">{{ 'remoteAccess.settings.outsideNote' | translate }}</p>
</details>
</section>
}
@@ -0,0 +1,173 @@
// Complète les styles partagés de la page Paramètres (.card, .hint, .alert).
.remote-access {
display: flex;
flex-direction: column;
gap: 1rem;
h3 {
margin: 0 0 0.5rem;
font-size: 0.85rem;
font-weight: 600;
letter-spacing: 0.03em;
text-transform: uppercase;
color: rgba(255, 255, 255, 0.6);
}
button {
display: inline-flex;
align-items: center;
gap: 0.45rem;
min-height: 44px;
}
}
.switch-row {
display: flex;
align-items: center;
gap: 0.7rem;
font-size: 0.95rem;
cursor: pointer;
input { accent-color: #6c63ff; width: 20px; height: 20px; margin: 0; }
}
.note {
display: flex;
align-items: flex-start;
gap: 0.45rem;
margin: 0;
font-size: 0.85rem;
line-height: 1.5;
color: rgba(255, 255, 255, 0.6);
lucide-icon { flex-shrink: 0; margin-top: 0.15rem; color: #86efac; }
}
.remote-block {
padding-top: 0.25rem;
}
.url-list {
margin: 0;
padding: 0;
list-style: none;
code {
font-size: 1.05rem;
color: #c7d2fe;
overflow-wrap: anywhere;
}
}
.pairing {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 1.25rem;
}
.qr {
border-radius: 8px;
background: white;
max-width: 100%;
height: auto;
}
.pairing-info {
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 0.5rem;
min-width: 0;
}
.pairing-steps {
margin: 0;
font-size: 0.88rem;
line-height: 1.5;
color: rgba(255, 255, 255, 0.75);
}
.code {
font-size: 2.2rem;
font-weight: 700;
letter-spacing: 0.12em;
font-variant-numeric: tabular-nums;
color: white;
}
.expires {
margin: 0;
font-size: 0.8rem;
color: rgba(255, 255, 255, 0.55);
}
.device-list {
margin: 0;
padding: 0;
list-style: none;
display: flex;
flex-direction: column;
gap: 0.4rem;
li {
display: flex;
align-items: center;
gap: 0.75rem;
padding: 0.55rem 0.75rem;
border-radius: 8px;
background: rgba(255, 255, 255, 0.03);
border: 1px solid rgba(255, 255, 255, 0.06);
}
}
.device-info {
flex: 1;
min-width: 0;
display: flex;
flex-direction: column;
}
.device-name { font-weight: 600; overflow-wrap: anywhere; }
.device-meta { font-size: 0.8rem; color: rgba(255, 255, 255, 0.5); }
.btn-icon-danger {
justify-content: center;
width: 44px;
border: none;
border-radius: 8px;
background: transparent;
color: #fca5a5;
cursor: pointer;
&:hover { background: rgba(239, 68, 68, 0.12); }
&:focus-visible { outline: 2px solid #6c63ff; }
}
.advanced {
summary {
cursor: pointer;
font-size: 0.88rem;
color: rgba(255, 255, 255, 0.7);
min-height: 32px;
}
&[open] summary { margin-bottom: 0.75rem; }
}
.port-row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.6rem;
margin-bottom: 0.75rem;
input {
width: 8rem;
padding: 0.6rem 0.8rem;
border-radius: 8px;
border: 1px solid #374151;
background: #1f2937;
color: white;
}
}
@@ -0,0 +1,185 @@
import { Component, ElementRef, OnDestroy, OnInit, inject } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpErrorResponse } from '@angular/common/http';
import { ActivatedRoute } from '@angular/router';
import { TranslatePipe, TranslateService } from '@ngx-translate/core';
import { LucideAngularModule, Tablet, Trash2, RefreshCw, AlertCircle, ShieldCheck } from 'lucide-angular';
import QRCode from 'qrcode';
import {
PairedDevice, PairingCode, RemoteAccessService, RemoteAccessStatus
} from '../../services/remote-access.service';
import { ConfirmDialogService } from '../../shared/confirm-dialog/confirm-dialog.service';
/**
* Paramètres > Accès depuis une tablette (mode bureau). Active le connecteur réseau local,
* affiche l'adresse + un code d'appairage (et son QR code), liste les appareils appairés.
* Masquée quand le Core ne connaît pas ces routes (Docker : 404).
*/
@Component({
selector: 'app-remote-access-section',
imports: [FormsModule, TranslatePipe, LucideAngularModule],
templateUrl: './remote-access-section.component.html',
styleUrls: ['../settings.component.scss', './remote-access-section.component.scss']
})
export class RemoteAccessSectionComponent implements OnInit, OnDestroy {
readonly Tablet = Tablet;
readonly Trash2 = Trash2;
readonly RefreshCw = RefreshCw;
readonly AlertCircle = AlertCircle;
readonly ShieldCheck = ShieldCheck;
private readonly remoteAccess = inject(RemoteAccessService);
private readonly translate = inject(TranslateService);
private readonly confirmDialog = inject(ConfirmDialogService);
private readonly route = inject(ActivatedRoute);
private readonly host = inject(ElementRef<HTMLElement>);
/** Null tant que non chargé, ou si la fonctionnalité n'existe pas (Docker). */
status: RemoteAccessStatus | null = null;
port = 0;
busy = false;
error: string | null = null;
pairing: PairingCode | null = null;
qrDataUrl: string | null = null;
secondsLeft = 0;
private countdown?: ReturnType<typeof setInterval>;
ngOnInit(): void {
this.remoteAccess.status().subscribe({
next: status => {
this.apply(status);
if (this.route.snapshot.queryParamMap.get('section') === 'remote-access') {
setTimeout(() => this.host.nativeElement.scrollIntoView({ behavior: 'smooth', block: 'start' }));
}
},
error: () => { this.status = null; }
});
}
ngOnDestroy(): void {
this.stopCountdown();
}
get primaryUrl(): string | null {
return this.status?.urls[0] ?? null;
}
toggle(enabled: boolean): void {
this.save(enabled);
}
applyPort(): void {
this.save(this.status?.enabled ?? false);
}
private save(enabled: boolean): void {
if (!this.status || this.busy) return;
this.busy = true;
this.error = null;
this.remoteAccess.configure(enabled, Number(this.port)).subscribe({
next: status => {
this.busy = false;
this.apply(status);
if (!status.running) this.clearPairing();
},
error: (err: HttpErrorResponse) => {
this.busy = false;
this.error = err.error?.error ?? this.translate.instant('remoteAccess.settings.saveError');
}
});
}
newCode(): void {
if (this.busy) return;
this.busy = true;
this.error = null;
this.remoteAccess.newPairingCode().subscribe({
next: async code => {
this.busy = false;
this.pairing = code;
this.startCountdown();
await this.renderQr(code.code);
},
error: (err: HttpErrorResponse) => {
this.busy = false;
this.error = err.error?.error ?? this.translate.instant('remoteAccess.settings.codeError');
}
});
}
async revoke(device: PairedDevice): Promise<void> {
const ok = await this.confirmDialog.confirm({
title: this.translate.instant('remoteAccess.settings.revokeTitle'),
message: this.translate.instant('remoteAccess.settings.revokeMessage', { name: device.name }),
confirmLabel: this.translate.instant('remoteAccess.settings.revoke'),
variant: 'danger'
});
if (!ok) return;
this.remoteAccess.revoke(device.id).subscribe({
next: () => {
if (this.status) this.status = { ...this.status, devices: this.status.devices.filter(d => d.id !== device.id) };
},
error: () => { this.error = this.translate.instant('remoteAccess.settings.revokeError'); }
});
}
refresh(): void {
this.remoteAccess.status().subscribe({ next: s => this.apply(s), error: () => undefined });
}
formatDate(value?: string | null): string {
if (!value) return '—';
const lang = this.translate.currentLang;
return new Date(value).toLocaleString(lang ? String(lang) : undefined, { dateStyle: 'medium', timeStyle: 'short' });
}
private apply(status: RemoteAccessStatus): void {
this.status = status;
this.port = status.port;
}
/** Le QR code ouvre directement l'écran d'appairage avec le code pré-rempli. */
private async renderQr(code: string): Promise<void> {
this.qrDataUrl = null;
if (!this.primaryUrl) return;
try {
this.qrDataUrl = await QRCode.toDataURL(`${this.primaryUrl}/pair?code=${code}`,
{ margin: 1, width: 220, color: { dark: '#111827', light: '#ffffff' } });
} catch {
this.qrDataUrl = null; // le code et l'adresse restent affichés
}
}
private startCountdown(): void {
this.stopCountdown();
const tick = () => {
const left = this.pairing ? Math.max(0, Math.round((Date.parse(this.pairing.expiresAt) - Date.now()) / 1000)) : 0;
this.secondsLeft = left;
if (left === 0) {
this.clearPairing();
this.refresh(); // l'appareil vient peut-être de s'appairer
}
};
tick();
this.countdown = setInterval(tick, 1000);
}
private stopCountdown(): void {
if (this.countdown) clearInterval(this.countdown);
this.countdown = undefined;
}
private clearPairing(): void {
this.stopCountdown();
this.pairing = null;
this.qrDataUrl = null;
}
get countdownLabel(): string {
const m = Math.floor(this.secondsLeft / 60);
const s = String(this.secondsLeft % 60).padStart(2, '0');
return `${m}:${s}`;
}
}
@@ -16,6 +16,16 @@
</div>
</section>
@if (remoteDevice) {
<div class="alert alert-warn">
<lucide-icon [img]="AlertCircle" [size]="16"></lucide-icon>
<span>{{ 'remoteAccess.settings.onDevice' | translate }}</span>
</div>
} @else {
<!-- Accès depuis une tablette (mode bureau ; masqué en Docker). -->
<app-remote-access-section></app-remote-access-section>
}
@if (errorMessage) {
<div class="alert alert-error">
<lucide-icon [img]="AlertCircle" [size]="16"></lucide-icon>
+12 -3
View File
@@ -12,6 +12,8 @@ import { UpdatesSectionComponent } from './updates-section/updates-section.compo
import { OllamaModelManagerComponent } from './ollama-model-manager/ollama-model-manager.component';
import { LanguageSwitcherComponent } from '../shared/language-switcher/language-switcher.component';
import { FileDropDirective } from '../shared/file-drop.directive';
import { RemoteAccessSectionComponent } from './remote-access-section/remote-access-section.component';
import { RemoteAccessService } from '../services/remote-access.service';
/**
* Ecran de parametrage du LLM utilise par le Brain.
@@ -29,7 +31,7 @@ import { FileDropDirective } from '../shared/file-drop.directive';
*/
@Component({
selector: 'app-settings',
imports: [CommonModule, FormsModule, LucideAngularModule, TranslatePipe, UpdatesSectionComponent, OllamaModelManagerComponent, LanguageSwitcherComponent, FileDropDirective],
imports: [CommonModule, FormsModule, LucideAngularModule, TranslatePipe, UpdatesSectionComponent, OllamaModelManagerComponent, LanguageSwitcherComponent, FileDropDirective, RemoteAccessSectionComponent],
templateUrl: './settings.component.html',
styleUrls: ['./settings.component.scss']
})
@@ -100,14 +102,21 @@ export class SettingsComponent implements OnInit {
private router: Router,
private layoutService: LayoutService,
private translate: TranslateService,
private campaignService: CampaignService
private campaignService: CampaignService,
private remoteAccess: RemoteAccessService
) {}
/** Ouvert depuis une tablette (accès distant) : les Paramètres restent réservés au PC. */
remoteDevice = false;
ngOnInit(): void {
// Page racine : on s'assure de ne pas heriter de la sidebar d'une
// section precedente (cf. fix CampaignsComponent / LoreComponent).
this.layoutService.hide();
this.loadSettings();
this.remoteAccess.session().subscribe(session => {
this.remoteDevice = session.remote;
if (!session.remote) this.loadSettings();
});
// Campagnes proposées pour un export ciblé (silencieux en cas d'échec).
this.campaignService.getAllCampaigns().subscribe({
next: (list) => this.campaigns = list,