diff --git a/core/src/main/java/com/loremind/application/remoteaccess/NetworkReadiness.java b/core/src/main/java/com/loremind/application/remoteaccess/NetworkReadiness.java index a93e722..823f245 100644 --- a/core/src/main/java/com/loremind/application/remoteaccess/NetworkReadiness.java +++ b/core/src/main/java/com/loremind/application/remoteaccess/NetworkReadiness.java @@ -18,6 +18,10 @@ import java.util.Locale; * @param thirdPartyFirewalls pare-feu tiers présents : leurs réglages ne sont pas lisibles, donc {@code ready} * ne peut pas être garanti — le front avertit l'utilisateur de les régler lui-même * @param program exécutable concerné + * @param platform {@code windows} ou {@code linux} + * @param linuxFirewall Linux : pare-feu actif ({@code ufw}, {@code firewalld}, {@code none}) + * @param portOpen Linux : port autorisé ({@code null} = invérifiable sans droits administrateur) + * @param fixCommand Linux : commande à lancer pour ouvrir le port, ou {@code null} */ public record NetworkReadiness( boolean supported, @@ -26,7 +30,11 @@ public record NetworkReadiness( boolean firewallAllowed, boolean firewallBlocked, List thirdPartyFirewalls, - String program + String program, + String platform, + String linuxFirewall, + Boolean portOpen, + String fixCommand ) { static final String PUBLIC = "Public"; @@ -34,7 +42,10 @@ public record NetworkReadiness( public static NetworkReadiness evaluate(NetworkSnapshot snapshot) { if (snapshot == null || !snapshot.supported()) { - return new NetworkReadiness(false, false, List.of(), false, false, List.of(), null); + return new NetworkReadiness(false, false, List.of(), false, false, List.of(), null, null, null, null, null); + } + if (NetworkSnapshot.LINUX.equals(snapshot.platform())) { + return evaluateLinux(snapshot); } List rules = snapshot.rules() == null ? List.of() : snapshot.rules(); boolean allowedPrivate = covers(rules, "Allow", PRIVATE); @@ -53,7 +64,27 @@ public record NetworkReadiness( boolean ready = allowedPrivate && !blockedPrivate && blockingPublic.isEmpty(); List thirdParty = snapshot.thirdPartyFirewalls() == null ? List.of() : snapshot.thirdPartyFirewalls(); return new NetworkReadiness(true, ready, blockingPublic, allowedPrivate, blockedPrivate, thirdParty, - snapshot.program()); + snapshot.program(), NetworkSnapshot.WINDOWS, null, null, null); + } + + /** + * Linux : prêt si aucun pare-feu (ufw, firewalld) n'est actif, ou si le port est ouvert. + * Port invérifiable (ufw sans droits root) : pas prêt, mais pas en erreur — le front + * affiche la commande « au cas où ». + */ + private static NetworkReadiness evaluateLinux(NetworkSnapshot s) { + String fw = s.linuxFirewall() == null ? "none" : s.linuxFirewall(); + boolean ready = "none".equals(fw) || Boolean.TRUE.equals(s.portOpen()); + return new NetworkReadiness(true, ready, List.of(), false, false, List.of(), null, + NetworkSnapshot.LINUX, fw, s.portOpen(), ready ? null : linuxCommand(fw, s.port())); + } + + static String linuxCommand(String firewall, int port) { + return switch (firewall) { + case "ufw" -> "sudo ufw allow " + port + "/tcp"; + case "firewalld" -> "sudo firewall-cmd --permanent --add-port=" + port + "/tcp && sudo firewall-cmd --reload"; + default -> null; + }; } /** Une règle ACTIVE de cette action couvre-t-elle ce profil (« Any » couvre tout) ? */ diff --git a/core/src/main/java/com/loremind/application/remoteaccess/RemoteAccessService.java b/core/src/main/java/com/loremind/application/remoteaccess/RemoteAccessService.java index f51208f..76b60e1 100644 --- a/core/src/main/java/com/loremind/application/remoteaccess/RemoteAccessService.java +++ b/core/src/main/java/com/loremind/application/remoteaccess/RemoteAccessService.java @@ -216,6 +216,11 @@ public class RemoteAccessService { return deviceRepository.deleteById(deviceId); } + /** Port réseau réglé (ouvert ou non) : celui que le pare-feu doit laisser passer. */ + public synchronized int configuredPort() { + return currentConfig().port(); + } + /** Port du connecteur réseau ouvert, ou -1 (pour le filtre : qui vient « de l'extérieur » ?). */ public int lanPort() { return lanConnector.runningPort(); diff --git a/core/src/main/java/com/loremind/domain/remoteaccess/NetworkSnapshot.java b/core/src/main/java/com/loremind/domain/remoteaccess/NetworkSnapshot.java index 857dfc7..203fda6 100644 --- a/core/src/main/java/com/loremind/domain/remoteaccess/NetworkSnapshot.java +++ b/core/src/main/java/com/loremind/domain/remoteaccess/NetworkSnapshot.java @@ -13,9 +13,29 @@ import java.util.List; * @param rules règles entrantes du pare-feu pour ce programme * @param thirdPartyFirewalls pare-feu tiers déclarés à Windows (Bitdefender, Norton…) : ils filtrent * EN PLUS du pare-feu Windows, avec leurs propres règles, illisibles d'ici + * @param platform {@code windows} ou {@code linux} + * @param linuxFirewall Linux : pare-feu actif détecté ({@code ufw}, {@code firewalld}, {@code none}) + * @param port port réseau de l'accès distant (Linux : port à ouvrir) + * @param portOpen Linux : port autorisé par le pare-feu ; {@code null} = impossible à savoir sans + * droits administrateur (ex. règles ufw illisibles) */ public record NetworkSnapshot(boolean supported, String program, List networks, List rules, - List thirdPartyFirewalls) { + List thirdPartyFirewalls, String platform, String linuxFirewall, + int port, Boolean portOpen) { + + public static final String WINDOWS = "windows"; + public static final String LINUX = "linux"; + + /** Instantané Windows (réseaux, règles du pare-feu, pare-feu tiers). */ + public NetworkSnapshot(boolean supported, String program, List networks, List rules, + List thirdPartyFirewalls) { + this(supported, program, networks, rules, thirdPartyFirewalls, WINDOWS, null, 0, null); + } + + /** Instantané Linux : pare-feu actif et état du port quand il est lisible. */ + public static NetworkSnapshot linux(String linuxFirewall, int port, Boolean portOpen) { + return new NetworkSnapshot(true, null, List.of(), List.of(), List.of(), LINUX, linuxFirewall, port, portOpen); + } /** Catégorie Windows : {@code Public}, {@code Private} ou {@code DomainAuthenticated}. */ public record Network(String name, String alias, String category) {} diff --git a/core/src/main/java/com/loremind/domain/remoteaccess/ports/HostNetworkAccess.java b/core/src/main/java/com/loremind/domain/remoteaccess/ports/HostNetworkAccess.java index c4d5336..ffb9bb9 100644 --- a/core/src/main/java/com/loremind/domain/remoteaccess/ports/HostNetworkAccess.java +++ b/core/src/main/java/com/loremind/domain/remoteaccess/ports/HostNetworkAccess.java @@ -12,8 +12,8 @@ public interface HostNetworkAccess { /** Résultat de la demande d'autorisation dans le pare-feu. */ enum FirewallFixOutcome { APPLIED, CANCELLED, FAILED, UNSUPPORTED } - /** Lecture seule, sans droits administrateur. */ - NetworkSnapshot inspect(); + /** Lecture seule, sans droits administrateur. {@code port} : port réseau de l'accès distant. */ + NetworkSnapshot inspect(int port); /** * Autorise l'application en entrée sur les réseaux privés. Passe par la confirmation diff --git a/core/src/main/java/com/loremind/infrastructure/desktop/HostNetworkAccessConfig.java b/core/src/main/java/com/loremind/infrastructure/desktop/HostNetworkAccessConfig.java new file mode 100644 index 0000000..7041a86 --- /dev/null +++ b/core/src/main/java/com/loremind/infrastructure/desktop/HostNetworkAccessConfig.java @@ -0,0 +1,34 @@ +package com.loremind.infrastructure.desktop; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.loremind.domain.remoteaccess.NetworkSnapshot; +import com.loremind.domain.remoteaccess.ports.HostNetworkAccess; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; + +import java.util.Locale; + +/** + * Mode bureau : choisit l'accès au pare-feu selon le système — Windows (PowerShell, UAC), + * Linux (ufw / firewalld, lecture sans root), sinon rien à vérifier (macOS…). + */ +@Configuration +@Profile("local") +public class HostNetworkAccessConfig { + + @Bean + public HostNetworkAccess hostNetworkAccess(ObjectMapper objectMapper) { + String os = System.getProperty("os.name", "").toLowerCase(Locale.ROOT); + if (os.startsWith("windows")) return new WindowsHostNetworkAccess(objectMapper); + if (os.contains("linux")) return new LinuxHostNetworkAccess(); + return new UnsupportedHostNetworkAccess(); + } + + /** Système sans vérification prise en charge : le front n'affiche pas de diagnostic. */ + static final class UnsupportedHostNetworkAccess implements HostNetworkAccess { + @Override public NetworkSnapshot inspect(int port) { return NetworkSnapshot.unsupported(); } + @Override public FirewallFixOutcome allowThroughFirewall() { return FirewallFixOutcome.UNSUPPORTED; } + @Override public void openNetworkSettings() { /* rien à ouvrir */ } + } +} diff --git a/core/src/main/java/com/loremind/infrastructure/desktop/LinuxHostNetworkAccess.java b/core/src/main/java/com/loremind/infrastructure/desktop/LinuxHostNetworkAccess.java new file mode 100644 index 0000000..49eba4c --- /dev/null +++ b/core/src/main/java/com/loremind/infrastructure/desktop/LinuxHostNetworkAccess.java @@ -0,0 +1,120 @@ +package com.loremind.infrastructure.desktop; + +import com.loremind.domain.remoteaccess.NetworkSnapshot; +import com.loremind.domain.remoteaccess.ports.HostNetworkAccess; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; +import java.util.Locale; +import java.util.concurrent.TimeUnit; + +/** + * Pare-feu sous Linux (Debian, Ubuntu, Fedora…) pour l'accès distant, SANS droits root. + *

+ * Ce qu'on peut savoir sans root : quel pare-feu est actif — {@code ufw} via + * {@code /etc/ufw/ufw.conf} (lisible par tous), {@code firewalld} via {@code systemctl} — et, + * pour firewalld seulement, si le port est ouvert ({@code firewall-cmd --query-port}, autorisé + * aux utilisateurs). Les règles d'ufw ne se lisent qu'en root : l'état du port reste alors + * inconnu et le front affiche la commande à lancer. Pas d'autorisation en un clic : sur un + * serveur sans écran, aucune fenêtre ne peut demander le mot de passe administrateur. + *

+ * Choisie au démarrage par {@code HostNetworkAccessConfig} sous Linux. + */ +public class LinuxHostNetworkAccess implements HostNetworkAccess { + + private static final Logger log = LoggerFactory.getLogger(LinuxHostNetworkAccess.class); + private static final long COMMAND_TIMEOUT_S = 10; + + static final String UFW = "ufw"; + static final String FIREWALLD = "firewalld"; + static final String NONE = "none"; + + private final Path ufwConf; + + public LinuxHostNetworkAccess() { + this(Path.of("/etc/ufw/ufw.conf")); + } + + LinuxHostNetworkAccess(Path ufwConf) { + this.ufwConf = ufwConf; + } + + @Override + public NetworkSnapshot inspect(int port) { + if (ufwEnabled(readQuietly(ufwConf))) { + // Règles d'ufw illisibles sans root : état du port inconnu. + return NetworkSnapshot.linux(UFW, port, null); + } + if ("active".equals(run(List.of("systemctl", "is-active", FIREWALLD)).output().trim())) { + return NetworkSnapshot.linux(FIREWALLD, port, firewalldPortOpen(port)); + } + return NetworkSnapshot.linux(NONE, port, null); + } + + @Override + public FirewallFixOutcome allowThroughFirewall() { + return FirewallFixOutcome.UNSUPPORTED; + } + + @Override + public void openNetworkSettings() { + // Pas de réglage réseau « Public / Privé » à basculer sous Linux. + } + + /** {@code firewall-cmd --query-port} : « yes » (0) / « no » (1) ; autre = inconnu. */ + private Boolean firewalldPortOpen(int port) { + Result r = run(List.of("firewall-cmd", "--query-port=" + port + "/tcp")); + return interpretQuery(r.exitCode(), r.output()); + } + + static Boolean interpretQuery(int exitCode, String output) { + String out = output == null ? "" : output.trim().toLowerCase(Locale.ROOT); + if (exitCode == 0 && out.startsWith("yes")) return true; + if (exitCode == 1 && out.startsWith("no")) return false; + return null; + } + + /** {@code ENABLED=yes} dans ufw.conf (guillemets et casse tolérés). */ + static boolean ufwEnabled(String conf) { + if (conf == null) return false; + return conf.lines() + .map(String::trim) + .filter(l -> !l.startsWith("#")) + .map(l -> l.replace("\"", "").replace("'", "").replace(" ", "")) + .anyMatch(l -> l.equalsIgnoreCase("ENABLED=yes")); + } + + private static String readQuietly(Path file) { + try { + return Files.isReadable(file) ? Files.readString(file, StandardCharsets.UTF_8) : null; + } catch (IOException e) { + return null; + } + } + + private record Result(int exitCode, String output) {} + + /** Commande système sans shell (pas d'interprétation), avec délai ; absente → code -1. */ + private static Result run(List command) { + try { + Process p = new ProcessBuilder(command).redirectErrorStream(true).start(); + p.getOutputStream().close(); + if (!p.waitFor(COMMAND_TIMEOUT_S, TimeUnit.SECONDS)) { + p.destroyForcibly(); + return new Result(-1, ""); + } + return new Result(p.exitValue(), new String(p.getInputStream().readAllBytes(), StandardCharsets.UTF_8)); + } catch (IOException e) { + log.debug("Commande {} indisponible : {}", command.get(0), e.getMessage()); + return new Result(-1, ""); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + return new Result(-1, ""); + } + } +} diff --git a/core/src/main/java/com/loremind/infrastructure/desktop/WindowsHostNetworkAccess.java b/core/src/main/java/com/loremind/infrastructure/desktop/WindowsHostNetworkAccess.java index 69deef8..04eaa9d 100644 --- a/core/src/main/java/com/loremind/infrastructure/desktop/WindowsHostNetworkAccess.java +++ b/core/src/main/java/com/loremind/infrastructure/desktop/WindowsHostNetworkAccess.java @@ -6,8 +6,6 @@ import com.loremind.domain.remoteaccess.NetworkSnapshot; import com.loremind.domain.remoteaccess.ports.HostNetworkAccess; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.context.annotation.Profile; -import org.springframework.stereotype.Component; import java.io.IOException; import java.io.InputStream; @@ -31,9 +29,9 @@ import java.util.concurrent.TimeUnit; * Les scripts sont passés en {@code -EncodedCommand} (UTF-16LE base64) : aucun problème de * guillemets ni d'accents. Le seul paramètre variable est le chemin de l'exécutable, * fourni par le système (pas par l'utilisateur), et échappé pour une chaîne PowerShell. + *

+ * Choisie au démarrage par {@code HostNetworkAccessConfig} sous Windows. */ -@Component -@Profile("local") public class WindowsHostNetworkAccess implements HostNetworkAccess { private static final Logger log = LoggerFactory.getLogger(WindowsHostNetworkAccess.class); @@ -52,7 +50,7 @@ public class WindowsHostNetworkAccess implements HostNetworkAccess { } @Override - public NetworkSnapshot inspect() { + public NetworkSnapshot inspect(int port) { String program = currentProgram(); if (!isWindows() || program == null) return NetworkSnapshot.unsupported(); try { diff --git a/core/src/main/java/com/loremind/infrastructure/web/controller/RemoteAccessAdminController.java b/core/src/main/java/com/loremind/infrastructure/web/controller/RemoteAccessAdminController.java index 55854b7..b275b56 100644 --- a/core/src/main/java/com/loremind/infrastructure/web/controller/RemoteAccessAdminController.java +++ b/core/src/main/java/com/loremind/infrastructure/web/controller/RemoteAccessAdminController.java @@ -61,14 +61,14 @@ public class RemoteAccessAdminController { /** Une tablette peut-elle joindre ce PC ? (type de réseau, règle du pare-feu) */ @GetMapping("/network-check") public NetworkReadiness networkCheck() { - return NetworkReadiness.evaluate(hostNetworkAccess.inspect()); + return NetworkReadiness.evaluate(hostNetworkAccess.inspect(remoteAccessService.configuredPort())); } /** Ajoute la règle du pare-feu ; attend la réponse de l'utilisateur à la confirmation Windows (UAC). */ @PostMapping("/firewall-rule") public FirewallFixResponse allowThroughFirewall() { HostNetworkAccess.FirewallFixOutcome outcome = hostNetworkAccess.allowThroughFirewall(); - return new FirewallFixResponse(outcome, NetworkReadiness.evaluate(hostNetworkAccess.inspect())); + return new FirewallFixResponse(outcome, NetworkReadiness.evaluate(hostNetworkAccess.inspect(remoteAccessService.configuredPort()))); } /** Ouvre les réglages réseau de Windows (pour passer un Wi-Fi « Public » en « Privé »). */ diff --git a/core/src/test/java/com/loremind/application/remoteaccess/NetworkReadinessTest.java b/core/src/test/java/com/loremind/application/remoteaccess/NetworkReadinessTest.java index b571b06..1677503 100644 --- a/core/src/test/java/com/loremind/application/remoteaccess/NetworkReadinessTest.java +++ b/core/src/test/java/com/loremind/application/remoteaccess/NetworkReadinessTest.java @@ -85,4 +85,34 @@ class NetworkReadinessTest { NetworkReadiness r = eval(List.of(new Network(null, "Wi-Fi", "Public")), List.of(ALLOW_PRIVATE)); assertEquals(List.of("Wi-Fi"), r.publicNetworks()); } + + // --- Linux --- + + @Test + void linux_withoutFirewall_isReady() { + NetworkReadiness r = NetworkReadiness.evaluate(NetworkSnapshot.linux("none", 8765, null)); + assertTrue(r.ready()); + assertEquals("linux", r.platform()); + assertNull(r.fixCommand()); + } + + @Test + void linux_ufw_portUnknown_proposesTheCommand() { + NetworkReadiness r = NetworkReadiness.evaluate(NetworkSnapshot.linux("ufw", 8765, null)); + assertFalse(r.ready()); + assertNull(r.portOpen()); + assertEquals("sudo ufw allow 8765/tcp", r.fixCommand()); + } + + @Test + void linux_firewalld_closedThenOpen() { + NetworkReadiness closed = NetworkReadiness.evaluate(NetworkSnapshot.linux("firewalld", 9000, false)); + assertFalse(closed.ready()); + assertEquals("sudo firewall-cmd --permanent --add-port=9000/tcp && sudo firewall-cmd --reload", closed.fixCommand()); + + NetworkReadiness open = NetworkReadiness.evaluate(NetworkSnapshot.linux("firewalld", 9000, true)); + assertTrue(open.ready()); + assertNull(open.fixCommand()); + } } + diff --git a/core/src/test/java/com/loremind/infrastructure/desktop/LinuxHostNetworkAccessTest.java b/core/src/test/java/com/loremind/infrastructure/desktop/LinuxHostNetworkAccessTest.java new file mode 100644 index 0000000..ae8f346 --- /dev/null +++ b/core/src/test/java/com/loremind/infrastructure/desktop/LinuxHostNetworkAccessTest.java @@ -0,0 +1,56 @@ +package com.loremind.infrastructure.desktop; + +import com.loremind.domain.remoteaccess.NetworkSnapshot; +import com.loremind.domain.remoteaccess.ports.HostNetworkAccess; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +import java.nio.file.Files; +import java.nio.file.Path; + +import static org.junit.jupiter.api.Assertions.*; + +/** + * Test de {@link LinuxHostNetworkAccess} : lecture de ufw.conf, interprétation de + * {@code firewall-cmd --query-port}, et cas ufw actif sans droits root (port inconnu). + */ +class LinuxHostNetworkAccessTest { + + @Test + void ufwEnabled_readsTheConfigFile() { + assertTrue(LinuxHostNetworkAccess.ufwEnabled("# commentaire\nENABLED=yes\nLOGLEVEL=low")); + assertTrue(LinuxHostNetworkAccess.ufwEnabled("ENABLED=\"yes\"")); + assertFalse(LinuxHostNetworkAccess.ufwEnabled("ENABLED=no")); + assertFalse(LinuxHostNetworkAccess.ufwEnabled("#ENABLED=yes")); + assertFalse(LinuxHostNetworkAccess.ufwEnabled(null)); + } + + @Test + void firewalldQuery_yesNoOrUnknown() { + assertEquals(Boolean.TRUE, LinuxHostNetworkAccess.interpretQuery(0, "yes\n")); + assertEquals(Boolean.FALSE, LinuxHostNetworkAccess.interpretQuery(1, "no\n")); + // Refus D-Bus / commande absente : on ne prétend rien. + assertNull(LinuxHostNetworkAccess.interpretQuery(-1, "")); + assertNull(LinuxHostNetworkAccess.interpretQuery(11, "Authorization failed.")); + } + + @Test + void activeUfw_meansPortUnknownWithoutRoot(@TempDir Path dir) throws Exception { + Path conf = dir.resolve("ufw.conf"); + Files.writeString(conf, "ENABLED=yes\n"); + + NetworkSnapshot s = new LinuxHostNetworkAccess(conf).inspect(8765); + + assertTrue(s.supported()); + assertEquals("linux", s.platform()); + assertEquals("ufw", s.linuxFirewall()); + assertEquals(8765, s.port()); + assertNull(s.portOpen()); + } + + @Test + void noOneClickFixOnLinux() { + assertEquals(HostNetworkAccess.FirewallFixOutcome.UNSUPPORTED, + new LinuxHostNetworkAccess(Path.of("absent")).allowThroughFirewall()); + } +} diff --git a/core/src/test/java/com/loremind/infrastructure/desktop/WindowsHostNetworkAccessTest.java b/core/src/test/java/com/loremind/infrastructure/desktop/WindowsHostNetworkAccessTest.java index f5199eb..d778ef4 100644 --- a/core/src/test/java/com/loremind/infrastructure/desktop/WindowsHostNetworkAccessTest.java +++ b/core/src/test/java/com/loremind/infrastructure/desktop/WindowsHostNetworkAccessTest.java @@ -79,7 +79,7 @@ class WindowsHostNetworkAccessTest { @Test @EnabledOnOs(OS.WINDOWS) void inspect_readsTheRealSystem_onWindows() { - NetworkSnapshot s = new WindowsHostNetworkAccess(mapper).inspect(); + NetworkSnapshot s = new WindowsHostNetworkAccess(mapper).inspect(8765); assertTrue(s.supported(), "PowerShell doit répondre en lecture seule sur Windows"); assertNotNull(s.program()); assertNotNull(s.thirdPartyFirewalls()); diff --git a/web/src/app/services/remote-access.service.ts b/web/src/app/services/remote-access.service.ts index c030213..42bb7d3 100644 --- a/web/src/app/services/remote-access.service.ts +++ b/web/src/app/services/remote-access.service.ts @@ -41,6 +41,13 @@ export interface NetworkReadiness { /** Pare-feu tiers (Bitdefender…) : ils filtrent en plus de Windows, réglages illisibles d'ici. */ thirdPartyFirewalls: string[]; program?: string | null; + platform?: 'windows' | 'linux' | null; + /** Linux : pare-feu actif (ufw, firewalld) ou « none ». */ + linuxFirewall?: string | null; + /** Linux : port autorisé ; null = invérifiable sans droits administrateur (ufw). */ + portOpen?: boolean | null; + /** Linux : commande à lancer sur la machine pour ouvrir le port. */ + fixCommand?: string | null; } export type FirewallFixOutcome = 'APPLIED' | 'CANCELLED' | 'FAILED' | 'UNSUPPORTED'; diff --git a/web/src/app/settings/remote-access-section/remote-access-section.component.html b/web/src/app/settings/remote-access-section/remote-access-section.component.html index 5a23d7f..dcc15dd 100644 --- a/web/src/app/settings/remote-access-section/remote-access-section.component.html +++ b/web/src/app/settings/remote-access-section/remote-access-section.component.html @@ -39,7 +39,32 @@ @if (network?.supported) {

{{ 'remoteAccess.network.title' | translate }}

- @if (network!.ready) { + @if (isLinux) { + + @if (network!.ready) { +

+ + {{ (network!.linuxFirewall === 'none' ? 'remoteAccess.network.linuxNone' : 'remoteAccess.network.linuxOpen') + | translate: { fw: network!.linuxFirewall, port: s.port } }} +

+ } @else { +
+

+ {{ (network!.portOpen === false ? 'remoteAccess.network.linuxClosed' : 'remoteAccess.network.linuxUnknown') + | translate: { fw: network!.linuxFirewall, port: s.port } }} +

+ @if (network!.fixCommand) { +
+ {{ network!.fixCommand }} + +
+ } +
+ } + } @else if (network!.ready) {

{{ (thirdPartyFirewalls.length > 0 ? 'remoteAccess.network.windowsReady' : 'remoteAccess.network.ready') | translate }} diff --git a/web/src/app/settings/remote-access-section/remote-access-section.component.scss b/web/src/app/settings/remote-access-section/remote-access-section.component.scss index 21578a6..5ddf3b7 100644 --- a/web/src/app/settings/remote-access-section/remote-access-section.component.scss +++ b/web/src/app/settings/remote-access-section/remote-access-section.component.scss @@ -231,3 +231,25 @@ &:disabled { opacity: 0.6; cursor: wait; } &:focus-visible { outline: 2px solid #6c63ff; border-radius: 4px; } } + +// Linux : commande d'ouverture du port, sélectionnable et copiable. +.command-row { + display: flex; + flex-wrap: wrap; + align-items: center; + gap: 0.5rem; + max-width: 100%; +} + +.command { + flex: 1 1 260px; + min-width: 0; + padding: 0.55rem 0.75rem; + border-radius: 6px; + background: #0b0b16; + border: 1px solid #2a2a45; + color: #c7d2fe; + font-size: 0.85rem; + overflow-wrap: anywhere; + user-select: all; +} diff --git a/web/src/app/settings/remote-access-section/remote-access-section.component.ts b/web/src/app/settings/remote-access-section/remote-access-section.component.ts index 7c50b6c..e0b1e5e 100644 --- a/web/src/app/settings/remote-access-section/remote-access-section.component.ts +++ b/web/src/app/settings/remote-access-section/remote-access-section.component.ts @@ -3,7 +3,7 @@ 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, CheckCircle2, Settings2 } from 'lucide-angular'; +import { LucideAngularModule, Tablet, Trash2, RefreshCw, AlertCircle, ShieldCheck, CheckCircle2, Settings2, Copy } from 'lucide-angular'; import QRCode from 'qrcode'; import { @@ -30,6 +30,8 @@ export class RemoteAccessSectionComponent implements OnInit, OnDestroy { readonly ShieldCheck = ShieldCheck; readonly CheckCircle2 = CheckCircle2; readonly Settings2 = Settings2; + readonly Copy = Copy; + copied = false; private readonly remoteAccess = inject(RemoteAccessService); private readonly translate = inject(TranslateService); @@ -197,8 +199,25 @@ export class RemoteAccessSectionComponent implements OnInit, OnDestroy { return this.network?.thirdPartyFirewalls ?? []; } + get isLinux(): boolean { + return this.network?.platform === 'linux'; + } + get firewallNeedsFix(): boolean { - return !!this.network && (!this.network.firewallAllowed || this.network.firewallBlocked); + return !!this.network && !this.isLinux && (!this.network.firewallAllowed || this.network.firewallBlocked); + } + + /** Linux : copie la commande d'ouverture du port (à lancer sur le serveur). */ + async copyFixCommand(): Promise { + const command = this.network?.fixCommand; + if (!command) return; + try { + await navigator.clipboard.writeText(command); + this.copied = true; + setTimeout(() => this.copied = false, 2000); + } catch { + this.copied = false; // presse-papiers indisponible : la commande reste lisible et sélectionnable + } } /** Le QR code ouvre directement l'écran d'appairage avec le code pré-rempli. */ diff --git a/web/src/assets/i18n/en.json b/web/src/assets/i18n/en.json index da59e40..d122aef 100644 --- a/web/src/assets/i18n/en.json +++ b/web/src/assets/i18n/en.json @@ -2458,7 +2458,13 @@ "thirdParty": "{{names}} also filters connections on this PC, with its own rules that DM Loremind can't check. Until it allows it, the tablet will load forever.", "thirdPartyHowTo": "In that software's firewall settings: classify your Wi-Fi as a home network (not public, stealth mode off), then add a rule allowing incoming connections for DM Loremind.", "docLink": "See how to fix it", - "docUrl": "https://loremind-docs.igmlcreation.fr/en/docs/configuration/acces-tablette#the-tablet-loads-forever" + "docUrl": "https://loremind-docs.igmlcreation.fr/en/docs/configuration/acces-tablette#the-tablet-loads-forever", + "linuxNone": "No ufw or firewalld firewall is active on this machine: nothing to open.", + "linuxOpen": "The firewall ({{fw}}) lets port {{port}} through.", + "linuxClosed": "The firewall ({{fw}}) blocks port {{port}}: other devices would load forever. Open it with this command on the machine:", + "linuxUnknown": "The {{fw}} firewall is active. DM Loremind can't read its rules without administrator rights: if you haven't already, open port {{port}} with this command on the machine:", + "copy": "Copy", + "copied": "Copied" } }, "mobileShell": { diff --git a/web/src/assets/i18n/fr.json b/web/src/assets/i18n/fr.json index f79de86..889578b 100644 --- a/web/src/assets/i18n/fr.json +++ b/web/src/assets/i18n/fr.json @@ -2458,7 +2458,13 @@ "thirdParty": "{{names}} filtre aussi les connexions sur ce PC, avec ses propres règles que DM Loremind ne peut pas vérifier. Tant qu'il ne l'autorise pas, la tablette chargera sans fin.", "thirdPartyHowTo": "Dans les réglages du pare-feu de ce logiciel : classe ton Wi-Fi en réseau domestique (pas public, sans mode furtif), puis ajoute une règle qui autorise DM Loremind en connexions entrantes.", "docLink": "Voir la marche à suivre", - "docUrl": "https://loremind-docs.igmlcreation.fr/docs/configuration/acces-tablette#la-tablette-charge-sans-fin" + "docUrl": "https://loremind-docs.igmlcreation.fr/docs/configuration/acces-tablette#la-tablette-charge-sans-fin", + "linuxNone": "Aucun pare-feu ufw ou firewalld n'est actif sur cette machine : rien à ouvrir.", + "linuxOpen": "Le pare-feu ({{fw}}) laisse passer le port {{port}}.", + "linuxClosed": "Le pare-feu ({{fw}}) bloque le port {{port}} : les autres appareils chargeraient sans fin. Ouvre-le avec cette commande sur la machine :", + "linuxUnknown": "Le pare-feu {{fw}} est actif. DM Loremind ne peut pas lire ses règles sans droits administrateur : si ce n'est pas déjà fait, ouvre le port {{port}} avec cette commande sur la machine :", + "copy": "Copier", + "copied": "Copié" } }, "mobileShell": { diff --git a/web/src/assets/i18n/fragments/remote-access.en.json b/web/src/assets/i18n/fragments/remote-access.en.json index a3b1a93..cd30e8f 100644 --- a/web/src/assets/i18n/fragments/remote-access.en.json +++ b/web/src/assets/i18n/fragments/remote-access.en.json @@ -69,7 +69,13 @@ "thirdParty": "{{names}} also filters connections on this PC, with its own rules that DM Loremind can't check. Until it allows it, the tablet will load forever.", "thirdPartyHowTo": "In that software's firewall settings: classify your Wi-Fi as a home network (not public, stealth mode off), then add a rule allowing incoming connections for DM Loremind.", "docLink": "See how to fix it", - "docUrl": "https://loremind-docs.igmlcreation.fr/en/docs/configuration/acces-tablette#the-tablet-loads-forever" + "docUrl": "https://loremind-docs.igmlcreation.fr/en/docs/configuration/acces-tablette#the-tablet-loads-forever", + "linuxNone": "No ufw or firewalld firewall is active on this machine: nothing to open.", + "linuxOpen": "The firewall ({{fw}}) lets port {{port}} through.", + "linuxClosed": "The firewall ({{fw}}) blocks port {{port}}: other devices would load forever. Open it with this command on the machine:", + "linuxUnknown": "The {{fw}} firewall is active. DM Loremind can't read its rules without administrator rights: if you haven't already, open port {{port}} with this command on the machine:", + "copy": "Copy", + "copied": "Copied" } } } diff --git a/web/src/assets/i18n/fragments/remote-access.fr.json b/web/src/assets/i18n/fragments/remote-access.fr.json index b0876ad..3e83f05 100644 --- a/web/src/assets/i18n/fragments/remote-access.fr.json +++ b/web/src/assets/i18n/fragments/remote-access.fr.json @@ -69,7 +69,13 @@ "thirdParty": "{{names}} filtre aussi les connexions sur ce PC, avec ses propres règles que DM Loremind ne peut pas vérifier. Tant qu'il ne l'autorise pas, la tablette chargera sans fin.", "thirdPartyHowTo": "Dans les réglages du pare-feu de ce logiciel : classe ton Wi-Fi en réseau domestique (pas public, sans mode furtif), puis ajoute une règle qui autorise DM Loremind en connexions entrantes.", "docLink": "Voir la marche à suivre", - "docUrl": "https://loremind-docs.igmlcreation.fr/docs/configuration/acces-tablette#la-tablette-charge-sans-fin" + "docUrl": "https://loremind-docs.igmlcreation.fr/docs/configuration/acces-tablette#la-tablette-charge-sans-fin", + "linuxNone": "Aucun pare-feu ufw ou firewalld n'est actif sur cette machine : rien à ouvrir.", + "linuxOpen": "Le pare-feu ({{fw}}) laisse passer le port {{port}}.", + "linuxClosed": "Le pare-feu ({{fw}}) bloque le port {{port}} : les autres appareils chargeraient sans fin. Ouvre-le avec cette commande sur la machine :", + "linuxUnknown": "Le pare-feu {{fw}} est actif. DM Loremind ne peut pas lire ses règles sans droits administrateur : si ce n'est pas déjà fait, ouvre le port {{port}} avec cette commande sur la machine :", + "copy": "Copier", + "copied": "Copié" } } }