From eaca10954e85dcae0330e4ff824b703a8fdb0c8d Mon Sep 17 00:00:00 2001 From: notplants Date: Fri, 23 May 2025 14:01:38 -0400 Subject: [PATCH] working --- Cargo.lock | 7 +++++++ pdeploy.sh | 4 ++++ peach-lib/src/sbot.rs | 9 +++++---- peach-web/Cargo.toml | 1 + peach-web/src/routes/authentication/change.rs | 10 +++++----- peach-web/src/routes/authentication/forgot.rs | 2 +- peach-web/src/routes/authentication/login.rs | 6 +++--- peach-web/src/routes/authentication/logout.rs | 4 ++-- peach-web/src/routes/authentication/reset.rs | 10 +++++----- .../src/routes/authentication/temporary.rs | 4 ++-- peach-web/src/routes/scuttlebutt/block.rs | 10 +++++----- peach-web/src/routes/scuttlebutt/follow.rs | 10 +++++----- peach-web/src/routes/scuttlebutt/invites.rs | 20 +++++++++++-------- peach-web/src/routes/scuttlebutt/private.rs | 12 +++++------ peach-web/src/routes/scuttlebutt/profile.rs | 2 +- .../src/routes/scuttlebutt/profile_update.rs | 14 ++++++------- peach-web/src/routes/scuttlebutt/publish.rs | 10 +++++----- peach-web/src/routes/scuttlebutt/search.rs | 4 ++-- peach-web/src/routes/scuttlebutt/unblock.rs | 10 +++++----- peach-web/src/routes/scuttlebutt/unfollow.rs | 10 +++++----- peach-web/src/routes/settings/admin/add.rs | 8 ++++---- .../src/routes/settings/admin/configure.rs | 6 +++--- peach-web/src/routes/settings/admin/delete.rs | 8 ++++---- .../src/routes/settings/network/add_ap.rs | 4 ++-- .../src/routes/settings/network/ap_details.rs | 2 +- .../routes/settings/network/configure_dns.rs | 4 ++-- .../settings/network/data_usage_limits.rs | 2 +- peach-web/src/routes/settings/network/menu.rs | 2 +- .../src/routes/settings/network/modify_ap.rs | 4 ++-- peach-web/src/routes/settings/power/menu.rs | 2 +- peach-web/src/routes/settings/power/reboot.rs | 2 +- .../src/routes/settings/power/shutdown.rs | 2 +- .../routes/settings/scuttlebutt/configure.rs | 4 ++-- .../routes/settings/scuttlebutt/default.rs | 2 +- .../src/routes/settings/scuttlebutt/menu.rs | 2 +- .../routes/settings/scuttlebutt/restart.rs | 12 +++++------ .../src/routes/settings/scuttlebutt/start.rs | 8 ++++---- .../src/routes/settings/scuttlebutt/stop.rs | 10 +++++----- peach-web/src/utils/flash.rs | 17 +++++++++------- peach-web/src/utils/sbot.rs | 18 ++++++++--------- tdeploy.sh | 3 +++ tilde-client/src/lib.rs | 7 ++++--- 42 files changed, 155 insertions(+), 133 deletions(-) create mode 100755 pdeploy.sh create mode 100755 tdeploy.sh diff --git a/Cargo.lock b/Cargo.lock index b5971f6..ee6e509 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2576,6 +2576,7 @@ dependencies = [ "reqwest", "rouille", "temporary", + "urlencoding", "vnstat_parse", "xdg", ] @@ -4187,6 +4188,12 @@ dependencies = [ "percent-encoding 2.1.0", ] +[[package]] +name = "urlencoding" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" + [[package]] name = "value-bag" version = "1.0.0-alpha.9" diff --git a/pdeploy.sh b/pdeploy.sh new file mode 100755 index 0000000..ac4f968 --- /dev/null +++ b/pdeploy.sh @@ -0,0 +1,4 @@ +#! /bin/bash +cargo build --package peach-web --release +rsync -azvh /home/notplants/computer/projects/peachpub/peach-workspace/target/release/peach-web root@159.89.42.156:/var/www/peachpub_ynh/peach-web +ssh root@159.89.42.156 'systemctl restart peachpub_ynh-peach-web' diff --git a/peach-lib/src/sbot.rs b/peach-lib/src/sbot.rs index 565d16e..43e364e 100644 --- a/peach-lib/src/sbot.rs +++ b/peach-lib/src/sbot.rs @@ -222,9 +222,10 @@ impl SbotConfig { pub fn read() -> Result { // determine path of user's solar-sbot config.toml let config_path = format!( - "{}/sbot-config.toml", + "{}/tilde-sbot.toml", config_manager::get_config_value("TILDE_SBOT_DATADIR")? ); + println!("TILDE_SBOT_CONFIG_PATH: {}", config_path); let config_contents = fs::read_to_string(config_path)?; @@ -233,7 +234,7 @@ impl SbotConfig { Ok(config) } - /// Write the given `SbotConfig` to the tilde-sbot `sbot-config.toml` file. + /// Write the given `SbotConfig` to the tilde-sbot `tilde-sbot.toml` file. pub fn write(config: SbotConfig) -> Result<(), PeachError> { let repo_comment = "# For details about tilde-sbot configuration, please visit tilde friends documentation\n".to_string(); @@ -242,7 +243,7 @@ impl SbotConfig { // determine path of user's solar-sbot config.toml let config_path = format!( - "{}/sbot-config.toml", + "{}/tilde-sbot.toml", config_manager::get_config_value("TILDE_SBOT_DATADIR")? ); @@ -272,7 +273,7 @@ pub async fn init_sbot() -> Result { debug!("Initialising an sbot client with configuration parameters"); let database_path = format!("{}/db.sqlite", config_manager::get_config_value("TILDE_SBOT_DATADIR")?); let sbot_client = TildeClient { - port: sbot_config.ssb_port, + ssb_port: sbot_config.ssb_port, tilde_binary_path: config_manager::get_config_value("TILDE_BINARY_PATH")?, tilde_database_path: database_path, }; diff --git a/peach-web/Cargo.toml b/peach-web/Cargo.toml index 6880306..dc495c5 100644 --- a/peach-web/Cargo.toml +++ b/peach-web/Cargo.toml @@ -51,3 +51,4 @@ vnstat_parse = "0.1.0" xdg = "2.2" jsonrpc_client = { version = "0.7", features = ["macros", "reqwest"] } reqwest = "0.11.24" +urlencoding = "2.1.3" diff --git a/peach-web/src/routes/authentication/change.rs b/peach-web/src/routes/authentication/change.rs index 50e7b69..1aa40ef 100644 --- a/peach-web/src/routes/authentication/change.rs +++ b/peach-web/src/routes/authentication/change.rs @@ -41,7 +41,7 @@ pub fn build_template(request: &Request) -> PreEscaped { // render flash message if cookies were found in the request @if let (Some(name), Some(msg)) = (flash_name, flash_msg) { (PreEscaped("")) - (templates::flash::build_template(name, msg)) + (templates::flash::build_template(&name, &msg)) } } }; @@ -102,12 +102,12 @@ pub fn handle_form(request: &Request) -> Response { ) { Ok(_) => ( // = - "flash_name=success".to_string(), - "flash_msg=New password has been saved".to_string(), + "success".to_string(), + "New password has been saved".to_string(), ), Err(err) => ( - "flash_name=error".to_string(), - format!("flash_msg=Failed to save new password: {}", err), + "error".to_string(), + format!("Failed to save new password: {}", err), ), }; diff --git a/peach-web/src/routes/authentication/forgot.rs b/peach-web/src/routes/authentication/forgot.rs index 84ff7df..098a396 100644 --- a/peach-web/src/routes/authentication/forgot.rs +++ b/peach-web/src/routes/authentication/forgot.rs @@ -38,7 +38,7 @@ pub fn build_template(request: &Request) -> PreEscaped { // render flash message if cookies were found in the request @if let (Some(name), Some(msg)) = (flash_name, flash_msg) { (PreEscaped("")) - (templates::flash::build_template(name, msg)) + (templates::flash::build_template(&name, &msg)) } } }; diff --git a/peach-web/src/routes/authentication/login.rs b/peach-web/src/routes/authentication/login.rs index ae423b3..e9268f7 100644 --- a/peach-web/src/routes/authentication/login.rs +++ b/peach-web/src/routes/authentication/login.rs @@ -37,7 +37,7 @@ pub fn build_template(request: &Request) -> PreEscaped { // render flash message if cookies were found in the request @if let (Some(name), Some(msg)) = (flash_name, flash_msg) { (PreEscaped("")) - (templates::flash::build_template(name, msg)) + (templates::flash::build_template(&name, &msg)) } } }; @@ -76,8 +76,8 @@ pub fn handle_form(request: &Request, session_data: &mut Option) -> debug!("Unsuccessful login attempt"); let err_msg = format!("Invalid password: {}", err); let (flash_name, flash_msg) = ( - "flash_name=error".to_string(), - format!("flash_msg={}", err_msg), + "error".to_string(), + format!("{}", err_msg), ); // if unsuccessful login, render /login page again diff --git a/peach-web/src/routes/authentication/logout.rs b/peach-web/src/routes/authentication/logout.rs index 21cc514..0fb4fe7 100644 --- a/peach-web/src/routes/authentication/logout.rs +++ b/peach-web/src/routes/authentication/logout.rs @@ -14,8 +14,8 @@ pub fn deauthenticate(session_data: &mut Option) -> Response { *session_data = None; let (flash_name, flash_msg) = ( - "flash_name=success".to_string(), - "flash_msg=Logged out".to_string(), + "success".to_string(), + "Logged out".to_string(), ); // set the flash cookie headers and redirect to the login page diff --git a/peach-web/src/routes/authentication/reset.rs b/peach-web/src/routes/authentication/reset.rs index e352490..fecd95a 100644 --- a/peach-web/src/routes/authentication/reset.rs +++ b/peach-web/src/routes/authentication/reset.rs @@ -41,7 +41,7 @@ pub fn build_template(request: &Request) -> PreEscaped { // render flash message if cookies were found in the request @if let (Some(name), Some(msg)) = (flash_name, flash_msg) { (PreEscaped("")) - (templates::flash::build_template(name, msg)) + (templates::flash::build_template(&name, &msg)) } } }; @@ -100,12 +100,12 @@ pub fn handle_form(request: &Request) -> Response { &data.new_password2, ) { Ok(_) => ( - "flash_name=success".to_string(), - "flash_msg=New password has been saved. Return home to login".to_string(), + "success".to_string(), + "New password has been saved. Return home to login".to_string(), ), Err(err) => ( - "flash_name=error".to_string(), - format!("flash_msg=Failed to reset password: {}", err), + "error".to_string(), + format!("Failed to reset password: {}", err), ), }; diff --git a/peach-web/src/routes/authentication/temporary.rs b/peach-web/src/routes/authentication/temporary.rs index 9bf17fb..994bbc1 100644 --- a/peach-web/src/routes/authentication/temporary.rs +++ b/peach-web/src/routes/authentication/temporary.rs @@ -21,8 +21,8 @@ pub fn handle_form() -> Response { Ok(_) => { debug!("Sent temporary password to device admin(s)"); ( - "flash_name=success".to_string(), - "flash_msg=A temporary password has been sent to the admin(s) of this device" + "success".to_string(), + "A temporary password has been sent to the admin(s) of this device" .to_string(), ) } diff --git a/peach-web/src/routes/scuttlebutt/block.rs b/peach-web/src/routes/scuttlebutt/block.rs index 176133c..c079781 100644 --- a/peach-web/src/routes/scuttlebutt/block.rs +++ b/peach-web/src/routes/scuttlebutt/block.rs @@ -21,17 +21,17 @@ pub fn handle_form(request: &Request) -> Response { Ok(status) if status.state == Some("active".to_string()) => { match sbot::block_peer(&data.public_key) { Ok(success_msg) => ( - "flash_name=success".to_string(), - format!("flash_msg={}", success_msg), + "success".to_string(), + format!("{}", success_msg), ), Err(error_msg) => ( - "flash_name=error".to_string(), - format!("flash_msg={}", error_msg), + "error".to_string(), + format!("{}", error_msg), ), } } _ => ( - "flash_name=warning".to_string(), + "warning".to_string(), "Social interactions are unavailable.".to_string(), ), }; diff --git a/peach-web/src/routes/scuttlebutt/follow.rs b/peach-web/src/routes/scuttlebutt/follow.rs index a73d47b..d045345 100644 --- a/peach-web/src/routes/scuttlebutt/follow.rs +++ b/peach-web/src/routes/scuttlebutt/follow.rs @@ -21,17 +21,17 @@ pub fn handle_form(request: &Request) -> Response { Ok(status) if status.state == Some("active".to_string()) => { match sbot::follow_peer(&data.public_key) { Ok(success_msg) => ( - "flash_name=success".to_string(), - format!("flash_msg={}", success_msg), + "success".to_string(), + format!("{}", success_msg), ), Err(error_msg) => ( - "flash_name=error".to_string(), - format!("flash_msg={}", error_msg), + "error".to_string(), + format!("{}", error_msg), ), } } _ => ( - "flash_name=warning".to_string(), + "warning".to_string(), "Social interactions are unavailable.".to_string(), ), }; diff --git a/peach-web/src/routes/scuttlebutt/invites.rs b/peach-web/src/routes/scuttlebutt/invites.rs index f2cc5d1..e122774 100644 --- a/peach-web/src/routes/scuttlebutt/invites.rs +++ b/peach-web/src/routes/scuttlebutt/invites.rs @@ -1,5 +1,6 @@ use maud::{html, Markup, PreEscaped}; use peach_lib::sbot::SbotStatus; +use peach_lib::config_manager; use rouille::{post_input, try_or_400, Request, Response}; use crate::{ @@ -14,9 +15,9 @@ use crate::{ /// Render the invite form template. fn invite_form_template( - flash_name: Option<&str>, - flash_msg: Option<&str>, - invite_code: Option<&str>, + flash_name: Option, + flash_msg: Option, + invite_code: Option, ) -> Markup { html! { (PreEscaped("")) @@ -40,7 +41,7 @@ fn invite_form_template( // avoid displaying the invite code-containing flash msg @if name != "code" { (PreEscaped("")) - (templates::flash::build_template(name, msg)) + (templates::flash::build_template(&name, &msg)) } } } @@ -51,10 +52,11 @@ fn invite_form_template( pub fn build_template(request: &Request) -> PreEscaped { // check for flash cookies; will be (None, None) if no flash cookies are found let (flash_name, flash_msg) = request.retrieve_flash(); + println!("build template invites!"); // if flash_name is "code" then flash_msg will be an invite code - let invite_code = if flash_name == Some("code") { - flash_msg + let invite_code = if flash_name == Some("code".to_string()) { + flash_msg.clone() } else { None }; @@ -89,9 +91,11 @@ pub fn handle_form(request: &Request) -> Response { })); let (flash_name, flash_msg) = match sbot::create_invite(data.uses) { - Ok(code) => ("flash_name=code".to_string(), format!("flash_msg={}", code)), - Err(e) => ("flash_name=error".to_string(), format!("flash_msg={}", e)), + Ok(code) => ("code".to_string(), format!("{}", code)), + Err(e) => ("error".to_string(), format!("{}", e)), }; + println!("invite flash name: {}, {}", flash_name, flash_msg); + Response::redirect_303("/scuttlebutt/invites").add_flash(flash_name, flash_msg) } diff --git a/peach-web/src/routes/scuttlebutt/private.rs b/peach-web/src/routes/scuttlebutt/private.rs index 737bbe8..a88a030 100644 --- a/peach-web/src/routes/scuttlebutt/private.rs +++ b/peach-web/src/routes/scuttlebutt/private.rs @@ -74,7 +74,7 @@ pub fn build_template(request: &Request, ssb_id: Option) -> PreEscaped")) - (templates::flash::build_template(name, msg)) + (templates::flash::build_template(&name, &msg)) } } } @@ -112,17 +112,17 @@ pub fn handle_form(request: &Request) -> Response { Ok(status) if status.state == Some("active".to_string()) => { match sbot::publish_private_msg(data.text, recipients) { Ok(success_msg) => ( - "flash_name=success".to_string(), - format!("flash_msg={}", success_msg), + "success".to_string(), + format!("{}", success_msg), ), Err(error_msg) => ( - "flash_name=error".to_string(), - format!("flash_msg={}", error_msg), + "error".to_string(), + format!("{}", error_msg), ), } } _ => ( - "flash_name=warning".to_string(), + "warning".to_string(), "Private messaging is unavailable.".to_string(), ), }; diff --git a/peach-web/src/routes/scuttlebutt/profile.rs b/peach-web/src/routes/scuttlebutt/profile.rs index 007aeb8..5f56e1b 100644 --- a/peach-web/src/routes/scuttlebutt/profile.rs +++ b/peach-web/src/routes/scuttlebutt/profile.rs @@ -160,7 +160,7 @@ pub fn build_template(request: &Request, ssb_id: Option) -> PreEscaped")) - (templates::flash::build_template(name, msg)) + (templates::flash::build_template(&name, &msg)) } } } diff --git a/peach-web/src/routes/scuttlebutt/profile_update.rs b/peach-web/src/routes/scuttlebutt/profile_update.rs index 8d7459b..ffb8ca8 100644 --- a/peach-web/src/routes/scuttlebutt/profile_update.rs +++ b/peach-web/src/routes/scuttlebutt/profile_update.rs @@ -81,7 +81,7 @@ pub fn build_template(request: &Request) -> PreEscaped { // render flash message if cookies were found in the request @if let (Some(name), Some(msg)) = (flash_name, flash_msg) { (PreEscaped("")) - (templates::flash::build_template(name, msg)) + (templates::flash::build_template(&name, &msg)) } } } @@ -139,17 +139,17 @@ pub fn handle_form(request: &Request) -> Response { data.image, ) { Ok(success_msg) => ( - "flash_name=success".to_string(), - format!("flash_msg={}", success_msg), + "success".to_string(), + format!("{}", success_msg), ), Err(error_msg) => ( - "flash_name=error".to_string(), - format!("flash_msg={}", error_msg), + "error".to_string(), + format!("{}", error_msg), ), } } _ => ( - "flash_name=warning".to_string(), + "warning".to_string(), "Profile is unavailable.".to_string(), ), }; @@ -165,7 +165,7 @@ pub fn handle_form(request: &Request) -> Response { } Err(err) => { let (flash_name, flash_msg) = - ("flash_name=error".to_string(), format!("flash_msg={}", err)); + ("error".to_string(), format!("{}", err)); Response::redirect_303("/scuttlebutt/search").add_flash(flash_name, flash_msg) } } diff --git a/peach-web/src/routes/scuttlebutt/publish.rs b/peach-web/src/routes/scuttlebutt/publish.rs index 3d1b0a9..9d246e3 100644 --- a/peach-web/src/routes/scuttlebutt/publish.rs +++ b/peach-web/src/routes/scuttlebutt/publish.rs @@ -22,17 +22,17 @@ pub fn handle_form(request: &Request) -> Response { Ok(status) if status.state == Some("active".to_string()) => { match sbot::publish_public_post(data.text) { Ok(success_msg) => ( - "flash_name=success".to_string(), - format!("flash_msg={}", success_msg), + "success".to_string(), + format!("{}", success_msg), ), Err(error_msg) => ( - "flash_name=error".to_string(), - format!("flash_msg={}", error_msg), + "error".to_string(), + format!("{}", error_msg), ), } } _ => ( - "flash_name=warning".to_string(), + "warning".to_string(), "Public posting is unavailable.".to_string(), ), }; diff --git a/peach-web/src/routes/scuttlebutt/search.rs b/peach-web/src/routes/scuttlebutt/search.rs index 01bebf5..3220ce3 100644 --- a/peach-web/src/routes/scuttlebutt/search.rs +++ b/peach-web/src/routes/scuttlebutt/search.rs @@ -29,7 +29,7 @@ pub fn build_template(request: &Request) -> PreEscaped { // render flash message if cookies were found in the request @if let (Some(name), Some(msg)) = (flash_name, flash_msg) { (PreEscaped("")) - (templates::flash::build_template(name, msg)) + (templates::flash::build_template(&name, &msg)) } } } @@ -62,7 +62,7 @@ pub fn handle_form(request: &Request) -> Response { } Err(err) => { let (flash_name, flash_msg) = - ("flash_name=error".to_string(), format!("flash_msg={}", err)); + ("error".to_string(), format!("{}", err)); Response::redirect_303("/scuttlebutt/search").add_flash(flash_name, flash_msg) } } diff --git a/peach-web/src/routes/scuttlebutt/unblock.rs b/peach-web/src/routes/scuttlebutt/unblock.rs index 7ebf7f2..d4f5d0d 100644 --- a/peach-web/src/routes/scuttlebutt/unblock.rs +++ b/peach-web/src/routes/scuttlebutt/unblock.rs @@ -21,17 +21,17 @@ pub fn handle_form(request: &Request) -> Response { Ok(status) if status.state == Some("active".to_string()) => { match sbot::unblock_peer(&data.public_key) { Ok(success_msg) => ( - "flash_name=success".to_string(), - format!("flash_msg={}", success_msg), + "success".to_string(), + format!("{}", success_msg), ), Err(error_msg) => ( - "flash_name=error".to_string(), - format!("flash_msg={}", error_msg), + "error".to_string(), + format!("{}", error_msg), ), } } _ => ( - "flash_name=warning".to_string(), + "warning".to_string(), "Social interactions are unavailable.".to_string(), ), }; diff --git a/peach-web/src/routes/scuttlebutt/unfollow.rs b/peach-web/src/routes/scuttlebutt/unfollow.rs index a043f06..20267d9 100644 --- a/peach-web/src/routes/scuttlebutt/unfollow.rs +++ b/peach-web/src/routes/scuttlebutt/unfollow.rs @@ -21,17 +21,17 @@ pub fn handle_form(request: &Request) -> Response { Ok(status) if status.state == Some("active".to_string()) => { match sbot::unfollow_peer(&data.public_key) { Ok(success_msg) => ( - "flash_name=success".to_string(), - format!("flash_msg={}", success_msg), + "success".to_string(), + format!("{}", success_msg), ), Err(error_msg) => ( - "flash_name=error".to_string(), - format!("flash_msg={}", error_msg), + "error".to_string(), + format!("{}", error_msg), ), } } _ => ( - "flash_name=warning".to_string(), + "warning".to_string(), "Social interactions are unavailable.".to_string(), ), }; diff --git a/peach-web/src/routes/settings/admin/add.rs b/peach-web/src/routes/settings/admin/add.rs index 863d3c7..c969f25 100644 --- a/peach-web/src/routes/settings/admin/add.rs +++ b/peach-web/src/routes/settings/admin/add.rs @@ -21,12 +21,12 @@ pub fn handle_form(request: &Request) -> Response { // save submitted admin id to file let (flash_name, flash_msg) = match config_manager::add_ssb_admin_id(&data.ssb_id) { Ok(_) => ( - "flash_name=success".to_string(), - "flash_msg=Added SSB administrator".to_string(), + "success".to_string(), + "Added SSB administrator".to_string(), ), Err(err) => ( - "flash_name=error".to_string(), - format!("flash_msg=Failed to add new administrator: {}", err), + "error".to_string(), + format!("Failed to add new administrator: {}", err), ), }; diff --git a/peach-web/src/routes/settings/admin/configure.rs b/peach-web/src/routes/settings/admin/configure.rs index 4b823eb..69d4bb6 100644 --- a/peach-web/src/routes/settings/admin/configure.rs +++ b/peach-web/src/routes/settings/admin/configure.rs @@ -20,8 +20,8 @@ pub fn build_template(request: &Request) -> PreEscaped { // currently produces an error because we end up with Some(String) // instead of Some(str) Err(_err) => { - flash_name = Some("flash_name=error"); - flash_msg = Some("flash_msg=Failed to read PeachCloud configuration file"); + flash_name = Some("error".to_string()); + flash_msg = Some("Failed to read PeachCloud configuration file".to_string()); None } }; @@ -58,7 +58,7 @@ pub fn build_template(request: &Request) -> PreEscaped { // render flash message if cookies were found in the request @if let (Some(name), Some(msg)) = (flash_name, flash_msg) { (PreEscaped("")) - (templates::flash::build_template(name, msg)) + (templates::flash::build_template(&name, &msg)) } } }; diff --git a/peach-web/src/routes/settings/admin/delete.rs b/peach-web/src/routes/settings/admin/delete.rs index 06bfc1c..da08393 100644 --- a/peach-web/src/routes/settings/admin/delete.rs +++ b/peach-web/src/routes/settings/admin/delete.rs @@ -21,12 +21,12 @@ pub fn handle_form(request: &Request) -> Response { let (flash_name, flash_msg) = match config_manager::delete_ssb_admin_id(&data.ssb_id) { Ok(_) => ( // = - "flash_name=success".to_string(), - "flash_msg=Removed SSB administrator".to_string(), + "success".to_string(), + "Removed SSB administrator".to_string(), ), Err(err) => ( - "flash_name=error".to_string(), - format!("flash_msg=Failed to remove administrator: {}", err), + "error".to_string(), + format!("Failed to remove administrator: {}", err), ), }; diff --git a/peach-web/src/routes/settings/network/add_ap.rs b/peach-web/src/routes/settings/network/add_ap.rs index fed88ad..cd400ce 100644 --- a/peach-web/src/routes/settings/network/add_ap.rs +++ b/peach-web/src/routes/settings/network/add_ap.rs @@ -51,7 +51,7 @@ pub fn build_template(request: &Request, selected_ap: Option) -> PreEsca } @if let (Some(name), Some(msg)) = (flash_name, flash_msg) { (PreEscaped("")) - (templates::flash::build_template(name, msg)) + (templates::flash::build_template(&name, &msg)) } } }; @@ -91,7 +91,7 @@ pub fn handle_form(request: &Request) -> Response { ), }; - let (flash_name, flash_msg) = (format!("flash_name={}", name), format!("flash_msg={}", msg)); + let (flash_name, flash_msg) = (format!("{}", name), format!("{}", msg)); Response::redirect_303("/settings/network/wifi/add").add_flash(flash_name, flash_msg) } diff --git a/peach-web/src/routes/settings/network/ap_details.rs b/peach-web/src/routes/settings/network/ap_details.rs index 20985b4..b67fd56 100644 --- a/peach-web/src/routes/settings/network/ap_details.rs +++ b/peach-web/src/routes/settings/network/ap_details.rs @@ -180,7 +180,7 @@ pub fn build_template(request: &Request, selected_ap: String) -> PreEscaped")) - (templates::flash::build_template(name, msg)) + (templates::flash::build_template(&name, &msg)) } } }; diff --git a/peach-web/src/routes/settings/network/configure_dns.rs b/peach-web/src/routes/settings/network/configure_dns.rs index a619234..606ca22 100644 --- a/peach-web/src/routes/settings/network/configure_dns.rs +++ b/peach-web/src/routes/settings/network/configure_dns.rs @@ -111,7 +111,7 @@ pub fn build_template(request: &Request) -> PreEscaped { (render_save_button()) @if let (Some(name), Some(msg)) = (flash_name, flash_msg) { (PreEscaped("")) - (templates::flash::build_template(name, msg)) + (templates::flash::build_template(&name, &msg)) } } } @@ -195,7 +195,7 @@ pub fn handle_form(request: &Request) -> Response { ), }; - let (flash_name, flash_msg) = (format!("flash_name={}", name), format!("flash_msg={}", msg)); + let (flash_name, flash_msg) = (format!("{}", name), format!("{}", msg)); Response::redirect_303("/settings/network/dns").add_flash(flash_name, flash_msg) } diff --git a/peach-web/src/routes/settings/network/data_usage_limits.rs b/peach-web/src/routes/settings/network/data_usage_limits.rs index 3e0fcb8..42d9a58 100644 --- a/peach-web/src/routes/settings/network/data_usage_limits.rs +++ b/peach-web/src/routes/settings/network/data_usage_limits.rs @@ -158,7 +158,7 @@ pub fn build_template(request: &Request) -> PreEscaped { } @if let (Some(name), Some(msg)) = (flash_name, flash_msg) { (PreEscaped("")) - (templates::flash::build_template(name, msg)) + (templates::flash::build_template(&name, &msg)) } }; } diff --git a/peach-web/src/routes/settings/network/menu.rs b/peach-web/src/routes/settings/network/menu.rs index 2ccd451..b37b048 100644 --- a/peach-web/src/routes/settings/network/menu.rs +++ b/peach-web/src/routes/settings/network/menu.rs @@ -52,7 +52,7 @@ pub fn build_template(request: &Request) -> PreEscaped { // render flash message if cookies were found in the request @if let (Some(name), Some(msg)) = (flash_name, flash_msg) { (PreEscaped("")) - (templates::flash::build_template(name, msg)) + (templates::flash::build_template(&name, &msg)) } } }; diff --git a/peach-web/src/routes/settings/network/modify_ap.rs b/peach-web/src/routes/settings/network/modify_ap.rs index 86a92fb..3e4f5a8 100644 --- a/peach-web/src/routes/settings/network/modify_ap.rs +++ b/peach-web/src/routes/settings/network/modify_ap.rs @@ -52,7 +52,7 @@ pub fn build_template(request: &Request, selected_ap: Option) -> PreEsca // render flash message if cookies were found in the request @if let (Some(name), Some(msg)) = (flash_name, flash_msg) { (PreEscaped("")) - (templates::flash::build_template(name, msg)) + (templates::flash::build_template(&name, &msg)) } } }; @@ -99,7 +99,7 @@ pub fn handle_form(request: &Request) -> Response { ), }; - let (flash_name, flash_msg) = (format!("flash_name={}", name), format!("flash_msg={}", msg)); + let (flash_name, flash_msg) = (format!("{}", name), format!("{}", msg)); Response::redirect_303("/settings/network/wifi/modify").add_flash(flash_name, flash_msg) } diff --git a/peach-web/src/routes/settings/power/menu.rs b/peach-web/src/routes/settings/power/menu.rs index 42dc28b..e15f282 100644 --- a/peach-web/src/routes/settings/power/menu.rs +++ b/peach-web/src/routes/settings/power/menu.rs @@ -23,7 +23,7 @@ pub fn build_template(request: &Request) -> PreEscaped { } @if let (Some(name), Some(msg)) = (flash_name, flash_msg) { (PreEscaped("")) - (templates::flash::build_template(name, msg)) + (templates::flash::build_template(&name, &msg)) } } } diff --git a/peach-web/src/routes/settings/power/reboot.rs b/peach-web/src/routes/settings/power/reboot.rs index 5c1ba7b..a033b97 100644 --- a/peach-web/src/routes/settings/power/reboot.rs +++ b/peach-web/src/routes/settings/power/reboot.rs @@ -30,7 +30,7 @@ pub fn handle_reboot() -> Response { ), }; - let (flash_name, flash_msg) = (format!("flash_name={}", name), format!("flash_msg={}", msg)); + let (flash_name, flash_msg) = (format!("{}", name), format!("{}", msg)); Response::redirect_303("/power").add_flash(flash_name, flash_msg) } diff --git a/peach-web/src/routes/settings/power/shutdown.rs b/peach-web/src/routes/settings/power/shutdown.rs index ae1dfa3..cb1ba3d 100644 --- a/peach-web/src/routes/settings/power/shutdown.rs +++ b/peach-web/src/routes/settings/power/shutdown.rs @@ -29,7 +29,7 @@ pub fn handle_shutdown() -> Response { ), }; - let (flash_name, flash_msg) = (format!("flash_name={}", name), format!("flash_msg={}", msg)); + let (flash_name, flash_msg) = (format!("{}", name), format!("{}", msg)); Response::redirect_303("/power").add_flash(flash_name, flash_msg) } diff --git a/peach-web/src/routes/settings/scuttlebutt/configure.rs b/peach-web/src/routes/settings/scuttlebutt/configure.rs index 715a0d6..329a473 100644 --- a/peach-web/src/routes/settings/scuttlebutt/configure.rs +++ b/peach-web/src/routes/settings/scuttlebutt/configure.rs @@ -160,7 +160,7 @@ pub fn build_template(request: &Request) -> PreEscaped { // render flash message if cookies were found in the request @if let (Some(name), Some(msg)) = (flash_name, flash_msg) { (PreEscaped("")) - (templates::flash::build_template(name, msg)) + (templates::flash::build_template(&name, &msg)) } } }; @@ -251,7 +251,7 @@ pub fn handle_form(request: &Request, restart: bool) -> Response { ), }; - let (flash_name, flash_msg) = (format!("flash_name={}", name), format!("flash_msg={}", msg)); + let (flash_name, flash_msg) = (format!("{}", name), format!("{}", msg)); Response::redirect_303("/settings/scuttlebutt/configure").add_flash(flash_name, flash_msg) } diff --git a/peach-web/src/routes/settings/scuttlebutt/default.rs b/peach-web/src/routes/settings/scuttlebutt/default.rs index daf8d94..df8ba59 100644 --- a/peach-web/src/routes/settings/scuttlebutt/default.rs +++ b/peach-web/src/routes/settings/scuttlebutt/default.rs @@ -15,7 +15,7 @@ pub fn write_config() -> Response { ), }; - let (flash_name, flash_msg) = (format!("flash_name={}", name), format!("flash_msg={}", msg)); + let (flash_name, flash_msg) = (format!("{}", name), format!("{}", msg)); Response::redirect_303("/settings/scuttlebutt/configure").add_flash(flash_name, flash_msg) } diff --git a/peach-web/src/routes/settings/scuttlebutt/menu.rs b/peach-web/src/routes/settings/scuttlebutt/menu.rs index 4360898..ea42016 100644 --- a/peach-web/src/routes/settings/scuttlebutt/menu.rs +++ b/peach-web/src/routes/settings/scuttlebutt/menu.rs @@ -48,7 +48,7 @@ pub fn build_template(request: &Request) -> PreEscaped { // render flash message if cookies were found in the request @if let (Some(name), Some(msg)) = (flash_name, flash_msg) { (PreEscaped("")) - (templates::flash::build_template(name, msg)) + (templates::flash::build_template(&name, &msg)) } } }; diff --git a/peach-web/src/routes/settings/scuttlebutt/restart.rs b/peach-web/src/routes/settings/scuttlebutt/restart.rs index 3e25b73..1c7d417 100644 --- a/peach-web/src/routes/settings/scuttlebutt/restart.rs +++ b/peach-web/src/routes/settings/scuttlebutt/restart.rs @@ -14,17 +14,17 @@ pub fn restart_sbot() -> Response { // if stop was successful, try to start the process Ok(_) => match systemctl_sbot_cmd("start") { Ok(_) => ( - "flash_name=success".to_string(), - "flash_msg=Sbot process has been restarted".to_string(), + "success".to_string(), + "Sbot process has been restarted".to_string(), ), Err(e) => ( - "flash_name=error".to_string(), - format!("flash_msg=Failed to start the sbot process: {}", e), + "error".to_string(), + format!("Failed to start the sbot process: {}", e), ), }, Err(e) => ( - "flash_name=error".to_string(), - format!("flash_msg=Failed to stop the sbot process: {}", e), + "error".to_string(), + format!("Failed to stop the sbot process: {}", e), ), }; diff --git a/peach-web/src/routes/settings/scuttlebutt/start.rs b/peach-web/src/routes/settings/scuttlebutt/start.rs index 2ee7f4e..ddf9932 100644 --- a/peach-web/src/routes/settings/scuttlebutt/start.rs +++ b/peach-web/src/routes/settings/scuttlebutt/start.rs @@ -12,12 +12,12 @@ pub fn start_sbot() -> Response { info!("Starting go-sbot.service"); let (flash_name, flash_msg) = match systemctl_sbot_cmd("start") { Ok(_) => ( - "flash_name=success".to_string(), - "flash_msg=Sbot process has been started".to_string(), + "success".to_string(), + "Sbot process has been started".to_string(), ), Err(_) => ( - "flash_name=error".to_string(), - "flash_msg=Failed to start the sbot process".to_string(), + "error".to_string(), + "Failed to start the sbot process".to_string(), ), }; diff --git a/peach-web/src/routes/settings/scuttlebutt/stop.rs b/peach-web/src/routes/settings/scuttlebutt/stop.rs index d548698..68ad881 100644 --- a/peach-web/src/routes/settings/scuttlebutt/stop.rs +++ b/peach-web/src/routes/settings/scuttlebutt/stop.rs @@ -9,15 +9,15 @@ use crate::utils::{flash::FlashResponse, sbot::systemctl_sbot_cmd}; /// Redirect to the Scuttlebutt settings menu and communicate the outcome of /// the attempt via a flash message. pub fn stop_sbot() -> Response { - info!("Stopping go-sbot.service"); + info!("Stopping tilde-sbot.service"); let (flash_name, flash_msg) = match systemctl_sbot_cmd("stop") { Ok(_) => ( - "flash_name=success".to_string(), - "flash_msg=Sbot process has been stopped".to_string(), + "success".to_string(), + "Sbot process has been stopped".to_string(), ), Err(_) => ( - "flash_name=error".to_string(), - "flash_msg=Failed to stop the sbot process".to_string(), + "error".to_string(), + "Failed to stop the sbot process".to_string(), ), }; diff --git a/peach-web/src/utils/flash.rs b/peach-web/src/utils/flash.rs index 0134ca1..b2b4b1c 100644 --- a/peach-web/src/utils/flash.rs +++ b/peach-web/src/utils/flash.rs @@ -1,21 +1,21 @@ use rouille::{input, Request, Response}; +use urlencoding; /// Flash message trait for `Request`. pub trait FlashRequest { /// Retrieve the flash message cookie values from a `Request`. - fn retrieve_flash(&self) -> (Option<&str>, Option<&str>); + fn retrieve_flash(&self) -> (Option, Option); } impl FlashRequest for Request { - fn retrieve_flash(&self) -> (Option<&str>, Option<&str>) { - // check for flash cookies + fn retrieve_flash(&self) -> (Option, Option) { let flash_name = input::cookies(self) .find(|&(n, _)| n == "flash_name") // return the value of the cookie (key is already known) - .map(|key_val| key_val.1); + .and_then(|(_, val)| urlencoding::decode(&val).ok().map(|s| s.into_owned())); let flash_msg = input::cookies(self) .find(|&(n, _)| n == "flash_msg") - .map(|key_val| key_val.1); + .and_then(|(_, val)| urlencoding::decode(&val).ok().map(|s| s.into_owned())); (flash_name, flash_msg) } @@ -31,9 +31,12 @@ pub trait FlashResponse { impl FlashResponse for Response { fn add_flash(self, flash_name: String, flash_msg: String) -> Response { + + let flash_name = urlencoding::encode(&flash_name).into_owned(); + let flash_msg = urlencoding::encode(&flash_msg).into_owned(); // set the flash cookie headers - self.with_additional_header("Set-Cookie", format!("{}; Max-Age=1", flash_name)) - .with_additional_header("Set-Cookie", format!("{}; Max-Age=1", flash_msg)) + self.with_additional_header("Set-Cookie", format!("flash_name={}; Max-Age=1;", flash_name)) + .with_additional_header("Set-Cookie", format!("flash_msg={}; Max-Age=1;", flash_msg)) } fn reset_flash(self) -> Response { diff --git a/peach-web/src/utils/sbot.rs b/peach-web/src/utils/sbot.rs index 810a98d..19e260e 100644 --- a/peach-web/src/utils/sbot.rs +++ b/peach-web/src/utils/sbot.rs @@ -26,11 +26,14 @@ use crate::{error::PeachWebError, utils::sbot}; /// Executes a systemctl command for the solar-sbot.service process. pub fn systemctl_sbot_cmd(cmd: &str) -> Result { - let output = Command::new("sudo") + let mut command = Command::new("sudo"); + command .arg("systemctl") .arg(cmd) - .arg(config_manager::get_config_value("TILDE_SBOT_SERVICE")?) - .output()?; + .arg(config_manager::get_config_value("TILDE_SBOT_SERVICE")?); + println!("systemctl command: {:?}", command); + let output = command.output()?; + println!("systemctl output: {:?}", output); Ok(output) } @@ -146,13 +149,8 @@ pub fn create_invite(uses: u16) -> Result { task::block_on(async { let mut sbot_client = init_sbot_client().await?; - debug!("Generating Scuttlebutt invite code"); - let mut invite_code = sbot_client.create_invite(uses as i32).await?; - - let domain = config_manager::get_config_value("EXTERNAL_DOMAIN")?; - if !domain.is_empty() { - invite_code = domain + &invite_code[4..]; - } + let external_domain = config_manager::get_config_value("EXTERNAL_DOMAIN").ok(); + let mut invite_code = sbot_client.create_invite(uses as i32, external_domain.as_deref()).await?; Ok(invite_code) }) diff --git a/tdeploy.sh b/tdeploy.sh new file mode 100755 index 0000000..0526979 --- /dev/null +++ b/tdeploy.sh @@ -0,0 +1,3 @@ +#! /bin/bash +cargo build --package peach-web --release +rsync -azvh /home/notplants/computer/projects/peachpub/peach-workspace/target/release/peach-web root@10.243.137.235:/var/www/peachpub_ynh/peach-web diff --git a/tilde-client/src/lib.rs b/tilde-client/src/lib.rs index 6b3b3d0..1b2d86f 100644 --- a/tilde-client/src/lib.rs +++ b/tilde-client/src/lib.rs @@ -9,7 +9,7 @@ use std::process::{Command, exit}; mod error; pub struct TildeClient { - pub port: String, + pub ssb_port: String, pub tilde_binary_path: String, pub tilde_database_path: String, } @@ -133,8 +133,9 @@ impl TildeClient { self.run_tilde_command(vec!["private", "-u", ":admin", "-i", &self_key, "-r", recipient_key, "-t", message]) } - pub async fn create_invite(&self, num_uses: i32) -> Result { + pub async fn create_invite(&self, num_uses: i32, external_domain: Option<&str>) -> Result { let key = self.whoami().await?; - self.run_tilde_command(vec!["create_invite", "-u", &num_uses.to_string(), "-i", &key, "-p", &self.port, "-a", "127.0.0.1", "-e", "-1"]) + let address = external_domain.unwrap_or_else(|| "127.0.0.1"); + self.run_tilde_command(vec!["create_invite", "-u", &num_uses.to_string(), "-i", &key, "-p", &self.ssb_port, "-a", address, "-e", "-1"]) } }