diff --git a/compliance-agent/src/api/handlers/devices.rs b/compliance-agent/src/api/handlers/devices.rs index 857b655..04cd78d 100644 --- a/compliance-agent/src/api/handlers/devices.rs +++ b/compliance-agent/src/api/handlers/devices.rs @@ -10,12 +10,12 @@ use axum::extract::{Extension, Path, Query}; use axum::http::StatusCode; use axum::Json; use mongodb::bson::doc; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; use super::dto::{tenant_db, AgentExt, ApiResponse, ApiResult}; use crate::pipeline::csaf_match::{AdvisoryIndex, Wanted}; use compliance_core::csaf_ingest::Advisory; -use compliance_core::device_check::{DeviceCheck, DeviceName}; +use compliance_core::device_check::{DeviceCheck, DeviceLookup}; use compliance_core::models::plc_device::normalised_order_number; use compliance_core::models::PlcDevice; use compliance_core::tenant_ctx::TenantCtx; @@ -107,20 +107,6 @@ pub struct LookupParams { pub order_number: String, } -/// What Siemens' advisories know of an order number. -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] -pub struct DeviceLookup { - /// The order number, normalised (`6ES7511-1AK02-0AB0`). - pub order_number: String, - /// Whether it has a Siemens order number's shape. - pub valid: bool, - /// What Siemens calls it, from the newest advisory naming it. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub product: Option, - /// How many advisories name it. - pub advisories: usize, -} - /// What Siemens' advisories know of an order number, to recognise it while /// it is typed. Public data only: nothing of the tenant is read. #[utoipa::path( diff --git a/compliance-core/src/device_check.rs b/compliance-core/src/device_check.rs index 0c6a33a..f08f1b9 100644 --- a/compliance-core/src/device_check.rs +++ b/compliance-core/src/device_check.rs @@ -77,6 +77,21 @@ pub struct DeviceAdvisory { pub fixed_from: Option, } +/// What Siemens' advisories know of an order number, to recognise it while +/// it is typed. +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct DeviceLookup { + /// The order number, normalised (`6ES7511-1AK02-0AB0`). + pub order_number: String, + /// Whether it has a Siemens order number's shape. + pub valid: bool, + /// What Siemens calls it, from the newest advisory naming it. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub product: Option, + /// How many advisories name it. + pub advisories: usize, +} + /// A device's state in the advisories. #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "snake_case")] diff --git a/compliance-dashboard/assets/main.css b/compliance-dashboard/assets/main.css index f4d5a38..10df1fb 100644 --- a/compliance-dashboard/assets/main.css +++ b/compliance-dashboard/assets/main.css @@ -9684,3 +9684,250 @@ div.offer-option { flex-direction: column; align-items: flex-start; justify-cont } .offer-waiting-dot { width: 8px; height: 8px; border-radius: 4px; background: var(--accent); } .offer-waiting-go { margin-left: auto; font-weight: 600; color: var(--accent); } + +/* A target's Siemens controllers (SPS item 4a): modules on a DIN rail. */ +.dev-page { + display: flex; + flex-direction: column; + gap: 22px; + min-width: 0; + max-width: 1280px; +} +.dev-page > * { min-width: 0; } +.dev-rail-card { + display: flex; + flex-direction: column; + gap: 16px; + padding: 24px 24px 20px; +} +.dev-legend { + display: flex; + flex-wrap: wrap; + gap: 8px 28px; + margin: 0; + padding: 0; + list-style: none; + font-size: 14px; + color: var(--text-secondary); +} +.dev-legend li { display: flex; align-items: center; gap: 8px; } +.dev-led { + display: inline-block; + flex: none; + width: 10px; + height: 10px; + border-radius: 50%; +} +.dev-led-affected { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-bg); } +.dev-led-clear { background: var(--success); box-shadow: 0 0 0 3px var(--success-bg); } +.dev-led-unnamed { background: var(--text-faint); box-shadow: 0 0 0 3px var(--bg-elevated); } +.dev-rail-scroll { overflow-x: auto; padding-bottom: 4px; } +.dev-rail { + position: relative; + display: flex; + align-items: flex-end; + gap: 6px; + min-width: max-content; + padding: 8px 12px 18px; +} +.dev-rail-bar { + position: absolute; + left: 0; + right: 0; + bottom: 4px; + height: 26px; + border-radius: 3px; + background: repeating-linear-gradient(90deg, var(--border-bright) 0 22px, var(--border-strong) 22px 24px); + border-top: 2px solid var(--border); + border-bottom: 2px solid var(--border-strong); +} +/* The module is a device's housing: dark in either theme. */ +.dev-module { + position: relative; + z-index: 1; + display: flex; + flex-direction: column; + justify-content: space-between; + gap: 8px; + width: 148px; + height: 236px; + box-sizing: border-box; + padding: 12px; + border: none; + border-radius: 8px 8px 4px 4px; + background: linear-gradient(180deg, #2E3250 0%, #262A44 100%); + box-shadow: 0 4px 12px rgb(20 22 43 / 0.18); + color: #fff; + text-align: left; + font: inherit; + cursor: pointer; + transition: transform 160ms ease, box-shadow 160ms ease; +} +.dev-module-on { + transform: translateY(-6px); + box-shadow: 0 0 0 3px var(--accent), 0 10px 24px rgb(20 22 43 / 0.25); +} +.dev-module:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; } +.dev-module-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; } +.dev-module-brand { font-size: 11px; letter-spacing: 0.02em; color: #C9CDE0; } +.dev-module-face { + display: flex; + align-items: center; + justify-content: center; + height: 40px; + border-radius: 4px; + background: #1D2033; + color: #8C91AE; + font-size: 12px; +} +.dev-module-names { display: flex; flex-direction: column; gap: 2px; } +.dev-module-short { font-size: 13px; font-weight: 600; line-height: 1.25; overflow-wrap: anywhere; } +.dev-module-label { font-size: 12px; color: #C9CDE0; overflow-wrap: anywhere; } +.dev-module-vents { display: flex; flex-direction: column; gap: 3px; } +.dev-module-vents span { height: 3px; border-radius: 2px; background: #3A3F5C; } +.dev-module-fw { font-size: 12px; color: #C9CDE0; font-variant-numeric: tabular-nums; } +.dev-add { + position: relative; + z-index: 1; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + gap: 10px; + width: 148px; + height: 236px; + box-sizing: border-box; + padding: 12px; + border: 2px dashed var(--border-strong); + border-radius: 8px 8px 4px 4px; + background: var(--bg-card); + color: var(--text-tertiary); + font: inherit; + font-size: 14px; + font-weight: 600; + cursor: pointer; +} +.dev-add-on { border-color: var(--accent); background: var(--accent-muted); color: var(--accent); } +.dev-add:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; } +.dev-empty { margin: 0; color: var(--text-secondary); } +.dev-body { display: flex; flex-wrap: wrap; gap: 24px; align-items: flex-start; } +.dev-detail, +.dev-form { + flex: 999 1 560px; + min-width: 0; + display: flex; + flex-direction: column; + gap: 20px; + padding: 24px; +} +.dev-detail h2, +.dev-form h2 { margin: 0; font-size: 22px; font-weight: 600; } +.dev-detail-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; align-items: flex-start; } +.dev-detail-head > div:first-child { display: flex; flex-direction: column; gap: 4px; } +.dev-detail-label { font-size: 14px; color: var(--text-tertiary); } +.dev-detail-actions { display: flex; gap: 8px; } +.dev-detail-actions .btn { min-height: 44px; } +.btn-danger-ghost { color: var(--danger); border-color: var(--danger-bg); } +.dev-figures { + display: grid; + grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); + gap: 12px; + margin: 0; +} +.dev-figures > div { + display: flex; + flex-direction: column; + gap: 4px; + padding: 12px 14px; + border-radius: 10px; + background: var(--bg-primary); +} +.dev-figures dt { font-size: 13px; color: var(--text-tertiary); } +.dev-figures dd { + display: flex; + align-items: center; + gap: 8px; + margin: 0; + font-size: 16px; + font-weight: 500; + font-variant-numeric: tabular-nums; +} +.dev-firmware-edit { flex-wrap: wrap; } +.dev-firmware-edit input { width: 9em; min-height: 40px; } +.dev-field-note { margin: 0; font-size: 13px; color: var(--warning); } +.dev-state { + display: flex; + align-items: center; + gap: 12px; + padding: 14px 16px; + border-radius: 10px; + font-size: 15px; + line-height: 1.45; +} +.dev-state .dev-led { width: 12px; height: 12px; } +.dev-state-affected { background: var(--danger-bg); } +.dev-state-clear { background: var(--success-bg); } +.dev-state-unnamed { background: var(--bg-elevated); } +.dev-advisories { display: flex; flex-direction: column; gap: 10px; } +.dev-advisories h3 { margin: 0; font-size: 15px; font-weight: 600; } +.dev-advisory { + display: flex; + flex-wrap: wrap; + align-items: center; + gap: 12px 16px; + padding: 12px 14px; + border: 1px solid var(--border); + border-radius: 10px; +} +.dev-advisory-clear { opacity: 0.72; } +.dev-advisory .badge { flex: none; min-width: 72px; text-align: center; } +.dev-advisory-text { flex: 1 1 260px; min-width: 0; display: flex; flex-direction: column; gap: 2px; } +.dev-advisory-title { font-size: 14px; font-weight: 500; } +.dev-advisory-meta { font-size: 13px; color: var(--text-tertiary); } +.dev-verdict { font-size: 13px; font-weight: 500; color: var(--success); white-space: nowrap; } +.dev-verdict-affected { color: var(--danger); } +.dev-source { font-size: 13px; } +.dev-to-cves { align-self: flex-start; font-size: 14px; font-weight: 500; } +.dev-form-fields { + display: grid; + grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); + gap: 16px; +} +.dev-form-fields input { min-height: 44px; font-size: 16px; font-variant-numeric: tabular-nums; } +.dev-recognised { + display: flex; + align-items: flex-start; + gap: 10px; + padding: 12px 14px; + border-radius: 10px; + background: var(--bg-elevated); + color: var(--text-secondary); + font-size: 14px; + line-height: 1.45; +} +.dev-recognised svg { flex: none; margin-top: 2px; } +.dev-recognised-bad { background: var(--warning-bg); color: var(--warning); } +.dev-recognised-known { background: var(--success-bg); color: var(--success); } +.dev-help { font-size: 14px; color: var(--text-secondary); } +.dev-help summary { min-height: 32px; color: var(--text-primary); font-weight: 500; cursor: pointer; } +.dev-help ul { display: flex; flex-direction: column; gap: 6px; margin: 8px 0 0; padding-left: 20px; line-height: 1.45; } +.dev-form-actions { display: flex; flex-wrap: wrap; gap: 8px; } +.dev-form-actions .btn { min-height: 44px; } +.dev-how { + flex: 1 1 280px; + min-width: 0; + display: flex; + flex-direction: column; + gap: 12px; + padding-top: 4px; + font-size: 14px; + line-height: 1.5; + color: var(--text-secondary); +} +.dev-how h2 { margin: 0; font-size: 15px; font-weight: 600; color: var(--text-primary); } +.dev-how p { margin: 0; } +.dev-card-lights { display: flex; flex-wrap: wrap; gap: 10px; padding: 6px 3px; } +@media (prefers-reduced-motion: reduce) { + .dev-module { transition: none; } + .dev-module-on { transform: none; } +} diff --git a/compliance-dashboard/src/app.rs b/compliance-dashboard/src/app.rs index cc17d3c..0624b86 100644 --- a/compliance-dashboard/src/app.rs +++ b/compliance-dashboard/src/app.rs @@ -48,6 +48,10 @@ pub enum Route { // and its published versions (#1028). #[route("/targets/:id/releases")] TargetReleasesPage { id: String }, + // The Siemens controllers it runs on, against Siemens' advisories + // (SPS item 4a). + #[route("/targets/:id/devices")] + TargetDevicesPage { id: String }, // A machine (#1026): a product project and its targets; `?tab=` // `parts` (the default), `cves` or `history`. #[route("/projects/:id?:tab")] diff --git a/compliance-dashboard/src/i18n/texts.rs b/compliance-dashboard/src/i18n/texts.rs index 13c3825..b6cc38e 100644 --- a/compliance-dashboard/src/i18n/texts.rs +++ b/compliance-dashboard/src/i18n/texts.rs @@ -8868,3 +8868,282 @@ pub mod offers { text.get(lang).to_string() } } + +/// A target's Siemens controllers (SPS item 4a). +pub mod devices { + use super::Text; + use crate::i18n::Lang; + + pub const CRUMB: Text = Text { + de: "Steuerungen", + en: "Controllers", + }; + pub fn title(name: &str, lang: Lang) -> String { + match lang { + Lang::De => format!("Auf welchen Siemens-Steuerungen läuft {name}?"), + Lang::En => format!("Which Siemens controllers does {name} run on?"), + } + } + pub const INTRO: Text = Text { + de: "Mit Artikelnummer und Firmware gleicht Prüfwerk jeden Sicherheitshinweis von \ + Siemens mit Ihren Steuerungen ab, auch ohne Projektdatei.", + en: "With the order number and firmware, Prüfwerk checks every Siemens security \ + advisory against your controllers, even without a project file.", + }; + pub const LOADING: Text = Text { + de: "Steuerungen werden geladen …", + en: "Loading the controllers …", + }; + pub const LOAD_FAILED: Text = Text { + de: "Die Steuerungen lassen sich gerade nicht laden.", + en: "The controllers cannot be loaded right now.", + }; + pub const SAVE_FAILED: Text = Text { + de: "Die Steuerungen ließen sich nicht speichern.", + en: "The controllers could not be saved.", + }; + pub const ADDED: Text = Text { + de: "Steuerung hinzugefügt", + en: "Controller added", + }; + pub const REMOVED: Text = Text { + de: "Steuerung entfernt", + en: "Controller removed", + }; + pub const FIRMWARE_SAVED: Text = Text { + de: "Firmware gespeichert", + en: "Firmware saved", + }; + + // The rail. + pub const RAIL: Text = Text { + de: "Steuerungen auf der Schiene", + en: "Controllers on the rail", + }; + pub const LEGEND_AFFECTED: Text = Text { + de: "Ein Hinweis betrifft die Firmware", + en: "An advisory affects the firmware", + }; + pub const LEGEND_NOT_AFFECTED: Text = Text { + de: "Genannt, aber nicht betroffen", + en: "Named, not affected", + }; + pub const LEGEND_NOT_NAMED: Text = Text { + de: "In keinem Hinweis genannt", + en: "Named in no advisory", + }; + pub const ADD: Text = Text { + de: "Steuerung hinzufügen", + en: "Add a controller", + }; + pub const NO_LABEL: Text = Text { + de: "Ohne Bezeichnung", + en: "No name", + }; + pub const EMPTY: Text = Text { + de: "Noch keine Steuerung. Fügen Sie die erste mit Artikelnummer und Firmware hinzu.", + en: "No controller yet. Add the first with its order number and firmware.", + }; + pub const EMPTY_READ_ONLY: Text = Text { + de: "Für dieses Prüfobjekt ist keine Steuerung eingetragen.", + en: "No controller is entered for this target.", + }; + /// What a screen reader says for a module on the rail. + pub fn module( + short: &str, + firmware: &str, + affecting: usize, + named: bool, + lang: Lang, + ) -> String { + match (lang, affecting, named) { + (Lang::De, 0, true) => { + format!("{short}, Firmware {firmware}, kein Hinweis betrifft sie") + } + (Lang::De, 0, false) => { + format!("{short}, Firmware {firmware}, in keinem Hinweis genannt") + } + (Lang::De, 1, _) => format!("{short}, Firmware {firmware}, ein Hinweis betrifft sie"), + (Lang::De, n, _) => format!("{short}, Firmware {firmware}, {n} Hinweise betreffen sie"), + (Lang::En, 0, true) => format!("{short}, firmware {firmware}, no advisory affects it"), + (Lang::En, 0, false) => format!("{short}, firmware {firmware}, named in no advisory"), + (Lang::En, 1, _) => format!("{short}, firmware {firmware}, one advisory affects it"), + (Lang::En, n, _) => format!("{short}, firmware {firmware}, {n} advisories affect it"), + } + } + + // The detail. + pub const ORDER_NUMBER: Text = Text { + de: "Artikelnummer", + en: "Order number", + }; + pub const FIRMWARE: Text = Text { + de: "Firmware", + en: "Firmware", + }; + pub const CHANGE_FIRMWARE: Text = Text { + de: "Firmware ändern", + en: "Change firmware", + }; + pub const SAVE_FIRMWARE: Text = Text { + de: "Firmware speichern", + en: "Save firmware", + }; + pub const REMOVE: Text = Text { + de: "Entfernen", + en: "Remove", + }; + pub const CANCEL: Text = Text { + de: "Abbrechen", + en: "Cancel", + }; + /// The sentence under a device's figures. + pub fn state(affecting: usize, named: usize, firmware: &str, lang: Lang) -> String { + match (lang, affecting, named) { + (Lang::De, 0, 0) => "Siemens nennt diese Artikelnummer bisher in keinem Hinweis. \ + Prüfwerk prüft sie bei jedem neuen." + .to_string(), + (Lang::De, 0, 1) => { + format!("Siemens nennt diese Steuerung in einem Hinweis; er betrifft Firmware V{firmware} nicht.") + } + (Lang::De, 0, n) => { + format!("Siemens nennt diese Steuerung in {n} Hinweisen; keiner betrifft Firmware V{firmware}.") + } + (Lang::De, 1, _) => format!("Ein Siemens-Hinweis betrifft Firmware V{firmware}."), + (Lang::De, n, _) => format!("{n} Siemens-Hinweise betreffen Firmware V{firmware}."), + (Lang::En, 0, 0) => "No Siemens advisory names this order number so far. Prüfwerk \ + checks it against every new one." + .to_string(), + (Lang::En, 0, 1) => { + format!("Siemens names this controller in one advisory; it does not affect firmware V{firmware}.") + } + (Lang::En, 0, n) => { + format!("Siemens names this controller in {n} advisories; none affects firmware V{firmware}.") + } + (Lang::En, 1, _) => format!("One Siemens advisory affects firmware V{firmware}."), + (Lang::En, n, _) => format!("{n} Siemens advisories affect firmware V{firmware}."), + } + } + pub const ADVISORIES: Text = Text { + de: "Siemens-Hinweise zu dieser Steuerung", + en: "Siemens advisories for this controller", + }; + pub fn fixed_from(version: &str, lang: Lang) -> String { + match lang { + Lang::De => format!("Behoben ab V{version}"), + Lang::En => format!("Fixed from V{version}"), + } + } + pub const NO_FIX: Text = Text { + de: "Noch keine behobene Firmware, Siemens nennt Gegenmaßnahmen", + en: "No fixed firmware yet, Siemens names mitigations", + }; + pub fn affects(firmware: &str, lang: Lang) -> String { + match lang { + Lang::De => format!("betrifft V{firmware}"), + Lang::En => format!("affects V{firmware}"), + } + } + pub const NOT_AFFECTED: Text = Text { + de: "nicht betroffen", + en: "not affected", + }; + pub const SOURCE: Text = Text { + de: "Quelle", + en: "Source", + }; + pub const TO_CVES: Text = Text { + de: "Zu den Schwachstellen dieses Prüfobjekts", + en: "To this target's vulnerabilities", + }; + pub const NEXT_SCAN: Text = Text { + de: "Die Schwachstellen des Prüfobjekts zeigen eine neue oder geänderte Steuerung nach \ + der nächsten Prüfung.", + en: "The target's vulnerabilities show a new or changed controller after the next scan.", + }; + + // Adding one. + pub const LABEL: Text = Text { + de: "Bezeichnung (optional)", + en: "Name (optional)", + }; + pub const LABEL_EXAMPLE: Text = Text { + de: "Hauptsteuerung Zelle 2", + en: "Main controller cell 2", + }; + pub const BAD_ORDER_NUMBER: Text = Text { + de: "Eine Artikelnummer hat drei Teile, etwa 6ES7511-1AK02-0AB0.", + en: "An order number has three parts, such as 6ES7511-1AK02-0AB0.", + }; + pub const BAD_FIRMWARE: Text = Text { + de: "Die Firmware besteht aus Zahlen mit Punkten, etwa V3.1.4.", + en: "Firmware is numbers with dots, such as V3.1.4.", + }; + pub fn known(name: &str, lang: Lang) -> String { + match lang { + Lang::De => format!("Siemens führt diese Nummer als {name}."), + Lang::En => format!("Siemens lists this number as {name}."), + } + } + pub const UNKNOWN: Text = Text { + de: "Gültige Artikelnummer. Siemens nennt sie bisher in keinem Hinweis; Prüfwerk prüft \ + sie bei jedem neuen.", + en: "A valid order number. No Siemens advisory names it so far; Prüfwerk checks it \ + against every new one.", + }; + pub const HELP: Text = Text { + de: "Wo finde ich Artikelnummer und Firmware?", + en: "Where do I find the order number and firmware?", + }; + pub const HELP_PLATE: Text = Text { + de: "Auf dem Typenschild vorn an der CPU, beginnend mit 6ES7, 6AG1 oder 6ED1.", + en: "On the rating plate on the front of the CPU, starting with 6ES7, 6AG1 or 6ED1.", + }; + pub const HELP_TIA: Text = Text { + de: "In TIA Portal: die CPU in der Gerätekonfiguration markieren, dann Eigenschaften, \ + Allgemein, Katalog-Informationen.", + en: "In TIA Portal: select the CPU in the device configuration, then Properties, \ + General, Catalog information.", + }; + pub const HELP_WEB: Text = Text { + de: "Die Firmware zeigt auch der Webserver der CPU auf der Startseite.", + en: "The CPU's web server also shows the firmware on its start page.", + }; + + // How it works. + pub const HOW_TITLE: Text = Text { + de: "So gleicht Prüfwerk ab", + en: "How Prüfwerk checks", + }; + pub const HOW_MATCH: Text = Text { + de: "Siemens nennt in seinen Hinweisen jede betroffene CPU mit Artikelnummer und \ + Firmware-Stand. Prüfwerk liest die Hinweise täglich und vergleicht sie mit den \ + Steuerungen hier.", + en: "Siemens names every affected CPU in its advisories by order number and firmware. \ + Prüfwerk reads the advisories daily and compares them with the controllers here.", + }; + pub const HOW_FAMILIES: Text = Text { + de: "Hinweise, die nur eine ganze Baureihe nennen (etwa „S7-1200 CPU family“), gleicht \ + Prüfwerk noch nicht ab.", + en: "Advisories that name only a whole series (such as “S7-1200 CPU family”) are not \ + checked yet.", + }; + + // The target page's card. + pub const CARD_HINT: Text = Text { + de: "Siemens-Steuerungen mit Artikelnummer und Firmware eintragen", + en: "Enter Siemens controllers by order number and firmware", + }; + pub fn card_figure(devices: usize, affected: usize, lang: Lang) -> String { + match (lang, devices, affected) { + (Lang::De, 1, 0) => "1 Steuerung, kein Hinweis betrifft sie".to_string(), + (Lang::De, n, 0) => format!("{n} Steuerungen, kein Hinweis betrifft sie"), + (Lang::De, 1, _) => "1 Steuerung, betroffen".to_string(), + (Lang::De, n, a) => format!("{n} Steuerungen, {a} betroffen"), + (Lang::En, 1, 0) => "1 controller, no advisory affects it".to_string(), + (Lang::En, n, 0) => format!("{n} controllers, no advisory affects them"), + (Lang::En, 1, _) => "1 controller, affected".to_string(), + (Lang::En, n, a) => format!("{n} controllers, {a} affected"), + } + } +} diff --git a/compliance-dashboard/src/infrastructure/devices.rs b/compliance-dashboard/src/infrastructure/devices.rs new file mode 100644 index 0000000..e5a9562 --- /dev/null +++ b/compliance-dashboard/src/infrastructure/devices.rs @@ -0,0 +1,41 @@ +//! A target's Siemens controllers (SPS item 4a), read from the agent's +//! `/api/v1/targets/{id}/devices` and changed with the target. + +use compliance_core::device_check::{DeviceCheck, DeviceLookup}; +use compliance_core::models::PlcDevice; +use dioxus::prelude::*; + +/// Target `id`'s devices, each with the Siemens advisories naming it. +#[server] +pub async fn fetch_devices(id: String) -> Result, ServerFnError> { + super::agent_client::data( + super::agent_client::agent_get(&format!("/api/v1/targets/{id}/devices")).await?, + ) + .await +} + +/// What Siemens' advisories know of `order_number`, as typed. +#[server] +pub async fn lookup_device(order_number: String) -> Result { + super::agent_client::data( + super::agent_client::agent_get("/api/v1/devices/lookup") + .await? + .query(&[("order_number", order_number)]), + ) + .await +} + +/// Store `devices` as target `id`'s devices, replacing the ones it had. +#[server] +pub async fn save_devices(id: String, devices: Vec) -> Result<(), ServerFnError> { + let resp = super::agent_client::agent_request( + reqwest::Method::PATCH, + &format!("/api/v1/targets/{id}"), + ) + .await? + .json(&serde_json::json!({ "devices": devices })) + .send() + .await + .map_err(|e| ServerFnError::new(e.to_string()))?; + super::agent_client::ok_or_error(resp).await +} diff --git a/compliance-dashboard/src/infrastructure/mod.rs b/compliance-dashboard/src/infrastructure/mod.rs index 6e7bfcc..9ca3ab8 100644 --- a/compliance-dashboard/src/infrastructure/mod.rs +++ b/compliance-dashboard/src/infrastructure/mod.rs @@ -5,6 +5,7 @@ pub mod chat; pub mod cve_history; pub mod cve_matrix; pub mod dast; +pub mod devices; pub mod download; pub mod evidence; pub mod finding_breakdown; diff --git a/compliance-dashboard/src/pages/devices.rs b/compliance-dashboard/src/pages/devices.rs new file mode 100644 index 0000000..1241736 --- /dev/null +++ b/compliance-dashboard/src/pages/devices.rs @@ -0,0 +1,667 @@ +//! A target's Siemens controllers (SPS item 4a): each one a module on a DIN +//! rail whose light says whether a Siemens advisory affects its firmware, +//! the chosen one's advisories beside it, and a form that recognises an +//! order number while it is typed. + +use dioxus::prelude::*; +use dioxus_free_icons::icons::bs_icons::{BsArrowRight, BsCheckLg, BsExclamationCircle, BsPlusLg}; +use dioxus_free_icons::Icon; + +use compliance_core::device_check::{DeviceAdvisory, DeviceCheck, DeviceState}; +use compliance_core::models::{PlcDevice, PlcDeviceError}; + +use crate::app::Route; +use crate::components::copy_button::CopyButton; +use crate::components::no_access::use_can_write; +use crate::components::severity_badge::SeverityBadge; +use crate::components::toast::{ToastType, Toasts}; +use crate::i18n::texts::{devices as tx, repo_views as rv}; +use crate::i18n::{use_lang, Text}; +use crate::infrastructure::devices::{fetch_devices, lookup_device, save_devices}; +use crate::infrastructure::onboarding::fetch_target; +use crate::pages::target_views::RepoView; + +/// The CSS class of a state's light. +fn light(state: DeviceState) -> &'static str { + match state { + DeviceState::Affected => "dev-led dev-led-affected", + DeviceState::NotAffected => "dev-led dev-led-clear", + DeviceState::NotNamed => "dev-led dev-led-unnamed", + } +} + +/// How many of a device's advisories affect it. +fn affecting(check: &DeviceCheck) -> usize { + check.advisories.iter().filter(|a| a.affected).count() +} + +/// What the rail shows of a device: Siemens' short name for it (or its order +/// number) and its series (or the vendor). +fn module_names(check: &DeviceCheck) -> (String, String) { + match &check.product { + Some(p) => ( + p.short.clone(), + p.family.clone().unwrap_or_else(|| "Siemens".to_string()), + ), + None => (check.device.order_number.clone(), "Siemens".to_string()), + } +} + +/// A change to a target's devices, for the toast it ends with. +#[derive(Debug, Clone, Copy, PartialEq)] +enum Change { + Added, + Removed, + Firmware, +} + +impl Change { + fn done(self) -> Text { + match self { + Self::Added => tx::ADDED, + Self::Removed => tx::REMOVED, + Self::Firmware => tx::FIRMWARE_SAVED, + } + } +} + +/// Target `id`'s Siemens controllers. +#[component] +pub fn TargetDevicesPage(id: String) -> Element { + let lang = use_lang()(); + let can_write = use_can_write(); + let mut toasts = use_context::(); + let target_id = use_signal(|| id.clone()); + let target = use_resource(move || async move { fetch_target(target_id()).await.ok() }); + let mut checks = use_resource(move || async move { fetch_devices(target_id()).await }); + let mut selected = use_signal(|| 0_usize); + let mut adding = use_signal(|| false); + let mut saving = use_signal(|| false); + + let name = match &*target.read() { + Some(Some(t)) => t + .data + .get("name") + .and_then(|n| n.as_str()) + .unwrap_or_default() + .to_string(), + Some(None) => { + return rsx! { + div { class: "card target-missing", + p { {crate::i18n::texts::targets::NOT_FOUND.get(lang)} } + } + } + } + None => return rsx! { div { class: "loading", {tx::LOADING.get(lang)} } }, + }; + let listed: Vec = match &*checks.read() { + Some(Ok(listed)) => listed.clone(), + Some(Err(_)) => { + return rsx! { + DeviceCrumbs { id: id.clone(), name } + div { class: "card", p { {tx::LOAD_FAILED.get(lang)} } } + } + } + None => return rsx! { div { class: "loading", {tx::LOADING.get(lang)} } }, + }; + let devices: Vec = listed.iter().map(|c| c.device.clone()).collect(); + // A first device is added from the empty rail's form. + let show_form = can_write && (adding() || listed.is_empty()); + let chosen = (!show_form) + .then(|| listed.get(selected())) + .flatten() + .cloned(); + + let save = move |next: Vec, change: Change, then_select: usize| { + spawn(async move { + saving.set(true); + match save_devices(target_id(), next).await { + Ok(()) => { + toasts.push(ToastType::Success, change.done().get(lang).to_string()); + selected.set(then_select); + adding.set(false); + checks.restart(); + } + Err(e) => toasts.push( + ToastType::Error, + format!("{} {e}", tx::SAVE_FAILED.get(lang)), + ), + } + saving.set(false); + }); + }; + + rsx! { + div { class: "dev-page", + DeviceCrumbs { id: id.clone(), name: name.clone() } + header { class: "chain-head", + h1 { {tx::title(&name, lang)} } + p { {tx::INTRO.get(lang)} } + } + section { class: "card dev-rail-card", "aria-label": tx::RAIL.get(lang), + ul { class: "dev-legend", + li { span { class: light(DeviceState::Affected), "aria-hidden": "true" } {tx::LEGEND_AFFECTED.get(lang)} } + li { span { class: light(DeviceState::NotAffected), "aria-hidden": "true" } {tx::LEGEND_NOT_AFFECTED.get(lang)} } + li { span { class: light(DeviceState::NotNamed), "aria-hidden": "true" } {tx::LEGEND_NOT_NAMED.get(lang)} } + } + div { class: "dev-rail-scroll", + div { class: "dev-rail", + div { class: "dev-rail-bar", "aria-hidden": "true" } + for (i , check) in listed.iter().enumerate() { + DeviceModule { + key: "{i}-{check.device.order_number}", + check: check.clone(), + pressed: chosen.is_some() && selected() == i, + on_pick: move |_| { + selected.set(i); + adding.set(false); + }, + } + } + if can_write { + button { + r#type: "button", + class: if show_form { "dev-add dev-add-on" } else { "dev-add" }, + "aria-pressed": "{show_form}", + onclick: move |_| adding.set(true), + Icon { icon: BsPlusLg, width: 28, height: 28 } + span { {tx::ADD.get(lang)} } + } + } + } + } + if listed.is_empty() && !can_write { + p { class: "dev-empty", {tx::EMPTY_READ_ONLY.get(lang)} } + } + } + div { class: "dev-body", + if show_form { + AddDevice { + first: listed.is_empty(), + saving: saving(), + on_cancel: move |_| adding.set(false), + on_add: { + let devices = devices.clone(); + move |device: PlcDevice| { + let mut next = devices.clone(); + next.push(device); + let last = next.len() - 1; + save(next, Change::Added, last); + } + }, + } + } else if let Some(check) = chosen { + DeviceDetail { + key: "{selected()}-{check.device.order_number}-{check.device.firmware}", + target_id: id.clone(), + check, + can_write, + saving: saving(), + on_firmware: { + let devices = devices.clone(); + move |firmware: String| { + let at = selected(); + let mut next = devices.clone(); + if let Some(d) = next.get_mut(at) { + d.firmware = firmware; + } + save(next, Change::Firmware, at); + } + }, + on_remove: { + let devices = devices.clone(); + move |_| { + let at = selected(); + let mut next = devices.clone(); + if at < next.len() { + next.remove(at); + } + save(next, Change::Removed, at.saturating_sub(1)); + } + }, + } + } + aside { class: "dev-how", "aria-label": tx::HOW_TITLE.get(lang), + h2 { {tx::HOW_TITLE.get(lang)} } + p { {tx::HOW_MATCH.get(lang)} } + p { {tx::HOW_FAMILIES.get(lang)} } + p { {tx::NEXT_SCAN.get(lang)} } + } + } + } + } +} + +/// The target page's card: a light per device and the way to the page. +#[component] +pub fn DevicesCard(target_id: String) -> Element { + let lang = use_lang()(); + let id = use_signal(|| target_id.clone()); + let checks = use_resource(move || async move { fetch_devices(id()).await.ok() }); + let listed = checks.read().clone().flatten().unwrap_or_default(); + let affected = listed + .iter() + .filter(|c| c.state() == DeviceState::Affected) + .count(); + rsx! { + section { class: "card target-devices", + div { class: "target-card-head", + h3 { {tx::CRUMB.get(lang)} } + Link { to: Route::TargetDevicesPage { id: target_id.clone() }, class: "target-card-link", + Icon { icon: BsArrowRight, width: 14, height: 14 } + } + } + if listed.is_empty() { + p { class: "target-graph-note", {tx::CARD_HINT.get(lang)} } + } else { + div { class: "dev-card-lights", "aria-hidden": "true", + for check in listed.iter() { + span { class: light(check.state()) } + } + } + p { class: "target-graph-note", {tx::card_figure(listed.len(), affected, lang)} } + } + } + } +} + +/// Overview › target › Controllers. +#[component] +fn DeviceCrumbs(id: String, name: String) -> Element { + let lang = use_lang()(); + rsx! { + nav { class: "repo-crumbs", "aria-label": rv::BREADCRUMB.get(lang), + Link { to: Route::OverviewPage {}, {rv::OVERVIEW.get(lang)} } + span { class: "repo-crumb-sep", "aria-hidden": "true", "›" } + Link { class: "repo-crumb-name", to: Route::target(id.clone()), "{name}" } + span { class: "repo-crumb-sep", "aria-hidden": "true", "›" } + span { "aria-current": "page", {tx::CRUMB.get(lang)} } + } + } +} + +/// One device on the rail. +#[component] +fn DeviceModule(check: DeviceCheck, pressed: bool, on_pick: EventHandler<()>) -> Element { + let lang = use_lang()(); + let (short, family) = module_names(&check); + let label = check + .device + .label + .clone() + .unwrap_or_else(|| tx::NO_LABEL.get(lang).to_string()); + let aria = tx::module( + &short, + &check.device.firmware, + affecting(&check), + !check.advisories.is_empty(), + lang, + ); + rsx! { + button { + r#type: "button", + class: if pressed { "dev-module dev-module-on" } else { "dev-module" }, + "aria-pressed": "{pressed}", + "aria-label": "{aria}", + onclick: move |_| on_pick.call(()), + span { class: "dev-module-top", + span { class: "dev-module-brand", "SIEMENS" } + span { class: light(check.state()), "aria-hidden": "true" } + } + span { class: "dev-module-face", "aria-hidden": "true", "{family}" } + span { class: "dev-module-names", + span { class: "dev-module-short", "{short}" } + span { class: "dev-module-label", "{label}" } + } + span { class: "dev-module-vents", "aria-hidden": "true", span {} span {} span {} } + span { class: "dev-module-fw", "V{check.device.firmware}" } + } + } +} + +/// The chosen device: its figures, its state and its advisories. +#[component] +fn DeviceDetail( + target_id: String, + check: DeviceCheck, + can_write: bool, + saving: bool, + on_firmware: EventHandler, + on_remove: EventHandler<()>, +) -> Element { + let lang = use_lang()(); + let mut editing = use_signal(|| false); + let mut draft = use_signal(|| check.device.firmware.clone()); + let state = check.state(); + let device = &check.device; + let order_number = device.order_number.clone(); + let name = check.product.as_ref().map_or_else( + || format!("Siemens {}", device.order_number), + |p| p.name.clone(), + ); + let label = device + .label + .clone() + .unwrap_or_else(|| tx::NO_LABEL.get(lang).to_string()); + let sentence = tx::state( + affecting(&check), + check.advisories.len(), + &device.firmware, + lang, + ); + let firmware_error = PlcDevice::new(&device.order_number, &draft(), None).is_err(); + let tint = match state { + DeviceState::Affected => "dev-state dev-state-affected", + DeviceState::NotAffected => "dev-state dev-state-clear", + DeviceState::NotNamed => "dev-state dev-state-unnamed", + }; + + rsx! { + section { class: "card dev-detail", "aria-label": "{name}", + div { class: "dev-detail-head", + div { + h2 { "{name}" } + span { class: "dev-detail-label", "{label}" } + } + if can_write { + div { class: "dev-detail-actions", + if !editing() { + button { + r#type: "button", + class: "btn btn-ghost", + disabled: saving, + onclick: move |_| editing.set(true), + {tx::CHANGE_FIRMWARE.get(lang)} + } + } + button { + r#type: "button", + class: "btn btn-ghost btn-danger-ghost", + disabled: saving, + onclick: move |_| on_remove.call(()), + {tx::REMOVE.get(lang)} + } + } + } + } + dl { class: "dev-figures", + div { + dt { {tx::ORDER_NUMBER.get(lang)} } + dd { "{device.order_number}" CopyButton { value: device.order_number.clone(), small: true } } + } + div { + dt { {tx::FIRMWARE.get(lang)} } + if editing() { + dd { class: "dev-firmware-edit", + input { + r#type: "text", + "aria-label": tx::FIRMWARE.get(lang), + "aria-invalid": "{firmware_error}", + value: "{draft}", + autocomplete: "off", + spellcheck: "false", + oninput: move |e| draft.set(e.value()), + } + button { + r#type: "button", + class: "btn btn-primary", + disabled: firmware_error || saving, + onclick: move |_| { + if let Ok(d) = PlcDevice::new(&order_number, &draft(), None) { + on_firmware.call(d.firmware); + } + }, + {tx::SAVE_FIRMWARE.get(lang)} + } + button { + r#type: "button", + class: "btn btn-ghost", + onclick: move |_| editing.set(false), + {tx::CANCEL.get(lang)} + } + } + if firmware_error && !draft().trim().is_empty() { + p { class: "dev-field-note", role: "status", {tx::BAD_FIRMWARE.get(lang)} } + } + } else { + dd { "V{device.firmware}" } + } + } + } + div { class: tint, + span { class: light(state), "aria-hidden": "true" } + span { "{sentence}" } + } + if !check.advisories.is_empty() { + div { class: "dev-advisories", + h3 { {tx::ADVISORIES.get(lang)} } + for advisory in check.advisories.iter() { + AdvisoryRow { key: "{advisory.id}", advisory: advisory.clone(), firmware: device.firmware.clone() } + } + Link { + class: "dev-to-cves", + to: Route::target_view(target_id.clone(), RepoView::Cves), + {tx::TO_CVES.get(lang)} + } + } + } + } + } +} + +/// One advisory naming the device. +#[component] +fn AdvisoryRow(advisory: DeviceAdvisory, firmware: String) -> Element { + let lang = use_lang()(); + let fix = match &advisory.fixed_from { + Some(version) => tx::fixed_from(version, lang), + None => tx::NO_FIX.get(lang).to_string(), + }; + let verdict = if advisory.affected { + tx::affects(&firmware, lang) + } else { + tx::NOT_AFFECTED.get(lang).to_string() + }; + rsx! { + div { class: if advisory.affected { "dev-advisory" } else { "dev-advisory dev-advisory-clear" }, + SeverityBadge { severity: advisory.severity.clone().unwrap_or_default() } + div { class: "dev-advisory-text", + span { class: "dev-advisory-title", "{advisory.title}" } + span { class: "dev-advisory-meta", "{advisory.id}. {fix}" } + } + span { class: if advisory.affected { "dev-verdict dev-verdict-affected" } else { "dev-verdict" }, "{verdict}" } + // Every row is Siemens' (the agent reads no other provider for a + // device), whose terms ask each use to link the advisory. + if let Some(url) = &advisory.url { + a { class: "dev-source", href: "{url}", target: "_blank", rel: "noopener noreferrer", {tx::SOURCE.get(lang)} } + } + } + } +} + +/// What the form says of the order number typed so far. +#[derive(Debug, Clone, PartialEq)] +enum Recognised { + /// Too short to say anything yet. + Nothing, + /// Long enough, but not an order number's shape. + BadShape, + /// The shape is right; what Siemens' advisories know is being asked. + Asking, + /// Siemens' advisories name it, by this name. + Known(String), + /// The shape is right, but no advisory names it. + Unknown, +} + +/// The shape of what has been typed: an order number, or not (yet). +fn shape(order_number: &str) -> Option { + match PlcDevice::new(order_number, "0", None) { + Ok(_) => Some(true), + Err(PlcDeviceError::OrderNumber(n)) if n.len() >= 6 => Some(false), + Err(_) => None, + } +} + +/// The form for a new device. +#[component] +fn AddDevice( + /// The target has no device yet: nothing to go back to. + first: bool, + saving: bool, + on_cancel: EventHandler<()>, + on_add: EventHandler, +) -> Element { + let lang = use_lang()(); + let mut order_number = use_signal(String::new); + let mut firmware = use_signal(String::new); + let mut label = use_signal(String::new); + // Asked only once the typed number has an order number's shape. + let known = use_resource(move || async move { + let typed = order_number(); + if shape(&typed) != Some(true) { + return None; + } + lookup_device(typed).await.ok() + }); + let recognised = match shape(&order_number()) { + None => Recognised::Nothing, + Some(false) => Recognised::BadShape, + Some(true) => match &*known.read() { + Some(Some(found)) => match &found.product { + Some(p) => Recognised::Known(p.name.clone()), + None => Recognised::Unknown, + }, + // Not answered, or the index cannot be read: the number is valid + // either way and can be added. + _ => Recognised::Asking, + }, + }; + let device = PlcDevice::new(&order_number(), &firmware(), Some(&label())); + let firmware_bad = + !firmware().trim().is_empty() && matches!(device, Err(PlcDeviceError::Firmware(_))); + + rsx! { + section { class: "card dev-form", "aria-label": tx::ADD.get(lang), + h2 { {tx::ADD.get(lang)} } + div { class: "dev-form-fields", + div { class: "form-group", + label { r#for: "dev-on", {tx::ORDER_NUMBER.get(lang)} } + input { + id: "dev-on", + r#type: "text", + value: "{order_number}", + placeholder: "6ES7511-1AK02-0AB0", + autocomplete: "off", + spellcheck: "false", + oninput: move |e| order_number.set(e.value()), + } + } + div { class: "form-group", + label { r#for: "dev-fw", {tx::FIRMWARE.get(lang)} } + input { + id: "dev-fw", + r#type: "text", + value: "{firmware}", + placeholder: "V3.1.4", + autocomplete: "off", + spellcheck: "false", + "aria-invalid": "{firmware_bad}", + oninput: move |e| firmware.set(e.value()), + } + } + div { class: "form-group", + label { r#for: "dev-label", {tx::LABEL.get(lang)} } + input { + id: "dev-label", + r#type: "text", + value: "{label}", + placeholder: tx::LABEL_EXAMPLE.get(lang), + autocomplete: "off", + oninput: move |e| label.set(e.value()), + } + } + } + match recognised { + Recognised::Nothing | Recognised::Asking => rsx! {}, + Recognised::BadShape => rsx! { + div { class: "dev-recognised dev-recognised-bad", role: "status", + Icon { icon: BsExclamationCircle, width: 16, height: 16 } + span { {tx::BAD_ORDER_NUMBER.get(lang)} } + } + }, + Recognised::Known(name) => rsx! { + div { class: "dev-recognised dev-recognised-known", role: "status", + Icon { icon: BsCheckLg, width: 16, height: 16 } + span { {tx::known(&name, lang)} } + } + }, + Recognised::Unknown => rsx! { + div { class: "dev-recognised", role: "status", + Icon { icon: BsExclamationCircle, width: 16, height: 16 } + span { {tx::UNKNOWN.get(lang)} } + } + }, + } + if firmware_bad { + div { class: "dev-recognised dev-recognised-bad", role: "status", + Icon { icon: BsExclamationCircle, width: 16, height: 16 } + span { {tx::BAD_FIRMWARE.get(lang)} } + } + } + details { class: "dev-help", + summary { {tx::HELP.get(lang)} } + ul { + li { {tx::HELP_PLATE.get(lang)} } + li { {tx::HELP_TIA.get(lang)} } + li { {tx::HELP_WEB.get(lang)} } + } + } + div { class: "dev-form-actions", + button { + r#type: "button", + class: "btn btn-primary", + disabled: device.is_err() || saving, + onclick: move |_| { + if let Ok(d) = PlcDevice::new(&order_number(), &firmware(), Some(&label())) { + on_add.call(d); + } + }, + {tx::ADD.get(lang)} + } + if !first { + button { + r#type: "button", + class: "btn btn-ghost", + onclick: move |_| on_cancel.call(()), + {tx::CANCEL.get(lang)} + } + } + } + } + } +} + +#[cfg(test)] +#[allow(clippy::unwrap_used)] +mod tests { + use super::*; + + #[test] + fn the_form_speaks_once_six_characters_are_typed() { + assert_eq!(shape("6ES7"), None); + assert_eq!(shape("6ES751"), Some(false)); + assert_eq!(shape("6es7511-1ak02-0ab0"), Some(true)); + } + + #[test] + fn a_module_shows_the_name_siemens_uses_or_the_order_number() { + let device = PlcDevice::new("6ES7511-1AK02-0AB0", "3.1.4", None).unwrap(); + let unnamed = DeviceCheck::new(device, &[]); + assert_eq!( + module_names(&unnamed), + ("6ES7511-1AK02-0AB0".to_string(), "Siemens".to_string()) + ); + assert_eq!(light(unnamed.state()), "dev-led dev-led-unnamed"); + } +} diff --git a/compliance-dashboard/src/pages/mod.rs b/compliance-dashboard/src/pages/mod.rs index f97ea87..d71f004 100644 --- a/compliance-dashboard/src/pages/mod.rs +++ b/compliance-dashboard/src/pages/mod.rs @@ -5,6 +5,7 @@ pub mod dast_finding_detail; pub mod dast_findings; pub mod dast_overview; pub mod dast_targets; +pub mod devices; pub mod finding_detail; pub mod findings; pub mod graph_explorer; @@ -34,6 +35,7 @@ pub use dast_finding_detail::DastFindingDetailPage; pub use dast_findings::DastFindingsPage; pub use dast_overview::DastOverviewPage; pub use dast_targets::DastTargetsPage; +pub use devices::TargetDevicesPage; pub use finding_detail::FindingDetailPage; pub use findings::FindingsPage; pub use graph_explorer::GraphExplorerPage; diff --git a/compliance-dashboard/src/pages/target.rs b/compliance-dashboard/src/pages/target.rs index 6fb04a3..c501de7 100644 --- a/compliance-dashboard/src/pages/target.rs +++ b/compliance-dashboard/src/pages/target.rs @@ -39,6 +39,7 @@ use crate::infrastructure::platform::{use_source_only, SourceOnlyNote}; use crate::infrastructure::projects::{ fetch_projects, project_ids_of, projects_named, set_target_projects, }; +use crate::pages::devices::DevicesCard; use crate::pages::target_views::{RepoCrumbs, RepoView, TodayLink}; /// Open findings listed on the page; the rest are one click away. @@ -317,6 +318,12 @@ pub fn TargetPage(id: String) -> Element { } } } + // A control application's Siemens controllers (SPS item 4a). + if str_at(&t, "target_type") == "plc_sps" + || t.get("devices").and_then(|d| d.as_array()).is_some_and(|d| !d.is_empty()) + { + DevicesCard { target_id: id.clone() } + } if let Some(graph) = graph { section { class: "card target-graph", div { class: "target-card-head",