working
This commit is contained in:
parent
8501296ea1
commit
eaca10954e
7
Cargo.lock
generated
7
Cargo.lock
generated
@ -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"
|
||||
|
4
pdeploy.sh
Executable file
4
pdeploy.sh
Executable file
@ -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'
|
@ -222,9 +222,10 @@ impl SbotConfig {
|
||||
pub fn read() -> Result<Self, PeachError> {
|
||||
// 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<TildeClient, PeachError> {
|
||||
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,
|
||||
};
|
||||
|
@ -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"
|
||||
|
@ -41,7 +41,7 @@ pub fn build_template(request: &Request) -> PreEscaped<String> {
|
||||
// render flash message if cookies were found in the request
|
||||
@if let (Some(name), Some(msg)) = (flash_name, flash_msg) {
|
||||
(PreEscaped("<!-- FLASH MESSAGE -->"))
|
||||
(templates::flash::build_template(name, msg))
|
||||
(templates::flash::build_template(&name, &msg))
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -102,12 +102,12 @@ pub fn handle_form(request: &Request) -> Response {
|
||||
) {
|
||||
Ok(_) => (
|
||||
// <cookie-name>=<cookie-value>
|
||||
"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),
|
||||
),
|
||||
};
|
||||
|
||||
|
@ -38,7 +38,7 @@ pub fn build_template(request: &Request) -> PreEscaped<String> {
|
||||
// render flash message if cookies were found in the request
|
||||
@if let (Some(name), Some(msg)) = (flash_name, flash_msg) {
|
||||
(PreEscaped("<!-- FLASH MESSAGE -->"))
|
||||
(templates::flash::build_template(name, msg))
|
||||
(templates::flash::build_template(&name, &msg))
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -37,7 +37,7 @@ pub fn build_template(request: &Request) -> PreEscaped<String> {
|
||||
// render flash message if cookies were found in the request
|
||||
@if let (Some(name), Some(msg)) = (flash_name, flash_msg) {
|
||||
(PreEscaped("<!-- FLASH MESSAGE -->"))
|
||||
(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<SessionData>) ->
|
||||
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
|
||||
|
@ -14,8 +14,8 @@ pub fn deauthenticate(session_data: &mut Option<SessionData>) -> 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
|
||||
|
@ -41,7 +41,7 @@ pub fn build_template(request: &Request) -> PreEscaped<String> {
|
||||
// render flash message if cookies were found in the request
|
||||
@if let (Some(name), Some(msg)) = (flash_name, flash_msg) {
|
||||
(PreEscaped("<!-- FLASH MESSAGE -->"))
|
||||
(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),
|
||||
),
|
||||
};
|
||||
|
||||
|
@ -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(),
|
||||
)
|
||||
}
|
||||
|
@ -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(),
|
||||
),
|
||||
};
|
||||
|
@ -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(),
|
||||
),
|
||||
};
|
||||
|
@ -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<String>,
|
||||
flash_msg: Option<String>,
|
||||
invite_code: Option<String>,
|
||||
) -> Markup {
|
||||
html! {
|
||||
(PreEscaped("<!-- SCUTTLEBUTT INVITE FORM -->"))
|
||||
@ -40,7 +41,7 @@ fn invite_form_template(
|
||||
// avoid displaying the invite code-containing flash msg
|
||||
@if name != "code" {
|
||||
(PreEscaped("<!-- FLASH MESSAGE -->"))
|
||||
(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<String> {
|
||||
// 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)
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ pub fn build_template(request: &Request, ssb_id: Option<String>) -> PreEscaped<S
|
||||
// render flash message if cookies were found in the request
|
||||
@if let (Some(name), Some(msg)) = (flash_name, flash_msg) {
|
||||
(PreEscaped("<!-- FLASH MESSAGE -->"))
|
||||
(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(),
|
||||
),
|
||||
};
|
||||
|
@ -160,7 +160,7 @@ pub fn build_template(request: &Request, ssb_id: Option<String>) -> PreEscaped<S
|
||||
// render flash message if cookies were found in the request
|
||||
@if let (Some(name), Some(msg)) = (flash_name, flash_msg) {
|
||||
(PreEscaped("<!-- FLASH MESSAGE -->"))
|
||||
(templates::flash::build_template(name, msg))
|
||||
(templates::flash::build_template(&name, &msg))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ pub fn build_template(request: &Request) -> PreEscaped<String> {
|
||||
// render flash message if cookies were found in the request
|
||||
@if let (Some(name), Some(msg)) = (flash_name, flash_msg) {
|
||||
(PreEscaped("<!-- FLASH MESSAGE -->"))
|
||||
(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)
|
||||
}
|
||||
}
|
||||
|
@ -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(),
|
||||
),
|
||||
};
|
||||
|
@ -29,7 +29,7 @@ pub fn build_template(request: &Request) -> PreEscaped<String> {
|
||||
// render flash message if cookies were found in the request
|
||||
@if let (Some(name), Some(msg)) = (flash_name, flash_msg) {
|
||||
(PreEscaped("<!-- FLASH MESSAGE -->"))
|
||||
(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)
|
||||
}
|
||||
}
|
||||
|
@ -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(),
|
||||
),
|
||||
};
|
||||
|
@ -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(),
|
||||
),
|
||||
};
|
||||
|
@ -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),
|
||||
),
|
||||
};
|
||||
|
||||
|
@ -20,8 +20,8 @@ pub fn build_template(request: &Request) -> PreEscaped<String> {
|
||||
// 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<String> {
|
||||
// render flash message if cookies were found in the request
|
||||
@if let (Some(name), Some(msg)) = (flash_name, flash_msg) {
|
||||
(PreEscaped("<!-- FLASH MESSAGE -->"))
|
||||
(templates::flash::build_template(name, msg))
|
||||
(templates::flash::build_template(&name, &msg))
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -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(_) => (
|
||||
// <cookie-name>=<cookie-value>
|
||||
"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),
|
||||
),
|
||||
};
|
||||
|
||||
|
@ -51,7 +51,7 @@ pub fn build_template(request: &Request, selected_ap: Option<String>) -> PreEsca
|
||||
}
|
||||
@if let (Some(name), Some(msg)) = (flash_name, flash_msg) {
|
||||
(PreEscaped("<!-- FLASH MESSAGE -->"))
|
||||
(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)
|
||||
}
|
||||
|
@ -180,7 +180,7 @@ pub fn build_template(request: &Request, selected_ap: String) -> PreEscaped<Stri
|
||||
}
|
||||
@if let (Some(name), Some(msg)) = (flash_name, flash_msg) {
|
||||
(PreEscaped("<!-- FLASH MESSAGE -->"))
|
||||
(templates::flash::build_template(name, msg))
|
||||
(templates::flash::build_template(&name, &msg))
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -111,7 +111,7 @@ pub fn build_template(request: &Request) -> PreEscaped<String> {
|
||||
(render_save_button())
|
||||
@if let (Some(name), Some(msg)) = (flash_name, flash_msg) {
|
||||
(PreEscaped("<!-- FLASH MESSAGE -->"))
|
||||
(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)
|
||||
}
|
||||
|
@ -158,7 +158,7 @@ pub fn build_template(request: &Request) -> PreEscaped<String> {
|
||||
}
|
||||
@if let (Some(name), Some(msg)) = (flash_name, flash_msg) {
|
||||
(PreEscaped("<!-- FLASH MESSAGE -->"))
|
||||
(templates::flash::build_template(name, msg))
|
||||
(templates::flash::build_template(&name, &msg))
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ pub fn build_template(request: &Request) -> PreEscaped<String> {
|
||||
// render flash message if cookies were found in the request
|
||||
@if let (Some(name), Some(msg)) = (flash_name, flash_msg) {
|
||||
(PreEscaped("<!-- FLASH MESSAGE -->"))
|
||||
(templates::flash::build_template(name, msg))
|
||||
(templates::flash::build_template(&name, &msg))
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -52,7 +52,7 @@ pub fn build_template(request: &Request, selected_ap: Option<String>) -> PreEsca
|
||||
// render flash message if cookies were found in the request
|
||||
@if let (Some(name), Some(msg)) = (flash_name, flash_msg) {
|
||||
(PreEscaped("<!-- FLASH MESSAGE -->"))
|
||||
(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)
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ pub fn build_template(request: &Request) -> PreEscaped<String> {
|
||||
}
|
||||
@if let (Some(name), Some(msg)) = (flash_name, flash_msg) {
|
||||
(PreEscaped("<!-- FLASH MESSAGE -->"))
|
||||
(templates::flash::build_template(name, msg))
|
||||
(templates::flash::build_template(&name, &msg))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -160,7 +160,7 @@ pub fn build_template(request: &Request) -> PreEscaped<String> {
|
||||
// render flash message if cookies were found in the request
|
||||
@if let (Some(name), Some(msg)) = (flash_name, flash_msg) {
|
||||
(PreEscaped("<!-- FLASH MESSAGE -->"))
|
||||
(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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ pub fn build_template(request: &Request) -> PreEscaped<String> {
|
||||
// render flash message if cookies were found in the request
|
||||
@if let (Some(name), Some(msg)) = (flash_name, flash_msg) {
|
||||
(PreEscaped("<!-- FLASH MESSAGE -->"))
|
||||
(templates::flash::build_template(name, msg))
|
||||
(templates::flash::build_template(&name, &msg))
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -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),
|
||||
),
|
||||
};
|
||||
|
||||
|
@ -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(),
|
||||
),
|
||||
};
|
||||
|
||||
|
@ -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(),
|
||||
),
|
||||
};
|
||||
|
||||
|
@ -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<String>, Option<String>);
|
||||
}
|
||||
|
||||
impl FlashRequest for Request {
|
||||
fn retrieve_flash(&self) -> (Option<&str>, Option<&str>) {
|
||||
// check for flash cookies
|
||||
fn retrieve_flash(&self) -> (Option<String>, Option<String>) {
|
||||
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 {
|
||||
|
@ -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<Output, PeachWebError> {
|
||||
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<String, PeachWebError> {
|
||||
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)
|
||||
})
|
||||
|
3
tdeploy.sh
Executable file
3
tdeploy.sh
Executable file
@ -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
|
@ -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<String, TildeError> {
|
||||
pub async fn create_invite(&self, num_uses: i32, external_domain: Option<&str>) -> Result<String, TildeError> {
|
||||
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"])
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user