Răsfoiți Sursa

fix(firmware): keep the target version the operator picked (#1898) (#1904)

* fix(firmware): keep the target version the operator picked (#1898)

* docs(changelog): cover the sticky firmware target (#1898)
Nacho 4 săptămâni în urmă
părinte
comite
525ec09758
2 a modificat fișierele cu 67 adăugiri și 14 ștergeri
  1. 2 0
      CHANGELOG.md
  2. 65 14
      app/src/pages/FirmwareUpgrades.tsx

+ 2 - 0
CHANGELOG.md

@@ -9,6 +9,8 @@ y este proyecto se adhiere a [Versionado Semántico](https://semver.org/lang/es/
 
 ### Fixed
 
+- The target version chosen on a firmware card stays where it was left (#1898). The selection lived only in the local state of the page, so a refresh, leaving and coming back, or the ten second auto-refresh that runs while an upgrade is in flight put the dropdown back to whatever the server had stored, and nothing was saved unless the separate Save button was pressed. Choosing a version now saves it, a reload no longer overwrites an edit that is still local, and scheduling a recurrence saves the target shown in the dialog before saving the schedule. That last case mattered beyond the dropdown: a scheduled run flashes the target stored on the server, and a unit with none had its recurrence disabled when it fired, with "no firmware target saved" as the only explanation.
+
 - A client is tagged with the VLAN its bridge actually sees (#1757). The forwarding table was read from one bridge only and every port carrying a dot was thrown away, so a router that segments with 802.1Q subinterfaces, where the real ports are `eth0.777` and `eth0.999`, lost its wired clients altogether: no port, no VLAN and no line in the topology. Every bridge the unit has is read now, a subinterface counts as a port, and each MAC carries the VLAN the bridge learned it on, which is the only evidence of where a client lives. A forwarding table without that field leaves the client without a VLAN instead of guessing one from the default of the port.
 - A wireless client keeps the interface and the SSID that served it (#1757). The hostapd path built each station without either, so on any OpenWrt that answers over ubus every WiFi client arrived with an empty interface, and the topology, which resolves the VLAN of a station through its AP interface, had nothing to colour. The interface is taken from the object that was queried and the SSID from `iw dev`, and the VLAN of an AP interface now carries the name and the subnet of the network it serves.
 - An upgrade that swaps the binary but cannot restart says so instead of leaving the unit lying (#1900). On a host without a procd script there is nothing to ask for a restart, so the new binary stayed on disk, the old one kept running from memory, and the UI reported the unit as up to date until the next reboot. That covers the Merlin-style installs under `/jffs`, Synology and any manual or Entware deployment, which are exactly the units that ended up as external in 2.49.x. The agent now replaces its own process with the binary it just installed, keeping the PID, the arguments and the environment, which starts the new build in place and leaves the OpenWrt path untouched. If even that fails, it reports the failure with the reason while it is still alive. The availability flag now uses the same criterion as upgrade all, a live agent stream rather than the row type, so the badge and the command stop disagreeing. And a restart that never completes stops sitting at restarting: after ninety seconds the row shows a terminal failure that names the cause and lives longer than the ordinary progress state, so an operator sees it instead of an empty slot.

+ 65 - 14
app/src/pages/FirmwareUpgrades.tsx

@@ -249,7 +249,23 @@ export default function FirmwareUpgrades() {
           checksum: it.checksum,
         }
       })
-      setEdits(initialEdits)
+      // #1898: no pisar las ediciones locales al recargar. El auto-refresco
+      // de un upgrade en curso (cada 10 s) devolvía el desplegable al target
+      // del servidor mientras el usuario estaba eligiendo otra versión.
+      setEdits((prev) => {
+        const next = { ...initialEdits }
+        data.forEach((it) => {
+          const p = prev[it.routerId]
+          if (!p) return
+          next[it.routerId] = {
+            ...next[it.routerId],
+            targetVersion: p.targetVersion ?? it.targetVersion ?? it.detectedVersion ?? '',
+            targetUrl: p.targetUrl ?? it.targetUrl,
+            checksum: p.checksum ?? it.checksum,
+          }
+        })
+        return next
+      })
     } catch (e) {
       setError(String(e))
     } finally {
@@ -440,23 +456,36 @@ export default function FirmwareUpgrades() {
     }
   }
 
+  // #1898: persistir el target es también lo que hace que la selección del
+  // desplegable se quede donde el usuario la dejó. Vive aparte del botón
+  // Guardar porque el desplegable lo llama solo, sin estado "busy".
+  const postTarget = async (id: string, e: Partial<FirmwareItem>) => {
+    const res = await fetch(`/api/firmware-upgrades/${encodeURIComponent(id)}/target`, {
+      method: 'POST',
+      headers: { 'Content-Type': 'application/json' },
+      body: JSON.stringify({
+        model: e.model ?? '',
+        currentVersion: e.currentVersion ?? '',
+        targetVersion: e.targetVersion ?? '',
+        targetUrl: e.targetUrl ?? '',
+        checksum: e.checksum ?? '',
+      }),
+    })
+    if (!res.ok) {
+      const body = await res.json().catch(() => ({}))
+      throw new Error(body?.error?.message ?? body?.message ?? `HTTP ${res.status}`)
+    }
+    // Sin recarga completa: la tarjeta refleja lo guardado y el resto de
+    // ediciones locales (URL, checksum, exclusiones) no se toca.
+    setItems((prev) => prev.map((it) => (it.routerId === id ? { ...it, targetVersion: e.targetVersion ?? '' } : it)))
+  }
+
   const saveTarget = async (id: string) => {
     const e = edits[id]
     if (!e) return
     setBusy((prev) => ({ ...prev, [id]: 'save' }))
     try {
-      const res = await fetch(`/api/firmware-upgrades/${encodeURIComponent(id)}/target`, {
-        method: 'POST',
-        headers: { 'Content-Type': 'application/json' },
-        body: JSON.stringify({
-          model: e.model ?? '',
-          currentVersion: e.currentVersion ?? '',
-          targetVersion: e.targetVersion ?? '',
-          targetUrl: e.targetUrl ?? '',
-          checksum: e.checksum ?? '',
-        }),
-      })
-      if (!res.ok) throw new Error(await res.text())
+      await postTarget(id, e)
       await fetchItems()
     } catch (err) {
       setError(String(err))
@@ -465,6 +494,19 @@ export default function FirmwareUpgrades() {
     }
   }
 
+  // #1898: elegir una versión la guarda en el acto. Antes el cambio vivía solo
+  // en `edits` (estado local de la página), así que al refrescar o al salir y
+  // volver el desplegable regresaba al target que tuviera el servidor.
+  const chooseTarget = (item: FirmwareItem, value: string) => {
+    updateEdit(item.routerId, { targetVersion: value })
+    const e = { ...edits[item.routerId], targetVersion: value }
+    // Sin modelo detectado el servidor rechaza el target: la selección se
+    // queda local (y ya no la pisa la recarga) hasta que haya modelo.
+    if (!e.model) return
+    setError('')
+    postTarget(item.routerId, e).catch((err) => setError(String(err)))
+  }
+
   // #519: descartar el aviso de un intento de upgrade fallido/obsoleto.
   const dismissUpgrade = async (id: string) => {
     setBusy((prev) => ({ ...prev, [id]: 'dismiss' }))
@@ -655,6 +697,15 @@ export default function FirmwareUpgrades() {
       payload.time = recTime
     }
     try {
+      // #1898: el disparo programado flashea el target GUARDADO en el servidor
+      // (`runRecurrenceShot`), no el que este diálogo enseña. Si difieren se
+      // guarda primero: programar sin target guardado desactivaba la
+      // recurrencia al vencer con "no firmware target saved".
+      const edit = edits[id]
+      const item = items.find((x) => x.routerId === id)
+      if (edit?.model && edit.targetVersion && edit.targetVersion !== item?.targetVersion) {
+        await postTarget(id, edit)
+      }
       const res = await fetch(`/api/firmware-upgrades/${encodeURIComponent(id)}/recurrence`, {
         method: 'PUT',
         headers: { 'Content-Type': 'application/json' },
@@ -1034,7 +1085,7 @@ export default function FirmwareUpgrades() {
                   <span className="text-caption text-text-muted">{t('firmwareUpgrades.targetVersion')} *</span>
                   <select
                     value={effTarget}
-                    onChange={(ev) => updateEdit(item.routerId, { targetVersion: ev.target.value })}
+                    onChange={(ev) => chooseTarget(item, ev.target.value)}
                     disabled={!isAdmin || active || versionsBusy[item.routerId]}
                     className="h-[38px] rounded-lg border border-border bg-canvas px-3 text-sm text-text-primary disabled:opacity-60"
                   >