]> git.ipfire.org Git - thirdparty/openwrt.git/commitdiff
unetd: cli: allow skipping pretty printing of status data
authorFelix Fietkau <nbd@nbd.name>
Wed, 30 Apr 2025 09:03:39 +0000 (11:03 +0200)
committerFelix Fietkau <nbd@nbd.name>
Wed, 30 Apr 2025 09:04:14 +0000 (11:04 +0200)
Makes it more useful for services built around the CLI API

Signed-off-by: Felix Fietkau <nbd@nbd.name>
package/network/services/unetd/files/unet.uc

index 1b7d021829d14fa27a0aad43db35c1772abb48f0..01ff05c3b16b900733fb3e38f5efc2dffc8af75b 100644 (file)
@@ -1296,18 +1296,23 @@ const Unet = {
                        for (let name, host in status.peers) {
                                let cur = [];
 
-                               data[`Host '${name}'`] = cur;
-                               push(cur, [ "State", host.connected ? "connected" : "disconnected" ]);
-                               if (!host.connected)
-                                       continue;
-
-                               if (host.endpoint)
-                                       push(cur, [ "IP address", host.endpoint ]);
-
-                               push(cur, [ "Idle time", time_format(host.idle) ]);
-                               push(cur, [ "Sent bytes", host.tx_bytes ]);
-                               push(cur, [ "Received bytes", host.rx_bytes ]);
-                               push(cur, [ "Last handshake", time_format(host.last_handshake_sec) + " ago" ]);
+                               let key = name;
+                               if (model.cb.opt_pretty_print) {
+                                       data[`Host '${name}'`] = cur;
+                                       push(cur, [ "State", host.connected ? "connected" : "disconnected" ]);
+                                       if (!host.connected)
+                                               continue;
+
+                                       if (host.endpoint)
+                                               push(cur, [ "IP address", host.endpoint ]);
+
+                                       push(cur, [ "Idle time", time_format(host.idle) ]);
+                                       push(cur, [ "Sent bytes", host.tx_bytes ]);
+                                       push(cur, [ "Received bytes", host.rx_bytes ]);
+                                       push(cur, [ "Last handshake", time_format(host.last_handshake_sec) + " ago" ]);
+                               } else {
+                                       data[name] = host;
+                               }
                        }
                        return ctx.multi_table("Status of network " + name, data);
                }