From 7346c37c863b1ec955d6e80dd491c8ce7ce68d81 Mon Sep 17 00:00:00 2001 From: glyph Date: Tue, 18 Jan 2022 12:48:11 +0200 Subject: [PATCH 1/4] define route and template for sbot status --- peach-web/src/routes/status/scuttlebutt.rs | 16 ++++++++++++++++ .../templates/status/scuttlebutt.html.tera | 17 +++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 peach-web/src/routes/status/scuttlebutt.rs create mode 100644 peach-web/templates/status/scuttlebutt.html.tera diff --git a/peach-web/src/routes/status/scuttlebutt.rs b/peach-web/src/routes/status/scuttlebutt.rs new file mode 100644 index 0000000..c1f532a --- /dev/null +++ b/peach-web/src/routes/status/scuttlebutt.rs @@ -0,0 +1,16 @@ +use rocket::{get, request::FlashMessage}; +use rocket_dyn_templates::{tera::Context, Template}; + +use crate::routes::authentication::Authenticated; + +// HELPERS AND ROUTES FOR /status/scuttlebutt + +#[get("/scuttlebutt")] +pub fn scuttlebutt_status(_auth: Authenticated) -> Template { + let mut context = Context::new(); + context.insert("flash_name", &None::<()>); + context.insert("flash_msg", &None::<()>); + context.insert("title", &Some("Scuttlebutt Status")); + + Template::render("status/scuttlebutt", &context.into_json()) +} diff --git a/peach-web/templates/status/scuttlebutt.html.tera b/peach-web/templates/status/scuttlebutt.html.tera new file mode 100644 index 0000000..29181de --- /dev/null +++ b/peach-web/templates/status/scuttlebutt.html.tera @@ -0,0 +1,17 @@ +{%- extends "nav" -%} +{%- block card %} + +
+
+

Network key:

+

Replication hops:

+

Sbot version:

+

Process status:

+

Process uptime:

+

Blobstore size:

+

Latest sequence number:

+

Last time you visited this page, latest sequence was x ... now it's y

+

Number of follows / followers / friends / blocks

+
+
+{%- endblock card -%} From 205dd145b48a28d3976b0c06df743edb93f72010 Mon Sep 17 00:00:00 2001 From: glyph Date: Tue, 18 Jan 2022 12:48:40 +0200 Subject: [PATCH 2/4] add links to templates for sbot status page --- peach-web/templates/home.html.tera | 4 ++++ peach-web/templates/status/device.html.tera | 26 +++++++++++---------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/peach-web/templates/home.html.tera b/peach-web/templates/home.html.tera index 23920be..5d16781 100644 --- a/peach-web/templates/home.html.tera +++ b/peach-web/templates/home.html.tera @@ -29,7 +29,11 @@ + {%- if standalone_mode == true -%} + + {% else -%} + {%- endif -%}
diff --git a/peach-web/templates/status/device.html.tera b/peach-web/templates/status/device.html.tera index f48bb58..ead9e93 100644 --- a/peach-web/templates/status/device.html.tera +++ b/peach-web/templates/status/device.html.tera @@ -25,13 +25,13 @@ {# Display microservice status for network, oled & stats #}
- -
- Sbot -
- - + +
+ Sbot +
+ + +
-
+
{# Display CPU usage meter #} {%- if cpu_stat_percent -%} From 44b68a8b71f2c6293ee2581489fb4afb744f1608 Mon Sep 17 00:00:00 2001 From: glyph Date: Tue, 18 Jan 2022 12:49:47 +0200 Subject: [PATCH 3/4] register scuttlebutt status routes and pass standalone var to home template --- peach-web/src/routes/index.rs | 3 +++ peach-web/src/routes/status/mod.rs | 1 + 2 files changed, 4 insertions(+) diff --git a/peach-web/src/routes/index.rs b/peach-web/src/routes/index.rs index 87d3d4f..54867b7 100644 --- a/peach-web/src/routes/index.rs +++ b/peach-web/src/routes/index.rs @@ -2,6 +2,7 @@ use rocket::{get, request::FlashMessage}; use rocket_dyn_templates::{tera::Context, Template}; use crate::routes::authentication::Authenticated; +use crate::STANDALONE_MODE; // HELPERS AND ROUTES FOR / (HOME PAGE) @@ -11,6 +12,8 @@ pub fn home(_auth: Authenticated) -> Template { context.insert("flash_name", &None::<()>); context.insert("flash_msg", &None::<()>); context.insert("title", &None::<()>); + // pass in mode so we can define appropriate urls in template + context.insert("standalone_mode", &*STANDALONE_MODE); Template::render("home", &context.into_json()) } diff --git a/peach-web/src/routes/status/mod.rs b/peach-web/src/routes/status/mod.rs index 803899a..a2e0f54 100644 --- a/peach-web/src/routes/status/mod.rs +++ b/peach-web/src/routes/status/mod.rs @@ -1,2 +1,3 @@ pub mod device; pub mod network; +pub mod scuttlebutt; From 792779f60f5f71beed9808d0eefde64432f70560 Mon Sep 17 00:00:00 2001 From: glyph Date: Tue, 18 Jan 2022 12:50:06 +0200 Subject: [PATCH 4/4] deduplicate mounting of routes --- peach-web/src/main.rs | 4 +-- peach-web/src/router.rs | 75 ++++++----------------------------------- 2 files changed, 13 insertions(+), 66 deletions(-) diff --git a/peach-web/src/main.rs b/peach-web/src/main.rs index 56c8f75..ded1686 100644 --- a/peach-web/src/main.rs +++ b/peach-web/src/main.rs @@ -55,9 +55,9 @@ static AP_IFACE: &str = "ap0"; pub fn init_rocket() -> Rocket { info!("Initializing Rocket"); if *STANDALONE_MODE { - router::build_minimal_rocket() + router::mount_peachpub_routes() } else { - router::build_complete_rocket() + router::mount_peachcloud_routes() } } diff --git a/peach-web/src/router.rs b/peach-web/src/router.rs index 51e34c5..341d9aa 100644 --- a/peach-web/src/router.rs +++ b/peach-web/src/router.rs @@ -7,15 +7,15 @@ use crate::routes::{ index::*, scuttlebutt::*, settings::{admin::*, dns::*, menu::*, network::*, scuttlebutt::*}, - status::{device::*, network::*}, + status::{device::*, network::*, scuttlebutt::*}, }; -/// Create minimal rocket instance and mount routes. This excludes settings -/// and status routes related to networking and the device (memory, +/// Create a Rocket instance and mount PeachPub routes, fileserver and +/// catchers. This gives us everything we need to run PeachPub and excludes +/// settings and status routes related to networking and the device (memory, /// hard disk, CPU etc.). -pub fn build_minimal_rocket() -> Rocket { +pub fn mount_peachpub_routes() -> Rocket { rocket::build() - // GENERAL HTML ROUTES .mount( "/", routes![ @@ -30,7 +30,6 @@ pub fn build_minimal_rocket() -> Rocket { settings_menu, ], ) - // ADMIN SETTINGS HTML ROUTES .mount( "/settings/admin", routes![ @@ -47,12 +46,10 @@ pub fn build_minimal_rocket() -> Rocket { send_password_reset_post, ], ) - // SCUTTLEBUTT SETTINGS HTML ROUTES .mount( "/settings/scuttlebutt", routes![ssb_settings_menu, configure_sbot], ) - // SCUTTLEBUTT SOCIAL HTML ROUTES .mount( "/scuttlebutt", routes![ @@ -60,50 +57,17 @@ pub fn build_minimal_rocket() -> Rocket { block, publish, ], ) - // STATUS HTML ROUTES - // TODO: replace this with a route for `scuttlebutt_status` - .mount("/status", routes![device_status, network_status]) + .mount("/status", routes![scuttlebutt_status]) .mount("/", FileServer::from("static")) .register("/", catchers![not_found, internal_error, forbidden]) .attach(Template::fairing()) } -/// Create complete rocket instance and mount all routes. -pub fn build_complete_rocket() -> Rocket { - rocket::build() - // GENERAL HTML ROUTES - .mount( - "/", - routes![ - help, - home, - login, - login_post, - logout, - reboot_cmd, - shutdown_cmd, - power_menu, - settings_menu, - ], - ) - // ADMIN SETTINGS HTML ROUTES - .mount( - "/settings/admin", - routes![ - admin_menu, - configure_admin, - add_admin, - add_admin_post, - delete_admin_post, - change_password, - change_password_post, - reset_password, - reset_password_post, - forgot_password_page, - send_password_reset_post, - ], - ) - // NETWORK SETTINGS HTML ROUTES +/// Create a Rocket instance with PeachPub routes, fileserver and catchers by +/// calling `mount_peachpub_routes()` and then mount all additional routes +/// required to run a complete PeachCloud build. +pub fn mount_peachcloud_routes() -> Rocket { + mount_peachpub_routes() .mount( "/settings/network", routes![ @@ -127,22 +91,5 @@ pub fn build_complete_rocket() -> Rocket { wifi_usage_reset, ], ) - // SCUTTLEBUTT SETTINGS HTML ROUTES - .mount( - "/settings/scuttlebutt", - routes![ssb_settings_menu, configure_sbot], - ) - // SCUTTLEBUTT SOCIAL HTML ROUTES - .mount( - "/scuttlebutt", - routes![ - peers, friends, follows, followers, blocks, profile, private, follow, unfollow, - block, publish, - ], - ) - // STATUS HTML ROUTES .mount("/status", routes![device_status, network_status]) - .mount("/", FileServer::from("static")) - .register("/", catchers![not_found, internal_error, forbidden]) - .attach(Template::fairing()) }