From 435e81964804c116852f34a30a5101b718614f44 Mon Sep 17 00:00:00 2001 From: glyph Date: Thu, 3 Feb 2022 16:27:20 +0200 Subject: [PATCH 1/5] add blobstore size lookup for sbot status --- peach-lib/src/sbot.rs | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/peach-lib/src/sbot.rs b/peach-lib/src/sbot.rs index d08e6db..a9fbc31 100644 --- a/peach-lib/src/sbot.rs +++ b/peach-lib/src/sbot.rs @@ -1,11 +1,31 @@ //! Data types and associated methods for monitoring and configuring go-sbot. -use std::{fs, fs::File, io::Write, process::Command, str}; +use std::{fs, fs::File, io, io::Write, path::PathBuf, process::Command, str}; use serde::{Deserialize, Serialize}; use crate::error::PeachError; +/* HELPER FUNCTIONS */ + +// iterate over the given directory path to determine the size of the directory +fn dir_size(path: impl Into) -> io::Result { + fn dir_size(mut dir: fs::ReadDir) -> io::Result { + dir.try_fold(0, |acc, file| { + let file = file?; + let size = match file.metadata()? { + data if data.is_dir() => dir_size(fs::read_dir(file.path())?)?, + data => data.len(), + }; + Ok(acc + size) + }) + } + + dir_size(fs::read_dir(path.into())?) +} + +/* SBOT-RELATED TYPES AND METHODS */ + /// go-sbot process status. #[derive(Debug, Serialize, Deserialize)] pub struct SbotStatus { @@ -19,6 +39,8 @@ pub struct SbotStatus { pub uptime: Option, /// Downtime for the process (if state is `inactive`). pub downtime: Option, + /// Size of the blobs directory in bytes. + pub blobstore: Option, } /// Default builder for `SbotStatus`. @@ -30,6 +52,7 @@ impl Default for SbotStatus { memory: None, uptime: None, downtime: None, + blobstore: None, } } } @@ -101,6 +124,15 @@ impl SbotStatus { } } + // determine path of user's home directory + let mut blobstore_path = dirs::home_dir().ok_or(PeachError::HomeDir)?; + + // append the blobstore path + blobstore_path.push(".ssb-go/blobs/sha256"); + + // determine the size of the blobstore directory in bytes + status.blobstore = dir_size(blobstore_path).ok(); + Ok(status) } } From 0737c435a8d102ba52fa18e7f2b2faae29a0b649 Mon Sep 17 00:00:00 2001 From: glyph Date: Thu, 3 Feb 2022 16:29:20 +0200 Subject: [PATCH 2/5] add theme setter and getter, update route handlers --- peach-web/Cargo.toml | 1 + peach-web/src/main.rs | 9 ++- peach-web/src/router.rs | 3 +- peach-web/src/routes/authentication.rs | 18 ++++- peach-web/src/routes/index.rs | 9 +++ peach-web/src/routes/scuttlebutt.rs | 74 ++++++++++++++++++-- peach-web/src/routes/settings/admin.rs | 13 ++++ peach-web/src/routes/settings/dns.rs | 6 +- peach-web/src/routes/settings/menu.rs | 5 ++ peach-web/src/routes/settings/mod.rs | 1 + peach-web/src/routes/settings/scuttlebutt.rs | 19 +++-- peach-web/src/routes/settings/theme.rs | 16 +++++ peach-web/src/routes/status/scuttlebutt.rs | 6 ++ peach-web/src/utils.rs | 28 +++++++- peach-web/templates/base.html.tera | 2 +- 15 files changed, 193 insertions(+), 17 deletions(-) create mode 100644 peach-web/src/routes/settings/theme.rs diff --git a/peach-web/Cargo.toml b/peach-web/Cargo.toml index 90e0295..ddd4b0d 100644 --- a/peach-web/Cargo.toml +++ b/peach-web/Cargo.toml @@ -36,6 +36,7 @@ maintenance = { status = "actively-developed" } [dependencies] env_logger = "0.8" +lazy_static = "1.4.0" log = "0.4" nest = "1.0.0" peach-lib = { path = "../peach-lib" } diff --git a/peach-web/src/main.rs b/peach-web/src/main.rs index 238e561..14a0a03 100644 --- a/peach-web/src/main.rs +++ b/peach-web/src/main.rs @@ -32,11 +32,14 @@ pub mod routes; mod tests; pub mod utils; -use std::process; +use std::{process, sync::RwLock}; +use lazy_static::lazy_static; use log::{debug, error, info}; use rocket::{fairing::AdHoc, serde::Deserialize, Build, Rocket}; +use utils::Theme; + pub type BoxError = Box; /// Application configuration parameters. @@ -51,6 +54,10 @@ pub struct RocketConfig { standalone_mode: bool, } +lazy_static! { + static ref THEME: RwLock = RwLock::new(Theme::Light); +} + static WLAN_IFACE: &str = "wlan0"; static AP_IFACE: &str = "ap0"; diff --git a/peach-web/src/router.rs b/peach-web/src/router.rs index d8cf8cb..be05163 100644 --- a/peach-web/src/router.rs +++ b/peach-web/src/router.rs @@ -6,7 +6,7 @@ use crate::routes::{ catchers::*, index::*, scuttlebutt::*, - settings::{admin::*, dns::*, menu::*, network::*, scuttlebutt::*}, + settings::{admin::*, dns::*, menu::*, network::*, scuttlebutt::*, theme::*}, status::{device::*, network::*, scuttlebutt::*}, }; @@ -28,6 +28,7 @@ pub fn mount_peachpub_routes(rocket: Rocket) -> Rocket { shutdown_cmd, power_menu, settings_menu, + set_theme, ], ) .mount( diff --git a/peach-web/src/routes/authentication.rs b/peach-web/src/routes/authentication.rs index e3e51a3..04df16c 100644 --- a/peach-web/src/routes/authentication.rs +++ b/peach-web/src/routes/authentication.rs @@ -13,8 +13,8 @@ use rocket_dyn_templates::{tera::Context, Template}; use peach_lib::{error::PeachError, password_utils}; use crate::error::PeachWebError; +use crate::utils; use crate::utils::TemplateOrRedirect; -//use crate::DisableAuth; use crate::RocketConfig; // HELPERS AND STRUCTS FOR AUTHENTICATION WITH COOKIES @@ -72,7 +72,11 @@ impl<'r> FromRequest<'r> for Authenticated { #[get("/login")] pub fn login(flash: Option) -> Template { + // retrieve current ui theme + let theme = utils::get_theme(); + let mut context = Context::new(); + context.insert("theme", &theme); context.insert("back", &Some("/".to_string())); context.insert("title", &Some("Login".to_string())); @@ -166,7 +170,11 @@ pub fn save_reset_password_form(password_form: ResetPasswordForm) -> Result<(), /// and is specifically for users who have forgotten their password. #[get("/reset_password")] pub fn reset_password(flash: Option) -> Template { + // retrieve current ui theme + let theme = utils::get_theme(); + let mut context = Context::new(); + context.insert("theme", &theme); context.insert("back", &Some("/".to_string())); context.insert("title", &Some("Reset Password".to_string())); @@ -211,7 +219,11 @@ pub fn reset_password_post(reset_password_form: Form) -> Temp /// to initiate the sending of a new password reset. #[get("/forgot_password")] pub fn forgot_password_page(flash: Option) -> Template { + // retrieve current ui theme + let theme = utils::get_theme(); + let mut context = Context::new(); + context.insert("theme", &theme); context.insert("back", &Some("/".to_string())); context.insert("title", &Some("Send Password Reset".to_string())); @@ -281,7 +293,11 @@ pub fn save_password_form(password_form: PasswordForm) -> Result<(), PeachWebErr /// Change password request handler. This is used by a user who is already logged in. #[get("/change_password")] pub fn change_password(flash: Option, _auth: Authenticated) -> Template { + // retrieve current ui theme + let theme = utils::get_theme(); + let mut context = Context::new(); + context.insert("theme", &theme); context.insert("back", &Some("/settings/admin".to_string())); context.insert("title", &Some("Change Password".to_string())); diff --git a/peach-web/src/routes/index.rs b/peach-web/src/routes/index.rs index 54011d5..e796c03 100644 --- a/peach-web/src/routes/index.rs +++ b/peach-web/src/routes/index.rs @@ -3,16 +3,21 @@ use rocket::{get, request::FlashMessage, State}; use rocket_dyn_templates::{tera::Context, Template}; use crate::routes::authentication::Authenticated; +use crate::utils; use crate::RocketConfig; // HELPERS AND ROUTES FOR / (HOME PAGE) #[get("/")] pub fn home(_auth: Authenticated, config: &State) -> Template { + // retrieve current ui theme + let theme = utils::get_theme(); + // retrieve go-sbot systemd process status let sbot_status = SbotStatus::read().ok(); let mut context = Context::new(); + context.insert("theme", &theme); context.insert("sbot_status", &sbot_status); context.insert("flash_name", &None::<()>); context.insert("flash_msg", &None::<()>); @@ -28,7 +33,11 @@ pub fn home(_auth: Authenticated, config: &State) -> Template { #[get("/help")] pub fn help(flash: Option) -> Template { + // retrieve current ui theme + let theme = utils::get_theme(); + let mut context = Context::new(); + context.insert("theme", &theme); context.insert("back", &Some("/".to_string())); context.insert("title", &Some("Help".to_string())); diff --git a/peach-web/src/routes/scuttlebutt.rs b/peach-web/src/routes/scuttlebutt.rs index 178a0ec..0d884a7 100644 --- a/peach-web/src/routes/scuttlebutt.rs +++ b/peach-web/src/routes/scuttlebutt.rs @@ -11,6 +11,7 @@ use rocket::{ use rocket_dyn_templates::Template; use crate::routes::authentication::Authenticated; +use crate::utils; // HELPERS AND ROUTES FOR /private @@ -20,6 +21,7 @@ pub struct PrivateContext { pub flash_name: Option, pub flash_msg: Option, pub title: Option, + pub theme: Option, } impl PrivateContext { @@ -29,6 +31,7 @@ impl PrivateContext { flash_name: None, flash_msg: None, title: None, + theme: None, } } } @@ -36,15 +39,21 @@ impl PrivateContext { /// A private message composition and publication page. #[get("/private")] pub fn private(flash: Option, _auth: Authenticated) -> Template { + // retrieve current ui theme + let theme = utils::get_theme(); + let mut context = PrivateContext::build(); context.back = Some("/".to_string()); context.title = Some("Private Messages".to_string()); + context.theme = Some(theme); + // check to see if there is a flash message to display if let Some(flash) = flash { // add flash message contents to the context object context.flash_name = Some(flash.kind().to_string()); context.flash_msg = Some(flash.message().to_string()); }; + Template::render("scuttlebutt/messages", &context) } @@ -56,6 +65,7 @@ pub struct PeerContext { pub flash_name: Option, pub flash_msg: Option, pub title: Option, + pub theme: Option, } impl PeerContext { @@ -65,6 +75,7 @@ impl PeerContext { flash_name: None, flash_msg: None, title: None, + theme: None, } } } @@ -72,15 +83,21 @@ impl PeerContext { /// A peer menu which allows navigating to lists of friends, follows, followers and blocks. #[get("/peers")] pub fn peers(flash: Option, _auth: Authenticated) -> Template { + // retrieve current ui theme + let theme = utils::get_theme(); + let mut context = PeerContext::build(); context.back = Some("/".to_string()); context.title = Some("Scuttlebutt Peers".to_string()); + context.theme = Some(theme); + // check to see if there is a flash message to display if let Some(flash) = flash { // add flash message contents to the context object context.flash_name = Some(flash.kind().to_string()); context.flash_msg = Some(flash.message().to_string()); }; + Template::render("scuttlebutt/peers", &context) } @@ -91,7 +108,10 @@ pub struct Post { pub text: String, } -/// Publish a public Scuttlebutt post. Redirects to profile page of the PeachCloud local identity with a flash message describing the outcome of the action (may be successful or unsuccessful). +/// Publish a public Scuttlebutt post. +/// Redirects to profile page of the PeachCloud local identity with a flash +/// message describing the outcome of the action (may be successful or +/// unsuccessful). #[post("/publish", data = "")] pub fn publish(post: Form, _auth: Authenticated) -> Flash { let post_text = &post.text; @@ -101,6 +121,7 @@ pub fn publish(post: Form, _auth: Authenticated) -> Flash { // redirect to the profile template without public key ("home" / local profile) let pub_key: std::option::Option<&str> = None; let profile_url = uri!(profile(pub_key)); + // consider adding the message reference to the flash message (or render it in the template for // `profile` Flash::success(Redirect::to(profile_url), "Published public post") @@ -113,7 +134,9 @@ pub struct PublicKey { pub key: String, } -/// Follow a Scuttlebutt profile specified by the given public key. Redirects to the appropriate profile page with a flash message describing the outcome of the action (may be successful or unsuccessful). +/// Follow a Scuttlebutt profile specified by the given public key. +/// Redirects to the appropriate profile page with a flash message describing +/// the outcome of the action (may be successful or unsuccessful). #[post("/follow", data = "")] pub fn follow(pub_key: Form, _auth: Authenticated) -> Flash { let public_key = &pub_key.key; @@ -123,12 +146,15 @@ pub fn follow(pub_key: Form, _auth: Authenticated) -> Flash // redirect to the profile template with provided public key let profile_url = uri!(profile(Some(public_key))); let success_msg = format!("Followed {}", public_key); + Flash::success(Redirect::to(profile_url), success_msg) } // HELPERS AND ROUTES FOR /unfollow -/// Unfollow a Scuttlebutt profile specified by the given public key. Redirects to the appropriate profile page with a flash message describing the outcome of the action (may be successful or unsuccessful). +/// Unfollow a Scuttlebutt profile specified by the given public key. +/// Redirects to the appropriate profile page with a flash message describing +/// the outcome of the action (may be successful or unsuccessful). #[post("/unfollow", data = "")] pub fn unfollow(pub_key: Form, _auth: Authenticated) -> Flash { let public_key = &pub_key.key; @@ -138,12 +164,15 @@ pub fn unfollow(pub_key: Form, _auth: Authenticated) -> Flash, _auth: Authenticated) -> Flash { let public_key = &pub_key.key; @@ -153,6 +182,7 @@ pub fn block(pub_key: Form, _auth: Authenticated) -> Flash // redirect to the profile template with provided public key let profile_url = uri!(profile(Some(public_key))); let success_msg = format!("Blocked {}", public_key); + Flash::success(Redirect::to(profile_url), success_msg) } @@ -164,6 +194,7 @@ pub struct ProfileContext { pub flash_name: Option, pub flash_msg: Option, pub title: Option, + pub theme: Option, } impl ProfileContext { @@ -173,6 +204,7 @@ impl ProfileContext { flash_name: None, flash_msg: None, title: None, + theme: None, } } } @@ -184,15 +216,21 @@ pub fn profile( flash: Option, _auth: Authenticated, ) -> Template { + // retrieve current ui theme + let theme = utils::get_theme(); + let mut context = ProfileContext::build(); context.back = Some("/".to_string()); context.title = Some("Profile".to_string()); + context.theme = Some(theme); + // check to see if there is a flash message to display if let Some(flash) = flash { // add flash message contents to the context object context.flash_name = Some(flash.kind().to_string()); context.flash_msg = Some(flash.message().to_string()); }; + Template::render("scuttlebutt/profile", &context) } @@ -204,6 +242,7 @@ pub struct FriendsContext { pub flash_name: Option, pub flash_msg: Option, pub title: Option, + pub theme: Option, } impl FriendsContext { @@ -213,6 +252,7 @@ impl FriendsContext { flash_name: None, flash_msg: None, title: None, + theme: None, } } } @@ -221,9 +261,13 @@ impl FriendsContext { /// key of the peer. #[get("/friends")] pub fn friends(flash: Option, _auth: Authenticated) -> Template { + // retrieve current ui theme + let theme = utils::get_theme(); + let mut context = FriendsContext::build(); context.back = Some("/scuttlebutt/peers".to_string()); context.title = Some("Friends".to_string()); + context.theme = Some(theme); // check to see if there is a flash message to display if let Some(flash) = flash { @@ -231,6 +275,7 @@ pub fn friends(flash: Option, _auth: Authenticated) -> Template { context.flash_name = Some(flash.kind().to_string()); context.flash_msg = Some(flash.message().to_string()); }; + Template::render("scuttlebutt/peers_list", &context) } @@ -242,6 +287,7 @@ pub struct FollowsContext { pub flash_name: Option, pub flash_msg: Option, pub title: Option, + pub theme: Option, } impl FollowsContext { @@ -251,6 +297,7 @@ impl FollowsContext { flash_name: None, flash_msg: None, title: None, + theme: None, } } } @@ -259,9 +306,13 @@ impl FollowsContext { /// key of the peer. #[get("/follows")] pub fn follows(flash: Option, _auth: Authenticated) -> Template { + // retrieve current ui theme + let theme = utils::get_theme(); + let mut context = FollowsContext::build(); context.back = Some("/scuttlebutt/peers".to_string()); context.title = Some("Follows".to_string()); + context.theme = Some(theme); // check to see if there is a flash message to display if let Some(flash) = flash { @@ -269,6 +320,7 @@ pub fn follows(flash: Option, _auth: Authenticated) -> Template { context.flash_name = Some(flash.kind().to_string()); context.flash_msg = Some(flash.message().to_string()); }; + Template::render("scuttlebutt/peers_list", &context) } @@ -280,6 +332,7 @@ pub struct FollowersContext { pub flash_name: Option, pub flash_msg: Option, pub title: Option, + pub theme: Option, } impl FollowersContext { @@ -289,6 +342,7 @@ impl FollowersContext { flash_name: None, flash_msg: None, title: None, + theme: None, } } } @@ -297,9 +351,13 @@ impl FollowersContext { /// key of the peer. #[get("/followers")] pub fn followers(flash: Option, _auth: Authenticated) -> Template { + // retrieve current ui theme + let theme = utils::get_theme(); + let mut context = FollowersContext::build(); context.back = Some("/scuttlebutt/peers".to_string()); context.title = Some("Followers".to_string()); + context.theme = Some(theme); // check to see if there is a flash message to display if let Some(flash) = flash { @@ -307,6 +365,7 @@ pub fn followers(flash: Option, _auth: Authenticated) -> Template context.flash_name = Some(flash.kind().to_string()); context.flash_msg = Some(flash.message().to_string()); }; + Template::render("scuttlebutt/peers_list", &context) } @@ -318,6 +377,7 @@ pub struct BlocksContext { pub flash_name: Option, pub flash_msg: Option, pub title: Option, + pub theme: Option, } impl BlocksContext { @@ -327,6 +387,7 @@ impl BlocksContext { flash_name: None, flash_msg: None, title: None, + theme: None, } } } @@ -335,9 +396,13 @@ impl BlocksContext { /// key of the peer. #[get("/blocks")] pub fn blocks(flash: Option, _auth: Authenticated) -> Template { + // retrieve current ui theme + let theme = utils::get_theme(); + let mut context = BlocksContext::build(); context.back = Some("/scuttlebutt/peers".to_string()); context.title = Some("Blocks".to_string()); + context.theme = Some(theme); // check to see if there is a flash message to display if let Some(flash) = flash { @@ -345,5 +410,6 @@ pub fn blocks(flash: Option, _auth: Authenticated) -> Template { context.flash_name = Some(flash.kind().to_string()); context.flash_msg = Some(flash.message().to_string()); }; + Template::render("scuttlebutt/peers_list", &context) } diff --git a/peach-web/src/routes/settings/admin.rs b/peach-web/src/routes/settings/admin.rs index 72ac264..c2312a3 100644 --- a/peach-web/src/routes/settings/admin.rs +++ b/peach-web/src/routes/settings/admin.rs @@ -12,13 +12,18 @@ use peach_lib::config_manager; use crate::error::PeachWebError; use crate::routes::authentication::Authenticated; +use crate::utils; // HELPERS AND ROUTES FOR /settings/admin /// Administrator settings menu. #[get("/")] pub fn admin_menu(flash: Option, _auth: Authenticated) -> Template { + // retrieve current ui theme + let theme = utils::get_theme(); + let mut context = Context::new(); + context.insert("theme", &theme); context.insert("back", &Some("/settings".to_string())); context.insert("title", &Some("Administrator Settings".to_string())); @@ -36,7 +41,11 @@ pub fn admin_menu(flash: Option, _auth: Authenticated) -> Template /// View and delete currently configured admin. #[get("/configure")] pub fn configure_admin(flash: Option, _auth: Authenticated) -> Template { + // retrieve current ui theme + let theme = utils::get_theme(); + let mut context = Context::new(); + context.insert("theme", &theme); context.insert("back", &Some("/settings/admin".to_string())); context.insert("title", &Some("Configure Admin".to_string())); @@ -81,7 +90,11 @@ pub fn save_add_admin_form(admin_form: AddAdminForm) -> Result<(), PeachWebError #[get("/add")] pub fn add_admin(flash: Option, _auth: Authenticated) -> Template { + // retrieve current ui theme + let theme = utils::get_theme(); + let mut context = Context::new(); + context.insert("theme", &theme); context.insert("back", &Some("/settings/admin/configure".to_string())); context.insert("title", &Some("Add Admin".to_string())); diff --git a/peach-web/src/routes/settings/dns.rs b/peach-web/src/routes/settings/dns.rs index 1694ec3..4d50672 100644 --- a/peach-web/src/routes/settings/dns.rs +++ b/peach-web/src/routes/settings/dns.rs @@ -16,6 +16,7 @@ use peach_lib::{ use crate::{ context::dns::ConfigureDNSContext, error::PeachWebError, routes::authentication::Authenticated, + utils, }; #[derive(Debug, Deserialize, FromForm)] @@ -76,11 +77,14 @@ pub fn save_dns_configuration(dns_form: DnsForm) -> Result<(), PeachWebError> { #[get("/dns")] pub fn configure_dns(flash: Option, _auth: Authenticated) -> Template { - let mut context = ConfigureDNSContext::build(); + // retrieve current ui theme + let theme = utils::get_theme(); + let mut context = ConfigureDNSContext::build(); // set back icon link to network route context.back = Some("/settings/network".to_string()); context.title = Some("Configure DNS".to_string()); + context.theme = Some(theme); // check to see if there is a flash message to display if let Some(flash) = flash { diff --git a/peach-web/src/routes/settings/menu.rs b/peach-web/src/routes/settings/menu.rs index 69572cc..b93c645 100644 --- a/peach-web/src/routes/settings/menu.rs +++ b/peach-web/src/routes/settings/menu.rs @@ -2,6 +2,7 @@ use rocket::{get, request::FlashMessage, State}; use rocket_dyn_templates::{tera::Context, Template}; use crate::routes::authentication::Authenticated; +use crate::utils; use crate::RocketConfig; // HELPERS AND ROUTES FOR /settings @@ -13,7 +14,11 @@ pub fn settings_menu( flash: Option, config: &State, ) -> Template { + // retrieve current ui theme + let theme = utils::get_theme(); + let mut context = Context::new(); + context.insert("theme", &theme); context.insert("back", &Some("/".to_string())); context.insert("title", &Some("Settings".to_string())); diff --git a/peach-web/src/routes/settings/mod.rs b/peach-web/src/routes/settings/mod.rs index 1096c8d..0356538 100644 --- a/peach-web/src/routes/settings/mod.rs +++ b/peach-web/src/routes/settings/mod.rs @@ -3,3 +3,4 @@ pub mod dns; pub mod menu; pub mod network; pub mod scuttlebutt; +pub mod theme; diff --git a/peach-web/src/routes/settings/scuttlebutt.rs b/peach-web/src/routes/settings/scuttlebutt.rs index bf100ad..8e364d4 100644 --- a/peach-web/src/routes/settings/scuttlebutt.rs +++ b/peach-web/src/routes/settings/scuttlebutt.rs @@ -15,6 +15,7 @@ use rocket::{ use rocket_dyn_templates::{tera::Context, Template}; use crate::routes::authentication::Authenticated; +use crate::utils; #[derive(Debug, Deserialize, FromForm)] pub struct SbotConfigForm { @@ -58,10 +59,14 @@ pub struct SbotConfigForm { /// Scuttlebutt settings menu. #[get("/")] pub fn ssb_settings_menu(flash: Option, _auth: Authenticated) -> Template { + // retrieve current ui theme + let theme = utils::get_theme(); + // retrieve go-sbot systemd process status let sbot_status = SbotStatus::read().ok(); let mut context = Context::new(); + context.insert("theme", &theme); context.insert("sbot_status", &sbot_status); context.insert("back", &Some("/settings".to_string())); context.insert("title", &Some("Scuttlebutt Settings".to_string())); @@ -77,6 +82,9 @@ pub fn ssb_settings_menu(flash: Option, _auth: Authenticated) -> T /// Sbot configuration page (includes form for updating configuration parameters). #[get("/configure")] pub fn configure_sbot(flash: Option, _auth: Authenticated) -> Template { + // retrieve current ui theme + let theme = utils::get_theme(); + // retrieve go-sbot systemd process status let sbot_status = SbotStatus::read().ok(); let run_on_startup = sbot_status.map(|status| status.boot_state); @@ -85,6 +93,7 @@ pub fn configure_sbot(flash: Option, _auth: Authenticated) -> Temp let sbot_config = SbotConfig::read().ok(); let mut context = Context::new(); + context.insert("theme", &theme); context.insert("back", &Some("/settings/scuttlebutt".to_string())); context.insert("title", &Some("Sbot Configuration".to_string())); context.insert("sbot_config", &sbot_config); @@ -135,16 +144,14 @@ pub fn configure_sbot_post( match owned_config.startup { true => { info!("Enabling go-sbot.service"); - match systemctl_sbot_cmd("enable") { - Err(e) => warn!("Failed to enable go-sbot.service: {}", e), - _ => (), + if let Err(e) = systemctl_sbot_cmd("enable") { + warn!("Failed to enable go-sbot.service: {}", e) } } false => { info!("Disabling go-sbot.service"); - match systemctl_sbot_cmd("disable") { - Err(e) => warn!("Failed to disable go-sbot.service: {}", e), - _ => (), + if let Err(e) = systemctl_sbot_cmd("disable") { + warn!("Failed to disable go-sbot.service: {}", e) } } }; diff --git a/peach-web/src/routes/settings/theme.rs b/peach-web/src/routes/settings/theme.rs new file mode 100644 index 0000000..3b28e2a --- /dev/null +++ b/peach-web/src/routes/settings/theme.rs @@ -0,0 +1,16 @@ +use rocket::{get, response::Redirect}; + +use crate::routes::authentication::Authenticated; +use crate::{utils, utils::Theme}; + +/// Set the user-interface theme according to the query parameter value. +#[get("/theme?")] +pub fn set_theme(_auth: Authenticated, theme: &str) -> Redirect { + match theme { + "light" => utils::set_theme(Theme::Light), + "dark" => utils::set_theme(Theme::Dark), + _ => (), + } + + Redirect::to("/") +} diff --git a/peach-web/src/routes/status/scuttlebutt.rs b/peach-web/src/routes/status/scuttlebutt.rs index d4e5b51..99b97b9 100644 --- a/peach-web/src/routes/status/scuttlebutt.rs +++ b/peach-web/src/routes/status/scuttlebutt.rs @@ -3,18 +3,24 @@ use rocket::{get, State}; use rocket_dyn_templates::{tera::Context, Template}; use crate::routes::authentication::Authenticated; +use crate::utils; use crate::RocketConfig; // HELPERS AND ROUTES FOR /status/scuttlebutt #[get("/scuttlebutt")] pub fn scuttlebutt_status(_auth: Authenticated, config: &State) -> Template { + // retrieve current ui theme + let theme = utils::get_theme(); + // 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(); + context.insert("theme", &theme); context.insert("sbot_status", &sbot_status); context.insert("sbot_config", &sbot_config); context.insert("flash_name", &None::<()>); diff --git a/peach-web/src/utils.rs b/peach-web/src/utils.rs index ebd5736..fee26fa 100644 --- a/peach-web/src/utils.rs +++ b/peach-web/src/utils.rs @@ -1,9 +1,33 @@ pub mod monitor; -use rocket_dyn_templates::Template; - +use log::info; use rocket::response::{Redirect, Responder}; use rocket::serde::Serialize; +use rocket_dyn_templates::Template; + +use crate::THEME; + +// THEME FUNCTIONS + +#[derive(Debug, Copy, Clone)] +pub enum Theme { + Light, + Dark, +} + +pub fn get_theme() -> String { + let current_theme = THEME.read().unwrap(); + match *current_theme { + Theme::Dark => "dark".to_string(), + _ => "light".to_string(), + } +} + +pub fn set_theme(theme: Theme) { + info!("set ui theme to: {:?}", theme); + let mut writable_theme = THEME.write().unwrap(); + *writable_theme = theme; +} // HELPER FUNCTIONS diff --git a/peach-web/templates/base.html.tera b/peach-web/templates/base.html.tera index 0ecbda1..ff9eb59 100644 --- a/peach-web/templates/base.html.tera +++ b/peach-web/templates/base.html.tera @@ -1,6 +1,6 @@ - + PeachCloud From da976ff4fed7de23f37ed3214645a2ca6352e691 Mon Sep 17 00:00:00 2001 From: glyph Date: Thu, 3 Feb 2022 16:29:53 +0200 Subject: [PATCH 3/5] introduce theme attributes and variables --- peach-web/static/css/_variables.css | 35 +++++- peach-web/static/css/peachcloud.css | 176 ++++++++++++++++++++-------- 2 files changed, 160 insertions(+), 51 deletions(-) diff --git a/peach-web/static/css/_variables.css b/peach-web/static/css/_variables.css index 45be819..3f5adc3 100644 --- a/peach-web/static/css/_variables.css +++ b/peach-web/static/css/_variables.css @@ -166,6 +166,40 @@ --light: var(--light-gray); --dark: var(--near-black); +/* LIGHT (default) THEME VARIABLES */ + + --background: var(--moon-gray); + --button-background: var(--light-gray); + --circle-background: var(--light-gray); + --circle-small-hover-background: var(--white); + + --color-ssb: var(--hot-pink); + --color-settings: var(--purple); + --color-status: var(--green); + --color-info: var(--info); + + --capsule-background: var(--light-gray); + + --text-color-normal: var(--near-black); + --text-color-gray: var(--mid-gray); + --text-color-light-gray: var(--moon-gray); + --text-color-light: var(--white); + + --icon-normal: invert(0%) sepia(1%) saturate(100%) hue-rotate(79deg) brightness(86%) contrast(87%); + --icon-gray: invert(72%) sepia(8%) saturate(14%) hue-rotate(316deg) brightness(93%) contrast(92%); + --icon-light: invert(); + + /* DARK THEME VARIABLES */ + + /*--background-dark: var(--dark-gray);*/ + --background-dark: #222; + --button-background-dark: var(--mid-gray); + /*--capsule-background-dark: var(--light-gray);*/ + --capsule-background-dark: #333; + --circle-background-dark: var(--silver); + --circle-small-hover-background-dark: var(--moon-gray); + +} /* we need to add shades for each accent colour * * --info-100 @@ -174,4 +208,3 @@ * --info-400 * --info-500 */ -} diff --git a/peach-web/static/css/peachcloud.css b/peach-web/static/css/peachcloud.css index 99ec9d2..250e1be 100644 --- a/peach-web/static/css/peachcloud.css +++ b/peach-web/static/css/peachcloud.css @@ -26,6 +26,8 @@ * - NAVIGATION * - PARAGRAPHS * - SWITCHES / SLIDERS + * - TEXT + * - TITLES * \* ------------------------------ */ @@ -128,13 +130,57 @@ */ body { - background-color: var(--moon-gray); + background-color: var(--background); height: 100%; display: flex; flex-direction: column; margin: 0; } +/* + * BORDERS + */ + +.border-circle-small { + border: 4px solid; +} + +.border-settings { + border-color: var(--color-settings); +} + +.border-ssb { + border-color: var(--color-ssb); +} + +.border-status { + border-color: var(--color-status); +} + +.border-primary { + border-color: var(--primary); +} + +.border-success { + border-color: var(--success); +} + +.border-info { + border-color: var(--info); +} + +.border-warning { + border-color: var(--warning); +} + +.border-danger { + border-color: var(--danger); +} + +.border-dark-gray { + border-color: var(--dark-gray); +} + /* * BUTTONS */ @@ -146,7 +192,7 @@ body { -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box; - color: var(--near-black); + color: var(--button-text-color); cursor: pointer; padding: 10px; text-align: center; @@ -169,37 +215,42 @@ body { } .button-primary { - background-color: var(--light-gray); + background-color: var(--button-background); } .button-primary:hover { background-color: var(--primary); + color: var(--button-text-hover-color); } .button-primary:focus { background-color: var(--primary); + color: var(--button-text-hover-color); outline: none; } .button-secondary { - background-color: var(--light-gray); + background-color: var(--button-background); } .button-secondary:hover { background-color: var(--light-silver); + color: var(--button-text-hover-color); } .button-secondary:focus { background-color: var(--light-silver); + color: var(--button-text-hover-color); outline: none; } .button-warning { - background-color: var(--light-gray); + background-color: var(--button-background); } .button-warning:hover { background-color: var(--light-red); + color: var(--button-text-hover-color); } .button-warning:focus { @@ -213,9 +264,9 @@ body { .capsule { padding: 1rem; - border: var(--border-width-1) solid; + border-style: solid; border-radius: var(--border-radius-3); - background-color: var(--light-gray); + background-color: var(--capsule-background); /* margin-top: 1rem; */ /* margin-bottom: 1rem; */ } @@ -272,6 +323,7 @@ body { } .card-text { + color: var(--text-color); margin: 0; font-size: var(--font-size-5); padding-bottom: 0.3rem; @@ -294,7 +346,7 @@ body { .circle { align-items: center; - background: var(--light-gray); + background: var(--circle-background); border-radius: 50%; box-shadow: var(--box-shadow-3); display: flex; @@ -307,6 +359,15 @@ body { width: 5rem; } +.circle-small:hover { + background: var(--circle-small-hover-background); +} + +.circle-small:focus { + background: var(--circle-small-hover-background); + outline: none; +} + .circle-medium { height: 8rem; width: 8rem; @@ -391,30 +452,6 @@ body { background-color: var(--light); } -.primary-border { - border-color: var(--primary); -} - -.success-border { - border-color: var(--success); -} - -.info-border { - border-color: var(--info); -} - -.warning-border { - border-color: var(--warning); -} - -.danger-border { - border-color: var(--danger); -} - -.dark-gray-border { - border-color: var(--dark-gray); -} - /* * GRIDS */ @@ -555,6 +592,30 @@ body { html { height: 100%; + + --background: var(--background); + --button-background: var(--button-background); + --button-text-color: var(--text-color-normal); + --button-text-hover-color: var(--text-color-normal); + --circle-background: var(--circle-background); + --circle-small-hover-background: var(--circle-small-hover-background); + --icon-color: var(--icon-normal); + --nav-icon-color: var(--nav-icon-color); + --text-color: var(--text-color-normal); +} + +html[data-theme='dark'] { + --background: var(--background-dark); + --button-background: var(--button-background-dark); + --button-text-color: var(--text-color-light); + --button-text-hover-color: var(--text-color-normal); + --capsule-background: var(--capsule-background-dark); + --circle-background: var(--circle-background-dark); + --circle-small-hover-background: var(--circle-small-hover-background-dark); + --icon-color: var(--icon-light); + --nav-icon-color: var(--nav-icon-color-light); + --text-color: var(--text-color-light); + --text-color-gray: var(--text-color-light-gray); } /* @@ -573,28 +634,21 @@ html { * FONTS */ +.font-normal { + color: var(--text-color); +} + .font-near-black { color: var(--near-black); } .font-gray { - color: var(--mid-gray); + color: var(--text-color-gray); } .font-light-gray { - color: var(--silver); -} - -.font-success { - color: var(--success); -} - -.font-warning { - color: var(--warning); -} - -.font-failure { - color: var(--danger); + /* color: var(--silver); */ + color: var(--text-color-light-gray); } /* @@ -637,12 +691,12 @@ form { /* icon-active: sets color of icon svg to near-black */ .icon-active { - filter: invert(0%) sepia(1%) saturate(4171%) hue-rotate(79deg) brightness(86%) contrast(87%); + filter: var(--icon-color); } /* icon-inactive: sets color of icon svg to gray */ .icon-inactive { - filter: invert(72%) sepia(8%) saturate(14%) hue-rotate(316deg) brightness(93%) contrast(92%); + filter: var(--icon-gray); } /* @@ -699,10 +753,11 @@ form { font-family: var(--sans-serif); font-size: var(--font-size-7); display: block; - margin-bottom: 2px; + /* margin-bottom: 2px; */ } .label-medium { + color: var(--text-color); font-size: var(--font-size-3); display: block; } @@ -728,7 +783,7 @@ form { .link { text-decoration: none; - color: var(--font-near-black); + /* color: var(--font-near-black); */ } /* @@ -861,6 +916,7 @@ meter::-moz-meter-bar { } .nav-title { + color: var(--text-color); font-family: var(--sans-serif); font-size: var(--font-size-4); font-weight: normal; @@ -976,6 +1032,26 @@ input:checked + .slider:before { border-radius: 50%; } +/* + * TEXT + */ + +.text-info { + color: var(--info); +} + +.text-danger { + color: var(--danger); +} + +.text-success { + color: var(--success); +} + +.text-warning { + color: var(--warning); +} + /* * TITLES */ From 62191e55090d7542b8e746db36b61a9f4cebdfd6 Mon Sep 17 00:00:00 2001 From: glyph Date: Thu, 3 Feb 2022 16:30:26 +0200 Subject: [PATCH 4/5] theme icons and updated hermies icons --- peach-web/static/icons/hermies_hex.svg | 885 +++++++++++++++++++ peach-web/static/icons/hermies_hex_light.svg | 870 ++++++++++++++++++ peach-web/static/icons/moon.png | Bin 0 -> 4787 bytes peach-web/static/icons/sun.png | Bin 0 -> 4346 bytes 4 files changed, 1755 insertions(+) create mode 100644 peach-web/static/icons/hermies_hex.svg create mode 100644 peach-web/static/icons/hermies_hex_light.svg create mode 100644 peach-web/static/icons/moon.png create mode 100644 peach-web/static/icons/sun.png diff --git a/peach-web/static/icons/hermies_hex.svg b/peach-web/static/icons/hermies_hex.svg new file mode 100644 index 0000000..1718824 --- /dev/null +++ b/peach-web/static/icons/hermies_hex.svg @@ -0,0 +1,885 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/peach-web/static/icons/hermies_hex_light.svg b/peach-web/static/icons/hermies_hex_light.svg new file mode 100644 index 0000000..0e4e3b0 --- /dev/null +++ b/peach-web/static/icons/hermies_hex_light.svg @@ -0,0 +1,870 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/peach-web/static/icons/moon.png b/peach-web/static/icons/moon.png new file mode 100644 index 0000000000000000000000000000000000000000..b81cc738a7de7947868108d84dfff7c73841102f GIT binary patch literal 4787 zcmV;k5=`xhP)?bK~#90?VWj?9aWXbzpvA2Ivtb7BtVwY5J^C62t?G8FzgT` zi-?0D!biqYTmTmaT$n*cKtO>32L(3<=ELBOLJXS=f*L?sB9SB@N+)0hB1;w$2qE2_ z?&lxpy>#7ktKO^SR@Hm2>-YK8=hN?X-E&S=-FNHUvzBO0>;TLJb_Hft{+&~z)D~R&|CR?ZDv=H5lVRr-~i)*xxfLyfj|$ieM-Du0v-eI z0qzCvMk1m0)sJVWQs-N-{r8(qL*zy-j4$VyU6#zEi~;E)VtYig8$V~_`0>xT9r%j_w@PPs^Gq8s=i za5JJ1){^}p;K+Q$Y;4Q}9-;Qly9f9vFd-)y!=MY942zJ}Dd<`jBZ};Z#~#4X3BFOU z0M`I}<|SYP>;_zhY#oEH?>6Agc?p;&x`3}ETPD97vljRg>FwvU#CYHw;01zTX%_&U zc?p;`4g;Pd_`!dHVGCU=p$oW<;MHISV#sP)bOM*)ui5tl-$hKgt%^~=AF02q`6jSk zPBNy39)d6aPO^Cq?g5+)ECilFj6r3@2k;c4xLty1>1iy-r(#}rFYq(`@5wSmhiD0$ zh$wUVB3}YNM!LqRcHl$6AAI=NI@SW00@EGI(S{hNygZJn{O|pUkxI+(a^-(bi&4Pk z_}}24kp3S2VCaNb9dd!+f_g!n3&0y`ixTwlZ!z}_kI z9s}I!!@G>E2Im2D0>(}Pjs+Irzdc<8{8J2>UWfTm*HK%^dpq!q5B~?q#?+k%Q-Q~^ zh5se#@9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4d(y= literal 0 HcmV?d00001 diff --git a/peach-web/static/icons/sun.png b/peach-web/static/icons/sun.png new file mode 100644 index 0000000000000000000000000000000000000000..5030b39af6ef4af9eb0715468dcbe7e52b4d7e96 GIT binary patch literal 4346 zcmVKn&{lEmEYsS3f0z-jPMQZ>C zXUb7@97)S(c^hb#DMvZLHME?x67X=Q97V^=xSwUeOgYK{zKeU(HUK@cWGVvo$Nd~7 zV3#bJ$^+_vCAcSUOqNVVzyr9S;iXJD$`P)|J$Z|OHZhK|5AY}C^D-nxx&U7S*5Q7J zQ)3>dX3-1SgnI&yiiv(7V08uEb-;j_Xaii0oA(vKRxyrI^O%Nv5}%BT_PGk}(J|4k z13psdUmp|wSW(QH0T0}*^c@ZC90Tp`0`^70FyPCMzD?-QlR0c&08arQIQojf@bp;; zg;7f1R79y|9c*3zjlg|M|Jgv>lz9n?0l>jZ{~c*F5)?Ks0Dy_WMn_){;J6HU34-&1 zf}`(U;Dz*A2?pC2z%t+orGI4Fj08YO;D<{8?T8R)C2U^+pbJlj1G}Zoh!2J%i=Yy# zfGHX95*T?{05gI29eo8v7O({c^j&EZ@OjF-ghCz`Knb`<=|2;D6e~vnyF2PKUaAAfOrj8t!TpQxF`FXh_tpt1j%!N9jf4|Ug7DA zD(JPs10!)y_O%)E(-v`7spMxZt-gPoaSU)H;^h+uwgTRwd9s%SJHXnm&ZgiRV>B5UEf7K zi=ftV8Sc3|I*Ebmk|5fIwMyRz#LfFW($SB%M_j-91O0$qf!;u;rr*jw0AC<#+f~RL z_kL4*4|o%|4kAg62F5G>gMq)M$Vb&U4gJ_w0&XRlouCLD1dKy0aBDqy2-?;G{{Y4! zzJp2XPBd4taWND*KhP~Pjx!Lr4*6zQ`-l6rCCCE)dW`(j#J_1w%`YN1xD@k) z{kjUeb-*dW91r?Qw>iLxRKF{X^BCja80cpXE!wBtu8csh7xHb+>W_D}cacwC6q#y* z2i-fVA)(o{%GU$igrs$!ftJ?lfkzO1#2LtUe0Rh(ymM3Qg?v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QXWT3d}+NfXcO9_2ZF@uAUTkh>2OvNUpV|RxOv}1_CcY!!Rfds za6J+}9w&w%TD&R1H)5n)L^oWGi*byah8A`;Ia7|p<0{;nS*|wk`wP9ZEfgbgf zMG&heY!d>tbZK*uz|TBk8M?JHXvOa>7VUs{XntcF(d+5t0fT9oM7o4-)og_WU6J6- oiR6F6&PF_=>w!x$=0(N-0TLu{x!y3@GXMYp07*qoM6N<$f(ra7?f?J) literal 0 HcmV?d00001 From 4e6bb15a23d8092328f45230c09b34d33047b6fa Mon Sep 17 00:00:00 2001 From: glyph Date: Thu, 3 Feb 2022 16:31:17 +0200 Subject: [PATCH 5/5] update templates to use theme variables and classes --- peach-web/src/context/dns.rs | 2 + peach-web/templates/help.html.tera | 11 +-- peach-web/templates/home.html.tera | 26 +++++-- peach-web/templates/login.html.tera | 8 +- peach-web/templates/nav.html.tera | 18 ++++- .../templates/scuttlebutt/messages.html.tera | 2 +- .../templates/scuttlebutt/profile.html.tera | 6 +- .../settings/admin/change_password.html.tera | 2 +- .../settings/admin/configure_admin.html.tera | 4 +- .../scuttlebutt/configure_sbot.html.tera | 74 ++++++++++--------- .../snippets/flash_message.html.tera | 8 +- .../templates/status/scuttlebutt.html.tera | 23 +++--- 12 files changed, 104 insertions(+), 80 deletions(-) diff --git a/peach-web/src/context/dns.rs b/peach-web/src/context/dns.rs index 9d74ced..7a86646 100644 --- a/peach-web/src/context/dns.rs +++ b/peach-web/src/context/dns.rs @@ -11,6 +11,7 @@ pub struct ConfigureDNSContext { pub title: Option, pub flash_name: Option, pub flash_msg: Option, + pub theme: Option, } impl ConfigureDNSContext { @@ -31,6 +32,7 @@ impl ConfigureDNSContext { title: None, flash_name: None, flash_msg: None, + theme: None, } } } diff --git a/peach-web/templates/help.html.tera b/peach-web/templates/help.html.tera index 4baa227..0109d1e 100644 --- a/peach-web/templates/help.html.tera +++ b/peach-web/templates/help.html.tera @@ -2,16 +2,9 @@ {%- block card %}
-
+
- - {%- if flash_msg and flash_name == "success" %} - -
{{ flash_msg }}.
- {%- elif flash_msg and flash_name == "error" %} - -
{{ flash_msg }}.
- {%- endif %} + {% include "snippets/flash_message" %}
{%- endblock card -%} diff --git a/peach-web/templates/home.html.tera b/peach-web/templates/home.html.tera index ecce8c2..9013c7c 100644 --- a/peach-web/templates/home.html.tera +++ b/peach-web/templates/home.html.tera @@ -5,27 +5,39 @@ -
+
-
+
-
+
-
+ {% if sbot_status.state == "active" %} +
+

^_^

+
+ {% elif sbot_status.state == "inactive" %} +
+

z_z

+
+ {% else %} +
+

x_x

+
+ {% endif %}
@@ -34,21 +46,21 @@ {% else -%} {%- endif -%} -
+
-
+
-
+
diff --git a/peach-web/templates/login.html.tera b/peach-web/templates/login.html.tera index 504b242..31d7ccf 100644 --- a/peach-web/templates/login.html.tera +++ b/peach-web/templates/login.html.tera @@ -3,7 +3,7 @@
-
+ @@ -12,12 +12,10 @@
- {% include "snippets/flash_message" %} - -
diff --git a/peach-web/templates/nav.html.tera b/peach-web/templates/nav.html.tera index e89e50a..7e31734 100644 --- a/peach-web/templates/nav.html.tera +++ b/peach-web/templates/nav.html.tera @@ -17,13 +17,25 @@ {%- endblock nav -%} diff --git a/peach-web/templates/scuttlebutt/messages.html.tera b/peach-web/templates/scuttlebutt/messages.html.tera index 979a68c..d3da0af 100644 --- a/peach-web/templates/scuttlebutt/messages.html.tera +++ b/peach-web/templates/scuttlebutt/messages.html.tera @@ -2,7 +2,7 @@ {%- block card %}
-
+
{% include "snippets/flash_message" %}
diff --git a/peach-web/templates/scuttlebutt/profile.html.tera b/peach-web/templates/scuttlebutt/profile.html.tera index a34a37a..74b1c31 100644 --- a/peach-web/templates/scuttlebutt/profile.html.tera +++ b/peach-web/templates/scuttlebutt/profile.html.tera @@ -5,7 +5,7 @@
- Profile picture + Profile picture Profile picture @@ -15,14 +15,14 @@

{ description }

-
+
-
+
Follow Block Private Message diff --git a/peach-web/templates/settings/admin/change_password.html.tera b/peach-web/templates/settings/admin/change_password.html.tera index 604fe46..b3b0749 100644 --- a/peach-web/templates/settings/admin/change_password.html.tera +++ b/peach-web/templates/settings/admin/change_password.html.tera @@ -2,7 +2,7 @@ {%- block card %}
-
+ diff --git a/peach-web/templates/settings/admin/configure_admin.html.tera b/peach-web/templates/settings/admin/configure_admin.html.tera index f19cead..0127e1b 100644 --- a/peach-web/templates/settings/admin/configure_admin.html.tera +++ b/peach-web/templates/settings/admin/configure_admin.html.tera @@ -3,9 +3,9 @@
-

Current Admins

+

Current Admins

{% if not ssb_admin_ids %} -
+
There are no currently configured admins.
{% else %} diff --git a/peach-web/templates/settings/scuttlebutt/configure_sbot.html.tera b/peach-web/templates/settings/scuttlebutt/configure_sbot.html.tera index a791519..3b74880 100644 --- a/peach-web/templates/settings/scuttlebutt/configure_sbot.html.tera +++ b/peach-web/templates/settings/scuttlebutt/configure_sbot.html.tera @@ -15,57 +15,59 @@
-
- +
+
- - - - - - - - - -
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
-
-
- +
+
-
- +
+
-
-
- +
+
-
-
- +
+
-
- -
-
- -
-
- -
-
+ +
+ +
+ +
-
+
-
@@ -75,7 +77,7 @@ - + Restore Defaults diff --git a/peach-web/templates/snippets/flash_message.html.tera b/peach-web/templates/snippets/flash_message.html.tera index 0c967ce..0b7fc3b 100644 --- a/peach-web/templates/snippets/flash_message.html.tera +++ b/peach-web/templates/snippets/flash_message.html.tera @@ -1,11 +1,11 @@ {% if flash_msg and flash_name == "success" %} -
{{ flash_msg }}.
+
{{ flash_msg }}.
{%- elif flash_msg and flash_name == "info" %} -
{{ flash_msg }}.
+
{{ flash_msg }}.
{%- elif flash_msg and flash_name == "error" %} -
{{ flash_msg }}.
-{%- endif -%} \ No newline at end of file +
{{ flash_msg }}.
+{%- endif -%} diff --git a/peach-web/templates/status/scuttlebutt.html.tera b/peach-web/templates/status/scuttlebutt.html.tera index d147bbf..32d04bc 100644 --- a/peach-web/templates/status/scuttlebutt.html.tera +++ b/peach-web/templates/status/scuttlebutt.html.tera @@ -6,21 +6,26 @@ {% set mem = sbot_status.memory / 1024 / 1024 | round -%} {%- else -%} {% set mem = "X" -%} + {%- endif -%} + {%- if sbot_status.blobstore -%} + {% set blobs = sbot_status.blobstore / 1024 / 1024 | round -%} + {%- else -%} + {% set blobs = "X" -%} {%- endif -%}
-
+
- Configure + Configure
- Hermies + Hermies
@@ -78,25 +83,25 @@
- +
- +
- - + +
- +
- +