Accès tablette : vérification du pare-feu sous Linux (ufw, firewalld)
- Choix de l'accès au pare-feu selon le système (HostNetworkAccessConfig) : Windows (PowerShell, UAC), Linux, sinon pas de diagnostic. - Linux, sans droits root : ufw détecté via /etc/ufw/ufw.conf, firewalld via systemctl ; firewalld dit si le port est ouvert (firewall-cmd --query-port). Règles ufw illisibles sans root : port « inconnu », jamais de faux « prêt ». - Vérification du réseau : état du pare-feu Linux et commande exacte à lancer sur la machine (sudo ufw allow <port>/tcp, ou firewall-cmd), avec bouton « Copier ». Pas d'autorisation en un clic (serveur sans écran). - Le diagnostic reçoit le port réglé de l'accès distant. Vérifié : core clean verify (1228 tests, dont lecture de ufw.conf, interprétation de firewall-cmd et verdicts Linux), web build + 342 vitest, lint sans erreur. À redéployer : core + web (mode bureau ; aucune migration).
This commit is contained in:
@@ -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<String> 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<NetworkSnapshot.FirewallRule> 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<String> 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) ? */
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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<Network> networks, List<FirewallRule> rules,
|
||||
List<String> 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<Network> networks, List<FirewallRule> rules,
|
||||
List<String> 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) {}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 */ }
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* 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<String> 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, "");
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-5
@@ -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.
|
||||
* <p>
|
||||
* 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 {
|
||||
|
||||
+2
-2
@@ -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é »). */
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+56
@@ -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());
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -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());
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -39,7 +39,32 @@
|
||||
@if (network?.supported) {
|
||||
<div class="remote-block network-check" [class.ok]="allClear">
|
||||
<h3>{{ 'remoteAccess.network.title' | translate }}</h3>
|
||||
@if (isLinux) {
|
||||
<!-- Linux : état du pare-feu lisible sans root, sinon commande à lancer sur la machine. -->
|
||||
@if (network!.ready) {
|
||||
<p class="check-ok">
|
||||
<lucide-icon [img]="CheckCircle2" [size]="16"></lucide-icon>
|
||||
{{ (network!.linuxFirewall === 'none' ? 'remoteAccess.network.linuxNone' : 'remoteAccess.network.linuxOpen')
|
||||
| translate: { fw: network!.linuxFirewall, port: s.port } }}
|
||||
</p>
|
||||
} @else {
|
||||
<div class="check-item">
|
||||
<p class="check-problem">
|
||||
{{ (network!.portOpen === false ? 'remoteAccess.network.linuxClosed' : 'remoteAccess.network.linuxUnknown')
|
||||
| translate: { fw: network!.linuxFirewall, port: s.port } }}
|
||||
</p>
|
||||
@if (network!.fixCommand) {
|
||||
<div class="command-row">
|
||||
<code class="command">{{ network!.fixCommand }}</code>
|
||||
<button type="button" class="btn-secondary" (click)="copyFixCommand()">
|
||||
<lucide-icon [img]="Copy" [size]="14"></lucide-icon>
|
||||
{{ (copied ? 'remoteAccess.network.copied' : 'remoteAccess.network.copy') | translate }}
|
||||
</button>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
} @else if (network!.ready) {
|
||||
<p class="check-ok">
|
||||
<lucide-icon [img]="CheckCircle2" [size]="16"></lucide-icon>
|
||||
{{ (thirdPartyFirewalls.length > 0 ? 'remoteAccess.network.windowsReady' : 'remoteAccess.network.ready') | translate }}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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<void> {
|
||||
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. */
|
||||
|
||||
@@ -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": {
|
||||
|
||||
@@ -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": {
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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é"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user