diff --git a/peach-stats/src/sbot.rs b/peach-stats/src/sbot.rs index b67a417..22a9579 100644 --- a/peach-stats/src/sbot.rs +++ b/peach-stats/src/sbot.rs @@ -2,19 +2,27 @@ use std::{process::Command, str}; +#[cfg(feature = "miniserde_support")] +use miniserde::{Deserialize, Serialize}; + +#[cfg(feature = "serde_support")] +use serde::{Deserialize, Serialize}; + use crate::StatsError; /// go-sbot process statistics. #[derive(Debug)] +#[cfg_attr(feature = "miniserde_support", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde_support", derive(Serialize, Deserialize))] pub struct SbotStat { /// Current process state. - state: String, + pub state: String, /// Current process memory usage in bytes. - memory: Option, + pub memory: Option, /// Uptime for the process (if state is `active`). - uptime: Option, + pub uptime: Option, /// Downtime for the process (if state is `inactive`). - downtime: Option, + pub downtime: Option, } impl SbotStat { diff --git a/peach-web/src/routes/settings/menu.rs b/peach-web/src/routes/settings/menu.rs index bb7db5d..69572cc 100644 --- a/peach-web/src/routes/settings/menu.rs +++ b/peach-web/src/routes/settings/menu.rs @@ -1,17 +1,25 @@ -use rocket::{get, request::FlashMessage}; +use rocket::{get, request::FlashMessage, State}; use rocket_dyn_templates::{tera::Context, Template}; use crate::routes::authentication::Authenticated; +use crate::RocketConfig; // HELPERS AND ROUTES FOR /settings /// View and delete currently configured admin. #[get("/settings")] -pub fn settings_menu(flash: Option, _auth: Authenticated) -> Template { +pub fn settings_menu( + _auth: Authenticated, + flash: Option, + config: &State, +) -> Template { let mut context = Context::new(); context.insert("back", &Some("/".to_string())); context.insert("title", &Some("Settings".to_string())); + // pass in mode from managed state so we can conditionally render html elements + context.insert("standalone_mode", &config.standalone_mode); + // check to see if there is a flash message to display if let Some(flash) = flash { context.insert("flash_name", &Some(flash.kind().to_string())); diff --git a/peach-web/src/routes/status/scuttlebutt.rs b/peach-web/src/routes/status/scuttlebutt.rs index 5ed3df1..aab41fb 100644 --- a/peach-web/src/routes/status/scuttlebutt.rs +++ b/peach-web/src/routes/status/scuttlebutt.rs @@ -1,16 +1,30 @@ -use rocket::get; +use peach_stats::sbot; +use rocket::{get, State}; use rocket_dyn_templates::{tera::Context, Template}; use crate::routes::authentication::Authenticated; +use crate::RocketConfig; // HELPERS AND ROUTES FOR /status/scuttlebutt #[get("/scuttlebutt")] -pub fn scuttlebutt_status(_auth: Authenticated) -> Template { +pub fn scuttlebutt_status(_auth: Authenticated, config: &State) -> Template { 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("flash_name", &None::<()>); context.insert("flash_msg", &None::<()>); context.insert("title", &Some("Scuttlebutt Status")); + // define back arrow url based on mode + if config.standalone_mode { + // return to home page + context.insert("back", &Some("/")); + } else { + // return to status menu + context.insert("back", &Some("/status")); + } + Template::render("status/scuttlebutt", &context.into_json()) } diff --git a/peach-web/static/icons/hermies.svg b/peach-web/static/icons/hermies.svg index 490f67f..b9c6fe9 100644 --- a/peach-web/static/icons/hermies.svg +++ b/peach-web/static/icons/hermies.svg @@ -1,23 +1,23 @@ - - - + xmlns:svg="http://www.w3.org/2000/svg" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:dc="http://purl.org/dc/elements/1.1/"> + inkscape:current-layer="svg4585" /> + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + id="layer5" + style="display:inline" + transform="translate(-1170,-1684.5924)"> + diff --git a/peach-web/static/icons/image-file.png b/peach-web/static/icons/image-file.png new file mode 100644 index 0000000..5f13599 Binary files /dev/null and b/peach-web/static/icons/image-file.png differ diff --git a/peach-web/static/icons/orbits.png b/peach-web/static/icons/orbits.png new file mode 100644 index 0000000..0b3e399 Binary files /dev/null and b/peach-web/static/icons/orbits.png differ diff --git a/peach-web/static/icons/ram.png b/peach-web/static/icons/ram.png new file mode 100644 index 0000000..7f601af Binary files /dev/null and b/peach-web/static/icons/ram.png differ diff --git a/peach-web/templates/settings/menu.html.tera b/peach-web/templates/settings/menu.html.tera index 8a7bdd0..4ac241e 100644 --- a/peach-web/templates/settings/menu.html.tera +++ b/peach-web/templates/settings/menu.html.tera @@ -4,7 +4,9 @@
+ {% if standalone_mode == false %} Network + {% endif %} Scuttlebutt Administration
diff --git a/peach-web/templates/status/network.html.tera b/peach-web/templates/status/network.html.tera index eaf630a..432a777 100644 --- a/peach-web/templates/status/network.html.tera +++ b/peach-web/templates/status/network.html.tera @@ -31,7 +31,7 @@
-
+
@@ -110,7 +110,7 @@
-
+
diff --git a/peach-web/templates/status/scuttlebutt.html.tera b/peach-web/templates/status/scuttlebutt.html.tera index 29181de..81f06e2 100644 --- a/peach-web/templates/status/scuttlebutt.html.tera +++ b/peach-web/templates/status/scuttlebutt.html.tera @@ -1,17 +1,98 @@ {%- extends "nav" -%} {%- block card %} + {# ASSIGN VARIABLES #} + {# ---------------- #} + {%- if sbot_stats.memory -%} + {% set mem = sbot_stats.memory / 1024 / 1024 | round -%} + {%- else -%} + {% set mem = "X" -%} + {%- endif -%}
-
-

Network key:

-

Replication hops:

-

Sbot version:

-

Process status:

-

Process uptime:

+ +
+ +
+ + + Configure + + + +
+ Hermies + +
+ + +
+ +

1.1.0-alpha

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

{{ sbot_stats.uptime }}

+ {%- else -%} + +

{{ sbot_stats.downtime }}

+ {%- endif -%} +
+
+
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ + +
+ +
+
+ +
+ + +
+ +
+
{%- endblock card -%}