From d801c957bd519b32af9a75a9b5da040e9bfd1265 Mon Sep 17 00:00:00 2001 From: glyph Date: Tue, 1 Feb 2022 10:06:45 +0200 Subject: [PATCH] introduce sbot status data --- peach-web/src/routes/index.rs | 8 ++--- peach-web/src/routes/status/device.rs | 11 +++--- peach-web/src/routes/status/scuttlebutt.rs | 12 ++++--- peach-web/templates/home.html.tera | 2 +- .../scuttlebutt/configure_sbot.html.tera | 36 ++++++++++++------- .../settings/scuttlebutt/menu.html.tera | 2 +- .../templates/status/scuttlebutt.html.tera | 28 +++++++-------- 7 files changed, 58 insertions(+), 41 deletions(-) diff --git a/peach-web/src/routes/index.rs b/peach-web/src/routes/index.rs index 8b40d53..54011d5 100644 --- a/peach-web/src/routes/index.rs +++ b/peach-web/src/routes/index.rs @@ -1,4 +1,4 @@ -use peach_stats::sbot; +use peach_lib::sbot::SbotStatus; use rocket::{get, request::FlashMessage, State}; use rocket_dyn_templates::{tera::Context, Template}; @@ -9,11 +9,11 @@ use crate::RocketConfig; #[get("/")] pub fn home(_auth: Authenticated, config: &State) -> Template { - // retrieve go-sbot systemd process stats - let sbot_stats = sbot::sbot_stats().ok(); + // retrieve go-sbot systemd process status + let sbot_status = SbotStatus::read().ok(); let mut context = Context::new(); - context.insert("sbot_stats", &sbot_stats); + context.insert("sbot_status", &sbot_status); context.insert("flash_name", &None::<()>); context.insert("flash_msg", &None::<()>); context.insert("title", &None::<()>); diff --git a/peach-web/src/routes/status/device.rs b/peach-web/src/routes/status/device.rs index dd3845b..ec66837 100644 --- a/peach-web/src/routes/status/device.rs +++ b/peach-web/src/routes/status/device.rs @@ -12,7 +12,7 @@ use std::{ }; use peach_lib::{ - config_manager::load_peach_config, dyndns_client, network_client, oled_client, sbot_client, + config_manager::load_peach_config, dyndns_client, network_client, oled_client, sbot::SbotStatus, }; use peach_stats::{ stats, @@ -117,10 +117,11 @@ impl StatusContext { } // test if go-sbot is running - let sbot_is_online_result = sbot_client::is_sbot_online(); - let sbot_is_online: bool = match sbot_is_online_result { - Ok(val) => val, - Err(_err) => false, + let sbot_status = SbotStatus::read(); + let sbot_is_online: bool = match sbot_status { + // return true if state is active + Ok(status) => matches!(status.state == Some("active".to_string()), true), + _ => false, }; StatusContext { diff --git a/peach-web/src/routes/status/scuttlebutt.rs b/peach-web/src/routes/status/scuttlebutt.rs index aab41fb..d4e5b51 100644 --- a/peach-web/src/routes/status/scuttlebutt.rs +++ b/peach-web/src/routes/status/scuttlebutt.rs @@ -1,4 +1,4 @@ -use peach_stats::sbot; +use peach_lib::sbot::{SbotConfig, SbotStatus}; use rocket::{get, State}; use rocket_dyn_templates::{tera::Context, Template}; @@ -9,10 +9,14 @@ use crate::RocketConfig; #[get("/scuttlebutt")] pub fn scuttlebutt_status(_auth: Authenticated, config: &State) -> Template { + // retrieve go-sbot systemd process status + let sbot_status = SbotStatus::read().ok(); + // retrieve go-sbot configuration parameters + let sbot_config = SbotConfig::read().ok(); + let mut context = Context::new(); - // retrieve go-sbot systemd process stats - let sbot_stats = sbot::sbot_stats().ok(); - context.insert("sbot_stats", &sbot_stats); + context.insert("sbot_status", &sbot_status); + context.insert("sbot_config", &sbot_config); context.insert("flash_name", &None::<()>); context.insert("flash_msg", &None::<()>); context.insert("title", &Some("Scuttlebutt Status")); diff --git a/peach-web/templates/home.html.tera b/peach-web/templates/home.html.tera index fe0e298..ecce8c2 100644 --- a/peach-web/templates/home.html.tera +++ b/peach-web/templates/home.html.tera @@ -25,7 +25,7 @@ -
+
diff --git a/peach-web/templates/settings/scuttlebutt/configure_sbot.html.tera b/peach-web/templates/settings/scuttlebutt/configure_sbot.html.tera index f72c5a6..40a597e 100644 --- a/peach-web/templates/settings/scuttlebutt/configure_sbot.html.tera +++ b/peach-web/templates/settings/scuttlebutt/configure_sbot.html.tera @@ -1,20 +1,32 @@ {%- extends "nav" -%} {%- block card %} + {# ASSIGN VARIABLES #} + {# ---------------- #} + {%- if sbot_config.hops -%} + {% set hops = sbot_config.hops -%} + {%- else -%} + {% set hops = "X" -%} + {%- endif -%} + {%- if sbot_config.lis -%} + {%- set listen_addr = sbot_config.lis | split(pat=":") -%} + {%- else -%} + {%- set listen_addr = ["", ""] -%} + {%- endif -%}
- + - + - + - + - +
@@ -22,32 +34,32 @@
- +
- +

- +

- +

- +

- +

- +

diff --git a/peach-web/templates/settings/scuttlebutt/menu.html.tera b/peach-web/templates/settings/scuttlebutt/menu.html.tera index ae72f49..346b89a 100644 --- a/peach-web/templates/settings/scuttlebutt/menu.html.tera +++ b/peach-web/templates/settings/scuttlebutt/menu.html.tera @@ -5,7 +5,7 @@
Configure Sbot - {% if sbot_stats.state == "active" %} + {% if sbot_status.state == "active" %} Stop Sbot Restart Sbot {% else %} diff --git a/peach-web/templates/status/scuttlebutt.html.tera b/peach-web/templates/status/scuttlebutt.html.tera index d99eb5e..d147bbf 100644 --- a/peach-web/templates/status/scuttlebutt.html.tera +++ b/peach-web/templates/status/scuttlebutt.html.tera @@ -2,15 +2,15 @@ {%- block card %} {# ASSIGN VARIABLES #} {# ---------------- #} - {%- if sbot_stats.memory -%} - {% set mem = sbot_stats.memory / 1024 / 1024 | round -%} + {%- if sbot_status.memory -%} + {% set mem = sbot_status.memory / 1024 / 1024 | round -%} {%- else -%} {% set mem = "X" -%} {%- endif -%}
-
+
@@ -20,25 +20,25 @@
- Hermies - + Hermies +

1.1.0-alpha

- {% if sbot_stats.state == "active" %} + {% if sbot_status.state == "active" %} -

{{ sbot_stats.uptime }}

+

{{ sbot_status.uptime }}

{# render downtime element if downtime is `Some(time)` #} {# downtime will be `None` if service is stopped and disabled #} - {%- elif sbot_stats.downtime -%} + {%- elif sbot_status.downtime -%} -

{{ sbot_stats.downtime }}

+

{{ sbot_status.downtime }}

{%- endif -%} - {% if sbot_stats.boot_state == "enabled" %} + {% if sbot_status.boot_state == "enabled" %}

Enabled

{% else %}

Disabled

@@ -80,7 +80,7 @@
- +
@@ -93,10 +93,10 @@
- +
- - + +