Merge pull request 'Deduplicate routes and add Scuttlebutt status route & template' (#73) from add_sbot_status into main

Reviewed-on: #73
This commit is contained in:
glyph 2022-01-18 10:55:43 +00:00
commit 66555f19bf
8 changed files with 68 additions and 78 deletions

View File

@ -55,9 +55,9 @@ static AP_IFACE: &str = "ap0";
pub fn init_rocket() -> Rocket<Build> {
info!("Initializing Rocket");
if *STANDALONE_MODE {
router::build_minimal_rocket()
router::mount_peachpub_routes()
} else {
router::build_complete_rocket()
router::mount_peachcloud_routes()
}
}

View File

@ -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<Build> {
pub fn mount_peachpub_routes() -> Rocket<Build> {
rocket::build()
// GENERAL HTML ROUTES
.mount(
"/",
routes![
@ -30,7 +30,6 @@ pub fn build_minimal_rocket() -> Rocket<Build> {
settings_menu,
],
)
// ADMIN SETTINGS HTML ROUTES
.mount(
"/settings/admin",
routes![
@ -47,12 +46,10 @@ pub fn build_minimal_rocket() -> Rocket<Build> {
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<Build> {
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<Build> {
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<Build> {
mount_peachpub_routes()
.mount(
"/settings/network",
routes![
@ -127,22 +91,5 @@ pub fn build_complete_rocket() -> Rocket<Build> {
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())
}

View File

@ -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())
}

View File

@ -1,2 +1,3 @@
pub mod device;
pub mod network;
pub mod scuttlebutt;

View File

@ -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())
}

View File

@ -29,7 +29,11 @@
</a>
<!-- bottom-left -->
<!-- SYSTEM STATUS LINK AND ICON -->
{%- if standalone_mode == true -%}
<a class="bottom-left" href="/status/scuttlebutt" title="Status">
{% else -%}
<a class="bottom-left" href="/status" title="Status">
{%- endif -%}
<div class="circle circle-small">
<img class="icon-medium" src="/icons/heart-pulse.svg">
</div>

View File

@ -25,13 +25,13 @@
{# Display microservice status for network, oled & stats #}
<!-- PEACH-NETWORK STATUS STACK -->
<a class="link" href="/status/network">
<div class="stack capsule{% if network_ping == "ONLINE" %} success-border{% else %} warning-border{% endif %}">
<img id="networkIcon" class="icon{% if network_ping == "OFFLINE" %} icon-inactive{% endif %} icon-medium" alt="Network" title="Network microservice status" src="/icons/wifi.svg">
<div class="stack" style="padding-top: 0.5rem;">
<label class="label-small font-near-black">Networking</label>
<label class="label-small font-near-black">{{ network_ping }}</label>
<div class="stack capsule{% if network_ping == "ONLINE" %} success-border{% else %} warning-border{% endif %}">
<img id="networkIcon" class="icon{% if network_ping == "OFFLINE" %} icon-inactive{% endif %} icon-medium" alt="Network" title="Network microservice status" src="/icons/wifi.svg">
<div class="stack" style="padding-top: 0.5rem;">
<label class="label-small font-near-black">Networking</label>
<label class="label-small font-near-black">{{ network_ping }}</label>
</div>
</div>
</div>
</a>
<!-- PEACH-OLED STATUS STACK -->
<div class="stack capsule{% if oled_ping == "ONLINE" %} success-border{% else %} warning-border{% endif %}">
@ -67,14 +67,16 @@
</div>
</div>
<!-- SBOT STATUS STACK -->
<div class="stack capsule{% if sbot_is_online %} success-border{% else %} warning-border{% endif %}">
<img id="networkIcon" class="icon{% if sbot_is_online != true %} icon-inactive{% endif %} icon-medium" alt="Sbot" title="Sbot status" src="/icons/hermies.svg">
<div class="stack" style="padding-top: 0.5rem;">
<label class="label-small font-near-black">Sbot</label>
<label class="label-small font-near-black">{% if sbot_is_online %} ONLINE {% else %} OFFLINE {% endif %} </label>
<a class="link" href="/status/scuttlebutt">
<div class="stack capsule{% if sbot_is_online %} success-border{% else %} warning-border{% endif %}">
<img id="networkIcon" class="icon{% if sbot_is_online != true %} icon-inactive{% endif %} icon-medium" alt="Sbot" title="Sbot status" src="/icons/hermies.svg">
<div class="stack" style="padding-top: 0.5rem;">
<label class="label-small font-near-black">Sbot</label>
<label class="label-small font-near-black">{% if sbot_is_online %} ONLINE {% else %} OFFLINE {% endif %} </label>
</div>
</div>
</div>
</div>
</a>
<div class="card-container">
{# Display CPU usage meter #}
{%- if cpu_stat_percent -%}

View File

@ -0,0 +1,17 @@
{%- extends "nav" -%}
{%- block card %}
<!-- SCUTTLEBUTT STATUS -->
<div class="card center">
<div class="card-container">
<p>Network key: </p>
<p>Replication hops: </p>
<p>Sbot version: </p>
<p>Process status: </p>
<p>Process uptime: </p>
<p>Blobstore size: </p>
<p>Latest sequence number: </p>
<p>Last time you visited this page, latest sequence was x ... now it's y</p>
<p>Number of follows / followers / friends / blocks</p>
</div>
</div>
{%- endblock card -%}